7
7
#include <linux/security.h>
8
8
#include "xattr.h"
9
9
10
- struct xattr_iter {
10
+ struct erofs_xattr_iter {
11
11
struct super_block * sb ;
12
12
struct erofs_buf buf ;
13
13
erofs_off_t pos ;
14
14
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 ;
15
25
};
16
26
17
27
static int erofs_init_inode_xattrs (struct inode * inode )
18
28
{
19
29
struct erofs_inode * const vi = EROFS_I (inode );
20
- struct xattr_iter it ;
30
+ struct erofs_xattr_iter it ;
21
31
unsigned int i ;
22
32
struct erofs_xattr_ibody_header * ih ;
23
33
struct super_block * sb = inode -> i_sb ;
@@ -121,15 +131,15 @@ static int erofs_init_inode_xattrs(struct inode *inode)
121
131
* and need to be handled
122
132
*/
123
133
struct 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 ,
126
136
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 ,
129
139
unsigned int len );
130
140
};
131
141
132
- static int inline_xattr_iter_begin (struct xattr_iter * it ,
142
+ static int inline_xattr_iter_begin (struct erofs_xattr_iter * it ,
133
143
struct inode * inode )
134
144
{
135
145
struct erofs_inode * const vi = EROFS_I (inode );
@@ -154,7 +164,7 @@ static int inline_xattr_iter_begin(struct xattr_iter *it,
154
164
* Regardless of success or failure, `xattr_foreach' will end up with
155
165
* `pos' pointing to the next xattr item rather than an arbitrary position.
156
166
*/
157
- static int xattr_foreach (struct xattr_iter * it ,
167
+ static int xattr_foreach (struct erofs_xattr_iter * it ,
158
168
const struct xattr_iter_handlers * op ,
159
169
unsigned int * tlimit )
160
170
{
@@ -257,18 +267,10 @@ static int xattr_foreach(struct xattr_iter *it,
257
267
return err < 0 ? err : 0 ;
258
268
}
259
269
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 ,
269
271
struct erofs_xattr_entry * entry )
270
272
{
271
- struct erofs_sb_info * sbi = EROFS_SB (it -> it . sb );
273
+ struct erofs_sb_info * sbi = EROFS_SB (it -> sb );
272
274
struct erofs_xattr_prefix_item * pf = sbi -> xattr_prefixes +
273
275
(entry -> e_name_index & EROFS_XATTR_LONG_PREFIX_MASK );
274
276
@@ -286,11 +288,9 @@ static int erofs_xattr_long_entrymatch(struct getxattr_iter *it,
286
288
return 0 ;
287
289
}
288
290
289
- static int xattr_entrymatch (struct xattr_iter * _it ,
291
+ static int xattr_entrymatch (struct erofs_xattr_iter * it ,
290
292
struct erofs_xattr_entry * entry )
291
293
{
292
- struct getxattr_iter * it = container_of (_it , struct getxattr_iter , it );
293
-
294
294
/* should also match the infix for long name prefixes */
295
295
if (entry -> e_name_index & EROFS_XATTR_LONG_PREFIX )
296
296
return erofs_xattr_long_entrymatch (it , entry );
@@ -302,32 +302,27 @@ static int xattr_entrymatch(struct xattr_iter *_it,
302
302
return 0 ;
303
303
}
304
304
305
- static int xattr_namematch (struct xattr_iter * _it ,
305
+ static int xattr_namematch (struct erofs_xattr_iter * it ,
306
306
unsigned int processed , char * buf , unsigned int len )
307
307
{
308
- struct getxattr_iter * it = container_of (_it , struct getxattr_iter , it );
309
-
310
308
if (memcmp (buf , it -> name .name + it -> infix_len + processed , len ))
311
309
return - ENOATTR ;
312
310
return 0 ;
313
311
}
314
312
315
- static int xattr_checkbuffer (struct xattr_iter * _it ,
313
+ static int xattr_checkbuffer (struct erofs_xattr_iter * it ,
316
314
unsigned int value_sz )
317
315
{
318
- struct getxattr_iter * it = container_of (_it , struct getxattr_iter , it );
319
316
int err = it -> buffer_size < value_sz ? - ERANGE : 0 ;
320
317
321
318
it -> buffer_size = value_sz ;
322
319
return !it -> buffer ? 1 : err ;
323
320
}
324
321
325
- static void xattr_copyvalue (struct xattr_iter * _it ,
322
+ static void xattr_copyvalue (struct erofs_xattr_iter * it ,
326
323
unsigned int processed ,
327
324
char * buf , unsigned int len )
328
325
{
329
- struct getxattr_iter * it = container_of (_it , struct getxattr_iter , it );
330
-
331
326
memcpy (it -> buffer + processed , buf , len );
332
327
}
333
328
@@ -338,41 +333,41 @@ static const struct xattr_iter_handlers find_xattr_handlers = {
338
333
.value = xattr_copyvalue
339
334
};
340
335
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 )
342
337
{
343
338
int ret ;
344
339
unsigned int remaining ;
345
340
346
- ret = inline_xattr_iter_begin (& it -> it , inode );
341
+ ret = inline_xattr_iter_begin (it , inode );
347
342
if (ret < 0 )
348
343
return ret ;
349
344
350
345
remaining = ret ;
351
346
while (remaining ) {
352
- ret = xattr_foreach (& it -> it , & find_xattr_handlers , & remaining );
347
+ ret = xattr_foreach (it , & find_xattr_handlers , & remaining );
353
348
if (ret != - ENOATTR )
354
349
break ;
355
350
}
356
351
return ret ? ret : it -> buffer_size ;
357
352
}
358
353
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 )
360
355
{
361
356
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 ;
363
358
struct erofs_sb_info * sbi = EROFS_SB (sb );
364
359
unsigned int i ;
365
360
int ret = - ENOATTR ;
366
361
367
362
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 ) +
369
364
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 );
374
369
375
- ret = xattr_foreach (& it -> it , & find_xattr_handlers , NULL );
370
+ ret = xattr_foreach (it , & find_xattr_handlers , NULL );
376
371
if (ret != - ENOATTR )
377
372
break ;
378
373
}
@@ -394,7 +389,7 @@ int erofs_getxattr(struct inode *inode, int index,
394
389
void * buffer , size_t buffer_size )
395
390
{
396
391
int ret ;
397
- struct getxattr_iter it ;
392
+ struct erofs_xattr_iter it ;
398
393
399
394
if (!name )
400
395
return - EINVAL ;
@@ -404,22 +399,21 @@ int erofs_getxattr(struct inode *inode, int index,
404
399
return ret ;
405
400
406
401
it .index = index ;
407
- it .name . len = strlen (name );
402
+ it .name = ( struct qstr ) QSTR_INIT ( name , strlen (name ) );
408
403
if (it .name .len > EROFS_NAME_LEN )
409
404
return - ERANGE ;
410
405
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 );
416
409
it .buffer = buffer ;
417
410
it .buffer_size = buffer_size ;
411
+ it .buffer_ofs = 0 ;
418
412
419
413
ret = inline_getxattr (inode , & it );
420
414
if (ret == - ENOATTR )
421
415
ret = shared_getxattr (inode , & it );
422
- erofs_put_metabuf (& it .it . buf );
416
+ erofs_put_metabuf (& it .buf );
423
417
return ret ;
424
418
}
425
419
@@ -465,25 +459,15 @@ const struct xattr_handler *erofs_xattr_handlers[] = {
465
459
NULL ,
466
460
};
467
461
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 ,
477
463
struct erofs_xattr_entry * entry )
478
464
{
479
- struct listxattr_iter * it =
480
- container_of (_it , struct listxattr_iter , it );
481
465
unsigned int base_index = entry -> e_name_index ;
482
466
unsigned int prefix_len , infix_len = 0 ;
483
467
const char * prefix , * infix = NULL ;
484
468
485
469
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 );
487
471
struct erofs_xattr_prefix_item * pf = sbi -> xattr_prefixes +
488
472
(entry -> e_name_index & EROFS_XATTR_LONG_PREFIX_MASK );
489
473
@@ -515,23 +499,17 @@ static int xattr_entrylist(struct xattr_iter *_it,
515
499
return 0 ;
516
500
}
517
501
518
- static int xattr_namelist (struct xattr_iter * _it ,
502
+ static int xattr_namelist (struct erofs_xattr_iter * it ,
519
503
unsigned int processed , char * buf , unsigned int len )
520
504
{
521
- struct listxattr_iter * it =
522
- container_of (_it , struct listxattr_iter , it );
523
-
524
505
memcpy (it -> buffer + it -> buffer_ofs , buf , len );
525
506
it -> buffer_ofs += len ;
526
507
return 0 ;
527
508
}
528
509
529
- static int xattr_skipvalue (struct xattr_iter * _it ,
510
+ static int xattr_skipvalue (struct erofs_xattr_iter * it ,
530
511
unsigned int value_sz )
531
512
{
532
- struct listxattr_iter * it =
533
- container_of (_it , struct listxattr_iter , it );
534
-
535
513
it -> buffer [it -> buffer_ofs ++ ] = '\0' ;
536
514
return 1 ;
537
515
}
@@ -543,42 +521,42 @@ static const struct xattr_iter_handlers list_xattr_handlers = {
543
521
.value = NULL
544
522
};
545
523
546
- static int inline_listxattr (struct listxattr_iter * it )
524
+ static int inline_listxattr (struct erofs_xattr_iter * it )
547
525
{
548
526
int ret ;
549
527
unsigned int remaining ;
550
528
551
- ret = inline_xattr_iter_begin (& it -> it , d_inode (it -> dentry ));
529
+ ret = inline_xattr_iter_begin (it , d_inode (it -> dentry ));
552
530
if (ret < 0 )
553
531
return ret ;
554
532
555
533
remaining = ret ;
556
534
while (remaining ) {
557
- ret = xattr_foreach (& it -> it , & list_xattr_handlers , & remaining );
535
+ ret = xattr_foreach (it , & list_xattr_handlers , & remaining );
558
536
if (ret )
559
537
break ;
560
538
}
561
539
return ret ? ret : it -> buffer_ofs ;
562
540
}
563
541
564
- static int shared_listxattr (struct listxattr_iter * it )
542
+ static int shared_listxattr (struct erofs_xattr_iter * it )
565
543
{
566
544
struct inode * const inode = d_inode (it -> dentry );
567
545
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 ;
569
547
struct erofs_sb_info * sbi = EROFS_SB (sb );
570
548
unsigned int i ;
571
549
int ret = 0 ;
572
550
573
551
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 ) +
575
553
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 );
580
558
581
- ret = xattr_foreach (& it -> it , & list_xattr_handlers , NULL );
559
+ ret = xattr_foreach (it , & list_xattr_handlers , NULL );
582
560
if (ret )
583
561
break ;
584
562
}
@@ -589,17 +567,17 @@ ssize_t erofs_listxattr(struct dentry *dentry,
589
567
char * buffer , size_t buffer_size )
590
568
{
591
569
int ret ;
592
- struct listxattr_iter it ;
570
+ struct erofs_xattr_iter it ;
593
571
594
572
ret = erofs_init_inode_xattrs (d_inode (dentry ));
595
573
if (ret == - ENOATTR )
596
574
return 0 ;
597
575
if (ret )
598
576
return ret ;
599
577
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 );
603
581
it .dentry = dentry ;
604
582
it .buffer = buffer ;
605
583
it .buffer_size = buffer_size ;
@@ -608,7 +586,7 @@ ssize_t erofs_listxattr(struct dentry *dentry,
608
586
ret = inline_listxattr (& it );
609
587
if (ret >= 0 || ret == - ENOATTR )
610
588
ret = shared_listxattr (& it );
611
- erofs_put_metabuf (& it .it . buf );
589
+ erofs_put_metabuf (& it .buf );
612
590
return ret ;
613
591
}
614
592
0 commit comments