2019-05-29 23:57:50 +00:00
|
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2008-07-14 16:08:37 +00:00
|
|
|
|
/*
|
|
|
|
|
* This file is part of UBIFS.
|
|
|
|
|
*
|
|
|
|
|
* Copyright (C) 2006-2008 Nokia Corporation.
|
|
|
|
|
*
|
|
|
|
|
* Authors: Artem Bityutskiy (Битюцкий Артём)
|
|
|
|
|
* Adrian Hunter
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* This file implements UBIFS superblock. The superblock is stored at the first
|
|
|
|
|
* LEB of the volume and is never changed by UBIFS. Only user-space tools may
|
|
|
|
|
* change it. The superblock node mostly contains geometry information.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "ubifs.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-12-18 12:06:51 +00:00
|
|
|
|
#include <linux/math64.h>
|
2016-05-21 00:01:00 +00:00
|
|
|
|
#include <linux/uuid.h>
|
2008-07-14 16:08:37 +00:00
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Default journal size in logical eraseblocks as a percent of total
|
|
|
|
|
* flash size.
|
|
|
|
|
*/
|
|
|
|
|
#define DEFAULT_JNL_PERCENT 5
|
|
|
|
|
|
|
|
|
|
/* Default maximum journal size in bytes */
|
|
|
|
|
#define DEFAULT_MAX_JNL (32*1024*1024)
|
|
|
|
|
|
|
|
|
|
/* Default indexing tree fanout */
|
|
|
|
|
#define DEFAULT_FANOUT 8
|
|
|
|
|
|
|
|
|
|
/* Default number of data journal heads */
|
|
|
|
|
#define DEFAULT_JHEADS_CNT 1
|
|
|
|
|
|
|
|
|
|
/* Default positions of different LEBs in the main area */
|
|
|
|
|
#define DEFAULT_IDX_LEB 0
|
|
|
|
|
#define DEFAULT_DATA_LEB 1
|
|
|
|
|
#define DEFAULT_GC_LEB 2
|
|
|
|
|
|
|
|
|
|
/* Default number of LEB numbers in LPT's save table */
|
|
|
|
|
#define DEFAULT_LSAVE_CNT 256
|
|
|
|
|
|
|
|
|
|
/* Default reserved pool size as a percent of maximum free space */
|
|
|
|
|
#define DEFAULT_RP_PERCENT 5
|
|
|
|
|
|
|
|
|
|
/* The default maximum size of reserved pool in bytes */
|
|
|
|
|
#define DEFAULT_MAX_RP_SIZE (5*1024*1024)
|
|
|
|
|
|
|
|
|
|
/* Default time granularity in nanoseconds */
|
|
|
|
|
#define DEFAULT_TIME_GRAN 1000000000
|
|
|
|
|
|
2018-12-09 17:12:13 +00:00
|
|
|
|
static int get_default_compressor(struct ubifs_info *c)
|
|
|
|
|
{
|
|
|
|
|
if (ubifs_compr_present(c, UBIFS_COMPR_LZO))
|
|
|
|
|
return UBIFS_COMPR_LZO;
|
|
|
|
|
|
|
|
|
|
if (ubifs_compr_present(c, UBIFS_COMPR_ZLIB))
|
|
|
|
|
return UBIFS_COMPR_ZLIB;
|
|
|
|
|
|
|
|
|
|
return UBIFS_COMPR_NONE;
|
|
|
|
|
}
|
|
|
|
|
|
2008-07-14 16:08:37 +00:00
|
|
|
|
/**
|
|
|
|
|
* create_default_filesystem - format empty UBI volume.
|
|
|
|
|
* @c: UBIFS file-system description object
|
|
|
|
|
*
|
|
|
|
|
* This function creates default empty file-system. Returns zero in case of
|
|
|
|
|
* success and a negative error code in case of failure.
|
|
|
|
|
*/
|
|
|
|
|
static int create_default_filesystem(struct ubifs_info *c)
|
|
|
|
|
{
|
|
|
|
|
struct ubifs_sb_node *sup;
|
|
|
|
|
struct ubifs_mst_node *mst;
|
|
|
|
|
struct ubifs_idx_node *idx;
|
|
|
|
|
struct ubifs_branch *br;
|
|
|
|
|
struct ubifs_ino_node *ino;
|
|
|
|
|
struct ubifs_cs_node *cs;
|
|
|
|
|
union ubifs_key key;
|
|
|
|
|
int err, tmp, jnl_lebs, log_lebs, max_buds, main_lebs, main_first;
|
|
|
|
|
int lpt_lebs, lpt_first, orph_lebs, big_lpt, ino_waste, sup_flags = 0;
|
|
|
|
|
int min_leb_cnt = UBIFS_MIN_LEB_CNT;
|
2018-09-07 12:36:23 +00:00
|
|
|
|
int idx_node_size;
|
2008-12-18 12:06:51 +00:00
|
|
|
|
long long tmp64, main_bytes;
|
2008-10-24 17:52:57 +00:00
|
|
|
|
__le64 tmp_le64;
|
2018-07-13 14:31:55 +00:00
|
|
|
|
struct timespec64 ts;
|
2018-09-07 12:36:43 +00:00
|
|
|
|
u8 hash[UBIFS_HASH_ARR_SZ];
|
2018-09-07 12:36:41 +00:00
|
|
|
|
u8 hash_lpt[UBIFS_HASH_ARR_SZ];
|
2008-07-14 16:08:37 +00:00
|
|
|
|
|
|
|
|
|
/* Some functions called from here depend on the @c->key_len filed */
|
|
|
|
|
c->key_len = UBIFS_SK_LEN;
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* First of all, we have to calculate default file-system geometry -
|
|
|
|
|
* log size, journal size, etc.
|
|
|
|
|
*/
|
|
|
|
|
if (c->leb_cnt < 0x7FFFFFFF / DEFAULT_JNL_PERCENT)
|
|
|
|
|
/* We can first multiply then divide and have no overflow */
|
|
|
|
|
jnl_lebs = c->leb_cnt * DEFAULT_JNL_PERCENT / 100;
|
|
|
|
|
else
|
|
|
|
|
jnl_lebs = (c->leb_cnt / 100) * DEFAULT_JNL_PERCENT;
|
|
|
|
|
|
|
|
|
|
if (jnl_lebs < UBIFS_MIN_JNL_LEBS)
|
|
|
|
|
jnl_lebs = UBIFS_MIN_JNL_LEBS;
|
|
|
|
|
if (jnl_lebs * c->leb_size > DEFAULT_MAX_JNL)
|
|
|
|
|
jnl_lebs = DEFAULT_MAX_JNL / c->leb_size;
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* The log should be large enough to fit reference nodes for all bud
|
|
|
|
|
* LEBs. Because buds do not have to start from the beginning of LEBs
|
|
|
|
|
* (half of the LEB may contain committed data), the log should
|
|
|
|
|
* generally be larger, make it twice as large.
|
|
|
|
|
*/
|
|
|
|
|
tmp = 2 * (c->ref_node_alsz * jnl_lebs) + c->leb_size - 1;
|
|
|
|
|
log_lebs = tmp / c->leb_size;
|
|
|
|
|
/* Plus one LEB reserved for commit */
|
|
|
|
|
log_lebs += 1;
|
|
|
|
|
if (c->leb_cnt - min_leb_cnt > 8) {
|
|
|
|
|
/* And some extra space to allow writes while committing */
|
|
|
|
|
log_lebs += 1;
|
|
|
|
|
min_leb_cnt += 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
max_buds = jnl_lebs - log_lebs;
|
|
|
|
|
if (max_buds < UBIFS_MIN_BUD_LEBS)
|
|
|
|
|
max_buds = UBIFS_MIN_BUD_LEBS;
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Orphan nodes are stored in a separate area. One node can store a lot
|
|
|
|
|
* of orphan inode numbers, but when new orphan comes we just add a new
|
|
|
|
|
* orphan node. At some point the nodes are consolidated into one
|
|
|
|
|
* orphan node.
|
|
|
|
|
*/
|
|
|
|
|
orph_lebs = UBIFS_MIN_ORPH_LEBS;
|
|
|
|
|
if (c->leb_cnt - min_leb_cnt > 1)
|
|
|
|
|
/*
|
|
|
|
|
* For debugging purposes it is better to have at least 2
|
|
|
|
|
* orphan LEBs, because the orphan subsystem would need to do
|
|
|
|
|
* consolidations and would be stressed more.
|
|
|
|
|
*/
|
|
|
|
|
orph_lebs += 1;
|
|
|
|
|
|
|
|
|
|
main_lebs = c->leb_cnt - UBIFS_SB_LEBS - UBIFS_MST_LEBS - log_lebs;
|
|
|
|
|
main_lebs -= orph_lebs;
|
|
|
|
|
|
|
|
|
|
lpt_first = UBIFS_LOG_LNUM + log_lebs;
|
|
|
|
|
c->lsave_cnt = DEFAULT_LSAVE_CNT;
|
|
|
|
|
c->max_leb_cnt = c->leb_cnt;
|
|
|
|
|
err = ubifs_create_dflt_lpt(c, &main_lebs, lpt_first, &lpt_lebs,
|
2018-09-07 12:36:41 +00:00
|
|
|
|
&big_lpt, hash_lpt);
|
2008-07-14 16:08:37 +00:00
|
|
|
|
if (err)
|
|
|
|
|
return err;
|
|
|
|
|
|
|
|
|
|
dbg_gen("LEB Properties Tree created (LEBs %d-%d)", lpt_first,
|
|
|
|
|
lpt_first + lpt_lebs - 1);
|
|
|
|
|
|
|
|
|
|
main_first = c->leb_cnt - main_lebs;
|
|
|
|
|
|
2018-09-07 12:36:23 +00:00
|
|
|
|
sup = kzalloc(ALIGN(UBIFS_SB_NODE_SZ, c->min_io_size), GFP_KERNEL);
|
|
|
|
|
mst = kzalloc(c->mst_node_alsz, GFP_KERNEL);
|
|
|
|
|
idx_node_size = ubifs_idx_node_sz(c, 1);
|
2019-12-04 10:09:58 +00:00
|
|
|
|
idx = kzalloc(ALIGN(idx_node_size, c->min_io_size), GFP_KERNEL);
|
2018-09-07 12:36:23 +00:00
|
|
|
|
ino = kzalloc(ALIGN(UBIFS_INO_NODE_SZ, c->min_io_size), GFP_KERNEL);
|
|
|
|
|
cs = kzalloc(ALIGN(UBIFS_CS_NODE_SZ, c->min_io_size), GFP_KERNEL);
|
|
|
|
|
|
|
|
|
|
if (!sup || !mst || !idx || !ino || !cs) {
|
|
|
|
|
err = -ENOMEM;
|
|
|
|
|
goto out;
|
|
|
|
|
}
|
|
|
|
|
|
2008-07-14 16:08:37 +00:00
|
|
|
|
/* Create default superblock */
|
|
|
|
|
|
2008-12-18 12:06:51 +00:00
|
|
|
|
tmp64 = (long long)max_buds * c->leb_size;
|
2008-07-14 16:08:37 +00:00
|
|
|
|
if (big_lpt)
|
|
|
|
|
sup_flags |= UBIFS_FLG_BIGLPT;
|
2016-10-19 13:59:12 +00:00
|
|
|
|
sup_flags |= UBIFS_FLG_DOUBLE_HASH;
|
2008-07-14 16:08:37 +00:00
|
|
|
|
|
2018-09-07 12:36:43 +00:00
|
|
|
|
if (ubifs_authenticated(c)) {
|
|
|
|
|
sup_flags |= UBIFS_FLG_AUTHENTICATION;
|
|
|
|
|
sup->hash_algo = cpu_to_le16(c->auth_hash_algo);
|
|
|
|
|
err = ubifs_hmac_wkm(c, sup->hmac_wkm);
|
|
|
|
|
if (err)
|
|
|
|
|
goto out;
|
|
|
|
|
} else {
|
2019-10-16 10:15:03 +00:00
|
|
|
|
sup->hash_algo = cpu_to_le16(0xffff);
|
2018-09-07 12:36:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
2008-07-14 16:08:37 +00:00
|
|
|
|
sup->ch.node_type = UBIFS_SB_NODE;
|
|
|
|
|
sup->key_hash = UBIFS_KEY_HASH_R5;
|
|
|
|
|
sup->flags = cpu_to_le32(sup_flags);
|
|
|
|
|
sup->min_io_size = cpu_to_le32(c->min_io_size);
|
|
|
|
|
sup->leb_size = cpu_to_le32(c->leb_size);
|
|
|
|
|
sup->leb_cnt = cpu_to_le32(c->leb_cnt);
|
|
|
|
|
sup->max_leb_cnt = cpu_to_le32(c->max_leb_cnt);
|
|
|
|
|
sup->max_bud_bytes = cpu_to_le64(tmp64);
|
|
|
|
|
sup->log_lebs = cpu_to_le32(log_lebs);
|
|
|
|
|
sup->lpt_lebs = cpu_to_le32(lpt_lebs);
|
|
|
|
|
sup->orph_lebs = cpu_to_le32(orph_lebs);
|
|
|
|
|
sup->jhead_cnt = cpu_to_le32(DEFAULT_JHEADS_CNT);
|
|
|
|
|
sup->fanout = cpu_to_le32(DEFAULT_FANOUT);
|
|
|
|
|
sup->lsave_cnt = cpu_to_le32(c->lsave_cnt);
|
|
|
|
|
sup->fmt_version = cpu_to_le32(UBIFS_FORMAT_VERSION);
|
|
|
|
|
sup->time_gran = cpu_to_le32(DEFAULT_TIME_GRAN);
|
2008-11-01 12:57:49 +00:00
|
|
|
|
if (c->mount_opts.override_compr)
|
|
|
|
|
sup->default_compr = cpu_to_le16(c->mount_opts.compr_type);
|
|
|
|
|
else
|
2018-12-09 17:12:13 +00:00
|
|
|
|
sup->default_compr = cpu_to_le16(get_default_compressor(c));
|
2008-07-14 16:08:37 +00:00
|
|
|
|
|
|
|
|
|
generate_random_uuid(sup->uuid);
|
|
|
|
|
|
2008-12-18 12:06:51 +00:00
|
|
|
|
main_bytes = (long long)main_lebs * c->leb_size;
|
|
|
|
|
tmp64 = div_u64(main_bytes * DEFAULT_RP_PERCENT, 100);
|
2008-07-14 16:08:37 +00:00
|
|
|
|
if (tmp64 > DEFAULT_MAX_RP_SIZE)
|
|
|
|
|
tmp64 = DEFAULT_MAX_RP_SIZE;
|
|
|
|
|
sup->rp_size = cpu_to_le64(tmp64);
|
2009-03-26 10:51:21 +00:00
|
|
|
|
sup->ro_compat_version = cpu_to_le32(UBIFS_RO_COMPAT_VERSION);
|
2008-07-14 16:08:37 +00:00
|
|
|
|
|
|
|
|
|
dbg_gen("default superblock created at LEB 0:0");
|
|
|
|
|
|
|
|
|
|
/* Create default master node */
|
|
|
|
|
|
|
|
|
|
mst->ch.node_type = UBIFS_MST_NODE;
|
|
|
|
|
mst->log_lnum = cpu_to_le32(UBIFS_LOG_LNUM);
|
|
|
|
|
mst->highest_inum = cpu_to_le64(UBIFS_FIRST_INO);
|
|
|
|
|
mst->cmt_no = 0;
|
|
|
|
|
mst->root_lnum = cpu_to_le32(main_first + DEFAULT_IDX_LEB);
|
|
|
|
|
mst->root_offs = 0;
|
|
|
|
|
tmp = ubifs_idx_node_sz(c, 1);
|
|
|
|
|
mst->root_len = cpu_to_le32(tmp);
|
|
|
|
|
mst->gc_lnum = cpu_to_le32(main_first + DEFAULT_GC_LEB);
|
|
|
|
|
mst->ihead_lnum = cpu_to_le32(main_first + DEFAULT_IDX_LEB);
|
|
|
|
|
mst->ihead_offs = cpu_to_le32(ALIGN(tmp, c->min_io_size));
|
|
|
|
|
mst->index_size = cpu_to_le64(ALIGN(tmp, 8));
|
|
|
|
|
mst->lpt_lnum = cpu_to_le32(c->lpt_lnum);
|
|
|
|
|
mst->lpt_offs = cpu_to_le32(c->lpt_offs);
|
|
|
|
|
mst->nhead_lnum = cpu_to_le32(c->nhead_lnum);
|
|
|
|
|
mst->nhead_offs = cpu_to_le32(c->nhead_offs);
|
|
|
|
|
mst->ltab_lnum = cpu_to_le32(c->ltab_lnum);
|
|
|
|
|
mst->ltab_offs = cpu_to_le32(c->ltab_offs);
|
|
|
|
|
mst->lsave_lnum = cpu_to_le32(c->lsave_lnum);
|
|
|
|
|
mst->lsave_offs = cpu_to_le32(c->lsave_offs);
|
|
|
|
|
mst->lscan_lnum = cpu_to_le32(main_first);
|
|
|
|
|
mst->empty_lebs = cpu_to_le32(main_lebs - 2);
|
|
|
|
|
mst->idx_lebs = cpu_to_le32(1);
|
|
|
|
|
mst->leb_cnt = cpu_to_le32(c->leb_cnt);
|
2018-09-07 12:36:43 +00:00
|
|
|
|
ubifs_copy_hash(c, hash_lpt, mst->hash_lpt);
|
2008-07-14 16:08:37 +00:00
|
|
|
|
|
|
|
|
|
/* Calculate lprops statistics */
|
|
|
|
|
tmp64 = main_bytes;
|
|
|
|
|
tmp64 -= ALIGN(ubifs_idx_node_sz(c, 1), c->min_io_size);
|
|
|
|
|
tmp64 -= ALIGN(UBIFS_INO_NODE_SZ, c->min_io_size);
|
|
|
|
|
mst->total_free = cpu_to_le64(tmp64);
|
|
|
|
|
|
|
|
|
|
tmp64 = ALIGN(ubifs_idx_node_sz(c, 1), c->min_io_size);
|
|
|
|
|
ino_waste = ALIGN(UBIFS_INO_NODE_SZ, c->min_io_size) -
|
|
|
|
|
UBIFS_INO_NODE_SZ;
|
|
|
|
|
tmp64 += ino_waste;
|
|
|
|
|
tmp64 -= ALIGN(ubifs_idx_node_sz(c, 1), 8);
|
|
|
|
|
mst->total_dirty = cpu_to_le64(tmp64);
|
|
|
|
|
|
|
|
|
|
/* The indexing LEB does not contribute to dark space */
|
2011-08-26 10:38:39 +00:00
|
|
|
|
tmp64 = ((long long)(c->main_lebs - 1) * c->dark_wm);
|
2008-07-14 16:08:37 +00:00
|
|
|
|
mst->total_dark = cpu_to_le64(tmp64);
|
|
|
|
|
|
|
|
|
|
mst->total_used = cpu_to_le64(UBIFS_INO_NODE_SZ);
|
|
|
|
|
|
|
|
|
|
dbg_gen("default master node created at LEB %d:0", UBIFS_MST_LNUM);
|
|
|
|
|
|
|
|
|
|
/* Create the root indexing node */
|
|
|
|
|
|
|
|
|
|
c->key_fmt = UBIFS_SIMPLE_KEY_FMT;
|
|
|
|
|
c->key_hash = key_r5_hash;
|
|
|
|
|
|
|
|
|
|
idx->ch.node_type = UBIFS_IDX_NODE;
|
|
|
|
|
idx->child_cnt = cpu_to_le16(1);
|
|
|
|
|
ino_key_init(c, &key, UBIFS_ROOT_INO);
|
|
|
|
|
br = ubifs_idx_branch(c, idx, 0);
|
|
|
|
|
key_write_idx(c, &key, &br->key);
|
|
|
|
|
br->lnum = cpu_to_le32(main_first + DEFAULT_DATA_LEB);
|
|
|
|
|
br->len = cpu_to_le32(UBIFS_INO_NODE_SZ);
|
|
|
|
|
|
|
|
|
|
dbg_gen("default root indexing node created LEB %d:0",
|
|
|
|
|
main_first + DEFAULT_IDX_LEB);
|
|
|
|
|
|
|
|
|
|
/* Create default root inode */
|
|
|
|
|
|
|
|
|
|
ino_key_init_flash(c, &ino->key, UBIFS_ROOT_INO);
|
|
|
|
|
ino->ch.node_type = UBIFS_INO_NODE;
|
|
|
|
|
ino->creat_sqnum = cpu_to_le64(++c->max_sqnum);
|
|
|
|
|
ino->nlink = cpu_to_le32(2);
|
2017-05-08 22:59:25 +00:00
|
|
|
|
|
2019-12-03 05:19:43 +00:00
|
|
|
|
ktime_get_coarse_real_ts64(&ts);
|
2017-05-08 22:59:25 +00:00
|
|
|
|
tmp_le64 = cpu_to_le64(ts.tv_sec);
|
2008-10-24 17:52:57 +00:00
|
|
|
|
ino->atime_sec = tmp_le64;
|
|
|
|
|
ino->ctime_sec = tmp_le64;
|
|
|
|
|
ino->mtime_sec = tmp_le64;
|
2019-12-03 05:19:43 +00:00
|
|
|
|
ino->atime_nsec = 0;
|
|
|
|
|
ino->ctime_nsec = 0;
|
|
|
|
|
ino->mtime_nsec = 0;
|
2008-07-14 16:08:37 +00:00
|
|
|
|
ino->mode = cpu_to_le32(S_IFDIR | S_IRUGO | S_IWUSR | S_IXUGO);
|
|
|
|
|
ino->size = cpu_to_le64(UBIFS_INO_NODE_SZ);
|
|
|
|
|
|
|
|
|
|
/* Set compression enabled by default */
|
|
|
|
|
ino->flags = cpu_to_le32(UBIFS_COMPR_FL);
|
|
|
|
|
|
|
|
|
|
dbg_gen("root inode created at LEB %d:0",
|
|
|
|
|
main_first + DEFAULT_DATA_LEB);
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* The first node in the log has to be the commit start node. This is
|
|
|
|
|
* always the case during normal file-system operation. Write a fake
|
|
|
|
|
* commit start node to the log.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
cs->ch.node_type = UBIFS_CS_NODE;
|
2018-09-07 12:36:23 +00:00
|
|
|
|
|
2018-09-07 12:36:43 +00:00
|
|
|
|
err = ubifs_write_node_hmac(c, sup, UBIFS_SB_NODE_SZ, 0, 0,
|
|
|
|
|
offsetof(struct ubifs_sb_node, hmac));
|
2018-09-07 12:36:23 +00:00
|
|
|
|
if (err)
|
|
|
|
|
goto out;
|
|
|
|
|
|
2018-09-07 12:36:43 +00:00
|
|
|
|
err = ubifs_write_node(c, ino, UBIFS_INO_NODE_SZ,
|
|
|
|
|
main_first + DEFAULT_DATA_LEB, 0);
|
2018-09-07 12:36:23 +00:00
|
|
|
|
if (err)
|
|
|
|
|
goto out;
|
|
|
|
|
|
2018-09-07 12:36:43 +00:00
|
|
|
|
ubifs_node_calc_hash(c, ino, hash);
|
|
|
|
|
ubifs_copy_hash(c, hash, ubifs_branch_hash(c, br));
|
|
|
|
|
|
|
|
|
|
err = ubifs_write_node(c, idx, idx_node_size, main_first + DEFAULT_IDX_LEB, 0);
|
2018-09-07 12:36:23 +00:00
|
|
|
|
if (err)
|
|
|
|
|
goto out;
|
|
|
|
|
|
2018-09-07 12:36:43 +00:00
|
|
|
|
ubifs_node_calc_hash(c, idx, hash);
|
|
|
|
|
ubifs_copy_hash(c, hash, mst->hash_root_idx);
|
|
|
|
|
|
|
|
|
|
err = ubifs_write_node_hmac(c, mst, UBIFS_MST_NODE_SZ, UBIFS_MST_LNUM, 0,
|
|
|
|
|
offsetof(struct ubifs_mst_node, hmac));
|
2018-09-07 12:36:23 +00:00
|
|
|
|
if (err)
|
|
|
|
|
goto out;
|
|
|
|
|
|
2018-09-07 12:36:43 +00:00
|
|
|
|
err = ubifs_write_node_hmac(c, mst, UBIFS_MST_NODE_SZ, UBIFS_MST_LNUM + 1,
|
|
|
|
|
0, offsetof(struct ubifs_mst_node, hmac));
|
2018-09-07 12:36:23 +00:00
|
|
|
|
if (err)
|
|
|
|
|
goto out;
|
|
|
|
|
|
2012-05-14 15:55:51 +00:00
|
|
|
|
err = ubifs_write_node(c, cs, UBIFS_CS_NODE_SZ, UBIFS_LOG_LNUM, 0);
|
2014-06-11 02:38:45 +00:00
|
|
|
|
if (err)
|
2018-09-07 12:36:23 +00:00
|
|
|
|
goto out;
|
2008-07-14 16:08:37 +00:00
|
|
|
|
|
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_msg(c, "default file-system created");
|
2018-09-07 12:36:23 +00:00
|
|
|
|
|
|
|
|
|
err = 0;
|
|
|
|
|
out:
|
|
|
|
|
kfree(sup);
|
|
|
|
|
kfree(mst);
|
|
|
|
|
kfree(idx);
|
|
|
|
|
kfree(ino);
|
|
|
|
|
kfree(cs);
|
|
|
|
|
|
|
|
|
|
return err;
|
2008-07-14 16:08:37 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* validate_sb - validate superblock node.
|
|
|
|
|
* @c: UBIFS file-system description object
|
|
|
|
|
* @sup: superblock node
|
|
|
|
|
*
|
|
|
|
|
* This function validates superblock node @sup. Since most of data was read
|
|
|
|
|
* from the superblock and stored in @c, the function validates fields in @c
|
|
|
|
|
* instead. Returns zero in case of success and %-EINVAL in case of validation
|
|
|
|
|
* failure.
|
|
|
|
|
*/
|
|
|
|
|
static int validate_sb(struct ubifs_info *c, struct ubifs_sb_node *sup)
|
|
|
|
|
{
|
|
|
|
|
long long max_bytes;
|
|
|
|
|
int err = 1, min_leb_cnt;
|
|
|
|
|
|
|
|
|
|
if (!c->key_hash) {
|
|
|
|
|
err = 2;
|
|
|
|
|
goto failed;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (sup->key_fmt != UBIFS_SIMPLE_KEY_FMT) {
|
|
|
|
|
err = 3;
|
|
|
|
|
goto failed;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (le32_to_cpu(sup->min_io_size) != c->min_io_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, "min. I/O unit mismatch: %d in superblock, %d real",
|
2008-07-14 16:08:37 +00:00
|
|
|
|
le32_to_cpu(sup->min_io_size), c->min_io_size);
|
|
|
|
|
goto failed;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (le32_to_cpu(sup->leb_size) != c->leb_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, "LEB size mismatch: %d in superblock, %d real",
|
2008-07-14 16:08:37 +00:00
|
|
|
|
le32_to_cpu(sup->leb_size), c->leb_size);
|
|
|
|
|
goto failed;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (c->log_lebs < UBIFS_MIN_LOG_LEBS ||
|
|
|
|
|
c->lpt_lebs < UBIFS_MIN_LPT_LEBS ||
|
|
|
|
|
c->orph_lebs < UBIFS_MIN_ORPH_LEBS ||
|
|
|
|
|
c->main_lebs < UBIFS_MIN_MAIN_LEBS) {
|
|
|
|
|
err = 4;
|
|
|
|
|
goto failed;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Calculate minimum allowed amount of main area LEBs. This is very
|
|
|
|
|
* similar to %UBIFS_MIN_LEB_CNT, but we take into account real what we
|
|
|
|
|
* have just read from the superblock.
|
|
|
|
|
*/
|
|
|
|
|
min_leb_cnt = UBIFS_SB_LEBS + UBIFS_MST_LEBS + c->log_lebs;
|
|
|
|
|
min_leb_cnt += c->lpt_lebs + c->orph_lebs + c->jhead_cnt + 6;
|
|
|
|
|
|
|
|
|
|
if (c->leb_cnt < min_leb_cnt || c->leb_cnt > c->vi.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, "bad LEB count: %d in superblock, %d on UBI volume, %d minimum required",
|
2012-08-27 10:34:09 +00:00
|
|
|
|
c->leb_cnt, c->vi.size, min_leb_cnt);
|
2008-07-14 16:08:37 +00:00
|
|
|
|
goto failed;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (c->max_leb_cnt < c->leb_cnt) {
|
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, "max. LEB count %d less than LEB count %d",
|
2008-07-14 16:08:37 +00:00
|
|
|
|
c->max_leb_cnt, c->leb_cnt);
|
|
|
|
|
goto failed;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (c->main_lebs < UBIFS_MIN_MAIN_LEBS) {
|
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, "too few main LEBs count %d, must be at least %d",
|
2012-03-07 14:29:45 +00:00
|
|
|
|
c->main_lebs, UBIFS_MIN_MAIN_LEBS);
|
2008-07-14 16:08:37 +00:00
|
|
|
|
goto failed;
|
|
|
|
|
}
|
|
|
|
|
|
2012-03-07 14:29:45 +00:00
|
|
|
|
max_bytes = (long long)c->leb_size * UBIFS_MIN_BUD_LEBS;
|
|
|
|
|
if (c->max_bud_bytes < max_bytes) {
|
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, "too small journal (%lld bytes), must be at least %lld bytes",
|
2012-08-27 10:34:09 +00:00
|
|
|
|
c->max_bud_bytes, max_bytes);
|
2012-03-07 14:29:45 +00:00
|
|
|
|
goto failed;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
max_bytes = (long long)c->leb_size * c->main_lebs;
|
|
|
|
|
if (c->max_bud_bytes > max_bytes) {
|
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, "too large journal size (%lld bytes), only %lld bytes available in the main area",
|
2012-03-07 14:29:45 +00:00
|
|
|
|
c->max_bud_bytes, max_bytes);
|
2008-07-14 16:08:37 +00:00
|
|
|
|
goto failed;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (c->jhead_cnt < NONDATA_JHEADS_CNT + 1 ||
|
|
|
|
|
c->jhead_cnt > NONDATA_JHEADS_CNT + UBIFS_MAX_JHEADS) {
|
|
|
|
|
err = 9;
|
|
|
|
|
goto failed;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (c->fanout < UBIFS_MIN_FANOUT ||
|
|
|
|
|
ubifs_idx_node_sz(c, c->fanout) > c->leb_size) {
|
|
|
|
|
err = 10;
|
|
|
|
|
goto failed;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (c->lsave_cnt < 0 || (c->lsave_cnt > DEFAULT_LSAVE_CNT &&
|
|
|
|
|
c->lsave_cnt > c->max_leb_cnt - UBIFS_SB_LEBS - UBIFS_MST_LEBS -
|
|
|
|
|
c->log_lebs - c->lpt_lebs - c->orph_lebs)) {
|
|
|
|
|
err = 11;
|
|
|
|
|
goto failed;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (UBIFS_SB_LEBS + UBIFS_MST_LEBS + c->log_lebs + c->lpt_lebs +
|
|
|
|
|
c->orph_lebs + c->main_lebs != c->leb_cnt) {
|
|
|
|
|
err = 12;
|
|
|
|
|
goto failed;
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-11 02:42:52 +00:00
|
|
|
|
if (c->default_compr >= UBIFS_COMPR_TYPES_CNT) {
|
2008-07-14 16:08:37 +00:00
|
|
|
|
err = 13;
|
|
|
|
|
goto failed;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (c->rp_size < 0 || max_bytes < c->rp_size) {
|
|
|
|
|
err = 14;
|
|
|
|
|
goto failed;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (le32_to_cpu(sup->time_gran) > 1000000000 ||
|
|
|
|
|
le32_to_cpu(sup->time_gran) < 1) {
|
|
|
|
|
err = 15;
|
|
|
|
|
goto failed;
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-19 21:46:39 +00:00
|
|
|
|
if (!c->double_hash && c->fmt_version >= 5) {
|
|
|
|
|
err = 16;
|
|
|
|
|
goto failed;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (c->encrypted && c->fmt_version < 5) {
|
|
|
|
|
err = 17;
|
|
|
|
|
goto failed;
|
|
|
|
|
}
|
|
|
|
|
|
2008-07-14 16:08:37 +00:00
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
failed:
|
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, "bad superblock, error %d", err);
|
2012-05-16 16:15:56 +00:00
|
|
|
|
ubifs_dump_node(c, sup);
|
2008-07-14 16:08:37 +00:00
|
|
|
|
return -EINVAL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* ubifs_read_sb_node - read superblock node.
|
|
|
|
|
* @c: UBIFS file-system description object
|
|
|
|
|
*
|
|
|
|
|
* This function returns a pointer to the superblock node or a negative error
|
2011-05-06 14:08:56 +00:00
|
|
|
|
* code. Note, the user of this function is responsible of kfree()'ing the
|
|
|
|
|
* returned superblock buffer.
|
2008-07-14 16:08:37 +00:00
|
|
|
|
*/
|
2018-09-07 12:36:29 +00:00
|
|
|
|
static struct ubifs_sb_node *ubifs_read_sb_node(struct ubifs_info *c)
|
2008-07-14 16:08:37 +00:00
|
|
|
|
{
|
|
|
|
|
struct ubifs_sb_node *sup;
|
|
|
|
|
int err;
|
|
|
|
|
|
|
|
|
|
sup = kmalloc(ALIGN(UBIFS_SB_NODE_SZ, c->min_io_size), GFP_NOFS);
|
|
|
|
|
if (!sup)
|
|
|
|
|
return ERR_PTR(-ENOMEM);
|
|
|
|
|
|
|
|
|
|
err = ubifs_read_node(c, sup, UBIFS_SB_NODE, UBIFS_SB_NODE_SZ,
|
|
|
|
|
UBIFS_SB_LNUM, 0);
|
|
|
|
|
if (err) {
|
|
|
|
|
kfree(sup);
|
|
|
|
|
return ERR_PTR(err);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return sup;
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-07 12:36:42 +00:00
|
|
|
|
static int authenticate_sb_node(struct ubifs_info *c,
|
|
|
|
|
const struct ubifs_sb_node *sup)
|
|
|
|
|
{
|
|
|
|
|
unsigned int sup_flags = le32_to_cpu(sup->flags);
|
|
|
|
|
u8 hmac_wkm[UBIFS_HMAC_ARR_SZ];
|
|
|
|
|
int authenticated = !!(sup_flags & UBIFS_FLG_AUTHENTICATION);
|
|
|
|
|
int hash_algo;
|
|
|
|
|
int err;
|
|
|
|
|
|
|
|
|
|
if (c->authenticated && !authenticated) {
|
|
|
|
|
ubifs_err(c, "authenticated FS forced, but found FS without authentication");
|
|
|
|
|
return -EINVAL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!c->authenticated && authenticated) {
|
|
|
|
|
ubifs_err(c, "authenticated FS found, but no key given");
|
|
|
|
|
return -EINVAL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ubifs_msg(c, "Mounting in %sauthenticated mode",
|
|
|
|
|
c->authenticated ? "" : "un");
|
|
|
|
|
|
|
|
|
|
if (!c->authenticated)
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
if (!IS_ENABLED(CONFIG_UBIFS_FS_AUTHENTICATION))
|
|
|
|
|
return -EOPNOTSUPP;
|
|
|
|
|
|
|
|
|
|
hash_algo = le16_to_cpu(sup->hash_algo);
|
|
|
|
|
if (hash_algo >= HASH_ALGO__LAST) {
|
|
|
|
|
ubifs_err(c, "superblock uses unknown hash algo %d",
|
|
|
|
|
hash_algo);
|
|
|
|
|
return -EINVAL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (strcmp(hash_algo_name[hash_algo], c->auth_hash_name)) {
|
|
|
|
|
ubifs_err(c, "This filesystem uses %s for hashing,"
|
|
|
|
|
" but %s is specified", hash_algo_name[hash_algo],
|
|
|
|
|
c->auth_hash_name);
|
|
|
|
|
return -EINVAL;
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-14 08:33:22 +00:00
|
|
|
|
/*
|
|
|
|
|
* The super block node can either be authenticated by a HMAC or
|
|
|
|
|
* by a signature in a ubifs_sig_node directly following the
|
|
|
|
|
* super block node to support offline image creation.
|
|
|
|
|
*/
|
|
|
|
|
if (ubifs_hmac_zero(c, sup->hmac)) {
|
|
|
|
|
err = ubifs_sb_verify_signature(c, sup);
|
|
|
|
|
} else {
|
|
|
|
|
err = ubifs_hmac_wkm(c, hmac_wkm);
|
|
|
|
|
if (err)
|
|
|
|
|
return err;
|
|
|
|
|
if (ubifs_check_hmac(c, hmac_wkm, sup->hmac_wkm)) {
|
|
|
|
|
ubifs_err(c, "provided key does not fit");
|
|
|
|
|
return -ENOKEY;
|
|
|
|
|
}
|
|
|
|
|
err = ubifs_node_verify_hmac(c, sup, sizeof(*sup),
|
|
|
|
|
offsetof(struct ubifs_sb_node,
|
|
|
|
|
hmac));
|
2018-09-07 12:36:42 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (err)
|
|
|
|
|
ubifs_err(c, "Failed to authenticate superblock: %d", err);
|
|
|
|
|
|
|
|
|
|
return err;
|
|
|
|
|
}
|
|
|
|
|
|
2008-07-14 16:08:37 +00:00
|
|
|
|
/**
|
|
|
|
|
* ubifs_write_sb_node - write superblock node.
|
|
|
|
|
* @c: UBIFS file-system description object
|
|
|
|
|
* @sup: superblock node read with 'ubifs_read_sb_node()'
|
|
|
|
|
*
|
|
|
|
|
* This function returns %0 on success and a negative error code on failure.
|
|
|
|
|
*/
|
|
|
|
|
int ubifs_write_sb_node(struct ubifs_info *c, struct ubifs_sb_node *sup)
|
|
|
|
|
{
|
|
|
|
|
int len = ALIGN(UBIFS_SB_NODE_SZ, c->min_io_size);
|
2018-09-07 12:36:42 +00:00
|
|
|
|
int err;
|
|
|
|
|
|
|
|
|
|
err = ubifs_prepare_node_hmac(c, sup, UBIFS_SB_NODE_SZ,
|
|
|
|
|
offsetof(struct ubifs_sb_node, hmac), 1);
|
|
|
|
|
if (err)
|
|
|
|
|
return err;
|
2008-07-14 16:08:37 +00:00
|
|
|
|
|
2012-05-14 15:55:51 +00:00
|
|
|
|
return ubifs_leb_change(c, UBIFS_SB_LNUM, sup, len);
|
2008-07-14 16:08:37 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* ubifs_read_superblock - read superblock.
|
|
|
|
|
* @c: UBIFS file-system description object
|
|
|
|
|
*
|
|
|
|
|
* This function finds, reads and checks the superblock. If an empty UBI volume
|
|
|
|
|
* is being mounted, this function creates default superblock. Returns zero in
|
|
|
|
|
* case of success, and a negative error code in case of failure.
|
|
|
|
|
*/
|
|
|
|
|
int ubifs_read_superblock(struct ubifs_info *c)
|
|
|
|
|
{
|
|
|
|
|
int err, sup_flags;
|
|
|
|
|
struct ubifs_sb_node *sup;
|
|
|
|
|
|
|
|
|
|
if (c->empty) {
|
|
|
|
|
err = create_default_filesystem(c);
|
|
|
|
|
if (err)
|
|
|
|
|
return err;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sup = ubifs_read_sb_node(c);
|
|
|
|
|
if (IS_ERR(sup))
|
|
|
|
|
return PTR_ERR(sup);
|
|
|
|
|
|
2018-09-07 12:36:29 +00:00
|
|
|
|
c->sup_node = sup;
|
|
|
|
|
|
2009-03-26 10:51:21 +00:00
|
|
|
|
c->fmt_version = le32_to_cpu(sup->fmt_version);
|
|
|
|
|
c->ro_compat_version = le32_to_cpu(sup->ro_compat_version);
|
|
|
|
|
|
2008-07-14 16:08:37 +00:00
|
|
|
|
/*
|
|
|
|
|
* The software supports all previous versions but not future versions,
|
|
|
|
|
* due to the unavailability of time-travelling equipment.
|
|
|
|
|
*/
|
|
|
|
|
if (c->fmt_version > UBIFS_FORMAT_VERSION) {
|
2018-07-12 11:01:57 +00:00
|
|
|
|
ubifs_assert(c, !c->ro_media || c->ro_mount);
|
2010-09-19 15:34:26 +00:00
|
|
|
|
if (!c->ro_mount ||
|
2009-03-26 10:51:21 +00:00
|
|
|
|
c->ro_compat_version > UBIFS_RO_COMPAT_VERSION) {
|
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, "on-flash format version is w%d/r%d, but software only supports up to version w%d/r%d",
|
2012-08-27 10:34:09 +00:00
|
|
|
|
c->fmt_version, c->ro_compat_version,
|
|
|
|
|
UBIFS_FORMAT_VERSION,
|
2009-03-26 10:51:21 +00:00
|
|
|
|
UBIFS_RO_COMPAT_VERSION);
|
|
|
|
|
if (c->ro_compat_version <= UBIFS_RO_COMPAT_VERSION) {
|
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_msg(c, "only R/O mounting is possible");
|
2009-03-26 10:51:21 +00:00
|
|
|
|
err = -EROFS;
|
|
|
|
|
} else
|
|
|
|
|
err = -EINVAL;
|
|
|
|
|
goto out;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* The FS is mounted R/O, and the media format is
|
|
|
|
|
* R/O-compatible with the UBIFS implementation, so we can
|
|
|
|
|
* mount.
|
|
|
|
|
*/
|
|
|
|
|
c->rw_incompat = 1;
|
2008-07-14 16:08:37 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (c->fmt_version < 3) {
|
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, "on-flash format version %d is not supported",
|
2008-07-14 16:08:37 +00:00
|
|
|
|
c->fmt_version);
|
|
|
|
|
err = -EINVAL;
|
|
|
|
|
goto out;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch (sup->key_hash) {
|
|
|
|
|
case UBIFS_KEY_HASH_R5:
|
|
|
|
|
c->key_hash = key_r5_hash;
|
|
|
|
|
c->key_hash_type = UBIFS_KEY_HASH_R5;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case UBIFS_KEY_HASH_TEST:
|
|
|
|
|
c->key_hash = key_test_hash;
|
|
|
|
|
c->key_hash_type = UBIFS_KEY_HASH_TEST;
|
|
|
|
|
break;
|
2018-08-24 05:15:05 +00:00
|
|
|
|
}
|
2008-07-14 16:08:37 +00:00
|
|
|
|
|
|
|
|
|
c->key_fmt = sup->key_fmt;
|
|
|
|
|
|
|
|
|
|
switch (c->key_fmt) {
|
|
|
|
|
case UBIFS_SIMPLE_KEY_FMT:
|
|
|
|
|
c->key_len = UBIFS_SK_LEN;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
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, "unsupported key format");
|
2008-07-14 16:08:37 +00:00
|
|
|
|
err = -EINVAL;
|
|
|
|
|
goto out;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
c->leb_cnt = le32_to_cpu(sup->leb_cnt);
|
|
|
|
|
c->max_leb_cnt = le32_to_cpu(sup->max_leb_cnt);
|
|
|
|
|
c->max_bud_bytes = le64_to_cpu(sup->max_bud_bytes);
|
|
|
|
|
c->log_lebs = le32_to_cpu(sup->log_lebs);
|
|
|
|
|
c->lpt_lebs = le32_to_cpu(sup->lpt_lebs);
|
|
|
|
|
c->orph_lebs = le32_to_cpu(sup->orph_lebs);
|
|
|
|
|
c->jhead_cnt = le32_to_cpu(sup->jhead_cnt) + NONDATA_JHEADS_CNT;
|
|
|
|
|
c->fanout = le32_to_cpu(sup->fanout);
|
|
|
|
|
c->lsave_cnt = le32_to_cpu(sup->lsave_cnt);
|
|
|
|
|
c->rp_size = le64_to_cpu(sup->rp_size);
|
2012-02-07 23:50:56 +00:00
|
|
|
|
c->rp_uid = make_kuid(&init_user_ns, le32_to_cpu(sup->rp_uid));
|
|
|
|
|
c->rp_gid = make_kgid(&init_user_ns, le32_to_cpu(sup->rp_gid));
|
2008-07-14 16:08:37 +00:00
|
|
|
|
sup_flags = le32_to_cpu(sup->flags);
|
2008-11-01 12:57:49 +00:00
|
|
|
|
if (!c->mount_opts.override_compr)
|
|
|
|
|
c->default_compr = le16_to_cpu(sup->default_compr);
|
2008-07-14 16:08:37 +00:00
|
|
|
|
|
|
|
|
|
c->vfs_sb->s_time_gran = le32_to_cpu(sup->time_gran);
|
|
|
|
|
memcpy(&c->uuid, &sup->uuid, 16);
|
|
|
|
|
c->big_lpt = !!(sup_flags & UBIFS_FLG_BIGLPT);
|
2011-05-05 20:33:20 +00:00
|
|
|
|
c->space_fixup = !!(sup_flags & UBIFS_FLG_SPACE_FIXUP);
|
2016-10-19 13:59:12 +00:00
|
|
|
|
c->double_hash = !!(sup_flags & UBIFS_FLG_DOUBLE_HASH);
|
2016-10-19 21:24:47 +00:00
|
|
|
|
c->encrypted = !!(sup_flags & UBIFS_FLG_ENCRYPTION);
|
|
|
|
|
|
2018-09-07 12:36:42 +00:00
|
|
|
|
err = authenticate_sb_node(c, sup);
|
|
|
|
|
if (err)
|
|
|
|
|
goto out;
|
|
|
|
|
|
2016-10-19 21:46:39 +00:00
|
|
|
|
if ((sup_flags & ~UBIFS_FLG_MASK) != 0) {
|
|
|
|
|
ubifs_err(c, "Unknown feature flags found: %#x",
|
|
|
|
|
sup_flags & ~UBIFS_FLG_MASK);
|
|
|
|
|
err = -EINVAL;
|
|
|
|
|
goto out;
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-14 19:10:49 +00:00
|
|
|
|
if (!IS_ENABLED(CONFIG_FS_ENCRYPTION) && c->encrypted) {
|
2016-10-19 21:24:47 +00:00
|
|
|
|
ubifs_err(c, "file system contains encrypted files but UBIFS"
|
|
|
|
|
" was built without crypto support.");
|
|
|
|
|
err = -EINVAL;
|
|
|
|
|
goto out;
|
|
|
|
|
}
|
2008-07-14 16:08:37 +00:00
|
|
|
|
|
|
|
|
|
/* Automatically increase file system size to the maximum size */
|
|
|
|
|
if (c->leb_cnt < c->vi.size && c->leb_cnt < c->max_leb_cnt) {
|
2019-05-14 08:33:22 +00:00
|
|
|
|
int old_leb_cnt = c->leb_cnt;
|
|
|
|
|
|
2008-07-14 16:08:37 +00:00
|
|
|
|
c->leb_cnt = min_t(int, c->max_leb_cnt, c->vi.size);
|
2019-05-14 08:33:22 +00:00
|
|
|
|
sup->leb_cnt = cpu_to_le32(c->leb_cnt);
|
|
|
|
|
|
|
|
|
|
c->superblock_need_write = 1;
|
|
|
|
|
|
|
|
|
|
dbg_mnt("Auto resizing from %d LEBs to %d LEBs",
|
|
|
|
|
old_leb_cnt, c->leb_cnt);
|
2008-07-14 16:08:37 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
c->log_bytes = (long long)c->log_lebs * c->leb_size;
|
|
|
|
|
c->log_last = UBIFS_LOG_LNUM + c->log_lebs - 1;
|
|
|
|
|
c->lpt_first = UBIFS_LOG_LNUM + c->log_lebs;
|
|
|
|
|
c->lpt_last = c->lpt_first + c->lpt_lebs - 1;
|
|
|
|
|
c->orph_first = c->lpt_last + 1;
|
|
|
|
|
c->orph_last = c->orph_first + c->orph_lebs - 1;
|
|
|
|
|
c->main_lebs = c->leb_cnt - UBIFS_SB_LEBS - UBIFS_MST_LEBS;
|
|
|
|
|
c->main_lebs -= c->log_lebs + c->lpt_lebs + c->orph_lebs;
|
|
|
|
|
c->main_first = c->leb_cnt - c->main_lebs;
|
|
|
|
|
|
|
|
|
|
err = validate_sb(c, sup);
|
|
|
|
|
out:
|
|
|
|
|
return err;
|
|
|
|
|
}
|
2011-05-06 22:58:22 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* fixup_leb - fixup/unmap an LEB containing free space.
|
|
|
|
|
* @c: UBIFS file-system description object
|
|
|
|
|
* @lnum: the LEB number to fix up
|
|
|
|
|
* @len: number of used bytes in LEB (starting at offset 0)
|
|
|
|
|
*
|
|
|
|
|
* This function reads the contents of the given LEB number @lnum, then fixes
|
|
|
|
|
* it up, so that empty min. I/O units in the end of LEB are actually erased on
|
|
|
|
|
* flash (rather than being just all-0xff real data). If the LEB is completely
|
|
|
|
|
* empty, it is simply unmapped.
|
|
|
|
|
*/
|
|
|
|
|
static int fixup_leb(struct ubifs_info *c, int lnum, int len)
|
|
|
|
|
{
|
|
|
|
|
int err;
|
|
|
|
|
|
2018-07-12 11:01:57 +00:00
|
|
|
|
ubifs_assert(c, len >= 0);
|
|
|
|
|
ubifs_assert(c, len % c->min_io_size == 0);
|
|
|
|
|
ubifs_assert(c, len < c->leb_size);
|
2011-05-06 22:58:22 +00:00
|
|
|
|
|
|
|
|
|
if (len == 0) {
|
|
|
|
|
dbg_mnt("unmap empty LEB %d", lnum);
|
2011-06-03 11:22:05 +00:00
|
|
|
|
return ubifs_leb_unmap(c, lnum);
|
2011-05-06 22:58:22 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
dbg_mnt("fixup LEB %d, data len %d", lnum, len);
|
2011-06-03 11:03:25 +00:00
|
|
|
|
err = ubifs_leb_read(c, lnum, c->sbuf, 0, len, 1);
|
2011-05-06 22:58:22 +00:00
|
|
|
|
if (err)
|
|
|
|
|
return err;
|
|
|
|
|
|
2012-05-14 15:55:51 +00:00
|
|
|
|
return ubifs_leb_change(c, lnum, c->sbuf, len);
|
2011-05-06 22:58:22 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* fixup_free_space - find & remap all LEBs containing free space.
|
|
|
|
|
* @c: UBIFS file-system description object
|
|
|
|
|
*
|
|
|
|
|
* This function walks through all LEBs in the filesystem and fiexes up those
|
|
|
|
|
* containing free/empty space.
|
|
|
|
|
*/
|
|
|
|
|
static int fixup_free_space(struct ubifs_info *c)
|
|
|
|
|
{
|
|
|
|
|
int lnum, err = 0;
|
|
|
|
|
struct ubifs_lprops *lprops;
|
|
|
|
|
|
|
|
|
|
ubifs_get_lprops(c);
|
|
|
|
|
|
|
|
|
|
/* Fixup LEBs in the master area */
|
|
|
|
|
for (lnum = UBIFS_MST_LNUM; lnum < UBIFS_LOG_LNUM; lnum++) {
|
|
|
|
|
err = fixup_leb(c, lnum, c->mst_offs + c->mst_node_alsz);
|
|
|
|
|
if (err)
|
|
|
|
|
goto out;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Unmap unused log LEBs */
|
|
|
|
|
lnum = ubifs_next_log_lnum(c, c->lhead_lnum);
|
|
|
|
|
while (lnum != c->ltail_lnum) {
|
|
|
|
|
err = fixup_leb(c, lnum, 0);
|
|
|
|
|
if (err)
|
|
|
|
|
goto out;
|
|
|
|
|
lnum = ubifs_next_log_lnum(c, lnum);
|
|
|
|
|
}
|
|
|
|
|
|
2012-07-14 11:33:09 +00:00
|
|
|
|
/*
|
|
|
|
|
* Fixup the log head which contains the only a CS node at the
|
|
|
|
|
* beginning.
|
|
|
|
|
*/
|
|
|
|
|
err = fixup_leb(c, c->lhead_lnum,
|
|
|
|
|
ALIGN(UBIFS_CS_NODE_SZ, c->min_io_size));
|
2011-05-06 22:58:22 +00:00
|
|
|
|
if (err)
|
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
|
|
/* Fixup LEBs in the LPT area */
|
|
|
|
|
for (lnum = c->lpt_first; lnum <= c->lpt_last; lnum++) {
|
|
|
|
|
int free = c->ltab[lnum - c->lpt_first].free;
|
|
|
|
|
|
|
|
|
|
if (free > 0) {
|
|
|
|
|
err = fixup_leb(c, lnum, c->leb_size - free);
|
|
|
|
|
if (err)
|
|
|
|
|
goto out;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Unmap LEBs in the orphans area */
|
|
|
|
|
for (lnum = c->orph_first; lnum <= c->orph_last; lnum++) {
|
|
|
|
|
err = fixup_leb(c, lnum, 0);
|
|
|
|
|
if (err)
|
|
|
|
|
goto out;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Fixup LEBs in the main area */
|
|
|
|
|
for (lnum = c->main_first; lnum < c->leb_cnt; lnum++) {
|
|
|
|
|
lprops = ubifs_lpt_lookup(c, lnum);
|
|
|
|
|
if (IS_ERR(lprops)) {
|
|
|
|
|
err = PTR_ERR(lprops);
|
|
|
|
|
goto out;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (lprops->free > 0) {
|
|
|
|
|
err = fixup_leb(c, lnum, c->leb_size - lprops->free);
|
|
|
|
|
if (err)
|
|
|
|
|
goto out;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
out:
|
|
|
|
|
ubifs_release_lprops(c);
|
|
|
|
|
return err;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* ubifs_fixup_free_space - find & fix all LEBs with free space.
|
|
|
|
|
* @c: UBIFS file-system description object
|
|
|
|
|
*
|
|
|
|
|
* This function fixes up LEBs containing free space on first mount, if the
|
|
|
|
|
* appropriate flag was set when the FS was created. Each LEB with one or more
|
|
|
|
|
* empty min. I/O unit (i.e. free-space-count > 0) is re-written, to make sure
|
|
|
|
|
* the free space is actually erased. E.g., this is necessary for some NAND
|
|
|
|
|
* chips, since the free space may have been programmed like real "0xff" data
|
|
|
|
|
* (generating a non-0xff ECC), causing future writes to the not-really-erased
|
|
|
|
|
* NAND pages to behave badly. After the space is fixed up, the superblock flag
|
|
|
|
|
* is cleared, so that this is skipped for all future mounts.
|
|
|
|
|
*/
|
|
|
|
|
int ubifs_fixup_free_space(struct ubifs_info *c)
|
|
|
|
|
{
|
|
|
|
|
int err;
|
2018-09-07 12:36:29 +00:00
|
|
|
|
struct ubifs_sb_node *sup = c->sup_node;
|
2011-05-06 22:58:22 +00:00
|
|
|
|
|
2018-07-12 11:01:57 +00:00
|
|
|
|
ubifs_assert(c, c->space_fixup);
|
|
|
|
|
ubifs_assert(c, !c->ro_mount);
|
2011-05-06 22:58:22 +00:00
|
|
|
|
|
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_msg(c, "start fixing up free space");
|
2011-05-06 22:58:22 +00:00
|
|
|
|
|
|
|
|
|
err = fixup_free_space(c);
|
|
|
|
|
if (err)
|
|
|
|
|
return err;
|
|
|
|
|
|
|
|
|
|
/* Free-space fixup is no longer required */
|
|
|
|
|
c->space_fixup = 0;
|
|
|
|
|
sup->flags &= cpu_to_le32(~UBIFS_FLG_SPACE_FIXUP);
|
|
|
|
|
|
2019-05-14 08:33:22 +00:00
|
|
|
|
c->superblock_need_write = 1;
|
2011-05-06 22:58:22 +00:00
|
|
|
|
|
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_msg(c, "free space fixup complete");
|
2011-05-06 22:58:22 +00:00
|
|
|
|
return err;
|
|
|
|
|
}
|
2016-10-19 21:24:47 +00:00
|
|
|
|
|
|
|
|
|
int ubifs_enable_encryption(struct ubifs_info *c)
|
|
|
|
|
{
|
|
|
|
|
int err;
|
2018-09-07 12:36:29 +00:00
|
|
|
|
struct ubifs_sb_node *sup = c->sup_node;
|
2016-10-19 21:24:47 +00:00
|
|
|
|
|
2019-05-14 19:10:49 +00:00
|
|
|
|
if (!IS_ENABLED(CONFIG_FS_ENCRYPTION))
|
2019-03-26 07:52:31 +00:00
|
|
|
|
return -EOPNOTSUPP;
|
|
|
|
|
|
2016-10-19 21:24:47 +00:00
|
|
|
|
if (c->encrypted)
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
if (c->ro_mount || c->ro_media)
|
|
|
|
|
return -EROFS;
|
|
|
|
|
|
|
|
|
|
if (c->fmt_version < 5) {
|
|
|
|
|
ubifs_err(c, "on-flash format version 5 is needed for encryption");
|
|
|
|
|
return -EINVAL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sup->flags |= cpu_to_le32(UBIFS_FLG_ENCRYPTION);
|
|
|
|
|
|
|
|
|
|
err = ubifs_write_sb_node(c, sup);
|
|
|
|
|
if (!err)
|
|
|
|
|
c->encrypted = 1;
|
|
|
|
|
|
|
|
|
|
return err;
|
|
|
|
|
}
|