27 */ |
27 */ |
28 |
28 |
29 #ifndef VFS_H |
29 #ifndef VFS_H |
30 #define VFS_H |
30 #define VFS_H |
31 |
31 |
32 #include "../public/nsapi.h" |
32 #include "../public/vfs.h" |
33 #include "acl.h" |
|
34 |
33 |
35 #ifdef __cplusplus |
34 #ifdef __cplusplus |
36 extern "C" { |
35 extern "C" { |
37 #endif |
36 #endif |
38 |
37 |
39 typedef struct VFS_IO VFS_IO; |
38 // private |
40 typedef struct VFS_DIRIO VFS_DIRIO; |
39 int vfs_init(); |
41 typedef struct VFSFile VFSFile; |
|
42 typedef struct VFSDir VFSDir; |
|
43 typedef struct VFSEntry VFSEntry; |
|
44 |
40 |
45 #define VFS_DIR VFSDir* |
|
46 #define VFS_ENTRY VFSEntry |
|
47 |
|
48 struct VFS { |
|
49 SYS_FILE (*open)(VFSContext *ctx, char *path, int oflags); |
|
50 int (*stat)(VFSContext *ctx, char *path, struct stat *buf); |
|
51 int (*fstat)(VFSContext *ctx, SYS_FILE fd, struct stat *buf); |
|
52 VFS_DIR (*opendir)(VFSContext *ctx, char *path); |
|
53 int (*mkdir)(VFSContext *ctx, char *path); |
|
54 int (*unlink)(VFSContext *ctx, char *path); |
|
55 }; |
|
56 |
|
57 struct VFSContext { |
|
58 Session *sn; |
|
59 Request *rq; |
|
60 VFS *vfs; |
|
61 pool_handle_t *pool; |
|
62 User *user; |
|
63 ACLListHandle *acllist; |
|
64 uint32_t aclreqaccess; |
|
65 int vfs_errno; |
|
66 }; |
|
67 |
|
68 struct VFSFile { |
|
69 VFSContext *ctx; |
|
70 VFS_IO *io; // IO functions |
|
71 void *data; // private data used by the VFSFile implementation |
|
72 int fd; // native file descriptor if available, or -1 |
|
73 }; |
|
74 |
|
75 struct VFSDir { |
|
76 VFSContext *ctx; |
|
77 VFS_DIRIO *io; |
|
78 void *data; // private data used by the VFSDir implementation |
|
79 int fd; // native file descriptor if available, or -1 |
|
80 }; |
|
81 |
|
82 struct VFSEntry { |
|
83 char *name; |
|
84 struct stat stat; |
|
85 void *stat_extra; |
|
86 int stat_errno; |
|
87 }; |
|
88 |
|
89 struct VFS_IO { |
|
90 ssize_t (*read)(SYS_FILE fd, void *buf, size_t nbyte); |
|
91 ssize_t (*write)(SYS_FILE fd, const void *buf, size_t nbyte); |
|
92 void (*close)(SYS_FILE fd); |
|
93 }; |
|
94 |
|
95 struct VFS_DIRIO { |
|
96 int (*readdir)(VFS_DIR dir, VFS_ENTRY *entry, int getstat); |
|
97 void (*close)(VFS_DIR dir); |
|
98 }; |
|
99 |
|
100 /* |
|
101 * creates a VFSContext for a Request |
|
102 * vfs calls will do ACL checks |
|
103 */ |
|
104 VFSContext* vfs_request_context(Session *sn, Request *rq); |
|
105 |
|
106 SYS_FILE vfs_open(VFSContext *ctx, char *path, int oflags); |
|
107 SYS_FILE vfs_openRO(VFSContext *ctx, char *path); |
|
108 SYS_FILE vfs_openWO(VFSContext *ctx, char *path); |
|
109 SYS_FILE vfs_openRW(VFSContext *ctx, char *path); |
|
110 int vfs_stat(VFSContext *ctx, char *path, struct stat *buf); |
|
111 int vfs_fstat(VFSContext *ctx, SYS_FILE fd, struct stat *buf); |
|
112 void vfs_close(SYS_FILE fd); |
|
113 VFS_DIR vfs_opendir(VFSContext *ctx, char *path); |
|
114 int vfs_readdir(VFS_DIR dir, VFS_ENTRY *entry); |
|
115 int vfs_readdir_stat(VFS_DIR dir, VFS_ENTRY *entry); |
|
116 void vfs_closedir(VFS_DIR dir); |
|
117 int vfs_mkdir(VFSContext *ctx, char *path); |
|
118 int vfs_unlink(VFSContext *ctx, char *path); |
|
119 |
|
120 // private |
|
121 typedef int(*vfs_op_f)(VFSContext *, char *); |
41 typedef int(*vfs_op_f)(VFSContext *, char *); |
122 int vfs_path_op(VFSContext *ctx, char *path, vfs_op_f op, uint32_t access); |
42 int vfs_path_op(VFSContext *ctx, char *path, vfs_op_f op, uint32_t access); |
123 |
43 |
124 int sys_acl_check(VFSContext *ctx, uint32_t acm, uid_t *uid, gid_t *gid); |
44 int sys_acl_check(VFSContext *ctx, uint32_t acm, uid_t *uid, gid_t *gid); |
125 void sys_set_error_status(VFSContext *ctx); |
45 void sys_set_error_status(VFSContext *ctx); |