src/server/plugins/postgresql/vfs.c

branch
webdav
changeset 276
0cb4eda146c4
parent 275
535004faa1a5
child 278
38bf7b42b58c
equal deleted inserted replaced
275:535004faa1a5 276:0cb4eda146c4
52 52
53 static VFS_DIRIO pg_vfs_dirio_class = { 53 static VFS_DIRIO pg_vfs_dirio_class = {
54 pg_vfs_dirio_readdir, 54 pg_vfs_dirio_readdir,
55 pg_vfs_dirio_close 55 pg_vfs_dirio_close
56 }; 56 };
57
58
59
60 VFS* pg_vfs_create(Session *sn, Request *rq, pblock *pb) {
61 // resourcepool is required
62 char *resource_pool = pblock_find("resourcepool", pb);
63 if(!resource_pool) {
64 log_ereport(LOG_MISCONFIG, "pg_vfs_create: missing resourcepool parameter");
65 return NULL;
66 }
67
68 // get the resource first (most likely to fail due to misconfig)
69 ResourceData *resdata = resourcepool_lookup(sn, rq, resource_pool, 0);
70 if(!resdata) {
71 log_ereport(LOG_MISCONFIG, "postgresql vfs: resource pool %s not found", resource_pool);
72 return NULL;
73 }
74 // resdata will be freed automatically when the request is finished
75
76 // Create a new VFS object and a separate instance object
77 // VFS contains fptrs that can be copied from pg_vfs_class
78 // instance contains request specific data (PGconn)
79 VFS *vfs = pool_malloc(sn->pool, sizeof(VFS));
80 if(!vfs) {
81 return NULL;
82 }
83
84 PgVFS *vfs_priv = pool_malloc(sn->pool, sizeof(PgVFS));
85 if(!vfs_priv) {
86 pool_free(sn->pool, vfs);
87 return NULL;
88 }
89
90 memcpy(vfs, &pg_vfs_class, sizeof(VFS));
91 vfs->flags = 0;
92 vfs->instance = vfs_priv;
93
94 return vfs;
95 }
96
57 97
58 /* -------------------------- VFS functions -------------------------- */ 98 /* -------------------------- VFS functions -------------------------- */
59 99
60 SYS_FILE pg_vfs_open(VFSContext *ctx, const char *path, int oflags) { 100 SYS_FILE pg_vfs_open(VFSContext *ctx, const char *path, int oflags) {
61 101

mercurial