2019-05-30 02:57:50 +03:00
// SPDX-License-Identifier: GPL-2.0-only
2008-07-14 20:08:37 +04:00
/*
* This file is part of UBIFS .
*
* Copyright ( C ) 2006 - 2008 Nokia Corporation .
*
* Authors : Artem Bityutskiy ( Б и т ю ц к и й А р т ё м )
* Adrian Hunter
*/
/*
* This file implements UBIFS extended attributes support .
*
* Extended attributes are implemented as regular inodes with attached data ,
* which limits extended attribute size to UBIFS block size ( 4 KiB ) . Names of
* extended attributes are described by extended attribute entries ( xentries ) ,
* which are almost identical to directory entries , but have different key type .
*
* In other words , the situation with extended attributes is very similar to
* directories . Indeed , any inode ( but of course not xattr inodes ) may have a
* number of associated xentries , just like directory inodes have associated
* directory entries . Extended attribute entries store the name of the extended
* attribute , the host inode number , and the extended attribute inode number .
* Similarly , direntries store the name , the parent and the target inode
* numbers . Thus , most of the common UBIFS mechanisms may be re - used for
* extended attributes .
*
* The number of extended attributes is not limited , but there is Linux
* limitation on the maximum possible size of the list of all extended
* attributes associated with an inode ( % XATTR_LIST_MAX ) , so UBIFS makes sure
* the sum of all extended attribute names of the inode does not exceed that
* limit .
*
* Extended attributes are synchronous , which means they are written to the
* flash media synchronously and there is no write - back for extended attribute
* inodes . The extended attribute values are not stored in compressed form on
* the media .
*
* Since extended attributes are represented by regular inodes , they are cached
* in the VFS inode cache . The xentries are cached in the LNC cache ( see
* tnc . c ) .
*
* ACL support is not implemented .
*/
2009-06-09 20:11:54 +04:00
# include "ubifs.h"
2011-04-06 01:51:48 +04:00
# include <linux/fs.h>
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 11:04:11 +03:00
# include <linux/slab.h>
2008-07-14 20:08:37 +04:00
# include <linux/xattr.h>
/*
* Extended attribute type constants .
*
* USER_XATTR : user extended attribute ( " user.* " )
* TRUSTED_XATTR : trusted extended attribute ( " trusted.*)
* SECURITY_XATTR : security extended attribute ( " security.* " )
*/
enum {
USER_XATTR ,
TRUSTED_XATTR ,
SECURITY_XATTR ,
} ;
2011-04-04 03:55:39 +04:00
static const struct inode_operations empty_iops ;
static const struct file_operations empty_fops ;
2008-07-14 20:08:37 +04:00
/**
* create_xattr - create an extended attribute .
* @ c : UBIFS file - system description object
* @ host : host inode
* @ nm : extended attribute name
* @ value : extended attribute value
* @ size : size of extended attribute value
*
* This is a helper function which creates an extended attribute of name @ nm
* and value @ value for inode @ host . The host inode is also updated on flash
* because the ctime and extended attribute accounting data changes . This
* function returns zero in case of success and a negative error code in case
* of failure .
*/
static int create_xattr ( struct ubifs_info * c , struct inode * host ,
2016-11-12 00:50:29 +03:00
const struct fscrypt_name * nm , const void * value , int size )
2008-07-14 20:08:37 +04:00
{
2014-10-31 21:50:31 +03:00
int err , names_len ;
2008-07-14 20:08:37 +04:00
struct inode * inode ;
struct ubifs_inode * ui , * host_ui = ubifs_inode ( host ) ;
struct ubifs_budget_req req = { . new_ino = 1 , . new_dent = 1 ,
2008-08-12 14:54:54 +04:00
. new_ino_d = ALIGN ( size , 8 ) , . dirtied_ino = 1 ,
. dirtied_ino_d = ALIGN ( host_ui - > data_len , 8 ) } ;
2008-07-14 20:08:37 +04:00
2019-04-05 01:34:38 +03:00
if ( host_ui - > xattr_cnt > = ubifs_xattr_max_cnt ( c ) ) {
UBIFS: extend debug/message capabilities
In the case where we have more than one volumes on different UBI
devices, it may be not that easy to tell which volume prints the
messages. Add ubi number and volume id in ubifs_msg/warn/error
to help debug. These two values are passed by struct ubifs_info.
For those where ubifs_info is not initialized yet, ubifs_* is
replaced by pr_*. For those where ubifs_info is not avaliable,
ubifs_info is passed to the calling function as a const parameter.
The output looks like,
[ 95.444879] UBIFS (ubi0:1): background thread "ubifs_bgt0_1" started, PID 696
[ 95.484688] UBIFS (ubi0:1): UBIFS: mounted UBI device 0, volume 1, name "test1"
[ 95.484694] UBIFS (ubi0:1): LEB size: 126976 bytes (124 KiB), min./max. I/O unit sizes: 2048 bytes/2048 bytes
[ 95.484699] UBIFS (ubi0:1): FS size: 30220288 bytes (28 MiB, 238 LEBs), journal size 1523712 bytes (1 MiB, 12 LEBs)
[ 95.484703] UBIFS (ubi0:1): reserved for root: 1427378 bytes (1393 KiB)
[ 95.484709] UBIFS (ubi0:1): media format: w4/r0 (latest is w4/r0), UUID 40DFFC0E-70BE-4193-8905-F7D6DFE60B17, small LPT model
[ 95.489875] UBIFS (ubi1:0): background thread "ubifs_bgt1_0" started, PID 699
[ 95.529713] UBIFS (ubi1:0): UBIFS: mounted UBI device 1, volume 0, name "test2"
[ 95.529718] UBIFS (ubi1:0): LEB size: 126976 bytes (124 KiB), min./max. I/O unit sizes: 2048 bytes/2048 bytes
[ 95.529724] UBIFS (ubi1:0): FS size: 19808256 bytes (18 MiB, 156 LEBs), journal size 1015809 bytes (0 MiB, 8 LEBs)
[ 95.529727] UBIFS (ubi1:0): reserved for root: 935592 bytes (913 KiB)
[ 95.529733] UBIFS (ubi1:0): media format: w4/r0 (latest is w4/r0), UUID EEB7779D-F419-4CA9-811B-831CAC7233D4, small LPT model
[ 954.264767] UBIFS error (ubi1:0 pid 756): ubifs_read_node: bad node type (255 but expected 6)
[ 954.367030] UBIFS error (ubi1:0 pid 756): ubifs_read_node: bad node at LEB 0:0, LEB mapping status 1
Signed-off-by: Sheng Yong <shengyong1@huawei.com>
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
2015-03-20 13:39:42 +03:00
ubifs_err ( c , " inode %lu already has too many xattrs (%d), cannot create more " ,
2014-10-31 21:50:31 +03:00
host - > i_ino , host_ui - > xattr_cnt ) ;
2008-07-14 20:08:37 +04:00
return - ENOSPC ;
2014-10-31 21:50:31 +03:00
}
2008-07-14 20:08:37 +04:00
/*
* Linux limits the maximum size of the extended attribute names list
2008-08-12 17:30:12 +04:00
* to % XATTR_LIST_MAX . This means we should not allow creating more
2008-07-14 20:08:37 +04:00
* extended attributes if the name list becomes larger . This limitation
* is artificial for UBIFS , though .
*/
2016-11-12 00:50:29 +03:00
names_len = host_ui - > xattr_names + host_ui - > xattr_cnt + fname_len ( nm ) + 1 ;
2014-10-31 21:50:31 +03:00
if ( names_len > XATTR_LIST_MAX ) {
UBIFS: extend debug/message capabilities
In the case where we have more than one volumes on different UBI
devices, it may be not that easy to tell which volume prints the
messages. Add ubi number and volume id in ubifs_msg/warn/error
to help debug. These two values are passed by struct ubifs_info.
For those where ubifs_info is not initialized yet, ubifs_* is
replaced by pr_*. For those where ubifs_info is not avaliable,
ubifs_info is passed to the calling function as a const parameter.
The output looks like,
[ 95.444879] UBIFS (ubi0:1): background thread "ubifs_bgt0_1" started, PID 696
[ 95.484688] UBIFS (ubi0:1): UBIFS: mounted UBI device 0, volume 1, name "test1"
[ 95.484694] UBIFS (ubi0:1): LEB size: 126976 bytes (124 KiB), min./max. I/O unit sizes: 2048 bytes/2048 bytes
[ 95.484699] UBIFS (ubi0:1): FS size: 30220288 bytes (28 MiB, 238 LEBs), journal size 1523712 bytes (1 MiB, 12 LEBs)
[ 95.484703] UBIFS (ubi0:1): reserved for root: 1427378 bytes (1393 KiB)
[ 95.484709] UBIFS (ubi0:1): media format: w4/r0 (latest is w4/r0), UUID 40DFFC0E-70BE-4193-8905-F7D6DFE60B17, small LPT model
[ 95.489875] UBIFS (ubi1:0): background thread "ubifs_bgt1_0" started, PID 699
[ 95.529713] UBIFS (ubi1:0): UBIFS: mounted UBI device 1, volume 0, name "test2"
[ 95.529718] UBIFS (ubi1:0): LEB size: 126976 bytes (124 KiB), min./max. I/O unit sizes: 2048 bytes/2048 bytes
[ 95.529724] UBIFS (ubi1:0): FS size: 19808256 bytes (18 MiB, 156 LEBs), journal size 1015809 bytes (0 MiB, 8 LEBs)
[ 95.529727] UBIFS (ubi1:0): reserved for root: 935592 bytes (913 KiB)
[ 95.529733] UBIFS (ubi1:0): media format: w4/r0 (latest is w4/r0), UUID EEB7779D-F419-4CA9-811B-831CAC7233D4, small LPT model
[ 954.264767] UBIFS error (ubi1:0 pid 756): ubifs_read_node: bad node type (255 but expected 6)
[ 954.367030] UBIFS error (ubi1:0 pid 756): ubifs_read_node: bad node at LEB 0:0, LEB mapping status 1
Signed-off-by: Sheng Yong <shengyong1@huawei.com>
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
2015-03-20 13:39:42 +03:00
ubifs_err ( c , " cannot add one more xattr name to inode %lu, total names length would become %d, max. is %d " ,
2014-10-31 21:50:31 +03:00
host - > i_ino , names_len , XATTR_LIST_MAX ) ;
2008-07-14 20:08:37 +04:00
return - ENOSPC ;
2014-10-31 21:50:31 +03:00
}
2008-07-14 20:08:37 +04:00
err = ubifs_budget_space ( c , & req ) ;
if ( err )
return err ;
inode = ubifs_new_inode ( c , host , S_IFREG | S_IRWXUGO ) ;
if ( IS_ERR ( inode ) ) {
err = PTR_ERR ( inode ) ;
goto out_budg ;
}
/* Re-define all operations to be "nothing" */
2011-04-06 01:51:48 +04:00
inode - > i_mapping - > a_ops = & empty_aops ;
2011-04-04 03:55:39 +04:00
inode - > i_op = & empty_iops ;
inode - > i_fop = & empty_fops ;
2008-07-14 20:08:37 +04:00
2018-05-11 05:26:03 +03:00
inode - > i_flags | = S_SYNC | S_NOATIME | S_NOCMTIME ;
2008-07-14 20:08:37 +04:00
ui = ubifs_inode ( inode ) ;
ui - > xattr = 1 ;
ui - > flags | = UBIFS_XATTR_FL ;
2011-11-18 03:00:52 +04:00
ui - > data = kmemdup ( value , size , GFP_NOFS ) ;
2008-07-14 20:08:37 +04:00
if ( ! ui - > data ) {
err = - ENOMEM ;
2008-08-12 17:30:12 +04:00
goto out_free ;
2008-07-14 20:08:37 +04:00
}
2008-08-12 17:30:12 +04:00
inode - > i_size = ui - > ui_size = size ;
ui - > data_len = size ;
mutex_lock ( & host_ui - > ui_mutex ) ;
2017-05-09 01:59:25 +03:00
host - > i_ctime = current_time ( host ) ;
2008-07-14 20:08:37 +04:00
host_ui - > xattr_cnt + = 1 ;
2016-11-12 00:50:29 +03:00
host_ui - > xattr_size + = CALC_DENT_SIZE ( fname_len ( nm ) ) ;
2008-07-14 20:08:37 +04:00
host_ui - > xattr_size + = CALC_XATTR_BYTES ( size ) ;
2016-11-12 00:50:29 +03:00
host_ui - > xattr_names + = fname_len ( nm ) ;
2008-07-14 20:08:37 +04:00
2016-10-20 17:47:56 +03:00
/*
* We handle UBIFS_XATTR_NAME_ENCRYPTION_CONTEXT here because we
* have to set the UBIFS_CRYPT_FL flag on the host inode .
* To avoid multiple updates of the same inode in the same operation ,
* let ' s do it here .
*/
2016-11-12 00:50:29 +03:00
if ( strcmp ( fname_name ( nm ) , UBIFS_XATTR_NAME_ENCRYPTION_CONTEXT ) = = 0 )
2016-10-20 17:47:56 +03:00
host_ui - > flags | = UBIFS_CRYPT_FL ;
2008-07-14 20:08:37 +04:00
err = ubifs_jnl_update ( c , host , nm , inode , 0 , 1 ) ;
if ( err )
goto out_cancel ;
2017-10-09 22:15:35 +03:00
ubifs_set_inode_flags ( host ) ;
2008-07-14 20:08:37 +04:00
mutex_unlock ( & host_ui - > ui_mutex ) ;
ubifs_release_budget ( c , & req ) ;
insert_inode_hash ( inode ) ;
iput ( inode ) ;
return 0 ;
out_cancel :
host_ui - > xattr_cnt - = 1 ;
2016-11-12 00:50:29 +03:00
host_ui - > xattr_size - = CALC_DENT_SIZE ( fname_len ( nm ) ) ;
2008-07-14 20:08:37 +04:00
host_ui - > xattr_size - = CALC_XATTR_BYTES ( size ) ;
2016-11-12 00:50:29 +03:00
host_ui - > xattr_names - = fname_len ( nm ) ;
2016-10-20 17:47:56 +03:00
host_ui - > flags & = ~ UBIFS_CRYPT_FL ;
2008-07-14 20:08:37 +04:00
mutex_unlock ( & host_ui - > ui_mutex ) ;
2008-08-12 17:30:12 +04:00
out_free :
2008-07-14 20:08:37 +04:00
make_bad_inode ( inode ) ;
iput ( inode ) ;
out_budg :
ubifs_release_budget ( c , & req ) ;
return err ;
}
/**
* change_xattr - change an extended attribute .
* @ c : UBIFS file - system description object
* @ host : host inode
* @ inode : extended attribute inode
* @ value : extended attribute value
* @ size : size of extended attribute value
*
* This helper function changes the value of extended attribute @ inode with new
* data from @ value . Returns zero in case of success and a negative error code
* in case of failure .
*/
static int change_xattr ( struct ubifs_info * c , struct inode * host ,
struct inode * inode , const void * value , int size )
{
int err ;
struct ubifs_inode * host_ui = ubifs_inode ( host ) ;
struct ubifs_inode * ui = ubifs_inode ( inode ) ;
2015-08-18 07:38:36 +03:00
void * buf = NULL ;
2016-09-22 00:57:30 +03:00
int old_size ;
2008-07-14 20:08:37 +04:00
struct ubifs_budget_req req = { . dirtied_ino = 2 ,
2008-08-12 14:54:54 +04:00
. dirtied_ino_d = ALIGN ( size , 8 ) + ALIGN ( host_ui - > data_len , 8 ) } ;
2008-07-14 20:08:37 +04:00
2018-07-12 14:01:57 +03:00
ubifs_assert ( c , ui - > data_len = = inode - > i_size ) ;
2008-07-14 20:08:37 +04:00
err = ubifs_budget_space ( c , & req ) ;
if ( err )
return err ;
2015-08-18 07:38:36 +03:00
buf = kmemdup ( value , size , GFP_NOFS ) ;
if ( ! buf ) {
2008-07-14 20:08:37 +04:00
err = - ENOMEM ;
2008-08-12 17:30:12 +04:00
goto out_free ;
2008-07-14 20:08:37 +04:00
}
2015-08-18 07:38:36 +03:00
mutex_lock ( & ui - > ui_mutex ) ;
kfree ( ui - > data ) ;
ui - > data = buf ;
2008-07-14 20:08:37 +04:00
inode - > i_size = ui - > ui_size = size ;
2016-09-22 00:57:30 +03:00
old_size = ui - > data_len ;
2008-07-14 20:08:37 +04:00
ui - > data_len = size ;
2015-08-18 07:38:36 +03:00
mutex_unlock ( & ui - > ui_mutex ) ;
2008-07-14 20:08:37 +04:00
2008-08-12 17:30:12 +04:00
mutex_lock ( & host_ui - > ui_mutex ) ;
2017-05-09 01:59:25 +03:00
host - > i_ctime = current_time ( host ) ;
2016-09-22 00:57:30 +03:00
host_ui - > xattr_size - = CALC_XATTR_BYTES ( old_size ) ;
2008-08-12 17:30:12 +04:00
host_ui - > xattr_size + = CALC_XATTR_BYTES ( size ) ;
2008-07-14 20:08:37 +04:00
/*
* It is important to write the host inode after the xattr inode
* because if the host inode gets synchronized ( via ' fsync ( ) ' ) , then
* the extended attribute inode gets synchronized , because it goes
* before the host inode in the write - buffer .
*/
err = ubifs_jnl_change_xattr ( c , inode , host ) ;
if ( err )
goto out_cancel ;
mutex_unlock ( & host_ui - > ui_mutex ) ;
ubifs_release_budget ( c , & req ) ;
return 0 ;
out_cancel :
host_ui - > xattr_size - = CALC_XATTR_BYTES ( size ) ;
2016-09-22 00:57:30 +03:00
host_ui - > xattr_size + = CALC_XATTR_BYTES ( old_size ) ;
2008-07-14 20:08:37 +04:00
mutex_unlock ( & host_ui - > ui_mutex ) ;
2008-08-12 17:30:12 +04:00
make_bad_inode ( inode ) ;
out_free :
2008-07-14 20:08:37 +04:00
ubifs_release_budget ( c , & req ) ;
return err ;
}
static struct inode * iget_xattr ( struct ubifs_info * c , ino_t inum )
{
struct inode * inode ;
inode = ubifs_iget ( c - > vfs_sb , inum ) ;
if ( IS_ERR ( inode ) ) {
UBIFS: extend debug/message capabilities
In the case where we have more than one volumes on different UBI
devices, it may be not that easy to tell which volume prints the
messages. Add ubi number and volume id in ubifs_msg/warn/error
to help debug. These two values are passed by struct ubifs_info.
For those where ubifs_info is not initialized yet, ubifs_* is
replaced by pr_*. For those where ubifs_info is not avaliable,
ubifs_info is passed to the calling function as a const parameter.
The output looks like,
[ 95.444879] UBIFS (ubi0:1): background thread "ubifs_bgt0_1" started, PID 696
[ 95.484688] UBIFS (ubi0:1): UBIFS: mounted UBI device 0, volume 1, name "test1"
[ 95.484694] UBIFS (ubi0:1): LEB size: 126976 bytes (124 KiB), min./max. I/O unit sizes: 2048 bytes/2048 bytes
[ 95.484699] UBIFS (ubi0:1): FS size: 30220288 bytes (28 MiB, 238 LEBs), journal size 1523712 bytes (1 MiB, 12 LEBs)
[ 95.484703] UBIFS (ubi0:1): reserved for root: 1427378 bytes (1393 KiB)
[ 95.484709] UBIFS (ubi0:1): media format: w4/r0 (latest is w4/r0), UUID 40DFFC0E-70BE-4193-8905-F7D6DFE60B17, small LPT model
[ 95.489875] UBIFS (ubi1:0): background thread "ubifs_bgt1_0" started, PID 699
[ 95.529713] UBIFS (ubi1:0): UBIFS: mounted UBI device 1, volume 0, name "test2"
[ 95.529718] UBIFS (ubi1:0): LEB size: 126976 bytes (124 KiB), min./max. I/O unit sizes: 2048 bytes/2048 bytes
[ 95.529724] UBIFS (ubi1:0): FS size: 19808256 bytes (18 MiB, 156 LEBs), journal size 1015809 bytes (0 MiB, 8 LEBs)
[ 95.529727] UBIFS (ubi1:0): reserved for root: 935592 bytes (913 KiB)
[ 95.529733] UBIFS (ubi1:0): media format: w4/r0 (latest is w4/r0), UUID EEB7779D-F419-4CA9-811B-831CAC7233D4, small LPT model
[ 954.264767] UBIFS error (ubi1:0 pid 756): ubifs_read_node: bad node type (255 but expected 6)
[ 954.367030] UBIFS error (ubi1:0 pid 756): ubifs_read_node: bad node at LEB 0:0, LEB mapping status 1
Signed-off-by: Sheng Yong <shengyong1@huawei.com>
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
2015-03-20 13:39:42 +03:00
ubifs_err ( c , " dead extended attribute entry, error %d " ,
2008-07-14 20:08:37 +04:00
( int ) PTR_ERR ( inode ) ) ;
return inode ;
}
if ( ubifs_inode ( inode ) - > xattr )
return inode ;
UBIFS: extend debug/message capabilities
In the case where we have more than one volumes on different UBI
devices, it may be not that easy to tell which volume prints the
messages. Add ubi number and volume id in ubifs_msg/warn/error
to help debug. These two values are passed by struct ubifs_info.
For those where ubifs_info is not initialized yet, ubifs_* is
replaced by pr_*. For those where ubifs_info is not avaliable,
ubifs_info is passed to the calling function as a const parameter.
The output looks like,
[ 95.444879] UBIFS (ubi0:1): background thread "ubifs_bgt0_1" started, PID 696
[ 95.484688] UBIFS (ubi0:1): UBIFS: mounted UBI device 0, volume 1, name "test1"
[ 95.484694] UBIFS (ubi0:1): LEB size: 126976 bytes (124 KiB), min./max. I/O unit sizes: 2048 bytes/2048 bytes
[ 95.484699] UBIFS (ubi0:1): FS size: 30220288 bytes (28 MiB, 238 LEBs), journal size 1523712 bytes (1 MiB, 12 LEBs)
[ 95.484703] UBIFS (ubi0:1): reserved for root: 1427378 bytes (1393 KiB)
[ 95.484709] UBIFS (ubi0:1): media format: w4/r0 (latest is w4/r0), UUID 40DFFC0E-70BE-4193-8905-F7D6DFE60B17, small LPT model
[ 95.489875] UBIFS (ubi1:0): background thread "ubifs_bgt1_0" started, PID 699
[ 95.529713] UBIFS (ubi1:0): UBIFS: mounted UBI device 1, volume 0, name "test2"
[ 95.529718] UBIFS (ubi1:0): LEB size: 126976 bytes (124 KiB), min./max. I/O unit sizes: 2048 bytes/2048 bytes
[ 95.529724] UBIFS (ubi1:0): FS size: 19808256 bytes (18 MiB, 156 LEBs), journal size 1015809 bytes (0 MiB, 8 LEBs)
[ 95.529727] UBIFS (ubi1:0): reserved for root: 935592 bytes (913 KiB)
[ 95.529733] UBIFS (ubi1:0): media format: w4/r0 (latest is w4/r0), UUID EEB7779D-F419-4CA9-811B-831CAC7233D4, small LPT model
[ 954.264767] UBIFS error (ubi1:0 pid 756): ubifs_read_node: bad node type (255 but expected 6)
[ 954.367030] UBIFS error (ubi1:0 pid 756): ubifs_read_node: bad node at LEB 0:0, LEB mapping status 1
Signed-off-by: Sheng Yong <shengyong1@huawei.com>
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
2015-03-20 13:39:42 +03:00
ubifs_err ( c , " corrupt extended attribute entry " ) ;
2008-07-14 20:08:37 +04:00
iput ( inode ) ;
return ERR_PTR ( - EINVAL ) ;
}
2016-09-19 22:42:06 +03:00
int ubifs_xattr_set ( struct inode * host , const char * name , const void * value ,
2017-06-23 05:37:23 +03:00
size_t size , int flags , bool check_lock )
2008-07-14 20:08:37 +04:00
{
2014-10-31 21:50:29 +03:00
struct inode * inode ;
2008-07-14 20:08:37 +04:00
struct ubifs_info * c = host - > i_sb - > s_fs_info ;
2016-11-12 00:50:29 +03:00
struct fscrypt_name nm = { . disk_name = FSTR_INIT ( ( char * ) name , strlen ( name ) ) } ;
2008-07-14 20:08:37 +04:00
struct ubifs_dent_node * xent ;
union ubifs_key key ;
2016-04-22 20:14:00 +03:00
int err ;
2008-07-14 20:08:37 +04:00
2017-06-23 05:37:23 +03:00
if ( check_lock )
2018-07-12 14:01:57 +03:00
ubifs_assert ( c , inode_is_locked ( host ) ) ;
2008-07-14 20:08:37 +04:00
if ( size > UBIFS_MAX_INO_DATA )
return - ERANGE ;
2016-11-12 00:50:29 +03:00
if ( fname_len ( & nm ) > UBIFS_MAX_NLEN )
2016-04-22 20:14:00 +03:00
return - ENAMETOOLONG ;
2008-07-14 20:08:37 +04:00
xent = kmalloc ( UBIFS_MAX_XENT_NODE_SZ , GFP_NOFS ) ;
if ( ! xent )
return - ENOMEM ;
/*
* The extended attribute entries are stored in LNC , so multiple
* look - ups do not involve reading the flash .
*/
xent_key_init ( c , & key , host - > i_ino , & nm ) ;
err = ubifs_tnc_lookup_nm ( c , & key , xent , & nm ) ;
if ( err ) {
if ( err ! = - ENOENT )
goto out_free ;
if ( flags & XATTR_REPLACE )
/* We are asked not to create the xattr */
err = - ENODATA ;
else
err = create_xattr ( c , host , & nm , value , size ) ;
goto out_free ;
}
if ( flags & XATTR_CREATE ) {
/* We are asked not to replace the xattr */
err = - EEXIST ;
goto out_free ;
}
inode = iget_xattr ( c , le64_to_cpu ( xent - > inum ) ) ;
if ( IS_ERR ( inode ) ) {
err = PTR_ERR ( inode ) ;
goto out_free ;
}
err = change_xattr ( c , host , inode , value , size ) ;
iput ( inode ) ;
out_free :
kfree ( xent ) ;
return err ;
}
2016-09-19 22:42:06 +03:00
ssize_t ubifs_xattr_get ( struct inode * host , const char * name , void * buf ,
size_t size )
2008-07-14 20:08:37 +04:00
{
2016-04-11 07:48:00 +03:00
struct inode * inode ;
2008-07-14 20:08:37 +04:00
struct ubifs_info * c = host - > i_sb - > s_fs_info ;
2016-11-12 00:50:29 +03:00
struct fscrypt_name nm = { . disk_name = FSTR_INIT ( ( char * ) name , strlen ( name ) ) } ;
2008-07-14 20:08:37 +04:00
struct ubifs_inode * ui ;
struct ubifs_dent_node * xent ;
union ubifs_key key ;
int err ;
2016-11-12 00:50:29 +03:00
if ( fname_len ( & nm ) > UBIFS_MAX_NLEN )
2016-04-22 20:14:00 +03:00
return - ENAMETOOLONG ;
2008-07-14 20:08:37 +04:00
xent = kmalloc ( UBIFS_MAX_XENT_NODE_SZ , GFP_NOFS ) ;
if ( ! xent )
return - ENOMEM ;
xent_key_init ( c , & key , host - > i_ino , & nm ) ;
err = ubifs_tnc_lookup_nm ( c , & key , xent , & nm ) ;
if ( err ) {
if ( err = = - ENOENT )
err = - ENODATA ;
goto out_unlock ;
}
inode = iget_xattr ( c , le64_to_cpu ( xent - > inum ) ) ;
if ( IS_ERR ( inode ) ) {
err = PTR_ERR ( inode ) ;
goto out_unlock ;
}
ui = ubifs_inode ( inode ) ;
2018-07-12 14:01:57 +03:00
ubifs_assert ( c , inode - > i_size = = ui - > data_len ) ;
ubifs_assert ( c , ubifs_inode ( host ) - > xattr_size > ui - > data_len ) ;
2008-07-14 20:08:37 +04:00
2015-08-18 07:38:36 +03:00
mutex_lock ( & ui - > ui_mutex ) ;
2008-07-14 20:08:37 +04:00
if ( buf ) {
/* If @buf is %NULL we are supposed to return the length */
if ( ui - > data_len > size ) {
err = - ERANGE ;
goto out_iput ;
}
memcpy ( buf , ui - > data , ui - > data_len ) ;
}
err = ui - > data_len ;
out_iput :
2015-08-18 07:38:36 +03:00
mutex_unlock ( & ui - > ui_mutex ) ;
2008-07-14 20:08:37 +04:00
iput ( inode ) ;
out_unlock :
kfree ( xent ) ;
return err ;
}
2016-09-21 13:21:29 +03:00
static bool xattr_visible ( const char * name )
{
/* File encryption related xattrs are for internal use only */
if ( strcmp ( name , UBIFS_XATTR_NAME_ENCRYPTION_CONTEXT ) = = 0 )
return false ;
/* Show trusted namespace only for "power" users */
if ( strncmp ( name , XATTR_TRUSTED_PREFIX ,
XATTR_TRUSTED_PREFIX_LEN ) = = 0 & & ! capable ( CAP_SYS_ADMIN ) )
return false ;
return true ;
}
2008-07-14 20:08:37 +04:00
ssize_t ubifs_listxattr ( struct dentry * dentry , char * buffer , size_t size )
{
union ubifs_key key ;
2015-03-18 01:25:59 +03:00
struct inode * host = d_inode ( dentry ) ;
2008-07-14 20:08:37 +04:00
struct ubifs_info * c = host - > i_sb - > s_fs_info ;
struct ubifs_inode * host_ui = ubifs_inode ( host ) ;
struct ubifs_dent_node * xent , * pxent = NULL ;
int err , len , written = 0 ;
2016-11-12 00:50:29 +03:00
struct fscrypt_name nm = { 0 } ;
2008-07-14 20:08:37 +04:00
2013-09-16 18:58:53 +04:00
dbg_gen ( " ino %lu ('%pd'), buffer size %zd " , host - > i_ino ,
dentry , size ) ;
2008-07-14 20:08:37 +04:00
len = host_ui - > xattr_names + host_ui - > xattr_cnt ;
if ( ! buffer )
/*
* We should return the minimum buffer size which will fit a
* null - terminated list of all the extended attribute names .
*/
return len ;
if ( len > size )
return - ERANGE ;
lowest_xent_key ( c , & key , host - > i_ino ) ;
while ( 1 ) {
xent = ubifs_tnc_next_ent ( c , & key , & nm ) ;
2008-08-21 18:16:40 +04:00
if ( IS_ERR ( xent ) ) {
2008-07-14 20:08:37 +04:00
err = PTR_ERR ( xent ) ;
break ;
}
2016-11-12 00:50:29 +03:00
fname_name ( & nm ) = xent - > name ;
fname_len ( & nm ) = le16_to_cpu ( xent - > nlen ) ;
2008-07-14 20:08:37 +04:00
2016-09-21 13:21:29 +03:00
if ( xattr_visible ( xent - > name ) ) {
2016-11-12 00:50:29 +03:00
memcpy ( buffer + written , fname_name ( & nm ) , fname_len ( & nm ) + 1 ) ;
written + = fname_len ( & nm ) + 1 ;
2008-07-14 20:08:37 +04:00
}
kfree ( pxent ) ;
pxent = xent ;
key_read ( c , & xent - > key , & key ) ;
}
kfree ( pxent ) ;
if ( err ! = - ENOENT ) {
UBIFS: extend debug/message capabilities
In the case where we have more than one volumes on different UBI
devices, it may be not that easy to tell which volume prints the
messages. Add ubi number and volume id in ubifs_msg/warn/error
to help debug. These two values are passed by struct ubifs_info.
For those where ubifs_info is not initialized yet, ubifs_* is
replaced by pr_*. For those where ubifs_info is not avaliable,
ubifs_info is passed to the calling function as a const parameter.
The output looks like,
[ 95.444879] UBIFS (ubi0:1): background thread "ubifs_bgt0_1" started, PID 696
[ 95.484688] UBIFS (ubi0:1): UBIFS: mounted UBI device 0, volume 1, name "test1"
[ 95.484694] UBIFS (ubi0:1): LEB size: 126976 bytes (124 KiB), min./max. I/O unit sizes: 2048 bytes/2048 bytes
[ 95.484699] UBIFS (ubi0:1): FS size: 30220288 bytes (28 MiB, 238 LEBs), journal size 1523712 bytes (1 MiB, 12 LEBs)
[ 95.484703] UBIFS (ubi0:1): reserved for root: 1427378 bytes (1393 KiB)
[ 95.484709] UBIFS (ubi0:1): media format: w4/r0 (latest is w4/r0), UUID 40DFFC0E-70BE-4193-8905-F7D6DFE60B17, small LPT model
[ 95.489875] UBIFS (ubi1:0): background thread "ubifs_bgt1_0" started, PID 699
[ 95.529713] UBIFS (ubi1:0): UBIFS: mounted UBI device 1, volume 0, name "test2"
[ 95.529718] UBIFS (ubi1:0): LEB size: 126976 bytes (124 KiB), min./max. I/O unit sizes: 2048 bytes/2048 bytes
[ 95.529724] UBIFS (ubi1:0): FS size: 19808256 bytes (18 MiB, 156 LEBs), journal size 1015809 bytes (0 MiB, 8 LEBs)
[ 95.529727] UBIFS (ubi1:0): reserved for root: 935592 bytes (913 KiB)
[ 95.529733] UBIFS (ubi1:0): media format: w4/r0 (latest is w4/r0), UUID EEB7779D-F419-4CA9-811B-831CAC7233D4, small LPT model
[ 954.264767] UBIFS error (ubi1:0 pid 756): ubifs_read_node: bad node type (255 but expected 6)
[ 954.367030] UBIFS error (ubi1:0 pid 756): ubifs_read_node: bad node at LEB 0:0, LEB mapping status 1
Signed-off-by: Sheng Yong <shengyong1@huawei.com>
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
2015-03-20 13:39:42 +03:00
ubifs_err ( c , " cannot find next direntry, error %d " , err ) ;
2008-07-14 20:08:37 +04:00
return err ;
}
2018-07-12 14:01:57 +03:00
ubifs_assert ( c , written < = size ) ;
2008-07-14 20:08:37 +04:00
return written ;
}
static int remove_xattr ( struct ubifs_info * c , struct inode * host ,
2016-11-12 00:50:29 +03:00
struct inode * inode , const struct fscrypt_name * nm )
2008-07-14 20:08:37 +04:00
{
int err ;
struct ubifs_inode * host_ui = ubifs_inode ( host ) ;
struct ubifs_inode * ui = ubifs_inode ( inode ) ;
2008-08-12 14:54:54 +04:00
struct ubifs_budget_req req = { . dirtied_ino = 2 , . mod_dent = 1 ,
. dirtied_ino_d = ALIGN ( host_ui - > data_len , 8 ) } ;
2008-07-14 20:08:37 +04:00
2018-07-12 14:01:57 +03:00
ubifs_assert ( c , ui - > data_len = = inode - > i_size ) ;
2008-07-14 20:08:37 +04:00
err = ubifs_budget_space ( c , & req ) ;
if ( err )
return err ;
mutex_lock ( & host_ui - > ui_mutex ) ;
2017-05-09 01:59:25 +03:00
host - > i_ctime = current_time ( host ) ;
2008-07-14 20:08:37 +04:00
host_ui - > xattr_cnt - = 1 ;
2016-11-12 00:50:29 +03:00
host_ui - > xattr_size - = CALC_DENT_SIZE ( fname_len ( nm ) ) ;
2008-07-14 20:08:37 +04:00
host_ui - > xattr_size - = CALC_XATTR_BYTES ( ui - > data_len ) ;
2016-11-12 00:50:29 +03:00
host_ui - > xattr_names - = fname_len ( nm ) ;
2008-07-14 20:08:37 +04:00
err = ubifs_jnl_delete_xattr ( c , host , inode , nm ) ;
if ( err )
goto out_cancel ;
mutex_unlock ( & host_ui - > ui_mutex ) ;
ubifs_release_budget ( c , & req ) ;
return 0 ;
out_cancel :
host_ui - > xattr_cnt + = 1 ;
2016-11-12 00:50:29 +03:00
host_ui - > xattr_size + = CALC_DENT_SIZE ( fname_len ( nm ) ) ;
2008-07-14 20:08:37 +04:00
host_ui - > xattr_size + = CALC_XATTR_BYTES ( ui - > data_len ) ;
2016-11-12 00:50:29 +03:00
host_ui - > xattr_names + = fname_len ( nm ) ;
2008-07-14 20:08:37 +04:00
mutex_unlock ( & host_ui - > ui_mutex ) ;
ubifs_release_budget ( c , & req ) ;
make_bad_inode ( inode ) ;
return err ;
}
2019-04-05 01:34:38 +03:00
int ubifs_purge_xattrs ( struct inode * host )
{
union ubifs_key key ;
struct ubifs_info * c = host - > i_sb - > s_fs_info ;
struct ubifs_dent_node * xent , * pxent = NULL ;
struct inode * xino ;
struct fscrypt_name nm = { 0 } ;
int err ;
if ( ubifs_inode ( host ) - > xattr_cnt < ubifs_xattr_max_cnt ( c ) )
return 0 ;
ubifs_warn ( c , " inode %lu has too many xattrs, doing a non-atomic deletion " ,
host - > i_ino ) ;
lowest_xent_key ( c , & key , host - > i_ino ) ;
while ( 1 ) {
xent = ubifs_tnc_next_ent ( c , & key , & nm ) ;
if ( IS_ERR ( xent ) ) {
err = PTR_ERR ( xent ) ;
break ;
}
fname_name ( & nm ) = xent - > name ;
fname_len ( & nm ) = le16_to_cpu ( xent - > nlen ) ;
2019-05-14 22:10:50 +03:00
xino = ubifs_iget ( c - > vfs_sb , le64_to_cpu ( xent - > inum ) ) ;
2019-04-05 01:34:38 +03:00
if ( IS_ERR ( xino ) ) {
err = PTR_ERR ( xino ) ;
ubifs_err ( c , " dead directory entry '%s', error %d " ,
xent - > name , err ) ;
ubifs_ro_mode ( c , err ) ;
kfree ( pxent ) ;
return err ;
}
ubifs_assert ( c , ubifs_inode ( xino ) - > xattr ) ;
clear_nlink ( xino ) ;
err = remove_xattr ( c , host , xino , & nm ) ;
if ( err ) {
kfree ( pxent ) ;
iput ( xino ) ;
ubifs_err ( c , " cannot remove xattr, error %d " , err ) ;
return err ;
}
iput ( xino ) ;
kfree ( pxent ) ;
pxent = xent ;
key_read ( c , & xent - > key , & key ) ;
}
kfree ( pxent ) ;
if ( err ! = - ENOENT ) {
ubifs_err ( c , " cannot find next direntry, error %d " , err ) ;
return err ;
}
return 0 ;
}
2017-05-17 01:20:27 +03:00
/**
* ubifs_evict_xattr_inode - Evict an xattr inode .
* @ c : UBIFS file - system description object
* @ xattr_inum : xattr inode number
*
* When an inode that hosts xattrs is being removed we have to make sure
* that cached inodes of the xattrs also get removed from the inode cache
* otherwise we ' d waste memory . This function looks up an inode from the
* inode cache and clears the link counter such that iput ( ) will evict
* the inode .
*/
void ubifs_evict_xattr_inode ( struct ubifs_info * c , ino_t xattr_inum )
{
struct inode * inode ;
inode = ilookup ( c - > vfs_sb , xattr_inum ) ;
if ( inode ) {
clear_nlink ( inode ) ;
iput ( inode ) ;
}
}
2016-09-19 22:42:06 +03:00
static int ubifs_xattr_remove ( struct inode * host , const char * name )
2008-07-14 20:08:37 +04:00
{
2016-04-22 20:14:00 +03:00
struct inode * inode ;
2008-07-14 20:08:37 +04:00
struct ubifs_info * c = host - > i_sb - > s_fs_info ;
2016-11-12 00:50:29 +03:00
struct fscrypt_name nm = { . disk_name = FSTR_INIT ( ( char * ) name , strlen ( name ) ) } ;
2008-07-14 20:08:37 +04:00
struct ubifs_dent_node * xent ;
union ubifs_key key ;
int err ;
2018-07-12 14:01:57 +03:00
ubifs_assert ( c , inode_is_locked ( host ) ) ;
2008-07-14 20:08:37 +04:00
2016-11-12 00:50:29 +03:00
if ( fname_len ( & nm ) > UBIFS_MAX_NLEN )
2016-04-22 20:14:00 +03:00
return - ENAMETOOLONG ;
2008-07-14 20:08:37 +04:00
xent = kmalloc ( UBIFS_MAX_XENT_NODE_SZ , GFP_NOFS ) ;
if ( ! xent )
return - ENOMEM ;
xent_key_init ( c , & key , host - > i_ino , & nm ) ;
err = ubifs_tnc_lookup_nm ( c , & key , xent , & nm ) ;
if ( err ) {
if ( err = = - ENOENT )
err = - ENODATA ;
goto out_free ;
}
inode = iget_xattr ( c , le64_to_cpu ( xent - > inum ) ) ;
if ( IS_ERR ( inode ) ) {
err = PTR_ERR ( inode ) ;
goto out_free ;
}
2018-07-12 14:01:57 +03:00
ubifs_assert ( c , inode - > i_nlink = = 1 ) ;
2011-10-28 16:13:28 +04:00
clear_nlink ( inode ) ;
2008-07-14 20:08:37 +04:00
err = remove_xattr ( c , host , inode , & nm ) ;
if ( err )
2011-10-28 16:13:29 +04:00
set_nlink ( inode , 1 ) ;
2008-07-14 20:08:37 +04:00
/* If @i_nlink is 0, 'iput()' will delete the inode */
iput ( inode ) ;
out_free :
kfree ( xent ) ;
return err ;
}
2014-10-31 21:50:30 +03:00
2017-03-03 10:44:03 +03:00
# ifdef CONFIG_UBIFS_FS_SECURITY
2014-10-31 21:50:30 +03:00
static int init_xattrs ( struct inode * inode , const struct xattr * xattr_array ,
void * fs_info )
{
const struct xattr * xattr ;
char * name ;
int err = 0 ;
for ( xattr = xattr_array ; xattr - > name ! = NULL ; xattr + + ) {
name = kmalloc ( XATTR_SECURITY_PREFIX_LEN +
strlen ( xattr - > name ) + 1 , GFP_NOFS ) ;
if ( ! name ) {
err = - ENOMEM ;
break ;
}
strcpy ( name , XATTR_SECURITY_PREFIX ) ;
strcpy ( name + XATTR_SECURITY_PREFIX_LEN , xattr - > name ) ;
2017-06-23 05:37:23 +03:00
/*
* creating a new inode without holding the inode rwsem ,
* no need to check whether inode is locked .
*/
2016-09-19 22:42:06 +03:00
err = ubifs_xattr_set ( inode , name , xattr - > value ,
2017-06-23 05:37:23 +03:00
xattr - > value_len , 0 , false ) ;
2014-10-31 21:50:30 +03:00
kfree ( name ) ;
if ( err < 0 )
break ;
}
return err ;
}
int ubifs_init_security ( struct inode * dentry , struct inode * inode ,
const struct qstr * qstr )
{
int err ;
err = security_inode_init_security ( inode , dentry , qstr ,
& init_xattrs , 0 ) ;
UBIFS: extend debug/message capabilities
In the case where we have more than one volumes on different UBI
devices, it may be not that easy to tell which volume prints the
messages. Add ubi number and volume id in ubifs_msg/warn/error
to help debug. These two values are passed by struct ubifs_info.
For those where ubifs_info is not initialized yet, ubifs_* is
replaced by pr_*. For those where ubifs_info is not avaliable,
ubifs_info is passed to the calling function as a const parameter.
The output looks like,
[ 95.444879] UBIFS (ubi0:1): background thread "ubifs_bgt0_1" started, PID 696
[ 95.484688] UBIFS (ubi0:1): UBIFS: mounted UBI device 0, volume 1, name "test1"
[ 95.484694] UBIFS (ubi0:1): LEB size: 126976 bytes (124 KiB), min./max. I/O unit sizes: 2048 bytes/2048 bytes
[ 95.484699] UBIFS (ubi0:1): FS size: 30220288 bytes (28 MiB, 238 LEBs), journal size 1523712 bytes (1 MiB, 12 LEBs)
[ 95.484703] UBIFS (ubi0:1): reserved for root: 1427378 bytes (1393 KiB)
[ 95.484709] UBIFS (ubi0:1): media format: w4/r0 (latest is w4/r0), UUID 40DFFC0E-70BE-4193-8905-F7D6DFE60B17, small LPT model
[ 95.489875] UBIFS (ubi1:0): background thread "ubifs_bgt1_0" started, PID 699
[ 95.529713] UBIFS (ubi1:0): UBIFS: mounted UBI device 1, volume 0, name "test2"
[ 95.529718] UBIFS (ubi1:0): LEB size: 126976 bytes (124 KiB), min./max. I/O unit sizes: 2048 bytes/2048 bytes
[ 95.529724] UBIFS (ubi1:0): FS size: 19808256 bytes (18 MiB, 156 LEBs), journal size 1015809 bytes (0 MiB, 8 LEBs)
[ 95.529727] UBIFS (ubi1:0): reserved for root: 935592 bytes (913 KiB)
[ 95.529733] UBIFS (ubi1:0): media format: w4/r0 (latest is w4/r0), UUID EEB7779D-F419-4CA9-811B-831CAC7233D4, small LPT model
[ 954.264767] UBIFS error (ubi1:0 pid 756): ubifs_read_node: bad node type (255 but expected 6)
[ 954.367030] UBIFS error (ubi1:0 pid 756): ubifs_read_node: bad node at LEB 0:0, LEB mapping status 1
Signed-off-by: Sheng Yong <shengyong1@huawei.com>
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
2015-03-20 13:39:42 +03:00
if ( err ) {
struct ubifs_info * c = dentry - > i_sb - > s_fs_info ;
ubifs_err ( c , " cannot initialize security for inode %lu, error %d " ,
2014-10-31 21:50:31 +03:00
inode - > i_ino , err ) ;
UBIFS: extend debug/message capabilities
In the case where we have more than one volumes on different UBI
devices, it may be not that easy to tell which volume prints the
messages. Add ubi number and volume id in ubifs_msg/warn/error
to help debug. These two values are passed by struct ubifs_info.
For those where ubifs_info is not initialized yet, ubifs_* is
replaced by pr_*. For those where ubifs_info is not avaliable,
ubifs_info is passed to the calling function as a const parameter.
The output looks like,
[ 95.444879] UBIFS (ubi0:1): background thread "ubifs_bgt0_1" started, PID 696
[ 95.484688] UBIFS (ubi0:1): UBIFS: mounted UBI device 0, volume 1, name "test1"
[ 95.484694] UBIFS (ubi0:1): LEB size: 126976 bytes (124 KiB), min./max. I/O unit sizes: 2048 bytes/2048 bytes
[ 95.484699] UBIFS (ubi0:1): FS size: 30220288 bytes (28 MiB, 238 LEBs), journal size 1523712 bytes (1 MiB, 12 LEBs)
[ 95.484703] UBIFS (ubi0:1): reserved for root: 1427378 bytes (1393 KiB)
[ 95.484709] UBIFS (ubi0:1): media format: w4/r0 (latest is w4/r0), UUID 40DFFC0E-70BE-4193-8905-F7D6DFE60B17, small LPT model
[ 95.489875] UBIFS (ubi1:0): background thread "ubifs_bgt1_0" started, PID 699
[ 95.529713] UBIFS (ubi1:0): UBIFS: mounted UBI device 1, volume 0, name "test2"
[ 95.529718] UBIFS (ubi1:0): LEB size: 126976 bytes (124 KiB), min./max. I/O unit sizes: 2048 bytes/2048 bytes
[ 95.529724] UBIFS (ubi1:0): FS size: 19808256 bytes (18 MiB, 156 LEBs), journal size 1015809 bytes (0 MiB, 8 LEBs)
[ 95.529727] UBIFS (ubi1:0): reserved for root: 935592 bytes (913 KiB)
[ 95.529733] UBIFS (ubi1:0): media format: w4/r0 (latest is w4/r0), UUID EEB7779D-F419-4CA9-811B-831CAC7233D4, small LPT model
[ 954.264767] UBIFS error (ubi1:0 pid 756): ubifs_read_node: bad node type (255 but expected 6)
[ 954.367030] UBIFS error (ubi1:0 pid 756): ubifs_read_node: bad node at LEB 0:0, LEB mapping status 1
Signed-off-by: Sheng Yong <shengyong1@huawei.com>
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
2015-03-20 13:39:42 +03:00
}
2014-10-31 21:50:30 +03:00
return err ;
}
2017-03-03 10:44:03 +03:00
# endif
2016-04-22 20:14:00 +03:00
2016-09-19 22:42:06 +03:00
static int xattr_get ( const struct xattr_handler * handler ,
2016-04-22 20:14:00 +03:00
struct dentry * dentry , struct inode * inode ,
const char * name , void * buffer , size_t size )
{
dbg_gen ( " xattr '%s', ino %lu ('%pd'), buf size %zd " , name ,
inode - > i_ino , dentry , size ) ;
2016-07-31 22:42:23 +03:00
name = xattr_full_name ( handler , name ) ;
2016-09-19 22:42:06 +03:00
return ubifs_xattr_get ( inode , name , buffer , size ) ;
2016-04-22 20:14:00 +03:00
}
2016-09-19 22:42:06 +03:00
static int xattr_set ( const struct xattr_handler * handler ,
2016-05-27 17:19:30 +03:00
struct dentry * dentry , struct inode * inode ,
const char * name , const void * value ,
size_t size , int flags )
2016-04-22 20:14:00 +03:00
{
dbg_gen ( " xattr '%s', host ino %lu ('%pd'), size %zd " ,
name , inode - > i_ino , dentry , size ) ;
2016-07-31 22:42:23 +03:00
name = xattr_full_name ( handler , name ) ;
2016-04-22 20:14:00 +03:00
if ( value )
2017-06-23 05:37:23 +03:00
return ubifs_xattr_set ( inode , name , value , size , flags , true ) ;
2016-04-22 20:14:00 +03:00
else
2016-09-19 22:42:06 +03:00
return ubifs_xattr_remove ( inode , name ) ;
2016-04-22 20:14:00 +03:00
}
2016-06-21 19:50:43 +03:00
static const struct xattr_handler ubifs_user_xattr_handler = {
2016-04-22 20:14:00 +03:00
. prefix = XATTR_USER_PREFIX ,
2016-09-19 22:42:06 +03:00
. get = xattr_get ,
. set = xattr_set ,
2016-04-22 20:14:00 +03:00
} ;
2016-06-21 19:50:43 +03:00
static const struct xattr_handler ubifs_trusted_xattr_handler = {
2016-04-22 20:14:00 +03:00
. prefix = XATTR_TRUSTED_PREFIX ,
2016-09-19 22:42:06 +03:00
. get = xattr_get ,
. set = xattr_set ,
2016-04-22 20:14:00 +03:00
} ;
2017-03-03 10:44:03 +03:00
# ifdef CONFIG_UBIFS_FS_SECURITY
2016-06-21 19:50:43 +03:00
static const struct xattr_handler ubifs_security_xattr_handler = {
2016-04-22 20:14:00 +03:00
. prefix = XATTR_SECURITY_PREFIX ,
2016-09-19 22:42:06 +03:00
. get = xattr_get ,
. set = xattr_set ,
2016-04-22 20:14:00 +03:00
} ;
2017-03-03 10:44:03 +03:00
# endif
2016-04-22 20:14:00 +03:00
const struct xattr_handler * ubifs_xattr_handlers [ ] = {
& ubifs_user_xattr_handler ,
& ubifs_trusted_xattr_handler ,
2017-03-03 10:44:03 +03:00
# ifdef CONFIG_UBIFS_FS_SECURITY
2016-04-22 20:14:00 +03:00
& ubifs_security_xattr_handler ,
2017-03-03 10:44:03 +03:00
# endif
2016-04-22 20:14:00 +03:00
NULL
} ;