• 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()
227 key_type(c, &r->key) == UBIFS_INO_KEY) in inode_still_linked()
232 ubifs_assert(c, 0); in inode_still_linked()
243 static int apply_replay_entry(struct ubifs_info *c, struct replay_entry *r) in apply_replay_entry() argument
250 if (is_hash_key(c, &r->key)) { in apply_replay_entry()
252 err = ubifs_tnc_remove_nm(c, &r->key, &r->nm); in apply_replay_entry()
254 err = ubifs_tnc_add_nm(c, &r->key, r->lnum, r->offs, in apply_replay_entry()
258 switch (key_type(c, &r->key)) { in apply_replay_entry()
261 ino_t inum = key_inum(c, &r->key); in apply_replay_entry()
263 if (inode_still_linked(c, r)) { in apply_replay_entry()
268 err = ubifs_tnc_remove_ino(c, inum); in apply_replay_entry()
272 err = trun_remove_range(c, r); in apply_replay_entry()
275 err = ubifs_tnc_remove(c, &r->key); in apply_replay_entry()
279 err = ubifs_tnc_add(c, &r->key, r->lnum, r->offs, in apply_replay_entry()
284 if (c->need_recovery) in apply_replay_entry()
285 err = ubifs_recover_size_accum(c, &r->key, r->deletion, in apply_replay_entry()
305 struct ubifs_info *c = priv; in replay_entries_cmp() local
314 ubifs_assert(c, ra->sqnum != rb->sqnum); in replay_entries_cmp()
327 static int apply_replay_list(struct ubifs_info *c) in apply_replay_list() argument
332 list_sort(c, &c->replay_list, &replay_entries_cmp); in apply_replay_list()
334 list_for_each_entry(r, &c->replay_list, list) { in apply_replay_list()
337 err = apply_replay_entry(c, r); in apply_replay_list()
351 static void destroy_replay_list(struct ubifs_info *c) in destroy_replay_list() argument
355 list_for_each_entry_safe(r, tmp, &c->replay_list, list) { in destroy_replay_list()
356 if (is_hash_key(c, &r->key)) in destroy_replay_list()
383 static int insert_node(struct ubifs_info *c, int lnum, int offs, int len, in insert_node() argument
392 if (key_inum(c, key) >= c->highest_inum) in insert_node()
393 c->highest_inum = key_inum(c, key); in insert_node()
404 ubifs_copy_hash(c, hash, r->hash); in insert_node()
407 key_copy(c, key, &r->key); in insert_node()
411 list_add_tail(&r->list, &c->replay_list); in insert_node()
432 static int insert_dent(struct ubifs_info *c, int lnum, int offs, int len, in insert_dent() argument
441 if (key_inum(c, key) >= c->highest_inum) in insert_dent()
442 c->highest_inum = key_inum(c, key); in insert_dent()
459 ubifs_copy_hash(c, hash, r->hash); in insert_dent()
462 key_copy(c, key, &r->key); in insert_dent()
468 list_add_tail(&r->list, &c->replay_list); in insert_dent()
480 int ubifs_validate_entry(struct ubifs_info *c, in ubifs_validate_entry() argument
483 int key_type = key_type_flash(c, dent->key); in ubifs_validate_entry()
491 ubifs_err(c, "bad %s node", key_type == UBIFS_DENT_KEY ? in ubifs_validate_entry()
497 ubifs_err(c, "bad key type %d", key_type); in ubifs_validate_entry()
514 static int is_last_bud(struct ubifs_info *c, struct ubifs_bud *bud) in is_last_bud() argument
516 struct ubifs_jhead *jh = &c->jheads[bud->jhead]; in is_last_bud()
555 err = ubifs_leb_read(c, next->lnum, (char *)&data, next->start, 4, 1); in is_last_bud()
564 authenticate_sleb_hash(struct ubifs_info *c, in authenticate_sleb_hash() argument
567 SHASH_DESC_ON_STACK(hash_desc, c->hash_tfm); in authenticate_sleb_hash()
569 hash_desc->tfm = c->hash_tfm; in authenticate_sleb_hash()
571 ubifs_shash_copy_state(c, log_hash, hash_desc); in authenticate_sleb_hash()
591 static int authenticate_sleb(struct ubifs_info *c, struct ubifs_scan_leb *sleb, in authenticate_sleb() argument
601 if (!ubifs_authenticated(c)) in authenticate_sleb()
611 err = authenticate_sleb_hash(c, log_hash, hash); in authenticate_sleb()
615 err = crypto_shash_tfm_digest(c->hmac_tfm, hash, in authenticate_sleb()
616 c->hash_len, hmac); in authenticate_sleb()
620 err = ubifs_check_hmac(c, auth->hmac, hmac); in authenticate_sleb()
666 static int replay_bud(struct ubifs_info *c, struct bud_entry *b) in replay_bud() argument
668 int is_last = is_last_bud(c, b->bud); in replay_bud()
677 if (c->need_recovery && is_last) in replay_bud()
684 sleb = ubifs_recover_leb(c, lnum, offs, c->sbuf, b->bud->jhead); in replay_bud()
686 sleb = ubifs_scan(c, lnum, offs, c->sbuf, 0); in replay_bud()
690 n_nodes = authenticate_sleb(c, sleb, b->bud->log_hash, is_last); in replay_bud()
696 ubifs_shash_copy_state(c, b->bud->log_hash, in replay_bud()
697 c->jheads[b->bud->jhead].log_hash); in replay_bud()
728 ubifs_err(c, "file system's life ended"); in replay_bud()
732 ubifs_node_calc_hash(c, snod->node, hash); in replay_bud()
734 if (snod->sqnum > c->max_sqnum) in replay_bud()
735 c->max_sqnum = snod->sqnum; in replay_bud()
745 err = insert_node(c, lnum, snod->offs, snod->len, hash, in replay_bud()
754 key_block(c, &snod->key) * in replay_bud()
757 err = insert_node(c, lnum, snod->offs, snod->len, hash, in replay_bud()
767 err = ubifs_validate_entry(c, dent); in replay_bud()
771 err = insert_dent(c, lnum, snod->offs, snod->len, hash, in replay_bud()
785 if (old_size < 0 || old_size > c->max_inode_sz || in replay_bud()
786 new_size < 0 || new_size > c->max_inode_sz || in replay_bud()
788 ubifs_err(c, "bad truncation node"); in replay_bud()
796 trun_key_init(c, &key, le32_to_cpu(trun->inum)); in replay_bud()
797 err = insert_node(c, lnum, snod->offs, snod->len, hash, in replay_bud()
805 ubifs_err(c, "unexpected node type %d in bud LEB %d:%d", in replay_bud()
818 ubifs_assert(c, ubifs_search_bud(c, lnum)); in replay_bud()
819 ubifs_assert(c, sleb->endpt - offs >= used); in replay_bud()
820 ubifs_assert(c, sleb->endpt % c->min_io_size == 0); in replay_bud()
823 b->free = c->leb_size - sleb->endpt; in replay_bud()
832 ubifs_err(c, "bad node is at LEB %d:%d", lnum, snod->offs); in replay_bud()
833 ubifs_dump_node(c, snod->node); in replay_bud()
845 static int replay_buds(struct ubifs_info *c) in replay_buds() argument
851 list_for_each_entry(b, &c->replay_buds, list) { in replay_buds()
852 err = replay_bud(c, b); in replay_buds()
856 ubifs_assert(c, b->sqnum > prev_sqnum); in replay_buds()
867 static void destroy_bud_list(struct ubifs_info *c) in destroy_bud_list() argument
871 while (!list_empty(&c->replay_buds)) { in destroy_bud_list()
872 b = list_entry(c->replay_buds.next, struct bud_entry, list); in destroy_bud_list()
889 static int add_replay_bud(struct ubifs_info *c, int lnum, int offs, int jhead, in add_replay_bud() argument
911 bud->log_hash = ubifs_hash_get_desc(c); in add_replay_bud()
917 ubifs_shash_copy_state(c, c->log_hash, bud->log_hash); in add_replay_bud()
919 ubifs_add_bud(c, bud); in add_replay_bud()
923 list_add_tail(&b->list, &c->replay_buds); in add_replay_bud()
942 static int validate_ref(struct ubifs_info *c, const struct ubifs_ref_node *ref) in validate_ref() argument
954 if (jhead >= c->jhead_cnt || lnum >= c->leb_cnt || in validate_ref()
955 lnum < c->main_first || offs > c->leb_size || in validate_ref()
956 offs & (c->min_io_size - 1)) in validate_ref()
960 bud = ubifs_search_bud(c, lnum); in validate_ref()
964 ubifs_err(c, "bud at LEB %d:%d was already referred", lnum, offs); in validate_ref()
982 static int replay_log_leb(struct ubifs_info *c, int lnum, int offs, void *sbuf) in replay_log_leb() argument
990 sleb = ubifs_scan(c, lnum, offs, sbuf, c->need_recovery); in replay_log_leb()
992 if (PTR_ERR(sleb) != -EUCLEAN || !c->need_recovery) in replay_log_leb()
999 sleb = ubifs_recover_log_leb(c, lnum, offs, sbuf); in replay_log_leb()
1011 if (c->cs_sqnum == 0) { in replay_log_leb()
1020 ubifs_err(c, "first log node at LEB %d:%d is not CS node", in replay_log_leb()
1024 if (le64_to_cpu(node->cmt_no) != c->cmt_no) { in replay_log_leb()
1025 ubifs_err(c, "first CS node at LEB %d:%d has wrong commit number %llu expected %llu", in replay_log_leb()
1028 c->cmt_no); in replay_log_leb()
1032 c->cs_sqnum = le64_to_cpu(node->ch.sqnum); in replay_log_leb()
1033 dbg_mnt("commit start sqnum %llu", c->cs_sqnum); in replay_log_leb()
1035 err = ubifs_shash_init(c, c->log_hash); in replay_log_leb()
1039 err = ubifs_shash_update(c, c->log_hash, node, UBIFS_CS_NODE_SZ); in replay_log_leb()
1044 if (snod->sqnum < c->cs_sqnum) { in replay_log_leb()
1058 ubifs_err(c, "first node is not at zero offset"); in replay_log_leb()
1066 ubifs_err(c, "file system's life ended"); in replay_log_leb()
1070 if (snod->sqnum < c->cs_sqnum) { in replay_log_leb()
1071 ubifs_err(c, "bad sqnum %llu, commit sqnum %llu", in replay_log_leb()
1072 snod->sqnum, c->cs_sqnum); in replay_log_leb()
1076 if (snod->sqnum > c->max_sqnum) in replay_log_leb()
1077 c->max_sqnum = snod->sqnum; in replay_log_leb()
1083 err = validate_ref(c, ref); in replay_log_leb()
1089 err = ubifs_shash_update(c, c->log_hash, ref, in replay_log_leb()
1094 err = add_replay_bud(c, le32_to_cpu(ref->lnum), in replay_log_leb()
1106 ubifs_err(c, "unexpected node in log"); in replay_log_leb()
1111 ubifs_err(c, "unexpected node in log"); in replay_log_leb()
1116 if (sleb->endpt || c->lhead_offs >= c->leb_size) { in replay_log_leb()
1117 c->lhead_lnum = lnum; in replay_log_leb()
1118 c->lhead_offs = sleb->endpt; in replay_log_leb()
1127 ubifs_err(c, "log error detected while replaying the log at LEB %d:%d", in replay_log_leb()
1129 ubifs_dump_node(c, snod->node); in replay_log_leb()
1141 static int take_ihead(struct ubifs_info *c) in take_ihead() argument
1146 ubifs_get_lprops(c); in take_ihead()
1148 lp = ubifs_lpt_lookup_dirty(c, c->ihead_lnum); in take_ihead()
1156 lp = ubifs_change_lp(c, lp, LPROPS_NC, LPROPS_NC, in take_ihead()
1165 ubifs_release_lprops(c); in take_ihead()
1177 int ubifs_replay_journal(struct ubifs_info *c) in ubifs_replay_journal() argument
1184 free = take_ihead(c); in ubifs_replay_journal()
1188 if (c->ihead_offs != c->leb_size - free) { in ubifs_replay_journal()
1189 ubifs_err(c, "bad index head LEB %d:%d", c->ihead_lnum, in ubifs_replay_journal()
1190 c->ihead_offs); in ubifs_replay_journal()
1195 c->replaying = 1; in ubifs_replay_journal()
1196 lnum = c->ltail_lnum = c->lhead_lnum; in ubifs_replay_journal()
1199 err = replay_log_leb(c, lnum, 0, c->sbuf); in ubifs_replay_journal()
1201 if (lnum != c->lhead_lnum) in ubifs_replay_journal()
1212 ubifs_err(c, "no UBIFS nodes found at the log head LEB %d:%d, possibly corrupted", in ubifs_replay_journal()
1218 lnum = ubifs_next_log_lnum(c, lnum); in ubifs_replay_journal()
1219 } while (lnum != c->ltail_lnum); in ubifs_replay_journal()
1221 err = replay_buds(c); in ubifs_replay_journal()
1225 err = apply_replay_list(c); in ubifs_replay_journal()
1229 err = set_buds_lprops(c); in ubifs_replay_journal()
1239 c->bi.uncommitted_idx = atomic_long_read(&c->dirty_zn_cnt); in ubifs_replay_journal()
1240 c->bi.uncommitted_idx *= c->max_idx_node_sz; in ubifs_replay_journal()
1242 ubifs_assert(c, c->bud_bytes <= c->max_bud_bytes || c->need_recovery); in ubifs_replay_journal()
1244 c->lhead_lnum, c->lhead_offs, c->max_sqnum, in ubifs_replay_journal()
1245 (unsigned long)c->highest_inum); in ubifs_replay_journal()
1247 destroy_replay_list(c); in ubifs_replay_journal()
1248 destroy_bud_list(c); in ubifs_replay_journal()
1249 c->replaying = 0; in ubifs_replay_journal()