namei.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624
  1. /*
  2. * linux/fs/hpfs/namei.c
  3. *
  4. * Mikulas Patocka (mikulas@artax.karlin.mff.cuni.cz), 1998-1999
  5. *
  6. * adding & removing files & directories
  7. */
  8. #include <linux/sched.h>
  9. #include "hpfs_fn.h"
  10. static void hpfs_update_directory_times(struct inode *dir)
  11. {
  12. time_t t = get_seconds();
  13. if (t == dir->i_mtime.tv_sec &&
  14. t == dir->i_ctime.tv_sec)
  15. return;
  16. dir->i_mtime.tv_sec = dir->i_ctime.tv_sec = t;
  17. dir->i_mtime.tv_nsec = dir->i_ctime.tv_nsec = 0;
  18. hpfs_write_inode_nolock(dir);
  19. }
  20. static int hpfs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
  21. {
  22. const unsigned char *name = dentry->d_name.name;
  23. unsigned len = dentry->d_name.len;
  24. struct quad_buffer_head qbh0;
  25. struct buffer_head *bh;
  26. struct hpfs_dirent *de;
  27. struct fnode *fnode;
  28. struct dnode *dnode;
  29. struct inode *result;
  30. fnode_secno fno;
  31. dnode_secno dno;
  32. int r;
  33. struct hpfs_dirent dee;
  34. int err;
  35. if ((err = hpfs_chk_name(name, &len))) return err==-ENOENT ? -EINVAL : err;
  36. hpfs_lock(dir->i_sb);
  37. err = -ENOSPC;
  38. fnode = hpfs_alloc_fnode(dir->i_sb, hpfs_i(dir)->i_dno, &fno, &bh);
  39. if (!fnode)
  40. goto bail;
  41. dnode = hpfs_alloc_dnode(dir->i_sb, fno, &dno, &qbh0);
  42. if (!dnode)
  43. goto bail1;
  44. memset(&dee, 0, sizeof dee);
  45. dee.directory = 1;
  46. if (!(mode & 0222)) dee.read_only = 1;
  47. /*dee.archive = 0;*/
  48. dee.hidden = name[0] == '.';
  49. dee.fnode = cpu_to_le32(fno);
  50. dee.creation_date = dee.write_date = dee.read_date = cpu_to_le32(gmt_to_local(dir->i_sb, get_seconds()));
  51. result = new_inode(dir->i_sb);
  52. if (!result)
  53. goto bail2;
  54. hpfs_init_inode(result);
  55. result->i_ino = fno;
  56. hpfs_i(result)->i_parent_dir = dir->i_ino;
  57. hpfs_i(result)->i_dno = dno;
  58. result->i_ctime.tv_sec = result->i_mtime.tv_sec = result->i_atime.tv_sec = local_to_gmt(dir->i_sb, le32_to_cpu(dee.creation_date));
  59. result->i_ctime.tv_nsec = 0;
  60. result->i_mtime.tv_nsec = 0;
  61. result->i_atime.tv_nsec = 0;
  62. hpfs_i(result)->i_ea_size = 0;
  63. result->i_mode |= S_IFDIR;
  64. result->i_op = &hpfs_dir_iops;
  65. result->i_fop = &hpfs_dir_ops;
  66. result->i_blocks = 4;
  67. result->i_size = 2048;
  68. set_nlink(result, 2);
  69. if (dee.read_only)
  70. result->i_mode &= ~0222;
  71. r = hpfs_add_dirent(dir, name, len, &dee);
  72. if (r == 1)
  73. goto bail3;
  74. if (r == -1) {
  75. err = -EEXIST;
  76. goto bail3;
  77. }
  78. fnode->len = len;
  79. memcpy(fnode->name, name, len > 15 ? 15 : len);
  80. fnode->up = cpu_to_le32(dir->i_ino);
  81. fnode->flags |= FNODE_dir;
  82. fnode->btree.n_free_nodes = 7;
  83. fnode->btree.n_used_nodes = 1;
  84. fnode->btree.first_free = cpu_to_le16(0x14);
  85. fnode->u.external[0].disk_secno = cpu_to_le32(dno);
  86. fnode->u.external[0].file_secno = cpu_to_le32(-1);
  87. dnode->root_dnode = 1;
  88. dnode->up = cpu_to_le32(fno);
  89. de = hpfs_add_de(dir->i_sb, dnode, "\001\001", 2, 0);
  90. de->creation_date = de->write_date = de->read_date = cpu_to_le32(gmt_to_local(dir->i_sb, get_seconds()));
  91. if (!(mode & 0222)) de->read_only = 1;
  92. de->first = de->directory = 1;
  93. /*de->hidden = de->system = 0;*/
  94. de->fnode = cpu_to_le32(fno);
  95. mark_buffer_dirty(bh);
  96. brelse(bh);
  97. hpfs_mark_4buffers_dirty(&qbh0);
  98. hpfs_brelse4(&qbh0);
  99. inc_nlink(dir);
  100. insert_inode_hash(result);
  101. if (!uid_eq(result->i_uid, current_fsuid()) ||
  102. !gid_eq(result->i_gid, current_fsgid()) ||
  103. result->i_mode != (mode | S_IFDIR)) {
  104. result->i_uid = current_fsuid();
  105. result->i_gid = current_fsgid();
  106. result->i_mode = mode | S_IFDIR;
  107. hpfs_write_inode_nolock(result);
  108. }
  109. hpfs_update_directory_times(dir);
  110. d_instantiate(dentry, result);
  111. hpfs_unlock(dir->i_sb);
  112. return 0;
  113. bail3:
  114. iput(result);
  115. bail2:
  116. hpfs_brelse4(&qbh0);
  117. hpfs_free_dnode(dir->i_sb, dno);
  118. bail1:
  119. brelse(bh);
  120. hpfs_free_sectors(dir->i_sb, fno, 1);
  121. bail:
  122. hpfs_unlock(dir->i_sb);
  123. return err;
  124. }
  125. static int hpfs_create(struct inode *dir, struct dentry *dentry, umode_t mode, bool excl)
  126. {
  127. const unsigned char *name = dentry->d_name.name;
  128. unsigned len = dentry->d_name.len;
  129. struct inode *result = NULL;
  130. struct buffer_head *bh;
  131. struct fnode *fnode;
  132. fnode_secno fno;
  133. int r;
  134. struct hpfs_dirent dee;
  135. int err;
  136. if ((err = hpfs_chk_name(name, &len)))
  137. return err==-ENOENT ? -EINVAL : err;
  138. hpfs_lock(dir->i_sb);
  139. err = -ENOSPC;
  140. fnode = hpfs_alloc_fnode(dir->i_sb, hpfs_i(dir)->i_dno, &fno, &bh);
  141. if (!fnode)
  142. goto bail;
  143. memset(&dee, 0, sizeof dee);
  144. if (!(mode & 0222)) dee.read_only = 1;
  145. dee.archive = 1;
  146. dee.hidden = name[0] == '.';
  147. dee.fnode = cpu_to_le32(fno);
  148. dee.creation_date = dee.write_date = dee.read_date = cpu_to_le32(gmt_to_local(dir->i_sb, get_seconds()));
  149. result = new_inode(dir->i_sb);
  150. if (!result)
  151. goto bail1;
  152. hpfs_init_inode(result);
  153. result->i_ino = fno;
  154. result->i_mode |= S_IFREG;
  155. result->i_mode &= ~0111;
  156. result->i_op = &hpfs_file_iops;
  157. result->i_fop = &hpfs_file_ops;
  158. set_nlink(result, 1);
  159. hpfs_i(result)->i_parent_dir = dir->i_ino;
  160. result->i_ctime.tv_sec = result->i_mtime.tv_sec = result->i_atime.tv_sec = local_to_gmt(dir->i_sb, le32_to_cpu(dee.creation_date));
  161. result->i_ctime.tv_nsec = 0;
  162. result->i_mtime.tv_nsec = 0;
  163. result->i_atime.tv_nsec = 0;
  164. hpfs_i(result)->i_ea_size = 0;
  165. if (dee.read_only)
  166. result->i_mode &= ~0222;
  167. result->i_blocks = 1;
  168. result->i_size = 0;
  169. result->i_data.a_ops = &hpfs_aops;
  170. hpfs_i(result)->mmu_private = 0;
  171. r = hpfs_add_dirent(dir, name, len, &dee);
  172. if (r == 1)
  173. goto bail2;
  174. if (r == -1) {
  175. err = -EEXIST;
  176. goto bail2;
  177. }
  178. fnode->len = len;
  179. memcpy(fnode->name, name, len > 15 ? 15 : len);
  180. fnode->up = cpu_to_le32(dir->i_ino);
  181. mark_buffer_dirty(bh);
  182. brelse(bh);
  183. insert_inode_hash(result);
  184. if (!uid_eq(result->i_uid, current_fsuid()) ||
  185. !gid_eq(result->i_gid, current_fsgid()) ||
  186. result->i_mode != (mode | S_IFREG)) {
  187. result->i_uid = current_fsuid();
  188. result->i_gid = current_fsgid();
  189. result->i_mode = mode | S_IFREG;
  190. hpfs_write_inode_nolock(result);
  191. }
  192. hpfs_update_directory_times(dir);
  193. d_instantiate(dentry, result);
  194. hpfs_unlock(dir->i_sb);
  195. return 0;
  196. bail2:
  197. iput(result);
  198. bail1:
  199. brelse(bh);
  200. hpfs_free_sectors(dir->i_sb, fno, 1);
  201. bail:
  202. hpfs_unlock(dir->i_sb);
  203. return err;
  204. }
  205. static int hpfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t rdev)
  206. {
  207. const unsigned char *name = dentry->d_name.name;
  208. unsigned len = dentry->d_name.len;
  209. struct buffer_head *bh;
  210. struct fnode *fnode;
  211. fnode_secno fno;
  212. int r;
  213. struct hpfs_dirent dee;
  214. struct inode *result = NULL;
  215. int err;
  216. if ((err = hpfs_chk_name(name, &len))) return err==-ENOENT ? -EINVAL : err;
  217. if (hpfs_sb(dir->i_sb)->sb_eas < 2) return -EPERM;
  218. hpfs_lock(dir->i_sb);
  219. err = -ENOSPC;
  220. fnode = hpfs_alloc_fnode(dir->i_sb, hpfs_i(dir)->i_dno, &fno, &bh);
  221. if (!fnode)
  222. goto bail;
  223. memset(&dee, 0, sizeof dee);
  224. if (!(mode & 0222)) dee.read_only = 1;
  225. dee.archive = 1;
  226. dee.hidden = name[0] == '.';
  227. dee.fnode = cpu_to_le32(fno);
  228. dee.creation_date = dee.write_date = dee.read_date = cpu_to_le32(gmt_to_local(dir->i_sb, get_seconds()));
  229. result = new_inode(dir->i_sb);
  230. if (!result)
  231. goto bail1;
  232. hpfs_init_inode(result);
  233. result->i_ino = fno;
  234. hpfs_i(result)->i_parent_dir = dir->i_ino;
  235. result->i_ctime.tv_sec = result->i_mtime.tv_sec = result->i_atime.tv_sec = local_to_gmt(dir->i_sb, le32_to_cpu(dee.creation_date));
  236. result->i_ctime.tv_nsec = 0;
  237. result->i_mtime.tv_nsec = 0;
  238. result->i_atime.tv_nsec = 0;
  239. hpfs_i(result)->i_ea_size = 0;
  240. result->i_uid = current_fsuid();
  241. result->i_gid = current_fsgid();
  242. set_nlink(result, 1);
  243. result->i_size = 0;
  244. result->i_blocks = 1;
  245. init_special_inode(result, mode, rdev);
  246. r = hpfs_add_dirent(dir, name, len, &dee);
  247. if (r == 1)
  248. goto bail2;
  249. if (r == -1) {
  250. err = -EEXIST;
  251. goto bail2;
  252. }
  253. fnode->len = len;
  254. memcpy(fnode->name, name, len > 15 ? 15 : len);
  255. fnode->up = cpu_to_le32(dir->i_ino);
  256. mark_buffer_dirty(bh);
  257. insert_inode_hash(result);
  258. hpfs_write_inode_nolock(result);
  259. hpfs_update_directory_times(dir);
  260. d_instantiate(dentry, result);
  261. brelse(bh);
  262. hpfs_unlock(dir->i_sb);
  263. return 0;
  264. bail2:
  265. iput(result);
  266. bail1:
  267. brelse(bh);
  268. hpfs_free_sectors(dir->i_sb, fno, 1);
  269. bail:
  270. hpfs_unlock(dir->i_sb);
  271. return err;
  272. }
  273. static int hpfs_symlink(struct inode *dir, struct dentry *dentry, const char *symlink)
  274. {
  275. const unsigned char *name = dentry->d_name.name;
  276. unsigned len = dentry->d_name.len;
  277. struct buffer_head *bh;
  278. struct fnode *fnode;
  279. fnode_secno fno;
  280. int r;
  281. struct hpfs_dirent dee;
  282. struct inode *result;
  283. int err;
  284. if ((err = hpfs_chk_name(name, &len))) return err==-ENOENT ? -EINVAL : err;
  285. hpfs_lock(dir->i_sb);
  286. if (hpfs_sb(dir->i_sb)->sb_eas < 2) {
  287. hpfs_unlock(dir->i_sb);
  288. return -EPERM;
  289. }
  290. err = -ENOSPC;
  291. fnode = hpfs_alloc_fnode(dir->i_sb, hpfs_i(dir)->i_dno, &fno, &bh);
  292. if (!fnode)
  293. goto bail;
  294. memset(&dee, 0, sizeof dee);
  295. dee.archive = 1;
  296. dee.hidden = name[0] == '.';
  297. dee.fnode = cpu_to_le32(fno);
  298. dee.creation_date = dee.write_date = dee.read_date = cpu_to_le32(gmt_to_local(dir->i_sb, get_seconds()));
  299. result = new_inode(dir->i_sb);
  300. if (!result)
  301. goto bail1;
  302. result->i_ino = fno;
  303. hpfs_init_inode(result);
  304. hpfs_i(result)->i_parent_dir = dir->i_ino;
  305. result->i_ctime.tv_sec = result->i_mtime.tv_sec = result->i_atime.tv_sec = local_to_gmt(dir->i_sb, le32_to_cpu(dee.creation_date));
  306. result->i_ctime.tv_nsec = 0;
  307. result->i_mtime.tv_nsec = 0;
  308. result->i_atime.tv_nsec = 0;
  309. hpfs_i(result)->i_ea_size = 0;
  310. result->i_mode = S_IFLNK | 0777;
  311. result->i_uid = current_fsuid();
  312. result->i_gid = current_fsgid();
  313. result->i_blocks = 1;
  314. set_nlink(result, 1);
  315. result->i_size = strlen(symlink);
  316. result->i_op = &page_symlink_inode_operations;
  317. result->i_data.a_ops = &hpfs_symlink_aops;
  318. r = hpfs_add_dirent(dir, name, len, &dee);
  319. if (r == 1)
  320. goto bail2;
  321. if (r == -1) {
  322. err = -EEXIST;
  323. goto bail2;
  324. }
  325. fnode->len = len;
  326. memcpy(fnode->name, name, len > 15 ? 15 : len);
  327. fnode->up = cpu_to_le32(dir->i_ino);
  328. hpfs_set_ea(result, fnode, "SYMLINK", symlink, strlen(symlink));
  329. mark_buffer_dirty(bh);
  330. brelse(bh);
  331. insert_inode_hash(result);
  332. hpfs_write_inode_nolock(result);
  333. hpfs_update_directory_times(dir);
  334. d_instantiate(dentry, result);
  335. hpfs_unlock(dir->i_sb);
  336. return 0;
  337. bail2:
  338. iput(result);
  339. bail1:
  340. brelse(bh);
  341. hpfs_free_sectors(dir->i_sb, fno, 1);
  342. bail:
  343. hpfs_unlock(dir->i_sb);
  344. return err;
  345. }
  346. static int hpfs_unlink(struct inode *dir, struct dentry *dentry)
  347. {
  348. const unsigned char *name = dentry->d_name.name;
  349. unsigned len = dentry->d_name.len;
  350. struct quad_buffer_head qbh;
  351. struct hpfs_dirent *de;
  352. struct inode *inode = d_inode(dentry);
  353. dnode_secno dno;
  354. int r;
  355. int err;
  356. hpfs_lock(dir->i_sb);
  357. hpfs_adjust_length(name, &len);
  358. err = -ENOENT;
  359. de = map_dirent(dir, hpfs_i(dir)->i_dno, name, len, &dno, &qbh);
  360. if (!de)
  361. goto out;
  362. err = -EPERM;
  363. if (de->first)
  364. goto out1;
  365. err = -EISDIR;
  366. if (de->directory)
  367. goto out1;
  368. r = hpfs_remove_dirent(dir, dno, de, &qbh, 1);
  369. switch (r) {
  370. case 1:
  371. hpfs_error(dir->i_sb, "there was error when removing dirent");
  372. err = -EFSERROR;
  373. break;
  374. case 2: /* no space for deleting */
  375. err = -ENOSPC;
  376. break;
  377. default:
  378. drop_nlink(inode);
  379. err = 0;
  380. }
  381. goto out;
  382. out1:
  383. hpfs_brelse4(&qbh);
  384. out:
  385. if (!err)
  386. hpfs_update_directory_times(dir);
  387. hpfs_unlock(dir->i_sb);
  388. return err;
  389. }
  390. static int hpfs_rmdir(struct inode *dir, struct dentry *dentry)
  391. {
  392. const unsigned char *name = dentry->d_name.name;
  393. unsigned len = dentry->d_name.len;
  394. struct quad_buffer_head qbh;
  395. struct hpfs_dirent *de;
  396. struct inode *inode = d_inode(dentry);
  397. dnode_secno dno;
  398. int n_items = 0;
  399. int err;
  400. int r;
  401. hpfs_adjust_length(name, &len);
  402. hpfs_lock(dir->i_sb);
  403. err = -ENOENT;
  404. de = map_dirent(dir, hpfs_i(dir)->i_dno, name, len, &dno, &qbh);
  405. if (!de)
  406. goto out;
  407. err = -EPERM;
  408. if (de->first)
  409. goto out1;
  410. err = -ENOTDIR;
  411. if (!de->directory)
  412. goto out1;
  413. hpfs_count_dnodes(dir->i_sb, hpfs_i(inode)->i_dno, NULL, NULL, &n_items);
  414. err = -ENOTEMPTY;
  415. if (n_items)
  416. goto out1;
  417. r = hpfs_remove_dirent(dir, dno, de, &qbh, 1);
  418. switch (r) {
  419. case 1:
  420. hpfs_error(dir->i_sb, "there was error when removing dirent");
  421. err = -EFSERROR;
  422. break;
  423. case 2:
  424. err = -ENOSPC;
  425. break;
  426. default:
  427. drop_nlink(dir);
  428. clear_nlink(inode);
  429. err = 0;
  430. }
  431. goto out;
  432. out1:
  433. hpfs_brelse4(&qbh);
  434. out:
  435. if (!err)
  436. hpfs_update_directory_times(dir);
  437. hpfs_unlock(dir->i_sb);
  438. return err;
  439. }
  440. static int hpfs_symlink_readpage(struct file *file, struct page *page)
  441. {
  442. char *link = kmap(page);
  443. struct inode *i = page->mapping->host;
  444. struct fnode *fnode;
  445. struct buffer_head *bh;
  446. int err;
  447. err = -EIO;
  448. hpfs_lock(i->i_sb);
  449. if (!(fnode = hpfs_map_fnode(i->i_sb, i->i_ino, &bh)))
  450. goto fail;
  451. err = hpfs_read_ea(i->i_sb, fnode, "SYMLINK", link, PAGE_SIZE);
  452. brelse(bh);
  453. if (err)
  454. goto fail;
  455. hpfs_unlock(i->i_sb);
  456. SetPageUptodate(page);
  457. kunmap(page);
  458. unlock_page(page);
  459. return 0;
  460. fail:
  461. hpfs_unlock(i->i_sb);
  462. SetPageError(page);
  463. kunmap(page);
  464. unlock_page(page);
  465. return err;
  466. }
  467. const struct address_space_operations hpfs_symlink_aops = {
  468. .readpage = hpfs_symlink_readpage
  469. };
  470. static int hpfs_rename(struct inode *old_dir, struct dentry *old_dentry,
  471. struct inode *new_dir, struct dentry *new_dentry)
  472. {
  473. const unsigned char *old_name = old_dentry->d_name.name;
  474. unsigned old_len = old_dentry->d_name.len;
  475. const unsigned char *new_name = new_dentry->d_name.name;
  476. unsigned new_len = new_dentry->d_name.len;
  477. struct inode *i = d_inode(old_dentry);
  478. struct inode *new_inode = d_inode(new_dentry);
  479. struct quad_buffer_head qbh, qbh1;
  480. struct hpfs_dirent *dep, *nde;
  481. struct hpfs_dirent de;
  482. dnode_secno dno;
  483. int r;
  484. struct buffer_head *bh;
  485. struct fnode *fnode;
  486. int err;
  487. if ((err = hpfs_chk_name(new_name, &new_len))) return err;
  488. err = 0;
  489. hpfs_adjust_length(old_name, &old_len);
  490. hpfs_lock(i->i_sb);
  491. /* order doesn't matter, due to VFS exclusion */
  492. /* Erm? Moving over the empty non-busy directory is perfectly legal */
  493. if (new_inode && S_ISDIR(new_inode->i_mode)) {
  494. err = -EINVAL;
  495. goto end1;
  496. }
  497. if (!(dep = map_dirent(old_dir, hpfs_i(old_dir)->i_dno, old_name, old_len, &dno, &qbh))) {
  498. hpfs_error(i->i_sb, "lookup succeeded but map dirent failed");
  499. err = -ENOENT;
  500. goto end1;
  501. }
  502. copy_de(&de, dep);
  503. de.hidden = new_name[0] == '.';
  504. if (new_inode) {
  505. int r;
  506. if ((r = hpfs_remove_dirent(old_dir, dno, dep, &qbh, 1)) != 2) {
  507. if ((nde = map_dirent(new_dir, hpfs_i(new_dir)->i_dno, new_name, new_len, NULL, &qbh1))) {
  508. clear_nlink(new_inode);
  509. copy_de(nde, &de);
  510. memcpy(nde->name, new_name, new_len);
  511. hpfs_mark_4buffers_dirty(&qbh1);
  512. hpfs_brelse4(&qbh1);
  513. goto end;
  514. }
  515. hpfs_error(new_dir->i_sb, "hpfs_rename: could not find dirent");
  516. err = -EFSERROR;
  517. goto end1;
  518. }
  519. err = r == 2 ? -ENOSPC : r == 1 ? -EFSERROR : 0;
  520. goto end1;
  521. }
  522. if (new_dir == old_dir) hpfs_brelse4(&qbh);
  523. if ((r = hpfs_add_dirent(new_dir, new_name, new_len, &de))) {
  524. if (r == -1) hpfs_error(new_dir->i_sb, "hpfs_rename: dirent already exists!");
  525. err = r == 1 ? -ENOSPC : -EFSERROR;
  526. if (new_dir != old_dir) hpfs_brelse4(&qbh);
  527. goto end1;
  528. }
  529. if (new_dir == old_dir)
  530. if (!(dep = map_dirent(old_dir, hpfs_i(old_dir)->i_dno, old_name, old_len, &dno, &qbh))) {
  531. hpfs_error(i->i_sb, "lookup succeeded but map dirent failed at #2");
  532. err = -ENOENT;
  533. goto end1;
  534. }
  535. if ((r = hpfs_remove_dirent(old_dir, dno, dep, &qbh, 0))) {
  536. hpfs_error(i->i_sb, "hpfs_rename: could not remove dirent");
  537. err = r == 2 ? -ENOSPC : -EFSERROR;
  538. goto end1;
  539. }
  540. end:
  541. hpfs_i(i)->i_parent_dir = new_dir->i_ino;
  542. if (S_ISDIR(i->i_mode)) {
  543. inc_nlink(new_dir);
  544. drop_nlink(old_dir);
  545. }
  546. if ((fnode = hpfs_map_fnode(i->i_sb, i->i_ino, &bh))) {
  547. fnode->up = cpu_to_le32(new_dir->i_ino);
  548. fnode->len = new_len;
  549. memcpy(fnode->name, new_name, new_len>15?15:new_len);
  550. if (new_len < 15) memset(&fnode->name[new_len], 0, 15 - new_len);
  551. mark_buffer_dirty(bh);
  552. brelse(bh);
  553. }
  554. end1:
  555. if (!err) {
  556. hpfs_update_directory_times(old_dir);
  557. hpfs_update_directory_times(new_dir);
  558. }
  559. hpfs_unlock(i->i_sb);
  560. return err;
  561. }
  562. const struct inode_operations hpfs_dir_iops =
  563. {
  564. .create = hpfs_create,
  565. .lookup = hpfs_lookup,
  566. .unlink = hpfs_unlink,
  567. .symlink = hpfs_symlink,
  568. .mkdir = hpfs_mkdir,
  569. .rmdir = hpfs_rmdir,
  570. .mknod = hpfs_mknod,
  571. .rename = hpfs_rename,
  572. .setattr = hpfs_setattr,
  573. };