annotate ezBAMQC/src/htslib/hfile_irods.c @ 20:9de3bbec2479 draft default tip

Uploaded
author youngkim
date Thu, 31 Mar 2016 10:10:37 -0400
parents dfa3745e5fd8
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
1 /* hfile_irods.c -- iRODS backend for low-level file streams.
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
2
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
3 Copyright (C) 2013, 2015 Genome Research Ltd.
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
4
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
5 Author: John Marshall <jm18@sanger.ac.uk>
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
6
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
7 Permission is hereby granted, free of charge, to any person obtaining a copy
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
8 of this software and associated documentation files (the "Software"), to deal
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
9 in the Software without restriction, including without limitation the rights
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
10 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
11 copies of the Software, and to permit persons to whom the Software is
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
12 furnished to do so, subject to the following conditions:
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
13
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
14 The above copyright notice and this permission notice shall be included in
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
15 all copies or substantial portions of the Software.
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
16
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
17 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
18 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
19 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
20 THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
21 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
22 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
23 DEALINGS IN THE SOFTWARE. */
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
24
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
25 #include <stdlib.h>
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
26 #include <string.h>
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
27 #include <errno.h>
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
28
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
29 #include "hfile_internal.h"
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
30
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
31 #include <rcConnect.h>
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
32 #include <dataObjOpen.h>
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
33 #include <dataObjRead.h>
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
34 #include <dataObjWrite.h>
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
35 #include <dataObjFsync.h>
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
36 #include <dataObjLseek.h>
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
37 #include <dataObjClose.h>
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
38
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
39 typedef struct {
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
40 hFILE base;
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
41 int descriptor;
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
42 } hFILE_irods;
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
43
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
44 static int status_errno(int status)
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
45 {
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
46 switch (status) {
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
47 case SYS_NO_API_PRIV: return EACCES;
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
48 case SYS_MALLOC_ERR: return ENOMEM;
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
49 case SYS_OUT_OF_FILE_DESC: return ENFILE;
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
50 case SYS_BAD_FILE_DESCRIPTOR: return EBADF;
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
51 case CAT_NO_ROWS_FOUND: return ENOENT;
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
52 case CATALOG_ALREADY_HAS_ITEM_BY_THAT_NAME: return EEXIST;
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
53 default: return EIO;
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
54 }
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
55 }
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
56
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
57 static void set_errno(int status)
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
58 {
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
59 int err = abs(status) % 1000;
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
60 errno = err? err : status_errno(status);
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
61 }
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
62
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
63 static struct {
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
64 rcComm_t *conn;
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
65 rodsEnv env;
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
66 } irods = { NULL };
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
67
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
68 static void irods_exit()
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
69 {
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
70 (void) rcDisconnect(irods.conn);
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
71 irods.conn = NULL;
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
72 }
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
73
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
74 static int irods_init()
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
75 {
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
76 rErrMsg_t err;
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
77 int ret;
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
78
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
79 ret = getRodsEnv(&irods.env);
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
80 if (ret < 0) goto error;
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
81
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
82 irods.conn = rcConnect(irods.env.rodsHost, irods.env.rodsPort,
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
83 irods.env.rodsUserName, irods.env.rodsZone,
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
84 NO_RECONN, &err);
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
85 if (irods.conn == NULL) { ret = err.status; goto error; }
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
86
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
87 if (strcmp(irods.env.rodsUserName, PUBLIC_USER_NAME) != 0) {
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
88 ret = clientLogin(irods.conn);
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
89 if (ret != 0) goto error;
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
90 }
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
91
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
92 // In the unlikely event atexit() fails, it's better to succeed here and
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
93 // carry on and do the I/O; then eventually when the program exits, we'll
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
94 // merely disconnect from the server uncleanly, as if we had aborted.
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
95 (void) atexit(irods_exit);
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
96
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
97 return 0;
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
98
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
99 error:
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
100 if (irods.conn) { (void) rcDisconnect(irods.conn); }
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
101 irods.conn = NULL;
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
102 set_errno(ret);
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
103 return -1;
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
104 }
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
105
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
106 static ssize_t irods_read(hFILE *fpv, void *buffer, size_t nbytes)
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
107 {
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
108 hFILE_irods *fp = (hFILE_irods *) fpv;
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
109 openedDataObjInp_t args;
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
110 bytesBuf_t buf;
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
111 int ret;
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
112
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
113 memset(&args, 0, sizeof args);
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
114 args.l1descInx = fp->descriptor;
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
115 args.len = nbytes;
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
116
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
117 buf.buf = buffer;
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
118 buf.len = nbytes;
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
119
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
120 ret = rcDataObjRead(irods.conn, &args, &buf);
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
121 if (ret < 0) set_errno(ret);
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
122 return ret;
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
123 }
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
124
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
125 static ssize_t irods_write(hFILE *fpv, const void *buffer, size_t nbytes)
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
126 {
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
127 hFILE_irods *fp = (hFILE_irods *) fpv;
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
128 openedDataObjInp_t args;
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
129 bytesBuf_t buf;
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
130 int ret;
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
131
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
132 memset(&args, 0, sizeof args);
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
133 args.l1descInx = fp->descriptor;
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
134 args.len = nbytes;
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
135
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
136 buf.buf = (void *) buffer; // ...the iRODS API is not const-correct here
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
137 buf.len = nbytes;
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
138
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
139 ret = rcDataObjWrite(irods.conn, &args, &buf);
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
140 if (ret < 0) set_errno(ret);
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
141 return ret;
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
142 }
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
143
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
144 static off_t irods_seek(hFILE *fpv, off_t offset, int whence)
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
145 {
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
146 hFILE_irods *fp = (hFILE_irods *) fpv;
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
147 openedDataObjInp_t args;
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
148 fileLseekOut_t *out = NULL;
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
149 int ret;
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
150
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
151 memset(&args, 0, sizeof args);
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
152 args.l1descInx = fp->descriptor;
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
153 args.offset = offset;
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
154 args.whence = whence;
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
155
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
156 ret = rcDataObjLseek(irods.conn, &args, &out);
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
157
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
158 if (out) { offset = out->offset; free(out); }
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
159 else offset = -1;
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
160 if (ret < 0) { set_errno(ret); return -1; }
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
161 return offset;
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
162 }
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
163
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
164 static int irods_flush(hFILE *fpv)
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
165 {
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
166 // FIXME rcDataObjFsync() doesn't seem to function as expected.
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
167 // For now, flush is a no-op: see https://github.com/samtools/htslib/issues/168
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
168 #if 0
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
169 hFILE_irods *fp = (hFILE_irods *) fpv;
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
170 openedDataObjInp_t args;
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
171 int ret;
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
172
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
173 memset(&args, 0, sizeof args);
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
174 args.l1descInx = fp->descriptor;
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
175
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
176 ret = rcDataObjFsync(irods.conn, &args);
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
177 if (ret < 0) set_errno(ret);
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
178 return ret;
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
179 #endif
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
180 return 0;
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
181 }
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
182
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
183 static int irods_close(hFILE *fpv)
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
184 {
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
185 hFILE_irods *fp = (hFILE_irods *) fpv;
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
186 openedDataObjInp_t args;
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
187 int ret;
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
188
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
189 memset(&args, 0, sizeof args);
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
190 args.l1descInx = fp->descriptor;
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
191
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
192 ret = rcDataObjClose(irods.conn, &args);
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
193 if (ret < 0) set_errno(ret);
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
194 return ret;
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
195 }
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
196
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
197 static const struct hFILE_backend irods_backend =
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
198 {
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
199 irods_read, irods_write, irods_seek, irods_flush, irods_close
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
200 };
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
201
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
202 hFILE *hopen_irods(const char *filename, const char *mode)
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
203 {
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
204 hFILE_irods *fp;
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
205 rodsPath_t path;
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
206 dataObjInp_t args;
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
207 int ret;
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
208
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
209 // Initialise the iRODS connection if this is the first use.
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
210 if (irods.conn == NULL) { if (irods_init() < 0) return NULL; }
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
211
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
212 if (strncmp(filename, "irods:", 6) == 0) filename += 6;
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
213 else { errno = EINVAL; return NULL; }
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
214
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
215 fp = (hFILE_irods *) hfile_init(sizeof (hFILE_irods), mode, 0);
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
216 if (fp == NULL) return NULL;
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
217
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
218 strncpy(path.inPath, filename, MAX_NAME_LEN-1);
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
219 path.inPath[MAX_NAME_LEN-1] = '\0';
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
220
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
221 ret = parseRodsPath(&path, &irods.env);
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
222 if (ret < 0) goto error;
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
223
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
224 memset(&args, 0, sizeof args);
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
225 strcpy(args.objPath, path.outPath);
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
226 args.openFlags = hfile_oflags(mode);
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
227 if (args.openFlags & O_CREAT) {
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
228 args.createMode = 0666;
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
229 addKeyVal(&args.condInput, DEST_RESC_NAME_KW,irods.env.rodsDefResource);
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
230 }
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
231
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
232 ret = rcDataObjOpen(irods.conn, &args);
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
233 if (ret < 0) goto error;
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
234 fp->descriptor = ret;
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
235
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
236 fp->base.backend = &irods_backend;
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
237 return &fp->base;
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
238
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
239 error:
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
240 hfile_destroy((hFILE *) fp);
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
241 set_errno(ret);
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
242 return NULL;
dfa3745e5fd8 Uploaded
youngkim
parents:
diff changeset
243 }