Lines Matching refs:dirh

54 static TEE_Result maybe_grow_files(struct tee_fs_dirfile_dirh *dirh, int idx)  in maybe_grow_files()  argument
58 if (idx < dirh->nbits) in maybe_grow_files()
61 p = realloc(dirh->files, bitstr_size(idx + 1)); in maybe_grow_files()
64 dirh->files = p; in maybe_grow_files()
66 bit_nclear(dirh->files, dirh->nbits, idx); in maybe_grow_files()
67 dirh->nbits = idx + 1; in maybe_grow_files()
72 static TEE_Result set_file(struct tee_fs_dirfile_dirh *dirh, int idx) in set_file() argument
74 TEE_Result res = maybe_grow_files(dirh, idx); in set_file()
77 bit_set(dirh->files, idx); in set_file()
82 static void clear_file(struct tee_fs_dirfile_dirh *dirh, int idx) in clear_file() argument
84 if (idx < dirh->nbits) in clear_file()
85 bit_clear(dirh->files, idx); in clear_file()
88 static bool test_file(struct tee_fs_dirfile_dirh *dirh, int idx) in test_file() argument
90 if (idx < dirh->nbits) in test_file()
91 return bit_test(dirh->files, idx); in test_file()
96 static TEE_Result read_dent(struct tee_fs_dirfile_dirh *dirh, int idx, in read_dent() argument
103 res = dirh->fops->read(dirh->fh, sizeof(struct dirfile_entry) * idx, in read_dent()
111 static TEE_Result write_dent(struct tee_fs_dirfile_dirh *dirh, size_t n, in write_dent() argument
116 res = dirh->fops->write(dirh->fh, sizeof(*dent) * n, in write_dent()
118 if (!res && n >= dirh->ndents) in write_dent()
119 dirh->ndents = n + 1; in write_dent()
129 struct tee_fs_dirfile_dirh *dirh = calloc(1, sizeof(*dirh)); in tee_fs_dirfile_open() local
132 if (!dirh) in tee_fs_dirfile_open()
135 dirh->fops = fops; in tee_fs_dirfile_open()
136 res = fops->open(create, hash, NULL, NULL, &dirh->fh); in tee_fs_dirfile_open()
143 res = read_dent(dirh, n, &dent); in tee_fs_dirfile_open()
153 if (test_file(dirh, dent.file_number)) { in tee_fs_dirfile_open()
157 res = write_dent(dirh, n, &dent); in tee_fs_dirfile_open()
163 res = set_file(dirh, dent.file_number); in tee_fs_dirfile_open()
169 dirh->ndents = n; in tee_fs_dirfile_open()
170 *dirh_ret = dirh; in tee_fs_dirfile_open()
172 tee_fs_dirfile_close(dirh); in tee_fs_dirfile_open()
177 void tee_fs_dirfile_close(struct tee_fs_dirfile_dirh *dirh) in tee_fs_dirfile_close() argument
179 if (dirh) { in tee_fs_dirfile_close()
180 dirh->fops->close(dirh->fh); in tee_fs_dirfile_close()
181 free(dirh->files); in tee_fs_dirfile_close()
182 free(dirh); in tee_fs_dirfile_close()
186 TEE_Result tee_fs_dirfile_commit_writes(struct tee_fs_dirfile_dirh *dirh, in tee_fs_dirfile_commit_writes() argument
189 return dirh->fops->commit_writes(dirh->fh, hash); in tee_fs_dirfile_commit_writes()
192 TEE_Result tee_fs_dirfile_get_tmp(struct tee_fs_dirfile_dirh *dirh, in tee_fs_dirfile_get_tmp() argument
198 if (dirh->nbits) { in tee_fs_dirfile_get_tmp()
199 bit_ffc(dirh->files, dirh->nbits, &i); in tee_fs_dirfile_get_tmp()
201 i = dirh->nbits; in tee_fs_dirfile_get_tmp()
204 res = set_file(dirh, i); in tee_fs_dirfile_get_tmp()
211 TEE_Result tee_fs_dirfile_find(struct tee_fs_dirfile_dirh *dirh, in tee_fs_dirfile_find() argument
220 res = read_dent(dirh, n, &dent); in tee_fs_dirfile_find()
229 assert(test_file(dirh, dent.file_number)); in tee_fs_dirfile_find()
286 TEE_Result tee_fs_dirfile_rename(struct tee_fs_dirfile_dirh *dirh, in tee_fs_dirfile_rename() argument
310 res = tee_fs_dirfile_find(dirh, uuid, oid, oidlen, &dfh2); in tee_fs_dirfile_rename()
313 res = find_empty_idx(dirh, &dfh2.idx); in tee_fs_dirfile_rename()
320 return write_dent(dirh, dfh->idx, &dent); in tee_fs_dirfile_rename()
323 TEE_Result tee_fs_dirfile_remove(struct tee_fs_dirfile_dirh *dirh, in tee_fs_dirfile_remove() argument
330 res = read_dent(dirh, dfh->idx, &dent); in tee_fs_dirfile_remove()
339 assert(test_file(dirh, file_number)); in tee_fs_dirfile_remove()
342 res = write_dent(dirh, dfh->idx, &dent); in tee_fs_dirfile_remove()
344 clear_file(dirh, file_number); in tee_fs_dirfile_remove()
349 TEE_Result tee_fs_dirfile_update_hash(struct tee_fs_dirfile_dirh *dirh, in tee_fs_dirfile_update_hash() argument
355 res = read_dent(dirh, dfh->idx, &dent); in tee_fs_dirfile_update_hash()
359 assert(test_file(dirh, dent.file_number)); in tee_fs_dirfile_update_hash()
363 return write_dent(dirh, dfh->idx, &dent); in tee_fs_dirfile_update_hash()
366 TEE_Result tee_fs_dirfile_get_next(struct tee_fs_dirfile_dirh *dirh, in tee_fs_dirfile_get_next() argument
378 res = read_dent(dirh, i, &dent); in tee_fs_dirfile_get_next()