dir.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670
  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/jbd2.h>
  25. #include <linux/buffer_head.h>
  26. #include <linux/slab.h>
  27. #include <linux/rbtree.h>
  28. #include "ext4.h"
  29. static unsigned char ext4_filetype_table[] = {
  30. DT_UNKNOWN, DT_REG, DT_DIR, DT_CHR, DT_BLK, DT_FIFO, DT_SOCK, DT_LNK
  31. };
  32. static int ext4_dx_readdir(struct file *filp,
  33. void *dirent, filldir_t filldir);
  34. static unsigned char get_dtype(struct super_block *sb, int filetype)
  35. {
  36. if (!EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_FILETYPE) ||
  37. (filetype >= EXT4_FT_MAX))
  38. return DT_UNKNOWN;
  39. return (ext4_filetype_table[filetype]);
  40. }
  41. /**
  42. * Check if the given dir-inode refers to an htree-indexed directory
  43. * (or a directory which chould potentially get coverted to use htree
  44. * indexing).
  45. *
  46. * Return 1 if it is a dx dir, 0 if not
  47. */
  48. static int is_dx_dir(struct inode *inode)
  49. {
  50. struct super_block *sb = inode->i_sb;
  51. if (EXT4_HAS_COMPAT_FEATURE(inode->i_sb,
  52. EXT4_FEATURE_COMPAT_DIR_INDEX) &&
  53. ((ext4_test_inode_flag(inode, EXT4_INODE_INDEX)) ||
  54. ((inode->i_size >> sb->s_blocksize_bits) == 1)))
  55. return 1;
  56. return 0;
  57. }
  58. /*
  59. * Return 0 if the directory entry is OK, and 1 if there is a problem
  60. *
  61. * Note: this is the opposite of what ext2 and ext3 historically returned...
  62. */
  63. int __ext4_check_dir_entry(const char *function, unsigned int line,
  64. struct inode *dir, struct file *filp,
  65. struct ext4_dir_entry_2 *de,
  66. struct buffer_head *bh,
  67. unsigned int offset)
  68. {
  69. const char *error_msg = NULL;
  70. const int rlen = ext4_rec_len_from_disk(de->rec_len,
  71. dir->i_sb->s_blocksize);
  72. if (unlikely(rlen < EXT4_DIR_REC_LEN(1)))
  73. error_msg = "rec_len is smaller than minimal";
  74. else if (unlikely(rlen % 4 != 0))
  75. error_msg = "rec_len % 4 != 0";
  76. else if (unlikely(rlen < EXT4_DIR_REC_LEN(de->name_len)))
  77. error_msg = "rec_len is too small for name_len";
  78. else if (unlikely(((char *) de - bh->b_data) + rlen >
  79. dir->i_sb->s_blocksize))
  80. error_msg = "directory entry across blocks";
  81. else if (unlikely(le32_to_cpu(de->inode) >
  82. le32_to_cpu(EXT4_SB(dir->i_sb)->s_es->s_inodes_count)))
  83. error_msg = "inode out of bounds";
  84. else
  85. return 0;
  86. print_bh(dir->i_sb, bh, 0, EXT4_BLOCK_SIZE(dir->i_sb));
  87. if (filp)
  88. ext4_error_file(filp, function, line, bh->b_blocknr,
  89. "bad entry in directory: %s - offset=%u(%u), "
  90. "inode=%u, rec_len=%d, name_len=%d",
  91. error_msg, (unsigned) (offset % bh->b_size),
  92. offset, le32_to_cpu(de->inode),
  93. rlen, de->name_len);
  94. else
  95. ext4_error_inode(dir, function, line, bh->b_blocknr,
  96. "bad entry in directory: %s - offset=%u(%u), "
  97. "inode=%u, rec_len=%d, name_len=%d",
  98. error_msg, (unsigned) (offset % bh->b_size),
  99. offset, le32_to_cpu(de->inode),
  100. rlen, de->name_len);
  101. return 1;
  102. }
  103. static int ext4_readdir(struct file *filp,
  104. void *dirent, filldir_t filldir)
  105. {
  106. int error = 0;
  107. unsigned int offset;
  108. int i, stored;
  109. struct ext4_dir_entry_2 *de;
  110. int err;
  111. struct inode *inode = filp->f_path.dentry->d_inode;
  112. struct super_block *sb = inode->i_sb;
  113. int ret = 0;
  114. int dir_has_error = 0;
  115. if (is_dx_dir(inode)) {
  116. err = ext4_dx_readdir(filp, dirent, filldir);
  117. if (err != ERR_BAD_DX_DIR) {
  118. ret = err;
  119. goto out;
  120. }
  121. /*
  122. * We don't set the inode dirty flag since it's not
  123. * critical that it get flushed back to the disk.
  124. */
  125. ext4_clear_inode_flag(filp->f_path.dentry->d_inode,
  126. EXT4_INODE_INDEX);
  127. }
  128. stored = 0;
  129. offset = filp->f_pos & (sb->s_blocksize - 1);
  130. while (!error && !stored && filp->f_pos < inode->i_size) {
  131. struct ext4_map_blocks map;
  132. struct buffer_head *bh = NULL;
  133. map.m_lblk = filp->f_pos >> EXT4_BLOCK_SIZE_BITS(sb);
  134. map.m_len = 1;
  135. err = ext4_map_blocks(NULL, inode, &map, 0);
  136. if (err > 0) {
  137. pgoff_t index = map.m_pblk >>
  138. (PAGE_CACHE_SHIFT - inode->i_blkbits);
  139. if (!ra_has_index(&filp->f_ra, index))
  140. page_cache_sync_readahead(
  141. sb->s_bdev->bd_inode->i_mapping,
  142. &filp->f_ra, filp,
  143. index, 1);
  144. filp->f_ra.prev_pos = (loff_t)index << PAGE_CACHE_SHIFT;
  145. bh = ext4_bread(NULL, inode, map.m_lblk, 0, &err);
  146. }
  147. /*
  148. * We ignore I/O errors on directories so users have a chance
  149. * of recovering data when there's a bad sector
  150. */
  151. if (!bh) {
  152. if (!dir_has_error) {
  153. EXT4_ERROR_FILE(filp, 0,
  154. "directory contains a "
  155. "hole at offset %llu",
  156. (unsigned long long) filp->f_pos);
  157. dir_has_error = 1;
  158. }
  159. /* corrupt size? Maybe no more blocks to read */
  160. if (filp->f_pos > inode->i_blocks << 9)
  161. break;
  162. filp->f_pos += sb->s_blocksize - offset;
  163. continue;
  164. }
  165. revalidate:
  166. /* If the dir block has changed since the last call to
  167. * readdir(2), then we might be pointing to an invalid
  168. * dirent right now. Scan from the start of the block
  169. * to make sure. */
  170. if (filp->f_version != inode->i_version) {
  171. for (i = 0; i < sb->s_blocksize && i < offset; ) {
  172. de = (struct ext4_dir_entry_2 *)
  173. (bh->b_data + i);
  174. /* It's too expensive to do a full
  175. * dirent test each time round this
  176. * loop, but we do have to test at
  177. * least that it is non-zero. A
  178. * failure will be detected in the
  179. * dirent test below. */
  180. if (ext4_rec_len_from_disk(de->rec_len,
  181. sb->s_blocksize) < EXT4_DIR_REC_LEN(1))
  182. break;
  183. i += ext4_rec_len_from_disk(de->rec_len,
  184. sb->s_blocksize);
  185. }
  186. offset = i;
  187. filp->f_pos = (filp->f_pos & ~(sb->s_blocksize - 1))
  188. | offset;
  189. filp->f_version = inode->i_version;
  190. }
  191. while (!error && filp->f_pos < inode->i_size
  192. && offset < sb->s_blocksize) {
  193. de = (struct ext4_dir_entry_2 *) (bh->b_data + offset);
  194. if (ext4_check_dir_entry(inode, filp, de,
  195. bh, offset)) {
  196. /*
  197. * On error, skip the f_pos to the next block
  198. */
  199. filp->f_pos = (filp->f_pos |
  200. (sb->s_blocksize - 1)) + 1;
  201. brelse(bh);
  202. ret = stored;
  203. goto out;
  204. }
  205. offset += ext4_rec_len_from_disk(de->rec_len,
  206. sb->s_blocksize);
  207. if (le32_to_cpu(de->inode)) {
  208. /* We might block in the next section
  209. * if the data destination is
  210. * currently swapped out. So, use a
  211. * version stamp to detect whether or
  212. * not the directory has been modified
  213. * during the copy operation.
  214. */
  215. u64 version = filp->f_version;
  216. error = filldir(dirent, de->name,
  217. de->name_len,
  218. filp->f_pos,
  219. le32_to_cpu(de->inode),
  220. get_dtype(sb, de->file_type));
  221. if (error)
  222. break;
  223. if (version != filp->f_version)
  224. goto revalidate;
  225. stored++;
  226. }
  227. filp->f_pos += ext4_rec_len_from_disk(de->rec_len,
  228. sb->s_blocksize);
  229. }
  230. offset = 0;
  231. brelse(bh);
  232. }
  233. out:
  234. return ret;
  235. }
  236. static inline int is_32bit_api(void)
  237. {
  238. #ifdef CONFIG_COMPAT
  239. return is_compat_task();
  240. #else
  241. return (BITS_PER_LONG == 32);
  242. #endif
  243. }
  244. /*
  245. * These functions convert from the major/minor hash to an f_pos
  246. * value for dx directories
  247. *
  248. * Upper layer (for example NFS) should specify FMODE_32BITHASH or
  249. * FMODE_64BITHASH explicitly. On the other hand, we allow ext4 to be mounted
  250. * directly on both 32-bit and 64-bit nodes, under such case, neither
  251. * FMODE_32BITHASH nor FMODE_64BITHASH is specified.
  252. */
  253. static inline loff_t hash2pos(struct file *filp, __u32 major, __u32 minor)
  254. {
  255. if ((filp->f_mode & FMODE_32BITHASH) ||
  256. (!(filp->f_mode & FMODE_64BITHASH) && is_32bit_api()))
  257. return major >> 1;
  258. else
  259. return ((__u64)(major >> 1) << 32) | (__u64)minor;
  260. }
  261. static inline __u32 pos2maj_hash(struct file *filp, loff_t pos)
  262. {
  263. if ((filp->f_mode & FMODE_32BITHASH) ||
  264. (!(filp->f_mode & FMODE_64BITHASH) && is_32bit_api()))
  265. return (pos << 1) & 0xffffffff;
  266. else
  267. return ((pos >> 32) << 1) & 0xffffffff;
  268. }
  269. static inline __u32 pos2min_hash(struct file *filp, loff_t pos)
  270. {
  271. if ((filp->f_mode & FMODE_32BITHASH) ||
  272. (!(filp->f_mode & FMODE_64BITHASH) && is_32bit_api()))
  273. return 0;
  274. else
  275. return pos & 0xffffffff;
  276. }
  277. /*
  278. * Return 32- or 64-bit end-of-file for dx directories
  279. */
  280. static inline loff_t ext4_get_htree_eof(struct file *filp)
  281. {
  282. if ((filp->f_mode & FMODE_32BITHASH) ||
  283. (!(filp->f_mode & FMODE_64BITHASH) && is_32bit_api()))
  284. return EXT4_HTREE_EOF_32BIT;
  285. else
  286. return EXT4_HTREE_EOF_64BIT;
  287. }
  288. /*
  289. * ext4_dir_llseek() based on generic_file_llseek() to handle both
  290. * non-htree and htree directories, where the "offset" is in terms
  291. * of the filename hash value instead of the byte offset.
  292. *
  293. * NOTE: offsets obtained *before* ext4_set_inode_flag(dir, EXT4_INODE_INDEX)
  294. * will be invalid once the directory was converted into a dx directory
  295. */
  296. loff_t ext4_dir_llseek(struct file *file, loff_t offset, int origin)
  297. {
  298. struct inode *inode = file->f_mapping->host;
  299. loff_t ret = -EINVAL;
  300. int dx_dir = is_dx_dir(inode);
  301. mutex_lock(&inode->i_mutex);
  302. /* NOTE: relative offsets with dx directories might not work
  303. * as expected, as it is difficult to figure out the
  304. * correct offset between dx hashes */
  305. switch (origin) {
  306. case SEEK_END:
  307. if (unlikely(offset > 0))
  308. goto out_err; /* not supported for directories */
  309. /* so only negative offsets are left, does that have a
  310. * meaning for directories at all? */
  311. if (dx_dir)
  312. offset += ext4_get_htree_eof(file);
  313. else
  314. offset += inode->i_size;
  315. break;
  316. case SEEK_CUR:
  317. /*
  318. * Here we special-case the lseek(fd, 0, SEEK_CUR)
  319. * position-querying operation. Avoid rewriting the "same"
  320. * f_pos value back to the file because a concurrent read(),
  321. * write() or lseek() might have altered it
  322. */
  323. if (offset == 0) {
  324. offset = file->f_pos;
  325. goto out_ok;
  326. }
  327. offset += file->f_pos;
  328. break;
  329. }
  330. if (unlikely(offset < 0))
  331. goto out_err;
  332. if (!dx_dir) {
  333. if (offset > inode->i_sb->s_maxbytes)
  334. goto out_err;
  335. } else if (offset > ext4_get_htree_eof(file))
  336. goto out_err;
  337. /* Special lock needed here? */
  338. if (offset != file->f_pos) {
  339. file->f_pos = offset;
  340. file->f_version = 0;
  341. }
  342. out_ok:
  343. ret = offset;
  344. out_err:
  345. mutex_unlock(&inode->i_mutex);
  346. return ret;
  347. }
  348. /*
  349. * This structure holds the nodes of the red-black tree used to store
  350. * the directory entry in hash order.
  351. */
  352. struct fname {
  353. __u32 hash;
  354. __u32 minor_hash;
  355. struct rb_node rb_hash;
  356. struct fname *next;
  357. __u32 inode;
  358. __u8 name_len;
  359. __u8 file_type;
  360. char name[0];
  361. };
  362. /*
  363. * This functoin implements a non-recursive way of freeing all of the
  364. * nodes in the red-black tree.
  365. */
  366. static void free_rb_tree_fname(struct rb_root *root)
  367. {
  368. struct rb_node *n = root->rb_node;
  369. struct rb_node *parent;
  370. struct fname *fname;
  371. while (n) {
  372. /* Do the node's children first */
  373. if (n->rb_left) {
  374. n = n->rb_left;
  375. continue;
  376. }
  377. if (n->rb_right) {
  378. n = n->rb_right;
  379. continue;
  380. }
  381. /*
  382. * The node has no children; free it, and then zero
  383. * out parent's link to it. Finally go to the
  384. * beginning of the loop and try to free the parent
  385. * node.
  386. */
  387. parent = rb_parent(n);
  388. fname = rb_entry(n, struct fname, rb_hash);
  389. while (fname) {
  390. struct fname *old = fname;
  391. fname = fname->next;
  392. kfree(old);
  393. }
  394. if (!parent)
  395. *root = RB_ROOT;
  396. else if (parent->rb_left == n)
  397. parent->rb_left = NULL;
  398. else if (parent->rb_right == n)
  399. parent->rb_right = NULL;
  400. n = parent;
  401. }
  402. }
  403. static struct dir_private_info *ext4_htree_create_dir_info(struct file *filp,
  404. loff_t pos)
  405. {
  406. struct dir_private_info *p;
  407. p = kzalloc(sizeof(struct dir_private_info), GFP_KERNEL);
  408. if (!p)
  409. return NULL;
  410. p->curr_hash = pos2maj_hash(filp, pos);
  411. p->curr_minor_hash = pos2min_hash(filp, pos);
  412. return p;
  413. }
  414. void ext4_htree_free_dir_info(struct dir_private_info *p)
  415. {
  416. free_rb_tree_fname(&p->root);
  417. kfree(p);
  418. }
  419. /*
  420. * Given a directory entry, enter it into the fname rb tree.
  421. */
  422. int ext4_htree_store_dirent(struct file *dir_file, __u32 hash,
  423. __u32 minor_hash,
  424. struct ext4_dir_entry_2 *dirent)
  425. {
  426. struct rb_node **p, *parent = NULL;
  427. struct fname *fname, *new_fn;
  428. struct dir_private_info *info;
  429. int len;
  430. info = dir_file->private_data;
  431. p = &info->root.rb_node;
  432. /* Create and allocate the fname structure */
  433. len = sizeof(struct fname) + dirent->name_len + 1;
  434. new_fn = kzalloc(len, GFP_KERNEL);
  435. if (!new_fn)
  436. return -ENOMEM;
  437. new_fn->hash = hash;
  438. new_fn->minor_hash = minor_hash;
  439. new_fn->inode = le32_to_cpu(dirent->inode);
  440. new_fn->name_len = dirent->name_len;
  441. new_fn->file_type = dirent->file_type;
  442. memcpy(new_fn->name, dirent->name, dirent->name_len);
  443. new_fn->name[dirent->name_len] = 0;
  444. while (*p) {
  445. parent = *p;
  446. fname = rb_entry(parent, struct fname, rb_hash);
  447. /*
  448. * If the hash and minor hash match up, then we put
  449. * them on a linked list. This rarely happens...
  450. */
  451. if ((new_fn->hash == fname->hash) &&
  452. (new_fn->minor_hash == fname->minor_hash)) {
  453. new_fn->next = fname->next;
  454. fname->next = new_fn;
  455. return 0;
  456. }
  457. if (new_fn->hash < fname->hash)
  458. p = &(*p)->rb_left;
  459. else if (new_fn->hash > fname->hash)
  460. p = &(*p)->rb_right;
  461. else if (new_fn->minor_hash < fname->minor_hash)
  462. p = &(*p)->rb_left;
  463. else /* if (new_fn->minor_hash > fname->minor_hash) */
  464. p = &(*p)->rb_right;
  465. }
  466. rb_link_node(&new_fn->rb_hash, parent, p);
  467. rb_insert_color(&new_fn->rb_hash, &info->root);
  468. return 0;
  469. }
  470. /*
  471. * This is a helper function for ext4_dx_readdir. It calls filldir
  472. * for all entres on the fname linked list. (Normally there is only
  473. * one entry on the linked list, unless there are 62 bit hash collisions.)
  474. */
  475. static int call_filldir(struct file *filp, void *dirent,
  476. filldir_t filldir, struct fname *fname)
  477. {
  478. struct dir_private_info *info = filp->private_data;
  479. loff_t curr_pos;
  480. struct inode *inode = filp->f_path.dentry->d_inode;
  481. struct super_block *sb;
  482. int error;
  483. sb = inode->i_sb;
  484. if (!fname) {
  485. ext4_msg(sb, KERN_ERR, "%s:%d: inode #%lu: comm %s: "
  486. "called with null fname?!?", __func__, __LINE__,
  487. inode->i_ino, current->comm);
  488. return 0;
  489. }
  490. curr_pos = hash2pos(filp, fname->hash, fname->minor_hash);
  491. while (fname) {
  492. error = filldir(dirent, fname->name,
  493. fname->name_len, curr_pos,
  494. fname->inode,
  495. get_dtype(sb, fname->file_type));
  496. if (error) {
  497. filp->f_pos = curr_pos;
  498. info->extra_fname = fname;
  499. return error;
  500. }
  501. fname = fname->next;
  502. }
  503. return 0;
  504. }
  505. static int ext4_dx_readdir(struct file *filp,
  506. void *dirent, filldir_t filldir)
  507. {
  508. struct dir_private_info *info = filp->private_data;
  509. struct inode *inode = filp->f_path.dentry->d_inode;
  510. struct fname *fname;
  511. int ret;
  512. if (!info) {
  513. info = ext4_htree_create_dir_info(filp, filp->f_pos);
  514. if (!info)
  515. return -ENOMEM;
  516. filp->private_data = info;
  517. }
  518. if (filp->f_pos == ext4_get_htree_eof(filp))
  519. return 0; /* EOF */
  520. /* Some one has messed with f_pos; reset the world */
  521. if (info->last_pos != filp->f_pos) {
  522. free_rb_tree_fname(&info->root);
  523. info->curr_node = NULL;
  524. info->extra_fname = NULL;
  525. info->curr_hash = pos2maj_hash(filp, filp->f_pos);
  526. info->curr_minor_hash = pos2min_hash(filp, filp->f_pos);
  527. }
  528. /*
  529. * If there are any leftover names on the hash collision
  530. * chain, return them first.
  531. */
  532. if (info->extra_fname) {
  533. if (call_filldir(filp, dirent, filldir, info->extra_fname))
  534. goto finished;
  535. info->extra_fname = NULL;
  536. goto next_node;
  537. } else if (!info->curr_node)
  538. info->curr_node = rb_first(&info->root);
  539. while (1) {
  540. /*
  541. * Fill the rbtree if we have no more entries,
  542. * or the inode has changed since we last read in the
  543. * cached entries.
  544. */
  545. if ((!info->curr_node) ||
  546. (filp->f_version != inode->i_version)) {
  547. info->curr_node = NULL;
  548. free_rb_tree_fname(&info->root);
  549. filp->f_version = inode->i_version;
  550. ret = ext4_htree_fill_tree(filp, info->curr_hash,
  551. info->curr_minor_hash,
  552. &info->next_hash);
  553. if (ret < 0)
  554. return ret;
  555. if (ret == 0) {
  556. filp->f_pos = ext4_get_htree_eof(filp);
  557. break;
  558. }
  559. info->curr_node = rb_first(&info->root);
  560. }
  561. fname = rb_entry(info->curr_node, struct fname, rb_hash);
  562. info->curr_hash = fname->hash;
  563. info->curr_minor_hash = fname->minor_hash;
  564. if (call_filldir(filp, dirent, filldir, fname))
  565. break;
  566. next_node:
  567. info->curr_node = rb_next(info->curr_node);
  568. if (info->curr_node) {
  569. fname = rb_entry(info->curr_node, struct fname,
  570. rb_hash);
  571. info->curr_hash = fname->hash;
  572. info->curr_minor_hash = fname->minor_hash;
  573. } else {
  574. if (info->next_hash == ~0) {
  575. filp->f_pos = ext4_get_htree_eof(filp);
  576. break;
  577. }
  578. info->curr_hash = info->next_hash;
  579. info->curr_minor_hash = 0;
  580. }
  581. }
  582. finished:
  583. info->last_pos = filp->f_pos;
  584. return 0;
  585. }
  586. static int ext4_release_dir(struct inode *inode, struct file *filp)
  587. {
  588. if (filp->private_data)
  589. ext4_htree_free_dir_info(filp->private_data);
  590. return 0;
  591. }
  592. const struct file_operations ext4_dir_operations = {
  593. .llseek = ext4_dir_llseek,
  594. .read = generic_read_dir,
  595. .readdir = ext4_readdir,
  596. .unlocked_ioctl = ext4_ioctl,
  597. #ifdef CONFIG_COMPAT
  598. .compat_ioctl = ext4_compat_ioctl,
  599. #endif
  600. .fsync = ext4_sync_file,
  601. .release = ext4_release_dir,
  602. };