dir.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659
  1. /*
  2. * linux/fs/ufs/ufs_dir.c
  3. *
  4. * Copyright (C) 1996
  5. * Adrian Rodriguez (adrian@franklins-tower.rutgers.edu)
  6. * Laboratory for Computer Science Research Computing Facility
  7. * Rutgers, The State University of New Jersey
  8. *
  9. * swab support by Francois-Rene Rideau <fare@tunes.org> 19970406
  10. *
  11. * 4.4BSD (FreeBSD) support added on February 1st 1998 by
  12. * Niels Kristian Bech Jensen <nkbj@image.dk> partially based
  13. * on code by Martin von Loewis <martin@mira.isdn.cs.tu-berlin.de>.
  14. *
  15. * Migration to usage of "page cache" on May 2006 by
  16. * Evgeniy Dushistov <dushistov@mail.ru> based on ext2 code base.
  17. */
  18. #include <linux/time.h>
  19. #include <linux/fs.h>
  20. #include <linux/swap.h>
  21. #include "ufs_fs.h"
  22. #include "ufs.h"
  23. #include "swab.h"
  24. #include "util.h"
  25. /*
  26. * NOTE! unlike strncmp, ufs_match returns 1 for success, 0 for failure.
  27. *
  28. * len <= UFS_MAXNAMLEN and de != NULL are guaranteed by caller.
  29. */
  30. static inline int ufs_match(struct super_block *sb, int len,
  31. const unsigned char *name, struct ufs_dir_entry *de)
  32. {
  33. if (len != ufs_get_de_namlen(sb, de))
  34. return 0;
  35. if (!de->d_ino)
  36. return 0;
  37. return !memcmp(name, de->d_name, len);
  38. }
  39. static int ufs_commit_chunk(struct page *page, loff_t pos, unsigned len)
  40. {
  41. struct address_space *mapping = page->mapping;
  42. struct inode *dir = mapping->host;
  43. int err = 0;
  44. dir->i_version++;
  45. block_write_end(NULL, mapping, pos, len, len, page, NULL);
  46. if (pos+len > dir->i_size) {
  47. i_size_write(dir, pos+len);
  48. mark_inode_dirty(dir);
  49. }
  50. if (IS_DIRSYNC(dir))
  51. err = write_one_page(page, 1);
  52. else
  53. unlock_page(page);
  54. return err;
  55. }
  56. static inline void ufs_put_page(struct page *page)
  57. {
  58. kunmap(page);
  59. page_cache_release(page);
  60. }
  61. ino_t ufs_inode_by_name(struct inode *dir, const struct qstr *qstr)
  62. {
  63. ino_t res = 0;
  64. struct ufs_dir_entry *de;
  65. struct page *page;
  66. de = ufs_find_entry(dir, qstr, &page);
  67. if (de) {
  68. res = fs32_to_cpu(dir->i_sb, de->d_ino);
  69. ufs_put_page(page);
  70. }
  71. return res;
  72. }
  73. /* Releases the page */
  74. void ufs_set_link(struct inode *dir, struct ufs_dir_entry *de,
  75. struct page *page, struct inode *inode,
  76. bool update_times)
  77. {
  78. loff_t pos = page_offset(page) +
  79. (char *) de - (char *) page_address(page);
  80. unsigned len = fs16_to_cpu(dir->i_sb, de->d_reclen);
  81. int err;
  82. lock_page(page);
  83. err = ufs_prepare_chunk(page, pos, len);
  84. BUG_ON(err);
  85. de->d_ino = cpu_to_fs32(dir->i_sb, inode->i_ino);
  86. ufs_set_de_type(dir->i_sb, de, inode->i_mode);
  87. err = ufs_commit_chunk(page, pos, len);
  88. ufs_put_page(page);
  89. if (update_times)
  90. dir->i_mtime = dir->i_ctime = CURRENT_TIME_SEC;
  91. mark_inode_dirty(dir);
  92. }
  93. static void ufs_check_page(struct page *page)
  94. {
  95. struct inode *dir = page->mapping->host;
  96. struct super_block *sb = dir->i_sb;
  97. char *kaddr = page_address(page);
  98. unsigned offs, rec_len;
  99. unsigned limit = PAGE_CACHE_SIZE;
  100. const unsigned chunk_mask = UFS_SB(sb)->s_uspi->s_dirblksize - 1;
  101. struct ufs_dir_entry *p;
  102. char *error;
  103. if ((dir->i_size >> PAGE_CACHE_SHIFT) == page->index) {
  104. limit = dir->i_size & ~PAGE_CACHE_MASK;
  105. if (limit & chunk_mask)
  106. goto Ebadsize;
  107. if (!limit)
  108. goto out;
  109. }
  110. for (offs = 0; offs <= limit - UFS_DIR_REC_LEN(1); offs += rec_len) {
  111. p = (struct ufs_dir_entry *)(kaddr + offs);
  112. rec_len = fs16_to_cpu(sb, p->d_reclen);
  113. if (rec_len < UFS_DIR_REC_LEN(1))
  114. goto Eshort;
  115. if (rec_len & 3)
  116. goto Ealign;
  117. if (rec_len < UFS_DIR_REC_LEN(ufs_get_de_namlen(sb, p)))
  118. goto Enamelen;
  119. if (((offs + rec_len - 1) ^ offs) & ~chunk_mask)
  120. goto Espan;
  121. if (fs32_to_cpu(sb, p->d_ino) > (UFS_SB(sb)->s_uspi->s_ipg *
  122. UFS_SB(sb)->s_uspi->s_ncg))
  123. goto Einumber;
  124. }
  125. if (offs != limit)
  126. goto Eend;
  127. out:
  128. SetPageChecked(page);
  129. return;
  130. /* Too bad, we had an error */
  131. Ebadsize:
  132. ufs_error(sb, "ufs_check_page",
  133. "size of directory #%lu is not a multiple of chunk size",
  134. dir->i_ino
  135. );
  136. goto fail;
  137. Eshort:
  138. error = "rec_len is smaller than minimal";
  139. goto bad_entry;
  140. Ealign:
  141. error = "unaligned directory entry";
  142. goto bad_entry;
  143. Enamelen:
  144. error = "rec_len is too small for name_len";
  145. goto bad_entry;
  146. Espan:
  147. error = "directory entry across blocks";
  148. goto bad_entry;
  149. Einumber:
  150. error = "inode out of bounds";
  151. bad_entry:
  152. ufs_error (sb, "ufs_check_page", "bad entry in directory #%lu: %s - "
  153. "offset=%lu, rec_len=%d, name_len=%d",
  154. dir->i_ino, error, (page->index<<PAGE_CACHE_SHIFT)+offs,
  155. rec_len, ufs_get_de_namlen(sb, p));
  156. goto fail;
  157. Eend:
  158. p = (struct ufs_dir_entry *)(kaddr + offs);
  159. ufs_error(sb, __func__,
  160. "entry in directory #%lu spans the page boundary"
  161. "offset=%lu",
  162. dir->i_ino, (page->index<<PAGE_CACHE_SHIFT)+offs);
  163. fail:
  164. SetPageChecked(page);
  165. SetPageError(page);
  166. }
  167. static struct page *ufs_get_page(struct inode *dir, unsigned long n)
  168. {
  169. struct address_space *mapping = dir->i_mapping;
  170. struct page *page = read_mapping_page(mapping, n, NULL);
  171. if (!IS_ERR(page)) {
  172. kmap(page);
  173. if (!PageChecked(page))
  174. ufs_check_page(page);
  175. if (PageError(page))
  176. goto fail;
  177. }
  178. return page;
  179. fail:
  180. ufs_put_page(page);
  181. return ERR_PTR(-EIO);
  182. }
  183. /*
  184. * Return the offset into page `page_nr' of the last valid
  185. * byte in that page, plus one.
  186. */
  187. static unsigned
  188. ufs_last_byte(struct inode *inode, unsigned long page_nr)
  189. {
  190. unsigned last_byte = inode->i_size;
  191. last_byte -= page_nr << PAGE_CACHE_SHIFT;
  192. if (last_byte > PAGE_CACHE_SIZE)
  193. last_byte = PAGE_CACHE_SIZE;
  194. return last_byte;
  195. }
  196. static inline struct ufs_dir_entry *
  197. ufs_next_entry(struct super_block *sb, struct ufs_dir_entry *p)
  198. {
  199. return (struct ufs_dir_entry *)((char *)p +
  200. fs16_to_cpu(sb, p->d_reclen));
  201. }
  202. struct ufs_dir_entry *ufs_dotdot(struct inode *dir, struct page **p)
  203. {
  204. struct page *page = ufs_get_page(dir, 0);
  205. struct ufs_dir_entry *de = NULL;
  206. if (!IS_ERR(page)) {
  207. de = ufs_next_entry(dir->i_sb,
  208. (struct ufs_dir_entry *)page_address(page));
  209. *p = page;
  210. }
  211. return de;
  212. }
  213. /*
  214. * ufs_find_entry()
  215. *
  216. * finds an entry in the specified directory with the wanted name. It
  217. * returns the page in which the entry was found, and the entry itself
  218. * (as a parameter - res_dir). Page is returned mapped and unlocked.
  219. * Entry is guaranteed to be valid.
  220. */
  221. struct ufs_dir_entry *ufs_find_entry(struct inode *dir, const struct qstr *qstr,
  222. struct page **res_page)
  223. {
  224. struct super_block *sb = dir->i_sb;
  225. const unsigned char *name = qstr->name;
  226. int namelen = qstr->len;
  227. unsigned reclen = UFS_DIR_REC_LEN(namelen);
  228. unsigned long start, n;
  229. unsigned long npages = dir_pages(dir);
  230. struct page *page = NULL;
  231. struct ufs_inode_info *ui = UFS_I(dir);
  232. struct ufs_dir_entry *de;
  233. UFSD("ENTER, dir_ino %lu, name %s, namlen %u\n", dir->i_ino, name, namelen);
  234. if (npages == 0 || namelen > UFS_MAXNAMLEN)
  235. goto out;
  236. /* OFFSET_CACHE */
  237. *res_page = NULL;
  238. start = ui->i_dir_start_lookup;
  239. if (start >= npages)
  240. start = 0;
  241. n = start;
  242. do {
  243. char *kaddr;
  244. page = ufs_get_page(dir, n);
  245. if (!IS_ERR(page)) {
  246. kaddr = page_address(page);
  247. de = (struct ufs_dir_entry *) kaddr;
  248. kaddr += ufs_last_byte(dir, n) - reclen;
  249. while ((char *) de <= kaddr) {
  250. if (de->d_reclen == 0) {
  251. ufs_error(dir->i_sb, __func__,
  252. "zero-length directory entry");
  253. ufs_put_page(page);
  254. goto out;
  255. }
  256. if (ufs_match(sb, namelen, name, de))
  257. goto found;
  258. de = ufs_next_entry(sb, de);
  259. }
  260. ufs_put_page(page);
  261. }
  262. if (++n >= npages)
  263. n = 0;
  264. } while (n != start);
  265. out:
  266. return NULL;
  267. found:
  268. *res_page = page;
  269. ui->i_dir_start_lookup = n;
  270. return de;
  271. }
  272. /*
  273. * Parent is locked.
  274. */
  275. int ufs_add_link(struct dentry *dentry, struct inode *inode)
  276. {
  277. struct inode *dir = d_inode(dentry->d_parent);
  278. const unsigned char *name = dentry->d_name.name;
  279. int namelen = dentry->d_name.len;
  280. struct super_block *sb = dir->i_sb;
  281. unsigned reclen = UFS_DIR_REC_LEN(namelen);
  282. const unsigned int chunk_size = UFS_SB(sb)->s_uspi->s_dirblksize;
  283. unsigned short rec_len, name_len;
  284. struct page *page = NULL;
  285. struct ufs_dir_entry *de;
  286. unsigned long npages = dir_pages(dir);
  287. unsigned long n;
  288. char *kaddr;
  289. loff_t pos;
  290. int err;
  291. UFSD("ENTER, name %s, namelen %u\n", name, namelen);
  292. /*
  293. * We take care of directory expansion in the same loop.
  294. * This code plays outside i_size, so it locks the page
  295. * to protect that region.
  296. */
  297. for (n = 0; n <= npages; n++) {
  298. char *dir_end;
  299. page = ufs_get_page(dir, n);
  300. err = PTR_ERR(page);
  301. if (IS_ERR(page))
  302. goto out;
  303. lock_page(page);
  304. kaddr = page_address(page);
  305. dir_end = kaddr + ufs_last_byte(dir, n);
  306. de = (struct ufs_dir_entry *)kaddr;
  307. kaddr += PAGE_CACHE_SIZE - reclen;
  308. while ((char *)de <= kaddr) {
  309. if ((char *)de == dir_end) {
  310. /* We hit i_size */
  311. name_len = 0;
  312. rec_len = chunk_size;
  313. de->d_reclen = cpu_to_fs16(sb, chunk_size);
  314. de->d_ino = 0;
  315. goto got_it;
  316. }
  317. if (de->d_reclen == 0) {
  318. ufs_error(dir->i_sb, __func__,
  319. "zero-length directory entry");
  320. err = -EIO;
  321. goto out_unlock;
  322. }
  323. err = -EEXIST;
  324. if (ufs_match(sb, namelen, name, de))
  325. goto out_unlock;
  326. name_len = UFS_DIR_REC_LEN(ufs_get_de_namlen(sb, de));
  327. rec_len = fs16_to_cpu(sb, de->d_reclen);
  328. if (!de->d_ino && rec_len >= reclen)
  329. goto got_it;
  330. if (rec_len >= name_len + reclen)
  331. goto got_it;
  332. de = (struct ufs_dir_entry *) ((char *) de + rec_len);
  333. }
  334. unlock_page(page);
  335. ufs_put_page(page);
  336. }
  337. BUG();
  338. return -EINVAL;
  339. got_it:
  340. pos = page_offset(page) +
  341. (char*)de - (char*)page_address(page);
  342. err = ufs_prepare_chunk(page, pos, rec_len);
  343. if (err)
  344. goto out_unlock;
  345. if (de->d_ino) {
  346. struct ufs_dir_entry *de1 =
  347. (struct ufs_dir_entry *) ((char *) de + name_len);
  348. de1->d_reclen = cpu_to_fs16(sb, rec_len - name_len);
  349. de->d_reclen = cpu_to_fs16(sb, name_len);
  350. de = de1;
  351. }
  352. ufs_set_de_namlen(sb, de, namelen);
  353. memcpy(de->d_name, name, namelen + 1);
  354. de->d_ino = cpu_to_fs32(sb, inode->i_ino);
  355. ufs_set_de_type(sb, de, inode->i_mode);
  356. err = ufs_commit_chunk(page, pos, rec_len);
  357. dir->i_mtime = dir->i_ctime = CURRENT_TIME_SEC;
  358. mark_inode_dirty(dir);
  359. /* OFFSET_CACHE */
  360. out_put:
  361. ufs_put_page(page);
  362. out:
  363. return err;
  364. out_unlock:
  365. unlock_page(page);
  366. goto out_put;
  367. }
  368. static inline unsigned
  369. ufs_validate_entry(struct super_block *sb, char *base,
  370. unsigned offset, unsigned mask)
  371. {
  372. struct ufs_dir_entry *de = (struct ufs_dir_entry*)(base + offset);
  373. struct ufs_dir_entry *p = (struct ufs_dir_entry*)(base + (offset&mask));
  374. while ((char*)p < (char*)de) {
  375. if (p->d_reclen == 0)
  376. break;
  377. p = ufs_next_entry(sb, p);
  378. }
  379. return (char *)p - base;
  380. }
  381. /*
  382. * This is blatantly stolen from ext2fs
  383. */
  384. static int
  385. ufs_readdir(struct file *file, struct dir_context *ctx)
  386. {
  387. loff_t pos = ctx->pos;
  388. struct inode *inode = file_inode(file);
  389. struct super_block *sb = inode->i_sb;
  390. unsigned int offset = pos & ~PAGE_CACHE_MASK;
  391. unsigned long n = pos >> PAGE_CACHE_SHIFT;
  392. unsigned long npages = dir_pages(inode);
  393. unsigned chunk_mask = ~(UFS_SB(sb)->s_uspi->s_dirblksize - 1);
  394. int need_revalidate = file->f_version != inode->i_version;
  395. unsigned flags = UFS_SB(sb)->s_flags;
  396. UFSD("BEGIN\n");
  397. if (pos > inode->i_size - UFS_DIR_REC_LEN(1))
  398. return 0;
  399. for ( ; n < npages; n++, offset = 0) {
  400. char *kaddr, *limit;
  401. struct ufs_dir_entry *de;
  402. struct page *page = ufs_get_page(inode, n);
  403. if (IS_ERR(page)) {
  404. ufs_error(sb, __func__,
  405. "bad page in #%lu",
  406. inode->i_ino);
  407. ctx->pos += PAGE_CACHE_SIZE - offset;
  408. return -EIO;
  409. }
  410. kaddr = page_address(page);
  411. if (unlikely(need_revalidate)) {
  412. if (offset) {
  413. offset = ufs_validate_entry(sb, kaddr, offset, chunk_mask);
  414. ctx->pos = (n<<PAGE_CACHE_SHIFT) + offset;
  415. }
  416. file->f_version = inode->i_version;
  417. need_revalidate = 0;
  418. }
  419. de = (struct ufs_dir_entry *)(kaddr+offset);
  420. limit = kaddr + ufs_last_byte(inode, n) - UFS_DIR_REC_LEN(1);
  421. for ( ;(char*)de <= limit; de = ufs_next_entry(sb, de)) {
  422. if (de->d_reclen == 0) {
  423. ufs_error(sb, __func__,
  424. "zero-length directory entry");
  425. ufs_put_page(page);
  426. return -EIO;
  427. }
  428. if (de->d_ino) {
  429. unsigned char d_type = DT_UNKNOWN;
  430. UFSD("filldir(%s,%u)\n", de->d_name,
  431. fs32_to_cpu(sb, de->d_ino));
  432. UFSD("namlen %u\n", ufs_get_de_namlen(sb, de));
  433. if ((flags & UFS_DE_MASK) == UFS_DE_44BSD)
  434. d_type = de->d_u.d_44.d_type;
  435. if (!dir_emit(ctx, de->d_name,
  436. ufs_get_de_namlen(sb, de),
  437. fs32_to_cpu(sb, de->d_ino),
  438. d_type)) {
  439. ufs_put_page(page);
  440. return 0;
  441. }
  442. }
  443. ctx->pos += fs16_to_cpu(sb, de->d_reclen);
  444. }
  445. ufs_put_page(page);
  446. }
  447. return 0;
  448. }
  449. /*
  450. * ufs_delete_entry deletes a directory entry by merging it with the
  451. * previous entry.
  452. */
  453. int ufs_delete_entry(struct inode *inode, struct ufs_dir_entry *dir,
  454. struct page * page)
  455. {
  456. struct super_block *sb = inode->i_sb;
  457. char *kaddr = page_address(page);
  458. unsigned from = ((char*)dir - kaddr) & ~(UFS_SB(sb)->s_uspi->s_dirblksize - 1);
  459. unsigned to = ((char*)dir - kaddr) + fs16_to_cpu(sb, dir->d_reclen);
  460. loff_t pos;
  461. struct ufs_dir_entry *pde = NULL;
  462. struct ufs_dir_entry *de = (struct ufs_dir_entry *) (kaddr + from);
  463. int err;
  464. UFSD("ENTER\n");
  465. UFSD("ino %u, reclen %u, namlen %u, name %s\n",
  466. fs32_to_cpu(sb, de->d_ino),
  467. fs16_to_cpu(sb, de->d_reclen),
  468. ufs_get_de_namlen(sb, de), de->d_name);
  469. while ((char*)de < (char*)dir) {
  470. if (de->d_reclen == 0) {
  471. ufs_error(inode->i_sb, __func__,
  472. "zero-length directory entry");
  473. err = -EIO;
  474. goto out;
  475. }
  476. pde = de;
  477. de = ufs_next_entry(sb, de);
  478. }
  479. if (pde)
  480. from = (char*)pde - (char*)page_address(page);
  481. pos = page_offset(page) + from;
  482. lock_page(page);
  483. err = ufs_prepare_chunk(page, pos, to - from);
  484. BUG_ON(err);
  485. if (pde)
  486. pde->d_reclen = cpu_to_fs16(sb, to - from);
  487. dir->d_ino = 0;
  488. err = ufs_commit_chunk(page, pos, to - from);
  489. inode->i_ctime = inode->i_mtime = CURRENT_TIME_SEC;
  490. mark_inode_dirty(inode);
  491. out:
  492. ufs_put_page(page);
  493. UFSD("EXIT\n");
  494. return err;
  495. }
  496. int ufs_make_empty(struct inode * inode, struct inode *dir)
  497. {
  498. struct super_block * sb = dir->i_sb;
  499. struct address_space *mapping = inode->i_mapping;
  500. struct page *page = grab_cache_page(mapping, 0);
  501. const unsigned int chunk_size = UFS_SB(sb)->s_uspi->s_dirblksize;
  502. struct ufs_dir_entry * de;
  503. char *base;
  504. int err;
  505. if (!page)
  506. return -ENOMEM;
  507. err = ufs_prepare_chunk(page, 0, chunk_size);
  508. if (err) {
  509. unlock_page(page);
  510. goto fail;
  511. }
  512. kmap(page);
  513. base = (char*)page_address(page);
  514. memset(base, 0, PAGE_CACHE_SIZE);
  515. de = (struct ufs_dir_entry *) base;
  516. de->d_ino = cpu_to_fs32(sb, inode->i_ino);
  517. ufs_set_de_type(sb, de, inode->i_mode);
  518. ufs_set_de_namlen(sb, de, 1);
  519. de->d_reclen = cpu_to_fs16(sb, UFS_DIR_REC_LEN(1));
  520. strcpy (de->d_name, ".");
  521. de = (struct ufs_dir_entry *)
  522. ((char *)de + fs16_to_cpu(sb, de->d_reclen));
  523. de->d_ino = cpu_to_fs32(sb, dir->i_ino);
  524. ufs_set_de_type(sb, de, dir->i_mode);
  525. de->d_reclen = cpu_to_fs16(sb, chunk_size - UFS_DIR_REC_LEN(1));
  526. ufs_set_de_namlen(sb, de, 2);
  527. strcpy (de->d_name, "..");
  528. kunmap(page);
  529. err = ufs_commit_chunk(page, 0, chunk_size);
  530. fail:
  531. page_cache_release(page);
  532. return err;
  533. }
  534. /*
  535. * routine to check that the specified directory is empty (for rmdir)
  536. */
  537. int ufs_empty_dir(struct inode * inode)
  538. {
  539. struct super_block *sb = inode->i_sb;
  540. struct page *page = NULL;
  541. unsigned long i, npages = dir_pages(inode);
  542. for (i = 0; i < npages; i++) {
  543. char *kaddr;
  544. struct ufs_dir_entry *de;
  545. page = ufs_get_page(inode, i);
  546. if (IS_ERR(page))
  547. continue;
  548. kaddr = page_address(page);
  549. de = (struct ufs_dir_entry *)kaddr;
  550. kaddr += ufs_last_byte(inode, i) - UFS_DIR_REC_LEN(1);
  551. while ((char *)de <= kaddr) {
  552. if (de->d_reclen == 0) {
  553. ufs_error(inode->i_sb, __func__,
  554. "zero-length directory entry: "
  555. "kaddr=%p, de=%p\n", kaddr, de);
  556. goto not_empty;
  557. }
  558. if (de->d_ino) {
  559. u16 namelen=ufs_get_de_namlen(sb, de);
  560. /* check for . and .. */
  561. if (de->d_name[0] != '.')
  562. goto not_empty;
  563. if (namelen > 2)
  564. goto not_empty;
  565. if (namelen < 2) {
  566. if (inode->i_ino !=
  567. fs32_to_cpu(sb, de->d_ino))
  568. goto not_empty;
  569. } else if (de->d_name[1] != '.')
  570. goto not_empty;
  571. }
  572. de = ufs_next_entry(sb, de);
  573. }
  574. ufs_put_page(page);
  575. }
  576. return 1;
  577. not_empty:
  578. ufs_put_page(page);
  579. return 0;
  580. }
  581. const struct file_operations ufs_dir_operations = {
  582. .read = generic_read_dir,
  583. .iterate = ufs_readdir,
  584. .fsync = generic_file_fsync,
  585. .llseek = generic_file_llseek,
  586. };