Lines Matching refs:fs

200     uint32_t block_size = tr->fs->super_dev->block_size;  in update_super_block_internal()
204 if (!tr->fs->writable) { in update_super_block_internal()
213 assert(tr->fs->initial_super_block_tr == NULL || in update_super_block_internal()
214 tr->fs->initial_super_block_tr == tr); in update_super_block_internal()
216 ver = (tr->fs->super_block_version + 1) & SUPER_BLOCK_FLAGS_VERSION_MASK; in update_super_block_internal()
230 if (tr->fs->alternate_data) { in update_super_block_internal()
233 if (tr->repaired || tr->fs->main_repaired) { in update_super_block_internal()
240 assert(!tr->repaired || !tr->fs->alternate_data); in update_super_block_internal()
254 if (tr->fs->needs_full_scan) { in update_super_block_internal()
259 tr->fs->super_block[index], ver); in update_super_block_internal()
261 super_rw = block_get_cleared_super(tr, tr->fs->super_block[index], in update_super_block_internal()
272 super_rw->block_size = tr->fs->dev->block_size; in update_super_block_internal()
273 super_rw->block_num_size = tr->fs->block_num_size; in update_super_block_internal()
274 super_rw->mac_size = tr->fs->mac_size; in update_super_block_internal()
276 super_rw->block_count = tr->fs->dev->block_count; in update_super_block_internal()
288 super_rw->backup = tr->fs->backup; in update_super_block_internal()
290 tr->fs->written_super_block_version = ver; in update_super_block_internal()
292 block_put_dirty_no_mac(super_rw, &super_ref, tr->fs->allow_tampering); in update_super_block_internal()
325 static bool write_initial_super_block(struct fs* fs) { in write_initial_super_block() argument
331 fs->initial_super_block_tr = tr; in write_initial_super_block()
333 transaction_init(tr, fs, true); in write_initial_super_block()
350 void write_current_super_block(struct fs* fs, bool reinitialize) { in write_current_super_block() argument
354 assert(fs->writable); in write_current_super_block()
356 if (fs->initial_super_block_tr) { in write_current_super_block()
383 assert(reinitialize || !fs->initial_super_block_tr->failed); in write_current_super_block()
384 if (!fs->initial_super_block_tr->failed || !reinitialize) { in write_current_super_block()
388 tr = fs->initial_super_block_tr; in write_current_super_block()
396 transaction_init(tr, fs, true); in write_current_super_block()
397 fs->initial_super_block_tr = tr; in write_current_super_block()
413 bool fs_is_cleared = !block_mac_valid(tr, &fs->free.block_tree.root); in write_current_super_block()
415 assert(!block_mac_valid(tr, &fs->files.root)); in write_current_super_block()
420 tr, &fs->free.block_tree.root, &fs->files.root, &fs->checkpoint, in write_current_super_block()
442 void fs_mark_scan_required(struct fs* fs) { in fs_mark_scan_required() argument
443 fs->needs_full_scan = true; in fs_mark_scan_required()
444 if (!fs->writable) { in fs_mark_scan_required()
448 write_current_super_block(fs, false); in fs_mark_scan_required()
449 assert(fs->initial_super_block_tr); in fs_mark_scan_required()
450 transaction_initial_super_block_complete(fs->initial_super_block_tr); in fs_mark_scan_required()
569 static void fs_init_free_set(struct fs* fs, struct block_set* set);
591 static bool fs_set_roots(struct fs* fs, in fs_set_roots() argument
603 fs->free.block_tree.root = *free; in fs_set_roots()
604 fs->files.root = *files; in fs_set_roots()
607 fs->checkpoint = *checkpoint; in fs_set_roots()
608 transaction_init(&tr, fs, true); in fs_set_roots()
614 assert(!block_range_empty(fs->checkpoint_free.initial_range)); in fs_set_roots()
616 if (block_mac_valid(&tr, &fs->checkpoint)) { in fs_set_roots()
617 success = checkpoint_read(&tr, &fs->checkpoint, &checkpoint_files, in fs_set_roots()
618 &fs->checkpoint_free); in fs_set_roots()
629 fs->main_repaired = true; in fs_set_roots()
630 fs->files.root = checkpoint_files.root; in fs_set_roots()
631 block_set_copy_ro(&tr, &fs->free, &fs->checkpoint_free); in fs_set_roots()
636 fs->free.block_tree.copy_on_write = true; in fs_set_roots()
655 static void fs_init_free_set(struct fs* fs, struct block_set* set) { in fs_init_free_set() argument
657 .start = fs->min_block_num, in fs_init_free_set()
658 .end = fs->dev->block_count, in fs_init_free_set()
674 static int fs_init_from_super(struct fs* fs, in fs_init_from_super() argument
698 fs->block_num_size = fs->dev->block_num_size; in fs_init_from_super()
699 fs->mac_size = fs->dev->mac_size; in fs_init_from_super()
701 block_set_init(fs, &fs->free); in fs_init_from_super()
702 fs->free.block_tree.copy_on_write = true; in fs_init_from_super()
703 fs_file_tree_init(fs, &fs->files); in fs_init_from_super()
704 fs->files.copy_on_write = true; in fs_init_from_super()
705 fs->files.allow_copy_on_write = true; in fs_init_from_super()
706 fs->main_repaired = false; in fs_init_from_super()
708 memset(&fs->checkpoint, 0, sizeof(fs->checkpoint)); in fs_init_from_super()
709 block_set_init(fs, &fs->checkpoint_free); in fs_init_from_super()
714 fs_init_free_set(fs, &fs->checkpoint_free); in fs_init_from_super()
717 fs->reserved_count = fs->dev->block_count / 8 * 5; in fs_init_from_super()
719 fs->alternate_data = flags & FS_INIT_FLAGS_ALTERNATE_DATA; in fs_init_from_super()
730 error_report_superblock_invalid(fs->name); in fs_init_from_super()
731 assert(!fs->readable); in fs_init_from_super()
732 assert(!fs->writable); in fs_init_from_super()
739 error_report_superblock_invalid(fs->name); in fs_init_from_super()
740 assert(!fs->readable); in fs_init_from_super()
741 assert(!fs->writable); in fs_init_from_super()
746 fs->super_block_version = super->flags & SUPER_BLOCK_FLAGS_VERSION_MASK; in fs_init_from_super()
747 fs->needs_full_scan = in fs_init_from_super()
749 fs->main_repaired = super->required_flags & in fs_init_from_super()
758 fs->backup.flags = super->flags & (SUPER_BLOCK_FLAGS_EMPTY | in fs_init_from_super()
760 fs->backup.free = super->free; in fs_init_from_super()
761 fs->backup.files = super->files; in fs_init_from_super()
762 fs->backup.checkpoint = super->checkpoint; in fs_init_from_super()
776 fs->backup = super->backup; in fs_init_from_super()
791 (!block_probe(fs, new_files_root, true) || in fs_init_from_super()
792 !block_probe(fs, new_free_root, false))) { in fs_init_from_super()
804 if (super->block_count > fs->dev->block_count) { in fs_init_from_super()
814 super->block_count, fs->dev->block_count); in fs_init_from_super()
826 assert(!fs->readable); in fs_init_from_super()
827 assert(!fs->writable); in fs_init_from_super()
839 if (!fs->alternate_data && (flags & FS_INIT_FLAGS_RESTORE_CHECKPOINT)) { in fs_init_from_super()
840 fs->needs_full_scan = false; in fs_init_from_super()
852 fs->backup = (struct super_block_backup){ in fs_init_from_super()
861 if (!fs_set_roots(fs, new_free_root, new_files_root, new_checkpoint, in fs_init_from_super()
867 pr_err("fs %s: failed to initialize filesystem roots\n", fs->name); in fs_init_from_super()
871 fs->name, fs->super_block_version, in fs_init_from_super()
872 block_range_empty(fs->checkpoint_free.initial_range)); in fs_init_from_super()
876 pr_init("fs %s: superblock, version %d, is empty fs\n", fs->name, in fs_init_from_super()
877 fs->super_block_version); in fs_init_from_super()
880 fs->name, fs->super_block_version); in fs_init_from_super()
881 if (!fs->alternate_data) { in fs_init_from_super()
882 fs->main_repaired = false; in fs_init_from_super()
883 fs->needs_full_scan = false; in fs_init_from_super()
887 fs->name); in fs_init_from_super()
889 fs_init_free_set(fs, &fs->free); in fs_init_from_super()
891 assert(fs->block_num_size >= fs->dev->block_num_size); in fs_init_from_super()
892 assert(fs->block_num_size <= sizeof(data_block_t)); in fs_init_from_super()
893 assert(fs->mac_size >= fs->dev->mac_size); in fs_init_from_super()
894 assert(fs->mac_size <= sizeof(struct mac)); in fs_init_from_super()
895 assert(fs->mac_size == sizeof(struct mac) || fs->dev->tamper_detecting); in fs_init_from_super()
902 fs->readable = true; in fs_init_from_super()
905 assert(!fs->writable); in fs_init_from_super()
909 fs->writable = true; in fs_init_from_super()
911 if (!write_initial_super_block(fs)) { in fs_init_from_super()
922 assert(!fs->initial_super_block_tr); in fs_init_from_super()
923 write_current_super_block(fs, false); in fs_init_from_super()
937 static int load_super_block(struct fs* fs, fs_init_flags32_t flags) { in load_super_block() argument
945 assert(fs->super_dev->block_size >= sizeof(struct super_block)); in load_super_block()
947 for (i = 0; i < countof(fs->super_block); i++) { in load_super_block()
948 new_super = block_get_super(fs, fs->super_block[i], &new_super_ref); in load_super_block()
950 if (fs->allow_tampering) { in load_super_block()
961 if (use_new_super(fs->dev, new_super, i, old_super)) { in load_super_block()
972 ret = fs_init_from_super(fs, old_super, flags); in load_super_block()
1043 enum fs_check_result fs_check_full(struct fs* fs) { in fs_check_full() argument
1053 transaction_init(&iterate_tr, fs, true); in fs_check_full()
1056 free_set_valid = block_set_check(&iterate_tr, &fs->free); in fs_check_full()
1073 file_tree_valid = block_tree_check(&iterate_tr, &fs->files); in fs_check_full()
1105 enum fs_check_result fs_check_quick(struct fs* fs) { in fs_check_quick() argument
1106 bool fs_is_clear = !block_range_empty(fs->free.initial_range); in fs_check_quick()
1107 if (fs_is_clear || (block_probe(fs, &fs->files.root, true) && in fs_check_quick()
1108 block_probe(fs, &fs->free.block_tree.root, false))) { in fs_check_quick()
1115 enum fs_check_result fs_check(struct fs* fs) { in fs_check() argument
1116 if (fs->needs_full_scan) { in fs_check()
1117 pr_warn("%s filesystem requires full scan on mount\n", fs->name); in fs_check()
1118 return fs_check_full(fs); in fs_check()
1120 return fs_check_quick(fs); in fs_check()
1129 void fs_file_tree_init(const struct fs* fs, struct block_tree* tree) { in fs_file_tree_init() argument
1133 block_num_size = fs->block_num_size; in fs_file_tree_init()
1134 block_mac_size = block_num_size + fs->mac_size; in fs_file_tree_init()
1135 block_tree_init(tree, fs->dev->block_size, block_num_size, block_mac_size, in fs_file_tree_init()
1148 int fs_init(struct fs* fs, in fs_init() argument
1174 fs->name = name; in fs_init()
1175 fs->key = key; in fs_init()
1176 fs->dev = dev; in fs_init()
1177 fs->super_dev = super_dev; in fs_init()
1178 fs->readable = false; in fs_init()
1179 fs->writable = false; in fs_init()
1180 fs->allow_tampering = flags & FS_INIT_FLAGS_ALLOW_TAMPERING; in fs_init()
1181 fs->checkpoint_required = false; in fs_init()
1182 list_initialize(&fs->transactions); in fs_init()
1183 list_initialize(&fs->allocated); in fs_init()
1184 fs->initial_super_block_tr = NULL; in fs_init()
1185 list_add_tail(&fs_list, &fs->node); in fs_init()
1188 fs->min_block_num = 2; in fs_init()
1191 fs->min_block_num = 1; in fs_init()
1193 fs->super_block[0] = 0; in fs_init()
1194 fs->super_block[1] = 1; in fs_init()
1195 ret = load_super_block(fs, flags); in fs_init()
1197 fs_destroy(fs); in fs_init()
1198 fs->dev = NULL; in fs_init()
1199 fs->super_dev = NULL; in fs_init()
1204 !block_mac_valid_fs(fs, &fs->checkpoint)) { in fs_init()
1205 if (fs_check_full(fs) == FS_CHECK_NO_ERROR) { in fs_init()
1206 fs->checkpoint_required = true; in fs_init()
1210 fs->name); in fs_init()
1224 void fs_destroy(struct fs* fs) { in fs_destroy() argument
1225 if (fs->initial_super_block_tr) { in fs_destroy()
1226 if (!fs->initial_super_block_tr->failed) { in fs_destroy()
1227 transaction_fail(fs->initial_super_block_tr); in fs_destroy()
1229 transaction_free(fs->initial_super_block_tr); in fs_destroy()
1230 free(fs->initial_super_block_tr); in fs_destroy()
1231 fs->initial_super_block_tr = NULL; in fs_destroy()
1233 assert(list_is_empty(&fs->transactions)); in fs_destroy()
1234 assert(list_is_empty(&fs->allocated)); in fs_destroy()
1235 list_delete(&fs->node); in fs_destroy()
1236 fs->readable = false; in fs_destroy()
1237 fs->writable = false; in fs_destroy()
1249 struct fs* fs; in fs_unknown_super_block_state_all() local
1250 list_for_every_entry(&fs_list, fs, struct fs, node) { in fs_unknown_super_block_state_all()
1268 if (fs->writable) { in fs_unknown_super_block_state_all()
1269 write_current_super_block(fs, false /* reinitialize */); in fs_unknown_super_block_state_all()
1277 struct fs* fs; in fs_fail_all_transactions() local
1278 list_for_every_entry(&fs_list, fs, struct fs, node) { in fs_fail_all_transactions()
1279 list_for_every_entry_safe(&fs->transactions, tr, tmp_tr, in fs_fail_all_transactions()