︙ | | |
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
|
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
|
-
+
-
+
+
+
+
-
-
-
-
-
-
+
+
+
+
+
+
+
-
+
-
-
+
+
+
+
+
+
-
-
-
-
-
-
+
+
+
+
+
+
+
|
pathLen = strlen(path);
<?= [dict get $hashTable body] ?>
return(XVFS_NAME_LOOKUP_ERROR);
}
static const char **xvfs_<?= $::xvfs::fsName ?>_getChildren(const char *path, Tcl_WideInt *count) {
static const char **xvfs_<?= $::xvfs::fsName ?>_getChildren(const char *path, long inode, Tcl_WideInt *count) {
const struct xvfs_file_data *fileInfo;
long inode;
/*
* Validate input parameters
*/
if (count == NULL) {
return(NULL);
}
/*
* Use user-supplied inode, or look up the path
*/
if (inode == XVFS_INODE_NULL) {
/*
* Get the inode from the lookup function
*/
inode = xvfs_<?= $::xvfs::fsName ?>_nameToIndex(path);
if (inode == XVFS_NAME_LOOKUP_ERROR) {
*count = XVFS_RV_ERR_ENOENT;
return(NULL);
* Get the inode from the lookup function
*/
inode = xvfs_<?= $::xvfs::fsName ?>_nameToIndex(path);
if (inode == XVFS_NAME_LOOKUP_ERROR) {
*count = XVFS_RV_ERR_ENOENT;
return(NULL);
}
}
fileInfo = &xvfs_<?= $::xvfs::fsName ?>_data[inode];
/*
* Ensure this is a directory
*/
if (fileInfo->type != XVFS_FILE_TYPE_DIR) {
*count = XVFS_RV_ERR_ENOTDIR;
return(NULL);
}
*count = fileInfo->size;
return(fileInfo->data.dirChildren);
}
static const unsigned char *xvfs_<?= $::xvfs::fsName ?>_getData(const char *path, Tcl_WideInt start, Tcl_WideInt *length) {
static const unsigned char *xvfs_<?= $::xvfs::fsName ?>_getData(const char *path, long inode, Tcl_WideInt start, Tcl_WideInt *length) {
const struct xvfs_file_data *fileInfo;
Tcl_WideInt resultLength;
long inode;
/*
* Validate input parameters
*/
if (length == NULL) {
return(NULL);
}
if (start < 0) {
*length = XVFS_RV_ERR_EINVAL;
return(NULL);
}
if (*length < 0) {
*length = XVFS_RV_ERR_EINVAL;
return(NULL);
}
/*
* Use user-supplied inode, or look up the path
*/
if (inode == XVFS_INODE_NULL) {
/*
* Get the inode from the lookup function
*/
inode = xvfs_<?= $::xvfs::fsName ?>_nameToIndex(path);
if (inode == XVFS_NAME_LOOKUP_ERROR) {
*length = XVFS_RV_ERR_ENOENT;
return(NULL);
* Get the inode from the lookup function
*/
inode = xvfs_<?= $::xvfs::fsName ?>_nameToIndex(path);
if (inode == XVFS_NAME_LOOKUP_ERROR) {
*length = XVFS_RV_ERR_ENOENT;
return(NULL);
}
}
fileInfo = &xvfs_<?= $::xvfs::fsName ?>_data[inode];
/*
* Ensure this is a file that can be read
*/
|
︙ | | |
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
|
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
|
-
+
-
+
+
+
+
-
-
-
-
-
+
+
+
+
+
+
|
/*
* Return the data
*/
return(fileInfo->data.fileContents + start);
}
static int xvfs_<?= $::xvfs::fsName ?>_getStat(const char *path, Tcl_StatBuf *statBuf) {
static int xvfs_<?= $::xvfs::fsName ?>_getStat(const char *path, long inode, Tcl_StatBuf *statBuf) {
const struct xvfs_file_data *fileInfo;
long inode;
/*
* Validate input parameters
*/
if (!statBuf) {
return(XVFS_RV_ERR_EINVAL);
}
/*
* Use user-supplied inode, or look up the path
*/
if (inode == XVFS_INODE_NULL) {
/*
* Get the inode from the lookup function
*/
inode = xvfs_<?= $::xvfs::fsName ?>_nameToIndex(path);
if (inode == XVFS_NAME_LOOKUP_ERROR) {
return(XVFS_RV_ERR_ENOENT);
* Get the inode from the lookup function
*/
inode = xvfs_<?= $::xvfs::fsName ?>_nameToIndex(path);
if (inode == XVFS_NAME_LOOKUP_ERROR) {
return(XVFS_RV_ERR_ENOENT);
}
}
fileInfo = &xvfs_<?= $::xvfs::fsName ?>_data[inode];
statBuf->st_dev = <?= [zlib adler32 $::xvfs::fsName 0] ?>;
statBuf->st_rdev = <?= [zlib adler32 $::xvfs::fsName 0] ?>;
statBuf->st_ino = inode;
|
︙ | | |
︙ | | |
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
|
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
|
-
+
|
/*
* Xvfs Memory Channel
*/
struct xvfs_tclfs_channel_id {
Tcl_Channel channel;
struct xvfs_tclfs_instance_info *fsInstanceInfo;
Tcl_Obj *path;
long inode;
Tcl_WideInt currentOffset;
Tcl_WideInt fileSize;
int eofMarked;
int queuedEvents;
int closed;
};
struct xvfs_tclfs_channel_event {
|
︙ | | |
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
|
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
|
-
+
|
Tcl_StatBuf fileInfo;
Tcl_Obj *channelName;
int statRet;
XVFS_DEBUG_ENTER;
XVFS_DEBUG_PRINTF("Opening file \"%s\" ...", Tcl_GetString(path));
statRet = instanceInfo->fsInfo->getStatProc(Tcl_GetString(path), &fileInfo);
statRet = instanceInfo->fsInfo->getStatProc(Tcl_GetString(path), XVFS_INODE_NULL, &fileInfo);
if (statRet < 0) {
XVFS_DEBUG_PRINTF("... failed: %s", xvfs_strerror(statRet));
xvfs_setresults_error(interp, XVFS_RV_ERR_ENOENT);
XVFS_DEBUG_LEAVE;
return(NULL);
|
︙ | | |
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
|
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
|
+
-
-
|
channelInstanceData = (struct xvfs_tclfs_channel_id *) Tcl_Alloc(sizeof(*channelInstanceData));
channelInstanceData->currentOffset = 0;
channelInstanceData->eofMarked = 0;
channelInstanceData->queuedEvents = 0;
channelInstanceData->closed = 0;
channelInstanceData->channel = NULL;
channelInstanceData->inode = fileInfo.st_ino;
channelName = Tcl_ObjPrintf("xvfs0x%llx", (unsigned long long) channelInstanceData);
if (!channelName) {
XVFS_DEBUG_PUTS("... failed");
Tcl_Free((char *) channelInstanceData);
XVFS_DEBUG_LEAVE;
return(NULL);
}
Tcl_IncrRefCount(channelName);
channelInstanceData->fsInstanceInfo = instanceInfo;
channelInstanceData->fileSize = fileInfo.st_size;
channelInstanceData->path = path;
Tcl_IncrRefCount(path);
channel = Tcl_CreateChannel(&xvfs_tclfs_channelType, Tcl_GetString(channelName), channelInstanceData, TCL_READABLE);
Tcl_DecrRefCount(channelName);
if (!channel) {
XVFS_DEBUG_PUTS("... failed");
Tcl_DecrRefCount(path);
|
︙ | | |
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
|
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
|
-
-
+
-
+
-
+
|
Tcl_QueueEvent((Tcl_Event *) event, TCL_QUEUE_TAIL);
XVFS_DEBUG_LEAVE;
return(0);
}
Tcl_DecrRefCount(channelInstanceData->path);
Tcl_Free((char *) channelInstanceData);
XVFS_DEBUG_PUTS("... ok");
XVFS_DEBUG_LEAVE;
return(0);
}
static int xvfs_tclfs_readChannel(ClientData channelInstanceData_p, char *buf, int bufSize, int *errorCodePtr) {
struct xvfs_tclfs_channel_id *channelInstanceData;
const unsigned char *data;
Tcl_WideInt offset, length;
char *path;
long inode;
channelInstanceData = (struct xvfs_tclfs_channel_id *) channelInstanceData_p;
/*
* If we are already at the end of the file we can skip
* attempting to read it
*/
if (channelInstanceData->eofMarked) {
return(0);
}
path = Tcl_GetString(channelInstanceData->path);
inode = channelInstanceData->inode;
offset = channelInstanceData->currentOffset;
length = bufSize;
data = channelInstanceData->fsInstanceInfo->fsInfo->getDataProc(path, offset, &length);
data = channelInstanceData->fsInstanceInfo->fsInfo->getDataProc(NULL, inode, offset, &length);
if (length < 0) {
*errorCodePtr = xvfs_errorToErrno(length);
return(-1);
}
|
︙ | | |
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
|
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
|
-
+
|
XVFS_DEBUG_PRINTF("Getting stat() on \"%s\" ...", Tcl_GetString(path));
path = xvfs_absolutePath(path);
pathStr = xvfs_relativePath(path, instanceInfo);
retval = instanceInfo->fsInfo->getStatProc(pathStr, statBuf);
retval = instanceInfo->fsInfo->getStatProc(pathStr, XVFS_INODE_NULL, statBuf);
if (retval < 0) {
XVFS_DEBUG_PRINTF("... failed: %s", xvfs_strerror(retval));
Tcl_SetErrno(xvfs_errorToErrno(retval));
retval = -1;
} else {
|
︙ | | |
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
|
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
|
-
+
|
Tcl_DecrRefCount(path);
XVFS_DEBUG_LEAVE;
return(-1);
}
statRetVal = instanceInfo->fsInfo->getStatProc(pathStr, &fileInfo);
statRetVal = instanceInfo->fsInfo->getStatProc(pathStr, XVFS_INODE_NULL, &fileInfo);
if (statRetVal < 0) {
XVFS_DEBUG_PUTS("... no (not statable)");
Tcl_DecrRefCount(path);
XVFS_DEBUG_LEAVE;
return(-1);
|
︙ | | |
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
|
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
|
-
+
|
xvfs_setresults_error(interp, XVFS_RV_ERR_ENOENT);
XVFS_DEBUG_LEAVE;
return(TCL_OK);
}
childrenCount = 0;
children = instanceInfo->fsInfo->getChildrenProc(pathStr, &childrenCount);
children = instanceInfo->fsInfo->getChildrenProc(pathStr, XVFS_INODE_NULL, &childrenCount);
if (childrenCount < 0) {
XVFS_DEBUG_PRINTF("... error: %s", xvfs_strerror(childrenCount));
Tcl_DecrRefCount(path);
xvfs_setresults_error(interp, childrenCount);
|
︙ | | |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
-
-
-
+
+
+
|
#ifndef XVFS_CORE_H_1B4B28D60EBAA11D5FF85642FA7CA22C29E8E817
#define XVFS_CORE_H_1B4B28D60EBAA11D5FF85642FA7CA22C29E8E817 1
#include <tcl.h>
#define XVFS_PROTOCOL_VERSION 1
typedef const char **(*xvfs_proc_getChildren_t)(const char *path, Tcl_WideInt *count);
typedef const unsigned char *(*xvfs_proc_getData_t)(const char *path, Tcl_WideInt start, Tcl_WideInt *length);
typedef int (*xvfs_proc_getStat_t)(const char *path, Tcl_StatBuf *statBuf);
typedef const char **(*xvfs_proc_getChildren_t)(const char *path, long inode, Tcl_WideInt *count);
typedef const unsigned char *(*xvfs_proc_getData_t)(const char *path, long inode, Tcl_WideInt start, Tcl_WideInt *length);
typedef int (*xvfs_proc_getStat_t)(const char *path, long inode, Tcl_StatBuf *statBuf);
/*
* Interface for the filesystem to fill out before registering.
* The protocolVersion is provided first so that if this
* needs to change over time it can be appropriately handled.
*/
struct Xvfs_FSInfo {
|
︙ | | |
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
+
+
+
+
+
+
+
|
#define XVFS_RV_ERR_EINVAL (-8193)
#define XVFS_RV_ERR_EISDIR (-8194)
#define XVFS_RV_ERR_ENOTDIR (-8195)
#define XVFS_RV_ERR_EFAULT (-8196)
#define XVFS_RV_ERR_EROFS (-8197)
#define XVFS_RV_ERR_INTERNAL (-16383)
/*
* Functions allow user to specify either a path or a inode.
* If a path is specified, the inode must be specified as
* XVFS_INODE_NULL.
*/
#define XVFS_INODE_NULL (-1)
#define XVFS_REGISTER_INTERFACE(name) int name(Tcl_Interp *interp, struct Xvfs_FSInfo *fsInfo);
#if defined(XVFS_MODE_STANDALONE)
/*
* In standalone mode, we just redefine calls to
* Xvfs_Register() to go to the xvfs_standalone_register()
* function
|
︙ | | |