namei.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628
  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. inode_nohighmem(result);
  317. result->i_op = &page_symlink_inode_operations;
  318. result->i_data.a_ops = &hpfs_symlink_aops;
  319. r = hpfs_add_dirent(dir, name, len, &dee);
  320. if (r == 1)
  321. goto bail2;
  322. if (r == -1) {
  323. err = -EEXIST;
  324. goto bail2;
  325. }
  326. fnode->len = len;
  327. memcpy(fnode->name, name, len > 15 ? 15 : len);
  328. fnode->up = cpu_to_le32(dir->i_ino);
  329. hpfs_set_ea(result, fnode, "SYMLINK", symlink, strlen(symlink));
  330. mark_buffer_dirty(bh);
  331. brelse(bh);
  332. insert_inode_hash(result);
  333. hpfs_write_inode_nolock(result);
  334. hpfs_update_directory_times(dir);
  335. d_instantiate(dentry, result);
  336. hpfs_unlock(dir->i_sb);
  337. return 0;
  338. bail2:
  339. iput(result);
  340. bail1:
  341. brelse(bh);
  342. hpfs_free_sectors(dir->i_sb, fno, 1);
  343. bail:
  344. hpfs_unlock(dir->i_sb);
  345. return err;
  346. }
  347. static int hpfs_unlink(struct inode *dir, struct dentry *dentry)
  348. {
  349. const unsigned char *name = dentry->d_name.name;
  350. unsigned len = dentry->d_name.len;
  351. struct quad_buffer_head qbh;
  352. struct hpfs_dirent *de;
  353. struct inode *inode = d_inode(dentry);
  354. dnode_secno dno;
  355. int r;
  356. int err;
  357. hpfs_lock(dir->i_sb);
  358. hpfs_adjust_length(name, &len);
  359. err = -ENOENT;
  360. de = map_dirent(dir, hpfs_i(dir)->i_dno, name, len, &dno, &qbh);
  361. if (!de)
  362. goto out;
  363. err = -EPERM;
  364. if (de->first)
  365. goto out1;
  366. err = -EISDIR;
  367. if (de->directory)
  368. goto out1;
  369. r = hpfs_remove_dirent(dir, dno, de, &qbh, 1);
  370. switch (r) {
  371. case 1:
  372. hpfs_error(dir->i_sb, "there was error when removing dirent");
  373. err = -EFSERROR;
  374. break;
  375. case 2: /* no space for deleting */
  376. err = -ENOSPC;
  377. break;
  378. default:
  379. drop_nlink(inode);
  380. err = 0;
  381. }
  382. goto out;
  383. out1:
  384. hpfs_brelse4(&qbh);
  385. out:
  386. if (!err)
  387. hpfs_update_directory_times(dir);
  388. hpfs_unlock(dir->i_sb);
  389. return err;
  390. }
  391. static int hpfs_rmdir(struct inode *dir, struct dentry *dentry)
  392. {
  393. const unsigned char *name = dentry->d_name.name;
  394. unsigned len = dentry->d_name.len;
  395. struct quad_buffer_head qbh;
  396. struct hpfs_dirent *de;
  397. struct inode *inode = d_inode(dentry);
  398. dnode_secno dno;
  399. int n_items = 0;
  400. int err;
  401. int r;
  402. hpfs_adjust_length(name, &len);
  403. hpfs_lock(dir->i_sb);
  404. err = -ENOENT;
  405. de = map_dirent(dir, hpfs_i(dir)->i_dno, name, len, &dno, &qbh);
  406. if (!de)
  407. goto out;
  408. err = -EPERM;
  409. if (de->first)
  410. goto out1;
  411. err = -ENOTDIR;
  412. if (!de->directory)
  413. goto out1;
  414. hpfs_count_dnodes(dir->i_sb, hpfs_i(inode)->i_dno, NULL, NULL, &n_items);
  415. err = -ENOTEMPTY;
  416. if (n_items)
  417. goto out1;
  418. r = hpfs_remove_dirent(dir, dno, de, &qbh, 1);
  419. switch (r) {
  420. case 1:
  421. hpfs_error(dir->i_sb, "there was error when removing dirent");
  422. err = -EFSERROR;
  423. break;
  424. case 2:
  425. err = -ENOSPC;
  426. break;
  427. default:
  428. drop_nlink(dir);
  429. clear_nlink(inode);
  430. err = 0;
  431. }
  432. goto out;
  433. out1:
  434. hpfs_brelse4(&qbh);
  435. out:
  436. if (!err)
  437. hpfs_update_directory_times(dir);
  438. hpfs_unlock(dir->i_sb);
  439. return err;
  440. }
  441. static int hpfs_symlink_readpage(struct file *file, struct page *page)
  442. {
  443. char *link = page_address(page);
  444. struct inode *i = page->mapping->host;
  445. struct fnode *fnode;
  446. struct buffer_head *bh;
  447. int err;
  448. err = -EIO;
  449. hpfs_lock(i->i_sb);
  450. if (!(fnode = hpfs_map_fnode(i->i_sb, i->i_ino, &bh)))
  451. goto fail;
  452. err = hpfs_read_ea(i->i_sb, fnode, "SYMLINK", link, PAGE_SIZE);
  453. brelse(bh);
  454. if (err)
  455. goto fail;
  456. hpfs_unlock(i->i_sb);
  457. SetPageUptodate(page);
  458. unlock_page(page);
  459. return 0;
  460. fail:
  461. hpfs_unlock(i->i_sb);
  462. SetPageError(page);
  463. unlock_page(page);
  464. return err;
  465. }
  466. const struct address_space_operations hpfs_symlink_aops = {
  467. .readpage = hpfs_symlink_readpage
  468. };
  469. static int hpfs_rename(struct inode *old_dir, struct dentry *old_dentry,
  470. struct inode *new_dir, struct dentry *new_dentry,
  471. unsigned int flags)
  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 (flags & ~RENAME_NOREPLACE)
  488. return -EINVAL;
  489. if ((err = hpfs_chk_name(new_name, &new_len))) return err;
  490. err = 0;
  491. hpfs_adjust_length(old_name, &old_len);
  492. hpfs_lock(i->i_sb);
  493. /* order doesn't matter, due to VFS exclusion */
  494. /* Erm? Moving over the empty non-busy directory is perfectly legal */
  495. if (new_inode && S_ISDIR(new_inode->i_mode)) {
  496. err = -EINVAL;
  497. goto end1;
  498. }
  499. if (!(dep = map_dirent(old_dir, hpfs_i(old_dir)->i_dno, old_name, old_len, &dno, &qbh))) {
  500. hpfs_error(i->i_sb, "lookup succeeded but map dirent failed");
  501. err = -ENOENT;
  502. goto end1;
  503. }
  504. copy_de(&de, dep);
  505. de.hidden = new_name[0] == '.';
  506. if (new_inode) {
  507. int r;
  508. if ((r = hpfs_remove_dirent(old_dir, dno, dep, &qbh, 1)) != 2) {
  509. if ((nde = map_dirent(new_dir, hpfs_i(new_dir)->i_dno, new_name, new_len, NULL, &qbh1))) {
  510. clear_nlink(new_inode);
  511. copy_de(nde, &de);
  512. memcpy(nde->name, new_name, new_len);
  513. hpfs_mark_4buffers_dirty(&qbh1);
  514. hpfs_brelse4(&qbh1);
  515. goto end;
  516. }
  517. hpfs_error(new_dir->i_sb, "hpfs_rename: could not find dirent");
  518. err = -EFSERROR;
  519. goto end1;
  520. }
  521. err = r == 2 ? -ENOSPC : r == 1 ? -EFSERROR : 0;
  522. goto end1;
  523. }
  524. if (new_dir == old_dir) hpfs_brelse4(&qbh);
  525. if ((r = hpfs_add_dirent(new_dir, new_name, new_len, &de))) {
  526. if (r == -1) hpfs_error(new_dir->i_sb, "hpfs_rename: dirent already exists!");
  527. err = r == 1 ? -ENOSPC : -EFSERROR;
  528. if (new_dir != old_dir) hpfs_brelse4(&qbh);
  529. goto end1;
  530. }
  531. if (new_dir == old_dir)
  532. if (!(dep = map_dirent(old_dir, hpfs_i(old_dir)->i_dno, old_name, old_len, &dno, &qbh))) {
  533. hpfs_error(i->i_sb, "lookup succeeded but map dirent failed at #2");
  534. err = -ENOENT;
  535. goto end1;
  536. }
  537. if ((r = hpfs_remove_dirent(old_dir, dno, dep, &qbh, 0))) {
  538. hpfs_error(i->i_sb, "hpfs_rename: could not remove dirent");
  539. err = r == 2 ? -ENOSPC : -EFSERROR;
  540. goto end1;
  541. }
  542. end:
  543. hpfs_i(i)->i_parent_dir = new_dir->i_ino;
  544. if (S_ISDIR(i->i_mode)) {
  545. inc_nlink(new_dir);
  546. drop_nlink(old_dir);
  547. }
  548. if ((fnode = hpfs_map_fnode(i->i_sb, i->i_ino, &bh))) {
  549. fnode->up = cpu_to_le32(new_dir->i_ino);
  550. fnode->len = new_len;
  551. memcpy(fnode->name, new_name, new_len>15?15:new_len);
  552. if (new_len < 15) memset(&fnode->name[new_len], 0, 15 - new_len);
  553. mark_buffer_dirty(bh);
  554. brelse(bh);
  555. }
  556. end1:
  557. if (!err) {
  558. hpfs_update_directory_times(old_dir);
  559. hpfs_update_directory_times(new_dir);
  560. }
  561. hpfs_unlock(i->i_sb);
  562. return err;
  563. }
  564. const struct inode_operations hpfs_dir_iops =
  565. {
  566. .create = hpfs_create,
  567. .lookup = hpfs_lookup,
  568. .unlink = hpfs_unlink,
  569. .symlink = hpfs_symlink,
  570. .mkdir = hpfs_mkdir,
  571. .rmdir = hpfs_rmdir,
  572. .mknod = hpfs_mknod,
  573. .rename = hpfs_rename,
  574. .setattr = hpfs_setattr,
  575. };