Commit 9c0aa1b87bf541affef519eb4879ce7c5a5941ae

Authored by OGAWA Hirofumi
Committed by Linus Torvalds
1 parent 45cfbe3547

fat: Cleanup FAT attribute stuff

This adds three helpers:

fat_make_attrs() - makes FAT attributes from inode.
fat_make_mode()  - makes mode_t from FAT attributes.
fat_save_attrs() - saves FAT attributes to inode.

Then this replaces: MSDOS_MKMODE() by fat_make_mode(), fat_attr() by
fat_make_attrs(), ->i_attrs = attr & ATTR_UNUSED by fat_save_attrs().
And for root inode, those is used with ATTR_DIR instead of bogus
ATTR_NONE.

Signed-off-by: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

Showing 4 changed files with 40 additions and 36 deletions Side-by-side Diff

... ... @@ -117,12 +117,30 @@
117 117 return container_of(inode, struct msdos_inode_info, vfs_inode);
118 118 }
119 119  
  120 +/* Convert attribute bits and a mask to the UNIX mode. */
  121 +static inline mode_t fat_make_mode(struct msdos_sb_info *sbi,
  122 + u8 attrs, mode_t mode)
  123 +{
  124 + if (attrs & ATTR_RO)
  125 + mode &= ~S_IWUGO;
  126 +
  127 + if (attrs & ATTR_DIR)
  128 + return (mode & ~sbi->options.fs_dmask) | S_IFDIR;
  129 + else
  130 + return (mode & ~sbi->options.fs_fmask) | S_IFREG;
  131 +}
  132 +
120 133 /* Return the FAT attribute byte for this inode */
121   -static inline u8 fat_attr(struct inode *inode)
  134 +static inline u8 fat_make_attrs(struct inode *inode)
122 135 {
123 136 return ((inode->i_mode & S_IWUGO) ? ATTR_NONE : ATTR_RO) |
124 137 (S_ISDIR(inode->i_mode) ? ATTR_DIR : ATTR_NONE) |
125 138 MSDOS_I(inode)->i_attrs;
  139 +}
  140 +
  141 +static inline void fat_save_attrs(struct inode *inode, u8 attrs)
  142 +{
  143 + MSDOS_I(inode)->i_attrs = attrs & ATTR_UNUSED;
126 144 }
127 145  
128 146 static inline unsigned char fat_checksum(const __u8 *name)
... ... @@ -27,13 +27,7 @@
27 27 switch (cmd) {
28 28 case FAT_IOCTL_GET_ATTRIBUTES:
29 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   -
  30 + u32 attr = fat_make_attrs(inode);
37 31 return put_user(attr, user_attr);
38 32 }
39 33 case FAT_IOCTL_SET_ATTRIBUTES:
40 34  
... ... @@ -62,20 +56,16 @@
62 56 /* Merge in ATTR_VOLUME and ATTR_DIR */
63 57 attr |= (MSDOS_I(inode)->i_attrs & ATTR_VOLUME) |
64 58 (is_dir ? ATTR_DIR : 0);
65   - oldattr = fat_attr(inode);
  59 + oldattr = fat_make_attrs(inode);
66 60  
67 61 /* Equivalent to a chmod() */
68 62 ia.ia_valid = ATTR_MODE | ATTR_CTIME;
69 63 ia.ia_ctime = current_fs_time(inode->i_sb);
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;
  64 + if (is_dir)
  65 + ia.ia_mode = fat_make_mode(sbi, attr, S_IRWXUGO);
  66 + else {
  67 + ia.ia_mode = fat_make_mode(sbi, attr,
  68 + S_IRUGO | S_IWUGO | (inode->i_mode & S_IXUGO));
79 69 }
80 70  
81 71 /* The root directory has no attributes */
... ... @@ -115,7 +105,7 @@
115 105 inode->i_flags &= S_IMMUTABLE;
116 106 }
117 107  
118   - MSDOS_I(inode)->i_attrs = attr & ATTR_UNUSED;
  108 + fat_save_attrs(inode, attr);
119 109 mark_inode_dirty(inode);
120 110 up:
121 111 mnt_drop_write(filp->f_path.mnt);
... ... @@ -274,7 +264,7 @@
274 264  
275 265 /*
276 266 * Note, the basic check is already done by a caller of
277   - * (attr->ia_mode & ~MSDOS_VALID_MODE)
  267 + * (attr->ia_mode & ~FAT_VALID_MODE)
278 268 */
279 269  
280 270 if (S_ISREG(inode->i_mode))
... ... @@ -314,6 +304,8 @@
314 304 }
315 305  
316 306 #define TIMES_SET_FLAGS (ATTR_MTIME_SET | ATTR_ATIME_SET | ATTR_TIMES_SET)
  307 +/* valid file mode bits */
  308 +#define FAT_VALID_MODE (S_IFREG | S_IFDIR | S_IRWXUGO)
317 309  
318 310 int fat_setattr(struct dentry *dentry, struct iattr *attr)
319 311 {
... ... @@ -356,7 +348,7 @@
356 348 ((attr->ia_valid & ATTR_GID) &&
357 349 (attr->ia_gid != sbi->options.fs_gid)) ||
358 350 ((attr->ia_valid & ATTR_MODE) &&
359   - (attr->ia_mode & ~MSDOS_VALID_MODE)))
  351 + (attr->ia_mode & ~FAT_VALID_MODE)))
