Lines Matching refs:f
46 static int file_tag_cmp(const struct file *f, const uint8_t *tag, in file_tag_cmp() argument
49 if (f->taglen != taglen) in file_tag_cmp()
51 return memcmp(tag, f->tag, taglen); in file_tag_cmp()
57 struct file *f = NULL; in file_find_tag_unlocked() local
59 TAILQ_FOREACH(f, &file_head, link) in file_find_tag_unlocked()
60 if (!file_tag_cmp(f, tag, taglen)) in file_find_tag_unlocked()
61 return f; in file_find_tag_unlocked()
66 static void file_free(struct file *f) in file_free() argument
68 mutex_destroy(&f->mu); in file_free()
70 while (!SLIST_EMPTY(&f->slice_head)) { in file_free()
71 struct file_slice_elem *fse = SLIST_FIRST(&f->slice_head); in file_free()
73 SLIST_REMOVE_HEAD(&f->slice_head, link); in file_free()
78 free(f); in file_free()
81 TEE_Result file_add_slice(struct file *f, struct fobj *fobj, in file_add_slice() argument
88 if (file_find_slice(f, page_offset)) in file_add_slice()
104 SLIST_INSERT_HEAD(&f->slice_head, fse, link); in file_add_slice()
109 struct file *file_get(struct file *f) in file_get() argument
111 if (f && !refcount_inc(&f->refc)) in file_get()
114 return f; in file_get()
119 struct file *f = NULL; in file_get_by_tag() local
121 if (taglen > sizeof(f->tag)) in file_get_by_tag()
147 f = file_find_tag_unlocked(tag, taglen); in file_get_by_tag()
148 if (f && refcount_inc(&f->refc)) in file_get_by_tag()
151 f = calloc(1, sizeof(*f)); in file_get_by_tag()
152 if (!f) in file_get_by_tag()
154 memcpy(f->tag, tag, taglen); in file_get_by_tag()
155 f->taglen = taglen; in file_get_by_tag()
156 refcount_set(&f->refc, 1); in file_get_by_tag()
157 mutex_init(&f->mu); in file_get_by_tag()
158 SLIST_INIT(&f->slice_head); in file_get_by_tag()
159 TAILQ_INSERT_HEAD(&file_head, f, link); in file_get_by_tag()
164 return f; in file_get_by_tag()
167 void file_put(struct file *f) in file_put() argument
169 if (f && refcount_dec(&f->refc)) { in file_put()
171 TAILQ_REMOVE(&file_head, f, link); in file_put()
174 file_free(f); in file_put()
179 struct file_slice *file_find_slice(struct file *f, unsigned int page_offset) in file_find_slice() argument
183 assert(f->mu.state); in file_find_slice()
185 SLIST_FOREACH(fse, &f->slice_head, link) { in file_find_slice()
196 void file_lock(struct file *f) in file_lock() argument
198 mutex_lock(&f->mu); in file_lock()
201 bool file_trylock(struct file *f) in file_trylock() argument
203 return mutex_trylock(&f->mu); in file_trylock()
206 void file_unlock(struct file *f) in file_unlock() argument
208 mutex_unlock(&f->mu); in file_unlock()