77#include <linux/security.h>
88#include "xattr.h"
99
10- struct xattr_iter {
10+ struct erofs_xattr_iter {
1111 struct super_block * sb ;
1212 struct erofs_buf buf ;
1313 erofs_off_t pos ;
1414 void * kaddr ;
15+
16+ char * buffer ;
17+ int buffer_size , buffer_ofs ;
18+
19+ /* getxattr */
20+ int index , infix_len ;
21+ struct qstr name ;
22+
23+ /* listxattr */
24+ struct dentry * dentry ;
1525};
1626
1727static int erofs_init_inode_xattrs (struct inode * inode )
1828{
1929 struct erofs_inode * const vi = EROFS_I (inode );
20- struct xattr_iter it ;
30+ struct erofs_xattr_iter it ;
2131 unsigned int i ;
2232 struct erofs_xattr_ibody_header * ih ;
2333 struct super_block * sb = inode -> i_sb ;
@@ -121,15 +131,15 @@ static int erofs_init_inode_xattrs(struct inode *inode)
121131 * and need to be handled
122132 */
123133struct xattr_iter_handlers {
124- int (* entry )(struct xattr_iter * _it , struct erofs_xattr_entry * entry );
125- int (* name )(struct xattr_iter * _it , unsigned int processed , char * buf ,
134+ int (* entry )(struct erofs_xattr_iter * it , struct erofs_xattr_entry * entry );
135+ int (* name )(struct erofs_xattr_iter * it , unsigned int processed , char * buf ,
126136 unsigned int len );
127- int (* alloc_buffer )(struct xattr_iter * _it , unsigned int value_sz );
128- void (* value )(struct xattr_iter * _it , unsigned int processed , char * buf ,
137+ int (* alloc_buffer )(struct erofs_xattr_iter * it , unsigned int value_sz );
138+ void (* value )(struct erofs_xattr_iter * it , unsigned int processed , char * buf ,
129139 unsigned int len );
130140};
131141
132- static int inline_xattr_iter_begin (struct xattr_iter * it ,
142+ static int inline_xattr_iter_begin (struct erofs_xattr_iter * it ,
133143 struct inode * inode )
134144{
135145 struct erofs_inode * const vi = EROFS_I (inode );
@@ -154,7 +164,7 @@ static int inline_xattr_iter_begin(struct xattr_iter *it,
154164 * Regardless of success or failure, `xattr_foreach' will end up with
155165 * `pos' pointing to the next xattr item rather than an arbitrary position.
156166 */
157- static int xattr_foreach (struct xattr_iter * it ,
167+ static int xattr_foreach (struct erofs_xattr_iter * it ,
158168 const struct xattr_iter_handlers * op ,
159169 unsigned int * tlimit )
160170{
@@ -257,18 +267,10 @@ static int xattr_foreach(struct xattr_iter *it,
257267 return err < 0 ? err : 0 ;
258268}
259269
260- struct getxattr_iter {
261- struct xattr_iter it ;
262-
263- char * buffer ;
264- int buffer_size , index , infix_len ;
265- struct qstr name ;
266- };
267-
268- static int erofs_xattr_long_entrymatch (struct getxattr_iter * it ,
270+ static int erofs_xattr_long_entrymatch (struct erofs_xattr_iter * it ,
269271 struct erofs_xattr_entry * entry )
270272{
271- struct erofs_sb_info * sbi = EROFS_SB (it -> it . sb );
273+ struct erofs_sb_info * sbi = EROFS_SB (it -> sb );
272274 struct erofs_xattr_prefix_item * pf = sbi -> xattr_prefixes +
273275 (entry -> e_name_index & EROFS_XATTR_LONG_PREFIX_MASK );
274276
@@ -286,11 +288,9 @@ static int erofs_xattr_long_entrymatch(struct getxattr_iter *it,
286288 return 0 ;
287289}
288290
289- static int xattr_entrymatch (struct xattr_iter * _it ,
291+ static int xattr_entrymatch (struct erofs_xattr_iter * it ,
290292 struct erofs_xattr_entry * entry )
291293{
292- struct getxattr_iter * it = container_of (_it , struct getxattr_iter , it );
293-
294294 /* should also match the infix for long name prefixes */
295295 if (entry -> e_name_index & EROFS_XATTR_LONG_PREFIX )
296296 return erofs_xattr_long_entrymatch (it , entry );
@@ -302,32 +302,27 @@ static int xattr_entrymatch(struct xattr_iter *_it,
302302 return 0 ;
303303}
304304
305- static int xattr_namematch (struct xattr_iter * _it ,
305+ static int xattr_namematch (struct erofs_xattr_iter * it ,
306306 unsigned int processed , char * buf , unsigned int len )
307307{
308- struct getxattr_iter * it = container_of (_it , struct getxattr_iter , it );
309-
310308 if (memcmp (buf , it -> name .name + it -> infix_len + processed , len ))
311309 return - ENOATTR ;
312310 return 0 ;
313311}
314312
315- static int xattr_checkbuffer (struct xattr_iter * _it ,
313+ static int xattr_checkbuffer (struct erofs_xattr_iter * it ,
316314 unsigned int value_sz )
317315{
318- struct getxattr_iter * it = container_of (_it , struct getxattr_iter , it );
319316 int err = it -> buffer_size < value_sz ? - ERANGE : 0 ;
320317
321318 it -> buffer_size = value_sz ;
322319 return !it -> buffer ? 1 : err ;
323320}
324321
325- static void xattr_copyvalue (struct xattr_iter * _it ,
322+ static void xattr_copyvalue (struct erofs_xattr_iter * it ,
326323 unsigned int processed ,
327324 char * buf , unsigned int len )
328325{
329- struct getxattr_iter * it = container_of (_it , struct getxattr_iter , it );
330-
331326 memcpy (it -> buffer + processed , buf , len );
332327}
333328
@@ -338,41 +333,41 @@ static const struct xattr_iter_handlers find_xattr_handlers = {
338333 .value = xattr_copyvalue
339334};
340335
341- static int inline_getxattr (struct inode * inode , struct getxattr_iter * it )
336+ static int inline_getxattr (struct inode * inode , struct erofs_xattr_iter * it )
342337{
343338 int ret ;
344339 unsigned int remaining ;
345340
346- ret = inline_xattr_iter_begin (& it -> it , inode );
341+ ret = inline_xattr_iter_begin (it , inode );
347342 if (ret < 0 )
348343 return ret ;
349344
350345 remaining = ret ;
351346 while (remaining ) {
352- ret = xattr_foreach (& it -> it , & find_xattr_handlers , & remaining );
347+ ret = xattr_foreach (it , & find_xattr_handlers , & remaining );
353348 if (ret != - ENOATTR )
354349 break ;
355350 }
356351 return ret ? ret : it -> buffer_size ;
357352}
358353
359- static int shared_getxattr (struct inode * inode , struct getxattr_iter * it )
354+ static int shared_getxattr (struct inode * inode , struct erofs_xattr_iter * it )
360355{
361356 struct erofs_inode * const vi = EROFS_I (inode );
362- struct super_block * const sb = it -> it . sb ;
357+ struct super_block * const sb = it -> sb ;
363358 struct erofs_sb_info * sbi = EROFS_SB (sb );
364359 unsigned int i ;
365360 int ret = - ENOATTR ;
366361
367362 for (i = 0 ; i < vi -> xattr_shared_count ; ++ i ) {
368- it -> it . pos = erofs_pos (sb , sbi -> xattr_blkaddr ) +
363+ it -> pos = erofs_pos (sb , sbi -> xattr_blkaddr ) +
369364 vi -> xattr_shared_xattrs [i ] * sizeof (__le32 );
370- it -> it . kaddr = erofs_bread (& it -> it . buf ,
371- erofs_blknr ( sb , it -> it . pos ), EROFS_KMAP );
372- if (IS_ERR (it -> it . kaddr ))
373- return PTR_ERR (it -> it . kaddr );
365+ it -> kaddr = erofs_bread (& it -> buf , erofs_blknr ( sb , it -> pos ) ,
366+ EROFS_KMAP );
367+ if (IS_ERR (it -> kaddr ))
368+ return PTR_ERR (it -> kaddr );
374369
375- ret = xattr_foreach (& it -> it , & find_xattr_handlers , NULL );
370+ ret = xattr_foreach (it , & find_xattr_handlers , NULL );
376371 if (ret != - ENOATTR )
377372 break ;
378373 }
@@ -394,7 +389,7 @@ int erofs_getxattr(struct inode *inode, int index,
394389 void * buffer , size_t buffer_size )
395390{
396391 int ret ;
397- struct getxattr_iter it ;
392+ struct erofs_xattr_iter it ;
398393
399394 if (!name )
400395 return - EINVAL ;
@@ -404,22 +399,21 @@ int erofs_getxattr(struct inode *inode, int index,
404399 return ret ;
405400
406401 it .index = index ;
407- it .name . len = strlen (name );
402+ it .name = ( struct qstr ) QSTR_INIT ( name , strlen (name ) );
408403 if (it .name .len > EROFS_NAME_LEN )
409404 return - ERANGE ;
410405
411- it .it .sb = inode -> i_sb ;
412- it .it .buf = __EROFS_BUF_INITIALIZER ;
413- erofs_init_metabuf (& it .it .buf , it .it .sb );
414- it .name .name = name ;
415-
406+ it .sb = inode -> i_sb ;
407+ it .buf = __EROFS_BUF_INITIALIZER ;
408+ erofs_init_metabuf (& it .buf , it .sb );
416409 it .buffer = buffer ;
417410 it .buffer_size = buffer_size ;
411+ it .buffer_ofs = 0 ;
418412
419413 ret = inline_getxattr (inode , & it );
420414 if (ret == - ENOATTR )
421415 ret = shared_getxattr (inode , & it );
422- erofs_put_metabuf (& it .it . buf );
416+ erofs_put_metabuf (& it .buf );
423417 return ret ;
424418}
425419
@@ -465,25 +459,15 @@ const struct xattr_handler *erofs_xattr_handlers[] = {
465459 NULL ,
466460};
467461
468- struct listxattr_iter {
469- struct xattr_iter it ;
470-
471- struct dentry * dentry ;
472- char * buffer ;
473- int buffer_size , buffer_ofs ;
474- };
475-
476- static int xattr_entrylist (struct xattr_iter * _it ,
462+ static int xattr_entrylist (struct erofs_xattr_iter * it ,
477463 struct erofs_xattr_entry * entry )
478464{
479- struct listxattr_iter * it =
480- container_of (_it , struct listxattr_iter , it );
481465 unsigned int base_index = entry -> e_name_index ;
482466 unsigned int prefix_len , infix_len = 0 ;
483467 const char * prefix , * infix = NULL ;
484468
485469 if (entry -> e_name_index & EROFS_XATTR_LONG_PREFIX ) {
486- struct erofs_sb_info * sbi = EROFS_SB (_it -> sb );
470+ struct erofs_sb_info * sbi = EROFS_SB (it -> sb );
487471 struct erofs_xattr_prefix_item * pf = sbi -> xattr_prefixes +
488472 (entry -> e_name_index & EROFS_XATTR_LONG_PREFIX_MASK );
489473
@@ -515,23 +499,17 @@ static int xattr_entrylist(struct xattr_iter *_it,
515499 return 0 ;
516500}
517501
518- static int xattr_namelist (struct xattr_iter * _it ,
502+ static int xattr_namelist (struct erofs_xattr_iter * it ,
519503 unsigned int processed , char * buf , unsigned int len )
520504{
521- struct listxattr_iter * it =
522- container_of (_it , struct listxattr_iter , it );
523-
524505 memcpy (it -> buffer + it -> buffer_ofs , buf , len );
525506 it -> buffer_ofs += len ;
526507 return 0 ;
527508}
528509
529- static int xattr_skipvalue (struct xattr_iter * _it ,
510+ static int xattr_skipvalue (struct erofs_xattr_iter * it ,
530511 unsigned int value_sz )
531512{
532- struct listxattr_iter * it =
533- container_of (_it , struct listxattr_iter , it );
534-
535513 it -> buffer [it -> buffer_ofs ++ ] = '\0' ;
536514 return 1 ;
537515}
@@ -543,42 +521,42 @@ static const struct xattr_iter_handlers list_xattr_handlers = {
543521 .value = NULL
544522};
545523
546- static int inline_listxattr (struct listxattr_iter * it )
524+ static int inline_listxattr (struct erofs_xattr_iter * it )
547525{
548526 int ret ;
549527 unsigned int remaining ;
550528
551- ret = inline_xattr_iter_begin (& it -> it , d_inode (it -> dentry ));
529+ ret = inline_xattr_iter_begin (it , d_inode (it -> dentry ));
552530 if (ret < 0 )
553531 return ret ;
554532
555533 remaining = ret ;
556534 while (remaining ) {
557- ret = xattr_foreach (& it -> it , & list_xattr_handlers , & remaining );
535+ ret = xattr_foreach (it , & list_xattr_handlers , & remaining );
558536 if (ret )
559537 break ;
560538 }
561539 return ret ? ret : it -> buffer_ofs ;
562540}
563541
564- static int shared_listxattr (struct listxattr_iter * it )
542+ static int shared_listxattr (struct erofs_xattr_iter * it )
565543{
566544 struct inode * const inode = d_inode (it -> dentry );
567545 struct erofs_inode * const vi = EROFS_I (inode );
568- struct super_block * const sb = it -> it . sb ;
546+ struct super_block * const sb = it -> sb ;
569547 struct erofs_sb_info * sbi = EROFS_SB (sb );
570548 unsigned int i ;
571549 int ret = 0 ;
572550
573551 for (i = 0 ; i < vi -> xattr_shared_count ; ++ i ) {
574- it -> it . pos = erofs_pos (sb , sbi -> xattr_blkaddr ) +
552+ it -> pos = erofs_pos (sb , sbi -> xattr_blkaddr ) +
575553 vi -> xattr_shared_xattrs [i ] * sizeof (__le32 );
576- it -> it . kaddr = erofs_bread (& it -> it . buf ,
577- erofs_blknr ( sb , it -> it . pos ), EROFS_KMAP );
578- if (IS_ERR (it -> it . kaddr ))
579- return PTR_ERR (it -> it . kaddr );
554+ it -> kaddr = erofs_bread (& it -> buf , erofs_blknr ( sb , it -> pos ) ,
555+ EROFS_KMAP );
556+ if (IS_ERR (it -> kaddr ))
557+ return PTR_ERR (it -> kaddr );
580558
581- ret = xattr_foreach (& it -> it , & list_xattr_handlers , NULL );
559+ ret = xattr_foreach (it , & list_xattr_handlers , NULL );
582560 if (ret )
583561 break ;
584562 }
@@ -589,17 +567,17 @@ ssize_t erofs_listxattr(struct dentry *dentry,
589567 char * buffer , size_t buffer_size )
590568{
591569 int ret ;
592- struct listxattr_iter it ;
570+ struct erofs_xattr_iter it ;
593571
594572 ret = erofs_init_inode_xattrs (d_inode (dentry ));
595573 if (ret == - ENOATTR )
596574 return 0 ;
597575 if (ret )
598576 return ret ;
599577
600- it .it . sb = dentry -> d_sb ;
601- it .it . buf = __EROFS_BUF_INITIALIZER ;
602- erofs_init_metabuf (& it .it . buf , it . it .sb );
578+ it .sb = dentry -> d_sb ;
579+ it .buf = __EROFS_BUF_INITIALIZER ;
580+ erofs_init_metabuf (& it .buf , it .sb );
603581 it .dentry = dentry ;
604582 it .buffer = buffer ;
605583 it .buffer_size = buffer_size ;
@@ -608,7 +586,7 @@ ssize_t erofs_listxattr(struct dentry *dentry,
608586 ret = inline_listxattr (& it );
609587 if (ret >= 0 || ret == - ENOATTR )
610588 ret = shared_listxattr (& it );
611- erofs_put_metabuf (& it .it . buf );
589+ erofs_put_metabuf (& it .buf );
612590 return ret ;
613591}
614592
0 commit comments