Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * linux/fs/msdos/namei.c |
| 3 | * |
| 4 | * Written 1992,1993 by Werner Almesberger |
| 5 | * Hidden files 1995 by Albert Cahalan <albert@ccs.neu.edu> <adc@coe.neu.edu> |
| 6 | * Rewritten for constant inumbers 1999 by Al Viro |
| 7 | */ |
| 8 | |
| 9 | #include <linux/module.h> |
Jeff Layton | 2489dba | 2017-12-11 06:35:09 -0500 | [diff] [blame] | 10 | #include <linux/iversion.h> |
OGAWA Hirofumi | 9e975da | 2008-11-06 12:53:46 -0800 | [diff] [blame] | 11 | #include "fat.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | /* Characters that are undesirable in an MS-DOS file name */ |
| 14 | static unsigned char bad_chars[] = "*?<>|\""; |
Rene Scharfe | 7557bc6 | 2008-07-25 01:46:45 -0700 | [diff] [blame] | 15 | static unsigned char bad_if_strict[] = "+=,; "; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | |
| 17 | /***** Formats an MS-DOS file name. Rejects invalid names. */ |
| 18 | static int msdos_format_name(const unsigned char *name, int len, |
| 19 | unsigned char *res, struct fat_mount_options *opts) |
| 20 | /* |
| 21 | * name is the proposed name, len is its length, res is |
| 22 | * the resulting name, opts->name_check is either (r)elaxed, |
| 23 | * (n)ormal or (s)trict, opts->dotsOK allows dots at the |
| 24 | * beginning of name (for hidden files) |
| 25 | */ |
| 26 | { |
| 27 | unsigned char *walk; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | unsigned char c; |
| 29 | int space; |
| 30 | |
| 31 | if (name[0] == '.') { /* dotfile because . and .. already done */ |
| 32 | if (opts->dotsOK) { |
| 33 | /* Get rid of dot - test for it elsewhere */ |
| 34 | name++; |
| 35 | len--; |
Rene Scharfe | 7557bc6 | 2008-07-25 01:46:45 -0700 | [diff] [blame] | 36 | } else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | return -EINVAL; |
| 38 | } |
| 39 | /* |
Rene Scharfe | 7557bc6 | 2008-07-25 01:46:45 -0700 | [diff] [blame] | 40 | * disallow names that _really_ start with a dot |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | */ |
Rene Scharfe | 7557bc6 | 2008-07-25 01:46:45 -0700 | [diff] [blame] | 42 | space = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | c = 0; |
| 44 | for (walk = res; len && walk - res < 8; walk++) { |
| 45 | c = *name++; |
| 46 | len--; |
| 47 | if (opts->name_check != 'r' && strchr(bad_chars, c)) |
| 48 | return -EINVAL; |
Rene Scharfe | 7557bc6 | 2008-07-25 01:46:45 -0700 | [diff] [blame] | 49 | if (opts->name_check == 's' && strchr(bad_if_strict, c)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | return -EINVAL; |
| 51 | if (c >= 'A' && c <= 'Z' && opts->name_check == 's') |
| 52 | return -EINVAL; |
| 53 | if (c < ' ' || c == ':' || c == '\\') |
| 54 | return -EINVAL; |
| 55 | /* |
| 56 | * 0xE5 is legal as a first character, but we must substitute |
| 57 | * 0x05 because 0xE5 marks deleted files. Yes, DOS really |
| 58 | * does this. |
| 59 | * It seems that Microsoft hacked DOS to support non-US |
| 60 | * characters after the 0xE5 character was already in use to |
| 61 | * mark deleted files. |
| 62 | */ |
| 63 | if ((res == walk) && (c == 0xE5)) |
| 64 | c = 0x05; |
| 65 | if (c == '.') |
| 66 | break; |
| 67 | space = (c == ' '); |
| 68 | *walk = (!opts->nocase && c >= 'a' && c <= 'z') ? c - 32 : c; |
| 69 | } |
| 70 | if (space) |
| 71 | return -EINVAL; |
| 72 | if (opts->name_check == 's' && len && c != '.') { |
| 73 | c = *name++; |
| 74 | len--; |
| 75 | if (c != '.') |
| 76 | return -EINVAL; |
| 77 | } |
| 78 | while (c != '.' && len--) |
| 79 | c = *name++; |
| 80 | if (c == '.') { |
| 81 | while (walk - res < 8) |
| 82 | *walk++ = ' '; |
| 83 | while (len > 0 && walk - res < MSDOS_NAME) { |
| 84 | c = *name++; |
| 85 | len--; |
| 86 | if (opts->name_check != 'r' && strchr(bad_chars, c)) |
| 87 | return -EINVAL; |
| 88 | if (opts->name_check == 's' && |
Rene Scharfe | 7557bc6 | 2008-07-25 01:46:45 -0700 | [diff] [blame] | 89 | strchr(bad_if_strict, c)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | return -EINVAL; |
| 91 | if (c < ' ' || c == ':' || c == '\\') |
| 92 | return -EINVAL; |
| 93 | if (c == '.') { |
| 94 | if (opts->name_check == 's') |
| 95 | return -EINVAL; |
| 96 | break; |
| 97 | } |
| 98 | if (c >= 'A' && c <= 'Z' && opts->name_check == 's') |
| 99 | return -EINVAL; |
| 100 | space = c == ' '; |
| 101 | if (!opts->nocase && c >= 'a' && c <= 'z') |
| 102 | *walk++ = c - 32; |
| 103 | else |
| 104 | *walk++ = c; |
| 105 | } |
| 106 | if (space) |
| 107 | return -EINVAL; |
| 108 | if (opts->name_check == 's' && len) |
| 109 | return -EINVAL; |
| 110 | } |
| 111 | while (walk - res < MSDOS_NAME) |
| 112 | *walk++ = ' '; |
OGAWA Hirofumi | 094e320 | 2006-03-31 02:30:53 -0800 | [diff] [blame] | 113 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | return 0; |
| 115 | } |
| 116 | |
| 117 | /***** Locates a directory entry. Uses unformatted name. */ |
| 118 | static int msdos_find(struct inode *dir, const unsigned char *name, int len, |
| 119 | struct fat_slot_info *sinfo) |
| 120 | { |
| 121 | struct msdos_sb_info *sbi = MSDOS_SB(dir->i_sb); |
| 122 | unsigned char msdos_name[MSDOS_NAME]; |
| 123 | int err; |
| 124 | |
| 125 | err = msdos_format_name(name, len, msdos_name, &sbi->options); |
| 126 | if (err) |
| 127 | return -ENOENT; |
| 128 | |
| 129 | err = fat_scan(dir, msdos_name, sinfo); |
| 130 | if (!err && sbi->options.dotsOK) { |
| 131 | if (name[0] == '.') { |
| 132 | if (!(sinfo->de->attr & ATTR_HIDDEN)) |
| 133 | err = -ENOENT; |
| 134 | } else { |
| 135 | if (sinfo->de->attr & ATTR_HIDDEN) |
| 136 | err = -ENOENT; |
| 137 | } |
| 138 | if (err) |
| 139 | brelse(sinfo->bh); |
| 140 | } |
| 141 | return err; |
| 142 | } |
| 143 | |
| 144 | /* |
| 145 | * Compute the hash for the msdos name corresponding to the dentry. |
| 146 | * Note: if the name is invalid, we leave the hash code unchanged so |
| 147 | * that the existing dentry can be used. The msdos fs routines will |
| 148 | * return ENOENT or EINVAL as appropriate. |
| 149 | */ |
Linus Torvalds | da53be1 | 2013-05-21 15:22:44 -0700 | [diff] [blame] | 150 | static int msdos_hash(const struct dentry *dentry, struct qstr *qstr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | { |
| 152 | struct fat_mount_options *options = &MSDOS_SB(dentry->d_sb)->options; |
| 153 | unsigned char msdos_name[MSDOS_NAME]; |
| 154 | int error; |
| 155 | |
| 156 | error = msdos_format_name(qstr->name, qstr->len, msdos_name, options); |
| 157 | if (!error) |
Linus Torvalds | 8387ff2 | 2016-06-10 07:51:30 -0700 | [diff] [blame] | 158 | qstr->hash = full_name_hash(dentry, msdos_name, MSDOS_NAME); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | return 0; |
| 160 | } |
| 161 | |
| 162 | /* |
| 163 | * Compare two msdos names. If either of the names are invalid, |
| 164 | * we fall back to doing the standard name comparison. |
| 165 | */ |
Al Viro | 6fa67e7 | 2016-07-31 16:37:25 -0400 | [diff] [blame] | 166 | static int msdos_cmp(const struct dentry *dentry, |
Nick Piggin | 621e155 | 2011-01-07 17:49:27 +1100 | [diff] [blame] | 167 | unsigned int len, const char *str, const struct qstr *name) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 168 | { |
Al Viro | d3fe198 | 2016-07-29 18:23:59 -0400 | [diff] [blame] | 169 | struct fat_mount_options *options = &MSDOS_SB(dentry->d_sb)->options; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | unsigned char a_msdos_name[MSDOS_NAME], b_msdos_name[MSDOS_NAME]; |
| 171 | int error; |
| 172 | |
Nick Piggin | 621e155 | 2011-01-07 17:49:27 +1100 | [diff] [blame] | 173 | error = msdos_format_name(name->name, name->len, a_msdos_name, options); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | if (error) |
| 175 | goto old_compare; |
Nick Piggin | 621e155 | 2011-01-07 17:49:27 +1100 | [diff] [blame] | 176 | error = msdos_format_name(str, len, b_msdos_name, options); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | if (error) |
| 178 | goto old_compare; |
| 179 | error = memcmp(a_msdos_name, b_msdos_name, MSDOS_NAME); |
| 180 | out: |
| 181 | return error; |
| 182 | |
| 183 | old_compare: |
| 184 | error = 1; |
Nick Piggin | 621e155 | 2011-01-07 17:49:27 +1100 | [diff] [blame] | 185 | if (name->len == len) |
| 186 | error = memcmp(name->name, str, len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | goto out; |
| 188 | } |
| 189 | |
Al Viro | ce6cdc4 | 2009-02-20 05:59:46 +0000 | [diff] [blame] | 190 | static const struct dentry_operations msdos_dentry_operations = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 191 | .d_hash = msdos_hash, |
| 192 | .d_compare = msdos_cmp, |
| 193 | }; |
| 194 | |
| 195 | /* |
| 196 | * AV. Wrappers for FAT sb operations. Is it wise? |
| 197 | */ |
| 198 | |
| 199 | /***** Get inode using directory and name */ |
| 200 | static struct dentry *msdos_lookup(struct inode *dir, struct dentry *dentry, |
Al Viro | 00cd8dd | 2012-06-10 17:13:09 -0400 | [diff] [blame] | 201 | unsigned int flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 202 | { |
| 203 | struct super_block *sb = dir->i_sb; |
| 204 | struct fat_slot_info sinfo; |
OGAWA Hirofumi | 45cfbe3 | 2008-11-06 12:53:53 -0800 | [diff] [blame] | 205 | struct inode *inode; |
| 206 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 207 | |
Marco Stornelli | e40b34c | 2012-10-06 12:40:03 +0200 | [diff] [blame] | 208 | mutex_lock(&MSDOS_SB(sb)->s_lock); |
OGAWA Hirofumi | 45cfbe3 | 2008-11-06 12:53:53 -0800 | [diff] [blame] | 209 | err = msdos_find(dir, dentry->d_name.name, dentry->d_name.len, &sinfo); |
Al Viro | a904937 | 2011-07-08 21:20:11 -0400 | [diff] [blame] | 210 | switch (err) { |
| 211 | case -ENOENT: |
| 212 | inode = NULL; |
| 213 | break; |
| 214 | case 0: |
| 215 | inode = fat_build_inode(sb, sinfo.de, sinfo.i_pos); |
| 216 | brelse(sinfo.bh); |
| 217 | break; |
| 218 | default: |
| 219 | inode = ERR_PTR(err); |
OGAWA Hirofumi | 45cfbe3 | 2008-11-06 12:53:53 -0800 | [diff] [blame] | 220 | } |
Marco Stornelli | e40b34c | 2012-10-06 12:40:03 +0200 | [diff] [blame] | 221 | mutex_unlock(&MSDOS_SB(sb)->s_lock); |
Al Viro | 3d23985 | 2010-12-18 10:44:00 -0500 | [diff] [blame] | 222 | return d_splice_alias(inode, dentry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 223 | } |
| 224 | |
| 225 | /***** Creates a directory entry (name is already formatted). */ |
| 226 | static int msdos_add_entry(struct inode *dir, const unsigned char *name, |
| 227 | int is_dir, int is_hid, int cluster, |
Arnd Bergmann | f423420 | 2018-08-21 21:59:48 -0700 | [diff] [blame^] | 228 | struct timespec64 *ts, struct fat_slot_info *sinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 229 | { |
Joe Peterson | b271e06 | 2008-07-25 01:46:47 -0700 | [diff] [blame] | 230 | struct msdos_sb_info *sbi = MSDOS_SB(dir->i_sb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 231 | struct msdos_dir_entry de; |
| 232 | __le16 time, date; |
| 233 | int err; |
| 234 | |
| 235 | memcpy(de.name, name, MSDOS_NAME); |
| 236 | de.attr = is_dir ? ATTR_DIR : ATTR_ARCH; |
| 237 | if (is_hid) |
| 238 | de.attr |= ATTR_HIDDEN; |
| 239 | de.lcase = 0; |
OGAWA Hirofumi | 7decd1c | 2008-11-06 12:53:47 -0800 | [diff] [blame] | 240 | fat_time_unix2fat(sbi, ts, &time, &date, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 241 | de.cdate = de.adate = 0; |
| 242 | de.ctime = 0; |
| 243 | de.ctime_cs = 0; |
| 244 | de.time = time; |
| 245 | de.date = date; |
Steven J. Magnani | a943ed7 | 2012-07-30 14:42:13 -0700 | [diff] [blame] | 246 | fat_set_start(&de, cluster); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 | de.size = 0; |
| 248 | |
| 249 | err = fat_add_entries(dir, &de, 1, sinfo); |
| 250 | if (err) |
| 251 | return err; |
| 252 | |
Arnd Bergmann | f423420 | 2018-08-21 21:59:48 -0700 | [diff] [blame^] | 253 | dir->i_ctime = dir->i_mtime = *ts; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | if (IS_DIRSYNC(dir)) |
| 255 | (void)fat_sync_inode(dir); |
| 256 | else |
| 257 | mark_inode_dirty(dir); |
| 258 | |
| 259 | return 0; |
| 260 | } |
| 261 | |
| 262 | /***** Create a file */ |
Al Viro | 4acdaf2 | 2011-07-26 01:42:34 -0400 | [diff] [blame] | 263 | static int msdos_create(struct inode *dir, struct dentry *dentry, umode_t mode, |
Al Viro | ebfc3b4 | 2012-06-10 18:05:36 -0400 | [diff] [blame] | 264 | bool excl) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 265 | { |
| 266 | struct super_block *sb = dir->i_sb; |
Chris Mason | ae78bf9 | 2006-09-29 02:00:03 -0700 | [diff] [blame] | 267 | struct inode *inode = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 268 | struct fat_slot_info sinfo; |
Deepa Dinamani | 95582b0 | 2018-05-08 19:36:02 -0700 | [diff] [blame] | 269 | struct timespec64 ts; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 270 | unsigned char msdos_name[MSDOS_NAME]; |
| 271 | int err, is_hid; |
| 272 | |
Marco Stornelli | e40b34c | 2012-10-06 12:40:03 +0200 | [diff] [blame] | 273 | mutex_lock(&MSDOS_SB(sb)->s_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 274 | |
| 275 | err = msdos_format_name(dentry->d_name.name, dentry->d_name.len, |
| 276 | msdos_name, &MSDOS_SB(sb)->options); |
| 277 | if (err) |
| 278 | goto out; |
| 279 | is_hid = (dentry->d_name.name[0] == '.') && (msdos_name[0] != '.'); |
| 280 | /* Have to do it due to foo vs. .foo conflicts */ |
| 281 | if (!fat_scan(dir, msdos_name, &sinfo)) { |
| 282 | brelse(sinfo.bh); |
| 283 | err = -EINVAL; |
| 284 | goto out; |
| 285 | } |
| 286 | |
Deepa Dinamani | 02027d4 | 2016-09-14 07:48:05 -0700 | [diff] [blame] | 287 | ts = current_time(dir); |
Arnd Bergmann | f423420 | 2018-08-21 21:59:48 -0700 | [diff] [blame^] | 288 | err = msdos_add_entry(dir, msdos_name, 0, is_hid, 0, &ts, &sinfo); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 289 | if (err) |
| 290 | goto out; |
| 291 | inode = fat_build_inode(sb, sinfo.de, sinfo.i_pos); |
| 292 | brelse(sinfo.bh); |
| 293 | if (IS_ERR(inode)) { |
| 294 | err = PTR_ERR(inode); |
| 295 | goto out; |
| 296 | } |
| 297 | inode->i_mtime = inode->i_atime = inode->i_ctime = ts; |
| 298 | /* timestamp is already written, so mark_inode_dirty() is unneeded. */ |
| 299 | |
| 300 | d_instantiate(dentry, inode); |
| 301 | out: |
Marco Stornelli | e40b34c | 2012-10-06 12:40:03 +0200 | [diff] [blame] | 302 | mutex_unlock(&MSDOS_SB(sb)->s_lock); |
Chris Mason | ae78bf9 | 2006-09-29 02:00:03 -0700 | [diff] [blame] | 303 | if (!err) |
| 304 | err = fat_flush_inodes(sb, dir, inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 305 | return err; |
| 306 | } |
| 307 | |
| 308 | /***** Remove a directory */ |
| 309 | static int msdos_rmdir(struct inode *dir, struct dentry *dentry) |
| 310 | { |
Linus Torvalds | 8f59342 | 2008-05-19 19:53:01 -0700 | [diff] [blame] | 311 | struct super_block *sb = dir->i_sb; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 312 | struct inode *inode = d_inode(dentry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 313 | struct fat_slot_info sinfo; |
| 314 | int err; |
| 315 | |
Marco Stornelli | e40b34c | 2012-10-06 12:40:03 +0200 | [diff] [blame] | 316 | mutex_lock(&MSDOS_SB(sb)->s_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 317 | err = fat_dir_empty(inode); |
| 318 | if (err) |
| 319 | goto out; |
| 320 | err = msdos_find(dir, dentry->d_name.name, dentry->d_name.len, &sinfo); |
| 321 | if (err) |
| 322 | goto out; |
| 323 | |
| 324 | err = fat_remove_entries(dir, &sinfo); /* and releases bh */ |
| 325 | if (err) |
| 326 | goto out; |
Dave Hansen | 9a53c3a | 2006-09-30 23:29:03 -0700 | [diff] [blame] | 327 | drop_nlink(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 328 | |
Dave Hansen | ce71ec3 | 2006-09-30 23:29:06 -0700 | [diff] [blame] | 329 | clear_nlink(inode); |
Deepa Dinamani | 02027d4 | 2016-09-14 07:48:05 -0700 | [diff] [blame] | 330 | inode->i_ctime = current_time(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 331 | fat_detach(inode); |
| 332 | out: |
Marco Stornelli | e40b34c | 2012-10-06 12:40:03 +0200 | [diff] [blame] | 333 | mutex_unlock(&MSDOS_SB(sb)->s_lock); |
Chris Mason | ae78bf9 | 2006-09-29 02:00:03 -0700 | [diff] [blame] | 334 | if (!err) |
Linus Torvalds | 8f59342 | 2008-05-19 19:53:01 -0700 | [diff] [blame] | 335 | err = fat_flush_inodes(sb, dir, inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 336 | |
| 337 | return err; |
| 338 | } |
| 339 | |
| 340 | /***** Make a directory */ |
Al Viro | 18bb1db | 2011-07-26 01:41:39 -0400 | [diff] [blame] | 341 | static int msdos_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 342 | { |
| 343 | struct super_block *sb = dir->i_sb; |
| 344 | struct fat_slot_info sinfo; |
| 345 | struct inode *inode; |
| 346 | unsigned char msdos_name[MSDOS_NAME]; |
Deepa Dinamani | 95582b0 | 2018-05-08 19:36:02 -0700 | [diff] [blame] | 347 | struct timespec64 ts; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 348 | int err, is_hid, cluster; |
| 349 | |
Marco Stornelli | e40b34c | 2012-10-06 12:40:03 +0200 | [diff] [blame] | 350 | mutex_lock(&MSDOS_SB(sb)->s_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 351 | |
| 352 | err = msdos_format_name(dentry->d_name.name, dentry->d_name.len, |
| 353 | msdos_name, &MSDOS_SB(sb)->options); |
| 354 | if (err) |
| 355 | goto out; |
| 356 | is_hid = (dentry->d_name.name[0] == '.') && (msdos_name[0] != '.'); |
| 357 | /* foo vs .foo situation */ |
| 358 | if (!fat_scan(dir, msdos_name, &sinfo)) { |
| 359 | brelse(sinfo.bh); |
| 360 | err = -EINVAL; |
| 361 | goto out; |
| 362 | } |
| 363 | |
Deepa Dinamani | 02027d4 | 2016-09-14 07:48:05 -0700 | [diff] [blame] | 364 | ts = current_time(dir); |
Arnd Bergmann | f423420 | 2018-08-21 21:59:48 -0700 | [diff] [blame^] | 365 | cluster = fat_alloc_new_dir(dir, &ts); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 366 | if (cluster < 0) { |
| 367 | err = cluster; |
| 368 | goto out; |
| 369 | } |
Arnd Bergmann | f423420 | 2018-08-21 21:59:48 -0700 | [diff] [blame^] | 370 | err = msdos_add_entry(dir, msdos_name, 1, is_hid, cluster, &ts, &sinfo); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 371 | if (err) |
| 372 | goto out_free; |
Dave Hansen | d8c76e6 | 2006-09-30 23:29:04 -0700 | [diff] [blame] | 373 | inc_nlink(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 374 | |
| 375 | inode = fat_build_inode(sb, sinfo.de, sinfo.i_pos); |
| 376 | brelse(sinfo.bh); |
| 377 | if (IS_ERR(inode)) { |
| 378 | err = PTR_ERR(inode); |
| 379 | /* the directory was completed, just return a error */ |
| 380 | goto out; |
| 381 | } |
Miklos Szeredi | bfe8684 | 2011-10-28 14:13:29 +0200 | [diff] [blame] | 382 | set_nlink(inode, 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 383 | inode->i_mtime = inode->i_atime = inode->i_ctime = ts; |
| 384 | /* timestamp is already written, so mark_inode_dirty() is unneeded. */ |
| 385 | |
| 386 | d_instantiate(dentry, inode); |
| 387 | |
Marco Stornelli | e40b34c | 2012-10-06 12:40:03 +0200 | [diff] [blame] | 388 | mutex_unlock(&MSDOS_SB(sb)->s_lock); |
Chris Mason | ae78bf9 | 2006-09-29 02:00:03 -0700 | [diff] [blame] | 389 | fat_flush_inodes(sb, dir, inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 390 | return 0; |
| 391 | |
| 392 | out_free: |
| 393 | fat_free_clusters(dir, cluster); |
| 394 | out: |
Marco Stornelli | e40b34c | 2012-10-06 12:40:03 +0200 | [diff] [blame] | 395 | mutex_unlock(&MSDOS_SB(sb)->s_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 396 | return err; |
| 397 | } |
| 398 | |
| 399 | /***** Unlink a file */ |
| 400 | static int msdos_unlink(struct inode *dir, struct dentry *dentry) |
| 401 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 402 | struct inode *inode = d_inode(dentry); |
Cruz Julian Bishop | 85cb9bf | 2012-10-04 17:14:47 -0700 | [diff] [blame] | 403 | struct super_block *sb = inode->i_sb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 404 | struct fat_slot_info sinfo; |
| 405 | int err; |
| 406 | |
Marco Stornelli | e40b34c | 2012-10-06 12:40:03 +0200 | [diff] [blame] | 407 | mutex_lock(&MSDOS_SB(sb)->s_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 408 | err = msdos_find(dir, dentry->d_name.name, dentry->d_name.len, &sinfo); |
| 409 | if (err) |
| 410 | goto out; |
| 411 | |
| 412 | err = fat_remove_entries(dir, &sinfo); /* and releases bh */ |
| 413 | if (err) |
| 414 | goto out; |
Dave Hansen | ce71ec3 | 2006-09-30 23:29:06 -0700 | [diff] [blame] | 415 | clear_nlink(inode); |
Deepa Dinamani | 02027d4 | 2016-09-14 07:48:05 -0700 | [diff] [blame] | 416 | inode->i_ctime = current_time(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 417 | fat_detach(inode); |
| 418 | out: |
Marco Stornelli | e40b34c | 2012-10-06 12:40:03 +0200 | [diff] [blame] | 419 | mutex_unlock(&MSDOS_SB(sb)->s_lock); |
Chris Mason | ae78bf9 | 2006-09-29 02:00:03 -0700 | [diff] [blame] | 420 | if (!err) |
Linus Torvalds | 8f59342 | 2008-05-19 19:53:01 -0700 | [diff] [blame] | 421 | err = fat_flush_inodes(sb, dir, inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 422 | |
| 423 | return err; |
| 424 | } |
| 425 | |
| 426 | static int do_msdos_rename(struct inode *old_dir, unsigned char *old_name, |
| 427 | struct dentry *old_dentry, |
| 428 | struct inode *new_dir, unsigned char *new_name, |
| 429 | struct dentry *new_dentry, int is_hid) |
| 430 | { |
| 431 | struct buffer_head *dotdot_bh; |
| 432 | struct msdos_dir_entry *dotdot_de; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 433 | struct inode *old_inode, *new_inode; |
| 434 | struct fat_slot_info old_sinfo, sinfo; |
Deepa Dinamani | 95582b0 | 2018-05-08 19:36:02 -0700 | [diff] [blame] | 435 | struct timespec64 ts; |
Steven J. Magnani | 7669e8f | 2012-10-04 17:14:45 -0700 | [diff] [blame] | 436 | loff_t new_i_pos; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 437 | int err, old_attrs, is_dir, update_dotdot, corrupt = 0; |
| 438 | |
| 439 | old_sinfo.bh = sinfo.bh = dotdot_bh = NULL; |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 440 | old_inode = d_inode(old_dentry); |
| 441 | new_inode = d_inode(new_dentry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 442 | |
| 443 | err = fat_scan(old_dir, old_name, &old_sinfo); |
| 444 | if (err) { |
| 445 | err = -EIO; |
| 446 | goto out; |
| 447 | } |
| 448 | |
| 449 | is_dir = S_ISDIR(old_inode->i_mode); |
| 450 | update_dotdot = (is_dir && old_dir != new_dir); |
| 451 | if (update_dotdot) { |
Steven J. Magnani | 7669e8f | 2012-10-04 17:14:45 -0700 | [diff] [blame] | 452 | if (fat_get_dotdot_entry(old_inode, &dotdot_bh, &dotdot_de)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 453 | err = -EIO; |
| 454 | goto out; |
| 455 | } |
| 456 | } |
| 457 | |
| 458 | old_attrs = MSDOS_I(old_inode)->i_attrs; |
| 459 | err = fat_scan(new_dir, new_name, &sinfo); |
| 460 | if (!err) { |
| 461 | if (!new_inode) { |
| 462 | /* "foo" -> ".foo" case. just change the ATTR_HIDDEN */ |
| 463 | if (sinfo.de != old_sinfo.de) { |
| 464 | err = -EINVAL; |
| 465 | goto out; |
| 466 | } |
| 467 | if (is_hid) |
| 468 | MSDOS_I(old_inode)->i_attrs |= ATTR_HIDDEN; |
| 469 | else |
| 470 | MSDOS_I(old_inode)->i_attrs &= ~ATTR_HIDDEN; |
| 471 | if (IS_DIRSYNC(old_dir)) { |
| 472 | err = fat_sync_inode(old_inode); |
| 473 | if (err) { |
| 474 | MSDOS_I(old_inode)->i_attrs = old_attrs; |
| 475 | goto out; |
| 476 | } |
| 477 | } else |
| 478 | mark_inode_dirty(old_inode); |
| 479 | |
Jeff Layton | 2489dba | 2017-12-11 06:35:09 -0500 | [diff] [blame] | 480 | inode_inc_iversion(old_dir); |
Deepa Dinamani | 02027d4 | 2016-09-14 07:48:05 -0700 | [diff] [blame] | 481 | old_dir->i_ctime = old_dir->i_mtime = current_time(old_dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 482 | if (IS_DIRSYNC(old_dir)) |
| 483 | (void)fat_sync_inode(old_dir); |
| 484 | else |
| 485 | mark_inode_dirty(old_dir); |
| 486 | goto out; |
| 487 | } |
| 488 | } |
| 489 | |
Deepa Dinamani | 02027d4 | 2016-09-14 07:48:05 -0700 | [diff] [blame] | 490 | ts = current_time(old_inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 491 | if (new_inode) { |
| 492 | if (err) |
| 493 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 494 | if (is_dir) { |
| 495 | err = fat_dir_empty(new_inode); |
| 496 | if (err) |
| 497 | goto out; |
| 498 | } |
OGAWA Hirofumi | 9131dd4 | 2005-10-30 15:03:50 -0800 | [diff] [blame] | 499 | new_i_pos = MSDOS_I(new_inode)->i_pos; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 500 | fat_detach(new_inode); |
| 501 | } else { |
| 502 | err = msdos_add_entry(new_dir, new_name, is_dir, is_hid, 0, |
Arnd Bergmann | f423420 | 2018-08-21 21:59:48 -0700 | [diff] [blame^] | 503 | &ts, &sinfo); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 504 | if (err) |
| 505 | goto out; |
OGAWA Hirofumi | 9131dd4 | 2005-10-30 15:03:50 -0800 | [diff] [blame] | 506 | new_i_pos = sinfo.i_pos; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 507 | } |
Jeff Layton | 2489dba | 2017-12-11 06:35:09 -0500 | [diff] [blame] | 508 | inode_inc_iversion(new_dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 509 | |
| 510 | fat_detach(old_inode); |
OGAWA Hirofumi | 9131dd4 | 2005-10-30 15:03:50 -0800 | [diff] [blame] | 511 | fat_attach(old_inode, new_i_pos); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 512 | if (is_hid) |
| 513 | MSDOS_I(old_inode)->i_attrs |= ATTR_HIDDEN; |
| 514 | else |
| 515 | MSDOS_I(old_inode)->i_attrs &= ~ATTR_HIDDEN; |
| 516 | if (IS_DIRSYNC(new_dir)) { |
| 517 | err = fat_sync_inode(old_inode); |
| 518 | if (err) |
| 519 | goto error_inode; |
| 520 | } else |
| 521 | mark_inode_dirty(old_inode); |
| 522 | |
| 523 | if (update_dotdot) { |
Steven J. Magnani | a943ed7 | 2012-07-30 14:42:13 -0700 | [diff] [blame] | 524 | fat_set_start(dotdot_de, MSDOS_I(new_dir)->i_logstart); |
Al Viro | b522412 | 2009-06-07 13:44:36 -0400 | [diff] [blame] | 525 | mark_buffer_dirty_inode(dotdot_bh, old_inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 526 | if (IS_DIRSYNC(new_dir)) { |
| 527 | err = sync_dirty_buffer(dotdot_bh); |
| 528 | if (err) |
| 529 | goto error_dotdot; |
| 530 | } |
Dave Hansen | 9a53c3a | 2006-09-30 23:29:03 -0700 | [diff] [blame] | 531 | drop_nlink(old_dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 532 | if (!new_inode) |
Dave Hansen | d8c76e6 | 2006-09-30 23:29:04 -0700 | [diff] [blame] | 533 | inc_nlink(new_dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 534 | } |
| 535 | |
| 536 | err = fat_remove_entries(old_dir, &old_sinfo); /* and releases bh */ |
| 537 | old_sinfo.bh = NULL; |
| 538 | if (err) |
| 539 | goto error_dotdot; |
Jeff Layton | 2489dba | 2017-12-11 06:35:09 -0500 | [diff] [blame] | 540 | inode_inc_iversion(old_dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 541 | old_dir->i_ctime = old_dir->i_mtime = ts; |
| 542 | if (IS_DIRSYNC(old_dir)) |
| 543 | (void)fat_sync_inode(old_dir); |
| 544 | else |
| 545 | mark_inode_dirty(old_dir); |
| 546 | |
| 547 | if (new_inode) { |
Dave Hansen | 9a53c3a | 2006-09-30 23:29:03 -0700 | [diff] [blame] | 548 | drop_nlink(new_inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 549 | if (is_dir) |
Dave Hansen | 9a53c3a | 2006-09-30 23:29:03 -0700 | [diff] [blame] | 550 | drop_nlink(new_inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 551 | new_inode->i_ctime = ts; |
| 552 | } |
| 553 | out: |
| 554 | brelse(sinfo.bh); |
| 555 | brelse(dotdot_bh); |
| 556 | brelse(old_sinfo.bh); |
| 557 | return err; |
| 558 | |
| 559 | error_dotdot: |
| 560 | /* data cluster is shared, serious corruption */ |
| 561 | corrupt = 1; |
| 562 | |
| 563 | if (update_dotdot) { |
Steven J. Magnani | a943ed7 | 2012-07-30 14:42:13 -0700 | [diff] [blame] | 564 | fat_set_start(dotdot_de, MSDOS_I(old_dir)->i_logstart); |
Al Viro | b522412 | 2009-06-07 13:44:36 -0400 | [diff] [blame] | 565 | mark_buffer_dirty_inode(dotdot_bh, old_inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 566 | corrupt |= sync_dirty_buffer(dotdot_bh); |
| 567 | } |
| 568 | error_inode: |
| 569 | fat_detach(old_inode); |
| 570 | fat_attach(old_inode, old_sinfo.i_pos); |
| 571 | MSDOS_I(old_inode)->i_attrs = old_attrs; |
| 572 | if (new_inode) { |
OGAWA Hirofumi | 9131dd4 | 2005-10-30 15:03:50 -0800 | [diff] [blame] | 573 | fat_attach(new_inode, new_i_pos); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 574 | if (corrupt) |
| 575 | corrupt |= fat_sync_inode(new_inode); |
| 576 | } else { |
| 577 | /* |
| 578 | * If new entry was not sharing the data cluster, it |
| 579 | * shouldn't be serious corruption. |
| 580 | */ |
| 581 | int err2 = fat_remove_entries(new_dir, &sinfo); |
| 582 | if (corrupt) |
| 583 | corrupt |= err2; |
| 584 | sinfo.bh = NULL; |
| 585 | } |
| 586 | if (corrupt < 0) { |
Denis Karpov | 85c7859 | 2009-06-04 02:34:22 +0900 | [diff] [blame] | 587 | fat_fs_error(new_dir->i_sb, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 588 | "%s: Filesystem corrupted (i_pos %lld)", |
Harvey Harrison | 8e24eea | 2008-04-30 00:55:09 -0700 | [diff] [blame] | 589 | __func__, sinfo.i_pos); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 590 | } |
| 591 | goto out; |
| 592 | } |
| 593 | |
| 594 | /***** Rename, a wrapper for rename_same_dir & rename_diff_dir */ |
| 595 | static int msdos_rename(struct inode *old_dir, struct dentry *old_dentry, |
Miklos Szeredi | f03b8ad | 2016-09-27 11:03:57 +0200 | [diff] [blame] | 596 | struct inode *new_dir, struct dentry *new_dentry, |
| 597 | unsigned int flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 598 | { |
Linus Torvalds | 8f59342 | 2008-05-19 19:53:01 -0700 | [diff] [blame] | 599 | struct super_block *sb = old_dir->i_sb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 600 | unsigned char old_msdos_name[MSDOS_NAME], new_msdos_name[MSDOS_NAME]; |
| 601 | int err, is_hid; |
| 602 | |
Miklos Szeredi | f03b8ad | 2016-09-27 11:03:57 +0200 | [diff] [blame] | 603 | if (flags & ~RENAME_NOREPLACE) |
| 604 | return -EINVAL; |
| 605 | |
Marco Stornelli | e40b34c | 2012-10-06 12:40:03 +0200 | [diff] [blame] | 606 | mutex_lock(&MSDOS_SB(sb)->s_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 607 | |
| 608 | err = msdos_format_name(old_dentry->d_name.name, |
| 609 | old_dentry->d_name.len, old_msdos_name, |
| 610 | &MSDOS_SB(old_dir->i_sb)->options); |
| 611 | if (err) |
| 612 | goto out; |
| 613 | err = msdos_format_name(new_dentry->d_name.name, |
| 614 | new_dentry->d_name.len, new_msdos_name, |
| 615 | &MSDOS_SB(new_dir->i_sb)->options); |
| 616 | if (err) |
| 617 | goto out; |
| 618 | |
| 619 | is_hid = |
| 620 | (new_dentry->d_name.name[0] == '.') && (new_msdos_name[0] != '.'); |
| 621 | |
| 622 | err = do_msdos_rename(old_dir, old_msdos_name, old_dentry, |
| 623 | new_dir, new_msdos_name, new_dentry, is_hid); |
| 624 | out: |
Marco Stornelli | e40b34c | 2012-10-06 12:40:03 +0200 | [diff] [blame] | 625 | mutex_unlock(&MSDOS_SB(sb)->s_lock); |
Chris Mason | ae78bf9 | 2006-09-29 02:00:03 -0700 | [diff] [blame] | 626 | if (!err) |
Linus Torvalds | 8f59342 | 2008-05-19 19:53:01 -0700 | [diff] [blame] | 627 | err = fat_flush_inodes(sb, old_dir, new_dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 628 | return err; |
| 629 | } |
| 630 | |
Arjan van de Ven | 92e1d5b | 2007-02-12 00:55:39 -0800 | [diff] [blame] | 631 | static const struct inode_operations msdos_dir_inode_operations = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 632 | .create = msdos_create, |
| 633 | .lookup = msdos_lookup, |
| 634 | .unlink = msdos_unlink, |
| 635 | .mkdir = msdos_mkdir, |
| 636 | .rmdir = msdos_rmdir, |
| 637 | .rename = msdos_rename, |
OGAWA Hirofumi | 1278fdd | 2008-04-28 02:16:25 -0700 | [diff] [blame] | 638 | .setattr = fat_setattr, |
OGAWA Hirofumi | da63fc7 | 2006-11-16 01:19:28 -0800 | [diff] [blame] | 639 | .getattr = fat_getattr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 640 | }; |
| 641 | |
Al Viro | 3d23985 | 2010-12-18 10:44:00 -0500 | [diff] [blame] | 642 | static void setup(struct super_block *sb) |
| 643 | { |
OGAWA Hirofumi | 384f5c9 | 2011-04-12 21:08:37 +0900 | [diff] [blame] | 644 | MSDOS_SB(sb)->dir_ops = &msdos_dir_inode_operations; |
Al Viro | 3d23985 | 2010-12-18 10:44:00 -0500 | [diff] [blame] | 645 | sb->s_d_op = &msdos_dentry_operations; |
Linus Torvalds | 1751e8a | 2017-11-27 13:05:09 -0800 | [diff] [blame] | 646 | sb->s_flags |= SB_NOATIME; |
Al Viro | 3d23985 | 2010-12-18 10:44:00 -0500 | [diff] [blame] | 647 | } |
| 648 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 649 | static int msdos_fill_super(struct super_block *sb, void *data, int silent) |
| 650 | { |
OGAWA Hirofumi | 384f5c9 | 2011-04-12 21:08:37 +0900 | [diff] [blame] | 651 | return fat_fill_super(sb, data, silent, 0, setup); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 652 | } |
| 653 | |
Al Viro | 152a083 | 2010-07-25 00:46:55 +0400 | [diff] [blame] | 654 | static struct dentry *msdos_mount(struct file_system_type *fs_type, |
David Howells | 454e239 | 2006-06-23 02:02:57 -0700 | [diff] [blame] | 655 | int flags, const char *dev_name, |
Al Viro | 152a083 | 2010-07-25 00:46:55 +0400 | [diff] [blame] | 656 | void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 657 | { |
Al Viro | 152a083 | 2010-07-25 00:46:55 +0400 | [diff] [blame] | 658 | return mount_bdev(fs_type, flags, dev_name, data, msdos_fill_super); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 659 | } |
| 660 | |
| 661 | static struct file_system_type msdos_fs_type = { |
| 662 | .owner = THIS_MODULE, |
| 663 | .name = "msdos", |
Al Viro | 152a083 | 2010-07-25 00:46:55 +0400 | [diff] [blame] | 664 | .mount = msdos_mount, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 665 | .kill_sb = kill_block_super, |
| 666 | .fs_flags = FS_REQUIRES_DEV, |
| 667 | }; |
Eric W. Biederman | 7f78e03 | 2013-03-02 19:39:14 -0800 | [diff] [blame] | 668 | MODULE_ALIAS_FS("msdos"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 669 | |
| 670 | static int __init init_msdos_fs(void) |
| 671 | { |
| 672 | return register_filesystem(&msdos_fs_type); |
| 673 | } |
| 674 | |
| 675 | static void __exit exit_msdos_fs(void) |
| 676 | { |
| 677 | unregister_filesystem(&msdos_fs_type); |
| 678 | } |
| 679 | |
| 680 | MODULE_LICENSE("GPL"); |
| 681 | MODULE_AUTHOR("Werner Almesberger"); |
| 682 | MODULE_DESCRIPTION("MS-DOS filesystem support"); |
| 683 | |
| 684 | module_init(init_msdos_fs) |
| 685 | module_exit(exit_msdos_fs) |