xref: /optee_os/core/include/tee/tee_fs_rpc.h (revision a50cb361d9e5735f197ccc87beb0d24af8315369)
1 /*
2  * Copyright (c) 2016, Linaro Limited
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * 1. Redistributions of source code must retain the above copyright notice,
9  * this list of conditions and the following disclaimer.
10  *
11  * 2. Redistributions in binary form must reproduce the above copyright notice,
12  * this list of conditions and the following disclaimer in the documentation
13  * and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
19  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25  * POSSIBILITY OF SUCH DAMAGE.
26  */
27 
28 /*
29  * Interface with tee-supplicant for POSIX-like file operations
30  */
31 
32 #ifndef TEE_FS_RPC_H
33 #define TEE_FS_RPC_H
34 
35 #include <stdbool.h>
36 #include <stddef.h>
37 #include <tee_api_types.h>
38 
39 /* TEE FS operation */
40 #define TEE_FS_OPEN       1
41 #define TEE_FS_CLOSE      2
42 #define TEE_FS_READ       3
43 #define TEE_FS_WRITE      4
44 #define TEE_FS_SEEK       5
45 #define TEE_FS_UNLINK     6
46 #define TEE_FS_RENAME     7
47 #define TEE_FS_TRUNC      8
48 #define TEE_FS_MKDIR      9
49 #define TEE_FS_OPENDIR   10
50 #define TEE_FS_CLOSEDIR  11
51 #define TEE_FS_READDIR   12
52 #define TEE_FS_RMDIR     13
53 #define TEE_FS_ACCESS    14
54 #define TEE_FS_LINK      15
55 #define TEE_FS_BEGIN     16 /* SQL FS: begin transaction */
56 #define TEE_FS_END       17 /* SQL FS: end transaction */
57 
58 /* sql_fs_send_cmd 'mode' */
59 #define TEE_FS_MODE_NONE 0
60 #define TEE_FS_MODE_IN   1
61 #define TEE_FS_MODE_OUT  2
62 
63 struct tee_fs_rpc {
64 	int op;
65 	int flags;
66 	int arg;
67 	int fd;
68 	uint32_t len;
69 	int res;
70 };
71 
72 /*
73  * Return values:
74  *   < 0: error. The actual value is meaningless (see below).
75  *  >= 0: success. The value may be a file descriptor, a number of bytes, or
76  *        simply 0 depending on the function.
77  *
78  * The return value is the status set by the normal world (tee-supplicant) or
79  * -1 in case of communication error. To facilitate debugging, tee-supplicant
80  * uses -(errno) when an error code from libc is available. Therefore the
81  * values are non-portable and specific values must not be tested in the code.
82  */
83 int tee_fs_rpc_access(int id, const char *name, int mode);
84 int tee_fs_rpc_begin_transaction(int id);
85 int tee_fs_rpc_close(int id, int fd);
86 int tee_fs_rpc_end_transaction(int id, bool rollback);
87 int tee_fs_rpc_ftruncate(int id, int fd, tee_fs_off_t length);
88 int tee_fs_rpc_link(int id, const char *old, const char *nw);
89 tee_fs_off_t tee_fs_rpc_lseek(int id, int fd, tee_fs_off_t offset,
90 				  int whence);
91 int tee_fs_rpc_mkdir(int id, const char *path, tee_fs_mode_t mode);
92 int tee_fs_rpc_open(int id, const char *file, int flags);
93 struct tee_fs_dir *tee_fs_rpc_opendir(int id, const char *name);
94 int tee_fs_rpc_read(int id, int fd, void *buf, size_t len);
95 struct tee_fs_dirent *tee_fs_rpc_readdir(int id, struct tee_fs_dir *d);
96 int tee_fs_rpc_rename(int id, const char *old, const char *nw);
97 int tee_fs_rpc_write(int id, int fd, const void *buf, size_t len);
98 int tee_fs_rpc_closedir(int id, struct tee_fs_dir *d);
99 int tee_fs_rpc_rmdir(int id, const char *name);
100 int tee_fs_rpc_unlink(int id, const char *file);
101 
102 #endif /* TEE_FS_RPC_H */
103