namei_msdos.c 17 KB

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