1 /* SPDX-License-Identifier: BSD-2-Clause */ 2 /* 3 * Copyright (c) 2019, Linaro Limited 4 */ 5 6 #ifndef __MM_FILE_H 7 #define __MM_FILE_H 8 9 #include <types_ext.h> 10 #include <utee_defines.h> 11 12 /* This is supposed to be large enough to hold any hash or tag used */ 13 #define FILE_TAG_SIZE TEE_SHA256_HASH_SIZE 14 15 /* 16 * struct file_slice - one slice of a file 17 * @fobj: Fobj holding the data of this slice 18 * @page_offset: Offset in pages into the file where the @fobj is 19 * located. 20 */ 21 struct file_slice { 22 struct fobj *fobj; 23 unsigned int page_offset; 24 }; 25 26 struct file; 27 28 /* 29 * file_new() - allocate a new struct file 30 * @tag: Tag of the file 31 * @taglen: Length of @tag 32 * @slices: An array of file slices 33 * @num_slices: Number of elements in the @slices array 34 * 35 * Returns a newly allocated file with the reference counters of the fobjs 36 * in all the slices increased on success. Returns NULL on failure. 37 */ 38 struct file *file_new(uint8_t *tag, unsigned int taglen, 39 struct file_slice *slices, unsigned int num_slices); 40 41 /* 42 * file_get() - Increase file reference counter 43 * @f: File pointer 44 * 45 * Returns @f, if @f isn't NULL its reference counter is first increased. 46 */ 47 struct file *file_get(struct file *f); 48 49 /* 50 * file_get_by_tag() - Finds a file based on tag and increase reference counter 51 * @tag: Tag of the file 52 * @taglen: Length of @tag 53 * 54 * Returns a file with an increased reference counter if found, or NULL if 55 * not found. 56 */ 57 struct file *file_get_by_tag(uint8_t *tag, unsigned int taglen); 58 59 /* 60 * file_put() - Decrease reference counter of file 61 * @f: File pointer 62 * 63 * If reference counter reaches 0, matching the numbers of file_new() + 64 * file_get() + file_get_by_tag(), the file is removed with reference 65 * counters for all contained fobjs decreased. 66 */ 67 void file_put(struct file *f); 68 69 /* 70 * file_find_slice() - Find a slice covering the @page_offset 71 * @f: File pointer 72 * @page_offset: Offset that must be covered 73 * 74 * If a matching file slice is found it is returned, else NULL is returned. 75 */ 76 struct file_slice *file_find_slice(struct file *f, unsigned int page_offset); 77 78 #endif /*__MM_FILE_H*/ 79 80