namei_msdos.c 17 KB

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