30 #include <linux/slab.h>
31 #include <linux/random.h>
38 #define DEFAULT_JNL_PERCENT 5
41 #define DEFAULT_MAX_JNL (32*1024*1024)
44 #define DEFAULT_FANOUT 8
47 #define DEFAULT_JHEADS_CNT 1
50 #define DEFAULT_IDX_LEB 0
51 #define DEFAULT_DATA_LEB 1
52 #define DEFAULT_GC_LEB 2
55 #define DEFAULT_LSAVE_CNT 256
58 #define DEFAULT_RP_PERCENT 5
61 #define DEFAULT_MAX_RP_SIZE (5*1024*1024)
64 #define DEFAULT_TIME_GRAN 1000000000
73 static int create_default_filesystem(
struct ubifs_info *
c)
82 int err,
tmp, jnl_lebs, log_lebs, max_buds, main_lebs, main_first;
83 int lpt_lebs, lpt_first, orph_lebs, big_lpt, ino_waste, sup_flags = 0;
85 long long tmp64, main_bytes;
122 max_buds = jnl_lebs - log_lebs;
133 if (c->
leb_cnt - min_leb_cnt > 1)
142 main_lebs -= orph_lebs;
152 dbg_gen(
"LEB Properties Tree created (LEBs %d-%d)", lpt_first,
153 lpt_first + lpt_lebs - 1);
155 main_first = c->
leb_cnt - main_lebs;
202 dbg_gen(
"default superblock created at LEB 0:0");
215 tmp = ubifs_idx_node_sz(c, 1);
244 tmp64 -=
ALIGN(ubifs_idx_node_sz(c, 1), 8);
267 tmp = ubifs_idx_node_sz(c, 1);
278 br = ubifs_idx_branch(c, idx, 0);
279 key_write_idx(c, &key, &br->
key);
287 dbg_gen(
"default root indexing node created LEB %d:0",
319 dbg_gen(
"root inode created at LEB %d:0",
336 ubifs_msg(
"default file-system created");
353 int err = 1, min_leb_cnt;
366 ubifs_err(
"min. I/O unit mismatch: %d in superblock, %d real",
372 ubifs_err(
"LEB size mismatch: %d in superblock, %d real",
394 ubifs_err(
"bad LEB count: %d in superblock, %d on UBI volume, %d minimum required",
400 ubifs_err(
"max. LEB count %d less than LEB count %d",
406 ubifs_err(
"too few main LEBs count %d, must be at least %d",
413 ubifs_err(
"too small journal (%lld bytes), must be at least %lld bytes",
420 ubifs_err(
"too large journal size (%lld bytes), only %lld bytes available in the main area",
455 if (c->
rp_size < 0 || max_bytes < c->rp_size) {
469 ubifs_err(
"bad superblock, error %d", err);
530 err = create_default_filesystem(c);
550 ubifs_err(
"on-flash format version is w%d/r%d, but software only supports up to version w%d/r%d",
555 ubifs_msg(
"only R/O mounting is possible");
571 ubifs_err(
"on-flash format version %d is not supported",
627 dbg_mnt(
"Auto resizing (ro) from %d LEBs to %d LEBs",
630 dbg_mnt(
"Auto resizing (sb) from %d LEBs to %d LEBs",
650 err = validate_sb(c, sup);
667 static int fixup_leb(
struct ubifs_info *c,
int lnum,
int len)
676 dbg_mnt(
"unmap empty LEB %d", lnum);
680 dbg_mnt(
"fixup LEB %d, data len %d", lnum, len);
695 static int fixup_free_space(
struct ubifs_info *c)
712 err = fixup_leb(c, lnum, 0);
715 lnum = ubifs_next_log_lnum(c, lnum);
728 for (lnum = c->
lpt_first; lnum <= c->lpt_last; lnum++) {
732 err = fixup_leb(c, lnum, c->
leb_size - free);
739 for (lnum = c->
orph_first; lnum <= c->orph_last; lnum++) {
740 err = fixup_leb(c, lnum, 0);
746 for (lnum = c->
main_first; lnum < c->leb_cnt; lnum++) {
748 if (IS_ERR(lprops)) {
749 err = PTR_ERR(lprops);
753 if (lprops->
free > 0) {
761 ubifs_release_lprops(c);
788 err = fixup_free_space(c);