@@ -998,68 +998,38 @@ static struct sysfs_dirent *sysfs_dir_next_pos(const void *ns,
998998 return pos ;
999999}
10001000
1001- static int sysfs_readdir (struct file * filp , void * dirent , filldir_t filldir )
1001+ static int sysfs_readdir (struct file * file , struct dir_context * ctx )
10021002{
1003- struct dentry * dentry = filp -> f_path .dentry ;
1003+ struct dentry * dentry = file -> f_path .dentry ;
10041004 struct sysfs_dirent * parent_sd = dentry -> d_fsdata ;
1005- struct sysfs_dirent * pos = filp -> private_data ;
1005+ struct sysfs_dirent * pos = file -> private_data ;
10061006 enum kobj_ns_type type ;
10071007 const void * ns ;
1008- ino_t ino ;
1009- loff_t off ;
10101008
10111009 type = sysfs_ns_type (parent_sd );
10121010 ns = sysfs_info (dentry -> d_sb )-> ns [type ];
10131011
1014- if (filp -> f_pos == 0 ) {
1015- ino = parent_sd -> s_ino ;
1016- if (filldir (dirent , "." , 1 , filp -> f_pos , ino , DT_DIR ) == 0 )
1017- filp -> f_pos ++ ;
1018- else
1019- return 0 ;
1020- }
1021- if (filp -> f_pos == 1 ) {
1022- if (parent_sd -> s_parent )
1023- ino = parent_sd -> s_parent -> s_ino ;
1024- else
1025- ino = parent_sd -> s_ino ;
1026- if (filldir (dirent , ".." , 2 , filp -> f_pos , ino , DT_DIR ) == 0 )
1027- filp -> f_pos ++ ;
1028- else
1029- return 0 ;
1030- }
1012+ if (!dir_emit_dots (file , ctx ))
1013+ return 0 ;
10311014 mutex_lock (& sysfs_mutex );
1032- off = filp -> f_pos ;
1033- for (pos = sysfs_dir_pos (ns , parent_sd , filp -> f_pos , pos );
1015+ for (pos = sysfs_dir_pos (ns , parent_sd , ctx -> pos , pos );
10341016 pos ;
1035- pos = sysfs_dir_next_pos (ns , parent_sd , filp -> f_pos , pos )) {
1036- const char * name ;
1037- unsigned int type ;
1038- int len , ret ;
1039-
1040- name = pos -> s_name ;
1041- len = strlen (name );
1042- ino = pos -> s_ino ;
1043- type = dt_type (pos );
1044- off = filp -> f_pos = pos -> s_hash ;
1045- filp -> private_data = sysfs_get (pos );
1017+ pos = sysfs_dir_next_pos (ns , parent_sd , ctx -> pos , pos )) {
1018+ const char * name = pos -> s_name ;
1019+ unsigned int type = dt_type (pos );
1020+ int len = strlen (name );
1021+ ino_t ino = pos -> s_ino ;
1022+ ctx -> pos = pos -> s_hash ;
1023+ file -> private_data = sysfs_get (pos );
10461024
10471025 mutex_unlock (& sysfs_mutex );
1048- ret = filldir (dirent , name , len , off , ino , type );
1026+ if (!dir_emit (ctx , name , len , ino , type ))
1027+ return 0 ;
10491028 mutex_lock (& sysfs_mutex );
1050- if (ret < 0 )
1051- break ;
10521029 }
10531030 mutex_unlock (& sysfs_mutex );
1054-
1055- /* don't reference last entry if its refcount is dropped */
1056- if (!pos ) {
1057- filp -> private_data = NULL ;
1058-
1059- /* EOF and not changed as 0 or 1 in read/write path */
1060- if (off == filp -> f_pos && off > 1 )
1061- filp -> f_pos = INT_MAX ;
1062- }
1031+ file -> private_data = NULL ;
1032+ ctx -> pos = INT_MAX ;
10631033 return 0 ;
10641034}
10651035
@@ -1077,7 +1047,7 @@ static loff_t sysfs_dir_llseek(struct file *file, loff_t offset, int whence)
10771047
10781048const struct file_operations sysfs_dir_operations = {
10791049 .read = generic_read_dir ,
1080- .readdir = sysfs_readdir ,
1050+ .iterate = sysfs_readdir ,
10811051 .release = sysfs_dir_release ,
10821052 .llseek = sysfs_dir_llseek ,
10831053};
0 commit comments