1/*
2 * Copyright (c) 2022 Apple Inc. All rights reserved.
3 *
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
14 *
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
17 *
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
25 *
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27 */
28
29#ifndef _VFS_EXCLAVE_FS_H_
30#define _VFS_EXCLAVE_FS_H_
31
32#include <kern/kern_types.h>
33
34/* directory entry */
35typedef struct {
36 uint32_t length;
37 uint32_t returned_attrs[5];
38 int32_t name_offset;
39 uint32_t name_length;
40 uint32_t obj_type;
41 uint64_t file_id;
42 off_t data_length;
43} __attribute__((packed)) exclave_fs_dirent_t;
44
45/* root_id for non-EFT_EXCLAVE fs, maps to base dir */
46#define EXCLAVE_FS_BASEDIR_ROOT_ID 0
47
48/* sync operations for vfs_exclave_fs_sync() */
49#define EXCLAVE_FS_SYNC_OP_BARRIER 0
50#define EXCLAVE_FS_SYNC_OP_FULL 1
51
52#define EXCLAVE_FS_REGISTER_ENTITLEMENT "com.apple.private.vfs.exclave-fs-register"
53
54int vfs_exclave_fs_start(void);
55void vfs_exclave_fs_stop(void);
56
57int vfs_exclave_fs_register(uint32_t fs_tag, vnode_t vp);
58int vfs_exclave_fs_unregister(vnode_t vp);
59int vfs_exclave_fs_get_base_dirs(void *buf, uint32_t *count);
60
61int vfs_exclave_fs_register_path(uint32_t fs_tag, const char *base_path);
62int vfs_exclave_fs_unregister_tag(uint32_t fs_tag);
63
64int vfs_exclave_fs_root(const char *exclave_id, uint64_t *root_id);
65int vfs_exclave_fs_open(uint32_t fs_tag, uint64_t root_id, const char *name, uint64_t *file_id);
66int vfs_exclave_fs_close(uint32_t fs_tag, uint64_t file_id);
67int vfs_exclave_fs_create(uint32_t fs_tag, uint64_t root_id, const char *name, uint64_t *file_id);
68int vfs_exclave_fs_read(uint32_t fs_tag, uint64_t file_id, uint64_t file_offset, uint64_t length, void *data);
69int vfs_exclave_fs_write(uint32_t fs_tag, uint64_t file_id, uint64_t file_offset, uint64_t length, void *data);
70int vfs_exclave_fs_remove(uint32_t fs_tag, uint64_t root_id, const char *name);
71int vfs_exclave_fs_sync(uint32_t fs_tag, uint64_t file_id, uint64_t sync_op);
72int vfs_exclave_fs_readdir(uint32_t fs_tag, uint64_t file_id, void *dirent_buf,
73 uint32_t buf_size, int32_t *count);
74int vfs_exclave_fs_getsize(uint32_t fs_tag, uint64_t file_id, uint64_t *size);
75int vfs_exclave_fs_sealstate(uint32_t fs_tag, bool *sealed);
76
77#endif
78