@@ -5137,10 +5137,9 @@ unsigned char btrfs_filetype_table[] = {
51375137 DT_UNKNOWN , DT_REG , DT_DIR , DT_CHR , DT_BLK , DT_FIFO , DT_SOCK , DT_LNK
51385138};
51395139
5140- static int btrfs_real_readdir (struct file * filp , void * dirent ,
5141- filldir_t filldir )
5140+ static int btrfs_real_readdir (struct file * file , struct dir_context * ctx )
51425141{
5143- struct inode * inode = file_inode (filp );
5142+ struct inode * inode = file_inode (file );
51445143 struct btrfs_root * root = BTRFS_I (inode )-> root ;
51455144 struct btrfs_item * item ;
51465145 struct btrfs_dir_item * di ;
@@ -5161,29 +5160,15 @@ static int btrfs_real_readdir(struct file *filp, void *dirent,
51615160 char tmp_name [32 ];
51625161 char * name_ptr ;
51635162 int name_len ;
5164- int is_curr = 0 ; /* filp->f_pos points to the current index? */
5163+ int is_curr = 0 ; /* ctx->pos points to the current index? */
51655164
51665165 /* FIXME, use a real flag for deciding about the key type */
51675166 if (root -> fs_info -> tree_root == root )
51685167 key_type = BTRFS_DIR_ITEM_KEY ;
51695168
5170- /* special case for "." */
5171- if (filp -> f_pos == 0 ) {
5172- over = filldir (dirent , "." , 1 ,
5173- filp -> f_pos , btrfs_ino (inode ), DT_DIR );
5174- if (over )
5175- return 0 ;
5176- filp -> f_pos = 1 ;
5177- }
5178- /* special case for .., just use the back ref */
5179- if (filp -> f_pos == 1 ) {
5180- u64 pino = parent_ino (filp -> f_path .dentry );
5181- over = filldir (dirent , ".." , 2 ,
5182- filp -> f_pos , pino , DT_DIR );
5183- if (over )
5184- return 0 ;
5185- filp -> f_pos = 2 ;
5186- }
5169+ if (!dir_emit_dots (file , ctx ))
5170+ return 0 ;
5171+
51875172 path = btrfs_alloc_path ();
51885173 if (!path )
51895174 return - ENOMEM ;
@@ -5197,7 +5182,7 @@ static int btrfs_real_readdir(struct file *filp, void *dirent,
51975182 }
51985183
51995184 btrfs_set_key_type (& key , key_type );
5200- key .offset = filp -> f_pos ;
5185+ key .offset = ctx -> pos ;
52015186 key .objectid = btrfs_ino (inode );
52025187
52035188 ret = btrfs_search_slot (NULL , root , & key , path , 0 , 0 );
@@ -5223,14 +5208,14 @@ static int btrfs_real_readdir(struct file *filp, void *dirent,
52235208 break ;
52245209 if (btrfs_key_type (& found_key ) != key_type )
52255210 break ;
5226- if (found_key .offset < filp -> f_pos )
5211+ if (found_key .offset < ctx -> pos )
52275212 goto next ;
52285213 if (key_type == BTRFS_DIR_INDEX_KEY &&
52295214 btrfs_should_delete_dir_index (& del_list ,
52305215 found_key .offset ))
52315216 goto next ;
52325217
5233- filp -> f_pos = found_key .offset ;
5218+ ctx -> pos = found_key .offset ;
52345219 is_curr = 1 ;
52355220
52365221 di = btrfs_item_ptr (leaf , slot , struct btrfs_dir_item );
@@ -5274,9 +5259,8 @@ static int btrfs_real_readdir(struct file *filp, void *dirent,
52745259 over = 0 ;
52755260 goto skip ;
52765261 }
5277- over = filldir (dirent , name_ptr , name_len ,
5278- found_key .offset , location .objectid ,
5279- d_type );
5262+ over = !dir_emit (ctx , name_ptr , name_len ,
5263+ location .objectid , d_type );
52805264
52815265skip :
52825266 if (name_ptr != tmp_name )
@@ -5295,9 +5279,8 @@ static int btrfs_real_readdir(struct file *filp, void *dirent,
52955279
52965280 if (key_type == BTRFS_DIR_INDEX_KEY ) {
52975281 if (is_curr )
5298- filp -> f_pos ++ ;
5299- ret = btrfs_readdir_delayed_dir_index (filp , dirent , filldir ,
5300- & ins_list );
5282+ ctx -> pos ++ ;
5283+ ret = btrfs_readdir_delayed_dir_index (ctx , & ins_list );
53015284 if (ret )
53025285 goto nopos ;
53035286 }
@@ -5308,9 +5291,9 @@ static int btrfs_real_readdir(struct file *filp, void *dirent,
53085291 * 32-bit glibc will use getdents64, but then strtol -
53095292 * so the last number we can serve is this.
53105293 */
5311- filp -> f_pos = 0x7fffffff ;
5294+ ctx -> pos = 0x7fffffff ;
53125295 else
5313- filp -> f_pos ++ ;
5296+ ctx -> pos ++ ;
53145297nopos :
53155298 ret = 0 ;
53165299err :
@@ -8731,7 +8714,7 @@ static const struct inode_operations btrfs_dir_ro_inode_operations = {
87318714static const struct file_operations btrfs_dir_file_operations = {
87328715 .llseek = generic_file_llseek ,
87338716 .read = generic_read_dir ,
8734- .readdir = btrfs_real_readdir ,
8717+ .iterate = btrfs_real_readdir ,
87358718 .unlocked_ioctl = btrfs_ioctl ,
87368719#ifdef CONFIG_COMPAT
87378720 .compat_ioctl = btrfs_ioctl ,
0 commit comments