namei_msdos.c 17 KB

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