Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * linux/fs/fat/file.c |
| 3 | * |
| 4 | * Written 1992,1993 by Werner Almesberger |
| 5 | * |
| 6 | * regular file handling primitives for fat-based filesystems |
| 7 | */ |
| 8 | |
Randy Dunlap | 16f7e0f | 2006-01-11 12:17:46 -0800 | [diff] [blame] | 9 | #include <linux/capability.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | #include <linux/module.h> |
Dave Hansen | 42a74f2 | 2008-02-15 14:37:46 -0800 | [diff] [blame] | 11 | #include <linux/mount.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | #include <linux/time.h> |
| 13 | #include <linux/msdos_fs.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | #include <linux/buffer_head.h> |
OGAWA Hirofumi | 05eb0b5 | 2006-01-08 01:02:13 -0800 | [diff] [blame] | 15 | #include <linux/writeback.h> |
Andrew Morton | 3fcfab1 | 2006-10-19 23:28:16 -0700 | [diff] [blame] | 16 | #include <linux/backing-dev.h> |
Chris Mason | ae78bf9 | 2006-09-29 02:00:03 -0700 | [diff] [blame] | 17 | #include <linux/blkdev.h> |
Miklos Szeredi | b1da47e | 2008-07-01 15:01:28 +0200 | [diff] [blame] | 18 | #include <linux/fsnotify.h> |
| 19 | #include <linux/security.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | int fat_generic_ioctl(struct inode *inode, struct file *filp, |
| 22 | unsigned int cmd, unsigned long arg) |
| 23 | { |
| 24 | struct msdos_sb_info *sbi = MSDOS_SB(inode->i_sb); |
| 25 | u32 __user *user_attr = (u32 __user *)arg; |
| 26 | |
| 27 | switch (cmd) { |
| 28 | case FAT_IOCTL_GET_ATTRIBUTES: |
| 29 | { |
| 30 | u32 attr; |
| 31 | |
| 32 | if (inode->i_ino == MSDOS_ROOT_INO) |
| 33 | attr = ATTR_DIR; |
| 34 | else |
| 35 | attr = fat_attr(inode); |
| 36 | |
| 37 | return put_user(attr, user_attr); |
| 38 | } |
| 39 | case FAT_IOCTL_SET_ATTRIBUTES: |
| 40 | { |
| 41 | u32 attr, oldattr; |
| 42 | int err, is_dir = S_ISDIR(inode->i_mode); |
| 43 | struct iattr ia; |
| 44 | |
| 45 | err = get_user(attr, user_attr); |
| 46 | if (err) |
| 47 | return err; |
| 48 | |
Jes Sorensen | 1b1dcc1 | 2006-01-09 15:59:24 -0800 | [diff] [blame] | 49 | mutex_lock(&inode->i_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | |
Dave Hansen | 42a74f2 | 2008-02-15 14:37:46 -0800 | [diff] [blame] | 51 | err = mnt_want_write(filp->f_path.mnt); |
| 52 | if (err) |
| 53 | goto up_no_drop_write; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | |
| 55 | /* |
| 56 | * ATTR_VOLUME and ATTR_DIR cannot be changed; this also |
| 57 | * prevents the user from turning us into a VFAT |
| 58 | * longname entry. Also, we obviously can't set |
| 59 | * any of the NTFS attributes in the high 24 bits. |
| 60 | */ |
| 61 | attr &= 0xff & ~(ATTR_VOLUME | ATTR_DIR); |
| 62 | /* Merge in ATTR_VOLUME and ATTR_DIR */ |
| 63 | attr |= (MSDOS_I(inode)->i_attrs & ATTR_VOLUME) | |
| 64 | (is_dir ? ATTR_DIR : 0); |
| 65 | oldattr = fat_attr(inode); |
| 66 | |
| 67 | /* Equivalent to a chmod() */ |
| 68 | ia.ia_valid = ATTR_MODE | ATTR_CTIME; |
Miklos Szeredi | b1da47e | 2008-07-01 15:01:28 +0200 | [diff] [blame] | 69 | ia.ia_ctime = current_fs_time(inode->i_sb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | if (is_dir) { |
| 71 | ia.ia_mode = MSDOS_MKMODE(attr, |
| 72 | S_IRWXUGO & ~sbi->options.fs_dmask) |
| 73 | | S_IFDIR; |
| 74 | } else { |
| 75 | ia.ia_mode = MSDOS_MKMODE(attr, |
| 76 | (S_IRUGO | S_IWUGO | (inode->i_mode & S_IXUGO)) |
| 77 | & ~sbi->options.fs_fmask) |
| 78 | | S_IFREG; |
| 79 | } |
| 80 | |
| 81 | /* The root directory has no attributes */ |
| 82 | if (inode->i_ino == MSDOS_ROOT_INO && attr != ATTR_DIR) { |
| 83 | err = -EINVAL; |
| 84 | goto up; |
| 85 | } |
| 86 | |
| 87 | if (sbi->options.sys_immutable) { |
| 88 | if ((attr | oldattr) & ATTR_SYS) { |
| 89 | if (!capable(CAP_LINUX_IMMUTABLE)) { |
| 90 | err = -EPERM; |
| 91 | goto up; |
| 92 | } |
| 93 | } |
| 94 | } |
| 95 | |
Miklos Szeredi | b1da47e | 2008-07-01 15:01:28 +0200 | [diff] [blame] | 96 | /* |
| 97 | * The security check is questionable... We single |
| 98 | * out the RO attribute for checking by the security |
| 99 | * module, just because it maps to a file mode. |
| 100 | */ |
| 101 | err = security_inode_setattr(filp->f_path.dentry, &ia); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | if (err) |
| 103 | goto up; |
| 104 | |
Miklos Szeredi | b1da47e | 2008-07-01 15:01:28 +0200 | [diff] [blame] | 105 | /* This MUST be done before doing anything irreversible... */ |
| 106 | err = fat_setattr(filp->f_path.dentry, &ia); |
| 107 | if (err) |
| 108 | goto up; |
| 109 | |
| 110 | fsnotify_change(filp->f_path.dentry, ia.ia_valid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | if (sbi->options.sys_immutable) { |
| 112 | if (attr & ATTR_SYS) |
| 113 | inode->i_flags |= S_IMMUTABLE; |
| 114 | else |
| 115 | inode->i_flags &= S_IMMUTABLE; |
| 116 | } |
| 117 | |
| 118 | MSDOS_I(inode)->i_attrs = attr & ATTR_UNUSED; |
| 119 | mark_inode_dirty(inode); |
Dave Hansen | 42a74f2 | 2008-02-15 14:37:46 -0800 | [diff] [blame] | 120 | up: |
| 121 | mnt_drop_write(filp->f_path.mnt); |
| 122 | up_no_drop_write: |
Jes Sorensen | 1b1dcc1 | 2006-01-09 15:59:24 -0800 | [diff] [blame] | 123 | mutex_unlock(&inode->i_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | return err; |
| 125 | } |
| 126 | default: |
| 127 | return -ENOTTY; /* Inappropriate ioctl for device */ |
| 128 | } |
| 129 | } |
| 130 | |
Chris Mason | ae78bf9 | 2006-09-29 02:00:03 -0700 | [diff] [blame] | 131 | static int fat_file_release(struct inode *inode, struct file *filp) |
| 132 | { |
| 133 | if ((filp->f_mode & FMODE_WRITE) && |
| 134 | MSDOS_SB(inode->i_sb)->options.flush) { |
| 135 | fat_flush_inodes(inode->i_sb, inode, NULL); |
Andrew Morton | 3fcfab1 | 2006-10-19 23:28:16 -0700 | [diff] [blame] | 136 | congestion_wait(WRITE, HZ/10); |
Chris Mason | ae78bf9 | 2006-09-29 02:00:03 -0700 | [diff] [blame] | 137 | } |
| 138 | return 0; |
| 139 | } |
| 140 | |
Arjan van de Ven | 4b6f5d2 | 2006-03-28 01:56:42 -0800 | [diff] [blame] | 141 | const struct file_operations fat_file_operations = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | .llseek = generic_file_llseek, |
| 143 | .read = do_sync_read, |
| 144 | .write = do_sync_write, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | .aio_read = generic_file_aio_read, |
OGAWA Hirofumi | ef40226 | 2005-09-16 19:28:13 -0700 | [diff] [blame] | 146 | .aio_write = generic_file_aio_write, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | .mmap = generic_file_mmap, |
Chris Mason | ae78bf9 | 2006-09-29 02:00:03 -0700 | [diff] [blame] | 148 | .release = fat_file_release, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | .ioctl = fat_generic_ioctl, |
| 150 | .fsync = file_fsync, |
Jens Axboe | 5ffc4ef | 2007-06-01 11:49:19 +0200 | [diff] [blame] | 151 | .splice_read = generic_file_splice_read, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 | }; |
| 153 | |
OGAWA Hirofumi | 05eb0b5 | 2006-01-08 01:02:13 -0800 | [diff] [blame] | 154 | static int fat_cont_expand(struct inode *inode, loff_t size) |
| 155 | { |
| 156 | struct address_space *mapping = inode->i_mapping; |
| 157 | loff_t start = inode->i_size, count = size - inode->i_size; |
| 158 | int err; |
| 159 | |
| 160 | err = generic_cont_expand_simple(inode, size); |
| 161 | if (err) |
| 162 | goto out; |
| 163 | |
| 164 | inode->i_ctime = inode->i_mtime = CURRENT_TIME_SEC; |
| 165 | mark_inode_dirty(inode); |
| 166 | if (IS_SYNC(inode)) |
| 167 | err = sync_page_range_nolock(inode, mapping, start, count); |
| 168 | out: |
| 169 | return err; |
| 170 | } |
| 171 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | /* Free all clusters after the skip'th cluster. */ |
| 173 | static int fat_free(struct inode *inode, int skip) |
| 174 | { |
| 175 | struct super_block *sb = inode->i_sb; |
| 176 | int err, wait, free_start, i_start, i_logstart; |
| 177 | |
| 178 | if (MSDOS_I(inode)->i_start == 0) |
| 179 | return 0; |
| 180 | |
OGAWA Hirofumi | 3b64140 | 2006-02-03 03:04:44 -0800 | [diff] [blame] | 181 | fat_cache_inval_inode(inode); |
| 182 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 183 | wait = IS_DIRSYNC(inode); |
OGAWA Hirofumi | 3b64140 | 2006-02-03 03:04:44 -0800 | [diff] [blame] | 184 | i_start = free_start = MSDOS_I(inode)->i_start; |
| 185 | i_logstart = MSDOS_I(inode)->i_logstart; |
| 186 | |
| 187 | /* First, we write the new file size. */ |
| 188 | if (!skip) { |
| 189 | MSDOS_I(inode)->i_start = 0; |
| 190 | MSDOS_I(inode)->i_logstart = 0; |
| 191 | } |
| 192 | MSDOS_I(inode)->i_attrs |= ATTR_ARCH; |
| 193 | inode->i_ctime = inode->i_mtime = CURRENT_TIME_SEC; |
| 194 | if (wait) { |
| 195 | err = fat_sync_inode(inode); |
| 196 | if (err) { |
| 197 | MSDOS_I(inode)->i_start = i_start; |
| 198 | MSDOS_I(inode)->i_logstart = i_logstart; |
| 199 | return err; |
| 200 | } |
| 201 | } else |
| 202 | mark_inode_dirty(inode); |
| 203 | |
| 204 | /* Write a new EOF, and get the remaining cluster chain for freeing. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | if (skip) { |
| 206 | struct fat_entry fatent; |
| 207 | int ret, fclus, dclus; |
| 208 | |
| 209 | ret = fat_get_cluster(inode, skip - 1, &fclus, &dclus); |
| 210 | if (ret < 0) |
| 211 | return ret; |
| 212 | else if (ret == FAT_ENT_EOF) |
| 213 | return 0; |
| 214 | |
| 215 | fatent_init(&fatent); |
| 216 | ret = fat_ent_read(inode, &fatent, dclus); |
| 217 | if (ret == FAT_ENT_EOF) { |
| 218 | fatent_brelse(&fatent); |
| 219 | return 0; |
| 220 | } else if (ret == FAT_ENT_FREE) { |
| 221 | fat_fs_panic(sb, |
| 222 | "%s: invalid cluster chain (i_pos %lld)", |
Harvey Harrison | 8e24eea | 2008-04-30 00:55:09 -0700 | [diff] [blame] | 223 | __func__, MSDOS_I(inode)->i_pos); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 224 | ret = -EIO; |
| 225 | } else if (ret > 0) { |
| 226 | err = fat_ent_write(inode, &fatent, FAT_ENT_EOF, wait); |
| 227 | if (err) |
| 228 | ret = err; |
| 229 | } |
| 230 | fatent_brelse(&fatent); |
| 231 | if (ret < 0) |
| 232 | return ret; |
| 233 | |
| 234 | free_start = ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 235 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 | inode->i_blocks = skip << (MSDOS_SB(sb)->cluster_bits - 9); |
| 237 | |
| 238 | /* Freeing the remained cluster chain */ |
| 239 | return fat_free_clusters(inode, free_start); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 240 | } |
| 241 | |
| 242 | void fat_truncate(struct inode *inode) |
| 243 | { |
Jonathan Corbet | 9c20616 | 2008-05-29 17:14:05 -0600 | [diff] [blame] | 244 | struct msdos_sb_info *sbi = MSDOS_SB(inode->i_sb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 245 | const unsigned int cluster_size = sbi->cluster_size; |
| 246 | int nr_clusters; |
| 247 | |
| 248 | /* |
| 249 | * This protects against truncating a file bigger than it was then |
| 250 | * trying to write into the hole. |
| 251 | */ |
| 252 | if (MSDOS_I(inode)->mmu_private > inode->i_size) |
| 253 | MSDOS_I(inode)->mmu_private = inode->i_size; |
| 254 | |
| 255 | nr_clusters = (inode->i_size + (cluster_size - 1)) >> sbi->cluster_bits; |
| 256 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 257 | fat_free(inode, nr_clusters); |
Chris Mason | ae78bf9 | 2006-09-29 02:00:03 -0700 | [diff] [blame] | 258 | fat_flush_inodes(inode->i_sb, inode, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 259 | } |
| 260 | |
OGAWA Hirofumi | da63fc7 | 2006-11-16 01:19:28 -0800 | [diff] [blame] | 261 | int fat_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat) |
| 262 | { |
| 263 | struct inode *inode = dentry->d_inode; |
| 264 | generic_fillattr(inode, stat); |
| 265 | stat->blksize = MSDOS_SB(inode->i_sb)->cluster_size; |
| 266 | return 0; |
| 267 | } |
| 268 | EXPORT_SYMBOL_GPL(fat_getattr); |
| 269 | |
OGAWA Hirofumi | 2d518f8 | 2008-06-12 15:21:28 -0700 | [diff] [blame] | 270 | static int fat_sanitize_mode(const struct msdos_sb_info *sbi, |
| 271 | struct inode *inode, umode_t *mode_ptr) |
OGAWA Hirofumi | 1278fdd | 2008-04-28 02:16:25 -0700 | [diff] [blame] | 272 | { |
OGAWA Hirofumi | 2d518f8 | 2008-06-12 15:21:28 -0700 | [diff] [blame] | 273 | mode_t mask, perm; |
OGAWA Hirofumi | 1278fdd | 2008-04-28 02:16:25 -0700 | [diff] [blame] | 274 | |
OGAWA Hirofumi | 2d518f8 | 2008-06-12 15:21:28 -0700 | [diff] [blame] | 275 | /* |
| 276 | * Note, the basic check is already done by a caller of |
| 277 | * (attr->ia_mode & ~MSDOS_VALID_MODE) |
| 278 | */ |
| 279 | |
| 280 | if (S_ISREG(inode->i_mode)) |
OGAWA Hirofumi | 1278fdd | 2008-04-28 02:16:25 -0700 | [diff] [blame] | 281 | mask = sbi->options.fs_fmask; |
| 282 | else |
| 283 | mask = sbi->options.fs_dmask; |
| 284 | |
OGAWA Hirofumi | 2d518f8 | 2008-06-12 15:21:28 -0700 | [diff] [blame] | 285 | perm = *mode_ptr & ~(S_IFMT | mask); |
| 286 | |
OGAWA Hirofumi | 1278fdd | 2008-04-28 02:16:25 -0700 | [diff] [blame] | 287 | /* |
| 288 | * Of the r and x bits, all (subject to umask) must be present. Of the |
| 289 | * w bits, either all (subject to umask) or none must be present. |
| 290 | */ |
OGAWA Hirofumi | 2d518f8 | 2008-06-12 15:21:28 -0700 | [diff] [blame] | 291 | if ((perm & (S_IRUGO | S_IXUGO)) != (inode->i_mode & (S_IRUGO|S_IXUGO))) |
OGAWA Hirofumi | 1278fdd | 2008-04-28 02:16:25 -0700 | [diff] [blame] | 292 | return -EPERM; |
OGAWA Hirofumi | 2d518f8 | 2008-06-12 15:21:28 -0700 | [diff] [blame] | 293 | if ((perm & S_IWUGO) && ((perm & S_IWUGO) != (S_IWUGO & ~mask))) |
OGAWA Hirofumi | 1278fdd | 2008-04-28 02:16:25 -0700 | [diff] [blame] | 294 | return -EPERM; |
| 295 | |
OGAWA Hirofumi | 2d518f8 | 2008-06-12 15:21:28 -0700 | [diff] [blame] | 296 | *mode_ptr &= S_IFMT | perm; |
| 297 | |
OGAWA Hirofumi | 1278fdd | 2008-04-28 02:16:25 -0700 | [diff] [blame] | 298 | return 0; |
| 299 | } |
| 300 | |
OGAWA Hirofumi | 1ae43f8 | 2008-04-28 02:16:26 -0700 | [diff] [blame] | 301 | static int fat_allow_set_time(struct msdos_sb_info *sbi, struct inode *inode) |
| 302 | { |
| 303 | mode_t allow_utime = sbi->options.allow_utime; |
| 304 | |
| 305 | if (current->fsuid != inode->i_uid) { |
| 306 | if (in_group_p(inode->i_gid)) |
| 307 | allow_utime >>= 3; |
| 308 | if (allow_utime & MAY_WRITE) |
| 309 | return 1; |
| 310 | } |
| 311 | |
| 312 | /* use a default check */ |
| 313 | return 0; |
| 314 | } |
| 315 | |
OGAWA Hirofumi | 1726384 | 2008-08-02 13:59:37 +0900 | [diff] [blame] | 316 | #define TIMES_SET_FLAGS (ATTR_MTIME_SET | ATTR_ATIME_SET | ATTR_TIMES_SET) |
| 317 | |
OGAWA Hirofumi | 1278fdd | 2008-04-28 02:16:25 -0700 | [diff] [blame] | 318 | int fat_setattr(struct dentry *dentry, struct iattr *attr) |
| 319 | { |
| 320 | struct msdos_sb_info *sbi = MSDOS_SB(dentry->d_sb); |
| 321 | struct inode *inode = dentry->d_inode; |
OGAWA Hirofumi | 2d518f8 | 2008-06-12 15:21:28 -0700 | [diff] [blame] | 322 | int error = 0; |
OGAWA Hirofumi | 1ae43f8 | 2008-04-28 02:16:26 -0700 | [diff] [blame] | 323 | unsigned int ia_valid; |
OGAWA Hirofumi | 1278fdd | 2008-04-28 02:16:25 -0700 | [diff] [blame] | 324 | |
OGAWA Hirofumi | 1278fdd | 2008-04-28 02:16:25 -0700 | [diff] [blame] | 325 | /* |
| 326 | * Expand the file. Since inode_setattr() updates ->i_size |
| 327 | * before calling the ->truncate(), but FAT needs to fill the |
| 328 | * hole before it. |
| 329 | */ |
| 330 | if (attr->ia_valid & ATTR_SIZE) { |
| 331 | if (attr->ia_size > inode->i_size) { |
| 332 | error = fat_cont_expand(inode, attr->ia_size); |
| 333 | if (error || attr->ia_valid == ATTR_SIZE) |
| 334 | goto out; |
| 335 | attr->ia_valid &= ~ATTR_SIZE; |
| 336 | } |
| 337 | } |
| 338 | |
OGAWA Hirofumi | 1ae43f8 | 2008-04-28 02:16:26 -0700 | [diff] [blame] | 339 | /* Check for setting the inode time. */ |
| 340 | ia_valid = attr->ia_valid; |
OGAWA Hirofumi | 1726384 | 2008-08-02 13:59:37 +0900 | [diff] [blame] | 341 | if (ia_valid & TIMES_SET_FLAGS) { |
OGAWA Hirofumi | 1ae43f8 | 2008-04-28 02:16:26 -0700 | [diff] [blame] | 342 | if (fat_allow_set_time(sbi, inode)) |
OGAWA Hirofumi | 1726384 | 2008-08-02 13:59:37 +0900 | [diff] [blame] | 343 | attr->ia_valid &= ~TIMES_SET_FLAGS; |
OGAWA Hirofumi | 1ae43f8 | 2008-04-28 02:16:26 -0700 | [diff] [blame] | 344 | } |
| 345 | |
OGAWA Hirofumi | 1278fdd | 2008-04-28 02:16:25 -0700 | [diff] [blame] | 346 | error = inode_change_ok(inode, attr); |
OGAWA Hirofumi | 1ae43f8 | 2008-04-28 02:16:26 -0700 | [diff] [blame] | 347 | attr->ia_valid = ia_valid; |
OGAWA Hirofumi | 1278fdd | 2008-04-28 02:16:25 -0700 | [diff] [blame] | 348 | if (error) { |
| 349 | if (sbi->options.quiet) |
| 350 | error = 0; |
| 351 | goto out; |
| 352 | } |
OGAWA Hirofumi | 2d518f8 | 2008-06-12 15:21:28 -0700 | [diff] [blame] | 353 | |
OGAWA Hirofumi | 1278fdd | 2008-04-28 02:16:25 -0700 | [diff] [blame] | 354 | if (((attr->ia_valid & ATTR_UID) && |
| 355 | (attr->ia_uid != sbi->options.fs_uid)) || |
| 356 | ((attr->ia_valid & ATTR_GID) && |
OGAWA Hirofumi | e97e8de | 2008-04-28 02:16:26 -0700 | [diff] [blame] | 357 | (attr->ia_gid != sbi->options.fs_gid)) || |
| 358 | ((attr->ia_valid & ATTR_MODE) && |
OGAWA Hirofumi | 2d518f8 | 2008-06-12 15:21:28 -0700 | [diff] [blame] | 359 | (attr->ia_mode & ~MSDOS_VALID_MODE))) |
OGAWA Hirofumi | 1278fdd | 2008-04-28 02:16:25 -0700 | [diff] [blame] | 360 | error = -EPERM; |
| 361 | |
| 362 | if (error) { |
| 363 | if (sbi->options.quiet) |
| 364 | error = 0; |
| 365 | goto out; |
| 366 | } |
| 367 | |
OGAWA Hirofumi | 2d518f8 | 2008-06-12 15:21:28 -0700 | [diff] [blame] | 368 | /* |
| 369 | * We don't return -EPERM here. Yes, strange, but this is too |
| 370 | * old behavior. |
| 371 | */ |
| 372 | if (attr->ia_valid & ATTR_MODE) { |
| 373 | if (fat_sanitize_mode(sbi, inode, &attr->ia_mode) < 0) |
| 374 | attr->ia_valid &= ~ATTR_MODE; |
| 375 | } |
OGAWA Hirofumi | 1278fdd | 2008-04-28 02:16:25 -0700 | [diff] [blame] | 376 | |
OGAWA Hirofumi | 2d518f8 | 2008-06-12 15:21:28 -0700 | [diff] [blame] | 377 | error = inode_setattr(inode, attr); |
OGAWA Hirofumi | 1278fdd | 2008-04-28 02:16:25 -0700 | [diff] [blame] | 378 | out: |
OGAWA Hirofumi | 1278fdd | 2008-04-28 02:16:25 -0700 | [diff] [blame] | 379 | return error; |
| 380 | } |
| 381 | EXPORT_SYMBOL_GPL(fat_setattr); |
| 382 | |
Arjan van de Ven | 754661f | 2007-02-12 00:55:38 -0800 | [diff] [blame] | 383 | const struct inode_operations fat_file_inode_operations = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 384 | .truncate = fat_truncate, |
OGAWA Hirofumi | 1278fdd | 2008-04-28 02:16:25 -0700 | [diff] [blame] | 385 | .setattr = fat_setattr, |
OGAWA Hirofumi | da63fc7 | 2006-11-16 01:19:28 -0800 | [diff] [blame] | 386 | .getattr = fat_getattr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 387 | }; |