2008-07-14 16:08:37 +00:00
|
|
|
|
/*
|
|
|
|
|
* This file is part of UBIFS.
|
|
|
|
|
*
|
|
|
|
|
* Copyright (C) 2006-2008 Nokia Corporation.
|
|
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
|
|
|
* under the terms of the GNU General Public License version 2 as published by
|
|
|
|
|
* the Free Software Foundation.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
|
|
|
* more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License along with
|
|
|
|
|
* this program; if not, write to the Free Software Foundation, Inc., 51
|
|
|
|
|
* Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
|
*
|
|
|
|
|
* 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 (4KiB). 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 16:11:54 +00:00
|
|
|
|
#include "ubifs.h"
|
2011-04-05 21:51:48 +00: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 08:04:11 +00:00
|
|
|
|
#include <linux/slab.h>
|
2008-07-14 16:08:37 +00:00
|
|
|
|
#include <linux/xattr.h>
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Limit the number of extended attributes per inode so that the total size
|
2008-08-12 13:30:12 +00:00
|
|
|
|
* (@xattr_size) is guaranteeded to fit in an 'unsigned int'.
|
2008-07-14 16:08:37 +00:00
|
|
|
|
*/
|
|
|
|
|
#define MAX_XATTRS_PER_INODE 65535
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* 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-03 23:55:39 +00:00
|
|
|
|
static const struct inode_operations empty_iops;
|
|
|
|
|
static const struct file_operations empty_fops;
|
2008-07-14 16:08:37 +00: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,
|
|
|
|
|
const struct qstr *nm, const void *value, int size)
|
|
|
|
|
{
|
2014-10-31 18:50:31 +00:00
|
|
|
|
int err, names_len;
|
2008-07-14 16:08:37 +00: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 10:54:54 +00:00
|
|
|
|
.new_ino_d = ALIGN(size, 8), .dirtied_ino = 1,
|
|
|
|
|
.dirtied_ino_d = ALIGN(host_ui->data_len, 8) };
|
2008-07-14 16:08:37 +00:00
|
|
|
|
|
2014-10-31 18:50:31 +00:00
|
|
|
|
if (host_ui->xattr_cnt >= MAX_XATTRS_PER_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 10:39:42 +00:00
|
|
|
|
ubifs_err(c, "inode %lu already has too many xattrs (%d), cannot create more",
|
2014-10-31 18:50:31 +00:00
|
|
|
|
host->i_ino, host_ui->xattr_cnt);
|
2008-07-14 16:08:37 +00:00
|
|
|
|
return -ENOSPC;
|
2014-10-31 18:50:31 +00:00
|
|
|
|
}
|
2008-07-14 16:08:37 +00:00
|
|
|
|
/*
|
|
|
|
|
* Linux limits the maximum size of the extended attribute names list
|
2008-08-12 13:30:12 +00:00
|
|
|
|
* to %XATTR_LIST_MAX. This means we should not allow creating more
|
2008-07-14 16:08:37 +00:00
|
|
|
|
* extended attributes if the name list becomes larger. This limitation
|
|
|
|
|
* is artificial for UBIFS, though.
|
|
|
|
|
*/
|
2014-10-31 18:50:31 +00:00
|
|
|
|
names_len = host_ui->xattr_names + host_ui->xattr_cnt + nm->len + 1;
|
|
|
|
|
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 10:39:42 +00: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 18:50:31 +00:00
|
|
|
|
host->i_ino, names_len, XATTR_LIST_MAX);
|
2008-07-14 16:08:37 +00:00
|
|
|
|
return -ENOSPC;
|
2014-10-31 18:50:31 +00:00
|
|
|
|
}
|
2008-07-14 16:08:37 +00: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-05 21:51:48 +00:00
|
|
|
|
inode->i_mapping->a_ops = &empty_aops;
|
2011-04-03 23:55:39 +00:00
|
|
|
|
inode->i_op = &empty_iops;
|
|
|
|
|
inode->i_fop = &empty_fops;
|
2008-07-14 16:08:37 +00:00
|
|
|
|
|
|
|
|
|
inode->i_flags |= S_SYNC | S_NOATIME | S_NOCMTIME | S_NOQUOTA;
|
|
|
|
|
ui = ubifs_inode(inode);
|
|
|
|
|
ui->xattr = 1;
|
|
|
|
|
ui->flags |= UBIFS_XATTR_FL;
|
2011-11-17 23:00:52 +00:00
|
|
|
|
ui->data = kmemdup(value, size, GFP_NOFS);
|
2008-07-14 16:08:37 +00:00
|
|
|
|
if (!ui->data) {
|
|
|
|
|
err = -ENOMEM;
|
2008-08-12 13:30:12 +00:00
|
|
|
|
goto out_free;
|
2008-07-14 16:08:37 +00:00
|
|
|
|
}
|
2008-08-12 13:30:12 +00:00
|
|
|
|
inode->i_size = ui->ui_size = size;
|
|
|
|
|
ui->data_len = size;
|
|
|
|
|
|
|
|
|
|
mutex_lock(&host_ui->ui_mutex);
|
2008-07-14 16:08:37 +00:00
|
|
|
|
host->i_ctime = ubifs_current_time(host);
|
|
|
|
|
host_ui->xattr_cnt += 1;
|
|
|
|
|
host_ui->xattr_size += CALC_DENT_SIZE(nm->len);
|
|
|
|
|
host_ui->xattr_size += CALC_XATTR_BYTES(size);
|
|
|
|
|
host_ui->xattr_names += nm->len;
|
|
|
|
|
|
|
|
|
|
err = ubifs_jnl_update(c, host, nm, inode, 0, 1);
|
|
|
|
|
if (err)
|
|
|
|
|
goto out_cancel;
|
|
|
|
|
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;
|
|
|
|
|
host_ui->xattr_size -= CALC_DENT_SIZE(nm->len);
|
|
|
|
|
host_ui->xattr_size -= CALC_XATTR_BYTES(size);
|
2016-09-20 08:08:30 +00:00
|
|
|
|
host_ui->xattr_names -= nm->len;
|
2008-07-14 16:08:37 +00:00
|
|
|
|
mutex_unlock(&host_ui->ui_mutex);
|
2008-08-12 13:30:12 +00:00
|
|
|
|
out_free:
|
2008-07-14 16:08:37 +00: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 04:38:36 +00:00
|
|
|
|
void *buf = NULL;
|
2016-09-21 21:57:30 +00:00
|
|
|
|
int old_size;
|
2008-07-14 16:08:37 +00:00
|
|
|
|
struct ubifs_budget_req req = { .dirtied_ino = 2,
|
2008-08-12 10:54:54 +00:00
|
|
|
|
.dirtied_ino_d = ALIGN(size, 8) + ALIGN(host_ui->data_len, 8) };
|
2008-07-14 16:08:37 +00:00
|
|
|
|
|
|
|
|
|
ubifs_assert(ui->data_len == inode->i_size);
|
|
|
|
|
err = ubifs_budget_space(c, &req);
|
|
|
|
|
if (err)
|
|
|
|
|
return err;
|
|
|
|
|
|
2015-08-18 04:38:36 +00:00
|
|
|
|
buf = kmemdup(value, size, GFP_NOFS);
|
|
|
|
|
if (!buf) {
|
2008-07-14 16:08:37 +00:00
|
|
|
|
err = -ENOMEM;
|
2008-08-12 13:30:12 +00:00
|
|
|
|
goto out_free;
|
2008-07-14 16:08:37 +00:00
|
|
|
|
}
|
2015-08-18 04:38:36 +00:00
|
|
|
|
mutex_lock(&ui->ui_mutex);
|
|
|
|
|
kfree(ui->data);
|
|
|
|
|
ui->data = buf;
|
2008-07-14 16:08:37 +00:00
|
|
|
|
inode->i_size = ui->ui_size = size;
|
2016-09-21 21:57:30 +00:00
|
|
|
|
old_size = ui->data_len;
|
2008-07-14 16:08:37 +00:00
|
|
|
|
ui->data_len = size;
|
2015-08-18 04:38:36 +00:00
|
|
|
|
mutex_unlock(&ui->ui_mutex);
|
2008-07-14 16:08:37 +00:00
|
|
|
|
|
2008-08-12 13:30:12 +00:00
|
|
|
|
mutex_lock(&host_ui->ui_mutex);
|
|
|
|
|
host->i_ctime = ubifs_current_time(host);
|
2016-09-21 21:57:30 +00:00
|
|
|
|
host_ui->xattr_size -= CALC_XATTR_BYTES(old_size);
|
2008-08-12 13:30:12 +00:00
|
|
|
|
host_ui->xattr_size += CALC_XATTR_BYTES(size);
|
|
|
|
|
|
2008-07-14 16:08:37 +00: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-21 21:57:30 +00:00
|
|
|
|
host_ui->xattr_size += CALC_XATTR_BYTES(old_size);
|
2008-07-14 16:08:37 +00:00
|
|
|
|
mutex_unlock(&host_ui->ui_mutex);
|
2008-08-12 13:30:12 +00:00
|
|
|
|
make_bad_inode(inode);
|
|
|
|
|
out_free:
|
2008-07-14 16:08:37 +00: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 10:39:42 +00:00
|
|
|
|
ubifs_err(c, "dead extended attribute entry, error %d",
|
2008-07-14 16:08:37 +00: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 10:39:42 +00:00
|
|
|
|
ubifs_err(c, "corrupt extended attribute entry");
|
2008-07-14 16:08:37 +00:00
|
|
|
|
iput(inode);
|
|
|
|
|
return ERR_PTR(-EINVAL);
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-22 17:14:00 +00:00
|
|
|
|
static int __ubifs_setxattr(struct inode *host, const char *name,
|
|
|
|
|
const void *value, size_t size, int flags)
|
2008-07-14 16:08:37 +00:00
|
|
|
|
{
|
2014-10-31 18:50:29 +00:00
|
|
|
|
struct inode *inode;
|
2008-07-14 16:08:37 +00:00
|
|
|
|
struct ubifs_info *c = host->i_sb->s_fs_info;
|
2012-05-10 20:14:12 +00:00
|
|
|
|
struct qstr nm = QSTR_INIT(name, strlen(name));
|
2008-07-14 16:08:37 +00:00
|
|
|
|
struct ubifs_dent_node *xent;
|
|
|
|
|
union ubifs_key key;
|
2016-04-22 17:14:00 +00:00
|
|
|
|
int err;
|
2008-07-14 16:08:37 +00:00
|
|
|
|
|
2016-01-22 20:40:57 +00:00
|
|
|
|
ubifs_assert(inode_is_locked(host));
|
2008-07-14 16:08:37 +00:00
|
|
|
|
|
|
|
|
|
if (size > UBIFS_MAX_INO_DATA)
|
|
|
|
|
return -ERANGE;
|
|
|
|
|
|
2016-04-22 17:14:00 +00:00
|
|
|
|
if (nm.len > UBIFS_MAX_NLEN)
|
|
|
|
|
return -ENAMETOOLONG;
|
2008-07-14 16:08:37 +00: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-04-22 17:14:00 +00:00
|
|
|
|
static ssize_t __ubifs_getxattr(struct inode *host, const char *name,
|
|
|
|
|
void *buf, size_t size)
|
2008-07-14 16:08:37 +00:00
|
|
|
|
{
|
2016-04-11 04:48:00 +00:00
|
|
|
|
struct inode *inode;
|
2008-07-14 16:08:37 +00:00
|
|
|
|
struct ubifs_info *c = host->i_sb->s_fs_info;
|
2012-05-10 20:14:12 +00:00
|
|
|
|
struct qstr nm = QSTR_INIT(name, strlen(name));
|
2008-07-14 16:08:37 +00:00
|
|
|
|
struct ubifs_inode *ui;
|
|
|
|
|
struct ubifs_dent_node *xent;
|
|
|
|
|
union ubifs_key key;
|
|
|
|
|
int err;
|
|
|
|
|
|
2016-04-22 17:14:00 +00:00
|
|
|
|
if (nm.len > UBIFS_MAX_NLEN)
|
|
|
|
|
return -ENAMETOOLONG;
|
2008-07-14 16:08:37 +00: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);
|
|
|
|
|
ubifs_assert(inode->i_size == ui->data_len);
|
|
|
|
|
ubifs_assert(ubifs_inode(host)->xattr_size > ui->data_len);
|
|
|
|
|
|
2015-08-18 04:38:36 +00:00
|
|
|
|
mutex_lock(&ui->ui_mutex);
|
2008-07-14 16:08:37 +00:00
|
|
|
|
if (buf) {
|
|
|
|
|
/* If @buf is %NULL we are supposed to return the length */
|
|
|
|
|
if (ui->data_len > size) {
|
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 10:39:42 +00:00
|
|
|
|
ubifs_err(c, "buffer size %zd, xattr len %d",
|
2012-05-16 17:11:23 +00:00
|
|
|
|
size, ui->data_len);
|
2008-07-14 16:08:37 +00:00
|
|
|
|
err = -ERANGE;
|
|
|
|
|
goto out_iput;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
memcpy(buf, ui->data, ui->data_len);
|
|
|
|
|
}
|
|
|
|
|
err = ui->data_len;
|
|
|
|
|
|
|
|
|
|
out_iput:
|
2015-08-18 04:38:36 +00:00
|
|
|
|
mutex_unlock(&ui->ui_mutex);
|
2008-07-14 16:08:37 +00:00
|
|
|
|
iput(inode);
|
|
|
|
|
out_unlock:
|
|
|
|
|
kfree(xent);
|
|
|
|
|
return err;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ssize_t ubifs_listxattr(struct dentry *dentry, char *buffer, size_t size)
|
|
|
|
|
{
|
|
|
|
|
union ubifs_key key;
|
2015-03-17 22:25:59 +00:00
|
|
|
|
struct inode *host = d_inode(dentry);
|
2008-07-14 16:08:37 +00: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;
|
|
|
|
|
struct qstr nm = { .name = NULL };
|
|
|
|
|
|
2013-09-16 14:58:53 +00:00
|
|
|
|
dbg_gen("ino %lu ('%pd'), buffer size %zd", host->i_ino,
|
|
|
|
|
dentry, size);
|
2008-07-14 16:08:37 +00: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 14:16:40 +00:00
|
|
|
|
if (IS_ERR(xent)) {
|
2008-07-14 16:08:37 +00:00
|
|
|
|
err = PTR_ERR(xent);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
nm.name = xent->name;
|
|
|
|
|
nm.len = le16_to_cpu(xent->nlen);
|
|
|
|
|
|
|
|
|
|
/* Show trusted namespace only for "power" users */
|
2016-04-22 17:14:00 +00:00
|
|
|
|
if (strncmp(xent->name, XATTR_TRUSTED_PREFIX,
|
|
|
|
|
XATTR_TRUSTED_PREFIX_LEN) ||
|
|
|
|
|
capable(CAP_SYS_ADMIN)) {
|
2008-07-14 16:08:37 +00:00
|
|
|
|
memcpy(buffer + written, nm.name, nm.len + 1);
|
|
|
|
|
written += nm.len + 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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 10:39:42 +00:00
|
|
|
|
ubifs_err(c, "cannot find next direntry, error %d", err);
|
2008-07-14 16:08:37 +00:00
|
|
|
|
return err;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ubifs_assert(written <= size);
|
|
|
|
|
return written;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int remove_xattr(struct ubifs_info *c, struct inode *host,
|
|
|
|
|
struct inode *inode, const struct qstr *nm)
|
|
|
|
|
{
|
|
|
|
|
int err;
|
|
|
|
|
struct ubifs_inode *host_ui = ubifs_inode(host);
|
|
|
|
|
struct ubifs_inode *ui = ubifs_inode(inode);
|
2008-08-12 10:54:54 +00:00
|
|
|
|
struct ubifs_budget_req req = { .dirtied_ino = 2, .mod_dent = 1,
|
|
|
|
|
.dirtied_ino_d = ALIGN(host_ui->data_len, 8) };
|
2008-07-14 16:08:37 +00:00
|
|
|
|
|
|
|
|
|
ubifs_assert(ui->data_len == inode->i_size);
|
|
|
|
|
|
|
|
|
|
err = ubifs_budget_space(c, &req);
|
|
|
|
|
if (err)
|
|
|
|
|
return err;
|
|
|
|
|
|
|
|
|
|
mutex_lock(&host_ui->ui_mutex);
|
|
|
|
|
host->i_ctime = ubifs_current_time(host);
|
|
|
|
|
host_ui->xattr_cnt -= 1;
|
|
|
|
|
host_ui->xattr_size -= CALC_DENT_SIZE(nm->len);
|
|
|
|
|
host_ui->xattr_size -= CALC_XATTR_BYTES(ui->data_len);
|
|
|
|
|
host_ui->xattr_names -= nm->len;
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
host_ui->xattr_size += CALC_DENT_SIZE(nm->len);
|
|
|
|
|
host_ui->xattr_size += CALC_XATTR_BYTES(ui->data_len);
|
2016-09-20 08:08:30 +00:00
|
|
|
|
host_ui->xattr_names += nm->len;
|
2008-07-14 16:08:37 +00:00
|
|
|
|
mutex_unlock(&host_ui->ui_mutex);
|
|
|
|
|
ubifs_release_budget(c, &req);
|
|
|
|
|
make_bad_inode(inode);
|
|
|
|
|
return err;
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-22 17:14:00 +00:00
|
|
|
|
static int __ubifs_removexattr(struct inode *host, const char *name)
|
2008-07-14 16:08:37 +00:00
|
|
|
|
{
|
2016-04-22 17:14:00 +00:00
|
|
|
|
struct inode *inode;
|
2008-07-14 16:08:37 +00:00
|
|
|
|
struct ubifs_info *c = host->i_sb->s_fs_info;
|
2012-05-10 20:14:12 +00:00
|
|
|
|
struct qstr nm = QSTR_INIT(name, strlen(name));
|
2008-07-14 16:08:37 +00:00
|
|
|
|
struct ubifs_dent_node *xent;
|
|
|
|
|
union ubifs_key key;
|
|
|
|
|
int err;
|
|
|
|
|
|
2016-01-22 20:40:57 +00:00
|
|
|
|
ubifs_assert(inode_is_locked(host));
|
2008-07-14 16:08:37 +00:00
|
|
|
|
|
2016-04-22 17:14:00 +00:00
|
|
|
|
if (nm.len > UBIFS_MAX_NLEN)
|
|
|
|
|
return -ENAMETOOLONG;
|
2008-07-14 16:08:37 +00: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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ubifs_assert(inode->i_nlink == 1);
|
2011-10-28 12:13:28 +00:00
|
|
|
|
clear_nlink(inode);
|
2008-07-14 16:08:37 +00:00
|
|
|
|
err = remove_xattr(c, host, inode, &nm);
|
|
|
|
|
if (err)
|
2011-10-28 12:13:29 +00:00
|
|
|
|
set_nlink(inode, 1);
|
2008-07-14 16:08:37 +00:00
|
|
|
|
|
|
|
|
|
/* If @i_nlink is 0, 'iput()' will delete the inode */
|
|
|
|
|
iput(inode);
|
|
|
|
|
|
|
|
|
|
out_free:
|
|
|
|
|
kfree(xent);
|
|
|
|
|
return err;
|
|
|
|
|
}
|
2014-10-31 18:50:30 +00: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);
|
2016-04-22 17:14:00 +00:00
|
|
|
|
err = __ubifs_setxattr(inode, name, xattr->value, xattr->value_len, 0);
|
2014-10-31 18:50:30 +00: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 10:39:42 +00: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 18:50:31 +00: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 10:39:42 +00:00
|
|
|
|
}
|
2014-10-31 18:50:30 +00:00
|
|
|
|
return err;
|
|
|
|
|
}
|
2016-04-22 17:14:00 +00:00
|
|
|
|
|
|
|
|
|
static int ubifs_xattr_get(const struct xattr_handler *handler,
|
|
|
|
|
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 19:42:23 +00:00
|
|
|
|
name = xattr_full_name(handler, name);
|
|
|
|
|
return __ubifs_getxattr(inode, name, buffer, size);
|
2016-04-22 17:14:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int ubifs_xattr_set(const struct xattr_handler *handler,
|
2016-05-27 14:19:30 +00:00
|
|
|
|
struct dentry *dentry, struct inode *inode,
|
|
|
|
|
const char *name, const void *value,
|
|
|
|
|
size_t size, int flags)
|
2016-04-22 17:14:00 +00:00
|
|
|
|
{
|
|
|
|
|
dbg_gen("xattr '%s', host ino %lu ('%pd'), size %zd",
|
|
|
|
|
name, inode->i_ino, dentry, size);
|
|
|
|
|
|
2016-07-31 19:42:23 +00:00
|
|
|
|
name = xattr_full_name(handler, name);
|
|
|
|
|
|
2016-04-22 17:14:00 +00:00
|
|
|
|
if (value)
|
|
|
|
|
return __ubifs_setxattr(inode, name, value, size, flags);
|
|
|
|
|
else
|
|
|
|
|
return __ubifs_removexattr(inode, name);
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-21 16:50:43 +00:00
|
|
|
|
static const struct xattr_handler ubifs_user_xattr_handler = {
|
2016-04-22 17:14:00 +00:00
|
|
|
|
.prefix = XATTR_USER_PREFIX,
|
|
|
|
|
.get = ubifs_xattr_get,
|
|
|
|
|
.set = ubifs_xattr_set,
|
|
|
|
|
};
|
|
|
|
|
|
2016-06-21 16:50:43 +00:00
|
|
|
|
static const struct xattr_handler ubifs_trusted_xattr_handler = {
|
2016-04-22 17:14:00 +00:00
|
|
|
|
.prefix = XATTR_TRUSTED_PREFIX,
|
|
|
|
|
.get = ubifs_xattr_get,
|
|
|
|
|
.set = ubifs_xattr_set,
|
|
|
|
|
};
|
|
|
|
|
|
2016-06-21 16:50:43 +00:00
|
|
|
|
static const struct xattr_handler ubifs_security_xattr_handler = {
|
2016-04-22 17:14:00 +00:00
|
|
|
|
.prefix = XATTR_SECURITY_PREFIX,
|
|
|
|
|
.get = ubifs_xattr_get,
|
|
|
|
|
.set = ubifs_xattr_set,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const struct xattr_handler *ubifs_xattr_handlers[] = {
|
|
|
|
|
&ubifs_user_xattr_handler,
|
|
|
|
|
&ubifs_trusted_xattr_handler,
|
|
|
|
|
&ubifs_security_xattr_handler,
|
|
|
|
|
NULL
|
|
|
|
|
};
|