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