namei_msdos.c 17 KB

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