~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/fs/stat.c

Version: ~ [ linux-6.11-rc3 ] ~ [ linux-6.10.4 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.45 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.104 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.164 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.223 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.281 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.319 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

Diff markup

Differences between /fs/stat.c (Version linux-6.11-rc3) and /fs/stat.c (Version linux-5.17.15)


  1 // SPDX-License-Identifier: GPL-2.0                 1 // SPDX-License-Identifier: GPL-2.0
  2 /*                                                  2 /*
  3  *  linux/fs/stat.c                                 3  *  linux/fs/stat.c
  4  *                                                  4  *
  5  *  Copyright (C) 1991, 1992  Linus Torvalds        5  *  Copyright (C) 1991, 1992  Linus Torvalds
  6  */                                                 6  */
  7                                                     7 
  8 #include <linux/blkdev.h>                      << 
  9 #include <linux/export.h>                           8 #include <linux/export.h>
 10 #include <linux/mm.h>                               9 #include <linux/mm.h>
 11 #include <linux/errno.h>                           10 #include <linux/errno.h>
 12 #include <linux/file.h>                            11 #include <linux/file.h>
 13 #include <linux/highuid.h>                         12 #include <linux/highuid.h>
 14 #include <linux/fs.h>                              13 #include <linux/fs.h>
 15 #include <linux/namei.h>                           14 #include <linux/namei.h>
 16 #include <linux/security.h>                        15 #include <linux/security.h>
 17 #include <linux/cred.h>                            16 #include <linux/cred.h>
 18 #include <linux/syscalls.h>                        17 #include <linux/syscalls.h>
 19 #include <linux/pagemap.h>                         18 #include <linux/pagemap.h>
 20 #include <linux/compat.h>                          19 #include <linux/compat.h>
 21 #include <linux/iversion.h>                    << 
 22                                                    20 
 23 #include <linux/uaccess.h>                         21 #include <linux/uaccess.h>
 24 #include <asm/unistd.h>                            22 #include <asm/unistd.h>
 25                                                    23 
 26 #include "internal.h"                              24 #include "internal.h"
 27 #include "mount.h"                                 25 #include "mount.h"
 28                                                    26 
 29 /**                                                27 /**
 30  * generic_fillattr - Fill in the basic attrib     28  * generic_fillattr - Fill in the basic attributes from the inode struct
 31  * @idmap:              idmap of the mount the !!  29  * @mnt_userns: user namespace of the mount the inode was found from
 32  * @request_mask:       statx request_mask     !!  30  * @inode:      Inode to use as the source
 33  * @inode:              Inode to use as the so !!  31  * @stat:       Where to fill in the attributes
 34  * @stat:               Where to fill in the a << 
 35  *                                                 32  *
 36  * Fill in the basic attributes in the kstat s     33  * Fill in the basic attributes in the kstat structure from data that's to be
 37  * found on the VFS inode structure.  This is      34  * found on the VFS inode structure.  This is the default if no getattr inode
 38  * operation is supplied.                          35  * operation is supplied.
 39  *                                                 36  *
 40  * If the inode has been found through an idma !!  37  * If the inode has been found through an idmapped mount the user namespace of
 41  * the vfsmount must be passed through @idmap. !!  38  * the vfsmount must be passed through @mnt_userns. This function will then
 42  * take care to map the inode according to @id !!  39  * take care to map the inode according to @mnt_userns before filling in the
 43  * uid and gid filds. On non-idmapped mounts o     40  * uid and gid filds. On non-idmapped mounts or if permission checking is to be
 44  * performed on the raw inode simply pass @nop !!  41  * performed on the raw inode simply passs init_user_ns.
 45  */                                                42  */
 46 void generic_fillattr(struct mnt_idmap *idmap, !!  43 void generic_fillattr(struct user_namespace *mnt_userns, struct inode *inode,
 47                       struct inode *inode, str !!  44                       struct kstat *stat)
 48 {                                                  45 {
 49         vfsuid_t vfsuid = i_uid_into_vfsuid(id << 
 50         vfsgid_t vfsgid = i_gid_into_vfsgid(id << 
 51                                                << 
 52         stat->dev = inode->i_sb->s_dev;            46         stat->dev = inode->i_sb->s_dev;
 53         stat->ino = inode->i_ino;                  47         stat->ino = inode->i_ino;
 54         stat->mode = inode->i_mode;                48         stat->mode = inode->i_mode;
 55         stat->nlink = inode->i_nlink;              49         stat->nlink = inode->i_nlink;
 56         stat->uid = vfsuid_into_kuid(vfsuid);  !!  50         stat->uid = i_uid_into_mnt(mnt_userns, inode);
 57         stat->gid = vfsgid_into_kgid(vfsgid);  !!  51         stat->gid = i_gid_into_mnt(mnt_userns, inode);
 58         stat->rdev = inode->i_rdev;                52         stat->rdev = inode->i_rdev;
 59         stat->size = i_size_read(inode);           53         stat->size = i_size_read(inode);
 60         stat->atime = inode_get_atime(inode);  !!  54         stat->atime = inode->i_atime;
 61         stat->mtime = inode_get_mtime(inode);  !!  55         stat->mtime = inode->i_mtime;
 62         stat->ctime = inode_get_ctime(inode);  !!  56         stat->ctime = inode->i_ctime;
 63         stat->blksize = i_blocksize(inode);        57         stat->blksize = i_blocksize(inode);
 64         stat->blocks = inode->i_blocks;            58         stat->blocks = inode->i_blocks;
 65                                                << 
 66         if ((request_mask & STATX_CHANGE_COOKI << 
 67                 stat->result_mask |= STATX_CHA << 
 68                 stat->change_cookie = inode_qu << 
 69         }                                      << 
 70                                                << 
 71 }                                                  59 }
 72 EXPORT_SYMBOL(generic_fillattr);                   60 EXPORT_SYMBOL(generic_fillattr);
 73                                                    61 
 74 /**                                                62 /**
 75  * generic_fill_statx_attr - Fill in the statx     63  * generic_fill_statx_attr - Fill in the statx attributes from the inode flags
 76  * @inode:      Inode to use as the source         64  * @inode:      Inode to use as the source
 77  * @stat:       Where to fill in the attribute     65  * @stat:       Where to fill in the attribute flags
 78  *                                                 66  *
 79  * Fill in the STATX_ATTR_* flags in the kstat     67  * Fill in the STATX_ATTR_* flags in the kstat structure for properties of the
 80  * inode that are published on i_flags and enf     68  * inode that are published on i_flags and enforced by the VFS.
 81  */                                                69  */
 82 void generic_fill_statx_attr(struct inode *ino     70 void generic_fill_statx_attr(struct inode *inode, struct kstat *stat)
 83 {                                                  71 {
 84         if (inode->i_flags & S_IMMUTABLE)          72         if (inode->i_flags & S_IMMUTABLE)
 85                 stat->attributes |= STATX_ATTR     73                 stat->attributes |= STATX_ATTR_IMMUTABLE;
 86         if (inode->i_flags & S_APPEND)             74         if (inode->i_flags & S_APPEND)
 87                 stat->attributes |= STATX_ATTR     75                 stat->attributes |= STATX_ATTR_APPEND;
 88         stat->attributes_mask |= KSTAT_ATTR_VF     76         stat->attributes_mask |= KSTAT_ATTR_VFS_FLAGS;
 89 }                                                  77 }
 90 EXPORT_SYMBOL(generic_fill_statx_attr);            78 EXPORT_SYMBOL(generic_fill_statx_attr);
 91                                                    79 
 92 /**                                                80 /**
 93  * generic_fill_statx_atomic_writes - Fill in  << 
 94  * @stat:       Where to fill in the attribute << 
 95  * @unit_min:   Minimum supported atomic write << 
 96  * @unit_max:   Maximum supported atomic write << 
 97  *                                             << 
 98  * Fill in the STATX{_ATTR}_WRITE_ATOMIC flags << 
 99  * atomic write unit_min and unit_max values.  << 
100  */                                            << 
101 void generic_fill_statx_atomic_writes(struct k << 
102                                       unsigned << 
103                                       unsigned << 
104 {                                              << 
105         /* Confirm that the request type is kn << 
106         stat->result_mask |= STATX_WRITE_ATOMI << 
107                                                << 
108         /* Confirm that the file attribute typ << 
109         stat->attributes_mask |= STATX_ATTR_WR << 
110                                                << 
111         if (unit_min) {                        << 
112                 stat->atomic_write_unit_min =  << 
113                 stat->atomic_write_unit_max =  << 
114                 /* Initially only allow 1x seg << 
115                 stat->atomic_write_segments_ma << 
116                                                << 
117                 /* Confirm atomic writes are a << 
118                 stat->attributes |= STATX_ATTR << 
119         }                                      << 
120 }                                              << 
121 EXPORT_SYMBOL_GPL(generic_fill_statx_atomic_wr << 
122                                                << 
123 /**                                            << 
124  * vfs_getattr_nosec - getattr without securit     81  * vfs_getattr_nosec - getattr without security checks
125  * @path: file to get attributes from              82  * @path: file to get attributes from
126  * @stat: structure to return attributes in        83  * @stat: structure to return attributes in
127  * @request_mask: STATX_xxx flags indicating w     84  * @request_mask: STATX_xxx flags indicating what the caller wants
128  * @query_flags: Query mode (AT_STATX_SYNC_TYP     85  * @query_flags: Query mode (AT_STATX_SYNC_TYPE)
129  *                                                 86  *
130  * Get attributes without calling security_ino     87  * Get attributes without calling security_inode_getattr.
131  *                                                 88  *
132  * Currently the only caller other than vfs_ge     89  * Currently the only caller other than vfs_getattr is internal to the
133  * filehandle lookup code, which uses only the     90  * filehandle lookup code, which uses only the inode number and returns no
134  * attributes to any user.  Any other code pro     91  * attributes to any user.  Any other code probably wants vfs_getattr.
135  */                                                92  */
136 int vfs_getattr_nosec(const struct path *path,     93 int vfs_getattr_nosec(const struct path *path, struct kstat *stat,
137                       u32 request_mask, unsign     94                       u32 request_mask, unsigned int query_flags)
138 {                                                  95 {
139         struct mnt_idmap *idmap;               !!  96         struct user_namespace *mnt_userns;
140         struct inode *inode = d_backing_inode(     97         struct inode *inode = d_backing_inode(path->dentry);
141                                                    98 
142         memset(stat, 0, sizeof(*stat));            99         memset(stat, 0, sizeof(*stat));
143         stat->result_mask |= STATX_BASIC_STATS    100         stat->result_mask |= STATX_BASIC_STATS;
144         query_flags &= AT_STATX_SYNC_TYPE;        101         query_flags &= AT_STATX_SYNC_TYPE;
145                                                   102 
146         /* allow the fs to override these if i    103         /* allow the fs to override these if it really wants to */
147         /* SB_NOATIME means filesystem supplie    104         /* SB_NOATIME means filesystem supplies dummy atime value */
148         if (inode->i_sb->s_flags & SB_NOATIME)    105         if (inode->i_sb->s_flags & SB_NOATIME)
149                 stat->result_mask &= ~STATX_AT    106                 stat->result_mask &= ~STATX_ATIME;
150                                                   107 
151         /*                                        108         /*
152          * Note: If you add another clause to     109          * Note: If you add another clause to set an attribute flag, please
153          * update attributes_mask below.          110          * update attributes_mask below.
154          */                                       111          */
155         if (IS_AUTOMOUNT(inode))                  112         if (IS_AUTOMOUNT(inode))
156                 stat->attributes |= STATX_ATTR    113                 stat->attributes |= STATX_ATTR_AUTOMOUNT;
157                                                   114 
158         if (IS_DAX(inode))                        115         if (IS_DAX(inode))
159                 stat->attributes |= STATX_ATTR    116                 stat->attributes |= STATX_ATTR_DAX;
160                                                   117 
161         stat->attributes_mask |= (STATX_ATTR_A    118         stat->attributes_mask |= (STATX_ATTR_AUTOMOUNT |
162                                   STATX_ATTR_D    119                                   STATX_ATTR_DAX);
163                                                   120 
164         idmap = mnt_idmap(path->mnt);          !! 121         mnt_userns = mnt_user_ns(path->mnt);
165         if (inode->i_op->getattr)                 122         if (inode->i_op->getattr)
166                 return inode->i_op->getattr(id !! 123                 return inode->i_op->getattr(mnt_userns, path, stat,
167                                             re !! 124                                             request_mask, query_flags);
168                                             qu << 
169                                                   125 
170         generic_fillattr(idmap, request_mask,  !! 126         generic_fillattr(mnt_userns, inode, stat);
171         return 0;                                 127         return 0;
172 }                                                 128 }
173 EXPORT_SYMBOL(vfs_getattr_nosec);                 129 EXPORT_SYMBOL(vfs_getattr_nosec);
174                                                   130 
175 /*                                                131 /*
176  * vfs_getattr - Get the enhanced basic attrib    132  * vfs_getattr - Get the enhanced basic attributes of a file
177  * @path: The file of interest                    133  * @path: The file of interest
178  * @stat: Where to return the statistics          134  * @stat: Where to return the statistics
179  * @request_mask: STATX_xxx flags indicating w    135  * @request_mask: STATX_xxx flags indicating what the caller wants
180  * @query_flags: Query mode (AT_STATX_SYNC_TYP    136  * @query_flags: Query mode (AT_STATX_SYNC_TYPE)
181  *                                                137  *
182  * Ask the filesystem for a file's attributes.    138  * Ask the filesystem for a file's attributes.  The caller must indicate in
183  * request_mask and query_flags to indicate wh    139  * request_mask and query_flags to indicate what they want.
184  *                                                140  *
185  * If the file is remote, the filesystem can b    141  * If the file is remote, the filesystem can be forced to update the attributes
186  * from the backing store by passing AT_STATX_    142  * from the backing store by passing AT_STATX_FORCE_SYNC in query_flags or can
187  * suppress the update by passing AT_STATX_DON    143  * suppress the update by passing AT_STATX_DONT_SYNC.
188  *                                                144  *
189  * Bits must have been set in request_mask to     145  * Bits must have been set in request_mask to indicate which attributes the
190  * caller wants retrieving.  Any such attribut    146  * caller wants retrieving.  Any such attribute not requested may be returned
191  * anyway, but the value may be approximate, a    147  * anyway, but the value may be approximate, and, if remote, may not have been
192  * synchronised with the server.                  148  * synchronised with the server.
193  *                                                149  *
194  * 0 will be returned on success, and a -ve er    150  * 0 will be returned on success, and a -ve error code if unsuccessful.
195  */                                               151  */
196 int vfs_getattr(const struct path *path, struc    152 int vfs_getattr(const struct path *path, struct kstat *stat,
197                 u32 request_mask, unsigned int    153                 u32 request_mask, unsigned int query_flags)
198 {                                                 154 {
199         int retval;                               155         int retval;
200                                                   156 
201         if (WARN_ON_ONCE(query_flags & AT_GETA << 
202                 return -EPERM;                 << 
203                                                << 
204         retval = security_inode_getattr(path);    157         retval = security_inode_getattr(path);
205         if (retval)                               158         if (retval)
206                 return retval;                    159                 return retval;
207         return vfs_getattr_nosec(path, stat, r    160         return vfs_getattr_nosec(path, stat, request_mask, query_flags);
208 }                                                 161 }
209 EXPORT_SYMBOL(vfs_getattr);                       162 EXPORT_SYMBOL(vfs_getattr);
210                                                   163 
211 /**                                               164 /**
212  * vfs_fstat - Get the basic attributes by fil    165  * vfs_fstat - Get the basic attributes by file descriptor
213  * @fd: The file descriptor referring to the f    166  * @fd: The file descriptor referring to the file of interest
214  * @stat: The result structure to fill in.        167  * @stat: The result structure to fill in.
215  *                                                168  *
216  * This function is a wrapper around vfs_getat    169  * This function is a wrapper around vfs_getattr().  The main difference is
217  * that it uses a file descriptor to determine    170  * that it uses a file descriptor to determine the file location.
218  *                                                171  *
219  * 0 will be returned on success, and a -ve er    172  * 0 will be returned on success, and a -ve error code if unsuccessful.
220  */                                               173  */
221 int vfs_fstat(int fd, struct kstat *stat)         174 int vfs_fstat(int fd, struct kstat *stat)
222 {                                                 175 {
223         struct fd f;                              176         struct fd f;
224         int error;                                177         int error;
225                                                   178 
226         f = fdget_raw(fd);                        179         f = fdget_raw(fd);
227         if (!f.file)                              180         if (!f.file)
228                 return -EBADF;                    181                 return -EBADF;
229         error = vfs_getattr(&f.file->f_path, s    182         error = vfs_getattr(&f.file->f_path, stat, STATX_BASIC_STATS, 0);
230         fdput(f);                                 183         fdput(f);
231         return error;                             184         return error;
232 }                                                 185 }
233                                                   186 
234 int getname_statx_lookup_flags(int flags)      << 
235 {                                              << 
236         int lookup_flags = 0;                  << 
237                                                << 
238         if (!(flags & AT_SYMLINK_NOFOLLOW))    << 
239                 lookup_flags |= LOOKUP_FOLLOW; << 
240         if (!(flags & AT_NO_AUTOMOUNT))        << 
241                 lookup_flags |= LOOKUP_AUTOMOU << 
242         if (flags & AT_EMPTY_PATH)             << 
243                 lookup_flags |= LOOKUP_EMPTY;  << 
244                                                << 
245         return lookup_flags;                   << 
246 }                                              << 
247                                                << 
248 static int vfs_statx_path(struct path *path, i << 
249                           u32 request_mask)    << 
250 {                                              << 
251         int error = vfs_getattr(path, stat, re << 
252                                                << 
253         if (request_mask & STATX_MNT_ID_UNIQUE << 
254                 stat->mnt_id = real_mount(path << 
255                 stat->result_mask |= STATX_MNT << 
256         } else {                               << 
257                 stat->mnt_id = real_mount(path << 
258                 stat->result_mask |= STATX_MNT << 
259         }                                      << 
260                                                << 
261         if (path_mounted(path))                << 
262                 stat->attributes |= STATX_ATTR << 
263         stat->attributes_mask |= STATX_ATTR_MO << 
264                                                << 
265         /*                                     << 
266          * If this is a block device inode, ov << 
267          * attributes with the block device sp << 
268          * obtained from the bdev backing inod << 
269          */                                    << 
270         if (S_ISBLK(stat->mode))               << 
271                 bdev_statx(path, stat, request << 
272                                                << 
273         return error;                          << 
274 }                                              << 
275                                                << 
276 static int vfs_statx_fd(int fd, int flags, str << 
277                           u32 request_mask)    << 
278 {                                              << 
279         CLASS(fd_raw, f)(fd);                  << 
280         if (!f.file)                           << 
281                 return -EBADF;                 << 
282         return vfs_statx_path(&f.file->f_path, << 
283 }                                              << 
284                                                << 
285 /**                                               187 /**
286  * vfs_statx - Get basic and extra attributes     188  * vfs_statx - Get basic and extra attributes by filename
287  * @dfd: A file descriptor representing the ba    189  * @dfd: A file descriptor representing the base dir for a relative filename
288  * @filename: The name of the file of interest    190  * @filename: The name of the file of interest
289  * @flags: Flags to control the query             191  * @flags: Flags to control the query
290  * @stat: The result structure to fill in.        192  * @stat: The result structure to fill in.
291  * @request_mask: STATX_xxx flags indicating w    193  * @request_mask: STATX_xxx flags indicating what the caller wants
292  *                                                194  *
293  * This function is a wrapper around vfs_getat    195  * This function is a wrapper around vfs_getattr().  The main difference is
294  * that it uses a filename and base directory     196  * that it uses a filename and base directory to determine the file location.
295  * Additionally, the use of AT_SYMLINK_NOFOLLO    197  * Additionally, the use of AT_SYMLINK_NOFOLLOW in flags will prevent a symlink
296  * at the given name from being referenced.       198  * at the given name from being referenced.
297  *                                                199  *
298  * 0 will be returned on success, and a -ve er    200  * 0 will be returned on success, and a -ve error code if unsuccessful.
299  */                                               201  */
300 static int vfs_statx(int dfd, struct filename  !! 202 static int vfs_statx(int dfd, const char __user *filename, int flags,
301               struct kstat *stat, u32 request_    203               struct kstat *stat, u32 request_mask)
302 {                                                 204 {
303         struct path path;                         205         struct path path;
304         unsigned int lookup_flags = getname_st !! 206         unsigned lookup_flags = 0;
305         int error;                                207         int error;
306                                                   208 
307         if (flags & ~(AT_SYMLINK_NOFOLLOW | AT    209         if (flags & ~(AT_SYMLINK_NOFOLLOW | AT_NO_AUTOMOUNT | AT_EMPTY_PATH |
308                       AT_STATX_SYNC_TYPE))        210                       AT_STATX_SYNC_TYPE))
309                 return -EINVAL;                   211                 return -EINVAL;
310                                                   212 
                                                   >> 213         if (!(flags & AT_SYMLINK_NOFOLLOW))
                                                   >> 214                 lookup_flags |= LOOKUP_FOLLOW;
                                                   >> 215         if (!(flags & AT_NO_AUTOMOUNT))
                                                   >> 216                 lookup_flags |= LOOKUP_AUTOMOUNT;
                                                   >> 217         if (flags & AT_EMPTY_PATH)
                                                   >> 218                 lookup_flags |= LOOKUP_EMPTY;
                                                   >> 219 
311 retry:                                            220 retry:
312         error = filename_lookup(dfd, filename, !! 221         error = user_path_at(dfd, filename, lookup_flags, &path);
313         if (error)                                222         if (error)
314                 return error;                  !! 223                 goto out;
315         error = vfs_statx_path(&path, flags, s !! 224 
                                                   >> 225         error = vfs_getattr(&path, stat, request_mask, flags);
                                                   >> 226         stat->mnt_id = real_mount(path.mnt)->mnt_id;
                                                   >> 227         stat->result_mask |= STATX_MNT_ID;
                                                   >> 228         if (path.mnt->mnt_root == path.dentry)
                                                   >> 229                 stat->attributes |= STATX_ATTR_MOUNT_ROOT;
                                                   >> 230         stat->attributes_mask |= STATX_ATTR_MOUNT_ROOT;
316         path_put(&path);                          231         path_put(&path);
317         if (retry_estale(error, lookup_flags))    232         if (retry_estale(error, lookup_flags)) {
318                 lookup_flags |= LOOKUP_REVAL;     233                 lookup_flags |= LOOKUP_REVAL;
319                 goto retry;                       234                 goto retry;
320         }                                         235         }
                                                   >> 236 out:
321         return error;                             237         return error;
322 }                                                 238 }
323                                                   239 
324 int vfs_fstatat(int dfd, const char __user *fi    240 int vfs_fstatat(int dfd, const char __user *filename,
325                               struct kstat *st    241                               struct kstat *stat, int flags)
326 {                                                 242 {
327         int ret;                               !! 243         return vfs_statx(dfd, filename, flags | AT_NO_AUTOMOUNT,
328         int statx_flags = flags | AT_NO_AUTOMO !! 244                          stat, STATX_BASIC_STATS);
329         struct filename *name;                 << 
330                                                << 
331         /*                                     << 
332          * Work around glibc turning fstat() i << 
333          *                                     << 
334          * If AT_EMPTY_PATH is set, we expect  << 
335          * empty path, and avoid doing all the << 
336          */                                    << 
337         if (flags == AT_EMPTY_PATH && vfs_empt << 
338                 return vfs_fstat(dfd, stat);   << 
339                                                << 
340         name = getname_flags(filename, getname << 
341         ret = vfs_statx(dfd, name, statx_flags << 
342         putname(name);                         << 
343                                                << 
344         return ret;                            << 
345 }                                                 245 }
346                                                   246 
347 #ifdef __ARCH_WANT_OLD_STAT                       247 #ifdef __ARCH_WANT_OLD_STAT
348                                                   248 
349 /*                                                249 /*
350  * For backward compatibility?  Maybe this sho    250  * For backward compatibility?  Maybe this should be moved
351  * into arch/i386 instead?                        251  * into arch/i386 instead?
352  */                                               252  */
353 static int cp_old_stat(struct kstat *stat, str    253 static int cp_old_stat(struct kstat *stat, struct __old_kernel_stat __user * statbuf)
354 {                                                 254 {
355         static int warncount = 5;                 255         static int warncount = 5;
356         struct __old_kernel_stat tmp;             256         struct __old_kernel_stat tmp;
357                                                   257 
358         if (warncount > 0) {                      258         if (warncount > 0) {
359                 warncount--;                      259                 warncount--;
360                 printk(KERN_WARNING "VFS: Warn    260                 printk(KERN_WARNING "VFS: Warning: %s using old stat() call. Recompile your binary.\n",
361                         current->comm);           261                         current->comm);
362         } else if (warncount < 0) {               262         } else if (warncount < 0) {
363                 /* it's laughable, but... */      263                 /* it's laughable, but... */
364                 warncount = 0;                    264                 warncount = 0;
365         }                                         265         }
366                                                   266 
367         memset(&tmp, 0, sizeof(struct __old_ke    267         memset(&tmp, 0, sizeof(struct __old_kernel_stat));
368         tmp.st_dev = old_encode_dev(stat->dev)    268         tmp.st_dev = old_encode_dev(stat->dev);
369         tmp.st_ino = stat->ino;                   269         tmp.st_ino = stat->ino;
370         if (sizeof(tmp.st_ino) < sizeof(stat->    270         if (sizeof(tmp.st_ino) < sizeof(stat->ino) && tmp.st_ino != stat->ino)
371                 return -EOVERFLOW;                271                 return -EOVERFLOW;
372         tmp.st_mode = stat->mode;                 272         tmp.st_mode = stat->mode;
373         tmp.st_nlink = stat->nlink;               273         tmp.st_nlink = stat->nlink;
374         if (tmp.st_nlink != stat->nlink)          274         if (tmp.st_nlink != stat->nlink)
375                 return -EOVERFLOW;                275                 return -EOVERFLOW;
376         SET_UID(tmp.st_uid, from_kuid_munged(c    276         SET_UID(tmp.st_uid, from_kuid_munged(current_user_ns(), stat->uid));
377         SET_GID(tmp.st_gid, from_kgid_munged(c    277         SET_GID(tmp.st_gid, from_kgid_munged(current_user_ns(), stat->gid));
378         tmp.st_rdev = old_encode_dev(stat->rde    278         tmp.st_rdev = old_encode_dev(stat->rdev);
379 #if BITS_PER_LONG == 32                           279 #if BITS_PER_LONG == 32
380         if (stat->size > MAX_NON_LFS)             280         if (stat->size > MAX_NON_LFS)
381                 return -EOVERFLOW;                281                 return -EOVERFLOW;
382 #endif                                            282 #endif
383         tmp.st_size = stat->size;                 283         tmp.st_size = stat->size;
384         tmp.st_atime = stat->atime.tv_sec;        284         tmp.st_atime = stat->atime.tv_sec;
385         tmp.st_mtime = stat->mtime.tv_sec;        285         tmp.st_mtime = stat->mtime.tv_sec;
386         tmp.st_ctime = stat->ctime.tv_sec;        286         tmp.st_ctime = stat->ctime.tv_sec;
387         return copy_to_user(statbuf,&tmp,sizeo    287         return copy_to_user(statbuf,&tmp,sizeof(tmp)) ? -EFAULT : 0;
388 }                                                 288 }
389                                                   289 
390 SYSCALL_DEFINE2(stat, const char __user *, fil    290 SYSCALL_DEFINE2(stat, const char __user *, filename,
391                 struct __old_kernel_stat __use    291                 struct __old_kernel_stat __user *, statbuf)
392 {                                                 292 {
393         struct kstat stat;                        293         struct kstat stat;
394         int error;                                294         int error;
395                                                   295 
396         error = vfs_stat(filename, &stat);        296         error = vfs_stat(filename, &stat);
397         if (error)                                297         if (error)
398                 return error;                     298                 return error;
399                                                   299 
400         return cp_old_stat(&stat, statbuf);       300         return cp_old_stat(&stat, statbuf);
401 }                                                 301 }
402                                                   302 
403 SYSCALL_DEFINE2(lstat, const char __user *, fi    303 SYSCALL_DEFINE2(lstat, const char __user *, filename,
404                 struct __old_kernel_stat __use    304                 struct __old_kernel_stat __user *, statbuf)
405 {                                                 305 {
406         struct kstat stat;                        306         struct kstat stat;
407         int error;                                307         int error;
408                                                   308 
409         error = vfs_lstat(filename, &stat);       309         error = vfs_lstat(filename, &stat);
410         if (error)                                310         if (error)
411                 return error;                     311                 return error;
412                                                   312 
413         return cp_old_stat(&stat, statbuf);       313         return cp_old_stat(&stat, statbuf);
414 }                                                 314 }
415                                                   315 
416 SYSCALL_DEFINE2(fstat, unsigned int, fd, struc    316 SYSCALL_DEFINE2(fstat, unsigned int, fd, struct __old_kernel_stat __user *, statbuf)
417 {                                                 317 {
418         struct kstat stat;                        318         struct kstat stat;
419         int error = vfs_fstat(fd, &stat);         319         int error = vfs_fstat(fd, &stat);
420                                                   320 
421         if (!error)                               321         if (!error)
422                 error = cp_old_stat(&stat, sta    322                 error = cp_old_stat(&stat, statbuf);
423                                                   323 
424         return error;                             324         return error;
425 }                                                 325 }
426                                                   326 
427 #endif /* __ARCH_WANT_OLD_STAT */                 327 #endif /* __ARCH_WANT_OLD_STAT */
428                                                   328 
429 #ifdef __ARCH_WANT_NEW_STAT                       329 #ifdef __ARCH_WANT_NEW_STAT
430                                                   330 
                                                   >> 331 #if BITS_PER_LONG == 32
                                                   >> 332 #  define choose_32_64(a,b) a
                                                   >> 333 #else
                                                   >> 334 #  define choose_32_64(a,b) b
                                                   >> 335 #endif
                                                   >> 336 
431 #ifndef INIT_STRUCT_STAT_PADDING                  337 #ifndef INIT_STRUCT_STAT_PADDING
432 #  define INIT_STRUCT_STAT_PADDING(st) memset(    338 #  define INIT_STRUCT_STAT_PADDING(st) memset(&st, 0, sizeof(st))
433 #endif                                            339 #endif
434                                                   340 
435 static int cp_new_stat(struct kstat *stat, str    341 static int cp_new_stat(struct kstat *stat, struct stat __user *statbuf)
436 {                                                 342 {
437         struct stat tmp;                          343         struct stat tmp;
438                                                   344 
439         if (sizeof(tmp.st_dev) < 4 && !old_val    345         if (sizeof(tmp.st_dev) < 4 && !old_valid_dev(stat->dev))
440                 return -EOVERFLOW;                346                 return -EOVERFLOW;
441         if (sizeof(tmp.st_rdev) < 4 && !old_va    347         if (sizeof(tmp.st_rdev) < 4 && !old_valid_dev(stat->rdev))
442                 return -EOVERFLOW;                348                 return -EOVERFLOW;
443 #if BITS_PER_LONG == 32                           349 #if BITS_PER_LONG == 32
444         if (stat->size > MAX_NON_LFS)             350         if (stat->size > MAX_NON_LFS)
445                 return -EOVERFLOW;                351                 return -EOVERFLOW;
446 #endif                                            352 #endif
447                                                   353 
448         INIT_STRUCT_STAT_PADDING(tmp);            354         INIT_STRUCT_STAT_PADDING(tmp);
449         tmp.st_dev = new_encode_dev(stat->dev)    355         tmp.st_dev = new_encode_dev(stat->dev);
450         tmp.st_ino = stat->ino;                   356         tmp.st_ino = stat->ino;
451         if (sizeof(tmp.st_ino) < sizeof(stat->    357         if (sizeof(tmp.st_ino) < sizeof(stat->ino) && tmp.st_ino != stat->ino)
452                 return -EOVERFLOW;                358                 return -EOVERFLOW;
453         tmp.st_mode = stat->mode;                 359         tmp.st_mode = stat->mode;
454         tmp.st_nlink = stat->nlink;               360         tmp.st_nlink = stat->nlink;
455         if (tmp.st_nlink != stat->nlink)          361         if (tmp.st_nlink != stat->nlink)
456                 return -EOVERFLOW;                362                 return -EOVERFLOW;
457         SET_UID(tmp.st_uid, from_kuid_munged(c    363         SET_UID(tmp.st_uid, from_kuid_munged(current_user_ns(), stat->uid));
458         SET_GID(tmp.st_gid, from_kgid_munged(c    364         SET_GID(tmp.st_gid, from_kgid_munged(current_user_ns(), stat->gid));
459         tmp.st_rdev = new_encode_dev(stat->rde    365         tmp.st_rdev = new_encode_dev(stat->rdev);
460         tmp.st_size = stat->size;                 366         tmp.st_size = stat->size;
461         tmp.st_atime = stat->atime.tv_sec;        367         tmp.st_atime = stat->atime.tv_sec;
462         tmp.st_mtime = stat->mtime.tv_sec;        368         tmp.st_mtime = stat->mtime.tv_sec;
463         tmp.st_ctime = stat->ctime.tv_sec;        369         tmp.st_ctime = stat->ctime.tv_sec;
464 #ifdef STAT_HAVE_NSEC                             370 #ifdef STAT_HAVE_NSEC
465         tmp.st_atime_nsec = stat->atime.tv_nse    371         tmp.st_atime_nsec = stat->atime.tv_nsec;
466         tmp.st_mtime_nsec = stat->mtime.tv_nse    372         tmp.st_mtime_nsec = stat->mtime.tv_nsec;
467         tmp.st_ctime_nsec = stat->ctime.tv_nse    373         tmp.st_ctime_nsec = stat->ctime.tv_nsec;
468 #endif                                            374 #endif
469         tmp.st_blocks = stat->blocks;             375         tmp.st_blocks = stat->blocks;
470         tmp.st_blksize = stat->blksize;           376         tmp.st_blksize = stat->blksize;
471         return copy_to_user(statbuf,&tmp,sizeo    377         return copy_to_user(statbuf,&tmp,sizeof(tmp)) ? -EFAULT : 0;
472 }                                                 378 }
473                                                   379 
474 SYSCALL_DEFINE2(newstat, const char __user *,     380 SYSCALL_DEFINE2(newstat, const char __user *, filename,
475                 struct stat __user *, statbuf)    381                 struct stat __user *, statbuf)
476 {                                                 382 {
477         struct kstat stat;                        383         struct kstat stat;
478         int error = vfs_stat(filename, &stat);    384         int error = vfs_stat(filename, &stat);
479                                                   385 
480         if (error)                                386         if (error)
481                 return error;                     387                 return error;
482         return cp_new_stat(&stat, statbuf);       388         return cp_new_stat(&stat, statbuf);
483 }                                                 389 }
484                                                   390 
485 SYSCALL_DEFINE2(newlstat, const char __user *,    391 SYSCALL_DEFINE2(newlstat, const char __user *, filename,
486                 struct stat __user *, statbuf)    392                 struct stat __user *, statbuf)
487 {                                                 393 {
488         struct kstat stat;                        394         struct kstat stat;
489         int error;                                395         int error;
490                                                   396 
491         error = vfs_lstat(filename, &stat);       397         error = vfs_lstat(filename, &stat);
492         if (error)                                398         if (error)
493                 return error;                     399                 return error;
494                                                   400 
495         return cp_new_stat(&stat, statbuf);       401         return cp_new_stat(&stat, statbuf);
496 }                                                 402 }
497                                                   403 
498 #if !defined(__ARCH_WANT_STAT64) || defined(__    404 #if !defined(__ARCH_WANT_STAT64) || defined(__ARCH_WANT_SYS_NEWFSTATAT)
499 SYSCALL_DEFINE4(newfstatat, int, dfd, const ch    405 SYSCALL_DEFINE4(newfstatat, int, dfd, const char __user *, filename,
500                 struct stat __user *, statbuf,    406                 struct stat __user *, statbuf, int, flag)
501 {                                                 407 {
502         struct kstat stat;                        408         struct kstat stat;
503         int error;                                409         int error;
504                                                   410 
505         error = vfs_fstatat(dfd, filename, &st    411         error = vfs_fstatat(dfd, filename, &stat, flag);
506         if (error)                                412         if (error)
507                 return error;                     413                 return error;
508         return cp_new_stat(&stat, statbuf);       414         return cp_new_stat(&stat, statbuf);
509 }                                                 415 }
510 #endif                                            416 #endif
511                                                   417 
512 SYSCALL_DEFINE2(newfstat, unsigned int, fd, st    418 SYSCALL_DEFINE2(newfstat, unsigned int, fd, struct stat __user *, statbuf)
513 {                                                 419 {
514         struct kstat stat;                        420         struct kstat stat;
515         int error = vfs_fstat(fd, &stat);         421         int error = vfs_fstat(fd, &stat);
516                                                   422 
517         if (!error)                               423         if (!error)
518                 error = cp_new_stat(&stat, sta    424                 error = cp_new_stat(&stat, statbuf);
519                                                   425 
520         return error;                             426         return error;
521 }                                                 427 }
522 #endif                                            428 #endif
523                                                   429 
524 static int do_readlinkat(int dfd, const char _    430 static int do_readlinkat(int dfd, const char __user *pathname,
525                          char __user *buf, int    431                          char __user *buf, int bufsiz)
526 {                                                 432 {
527         struct path path;                         433         struct path path;
528         struct filename *name;                 << 
529         int error;                                434         int error;
                                                   >> 435         int empty = 0;
530         unsigned int lookup_flags = LOOKUP_EMP    436         unsigned int lookup_flags = LOOKUP_EMPTY;
531                                                   437 
532         if (bufsiz <= 0)                          438         if (bufsiz <= 0)
533                 return -EINVAL;                   439                 return -EINVAL;
534                                                   440 
535 retry:                                            441 retry:
536         name = getname_flags(pathname, lookup_ !! 442         error = user_path_at_empty(dfd, pathname, lookup_flags, &path, &empty);
537         error = filename_lookup(dfd, name, loo !! 443         if (!error) {
538         if (unlikely(error)) {                 !! 444                 struct inode *inode = d_backing_inode(path.dentry);
539                 putname(name);                 !! 445 
540                 return error;                  !! 446                 error = empty ? -ENOENT : -EINVAL;
541         }                                      !! 447                 /*
542                                                !! 448                  * AFS mountpoints allow readlink(2) but are not symlinks
543         /*                                     !! 449                  */
544          * AFS mountpoints allow readlink(2) b !! 450                 if (d_is_symlink(path.dentry) || inode->i_op->readlink) {
545          */                                    !! 451                         error = security_inode_readlink(path.dentry);
546         if (d_is_symlink(path.dentry) ||       !! 452                         if (!error) {
547             d_backing_inode(path.dentry)->i_op !! 453                                 touch_atime(&path);
548                 error = security_inode_readlin !! 454                                 error = vfs_readlink(path.dentry, buf, bufsiz);
549                 if (!error) {                  !! 455                         }
550                         touch_atime(&path);    !! 456                 }
551                         error = vfs_readlink(p !! 457                 path_put(&path);
                                                   >> 458                 if (retry_estale(error, lookup_flags)) {
                                                   >> 459                         lookup_flags |= LOOKUP_REVAL;
                                                   >> 460                         goto retry;
552                 }                                 461                 }
553         } else {                               << 
554                 error = (name->name[0] == '\0' << 
555         }                                      << 
556         path_put(&path);                       << 
557         putname(name);                         << 
558         if (retry_estale(error, lookup_flags)) << 
559                 lookup_flags |= LOOKUP_REVAL;  << 
560                 goto retry;                    << 
561         }                                         462         }
562         return error;                             463         return error;
563 }                                                 464 }
564                                                   465 
565 SYSCALL_DEFINE4(readlinkat, int, dfd, const ch    466 SYSCALL_DEFINE4(readlinkat, int, dfd, const char __user *, pathname,
566                 char __user *, buf, int, bufsi    467                 char __user *, buf, int, bufsiz)
567 {                                                 468 {
568         return do_readlinkat(dfd, pathname, bu    469         return do_readlinkat(dfd, pathname, buf, bufsiz);
569 }                                                 470 }
570                                                   471 
571 SYSCALL_DEFINE3(readlink, const char __user *,    472 SYSCALL_DEFINE3(readlink, const char __user *, path, char __user *, buf,
572                 int, bufsiz)                      473                 int, bufsiz)
573 {                                                 474 {
574         return do_readlinkat(AT_FDCWD, path, b    475         return do_readlinkat(AT_FDCWD, path, buf, bufsiz);
575 }                                                 476 }
576                                                   477 
577                                                   478 
578 /* ---------- LFS-64 ----------- */               479 /* ---------- LFS-64 ----------- */
579 #if defined(__ARCH_WANT_STAT64) || defined(__A    480 #if defined(__ARCH_WANT_STAT64) || defined(__ARCH_WANT_COMPAT_STAT64)
580                                                   481 
581 #ifndef INIT_STRUCT_STAT64_PADDING                482 #ifndef INIT_STRUCT_STAT64_PADDING
582 #  define INIT_STRUCT_STAT64_PADDING(st) memse    483 #  define INIT_STRUCT_STAT64_PADDING(st) memset(&st, 0, sizeof(st))
583 #endif                                            484 #endif
584                                                   485 
585 static long cp_new_stat64(struct kstat *stat,     486 static long cp_new_stat64(struct kstat *stat, struct stat64 __user *statbuf)
586 {                                                 487 {
587         struct stat64 tmp;                        488         struct stat64 tmp;
588                                                   489 
589         INIT_STRUCT_STAT64_PADDING(tmp);          490         INIT_STRUCT_STAT64_PADDING(tmp);
590 #ifdef CONFIG_MIPS                                491 #ifdef CONFIG_MIPS
591         /* mips has weird padding, so we don't    492         /* mips has weird padding, so we don't get 64 bits there */
592         tmp.st_dev = new_encode_dev(stat->dev)    493         tmp.st_dev = new_encode_dev(stat->dev);
593         tmp.st_rdev = new_encode_dev(stat->rde    494         tmp.st_rdev = new_encode_dev(stat->rdev);
594 #else                                             495 #else
595         tmp.st_dev = huge_encode_dev(stat->dev    496         tmp.st_dev = huge_encode_dev(stat->dev);
596         tmp.st_rdev = huge_encode_dev(stat->rd    497         tmp.st_rdev = huge_encode_dev(stat->rdev);
597 #endif                                            498 #endif
598         tmp.st_ino = stat->ino;                   499         tmp.st_ino = stat->ino;
599         if (sizeof(tmp.st_ino) < sizeof(stat->    500         if (sizeof(tmp.st_ino) < sizeof(stat->ino) && tmp.st_ino != stat->ino)
600                 return -EOVERFLOW;                501                 return -EOVERFLOW;
601 #ifdef STAT64_HAS_BROKEN_ST_INO                   502 #ifdef STAT64_HAS_BROKEN_ST_INO
602         tmp.__st_ino = stat->ino;                 503         tmp.__st_ino = stat->ino;
603 #endif                                            504 #endif
604         tmp.st_mode = stat->mode;                 505         tmp.st_mode = stat->mode;
605         tmp.st_nlink = stat->nlink;               506         tmp.st_nlink = stat->nlink;
606         tmp.st_uid = from_kuid_munged(current_    507         tmp.st_uid = from_kuid_munged(current_user_ns(), stat->uid);
607         tmp.st_gid = from_kgid_munged(current_    508         tmp.st_gid = from_kgid_munged(current_user_ns(), stat->gid);
608         tmp.st_atime = stat->atime.tv_sec;        509         tmp.st_atime = stat->atime.tv_sec;
609         tmp.st_atime_nsec = stat->atime.tv_nse    510         tmp.st_atime_nsec = stat->atime.tv_nsec;
610         tmp.st_mtime = stat->mtime.tv_sec;        511         tmp.st_mtime = stat->mtime.tv_sec;
611         tmp.st_mtime_nsec = stat->mtime.tv_nse    512         tmp.st_mtime_nsec = stat->mtime.tv_nsec;
612         tmp.st_ctime = stat->ctime.tv_sec;        513         tmp.st_ctime = stat->ctime.tv_sec;
613         tmp.st_ctime_nsec = stat->ctime.tv_nse    514         tmp.st_ctime_nsec = stat->ctime.tv_nsec;
614         tmp.st_size = stat->size;                 515         tmp.st_size = stat->size;
615         tmp.st_blocks = stat->blocks;             516         tmp.st_blocks = stat->blocks;
616         tmp.st_blksize = stat->blksize;           517         tmp.st_blksize = stat->blksize;
617         return copy_to_user(statbuf,&tmp,sizeo    518         return copy_to_user(statbuf,&tmp,sizeof(tmp)) ? -EFAULT : 0;
618 }                                                 519 }
619                                                   520 
620 SYSCALL_DEFINE2(stat64, const char __user *, f    521 SYSCALL_DEFINE2(stat64, const char __user *, filename,
621                 struct stat64 __user *, statbu    522                 struct stat64 __user *, statbuf)
622 {                                                 523 {
623         struct kstat stat;                        524         struct kstat stat;
624         int error = vfs_stat(filename, &stat);    525         int error = vfs_stat(filename, &stat);
625                                                   526 
626         if (!error)                               527         if (!error)
627                 error = cp_new_stat64(&stat, s    528                 error = cp_new_stat64(&stat, statbuf);
628                                                   529 
629         return error;                             530         return error;
630 }                                                 531 }
631                                                   532 
632 SYSCALL_DEFINE2(lstat64, const char __user *,     533 SYSCALL_DEFINE2(lstat64, const char __user *, filename,
633                 struct stat64 __user *, statbu    534                 struct stat64 __user *, statbuf)
634 {                                                 535 {
635         struct kstat stat;                        536         struct kstat stat;
636         int error = vfs_lstat(filename, &stat)    537         int error = vfs_lstat(filename, &stat);
637                                                   538 
638         if (!error)                               539         if (!error)
639                 error = cp_new_stat64(&stat, s    540                 error = cp_new_stat64(&stat, statbuf);
640                                                   541 
641         return error;                             542         return error;
642 }                                                 543 }
643                                                   544 
644 SYSCALL_DEFINE2(fstat64, unsigned long, fd, st    545 SYSCALL_DEFINE2(fstat64, unsigned long, fd, struct stat64 __user *, statbuf)
645 {                                                 546 {
646         struct kstat stat;                        547         struct kstat stat;
647         int error = vfs_fstat(fd, &stat);         548         int error = vfs_fstat(fd, &stat);
648                                                   549 
649         if (!error)                               550         if (!error)
650                 error = cp_new_stat64(&stat, s    551                 error = cp_new_stat64(&stat, statbuf);
651                                                   552 
652         return error;                             553         return error;
653 }                                                 554 }
654                                                   555 
655 SYSCALL_DEFINE4(fstatat64, int, dfd, const cha    556 SYSCALL_DEFINE4(fstatat64, int, dfd, const char __user *, filename,
656                 struct stat64 __user *, statbu    557                 struct stat64 __user *, statbuf, int, flag)
657 {                                                 558 {
658         struct kstat stat;                        559         struct kstat stat;
659         int error;                                560         int error;
660                                                   561 
661         error = vfs_fstatat(dfd, filename, &st    562         error = vfs_fstatat(dfd, filename, &stat, flag);
662         if (error)                                563         if (error)
663                 return error;                     564                 return error;
664         return cp_new_stat64(&stat, statbuf);     565         return cp_new_stat64(&stat, statbuf);
665 }                                                 566 }
666 #endif /* __ARCH_WANT_STAT64 || __ARCH_WANT_CO    567 #endif /* __ARCH_WANT_STAT64 || __ARCH_WANT_COMPAT_STAT64 */
667                                                   568 
668 static noinline_for_stack int                     569 static noinline_for_stack int
669 cp_statx(const struct kstat *stat, struct stat    570 cp_statx(const struct kstat *stat, struct statx __user *buffer)
670 {                                                 571 {
671         struct statx tmp;                         572         struct statx tmp;
672                                                   573 
673         memset(&tmp, 0, sizeof(tmp));             574         memset(&tmp, 0, sizeof(tmp));
674                                                   575 
675         /* STATX_CHANGE_COOKIE is kernel-only  !! 576         tmp.stx_mask = stat->result_mask;
676         tmp.stx_mask = stat->result_mask & ~ST << 
677         tmp.stx_blksize = stat->blksize;          577         tmp.stx_blksize = stat->blksize;
678         /* STATX_ATTR_CHANGE_MONOTONIC is kern !! 578         tmp.stx_attributes = stat->attributes;
679         tmp.stx_attributes = stat->attributes  << 
680         tmp.stx_nlink = stat->nlink;              579         tmp.stx_nlink = stat->nlink;
681         tmp.stx_uid = from_kuid_munged(current    580         tmp.stx_uid = from_kuid_munged(current_user_ns(), stat->uid);
682         tmp.stx_gid = from_kgid_munged(current    581         tmp.stx_gid = from_kgid_munged(current_user_ns(), stat->gid);
683         tmp.stx_mode = stat->mode;                582         tmp.stx_mode = stat->mode;
684         tmp.stx_ino = stat->ino;                  583         tmp.stx_ino = stat->ino;
685         tmp.stx_size = stat->size;                584         tmp.stx_size = stat->size;
686         tmp.stx_blocks = stat->blocks;            585         tmp.stx_blocks = stat->blocks;
687         tmp.stx_attributes_mask = stat->attrib    586         tmp.stx_attributes_mask = stat->attributes_mask;
688         tmp.stx_atime.tv_sec = stat->atime.tv_    587         tmp.stx_atime.tv_sec = stat->atime.tv_sec;
689         tmp.stx_atime.tv_nsec = stat->atime.tv    588         tmp.stx_atime.tv_nsec = stat->atime.tv_nsec;
690         tmp.stx_btime.tv_sec = stat->btime.tv_    589         tmp.stx_btime.tv_sec = stat->btime.tv_sec;
691         tmp.stx_btime.tv_nsec = stat->btime.tv    590         tmp.stx_btime.tv_nsec = stat->btime.tv_nsec;
692         tmp.stx_ctime.tv_sec = stat->ctime.tv_    591         tmp.stx_ctime.tv_sec = stat->ctime.tv_sec;
693         tmp.stx_ctime.tv_nsec = stat->ctime.tv    592         tmp.stx_ctime.tv_nsec = stat->ctime.tv_nsec;
694         tmp.stx_mtime.tv_sec = stat->mtime.tv_    593         tmp.stx_mtime.tv_sec = stat->mtime.tv_sec;
695         tmp.stx_mtime.tv_nsec = stat->mtime.tv    594         tmp.stx_mtime.tv_nsec = stat->mtime.tv_nsec;
696         tmp.stx_rdev_major = MAJOR(stat->rdev)    595         tmp.stx_rdev_major = MAJOR(stat->rdev);
697         tmp.stx_rdev_minor = MINOR(stat->rdev)    596         tmp.stx_rdev_minor = MINOR(stat->rdev);
698         tmp.stx_dev_major = MAJOR(stat->dev);     597         tmp.stx_dev_major = MAJOR(stat->dev);
699         tmp.stx_dev_minor = MINOR(stat->dev);     598         tmp.stx_dev_minor = MINOR(stat->dev);
700         tmp.stx_mnt_id = stat->mnt_id;            599         tmp.stx_mnt_id = stat->mnt_id;
701         tmp.stx_dio_mem_align = stat->dio_mem_ << 
702         tmp.stx_dio_offset_align = stat->dio_o << 
703         tmp.stx_subvol = stat->subvol;         << 
704         tmp.stx_atomic_write_unit_min = stat-> << 
705         tmp.stx_atomic_write_unit_max = stat-> << 
706         tmp.stx_atomic_write_segments_max = st << 
707                                                   600 
708         return copy_to_user(buffer, &tmp, size    601         return copy_to_user(buffer, &tmp, sizeof(tmp)) ? -EFAULT : 0;
709 }                                                 602 }
710                                                   603 
711 int do_statx(int dfd, struct filename *filenam !! 604 int do_statx(int dfd, const char __user *filename, unsigned flags,
712              unsigned int mask, struct statx _    605              unsigned int mask, struct statx __user *buffer)
713 {                                                 606 {
714         struct kstat stat;                        607         struct kstat stat;
715         int error;                                608         int error;
716                                                   609 
717         if (mask & STATX__RESERVED)               610         if (mask & STATX__RESERVED)
718                 return -EINVAL;                   611                 return -EINVAL;
719         if ((flags & AT_STATX_SYNC_TYPE) == AT    612         if ((flags & AT_STATX_SYNC_TYPE) == AT_STATX_SYNC_TYPE)
720                 return -EINVAL;                   613                 return -EINVAL;
721                                                   614 
722         /*                                     << 
723          * STATX_CHANGE_COOKIE is kernel-only  << 
724          * from userland.                      << 
725          */                                    << 
726         mask &= ~STATX_CHANGE_COOKIE;          << 
727                                                << 
728         error = vfs_statx(dfd, filename, flags    615         error = vfs_statx(dfd, filename, flags, &stat, mask);
729         if (error)                                616         if (error)
730                 return error;                     617                 return error;
731                                                   618 
732         return cp_statx(&stat, buffer);           619         return cp_statx(&stat, buffer);
733 }                                                 620 }
734                                                   621 
735 int do_statx_fd(int fd, unsigned int flags, un << 
736              struct statx __user *buffer)      << 
737 {                                              << 
738         struct kstat stat;                     << 
739         int error;                             << 
740                                                << 
741         if (mask & STATX__RESERVED)            << 
742                 return -EINVAL;                << 
743         if ((flags & AT_STATX_SYNC_TYPE) == AT << 
744                 return -EINVAL;                << 
745                                                << 
746         /*                                     << 
747          * STATX_CHANGE_COOKIE is kernel-only  << 
748          * from userland.                      << 
749          */                                    << 
750         mask &= ~STATX_CHANGE_COOKIE;          << 
751                                                << 
752         error = vfs_statx_fd(fd, flags, &stat, << 
753         if (error)                             << 
754                 return error;                  << 
755                                                << 
756         return cp_statx(&stat, buffer);        << 
757 }                                              << 
758                                                << 
759 /**                                               622 /**
760  * sys_statx - System call to get enhanced sta    623  * sys_statx - System call to get enhanced stats
761  * @dfd: Base directory to pathwalk from *or*     624  * @dfd: Base directory to pathwalk from *or* fd to stat.
762  * @filename: File to stat or either NULL or " !! 625  * @filename: File to stat or "" with AT_EMPTY_PATH
763  * @flags: AT_* flags to control pathwalk.        626  * @flags: AT_* flags to control pathwalk.
764  * @mask: Parts of statx struct actually requi    627  * @mask: Parts of statx struct actually required.
765  * @buffer: Result buffer.                        628  * @buffer: Result buffer.
766  *                                                629  *
767  * Note that fstat() can be emulated by settin    630  * Note that fstat() can be emulated by setting dfd to the fd of interest,
768  * supplying "" (or preferably NULL) as the fi !! 631  * supplying "" as the filename and setting AT_EMPTY_PATH in the flags.
769  * in the flags.                               << 
770  */                                               632  */
771 SYSCALL_DEFINE5(statx,                            633 SYSCALL_DEFINE5(statx,
772                 int, dfd, const char __user *,    634                 int, dfd, const char __user *, filename, unsigned, flags,
773                 unsigned int, mask,               635                 unsigned int, mask,
774                 struct statx __user *, buffer)    636                 struct statx __user *, buffer)
775 {                                                 637 {
776         int ret;                               !! 638         return do_statx(dfd, filename, flags, mask, buffer);
777         unsigned lflags;                       << 
778         struct filename *name;                 << 
779                                                << 
780         /*                                     << 
781          * Short-circuit handling of NULL and  << 
782          *                                     << 
783          * For a NULL path we require and acce << 
784          * (possibly |'d with AT_STATX flags). << 
785          *                                     << 
786          * However, glibc on 32-bit architectu << 
787          * with the "" pathname and AT_NO_AUTO << 
788          * Supporting this results in the ugli << 
789          */                                    << 
790         lflags = flags & ~(AT_NO_AUTOMOUNT | A << 
791         if (lflags == AT_EMPTY_PATH && vfs_emp << 
792                 return do_statx_fd(dfd, flags  << 
793                                                << 
794         name = getname_flags(filename, getname << 
795         ret = do_statx(dfd, name, flags, mask, << 
796         putname(name);                         << 
797                                                << 
798         return ret;                            << 
799 }                                                 639 }
800                                                   640 
801 #if defined(CONFIG_COMPAT) && defined(__ARCH_W !! 641 #ifdef CONFIG_COMPAT
802 static int cp_compat_stat(struct kstat *stat,     642 static int cp_compat_stat(struct kstat *stat, struct compat_stat __user *ubuf)
803 {                                                 643 {
804         struct compat_stat tmp;                   644         struct compat_stat tmp;
805                                                   645 
806         if (sizeof(tmp.st_dev) < 4 && !old_val    646         if (sizeof(tmp.st_dev) < 4 && !old_valid_dev(stat->dev))
807                 return -EOVERFLOW;                647                 return -EOVERFLOW;
808         if (sizeof(tmp.st_rdev) < 4 && !old_va    648         if (sizeof(tmp.st_rdev) < 4 && !old_valid_dev(stat->rdev))
809                 return -EOVERFLOW;                649                 return -EOVERFLOW;
810                                                   650 
811         memset(&tmp, 0, sizeof(tmp));             651         memset(&tmp, 0, sizeof(tmp));
812         tmp.st_dev = new_encode_dev(stat->dev)    652         tmp.st_dev = new_encode_dev(stat->dev);
813         tmp.st_ino = stat->ino;                   653         tmp.st_ino = stat->ino;
814         if (sizeof(tmp.st_ino) < sizeof(stat->    654         if (sizeof(tmp.st_ino) < sizeof(stat->ino) && tmp.st_ino != stat->ino)
815                 return -EOVERFLOW;                655                 return -EOVERFLOW;
816         tmp.st_mode = stat->mode;                 656         tmp.st_mode = stat->mode;
817         tmp.st_nlink = stat->nlink;               657         tmp.st_nlink = stat->nlink;
818         if (tmp.st_nlink != stat->nlink)          658         if (tmp.st_nlink != stat->nlink)
819                 return -EOVERFLOW;                659                 return -EOVERFLOW;
820         SET_UID(tmp.st_uid, from_kuid_munged(c    660         SET_UID(tmp.st_uid, from_kuid_munged(current_user_ns(), stat->uid));
821         SET_GID(tmp.st_gid, from_kgid_munged(c    661         SET_GID(tmp.st_gid, from_kgid_munged(current_user_ns(), stat->gid));
822         tmp.st_rdev = new_encode_dev(stat->rde    662         tmp.st_rdev = new_encode_dev(stat->rdev);
823         if ((u64) stat->size > MAX_NON_LFS)       663         if ((u64) stat->size > MAX_NON_LFS)
824                 return -EOVERFLOW;                664                 return -EOVERFLOW;
825         tmp.st_size = stat->size;                 665         tmp.st_size = stat->size;
826         tmp.st_atime = stat->atime.tv_sec;        666         tmp.st_atime = stat->atime.tv_sec;
827         tmp.st_atime_nsec = stat->atime.tv_nse    667         tmp.st_atime_nsec = stat->atime.tv_nsec;
828         tmp.st_mtime = stat->mtime.tv_sec;        668         tmp.st_mtime = stat->mtime.tv_sec;
829         tmp.st_mtime_nsec = stat->mtime.tv_nse    669         tmp.st_mtime_nsec = stat->mtime.tv_nsec;
830         tmp.st_ctime = stat->ctime.tv_sec;        670         tmp.st_ctime = stat->ctime.tv_sec;
831         tmp.st_ctime_nsec = stat->ctime.tv_nse    671         tmp.st_ctime_nsec = stat->ctime.tv_nsec;
832         tmp.st_blocks = stat->blocks;             672         tmp.st_blocks = stat->blocks;
833         tmp.st_blksize = stat->blksize;           673         tmp.st_blksize = stat->blksize;
834         return copy_to_user(ubuf, &tmp, sizeof    674         return copy_to_user(ubuf, &tmp, sizeof(tmp)) ? -EFAULT : 0;
835 }                                                 675 }
836                                                   676 
837 COMPAT_SYSCALL_DEFINE2(newstat, const char __u    677 COMPAT_SYSCALL_DEFINE2(newstat, const char __user *, filename,
838                        struct compat_stat __us    678                        struct compat_stat __user *, statbuf)
839 {                                                 679 {
840         struct kstat stat;                        680         struct kstat stat;
841         int error;                                681         int error;
842                                                   682 
843         error = vfs_stat(filename, &stat);        683         error = vfs_stat(filename, &stat);
844         if (error)                                684         if (error)
845                 return error;                     685                 return error;
846         return cp_compat_stat(&stat, statbuf);    686         return cp_compat_stat(&stat, statbuf);
847 }                                                 687 }
848                                                   688 
849 COMPAT_SYSCALL_DEFINE2(newlstat, const char __    689 COMPAT_SYSCALL_DEFINE2(newlstat, const char __user *, filename,
850                        struct compat_stat __us    690                        struct compat_stat __user *, statbuf)
851 {                                                 691 {
852         struct kstat stat;                        692         struct kstat stat;
853         int error;                                693         int error;
854                                                   694 
855         error = vfs_lstat(filename, &stat);       695         error = vfs_lstat(filename, &stat);
856         if (error)                                696         if (error)
857                 return error;                     697                 return error;
858         return cp_compat_stat(&stat, statbuf);    698         return cp_compat_stat(&stat, statbuf);
859 }                                                 699 }
860                                                   700 
861 #ifndef __ARCH_WANT_STAT64                        701 #ifndef __ARCH_WANT_STAT64
862 COMPAT_SYSCALL_DEFINE4(newfstatat, unsigned in    702 COMPAT_SYSCALL_DEFINE4(newfstatat, unsigned int, dfd,
863                        const char __user *, fi    703                        const char __user *, filename,
864                        struct compat_stat __us    704                        struct compat_stat __user *, statbuf, int, flag)
865 {                                                 705 {
866         struct kstat stat;                        706         struct kstat stat;
867         int error;                                707         int error;
868                                                   708 
869         error = vfs_fstatat(dfd, filename, &st    709         error = vfs_fstatat(dfd, filename, &stat, flag);
870         if (error)                                710         if (error)
871                 return error;                     711                 return error;
872         return cp_compat_stat(&stat, statbuf);    712         return cp_compat_stat(&stat, statbuf);
873 }                                                 713 }
874 #endif                                            714 #endif
875                                                   715 
876 COMPAT_SYSCALL_DEFINE2(newfstat, unsigned int,    716 COMPAT_SYSCALL_DEFINE2(newfstat, unsigned int, fd,
877                        struct compat_stat __us    717                        struct compat_stat __user *, statbuf)
878 {                                                 718 {
879         struct kstat stat;                        719         struct kstat stat;
880         int error = vfs_fstat(fd, &stat);         720         int error = vfs_fstat(fd, &stat);
881                                                   721 
882         if (!error)                               722         if (!error)
883                 error = cp_compat_stat(&stat,     723                 error = cp_compat_stat(&stat, statbuf);
884         return error;                             724         return error;
885 }                                                 725 }
886 #endif                                            726 #endif
887                                                   727 
888 /* Caller is here responsible for sufficient l    728 /* Caller is here responsible for sufficient locking (ie. inode->i_lock) */
889 void __inode_add_bytes(struct inode *inode, lo    729 void __inode_add_bytes(struct inode *inode, loff_t bytes)
890 {                                                 730 {
891         inode->i_blocks += bytes >> 9;            731         inode->i_blocks += bytes >> 9;
892         bytes &= 511;                             732         bytes &= 511;
893         inode->i_bytes += bytes;                  733         inode->i_bytes += bytes;
894         if (inode->i_bytes >= 512) {              734         if (inode->i_bytes >= 512) {
895                 inode->i_blocks++;                735                 inode->i_blocks++;
896                 inode->i_bytes -= 512;            736                 inode->i_bytes -= 512;
897         }                                         737         }
898 }                                                 738 }
899 EXPORT_SYMBOL(__inode_add_bytes);                 739 EXPORT_SYMBOL(__inode_add_bytes);
900                                                   740 
901 void inode_add_bytes(struct inode *inode, loff    741 void inode_add_bytes(struct inode *inode, loff_t bytes)
902 {                                                 742 {
903         spin_lock(&inode->i_lock);                743         spin_lock(&inode->i_lock);
904         __inode_add_bytes(inode, bytes);          744         __inode_add_bytes(inode, bytes);
905         spin_unlock(&inode->i_lock);              745         spin_unlock(&inode->i_lock);
906 }                                                 746 }
907                                                   747 
908 EXPORT_SYMBOL(inode_add_bytes);                   748 EXPORT_SYMBOL(inode_add_bytes);
909                                                   749 
910 void __inode_sub_bytes(struct inode *inode, lo    750 void __inode_sub_bytes(struct inode *inode, loff_t bytes)
911 {                                                 751 {
912         inode->i_blocks -= bytes >> 9;            752         inode->i_blocks -= bytes >> 9;
913         bytes &= 511;                             753         bytes &= 511;
914         if (inode->i_bytes < bytes) {             754         if (inode->i_bytes < bytes) {
915                 inode->i_blocks--;                755                 inode->i_blocks--;
916                 inode->i_bytes += 512;            756                 inode->i_bytes += 512;
917         }                                         757         }
918         inode->i_bytes -= bytes;                  758         inode->i_bytes -= bytes;
919 }                                                 759 }
920                                                   760 
921 EXPORT_SYMBOL(__inode_sub_bytes);                 761 EXPORT_SYMBOL(__inode_sub_bytes);
922                                                   762 
923 void inode_sub_bytes(struct inode *inode, loff    763 void inode_sub_bytes(struct inode *inode, loff_t bytes)
924 {                                                 764 {
925         spin_lock(&inode->i_lock);                765         spin_lock(&inode->i_lock);
926         __inode_sub_bytes(inode, bytes);          766         __inode_sub_bytes(inode, bytes);
927         spin_unlock(&inode->i_lock);              767         spin_unlock(&inode->i_lock);
928 }                                                 768 }
929                                                   769 
930 EXPORT_SYMBOL(inode_sub_bytes);                   770 EXPORT_SYMBOL(inode_sub_bytes);
931                                                   771 
932 loff_t inode_get_bytes(struct inode *inode)       772 loff_t inode_get_bytes(struct inode *inode)
933 {                                                 773 {
934         loff_t ret;                               774         loff_t ret;
935                                                   775 
936         spin_lock(&inode->i_lock);                776         spin_lock(&inode->i_lock);
937         ret = __inode_get_bytes(inode);           777         ret = __inode_get_bytes(inode);
938         spin_unlock(&inode->i_lock);              778         spin_unlock(&inode->i_lock);
939         return ret;                               779         return ret;
940 }                                                 780 }
941                                                   781 
942 EXPORT_SYMBOL(inode_get_bytes);                   782 EXPORT_SYMBOL(inode_get_bytes);
943                                                   783 
944 void inode_set_bytes(struct inode *inode, loff    784 void inode_set_bytes(struct inode *inode, loff_t bytes)
945 {                                                 785 {
946         /* Caller is here responsible for suff    786         /* Caller is here responsible for sufficient locking
947          * (ie. inode->i_lock) */                 787          * (ie. inode->i_lock) */
948         inode->i_blocks = bytes >> 9;             788         inode->i_blocks = bytes >> 9;
949         inode->i_bytes = bytes & 511;             789         inode->i_bytes = bytes & 511;
950 }                                                 790 }
951                                                   791 
952 EXPORT_SYMBOL(inode_set_bytes);                   792 EXPORT_SYMBOL(inode_set_bytes);
953                                                   793 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php