namei_msdos.c 17 KB

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