Sun, 15 May 2022 08:56:00 +0200
make sure the http stream is finished if headers are sent
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 | ||
105
63d9051fe35c
using readdir_r instead of readdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
97
diff
changeset
|
29 | #define _POSIX_PTHREAD_SEMANTIS |
63d9051fe35c
using readdir_r instead of readdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
97
diff
changeset
|
30 | |
54 | 31 | #include <stdio.h> |
32 | #include <stdlib.h> | |
33 | #include <unistd.h> | |
34 | #include <sys/types.h> | |
172
5580517faafc
adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
165
diff
changeset
|
35 | #include <aio.h> |
92
382bff43c6eb
fixed some includes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
87
diff
changeset
|
36 | #include <ucx/map.h> |
382bff43c6eb
fixed some includes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
87
diff
changeset
|
37 | |
54 | 38 | #include "../util/pool.h" |
171
af7e2d80dee6
adds wrapper for close syscall with error handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
39 | #include "netsite.h" |
63
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
40 | #include "acl.h" |
54 | 41 | #include "vfs.h" |
187
4384bfbb7e26
adds platform independent aio functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
42 | #include "threadpools.h" |
172
5580517faafc
adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
165
diff
changeset
|
43 | #include "event.h" |
54 | 44 | |
165
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
45 | #define VFS_MALLOC(pool, size) pool ? pool_malloc(pool, size) : malloc(size) |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
46 | #define VFS_FREE(pool, ptr) pool ? pool_free(pool, ptr) : free(ptr) |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
47 | |
276
0cb4eda146c4
add function to create a postgresql-based VFS
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
269
diff
changeset
|
48 | static UcxMap *vfs_type_map; |
59
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
49 | |
165
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
50 | static VFS sys_vfs = { |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
51 | sys_vfs_open, |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
52 | sys_vfs_stat, |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
53 | sys_vfs_fstat, |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
54 | sys_vfs_opendir, |
211
2160585200ac
add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
193
diff
changeset
|
55 | sys_vfs_fdopendir, |
165
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
56 | sys_vfs_mkdir, |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
57 | sys_vfs_unlink, |
247
1df803e06076
implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
241
diff
changeset
|
58 | sys_vfs_rmdir, |
211
2160585200ac
add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
193
diff
changeset
|
59 | VFS_CHECKS_ACL, |
2160585200ac
add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
193
diff
changeset
|
60 | NULL |
165
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
61 | }; |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
62 | |
54 | 63 | static VFS_IO sys_file_io = { |
64 | sys_file_read, | |
65 | sys_file_write, | |
189
a2438f6d1e73
adds vfs pread/pwrite functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
187
diff
changeset
|
66 | sys_file_pread, |
a2438f6d1e73
adds vfs pread/pwrite functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
187
diff
changeset
|
67 | sys_file_pwrite, |
66
74babc0082b7
added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
63
diff
changeset
|
68 | sys_file_seek, |
172
5580517faafc
adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
165
diff
changeset
|
69 | sys_file_close, |
187
4384bfbb7e26
adds platform independent aio functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
70 | //sys_file_aioread, |
4384bfbb7e26
adds platform independent aio functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
71 | //sys_file_aiowrite, |
345
5832e10fc59a
add optional getetag function to VFS API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
72 | NULL, // aioread |
5832e10fc59a
add optional getetag function to VFS API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
73 | NULL, // aiowrite |
5832e10fc59a
add optional getetag function to VFS API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
74 | NULL // getetag |
54 | 75 | }; |
76 | ||
55
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
77 | static VFS_DIRIO sys_dir_io = { |
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
78 | sys_dir_read, |
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
79 | sys_dir_close |
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 | |
289
285d483db2fb
add first pg vfs tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
286
diff
changeset
|
82 | int vfs_init(void) { |
276
0cb4eda146c4
add function to create a postgresql-based VFS
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
269
diff
changeset
|
83 | vfs_type_map = ucx_map_new(16); |
0cb4eda146c4
add function to create a postgresql-based VFS
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
269
diff
changeset
|
84 | if(!vfs_type_map) { |
59
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
85 | return -1; |
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
86 | } |
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
87 | return 0; |
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
88 | } |
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
89 | |
276
0cb4eda146c4
add function to create a postgresql-based VFS
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
269
diff
changeset
|
90 | int vfs_register_type(const char *name, vfs_create_func vfsCreate) { |
87
bdec069d2239
fixed pathcheck behavior
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
72
diff
changeset
|
91 | WS_ASSERT(name); |
bdec069d2239
fixed pathcheck behavior
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
72
diff
changeset
|
92 | |
276
0cb4eda146c4
add function to create a postgresql-based VFS
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
269
diff
changeset
|
93 | if(!vfs_type_map) { |
0cb4eda146c4
add function to create a postgresql-based VFS
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
269
diff
changeset
|
94 | if(vfs_init()) { |
0cb4eda146c4
add function to create a postgresql-based VFS
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
269
diff
changeset
|
95 | return 1; |
0cb4eda146c4
add function to create a postgresql-based VFS
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
269
diff
changeset
|
96 | } |
59
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
97 | } |
276
0cb4eda146c4
add function to create a postgresql-based VFS
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
269
diff
changeset
|
98 | return ucx_map_cstr_put(vfs_type_map, name, vfsCreate); |
59
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
99 | } |
ab25c0a231d0
some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
58
diff
changeset
|
100 | |
277
7608af69739f
add support for vfsclass parameter in nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
276
diff
changeset
|
101 | |
7608af69739f
add support for vfsclass parameter in nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
276
diff
changeset
|
102 | VFS* vfs_create(Session *sn, Request *rq, const char *vfs_class, pblock *pb) { |
7608af69739f
add support for vfsclass parameter in nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
276
diff
changeset
|
103 | vfs_create_func createVFS = ucx_map_cstr_get(vfs_type_map, vfs_class); |
7608af69739f
add support for vfsclass parameter in nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
276
diff
changeset
|
104 | if(!createVFS) { |
7608af69739f
add support for vfsclass parameter in nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
276
diff
changeset
|
105 | log_ereport(LOG_MISCONFIG, "vfs_create: unkown VFS type %s", vfs_class); |
7608af69739f
add support for vfsclass parameter in nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
276
diff
changeset
|
106 | return NULL; |
7608af69739f
add support for vfsclass parameter in nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
276
diff
changeset
|
107 | } |
7608af69739f
add support for vfsclass parameter in nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
276
diff
changeset
|
108 | |
7608af69739f
add support for vfsclass parameter in nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
276
diff
changeset
|
109 | return createVFS(sn, rq, pb); |
7608af69739f
add support for vfsclass parameter in nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
276
diff
changeset
|
110 | } |
7608af69739f
add support for vfsclass parameter in nametrans safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
276
diff
changeset
|
111 | |
54 | 112 | VFSContext* vfs_request_context(Session *sn, Request *rq) { |
87
bdec069d2239
fixed pathcheck behavior
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
72
diff
changeset
|
113 | WS_ASSERT(sn); |
bdec069d2239
fixed pathcheck behavior
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
72
diff
changeset
|
114 | WS_ASSERT(rq); |
bdec069d2239
fixed pathcheck behavior
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
72
diff
changeset
|
115 | |
54 | 116 | VFSContext *ctx = pool_malloc(sn->pool, sizeof(VFSContext)); |
241
4adad7faf452
add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
211
diff
changeset
|
117 | if(!ctx) { |
4adad7faf452
add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
211
diff
changeset
|
118 | return NULL; |
4adad7faf452
add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
211
diff
changeset
|
119 | } |
54 | 120 | ctx->sn = sn; |
121 | ctx->rq = rq; | |
165
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
122 | ctx->vfs = rq->vfs ? rq->vfs : &sys_vfs; |
54 | 123 | ctx->user = acllist_getuser(sn, rq, rq->acllist); |
124 | ctx->acllist = rq->acllist; | |
125 | ctx->aclreqaccess = rq->aclreqaccess; | |
126 | ctx->pool = sn->pool; | |
127 | ctx->vfs_errno = 0; | |
286
864e2d701dd4
set error status code directly in vfs_* calls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
277
diff
changeset
|
128 | ctx->error_response_set = 0; |
54 | 129 | return ctx; |
130 | } | |
131 | ||
241
4adad7faf452
add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
211
diff
changeset
|
132 | SYS_FILE vfs_open(VFSContext *ctx, const char *path, int oflags) { |
165
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
133 | WS_ASSERT(ctx); |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
134 | WS_ASSERT(path); |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
135 | |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
136 | uint32_t access_mask = ctx->aclreqaccess | acl_oflag2mask(oflags); |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
137 | |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
138 | // ctx->aclreqaccess should be the complete access mask |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
139 | uint32_t m = ctx->aclreqaccess; // save original access mask |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
140 | ctx->aclreqaccess = access_mask; // set mask for vfs->open call |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
141 | if((ctx->vfs->flags & VFS_CHECKS_ACL) != VFS_CHECKS_ACL) { |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
142 | // VFS does not evaluates the ACL itself, so we have to do it here |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
143 | SysACL sysacl; |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
144 | if(sys_acl_check(ctx, access_mask, &sysacl)) { |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
145 | return NULL; |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
146 | } |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
147 | } |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
148 | SYS_FILE file = ctx->vfs->open(ctx, path, oflags); |
286
864e2d701dd4
set error status code directly in vfs_* calls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
277
diff
changeset
|
149 | ctx->aclreqaccess = m; // restore original access mask |
864e2d701dd4
set error status code directly in vfs_* calls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
277
diff
changeset
|
150 | if(!file && ctx) { |
864e2d701dd4
set error status code directly in vfs_* calls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
277
diff
changeset
|
151 | sys_set_error_status(ctx); |
864e2d701dd4
set error status code directly in vfs_* calls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
277
diff
changeset
|
152 | } |
165
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
153 | return file; |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
154 | } |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
155 | |
241
4adad7faf452
add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
211
diff
changeset
|
156 | SYS_FILE vfs_openRO(VFSContext *ctx, const char *path) { |
165
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
157 | return vfs_open(ctx, path, O_RDONLY); |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
158 | } |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
159 | |
241
4adad7faf452
add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
211
diff
changeset
|
160 | SYS_FILE vfs_openWO(VFSContext *ctx, const char *path) { |
165
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
161 | return vfs_open(ctx, path, O_WRONLY | O_CREAT); |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
162 | } |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
163 | |
241
4adad7faf452
add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
211
diff
changeset
|
164 | SYS_FILE vfs_openRW(VFSContext *ctx, const char *path) { |
165
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
165 | return vfs_open(ctx, path, O_RDONLY | O_WRONLY | O_CREAT); |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
166 | } |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
167 | |
241
4adad7faf452
add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
211
diff
changeset
|
168 | int vfs_stat(VFSContext *ctx, const char *path, struct stat *buf) { |
165
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
169 | WS_ASSERT(ctx); |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
170 | WS_ASSERT(path); |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
171 | |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
172 | uint32_t access_mask = ctx->aclreqaccess | ACL_READ_ATTRIBUTES; |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
173 | |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
174 | // ctx->aclreqaccess should be the complete access mask |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
175 | uint32_t m = ctx->aclreqaccess; // save original access mask |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
176 | ctx->aclreqaccess = access_mask; // set mask for vfs->open call |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
177 | if((ctx->vfs->flags & VFS_CHECKS_ACL) != VFS_CHECKS_ACL) { |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
178 | // VFS does not evaluates the ACL itself, so we have to do it here |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
179 | SysACL sysacl; |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
180 | if(sys_acl_check(ctx, access_mask, &sysacl)) { |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
181 | return -1; |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
182 | } |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
183 | } |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
184 | int ret = ctx->vfs->stat(ctx, path, buf); |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
185 | ctx->aclreqaccess = m; // restore original access mask |
286
864e2d701dd4
set error status code directly in vfs_* calls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
277
diff
changeset
|
186 | if(ret && ctx) { |
864e2d701dd4
set error status code directly in vfs_* calls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
277
diff
changeset
|
187 | sys_set_error_status(ctx); |
864e2d701dd4
set error status code directly in vfs_* calls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
277
diff
changeset
|
188 | } |
165
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
189 | return ret; |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
190 | } |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
191 | |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
192 | int vfs_fstat(VFSContext *ctx, SYS_FILE fd, struct stat *buf) { |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
193 | WS_ASSERT(ctx); |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
194 | WS_ASSERT(fd); |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
195 | WS_ASSERT(buf); |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
196 | |
286
864e2d701dd4
set error status code directly in vfs_* calls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
277
diff
changeset
|
197 | int ret = ctx->vfs->fstat(ctx, fd, buf); |
864e2d701dd4
set error status code directly in vfs_* calls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
277
diff
changeset
|
198 | if(ret && ctx) { |
864e2d701dd4
set error status code directly in vfs_* calls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
277
diff
changeset
|
199 | sys_set_error_status(ctx); |
864e2d701dd4
set error status code directly in vfs_* calls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
277
diff
changeset
|
200 | } |
864e2d701dd4
set error status code directly in vfs_* calls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
277
diff
changeset
|
201 | return ret; |
165
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
202 | } |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
203 | |
345
5832e10fc59a
add optional getetag function to VFS API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
204 | const char * vfs_getetag(SYS_FILE fd) { |
5832e10fc59a
add optional getetag function to VFS API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
205 | WS_ASSERT(fd); |
5832e10fc59a
add optional getetag function to VFS API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
206 | |
5832e10fc59a
add optional getetag function to VFS API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
207 | if(fd->io->opt_getetag) { |
5832e10fc59a
add optional getetag function to VFS API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
208 | return fd->io->opt_getetag(fd); |
5832e10fc59a
add optional getetag function to VFS API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
209 | } |
5832e10fc59a
add optional getetag function to VFS API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
210 | return NULL; |
5832e10fc59a
add optional getetag function to VFS API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
211 | } |
5832e10fc59a
add optional getetag function to VFS API
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
289
diff
changeset
|
212 | |
165
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
213 | void vfs_close(SYS_FILE fd) { |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
214 | WS_ASSERT(fd); |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
215 | |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
216 | fd->io->close(fd); |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
217 | if(fd->ctx) { |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
218 | pool_free(fd->ctx->pool, fd); |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
219 | } else { |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
220 | free(fd); |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
221 | } |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
222 | } |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
223 | |
241
4adad7faf452
add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
211
diff
changeset
|
224 | VFS_DIR vfs_opendir(VFSContext *ctx, const char *path) { |
165
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
225 | WS_ASSERT(ctx); |
87
bdec069d2239
fixed pathcheck behavior
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
72
diff
changeset
|
226 | WS_ASSERT(path); |
bdec069d2239
fixed pathcheck behavior
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
72
diff
changeset
|
227 | |
165
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
228 | uint32_t access_mask = ctx->aclreqaccess | ACL_LIST; |
54 | 229 | |
165
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
230 | // ctx->aclreqaccess should be the complete access mask |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
231 | uint32_t m = ctx->aclreqaccess; // save original access mask |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
232 | ctx->aclreqaccess = access_mask; // set mask for vfs->open call |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
233 | if((ctx->vfs->flags & VFS_CHECKS_ACL) != VFS_CHECKS_ACL) { |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
234 | // VFS does not evaluates the ACL itself, so we have to do it here |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
235 | SysACL sysacl; |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
236 | if(sys_acl_check(ctx, access_mask, &sysacl)) { |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
237 | return NULL; |
54 | 238 | } |
165
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
239 | } |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
240 | VFS_DIR dir = ctx->vfs->opendir(ctx, path); |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
241 | ctx->aclreqaccess = m; // restore original access mask |
286
864e2d701dd4
set error status code directly in vfs_* calls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
277
diff
changeset
|
242 | if(!dir && ctx) { |
864e2d701dd4
set error status code directly in vfs_* calls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
277
diff
changeset
|
243 | sys_set_error_status(ctx); |
864e2d701dd4
set error status code directly in vfs_* calls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
277
diff
changeset
|
244 | } |
165
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
245 | return dir; |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
246 | } |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
247 | |
211
2160585200ac
add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
193
diff
changeset
|
248 | VFS_DIR vfs_fdopendir(VFSContext *ctx, SYS_FILE fd) { |
2160585200ac
add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
193
diff
changeset
|
249 | WS_ASSERT(ctx); |
2160585200ac
add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
193
diff
changeset
|
250 | WS_ASSERT(path); |
2160585200ac
add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
193
diff
changeset
|
251 | |
2160585200ac
add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
193
diff
changeset
|
252 | uint32_t access_mask = ctx->aclreqaccess | ACL_LIST; |
2160585200ac
add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
193
diff
changeset
|
253 | |
2160585200ac
add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
193
diff
changeset
|
254 | // ctx->aclreqaccess should be the complete access mask |
2160585200ac
add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
193
diff
changeset
|
255 | uint32_t m = ctx->aclreqaccess; // save original access mask |
2160585200ac
add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
193
diff
changeset
|
256 | ctx->aclreqaccess = access_mask; // set mask for vfs->open call |
2160585200ac
add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
193
diff
changeset
|
257 | if((ctx->vfs->flags & VFS_CHECKS_ACL) != VFS_CHECKS_ACL) { |
2160585200ac
add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
193
diff
changeset
|
258 | // VFS does not evaluates the ACL itself, so we have to do it here |
2160585200ac
add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
193
diff
changeset
|
259 | SysACL sysacl; |
2160585200ac
add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
193
diff
changeset
|
260 | if(sys_acl_check(ctx, access_mask, &sysacl)) { |
2160585200ac
add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
193
diff
changeset
|
261 | return NULL; |
2160585200ac
add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
193
diff
changeset
|
262 | } |
2160585200ac
add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
193
diff
changeset
|
263 | } |
2160585200ac
add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
193
diff
changeset
|
264 | VFS_DIR dir = ctx->vfs->fdopendir(ctx, fd); |
2160585200ac
add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
193
diff
changeset
|
265 | ctx->aclreqaccess = m; // restore original access mask |
286
864e2d701dd4
set error status code directly in vfs_* calls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
277
diff
changeset
|
266 | if(!dir && ctx) { |
864e2d701dd4
set error status code directly in vfs_* calls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
277
diff
changeset
|
267 | sys_set_error_status(ctx); |
864e2d701dd4
set error status code directly in vfs_* calls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
277
diff
changeset
|
268 | } |
211
2160585200ac
add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
193
diff
changeset
|
269 | return dir; |
2160585200ac
add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
193
diff
changeset
|
270 | } |
2160585200ac
add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
193
diff
changeset
|
271 | |
165
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
272 | int vfs_readdir(VFS_DIR dir, VFS_ENTRY *entry) { |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
273 | WS_ASSERT(dir); |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
274 | WS_ASSERT(entry); |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
275 | |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
276 | return dir->io->readdir(dir, entry, 0); |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
277 | } |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
278 | |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
279 | int vfs_readdir_stat(VFS_DIR dir, VFS_ENTRY *entry) { |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
280 | WS_ASSERT(dir); |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
281 | WS_ASSERT(entry); |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
282 | |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
283 | return dir->io->readdir(dir, entry, 1); |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
284 | } |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
285 | |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
286 | void vfs_closedir(VFS_DIR dir) { |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
287 | WS_ASSERT(dir); |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
288 | |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
289 | dir->io->close(dir); |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
290 | if(dir->ctx) { |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
291 | VFS_FREE(dir->ctx->pool, dir); |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
292 | } else { |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
293 | free(dir); |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
294 | } |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
295 | } |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
296 | |
241
4adad7faf452
add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
211
diff
changeset
|
297 | int vfs_mkdir(VFSContext *ctx, const char *path) { |
165
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
298 | WS_ASSERT(ctx); |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
299 | WS_ASSERT(path); |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
300 | |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
301 | return vfs_path_op(ctx, path, ctx->vfs->mkdir, ACL_ADD_FILE); |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
302 | } |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
303 | |
241
4adad7faf452
add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
211
diff
changeset
|
304 | int vfs_unlink(VFSContext *ctx, const char *path) { |
165
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
305 | WS_ASSERT(ctx); |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
306 | WS_ASSERT(path); |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
307 | |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
308 | return vfs_path_op(ctx, path, ctx->vfs->unlink, ACL_DELETE); |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
309 | } |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
310 | |
247
1df803e06076
implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
241
diff
changeset
|
311 | int vfs_rmdir(VFSContext *ctx, const char *path) { |
1df803e06076
implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
241
diff
changeset
|
312 | WS_ASSERT(ctx); |
1df803e06076
implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
241
diff
changeset
|
313 | WS_ASSERT(path); |
1df803e06076
implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
241
diff
changeset
|
314 | |
1df803e06076
implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
241
diff
changeset
|
315 | return vfs_path_op(ctx, path, ctx->vfs->rmdir, ACL_DELETE); |
1df803e06076
implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
241
diff
changeset
|
316 | } |
165
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
317 | |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
318 | // private |
241
4adad7faf452
add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
211
diff
changeset
|
319 | int vfs_path_op(VFSContext *ctx, const char *path, vfs_op_f op, uint32_t access) { |
165
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
320 | uint32_t access_mask = ctx->aclreqaccess; |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
321 | access_mask |= access; |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
322 | |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
323 | // ctx->aclreqaccess should be the complete access mask |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
324 | uint32_t m = ctx->aclreqaccess; // save original access mask |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
325 | ctx->aclreqaccess = access_mask; // set mask for vfs function call |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
326 | if((ctx->vfs->flags & VFS_CHECKS_ACL) != VFS_CHECKS_ACL) { |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
327 | // VFS does not evaluates the ACL itself, so we have to do it here |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
328 | SysACL sysacl; |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
329 | if(sys_acl_check(ctx, access_mask, &sysacl)) { |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
330 | return -1; |
54 | 331 | } |
332 | } | |
165
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
333 | int ret = op(ctx, path); |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
334 | ctx->aclreqaccess = m; // restore original access mask |
286
864e2d701dd4
set error status code directly in vfs_* calls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
277
diff
changeset
|
335 | if(ret && ctx) { |
864e2d701dd4
set error status code directly in vfs_* calls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
277
diff
changeset
|
336 | sys_set_error_status(ctx); |
864e2d701dd4
set error status code directly in vfs_* calls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
277
diff
changeset
|
337 | } |
165
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
338 | return ret; |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
339 | } |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
340 | |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
341 | /* system vfs implementation */ |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
342 | |
241
4adad7faf452
add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
211
diff
changeset
|
343 | SYS_FILE sys_vfs_open(VFSContext *ctx, const char *path, int oflags) { |
165
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
344 | uint32_t access_mask = ctx->aclreqaccess; |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
345 | pool_handle_t *pool = ctx->pool; |
54 | 346 | |
347 | // check ACLs | |
63
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
348 | SysACL sysacl; |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
349 | if(sys_acl_check(ctx, access_mask, &sysacl)) { |
54 | 350 | return NULL; |
351 | } | |
352 | ||
63
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
353 | if(sysacl.acl) { |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
354 | if(!fs_acl_check(&sysacl, ctx->user, path, access_mask)) { |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
355 | acl_set_error_status(ctx->sn, ctx->rq, sysacl.acl, ctx->user); |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
356 | return NULL; |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
357 | } |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
358 | } |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
359 | |
54 | 360 | // open file |
58
66c22e54aa90
webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
57
diff
changeset
|
361 | mode_t mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH; |
66c22e54aa90
webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
57
diff
changeset
|
362 | int fd = open(path, oflags, mode); |
54 | 363 | if(fd == -1) { |
364 | if(ctx) { | |
365 | ctx->vfs_errno = errno; | |
366 | sys_set_error_status(ctx); | |
367 | } | |
368 | return NULL; | |
369 | } | |
370 | ||
63
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
371 | // if a file system acl is active, we set the owner for newly created files |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
372 | if(((oflags & O_CREAT) == O_CREAT) && sysacl.user_uid != -1) { |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
373 | if(fchown(fd, sysacl.user_uid, sysacl.user_gid)) { |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
374 | perror("vfs_open: fchown"); |
171
af7e2d80dee6
adds wrapper for close syscall with error handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
375 | system_close(fd); |
63
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
376 | return NULL; |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
377 | } |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
378 | } |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
379 | |
165
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
380 | VFSFile *file = VFS_MALLOC(pool, sizeof(VFSFile)); |
54 | 381 | if(!file) { |
171
af7e2d80dee6
adds wrapper for close syscall with error handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
382 | system_close(fd); |
54 | 383 | return NULL; |
384 | } | |
385 | file->ctx = ctx; | |
386 | file->data = NULL; | |
387 | file->fd = fd; | |
388 | file->io = &sys_file_io; | |
389 | return file; | |
390 | } | |
391 | ||
241
4adad7faf452
add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
211
diff
changeset
|
392 | int sys_vfs_stat(VFSContext *ctx, const char *path, struct stat *buf) { |
165
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
393 | uint32_t access_mask = ctx->aclreqaccess; |
54 | 394 | |
395 | // check ACLs | |
63
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
396 | SysACL sysacl; |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
397 | if(sys_acl_check(ctx, access_mask, &sysacl)) { |
57 | 398 | return -1; |
54 | 399 | } |
400 | ||
63
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
401 | if(sysacl.acl) { |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
402 | if(!fs_acl_check(&sysacl, ctx->user, path, access_mask)) { |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
403 | acl_set_error_status(ctx->sn, ctx->rq, sysacl.acl, ctx->user); |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
404 | return -1; |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
405 | } |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
406 | } |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
407 | |
54 | 408 | // stat |
409 | if(stat(path, buf)) { | |
410 | if(ctx) { | |
411 | ctx->vfs_errno = errno; | |
412 | sys_set_error_status(ctx); | |
413 | } | |
414 | return -1; | |
415 | } | |
416 | ||
417 | return 0; | |
418 | } | |
419 | ||
165
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
420 | int sys_vfs_fstat(VFSContext *ctx, SYS_FILE fd, struct stat *buf) { |
54 | 421 | // stat |
422 | if(fstat(fd->fd, buf)) { | |
423 | if(ctx) { | |
424 | ctx->vfs_errno = errno; | |
425 | } | |
426 | return -1; | |
427 | } | |
428 | ||
429 | return 0; | |
430 | } | |
431 | ||
241
4adad7faf452
add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
211
diff
changeset
|
432 | VFS_DIR sys_vfs_opendir(VFSContext *ctx, const char *path) { |
165
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
433 | uint32_t access_mask = ctx->aclreqaccess; |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
434 | pool_handle_t *pool = ctx->pool; |
55
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
435 | |
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
436 | // check ACLs |
63
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
437 | SysACL sysacl; |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
438 | if(sys_acl_check(ctx, access_mask, &sysacl)) { |
55
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
439 | return NULL; |
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
440 | } |
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
441 | |
63
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
442 | if(sysacl.acl) { |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
443 | if(!fs_acl_check(&sysacl, ctx->user, path, access_mask)) { |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
444 | acl_set_error_status(ctx->sn, ctx->rq, sysacl.acl, ctx->user); |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
445 | return NULL; |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
446 | } |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
447 | } |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
448 | |
72 | 449 | // open directory |
450 | #ifdef BSD | |
69
4a10bc0ee80d
compiles on os x
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
67
diff
changeset
|
451 | DIR *sys_dir = opendir(path); |
97
09fbefc0e6a9
added ldap group support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
92
diff
changeset
|
452 | int dir_fd = sys_dir ? dirfd(sys_dir) : 0; |
72 | 453 | #else |
454 | int dir_fd = open(path, O_RDONLY); | |
455 | if(dir_fd == -1) { | |
456 | if(ctx) { | |
457 | ctx->vfs_errno = errno; | |
458 | sys_set_error_status(ctx); | |
459 | } | |
460 | return NULL; | |
461 | } | |
462 | DIR *sys_dir = fdopendir(dir_fd); | |
463 | #endif | |
55
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
464 | if(!sys_dir) { |
269
3dfbd0b91950
add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
247
diff
changeset
|
465 | if(dir_fd > 0) { |
3dfbd0b91950
add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
247
diff
changeset
|
466 | close(dir_fd); |
3dfbd0b91950
add ResourcePool initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
247
diff
changeset
|
467 | } |
55
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
468 | if(ctx) { |
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
469 | ctx->vfs_errno = errno; |
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
470 | sys_set_error_status(ctx); |
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
471 | } |
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
472 | return NULL; |
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
473 | } |
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
474 | |
165
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
475 | SysVFSDir *dir_data = VFS_MALLOC(pool, sizeof(SysVFSDir)); |
105
63d9051fe35c
using readdir_r instead of readdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
97
diff
changeset
|
476 | if(!dir_data) { |
63d9051fe35c
using readdir_r instead of readdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
97
diff
changeset
|
477 | closedir(sys_dir); |
63d9051fe35c
using readdir_r instead of readdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
97
diff
changeset
|
478 | return NULL; |
63d9051fe35c
using readdir_r instead of readdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
97
diff
changeset
|
479 | } |
63d9051fe35c
using readdir_r instead of readdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
97
diff
changeset
|
480 | long maxfilelen = fpathconf(dir_fd, _PC_NAME_MAX); |
63d9051fe35c
using readdir_r instead of readdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
97
diff
changeset
|
481 | size_t entry_len = offsetof(struct dirent, d_name) + maxfilelen + 1; |
165
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
482 | dir_data->cur = VFS_MALLOC(pool, entry_len); |
105
63d9051fe35c
using readdir_r instead of readdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
97
diff
changeset
|
483 | if(!dir_data->cur) { |
63d9051fe35c
using readdir_r instead of readdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
97
diff
changeset
|
484 | closedir(sys_dir); |
165
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
485 | VFS_FREE(pool, dir_data); |
105
63d9051fe35c
using readdir_r instead of readdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
97
diff
changeset
|
486 | return NULL; |
63d9051fe35c
using readdir_r instead of readdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
97
diff
changeset
|
487 | } |
63d9051fe35c
using readdir_r instead of readdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
97
diff
changeset
|
488 | dir_data->dir = sys_dir; |
63d9051fe35c
using readdir_r instead of readdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
97
diff
changeset
|
489 | |
165
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
490 | VFSDir *dir = VFS_MALLOC(pool, sizeof(VFSDir)); |
55
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
491 | if(!dir) { |
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
492 | closedir(sys_dir); |
165
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
493 | VFS_FREE(pool, dir_data->cur); |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
494 | VFS_FREE(pool, dir_data); |
55
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
495 | return NULL; |
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
496 | } |
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
497 | dir->ctx = ctx; |
105
63d9051fe35c
using readdir_r instead of readdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
97
diff
changeset
|
498 | dir->data = dir_data; |
72 | 499 | dir->fd = dir_fd; |
55
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
500 | dir->io = &sys_dir_io; |
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
501 | return dir; |
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
502 | } |
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
503 | |
211
2160585200ac
add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
193
diff
changeset
|
504 | VFS_DIR sys_vfs_fdopendir(VFSContext *ctx, SYS_FILE fd) { |
2160585200ac
add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
193
diff
changeset
|
505 | uint32_t access_mask = ctx->aclreqaccess; |
2160585200ac
add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
193
diff
changeset
|
506 | pool_handle_t *pool = ctx->pool; |
2160585200ac
add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
193
diff
changeset
|
507 | |
2160585200ac
add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
193
diff
changeset
|
508 | // check ACLs |
2160585200ac
add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
193
diff
changeset
|
509 | SysACL sysacl; |
2160585200ac
add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
193
diff
changeset
|
510 | if(sys_acl_check(ctx, access_mask, &sysacl)) { |
2160585200ac
add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
193
diff
changeset
|
511 | return NULL; |
2160585200ac
add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
193
diff
changeset
|
512 | } |
2160585200ac
add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
193
diff
changeset
|
513 | |
2160585200ac
add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
193
diff
changeset
|
514 | if(sysacl.acl) { |
2160585200ac
add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
193
diff
changeset
|
515 | if(!fs_acl_check_fd(&sysacl, ctx->user, fd->fd, access_mask)) { |
2160585200ac
add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
193
diff
changeset
|
516 | acl_set_error_status(ctx->sn, ctx->rq, sysacl.acl, ctx->user); |
2160585200ac
add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
193
diff
changeset
|
517 | return NULL; |
2160585200ac
add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
193
diff
changeset
|
518 | } |
2160585200ac
add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
193
diff
changeset
|
519 | } |
2160585200ac
add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
193
diff
changeset
|
520 | |
2160585200ac
add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
193
diff
changeset
|
521 | // open directory |
2160585200ac
add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
193
diff
changeset
|
522 | DIR *sys_dir = fdopendir(fd->fd); |
2160585200ac
add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
193
diff
changeset
|
523 | if(!sys_dir) { |
2160585200ac
add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
193
diff
changeset
|
524 | if(ctx) { |
2160585200ac
add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
193
diff
changeset
|
525 | ctx->vfs_errno = errno; |
2160585200ac
add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
193
diff
changeset
|
526 | sys_set_error_status(ctx); |
2160585200ac
add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
193
diff
changeset
|
527 | } |
2160585200ac
add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
193
diff
changeset
|
528 | return NULL; |
2160585200ac
add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
193
diff
changeset
|
529 | } |
2160585200ac
add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
193
diff
changeset
|
530 | |
2160585200ac
add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
193
diff
changeset
|
531 | SysVFSDir *dir_data = VFS_MALLOC(pool, sizeof(SysVFSDir)); |
2160585200ac
add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
193
diff
changeset
|
532 | if(!dir_data) { |
2160585200ac
add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
193
diff
changeset
|
533 | closedir(sys_dir); |
2160585200ac
add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
193
diff
changeset
|
534 | return NULL; |
2160585200ac
add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
193
diff
changeset
|
535 | } |
2160585200ac
add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
193
diff
changeset
|
536 | long maxfilelen = fpathconf(fd->fd, _PC_NAME_MAX); |
2160585200ac
add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
193
diff
changeset
|
537 | size_t entry_len = offsetof(struct dirent, d_name) + maxfilelen + 1; |
2160585200ac
add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
193
diff
changeset
|
538 | dir_data->cur = VFS_MALLOC(pool, entry_len); |
2160585200ac
add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
193
diff
changeset
|
539 | if(!dir_data->cur) { |
2160585200ac
add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
193
diff
changeset
|
540 | closedir(sys_dir); |
2160585200ac
add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
193
diff
changeset
|
541 | VFS_FREE(pool, dir_data); |
2160585200ac
add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
193
diff
changeset
|
542 | return NULL; |
2160585200ac
add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
193
diff
changeset
|
543 | } |
2160585200ac
add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
193
diff
changeset
|
544 | dir_data->dir = sys_dir; |
2160585200ac
add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
193
diff
changeset
|
545 | |
2160585200ac
add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
193
diff
changeset
|
546 | VFSDir *dir = VFS_MALLOC(pool, sizeof(VFSDir)); |
2160585200ac
add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
193
diff
changeset
|
547 | if(!dir) { |
2160585200ac
add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
193
diff
changeset
|
548 | closedir(sys_dir); |
2160585200ac
add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
193
diff
changeset
|
549 | VFS_FREE(pool, dir_data->cur); |
2160585200ac
add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
193
diff
changeset
|
550 | VFS_FREE(pool, dir_data); |
2160585200ac
add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
193
diff
changeset
|
551 | return NULL; |
2160585200ac
add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
193
diff
changeset
|
552 | } |
2160585200ac
add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
193
diff
changeset
|
553 | dir->ctx = ctx; |
2160585200ac
add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
193
diff
changeset
|
554 | dir->data = dir_data; |
2160585200ac
add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
193
diff
changeset
|
555 | dir->fd = fd->fd; |
2160585200ac
add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
193
diff
changeset
|
556 | dir->io = &sys_dir_io; |
2160585200ac
add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
193
diff
changeset
|
557 | return dir; |
2160585200ac
add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
193
diff
changeset
|
558 | } |
2160585200ac
add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
193
diff
changeset
|
559 | |
241
4adad7faf452
add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
211
diff
changeset
|
560 | int sys_vfs_mkdir(VFSContext *ctx, const char *path) { |
165
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
561 | return sys_path_op(ctx, path, sys_mkdir); |
55
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
562 | } |
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
563 | |
241
4adad7faf452
add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
211
diff
changeset
|
564 | int sys_vfs_unlink(VFSContext *ctx, const char *path) { |
165
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
565 | return sys_path_op(ctx, path, sys_unlink); |
56
c6cf20b09043
added vfs_mkdir and vfs_unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
55
diff
changeset
|
566 | } |
c6cf20b09043
added vfs_mkdir and vfs_unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
55
diff
changeset
|
567 | |
247
1df803e06076
implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
241
diff
changeset
|
568 | int sys_vfs_rmdir(VFSContext *ctx, const char *path) { |
1df803e06076
implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
241
diff
changeset
|
569 | return sys_path_op(ctx, path, sys_rmdir); |
1df803e06076
implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
241
diff
changeset
|
570 | } |
1df803e06076
implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
241
diff
changeset
|
571 | |
54 | 572 | |
241
4adad7faf452
add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
211
diff
changeset
|
573 | int sys_path_op(VFSContext *ctx, const char *path, sys_op_f op) { |
63
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
574 | uint32_t access_mask = ctx->aclreqaccess; |
56
c6cf20b09043
added vfs_mkdir and vfs_unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
55
diff
changeset
|
575 | |
c6cf20b09043
added vfs_mkdir and vfs_unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
55
diff
changeset
|
576 | // check ACLs |
63
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
577 | SysACL sysacl; |
165
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
578 | if(sys_acl_check(ctx, access_mask, &sysacl)) { |
57 | 579 | return -1; |
56
c6cf20b09043
added vfs_mkdir and vfs_unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
55
diff
changeset
|
580 | } |
c6cf20b09043
added vfs_mkdir and vfs_unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
55
diff
changeset
|
581 | |
63
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
582 | if(sysacl.acl) { |
165
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
583 | if(!fs_acl_check(&sysacl, ctx->user, path, access_mask)) { |
63
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
584 | acl_set_error_status(ctx->sn, ctx->rq, sysacl.acl, ctx->user); |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
585 | return -1; |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
586 | } |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
587 | } |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
588 | |
56
c6cf20b09043
added vfs_mkdir and vfs_unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
55
diff
changeset
|
589 | // do path operation |
63
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
590 | if(op(ctx, path, &sysacl)) { |
56
c6cf20b09043
added vfs_mkdir and vfs_unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
55
diff
changeset
|
591 | // error |
165
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
592 | ctx->vfs_errno = errno; |
6942a8c3e737
refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
593 | sys_set_error_status(ctx); |
56
c6cf20b09043
added vfs_mkdir and vfs_unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
55
diff
changeset
|
594 | return -1; |
c6cf20b09043
added vfs_mkdir and vfs_unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
55
diff
changeset
|
595 | } |
c6cf20b09043
added vfs_mkdir and vfs_unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
55
diff
changeset
|
596 | |
c6cf20b09043
added vfs_mkdir and vfs_unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
55
diff
changeset
|
597 | return 0; |
c6cf20b09043
added vfs_mkdir and vfs_unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
55
diff
changeset
|
598 | } |
54 | 599 | |
63
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
600 | int sys_acl_check(VFSContext *ctx, uint32_t access_mask, SysACL *sysacl) { |
67
50505dc3f8a6
dynamic thread pool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
66
diff
changeset
|
601 | if(sysacl) { |
50505dc3f8a6
dynamic thread pool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
66
diff
changeset
|
602 | sysacl->acl = NULL; |
50505dc3f8a6
dynamic thread pool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
66
diff
changeset
|
603 | } |
54 | 604 | if(!ctx) { |
605 | return 0; | |
606 | } | |
607 | ||
608 | ACLListHandle *acllist = ctx->acllist; | |
609 | if(acllist) { | |
63
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
610 | ACLList *acl = acl_evallist( |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
611 | acllist, |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
612 | ctx->user, |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
613 | access_mask, |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
614 | &sysacl->acl); |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
615 | |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
616 | if(acl) { |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
617 | acl_set_error_status(ctx->sn, ctx->rq, acl, ctx->user); |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
618 | return 1; |
54 | 619 | } |
620 | } | |
621 | ||
622 | return 0; | |
623 | } | |
624 | ||
625 | void sys_set_error_status(VFSContext *ctx) { | |
286
864e2d701dd4
set error status code directly in vfs_* calls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
277
diff
changeset
|
626 | if(ctx->sn && ctx->rq && !ctx->error_response_set) { |
56
c6cf20b09043
added vfs_mkdir and vfs_unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
55
diff
changeset
|
627 | int status = util_errno2status(ctx->vfs_errno); |
54 | 628 | protocol_status(ctx->sn, ctx->rq, status, NULL); |
286
864e2d701dd4
set error status code directly in vfs_* calls
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
277
diff
changeset
|
629 | ctx->error_response_set = TRUE; |
54 | 630 | } |
631 | } | |
632 | ||
633 | ssize_t sys_file_read(SYS_FILE fd, void *buf, size_t nbyte) { | |
634 | return read(fd->fd, buf, nbyte); | |
635 | } | |
636 | ||
637 | ssize_t sys_file_write(SYS_FILE fd, const void *buf, size_t nbyte) { | |
638 | return write(fd->fd, buf, nbyte); | |
639 | } | |
640 | ||
189
a2438f6d1e73
adds vfs pread/pwrite functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
187
diff
changeset
|
641 | ssize_t sys_file_pread(SYS_FILE fd, void *buf, size_t nbyte, off_t offset) { |
a2438f6d1e73
adds vfs pread/pwrite functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
187
diff
changeset
|
642 | return pread(fd->fd, buf, nbyte, offset); |
a2438f6d1e73
adds vfs pread/pwrite functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
187
diff
changeset
|
643 | } |
a2438f6d1e73
adds vfs pread/pwrite functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
187
diff
changeset
|
644 | |
a2438f6d1e73
adds vfs pread/pwrite functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
187
diff
changeset
|
645 | ssize_t sys_file_pwrite(SYS_FILE fd, const void *buf, size_t nbyte, off_t offset) { |
a2438f6d1e73
adds vfs pread/pwrite functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
187
diff
changeset
|
646 | return pwrite(fd->fd, buf, nbyte, offset); |
a2438f6d1e73
adds vfs pread/pwrite functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
187
diff
changeset
|
647 | } |
a2438f6d1e73
adds vfs pread/pwrite functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
187
diff
changeset
|
648 | |
66
74babc0082b7
added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
63
diff
changeset
|
649 | off_t sys_file_seek(SYS_FILE fd, off_t offset, int whence) { |
74babc0082b7
added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
63
diff
changeset
|
650 | return lseek(fd->fd, offset, whence); |
74babc0082b7
added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
63
diff
changeset
|
651 | } |
74babc0082b7
added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
63
diff
changeset
|
652 | |
54 | 653 | void sys_file_close(SYS_FILE fd) { |
171
af7e2d80dee6
adds wrapper for close syscall with error handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
105
diff
changeset
|
654 | system_close(fd->fd); |
54 | 655 | } |
55
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
656 | |
172
5580517faafc
adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
165
diff
changeset
|
657 | int sys_file_aioread(aiocb_s *aiocb) { |
5580517faafc
adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
165
diff
changeset
|
658 | WS_ASSERT(aiocb->buf); |
5580517faafc
adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
165
diff
changeset
|
659 | WS_ASSERT(aiocb->nbytes > 0); |
5580517faafc
adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
165
diff
changeset
|
660 | return ev_aioread(aiocb->filedes->fd, aiocb); |
5580517faafc
adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
165
diff
changeset
|
661 | } |
5580517faafc
adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
165
diff
changeset
|
662 | |
5580517faafc
adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
165
diff
changeset
|
663 | int sys_file_aiowrite(aiocb_s *aiocb) { |
5580517faafc
adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
165
diff
changeset
|
664 | WS_ASSERT(aiocb->buf); |
5580517faafc
adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
165
diff
changeset
|
665 | WS_ASSERT(aiocb->nbytes > 0); |
5580517faafc
adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
165
diff
changeset
|
666 | return ev_aiowrite(aiocb->filedes->fd, aiocb); |
5580517faafc
adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
165
diff
changeset
|
667 | } |
5580517faafc
adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
165
diff
changeset
|
668 | |
5580517faafc
adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
165
diff
changeset
|
669 | |
55
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
670 | int sys_dir_read(VFS_DIR dir, VFS_ENTRY *entry, int getstat) { |
105
63d9051fe35c
using readdir_r instead of readdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
97
diff
changeset
|
671 | SysVFSDir *dirdata = dir->data; |
63d9051fe35c
using readdir_r instead of readdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
97
diff
changeset
|
672 | struct dirent *result = NULL; |
63d9051fe35c
using readdir_r instead of readdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
97
diff
changeset
|
673 | int s = readdir_r(dirdata->dir, dirdata->cur, &result); |
63d9051fe35c
using readdir_r instead of readdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
97
diff
changeset
|
674 | if(!s && result) { |
63d9051fe35c
using readdir_r instead of readdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
97
diff
changeset
|
675 | char *name = result->d_name; |
58
66c22e54aa90
webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
57
diff
changeset
|
676 | if(!strcmp(name, ".") || !strcmp(name, "..")) { |
66c22e54aa90
webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
57
diff
changeset
|
677 | return sys_dir_read(dir, entry, getstat); |
66c22e54aa90
webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
57
diff
changeset
|
678 | } else { |
66c22e54aa90
webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
57
diff
changeset
|
679 | entry->name = name; |
66c22e54aa90
webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
57
diff
changeset
|
680 | if(getstat) { |
66c22e54aa90
webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
57
diff
changeset
|
681 | // TODO: check ACLs again for new path |
211
2160585200ac
add propfind/proppatch parser and first iteration of the new webdav api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
193
diff
changeset
|
682 | entry->stat_errno = 0; |
105
63d9051fe35c
using readdir_r instead of readdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
97
diff
changeset
|
683 | if(fstatat(dir->fd, result->d_name, &entry->stat, 0)) { |
58
66c22e54aa90
webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
57
diff
changeset
|
684 | entry->stat_errno = errno; |
66c22e54aa90
webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
57
diff
changeset
|
685 | } |
66c22e54aa90
webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
57
diff
changeset
|
686 | entry->stat_extra = NULL; |
185
b4d7ccf4e06d
implements new event handler and aio on linux
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
172
diff
changeset
|
687 | } |
58
66c22e54aa90
webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
57
diff
changeset
|
688 | return 1; |
55
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
689 | } |
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
690 | } else { |
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
691 | return 0; |
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
692 | } |
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
693 | } |
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
694 | |
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
695 | void sys_dir_close(VFS_DIR dir) { |
105
63d9051fe35c
using readdir_r instead of readdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
97
diff
changeset
|
696 | SysVFSDir *dirdata = dir->data; |
63d9051fe35c
using readdir_r instead of readdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
97
diff
changeset
|
697 | closedir(dirdata->dir); |
63d9051fe35c
using readdir_r instead of readdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
97
diff
changeset
|
698 | |
63d9051fe35c
using readdir_r instead of readdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
97
diff
changeset
|
699 | pool_handle_t *pool = dir->ctx->pool; |
63d9051fe35c
using readdir_r instead of readdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
97
diff
changeset
|
700 | if(pool) { |
63d9051fe35c
using readdir_r instead of readdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
97
diff
changeset
|
701 | pool_free(pool, dirdata->cur); |
63d9051fe35c
using readdir_r instead of readdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
97
diff
changeset
|
702 | pool_free(pool, dirdata); |
63d9051fe35c
using readdir_r instead of readdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
97
diff
changeset
|
703 | pool_free(pool, dir); |
63d9051fe35c
using readdir_r instead of readdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
97
diff
changeset
|
704 | } else { |
63d9051fe35c
using readdir_r instead of readdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
97
diff
changeset
|
705 | free(dirdata->cur); |
63d9051fe35c
using readdir_r instead of readdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
97
diff
changeset
|
706 | free(dirdata); |
63d9051fe35c
using readdir_r instead of readdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
97
diff
changeset
|
707 | free(dir); |
63d9051fe35c
using readdir_r instead of readdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
97
diff
changeset
|
708 | } |
55
b7908bf38f9f
vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
54
diff
changeset
|
709 | } |
56
c6cf20b09043
added vfs_mkdir and vfs_unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
55
diff
changeset
|
710 | |
241
4adad7faf452
add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
211
diff
changeset
|
711 | int sys_mkdir(VFSContext *ctx, const char *path, SysACL *sysacl) { |
56
c6cf20b09043
added vfs_mkdir and vfs_unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
55
diff
changeset
|
712 | mode_t mode = S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH; |
63
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
713 | int ret = mkdir(path, mode); |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
714 | if(ret == 0) { |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
715 | if(sysacl->user_uid != -1) { |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
716 | if(chown(path, sysacl->user_uid, sysacl->user_gid)) { |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
717 | // TODO: error |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
718 | } |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
719 | } |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
720 | } |
66442f81f823
supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
59
diff
changeset
|
721 | return ret; |
56
c6cf20b09043
added vfs_mkdir and vfs_unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
55
diff
changeset
|
722 | } |
c6cf20b09043
added vfs_mkdir and vfs_unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
55
diff
changeset
|
723 | |
241
4adad7faf452
add proppatch op
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
211
diff
changeset
|
724 | int sys_unlink(VFSContext *ctx, const char *path, SysACL *sysacl) { |
56
c6cf20b09043
added vfs_mkdir and vfs_unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
55
diff
changeset
|
725 | return unlink(path); |
c6cf20b09043
added vfs_mkdir and vfs_unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
55
diff
changeset
|
726 | } |
58
66c22e54aa90
webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
57
diff
changeset
|
727 | |
247
1df803e06076
implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
241
diff
changeset
|
728 | int sys_rmdir(VFSContext *ctx, const char *path, SysACL *sysacl) { |
1df803e06076
implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
241
diff
changeset
|
729 | return rmdir(path); |
1df803e06076
implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
241
diff
changeset
|
730 | } |
1df803e06076
implement webdav delete for collections
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
241
diff
changeset
|
731 | |
58
66c22e54aa90
webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
57
diff
changeset
|
732 | /* public file api */ |
66c22e54aa90
webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
57
diff
changeset
|
733 | |
66c22e54aa90
webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
57
diff
changeset
|
734 | NSAPI_PUBLIC int system_fread(SYS_FILE fd, void *buf, int nbyte) { |
66c22e54aa90
webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
57
diff
changeset
|
735 | return fd->io->read(fd, buf, nbyte); |
66c22e54aa90
webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
57
diff
changeset
|
736 | } |
66c22e54aa90
webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
57
diff
changeset
|
737 | |
66c22e54aa90
webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
57
diff
changeset
|
738 | NSAPI_PUBLIC int system_fwrite(SYS_FILE fd, const void *buf, int nbyte) { |
66c22e54aa90
webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
57
diff
changeset
|
739 | return fd->io->write(fd, buf, nbyte); |
66c22e54aa90
webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
57
diff
changeset
|
740 | } |
66c22e54aa90
webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
57
diff
changeset
|
741 | |
189
a2438f6d1e73
adds vfs pread/pwrite functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
187
diff
changeset
|
742 | NSAPI_PUBLIC int system_pread(SYS_FILE fd, void *buf, int nbyte, off_t offset) { |
a2438f6d1e73
adds vfs pread/pwrite functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
187
diff
changeset
|
743 | return fd->io->pread(fd, buf, nbyte, offset); |
a2438f6d1e73
adds vfs pread/pwrite functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
187
diff
changeset
|
744 | } |
a2438f6d1e73
adds vfs pread/pwrite functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
187
diff
changeset
|
745 | |
a2438f6d1e73
adds vfs pread/pwrite functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
187
diff
changeset
|
746 | NSAPI_PUBLIC int system_pwrite(SYS_FILE fd, const void *buf, int nbyte, off_t offset) { |
a2438f6d1e73
adds vfs pread/pwrite functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
187
diff
changeset
|
747 | return fd->io->pwrite(fd, buf, nbyte, offset); |
a2438f6d1e73
adds vfs pread/pwrite functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
187
diff
changeset
|
748 | } |
a2438f6d1e73
adds vfs pread/pwrite functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
187
diff
changeset
|
749 | |
66
74babc0082b7
added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
63
diff
changeset
|
750 | NSAPI_PUBLIC off_t system_lseek(SYS_FILE fd, off_t offset, int whence) { |
74babc0082b7
added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
63
diff
changeset
|
751 | return fd->io->seek(fd, offset, whence); |
74babc0082b7
added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
63
diff
changeset
|
752 | } |
74babc0082b7
added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
63
diff
changeset
|
753 | |
58
66c22e54aa90
webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
57
diff
changeset
|
754 | NSAPI_PUBLIC int system_fclose(SYS_FILE fd) { |
66c22e54aa90
webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
57
diff
changeset
|
755 | vfs_close(fd); |
66c22e54aa90
webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
57
diff
changeset
|
756 | return 0; |
66c22e54aa90
webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
57
diff
changeset
|
757 | } |
172
5580517faafc
adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
165
diff
changeset
|
758 | |
5580517faafc
adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
165
diff
changeset
|
759 | // AIO API |
5580517faafc
adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
165
diff
changeset
|
760 | |
5580517faafc
adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
165
diff
changeset
|
761 | NSAPI_PUBLIC int system_aio_read(aiocb_s *aiocb) { |
5580517faafc
adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
165
diff
changeset
|
762 | if(!aiocb->event || !aiocb->evhandler) { |
5580517faafc
adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
165
diff
changeset
|
763 | return -1; |
5580517faafc
adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
165
diff
changeset
|
764 | } |
5580517faafc
adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
165
diff
changeset
|
765 | |
5580517faafc
adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
165
diff
changeset
|
766 | SYS_FILE file = aiocb->filedes; |
5580517faafc
adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
165
diff
changeset
|
767 | aiocb->event->object = (intptr_t)aiocb; |
5580517faafc
adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
165
diff
changeset
|
768 | if(file->io->opt_aioread) { |
5580517faafc
adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
165
diff
changeset
|
769 | return file->io->opt_aioread(aiocb); |
5580517faafc
adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
165
diff
changeset
|
770 | } else { |
187
4384bfbb7e26
adds platform independent aio functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
771 | vfs_queue_aio(aiocb, VFS_AIO_READ); |
4384bfbb7e26
adds platform independent aio functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
772 | return 0; |
172
5580517faafc
adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
165
diff
changeset
|
773 | } |
5580517faafc
adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
165
diff
changeset
|
774 | } |
5580517faafc
adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
165
diff
changeset
|
775 | |
5580517faafc
adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
165
diff
changeset
|
776 | NSAPI_PUBLIC int system_aio_write(aiocb_s *aiocb) { |
5580517faafc
adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
165
diff
changeset
|
777 | if(!aiocb->event || !aiocb->evhandler) { |
5580517faafc
adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
165
diff
changeset
|
778 | return -1; |
5580517faafc
adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
165
diff
changeset
|
779 | } |
5580517faafc
adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
165
diff
changeset
|
780 | |
5580517faafc
adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
165
diff
changeset
|
781 | SYS_FILE file = aiocb->filedes; |
5580517faafc
adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
165
diff
changeset
|
782 | aiocb->event->object = (intptr_t)aiocb; |
5580517faafc
adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
165
diff
changeset
|
783 | if(file->io->opt_aiowrite) { |
5580517faafc
adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
165
diff
changeset
|
784 | return file->io->opt_aiowrite(aiocb); |
5580517faafc
adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
165
diff
changeset
|
785 | } else { |
187
4384bfbb7e26
adds platform independent aio functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
786 | vfs_queue_aio(aiocb, VFS_AIO_WRITE); |
4384bfbb7e26
adds platform independent aio functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
787 | return 0; |
172
5580517faafc
adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
165
diff
changeset
|
788 | } |
5580517faafc
adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
165
diff
changeset
|
789 | } |
187
4384bfbb7e26
adds platform independent aio functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
790 | |
4384bfbb7e26
adds platform independent aio functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
791 | static void* vfs_aio_read(aiocb_s *aiocb) { |
189
a2438f6d1e73
adds vfs pread/pwrite functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
187
diff
changeset
|
792 | int result = system_pread(aiocb->filedes, aiocb->buf, aiocb->nbytes, aiocb->offset); |
187
4384bfbb7e26
adds platform independent aio functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
793 | aiocb->result = result; |
4384bfbb7e26
adds platform independent aio functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
794 | if(result < 0) { |
4384bfbb7e26
adds platform independent aio functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
795 | aiocb->result_errno = errno; |
4384bfbb7e26
adds platform independent aio functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
796 | } |
4384bfbb7e26
adds platform independent aio functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
797 | event_send(aiocb->evhandler, aiocb->event); |
4384bfbb7e26
adds platform independent aio functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
798 | return NULL; |
4384bfbb7e26
adds platform independent aio functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
799 | } |
4384bfbb7e26
adds platform independent aio functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
800 | |
4384bfbb7e26
adds platform independent aio functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
801 | static void* vfs_aio_write(aiocb_s *aiocb) { |
189
a2438f6d1e73
adds vfs pread/pwrite functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
187
diff
changeset
|
802 | int result = system_pwrite(aiocb->filedes, aiocb->buf, aiocb->nbytes, aiocb->offset); |
187
4384bfbb7e26
adds platform independent aio functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
803 | aiocb->result = result; |
4384bfbb7e26
adds platform independent aio functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
804 | if(result < 0) { |
4384bfbb7e26
adds platform independent aio functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
805 | aiocb->result_errno = errno; |
4384bfbb7e26
adds platform independent aio functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
806 | } |
4384bfbb7e26
adds platform independent aio functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
807 | event_send(aiocb->evhandler, aiocb->event); |
4384bfbb7e26
adds platform independent aio functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
808 | return NULL; |
4384bfbb7e26
adds platform independent aio functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
809 | } |
4384bfbb7e26
adds platform independent aio functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
810 | |
4384bfbb7e26
adds platform independent aio functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
811 | void vfs_queue_aio(aiocb_s *aiocb, VFSAioOp op) { |
190
1f73302461e0
adds IO threadpool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
189
diff
changeset
|
812 | threadpool_t *pool = get_default_iopool(); // TODO: use specific IOPool |
187
4384bfbb7e26
adds platform independent aio functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
813 | if(op == VFS_AIO_READ) { |
4384bfbb7e26
adds platform independent aio functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
814 | threadpool_run(pool, (job_callback_f)vfs_aio_read, aiocb); |
4384bfbb7e26
adds platform independent aio functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
815 | } else if(VFS_AIO_WRITE) { |
4384bfbb7e26
adds platform independent aio functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
816 | threadpool_run(pool, (job_callback_f)vfs_aio_write, aiocb); |
4384bfbb7e26
adds platform independent aio functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
817 | } |
4384bfbb7e26
adds platform independent aio functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
185
diff
changeset
|
818 | } |