src/server/daemon/vfs.c

Wed, 10 Jan 2018 17:25:55 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Wed, 10 Jan 2018 17:25:55 +0100
branch
aio
changeset 186
8041ac363f26
parent 185
b4d7ccf4e06d
child 187
4384bfbb7e26
permissions
-rw-r--r--

fixes aio error handling

54
3a1d5a52adfc new vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1 /*
3a1d5a52adfc new vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3a1d5a52adfc new vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
3 *
3a1d5a52adfc new vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
4 * Copyright 2013 Olaf Wintermann. All rights reserved.
3a1d5a52adfc new vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
5 *
3a1d5a52adfc new vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
6 * Redistribution and use in source and binary forms, with or without
3a1d5a52adfc new vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
7 * modification, are permitted provided that the following conditions are met:
3a1d5a52adfc new vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
8 *
3a1d5a52adfc new vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
9 * 1. Redistributions of source code must retain the above copyright
3a1d5a52adfc new vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
10 * notice, this list of conditions and the following disclaimer.
3a1d5a52adfc new vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
11 *
3a1d5a52adfc new vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
12 * 2. Redistributions in binary form must reproduce the above copyright
3a1d5a52adfc new vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
13 * notice, this list of conditions and the following disclaimer in the
3a1d5a52adfc new vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
14 * documentation and/or other materials provided with the distribution.
3a1d5a52adfc new vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
15 *
3a1d5a52adfc new vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
3a1d5a52adfc new vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
3a1d5a52adfc new vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
3a1d5a52adfc new vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
3a1d5a52adfc new vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
3a1d5a52adfc new vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
3a1d5a52adfc new vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
3a1d5a52adfc new vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
3a1d5a52adfc new vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
3a1d5a52adfc new vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
3a1d5a52adfc new vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
26 * POSSIBILITY OF SUCH DAMAGE.
3a1d5a52adfc new vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
27 */
3a1d5a52adfc new vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
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
3a1d5a52adfc new vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
31 #include <stdio.h>
3a1d5a52adfc new vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
32 #include <stdlib.h>
3a1d5a52adfc new vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
33 #include <unistd.h>
3a1d5a52adfc new vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
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>
54
3a1d5a52adfc new vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
36
92
382bff43c6eb fixed some includes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 87
diff changeset
37 #include <ucx/map.h>
382bff43c6eb fixed some includes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 87
diff changeset
38
54
3a1d5a52adfc new vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
39 #include "../util/pool.h"
63
66442f81f823 supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 59
diff changeset
40 #include "acl.h"
54
3a1d5a52adfc new vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
41 #include "vfs.h"
172
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 165
diff changeset
42 #include "event.h"
54
3a1d5a52adfc new vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
43
165
6942a8c3e737 refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 105
diff changeset
44 #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
45 #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
46
59
ab25c0a231d0 some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 58
diff changeset
47 static UcxMap *vfs_map;
ab25c0a231d0 some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 58
diff changeset
48
165
6942a8c3e737 refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 105
diff changeset
49 static VFS sys_vfs = {
6942a8c3e737 refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 105
diff changeset
50 sys_vfs_open,
6942a8c3e737 refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 105
diff changeset
51 sys_vfs_stat,
6942a8c3e737 refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 105
diff changeset
52 sys_vfs_fstat,
6942a8c3e737 refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 105
diff changeset
53 sys_vfs_opendir,
6942a8c3e737 refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 105
diff changeset
54 sys_vfs_mkdir,
6942a8c3e737 refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 105
diff changeset
55 sys_vfs_unlink,
6942a8c3e737 refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 105
diff changeset
56 VFS_CHECKS_ACL
6942a8c3e737 refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 105
diff changeset
57 };
6942a8c3e737 refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 105
diff changeset
58
54
3a1d5a52adfc new vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
59 static VFS_IO sys_file_io = {
3a1d5a52adfc new vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
60 sys_file_read,
3a1d5a52adfc new vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
61 sys_file_write,
66
74babc0082b7 added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 63
diff changeset
62 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
63 sys_file_close,
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 165
diff changeset
64 sys_file_aioread,
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 165
diff changeset
65 sys_file_aiowrite
54
3a1d5a52adfc new vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
66 };
3a1d5a52adfc new vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
67
55
b7908bf38f9f vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
68 static VFS_DIRIO sys_dir_io = {
b7908bf38f9f vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
69 sys_dir_read,
b7908bf38f9f vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
70 sys_dir_close
b7908bf38f9f vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
71 };
b7908bf38f9f vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
72
59
ab25c0a231d0 some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 58
diff changeset
73 int vfs_init() {
ab25c0a231d0 some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 58
diff changeset
74 vfs_map = ucx_map_new(16);
ab25c0a231d0 some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 58
diff changeset
75 if(!vfs_map) {
ab25c0a231d0 some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 58
diff changeset
76 return -1;
ab25c0a231d0 some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 58
diff changeset
77 }
ab25c0a231d0 some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 58
diff changeset
78 return 0;
ab25c0a231d0 some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 58
diff changeset
79 }
ab25c0a231d0 some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 58
diff changeset
80
ab25c0a231d0 some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 58
diff changeset
81 void vfs_add(char *name, VFS *vfs) {
87
bdec069d2239 fixed pathcheck behavior
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 72
diff changeset
82 WS_ASSERT(name);
bdec069d2239 fixed pathcheck behavior
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 72
diff changeset
83
59
ab25c0a231d0 some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 58
diff changeset
84 if(!vfs_map) {
ab25c0a231d0 some fixes and new public APIs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 58
diff changeset
85 vfs_init();
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 ucx_map_cstr_put(vfs_map, name, vfs);
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
54
3a1d5a52adfc new vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
90 VFSContext* vfs_request_context(Session *sn, Request *rq) {
87
bdec069d2239 fixed pathcheck behavior
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 72
diff changeset
91 WS_ASSERT(sn);
bdec069d2239 fixed pathcheck behavior
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 72
diff changeset
92 WS_ASSERT(rq);
bdec069d2239 fixed pathcheck behavior
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 72
diff changeset
93
54
3a1d5a52adfc new vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
94 VFSContext *ctx = pool_malloc(sn->pool, sizeof(VFSContext));
3a1d5a52adfc new vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
95 ctx->sn = sn;
3a1d5a52adfc new vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
96 ctx->rq = rq;
165
6942a8c3e737 refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 105
diff changeset
97 ctx->vfs = rq->vfs ? rq->vfs : &sys_vfs;
54
3a1d5a52adfc new vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
98 ctx->user = acllist_getuser(sn, rq, rq->acllist);
3a1d5a52adfc new vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
99 ctx->acllist = rq->acllist;
3a1d5a52adfc new vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
100 ctx->aclreqaccess = rq->aclreqaccess;
3a1d5a52adfc new vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
101 ctx->pool = sn->pool;
3a1d5a52adfc new vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
102 ctx->vfs_errno = 0;
3a1d5a52adfc new vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
103 return ctx;
3a1d5a52adfc new vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
104 }
3a1d5a52adfc new vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
105
3a1d5a52adfc new vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
106 SYS_FILE vfs_open(VFSContext *ctx, char *path, int oflags) {
165
6942a8c3e737 refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 105
diff changeset
107 WS_ASSERT(ctx);
6942a8c3e737 refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 105
diff changeset
108 WS_ASSERT(path);
6942a8c3e737 refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 105
diff changeset
109
6942a8c3e737 refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 105
diff changeset
110 uint32_t access_mask = ctx->aclreqaccess | acl_oflag2mask(oflags);
6942a8c3e737 refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 105
diff changeset
111
6942a8c3e737 refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 105
diff changeset
112 // ctx->aclreqaccess should be the complete access mask
6942a8c3e737 refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 105
diff changeset
113 uint32_t m = ctx->aclreqaccess; // save original access mask
6942a8c3e737 refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 105
diff changeset
114 ctx->aclreqaccess = access_mask; // set mask for vfs->open call
6942a8c3e737 refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 105
diff changeset
115 if((ctx->vfs->flags & VFS_CHECKS_ACL) != VFS_CHECKS_ACL) {
6942a8c3e737 refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 105
diff changeset
116 // 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
117 SysACL sysacl;
6942a8c3e737 refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 105
diff changeset
118 if(sys_acl_check(ctx, access_mask, &sysacl)) {
6942a8c3e737 refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 105
diff changeset
119 return NULL;
6942a8c3e737 refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 105
diff changeset
120 }
6942a8c3e737 refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 105
diff changeset
121 }
6942a8c3e737 refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 105
diff changeset
122 SYS_FILE file = ctx->vfs->open(ctx, path, oflags);
6942a8c3e737 refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 105
diff changeset
123 ctx->aclreqaccess = m; // restore original access mask
6942a8c3e737 refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 105
diff changeset
124 return file;
6942a8c3e737 refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 105
diff changeset
125 }
6942a8c3e737 refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 105
diff changeset
126
6942a8c3e737 refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 105
diff changeset
127 SYS_FILE vfs_openRO(VFSContext *ctx, char *path) {
6942a8c3e737 refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 105
diff changeset
128 return vfs_open(ctx, path, O_RDONLY);
6942a8c3e737 refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 105
diff changeset
129 }
6942a8c3e737 refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 105
diff changeset
130
6942a8c3e737 refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 105
diff changeset
131 SYS_FILE vfs_openWO(VFSContext *ctx, char *path) {
6942a8c3e737 refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 105
diff changeset
132 return vfs_open(ctx, path, O_WRONLY | O_CREAT);
6942a8c3e737 refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 105
diff changeset
133 }
6942a8c3e737 refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 105
diff changeset
134
6942a8c3e737 refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 105
diff changeset
135 SYS_FILE vfs_openRW(VFSContext *ctx, char *path) {
6942a8c3e737 refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 105
diff changeset
136 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
137 }
6942a8c3e737 refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 105
diff changeset
138
6942a8c3e737 refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 105
diff changeset
139 int vfs_stat(VFSContext *ctx, char *path, struct stat *buf) {
6942a8c3e737 refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 105
diff changeset
140 WS_ASSERT(ctx);
6942a8c3e737 refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 105
diff changeset
141 WS_ASSERT(path);
6942a8c3e737 refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 105
diff changeset
142
6942a8c3e737 refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 105
diff changeset
143 uint32_t access_mask = ctx->aclreqaccess | ACL_READ_ATTRIBUTES;
6942a8c3e737 refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 105
diff changeset
144
6942a8c3e737 refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 105
diff changeset
145 // ctx->aclreqaccess should be the complete access mask
6942a8c3e737 refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 105
diff changeset
146 uint32_t m = ctx->aclreqaccess; // save original access mask
6942a8c3e737 refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 105
diff changeset
147 ctx->aclreqaccess = access_mask; // set mask for vfs->open call
6942a8c3e737 refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 105
diff changeset
148 if((ctx->vfs->flags & VFS_CHECKS_ACL) != VFS_CHECKS_ACL) {
6942a8c3e737 refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 105
diff changeset
149 // 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
150 SysACL sysacl;
6942a8c3e737 refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 105
diff changeset
151 if(sys_acl_check(ctx, access_mask, &sysacl)) {
6942a8c3e737 refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 105
diff changeset
152 return -1;
6942a8c3e737 refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 105
diff changeset
153 }
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 int ret = ctx->vfs->stat(ctx, path, buf);
6942a8c3e737 refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 105
diff changeset
156 ctx->aclreqaccess = m; // restore original access mask
6942a8c3e737 refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 105
diff changeset
157 return ret;
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
6942a8c3e737 refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 105
diff changeset
160 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
161 WS_ASSERT(ctx);
6942a8c3e737 refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 105
diff changeset
162 WS_ASSERT(fd);
6942a8c3e737 refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 105
diff changeset
163 WS_ASSERT(buf);
6942a8c3e737 refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 105
diff changeset
164
6942a8c3e737 refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 105
diff changeset
165 return ctx->vfs->fstat(ctx, fd, buf);
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
6942a8c3e737 refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 105
diff changeset
168 void vfs_close(SYS_FILE fd) {
6942a8c3e737 refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 105
diff changeset
169 WS_ASSERT(fd);
6942a8c3e737 refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 105
diff changeset
170
6942a8c3e737 refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 105
diff changeset
171 fd->io->close(fd);
6942a8c3e737 refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 105
diff changeset
172 if(fd->ctx) {
6942a8c3e737 refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 105
diff changeset
173 pool_free(fd->ctx->pool, fd);
6942a8c3e737 refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 105
diff changeset
174 } else {
6942a8c3e737 refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 105
diff changeset
175 free(fd);
6942a8c3e737 refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 105
diff changeset
176 }
6942a8c3e737 refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 105
diff changeset
177 }
6942a8c3e737 refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 105
diff changeset
178
6942a8c3e737 refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 105
diff changeset
179 VFS_DIR vfs_opendir(VFSContext *ctx, char *path) {
6942a8c3e737 refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 105
diff changeset
180 WS_ASSERT(ctx);
87
bdec069d2239 fixed pathcheck behavior
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 72
diff changeset
181 WS_ASSERT(path);
bdec069d2239 fixed pathcheck behavior
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 72
diff changeset
182
165
6942a8c3e737 refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 105
diff changeset
183 uint32_t access_mask = ctx->aclreqaccess | ACL_LIST;
54
3a1d5a52adfc new vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
184
165
6942a8c3e737 refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 105
diff changeset
185 // ctx->aclreqaccess should be the complete access mask
6942a8c3e737 refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 105
diff changeset
186 uint32_t m = ctx->aclreqaccess; // save original access mask
6942a8c3e737 refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 105
diff changeset
187 ctx->aclreqaccess = access_mask; // set mask for vfs->open call
6942a8c3e737 refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 105
diff changeset
188 if((ctx->vfs->flags & VFS_CHECKS_ACL) != VFS_CHECKS_ACL) {
6942a8c3e737 refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 105
diff changeset
189 // 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
190 SysACL sysacl;
6942a8c3e737 refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 105
diff changeset
191 if(sys_acl_check(ctx, access_mask, &sysacl)) {
6942a8c3e737 refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 105
diff changeset
192 return NULL;
54
3a1d5a52adfc new vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
193 }
165
6942a8c3e737 refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 105
diff changeset
194 }
6942a8c3e737 refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 105
diff changeset
195 VFS_DIR dir = ctx->vfs->opendir(ctx, path);
6942a8c3e737 refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 105
diff changeset
196 ctx->aclreqaccess = m; // restore original access mask
6942a8c3e737 refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 105
diff changeset
197 return dir;
6942a8c3e737 refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 105
diff changeset
198 }
6942a8c3e737 refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 105
diff changeset
199
6942a8c3e737 refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 105
diff changeset
200 int vfs_readdir(VFS_DIR dir, VFS_ENTRY *entry) {
6942a8c3e737 refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 105
diff changeset
201 WS_ASSERT(dir);
6942a8c3e737 refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 105
diff changeset
202 WS_ASSERT(entry);
6942a8c3e737 refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 105
diff changeset
203
6942a8c3e737 refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 105
diff changeset
204 return dir->io->readdir(dir, entry, 0);
6942a8c3e737 refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 105
diff changeset
205 }
6942a8c3e737 refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 105
diff changeset
206
6942a8c3e737 refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 105
diff changeset
207 int vfs_readdir_stat(VFS_DIR dir, VFS_ENTRY *entry) {
6942a8c3e737 refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 105
diff changeset
208 WS_ASSERT(dir);
6942a8c3e737 refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 105
diff changeset
209 WS_ASSERT(entry);
6942a8c3e737 refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 105
diff changeset
210
6942a8c3e737 refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 105
diff changeset
211 return dir->io->readdir(dir, entry, 1);
6942a8c3e737 refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 105
diff changeset
212 }
6942a8c3e737 refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 105
diff changeset
213
6942a8c3e737 refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 105
diff changeset
214 void vfs_closedir(VFS_DIR dir) {
6942a8c3e737 refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 105
diff changeset
215 WS_ASSERT(dir);
6942a8c3e737 refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 105
diff changeset
216
6942a8c3e737 refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 105
diff changeset
217 dir->io->close(dir);
6942a8c3e737 refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 105
diff changeset
218 if(dir->ctx) {
6942a8c3e737 refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 105
diff changeset
219 VFS_FREE(dir->ctx->pool, dir);
6942a8c3e737 refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 105
diff changeset
220 } else {
6942a8c3e737 refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 105
diff changeset
221 free(dir);
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 }
6942a8c3e737 refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 105
diff changeset
224
6942a8c3e737 refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 105
diff changeset
225 int vfs_mkdir(VFSContext *ctx, char *path) {
6942a8c3e737 refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 105
diff changeset
226 WS_ASSERT(ctx);
6942a8c3e737 refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 105
diff changeset
227 WS_ASSERT(path);
6942a8c3e737 refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 105
diff changeset
228
6942a8c3e737 refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 105
diff changeset
229 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
230 }
6942a8c3e737 refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 105
diff changeset
231
6942a8c3e737 refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 105
diff changeset
232 int vfs_unlink(VFSContext *ctx, char *path) {
6942a8c3e737 refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 105
diff changeset
233 WS_ASSERT(ctx);
6942a8c3e737 refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 105
diff changeset
234 WS_ASSERT(path);
6942a8c3e737 refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 105
diff changeset
235
6942a8c3e737 refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 105
diff changeset
236 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
237 }
6942a8c3e737 refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 105
diff changeset
238
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 // private
6942a8c3e737 refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 105
diff changeset
241 int vfs_path_op(VFSContext *ctx, char *path, vfs_op_f op, uint32_t access) {
6942a8c3e737 refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 105
diff changeset
242 uint32_t access_mask = ctx->aclreqaccess;
6942a8c3e737 refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 105
diff changeset
243 access_mask |= access;
6942a8c3e737 refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 105
diff changeset
244
6942a8c3e737 refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 105
diff changeset
245 // ctx->aclreqaccess should be the complete access mask
6942a8c3e737 refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 105
diff changeset
246 uint32_t m = ctx->aclreqaccess; // save original access mask
6942a8c3e737 refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 105
diff changeset
247 ctx->aclreqaccess = access_mask; // set mask for vfs function call
6942a8c3e737 refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 105
diff changeset
248 if((ctx->vfs->flags & VFS_CHECKS_ACL) != VFS_CHECKS_ACL) {
6942a8c3e737 refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 105
diff changeset
249 // 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
250 SysACL sysacl;
6942a8c3e737 refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 105
diff changeset
251 if(sys_acl_check(ctx, access_mask, &sysacl)) {
6942a8c3e737 refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 105
diff changeset
252 return -1;
54
3a1d5a52adfc new vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
253 }
3a1d5a52adfc new vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
254 }
165
6942a8c3e737 refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 105
diff changeset
255 int ret = op(ctx, path);
6942a8c3e737 refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 105
diff changeset
256 ctx->aclreqaccess = m; // restore original access mask
6942a8c3e737 refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 105
diff changeset
257 return ret;
6942a8c3e737 refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 105
diff changeset
258 }
6942a8c3e737 refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 105
diff changeset
259
6942a8c3e737 refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 105
diff changeset
260 /* system vfs implementation */
6942a8c3e737 refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 105
diff changeset
261
6942a8c3e737 refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 105
diff changeset
262 SYS_FILE sys_vfs_open(VFSContext *ctx, char *path, int oflags) {
6942a8c3e737 refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 105
diff changeset
263 uint32_t access_mask = ctx->aclreqaccess;
6942a8c3e737 refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 105
diff changeset
264 pool_handle_t *pool = ctx->pool;
54
3a1d5a52adfc new vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
265
3a1d5a52adfc new vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
266 // check ACLs
63
66442f81f823 supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 59
diff changeset
267 SysACL sysacl;
66442f81f823 supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 59
diff changeset
268 if(sys_acl_check(ctx, access_mask, &sysacl)) {
54
3a1d5a52adfc new vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
269 return NULL;
3a1d5a52adfc new vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
270 }
3a1d5a52adfc new vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
271
63
66442f81f823 supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 59
diff changeset
272 if(sysacl.acl) {
66442f81f823 supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 59
diff changeset
273 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
274 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
275 return NULL;
66442f81f823 supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 59
diff changeset
276 }
66442f81f823 supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 59
diff changeset
277 }
66442f81f823 supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 59
diff changeset
278
54
3a1d5a52adfc new vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
279 // open file
58
66c22e54aa90 webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 57
diff changeset
280 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
281 int fd = open(path, oflags, mode);
54
3a1d5a52adfc new vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
282 if(fd == -1) {
3a1d5a52adfc new vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
283 if(ctx) {
3a1d5a52adfc new vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
284 ctx->vfs_errno = errno;
3a1d5a52adfc new vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
285 sys_set_error_status(ctx);
3a1d5a52adfc new vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
286 }
3a1d5a52adfc new vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
287 return NULL;
3a1d5a52adfc new vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
288 }
3a1d5a52adfc new vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
289
63
66442f81f823 supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 59
diff changeset
290 // 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
291 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
292 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
293 perror("vfs_open: fchown");
66442f81f823 supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 59
diff changeset
294 close(fd);
66442f81f823 supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 59
diff changeset
295 return NULL;
66442f81f823 supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 59
diff changeset
296 }
66442f81f823 supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 59
diff changeset
297 }
66442f81f823 supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 59
diff changeset
298
165
6942a8c3e737 refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 105
diff changeset
299 VFSFile *file = VFS_MALLOC(pool, sizeof(VFSFile));
54
3a1d5a52adfc new vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
300 if(!file) {
55
b7908bf38f9f vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
301 close(fd);
54
3a1d5a52adfc new vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
302 return NULL;
3a1d5a52adfc new vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
303 }
3a1d5a52adfc new vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
304 file->ctx = ctx;
3a1d5a52adfc new vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
305 file->data = NULL;
3a1d5a52adfc new vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
306 file->fd = fd;
3a1d5a52adfc new vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
307 file->io = &sys_file_io;
3a1d5a52adfc new vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
308 return file;
3a1d5a52adfc new vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
309 }
3a1d5a52adfc new vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
310
165
6942a8c3e737 refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 105
diff changeset
311 int sys_vfs_stat(VFSContext *ctx, char *path, struct stat *buf) {
6942a8c3e737 refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 105
diff changeset
312 uint32_t access_mask = ctx->aclreqaccess;
54
3a1d5a52adfc new vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
313
3a1d5a52adfc new vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
314 // check ACLs
63
66442f81f823 supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 59
diff changeset
315 SysACL sysacl;
66442f81f823 supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 59
diff changeset
316 if(sys_acl_check(ctx, access_mask, &sysacl)) {
57
b3a89736b23e some fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 56
diff changeset
317 return -1;
54
3a1d5a52adfc new vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
318 }
3a1d5a52adfc new vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
319
63
66442f81f823 supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 59
diff changeset
320 if(sysacl.acl) {
66442f81f823 supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 59
diff changeset
321 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
322 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
323 return -1;
66442f81f823 supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 59
diff changeset
324 }
66442f81f823 supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 59
diff changeset
325 }
66442f81f823 supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 59
diff changeset
326
54
3a1d5a52adfc new vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
327 // stat
3a1d5a52adfc new vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
328 if(stat(path, buf)) {
3a1d5a52adfc new vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
329 if(ctx) {
3a1d5a52adfc new vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
330 ctx->vfs_errno = errno;
3a1d5a52adfc new vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
331 sys_set_error_status(ctx);
3a1d5a52adfc new vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
332 }
3a1d5a52adfc new vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
333 return -1;
3a1d5a52adfc new vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
334 }
3a1d5a52adfc new vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
335
3a1d5a52adfc new vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
336 return 0;
3a1d5a52adfc new vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
337 }
3a1d5a52adfc new vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
338
165
6942a8c3e737 refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 105
diff changeset
339 int sys_vfs_fstat(VFSContext *ctx, SYS_FILE fd, struct stat *buf) {
54
3a1d5a52adfc new vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
340 // stat
3a1d5a52adfc new vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
341 if(fstat(fd->fd, buf)) {
3a1d5a52adfc new vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
342 if(ctx) {
3a1d5a52adfc new vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
343 ctx->vfs_errno = errno;
3a1d5a52adfc new vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
344 }
3a1d5a52adfc new vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
345 return -1;
3a1d5a52adfc new vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
346 }
3a1d5a52adfc new vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
347
3a1d5a52adfc new vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
348 return 0;
3a1d5a52adfc new vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
349 }
3a1d5a52adfc new vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
350
165
6942a8c3e737 refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 105
diff changeset
351 VFS_DIR sys_vfs_opendir(VFSContext *ctx, char *path) {
6942a8c3e737 refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 105
diff changeset
352 uint32_t access_mask = ctx->aclreqaccess;
6942a8c3e737 refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 105
diff changeset
353 pool_handle_t *pool = ctx->pool;
55
b7908bf38f9f vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
354
b7908bf38f9f vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
355 // check ACLs
63
66442f81f823 supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 59
diff changeset
356 SysACL sysacl;
66442f81f823 supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 59
diff changeset
357 if(sys_acl_check(ctx, access_mask, &sysacl)) {
55
b7908bf38f9f vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
358 return NULL;
b7908bf38f9f vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
359 }
b7908bf38f9f vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
360
63
66442f81f823 supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 59
diff changeset
361 if(sysacl.acl) {
66442f81f823 supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 59
diff changeset
362 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
363 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
364 return NULL;
66442f81f823 supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 59
diff changeset
365 }
66442f81f823 supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 59
diff changeset
366 }
66442f81f823 supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 59
diff changeset
367
72
9b888965f3ee some fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 70
diff changeset
368 // open directory
9b888965f3ee some fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 70
diff changeset
369 #ifdef BSD
69
4a10bc0ee80d compiles on os x
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 67
diff changeset
370 DIR *sys_dir = opendir(path);
97
09fbefc0e6a9 added ldap group support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 92
diff changeset
371 int dir_fd = sys_dir ? dirfd(sys_dir) : 0;
72
9b888965f3ee some fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 70
diff changeset
372 #else
9b888965f3ee some fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 70
diff changeset
373 int dir_fd = open(path, O_RDONLY);
9b888965f3ee some fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 70
diff changeset
374 if(dir_fd == -1) {
9b888965f3ee some fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 70
diff changeset
375 if(ctx) {
9b888965f3ee some fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 70
diff changeset
376 ctx->vfs_errno = errno;
9b888965f3ee some fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 70
diff changeset
377 sys_set_error_status(ctx);
9b888965f3ee some fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 70
diff changeset
378 }
9b888965f3ee some fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 70
diff changeset
379 return NULL;
9b888965f3ee some fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 70
diff changeset
380 }
9b888965f3ee some fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 70
diff changeset
381 DIR *sys_dir = fdopendir(dir_fd);
9b888965f3ee some fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 70
diff changeset
382 #endif
55
b7908bf38f9f vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
383 if(!sys_dir) {
b7908bf38f9f vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
384 if(ctx) {
b7908bf38f9f vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
385 ctx->vfs_errno = errno;
b7908bf38f9f vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
386 sys_set_error_status(ctx);
b7908bf38f9f vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
387 }
b7908bf38f9f vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
388 return NULL;
b7908bf38f9f vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
389 }
b7908bf38f9f vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
390
165
6942a8c3e737 refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 105
diff changeset
391 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
392 if(!dir_data) {
63d9051fe35c using readdir_r instead of readdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 97
diff changeset
393 closedir(sys_dir);
63d9051fe35c using readdir_r instead of readdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 97
diff changeset
394 return NULL;
63d9051fe35c using readdir_r instead of readdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 97
diff changeset
395 }
63d9051fe35c using readdir_r instead of readdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 97
diff changeset
396 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
397 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
398 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
399 if(!dir_data->cur) {
63d9051fe35c using readdir_r instead of readdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 97
diff changeset
400 closedir(sys_dir);
165
6942a8c3e737 refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 105
diff changeset
401 VFS_FREE(pool, dir_data);
105
63d9051fe35c using readdir_r instead of readdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 97
diff changeset
402 return NULL;
63d9051fe35c using readdir_r instead of readdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 97
diff changeset
403 }
63d9051fe35c using readdir_r instead of readdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 97
diff changeset
404 dir_data->dir = sys_dir;
63d9051fe35c using readdir_r instead of readdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 97
diff changeset
405
165
6942a8c3e737 refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 105
diff changeset
406 VFSDir *dir = VFS_MALLOC(pool, sizeof(VFSDir));
55
b7908bf38f9f vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
407 if(!dir) {
b7908bf38f9f vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
408 closedir(sys_dir);
165
6942a8c3e737 refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 105
diff changeset
409 VFS_FREE(pool, dir_data->cur);
6942a8c3e737 refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 105
diff changeset
410 VFS_FREE(pool, dir_data);
55
b7908bf38f9f vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
411 return NULL;
b7908bf38f9f vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
412 }
b7908bf38f9f vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
413 dir->ctx = ctx;
105
63d9051fe35c using readdir_r instead of readdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 97
diff changeset
414 dir->data = dir_data;
72
9b888965f3ee some fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 70
diff changeset
415 dir->fd = dir_fd;
55
b7908bf38f9f vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
416 dir->io = &sys_dir_io;
b7908bf38f9f vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
417 return dir;
b7908bf38f9f vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
418 }
b7908bf38f9f vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
419
165
6942a8c3e737 refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 105
diff changeset
420 int sys_vfs_mkdir(VFSContext *ctx, char *path) {
6942a8c3e737 refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 105
diff changeset
421 return sys_path_op(ctx, path, sys_mkdir);
55
b7908bf38f9f vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
422 }
b7908bf38f9f vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
423
165
6942a8c3e737 refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 105
diff changeset
424 int sys_vfs_unlink(VFSContext *ctx, char *path) {
6942a8c3e737 refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 105
diff changeset
425 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
426 }
c6cf20b09043 added vfs_mkdir and vfs_unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
427
54
3a1d5a52adfc new vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
428
165
6942a8c3e737 refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 105
diff changeset
429 int sys_path_op(VFSContext *ctx, char *path, sys_op_f op) {
63
66442f81f823 supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 59
diff changeset
430 uint32_t access_mask = ctx->aclreqaccess;
56
c6cf20b09043 added vfs_mkdir and vfs_unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
431
c6cf20b09043 added vfs_mkdir and vfs_unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
432 // check ACLs
63
66442f81f823 supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 59
diff changeset
433 SysACL sysacl;
165
6942a8c3e737 refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 105
diff changeset
434 if(sys_acl_check(ctx, access_mask, &sysacl)) {
57
b3a89736b23e some fixes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 56
diff changeset
435 return -1;
56
c6cf20b09043 added vfs_mkdir and vfs_unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
436 }
c6cf20b09043 added vfs_mkdir and vfs_unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
437
63
66442f81f823 supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 59
diff changeset
438 if(sysacl.acl) {
165
6942a8c3e737 refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 105
diff changeset
439 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
440 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
441 return -1;
66442f81f823 supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 59
diff changeset
442 }
66442f81f823 supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 59
diff changeset
443 }
66442f81f823 supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 59
diff changeset
444
56
c6cf20b09043 added vfs_mkdir and vfs_unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
445 // do path operation
63
66442f81f823 supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 59
diff changeset
446 if(op(ctx, path, &sysacl)) {
56
c6cf20b09043 added vfs_mkdir and vfs_unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
447 // error
165
6942a8c3e737 refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 105
diff changeset
448 ctx->vfs_errno = errno;
6942a8c3e737 refactors vfs code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 105
diff changeset
449 sys_set_error_status(ctx);
56
c6cf20b09043 added vfs_mkdir and vfs_unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
450 return -1;
c6cf20b09043 added vfs_mkdir and vfs_unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
451 }
c6cf20b09043 added vfs_mkdir and vfs_unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
452
c6cf20b09043 added vfs_mkdir and vfs_unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
453 return 0;
c6cf20b09043 added vfs_mkdir and vfs_unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
454 }
54
3a1d5a52adfc new vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
455
63
66442f81f823 supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 59
diff changeset
456 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
457 if(sysacl) {
50505dc3f8a6 dynamic thread pool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 66
diff changeset
458 sysacl->acl = NULL;
50505dc3f8a6 dynamic thread pool
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 66
diff changeset
459 }
54
3a1d5a52adfc new vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
460 if(!ctx) {
3a1d5a52adfc new vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
461 return 0;
3a1d5a52adfc new vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
462 }
3a1d5a52adfc new vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
463
3a1d5a52adfc new vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
464 ACLListHandle *acllist = ctx->acllist;
3a1d5a52adfc new vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
465 if(acllist) {
63
66442f81f823 supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 59
diff changeset
466 ACLList *acl = acl_evallist(
66442f81f823 supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 59
diff changeset
467 acllist,
66442f81f823 supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 59
diff changeset
468 ctx->user,
66442f81f823 supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 59
diff changeset
469 access_mask,
66442f81f823 supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 59
diff changeset
470 &sysacl->acl);
66442f81f823 supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 59
diff changeset
471
66442f81f823 supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 59
diff changeset
472 if(acl) {
66442f81f823 supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 59
diff changeset
473 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
474 return 1;
54
3a1d5a52adfc new vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
475 }
3a1d5a52adfc new vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
476 }
3a1d5a52adfc new vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
477
3a1d5a52adfc new vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
478 return 0;
3a1d5a52adfc new vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
479 }
3a1d5a52adfc new vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
480
3a1d5a52adfc new vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
481 void sys_set_error_status(VFSContext *ctx) {
3a1d5a52adfc new vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
482 if(ctx->sn && ctx->rq) {
56
c6cf20b09043 added vfs_mkdir and vfs_unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
483 int status = util_errno2status(ctx->vfs_errno);
54
3a1d5a52adfc new vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
484 protocol_status(ctx->sn, ctx->rq, status, NULL);
3a1d5a52adfc new vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
485 }
3a1d5a52adfc new vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
486 }
3a1d5a52adfc new vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
487
3a1d5a52adfc new vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
488 ssize_t sys_file_read(SYS_FILE fd, void *buf, size_t nbyte) {
3a1d5a52adfc new vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
489 return read(fd->fd, buf, nbyte);
3a1d5a52adfc new vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
490 }
3a1d5a52adfc new vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
491
3a1d5a52adfc new vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
492 ssize_t sys_file_write(SYS_FILE fd, const void *buf, size_t nbyte) {
3a1d5a52adfc new vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
493 return write(fd->fd, buf, nbyte);
3a1d5a52adfc new vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
494 }
3a1d5a52adfc new vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
495
66
74babc0082b7 added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 63
diff changeset
496 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
497 return lseek(fd->fd, offset, whence);
74babc0082b7 added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 63
diff changeset
498 }
74babc0082b7 added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 63
diff changeset
499
54
3a1d5a52adfc new vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
500 void sys_file_close(SYS_FILE fd) {
3a1d5a52adfc new vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
501 close(fd->fd);
3a1d5a52adfc new vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
502 }
55
b7908bf38f9f vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
503
172
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 165
diff changeset
504 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
505 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
506 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
507 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
508 }
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 165
diff changeset
509
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 165
diff changeset
510 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
511 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
512 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
513 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
514 }
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 165
diff changeset
515
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 165
diff changeset
516
55
b7908bf38f9f vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
517 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
518 SysVFSDir *dirdata = dir->data;
63d9051fe35c using readdir_r instead of readdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 97
diff changeset
519 struct dirent *result = NULL;
63d9051fe35c using readdir_r instead of readdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 97
diff changeset
520 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
521 if(!s && result) {
63d9051fe35c using readdir_r instead of readdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 97
diff changeset
522 char *name = result->d_name;
58
66c22e54aa90 webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 57
diff changeset
523 if(!strcmp(name, ".") || !strcmp(name, "..")) {
66c22e54aa90 webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 57
diff changeset
524 return sys_dir_read(dir, entry, getstat);
66c22e54aa90 webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 57
diff changeset
525 } else {
66c22e54aa90 webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 57
diff changeset
526 entry->name = name;
66c22e54aa90 webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 57
diff changeset
527 if(getstat) {
66c22e54aa90 webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 57
diff changeset
528 // TODO: check ACLs again for new path
105
63d9051fe35c using readdir_r instead of readdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 97
diff changeset
529 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
530 entry->stat_errno = errno;
66c22e54aa90 webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 57
diff changeset
531 }
66c22e54aa90 webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 57
diff changeset
532 entry->stat_extra = NULL;
185
b4d7ccf4e06d implements new event handler and aio on linux
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 172
diff changeset
533 }
58
66c22e54aa90 webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 57
diff changeset
534 return 1;
55
b7908bf38f9f vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
535 }
b7908bf38f9f vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
536 } else {
b7908bf38f9f vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
537 return 0;
b7908bf38f9f vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
538 }
b7908bf38f9f vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
539 }
b7908bf38f9f vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
540
b7908bf38f9f vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
541 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
542 SysVFSDir *dirdata = dir->data;
63d9051fe35c using readdir_r instead of readdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 97
diff changeset
543 closedir(dirdata->dir);
63d9051fe35c using readdir_r instead of readdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 97
diff changeset
544
63d9051fe35c using readdir_r instead of readdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 97
diff changeset
545 pool_handle_t *pool = dir->ctx->pool;
63d9051fe35c using readdir_r instead of readdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 97
diff changeset
546 if(pool) {
63d9051fe35c using readdir_r instead of readdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 97
diff changeset
547 pool_free(pool, dirdata->cur);
63d9051fe35c using readdir_r instead of readdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 97
diff changeset
548 pool_free(pool, dirdata);
63d9051fe35c using readdir_r instead of readdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 97
diff changeset
549 pool_free(pool, dir);
63d9051fe35c using readdir_r instead of readdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 97
diff changeset
550 } else {
63d9051fe35c using readdir_r instead of readdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 97
diff changeset
551 free(dirdata->cur);
63d9051fe35c using readdir_r instead of readdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 97
diff changeset
552 free(dirdata);
63d9051fe35c using readdir_r instead of readdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 97
diff changeset
553 free(dir);
63d9051fe35c using readdir_r instead of readdir
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 97
diff changeset
554 }
55
b7908bf38f9f vfs can read directories
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 54
diff changeset
555 }
56
c6cf20b09043 added vfs_mkdir and vfs_unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
556
63
66442f81f823 supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 59
diff changeset
557 int sys_mkdir(VFSContext *ctx, char *path, SysACL *sysacl) {
56
c6cf20b09043 added vfs_mkdir and vfs_unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
558 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
559 int ret = mkdir(path, mode);
66442f81f823 supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 59
diff changeset
560 if(ret == 0) {
66442f81f823 supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 59
diff changeset
561 if(sysacl->user_uid != -1) {
66442f81f823 supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 59
diff changeset
562 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
563 // TODO: error
66442f81f823 supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 59
diff changeset
564 }
66442f81f823 supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 59
diff changeset
565 }
66442f81f823 supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 59
diff changeset
566 }
66442f81f823 supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 59
diff changeset
567 return ret;
56
c6cf20b09043 added vfs_mkdir and vfs_unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
568 }
c6cf20b09043 added vfs_mkdir and vfs_unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
569
63
66442f81f823 supports file system ACLs on Solaris
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 59
diff changeset
570 int sys_unlink(VFSContext *ctx, char *path, SysACL *sysacl) {
56
c6cf20b09043 added vfs_mkdir and vfs_unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
571 return unlink(path);
c6cf20b09043 added vfs_mkdir and vfs_unlink
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 55
diff changeset
572 }
58
66c22e54aa90 webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 57
diff changeset
573
66c22e54aa90 webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 57
diff changeset
574 /* public file api */
66c22e54aa90 webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 57
diff changeset
575
66c22e54aa90 webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 57
diff changeset
576 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
577 return fd->io->read(fd, buf, nbyte);
66c22e54aa90 webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 57
diff changeset
578 }
66c22e54aa90 webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 57
diff changeset
579
66c22e54aa90 webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 57
diff changeset
580 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
581 return fd->io->write(fd, buf, nbyte);
66c22e54aa90 webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 57
diff changeset
582 }
66c22e54aa90 webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 57
diff changeset
583
66
74babc0082b7 added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 63
diff changeset
584 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
585 return fd->io->seek(fd, offset, whence);
74babc0082b7 added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 63
diff changeset
586 }
74babc0082b7 added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 63
diff changeset
587
58
66c22e54aa90 webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 57
diff changeset
588 NSAPI_PUBLIC int system_fclose(SYS_FILE fd) {
66c22e54aa90 webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 57
diff changeset
589 vfs_close(fd);
66c22e54aa90 webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 57
diff changeset
590 return 0;
66c22e54aa90 webdav uses the vfs api
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 57
diff changeset
591 }
172
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 165
diff changeset
592
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 165
diff changeset
593 // AIO API
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 165
diff changeset
594
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 165
diff changeset
595 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
596 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
597 return -1;
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 165
diff changeset
598 }
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 165
diff changeset
599
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 165
diff changeset
600 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
601 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
602 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
603 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
604 } else {
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 165
diff changeset
605 // TODO: implement
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 165
diff changeset
606 return -1;
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 165
diff changeset
607 }
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 165
diff changeset
608 }
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 165
diff changeset
609
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 165
diff changeset
610 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
611 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
612 return -1;
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 165
diff changeset
613 }
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 165
diff changeset
614
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 165
diff changeset
615 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
616 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
617 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
618 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
619 } else {
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 165
diff changeset
620 // TODO: implement
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 165
diff changeset
621 return -1;
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 165
diff changeset
622 }
5580517faafc adds public aio and poll api and asynchronous send_range function
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 165
diff changeset
623 }

mercurial