namei_msdos.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685
  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 timespec64 *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 timespec64 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. err = fat_dir_empty(inode);
  289. if (err)
  290. goto out;
  291. err = msdos_find(dir, dentry->d_name.name, dentry->d_name.len, &sinfo);
  292. if (err)
  293. goto out;
  294. err = fat_remove_entries(dir, &sinfo); /* and releases bh */
  295. if (err)
  296. goto out;
  297. drop_nlink(dir);
  298. clear_nlink(inode);
  299. inode->i_ctime = current_time(inode);
  300. fat_detach(inode);
  301. out:
  302. mutex_unlock(&MSDOS_SB(sb)->s_lock);
  303. if (!err)
  304. err = fat_flush_inodes(sb, dir, inode);
  305. return err;
  306. }
  307. /***** Make a directory */
  308. static int msdos_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
  309. {
  310. struct super_block *sb = dir->i_sb;
  311. struct fat_slot_info sinfo;
  312. struct inode *inode;
  313. unsigned char msdos_name[MSDOS_NAME];
  314. struct timespec64 ts;
  315. int err, is_hid, cluster;
  316. mutex_lock(&MSDOS_SB(sb)->s_lock);
  317. err = msdos_format_name(dentry->d_name.name, dentry->d_name.len,
  318. msdos_name, &MSDOS_SB(sb)->options);
  319. if (err)
  320. goto out;
  321. is_hid = (dentry->d_name.name[0] == '.') && (msdos_name[0] != '.');
  322. /* foo vs .foo situation */
  323. if (!fat_scan(dir, msdos_name, &sinfo)) {
  324. brelse(sinfo.bh);
  325. err = -EINVAL;
  326. goto out;
  327. }
  328. ts = current_time(dir);
  329. cluster = fat_alloc_new_dir(dir, &ts);
  330. if (cluster < 0) {
  331. err = cluster;
  332. goto out;
  333. }
  334. err = msdos_add_entry(dir, msdos_name, 1, is_hid, cluster, &ts, &sinfo);
  335. if (err)
  336. goto out_free;
  337. inc_nlink(dir);
  338. inode = fat_build_inode(sb, sinfo.de, sinfo.i_pos);
  339. brelse(sinfo.bh);
  340. if (IS_ERR(inode)) {
  341. err = PTR_ERR(inode);
  342. /* the directory was completed, just return a error */
  343. goto out;
  344. }
  345. set_nlink(inode, 2);
  346. inode->i_mtime = inode->i_atime = inode->i_ctime = ts;
  347. /* timestamp is already written, so mark_inode_dirty() is unneeded. */
  348. d_instantiate(dentry, inode);
  349. mutex_unlock(&MSDOS_SB(sb)->s_lock);
  350. fat_flush_inodes(sb, dir, inode);
  351. return 0;
  352. out_free:
  353. fat_free_clusters(dir, cluster);
  354. out:
  355. mutex_unlock(&MSDOS_SB(sb)->s_lock);
  356. return err;
  357. }
  358. /***** Unlink a file */
  359. static int msdos_unlink(struct inode *dir, struct dentry *dentry)
  360. {
  361. struct inode *inode = d_inode(dentry);
  362. struct super_block *sb = inode->i_sb;
  363. struct fat_slot_info sinfo;
  364. int err;
  365. mutex_lock(&MSDOS_SB(sb)->s_lock);
  366. err = msdos_find(dir, dentry->d_name.name, dentry->d_name.len, &sinfo);
  367. if (err)
  368. goto out;
  369. err = fat_remove_entries(dir, &sinfo); /* and releases bh */
  370. if (err)
  371. goto out;
  372. clear_nlink(inode);
  373. inode->i_ctime = current_time(inode);
  374. fat_detach(inode);
  375. out:
  376. mutex_unlock(&MSDOS_SB(sb)->s_lock);
  377. if (!err)
  378. err = fat_flush_inodes(sb, dir, inode);
  379. return err;
  380. }
  381. static int do_msdos_rename(struct inode *old_dir, unsigned char *old_name,
  382. struct dentry *old_dentry,
  383. struct inode *new_dir, unsigned char *new_name,
  384. struct dentry *new_dentry, int is_hid)
  385. {
  386. struct buffer_head *dotdot_bh;
  387. struct msdos_dir_entry *dotdot_de;
  388. struct inode *old_inode, *new_inode;
  389. struct fat_slot_info old_sinfo, sinfo;
  390. struct timespec64 ts;
  391. loff_t new_i_pos;
  392. int err, old_attrs, is_dir, update_dotdot, corrupt = 0;
  393. old_sinfo.bh = sinfo.bh = dotdot_bh = NULL;
  394. old_inode = d_inode(old_dentry);
  395. new_inode = d_inode(new_dentry);
  396. err = fat_scan(old_dir, old_name, &old_sinfo);
  397. if (err) {
  398. err = -EIO;
  399. goto out;
  400. }
  401. is_dir = S_ISDIR(old_inode->i_mode);
  402. update_dotdot = (is_dir && old_dir != new_dir);
  403. if (update_dotdot) {
  404. if (fat_get_dotdot_entry(old_inode, &dotdot_bh, &dotdot_de)) {
  405. err = -EIO;
  406. goto out;
  407. }
  408. }
  409. old_attrs = MSDOS_I(old_inode)->i_attrs;
  410. err = fat_scan(new_dir, new_name, &sinfo);
  411. if (!err) {
  412. if (!new_inode) {
  413. /* "foo" -> ".foo" case. just change the ATTR_HIDDEN */
  414. if (sinfo.de != old_sinfo.de) {
  415. err = -EINVAL;
  416. goto out;
  417. }
  418. if (is_hid)
  419. MSDOS_I(old_inode)->i_attrs |= ATTR_HIDDEN;
  420. else
  421. MSDOS_I(old_inode)->i_attrs &= ~ATTR_HIDDEN;
  422. if (IS_DIRSYNC(old_dir)) {
  423. err = fat_sync_inode(old_inode);
  424. if (err) {
  425. MSDOS_I(old_inode)->i_attrs = old_attrs;
  426. goto out;
  427. }
  428. } else
  429. mark_inode_dirty(old_inode);
  430. inode_inc_iversion(old_dir);
  431. old_dir->i_ctime = old_dir->i_mtime = current_time(old_dir);
  432. if (IS_DIRSYNC(old_dir))
  433. (void)fat_sync_inode(old_dir);
  434. else
  435. mark_inode_dirty(old_dir);
  436. goto out;
  437. }
  438. }
  439. ts = current_time(old_inode);
  440. if (new_inode) {
  441. if (err)
  442. goto out;
  443. if (is_dir) {
  444. err = fat_dir_empty(new_inode);
  445. if (err)
  446. goto out;
  447. }
  448. new_i_pos = MSDOS_I(new_inode)->i_pos;
  449. fat_detach(new_inode);
  450. } else {
  451. err = msdos_add_entry(new_dir, new_name, is_dir, is_hid, 0,
  452. &ts, &sinfo);
  453. if (err)
  454. goto out;
  455. new_i_pos = sinfo.i_pos;
  456. }
  457. inode_inc_iversion(new_dir);
  458. fat_detach(old_inode);
  459. fat_attach(old_inode, new_i_pos);
  460. if (is_hid)
  461. MSDOS_I(old_inode)->i_attrs |= ATTR_HIDDEN;
  462. else
  463. MSDOS_I(old_inode)->i_attrs &= ~ATTR_HIDDEN;
  464. if (IS_DIRSYNC(new_dir)) {
  465. err = fat_sync_inode(old_inode);
  466. if (err)
  467. goto error_inode;
  468. } else
  469. mark_inode_dirty(old_inode);
  470. if (update_dotdot) {
  471. fat_set_start(dotdot_de, MSDOS_I(new_dir)->i_logstart);
  472. mark_buffer_dirty_inode(dotdot_bh, old_inode);
  473. if (IS_DIRSYNC(new_dir)) {
  474. err = sync_dirty_buffer(dotdot_bh);
  475. if (err)
  476. goto error_dotdot;
  477. }
  478. drop_nlink(old_dir);
  479. if (!new_inode)
  480. inc_nlink(new_dir);
  481. }
  482. err = fat_remove_entries(old_dir, &old_sinfo); /* and releases bh */
  483. old_sinfo.bh = NULL;
  484. if (err)
  485. goto error_dotdot;
  486. inode_inc_iversion(old_dir);
  487. old_dir->i_ctime = old_dir->i_mtime = ts;
  488. if (IS_DIRSYNC(old_dir))
  489. (void)fat_sync_inode(old_dir);
  490. else
  491. mark_inode_dirty(old_dir);
  492. if (new_inode) {
  493. drop_nlink(new_inode);
  494. if (is_dir)
  495. drop_nlink(new_inode);
  496. new_inode->i_ctime = ts;
  497. }
  498. out:
  499. brelse(sinfo.bh);
  500. brelse(dotdot_bh);
  501. brelse(old_sinfo.bh);
  502. return err;
  503. error_dotdot:
  504. /* data cluster is shared, serious corruption */
  505. corrupt = 1;
  506. if (update_dotdot) {
  507. fat_set_start(dotdot_de, MSDOS_I(old_dir)->i_logstart);
  508. mark_buffer_dirty_inode(dotdot_bh, old_inode);
  509. corrupt |= sync_dirty_buffer(dotdot_bh);
  510. }
  511. error_inode:
  512. fat_detach(old_inode);
  513. fat_attach(old_inode, old_sinfo.i_pos);
  514. MSDOS_I(old_inode)->i_attrs = old_attrs;
  515. if (new_inode) {
  516. fat_attach(new_inode, new_i_pos);
  517. if (corrupt)
  518. corrupt |= fat_sync_inode(new_inode);
  519. } else {
  520. /*
  521. * If new entry was not sharing the data cluster, it
  522. * shouldn't be serious corruption.
  523. */
  524. int err2 = fat_remove_entries(new_dir, &sinfo);
  525. if (corrupt)
  526. corrupt |= err2;
  527. sinfo.bh = NULL;
  528. }
  529. if (corrupt < 0) {
  530. fat_fs_error(new_dir->i_sb,
  531. "%s: Filesystem corrupted (i_pos %lld)",
  532. __func__, sinfo.i_pos);
  533. }
  534. goto out;
  535. }
  536. /***** Rename, a wrapper for rename_same_dir & rename_diff_dir */
  537. static int msdos_rename(struct inode *old_dir, struct dentry *old_dentry,
  538. struct inode *new_dir, struct dentry *new_dentry,
  539. unsigned int flags)
  540. {
  541. struct super_block *sb = old_dir->i_sb;
  542. unsigned char old_msdos_name[MSDOS_NAME], new_msdos_name[MSDOS_NAME];
  543. int err, is_hid;
  544. if (flags & ~RENAME_NOREPLACE)
  545. return -EINVAL;
  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 |= SB_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)