Lines Matching +full:1 +full:br +full:- +full:100
1 // SPDX-License-Identifier: GPL-2.0-only
5 * Copyright (C) 2006-2008 Nokia Corporation.
13 * LEB of the volume and is never changed by UBIFS. Only user-space tools may
35 #define DEFAULT_JHEADS_CNT 1
39 #define DEFAULT_DATA_LEB 1
69 * create_default_filesystem - format empty UBI volume.
70 * @c: UBIFS file-system description object
72 * This function creates default empty file-system. Returns zero in case of
80 struct ubifs_branch *br; in create_default_filesystem() local
94 /* Some functions called from here depend on the @c->key_len filed */ in create_default_filesystem()
95 c->key_len = UBIFS_SK_LEN; in create_default_filesystem()
98 * First of all, we have to calculate default file-system geometry - in create_default_filesystem()
101 if (c->leb_cnt < 0x7FFFFFFF / DEFAULT_JNL_PERCENT) in create_default_filesystem()
103 jnl_lebs = c->leb_cnt * DEFAULT_JNL_PERCENT / 100; in create_default_filesystem()
105 jnl_lebs = (c->leb_cnt / 100) * DEFAULT_JNL_PERCENT; in create_default_filesystem()
109 if (jnl_lebs * c->leb_size > DEFAULT_MAX_JNL) in create_default_filesystem()
110 jnl_lebs = DEFAULT_MAX_JNL / c->leb_size; in create_default_filesystem()
118 tmp = 2 * (c->ref_node_alsz * jnl_lebs) + c->leb_size - 1; in create_default_filesystem()
119 log_lebs = tmp / c->leb_size; in create_default_filesystem()
121 log_lebs += 1; in create_default_filesystem()
122 if (c->leb_cnt - min_leb_cnt > 8) { in create_default_filesystem()
124 log_lebs += 1; in create_default_filesystem()
125 min_leb_cnt += 1; in create_default_filesystem()
128 max_buds = jnl_lebs - log_lebs; in create_default_filesystem()
139 if (c->leb_cnt - min_leb_cnt > 1) in create_default_filesystem()
145 orph_lebs += 1; in create_default_filesystem()
147 main_lebs = c->leb_cnt - UBIFS_SB_LEBS - UBIFS_MST_LEBS - log_lebs; in create_default_filesystem()
148 main_lebs -= orph_lebs; in create_default_filesystem()
151 c->lsave_cnt = DEFAULT_LSAVE_CNT; in create_default_filesystem()
152 c->max_leb_cnt = c->leb_cnt; in create_default_filesystem()
158 dbg_gen("LEB Properties Tree created (LEBs %d-%d)", lpt_first, in create_default_filesystem()
159 lpt_first + lpt_lebs - 1); in create_default_filesystem()
161 main_first = c->leb_cnt - main_lebs; in create_default_filesystem()
163 sup = kzalloc(ALIGN(UBIFS_SB_NODE_SZ, c->min_io_size), GFP_KERNEL); in create_default_filesystem()
164 mst = kzalloc(c->mst_node_alsz, GFP_KERNEL); in create_default_filesystem()
165 idx_node_size = ubifs_idx_node_sz(c, 1); in create_default_filesystem()
166 idx = kzalloc(ALIGN(idx_node_size, c->min_io_size), GFP_KERNEL); in create_default_filesystem()
167 ino = kzalloc(ALIGN(UBIFS_INO_NODE_SZ, c->min_io_size), GFP_KERNEL); in create_default_filesystem()
168 cs = kzalloc(ALIGN(UBIFS_CS_NODE_SZ, c->min_io_size), GFP_KERNEL); in create_default_filesystem()
171 err = -ENOMEM; in create_default_filesystem()
177 tmp64 = (long long)max_buds * c->leb_size; in create_default_filesystem()
185 sup->hash_algo = cpu_to_le16(c->auth_hash_algo); in create_default_filesystem()
186 err = ubifs_hmac_wkm(c, sup->hmac_wkm); in create_default_filesystem()
190 sup->hash_algo = cpu_to_le16(0xffff); in create_default_filesystem()
193 sup->ch.node_type = UBIFS_SB_NODE; in create_default_filesystem()
194 sup->key_hash = UBIFS_KEY_HASH_R5; in create_default_filesystem()
195 sup->flags = cpu_to_le32(sup_flags); in create_default_filesystem()
196 sup->min_io_size = cpu_to_le32(c->min_io_size); in create_default_filesystem()
197 sup->leb_size = cpu_to_le32(c->leb_size); in create_default_filesystem()
198 sup->leb_cnt = cpu_to_le32(c->leb_cnt); in create_default_filesystem()
199 sup->max_leb_cnt = cpu_to_le32(c->max_leb_cnt); in create_default_filesystem()
200 sup->max_bud_bytes = cpu_to_le64(tmp64); in create_default_filesystem()
201 sup->log_lebs = cpu_to_le32(log_lebs); in create_default_filesystem()
202 sup->lpt_lebs = cpu_to_le32(lpt_lebs); in create_default_filesystem()
203 sup->orph_lebs = cpu_to_le32(orph_lebs); in create_default_filesystem()
204 sup->jhead_cnt = cpu_to_le32(DEFAULT_JHEADS_CNT); in create_default_filesystem()
205 sup->fanout = cpu_to_le32(DEFAULT_FANOUT); in create_default_filesystem()
206 sup->lsave_cnt = cpu_to_le32(c->lsave_cnt); in create_default_filesystem()
207 sup->fmt_version = cpu_to_le32(ubifs_default_version); in create_default_filesystem()
208 sup->time_gran = cpu_to_le32(DEFAULT_TIME_GRAN); in create_default_filesystem()
209 if (c->mount_opts.override_compr) in create_default_filesystem()
210 sup->default_compr = cpu_to_le16(c->mount_opts.compr_type); in create_default_filesystem()
212 sup->default_compr = cpu_to_le16(get_default_compressor(c)); in create_default_filesystem()
214 generate_random_uuid(sup->uuid); in create_default_filesystem()
216 main_bytes = (long long)main_lebs * c->leb_size; in create_default_filesystem()
217 tmp64 = div_u64(main_bytes * DEFAULT_RP_PERCENT, 100); in create_default_filesystem()
220 sup->rp_size = cpu_to_le64(tmp64); in create_default_filesystem()
221 sup->ro_compat_version = cpu_to_le32(UBIFS_RO_COMPAT_VERSION); in create_default_filesystem()
227 mst->ch.node_type = UBIFS_MST_NODE; in create_default_filesystem()
228 mst->log_lnum = cpu_to_le32(UBIFS_LOG_LNUM); in create_default_filesystem()
229 mst->highest_inum = cpu_to_le64(UBIFS_FIRST_INO); in create_default_filesystem()
230 mst->cmt_no = 0; in create_default_filesystem()
231 mst->root_lnum = cpu_to_le32(main_first + DEFAULT_IDX_LEB); in create_default_filesystem()
232 mst->root_offs = 0; in create_default_filesystem()
233 tmp = ubifs_idx_node_sz(c, 1); in create_default_filesystem()
234 mst->root_len = cpu_to_le32(tmp); in create_default_filesystem()
235 mst->gc_lnum = cpu_to_le32(main_first + DEFAULT_GC_LEB); in create_default_filesystem()
236 mst->ihead_lnum = cpu_to_le32(main_first + DEFAULT_IDX_LEB); in create_default_filesystem()
237 mst->ihead_offs = cpu_to_le32(ALIGN(tmp, c->min_io_size)); in create_default_filesystem()
238 mst->index_size = cpu_to_le64(ALIGN(tmp, 8)); in create_default_filesystem()
239 mst->lpt_lnum = cpu_to_le32(c->lpt_lnum); in create_default_filesystem()
240 mst->lpt_offs = cpu_to_le32(c->lpt_offs); in create_default_filesystem()
241 mst->nhead_lnum = cpu_to_le32(c->nhead_lnum); in create_default_filesystem()
242 mst->nhead_offs = cpu_to_le32(c->nhead_offs); in create_default_filesystem()
243 mst->ltab_lnum = cpu_to_le32(c->ltab_lnum); in create_default_filesystem()
244 mst->ltab_offs = cpu_to_le32(c->ltab_offs); in create_default_filesystem()
245 mst->lsave_lnum = cpu_to_le32(c->lsave_lnum); in create_default_filesystem()
246 mst->lsave_offs = cpu_to_le32(c->lsave_offs); in create_default_filesystem()
247 mst->lscan_lnum = cpu_to_le32(main_first); in create_default_filesystem()
248 mst->empty_lebs = cpu_to_le32(main_lebs - 2); in create_default_filesystem()
249 mst->idx_lebs = cpu_to_le32(1); in create_default_filesystem()
250 mst->leb_cnt = cpu_to_le32(c->leb_cnt); in create_default_filesystem()
251 ubifs_copy_hash(c, hash_lpt, mst->hash_lpt); in create_default_filesystem()
255 tmp64 -= ALIGN(ubifs_idx_node_sz(c, 1), c->min_io_size); in create_default_filesystem()
256 tmp64 -= ALIGN(UBIFS_INO_NODE_SZ, c->min_io_size); in create_default_filesystem()
257 mst->total_free = cpu_to_le64(tmp64); in create_default_filesystem()
259 tmp64 = ALIGN(ubifs_idx_node_sz(c, 1), c->min_io_size); in create_default_filesystem()
260 ino_waste = ALIGN(UBIFS_INO_NODE_SZ, c->min_io_size) - in create_default_filesystem()
263 tmp64 -= ALIGN(ubifs_idx_node_sz(c, 1), 8); in create_default_filesystem()
264 mst->total_dirty = cpu_to_le64(tmp64); in create_default_filesystem()
267 tmp64 = ((long long)(c->main_lebs - 1) * c->dark_wm); in create_default_filesystem()
268 mst->total_dark = cpu_to_le64(tmp64); in create_default_filesystem()
270 mst->total_used = cpu_to_le64(UBIFS_INO_NODE_SZ); in create_default_filesystem()
276 c->key_fmt = UBIFS_SIMPLE_KEY_FMT; in create_default_filesystem()
277 c->key_hash = key_r5_hash; in create_default_filesystem()
279 idx->ch.node_type = UBIFS_IDX_NODE; in create_default_filesystem()
280 idx->child_cnt = cpu_to_le16(1); in create_default_filesystem()
282 br = ubifs_idx_branch(c, idx, 0); in create_default_filesystem()
283 key_write_idx(c, &key, &br->key); in create_default_filesystem()
284 br->lnum = cpu_to_le32(main_first + DEFAULT_DATA_LEB); in create_default_filesystem()
285 br->len = cpu_to_le32(UBIFS_INO_NODE_SZ); in create_default_filesystem()
292 ino_key_init_flash(c, &ino->key, UBIFS_ROOT_INO); in create_default_filesystem()
293 ino->ch.node_type = UBIFS_INO_NODE; in create_default_filesystem()
294 ino->creat_sqnum = cpu_to_le64(++c->max_sqnum); in create_default_filesystem()
295 ino->nlink = cpu_to_le32(2); in create_default_filesystem()
299 ino->atime_sec = tmp_le64; in create_default_filesystem()
300 ino->ctime_sec = tmp_le64; in create_default_filesystem()
301 ino->mtime_sec = tmp_le64; in create_default_filesystem()
302 ino->atime_nsec = 0; in create_default_filesystem()
303 ino->ctime_nsec = 0; in create_default_filesystem()
304 ino->mtime_nsec = 0; in create_default_filesystem()
305 ino->mode = cpu_to_le32(S_IFDIR | S_IRUGO | S_IWUSR | S_IXUGO); in create_default_filesystem()
306 ino->size = cpu_to_le64(UBIFS_INO_NODE_SZ); in create_default_filesystem()
309 ino->flags = cpu_to_le32(UBIFS_COMPR_FL); in create_default_filesystem()
316 * always the case during normal file-system operation. Write a fake in create_default_filesystem()
320 cs->ch.node_type = UBIFS_CS_NODE; in create_default_filesystem()
333 ubifs_copy_hash(c, hash, ubifs_branch_hash(c, br)); in create_default_filesystem()
340 ubifs_copy_hash(c, hash, mst->hash_root_idx); in create_default_filesystem()
347 err = ubifs_write_node_hmac(c, mst, UBIFS_MST_NODE_SZ, UBIFS_MST_LNUM + 1, in create_default_filesystem()
356 ubifs_msg(c, "default file-system created"); in create_default_filesystem()
370 * validate_sb - validate superblock node.
371 * @c: UBIFS file-system description object
376 * instead. Returns zero in case of success and %-EINVAL in case of validation
382 int err = 1, min_leb_cnt; in validate_sb()
384 if (!c->key_hash) { in validate_sb()
389 if (sup->key_fmt != UBIFS_SIMPLE_KEY_FMT) { in validate_sb()
394 if (le32_to_cpu(sup->min_io_size) != c->min_io_size) { in validate_sb()
396 le32_to_cpu(sup->min_io_size), c->min_io_size); in validate_sb()
400 if (le32_to_cpu(sup->leb_size) != c->leb_size) { in validate_sb()
402 le32_to_cpu(sup->leb_size), c->leb_size); in validate_sb()
406 if (c->log_lebs < UBIFS_MIN_LOG_LEBS || in validate_sb()
407 c->lpt_lebs < UBIFS_MIN_LPT_LEBS || in validate_sb()
408 c->orph_lebs < UBIFS_MIN_ORPH_LEBS || in validate_sb()
409 c->main_lebs < UBIFS_MIN_MAIN_LEBS) { in validate_sb()
419 min_leb_cnt = UBIFS_SB_LEBS + UBIFS_MST_LEBS + c->log_lebs; in validate_sb()
420 min_leb_cnt += c->lpt_lebs + c->orph_lebs + c->jhead_cnt + 6; in validate_sb()
422 if (c->leb_cnt < min_leb_cnt || c->leb_cnt > c->vi.size) { in validate_sb()
424 c->leb_cnt, c->vi.size, min_leb_cnt); in validate_sb()
428 if (c->max_leb_cnt < c->leb_cnt) { in validate_sb()
430 c->max_leb_cnt, c->leb_cnt); in validate_sb()
434 if (c->main_lebs < UBIFS_MIN_MAIN_LEBS) { in validate_sb()
436 c->main_lebs, UBIFS_MIN_MAIN_LEBS); in validate_sb()
440 max_bytes = (long long)c->leb_size * UBIFS_MIN_BUD_LEBS; in validate_sb()
441 if (c->max_bud_bytes < max_bytes) { in validate_sb()
443 c->max_bud_bytes, max_bytes); in validate_sb()
447 max_bytes = (long long)c->leb_size * c->main_lebs; in validate_sb()
448 if (c->max_bud_bytes > max_bytes) { in validate_sb()
450 c->max_bud_bytes, max_bytes); in validate_sb()
454 if (c->jhead_cnt < NONDATA_JHEADS_CNT + 1 || in validate_sb()
455 c->jhead_cnt > NONDATA_JHEADS_CNT + UBIFS_MAX_JHEADS) { in validate_sb()
460 if (c->fanout < UBIFS_MIN_FANOUT || in validate_sb()
461 ubifs_idx_node_sz(c, c->fanout) > c->leb_size) { in validate_sb()
466 if (c->lsave_cnt < 0 || (c->lsave_cnt > DEFAULT_LSAVE_CNT && in validate_sb()
467 c->lsave_cnt > c->max_leb_cnt - UBIFS_SB_LEBS - UBIFS_MST_LEBS - in validate_sb()
468 c->log_lebs - c->lpt_lebs - c->orph_lebs)) { in validate_sb()
473 if (UBIFS_SB_LEBS + UBIFS_MST_LEBS + c->log_lebs + c->lpt_lebs + in validate_sb()
474 c->orph_lebs + c->main_lebs != c->leb_cnt) { in validate_sb()
479 if (c->default_compr >= UBIFS_COMPR_TYPES_CNT) { in validate_sb()
484 if (c->rp_size < 0 || max_bytes < c->rp_size) { in validate_sb()
489 if (le32_to_cpu(sup->time_gran) > 1000000000 || in validate_sb()
490 le32_to_cpu(sup->time_gran) < 1) { in validate_sb()
495 if (!c->double_hash && c->fmt_version >= 5) { in validate_sb()
500 if (c->encrypted && c->fmt_version < 5) { in validate_sb()
509 ubifs_dump_node(c, sup, ALIGN(UBIFS_SB_NODE_SZ, c->min_io_size)); in validate_sb()
510 return -EINVAL; in validate_sb()
514 * ubifs_read_sb_node - read superblock node.
515 * @c: UBIFS file-system description object
526 sup = kmalloc(ALIGN(UBIFS_SB_NODE_SZ, c->min_io_size), GFP_NOFS); in ubifs_read_sb_node()
528 return ERR_PTR(-ENOMEM); in ubifs_read_sb_node()
543 unsigned int sup_flags = le32_to_cpu(sup->flags); in authenticate_sb_node()
549 if (c->authenticated && !authenticated) { in authenticate_sb_node()
551 return -EINVAL; in authenticate_sb_node()
554 if (!c->authenticated && authenticated) { in authenticate_sb_node()
556 return -EINVAL; in authenticate_sb_node()
560 c->authenticated ? "" : "un"); in authenticate_sb_node()
562 if (!c->authenticated) in authenticate_sb_node()
566 return -EOPNOTSUPP; in authenticate_sb_node()
568 hash_algo = le16_to_cpu(sup->hash_algo); in authenticate_sb_node()
572 return -EINVAL; in authenticate_sb_node()
575 if (strcmp(hash_algo_name[hash_algo], c->auth_hash_name)) { in authenticate_sb_node()
578 c->auth_hash_name); in authenticate_sb_node()
579 return -EINVAL; in authenticate_sb_node()
587 if (ubifs_hmac_zero(c, sup->hmac)) { in authenticate_sb_node()
593 if (ubifs_check_hmac(c, hmac_wkm, sup->hmac_wkm)) { in authenticate_sb_node()
595 return -ENOKEY; in authenticate_sb_node()
609 * ubifs_write_sb_node - write superblock node.
610 * @c: UBIFS file-system description object
617 int len = ALIGN(UBIFS_SB_NODE_SZ, c->min_io_size); in ubifs_write_sb_node()
621 offsetof(struct ubifs_sb_node, hmac), 1); in ubifs_write_sb_node()
629 * ubifs_read_superblock - read superblock.
630 * @c: UBIFS file-system description object
641 if (c->empty) { in ubifs_read_superblock()
651 c->sup_node = sup; in ubifs_read_superblock()
653 c->fmt_version = le32_to_cpu(sup->fmt_version); in ubifs_read_superblock()
654 c->ro_compat_version = le32_to_cpu(sup->ro_compat_version); in ubifs_read_superblock()
658 * due to the unavailability of time-travelling equipment. in ubifs_read_superblock()
660 if (c->fmt_version > UBIFS_FORMAT_VERSION) { in ubifs_read_superblock()
661 ubifs_assert(c, !c->ro_media || c->ro_mount); in ubifs_read_superblock()
662 if (!c->ro_mount || in ubifs_read_superblock()
663 c->ro_compat_version > UBIFS_RO_COMPAT_VERSION) { in ubifs_read_superblock()
664 …ubifs_err(c, "on-flash format version is w%d/r%d, but software only supports up to version w%d/r%d… in ubifs_read_superblock()
665 c->fmt_version, c->ro_compat_version, in ubifs_read_superblock()
668 if (c->ro_compat_version <= UBIFS_RO_COMPAT_VERSION) { in ubifs_read_superblock()
670 err = -EROFS; in ubifs_read_superblock()
672 err = -EINVAL; in ubifs_read_superblock()
678 * R/O-compatible with the UBIFS implementation, so we can in ubifs_read_superblock()
681 c->rw_incompat = 1; in ubifs_read_superblock()
684 if (c->fmt_version < 3) { in ubifs_read_superblock()
685 ubifs_err(c, "on-flash format version %d is not supported", in ubifs_read_superblock()
686 c->fmt_version); in ubifs_read_superblock()
687 err = -EINVAL; in ubifs_read_superblock()
691 switch (sup->key_hash) { in ubifs_read_superblock()
693 c->key_hash = key_r5_hash; in ubifs_read_superblock()
694 c->key_hash_type = UBIFS_KEY_HASH_R5; in ubifs_read_superblock()
698 c->key_hash = key_test_hash; in ubifs_read_superblock()
699 c->key_hash_type = UBIFS_KEY_HASH_TEST; in ubifs_read_superblock()
703 c->key_fmt = sup->key_fmt; in ubifs_read_superblock()
705 switch (c->key_fmt) { in ubifs_read_superblock()
707 c->key_len = UBIFS_SK_LEN; in ubifs_read_superblock()
711 err = -EINVAL; in ubifs_read_superblock()
715 c->leb_cnt = le32_to_cpu(sup->leb_cnt); in ubifs_read_superblock()
716 c->max_leb_cnt = le32_to_cpu(sup->max_leb_cnt); in ubifs_read_superblock()
717 c->max_bud_bytes = le64_to_cpu(sup->max_bud_bytes); in ubifs_read_superblock()
718 c->log_lebs = le32_to_cpu(sup->log_lebs); in ubifs_read_superblock()
719 c->lpt_lebs = le32_to_cpu(sup->lpt_lebs); in ubifs_read_superblock()
720 c->orph_lebs = le32_to_cpu(sup->orph_lebs); in ubifs_read_superblock()
721 c->jhead_cnt = le32_to_cpu(sup->jhead_cnt) + NONDATA_JHEADS_CNT; in ubifs_read_superblock()
722 c->fanout = le32_to_cpu(sup->fanout); in ubifs_read_superblock()
723 c->lsave_cnt = le32_to_cpu(sup->lsave_cnt); in ubifs_read_superblock()
724 c->rp_size = le64_to_cpu(sup->rp_size); in ubifs_read_superblock()
725 c->rp_uid = make_kuid(&init_user_ns, le32_to_cpu(sup->rp_uid)); in ubifs_read_superblock()
726 c->rp_gid = make_kgid(&init_user_ns, le32_to_cpu(sup->rp_gid)); in ubifs_read_superblock()
727 sup_flags = le32_to_cpu(sup->flags); in ubifs_read_superblock()
728 if (!c->mount_opts.override_compr) in ubifs_read_superblock()
729 c->default_compr = le16_to_cpu(sup->default_compr); in ubifs_read_superblock()
731 c->vfs_sb->s_time_gran = le32_to_cpu(sup->time_gran); in ubifs_read_superblock()
732 memcpy(&c->uuid, &sup->uuid, 16); in ubifs_read_superblock()
733 c->big_lpt = !!(sup_flags & UBIFS_FLG_BIGLPT); in ubifs_read_superblock()
734 c->space_fixup = !!(sup_flags & UBIFS_FLG_SPACE_FIXUP); in ubifs_read_superblock()
735 c->double_hash = !!(sup_flags & UBIFS_FLG_DOUBLE_HASH); in ubifs_read_superblock()
736 c->encrypted = !!(sup_flags & UBIFS_FLG_ENCRYPTION); in ubifs_read_superblock()
745 err = -EINVAL; in ubifs_read_superblock()
749 if (!IS_ENABLED(CONFIG_FS_ENCRYPTION) && c->encrypted) { in ubifs_read_superblock()
752 err = -EINVAL; in ubifs_read_superblock()
757 if (c->leb_cnt < c->vi.size && c->leb_cnt < c->max_leb_cnt) { in ubifs_read_superblock()
758 int old_leb_cnt = c->leb_cnt; in ubifs_read_superblock()
760 c->leb_cnt = min_t(int, c->max_leb_cnt, c->vi.size); in ubifs_read_superblock()
761 sup->leb_cnt = cpu_to_le32(c->leb_cnt); in ubifs_read_superblock()
763 c->superblock_need_write = 1; in ubifs_read_superblock()
766 old_leb_cnt, c->leb_cnt); in ubifs_read_superblock()
769 c->log_bytes = (long long)c->log_lebs * c->leb_size; in ubifs_read_superblock()
770 c->log_last = UBIFS_LOG_LNUM + c->log_lebs - 1; in ubifs_read_superblock()
771 c->lpt_first = UBIFS_LOG_LNUM + c->log_lebs; in ubifs_read_superblock()
772 c->lpt_last = c->lpt_first + c->lpt_lebs - 1; in ubifs_read_superblock()
773 c->orph_first = c->lpt_last + 1; in ubifs_read_superblock()
774 c->orph_last = c->orph_first + c->orph_lebs - 1; in ubifs_read_superblock()
775 c->main_lebs = c->leb_cnt - UBIFS_SB_LEBS - UBIFS_MST_LEBS; in ubifs_read_superblock()
776 c->main_lebs -= c->log_lebs + c->lpt_lebs + c->orph_lebs; in ubifs_read_superblock()
777 c->main_first = c->leb_cnt - c->main_lebs; in ubifs_read_superblock()
785 * fixup_leb - fixup/unmap an LEB containing free space.
786 * @c: UBIFS file-system description object
792 * flash (rather than being just all-0xff real data). If the LEB is completely
800 ubifs_assert(c, len % c->min_io_size == 0); in fixup_leb()
801 ubifs_assert(c, len < c->leb_size); in fixup_leb()
809 err = ubifs_leb_read(c, lnum, c->sbuf, 0, len, 1); in fixup_leb()
813 return ubifs_leb_change(c, lnum, c->sbuf, len); in fixup_leb()
817 * fixup_free_space - find & remap all LEBs containing free space.
818 * @c: UBIFS file-system description object
832 err = fixup_leb(c, lnum, c->mst_offs + c->mst_node_alsz); in fixup_free_space()
838 lnum = ubifs_next_log_lnum(c, c->lhead_lnum); in fixup_free_space()
839 while (lnum != c->ltail_lnum) { in fixup_free_space()
850 err = fixup_leb(c, c->lhead_lnum, in fixup_free_space()
851 ALIGN(UBIFS_CS_NODE_SZ, c->min_io_size)); in fixup_free_space()
856 for (lnum = c->lpt_first; lnum <= c->lpt_last; lnum++) { in fixup_free_space()
857 int free = c->ltab[lnum - c->lpt_first].free; in fixup_free_space()
860 err = fixup_leb(c, lnum, c->leb_size - free); in fixup_free_space()
867 for (lnum = c->orph_first; lnum <= c->orph_last; lnum++) { in fixup_free_space()
874 for (lnum = c->main_first; lnum < c->leb_cnt; lnum++) { in fixup_free_space()
881 if (lprops->free > 0) { in fixup_free_space()
882 err = fixup_leb(c, lnum, c->leb_size - lprops->free); in fixup_free_space()
894 * ubifs_fixup_free_space - find & fix all LEBs with free space.
895 * @c: UBIFS file-system description object
899 * empty min. I/O unit (i.e. free-space-count > 0) is re-written, to make sure
902 * (generating a non-0xff ECC), causing future writes to the not-really-erased
909 struct ubifs_sb_node *sup = c->sup_node; in ubifs_fixup_free_space()
911 ubifs_assert(c, c->space_fixup); in ubifs_fixup_free_space()
912 ubifs_assert(c, !c->ro_mount); in ubifs_fixup_free_space()
920 /* Free-space fixup is no longer required */ in ubifs_fixup_free_space()
921 c->space_fixup = 0; in ubifs_fixup_free_space()
922 sup->flags &= cpu_to_le32(~UBIFS_FLG_SPACE_FIXUP); in ubifs_fixup_free_space()
924 c->superblock_need_write = 1; in ubifs_fixup_free_space()
933 struct ubifs_sb_node *sup = c->sup_node; in ubifs_enable_encryption()
936 return -EOPNOTSUPP; in ubifs_enable_encryption()
938 if (c->encrypted) in ubifs_enable_encryption()
941 if (c->ro_mount || c->ro_media) in ubifs_enable_encryption()
942 return -EROFS; in ubifs_enable_encryption()
944 if (c->fmt_version < 5) { in ubifs_enable_encryption()
945 ubifs_err(c, "on-flash format version 5 is needed for encryption"); in ubifs_enable_encryption()
946 return -EINVAL; in ubifs_enable_encryption()
949 sup->flags |= cpu_to_le32(UBIFS_FLG_ENCRYPTION); in ubifs_enable_encryption()
953 c->encrypted = 1; in ubifs_enable_encryption()