• Home
  • Raw
  • Download

Lines Matching refs:c

88 static int set_bud_lprops(struct ubifs_info *c, struct bud_entry *b)  in set_bud_lprops()  argument
93 ubifs_get_lprops(c); in set_bud_lprops()
95 lp = ubifs_lpt_lookup_dirty(c, b->bud->lnum); in set_bud_lprops()
102 if (b->bud->start == 0 && (lp->free != c->leb_size || lp->dirty != 0)) { in set_bud_lprops()
126 dirty -= c->leb_size - lp->free; in set_bud_lprops()
139 lp = ubifs_change_lp(c, lp, b->free, dirty + b->dirty, in set_bud_lprops()
147 err = ubifs_wbuf_seek_nolock(&c->jheads[b->bud->jhead].wbuf, in set_bud_lprops()
148 b->bud->lnum, c->leb_size - b->free); in set_bud_lprops()
151 ubifs_release_lprops(c); in set_bud_lprops()
162 static int set_buds_lprops(struct ubifs_info *c) in set_buds_lprops() argument
167 list_for_each_entry(b, &c->replay_buds, list) { in set_buds_lprops()
168 err = set_bud_lprops(c, b); in set_buds_lprops()
181 static int trun_remove_range(struct ubifs_info *c, struct replay_entry *r) in trun_remove_range() argument
195 ino = key_inum(c, &r->key); in trun_remove_range()
197 data_key_init(c, &min_key, ino, min_blk); in trun_remove_range()
198 data_key_init(c, &max_key, ino, max_blk); in trun_remove_range()
200 return ubifs_tnc_remove_range(c, &min_key, &max_key); in trun_remove_range()
213 static bool inode_still_linked(struct ubifs_info *c, struct replay_entry *rino) in inode_still_linked() argument
217 ubifs_assert(c, rino->deletion); in inode_still_linked()
218 ubifs_assert(c, key_type(c, &rino->key) == UBIFS_INO_KEY); in inode_still_linked()
224 list_for_each_entry_reverse(r, &c->replay_list, list) { in inode_still_linked()
225 ubifs_assert(c, r->sqnum >= rino->sqnum); in inode_still_linked()
226 if (key_inum(c, &r->key) == key_inum(c, &rino->key)) in inode_still_linked()
231 ubifs_assert(c, 0); in inode_still_linked()
242 static int apply_replay_entry(struct ubifs_info *c, struct replay_entry *r) in apply_replay_entry() argument
249 if (is_hash_key(c, &r->key)) { in apply_replay_entry()
251 err = ubifs_tnc_remove_nm(c, &r->key, &r->nm); in apply_replay_entry()
253 err = ubifs_tnc_add_nm(c, &r->key, r->lnum, r->offs, in apply_replay_entry()
257 switch (key_type(c, &r->key)) { in apply_replay_entry()
260 ino_t inum = key_inum(c, &r->key); in apply_replay_entry()
262 if (inode_still_linked(c, r)) { in apply_replay_entry()
267 err = ubifs_tnc_remove_ino(c, inum); in apply_replay_entry()
271 err = trun_remove_range(c, r); in apply_replay_entry()
274 err = ubifs_tnc_remove(c, &r->key); in apply_replay_entry()
278 err = ubifs_tnc_add(c, &r->key, r->lnum, r->offs, in apply_replay_entry()
283 if (c->need_recovery) in apply_replay_entry()
284 err = ubifs_recover_size_accum(c, &r->key, r->deletion, in apply_replay_entry()
304 struct ubifs_info *c = priv; in replay_entries_cmp() local
313 ubifs_assert(c, ra->sqnum != rb->sqnum); in replay_entries_cmp()
326 static int apply_replay_list(struct ubifs_info *c) in apply_replay_list() argument
331 list_sort(c, &c->replay_list, &replay_entries_cmp); in apply_replay_list()
333 list_for_each_entry(r, &c->replay_list, list) { in apply_replay_list()
336 err = apply_replay_entry(c, r); in apply_replay_list()
350 static void destroy_replay_list(struct ubifs_info *c) in destroy_replay_list() argument
354 list_for_each_entry_safe(r, tmp, &c->replay_list, list) { in destroy_replay_list()
355 if (is_hash_key(c, &r->key)) in destroy_replay_list()
382 static int insert_node(struct ubifs_info *c, int lnum, int offs, int len, in insert_node() argument
391 if (key_inum(c, key) >= c->highest_inum) in insert_node()
392 c->highest_inum = key_inum(c, key); in insert_node()
403 ubifs_copy_hash(c, hash, r->hash); in insert_node()
406 key_copy(c, key, &r->key); in insert_node()
410 list_add_tail(&r->list, &c->replay_list); in insert_node()
431 static int insert_dent(struct ubifs_info *c, int lnum, int offs, int len, in insert_dent() argument
440 if (key_inum(c, key) >= c->highest_inum) in insert_dent()
441 c->highest_inum = key_inum(c, key); in insert_dent()
458 ubifs_copy_hash(c, hash, r->hash); in insert_dent()
461 key_copy(c, key, &r->key); in insert_dent()
467 list_add_tail(&r->list, &c->replay_list); in insert_dent()
479 int ubifs_validate_entry(struct ubifs_info *c, in ubifs_validate_entry() argument
482 int key_type = key_type_flash(c, dent->key); in ubifs_validate_entry()
490 ubifs_err(c, "bad %s node", key_type == UBIFS_DENT_KEY ? in ubifs_validate_entry()
496 ubifs_err(c, "bad key type %d", key_type); in ubifs_validate_entry()
513 static int is_last_bud(struct ubifs_info *c, struct ubifs_bud *bud) in is_last_bud() argument
515 struct ubifs_jhead *jh = &c->jheads[bud->jhead]; in is_last_bud()
554 err = ubifs_leb_read(c, next->lnum, (char *)&data, next->start, 4, 1); in is_last_bud()
562 static int authenticate_sleb_hash(struct ubifs_info *c, struct shash_desc *log_hash, u8 *hash) in authenticate_sleb_hash() argument
564 SHASH_DESC_ON_STACK(hash_desc, c->hash_tfm); in authenticate_sleb_hash()
566 hash_desc->tfm = c->hash_tfm; in authenticate_sleb_hash()
568 ubifs_shash_copy_state(c, log_hash, hash_desc); in authenticate_sleb_hash()
572 static int authenticate_sleb_hmac(struct ubifs_info *c, u8 *hash, u8 *hmac) in authenticate_sleb_hmac() argument
574 SHASH_DESC_ON_STACK(hmac_desc, c->hmac_tfm); in authenticate_sleb_hmac()
576 hmac_desc->tfm = c->hmac_tfm; in authenticate_sleb_hmac()
578 return crypto_shash_digest(hmac_desc, hash, c->hash_len, hmac); in authenticate_sleb_hmac()
597 static int authenticate_sleb(struct ubifs_info *c, struct ubifs_scan_leb *sleb, in authenticate_sleb() argument
606 if (!ubifs_authenticated(c)) in authenticate_sleb()
609 hash = kmalloc(crypto_shash_descsize(c->hash_tfm), GFP_NOFS); in authenticate_sleb()
610 hmac = kmalloc(c->hmac_desc_len, GFP_NOFS); in authenticate_sleb()
623 err = authenticate_sleb_hash(c, log_hash, hash); in authenticate_sleb()
627 err = authenticate_sleb_hmac(c, hash, hmac); in authenticate_sleb()
631 err = ubifs_check_hmac(c, auth->hmac, hmac); in authenticate_sleb()
680 static int replay_bud(struct ubifs_info *c, struct bud_entry *b) in replay_bud() argument
682 int is_last = is_last_bud(c, b->bud); in replay_bud()
691 if (c->need_recovery && is_last) in replay_bud()
698 sleb = ubifs_recover_leb(c, lnum, offs, c->sbuf, b->bud->jhead); in replay_bud()
700 sleb = ubifs_scan(c, lnum, offs, c->sbuf, 0); in replay_bud()
704 n_nodes = authenticate_sleb(c, sleb, b->bud->log_hash, is_last); in replay_bud()
710 ubifs_shash_copy_state(c, b->bud->log_hash, in replay_bud()
711 c->jheads[b->bud->jhead].log_hash); in replay_bud()
742 ubifs_err(c, "file system's life ended"); in replay_bud()
746 ubifs_node_calc_hash(c, snod->node, hash); in replay_bud()
748 if (snod->sqnum > c->max_sqnum) in replay_bud()
749 c->max_sqnum = snod->sqnum; in replay_bud()
759 err = insert_node(c, lnum, snod->offs, snod->len, hash, in replay_bud()
768 key_block(c, &snod->key) * in replay_bud()
771 err = insert_node(c, lnum, snod->offs, snod->len, hash, in replay_bud()
781 err = ubifs_validate_entry(c, dent); in replay_bud()
785 err = insert_dent(c, lnum, snod->offs, snod->len, hash, in replay_bud()
799 if (old_size < 0 || old_size > c->max_inode_sz || in replay_bud()
800 new_size < 0 || new_size > c->max_inode_sz || in replay_bud()
802 ubifs_err(c, "bad truncation node"); in replay_bud()
810 trun_key_init(c, &key, le32_to_cpu(trun->inum)); in replay_bud()
811 err = insert_node(c, lnum, snod->offs, snod->len, hash, in replay_bud()
819 ubifs_err(c, "unexpected node type %d in bud LEB %d:%d", in replay_bud()
832 ubifs_assert(c, ubifs_search_bud(c, lnum)); in replay_bud()
833 ubifs_assert(c, sleb->endpt - offs >= used); in replay_bud()
834 ubifs_assert(c, sleb->endpt % c->min_io_size == 0); in replay_bud()
837 b->free = c->leb_size - sleb->endpt; in replay_bud()
846 ubifs_err(c, "bad node is at LEB %d:%d", lnum, snod->offs); in replay_bud()
847 ubifs_dump_node(c, snod->node); in replay_bud()
859 static int replay_buds(struct ubifs_info *c) in replay_buds() argument
865 list_for_each_entry(b, &c->replay_buds, list) { in replay_buds()
866 err = replay_bud(c, b); in replay_buds()
870 ubifs_assert(c, b->sqnum > prev_sqnum); in replay_buds()
881 static void destroy_bud_list(struct ubifs_info *c) in destroy_bud_list() argument
885 while (!list_empty(&c->replay_buds)) { in destroy_bud_list()
886 b = list_entry(c->replay_buds.next, struct bud_entry, list); in destroy_bud_list()
903 static int add_replay_bud(struct ubifs_info *c, int lnum, int offs, int jhead, in add_replay_bud() argument
925 bud->log_hash = ubifs_hash_get_desc(c); in add_replay_bud()
931 ubifs_shash_copy_state(c, c->log_hash, bud->log_hash); in add_replay_bud()
933 ubifs_add_bud(c, bud); in add_replay_bud()
937 list_add_tail(&b->list, &c->replay_buds); in add_replay_bud()
958 static int validate_ref(struct ubifs_info *c, const struct ubifs_ref_node *ref) in validate_ref() argument
970 if (jhead >= c->jhead_cnt || lnum >= c->leb_cnt || in validate_ref()
971 lnum < c->main_first || offs > c->leb_size || in validate_ref()
972 offs & (c->min_io_size - 1)) in validate_ref()
976 bud = ubifs_search_bud(c, lnum); in validate_ref()
980 ubifs_err(c, "bud at LEB %d:%d was already referred", lnum, offs); in validate_ref()
998 static int replay_log_leb(struct ubifs_info *c, int lnum, int offs, void *sbuf) in replay_log_leb() argument
1006 sleb = ubifs_scan(c, lnum, offs, sbuf, c->need_recovery); in replay_log_leb()
1008 if (PTR_ERR(sleb) != -EUCLEAN || !c->need_recovery) in replay_log_leb()
1015 sleb = ubifs_recover_log_leb(c, lnum, offs, sbuf); in replay_log_leb()
1027 if (c->cs_sqnum == 0) { in replay_log_leb()
1036 ubifs_err(c, "first log node at LEB %d:%d is not CS node", in replay_log_leb()
1040 if (le64_to_cpu(node->cmt_no) != c->cmt_no) { in replay_log_leb()
1041 ubifs_err(c, "first CS node at LEB %d:%d has wrong commit number %llu expected %llu", in replay_log_leb()
1044 c->cmt_no); in replay_log_leb()
1048 c->cs_sqnum = le64_to_cpu(node->ch.sqnum); in replay_log_leb()
1049 dbg_mnt("commit start sqnum %llu", c->cs_sqnum); in replay_log_leb()
1051 err = ubifs_shash_init(c, c->log_hash); in replay_log_leb()
1055 err = ubifs_shash_update(c, c->log_hash, node, UBIFS_CS_NODE_SZ); in replay_log_leb()
1060 if (snod->sqnum < c->cs_sqnum) { in replay_log_leb()
1074 ubifs_err(c, "first node is not at zero offset"); in replay_log_leb()
1082 ubifs_err(c, "file system's life ended"); in replay_log_leb()
1086 if (snod->sqnum < c->cs_sqnum) { in replay_log_leb()
1087 ubifs_err(c, "bad sqnum %llu, commit sqnum %llu", in replay_log_leb()
1088 snod->sqnum, c->cs_sqnum); in replay_log_leb()
1092 if (snod->sqnum > c->max_sqnum) in replay_log_leb()
1093 c->max_sqnum = snod->sqnum; in replay_log_leb()
1099 err = validate_ref(c, ref); in replay_log_leb()
1105 err = ubifs_shash_update(c, c->log_hash, ref, in replay_log_leb()
1110 err = add_replay_bud(c, le32_to_cpu(ref->lnum), in replay_log_leb()
1122 ubifs_err(c, "unexpected node in log"); in replay_log_leb()
1127 ubifs_err(c, "unexpected node in log"); in replay_log_leb()
1132 if (sleb->endpt || c->lhead_offs >= c->leb_size) { in replay_log_leb()
1133 c->lhead_lnum = lnum; in replay_log_leb()
1134 c->lhead_offs = sleb->endpt; in replay_log_leb()
1143 ubifs_err(c, "log error detected while replaying the log at LEB %d:%d", in replay_log_leb()
1145 ubifs_dump_node(c, snod->node); in replay_log_leb()
1157 static int take_ihead(struct ubifs_info *c) in take_ihead() argument
1162 ubifs_get_lprops(c); in take_ihead()
1164 lp = ubifs_lpt_lookup_dirty(c, c->ihead_lnum); in take_ihead()
1172 lp = ubifs_change_lp(c, lp, LPROPS_NC, LPROPS_NC, in take_ihead()
1181 ubifs_release_lprops(c); in take_ihead()
1193 int ubifs_replay_journal(struct ubifs_info *c) in ubifs_replay_journal() argument
1200 free = take_ihead(c); in ubifs_replay_journal()
1204 if (c->ihead_offs != c->leb_size - free) { in ubifs_replay_journal()
1205 ubifs_err(c, "bad index head LEB %d:%d", c->ihead_lnum, in ubifs_replay_journal()
1206 c->ihead_offs); in ubifs_replay_journal()
1211 c->replaying = 1; in ubifs_replay_journal()
1212 lnum = c->ltail_lnum = c->lhead_lnum; in ubifs_replay_journal()
1215 err = replay_log_leb(c, lnum, 0, c->sbuf); in ubifs_replay_journal()
1217 if (lnum != c->lhead_lnum) in ubifs_replay_journal()
1228 ubifs_err(c, "no UBIFS nodes found at the log head LEB %d:%d, possibly corrupted", in ubifs_replay_journal()
1234 lnum = ubifs_next_log_lnum(c, lnum); in ubifs_replay_journal()
1235 } while (lnum != c->ltail_lnum); in ubifs_replay_journal()
1237 err = replay_buds(c); in ubifs_replay_journal()
1241 err = apply_replay_list(c); in ubifs_replay_journal()
1245 err = set_buds_lprops(c); in ubifs_replay_journal()
1255 c->bi.uncommitted_idx = atomic_long_read(&c->dirty_zn_cnt); in ubifs_replay_journal()
1256 c->bi.uncommitted_idx *= c->max_idx_node_sz; in ubifs_replay_journal()
1258 ubifs_assert(c, c->bud_bytes <= c->max_bud_bytes || c->need_recovery); in ubifs_replay_journal()
1260 c->lhead_lnum, c->lhead_offs, c->max_sqnum, in ubifs_replay_journal()
1261 (unsigned long)c->highest_inum); in ubifs_replay_journal()
1263 destroy_replay_list(c); in ubifs_replay_journal()
1264 destroy_bud_list(c); in ubifs_replay_journal()
1265 c->replaying = 0; in ubifs_replay_journal()