Lines Matching refs:db

59 	struct tee_tadb_dir *db;  member
67 struct tee_tadb_dir *db; member
143 static TEE_Result maybe_grow_files(struct tee_tadb_dir *db, int idx) in maybe_grow_files() argument
147 if (idx < db->nbits) in maybe_grow_files()
150 p = realloc(db->files, bitstr_size(idx + 1)); in maybe_grow_files()
153 db->files = p; in maybe_grow_files()
155 bit_nclear(db->files, db->nbits, idx); in maybe_grow_files()
156 db->nbits = idx + 1; in maybe_grow_files()
161 static TEE_Result set_file(struct tee_tadb_dir *db, int idx) in set_file() argument
163 TEE_Result res = maybe_grow_files(db, idx); in set_file()
166 bit_set(db->files, idx); in set_file()
171 static void clear_file(struct tee_tadb_dir *db, int idx) in clear_file() argument
177 if (idx < db->nbits) in clear_file()
178 bit_clear(db->files, idx); in clear_file()
181 static bool test_file(struct tee_tadb_dir *db, int idx) in test_file() argument
187 if (idx < db->nbits) in test_file()
188 return bit_test(db->files, idx); in test_file()
193 static TEE_Result read_ent(struct tee_tadb_dir *db, size_t idx, in read_ent() argument
197 TEE_Result res = db->ops->read(db->fh, idx * l, entry, NULL, &l); in read_ent()
205 static TEE_Result write_ent(struct tee_tadb_dir *db, size_t idx, in write_ent() argument
210 return db->ops->write(db->fh, idx * l, entry, NULL, l); in write_ent()
216 struct tee_tadb_dir *db = calloc(1, sizeof(*db)); in tadb_open() local
222 if (!db) in tadb_open()
225 db->ops = tee_svc_storage_file_ops(TEE_STORAGE_PRIVATE); in tadb_open()
227 res = db->ops->open(&po, NULL, &db->fh); in tadb_open()
229 res = db->ops->create(&po, false, NULL, 0, NULL, 0, in tadb_open()
230 NULL, NULL, 0, &db->fh); in tadb_open()
233 free(db); in tadb_open()
235 *db_ret = db; in tadb_open()
240 static TEE_Result tee_tadb_open(struct tee_tadb_dir **db) in tee_tadb_open() argument
252 *db = tadb_db; in tee_tadb_open()
258 static void tadb_put(struct tee_tadb_dir *db) in tadb_put() argument
260 assert(db == tadb_db); in tadb_put()
265 db->ops->close(&db->fh); in tadb_put()
266 free(db->files); in tadb_put()
267 free(db); in tadb_put()
273 static void tee_tadb_close(struct tee_tadb_dir *db) in tee_tadb_close() argument
275 tadb_put(db); in tee_tadb_close()
313 static TEE_Result populate_files(struct tee_tadb_dir *db) in populate_files() argument
322 if (db->nbits) in populate_files()
339 res = read_ent(db, idx, &entry); in populate_files()
349 if (test_file(db, entry.file_number)) { in populate_files()
353 res = write_ent(db, idx, &entry); in populate_files()
359 res = set_file(db, entry.file_number); in populate_files()
365 free(db->files); in populate_files()
366 db->files = NULL; in populate_files()
367 db->nbits = 0; in populate_files()
386 res = tee_tadb_open(&ta->db); in tee_tadb_ta_create()
396 res = populate_files(ta->db); in tee_tadb_ta_create()
400 if (ta->db->files) { in tee_tadb_ta_create()
401 bit_ffc(ta->db->files, ta->db->nbits, &i); in tee_tadb_ta_create()
403 i = ta->db->nbits; in tee_tadb_ta_create()
406 res = set_file(ta->db, i); in tee_tadb_ta_create()
439 tadb_put(ta->db); in tee_tadb_ta_create()
488 clear_file(ta->db, ta->entry.file_number); in tee_tadb_ta_close_and_delete()
491 tadb_put(ta->db); in tee_tadb_ta_close_and_delete()
495 static TEE_Result find_ent(struct tee_tadb_dir *db, const TEE_UUID *uuid, in find_ent() argument
511 res = read_ent(db, idx, &entry); in find_ent()
529 static TEE_Result find_free_ent_idx(struct tee_tadb_dir *db, size_t *idx) in find_free_ent_idx() argument
532 TEE_Result res = find_ent(db, &null_uuid, idx, NULL); in find_free_ent_idx()
567 res = find_ent(ta->db, &ta->entry.prop.uuid, &idx, &old_ent); in tee_tadb_ta_close_and_commit()
571 res = find_free_ent_idx(ta->db, &idx); in tee_tadb_ta_close_and_commit()
575 res = write_ent(ta->db, idx, &ta->entry); in tee_tadb_ta_close_and_commit()
579 clear_file(ta->db, old_ent.file_number); in tee_tadb_ta_close_and_commit()
584 tadb_put(ta->db); in tee_tadb_ta_close_and_commit()
600 struct tee_tadb_dir *db; in tee_tadb_ta_delete() local
608 res = tee_tadb_open(&db); in tee_tadb_ta_delete()
613 res = find_ent(db, uuid, &idx, &entry); in tee_tadb_ta_delete()
616 tee_tadb_close(db); in tee_tadb_ta_delete()
620 clear_file(db, entry.file_number); in tee_tadb_ta_delete()
621 res = write_ent(db, idx, &null_entry); in tee_tadb_ta_delete()
624 tee_tadb_close(db); in tee_tadb_ta_delete()
646 res = tee_tadb_open(&ta->db); in tee_tadb_ta_open()
651 res = find_ent(ta->db, uuid, &idx, &ta->entry); in tee_tadb_ta_open()
669 tadb_put(ta->db); in tee_tadb_ta_open()
794 tadb_put(ta->db); in tee_tadb_ta_close()