namei_msdos.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688
  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, const struct inode *inode,
  143. struct qstr *qstr)
  144. {
  145. struct fat_mount_options *options = &MSDOS_SB(dentry->d_sb)->options;
  146. unsigned char msdos_name[MSDOS_NAME];
  147. int error;
  148. error = msdos_format_name(qstr->name, qstr->len, msdos_name, options);
  149. if (!error)
  150. qstr->hash = full_name_hash(msdos_name, MSDOS_NAME);
  151. return 0;
  152. }
  153. /*
  154. * Compare two msdos names. If either of the names are invalid,
  155. * we fall back to doing the standard name comparison.
  156. */
  157. static int msdos_cmp(const struct dentry *parent, const struct inode *pinode,
  158. const struct dentry *dentry, const struct inode *inode,
  159. unsigned int len, const char *str, const struct qstr *name)
  160. {
  161. struct fat_mount_options *options = &MSDOS_SB(parent->d_sb)->options;
  162. unsigned char a_msdos_name[MSDOS_NAME], b_msdos_name[MSDOS_NAME];
  163. int error;
  164. error = msdos_format_name(name->name, name->len, a_msdos_name, options);
  165. if (error)
  166. goto old_compare;
  167. error = msdos_format_name(str, len, b_msdos_name, options);
  168. if (error)
  169. goto old_compare;
  170. error = memcmp(a_msdos_name, b_msdos_name, MSDOS_NAME);
  171. out:
  172. return error;
  173. old_compare:
  174. error = 1;
  175. if (name->len == len)
  176. error = memcmp(name->name, str, len);
  177. goto out;
  178. }
  179. static const struct dentry_operations msdos_dentry_operations = {
  180. .d_hash = msdos_hash,
  181. .d_compare = msdos_cmp,
  182. };
  183. /*
  184. * AV. Wrappers for FAT sb operations. Is it wise?
  185. */
  186. /***** Get inode using directory and name */
  187. static struct dentry *msdos_lookup(struct inode *dir, struct dentry *dentry,
  188. unsigned int flags)
  189. {
  190. struct super_block *sb = dir->i_sb;
  191. struct fat_slot_info sinfo;
  192. struct inode *inode;
  193. int err;
  194. mutex_lock(&MSDOS_SB(sb)->s_lock);
  195. err = msdos_find(dir, dentry->d_name.name, dentry->d_name.len, &sinfo);
  196. switch (err) {
  197. case -ENOENT:
  198. inode = NULL;
  199. break;
  200. case 0:
  201. inode = fat_build_inode(sb, sinfo.de, sinfo.i_pos);
  202. brelse(sinfo.bh);
  203. break;
  204. default:
  205. inode = ERR_PTR(err);
  206. }
  207. mutex_unlock(&MSDOS_SB(sb)->s_lock);
  208. return d_splice_alias(inode, dentry);
  209. }
  210. /***** Creates a directory entry (name is already formatted). */
  211. static int msdos_add_entry(struct inode *dir, const unsigned char *name,
  212. int is_dir, int is_hid, int cluster,
  213. struct timespec *ts, struct fat_slot_info *sinfo)
  214. {
  215. struct msdos_sb_info *sbi = MSDOS_SB(dir->i_sb);
  216. struct msdos_dir_entry de;
  217. __le16 time, date;
  218. int err;
  219. memcpy(de.name, name, MSDOS_NAME);
  220. de.attr = is_dir ? ATTR_DIR : ATTR_ARCH;
  221. if (is_hid)
  222. de.attr |= ATTR_HIDDEN;
  223. de.lcase = 0;
  224. fat_time_unix2fat(sbi, ts, &time, &date, NULL);
  225. de.cdate = de.adate = 0;
  226. de.ctime = 0;
  227. de.ctime_cs = 0;
  228. de.time = time;
  229. de.date = date;
  230. fat_set_start(&de, cluster);
  231. de.size = 0;
  232. err = fat_add_entries(dir, &de, 1, sinfo);
  233. if (err)
  234. return err;
  235. dir->i_ctime = dir->i_mtime = *ts;
  236. if (IS_DIRSYNC(dir))
  237. (void)fat_sync_inode(dir);
  238. else
  239. mark_inode_dirty(dir);
  240. return 0;
  241. }
  242. /***** Create a file */
  243. static int msdos_create(struct inode *dir, struct dentry *dentry, umode_t mode,
  244. bool excl)
  245. {
  246. struct super_block *sb = dir->i_sb;
  247. struct inode *inode = NULL;
  248. struct fat_slot_info sinfo;
  249. struct timespec ts;
  250. unsigned char msdos_name[MSDOS_NAME];
  251. int err, is_hid;
  252. mutex_lock(&MSDOS_SB(sb)->s_lock);
  253. err = msdos_format_name(dentry->d_name.name, dentry->d_name.len,
  254. msdos_name, &MSDOS_SB(sb)->options);
  255. if (err)
  256. goto out;
  257. is_hid = (dentry->d_name.name[0] == '.') && (msdos_name[0] != '.');
  258. /* Have to do it due to foo vs. .foo conflicts */
  259. if (!fat_scan(dir, msdos_name, &sinfo)) {
  260. brelse(sinfo.bh);
  261. err = -EINVAL;
  262. goto out;
  263. }
  264. ts = CURRENT_TIME_SEC;
  265. err = msdos_add_entry(dir, msdos_name, 0, is_hid, 0, &ts, &sinfo);
  266. if (err)
  267. goto out;
  268. inode = fat_build_inode(sb, sinfo.de, sinfo.i_pos);
  269. brelse(sinfo.bh);
  270. if (IS_ERR(inode)) {
  271. err = PTR_ERR(inode);
  272. goto out;
  273. }
  274. inode->i_mtime = inode->i_atime = inode->i_ctime = ts;
  275. /* timestamp is already written, so mark_inode_dirty() is unneeded. */
  276. d_instantiate(dentry, inode);
  277. out:
  278. mutex_unlock(&MSDOS_SB(sb)->s_lock);
  279. if (!err)
  280. err = fat_flush_inodes(sb, dir, inode);
  281. return err;
  282. }
  283. /***** Remove a directory */
  284. static int msdos_rmdir(struct inode *dir, struct dentry *dentry)
  285. {
  286. struct super_block *sb = dir->i_sb;
  287. struct inode *inode = dentry->d_inode;
  288. struct fat_slot_info sinfo;
  289. int err;
  290. mutex_lock(&MSDOS_SB(sb)->s_lock);
  291. /*
  292. * Check whether the directory is not in use, then check
  293. * whether it is empty.
  294. */
  295. err = fat_dir_empty(inode);
  296. if (err)
  297. goto out;
  298. err = msdos_find(dir, dentry->d_name.name, dentry->d_name.len, &sinfo);
  299. if (err)
  300. goto out;
  301. err = fat_remove_entries(dir, &sinfo); /* and releases bh */
  302. if (err)
  303. goto out;
  304. drop_nlink(dir);
  305. clear_nlink(inode);
  306. inode->i_ctime = CURRENT_TIME_SEC;
  307. fat_detach(inode);
  308. out:
  309. mutex_unlock(&MSDOS_SB(sb)->s_lock);
  310. if (!err)
  311. err = fat_flush_inodes(sb, dir, inode);
  312. return err;
  313. }
  314. /***** Make a directory */
  315. static int msdos_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
  316. {
  317. struct super_block *sb = dir->i_sb;
  318. struct fat_slot_info sinfo;
  319. struct inode *inode;
  320. unsigned char msdos_name[MSDOS_NAME];
  321. struct timespec ts;
  322. int err, is_hid, cluster;
  323. mutex_lock(&MSDOS_SB(sb)->s_lock);
  324. err = msdos_format_name(dentry->d_name.name, dentry->d_name.len,
  325. msdos_name, &MSDOS_SB(sb)->options);
  326. if (err)
  327. goto out;
  328. is_hid = (dentry->d_name.name[0] == '.') && (msdos_name[0] != '.');
  329. /* foo vs .foo situation */
  330. if (!fat_scan(dir, msdos_name, &sinfo)) {
  331. brelse(sinfo.bh);
  332. err = -EINVAL;
  333. goto out;
  334. }
  335. ts = CURRENT_TIME_SEC;
  336. cluster = fat_alloc_new_dir(dir, &ts);
  337. if (cluster < 0) {
  338. err = cluster;
  339. goto out;
  340. }
  341. err = msdos_add_entry(dir, msdos_name, 1, is_hid, cluster, &ts, &sinfo);
  342. if (err)
  343. goto out_free;
  344. inc_nlink(dir);
  345. inode = fat_build_inode(sb, sinfo.de, sinfo.i_pos);
  346. brelse(sinfo.bh);
  347. if (IS_ERR(inode)) {
  348. err = PTR_ERR(inode);
  349. /* the directory was completed, just return a error */
  350. goto out;
  351. }
  352. set_nlink(inode, 2);
  353. inode->i_mtime = inode->i_atime = inode->i_ctime = ts;
  354. /* timestamp is already written, so mark_inode_dirty() is unneeded. */
  355. d_instantiate(dentry, inode);
  356. mutex_unlock(&MSDOS_SB(sb)->s_lock);
  357. fat_flush_inodes(sb, dir, inode);
  358. return 0;
  359. out_free:
  360. fat_free_clusters(dir, cluster);
  361. out:
  362. mutex_unlock(&MSDOS_SB(sb)->s_lock);
  363. return err;
  364. }
  365. /***** Unlink a file */
  366. static int msdos_unlink(struct inode *dir, struct dentry *dentry)
  367. {
  368. struct inode *inode = dentry->d_inode;
  369. struct super_block *sb = inode->i_sb;
  370. struct fat_slot_info sinfo;
  371. int err;
  372. mutex_lock(&MSDOS_SB(sb)->s_lock);
  373. err = msdos_find(dir, dentry->d_name.name, dentry->d_name.len, &sinfo);
  374. if (err)
  375. goto out;
  376. err = fat_remove_entries(dir, &sinfo); /* and releases bh */
  377. if (err)
  378. goto out;
  379. clear_nlink(inode);
  380. inode->i_ctime = CURRENT_TIME_SEC;
  381. fat_detach(inode);
  382. out:
  383. mutex_unlock(&MSDOS_SB(sb)->s_lock);
  384. if (!err)
  385. err = fat_flush_inodes(sb, dir, inode);
  386. return err;
  387. }
  388. static int do_msdos_rename(struct inode *old_dir, unsigned char *old_name,
  389. struct dentry *old_dentry,
  390. struct inode *new_dir, unsigned char *new_name,
  391. struct dentry *new_dentry, int is_hid)
  392. {
  393. struct buffer_head *dotdot_bh;
  394. struct msdos_dir_entry *dotdot_de;
  395. struct inode *old_inode, *new_inode;
  396. struct fat_slot_info old_sinfo, sinfo;
  397. struct timespec ts;
  398. loff_t new_i_pos;
  399. int err, old_attrs, is_dir, update_dotdot, corrupt = 0;
  400. old_sinfo.bh = sinfo.bh = dotdot_bh = NULL;
  401. old_inode = old_dentry->d_inode;
  402. new_inode = new_dentry->d_inode;
  403. err = fat_scan(old_dir, old_name, &old_sinfo);
  404. if (err) {
  405. err = -EIO;
  406. goto out;
  407. }
  408. is_dir = S_ISDIR(old_inode->i_mode);
  409. update_dotdot = (is_dir && old_dir != new_dir);
  410. if (update_dotdot) {
  411. if (fat_get_dotdot_entry(old_inode, &dotdot_bh, &dotdot_de)) {
  412. err = -EIO;
  413. goto out;
  414. }
  415. }
  416. old_attrs = MSDOS_I(old_inode)->i_attrs;
  417. err = fat_scan(new_dir, new_name, &sinfo);
  418. if (!err) {
  419. if (!new_inode) {
  420. /* "foo" -> ".foo" case. just change the ATTR_HIDDEN */
  421. if (sinfo.de != old_sinfo.de) {
  422. err = -EINVAL;
  423. goto out;
  424. }
  425. if (is_hid)
  426. MSDOS_I(old_inode)->i_attrs |= ATTR_HIDDEN;
  427. else
  428. MSDOS_I(old_inode)->i_attrs &= ~ATTR_HIDDEN;
  429. if (IS_DIRSYNC(old_dir)) {
  430. err = fat_sync_inode(old_inode);
  431. if (err) {
  432. MSDOS_I(old_inode)->i_attrs = old_attrs;
  433. goto out;
  434. }
  435. } else
  436. mark_inode_dirty(old_inode);
  437. old_dir->i_version++;
  438. old_dir->i_ctime = old_dir->i_mtime = CURRENT_TIME_SEC;
  439. if (IS_DIRSYNC(old_dir))
  440. (void)fat_sync_inode(old_dir);
  441. else
  442. mark_inode_dirty(old_dir);
  443. goto out;
  444. }
  445. }
  446. ts = CURRENT_TIME_SEC;
  447. if (new_inode) {
  448. if (err)
  449. goto out;
  450. if (is_dir) {
  451. err = fat_dir_empty(new_inode);
  452. if (err)
  453. goto out;
  454. }
  455. new_i_pos = MSDOS_I(new_inode)->i_pos;
  456. fat_detach(new_inode);
  457. } else {
  458. err = msdos_add_entry(new_dir, new_name, is_dir, is_hid, 0,
  459. &ts, &sinfo);
  460. if (err)
  461. goto out;
  462. new_i_pos = sinfo.i_pos;
  463. }
  464. new_dir->i_version++;
  465. fat_detach(old_inode);
  466. fat_attach(old_inode, new_i_pos);
  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(new_dir)) {
  472. err = fat_sync_inode(old_inode);
  473. if (err)
  474. goto error_inode;
  475. } else
  476. mark_inode_dirty(old_inode);
  477. if (update_dotdot) {
  478. fat_set_start(dotdot_de, MSDOS_I(new_dir)->i_logstart);
  479. mark_buffer_dirty_inode(dotdot_bh, old_inode);
  480. if (IS_DIRSYNC(new_dir)) {
  481. err = sync_dirty_buffer(dotdot_bh);
  482. if (err)
  483. goto error_dotdot;
  484. }
  485. drop_nlink(old_dir);
  486. if (!new_inode)
  487. inc_nlink(new_dir);
  488. }
  489. err = fat_remove_entries(old_dir, &old_sinfo); /* and releases bh */
  490. old_sinfo.bh = NULL;
  491. if (err)
  492. goto error_dotdot;
  493. old_dir->i_version++;
  494. old_dir->i_ctime = old_dir->i_mtime = ts;
  495. if (IS_DIRSYNC(old_dir))
  496. (void)fat_sync_inode(old_dir);
  497. else
  498. mark_inode_dirty(old_dir);
  499. if (new_inode) {
  500. drop_nlink(new_inode);
  501. if (is_dir)
  502. drop_nlink(new_inode);
  503. new_inode->i_ctime = ts;
  504. }
  505. out:
  506. brelse(sinfo.bh);
  507. brelse(dotdot_bh);
  508. brelse(old_sinfo.bh);
  509. return err;
  510. error_dotdot:
  511. /* data cluster is shared, serious corruption */
  512. corrupt = 1;
  513. if (update_dotdot) {
  514. fat_set_start(dotdot_de, MSDOS_I(old_dir)->i_logstart);
  515. mark_buffer_dirty_inode(dotdot_bh, old_inode);
  516. corrupt |= sync_dirty_buffer(dotdot_bh);
  517. }
  518. error_inode:
  519. fat_detach(old_inode);
  520. fat_attach(old_inode, old_sinfo.i_pos);
  521. MSDOS_I(old_inode)->i_attrs = old_attrs;
  522. if (new_inode) {
  523. fat_attach(new_inode, new_i_pos);
  524. if (corrupt)
  525. corrupt |= fat_sync_inode(new_inode);
  526. } else {
  527. /*
  528. * If new entry was not sharing the data cluster, it
  529. * shouldn't be serious corruption.
  530. */
  531. int err2 = fat_remove_entries(new_dir, &sinfo);
  532. if (corrupt)
  533. corrupt |= err2;
  534. sinfo.bh = NULL;
  535. }
  536. if (corrupt < 0) {
  537. fat_fs_error(new_dir->i_sb,
  538. "%s: Filesystem corrupted (i_pos %lld)",
  539. __func__, sinfo.i_pos);
  540. }
  541. goto out;
  542. }
  543. /***** Rename, a wrapper for rename_same_dir & rename_diff_dir */
  544. static int msdos_rename(struct inode *old_dir, struct dentry *old_dentry,
  545. struct inode *new_dir, struct dentry *new_dentry)
  546. {
  547. struct super_block *sb = old_dir->i_sb;
  548. unsigned char old_msdos_name[MSDOS_NAME], new_msdos_name[MSDOS_NAME];
  549. int err, is_hid;
  550. mutex_lock(&MSDOS_SB(sb)->s_lock);
  551. err = msdos_format_name(old_dentry->d_name.name,
  552. old_dentry->d_name.len, old_msdos_name,
  553. &MSDOS_SB(old_dir->i_sb)->options);
  554. if (err)
  555. goto out;
  556. err = msdos_format_name(new_dentry->d_name.name,
  557. new_dentry->d_name.len, new_msdos_name,
  558. &MSDOS_SB(new_dir->i_sb)->options);
  559. if (err)
  560. goto out;
  561. is_hid =
  562. (new_dentry->d_name.name[0] == '.') && (new_msdos_name[0] != '.');
  563. err = do_msdos_rename(old_dir, old_msdos_name, old_dentry,
  564. new_dir, new_msdos_name, new_dentry, is_hid);
  565. out:
  566. mutex_unlock(&MSDOS_SB(sb)->s_lock);
  567. if (!err)
  568. err = fat_flush_inodes(sb, old_dir, new_dir);
  569. return err;
  570. }
  571. static const struct inode_operations msdos_dir_inode_operations = {
  572. .create = msdos_create,
  573. .lookup = msdos_lookup,
  574. .unlink = msdos_unlink,
  575. .mkdir = msdos_mkdir,
  576. .rmdir = msdos_rmdir,
  577. .rename = msdos_rename,
  578. .setattr = fat_setattr,
  579. .getattr = fat_getattr,
  580. };
  581. static void setup(struct super_block *sb)
  582. {
  583. MSDOS_SB(sb)->dir_ops = &msdos_dir_inode_operations;
  584. sb->s_d_op = &msdos_dentry_operations;
  585. sb->s_flags |= MS_NOATIME;
  586. }
  587. static int msdos_fill_super(struct super_block *sb, void *data, int silent)
  588. {
  589. return fat_fill_super(sb, data, silent, 0, setup);
  590. }
  591. static struct dentry *msdos_mount(struct file_system_type *fs_type,
  592. int flags, const char *dev_name,
  593. void *data)
  594. {
  595. return mount_bdev(fs_type, flags, dev_name, data, msdos_fill_super);
  596. }
  597. static struct file_system_type msdos_fs_type = {
  598. .owner = THIS_MODULE,
  599. .name = "msdos",
  600. .mount = msdos_mount,
  601. .kill_sb = kill_block_super,
  602. .fs_flags = FS_REQUIRES_DEV,
  603. };
  604. MODULE_ALIAS_FS("msdos");
  605. static int __init init_msdos_fs(void)
  606. {
  607. return register_filesystem(&msdos_fs_type);
  608. }
  609. static void __exit exit_msdos_fs(void)
  610. {
  611. unregister_filesystem(&msdos_fs_type);
  612. }
  613. MODULE_LICENSE("GPL");
  614. MODULE_AUTHOR("Werner Almesberger");
  615. MODULE_DESCRIPTION("MS-DOS filesystem support");
  616. module_init(init_msdos_fs)
  617. module_exit(exit_msdos_fs)