Tue, 19 Mar 2013 17:38:32 +0100
webdav uses the vfs api
54 | 1 | /* |
2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. | |
3 | * | |
4 | * Copyright 2013 Olaf Wintermann. All rights reserved. | |
5 | * | |
6 | * Redistribution and use in source and binary forms, with or without | |
7 | * modification, are permitted provided that the following conditions are met: | |
8 | * | |
9 | * 1. Redistributions of source code must retain the above copyright | |
10 | * notice, this list of conditions and the following disclaimer. | |
11 | * | |
12 | * 2. Redistributions in binary form must reproduce the above copyright | |
13 | * notice, this list of conditions and the following disclaimer in the | |
14 | * documentation and/or other materials provided with the distribution. | |
15 | * | |
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE | |
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | |
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | |
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | |
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
26 | * POSSIBILITY OF SUCH DAMAGE. | |
27 | */ | |
28 | ||
29 | #ifndef VFS_H | |
30 | #define VFS_H | |
31 | ||
32 | #include "../public/nsapi.h" | |
33 | #include "acl.h" | |
34 | ||
35 | #ifdef __cplusplus | |
36 | extern "C" { | |
37 | #endif | |
38 | ||
55
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
39 | typedef struct VFS_IO VFS_IO; |
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
40 | typedef struct VFS_DIRIO VFS_DIRIO; |
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
41 | typedef struct VFSFile VFSFile; |
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
42 | typedef struct VFSDir VFSDir; |
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
43 | typedef struct VFSEntry VFSEntry; |
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
44 | |
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
45 | #define VFS_DIR VFSDir* |
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
46 | #define VFS_ENTRY VFSEntry |
54 | 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); | |
55
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
52 | VFS_DIR (*opendir)(VFSContext *ctx, char *path); |
56
c6cf20b09043
added vfs_mkdir and vfs_unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
55
diff
changeset
|
53 | int (*mkdir)(VFSContext *ctx, char *path); |
c6cf20b09043
added vfs_mkdir and vfs_unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
55
diff
changeset
|
54 | int (*unlink)(VFSContext *ctx, char *path); |
54 | 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 | ||
55
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
75 | struct VFSDir { |
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
76 | VFSContext *ctx; |
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
77 | VFS_DIRIO *io; |
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
78 | void *data; // private data used by the VFSDir implementation |
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
79 | int fd; // native file descriptor if available, or -1 |
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
80 | }; |
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
81 | |
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
82 | struct VFSEntry { |
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
83 | char *name; |
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
84 | struct stat stat; |
58
66c22e54aa90
webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
56
diff
changeset
|
85 | void *stat_extra; |
55
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
86 | int stat_errno; |
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
87 | }; |
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
88 | |
54 | 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 | ||
55
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
95 | struct VFS_DIRIO { |
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
96 | int (*readdir)(VFS_DIR dir, VFS_ENTRY *entry, int getstat); |
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
97 | void (*close)(VFS_DIR dir); |
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
98 | }; |
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
99 | |
54 | 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); | |
55
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
113 | VFS_DIR vfs_opendir(VFSContext *ctx, char *path); |
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
114 | int vfs_readdir(VFS_DIR dir, VFS_ENTRY *entry); |
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
115 | int vfs_readdir_stat(VFS_DIR dir, VFS_ENTRY *entry); |
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
116 | void vfs_closedir(VFS_DIR dir); |
56
c6cf20b09043
added vfs_mkdir and vfs_unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
55
diff
changeset
|
117 | int vfs_mkdir(VFSContext *ctx, char *path); |
c6cf20b09043
added vfs_mkdir and vfs_unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
55
diff
changeset
|
118 | int vfs_unlink(VFSContext *ctx, char *path); |
54 | 119 | |
120 | // private | |
56
c6cf20b09043
added vfs_mkdir and vfs_unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
55
diff
changeset
|
121 | typedef int(*vfs_op_f)(VFSContext *, char *); |
c6cf20b09043
added vfs_mkdir and vfs_unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
55
diff
changeset
|
122 | int vfs_path_op(VFSContext *ctx, char *path, vfs_op_f op, uint32_t access); |
c6cf20b09043
added vfs_mkdir and vfs_unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
55
diff
changeset
|
123 | |
54 | 124 | int sys_acl_check(VFSContext *ctx, uint32_t acm, uid_t *uid, gid_t *gid); |
125 | void sys_set_error_status(VFSContext *ctx); | |
126 | ssize_t sys_file_read(SYS_FILE fd, void *buf, size_t nbyte); | |
127 | ssize_t sys_file_write(SYS_FILE fd, const void *buf, size_t nbyte); | |
128 | void sys_file_close(SYS_FILE fd); | |
55
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
129 | int sys_dir_read(VFS_DIR dir, VFS_ENTRY *entry, int getstat); |
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
130 | void sys_dir_close(VFS_DIR dir); |
56
c6cf20b09043
added vfs_mkdir and vfs_unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
55
diff
changeset
|
131 | int sys_mkdir(VFSContext *ctx, char *path); |
c6cf20b09043
added vfs_mkdir and vfs_unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
55
diff
changeset
|
132 | int sys_unlink(VFSContext *ctx, char *path); |
54 | 133 | |
134 | #ifdef __cplusplus | |
135 | } | |
136 | #endif | |
137 | ||
138 | #endif /* VFS_H */ | |
139 |