69e476dcd5 2019-05-02 1: #include <xvfs-core.h>
717062426a 2020-04-13 2: #ifndef XVFS_CORE_H_1B4B28D60EBAA11D5FF85642FA7CA22C29E8E817
717062426a 2020-04-13 3: #define XVFS_CORE_C_1B4B28D60EBAA11D5FF85642FA7CA22C29E8E817 1
d121970301 2019-05-02 4: #include <string.h>
38bed7cee0 2019-09-13 5: #include <sys/stat.h>
38bed7cee0 2019-09-13 6: #include <errno.h>
38bed7cee0 2019-09-13 7: #include <fcntl.h>
69e476dcd5 2019-05-02 8: #include <tcl.h>
d80c88cee0 2019-09-16 9:
d80c88cee0 2019-09-16 10: #ifdef XVFS_DEBUG
d80c88cee0 2019-09-16 11: #include <stdio.h> /* Needed for XVFS_DEBUG_PRINTF */
d80c88cee0 2019-09-16 12: static int xvfs_debug_depth = 0;
d80c88cee0 2019-09-16 13: #define XVFS_DEBUG_PRINTF(fmt, ...) fprintf(stderr, "[XVFS:DEBUG:%-30s:%4i] %s" fmt "\n", __func__, __LINE__, " " + (80 - (xvfs_debug_depth * 4)), __VA_ARGS__)
d80c88cee0 2019-09-16 14: #define XVFS_DEBUG_PUTS(str) XVFS_DEBUG_PRINTF("%s", str);
d80c88cee0 2019-09-16 15: #define XVFS_DEBUG_ENTER { xvfs_debug_depth++; XVFS_DEBUG_PUTS("Entered"); }
d80c88cee0 2019-09-16 16: #define XVFS_DEBUG_LEAVE { XVFS_DEBUG_PUTS("Returning"); xvfs_debug_depth--; }
d80c88cee0 2019-09-16 17: #else /* XVFS_DEBUG */
d80c88cee0 2019-09-16 18: #define XVFS_DEBUG_PRINTF(fmt, ...) /**/
d80c88cee0 2019-09-16 19: #define XVFS_DEBUG_PUTS(str) /**/
d80c88cee0 2019-09-16 20: #define XVFS_DEBUG_ENTER /**/
d80c88cee0 2019-09-16 21: #define XVFS_DEBUG_LEAVE /**/
d80c88cee0 2019-09-16 22: #endif /* XVFS_DEBUG */
d92ba3d36d 2019-05-08 23:
d92ba3d36d 2019-05-08 24: #if defined(XVFS_MODE_FLEXIBLE) || defined(XVFS_MODE_SERVER)
d92ba3d36d 2019-05-08 25: #define XVFS_INTERNAL_SERVER_MAGIC "\xD4\xF3\x05\x96\x25\xCF\xAF\xFE"
d92ba3d36d 2019-05-08 26: #define XVFS_INTERNAL_SERVER_MAGIC_LEN 8
d92ba3d36d 2019-05-08 27:
d92ba3d36d 2019-05-08 28: struct xvfs_tclfs_server_info {
b586d5b0a1 2019-05-08 29: char magic[XVFS_INTERNAL_SERVER_MAGIC_LEN];
d92ba3d36d 2019-05-08 30: int (*registerProc)(Tcl_Interp *interp, struct Xvfs_FSInfo *fsInfo);
d92ba3d36d 2019-05-08 31: };
d92ba3d36d 2019-05-08 32: #endif /* XVFS_MODE_FLEXIBLE || XVFS_MODE_SERVER */
d92ba3d36d 2019-05-08 33:
3e44e1def1 2019-05-02 34: #if defined(XVFS_MODE_SERVER) || defined(XVFS_MODE_STANDALONE) || defined(XVFS_MODE_FLEXIBLE)
4221e5dcbc 2019-09-18 35: #ifndef XVFS_ROOT_MOUNTPOINT
4221e5dcbc 2019-09-18 36: # define XVFS_ROOT_MOUNTPOINT "//xvfs:/"
f01f82c2d8 2020-04-01 37: #endif
f01f82c2d8 2020-04-01 38:
f01f82c2d8 2020-04-01 39: /*
f01f82c2d8 2020-04-01 40: * Windows lacks X_OK and W_OK
f01f82c2d8 2020-04-01 41: */
f01f82c2d8 2020-04-01 42: #ifdef _MSC_BUILD
f01f82c2d8 2020-04-01 43: # define W_OK 02
f01f82c2d8 2020-04-01 44: # define X_OK 0 /* Mask it with nothing to get false */
4221e5dcbc 2019-09-18 45: #endif
d121970301 2019-05-02 46:
d121970301 2019-05-02 47: struct xvfs_tclfs_instance_info {
d121970301 2019-05-02 48: struct Xvfs_FSInfo *fsInfo;
d121970301 2019-05-02 49: Tcl_Obj *mountpoint;
d121970301 2019-05-02 50: };
d121970301 2019-05-02 51:
d121970301 2019-05-02 52: /*
d121970301 2019-05-02 53: * Internal Core Utilities
d121970301 2019-05-02 54: */
d80c88cee0 2019-09-16 55: static Tcl_Obj *xvfs_absolutePath(Tcl_Obj *path) {
5ae034e55e 2019-09-14 56: Tcl_Obj *currentDirectory;
d80c88cee0 2019-09-16 57: const char *pathStr;
5ae034e55e 2019-09-14 58:
d80c88cee0 2019-09-16 59: XVFS_DEBUG_ENTER;
d80c88cee0 2019-09-16 60:
d80c88cee0 2019-09-16 61: pathStr = Tcl_GetString(path);
d80c88cee0 2019-09-16 62:
5ae034e55e 2019-09-14 63: if (pathStr[0] != '/') {
5ae034e55e 2019-09-14 64: currentDirectory = Tcl_FSGetCwd(NULL);
5ae034e55e 2019-09-14 65: Tcl_IncrRefCount(currentDirectory);
5ae034e55e 2019-09-14 66:
5ae034e55e 2019-09-14 67: path = Tcl_ObjPrintf("%s/%s", Tcl_GetString(currentDirectory), pathStr);
5ae034e55e 2019-09-14 68: Tcl_IncrRefCount(path);
5ae034e55e 2019-09-14 69: Tcl_DecrRefCount(currentDirectory);
d80c88cee0 2019-09-16 70: } else {
d80c88cee0 2019-09-16 71: Tcl_IncrRefCount(path);
d80c88cee0 2019-09-16 72: }
5ae034e55e 2019-09-14 73:
d80c88cee0 2019-09-16 74: XVFS_DEBUG_PRINTF("Converted path \"%s\" to absolute path: \"%s\"", pathStr, Tcl_GetString(path));
d80c88cee0 2019-09-16 75:
d80c88cee0 2019-09-16 76: XVFS_DEBUG_LEAVE;
d80c88cee0 2019-09-16 77: return(path);
d80c88cee0 2019-09-16 78: }
d80c88cee0 2019-09-16 79:
d80c88cee0 2019-09-16 80: static const char *xvfs_relativePath(Tcl_Obj *path, struct xvfs_tclfs_instance_info *info) {
d80c88cee0 2019-09-16 81: const char *pathStr, *rootStr;
d80c88cee0 2019-09-16 82: const char *pathFinal;
d80c88cee0 2019-09-16 83: int pathLen, rootLen;
d80c88cee0 2019-09-16 84:
d80c88cee0 2019-09-16 85: XVFS_DEBUG_ENTER;
d80c88cee0 2019-09-16 86:
d80c88cee0 2019-09-16 87: rootStr = Tcl_GetStringFromObj(info->mountpoint, &rootLen);
d80c88cee0 2019-09-16 88: pathStr = Tcl_GetStringFromObj(path, &pathLen);
d80c88cee0 2019-09-16 89:
d80c88cee0 2019-09-16 90: XVFS_DEBUG_PRINTF("Finding relative path of \"%s\" from \"%s\" ...", pathStr, rootStr);
38bed7cee0 2019-09-13 91:
d121970301 2019-05-02 92: if (pathLen < rootLen) {
d80c88cee0 2019-09-16 93: XVFS_DEBUG_PUTS("... none possible (length)");
d80c88cee0 2019-09-16 94:
d80c88cee0 2019-09-16 95: XVFS_DEBUG_LEAVE;
d121970301 2019-05-02 96: return(NULL);
d121970301 2019-05-02 97: }
38bed7cee0 2019-09-13 98:
d121970301 2019-05-02 99: if (memcmp(pathStr, rootStr, rootLen) != 0) {
d80c88cee0 2019-09-16 100: XVFS_DEBUG_PUTS("... none possible (prefix differs)");
d80c88cee0 2019-09-16 101:
d80c88cee0 2019-09-16 102: XVFS_DEBUG_LEAVE;
d121970301 2019-05-02 103: return(NULL);
d121970301 2019-05-02 104: }
38bed7cee0 2019-09-13 105:
d121970301 2019-05-02 106: if (pathLen == rootLen) {
d80c88cee0 2019-09-16 107: XVFS_DEBUG_PUTS("... short circuit: \"\"");
d80c88cee0 2019-09-16 108:
d80c88cee0 2019-09-16 109: XVFS_DEBUG_LEAVE;
d121970301 2019-05-02 110: return("");
d121970301 2019-05-02 111: }
d121970301 2019-05-02 112:
d121970301 2019-05-02 113: /* XXX:TODO: Should this use the native OS path separator ? */
d121970301 2019-05-02 114: if (pathStr[rootLen] != '/') {
d80c88cee0 2019-09-16 115: XVFS_DEBUG_PUTS("... none possible (no seperator)");
d80c88cee0 2019-09-16 116:
d80c88cee0 2019-09-16 117: XVFS_DEBUG_LEAVE;
149aa89b7d 2019-09-13 118: return(NULL);
149aa89b7d 2019-09-13 119: }
38bed7cee0 2019-09-13 120:
5583d77f1c 2019-09-14 121: pathFinal = pathStr + rootLen + 1;
5583d77f1c 2019-09-14 122: pathLen -= rootLen + 1;
5583d77f1c 2019-09-14 123:
5583d77f1c 2019-09-14 124: if (pathLen == 1 && memcmp(pathFinal, ".", 1) == 0) {
d80c88cee0 2019-09-16 125: XVFS_DEBUG_PUTS("... short circuit: \".\" -> \"\"");
d80c88cee0 2019-09-16 126:
d80c88cee0 2019-09-16 127: XVFS_DEBUG_LEAVE;
5583d77f1c 2019-09-14 128: return("");
5583d77f1c 2019-09-14 129: }
5583d77f1c 2019-09-14 130:
5583d77f1c 2019-09-14 131: while (pathLen >= 2 && memcmp(pathFinal, "./", 2) == 0) {
5583d77f1c 2019-09-14 132: pathFinal += 2;
5583d77f1c 2019-09-14 133: pathLen -= 2;
5583d77f1c 2019-09-14 134: }
5583d77f1c 2019-09-14 135:
d80c88cee0 2019-09-16 136: XVFS_DEBUG_PRINTF("... relative path: \"%s\"", pathFinal);
d80c88cee0 2019-09-16 137:
d80c88cee0 2019-09-16 138: XVFS_DEBUG_LEAVE;
5583d77f1c 2019-09-14 139: return(pathFinal);
5583d77f1c 2019-09-14 140: }
38bed7cee0 2019-09-13 141:
38bed7cee0 2019-09-13 142: static int xvfs_errorToErrno(int xvfs_error) {
38bed7cee0 2019-09-13 143: if (xvfs_error >= 0) {
38bed7cee0 2019-09-13 144: return(0);
38bed7cee0 2019-09-13 145: }
38bed7cee0 2019-09-13 146:
38bed7cee0 2019-09-13 147: switch (xvfs_error) {
38bed7cee0 2019-09-13 148: case XVFS_RV_ERR_ENOENT:
38bed7cee0 2019-09-13 149: return(ENOENT);
38bed7cee0 2019-09-13 150: case XVFS_RV_ERR_EINVAL:
38bed7cee0 2019-09-13 151: return(EINVAL);
38bed7cee0 2019-09-13 152: case XVFS_RV_ERR_EISDIR:
38bed7cee0 2019-09-13 153: return(EISDIR);
38bed7cee0 2019-09-13 154: case XVFS_RV_ERR_ENOTDIR:
38bed7cee0 2019-09-13 155: return(ENOTDIR);
38bed7cee0 2019-09-13 156: case XVFS_RV_ERR_EFAULT:
38bed7cee0 2019-09-13 157: return(EFAULT);
10f67b2ced 2019-09-16 158: case XVFS_RV_ERR_EROFS:
10f67b2ced 2019-09-16 159: return(EROFS);
5583d77f1c 2019-09-14 160: case XVFS_RV_ERR_INTERNAL:
5583d77f1c 2019-09-14 161: return(EINVAL);
38bed7cee0 2019-09-13 162: default:
38bed7cee0 2019-09-13 163: return(ERANGE);
38bed7cee0 2019-09-13 164: }
10f67b2ced 2019-09-16 165: }
10f67b2ced 2019-09-16 166:
cf56967f97 2019-09-17 167: static const char *xvfs_strerror(int xvfs_error) {
10f67b2ced 2019-09-16 168: if (xvfs_error >= 0) {
10f67b2ced 2019-09-16 169: return("Not an error");
10f67b2ced 2019-09-16 170: }
10f67b2ced 2019-09-16 171:
10f67b2ced 2019-09-16 172: switch (xvfs_error) {
10f67b2ced 2019-09-16 173: case XVFS_RV_ERR_ENOENT:
10f67b2ced 2019-09-16 174: case XVFS_RV_ERR_EINVAL:
10f67b2ced 2019-09-16 175: case XVFS_RV_ERR_EISDIR:
10f67b2ced 2019-09-16 176: case XVFS_RV_ERR_ENOTDIR:
10f67b2ced 2019-09-16 177: case XVFS_RV_ERR_EFAULT:
10f67b2ced 2019-09-16 178: case XVFS_RV_ERR_EROFS:
10f67b2ced 2019-09-16 179: return(Tcl_ErrnoMsg(xvfs_errorToErrno(xvfs_error)));
10f67b2ced 2019-09-16 180: case XVFS_RV_ERR_INTERNAL:
10f67b2ced 2019-09-16 181: return("Internal error");
10f67b2ced 2019-09-16 182: default:
10f67b2ced 2019-09-16 183: return("Unknown error");
10f67b2ced 2019-09-16 184: }
e786b9e07b 2019-09-16 185: }
e786b9e07b 2019-09-16 186:
e786b9e07b 2019-09-16 187: static void xvfs_setresults_error(Tcl_Interp *interp, int xvfs_error) {
e786b9e07b 2019-09-16 188: if (!interp) {
e786b9e07b 2019-09-16 189: return;
e786b9e07b 2019-09-16 190: }
e786b9e07b 2019-09-16 191:
e786b9e07b 2019-09-16 192: Tcl_SetErrno(xvfs_errorToErrno(xvfs_error));
cf56967f97 2019-09-17 193: Tcl_SetResult(interp, (char *) xvfs_strerror(xvfs_error), NULL);
e786b9e07b 2019-09-16 194:
e786b9e07b 2019-09-16 195: return;
38bed7cee0 2019-09-13 196: }
38bed7cee0 2019-09-13 197:
38bed7cee0 2019-09-13 198: /*
38bed7cee0 2019-09-13 199: * Xvfs Memory Channel
38bed7cee0 2019-09-13 200: */
38bed7cee0 2019-09-13 201: struct xvfs_tclfs_channel_id {
38bed7cee0 2019-09-13 202: Tcl_Channel channel;
38bed7cee0 2019-09-13 203: struct xvfs_tclfs_instance_info *fsInstanceInfo;
38bed7cee0 2019-09-13 204: Tcl_Obj *path;
38bed7cee0 2019-09-13 205: Tcl_WideInt currentOffset;
38bed7cee0 2019-09-13 206: Tcl_WideInt fileSize;
7d74392642 2019-09-13 207: int eofMarked;
aa08a4a749 2019-09-14 208: int queuedEvents;
aa08a4a749 2019-09-14 209: int closed;
7d74392642 2019-09-13 210: };
7d74392642 2019-09-13 211: struct xvfs_tclfs_channel_event {
7d74392642 2019-09-13 212: Tcl_Event tcl;
7d74392642 2019-09-13 213: struct xvfs_tclfs_channel_id *channelInstanceData;
38bed7cee0 2019-09-13 214: };
38bed7cee0 2019-09-13 215: static Tcl_ChannelType xvfs_tclfs_channelType;
38bed7cee0 2019-09-13 216:
e786b9e07b 2019-09-16 217: static Tcl_Channel xvfs_tclfs_openChannel(Tcl_Interp *interp, Tcl_Obj *path, struct xvfs_tclfs_instance_info *instanceInfo) {
38bed7cee0 2019-09-13 218: struct xvfs_tclfs_channel_id *channelInstanceData;
38bed7cee0 2019-09-13 219: Tcl_Channel channel;
38bed7cee0 2019-09-13 220: Tcl_StatBuf fileInfo;
7d74392642 2019-09-13 221: Tcl_Obj *channelName;
38bed7cee0 2019-09-13 222: int statRet;
7d74392642 2019-09-13 223:
d80c88cee0 2019-09-16 224: XVFS_DEBUG_ENTER;
d80c88cee0 2019-09-16 225: XVFS_DEBUG_PRINTF("Opening file \"%s\" ...", Tcl_GetString(path));
d80c88cee0 2019-09-16 226:
38bed7cee0 2019-09-13 227: statRet = instanceInfo->fsInfo->getStatProc(Tcl_GetString(path), &fileInfo);
38bed7cee0 2019-09-13 228: if (statRet < 0) {
cf56967f97 2019-09-17 229: XVFS_DEBUG_PRINTF("... failed: %s", xvfs_strerror(statRet));
e786b9e07b 2019-09-16 230:
e786b9e07b 2019-09-16 231: xvfs_setresults_error(interp, XVFS_RV_ERR_ENOENT);
e786b9e07b 2019-09-16 232:
e786b9e07b 2019-09-16 233: XVFS_DEBUG_LEAVE;
e786b9e07b 2019-09-16 234: return(NULL);
e786b9e07b 2019-09-16 235: }
e786b9e07b 2019-09-16 236:
e786b9e07b 2019-09-16 237: if (fileInfo.st_mode & 040000) {
e786b9e07b 2019-09-16 238: XVFS_DEBUG_PUTS("... failed (cannot open directories)");
e786b9e07b 2019-09-16 239:
e786b9e07b 2019-09-16 240: xvfs_setresults_error(interp, XVFS_RV_ERR_EISDIR);
d80c88cee0 2019-09-16 241:
d80c88cee0 2019-09-16 242: XVFS_DEBUG_LEAVE;
38bed7cee0 2019-09-13 243: return(NULL);
38bed7cee0 2019-09-13 244: }
38bed7cee0 2019-09-13 245:
38bed7cee0 2019-09-13 246: channelInstanceData = (struct xvfs_tclfs_channel_id *) Tcl_Alloc(sizeof(*channelInstanceData));
38bed7cee0 2019-09-13 247: channelInstanceData->currentOffset = 0;
7d74392642 2019-09-13 248: channelInstanceData->eofMarked = 0;
aa08a4a749 2019-09-14 249: channelInstanceData->queuedEvents = 0;
aa08a4a749 2019-09-14 250: channelInstanceData->closed = 0;
38bed7cee0 2019-09-13 251: channelInstanceData->channel = NULL;
38bed7cee0 2019-09-13 252:
7d74392642 2019-09-13 253: channelName = Tcl_ObjPrintf("xvfs0x%llx", (unsigned long long) channelInstanceData);
7d74392642 2019-09-13 254: if (!channelName) {
d80c88cee0 2019-09-16 255: XVFS_DEBUG_PUTS("... failed");
d80c88cee0 2019-09-16 256:
7d74392642 2019-09-13 257: Tcl_Free((char *) channelInstanceData);
7d74392642 2019-09-13 258:
d80c88cee0 2019-09-16 259: XVFS_DEBUG_LEAVE;
7d74392642 2019-09-13 260: return(NULL);
7d74392642 2019-09-13 261: }
7d74392642 2019-09-13 262: Tcl_IncrRefCount(channelName);
7d74392642 2019-09-13 263:
38bed7cee0 2019-09-13 264: channelInstanceData->fsInstanceInfo = instanceInfo;
38bed7cee0 2019-09-13 265: channelInstanceData->fileSize = fileInfo.st_size;
7d74392642 2019-09-13 266: channelInstanceData->path = path;
38bed7cee0 2019-09-13 267: Tcl_IncrRefCount(path);
38bed7cee0 2019-09-13 268:
7d74392642 2019-09-13 269: channel = Tcl_CreateChannel(&xvfs_tclfs_channelType, Tcl_GetString(channelName), channelInstanceData, TCL_READABLE);
7d74392642 2019-09-13 270: Tcl_DecrRefCount(channelName);
38bed7cee0 2019-09-13 271: if (!channel) {
d80c88cee0 2019-09-16 272: XVFS_DEBUG_PUTS("... failed");
d80c88cee0 2019-09-16 273:
38bed7cee0 2019-09-13 274: Tcl_DecrRefCount(path);
38bed7cee0 2019-09-13 275: Tcl_Free((char *) channelInstanceData);
38bed7cee0 2019-09-13 276:
d80c88cee0 2019-09-16 277: XVFS_DEBUG_LEAVE;
38bed7cee0 2019-09-13 278: return(NULL);
38bed7cee0 2019-09-13 279: }
38bed7cee0 2019-09-13 280:
38bed7cee0 2019-09-13 281: channelInstanceData->channel = channel;
38bed7cee0 2019-09-13 282:
d80c88cee0 2019-09-16 283: XVFS_DEBUG_PRINTF("... ok (%p)", channelInstanceData);
d80c88cee0 2019-09-16 284:
d80c88cee0 2019-09-16 285: XVFS_DEBUG_LEAVE;
38bed7cee0 2019-09-13 286: return(channel);
aa08a4a749 2019-09-14 287: }
aa08a4a749 2019-09-14 288:
aa08a4a749 2019-09-14 289: static int xvfs_tclfs_closeChannel(ClientData channelInstanceData_p, Tcl_Interp *interp);
aa08a4a749 2019-09-14 290: static int xvfs_tclfs_closeChannelEvent(Tcl_Event *event_p, int flags) {
aa08a4a749 2019-09-14 291: struct xvfs_tclfs_channel_id *channelInstanceData;
aa08a4a749 2019-09-14 292: struct xvfs_tclfs_channel_event *event;
aa08a4a749 2019-09-14 293:
aa08a4a749 2019-09-14 294: event = (struct xvfs_tclfs_channel_event *) event_p;
aa08a4a749 2019-09-14 295: channelInstanceData = event->channelInstanceData;
aa08a4a749 2019-09-14 296:
aa08a4a749 2019-09-14 297: channelInstanceData->queuedEvents--;
aa08a4a749 2019-09-14 298:
aa08a4a749 2019-09-14 299: xvfs_tclfs_closeChannel((ClientData) channelInstanceData, NULL);
aa08a4a749 2019-09-14 300:
aa08a4a749 2019-09-14 301: return(1);
38bed7cee0 2019-09-13 302: }
38bed7cee0 2019-09-13 303:
38bed7cee0 2019-09-13 304: static int xvfs_tclfs_closeChannel(ClientData channelInstanceData_p, Tcl_Interp *interp) {
38bed7cee0 2019-09-13 305: struct xvfs_tclfs_channel_id *channelInstanceData;
aa08a4a749 2019-09-14 306: struct xvfs_tclfs_channel_event *event;
aa08a4a749 2019-09-14 307:
d80c88cee0 2019-09-16 308: XVFS_DEBUG_ENTER;
d80c88cee0 2019-09-16 309: XVFS_DEBUG_PRINTF("Closing channel %p ...", channelInstanceData_p);
d80c88cee0 2019-09-16 310:
38bed7cee0 2019-09-13 311: channelInstanceData = (struct xvfs_tclfs_channel_id *) channelInstanceData_p;
aa08a4a749 2019-09-14 312:
aa08a4a749 2019-09-14 313: channelInstanceData->closed = 1;
aa08a4a749 2019-09-14 314:
aa08a4a749 2019-09-14 315: if (channelInstanceData->queuedEvents != 0) {
d80c88cee0 2019-09-16 316: XVFS_DEBUG_PUTS("... queued");
d80c88cee0 2019-09-16 317:
aa08a4a749 2019-09-14 318: event = (struct xvfs_tclfs_channel_event *) Tcl_Alloc(sizeof(*event));
aa08a4a749 2019-09-14 319: event->tcl.proc = xvfs_tclfs_closeChannelEvent;
aa08a4a749 2019-09-14 320: event->tcl.nextPtr = NULL;
aa08a4a749 2019-09-14 321: event->channelInstanceData = channelInstanceData;
aa08a4a749 2019-09-14 322:
aa08a4a749 2019-09-14 323: channelInstanceData->queuedEvents++;
aa08a4a749 2019-09-14 324:
aa08a4a749 2019-09-14 325: Tcl_QueueEvent((Tcl_Event *) event, TCL_QUEUE_TAIL);
aa08a4a749 2019-09-14 326:
d80c88cee0 2019-09-16 327: XVFS_DEBUG_LEAVE;
aa08a4a749 2019-09-14 328: return(0);
aa08a4a749 2019-09-14 329: }
38bed7cee0 2019-09-13 330:
38bed7cee0 2019-09-13 331: Tcl_DecrRefCount(channelInstanceData->path);
38bed7cee0 2019-09-13 332: Tcl_Free((char *) channelInstanceData);
38bed7cee0 2019-09-13 333:
d80c88cee0 2019-09-16 334: XVFS_DEBUG_PUTS("... ok");
d80c88cee0 2019-09-16 335:
d80c88cee0 2019-09-16 336: XVFS_DEBUG_LEAVE;
38bed7cee0 2019-09-13 337: return(0);
38bed7cee0 2019-09-13 338: }
38bed7cee0 2019-09-13 339:
38bed7cee0 2019-09-13 340: static int xvfs_tclfs_readChannel(ClientData channelInstanceData_p, char *buf, int bufSize, int *errorCodePtr) {
38bed7cee0 2019-09-13 341: struct xvfs_tclfs_channel_id *channelInstanceData;
38bed7cee0 2019-09-13 342: const unsigned char *data;
38bed7cee0 2019-09-13 343: Tcl_WideInt offset, length;
38bed7cee0 2019-09-13 344: char *path;
38bed7cee0 2019-09-13 345:
38bed7cee0 2019-09-13 346: channelInstanceData = (struct xvfs_tclfs_channel_id *) channelInstanceData_p;
7d74392642 2019-09-13 347:
7d74392642 2019-09-13 348: /*
7d74392642 2019-09-13 349: * If we are already at the end of the file we can skip
7d74392642 2019-09-13 350: * attempting to read it
7d74392642 2019-09-13 351: */
7d74392642 2019-09-13 352: if (channelInstanceData->eofMarked) {
7d74392642 2019-09-13 353: return(0);
7d74392642 2019-09-13 354: }
38bed7cee0 2019-09-13 355:
38bed7cee0 2019-09-13 356: path = Tcl_GetString(channelInstanceData->path);
38bed7cee0 2019-09-13 357: offset = channelInstanceData->currentOffset;
38bed7cee0 2019-09-13 358: length = bufSize;
38bed7cee0 2019-09-13 359:
38bed7cee0 2019-09-13 360: data = channelInstanceData->fsInstanceInfo->fsInfo->getDataProc(path, offset, &length);
38bed7cee0 2019-09-13 361:
38bed7cee0 2019-09-13 362: if (length < 0) {
38bed7cee0 2019-09-13 363: *errorCodePtr = xvfs_errorToErrno(length);
38bed7cee0 2019-09-13 364:
38bed7cee0 2019-09-13 365: return(-1);
38bed7cee0 2019-09-13 366: }
38bed7cee0 2019-09-13 367:
7d74392642 2019-09-13 368: if (length == 0) {
7d74392642 2019-09-13 369: channelInstanceData->eofMarked = 1;
7d74392642 2019-09-13 370: } else {
7d74392642 2019-09-13 371: memcpy(buf, data, length);
38bed7cee0 2019-09-13 372:
7d74392642 2019-09-13 373: channelInstanceData->currentOffset += length;
7d74392642 2019-09-13 374: }
38bed7cee0 2019-09-13 375:
38bed7cee0 2019-09-13 376: return(length);
38bed7cee0 2019-09-13 377: }
38bed7cee0 2019-09-13 378:
7d74392642 2019-09-13 379: static int xvfs_tclfs_watchChannelEvent(Tcl_Event *event_p, int flags) {
7d74392642 2019-09-13 380: struct xvfs_tclfs_channel_id *channelInstanceData;
7d74392642 2019-09-13 381: struct xvfs_tclfs_channel_event *event;
7d74392642 2019-09-13 382:
7d74392642 2019-09-13 383: event = (struct xvfs_tclfs_channel_event *) event_p;
7d74392642 2019-09-13 384: channelInstanceData = event->channelInstanceData;
7d74392642 2019-09-13 385:
aa08a4a749 2019-09-14 386: channelInstanceData->queuedEvents--;
aa08a4a749 2019-09-14 387:
aa08a4a749 2019-09-14 388: if (channelInstanceData->closed) {
aa08a4a749 2019-09-14 389: return(1);
aa08a4a749 2019-09-14 390: }
aa08a4a749 2019-09-14 391:
7d74392642 2019-09-13 392: Tcl_NotifyChannel(channelInstanceData->channel, TCL_READABLE);
7d74392642 2019-09-13 393:
aa08a4a749 2019-09-14 394: return(1);
7d74392642 2019-09-13 395: }
7d74392642 2019-09-13 396:
38bed7cee0 2019-09-13 397: static void xvfs_tclfs_watchChannel(ClientData channelInstanceData_p, int mask) {
7d74392642 2019-09-13 398: struct xvfs_tclfs_channel_id *channelInstanceData;
7d74392642 2019-09-13 399: struct xvfs_tclfs_channel_event *event;
7d74392642 2019-09-13 400:
38bed7cee0 2019-09-13 401: if ((mask & TCL_READABLE) != TCL_READABLE) {
38bed7cee0 2019-09-13 402: return;
38bed7cee0 2019-09-13 403: }
38bed7cee0 2019-09-13 404:
7d74392642 2019-09-13 405: channelInstanceData = (struct xvfs_tclfs_channel_id *) channelInstanceData_p;
7d74392642 2019-09-13 406:
7d74392642 2019-09-13 407: event = (struct xvfs_tclfs_channel_event *) Tcl_Alloc(sizeof(*event));
7d74392642 2019-09-13 408: event->tcl.proc = xvfs_tclfs_watchChannelEvent;
7d74392642 2019-09-13 409: event->tcl.nextPtr = NULL;
7d74392642 2019-09-13 410: event->channelInstanceData = channelInstanceData;
aa08a4a749 2019-09-14 411:
aa08a4a749 2019-09-14 412: channelInstanceData->queuedEvents++;
7d74392642 2019-09-13 413:
7d74392642 2019-09-13 414: Tcl_QueueEvent((Tcl_Event *) event, TCL_QUEUE_TAIL);
7d74392642 2019-09-13 415:
38bed7cee0 2019-09-13 416: return;
38bed7cee0 2019-09-13 417: }
38bed7cee0 2019-09-13 418:
38bed7cee0 2019-09-13 419: static int xvfs_tclfs_seekChannel(ClientData channelInstanceData_p, long offset, int mode, int *errorCodePtr) {
38bed7cee0 2019-09-13 420: struct xvfs_tclfs_channel_id *channelInstanceData;
38bed7cee0 2019-09-13 421: Tcl_WideInt newOffset, fileSize;
38bed7cee0 2019-09-13 422:
38bed7cee0 2019-09-13 423: channelInstanceData = (struct xvfs_tclfs_channel_id *) channelInstanceData_p;
38bed7cee0 2019-09-13 424:
38bed7cee0 2019-09-13 425: newOffset = channelInstanceData->currentOffset;
38bed7cee0 2019-09-13 426: fileSize = channelInstanceData->fileSize;
38bed7cee0 2019-09-13 427:
38bed7cee0 2019-09-13 428: switch (mode) {
38bed7cee0 2019-09-13 429: case SEEK_CUR:
38bed7cee0 2019-09-13 430: newOffset += offset;
38bed7cee0 2019-09-13 431: break;
38bed7cee0 2019-09-13 432: case SEEK_SET:
38bed7cee0 2019-09-13 433: newOffset = offset;
38bed7cee0 2019-09-13 434: break;
38bed7cee0 2019-09-13 435: case SEEK_END:
38bed7cee0 2019-09-13 436: newOffset = fileSize + offset;
38bed7cee0 2019-09-13 437: break;
38bed7cee0 2019-09-13 438: default:
38bed7cee0 2019-09-13 439: *errorCodePtr = xvfs_errorToErrno(XVFS_RV_ERR_EINVAL);
38bed7cee0 2019-09-13 440:
38bed7cee0 2019-09-13 441: return(-1);
38bed7cee0 2019-09-13 442: }
38bed7cee0 2019-09-13 443:
38bed7cee0 2019-09-13 444: /*
38bed7cee0 2019-09-13 445: * We allow users to seek right up to the end of the buffer, but
38bed7cee0 2019-09-13 446: * no further, this way if they want to seek backwards from there
38bed7cee0 2019-09-13 447: * it is possible to do so.
38bed7cee0 2019-09-13 448: */
38bed7cee0 2019-09-13 449: if (newOffset < 0 || newOffset > fileSize) {
38bed7cee0 2019-09-13 450: *errorCodePtr = xvfs_errorToErrno(XVFS_RV_ERR_EINVAL);
38bed7cee0 2019-09-13 451:
38bed7cee0 2019-09-13 452: return(-1);
38bed7cee0 2019-09-13 453: }
38bed7cee0 2019-09-13 454:
7d74392642 2019-09-13 455: if (newOffset != channelInstanceData->currentOffset) {
7d74392642 2019-09-13 456: channelInstanceData->eofMarked = 0;
7d74392642 2019-09-13 457: channelInstanceData->currentOffset = newOffset;
7d74392642 2019-09-13 458: }
38bed7cee0 2019-09-13 459:
38bed7cee0 2019-09-13 460: return(channelInstanceData->currentOffset);
38bed7cee0 2019-09-13 461: }
38bed7cee0 2019-09-13 462:
38bed7cee0 2019-09-13 463: static void xvfs_tclfs_prepareChannelType(void) {
38bed7cee0 2019-09-13 464: xvfs_tclfs_channelType.typeName = "xvfs";
38bed7cee0 2019-09-13 465: xvfs_tclfs_channelType.version = TCL_CHANNEL_VERSION_2;
38bed7cee0 2019-09-13 466: xvfs_tclfs_channelType.closeProc = xvfs_tclfs_closeChannel;
38bed7cee0 2019-09-13 467: xvfs_tclfs_channelType.inputProc = xvfs_tclfs_readChannel;
38bed7cee0 2019-09-13 468: xvfs_tclfs_channelType.outputProc = NULL;
38bed7cee0 2019-09-13 469: xvfs_tclfs_channelType.watchProc = xvfs_tclfs_watchChannel;
38bed7cee0 2019-09-13 470: xvfs_tclfs_channelType.getHandleProc = NULL;
38bed7cee0 2019-09-13 471: xvfs_tclfs_channelType.seekProc = xvfs_tclfs_seekChannel;
38bed7cee0 2019-09-13 472: xvfs_tclfs_channelType.setOptionProc = NULL;
38bed7cee0 2019-09-13 473: xvfs_tclfs_channelType.getOptionProc = NULL;
38bed7cee0 2019-09-13 474: xvfs_tclfs_channelType.close2Proc = NULL;
38bed7cee0 2019-09-13 475: xvfs_tclfs_channelType.blockModeProc = NULL;
38bed7cee0 2019-09-13 476: xvfs_tclfs_channelType.flushProc = NULL;
38bed7cee0 2019-09-13 477: xvfs_tclfs_channelType.handlerProc = NULL;
38bed7cee0 2019-09-13 478: xvfs_tclfs_channelType.wideSeekProc = NULL;
38bed7cee0 2019-09-13 479: xvfs_tclfs_channelType.threadActionProc = NULL;
38bed7cee0 2019-09-13 480: xvfs_tclfs_channelType.truncateProc = NULL;
d121970301 2019-05-02 481: }
d121970301 2019-05-02 482:
d121970301 2019-05-02 483: /*
d121970301 2019-05-02 484: * Internal Tcl_Filesystem functions, with the appropriate instance info
d121970301 2019-05-02 485: */
d121970301 2019-05-02 486: static int xvfs_tclfs_pathInFilesystem(Tcl_Obj *path, ClientData *dataPtr, struct xvfs_tclfs_instance_info *instanceInfo) {
d121970301 2019-05-02 487: const char *relativePath;
d80c88cee0 2019-09-16 488: int retval;
d80c88cee0 2019-09-16 489:
d80c88cee0 2019-09-16 490: XVFS_DEBUG_ENTER;
d80c88cee0 2019-09-16 491:
d80c88cee0 2019-09-16 492: XVFS_DEBUG_PRINTF("Checking to see if path \"%s\" is in the filesystem ...", Tcl_GetString(path));
d80c88cee0 2019-09-16 493:
d80c88cee0 2019-09-16 494: path = xvfs_absolutePath(path);
38bed7cee0 2019-09-13 495:
d121970301 2019-05-02 496: relativePath = xvfs_relativePath(path, instanceInfo);
d80c88cee0 2019-09-16 497:
d80c88cee0 2019-09-16 498: retval = TCL_OK;
d121970301 2019-05-02 499: if (!relativePath) {
d80c88cee0 2019-09-16 500: retval = -1;
d121970301 2019-05-02 501: }
38bed7cee0 2019-09-13 502:
d80c88cee0 2019-09-16 503: Tcl_DecrRefCount(path);
d80c88cee0 2019-09-16 504:
d80c88cee0 2019-09-16 505: XVFS_DEBUG_PRINTF("... %s", retval == -1 ? "no" : "yes");
d80c88cee0 2019-09-16 506:
d80c88cee0 2019-09-16 507: XVFS_DEBUG_LEAVE;
d80c88cee0 2019-09-16 508: return(retval);
d121970301 2019-05-02 509: }
d121970301 2019-05-02 510:
d121970301 2019-05-02 511: static int xvfs_tclfs_stat(Tcl_Obj *path, Tcl_StatBuf *statBuf, struct xvfs_tclfs_instance_info *instanceInfo) {
d121970301 2019-05-02 512: const char *pathStr;
d121970301 2019-05-02 513: int retval;
d121970301 2019-05-02 514:
d80c88cee0 2019-09-16 515: XVFS_DEBUG_ENTER;
d80c88cee0 2019-09-16 516:
d80c88cee0 2019-09-16 517: XVFS_DEBUG_PRINTF("Getting stat() on \"%s\" ...", Tcl_GetString(path));
d80c88cee0 2019-09-16 518:
d80c88cee0 2019-09-16 519: path = xvfs_absolutePath(path);
d80c88cee0 2019-09-16 520:
d121970301 2019-05-02 521: pathStr = xvfs_relativePath(path, instanceInfo);
38bed7cee0 2019-09-13 522:
daf25f5222 2019-05-03 523: retval = instanceInfo->fsInfo->getStatProc(pathStr, statBuf);
149aa89b7d 2019-09-13 524: if (retval < 0) {
cf56967f97 2019-09-17 525: XVFS_DEBUG_PRINTF("... failed: %s", xvfs_strerror(retval));
f1d16a3958 2019-09-17 526:
f1d16a3958 2019-09-17 527: Tcl_SetErrno(xvfs_errorToErrno(retval));
f1d16a3958 2019-09-17 528:
149aa89b7d 2019-09-13 529: retval = -1;
d80c88cee0 2019-09-16 530: } else {
d80c88cee0 2019-09-16 531: XVFS_DEBUG_PUTS("... ok");
149aa89b7d 2019-09-13 532: }
38bed7cee0 2019-09-13 533:
d80c88cee0 2019-09-16 534: Tcl_DecrRefCount(path);
d80c88cee0 2019-09-16 535:
d80c88cee0 2019-09-16 536: XVFS_DEBUG_LEAVE;
d121970301 2019-05-02 537: return(retval);
d121970301 2019-05-02 538: }
d121970301 2019-05-02 539:
12ff77016f 2019-09-14 540: static int xvfs_tclfs_access(Tcl_Obj *path, int mode, struct xvfs_tclfs_instance_info *instanceInfo) {
12ff77016f 2019-09-14 541: const char *pathStr;
12ff77016f 2019-09-14 542: Tcl_StatBuf fileInfo;
12ff77016f 2019-09-14 543: int statRetVal;
12ff77016f 2019-09-14 544:
d80c88cee0 2019-09-16 545: XVFS_DEBUG_ENTER;
d80c88cee0 2019-09-16 546:
d80c88cee0 2019-09-16 547: XVFS_DEBUG_PRINTF("Getting access(..., %i) on \"%s\" ...", mode, Tcl_GetString(path));
12ff77016f 2019-09-14 548:
12ff77016f 2019-09-14 549: if (mode & W_OK) {
d80c88cee0 2019-09-16 550: XVFS_DEBUG_PUTS("... no (not writable)");
d80c88cee0 2019-09-16 551:
d80c88cee0 2019-09-16 552: XVFS_DEBUG_LEAVE;
d80c88cee0 2019-09-16 553: return(-1);
d80c88cee0 2019-09-16 554: }
d80c88cee0 2019-09-16 555:
d80c88cee0 2019-09-16 556: path = xvfs_absolutePath(path);
d80c88cee0 2019-09-16 557:
d80c88cee0 2019-09-16 558: pathStr = xvfs_relativePath(path, instanceInfo);
d80c88cee0 2019-09-16 559: if (!pathStr) {
d80c88cee0 2019-09-16 560: XVFS_DEBUG_PUTS("... no (not in our path)");
d80c88cee0 2019-09-16 561:
d80c88cee0 2019-09-16 562: Tcl_DecrRefCount(path);
d80c88cee0 2019-09-16 563:
d80c88cee0 2019-09-16 564: XVFS_DEBUG_LEAVE;
12ff77016f 2019-09-14 565: return(-1);
12ff77016f 2019-09-14 566: }
12ff77016f 2019-09-14 567:
12ff77016f 2019-09-14 568: statRetVal = instanceInfo->fsInfo->getStatProc(pathStr, &fileInfo);
12ff77016f 2019-09-14 569: if (statRetVal < 0) {
d80c88cee0 2019-09-16 570: XVFS_DEBUG_PUTS("... no (not statable)");
d80c88cee0 2019-09-16 571:
d80c88cee0 2019-09-16 572: Tcl_DecrRefCount(path);
d80c88cee0 2019-09-16 573:
d80c88cee0 2019-09-16 574: XVFS_DEBUG_LEAVE;
12ff77016f 2019-09-14 575: return(-1);
12ff77016f 2019-09-14 576: }
12ff77016f 2019-09-14 577:
12ff77016f 2019-09-14 578: if (mode & X_OK) {
12ff77016f 2019-09-14 579: if (!(fileInfo.st_mode & 040000)) {
d80c88cee0 2019-09-16 580: XVFS_DEBUG_PUTS("... no (not a directory and X_OK specified)");
d80c88cee0 2019-09-16 581:
d80c88cee0 2019-09-16 582: Tcl_DecrRefCount(path);
d80c88cee0 2019-09-16 583:
d80c88cee0 2019-09-16 584: XVFS_DEBUG_LEAVE;
12ff77016f 2019-09-14 585: return(-1);
12ff77016f 2019-09-14 586: }
12ff77016f 2019-09-14 587: }
12ff77016f 2019-09-14 588:
d80c88cee0 2019-09-16 589: Tcl_DecrRefCount(path);
d80c88cee0 2019-09-16 590:
d80c88cee0 2019-09-16 591: XVFS_DEBUG_PUTS("... ok");
d80c88cee0 2019-09-16 592:
d80c88cee0 2019-09-16 593: XVFS_DEBUG_LEAVE;
12ff77016f 2019-09-14 594: return(0);
d121970301 2019-05-02 595: }
d121970301 2019-05-02 596:
d121970301 2019-05-02 597: static Tcl_Channel xvfs_tclfs_openFileChannel(Tcl_Interp *interp, Tcl_Obj *path, int mode, int permissions, struct xvfs_tclfs_instance_info *instanceInfo) {
d80c88cee0 2019-09-16 598: Tcl_Channel retval;
d80c88cee0 2019-09-16 599: Tcl_Obj *pathRel;
38bed7cee0 2019-09-13 600: const char *pathStr;
38bed7cee0 2019-09-13 601:
d80c88cee0 2019-09-16 602: XVFS_DEBUG_ENTER;
d80c88cee0 2019-09-16 603:
d80c88cee0 2019-09-16 604: XVFS_DEBUG_PRINTF("Asked to open(\"%s\", %x)...", Tcl_GetString(path), mode);
38bed7cee0 2019-09-13 605:
38bed7cee0 2019-09-13 606: if (mode & O_WRONLY) {
10f67b2ced 2019-09-16 607: XVFS_DEBUG_PUTS("... failed (asked to open for writing)");
10f67b2ced 2019-09-16 608:
e786b9e07b 2019-09-16 609: xvfs_setresults_error(interp, XVFS_RV_ERR_EROFS);
d80c88cee0 2019-09-16 610:
d80c88cee0 2019-09-16 611: XVFS_DEBUG_LEAVE;
38bed7cee0 2019-09-13 612: return(NULL);
38bed7cee0 2019-09-13 613: }
38bed7cee0 2019-09-13 614:
d80c88cee0 2019-09-16 615: path = xvfs_absolutePath(path);
d80c88cee0 2019-09-16 616:
d80c88cee0 2019-09-16 617: pathStr = xvfs_relativePath(path, instanceInfo);
d80c88cee0 2019-09-16 618:
d80c88cee0 2019-09-16 619: pathRel = Tcl_NewStringObj(pathStr, -1);
d80c88cee0 2019-09-16 620:
d80c88cee0 2019-09-16 621: Tcl_DecrRefCount(path);
d80c88cee0 2019-09-16 622:
d80c88cee0 2019-09-16 623: XVFS_DEBUG_PUTS("... done, passing off to channel handler");
d80c88cee0 2019-09-16 624:
e786b9e07b 2019-09-16 625: retval = xvfs_tclfs_openChannel(interp, pathRel, instanceInfo);
d80c88cee0 2019-09-16 626:
d80c88cee0 2019-09-16 627: XVFS_DEBUG_LEAVE;
d80c88cee0 2019-09-16 628: return(retval);
5583d77f1c 2019-09-14 629: }
5583d77f1c 2019-09-14 630:
5583d77f1c 2019-09-14 631: static int xvfs_tclfs_verifyType(Tcl_Obj *path, Tcl_GlobTypeData *types, struct xvfs_tclfs_instance_info *instanceInfo) {
5583d77f1c 2019-09-14 632: const char *pathStr;
5583d77f1c 2019-09-14 633: Tcl_StatBuf fileInfo;
5583d77f1c 2019-09-14 634: int statRetVal;
5583d77f1c 2019-09-14 635:
d80c88cee0 2019-09-16 636: XVFS_DEBUG_ENTER;
d80c88cee0 2019-09-16 637:
d80c88cee0 2019-09-16 638: if (types) {
d80c88cee0 2019-09-16 639: XVFS_DEBUG_PRINTF("Asked to verify the existence and type of \"%s\" matches type=%i and perm=%i ...", Tcl_GetString(path), types->type, types->perm);
d80c88cee0 2019-09-16 640: } else {
d80c88cee0 2019-09-16 641: XVFS_DEBUG_PRINTF("Asked to verify the existence \"%s\" ...", Tcl_GetString(path));
d80c88cee0 2019-09-16 642: }
d80c88cee0 2019-09-16 643:
5583d77f1c 2019-09-14 644: statRetVal = xvfs_tclfs_stat(path, &fileInfo, instanceInfo);
5583d77f1c 2019-09-14 645: if (statRetVal != 0) {
d80c88cee0 2019-09-16 646: XVFS_DEBUG_PUTS("... no (cannot stat)");
d80c88cee0 2019-09-16 647:
d80c88cee0 2019-09-16 648: XVFS_DEBUG_LEAVE;
5583d77f1c 2019-09-14 649: return(0);
5583d77f1c 2019-09-14 650: }
5583d77f1c 2019-09-14 651:
5583d77f1c 2019-09-14 652: if (!types) {
d80c88cee0 2019-09-16 653: XVFS_DEBUG_PUTS("... yes");
d80c88cee0 2019-09-16 654:
d80c88cee0 2019-09-16 655: XVFS_DEBUG_LEAVE;
5583d77f1c 2019-09-14 656: return(1);
5583d77f1c 2019-09-14 657: }
5583d77f1c 2019-09-14 658:
5583d77f1c 2019-09-14 659: if (types->perm != TCL_GLOB_PERM_RONLY) {
12ff77016f 2019-09-14 660: if (types->perm & (TCL_GLOB_PERM_W | TCL_GLOB_PERM_HIDDEN)) {
d80c88cee0 2019-09-16 661: XVFS_DEBUG_PUTS("... no (checked for writable or hidden, not supported)");
d80c88cee0 2019-09-16 662:
d80c88cee0 2019-09-16 663: XVFS_DEBUG_LEAVE;
5583d77f1c 2019-09-14 664: return(0);
12ff77016f 2019-09-14 665: }
12ff77016f 2019-09-14 666:
12ff77016f 2019-09-14 667: if ((types->perm & TCL_GLOB_PERM_X) == TCL_GLOB_PERM_X) {
12ff77016f 2019-09-14 668: if (!(fileInfo.st_mode & 040000)) {
d80c88cee0 2019-09-16 669: XVFS_DEBUG_PUTS("... no (checked for executable but not a directory)");
d80c88cee0 2019-09-16 670:
d80c88cee0 2019-09-16 671: XVFS_DEBUG_LEAVE;
12ff77016f 2019-09-14 672: return(0);
12ff77016f 2019-09-14 673: }
5583d77f1c 2019-09-14 674: }
5583d77f1c 2019-09-14 675: }
5583d77f1c 2019-09-14 676:
5583d77f1c 2019-09-14 677: if (types->type & (TCL_GLOB_TYPE_BLOCK | TCL_GLOB_TYPE_CHAR | TCL_GLOB_TYPE_PIPE | TCL_GLOB_TYPE_SOCK | TCL_GLOB_TYPE_LINK)) {
d80c88cee0 2019-09-16 678: XVFS_DEBUG_PUTS("... no (checked for block, char, pipe, sock, or link, not supported)");
d80c88cee0 2019-09-16 679:
d80c88cee0 2019-09-16 680: XVFS_DEBUG_LEAVE;
5583d77f1c 2019-09-14 681: return(0);
5583d77f1c 2019-09-14 682: }
5583d77f1c 2019-09-14 683:
5583d77f1c 2019-09-14 684: if ((types->type & TCL_GLOB_TYPE_DIR) == TCL_GLOB_TYPE_DIR) {
5583d77f1c 2019-09-14 685: if (!(fileInfo.st_mode & 040000)) {
d80c88cee0 2019-09-16 686: XVFS_DEBUG_PUTS("... no (checked for directory but not a directory)");
d80c88cee0 2019-09-16 687:
d80c88cee0 2019-09-16 688: XVFS_DEBUG_LEAVE;
5583d77f1c 2019-09-14 689: return(0);
5583d77f1c 2019-09-14 690: }
5583d77f1c 2019-09-14 691: }
5583d77f1c 2019-09-14 692:
5583d77f1c 2019-09-14 693: if ((types->type & TCL_GLOB_TYPE_FILE) == TCL_GLOB_TYPE_FILE) {
5583d77f1c 2019-09-14 694: if (!(fileInfo.st_mode & 0100000)) {
d80c88cee0 2019-09-16 695: XVFS_DEBUG_PUTS("... no (checked for file but not a file)");
d80c88cee0 2019-09-16 696:
d80c88cee0 2019-09-16 697: XVFS_DEBUG_LEAVE;
5583d77f1c 2019-09-14 698: return(0);
5583d77f1c 2019-09-14 699: }
5583d77f1c 2019-09-14 700: }
5583d77f1c 2019-09-14 701:
5583d77f1c 2019-09-14 702: if ((types->type & TCL_GLOB_TYPE_MOUNT) == TCL_GLOB_TYPE_MOUNT) {
d80c88cee0 2019-09-16 703: path = xvfs_absolutePath(path);
5583d77f1c 2019-09-14 704: pathStr = xvfs_relativePath(path, instanceInfo);
5583d77f1c 2019-09-14 705: if (!pathStr) {
d80c88cee0 2019-09-16 706: XVFS_DEBUG_PUTS("... no (checked for mount but not able to resolve path)");
d80c88cee0 2019-09-16 707:
d80c88cee0 2019-09-16 708: Tcl_DecrRefCount(path);
d80c88cee0 2019-09-16 709:
d80c88cee0 2019-09-16 710: XVFS_DEBUG_LEAVE;
5583d77f1c 2019-09-14 711: return(0);
5583d77f1c 2019-09-14 712: }
5583d77f1c 2019-09-14 713:
5583d77f1c 2019-09-14 714: if (strlen(pathStr) != 0) {
d80c88cee0 2019-09-16 715: XVFS_DEBUG_PUTS("... no (checked for mount but not our top-level directory)");
d80c88cee0 2019-09-16 716:
d80c88cee0 2019-09-16 717: Tcl_DecrRefCount(path);
d80c88cee0 2019-09-16 718:
d80c88cee0 2019-09-16 719: XVFS_DEBUG_LEAVE;
5583d77f1c 2019-09-14 720: return(0);
5583d77f1c 2019-09-14 721: }
d80c88cee0 2019-09-16 722:
d80c88cee0 2019-09-16 723: Tcl_DecrRefCount(path);
5583d77f1c 2019-09-14 724: }
5583d77f1c 2019-09-14 725:
d80c88cee0 2019-09-16 726: XVFS_DEBUG_PUTS("... yes");
d80c88cee0 2019-09-16 727:
d80c88cee0 2019-09-16 728: XVFS_DEBUG_LEAVE;
5583d77f1c 2019-09-14 729: return(1);
5583d77f1c 2019-09-14 730: }
5583d77f1c 2019-09-14 731:
5583d77f1c 2019-09-14 732: static int xvfs_tclfs_matchInDir(Tcl_Interp *interp, Tcl_Obj *resultPtr, Tcl_Obj *path, const char *pattern, Tcl_GlobTypeData *types, struct xvfs_tclfs_instance_info *instanceInfo) {
5583d77f1c 2019-09-14 733: const char *pathStr;
5583d77f1c 2019-09-14 734: const char **children, *child;
5583d77f1c 2019-09-14 735: Tcl_WideInt childrenCount, idx;
5583d77f1c 2019-09-14 736: Tcl_Obj *childObj;
5583d77f1c 2019-09-14 737: int tclRetVal;
5583d77f1c 2019-09-14 738:
5583d77f1c 2019-09-14 739: if (pattern == NULL) {
5583d77f1c 2019-09-14 740: if (xvfs_tclfs_verifyType(path, types, instanceInfo)) {
5583d77f1c 2019-09-14 741: return(TCL_OK);
5583d77f1c 2019-09-14 742: }
5583d77f1c 2019-09-14 743:
5583d77f1c 2019-09-14 744: return(TCL_ERROR);
5583d77f1c 2019-09-14 745: }
5583d77f1c 2019-09-14 746:
d80c88cee0 2019-09-16 747: XVFS_DEBUG_ENTER;
d80c88cee0 2019-09-16 748:
d80c88cee0 2019-09-16 749: path = xvfs_absolutePath(path);
d80c88cee0 2019-09-16 750:
d80c88cee0 2019-09-16 751: if (types) {
d80c88cee0 2019-09-16 752: XVFS_DEBUG_PRINTF("Checking for files matching %s in \"%s\" and type=%i and perm=%i ...", pattern, Tcl_GetString(path), types->type, types->perm);
d80c88cee0 2019-09-16 753: } else {
d80c88cee0 2019-09-16 754: XVFS_DEBUG_PRINTF("Checking for files matching %s in \"%s\" ...", pattern, Tcl_GetString(path));
d80c88cee0 2019-09-16 755: }
d80c88cee0 2019-09-16 756:
5583d77f1c 2019-09-14 757: pathStr = xvfs_relativePath(path, instanceInfo);
5583d77f1c 2019-09-14 758: if (!pathStr) {
d80c88cee0 2019-09-16 759: XVFS_DEBUG_PUTS("... error (not in our VFS)");
5583d77f1c 2019-09-14 760:
d80c88cee0 2019-09-16 761: Tcl_DecrRefCount(path);
d80c88cee0 2019-09-16 762:
e786b9e07b 2019-09-16 763: xvfs_setresults_error(interp, XVFS_RV_ERR_ENOENT);
d80c88cee0 2019-09-16 764:
d80c88cee0 2019-09-16 765: XVFS_DEBUG_LEAVE;
d80c88cee0 2019-09-16 766: return(TCL_OK);
5583d77f1c 2019-09-14 767: }
5583d77f1c 2019-09-14 768:
5583d77f1c 2019-09-14 769: childrenCount = 0;
5583d77f1c 2019-09-14 770: children = instanceInfo->fsInfo->getChildrenProc(pathStr, &childrenCount);
5583d77f1c 2019-09-14 771: if (childrenCount < 0) {
cf56967f97 2019-09-17 772: XVFS_DEBUG_PRINTF("... error: %s", xvfs_strerror(childrenCount));
5583d77f1c 2019-09-14 773:
d80c88cee0 2019-09-16 774: Tcl_DecrRefCount(path);
d80c88cee0 2019-09-16 775:
e786b9e07b 2019-09-16 776: xvfs_setresults_error(interp, childrenCount);
d80c88cee0 2019-09-16 777:
d80c88cee0 2019-09-16 778: XVFS_DEBUG_LEAVE;
5583d77f1c 2019-09-14 779: return(TCL_ERROR);
5583d77f1c 2019-09-14 780: }
5583d77f1c 2019-09-14 781:
5583d77f1c 2019-09-14 782: for (idx = 0; idx < childrenCount; idx++) {
5583d77f1c 2019-09-14 783: child = children[idx];
5583d77f1c 2019-09-14 784:
5583d77f1c 2019-09-14 785: if (!Tcl_StringMatch(child, pattern)) {
5583d77f1c 2019-09-14 786: continue;
5583d77f1c 2019-09-14 787: }
5583d77f1c 2019-09-14 788:
5583d77f1c 2019-09-14 789: childObj = Tcl_DuplicateObj(path);
5583d77f1c 2019-09-14 790: Tcl_IncrRefCount(childObj);
5ae034e55e 2019-09-14 791: Tcl_AppendStringsToObj(childObj, "/", child, NULL);
5583d77f1c 2019-09-14 792:
5583d77f1c 2019-09-14 793: if (!xvfs_tclfs_verifyType(childObj, types, instanceInfo)) {
5583d77f1c 2019-09-14 794: Tcl_DecrRefCount(childObj);
5583d77f1c 2019-09-14 795:
5583d77f1c 2019-09-14 796: continue;
5583d77f1c 2019-09-14 797: }
5583d77f1c 2019-09-14 798:
5583d77f1c 2019-09-14 799: tclRetVal = Tcl_ListObjAppendElement(interp, resultPtr, childObj);
5583d77f1c 2019-09-14 800: Tcl_DecrRefCount(childObj);
5583d77f1c 2019-09-14 801:
5583d77f1c 2019-09-14 802: if (tclRetVal != TCL_OK) {
d80c88cee0 2019-09-16 803: XVFS_DEBUG_PUTS("... error (lappend)");
d80c88cee0 2019-09-16 804: Tcl_DecrRefCount(path);
d80c88cee0 2019-09-16 805:
d80c88cee0 2019-09-16 806: XVFS_DEBUG_LEAVE;
5583d77f1c 2019-09-14 807: return(tclRetVal);
5583d77f1c 2019-09-14 808: }
5583d77f1c 2019-09-14 809: }
5583d77f1c 2019-09-14 810:
d80c88cee0 2019-09-16 811: Tcl_DecrRefCount(path);
d80c88cee0 2019-09-16 812:
d80c88cee0 2019-09-16 813: XVFS_DEBUG_PRINTF("... ok (returning items: %s)", Tcl_GetString(resultPtr));
d80c88cee0 2019-09-16 814:
d80c88cee0 2019-09-16 815: XVFS_DEBUG_LEAVE;
5583d77f1c 2019-09-14 816: return(TCL_OK);
d121970301 2019-05-02 817: }
3e44e1def1 2019-05-02 818: #endif /* XVFS_MODE_SERVER || XVFS_MODE_STANDALONE || XVFS_MODE_FLEIXBLE */
d121970301 2019-05-02 819:
88f96696b7 2019-05-03 820: #if defined(XVFS_MODE_STANDALONE) || defined(XVFS_MODE_FLEXIBLE)
d121970301 2019-05-02 821: /*
d121970301 2019-05-02 822: * Tcl_Filesystem handlers for the standalone implementation
d121970301 2019-05-02 823: */
acfc5037c6 2019-05-02 824: static struct xvfs_tclfs_instance_info xvfs_tclfs_standalone_info;
d121970301 2019-05-02 825: static int xvfs_tclfs_standalone_pathInFilesystem(Tcl_Obj *path, ClientData *dataPtr) {
d121970301 2019-05-02 826: return(xvfs_tclfs_pathInFilesystem(path, dataPtr, &xvfs_tclfs_standalone_info));
d121970301 2019-05-02 827: }
d121970301 2019-05-02 828:
d121970301 2019-05-02 829: static int xvfs_tclfs_standalone_stat(Tcl_Obj *path, Tcl_StatBuf *statBuf) {
d121970301 2019-05-02 830: return(xvfs_tclfs_stat(path, statBuf, &xvfs_tclfs_standalone_info));
d121970301 2019-05-02 831: }
d121970301 2019-05-02 832:
12ff77016f 2019-09-14 833: static int xvfs_tclfs_standalone_access(Tcl_Obj *path, int mode) {
12ff77016f 2019-09-14 834: return(xvfs_tclfs_access(path, mode, &xvfs_tclfs_standalone_info));
e5b6962adf 2019-05-02 835: }
e5b6962adf 2019-05-02 836:
d121970301 2019-05-02 837: static Tcl_Channel xvfs_tclfs_standalone_openFileChannel(Tcl_Interp *interp, Tcl_Obj *path, int mode, int permissions) {
d121970301 2019-05-02 838: return(xvfs_tclfs_openFileChannel(interp, path, mode, permissions, &xvfs_tclfs_standalone_info));
5583d77f1c 2019-09-14 839: }
5583d77f1c 2019-09-14 840:
5583d77f1c 2019-09-14 841: static int xvfs_tclfs_standalone_matchInDir(Tcl_Interp *interp, Tcl_Obj *resultPtr, Tcl_Obj *pathPtr, const char *pattern, Tcl_GlobTypeData *types) {
5583d77f1c 2019-09-14 842: return(xvfs_tclfs_matchInDir(interp, resultPtr, pathPtr, pattern, types, &xvfs_tclfs_standalone_info));
e5b6962adf 2019-05-02 843: }
32b55a907b 2019-05-02 844:
32b55a907b 2019-05-02 845: /*
32b55a907b 2019-05-02 846: * There are three (3) modes of operation for Xvfs_Register:
32b55a907b 2019-05-02 847: * 1. standalone -- We register our own Tcl_Filesystem
32b55a907b 2019-05-02 848: * and handle requests under `//xvfs:/<fsName>`
32b55a907b 2019-05-02 849: * 2. client -- A single Tcl_Filesystem is registered for the
32b55a907b 2019-05-02 850: * interp to handle requests under `//xvfs:/` which
32b55a907b 2019-05-02 851: * then dispatches to the appropriate registered
32b55a907b 2019-05-02 852: * handler
32b55a907b 2019-05-02 853: * 3. flexible -- Attempts to find a core Xvfs instance for the
32b55a907b 2019-05-02 854: * process at runtime, if found do #2, otherwise
32b55a907b 2019-05-02 855: * fallback to #1
32b55a907b 2019-05-02 856: *
32b55a907b 2019-05-02 857: */
cb77ecfb24 2019-05-06 858: static Tcl_Filesystem xvfs_tclfs_standalone_fs;
b8cca3a6b4 2019-05-08 859: static int xvfs_standalone_register(Tcl_Interp *interp, struct Xvfs_FSInfo *fsInfo) {
0e05b2a8c7 2019-09-16 860: int tclRet;
d121970301 2019-05-02 861: static int registered = 0;
38bed7cee0 2019-09-13 862:
d121970301 2019-05-02 863: /*
d121970301 2019-05-02 864: * Ensure this instance is not already registered
d121970301 2019-05-02 865: */
d121970301 2019-05-02 866: if (registered) {
d121970301 2019-05-02 867: return(TCL_OK);
d121970301 2019-05-02 868: }
d121970301 2019-05-02 869: registered = 1;
d121970301 2019-05-02 870:
e5b6962adf 2019-05-02 871: /*
e5b6962adf 2019-05-02 872: * In standalone mode, we only support the same protocol we are
e5b6962adf 2019-05-02 873: * compiling for.
e5b6962adf 2019-05-02 874: */
e5b6962adf 2019-05-02 875: if (fsInfo->protocolVersion != XVFS_PROTOCOL_VERSION) {
e5b6962adf 2019-05-02 876: if (interp) {
e5b6962adf 2019-05-02 877: Tcl_SetResult(interp, "Protocol mismatch", NULL);
e5b6962adf 2019-05-02 878: }
e5b6962adf 2019-05-02 879: return(TCL_ERROR);
e5b6962adf 2019-05-02 880: }
38bed7cee0 2019-09-13 881:
0e05b2a8c7 2019-09-16 882: xvfs_tclfs_standalone_fs.typeName = "xvfsInstance";
cb77ecfb24 2019-05-06 883: xvfs_tclfs_standalone_fs.structureLength = sizeof(xvfs_tclfs_standalone_fs);
cb77ecfb24 2019-05-06 884: xvfs_tclfs_standalone_fs.version = TCL_FILESYSTEM_VERSION_1;
cb77ecfb24 2019-05-06 885: xvfs_tclfs_standalone_fs.pathInFilesystemProc = xvfs_tclfs_standalone_pathInFilesystem;
cb77ecfb24 2019-05-06 886: xvfs_tclfs_standalone_fs.dupInternalRepProc = NULL;
cb77ecfb24 2019-05-06 887: xvfs_tclfs_standalone_fs.freeInternalRepProc = NULL;
cb77ecfb24 2019-05-06 888: xvfs_tclfs_standalone_fs.internalToNormalizedProc = NULL;
cb77ecfb24 2019-05-06 889: xvfs_tclfs_standalone_fs.createInternalRepProc = NULL;
cb77ecfb24 2019-05-06 890: xvfs_tclfs_standalone_fs.normalizePathProc = NULL;
cb77ecfb24 2019-05-06 891: xvfs_tclfs_standalone_fs.filesystemPathTypeProc = NULL;
cb77ecfb24 2019-05-06 892: xvfs_tclfs_standalone_fs.filesystemSeparatorProc = NULL;
cb77ecfb24 2019-05-06 893: xvfs_tclfs_standalone_fs.statProc = xvfs_tclfs_standalone_stat;
12ff77016f 2019-09-14 894: xvfs_tclfs_standalone_fs.accessProc = xvfs_tclfs_standalone_access;
cb77ecfb24 2019-05-06 895: xvfs_tclfs_standalone_fs.openFileChannelProc = xvfs_tclfs_standalone_openFileChannel;
5583d77f1c 2019-09-14 896: xvfs_tclfs_standalone_fs.matchInDirectoryProc = xvfs_tclfs_standalone_matchInDir;
cb77ecfb24 2019-05-06 897: xvfs_tclfs_standalone_fs.utimeProc = NULL;
cb77ecfb24 2019-05-06 898: xvfs_tclfs_standalone_fs.linkProc = NULL;
d80c88cee0 2019-09-16 899: xvfs_tclfs_standalone_fs.listVolumesProc = NULL;
cb77ecfb24 2019-05-06 900: xvfs_tclfs_standalone_fs.fileAttrStringsProc = NULL;
cb77ecfb24 2019-05-06 901: xvfs_tclfs_standalone_fs.fileAttrsGetProc = NULL;
cb77ecfb24 2019-05-06 902: xvfs_tclfs_standalone_fs.fileAttrsSetProc = NULL;
cb77ecfb24 2019-05-06 903: xvfs_tclfs_standalone_fs.createDirectoryProc = NULL;
cb77ecfb24 2019-05-06 904: xvfs_tclfs_standalone_fs.removeDirectoryProc = NULL;
cb77ecfb24 2019-05-06 905: xvfs_tclfs_standalone_fs.deleteFileProc = NULL;
cb77ecfb24 2019-05-06 906: xvfs_tclfs_standalone_fs.copyFileProc = NULL;
cb77ecfb24 2019-05-06 907: xvfs_tclfs_standalone_fs.renameFileProc = NULL;
cb77ecfb24 2019-05-06 908: xvfs_tclfs_standalone_fs.copyDirectoryProc = NULL;
cb77ecfb24 2019-05-06 909: xvfs_tclfs_standalone_fs.lstatProc = NULL;
cb77ecfb24 2019-05-06 910: xvfs_tclfs_standalone_fs.loadFileProc = NULL;
cb77ecfb24 2019-05-06 911: xvfs_tclfs_standalone_fs.getCwdProc = NULL;
cb77ecfb24 2019-05-06 912: xvfs_tclfs_standalone_fs.chdirProc = NULL;
d121970301 2019-05-02 913:
d121970301 2019-05-02 914: xvfs_tclfs_standalone_info.fsInfo = fsInfo;
d121970301 2019-05-02 915: xvfs_tclfs_standalone_info.mountpoint = Tcl_NewObj();
5ae034e55e 2019-09-14 916:
5ae034e55e 2019-09-14 917: Tcl_IncrRefCount(xvfs_tclfs_standalone_info.mountpoint);
d121970301 2019-05-02 918: Tcl_AppendStringsToObj(xvfs_tclfs_standalone_info.mountpoint, XVFS_ROOT_MOUNTPOINT, fsInfo->name, NULL);
5ae034e55e 2019-09-14 919:
0e05b2a8c7 2019-09-16 920: tclRet = Tcl_FSRegister(NULL, &xvfs_tclfs_standalone_fs);
0e05b2a8c7 2019-09-16 921: if (tclRet != TCL_OK) {
5ae034e55e 2019-09-14 922: Tcl_DecrRefCount(xvfs_tclfs_standalone_info.mountpoint);
38bed7cee0 2019-09-13 923:
9bcf758fef 2019-05-08 924: if (interp) {
9bcf758fef 2019-05-08 925: Tcl_SetResult(interp, "Tcl_FSRegister() failed", NULL);
9bcf758fef 2019-05-08 926: }
38bed7cee0 2019-09-13 927:
0e05b2a8c7 2019-09-16 928: return(tclRet);
9bcf758fef 2019-05-08 929: }
38bed7cee0 2019-09-13 930:
38bed7cee0 2019-09-13 931: xvfs_tclfs_prepareChannelType();
38bed7cee0 2019-09-13 932:
9bcf758fef 2019-05-08 933: return(TCL_OK);
9bcf758fef 2019-05-08 934: }
d92ba3d36d 2019-05-08 935: #endif /* XVFS_MODE_STANDALONE || XVFS_MODE_FLEXIBLE */
9bcf758fef 2019-05-08 936:
9bcf758fef 2019-05-08 937: #if defined(XVFS_MODE_FLEXIBLE)
b8cca3a6b4 2019-05-08 938: static int xvfs_flexible_register(Tcl_Interp *interp, struct Xvfs_FSInfo *fsInfo) {
9bcf758fef 2019-05-08 939: ClientData fsHandlerDataRaw;
9bcf758fef 2019-05-08 940: struct xvfs_tclfs_server_info *fsHandlerData;
9bcf758fef 2019-05-08 941: const Tcl_Filesystem *fsHandler;
9bcf758fef 2019-05-08 942: int (*xvfs_register)(Tcl_Interp *interp, struct Xvfs_FSInfo *fsInfo);
9bcf758fef 2019-05-08 943: Tcl_Obj *rootPathObj;
9bcf758fef 2019-05-08 944:
f1d16a3958 2019-09-17 945: XVFS_DEBUG_ENTER;
f1d16a3958 2019-09-17 946:
9bcf758fef 2019-05-08 947: xvfs_register = &xvfs_standalone_register;
9bcf758fef 2019-05-08 948:
9bcf758fef 2019-05-08 949: rootPathObj = Tcl_NewStringObj(XVFS_ROOT_MOUNTPOINT, -1);
9bcf758fef 2019-05-08 950: if (!rootPathObj) {
f1d16a3958 2019-09-17 951: XVFS_DEBUG_LEAVE;
f1d16a3958 2019-09-17 952:
9bcf758fef 2019-05-08 953: return(xvfs_register(interp, fsInfo));
9bcf758fef 2019-05-08 954: }
9bcf758fef 2019-05-08 955:
9bcf758fef 2019-05-08 956: Tcl_IncrRefCount(rootPathObj);
9bcf758fef 2019-05-08 957: fsHandler = Tcl_FSGetFileSystemForPath(rootPathObj);
9bcf758fef 2019-05-08 958: Tcl_DecrRefCount(rootPathObj);
9bcf758fef 2019-05-08 959:
9bcf758fef 2019-05-08 960: if (!fsHandler) {
f1d16a3958 2019-09-17 961: XVFS_DEBUG_LEAVE;
f1d16a3958 2019-09-17 962:
9bcf758fef 2019-05-08 963: return(xvfs_register(interp, fsInfo));
9bcf758fef 2019-05-08 964: }
9bcf758fef 2019-05-08 965:
9bcf758fef 2019-05-08 966: fsHandlerDataRaw = Tcl_FSData(fsHandler);
9bcf758fef 2019-05-08 967: if (!fsHandlerDataRaw) {
f1d16a3958 2019-09-17 968: XVFS_DEBUG_LEAVE;
f1d16a3958 2019-09-17 969:
9bcf758fef 2019-05-08 970: return(xvfs_register(interp, fsInfo));
9bcf758fef 2019-05-08 971: }
9bcf758fef 2019-05-08 972:
9bcf758fef 2019-05-08 973: fsHandlerData = (struct xvfs_tclfs_server_info *) fsHandlerDataRaw;
9bcf758fef 2019-05-08 974:
9bcf758fef 2019-05-08 975: /*
9bcf758fef 2019-05-08 976: * XXX:TODO: What is the chance that the handler for //xvfs:/ hold
b586d5b0a1 2019-05-08 977: * client data smaller than XVFS_INTERNAL_SERVER_MAGIC_LEN ?
9bcf758fef 2019-05-08 978: */
b586d5b0a1 2019-05-08 979: if (memcmp(fsHandlerData->magic, XVFS_INTERNAL_SERVER_MAGIC, sizeof(fsHandlerData->magic)) == 0) {
f1d16a3958 2019-09-17 980: XVFS_DEBUG_PUTS("Found a server handler");
9bcf758fef 2019-05-08 981: xvfs_register = fsHandlerData->registerProc;
9bcf758fef 2019-05-08 982: }
f1d16a3958 2019-09-17 983:
f1d16a3958 2019-09-17 984: XVFS_DEBUG_LEAVE;
d92ba3d36d 2019-05-08 985:
9bcf758fef 2019-05-08 986: return(xvfs_register(interp, fsInfo));
9bcf758fef 2019-05-08 987: }
d92ba3d36d 2019-05-08 988: #endif /* XVFS_MODE_FLEXIBLE */
9bcf758fef 2019-05-08 989:
9bcf758fef 2019-05-08 990: #if defined(XVFS_MODE_SERVER)
0e05b2a8c7 2019-09-16 991: static Tcl_Filesystem xvfs_tclfs_dispatch_fs;
0e05b2a8c7 2019-09-16 992: static Tcl_HashTable xvfs_tclfs_dispatch_map;
f1d16a3958 2019-09-17 993: static struct xvfs_tclfs_server_info xvfs_tclfs_dispatch_fsdata;
0e05b2a8c7 2019-09-16 994:
a101629cc6 2019-09-17 995: static int xvfs_tclfs_dispatch_pathInFS(Tcl_Obj *path, ClientData *dataPtr) {
0e05b2a8c7 2019-09-16 996: const char *pathStr, *rootStr;
0e05b2a8c7 2019-09-16 997: int pathLen, rootLen;
0e05b2a8c7 2019-09-16 998:
0e05b2a8c7 2019-09-16 999: XVFS_DEBUG_ENTER;
0e05b2a8c7 2019-09-16 1000:
f1d16a3958 2019-09-17 1001: XVFS_DEBUG_PRINTF("Verifying that \"%s\" belongs in XVFS ...", Tcl_GetString(path));
4221e5dcbc 2019-09-18 1002:
4221e5dcbc 2019-09-18 1003: path = xvfs_absolutePath(path);
4221e5dcbc 2019-09-18 1004:
0e05b2a8c7 2019-09-16 1005: rootStr = XVFS_ROOT_MOUNTPOINT;
0e05b2a8c7 2019-09-16 1006: rootLen = strlen(XVFS_ROOT_MOUNTPOINT);
0e05b2a8c7 2019-09-16 1007:
0e05b2a8c7 2019-09-16 1008: pathStr = Tcl_GetStringFromObj(path, &pathLen);
0e05b2a8c7 2019-09-16 1009:
0e05b2a8c7 2019-09-16 1010: if (pathLen < rootLen) {
4221e5dcbc 2019-09-18 1011: Tcl_DecrRefCount(path);
4221e5dcbc 2019-09-18 1012:
0e05b2a8c7 2019-09-16 1013: XVFS_DEBUG_PUTS("... failed (length too short)");
0e05b2a8c7 2019-09-16 1014: XVFS_DEBUG_LEAVE;
f1d16a3958 2019-09-17 1015: return(-1);
0e05b2a8c7 2019-09-16 1016: }
0e05b2a8c7 2019-09-16 1017:
0e05b2a8c7 2019-09-16 1018: if (memcmp(pathStr, rootStr, rootLen) != 0) {
4221e5dcbc 2019-09-18 1019: Tcl_DecrRefCount(path);
4221e5dcbc 2019-09-18 1020:
0e05b2a8c7 2019-09-16 1021: XVFS_DEBUG_PUTS("... failed (incorrect prefix)");
0e05b2a8c7 2019-09-16 1022: XVFS_DEBUG_LEAVE;
f1d16a3958 2019-09-17 1023: return(-1);
f1d16a3958 2019-09-17 1024: }
4221e5dcbc 2019-09-18 1025:
4221e5dcbc 2019-09-18 1026: Tcl_DecrRefCount(path);
f1d16a3958 2019-09-17 1027:
f1d16a3958 2019-09-17 1028: XVFS_DEBUG_PUTS("... yes");
f1d16a3958 2019-09-17 1029:
f1d16a3958 2019-09-17 1030: XVFS_DEBUG_LEAVE;
f1d16a3958 2019-09-17 1031:
f1d16a3958 2019-09-17 1032: return(TCL_OK);
f1d16a3958 2019-09-17 1033: }
f1d16a3958 2019-09-17 1034:
f1d16a3958 2019-09-17 1035: static struct xvfs_tclfs_instance_info *xvfs_tclfs_dispatch_pathToInfo(Tcl_Obj *path) {
f1d16a3958 2019-09-17 1036: Tcl_HashEntry *mapEntry;
f1d16a3958 2019-09-17 1037: struct xvfs_tclfs_instance_info *retval;
f1d16a3958 2019-09-17 1038: int rootLen;
f1d16a3958 2019-09-17 1039: char *pathStr, *fsName, *fsNameEnds, origSep;
f1d16a3958 2019-09-17 1040:
f1d16a3958 2019-09-17 1041: XVFS_DEBUG_ENTER;
f1d16a3958 2019-09-17 1042:
4221e5dcbc 2019-09-18 1043: path = xvfs_absolutePath(path);
4221e5dcbc 2019-09-18 1044:
a101629cc6 2019-09-17 1045: if (xvfs_tclfs_dispatch_pathInFS(path, NULL) != TCL_OK) {
4221e5dcbc 2019-09-18 1046: Tcl_DecrRefCount(path);
4221e5dcbc 2019-09-18 1047:
f1d16a3958 2019-09-17 1048: XVFS_DEBUG_LEAVE;
f1d16a3958 2019-09-17 1049:
0e05b2a8c7 2019-09-16 1050: return(NULL);
0e05b2a8c7 2019-09-16 1051: }
f1d16a3958 2019-09-17 1052:
f1d16a3958 2019-09-17 1053: rootLen = strlen(XVFS_ROOT_MOUNTPOINT);
f1d16a3958 2019-09-17 1054: pathStr = Tcl_GetString(path);
0e05b2a8c7 2019-09-16 1055:
0e05b2a8c7 2019-09-16 1056: fsName = ((char *) pathStr) + rootLen;
0e05b2a8c7 2019-09-16 1057:
0e05b2a8c7 2019-09-16 1058: fsNameEnds = strchr(fsName, '/');
0e05b2a8c7 2019-09-16 1059: if (fsNameEnds) {
0e05b2a8c7 2019-09-16 1060: origSep = *fsNameEnds;
0e05b2a8c7 2019-09-16 1061: *fsNameEnds = '\0';
0e05b2a8c7 2019-09-16 1062: }
0e05b2a8c7 2019-09-16 1063:
0e05b2a8c7 2019-09-16 1064: XVFS_DEBUG_PRINTF("... fsName = %s...", fsName);
0e05b2a8c7 2019-09-16 1065:
0e05b2a8c7 2019-09-16 1066: mapEntry = Tcl_FindHashEntry(&xvfs_tclfs_dispatch_map, fsName);
0e05b2a8c7 2019-09-16 1067:
0e05b2a8c7 2019-09-16 1068: if (fsNameEnds) {
0e05b2a8c7 2019-09-16 1069: *fsNameEnds = origSep;
0e05b2a8c7 2019-09-16 1070: }
0e05b2a8c7 2019-09-16 1071:
0e05b2a8c7 2019-09-16 1072: if (mapEntry) {
0e05b2a8c7 2019-09-16 1073: retval = (struct xvfs_tclfs_instance_info *) Tcl_GetHashValue(mapEntry);
0e05b2a8c7 2019-09-16 1074: XVFS_DEBUG_PRINTF("... found a registered filesystem: %p", retval);
0e05b2a8c7 2019-09-16 1075: } else {
0e05b2a8c7 2019-09-16 1076: retval = NULL;
0e05b2a8c7 2019-09-16 1077: XVFS_DEBUG_PUTS("... found no registered filesystem.");
0e05b2a8c7 2019-09-16 1078: }
4221e5dcbc 2019-09-18 1079:
4221e5dcbc 2019-09-18 1080: Tcl_DecrRefCount(path);
d058c6c7f8 2019-09-17 1081:
0e05b2a8c7 2019-09-16 1082: XVFS_DEBUG_LEAVE;
0e05b2a8c7 2019-09-16 1083: return(retval);
d058c6c7f8 2019-09-17 1084:
d058c6c7f8 2019-09-17 1085: /*
d058c6c7f8 2019-09-17 1086: * UNREACH: We do no need the more specific check because we
d058c6c7f8 2019-09-17 1087: * claim everything under the root, but we want to suppress
d058c6c7f8 2019-09-17 1088: * a warning about it not being used.
d058c6c7f8 2019-09-17 1089: */
d058c6c7f8 2019-09-17 1090: xvfs_tclfs_pathInFilesystem(NULL, NULL, NULL);
d058c6c7f8 2019-09-17 1091: return(NULL);
0e05b2a8c7 2019-09-16 1092: }
0e05b2a8c7 2019-09-16 1093:
0e05b2a8c7 2019-09-16 1094: static int xvfs_tclfs_dispatch_stat(Tcl_Obj *path, Tcl_StatBuf *statBuf) {
0e05b2a8c7 2019-09-16 1095: struct xvfs_tclfs_instance_info *instanceInfo;
0e05b2a8c7 2019-09-16 1096:
f1d16a3958 2019-09-17 1097: instanceInfo = xvfs_tclfs_dispatch_pathToInfo(path);
0e05b2a8c7 2019-09-16 1098: if (!instanceInfo) {
f1d16a3958 2019-09-17 1099: Tcl_SetErrno(xvfs_errorToErrno(XVFS_RV_ERR_ENOENT));
f1d16a3958 2019-09-17 1100:
f1d16a3958 2019-09-17 1101: return(-1);
0e05b2a8c7 2019-09-16 1102: }
0e05b2a8c7 2019-09-16 1103:
0e05b2a8c7 2019-09-16 1104: return(xvfs_tclfs_stat(path, statBuf, instanceInfo));
0e05b2a8c7 2019-09-16 1105: }
0e05b2a8c7 2019-09-16 1106:
0e05b2a8c7 2019-09-16 1107: static int xvfs_tclfs_dispatch_access(Tcl_Obj *path, int mode) {
0e05b2a8c7 2019-09-16 1108: struct xvfs_tclfs_instance_info *instanceInfo;
0e05b2a8c7 2019-09-16 1109:
f1d16a3958 2019-09-17 1110: instanceInfo = xvfs_tclfs_dispatch_pathToInfo(path);
0e05b2a8c7 2019-09-16 1111: if (!instanceInfo) {
0e05b2a8c7 2019-09-16 1112: return(-1);
0e05b2a8c7 2019-09-16 1113: }
0e05b2a8c7 2019-09-16 1114:
0e05b2a8c7 2019-09-16 1115: return(xvfs_tclfs_access(path, mode, instanceInfo));
0e05b2a8c7 2019-09-16 1116: }
0e05b2a8c7 2019-09-16 1117:
0e05b2a8c7 2019-09-16 1118: static Tcl_Channel xvfs_tclfs_dispatch_openFileChannel(Tcl_Interp *interp, Tcl_Obj *path, int mode, int permissions) {
0e05b2a8c7 2019-09-16 1119: struct xvfs_tclfs_instance_info *instanceInfo;
0e05b2a8c7 2019-09-16 1120:
f1d16a3958 2019-09-17 1121: instanceInfo = xvfs_tclfs_dispatch_pathToInfo(path);
0e05b2a8c7 2019-09-16 1122: if (!instanceInfo) {
0e05b2a8c7 2019-09-16 1123: return(NULL);
0e05b2a8c7 2019-09-16 1124: }
0e05b2a8c7 2019-09-16 1125:
0e05b2a8c7 2019-09-16 1126: return(xvfs_tclfs_openFileChannel(interp, path, mode, permissions, instanceInfo));
0e05b2a8c7 2019-09-16 1127: }
0e05b2a8c7 2019-09-16 1128:
0e05b2a8c7 2019-09-16 1129: static int xvfs_tclfs_dispatch_matchInDir(Tcl_Interp *interp, Tcl_Obj *resultPtr, Tcl_Obj *pathPtr, const char *pattern, Tcl_GlobTypeData *types) {
0e05b2a8c7 2019-09-16 1130: struct xvfs_tclfs_instance_info *instanceInfo;
0e05b2a8c7 2019-09-16 1131:
f1d16a3958 2019-09-17 1132: instanceInfo = xvfs_tclfs_dispatch_pathToInfo(pathPtr);
0e05b2a8c7 2019-09-16 1133: if (!instanceInfo) {
0e05b2a8c7 2019-09-16 1134: return(TCL_ERROR);
0e05b2a8c7 2019-09-16 1135: }
0e05b2a8c7 2019-09-16 1136:
0e05b2a8c7 2019-09-16 1137: return(xvfs_tclfs_matchInDir(interp, resultPtr, pathPtr, pattern, types, instanceInfo));
0e05b2a8c7 2019-09-16 1138: }
0e05b2a8c7 2019-09-16 1139:
f1d16a3958 2019-09-17 1140: int Xvfs_Init(Tcl_Interp *interp) {
0e05b2a8c7 2019-09-16 1141: static int registered = 0;
0e05b2a8c7 2019-09-16 1142: int tclRet;
a101629cc6 2019-09-17 1143: #ifdef USE_TCL_STUBS
a101629cc6 2019-09-17 1144: const char *tclInitStubs_ret;
a101629cc6 2019-09-17 1145: #endif
0e05b2a8c7 2019-09-16 1146:
0e05b2a8c7 2019-09-16 1147: /* XXX:TODO: Make this thread-safe */
0e05b2a8c7 2019-09-16 1148: if (registered) {
0e05b2a8c7 2019-09-16 1149: return(TCL_OK);
0e05b2a8c7 2019-09-16 1150: }
0e05b2a8c7 2019-09-16 1151: registered = 1;
a4f7828c1d 2019-09-17 1152:
a4f7828c1d 2019-09-17 1153: #ifdef USE_TCL_STUBS
a4f7828c1d 2019-09-17 1154: /* Initialize Stubs */
a4f7828c1d 2019-09-17 1155: tclInitStubs_ret = Tcl_InitStubs(interp, TCL_PATCH_LEVEL, 0);
a4f7828c1d 2019-09-17 1156: if (!tclInitStubs_ret) {
a4f7828c1d 2019-09-17 1157: return(TCL_ERROR);
a4f7828c1d 2019-09-17 1158: }
a4f7828c1d 2019-09-17 1159: #endif
a101629cc6 2019-09-17 1160:
0e05b2a8c7 2019-09-16 1161: xvfs_tclfs_dispatch_fs.typeName = "xvfsDispatch";
0e05b2a8c7 2019-09-16 1162: xvfs_tclfs_dispatch_fs.structureLength = sizeof(xvfs_tclfs_dispatch_fs);
0e05b2a8c7 2019-09-16 1163: xvfs_tclfs_dispatch_fs.version = TCL_FILESYSTEM_VERSION_1;
a101629cc6 2019-09-17 1164: xvfs_tclfs_dispatch_fs.pathInFilesystemProc = xvfs_tclfs_dispatch_pathInFS;
0e05b2a8c7 2019-09-16 1165: xvfs_tclfs_dispatch_fs.dupInternalRepProc = NULL;
0e05b2a8c7 2019-09-16 1166: xvfs_tclfs_dispatch_fs.freeInternalRepProc = NULL;
0e05b2a8c7 2019-09-16 1167: xvfs_tclfs_dispatch_fs.internalToNormalizedProc = NULL;
0e05b2a8c7 2019-09-16 1168: xvfs_tclfs_dispatch_fs.createInternalRepProc = NULL;
0e05b2a8c7 2019-09-16 1169: xvfs_tclfs_dispatch_fs.normalizePathProc = NULL;
0e05b2a8c7 2019-09-16 1170: xvfs_tclfs_dispatch_fs.filesystemPathTypeProc = NULL;
0e05b2a8c7 2019-09-16 1171: xvfs_tclfs_dispatch_fs.filesystemSeparatorProc = NULL;
0e05b2a8c7 2019-09-16 1172: xvfs_tclfs_dispatch_fs.statProc = xvfs_tclfs_dispatch_stat;
0e05b2a8c7 2019-09-16 1173: xvfs_tclfs_dispatch_fs.accessProc = xvfs_tclfs_dispatch_access;
0e05b2a8c7 2019-09-16 1174: xvfs_tclfs_dispatch_fs.openFileChannelProc = xvfs_tclfs_dispatch_openFileChannel;
0e05b2a8c7 2019-09-16 1175: xvfs_tclfs_dispatch_fs.matchInDirectoryProc = xvfs_tclfs_dispatch_matchInDir;
0e05b2a8c7 2019-09-16 1176: xvfs_tclfs_dispatch_fs.utimeProc = NULL;
0e05b2a8c7 2019-09-16 1177: xvfs_tclfs_dispatch_fs.linkProc = NULL;
0e05b2a8c7 2019-09-16 1178: xvfs_tclfs_dispatch_fs.listVolumesProc = NULL;
0e05b2a8c7 2019-09-16 1179: xvfs_tclfs_dispatch_fs.fileAttrStringsProc = NULL;
0e05b2a8c7 2019-09-16 1180: xvfs_tclfs_dispatch_fs.fileAttrsGetProc = NULL;
0e05b2a8c7 2019-09-16 1181: xvfs_tclfs_dispatch_fs.fileAttrsSetProc = NULL;
0e05b2a8c7 2019-09-16 1182: xvfs_tclfs_dispatch_fs.createDirectoryProc = NULL;
0e05b2a8c7 2019-09-16 1183: xvfs_tclfs_dispatch_fs.removeDirectoryProc = NULL;
0e05b2a8c7 2019-09-16 1184: xvfs_tclfs_dispatch_fs.deleteFileProc = NULL;
0e05b2a8c7 2019-09-16 1185: xvfs_tclfs_dispatch_fs.copyFileProc = NULL;
0e05b2a8c7 2019-09-16 1186: xvfs_tclfs_dispatch_fs.renameFileProc = NULL;
0e05b2a8c7 2019-09-16 1187: xvfs_tclfs_dispatch_fs.copyDirectoryProc = NULL;
0e05b2a8c7 2019-09-16 1188: xvfs_tclfs_dispatch_fs.lstatProc = NULL;
0e05b2a8c7 2019-09-16 1189: xvfs_tclfs_dispatch_fs.loadFileProc = NULL;
0e05b2a8c7 2019-09-16 1190: xvfs_tclfs_dispatch_fs.getCwdProc = NULL;
0e05b2a8c7 2019-09-16 1191: xvfs_tclfs_dispatch_fs.chdirProc = NULL;
0e05b2a8c7 2019-09-16 1192:
f1d16a3958 2019-09-17 1193: memcpy(xvfs_tclfs_dispatch_fsdata.magic, XVFS_INTERNAL_SERVER_MAGIC, XVFS_INTERNAL_SERVER_MAGIC_LEN);
f1d16a3958 2019-09-17 1194: xvfs_tclfs_dispatch_fsdata.registerProc = Xvfs_Register;
f1d16a3958 2019-09-17 1195:
f1d16a3958 2019-09-17 1196: tclRet = Tcl_FSRegister((ClientData) &xvfs_tclfs_dispatch_fsdata, &xvfs_tclfs_dispatch_fs);
0e05b2a8c7 2019-09-16 1197: if (tclRet != TCL_OK) {
0e05b2a8c7 2019-09-16 1198: if (interp) {
0e05b2a8c7 2019-09-16 1199: Tcl_SetResult(interp, "Tcl_FSRegister() failed", NULL);
0e05b2a8c7 2019-09-16 1200: }
0e05b2a8c7 2019-09-16 1201:
0e05b2a8c7 2019-09-16 1202: return(tclRet);
0e05b2a8c7 2019-09-16 1203: }
0e05b2a8c7 2019-09-16 1204:
0e05b2a8c7 2019-09-16 1205: /*
0e05b2a8c7 2019-09-16 1206: * Initialize the channel type we will use for I/O
0e05b2a8c7 2019-09-16 1207: */
0e05b2a8c7 2019-09-16 1208: xvfs_tclfs_prepareChannelType();
0e05b2a8c7 2019-09-16 1209:
0e05b2a8c7 2019-09-16 1210: /*
0e05b2a8c7 2019-09-16 1211: * Initialize the map to lookup paths to registered
0e05b2a8c7 2019-09-16 1212: * filesystems
0e05b2a8c7 2019-09-16 1213: */
0e05b2a8c7 2019-09-16 1214: Tcl_InitHashTable(&xvfs_tclfs_dispatch_map, TCL_STRING_KEYS);
0e05b2a8c7 2019-09-16 1215:
0e05b2a8c7 2019-09-16 1216: return(TCL_OK);
0e05b2a8c7 2019-09-16 1217: }
0e05b2a8c7 2019-09-16 1218:
d92ba3d36d 2019-05-08 1219: int Xvfs_Register(Tcl_Interp *interp, struct Xvfs_FSInfo *fsInfo) {
0e05b2a8c7 2019-09-16 1220: Tcl_HashEntry *mapEntry;
0e05b2a8c7 2019-09-16 1221: struct xvfs_tclfs_instance_info *instanceInfo;
0e05b2a8c7 2019-09-16 1222: int dispatchInitRet;
0e05b2a8c7 2019-09-16 1223: int new;
0e05b2a8c7 2019-09-16 1224:
f1d16a3958 2019-09-17 1225: dispatchInitRet = Xvfs_Init(interp);
0e05b2a8c7 2019-09-16 1226: if (dispatchInitRet != TCL_OK) {
0e05b2a8c7 2019-09-16 1227: return(dispatchInitRet);
0e05b2a8c7 2019-09-16 1228: }
0e05b2a8c7 2019-09-16 1229:
0e05b2a8c7 2019-09-16 1230: /*
0e05b2a8c7 2019-09-16 1231: * Verify this is for a protocol we support
0e05b2a8c7 2019-09-16 1232: */
0e05b2a8c7 2019-09-16 1233: if (fsInfo->protocolVersion != XVFS_PROTOCOL_VERSION) {
0e05b2a8c7 2019-09-16 1234: if (interp) {
0e05b2a8c7 2019-09-16 1235: Tcl_SetResult(interp, "Protocol mismatch", NULL);
0e05b2a8c7 2019-09-16 1236: }
0e05b2a8c7 2019-09-16 1237: return(TCL_ERROR);
0e05b2a8c7 2019-09-16 1238: }
0e05b2a8c7 2019-09-16 1239:
0e05b2a8c7 2019-09-16 1240: /*
0e05b2a8c7 2019-09-16 1241: * Create the structure needed
0e05b2a8c7 2019-09-16 1242: */
0e05b2a8c7 2019-09-16 1243: instanceInfo = (struct xvfs_tclfs_instance_info *) Tcl_Alloc(sizeof(*instanceInfo));
0e05b2a8c7 2019-09-16 1244: instanceInfo->fsInfo = fsInfo;
0e05b2a8c7 2019-09-16 1245: instanceInfo->mountpoint = Tcl_ObjPrintf("%s%s", XVFS_ROOT_MOUNTPOINT, fsInfo->name);
0e05b2a8c7 2019-09-16 1246: Tcl_IncrRefCount(instanceInfo->mountpoint);
0e05b2a8c7 2019-09-16 1247:
0e05b2a8c7 2019-09-16 1248: /*
0e05b2a8c7 2019-09-16 1249: * Register a hash table entry for this name
0e05b2a8c7 2019-09-16 1250: */
0e05b2a8c7 2019-09-16 1251: new = 0;
0e05b2a8c7 2019-09-16 1252: mapEntry = Tcl_CreateHashEntry(&xvfs_tclfs_dispatch_map, fsInfo->name, &new);
0e05b2a8c7 2019-09-16 1253: Tcl_SetHashValue(mapEntry, instanceInfo);
0e05b2a8c7 2019-09-16 1254:
0e05b2a8c7 2019-09-16 1255: return(TCL_OK);
d92ba3d36d 2019-05-08 1256: }
d92ba3d36d 2019-05-08 1257: #endif /* XVFS_MODE_SERVER */
5f2895faba 2019-09-17 1258: #undef XVFS_DEBUG_PRINTF
5f2895faba 2019-09-17 1259: #undef XVFS_DEBUG_PUTS
5f2895faba 2019-09-17 1260: #undef XVFS_DEBUG_ENTER
5f2895faba 2019-09-17 1261: #undef XVFS_DEBUG_LEAVE
5f2895faba 2019-09-17 1262: #undef XVFS_INTERNAL_SERVER_MAGIC
5f2895faba 2019-09-17 1263: #undef XVFS_INTERNAL_SERVER_MAGIC_LEN
5f2895faba 2019-09-17 1264: #undef XVFS_ROOT_MOUNTPOINT
717062426a 2020-04-13 1265: #endif /* XVFS_CORE_C_1B4B28D60EBAA11D5FF85642FA7CA22C29E8E817 */