Lines Matching refs:c

73 static int validate_inode(struct ubifs_info *c, const struct inode *inode)  in validate_inode()  argument
78 if (inode->i_size > c->max_inode_sz) { in validate_inode()
79 ubifs_err(c, "inode is too large (%lld)", in validate_inode()
85 ubifs_err(c, "unknown compression type %d", ui->compr_type); in validate_inode()
98 if (!ubifs_compr_present(c, ui->compr_type)) { in validate_inode()
99 ubifs_warn(c, "inode %lu uses '%s' compression, but it was not compiled in", in validate_inode()
100 inode->i_ino, ubifs_compr_name(c, ui->compr_type)); in validate_inode()
103 err = dbg_check_dir(c, inode); in validate_inode()
112 struct ubifs_info *c = sb->s_fs_info; in ubifs_iget() local
131 ino_key_init(c, &key, inode->i_ino); in ubifs_iget()
133 err = ubifs_tnc_lookup(c, &key, ino); in ubifs_iget()
165 err = validate_inode(c, inode); in ubifs_iget()
255 ubifs_err(c, "inode %lu validation failed, error %d", inode->i_ino, err); in ubifs_iget()
256 ubifs_dump_node(c, ino, UBIFS_MAX_INO_NODE_SZ); in ubifs_iget()
257 ubifs_dump_inode(c, inode); in ubifs_iget()
262 ubifs_err(c, "failed to read inode %lu, error %d", inode->i_ino, err); in ubifs_iget()
299 struct ubifs_info *c = inode->i_sb->s_fs_info; in ubifs_write_inode() local
302 ubifs_assert(c, !ui->xattr); in ubifs_write_inode()
326 err = ubifs_jnl_write_inode(c, inode); in ubifs_write_inode()
328 ubifs_err(c, "can't write inode %lu, error %d", in ubifs_write_inode()
331 err = dbg_check_inode_size(c, inode, ui->ui_size); in ubifs_write_inode()
336 ubifs_release_dirty_inode_budget(c, ui); in ubifs_write_inode()
353 struct ubifs_info *c = inode->i_sb->s_fs_info; in ubifs_evict_inode() local
365 ubifs_assert(c, !atomic_read(&inode->i_count)); in ubifs_evict_inode()
376 err = ubifs_jnl_delete_inode(c, inode); in ubifs_evict_inode()
382 ubifs_err(c, "can't delete inode %lu, error %d", in ubifs_evict_inode()
387 ubifs_release_dirty_inode_budget(c, ui); in ubifs_evict_inode()
390 c->bi.nospace = c->bi.nospace_rp = 0; in ubifs_evict_inode()
400 struct ubifs_info *c = inode->i_sb->s_fs_info; in ubifs_dirty_inode() local
403 ubifs_assert(c, mutex_is_locked(&ui->ui_mutex)); in ubifs_dirty_inode()
412 struct ubifs_info *c = dentry->d_sb->s_fs_info; in ubifs_statfs() local
414 __le32 *uuid = (__le32 *)c->uuid; in ubifs_statfs()
416 free = ubifs_get_free_space(c); in ubifs_statfs()
422 buf->f_blocks = c->block_cnt; in ubifs_statfs()
424 if (free > c->report_rp_size) in ubifs_statfs()
425 buf->f_bavail = (free - c->report_rp_size) >> UBIFS_BLOCK_SHIFT; in ubifs_statfs()
433 ubifs_assert(c, buf->f_bfree <= c->block_cnt); in ubifs_statfs()
439 struct ubifs_info *c = root->d_sb->s_fs_info; in ubifs_show_options() local
441 if (c->mount_opts.unmount_mode == 2) in ubifs_show_options()
443 else if (c->mount_opts.unmount_mode == 1) in ubifs_show_options()
446 if (c->mount_opts.bulk_read == 2) in ubifs_show_options()
448 else if (c->mount_opts.bulk_read == 1) in ubifs_show_options()
451 if (c->mount_opts.chk_data_crc == 2) in ubifs_show_options()
453 else if (c->mount_opts.chk_data_crc == 1) in ubifs_show_options()
456 if (c->mount_opts.override_compr) { in ubifs_show_options()
458 ubifs_compr_name(c, c->mount_opts.compr_type)); in ubifs_show_options()
461 seq_printf(s, ",assert=%s", ubifs_assert_action_name(c)); in ubifs_show_options()
462 seq_printf(s, ",ubi=%d,vol=%d", c->vi.ubi_num, c->vi.vol_id); in ubifs_show_options()
470 struct ubifs_info *c = sb->s_fs_info; in ubifs_sync_fs() local
484 for (i = 0; i < c->jhead_cnt; i++) { in ubifs_sync_fs()
485 err = ubifs_wbuf_sync(&c->jheads[i].wbuf); in ubifs_sync_fs()
497 err = ubifs_run_commit(c); in ubifs_sync_fs()
501 return ubi_sync(c->vi.ubi_num); in ubifs_sync_fs()
513 static int init_constants_early(struct ubifs_info *c) in init_constants_early() argument
515 if (c->vi.corrupted) { in init_constants_early()
516 ubifs_warn(c, "UBI volume is corrupted - read-only mode"); in init_constants_early()
517 c->ro_media = 1; in init_constants_early()
520 if (c->di.ro_mode) { in init_constants_early()
521 ubifs_msg(c, "read-only UBI device"); in init_constants_early()
522 c->ro_media = 1; in init_constants_early()
525 if (c->vi.vol_type == UBI_STATIC_VOLUME) { in init_constants_early()
526 ubifs_msg(c, "static UBI volume - read-only mode"); in init_constants_early()
527 c->ro_media = 1; in init_constants_early()
530 c->leb_cnt = c->vi.size; in init_constants_early()
531 c->leb_size = c->vi.usable_leb_size; in init_constants_early()
532 c->leb_start = c->di.leb_start; in init_constants_early()
533 c->half_leb_size = c->leb_size / 2; in init_constants_early()
534 c->min_io_size = c->di.min_io_size; in init_constants_early()
535 c->min_io_shift = fls(c->min_io_size) - 1; in init_constants_early()
536 c->max_write_size = c->di.max_write_size; in init_constants_early()
537 c->max_write_shift = fls(c->max_write_size) - 1; in init_constants_early()
539 if (c->leb_size < UBIFS_MIN_LEB_SZ) { in init_constants_early()
540 ubifs_errc(c, "too small LEBs (%d bytes), min. is %d bytes", in init_constants_early()
541 c->leb_size, UBIFS_MIN_LEB_SZ); in init_constants_early()
545 if (c->leb_cnt < UBIFS_MIN_LEB_CNT) { in init_constants_early()
546 ubifs_errc(c, "too few LEBs (%d), min. is %d", in init_constants_early()
547 c->leb_cnt, UBIFS_MIN_LEB_CNT); in init_constants_early()
551 if (!is_power_of_2(c->min_io_size)) { in init_constants_early()
552 ubifs_errc(c, "bad min. I/O size %d", c->min_io_size); in init_constants_early()
560 if (c->max_write_size < c->min_io_size || in init_constants_early()
561 c->max_write_size % c->min_io_size || in init_constants_early()
562 !is_power_of_2(c->max_write_size)) { in init_constants_early()
563 ubifs_errc(c, "bad write buffer size %d for %d min. I/O unit", in init_constants_early()
564 c->max_write_size, c->min_io_size); in init_constants_early()
573 if (c->min_io_size < 8) { in init_constants_early()
574 c->min_io_size = 8; in init_constants_early()
575 c->min_io_shift = 3; in init_constants_early()
576 if (c->max_write_size < c->min_io_size) { in init_constants_early()
577 c->max_write_size = c->min_io_size; in init_constants_early()
578 c->max_write_shift = c->min_io_shift; in init_constants_early()
582 c->ref_node_alsz = ALIGN(UBIFS_REF_NODE_SZ, c->min_io_size); in init_constants_early()
583 c->mst_node_alsz = ALIGN(UBIFS_MST_NODE_SZ, c->min_io_size); in init_constants_early()
589 c->ranges[UBIFS_PAD_NODE].len = UBIFS_PAD_NODE_SZ; in init_constants_early()
590 c->ranges[UBIFS_SB_NODE].len = UBIFS_SB_NODE_SZ; in init_constants_early()
591 c->ranges[UBIFS_MST_NODE].len = UBIFS_MST_NODE_SZ; in init_constants_early()
592 c->ranges[UBIFS_REF_NODE].len = UBIFS_REF_NODE_SZ; in init_constants_early()
593 c->ranges[UBIFS_TRUN_NODE].len = UBIFS_TRUN_NODE_SZ; in init_constants_early()
594 c->ranges[UBIFS_CS_NODE].len = UBIFS_CS_NODE_SZ; in init_constants_early()
595 c->ranges[UBIFS_AUTH_NODE].min_len = UBIFS_AUTH_NODE_SZ; in init_constants_early()
596 c->ranges[UBIFS_AUTH_NODE].max_len = UBIFS_AUTH_NODE_SZ + in init_constants_early()
598 c->ranges[UBIFS_SIG_NODE].min_len = UBIFS_SIG_NODE_SZ; in init_constants_early()
599 c->ranges[UBIFS_SIG_NODE].max_len = c->leb_size - UBIFS_SB_NODE_SZ; in init_constants_early()
601 c->ranges[UBIFS_INO_NODE].min_len = UBIFS_INO_NODE_SZ; in init_constants_early()
602 c->ranges[UBIFS_INO_NODE].max_len = UBIFS_MAX_INO_NODE_SZ; in init_constants_early()
603 c->ranges[UBIFS_ORPH_NODE].min_len = in init_constants_early()
605 c->ranges[UBIFS_ORPH_NODE].max_len = c->leb_size; in init_constants_early()
606 c->ranges[UBIFS_DENT_NODE].min_len = UBIFS_DENT_NODE_SZ; in init_constants_early()
607 c->ranges[UBIFS_DENT_NODE].max_len = UBIFS_MAX_DENT_NODE_SZ; in init_constants_early()
608 c->ranges[UBIFS_XENT_NODE].min_len = UBIFS_XENT_NODE_SZ; in init_constants_early()
609 c->ranges[UBIFS_XENT_NODE].max_len = UBIFS_MAX_XENT_NODE_SZ; in init_constants_early()
610 c->ranges[UBIFS_DATA_NODE].min_len = UBIFS_DATA_NODE_SZ; in init_constants_early()
611 c->ranges[UBIFS_DATA_NODE].max_len = UBIFS_MAX_DATA_NODE_SZ; in init_constants_early()
616 c->ranges[UBIFS_IDX_NODE].min_len = UBIFS_IDX_NODE_SZ + UBIFS_BRANCH_SZ; in init_constants_early()
621 c->ranges[UBIFS_IDX_NODE].max_len = INT_MAX; in init_constants_early()
627 c->dead_wm = ALIGN(MIN_WRITE_SZ, c->min_io_size); in init_constants_early()
628 c->dark_wm = ALIGN(UBIFS_MAX_NODE_SZ, c->min_io_size); in init_constants_early()
635 c->leb_overhead = c->leb_size % UBIFS_MAX_DATA_NODE_SZ; in init_constants_early()
638 c->max_bu_buf_len = UBIFS_MAX_BULK_READ * UBIFS_MAX_DATA_NODE_SZ; in init_constants_early()
639 if (c->max_bu_buf_len > c->leb_size) in init_constants_early()
640 c->max_bu_buf_len = c->leb_size; in init_constants_early()
643 c->min_log_bytes = c->leb_size; in init_constants_early()
663 static int bud_wbuf_callback(struct ubifs_info *c, int lnum, int free, int pad) in bud_wbuf_callback() argument
665 return ubifs_update_one_lp(c, lnum, free, pad, 0, 0); in bud_wbuf_callback()
677 static int init_constants_sb(struct ubifs_info *c) in init_constants_sb() argument
682 c->main_bytes = (long long)c->main_lebs * c->leb_size; in init_constants_sb()
683 c->max_znode_sz = sizeof(struct ubifs_znode) + in init_constants_sb()
684 c->fanout * sizeof(struct ubifs_zbranch); in init_constants_sb()
686 tmp = ubifs_idx_node_sz(c, 1); in init_constants_sb()
687 c->ranges[UBIFS_IDX_NODE].min_len = tmp; in init_constants_sb()
688 c->min_idx_node_sz = ALIGN(tmp, 8); in init_constants_sb()
690 tmp = ubifs_idx_node_sz(c, c->fanout); in init_constants_sb()
691 c->ranges[UBIFS_IDX_NODE].max_len = tmp; in init_constants_sb()
692 c->max_idx_node_sz = ALIGN(tmp, 8); in init_constants_sb()
695 tmp = UBIFS_CS_NODE_SZ + UBIFS_REF_NODE_SZ * c->jhead_cnt; in init_constants_sb()
696 tmp = ALIGN(tmp, c->min_io_size); in init_constants_sb()
697 if (tmp > c->leb_size) { in init_constants_sb()
698 ubifs_err(c, "too small LEB size %d, at least %d needed", in init_constants_sb()
699 c->leb_size, tmp); in init_constants_sb()
707 tmp64 = c->max_bud_bytes + c->leb_size - 1; in init_constants_sb()
708 c->max_bud_cnt = div_u64(tmp64, c->leb_size); in init_constants_sb()
709 tmp = (c->ref_node_alsz * c->max_bud_cnt + c->leb_size - 1); in init_constants_sb()
710 tmp /= c->leb_size; in init_constants_sb()
712 if (c->log_lebs < tmp) { in init_constants_sb()
713 ubifs_err(c, "too small log %d LEBs, required min. %d LEBs", in init_constants_sb()
714 c->log_lebs, tmp); in init_constants_sb()
725 c->bi.page_budget = UBIFS_MAX_DATA_NODE_SZ * UBIFS_BLOCKS_PER_PAGE; in init_constants_sb()
726 c->bi.inode_budget = UBIFS_INO_NODE_SZ; in init_constants_sb()
727 c->bi.dent_budget = UBIFS_MAX_DENT_NODE_SZ; in init_constants_sb()
736 c->bg_bud_bytes = (c->max_bud_bytes * 13) >> 4; in init_constants_sb()
744 tmp64 = (long long)(c->jhead_cnt + 1) * c->leb_size + 1; in init_constants_sb()
745 if (c->bg_bud_bytes < tmp64) in init_constants_sb()
746 c->bg_bud_bytes = tmp64; in init_constants_sb()
747 if (c->max_bud_bytes < tmp64 + c->leb_size) in init_constants_sb()
748 c->max_bud_bytes = tmp64 + c->leb_size; in init_constants_sb()
750 err = ubifs_calc_lpt_geom(c); in init_constants_sb()
755 c->idx_leb_size = c->leb_size - c->max_idx_node_sz; in init_constants_sb()
767 static void init_constants_master(struct ubifs_info *c) in init_constants_master() argument
771 c->bi.min_idx_lebs = ubifs_calc_min_idx_lebs(c); in init_constants_master()
772 c->report_rp_size = ubifs_reported_space(c, c->rp_size); in init_constants_master()
783 tmp64 = c->main_lebs - 1 - 1 - MIN_INDEX_LEBS - c->jhead_cnt + 1; in init_constants_master()
784 tmp64 *= (long long)c->leb_size - c->leb_overhead; in init_constants_master()
785 tmp64 = ubifs_reported_space(c, tmp64); in init_constants_master()
786 c->block_cnt = tmp64 >> UBIFS_BLOCK_SHIFT; in init_constants_master()
800 static int take_gc_lnum(struct ubifs_info *c) in take_gc_lnum() argument
804 if (c->gc_lnum == -1) { in take_gc_lnum()
805 ubifs_err(c, "no LEB for GC"); in take_gc_lnum()
810 err = ubifs_change_one_lp(c, c->gc_lnum, c->leb_size, 0, in take_gc_lnum()
822 static int alloc_wbufs(struct ubifs_info *c) in alloc_wbufs() argument
826 c->jheads = kcalloc(c->jhead_cnt, sizeof(struct ubifs_jhead), in alloc_wbufs()
828 if (!c->jheads) in alloc_wbufs()
832 for (i = 0; i < c->jhead_cnt; i++) { in alloc_wbufs()
833 INIT_LIST_HEAD(&c->jheads[i].buds_list); in alloc_wbufs()
834 err = ubifs_wbuf_init(c, &c->jheads[i].wbuf); in alloc_wbufs()
838 c->jheads[i].wbuf.sync_callback = &bud_wbuf_callback; in alloc_wbufs()
839 c->jheads[i].wbuf.jhead = i; in alloc_wbufs()
840 c->jheads[i].grouped = 1; in alloc_wbufs()
841 c->jheads[i].log_hash = ubifs_hash_get_desc(c); in alloc_wbufs()
842 if (IS_ERR(c->jheads[i].log_hash)) { in alloc_wbufs()
843 err = PTR_ERR(c->jheads[i].log_hash); in alloc_wbufs()
852 c->jheads[GCHD].wbuf.no_timer = 1; in alloc_wbufs()
853 c->jheads[GCHD].grouped = 0; in alloc_wbufs()
858 kfree(c->jheads[i].wbuf.buf); in alloc_wbufs()
859 kfree(c->jheads[i].wbuf.inodes); in alloc_wbufs()
863 kfree(c->jheads[i].wbuf.buf); in alloc_wbufs()
864 kfree(c->jheads[i].wbuf.inodes); in alloc_wbufs()
865 kfree(c->jheads[i].log_hash); in alloc_wbufs()
867 kfree(c->jheads); in alloc_wbufs()
868 c->jheads = NULL; in alloc_wbufs()
877 static void free_wbufs(struct ubifs_info *c) in free_wbufs() argument
881 if (c->jheads) { in free_wbufs()
882 for (i = 0; i < c->jhead_cnt; i++) { in free_wbufs()
883 kfree(c->jheads[i].wbuf.buf); in free_wbufs()
884 kfree(c->jheads[i].wbuf.inodes); in free_wbufs()
885 kfree(c->jheads[i].log_hash); in free_wbufs()
887 kfree(c->jheads); in free_wbufs()
888 c->jheads = NULL; in free_wbufs()
896 static void free_orphans(struct ubifs_info *c) in free_orphans() argument
900 while (c->orph_dnext) { in free_orphans()
901 orph = c->orph_dnext; in free_orphans()
902 c->orph_dnext = orph->dnext; in free_orphans()
907 while (!list_empty(&c->orph_list)) { in free_orphans()
908 orph = list_entry(c->orph_list.next, struct ubifs_orphan, list); in free_orphans()
911 ubifs_err(c, "orphan list not empty at unmount"); in free_orphans()
914 vfree(c->orph_buf); in free_orphans()
915 c->orph_buf = NULL; in free_orphans()
922 static void free_buds(struct ubifs_info *c) in free_buds() argument
926 rbtree_postorder_for_each_entry_safe(bud, n, &c->buds, rb) in free_buds()
939 static int check_volume_empty(struct ubifs_info *c) in check_volume_empty() argument
943 c->empty = 1; in check_volume_empty()
944 for (lnum = 0; lnum < c->leb_cnt; lnum++) { in check_volume_empty()
945 err = ubifs_is_mapped(c, lnum); in check_volume_empty()
949 c->empty = 0; in check_volume_empty()
1036 static int ubifs_parse_options(struct ubifs_info *c, char *options, in ubifs_parse_options() argument
1059 c->mount_opts.unmount_mode = 2; in ubifs_parse_options()
1062 c->mount_opts.unmount_mode = 1; in ubifs_parse_options()
1065 c->mount_opts.bulk_read = 2; in ubifs_parse_options()
1066 c->bulk_read = 1; in ubifs_parse_options()
1069 c->mount_opts.bulk_read = 1; in ubifs_parse_options()
1070 c->bulk_read = 0; in ubifs_parse_options()
1073 c->mount_opts.chk_data_crc = 2; in ubifs_parse_options()
1074 c->no_chk_data_crc = 0; in ubifs_parse_options()
1077 c->mount_opts.chk_data_crc = 1; in ubifs_parse_options()
1078 c->no_chk_data_crc = 1; in ubifs_parse_options()
1087 c->mount_opts.compr_type = UBIFS_COMPR_NONE; in ubifs_parse_options()
1089 c->mount_opts.compr_type = UBIFS_COMPR_LZO; in ubifs_parse_options()
1091 c->mount_opts.compr_type = UBIFS_COMPR_ZLIB; in ubifs_parse_options()
1093 c->mount_opts.compr_type = UBIFS_COMPR_ZSTD; in ubifs_parse_options()
1095 ubifs_err(c, "unknown compressor \"%s\"", name); //FIXME: is c ready? in ubifs_parse_options()
1100 c->mount_opts.override_compr = 1; in ubifs_parse_options()
1101 c->default_compr = c->mount_opts.compr_type; in ubifs_parse_options()
1111 c->assert_action = ASSACT_REPORT; in ubifs_parse_options()
1113 c->assert_action = ASSACT_RO; in ubifs_parse_options()
1115 c->assert_action = ASSACT_PANIC; in ubifs_parse_options()
1117 ubifs_err(c, "unknown assert action \"%s\"", act); in ubifs_parse_options()
1126 c->auth_key_name = kstrdup(args[0].from, in ubifs_parse_options()
1128 if (!c->auth_key_name) in ubifs_parse_options()
1134 c->auth_hash_name = kstrdup(args[0].from, in ubifs_parse_options()
1136 if (!c->auth_hash_name) in ubifs_parse_options()
1145 struct super_block *sb = c->vfs_sb; in ubifs_parse_options()
1149 ubifs_err(c, "unrecognized mount option \"%s\" or missing value", in ubifs_parse_options()
1166 static void ubifs_release_options(struct ubifs_info *c) in ubifs_release_options() argument
1168 kfree(c->auth_key_name); in ubifs_release_options()
1169 c->auth_key_name = NULL; in ubifs_release_options()
1170 kfree(c->auth_hash_name); in ubifs_release_options()
1171 c->auth_hash_name = NULL; in ubifs_release_options()
1181 static void destroy_journal(struct ubifs_info *c) in destroy_journal() argument
1183 while (!list_empty(&c->unclean_leb_list)) { in destroy_journal()
1186 ucleb = list_entry(c->unclean_leb_list.next, in destroy_journal()
1191 while (!list_empty(&c->old_buds)) { in destroy_journal()
1194 bud = list_entry(c->old_buds.next, struct ubifs_bud, list); in destroy_journal()
1198 ubifs_destroy_idx_gc(c); in destroy_journal()
1199 ubifs_destroy_size_tree(c); in destroy_journal()
1200 ubifs_tnc_close(c); in destroy_journal()
1201 free_buds(c); in destroy_journal()
1208 static void bu_init(struct ubifs_info *c) in bu_init() argument
1210 ubifs_assert(c, c->bulk_read == 1); in bu_init()
1212 if (c->bu.buf) in bu_init()
1216 c->bu.buf = kmalloc(c->max_bu_buf_len, GFP_KERNEL | __GFP_NOWARN); in bu_init()
1217 if (!c->bu.buf) { in bu_init()
1218 if (c->max_bu_buf_len > UBIFS_KMALLOC_OK) { in bu_init()
1219 c->max_bu_buf_len = UBIFS_KMALLOC_OK; in bu_init()
1224 ubifs_warn(c, "cannot allocate %d bytes of memory for bulk-read, disabling it", in bu_init()
1225 c->max_bu_buf_len); in bu_init()
1226 c->mount_opts.bulk_read = 1; in bu_init()
1227 c->bulk_read = 0; in bu_init()
1239 static int check_free_space(struct ubifs_info *c) in check_free_space() argument
1241 ubifs_assert(c, c->dark_wm > 0); in check_free_space()
1242 if (c->lst.total_free + c->lst.total_dirty < c->dark_wm) { in check_free_space()
1243 ubifs_err(c, "insufficient free space to mount in R/W mode"); in check_free_space()
1244 ubifs_dump_budg(c, &c->bi); in check_free_space()
1245 ubifs_dump_lprops(c); in check_free_space()
1258 static int mount_ubifs(struct ubifs_info *c) in mount_ubifs() argument
1264 c->ro_mount = !!sb_rdonly(c->vfs_sb); in mount_ubifs()
1266 c->probing = !!(c->vfs_sb->s_flags & SB_SILENT); in mount_ubifs()
1268 err = init_constants_early(c); in mount_ubifs()
1272 err = ubifs_debugging_init(c); in mount_ubifs()
1276 err = ubifs_sysfs_register(c); in mount_ubifs()
1280 err = check_volume_empty(c); in mount_ubifs()
1284 if (c->empty && (c->ro_mount || c->ro_media)) { in mount_ubifs()
1289 ubifs_err(c, "can't format empty UBI volume: read-only %s", in mount_ubifs()
1290 c->ro_media ? "UBI volume" : "mount"); in mount_ubifs()
1295 if (c->ro_media && !c->ro_mount) { in mount_ubifs()
1296 ubifs_err(c, "cannot mount read-write - read-only media"); in mount_ubifs()
1307 c->bottom_up_buf = kmalloc_array(BOTTOM_UP_HEIGHT, sizeof(int), in mount_ubifs()
1309 if (!c->bottom_up_buf) in mount_ubifs()
1312 c->sbuf = vmalloc(c->leb_size); in mount_ubifs()
1313 if (!c->sbuf) in mount_ubifs()
1316 if (!c->ro_mount) { in mount_ubifs()
1317 c->ileb_buf = vmalloc(c->leb_size); in mount_ubifs()
1318 if (!c->ileb_buf) in mount_ubifs()
1322 if (c->bulk_read == 1) in mount_ubifs()
1323 bu_init(c); in mount_ubifs()
1325 if (!c->ro_mount) { in mount_ubifs()
1326 c->write_reserve_buf = kmalloc(COMPRESSED_DATA_NODE_BUF_SZ + \ in mount_ubifs()
1329 if (!c->write_reserve_buf) in mount_ubifs()
1333 c->mounting = 1; in mount_ubifs()
1335 if (c->auth_key_name) { in mount_ubifs()
1337 err = ubifs_init_authentication(c); in mount_ubifs()
1341 ubifs_err(c, "auth_key_name, but UBIFS is built without" in mount_ubifs()
1348 err = ubifs_read_superblock(c); in mount_ubifs()
1352 c->probing = 0; in mount_ubifs()
1358 if (!ubifs_compr_present(c, c->default_compr)) { in mount_ubifs()
1359 ubifs_err(c, "'compressor \"%s\" is not compiled in", in mount_ubifs()
1360 ubifs_compr_name(c, c->default_compr)); in mount_ubifs()
1365 err = init_constants_sb(c); in mount_ubifs()
1369 sz = ALIGN(c->max_idx_node_sz, c->min_io_size) * 2; in mount_ubifs()
1370 c->cbuf = kmalloc(sz, GFP_NOFS); in mount_ubifs()
1371 if (!c->cbuf) { in mount_ubifs()
1376 err = alloc_wbufs(c); in mount_ubifs()
1380 sprintf(c->bgt_name, BGT_NAME_PATTERN, c->vi.ubi_num, c->vi.vol_id); in mount_ubifs()
1381 if (!c->ro_mount) { in mount_ubifs()
1383 c->bgt = kthread_run(ubifs_bg_thread, c, "%s", c->bgt_name); in mount_ubifs()
1384 if (IS_ERR(c->bgt)) { in mount_ubifs()
1385 err = PTR_ERR(c->bgt); in mount_ubifs()
1386 c->bgt = NULL; in mount_ubifs()
1387 ubifs_err(c, "cannot spawn \"%s\", error %d", in mount_ubifs()
1388 c->bgt_name, err); in mount_ubifs()
1393 err = ubifs_read_master(c); in mount_ubifs()
1397 init_constants_master(c); in mount_ubifs()
1399 if ((c->mst_node->flags & cpu_to_le32(UBIFS_MST_DIRTY)) != 0) { in mount_ubifs()
1400 ubifs_msg(c, "recovery needed"); in mount_ubifs()
1401 c->need_recovery = 1; in mount_ubifs()
1404 if (c->need_recovery && !c->ro_mount) { in mount_ubifs()
1405 err = ubifs_recover_inl_heads(c, c->sbuf); in mount_ubifs()
1410 err = ubifs_lpt_init(c, 1, !c->ro_mount); in mount_ubifs()
1414 if (!c->ro_mount && c->space_fixup) { in mount_ubifs()
1415 err = ubifs_fixup_free_space(c); in mount_ubifs()
1420 if (!c->ro_mount && !c->need_recovery) { in mount_ubifs()
1425 c->mst_node->flags |= cpu_to_le32(UBIFS_MST_DIRTY); in mount_ubifs()
1426 err = ubifs_write_master(c); in mount_ubifs()
1437 if (ubifs_authenticated(c) && ubifs_hmac_zero(c, c->sup_node->hmac)) { in mount_ubifs()
1438 err = ubifs_hmac_wkm(c, c->sup_node->hmac_wkm); in mount_ubifs()
1441 c->superblock_need_write = 1; in mount_ubifs()
1444 if (!c->ro_mount && c->superblock_need_write) { in mount_ubifs()
1445 err = ubifs_write_sb_node(c, c->sup_node); in mount_ubifs()
1448 c->superblock_need_write = 0; in mount_ubifs()
1451 err = dbg_check_idx_size(c, c->bi.old_idx_sz); in mount_ubifs()
1455 err = ubifs_replay_journal(c); in mount_ubifs()
1460 c->bi.min_idx_lebs = ubifs_calc_min_idx_lebs(c); in mount_ubifs()
1462 err = ubifs_mount_orphans(c, c->need_recovery, c->ro_mount); in mount_ubifs()
1466 if (!c->ro_mount) { in mount_ubifs()
1469 err = check_free_space(c); in mount_ubifs()
1474 lnum = c->lhead_lnum + 1; in mount_ubifs()
1475 if (lnum >= UBIFS_LOG_LNUM + c->log_lebs) in mount_ubifs()
1477 if (lnum == c->ltail_lnum) { in mount_ubifs()
1478 err = ubifs_consolidate_log(c); in mount_ubifs()
1483 if (c->need_recovery) { in mount_ubifs()
1484 if (!ubifs_authenticated(c)) { in mount_ubifs()
1485 err = ubifs_recover_size(c, true); in mount_ubifs()
1490 err = ubifs_rcvry_gc_commit(c); in mount_ubifs()
1494 if (ubifs_authenticated(c)) { in mount_ubifs()
1495 err = ubifs_recover_size(c, false); in mount_ubifs()
1500 err = take_gc_lnum(c); in mount_ubifs()
1508 err = ubifs_leb_unmap(c, c->gc_lnum); in mount_ubifs()
1513 err = dbg_check_lprops(c); in mount_ubifs()
1516 } else if (c->need_recovery) { in mount_ubifs()
1517 err = ubifs_recover_size(c, false); in mount_ubifs()
1527 err = take_gc_lnum(c); in mount_ubifs()
1533 list_add_tail(&c->infos_list, &ubifs_infos); in mount_ubifs()
1536 if (c->need_recovery) { in mount_ubifs()
1537 if (c->ro_mount) in mount_ubifs()
1538 ubifs_msg(c, "recovery deferred"); in mount_ubifs()
1540 c->need_recovery = 0; in mount_ubifs()
1541 ubifs_msg(c, "recovery completed"); in mount_ubifs()
1547 ubifs_assert(c, c->lst.taken_empty_lebs > 0); in mount_ubifs()
1550 ubifs_assert(c, c->lst.taken_empty_lebs > 0); in mount_ubifs()
1552 err = dbg_check_filesystem(c); in mount_ubifs()
1556 dbg_debugfs_init_fs(c); in mount_ubifs()
1558 c->mounting = 0; in mount_ubifs()
1560 ubifs_msg(c, "UBIFS: mounted UBI device %d, volume %d, name \"%s\"%s", in mount_ubifs()
1561 c->vi.ubi_num, c->vi.vol_id, c->vi.name, in mount_ubifs()
1562 c->ro_mount ? ", R/O mode" : ""); in mount_ubifs()
1563 x = (long long)c->main_lebs * c->leb_size; in mount_ubifs()
1564 y = (long long)c->log_lebs * c->leb_size + c->max_bud_bytes; in mount_ubifs()
1565 ubifs_msg(c, "LEB size: %d bytes (%d KiB), min./max. I/O unit sizes: %d bytes/%d bytes", in mount_ubifs()
1566 c->leb_size, c->leb_size >> 10, c->min_io_size, in mount_ubifs()
1567 c->max_write_size); in mount_ubifs()
1568 …ubifs_msg(c, "FS size: %lld bytes (%lld MiB, %d LEBs), max %d LEBs, journal size %lld bytes (%lld … in mount_ubifs()
1569 x, x >> 20, c->main_lebs, c->max_leb_cnt, in mount_ubifs()
1570 y, y >> 20, c->log_lebs + c->max_bud_cnt); in mount_ubifs()
1571 ubifs_msg(c, "reserved for root: %llu bytes (%llu KiB)", in mount_ubifs()
1572 c->report_rp_size, c->report_rp_size >> 10); in mount_ubifs()
1573 ubifs_msg(c, "media format: w%d/r%d (latest is w%d/r%d), UUID %pUB%s", in mount_ubifs()
1574 c->fmt_version, c->ro_compat_version, in mount_ubifs()
1575 UBIFS_FORMAT_VERSION, UBIFS_RO_COMPAT_VERSION, c->uuid, in mount_ubifs()
1576 c->big_lpt ? ", big LPT model" : ", small LPT model"); in mount_ubifs()
1578 dbg_gen("default compressor: %s", ubifs_compr_name(c, c->default_compr)); in mount_ubifs()
1580 c->jhead_cnt - NONDATA_JHEADS_CNT); in mount_ubifs()
1582 c->log_lebs, UBIFS_LOG_LNUM, c->log_last); in mount_ubifs()
1584 c->lpt_lebs, c->lpt_first, c->lpt_last); in mount_ubifs()
1586 c->orph_lebs, c->orph_first, c->orph_last); in mount_ubifs()
1588 c->main_lebs, c->main_first, c->leb_cnt - 1); in mount_ubifs()
1589 dbg_gen("index LEBs: %d", c->lst.idx_lebs); in mount_ubifs()
1591 c->bi.old_idx_sz, c->bi.old_idx_sz >> 10, in mount_ubifs()
1592 c->bi.old_idx_sz >> 20); in mount_ubifs()
1593 dbg_gen("key hash type: %d", c->key_hash_type); in mount_ubifs()
1594 dbg_gen("tree fanout: %d", c->fanout); in mount_ubifs()
1595 dbg_gen("reserved GC LEB: %d", c->gc_lnum); in mount_ubifs()
1596 dbg_gen("max. znode size %d", c->max_znode_sz); in mount_ubifs()
1597 dbg_gen("max. index node size %d", c->max_idx_node_sz); in mount_ubifs()
1606 UBIFS_MAX_DENT_NODE_SZ, ubifs_idx_node_sz(c, c->fanout)); in mount_ubifs()
1607 dbg_gen("dead watermark: %d", c->dead_wm); in mount_ubifs()
1608 dbg_gen("dark watermark: %d", c->dark_wm); in mount_ubifs()
1609 dbg_gen("LEB overhead: %d", c->leb_overhead); in mount_ubifs()
1610 x = (long long)c->main_lebs * c->dark_wm; in mount_ubifs()
1614 c->max_bud_bytes, c->max_bud_bytes >> 10, in mount_ubifs()
1615 c->max_bud_bytes >> 20); in mount_ubifs()
1617 c->bg_bud_bytes, c->bg_bud_bytes >> 10, in mount_ubifs()
1618 c->bg_bud_bytes >> 20); in mount_ubifs()
1620 c->bud_bytes, c->bud_bytes >> 10, c->bud_bytes >> 20); in mount_ubifs()
1621 dbg_gen("max. seq. number: %llu", c->max_sqnum); in mount_ubifs()
1622 dbg_gen("commit number: %llu", c->cmt_no); in mount_ubifs()
1623 dbg_gen("max. xattrs per inode: %d", ubifs_xattr_max_cnt(c)); in mount_ubifs()
1624 dbg_gen("max orphans: %d", c->max_orphans); in mount_ubifs()
1630 list_del(&c->infos_list); in mount_ubifs()
1633 free_orphans(c); in mount_ubifs()
1635 destroy_journal(c); in mount_ubifs()
1637 ubifs_lpt_free(c, 0); in mount_ubifs()
1639 kfree(c->mst_node); in mount_ubifs()
1640 kfree(c->rcvrd_mst_node); in mount_ubifs()
1641 if (c->bgt) in mount_ubifs()
1642 kthread_stop(c->bgt); in mount_ubifs()
1644 free_wbufs(c); in mount_ubifs()
1646 kfree(c->cbuf); in mount_ubifs()
1648 ubifs_exit_authentication(c); in mount_ubifs()
1650 kfree(c->write_reserve_buf); in mount_ubifs()
1651 kfree(c->bu.buf); in mount_ubifs()
1652 vfree(c->ileb_buf); in mount_ubifs()
1653 vfree(c->sbuf); in mount_ubifs()
1654 kfree(c->bottom_up_buf); in mount_ubifs()
1655 kfree(c->sup_node); in mount_ubifs()
1656 ubifs_sysfs_unregister(c); in mount_ubifs()
1658 ubifs_debugging_exit(c); in mount_ubifs()
1671 static void ubifs_umount(struct ubifs_info *c) in ubifs_umount() argument
1673 dbg_gen("un-mounting UBI device %d, volume %d", c->vi.ubi_num, in ubifs_umount()
1674 c->vi.vol_id); in ubifs_umount()
1676 dbg_debugfs_exit_fs(c); in ubifs_umount()
1678 list_del(&c->infos_list); in ubifs_umount()
1681 if (c->bgt) in ubifs_umount()
1682 kthread_stop(c->bgt); in ubifs_umount()
1684 destroy_journal(c); in ubifs_umount()
1685 free_wbufs(c); in ubifs_umount()
1686 free_orphans(c); in ubifs_umount()
1687 ubifs_lpt_free(c, 0); in ubifs_umount()
1688 ubifs_exit_authentication(c); in ubifs_umount()
1690 ubifs_release_options(c); in ubifs_umount()
1691 kfree(c->cbuf); in ubifs_umount()
1692 kfree(c->rcvrd_mst_node); in ubifs_umount()
1693 kfree(c->mst_node); in ubifs_umount()
1694 kfree(c->write_reserve_buf); in ubifs_umount()
1695 kfree(c->bu.buf); in ubifs_umount()
1696 vfree(c->ileb_buf); in ubifs_umount()
1697 vfree(c->sbuf); in ubifs_umount()
1698 kfree(c->bottom_up_buf); in ubifs_umount()
1699 kfree(c->sup_node); in ubifs_umount()
1700 ubifs_debugging_exit(c); in ubifs_umount()
1701 ubifs_sysfs_unregister(c); in ubifs_umount()
1712 static int ubifs_remount_rw(struct ubifs_info *c) in ubifs_remount_rw() argument
1716 if (c->rw_incompat) { in ubifs_remount_rw()
1717 ubifs_err(c, "the file-system is not R/W-compatible"); in ubifs_remount_rw()
1718 …ubifs_msg(c, "on-flash format version is w%d/r%d, but software only supports up to version w%d/r%d… in ubifs_remount_rw()
1719 c->fmt_version, c->ro_compat_version, in ubifs_remount_rw()
1724 mutex_lock(&c->umount_mutex); in ubifs_remount_rw()
1725 dbg_save_space_info(c); in ubifs_remount_rw()
1726 c->remounting_rw = 1; in ubifs_remount_rw()
1727 c->ro_mount = 0; in ubifs_remount_rw()
1729 if (c->space_fixup) { in ubifs_remount_rw()
1730 err = ubifs_fixup_free_space(c); in ubifs_remount_rw()
1735 err = check_free_space(c); in ubifs_remount_rw()
1739 if (c->need_recovery) { in ubifs_remount_rw()
1740 ubifs_msg(c, "completing deferred recovery"); in ubifs_remount_rw()
1741 err = ubifs_write_rcvrd_mst_node(c); in ubifs_remount_rw()
1744 if (!ubifs_authenticated(c)) { in ubifs_remount_rw()
1745 err = ubifs_recover_size(c, true); in ubifs_remount_rw()
1749 err = ubifs_clean_lebs(c, c->sbuf); in ubifs_remount_rw()
1752 err = ubifs_recover_inl_heads(c, c->sbuf); in ubifs_remount_rw()
1757 ubifs_assert(c, c->tot_orphans == 0); in ubifs_remount_rw()
1758 err = ubifs_clear_orphans(c); in ubifs_remount_rw()
1763 if (!(c->mst_node->flags & cpu_to_le32(UBIFS_MST_DIRTY))) { in ubifs_remount_rw()
1764 c->mst_node->flags |= cpu_to_le32(UBIFS_MST_DIRTY); in ubifs_remount_rw()
1765 err = ubifs_write_master(c); in ubifs_remount_rw()
1770 if (c->superblock_need_write) { in ubifs_remount_rw()
1771 struct ubifs_sb_node *sup = c->sup_node; in ubifs_remount_rw()
1773 err = ubifs_write_sb_node(c, sup); in ubifs_remount_rw()
1777 c->superblock_need_write = 0; in ubifs_remount_rw()
1780 c->ileb_buf = vmalloc(c->leb_size); in ubifs_remount_rw()
1781 if (!c->ileb_buf) { in ubifs_remount_rw()
1786 c->write_reserve_buf = kmalloc(COMPRESSED_DATA_NODE_BUF_SZ + \ in ubifs_remount_rw()
1788 if (!c->write_reserve_buf) { in ubifs_remount_rw()
1793 err = ubifs_lpt_init(c, 0, 1); in ubifs_remount_rw()
1798 c->bgt = kthread_run(ubifs_bg_thread, c, "%s", c->bgt_name); in ubifs_remount_rw()
1799 if (IS_ERR(c->bgt)) { in ubifs_remount_rw()
1800 err = PTR_ERR(c->bgt); in ubifs_remount_rw()
1801 c->bgt = NULL; in ubifs_remount_rw()
1802 ubifs_err(c, "cannot spawn \"%s\", error %d", in ubifs_remount_rw()
1803 c->bgt_name, err); in ubifs_remount_rw()
1807 c->orph_buf = vmalloc(c->leb_size); in ubifs_remount_rw()
1808 if (!c->orph_buf) { in ubifs_remount_rw()
1814 lnum = c->lhead_lnum + 1; in ubifs_remount_rw()
1815 if (lnum >= UBIFS_LOG_LNUM + c->log_lebs) in ubifs_remount_rw()
1817 if (lnum == c->ltail_lnum) { in ubifs_remount_rw()
1818 err = ubifs_consolidate_log(c); in ubifs_remount_rw()
1823 if (c->need_recovery) { in ubifs_remount_rw()
1824 err = ubifs_rcvry_gc_commit(c); in ubifs_remount_rw()
1828 if (ubifs_authenticated(c)) { in ubifs_remount_rw()
1829 err = ubifs_recover_size(c, false); in ubifs_remount_rw()
1834 err = ubifs_leb_unmap(c, c->gc_lnum); in ubifs_remount_rw()
1840 c->remounting_rw = 0; in ubifs_remount_rw()
1842 if (c->need_recovery) { in ubifs_remount_rw()
1843 c->need_recovery = 0; in ubifs_remount_rw()
1844 ubifs_msg(c, "deferred recovery completed"); in ubifs_remount_rw()
1856 err = dbg_check_space_info(c); in ubifs_remount_rw()
1859 mutex_unlock(&c->umount_mutex); in ubifs_remount_rw()
1863 c->ro_mount = 1; in ubifs_remount_rw()
1864 vfree(c->orph_buf); in ubifs_remount_rw()
1865 c->orph_buf = NULL; in ubifs_remount_rw()
1866 if (c->bgt) { in ubifs_remount_rw()
1867 kthread_stop(c->bgt); in ubifs_remount_rw()
1868 c->bgt = NULL; in ubifs_remount_rw()
1870 kfree(c->write_reserve_buf); in ubifs_remount_rw()
1871 c->write_reserve_buf = NULL; in ubifs_remount_rw()
1872 vfree(c->ileb_buf); in ubifs_remount_rw()
1873 c->ileb_buf = NULL; in ubifs_remount_rw()
1874 ubifs_lpt_free(c, 1); in ubifs_remount_rw()
1875 c->remounting_rw = 0; in ubifs_remount_rw()
1876 mutex_unlock(&c->umount_mutex); in ubifs_remount_rw()
1887 static void ubifs_remount_ro(struct ubifs_info *c) in ubifs_remount_ro() argument
1891 ubifs_assert(c, !c->need_recovery); in ubifs_remount_ro()
1892 ubifs_assert(c, !c->ro_mount); in ubifs_remount_ro()
1894 mutex_lock(&c->umount_mutex); in ubifs_remount_ro()
1895 if (c->bgt) { in ubifs_remount_ro()
1896 kthread_stop(c->bgt); in ubifs_remount_ro()
1897 c->bgt = NULL; in ubifs_remount_ro()
1900 dbg_save_space_info(c); in ubifs_remount_ro()
1902 for (i = 0; i < c->jhead_cnt; i++) { in ubifs_remount_ro()
1903 err = ubifs_wbuf_sync(&c->jheads[i].wbuf); in ubifs_remount_ro()
1905 ubifs_ro_mode(c, err); in ubifs_remount_ro()
1908 c->mst_node->flags &= ~cpu_to_le32(UBIFS_MST_DIRTY); in ubifs_remount_ro()
1909 c->mst_node->flags |= cpu_to_le32(UBIFS_MST_NO_ORPHS); in ubifs_remount_ro()
1910 c->mst_node->gc_lnum = cpu_to_le32(c->gc_lnum); in ubifs_remount_ro()
1911 err = ubifs_write_master(c); in ubifs_remount_ro()
1913 ubifs_ro_mode(c, err); in ubifs_remount_ro()
1915 vfree(c->orph_buf); in ubifs_remount_ro()
1916 c->orph_buf = NULL; in ubifs_remount_ro()
1917 kfree(c->write_reserve_buf); in ubifs_remount_ro()
1918 c->write_reserve_buf = NULL; in ubifs_remount_ro()
1919 vfree(c->ileb_buf); in ubifs_remount_ro()
1920 c->ileb_buf = NULL; in ubifs_remount_ro()
1921 ubifs_lpt_free(c, 1); in ubifs_remount_ro()
1922 c->ro_mount = 1; in ubifs_remount_ro()
1923 err = dbg_check_space_info(c); in ubifs_remount_ro()
1925 ubifs_ro_mode(c, err); in ubifs_remount_ro()
1926 mutex_unlock(&c->umount_mutex); in ubifs_remount_ro()
1932 struct ubifs_info *c = sb->s_fs_info; in ubifs_put_super() local
1934 ubifs_msg(c, "un-mount UBI device %d", c->vi.ubi_num); in ubifs_put_super()
1941 if (!c->ro_error) { in ubifs_put_super()
1942 ubifs_assert(c, c->bi.idx_growth == 0); in ubifs_put_super()
1943 ubifs_assert(c, c->bi.dd_growth == 0); in ubifs_put_super()
1944 ubifs_assert(c, c->bi.data_growth == 0); in ubifs_put_super()
1953 mutex_lock(&c->umount_mutex); in ubifs_put_super()
1954 if (!c->ro_mount) { in ubifs_put_super()
1959 if (c->bgt) { in ubifs_put_super()
1960 kthread_stop(c->bgt); in ubifs_put_super()
1961 c->bgt = NULL; in ubifs_put_super()
1968 if (!c->ro_error) { in ubifs_put_super()
1972 for (i = 0; i < c->jhead_cnt; i++) { in ubifs_put_super()
1973 err = ubifs_wbuf_sync(&c->jheads[i].wbuf); in ubifs_put_super()
1975 ubifs_ro_mode(c, err); in ubifs_put_super()
1983 c->mst_node->flags &= ~cpu_to_le32(UBIFS_MST_DIRTY); in ubifs_put_super()
1984 c->mst_node->flags |= cpu_to_le32(UBIFS_MST_NO_ORPHS); in ubifs_put_super()
1985 c->mst_node->gc_lnum = cpu_to_le32(c->gc_lnum); in ubifs_put_super()
1986 err = ubifs_write_master(c); in ubifs_put_super()
1993 ubifs_err(c, "failed to write master node, error %d", in ubifs_put_super()
1996 for (i = 0; i < c->jhead_cnt; i++) in ubifs_put_super()
1998 hrtimer_cancel(&c->jheads[i].wbuf.timer); in ubifs_put_super()
2002 ubifs_umount(c); in ubifs_put_super()
2003 ubi_close_volume(c->ubi); in ubifs_put_super()
2004 mutex_unlock(&c->umount_mutex); in ubifs_put_super()
2010 struct ubifs_info *c = sb->s_fs_info; in ubifs_remount_fs() local
2015 err = ubifs_parse_options(c, data, 1); in ubifs_remount_fs()
2017 ubifs_err(c, "invalid or unknown remount parameter"); in ubifs_remount_fs()
2021 if (c->ro_mount && !(*flags & SB_RDONLY)) { in ubifs_remount_fs()
2022 if (c->ro_error) { in ubifs_remount_fs()
2023 ubifs_msg(c, "cannot re-mount R/W due to prior errors"); in ubifs_remount_fs()
2026 if (c->ro_media) { in ubifs_remount_fs()
2027 ubifs_msg(c, "cannot re-mount R/W - UBI volume is R/O"); in ubifs_remount_fs()
2030 err = ubifs_remount_rw(c); in ubifs_remount_fs()
2033 } else if (!c->ro_mount && (*flags & SB_RDONLY)) { in ubifs_remount_fs()
2034 if (c->ro_error) { in ubifs_remount_fs()
2035 ubifs_msg(c, "cannot re-mount R/O due to prior errors"); in ubifs_remount_fs()
2038 ubifs_remount_ro(c); in ubifs_remount_fs()
2041 if (c->bulk_read == 1) in ubifs_remount_fs()
2042 bu_init(c); in ubifs_remount_fs()
2045 mutex_lock(&c->bu_mutex); in ubifs_remount_fs()
2046 kfree(c->bu.buf); in ubifs_remount_fs()
2047 c->bu.buf = NULL; in ubifs_remount_fs()
2048 mutex_unlock(&c->bu_mutex); in ubifs_remount_fs()
2051 if (!c->need_recovery) in ubifs_remount_fs()
2052 ubifs_assert(c, c->lst.taken_empty_lebs > 0); in ubifs_remount_fs()
2138 struct ubifs_info *c; in alloc_ubifs_info() local
2140 c = kzalloc(sizeof(struct ubifs_info), GFP_KERNEL); in alloc_ubifs_info()
2141 if (c) { in alloc_ubifs_info()
2142 spin_lock_init(&c->cnt_lock); in alloc_ubifs_info()
2143 spin_lock_init(&c->cs_lock); in alloc_ubifs_info()
2144 spin_lock_init(&c->buds_lock); in alloc_ubifs_info()
2145 spin_lock_init(&c->space_lock); in alloc_ubifs_info()
2146 spin_lock_init(&c->orphan_lock); in alloc_ubifs_info()
2147 init_rwsem(&c->commit_sem); in alloc_ubifs_info()
2148 mutex_init(&c->lp_mutex); in alloc_ubifs_info()
2149 mutex_init(&c->tnc_mutex); in alloc_ubifs_info()
2150 mutex_init(&c->log_mutex); in alloc_ubifs_info()
2151 mutex_init(&c->umount_mutex); in alloc_ubifs_info()
2152 mutex_init(&c->bu_mutex); in alloc_ubifs_info()
2153 mutex_init(&c->write_reserve_mutex); in alloc_ubifs_info()
2154 init_waitqueue_head(&c->cmt_wq); in alloc_ubifs_info()
2155 c->buds = RB_ROOT; in alloc_ubifs_info()
2156 c->old_idx = RB_ROOT; in alloc_ubifs_info()
2157 c->size_tree = RB_ROOT; in alloc_ubifs_info()
2158 c->orph_tree = RB_ROOT; in alloc_ubifs_info()
2159 INIT_LIST_HEAD(&c->infos_list); in alloc_ubifs_info()
2160 INIT_LIST_HEAD(&c->idx_gc); in alloc_ubifs_info()
2161 INIT_LIST_HEAD(&c->replay_list); in alloc_ubifs_info()
2162 INIT_LIST_HEAD(&c->replay_buds); in alloc_ubifs_info()
2163 INIT_LIST_HEAD(&c->uncat_list); in alloc_ubifs_info()
2164 INIT_LIST_HEAD(&c->empty_list); in alloc_ubifs_info()
2165 INIT_LIST_HEAD(&c->freeable_list); in alloc_ubifs_info()
2166 INIT_LIST_HEAD(&c->frdi_idx_list); in alloc_ubifs_info()
2167 INIT_LIST_HEAD(&c->unclean_leb_list); in alloc_ubifs_info()
2168 INIT_LIST_HEAD(&c->old_buds); in alloc_ubifs_info()
2169 INIT_LIST_HEAD(&c->orph_list); in alloc_ubifs_info()
2170 INIT_LIST_HEAD(&c->orph_new); in alloc_ubifs_info()
2171 c->no_chk_data_crc = 1; in alloc_ubifs_info()
2172 c->assert_action = ASSACT_RO; in alloc_ubifs_info()
2174 c->highest_inum = UBIFS_FIRST_INO; in alloc_ubifs_info()
2175 c->lhead_lnum = c->ltail_lnum = UBIFS_LOG_LNUM; in alloc_ubifs_info()
2177 ubi_get_volume_info(ubi, &c->vi); in alloc_ubifs_info()
2178 ubi_get_device_info(c->vi.ubi_num, &c->di); in alloc_ubifs_info()
2180 return c; in alloc_ubifs_info()
2185 struct ubifs_info *c = sb->s_fs_info; in ubifs_fill_super() local
2189 c->vfs_sb = sb; in ubifs_fill_super()
2191 c->ubi = ubi_open_volume(c->vi.ubi_num, c->vi.vol_id, UBI_READWRITE); in ubifs_fill_super()
2192 if (IS_ERR(c->ubi)) { in ubifs_fill_super()
2193 err = PTR_ERR(c->ubi); in ubifs_fill_super()
2197 err = ubifs_parse_options(c, data, 0); in ubifs_fill_super()
2211 err = super_setup_bdi_name(sb, "ubifs_%d_%d", c->vi.ubi_num, in ubifs_fill_super()
2212 c->vi.vol_id); in ubifs_fill_super()
2218 sb->s_fs_info = c; in ubifs_fill_super()
2222 sb->s_maxbytes = c->max_inode_sz = key_max_inode_size(c); in ubifs_fill_super()
2223 if (c->max_inode_sz > MAX_LFS_FILESIZE) in ubifs_fill_super()
2224 sb->s_maxbytes = c->max_inode_sz = MAX_LFS_FILESIZE; in ubifs_fill_super()
2229 mutex_lock(&c->umount_mutex); in ubifs_fill_super()
2230 err = mount_ubifs(c); in ubifs_fill_super()
2232 ubifs_assert(c, err < 0); in ubifs_fill_super()
2249 import_uuid(&sb->s_uuid, c->uuid); in ubifs_fill_super()
2251 mutex_unlock(&c->umount_mutex); in ubifs_fill_super()
2255 ubifs_umount(c); in ubifs_fill_super()
2257 mutex_unlock(&c->umount_mutex); in ubifs_fill_super()
2259 ubifs_release_options(c); in ubifs_fill_super()
2260 ubi_close_volume(c->ubi); in ubifs_fill_super()
2268 struct ubifs_info *c = sb->s_fs_info; in sb_test() local
2270 return c->vi.cdev == c1->vi.cdev; in sb_test()
2283 struct ubifs_info *c; in ubifs_mount() local
2302 c = alloc_ubifs_info(ubi); in ubifs_mount()
2303 if (!c) { in ubifs_mount()
2308 dbg_gen("opened ubi%d_%d", c->vi.ubi_num, c->vi.vol_id); in ubifs_mount()
2310 sb = sget(fs_type, sb_test, sb_set, flags, c); in ubifs_mount()
2313 kfree(c); in ubifs_mount()
2319 kfree(c); in ubifs_mount()
2333 ubifs_msg(c, "full atime support is enabled."); in ubifs_mount()
2352 struct ubifs_info *c = s->s_fs_info; in kill_ubifs_super() local
2354 kfree(c); in kill_ubifs_super()