360 352 error = -EPERM;
361 353  
362 354 if (error) {
... ... @@ -337,8 +337,7 @@
337 337  
338 338 if ((de->attr & ATTR_DIR) && !IS_FREE(de->name)) {
339 339 inode->i_generation &= ~1;
340   - inode->i_mode = MSDOS_MKMODE(de->attr,
341   - S_IRWXUGO & ~sbi->options.fs_dmask) | S_IFDIR;
  340 + inode->i_mode = fat_make_mode(sbi, de->attr, S_IRWXUGO);
342 341 inode->i_op = sbi->dir_ops;
343 342 inode->i_fop = &fat_dir_operations;
344 343  
... ... @@ -355,10 +354,9 @@
355 354 inode->i_nlink = fat_subdirs(inode);
356 355 } else { /* not a directory */
357 356 inode->i_generation |= 1;
358   - inode->i_mode = MSDOS_MKMODE(de->attr,
359   - ((sbi->options.showexec && !is_exec(de->name + 8))
360   - ? S_IRUGO|S_IWUGO : S_IRWXUGO)
361   - & ~sbi->options.fs_fmask) | S_IFREG;
  357 + inode->i_mode = fat_make_mode(sbi, de->attr,
  358 + ((sbi->options.showexec && !is_exec(de->name + 8))
  359 + ? S_IRUGO|S_IWUGO : S_IRWXUGO));
362 360 MSDOS_I(inode)->i_start = le16_to_cpu(de->start);
363 361 if (sbi->fat_bits == 32)
364 362 MSDOS_I(inode)->i_start |= (le16_to_cpu(de->starthi) << 16);
... ... @@ -374,7 +372,8 @@
374 372 if (sbi->options.sys_immutable)
375 373 inode->i_flags |= S_IMMUTABLE;
376 374 }
377   - MSDOS_I(inode)->i_attrs = de->attr & ATTR_UNUSED;
  375 + fat_save_attrs(inode, de->attr);
  376 +
378 377 inode->i_blocks = ((inode->i_size + (sbi->cluster_size - 1))
379 378 & ~((loff_t)sbi->cluster_size - 1)) >> 9;
380 379  
... ... @@ -569,7 +568,7 @@
569 568 raw_entry->size = 0;
570 569 else
571 570 raw_entry->size = cpu_to_le32(inode->i_size);
572   - raw_entry->attr = fat_attr(inode);
  571 + raw_entry->attr = fat_make_attrs(inode);
573 572 raw_entry->start = cpu_to_le16(MSDOS_I(inode)->i_logstart);
574 573 raw_entry->starthi = cpu_to_le16(MSDOS_I(inode)->i_logstart >> 16);
575 574 fat_time_unix2fat(sbi, &inode->i_mtime, &raw_entry->time,
... ... @@ -1105,7 +1104,7 @@
1105 1104 inode->i_gid = sbi->options.fs_gid;
1106 1105 inode->i_version++;
1107 1106 inode->i_generation = 0;
1108   - inode->i_mode = (S_IRWXUGO & ~sbi->options.fs_dmask) | S_IFDIR;
  1107 + inode->i_mode = fat_make_mode(sbi, ATTR_DIR, S_IRWXUGO);
1109 1108 inode->i_op = sbi->dir_ops;
1110 1109 inode->i_fop = &fat_dir_operations;
1111 1110 if (sbi->fat_bits == 32) {
... ... @@ -1122,7 +1121,7 @@
1122 1121 MSDOS_I(inode)->i_logstart = 0;
1123 1122 MSDOS_I(inode)->mmu_private = inode->i_size;
1124 1123  
1125   - MSDOS_I(inode)->i_attrs = ATTR_NONE;
  1124 + fat_save_attrs(inode, ATTR_DIR);
1126 1125 inode->i_mtime.tv_sec = inode->i_atime.tv_sec = inode->i_ctime.tv_sec = 0;
1127 1126 inode->i_mtime.tv_nsec = inode->i_atime.tv_nsec = inode->i_ctime.tv_nsec = 0;
1128 1127 inode->i_nlink = fat_subdirs(inode)+2;
include/linux/msdos_fs.h
... ... @@ -46,11 +46,6 @@
46 46 #define DELETED_FLAG 0xe5 /* marks file as deleted when in name[0] */
47 47 #define IS_FREE(n) (!*(n) || *(n) == DELETED_FLAG)
48 48  
49   -/* valid file mode bits */
50   -#define MSDOS_VALID_MODE (S_IFREG | S_IFDIR | S_IRWXU | S_IRWXG | S_IRWXO)
51   -/* Convert attribute bits and a mask to the UNIX mode. */
52   -#define MSDOS_MKMODE(a, m) (m & (a & ATTR_RO ? S_IRUGO|S_IXUGO : S_IRWXUGO))
53   -
54 49 #define MSDOS_NAME 11 /* maximum name length */
55 50 #define MSDOS_LONGNAME 256 /* maximum name length */
56 51 #define MSDOS_SLOTS 21 /* max # of slots for short and long names */