summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJens Wiklander <jens.wiklander@linaro.org>2017-04-13 15:01:49 +0200
committerJérôme Forissier <jerome.forissier@linaro.org>2017-04-21 14:05:23 +0200
commit22efbd4a59b28eec98ca02cca5bc4b88f230487f (patch)
tree872db861fe7344cac393ba52fa909922ff3fe539
parentd7767217cb365fd91f5d592d1c96f0476cef811b (diff)
core: FS: add helpers for tee_fs_dirfile_fileh
Reviewed-by: Jerome Forissier <jerome.forissier@linaro.org> Acked-by: Etienne Carriere <etienne.carriere@linaro.org> Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
-rw-r--r--core/include/tee/tee_fs_rpc.h9
-rw-r--r--core/include/tee/tee_svc_storage.h4
-rw-r--r--core/tee/tee_fs_rpc.c76
-rw-r--r--core/tee/tee_svc_storage.c22
4 files changed, 111 insertions, 0 deletions
diff --git a/core/include/tee/tee_fs_rpc.h b/core/include/tee/tee_fs_rpc.h
index 43c7631d..d10b3b55 100644
--- a/core/include/tee/tee_fs_rpc.h
+++ b/core/include/tee/tee_fs_rpc.h
@@ -44,8 +44,15 @@ struct tee_fs_rpc_operation {
size_t num_params;
};
+struct tee_fs_dirfile_fileh;
+
TEE_Result tee_fs_rpc_open(uint32_t id, struct tee_pobj *po, int *fd);
+TEE_Result tee_fs_rpc_open_dfh(uint32_t id,
+ const struct tee_fs_dirfile_fileh *dfh, int *fd);
TEE_Result tee_fs_rpc_create(uint32_t id, struct tee_pobj *po, int *fd);
+TEE_Result tee_fs_rpc_create_dfh(uint32_t id,
+ const struct tee_fs_dirfile_fileh *dfh,
+ int *fd);
TEE_Result tee_fs_rpc_close(uint32_t id, int fd);
TEE_Result tee_fs_rpc_read_init(struct tee_fs_rpc_operation *op,
@@ -62,6 +69,8 @@ TEE_Result tee_fs_rpc_write_final(struct tee_fs_rpc_operation *op);
TEE_Result tee_fs_rpc_truncate(uint32_t id, int fd, size_t len);
TEE_Result tee_fs_rpc_remove(uint32_t id, struct tee_pobj *po);
+TEE_Result tee_fs_rpc_remove_dfh(uint32_t id,
+ const struct tee_fs_dirfile_fileh *dfh);
TEE_Result tee_fs_rpc_rename(uint32_t id, struct tee_pobj *old,
struct tee_pobj *new, bool overwrite);
diff --git a/core/include/tee/tee_svc_storage.h b/core/include/tee/tee_svc_storage.h
index d3f08581..68cd0419 100644
--- a/core/include/tee/tee_svc_storage.h
+++ b/core/include/tee/tee_svc_storage.h
@@ -85,6 +85,10 @@ void tee_svc_storage_init(void);
struct tee_pobj;
TEE_Result tee_svc_storage_create_filename(void *buf, size_t blen,
struct tee_pobj *po, bool transient);
+struct tee_fs_dirfile_fileh;
+TEE_Result
+tee_svc_storage_create_filename_dfh(void *buf, size_t blen,
+ const struct tee_fs_dirfile_fileh *dfh);
TEE_Result tee_svc_storage_create_dirname(void *buf, size_t blen,
const TEE_UUID *uuid);
diff --git a/core/tee/tee_fs_rpc.c b/core/tee/tee_fs_rpc.c
index 3ce1ba8f..3eb572b1 100644
--- a/core/tee/tee_fs_rpc.c
+++ b/core/tee/tee_fs_rpc.c
@@ -94,6 +94,55 @@ TEE_Result tee_fs_rpc_create(uint32_t id, struct tee_pobj *po, int *fd)
return operation_open(id, OPTEE_MRF_CREATE, po, fd);
}
+static TEE_Result operation_open_dfh(uint32_t id, unsigned int cmd,
+ const struct tee_fs_dirfile_fileh *dfh,
+ int *fd)
+{
+ struct tee_fs_rpc_operation op = { .id = id, .num_params = 3 };
+ TEE_Result res;
+ void *va;
+ paddr_t pa;
+ uint64_t cookie;
+
+ va = tee_fs_rpc_cache_alloc(TEE_FS_NAME_MAX, &pa, &cookie);
+ if (!va)
+ return TEE_ERROR_OUT_OF_MEMORY;
+
+ op.params[0].attr = OPTEE_MSG_ATTR_TYPE_VALUE_INPUT;
+ op.params[0].u.value.a = cmd;
+
+ op.params[1].attr = OPTEE_MSG_ATTR_TYPE_TMEM_INPUT;
+ op.params[1].u.tmem.buf_ptr = pa;
+ op.params[1].u.tmem.size = TEE_FS_NAME_MAX;
+ op.params[1].u.tmem.shm_ref = cookie;
+ res = tee_svc_storage_create_filename_dfh(va, TEE_FS_NAME_MAX, dfh);
+ if (res != TEE_SUCCESS)
+ return res;
+
+ op.params[2].attr = OPTEE_MSG_ATTR_TYPE_VALUE_OUTPUT;
+
+ res = operation_commit(&op);
+ if (res == TEE_SUCCESS)
+ *fd = op.params[2].u.value.a;
+
+ return res;
+}
+
+
+
+TEE_Result tee_fs_rpc_open_dfh(uint32_t id,
+ const struct tee_fs_dirfile_fileh *dfh, int *fd)
+{
+ return operation_open_dfh(id, OPTEE_MRF_OPEN, dfh, fd);
+}
+
+TEE_Result tee_fs_rpc_create_dfh(uint32_t id,
+ const struct tee_fs_dirfile_fileh *dfh,
+ int *fd)
+{
+ return operation_open_dfh(id, OPTEE_MRF_CREATE, dfh, fd);
+}
+
TEE_Result tee_fs_rpc_close(uint32_t id, int fd)
{
struct tee_fs_rpc_operation op = { .id = id, .num_params = 1 };
@@ -228,6 +277,33 @@ TEE_Result tee_fs_rpc_remove(uint32_t id, struct tee_pobj *po)
return operation_commit(&op);
}
+TEE_Result tee_fs_rpc_remove_dfh(uint32_t id,
+ const struct tee_fs_dirfile_fileh *dfh)
+{
+ TEE_Result res;
+ struct tee_fs_rpc_operation op = { .id = id, .num_params = 2 };
+ void *va;
+ paddr_t pa;
+ uint64_t cookie;
+
+ va = tee_fs_rpc_cache_alloc(TEE_FS_NAME_MAX, &pa, &cookie);
+ if (!va)
+ return TEE_ERROR_OUT_OF_MEMORY;
+
+ op.params[0].attr = OPTEE_MSG_ATTR_TYPE_VALUE_INPUT;
+ op.params[0].u.value.a = OPTEE_MRF_REMOVE;
+
+ op.params[1].attr = OPTEE_MSG_ATTR_TYPE_TMEM_INPUT;
+ op.params[1].u.tmem.buf_ptr = pa;
+ op.params[1].u.tmem.size = TEE_FS_NAME_MAX;
+ op.params[1].u.tmem.shm_ref = cookie;
+ res = tee_svc_storage_create_filename_dfh(va, TEE_FS_NAME_MAX, dfh);
+ if (res != TEE_SUCCESS)
+ return res;
+
+ return operation_commit(&op);
+}
+
TEE_Result tee_fs_rpc_rename(uint32_t id, struct tee_pobj *old,
struct tee_pobj *new, bool overwrite)
{
diff --git a/core/tee/tee_svc_storage.c b/core/tee/tee_svc_storage.c
index 8f1a509b..c2be3d48 100644
--- a/core/tee/tee_svc_storage.c
+++ b/core/tee/tee_svc_storage.c
@@ -32,6 +32,7 @@
#include <string.h>
#include <tee_api_defines_extensions.h>
#include <tee_api_defines.h>
+#include <tee/fs_dirfile.h>
#include <tee/tee_fs.h>
#include <tee/tee_obj.h>
#include <tee/tee_pobj.h>
@@ -156,6 +157,27 @@ TEE_Result tee_svc_storage_create_filename(void *buf, size_t blen,
return TEE_SUCCESS;
}
+/* "/dirf.db" or "/<file number>" */
+TEE_Result
+tee_svc_storage_create_filename_dfh(void *buf, size_t blen,
+ const struct tee_fs_dirfile_fileh *dfh)
+{
+ char *file = buf;
+ size_t pos = 0;
+ size_t l;
+
+ if (pos >= blen)
+ return TEE_ERROR_SHORT_BUFFER;
+
+ file[pos] = '/';
+ pos++;
+ if (pos >= blen)
+ return TEE_ERROR_SHORT_BUFFER;
+
+ l = blen - pos;
+ return tee_fs_dirfile_fileh_to_fname(dfh, file + pos, &l);
+}
+
/* "/TA_uuid" */
TEE_Result tee_svc_storage_create_dirname(void *buf, size_t blen,
const TEE_UUID *uuid)