Commit dfc209c0064efef5590f608056a48b61a5cac09c
Committed by
Linus Torvalds
1 parent
9183482f5d
Exists in
master
and in
4 other branches
fat: Fix ATTR_RO for directory
FAT has the ATTR_RO (read-only) attribute. But on Windows, the ATTR_RO of the directory will be just ignored actually, and is used by only applications as flag. E.g. it's setted for the customized folder by Explorer. http://msdn2.microsoft.com/en-us/library/aa969337.aspx This adds "rodir" option. If user specified it, ATTR_RO is used as read-only flag even if it's the directory. Otherwise, inode->i_mode is not used to hold ATTR_RO (i.e. fat_mode_can_save_ro() returns 0). 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 43 additions and 12 deletions Side-by-side Diff
Documentation/filesystems/vfat.txt
... | ... | @@ -124,6 +124,14 @@ |
124 | 124 | flush -- If set, the filesystem will try to flush to disk more |
125 | 125 | early than normal. Not set by default. |
126 | 126 | |
127 | +rodir -- FAT has the ATTR_RO (read-only) attribute. But on Windows, | |
128 | + the ATTR_RO of the directory will be just ignored actually, | |
129 | + and is used by only applications as flag. E.g. it's setted | |
130 | + for the customized folder. | |
131 | + | |
132 | + If you want to use ATTR_RO as read-only flag even for | |
133 | + the directory, set this option. | |
134 | + | |
127 | 135 | <bool>: 0,1,yes,no,true,false |
128 | 136 | |
129 | 137 | TODO |
fs/fat/fat.h
... | ... | @@ -38,7 +38,8 @@ |
38 | 38 | flush:1, /* write things quickly */ |
39 | 39 | nocase:1, /* Does this need case conversion? 0=need case conversion*/ |
40 | 40 | usefree:1, /* Use free_clusters for FAT32 */ |
41 | - tz_utc:1; /* Filesystem timestamps are in UTC */ | |
41 | + tz_utc:1, /* Filesystem timestamps are in UTC */ | |
42 | + rodir:1; /* allow ATTR_RO for directory */ | |
42 | 43 | }; |
43 | 44 | |
44 | 45 | #define FAT_HASH_BITS 8 |
45 | 46 | |
46 | 47 | |
... | ... | @@ -120,15 +121,20 @@ |
120 | 121 | /* |
121 | 122 | * If ->i_mode can't hold S_IWUGO (i.e. ATTR_RO), we use ->i_attrs to |
122 | 123 | * save ATTR_RO instead of ->i_mode. |
124 | + * | |
125 | + * If it's directory and !sbi->options.rodir, ATTR_RO isn't read-only | |
126 | + * bit, it's just used as flag for app. | |
123 | 127 | */ |
124 | 128 | static inline int fat_mode_can_hold_ro(struct inode *inode) |
125 | 129 | { |
126 | 130 | struct msdos_sb_info *sbi = MSDOS_SB(inode->i_sb); |
127 | 131 | mode_t mask; |
128 | 132 | |
129 | - if (S_ISDIR(inode->i_mode)) | |
133 | + if (S_ISDIR(inode->i_mode)) { | |
134 | + if (!sbi->options.rodir) | |
135 | + return 0; | |
130 | 136 | mask = ~sbi->options.fs_dmask; |
131 | - else | |
137 | + } else | |
132 | 138 | mask = ~sbi->options.fs_fmask; |
133 | 139 | |
134 | 140 | if (!(mask & S_IWUGO)) |
... | ... | @@ -140,7 +146,7 @@ |
140 | 146 | static inline mode_t fat_make_mode(struct msdos_sb_info *sbi, |
141 | 147 | u8 attrs, mode_t mode) |
142 | 148 | { |
143 | - if (attrs & ATTR_RO) | |
149 | + if (attrs & ATTR_RO && !((attrs & ATTR_DIR) && !sbi->options.rodir)) | |
144 | 150 | mode &= ~S_IWUGO; |
145 | 151 | |
146 | 152 | if (attrs & ATTR_DIR) |
fs/fat/file.c
... | ... | @@ -282,11 +282,18 @@ |
282 | 282 | /* |
283 | 283 | * Of the r and x bits, all (subject to umask) must be present. Of the |
284 | 284 | * w bits, either all (subject to umask) or none must be present. |
285 | + * | |
286 | + * If fat_mode_can_hold_ro(inode) is false, can't change w bits. | |
285 | 287 | */ |
286 | 288 | if ((perm & (S_IRUGO | S_IXUGO)) != (inode->i_mode & (S_IRUGO|S_IXUGO))) |
287 | 289 | return -EPERM; |
288 | - if ((perm & S_IWUGO) && ((perm & S_IWUGO) != (S_IWUGO & ~mask))) | |
289 | - return -EPERM; | |
290 | + if (fat_mode_can_hold_ro(inode)) { | |
291 | + if ((perm & S_IWUGO) && ((perm & S_IWUGO) != (S_IWUGO & ~mask))) | |
292 | + return -EPERM; | |
293 | + } else { | |
294 | + if ((perm & S_IWUGO) != (S_IWUGO & ~mask)) | |
295 | + return -EPERM; | |
296 | + } | |
290 | 297 | |
291 | 298 | *mode_ptr &= S_IFMT | perm; |
292 | 299 | |
293 | 300 | |
... | ... | @@ -316,8 +323,8 @@ |
316 | 323 | { |
317 | 324 | struct msdos_sb_info *sbi = MSDOS_SB(dentry->d_sb); |
318 | 325 | struct inode *inode = dentry->d_inode; |
319 | - int error = 0; | |
320 | 326 | unsigned int ia_valid; |
327 | + int error; | |
321 | 328 | |
322 | 329 | /* |
323 | 330 | * Expand the file. Since inode_setattr() updates ->i_size |
... | ... | @@ -371,7 +378,8 @@ |
371 | 378 | attr->ia_valid &= ~ATTR_MODE; |
372 | 379 | } |
373 | 380 | |
374 | - error = inode_setattr(inode, attr); | |
381 | + if (attr->ia_valid) | |
382 | + error = inode_setattr(inode, attr); | |
375 | 383 | out: |
376 | 384 | return error; |
377 | 385 | } |
fs/fat/inode.c
... | ... | @@ -797,8 +797,10 @@ |
797 | 797 | seq_puts(m, ",uni_xlate"); |
798 | 798 | if (!opts->numtail) |
799 | 799 | seq_puts(m, ",nonumtail"); |
800 | + if (opts->rodir) | |
801 | + seq_puts(m, ",rodir"); | |
800 | 802 | } |
801 | - if (sbi->options.flush) | |
803 | + if (opts->flush) | |
802 | 804 | seq_puts(m, ",flush"); |
803 | 805 | if (opts->tz_utc) |
804 | 806 | seq_puts(m, ",tz=UTC"); |
... | ... | @@ -814,7 +816,7 @@ |
814 | 816 | Opt_charset, Opt_shortname_lower, Opt_shortname_win95, |
815 | 817 | Opt_shortname_winnt, Opt_shortname_mixed, Opt_utf8_no, Opt_utf8_yes, |
816 | 818 | Opt_uni_xl_no, Opt_uni_xl_yes, Opt_nonumtail_no, Opt_nonumtail_yes, |
817 | - Opt_obsolate, Opt_flush, Opt_tz_utc, Opt_err, | |
819 | + Opt_obsolate, Opt_flush, Opt_tz_utc, Opt_rodir, Opt_err, | |
818 | 820 | }; |
819 | 821 | |
820 | 822 | static const match_table_t fat_tokens = { |
... | ... | @@ -886,6 +888,7 @@ |
886 | 888 | {Opt_nonumtail_yes, "nonumtail=yes"}, |
887 | 889 | {Opt_nonumtail_yes, "nonumtail=true"}, |
888 | 890 | {Opt_nonumtail_yes, "nonumtail"}, |
891 | + {Opt_rodir, "rodir"}, | |
889 | 892 | {Opt_err, NULL} |
890 | 893 | }; |
891 | 894 | |
892 | 895 | |
893 | 896 | |
... | ... | @@ -905,10 +908,13 @@ |
905 | 908 | opts->allow_utime = -1; |
906 | 909 | opts->codepage = fat_default_codepage; |
907 | 910 | opts->iocharset = fat_default_iocharset; |
908 | - if (is_vfat) | |
911 | + if (is_vfat) { | |
909 | 912 | opts->shortname = VFAT_SFN_DISPLAY_LOWER|VFAT_SFN_CREATE_WIN95; |
910 | - else | |
913 | + opts->rodir = 0; | |
914 | + } else { | |
911 | 915 | opts->shortname = 0; |
916 | + opts->rodir = 1; | |
917 | + } | |
912 | 918 | opts->name_check = 'n'; |
913 | 919 | opts->quiet = opts->showexec = opts->sys_immutable = opts->dotsOK = 0; |
914 | 920 | opts->utf8 = opts->unicode_xlate = 0; |
... | ... | @@ -1058,6 +1064,9 @@ |
1058 | 1064 | break; |
1059 | 1065 | case Opt_nonumtail_yes: /* empty or 1 or yes or true */ |
1060 | 1066 | opts->numtail = 0; /* negated option */ |
1067 | + break; | |
1068 | + case Opt_rodir: | |
1069 | + opts->rodir = 1; | |
1061 | 1070 | break; |
1062 | 1071 | |
1063 | 1072 | /* obsolete mount options */ |