namei.c 17 KB

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