dir.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662
  1. /*
  2. * linux/fs/ext4/dir.c
  3. *
  4. * Copyright (C) 1992, 1993, 1994, 1995
  5. * Remy Card (card@masi.ibp.fr)
  6. * Laboratoire MASI - Institut Blaise Pascal
  7. * Universite Pierre et Marie Curie (Paris VI)
  8. *
  9. * from
  10. *
  11. * linux/fs/minix/dir.c
  12. *
  13. * Copyright (C) 1991, 1992 Linus Torvalds
  14. *
  15. * ext4 directory handling functions
  16. *
  17. * Big-endian to little-endian byte-swapping/bitmaps by
  18. * David S. Miller (davem@caip.rutgers.edu), 1995
  19. *
  20. * Hash Tree Directory indexing (c) 2001 Daniel Phillips
  21. *
  22. */
  23. #include <linux/fs.h>
  24. #include <linux/buffer_head.h>
  25. #include <linux/slab.h>
  26. #include "ext4.h"
  27. #include "xattr.h"
  28. static int ext4_dx_readdir(struct file *, struct dir_context *);
  29. /**
  30. * Check if the given dir-inode refers to an htree-indexed directory
  31. * (or a directory which could potentially get converted to use htree
  32. * indexing).
  33. *
  34. * Return 1 if it is a dx dir, 0 if not
  35. */
  36. static int is_dx_dir(struct inode *inode)
  37. {
  38. struct super_block *sb = inode->i_sb;
  39. if (ext4_has_feature_dir_index(inode->i_sb) &&
  40. ((ext4_test_inode_flag(inode, EXT4_INODE_INDEX)) ||
  41. ((inode->i_size >> sb->s_blocksize_bits) == 1) ||
  42. ext4_has_inline_data(inode)))
  43. return 1;
  44. return 0;
  45. }
  46. /*
  47. * Return 0 if the directory entry is OK, and 1 if there is a problem
  48. *
  49. * Note: this is the opposite of what ext2 and ext3 historically returned...
  50. *
  51. * bh passed here can be an inode block or a dir data block, depending
  52. * on the inode inline data flag.
  53. */
  54. int __ext4_check_dir_entry(const char *function, unsigned int line,
  55. struct inode *dir, struct file *filp,
  56. struct ext4_dir_entry_2 *de,
  57. struct buffer_head *bh, char *buf, int size,
  58. unsigned int offset)
  59. {
  60. const char *error_msg = NULL;
  61. const int rlen = ext4_rec_len_from_disk(de->rec_len,
  62. dir->i_sb->s_blocksize);
  63. if (unlikely(rlen < EXT4_DIR_REC_LEN(1)))
  64. error_msg = "rec_len is smaller than minimal";
  65. else if (unlikely(rlen % 4 != 0))
  66. error_msg = "rec_len % 4 != 0";
  67. else if (unlikely(rlen < EXT4_DIR_REC_LEN(de->name_len)))
  68. error_msg = "rec_len is too small for name_len";
  69. else if (unlikely(((char *) de - buf) + rlen > size))
  70. error_msg = "directory entry across range";
  71. else if (unlikely(le32_to_cpu(de->inode) >
  72. le32_to_cpu(EXT4_SB(dir->i_sb)->s_es->s_inodes_count)))
  73. error_msg = "inode out of bounds";
  74. else
  75. return 0;
  76. if (filp)
  77. ext4_error_file(filp, function, line, bh->b_blocknr,
  78. "bad entry in directory: %s - offset=%u(%u), "
  79. "inode=%u, rec_len=%d, name_len=%d",
  80. error_msg, (unsigned) (offset % size),
  81. offset, le32_to_cpu(de->inode),
  82. rlen, de->name_len);
  83. else
  84. ext4_error_inode(dir, function, line, bh->b_blocknr,
  85. "bad entry in directory: %s - offset=%u(%u), "
  86. "inode=%u, rec_len=%d, name_len=%d",
  87. error_msg, (unsigned) (offset % size),
  88. offset, le32_to_cpu(de->inode),
  89. rlen, de->name_len);
  90. return 1;
  91. }
  92. static int ext4_readdir(struct file *file, struct dir_context *ctx)
  93. {
  94. unsigned int offset;
  95. int i;
  96. struct ext4_dir_entry_2 *de;
  97. int err;
  98. struct inode *inode = file_inode(file);
  99. struct super_block *sb = inode->i_sb;
  100. struct buffer_head *bh = NULL;
  101. int dir_has_error = 0;
  102. struct fscrypt_str fstr = FSTR_INIT(NULL, 0);
  103. if (ext4_encrypted_inode(inode)) {
  104. err = fscrypt_get_encryption_info(inode);
  105. if (err && err != -ENOKEY)
  106. return err;
  107. }
  108. if (is_dx_dir(inode)) {
  109. err = ext4_dx_readdir(file, ctx);
  110. if (err != ERR_BAD_DX_DIR) {
  111. return err;
  112. }
  113. /*
  114. * We don't set the inode dirty flag since it's not
  115. * critical that it get flushed back to the disk.
  116. */
  117. ext4_clear_inode_flag(file_inode(file),
  118. EXT4_INODE_INDEX);
  119. }
  120. if (ext4_has_inline_data(inode)) {
  121. int has_inline_data = 1;
  122. err = ext4_read_inline_dir(file, ctx,
  123. &has_inline_data);
  124. if (has_inline_data)
  125. return err;
  126. }
  127. if (ext4_encrypted_inode(inode)) {
  128. err = fscrypt_fname_alloc_buffer(inode, EXT4_NAME_LEN, &fstr);
  129. if (err < 0)
  130. return err;
  131. }
  132. offset = ctx->pos & (sb->s_blocksize - 1);
  133. while (ctx->pos < inode->i_size) {
  134. struct ext4_map_blocks map;
  135. if (fatal_signal_pending(current)) {
  136. err = -ERESTARTSYS;
  137. goto errout;
  138. }
  139. cond_resched();
  140. map.m_lblk = ctx->pos >> EXT4_BLOCK_SIZE_BITS(sb);
  141. map.m_len = 1;
  142. err = ext4_map_blocks(NULL, inode, &map, 0);
  143. if (err > 0) {
  144. pgoff_t index = map.m_pblk >>
  145. (PAGE_SHIFT - inode->i_blkbits);
  146. if (!ra_has_index(&file->f_ra, index))
  147. page_cache_sync_readahead(
  148. sb->s_bdev->bd_inode->i_mapping,
  149. &file->f_ra, file,
  150. index, 1);
  151. file->f_ra.prev_pos = (loff_t)index << PAGE_SHIFT;
  152. bh = ext4_bread(NULL, inode, map.m_lblk, 0);
  153. if (IS_ERR(bh)) {
  154. err = PTR_ERR(bh);
  155. bh = NULL;
  156. goto errout;
  157. }
  158. }
  159. if (!bh) {
  160. if (!dir_has_error) {
  161. EXT4_ERROR_FILE(file, 0,
  162. "directory contains a "
  163. "hole at offset %llu",
  164. (unsigned long long) ctx->pos);
  165. dir_has_error = 1;
  166. }
  167. /* corrupt size? Maybe no more blocks to read */
  168. if (ctx->pos > inode->i_blocks << 9)
  169. break;
  170. ctx->pos += sb->s_blocksize - offset;
  171. continue;
  172. }
  173. /* Check the checksum */
  174. if (!buffer_verified(bh) &&
  175. !ext4_dirent_csum_verify(inode,
  176. (struct ext4_dir_entry *)bh->b_data)) {
  177. EXT4_ERROR_FILE(file, 0, "directory fails checksum "
  178. "at offset %llu",
  179. (unsigned long long)ctx->pos);
  180. ctx->pos += sb->s_blocksize - offset;
  181. brelse(bh);
  182. bh = NULL;
  183. continue;
  184. }
  185. set_buffer_verified(bh);
  186. /* If the dir block has changed since the last call to
  187. * readdir(2), then we might be pointing to an invalid
  188. * dirent right now. Scan from the start of the block
  189. * to make sure. */
  190. if (file->f_version != inode->i_version) {
  191. for (i = 0; i < sb->s_blocksize && i < offset; ) {
  192. de = (struct ext4_dir_entry_2 *)
  193. (bh->b_data + i);
  194. /* It's too expensive to do a full
  195. * dirent test each time round this
  196. * loop, but we do have to test at
  197. * least that it is non-zero. A
  198. * failure will be detected in the
  199. * dirent test below. */
  200. if (ext4_rec_len_from_disk(de->rec_len,
  201. sb->s_blocksize) < EXT4_DIR_REC_LEN(1))
  202. break;
  203. i += ext4_rec_len_from_disk(de->rec_len,
  204. sb->s_blocksize);
  205. }
  206. offset = i;
  207. ctx->pos = (ctx->pos & ~(sb->s_blocksize - 1))
  208. | offset;
  209. file->f_version = inode->i_version;
  210. }
  211. while (ctx->pos < inode->i_size
  212. && offset < sb->s_blocksize) {
  213. de = (struct ext4_dir_entry_2 *) (bh->b_data + offset);
  214. if (ext4_check_dir_entry(inode, file, de, bh,
  215. bh->b_data, bh->b_size,
  216. offset)) {
  217. /*
  218. * On error, skip to the next block
  219. */
  220. ctx->pos = (ctx->pos |
  221. (sb->s_blocksize - 1)) + 1;
  222. break;
  223. }
  224. offset += ext4_rec_len_from_disk(de->rec_len,
  225. sb->s_blocksize);
  226. if (le32_to_cpu(de->inode)) {
  227. if (!ext4_encrypted_inode(inode)) {
  228. if (!dir_emit(ctx, de->name,
  229. de->name_len,
  230. le32_to_cpu(de->inode),
  231. get_dtype(sb, de->file_type)))
  232. goto done;
  233. } else {
  234. int save_len = fstr.len;
  235. struct fscrypt_str de_name =
  236. FSTR_INIT(de->name,
  237. de->name_len);
  238. /* Directory is encrypted */
  239. err = fscrypt_fname_disk_to_usr(inode,
  240. 0, 0, &de_name, &fstr);
  241. fstr.len = save_len;
  242. if (err < 0)
  243. goto errout;
  244. if (!dir_emit(ctx,
  245. fstr.name, err,
  246. le32_to_cpu(de->inode),
  247. get_dtype(sb, de->file_type)))
  248. goto done;
  249. }
  250. }
  251. ctx->pos += ext4_rec_len_from_disk(de->rec_len,
  252. sb->s_blocksize);
  253. }
  254. if ((ctx->pos < inode->i_size) && !dir_relax_shared(inode))
  255. goto done;
  256. brelse(bh);
  257. bh = NULL;
  258. offset = 0;
  259. }
  260. done:
  261. err = 0;
  262. errout:
  263. #ifdef CONFIG_EXT4_FS_ENCRYPTION
  264. fscrypt_fname_free_buffer(&fstr);
  265. #endif
  266. brelse(bh);
  267. return err;
  268. }
  269. static inline int is_32bit_api(void)
  270. {
  271. #ifdef CONFIG_COMPAT
  272. return in_compat_syscall();
  273. #else
  274. return (BITS_PER_LONG == 32);
  275. #endif
  276. }
  277. /*
  278. * These functions convert from the major/minor hash to an f_pos
  279. * value for dx directories
  280. *
  281. * Upper layer (for example NFS) should specify FMODE_32BITHASH or
  282. * FMODE_64BITHASH explicitly. On the other hand, we allow ext4 to be mounted
  283. * directly on both 32-bit and 64-bit nodes, under such case, neither
  284. * FMODE_32BITHASH nor FMODE_64BITHASH is specified.
  285. */
  286. static inline loff_t hash2pos(struct file *filp, __u32 major, __u32 minor)
  287. {
  288. if ((filp->f_mode & FMODE_32BITHASH) ||
  289. (!(filp->f_mode & FMODE_64BITHASH) && is_32bit_api()))
  290. return major >> 1;
  291. else
  292. return ((__u64)(major >> 1) << 32) | (__u64)minor;
  293. }
  294. static inline __u32 pos2maj_hash(struct file *filp, loff_t pos)
  295. {
  296. if ((filp->f_mode & FMODE_32BITHASH) ||
  297. (!(filp->f_mode & FMODE_64BITHASH) && is_32bit_api()))
  298. return (pos << 1) & 0xffffffff;
  299. else
  300. return ((pos >> 32) << 1) & 0xffffffff;
  301. }
  302. static inline __u32 pos2min_hash(struct file *filp, loff_t pos)
  303. {
  304. if ((filp->f_mode & FMODE_32BITHASH) ||
  305. (!(filp->f_mode & FMODE_64BITHASH) && is_32bit_api()))
  306. return 0;
  307. else
  308. return pos & 0xffffffff;
  309. }
  310. /*
  311. * Return 32- or 64-bit end-of-file for dx directories
  312. */
  313. static inline loff_t ext4_get_htree_eof(struct file *filp)
  314. {
  315. if ((filp->f_mode & FMODE_32BITHASH) ||
  316. (!(filp->f_mode & FMODE_64BITHASH) && is_32bit_api()))
  317. return EXT4_HTREE_EOF_32BIT;
  318. else
  319. return EXT4_HTREE_EOF_64BIT;
  320. }
  321. /*
  322. * ext4_dir_llseek() calls generic_file_llseek_size to handle htree
  323. * directories, where the "offset" is in terms of the filename hash
  324. * value instead of the byte offset.
  325. *
  326. * Because we may return a 64-bit hash that is well beyond offset limits,
  327. * we need to pass the max hash as the maximum allowable offset in
  328. * the htree directory case.
  329. *
  330. * For non-htree, ext4_llseek already chooses the proper max offset.
  331. */
  332. static loff_t ext4_dir_llseek(struct file *file, loff_t offset, int whence)
  333. {
  334. struct inode *inode = file->f_mapping->host;
  335. int dx_dir = is_dx_dir(inode);
  336. loff_t htree_max = ext4_get_htree_eof(file);
  337. if (likely(dx_dir))
  338. return generic_file_llseek_size(file, offset, whence,
  339. htree_max, htree_max);
  340. else
  341. return ext4_llseek(file, offset, whence);
  342. }
  343. /*
  344. * This structure holds the nodes of the red-black tree used to store
  345. * the directory entry in hash order.
  346. */
  347. struct fname {
  348. __u32 hash;
  349. __u32 minor_hash;
  350. struct rb_node rb_hash;
  351. struct fname *next;
  352. __u32 inode;
  353. __u8 name_len;
  354. __u8 file_type;
  355. char name[0];
  356. };
  357. /*
  358. * This functoin implements a non-recursive way of freeing all of the
  359. * nodes in the red-black tree.
  360. */
  361. static void free_rb_tree_fname(struct rb_root *root)
  362. {
  363. struct fname *fname, *next;
  364. rbtree_postorder_for_each_entry_safe(fname, next, root, rb_hash)
  365. while (fname) {
  366. struct fname *old = fname;
  367. fname = fname->next;
  368. kfree(old);
  369. }
  370. *root = RB_ROOT;
  371. }
  372. static struct dir_private_info *ext4_htree_create_dir_info(struct file *filp,
  373. loff_t pos)
  374. {
  375. struct dir_private_info *p;
  376. p = kzalloc(sizeof(struct dir_private_info), GFP_KERNEL);
  377. if (!p)
  378. return NULL;
  379. p->curr_hash = pos2maj_hash(filp, pos);
  380. p->curr_minor_hash = pos2min_hash(filp, pos);
  381. return p;
  382. }
  383. void ext4_htree_free_dir_info(struct dir_private_info *p)
  384. {
  385. free_rb_tree_fname(&p->root);
  386. kfree(p);
  387. }
  388. /*
  389. * Given a directory entry, enter it into the fname rb tree.
  390. *
  391. * When filename encryption is enabled, the dirent will hold the
  392. * encrypted filename, while the htree will hold decrypted filename.
  393. * The decrypted filename is passed in via ent_name. parameter.
  394. */
  395. int ext4_htree_store_dirent(struct file *dir_file, __u32 hash,
  396. __u32 minor_hash,
  397. struct ext4_dir_entry_2 *dirent,
  398. struct fscrypt_str *ent_name)
  399. {
  400. struct rb_node **p, *parent = NULL;
  401. struct fname *fname, *new_fn;
  402. struct dir_private_info *info;
  403. int len;
  404. info = dir_file->private_data;
  405. p = &info->root.rb_node;
  406. /* Create and allocate the fname structure */
  407. len = sizeof(struct fname) + ent_name->len + 1;
  408. new_fn = kzalloc(len, GFP_KERNEL);
  409. if (!new_fn)
  410. return -ENOMEM;
  411. new_fn->hash = hash;
  412. new_fn->minor_hash = minor_hash;
  413. new_fn->inode = le32_to_cpu(dirent->inode);
  414. new_fn->name_len = ent_name->len;
  415. new_fn->file_type = dirent->file_type;
  416. memcpy(new_fn->name, ent_name->name, ent_name->len);
  417. new_fn->name[ent_name->len] = 0;
  418. while (*p) {
  419. parent = *p;
  420. fname = rb_entry(parent, struct fname, rb_hash);
  421. /*
  422. * If the hash and minor hash match up, then we put
  423. * them on a linked list. This rarely happens...
  424. */
  425. if ((new_fn->hash == fname->hash) &&
  426. (new_fn->minor_hash == fname->minor_hash)) {
  427. new_fn->next = fname->next;
  428. fname->next = new_fn;
  429. return 0;
  430. }
  431. if (new_fn->hash < fname->hash)
  432. p = &(*p)->rb_left;
  433. else if (new_fn->hash > fname->hash)
  434. p = &(*p)->rb_right;
  435. else if (new_fn->minor_hash < fname->minor_hash)
  436. p = &(*p)->rb_left;
  437. else /* if (new_fn->minor_hash > fname->minor_hash) */
  438. p = &(*p)->rb_right;
  439. }
  440. rb_link_node(&new_fn->rb_hash, parent, p);
  441. rb_insert_color(&new_fn->rb_hash, &info->root);
  442. return 0;
  443. }
  444. /*
  445. * This is a helper function for ext4_dx_readdir. It calls filldir
  446. * for all entres on the fname linked list. (Normally there is only
  447. * one entry on the linked list, unless there are 62 bit hash collisions.)
  448. */
  449. static int call_filldir(struct file *file, struct dir_context *ctx,
  450. struct fname *fname)
  451. {
  452. struct dir_private_info *info = file->private_data;
  453. struct inode *inode = file_inode(file);
  454. struct super_block *sb = inode->i_sb;
  455. if (!fname) {
  456. ext4_msg(sb, KERN_ERR, "%s:%d: inode #%lu: comm %s: "
  457. "called with null fname?!?", __func__, __LINE__,
  458. inode->i_ino, current->comm);
  459. return 0;
  460. }
  461. ctx->pos = hash2pos(file, fname->hash, fname->minor_hash);
  462. while (fname) {
  463. if (!dir_emit(ctx, fname->name,
  464. fname->name_len,
  465. fname->inode,
  466. get_dtype(sb, fname->file_type))) {
  467. info->extra_fname = fname;
  468. return 1;
  469. }
  470. fname = fname->next;
  471. }
  472. return 0;
  473. }
  474. static int ext4_dx_readdir(struct file *file, struct dir_context *ctx)
  475. {
  476. struct dir_private_info *info = file->private_data;
  477. struct inode *inode = file_inode(file);
  478. struct fname *fname;
  479. int ret;
  480. if (!info) {
  481. info = ext4_htree_create_dir_info(file, ctx->pos);
  482. if (!info)
  483. return -ENOMEM;
  484. file->private_data = info;
  485. }
  486. if (ctx->pos == ext4_get_htree_eof(file))
  487. return 0; /* EOF */
  488. /* Some one has messed with f_pos; reset the world */
  489. if (info->last_pos != ctx->pos) {
  490. free_rb_tree_fname(&info->root);
  491. info->curr_node = NULL;
  492. info->extra_fname = NULL;
  493. info->curr_hash = pos2maj_hash(file, ctx->pos);
  494. info->curr_minor_hash = pos2min_hash(file, ctx->pos);
  495. }
  496. /*
  497. * If there are any leftover names on the hash collision
  498. * chain, return them first.
  499. */
  500. if (info->extra_fname) {
  501. if (call_filldir(file, ctx, info->extra_fname))
  502. goto finished;
  503. info->extra_fname = NULL;
  504. goto next_node;
  505. } else if (!info->curr_node)
  506. info->curr_node = rb_first(&info->root);
  507. while (1) {
  508. /*
  509. * Fill the rbtree if we have no more entries,
  510. * or the inode has changed since we last read in the
  511. * cached entries.
  512. */
  513. if ((!info->curr_node) ||
  514. (file->f_version != inode->i_version)) {
  515. info->curr_node = NULL;
  516. free_rb_tree_fname(&info->root);
  517. file->f_version = inode->i_version;
  518. ret = ext4_htree_fill_tree(file, info->curr_hash,
  519. info->curr_minor_hash,
  520. &info->next_hash);
  521. if (ret < 0)
  522. return ret;
  523. if (ret == 0) {
  524. ctx->pos = ext4_get_htree_eof(file);
  525. break;
  526. }
  527. info->curr_node = rb_first(&info->root);
  528. }
  529. fname = rb_entry(info->curr_node, struct fname, rb_hash);
  530. info->curr_hash = fname->hash;
  531. info->curr_minor_hash = fname->minor_hash;
  532. if (call_filldir(file, ctx, fname))
  533. break;
  534. next_node:
  535. info->curr_node = rb_next(info->curr_node);
  536. if (info->curr_node) {
  537. fname = rb_entry(info->curr_node, struct fname,
  538. rb_hash);
  539. info->curr_hash = fname->hash;
  540. info->curr_minor_hash = fname->minor_hash;
  541. } else {
  542. if (info->next_hash == ~0) {
  543. ctx->pos = ext4_get_htree_eof(file);
  544. break;
  545. }
  546. info->curr_hash = info->next_hash;
  547. info->curr_minor_hash = 0;
  548. }
  549. }
  550. finished:
  551. info->last_pos = ctx->pos;
  552. return 0;
  553. }
  554. static int ext4_dir_open(struct inode * inode, struct file * filp)
  555. {
  556. if (ext4_encrypted_inode(inode))
  557. return fscrypt_get_encryption_info(inode) ? -EACCES : 0;
  558. return 0;
  559. }
  560. static int ext4_release_dir(struct inode *inode, struct file *filp)
  561. {
  562. if (filp->private_data)
  563. ext4_htree_free_dir_info(filp->private_data);
  564. return 0;
  565. }
  566. int ext4_check_all_de(struct inode *dir, struct buffer_head *bh, void *buf,
  567. int buf_size)
  568. {
  569. struct ext4_dir_entry_2 *de;
  570. int nlen, rlen;
  571. unsigned int offset = 0;
  572. char *top;
  573. de = (struct ext4_dir_entry_2 *)buf;
  574. top = buf + buf_size;
  575. while ((char *) de < top) {
  576. if (ext4_check_dir_entry(dir, NULL, de, bh,
  577. buf, buf_size, offset))
  578. return -EFSCORRUPTED;
  579. nlen = EXT4_DIR_REC_LEN(de->name_len);
  580. rlen = ext4_rec_len_from_disk(de->rec_len, buf_size);
  581. de = (struct ext4_dir_entry_2 *)((char *)de + rlen);
  582. offset += rlen;
  583. }
  584. if ((char *) de > top)
  585. return -EFSCORRUPTED;
  586. return 0;
  587. }
  588. const struct file_operations ext4_dir_operations = {
  589. .llseek = ext4_dir_llseek,
  590. .read = generic_read_dir,
  591. .iterate_shared = ext4_readdir,
  592. .unlocked_ioctl = ext4_ioctl,
  593. #ifdef CONFIG_COMPAT
  594. .compat_ioctl = ext4_compat_ioctl,
  595. #endif
  596. .fsync = ext4_sync_file,
  597. .open = ext4_dir_open,
  598. .release = ext4_release_dir,
  599. };