2222static struct dentry * afs_lookup (struct inode * dir , struct dentry * dentry ,
2323 unsigned int flags );
2424static int afs_dir_open (struct inode * inode , struct file * file );
25- static int afs_readdir (struct file * file , void * dirent , filldir_t filldir );
25+ static int afs_readdir (struct file * file , struct dir_context * ctx );
2626static int afs_d_revalidate (struct dentry * dentry , unsigned int flags );
2727static int afs_d_delete (const struct dentry * dentry );
2828static void afs_d_release (struct dentry * dentry );
@@ -43,7 +43,7 @@ static int afs_rename(struct inode *old_dir, struct dentry *old_dentry,
4343const struct file_operations afs_dir_file_operations = {
4444 .open = afs_dir_open ,
4545 .release = afs_release ,
46- .readdir = afs_readdir ,
46+ .iterate = afs_readdir ,
4747 .lock = afs_lock ,
4848 .llseek = generic_file_llseek ,
4949};
@@ -119,9 +119,9 @@ struct afs_dir_page {
119119};
120120
121121struct afs_lookup_cookie {
122+ struct dir_context ctx ;
122123 struct afs_fid fid ;
123- const char * name ;
124- size_t nlen ;
124+ struct qstr name ;
125125 int found ;
126126};
127127
@@ -228,20 +228,18 @@ static int afs_dir_open(struct inode *inode, struct file *file)
228228/*
229229 * deal with one block in an AFS directory
230230 */
231- static int afs_dir_iterate_block (unsigned * fpos ,
231+ static int afs_dir_iterate_block (struct dir_context * ctx ,
232232 union afs_dir_block * block ,
233- unsigned blkoff ,
234- void * cookie ,
235- filldir_t filldir )
233+ unsigned blkoff )
236234{
237235 union afs_dirent * dire ;
238236 unsigned offset , next , curr ;
239237 size_t nlen ;
240- int tmp , ret ;
238+ int tmp ;
241239
242- _enter ("%u,%x,%p,," ,* fpos ,blkoff ,block );
240+ _enter ("%u,%x,%p,," ,( unsigned ) ctx -> pos ,blkoff ,block );
243241
244- curr = (* fpos - blkoff ) / sizeof (union afs_dirent );
242+ curr = (ctx -> pos - blkoff ) / sizeof (union afs_dirent );
245243
246244 /* walk through the block, an entry at a time */
247245 for (offset = AFS_DIRENT_PER_BLOCK - block -> pagehdr .nentries ;
@@ -256,7 +254,7 @@ static int afs_dir_iterate_block(unsigned *fpos,
256254 _debug ("ENT[%Zu.%u]: unused" ,
257255 blkoff / sizeof (union afs_dir_block ), offset );
258256 if (offset >= curr )
259- * fpos = blkoff +
257+ ctx -> pos = blkoff +
260258 next * sizeof (union afs_dirent );
261259 continue ;
262260 }
@@ -302,19 +300,15 @@ static int afs_dir_iterate_block(unsigned *fpos,
302300 continue ;
303301
304302 /* found the next entry */
305- ret = filldir (cookie ,
306- dire -> u .name ,
307- nlen ,
308- blkoff + offset * sizeof (union afs_dirent ),
303+ if (!dir_emit (ctx , dire -> u .name , nlen ,
309304 ntohl (dire -> u .vnode ),
310- filldir == afs_lookup_filldir ?
311- ntohl (dire -> u .unique ) : DT_UNKNOWN );
312- if (ret < 0 ) {
305+ ctx -> actor == afs_lookup_filldir ?
306+ ntohl (dire -> u .unique ) : DT_UNKNOWN )) {
313307 _leave (" = 0 [full]" );
314308 return 0 ;
315309 }
316310
317- * fpos = blkoff + next * sizeof (union afs_dirent );
311+ ctx -> pos = blkoff + next * sizeof (union afs_dirent );
318312 }
319313
320314 _leave (" = 1 [more]" );
@@ -324,30 +318,30 @@ static int afs_dir_iterate_block(unsigned *fpos,
324318/*
325319 * iterate through the data blob that lists the contents of an AFS directory
326320 */
327- static int afs_dir_iterate (struct inode * dir , unsigned * fpos , void * cookie ,
328- filldir_t filldir , struct key * key )
321+ static int afs_dir_iterate (struct inode * dir , struct dir_context * ctx ,
322+ struct key * key )
329323{
330324 union afs_dir_block * dblock ;
331325 struct afs_dir_page * dbuf ;
332326 struct page * page ;
333327 unsigned blkoff , limit ;
334328 int ret ;
335329
336- _enter ("{%lu},%u,," , dir -> i_ino , * fpos );
330+ _enter ("{%lu},%u,," , dir -> i_ino , ( unsigned ) ctx -> pos );
337331
338332 if (test_bit (AFS_VNODE_DELETED , & AFS_FS_I (dir )-> flags )) {
339333 _leave (" = -ESTALE" );
340334 return - ESTALE ;
341335 }
342336
343337 /* round the file position up to the next entry boundary */
344- * fpos += sizeof (union afs_dirent ) - 1 ;
345- * fpos &= ~(sizeof (union afs_dirent ) - 1 );
338+ ctx -> pos += sizeof (union afs_dirent ) - 1 ;
339+ ctx -> pos &= ~(sizeof (union afs_dirent ) - 1 );
346340
347341 /* walk through the blocks in sequence */
348342 ret = 0 ;
349- while (* fpos < dir -> i_size ) {
350- blkoff = * fpos & ~(sizeof (union afs_dir_block ) - 1 );
343+ while (ctx -> pos < dir -> i_size ) {
344+ blkoff = ctx -> pos & ~(sizeof (union afs_dir_block ) - 1 );
351345
352346 /* fetch the appropriate page from the directory */
353347 page = afs_dir_get_page (dir , blkoff / PAGE_SIZE , key );
@@ -364,16 +358,15 @@ static int afs_dir_iterate(struct inode *dir, unsigned *fpos, void *cookie,
364358 do {
365359 dblock = & dbuf -> blocks [(blkoff % PAGE_SIZE ) /
366360 sizeof (union afs_dir_block )];
367- ret = afs_dir_iterate_block (fpos , dblock , blkoff ,
368- cookie , filldir );
361+ ret = afs_dir_iterate_block (ctx , dblock , blkoff );
369362 if (ret != 1 ) {
370363 afs_dir_put_page (page );
371364 goto out ;
372365 }
373366
374367 blkoff += sizeof (union afs_dir_block );
375368
376- } while (* fpos < dir -> i_size && blkoff < limit );
369+ } while (ctx -> pos < dir -> i_size && blkoff < limit );
377370
378371 afs_dir_put_page (page );
379372 ret = 0 ;
@@ -387,23 +380,10 @@ static int afs_dir_iterate(struct inode *dir, unsigned *fpos, void *cookie,
387380/*
388381 * read an AFS directory
389382 */
390- static int afs_readdir (struct file * file , void * cookie , filldir_t filldir )
383+ static int afs_readdir (struct file * file , struct dir_context * ctx )
391384{
392- unsigned fpos ;
393- int ret ;
394-
395- _enter ("{%Ld,{%lu}}" ,
396- file -> f_pos , file_inode (file )-> i_ino );
397-
398- ASSERT (file -> private_data != NULL );
399-
400- fpos = file -> f_pos ;
401- ret = afs_dir_iterate (file_inode (file ), & fpos ,
402- cookie , filldir , file -> private_data );
403- file -> f_pos = fpos ;
404-
405- _leave (" = %d" , ret );
406- return ret ;
385+ return afs_dir_iterate (file_inode (file ),
386+ ctx , file -> private_data );
407387}
408388
409389/*
@@ -416,15 +396,16 @@ static int afs_lookup_filldir(void *_cookie, const char *name, int nlen,
416396{
417397 struct afs_lookup_cookie * cookie = _cookie ;
418398
419- _enter ("{%s,%Zu },%s,%u,,%llu,%u" ,
420- cookie -> name , cookie -> nlen , name , nlen ,
399+ _enter ("{%s,%u },%s,%u,,%llu,%u" ,
400+ cookie -> name . name , cookie -> name . len , name , nlen ,
421401 (unsigned long long ) ino , dtype );
422402
423403 /* insanity checks first */
424404 BUILD_BUG_ON (sizeof (union afs_dir_block ) != 2048 );
425405 BUILD_BUG_ON (sizeof (union afs_dirent ) != 32 );
426406
427- if (cookie -> nlen != nlen || memcmp (cookie -> name , name , nlen ) != 0 ) {
407+ if (cookie -> name .len != nlen ||
408+ memcmp (cookie -> name .name , name , nlen ) != 0 ) {
428409 _leave (" = 0 [no]" );
429410 return 0 ;
430411 }
@@ -444,24 +425,18 @@ static int afs_lookup_filldir(void *_cookie, const char *name, int nlen,
444425static int afs_do_lookup (struct inode * dir , struct dentry * dentry ,
445426 struct afs_fid * fid , struct key * key )
446427{
447- struct afs_lookup_cookie cookie ;
448- struct afs_super_info * as ;
449- unsigned fpos ;
428+ struct afs_super_info * as = dir -> i_sb -> s_fs_info ;
429+ struct afs_lookup_cookie cookie = {
430+ .ctx .actor = afs_lookup_filldir ,
431+ .name = dentry -> d_name ,
432+ .fid .vid = as -> volume -> vid
433+ };
450434 int ret ;
451435
452436 _enter ("{%lu},%p{%s}," , dir -> i_ino , dentry , dentry -> d_name .name );
453437
454- as = dir -> i_sb -> s_fs_info ;
455-
456438 /* search the directory */
457- cookie .name = dentry -> d_name .name ;
458- cookie .nlen = dentry -> d_name .len ;
459- cookie .fid .vid = as -> volume -> vid ;
460- cookie .found = 0 ;
461-
462- fpos = 0 ;
463- ret = afs_dir_iterate (dir , & fpos , & cookie , afs_lookup_filldir ,
464- key );
439+ ret = afs_dir_iterate (dir , & cookie .ctx , key );
465440 if (ret < 0 ) {
466441 _leave (" = %d [iter]" , ret );
467442 return ret ;
0 commit comments