src/server/public/vfs.h

changeset 385
a1f4cb076d2f
parent 366
47bc686fafe4
equal deleted inserted replaced
210:21274e5950af 385:a1f4cb076d2f
1 /* 1 /*
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3 * 3 *
4 * Copyright 2013 Olaf Wintermann. All rights reserved. 4 * Copyright 2018 Olaf Wintermann. All rights reserved.
5 * 5 *
6 * Redistribution and use in source and binary forms, with or without 6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are met: 7 * modification, are permitted provided that the following conditions are met:
8 * 8 *
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
46 46
47 #define VFS_DIR VFSDir* 47 #define VFS_DIR VFSDir*
48 #define VFS_ENTRY VFSEntry 48 #define VFS_ENTRY VFSEntry
49 49
50 struct VFS { 50 struct VFS {
51 SYS_FILE (*open)(VFSContext *ctx, char *path, int oflags); 51 SYS_FILE (*open)(VFSContext *ctx, const char *path, int oflags);
52 int (*stat)(VFSContext *ctx, char *path, struct stat *buf); 52 int (*stat)(VFSContext *ctx, const char *path, struct stat *buf);
53 int (*fstat)(VFSContext *ctx, SYS_FILE fd, struct stat *buf); 53 int (*fstat)(VFSContext *ctx, SYS_FILE fd, struct stat *buf);
54 VFS_DIR (*opendir)(VFSContext *ctx, char *path); 54 VFS_DIR (*opendir)(VFSContext *ctx, const char *path);
55 int (*mkdir)(VFSContext *ctx, char *path); 55 VFS_DIR (*fdopendir)(VFSContext *ctx, SYS_FILE fd);
56 int (*unlink)(VFSContext *ctx, char *path); 56 int (*mkdir)(VFSContext *ctx, const char *path);
57 int (*unlink)(VFSContext *ctx, const char *path);
58 int (*rmdir)(VFSContext *Ctx, const char *path);
57 uint32_t flags; 59 uint32_t flags;
60 void *instance;
58 }; 61 };
59 62
60 struct VFSContext { 63 struct VFSContext {
61 pool_handle_t *pool; 64 pool_handle_t *pool;
62 Session *sn; 65 Session *sn;
64 VFS *vfs; 67 VFS *vfs;
65 User *user; 68 User *user;
66 ACLListHandle *acllist; 69 ACLListHandle *acllist;
67 uint32_t aclreqaccess; 70 uint32_t aclreqaccess;
68 int vfs_errno; 71 int vfs_errno;
72 WSBool error_response_set;
69 }; 73 };
70 74
71 struct VFSFile { 75 struct VFSFile {
72 VFSContext *ctx; 76 VFSContext *ctx;
73 VFS_IO *io; // IO functions 77 VFS_IO *io; /* IO functions */
74 void *data; // private data used by the VFSFile implementation 78 void *data; /* private data used by the VFSFile implementation */
75 int fd; // native file descriptor if available, or -1 79 int fd; /* native file descriptor if available, or -1 */
76 }; 80 };
77 81
78 struct VFSDir { 82 struct VFSDir {
79 VFSContext *ctx; 83 VFSContext *ctx;
80 VFS_DIRIO *io; 84 VFS_DIRIO *io;
81 void *data; // private data used by the VFSDir implementation 85 void *data; /* private data used by the VFSDir implementation */
82 int fd; // native file descriptor if available, or -1 86 int fd; /* native file descriptor if available, or -1 */
83 }; 87 };
84 88
85 struct VFSEntry { 89 struct VFSEntry {
86 char *name; 90 char *name;
87 struct stat stat; 91 struct stat stat;
96 ssize_t (*pwrite)(SYS_FILE fd, const void *buf, size_t nbyte, off_t offset); 100 ssize_t (*pwrite)(SYS_FILE fd, const void *buf, size_t nbyte, off_t offset);
97 off_t (*seek)(SYS_FILE fd, off_t offset, int whence); 101 off_t (*seek)(SYS_FILE fd, off_t offset, int whence);
98 void (*close)(SYS_FILE fd); 102 void (*close)(SYS_FILE fd);
99 int (*opt_aioread)(aiocb_s *aiocb); 103 int (*opt_aioread)(aiocb_s *aiocb);
100 int (*opt_aiowrite)(aiocb_s *aiocb); 104 int (*opt_aiowrite)(aiocb_s *aiocb);
105 const char* (*opt_getetag)(SYS_FILE fd);
101 }; 106 };
102 107
103 struct VFS_DIRIO { 108 struct VFS_DIRIO {
104 int (*readdir)(VFS_DIR dir, VFS_ENTRY *entry, int getstat); 109 int (*readdir)(VFS_DIR dir, VFS_ENTRY *entry, int getstat);
105 void (*close)(VFS_DIR dir); 110 void (*close)(VFS_DIR dir);
106 }; 111 };
107 112
113 typedef void*(*vfs_init_func)(ServerConfiguration *cfg, pool_handle_t *pool, WSConfigNode *config);
114 typedef VFS*(*vfs_create_func)(Session *sn, Request *rq, pblock *pb, void *initData);
115
108 /* 116 /*
109 * registers a new VFS 117 * registers a new VFS
110 */ 118 */
111 void vfs_add(char *name, VFS *vfs); 119 int vfs_register_type(const char *name, vfs_init_func vfsInit, vfs_create_func vfsCreate);
120
121 /*
122 * Create a new VFS instance
123 */
124 VFS* vfs_create(Session *sn, Request *rq, const char *vfs_class, pblock *pb, void *initData);
112 125
113 /* 126 /*
114 * creates a VFSContext for a Request 127 * creates a VFSContext for a Request
115 * vfs calls will do ACL checks 128 * vfs calls will do ACL checks
116 */ 129 */
117 VFSContext* vfs_request_context(Session *sn, Request *rq); 130 VFSContext* vfs_request_context(Session *sn, Request *rq);
118 131
119 SYS_FILE vfs_open(VFSContext *ctx, char *path, int oflags); 132 SYS_FILE vfs_open(VFSContext *ctx, const char *path, int oflags);
120 SYS_FILE vfs_openRO(VFSContext *ctx, char *path); 133 SYS_FILE vfs_openRO(VFSContext *ctx, const char *path);
121 SYS_FILE vfs_openWO(VFSContext *ctx, char *path); 134 SYS_FILE vfs_openWO(VFSContext *ctx, const char *path);
122 SYS_FILE vfs_openRW(VFSContext *ctx, char *path); 135 SYS_FILE vfs_openRW(VFSContext *ctx, const char *path);
123 int vfs_stat(VFSContext *ctx, char *path, struct stat *buf); 136 int vfs_stat(VFSContext *ctx, const char *path, struct stat *buf);
124 int vfs_fstat(VFSContext *ctx, SYS_FILE fd, struct stat *buf); 137 int vfs_fstat(VFSContext *ctx, SYS_FILE fd, struct stat *buf);
138 const char * vfs_getetag(SYS_FILE fd);
125 void vfs_close(SYS_FILE fd); 139 void vfs_close(SYS_FILE fd);
126 VFS_DIR vfs_opendir(VFSContext *ctx, char *path); 140 VFS_DIR vfs_opendir(VFSContext *ctx, const char *path);
141 VFS_DIR vfs_fdopendir(VFSContext *ctx, SYS_FILE fd);
127 int vfs_readdir(VFS_DIR dir, VFS_ENTRY *entry); 142 int vfs_readdir(VFS_DIR dir, VFS_ENTRY *entry);
128 int vfs_readdir_stat(VFS_DIR dir, VFS_ENTRY *entry); 143 int vfs_readdir_stat(VFS_DIR dir, VFS_ENTRY *entry);
129 void vfs_closedir(VFS_DIR dir); 144 void vfs_closedir(VFS_DIR dir);
130 int vfs_mkdir(VFSContext *ctx, char *path); 145 int vfs_mkdir(VFSContext *ctx, const char *path);
131 int vfs_unlink(VFSContext *ctx, char *path); 146 int vfs_unlink(VFSContext *ctx, const char *path);
147 int vfs_rmdir(VFSContext *ctx, const char *path);
132 148
133 #ifdef __cplusplus 149 #ifdef __cplusplus
134 } 150 }
135 #endif 151 #endif
136 152

mercurial