69e476dcd5 2019-05-02 1: #include <xvfs-core.h>
d121970301 2019-05-02 2: #include <string.h>
38bed7cee0 2019-09-13 3: #include <sys/stat.h>
38bed7cee0 2019-09-13 4: #include <errno.h>
38bed7cee0 2019-09-13 5: #include <fcntl.h>
69e476dcd5 2019-05-02 6: #include <tcl.h>
d92ba3d36d 2019-05-08 7:
d92ba3d36d 2019-05-08 8: #if defined(XVFS_MODE_FLEXIBLE) || defined(XVFS_MODE_SERVER)
d92ba3d36d 2019-05-08 9: #define XVFS_INTERNAL_SERVER_MAGIC "\xD4\xF3\x05\x96\x25\xCF\xAF\xFE"
d92ba3d36d 2019-05-08 10: #define XVFS_INTERNAL_SERVER_MAGIC_LEN 8
d92ba3d36d 2019-05-08 11:
d92ba3d36d 2019-05-08 12: struct xvfs_tclfs_server_info {
b586d5b0a1 2019-05-08 13: char magic[XVFS_INTERNAL_SERVER_MAGIC_LEN];
d92ba3d36d 2019-05-08 14: int (*registerProc)(Tcl_Interp *interp, struct Xvfs_FSInfo *fsInfo);
d92ba3d36d 2019-05-08 15: };
d92ba3d36d 2019-05-08 16: #endif /* XVFS_MODE_FLEXIBLE || XVFS_MODE_SERVER */
3e44e1def1 2019-05-02 17:
3e44e1def1 2019-05-02 18: #if defined(XVFS_MODE_SERVER) || defined(XVFS_MODE_STANDALONE) || defined(XVFS_MODE_FLEXIBLE)
d121970301 2019-05-02 19: #define XVFS_ROOT_MOUNTPOINT "//xvfs:/"
d121970301 2019-05-02 20:
d121970301 2019-05-02 21: struct xvfs_tclfs_instance_info {
d121970301 2019-05-02 22: struct Xvfs_FSInfo *fsInfo;
d121970301 2019-05-02 23: Tcl_Obj *mountpoint;
d121970301 2019-05-02 24: };
d121970301 2019-05-02 25:
d121970301 2019-05-02 26: /*
d121970301 2019-05-02 27: * Internal Core Utilities
d121970301 2019-05-02 28: */
d121970301 2019-05-02 29: static const char *xvfs_relativePath(Tcl_Obj *path, struct xvfs_tclfs_instance_info *info) {
d121970301 2019-05-02 30: const char *pathStr, *rootStr;
5583d77f1c 2019-09-14 31: const char *pathFinal;
d121970301 2019-05-02 32: int pathLen, rootLen;
38bed7cee0 2019-09-13 33:
d121970301 2019-05-02 34: pathStr = Tcl_GetStringFromObj(path, &pathLen);
d121970301 2019-05-02 35: rootStr = Tcl_GetStringFromObj(info->mountpoint, &rootLen);
38bed7cee0 2019-09-13 36:
d121970301 2019-05-02 37: if (pathLen < rootLen) {
d121970301 2019-05-02 38: return(NULL);
d121970301 2019-05-02 39: }
38bed7cee0 2019-09-13 40:
d121970301 2019-05-02 41: if (memcmp(pathStr, rootStr, rootLen) != 0) {
d121970301 2019-05-02 42: return(NULL);
d121970301 2019-05-02 43: }
38bed7cee0 2019-09-13 44:
d121970301 2019-05-02 45: if (pathLen == rootLen) {
d121970301 2019-05-02 46: return("");
d121970301 2019-05-02 47: }
d121970301 2019-05-02 48:
d121970301 2019-05-02 49: /* XXX:TODO: Should this use the native OS path separator ? */
d121970301 2019-05-02 50: if (pathStr[rootLen] != '/') {
d121970301 2019-05-02 51: return(NULL);
d121970301 2019-05-02 52: }
38bed7cee0 2019-09-13 53:
5583d77f1c 2019-09-14 54: pathFinal = pathStr + rootLen + 1;
5583d77f1c 2019-09-14 55: pathLen -= rootLen + 1;
5583d77f1c 2019-09-14 56:
5583d77f1c 2019-09-14 57: if (pathLen == 1 && memcmp(pathFinal, ".", 1) == 0) {
5583d77f1c 2019-09-14 58: return("");
5583d77f1c 2019-09-14 59: }
5583d77f1c 2019-09-14 60:
5583d77f1c 2019-09-14 61: while (pathLen >= 2 && memcmp(pathFinal, "./", 2) == 0) {
5583d77f1c 2019-09-14 62: pathFinal += 2;
5583d77f1c 2019-09-14 63: pathLen -= 2;
5583d77f1c 2019-09-14 64: }
5583d77f1c 2019-09-14 65:
5583d77f1c 2019-09-14 66: return(pathFinal);
149aa89b7d 2019-09-13 67: }
149aa89b7d 2019-09-13 68:
149aa89b7d 2019-09-13 69: static const char *xvfs_perror(int xvfs_error) {
149aa89b7d 2019-09-13 70: if (xvfs_error >= 0) {
149aa89b7d 2019-09-13 71: return("Not an error");
149aa89b7d 2019-09-13 72: }
149aa89b7d 2019-09-13 73:
149aa89b7d 2019-09-13 74: switch (xvfs_error) {
149aa89b7d 2019-09-13 75: case XVFS_RV_ERR_ENOENT:
149aa89b7d 2019-09-13 76: return("No such file or directory");
149aa89b7d 2019-09-13 77: case XVFS_RV_ERR_EINVAL:
149aa89b7d 2019-09-13 78: return("Invalid argument");
149aa89b7d 2019-09-13 79: case XVFS_RV_ERR_EISDIR:
149aa89b7d 2019-09-13 80: return("Is a directory");
149aa89b7d 2019-09-13 81: case XVFS_RV_ERR_ENOTDIR:
149aa89b7d 2019-09-13 82: return("Not a directory");
149aa89b7d 2019-09-13 83: case XVFS_RV_ERR_EFAULT:
149aa89b7d 2019-09-13 84: return("Bad address");
5583d77f1c 2019-09-14 85: case XVFS_RV_ERR_INTERNAL:
5583d77f1c 2019-09-14 86: return("Internal error");
149aa89b7d 2019-09-13 87: default:
149aa89b7d 2019-09-13 88: return("Unknown error");
149aa89b7d 2019-09-13 89: }
38bed7cee0 2019-09-13 90: }
38bed7cee0 2019-09-13 91:
38bed7cee0 2019-09-13 92: static int xvfs_errorToErrno(int xvfs_error) {
38bed7cee0 2019-09-13 93: if (xvfs_error >= 0) {
38bed7cee0 2019-09-13 94: return(0);
38bed7cee0 2019-09-13 95: }
38bed7cee0 2019-09-13 96:
38bed7cee0 2019-09-13 97: switch (xvfs_error) {
38bed7cee0 2019-09-13 98: case XVFS_RV_ERR_ENOENT:
38bed7cee0 2019-09-13 99: return(ENOENT);
38bed7cee0 2019-09-13 100: case XVFS_RV_ERR_EINVAL:
38bed7cee0 2019-09-13 101: return(EINVAL);
38bed7cee0 2019-09-13 102: case XVFS_RV_ERR_EISDIR:
38bed7cee0 2019-09-13 103: return(EISDIR);
38bed7cee0 2019-09-13 104: case XVFS_RV_ERR_ENOTDIR:
38bed7cee0 2019-09-13 105: return(ENOTDIR);
38bed7cee0 2019-09-13 106: case XVFS_RV_ERR_EFAULT:
38bed7cee0 2019-09-13 107: return(EFAULT);
5583d77f1c 2019-09-14 108: case XVFS_RV_ERR_INTERNAL:
5583d77f1c 2019-09-14 109: return(EINVAL);
38bed7cee0 2019-09-13 110: default:
38bed7cee0 2019-09-13 111: return(ERANGE);
38bed7cee0 2019-09-13 112: }
38bed7cee0 2019-09-13 113: }
38bed7cee0 2019-09-13 114:
38bed7cee0 2019-09-13 115: /*
38bed7cee0 2019-09-13 116: * Xvfs Memory Channel
38bed7cee0 2019-09-13 117: */
38bed7cee0 2019-09-13 118: struct xvfs_tclfs_channel_id {
38bed7cee0 2019-09-13 119: Tcl_Channel channel;
38bed7cee0 2019-09-13 120: struct xvfs_tclfs_instance_info *fsInstanceInfo;
38bed7cee0 2019-09-13 121: Tcl_Obj *path;
38bed7cee0 2019-09-13 122: Tcl_WideInt currentOffset;
38bed7cee0 2019-09-13 123: Tcl_WideInt fileSize;
7d74392642 2019-09-13 124: int eofMarked;
aa08a4a749 2019-09-14 125: int queuedEvents;
aa08a4a749 2019-09-14 126: int closed;
7d74392642 2019-09-13 127: };
7d74392642 2019-09-13 128: struct xvfs_tclfs_channel_event {
7d74392642 2019-09-13 129: Tcl_Event tcl;
7d74392642 2019-09-13 130: struct xvfs_tclfs_channel_id *channelInstanceData;
38bed7cee0 2019-09-13 131: };
38bed7cee0 2019-09-13 132: static Tcl_ChannelType xvfs_tclfs_channelType;
38bed7cee0 2019-09-13 133:
38bed7cee0 2019-09-13 134: static Tcl_Channel xvfs_tclfs_openChannel(Tcl_Obj *path, struct xvfs_tclfs_instance_info *instanceInfo) {
38bed7cee0 2019-09-13 135: struct xvfs_tclfs_channel_id *channelInstanceData;
38bed7cee0 2019-09-13 136: Tcl_Channel channel;
38bed7cee0 2019-09-13 137: Tcl_StatBuf fileInfo;
7d74392642 2019-09-13 138: Tcl_Obj *channelName;
38bed7cee0 2019-09-13 139: int statRet;
38bed7cee0 2019-09-13 140:
38bed7cee0 2019-09-13 141: statRet = instanceInfo->fsInfo->getStatProc(Tcl_GetString(path), &fileInfo);
38bed7cee0 2019-09-13 142: if (statRet < 0) {
38bed7cee0 2019-09-13 143: return(NULL);
38bed7cee0 2019-09-13 144: }
38bed7cee0 2019-09-13 145:
38bed7cee0 2019-09-13 146: channelInstanceData = (struct xvfs_tclfs_channel_id *) Tcl_Alloc(sizeof(*channelInstanceData));
38bed7cee0 2019-09-13 147: channelInstanceData->currentOffset = 0;
7d74392642 2019-09-13 148: channelInstanceData->eofMarked = 0;
aa08a4a749 2019-09-14 149: channelInstanceData->queuedEvents = 0;
aa08a4a749 2019-09-14 150: channelInstanceData->closed = 0;
38bed7cee0 2019-09-13 151: channelInstanceData->channel = NULL;
38bed7cee0 2019-09-13 152:
7d74392642 2019-09-13 153: channelName = Tcl_ObjPrintf("xvfs0x%llx", (unsigned long long) channelInstanceData);
7d74392642 2019-09-13 154: if (!channelName) {
7d74392642 2019-09-13 155: Tcl_Free((char *) channelInstanceData);
7d74392642 2019-09-13 156:
7d74392642 2019-09-13 157: return(NULL);
7d74392642 2019-09-13 158: }
7d74392642 2019-09-13 159: Tcl_IncrRefCount(channelName);
7d74392642 2019-09-13 160:
38bed7cee0 2019-09-13 161: channelInstanceData->fsInstanceInfo = instanceInfo;
38bed7cee0 2019-09-13 162: channelInstanceData->fileSize = fileInfo.st_size;
7d74392642 2019-09-13 163: channelInstanceData->path = path;
38bed7cee0 2019-09-13 164: Tcl_IncrRefCount(path);
38bed7cee0 2019-09-13 165:
7d74392642 2019-09-13 166: channel = Tcl_CreateChannel(&xvfs_tclfs_channelType, Tcl_GetString(channelName), channelInstanceData, TCL_READABLE);
7d74392642 2019-09-13 167: Tcl_DecrRefCount(channelName);
38bed7cee0 2019-09-13 168: if (!channel) {
38bed7cee0 2019-09-13 169: Tcl_DecrRefCount(path);
38bed7cee0 2019-09-13 170: Tcl_Free((char *) channelInstanceData);
38bed7cee0 2019-09-13 171:
38bed7cee0 2019-09-13 172: return(NULL);
38bed7cee0 2019-09-13 173: }
38bed7cee0 2019-09-13 174:
38bed7cee0 2019-09-13 175: channelInstanceData->channel = channel;
38bed7cee0 2019-09-13 176:
38bed7cee0 2019-09-13 177: return(channel);
38bed7cee0 2019-09-13 178: }
38bed7cee0 2019-09-13 179:
aa08a4a749 2019-09-14 180: static int xvfs_tclfs_closeChannel(ClientData channelInstanceData_p, Tcl_Interp *interp);
aa08a4a749 2019-09-14 181: static int xvfs_tclfs_closeChannelEvent(Tcl_Event *event_p, int flags) {
aa08a4a749 2019-09-14 182: struct xvfs_tclfs_channel_id *channelInstanceData;
aa08a4a749 2019-09-14 183: struct xvfs_tclfs_channel_event *event;
aa08a4a749 2019-09-14 184:
aa08a4a749 2019-09-14 185: event = (struct xvfs_tclfs_channel_event *) event_p;
aa08a4a749 2019-09-14 186: channelInstanceData = event->channelInstanceData;
aa08a4a749 2019-09-14 187:
aa08a4a749 2019-09-14 188: channelInstanceData->queuedEvents--;
aa08a4a749 2019-09-14 189:
aa08a4a749 2019-09-14 190: xvfs_tclfs_closeChannel((ClientData) channelInstanceData, NULL);
aa08a4a749 2019-09-14 191:
aa08a4a749 2019-09-14 192: return(1);
aa08a4a749 2019-09-14 193: }
aa08a4a749 2019-09-14 194:
38bed7cee0 2019-09-13 195: static int xvfs_tclfs_closeChannel(ClientData channelInstanceData_p, Tcl_Interp *interp) {
38bed7cee0 2019-09-13 196: struct xvfs_tclfs_channel_id *channelInstanceData;
aa08a4a749 2019-09-14 197: struct xvfs_tclfs_channel_event *event;
38bed7cee0 2019-09-13 198:
38bed7cee0 2019-09-13 199: channelInstanceData = (struct xvfs_tclfs_channel_id *) channelInstanceData_p;
aa08a4a749 2019-09-14 200:
aa08a4a749 2019-09-14 201: channelInstanceData->closed = 1;
aa08a4a749 2019-09-14 202:
aa08a4a749 2019-09-14 203: if (channelInstanceData->queuedEvents != 0) {
aa08a4a749 2019-09-14 204: event = (struct xvfs_tclfs_channel_event *) Tcl_Alloc(sizeof(*event));
aa08a4a749 2019-09-14 205: event->tcl.proc = xvfs_tclfs_closeChannelEvent;
aa08a4a749 2019-09-14 206: event->tcl.nextPtr = NULL;
aa08a4a749 2019-09-14 207: event->channelInstanceData = channelInstanceData;
aa08a4a749 2019-09-14 208:
aa08a4a749 2019-09-14 209: channelInstanceData->queuedEvents++;
aa08a4a749 2019-09-14 210:
aa08a4a749 2019-09-14 211: Tcl_QueueEvent((Tcl_Event *) event, TCL_QUEUE_TAIL);
aa08a4a749 2019-09-14 212:
aa08a4a749 2019-09-14 213: return(0);
aa08a4a749 2019-09-14 214: }
38bed7cee0 2019-09-13 215:
38bed7cee0 2019-09-13 216: Tcl_DecrRefCount(channelInstanceData->path);
38bed7cee0 2019-09-13 217: Tcl_Free((char *) channelInstanceData);
38bed7cee0 2019-09-13 218:
38bed7cee0 2019-09-13 219: return(0);
38bed7cee0 2019-09-13 220: }
38bed7cee0 2019-09-13 221:
38bed7cee0 2019-09-13 222: static int xvfs_tclfs_readChannel(ClientData channelInstanceData_p, char *buf, int bufSize, int *errorCodePtr) {
38bed7cee0 2019-09-13 223: struct xvfs_tclfs_channel_id *channelInstanceData;
38bed7cee0 2019-09-13 224: const unsigned char *data;
38bed7cee0 2019-09-13 225: Tcl_WideInt offset, length;
38bed7cee0 2019-09-13 226: char *path;
38bed7cee0 2019-09-13 227:
38bed7cee0 2019-09-13 228: channelInstanceData = (struct xvfs_tclfs_channel_id *) channelInstanceData_p;
38bed7cee0 2019-09-13 229:
7d74392642 2019-09-13 230: /*
7d74392642 2019-09-13 231: * If we are already at the end of the file we can skip
7d74392642 2019-09-13 232: * attempting to read it
7d74392642 2019-09-13 233: */
7d74392642 2019-09-13 234: if (channelInstanceData->eofMarked) {
7d74392642 2019-09-13 235: return(0);
7d74392642 2019-09-13 236: }
7d74392642 2019-09-13 237:
38bed7cee0 2019-09-13 238: path = Tcl_GetString(channelInstanceData->path);
38bed7cee0 2019-09-13 239: offset = channelInstanceData->currentOffset;
38bed7cee0 2019-09-13 240: length = bufSize;
38bed7cee0 2019-09-13 241:
38bed7cee0 2019-09-13 242: data = channelInstanceData->fsInstanceInfo->fsInfo->getDataProc(path, offset, &length);
38bed7cee0 2019-09-13 243:
38bed7cee0 2019-09-13 244: if (length < 0) {
38bed7cee0 2019-09-13 245: *errorCodePtr = xvfs_errorToErrno(length);
38bed7cee0 2019-09-13 246:
38bed7cee0 2019-09-13 247: return(-1);
38bed7cee0 2019-09-13 248: }
38bed7cee0 2019-09-13 249:
7d74392642 2019-09-13 250: if (length == 0) {
7d74392642 2019-09-13 251: channelInstanceData->eofMarked = 1;
7d74392642 2019-09-13 252: } else {
7d74392642 2019-09-13 253: memcpy(buf, data, length);
38bed7cee0 2019-09-13 254:
7d74392642 2019-09-13 255: channelInstanceData->currentOffset += length;
7d74392642 2019-09-13 256: }
38bed7cee0 2019-09-13 257:
38bed7cee0 2019-09-13 258: return(length);
38bed7cee0 2019-09-13 259: }
38bed7cee0 2019-09-13 260:
7d74392642 2019-09-13 261: static int xvfs_tclfs_watchChannelEvent(Tcl_Event *event_p, int flags) {
7d74392642 2019-09-13 262: struct xvfs_tclfs_channel_id *channelInstanceData;
7d74392642 2019-09-13 263: struct xvfs_tclfs_channel_event *event;
7d74392642 2019-09-13 264:
7d74392642 2019-09-13 265: event = (struct xvfs_tclfs_channel_event *) event_p;
7d74392642 2019-09-13 266: channelInstanceData = event->channelInstanceData;
7d74392642 2019-09-13 267:
aa08a4a749 2019-09-14 268: channelInstanceData->queuedEvents--;
aa08a4a749 2019-09-14 269:
aa08a4a749 2019-09-14 270: if (channelInstanceData->closed) {
aa08a4a749 2019-09-14 271: return(1);
aa08a4a749 2019-09-14 272: }
aa08a4a749 2019-09-14 273:
7d74392642 2019-09-13 274: Tcl_NotifyChannel(channelInstanceData->channel, TCL_READABLE);
7d74392642 2019-09-13 275:
aa08a4a749 2019-09-14 276: return(1);
7d74392642 2019-09-13 277: }
7d74392642 2019-09-13 278:
38bed7cee0 2019-09-13 279: static void xvfs_tclfs_watchChannel(ClientData channelInstanceData_p, int mask) {
7d74392642 2019-09-13 280: struct xvfs_tclfs_channel_id *channelInstanceData;
7d74392642 2019-09-13 281: struct xvfs_tclfs_channel_event *event;
7d74392642 2019-09-13 282:
38bed7cee0 2019-09-13 283: if ((mask & TCL_READABLE) != TCL_READABLE) {
38bed7cee0 2019-09-13 284: return;
38bed7cee0 2019-09-13 285: }
38bed7cee0 2019-09-13 286:
7d74392642 2019-09-13 287: channelInstanceData = (struct xvfs_tclfs_channel_id *) channelInstanceData_p;
7d74392642 2019-09-13 288:
7d74392642 2019-09-13 289: /*
7d74392642 2019-09-13 290: * If the read call has marked that we have reached EOF,
7d74392642 2019-09-13 291: * do not signal any further
7d74392642 2019-09-13 292: */
7d74392642 2019-09-13 293: if (channelInstanceData->eofMarked) {
7d74392642 2019-09-13 294: return;
7d74392642 2019-09-13 295: }
7d74392642 2019-09-13 296:
7d74392642 2019-09-13 297: event = (struct xvfs_tclfs_channel_event *) Tcl_Alloc(sizeof(*event));
7d74392642 2019-09-13 298: event->tcl.proc = xvfs_tclfs_watchChannelEvent;
7d74392642 2019-09-13 299: event->tcl.nextPtr = NULL;
7d74392642 2019-09-13 300: event->channelInstanceData = channelInstanceData;
aa08a4a749 2019-09-14 301:
aa08a4a749 2019-09-14 302: channelInstanceData->queuedEvents++;
7d74392642 2019-09-13 303:
7d74392642 2019-09-13 304: Tcl_QueueEvent((Tcl_Event *) event, TCL_QUEUE_TAIL);
7d74392642 2019-09-13 305:
38bed7cee0 2019-09-13 306: return;
38bed7cee0 2019-09-13 307: }
38bed7cee0 2019-09-13 308:
38bed7cee0 2019-09-13 309: static int xvfs_tclfs_seekChannel(ClientData channelInstanceData_p, long offset, int mode, int *errorCodePtr) {
38bed7cee0 2019-09-13 310: struct xvfs_tclfs_channel_id *channelInstanceData;
38bed7cee0 2019-09-13 311: Tcl_WideInt newOffset, fileSize;
38bed7cee0 2019-09-13 312:
38bed7cee0 2019-09-13 313: channelInstanceData = (struct xvfs_tclfs_channel_id *) channelInstanceData_p;
38bed7cee0 2019-09-13 314:
38bed7cee0 2019-09-13 315: newOffset = channelInstanceData->currentOffset;
38bed7cee0 2019-09-13 316: fileSize = channelInstanceData->fileSize;
38bed7cee0 2019-09-13 317:
38bed7cee0 2019-09-13 318: switch (mode) {
38bed7cee0 2019-09-13 319: case SEEK_CUR:
38bed7cee0 2019-09-13 320: newOffset += offset;
38bed7cee0 2019-09-13 321: break;
38bed7cee0 2019-09-13 322: case SEEK_SET:
38bed7cee0 2019-09-13 323: newOffset = offset;
38bed7cee0 2019-09-13 324: break;
38bed7cee0 2019-09-13 325: case SEEK_END:
38bed7cee0 2019-09-13 326: newOffset = fileSize + offset;
38bed7cee0 2019-09-13 327: break;
38bed7cee0 2019-09-13 328: default:
38bed7cee0 2019-09-13 329: *errorCodePtr = xvfs_errorToErrno(XVFS_RV_ERR_EINVAL);
38bed7cee0 2019-09-13 330:
38bed7cee0 2019-09-13 331: return(-1);
38bed7cee0 2019-09-13 332: }
38bed7cee0 2019-09-13 333:
38bed7cee0 2019-09-13 334: /*
38bed7cee0 2019-09-13 335: * We allow users to seek right up to the end of the buffer, but
38bed7cee0 2019-09-13 336: * no further, this way if they want to seek backwards from there
38bed7cee0 2019-09-13 337: * it is possible to do so.
38bed7cee0 2019-09-13 338: */
38bed7cee0 2019-09-13 339: if (newOffset < 0 || newOffset > fileSize) {
38bed7cee0 2019-09-13 340: *errorCodePtr = xvfs_errorToErrno(XVFS_RV_ERR_EINVAL);
38bed7cee0 2019-09-13 341:
38bed7cee0 2019-09-13 342: return(-1);
38bed7cee0 2019-09-13 343: }
38bed7cee0 2019-09-13 344:
7d74392642 2019-09-13 345: if (newOffset != channelInstanceData->currentOffset) {
7d74392642 2019-09-13 346: channelInstanceData->eofMarked = 0;
7d74392642 2019-09-13 347: channelInstanceData->currentOffset = newOffset;
7d74392642 2019-09-13 348: }
38bed7cee0 2019-09-13 349:
38bed7cee0 2019-09-13 350: return(channelInstanceData->currentOffset);
38bed7cee0 2019-09-13 351: }
38bed7cee0 2019-09-13 352:
38bed7cee0 2019-09-13 353: static void xvfs_tclfs_prepareChannelType(void) {
38bed7cee0 2019-09-13 354: xvfs_tclfs_channelType.typeName = "xvfs";
38bed7cee0 2019-09-13 355: xvfs_tclfs_channelType.version = TCL_CHANNEL_VERSION_2;
38bed7cee0 2019-09-13 356: xvfs_tclfs_channelType.closeProc = xvfs_tclfs_closeChannel;
38bed7cee0 2019-09-13 357: xvfs_tclfs_channelType.inputProc = xvfs_tclfs_readChannel;
38bed7cee0 2019-09-13 358: xvfs_tclfs_channelType.outputProc = NULL;
38bed7cee0 2019-09-13 359: xvfs_tclfs_channelType.watchProc = xvfs_tclfs_watchChannel;
38bed7cee0 2019-09-13 360: xvfs_tclfs_channelType.getHandleProc = NULL;
38bed7cee0 2019-09-13 361: xvfs_tclfs_channelType.seekProc = xvfs_tclfs_seekChannel;
38bed7cee0 2019-09-13 362: xvfs_tclfs_channelType.setOptionProc = NULL;
38bed7cee0 2019-09-13 363: xvfs_tclfs_channelType.getOptionProc = NULL;
38bed7cee0 2019-09-13 364: xvfs_tclfs_channelType.close2Proc = NULL;
38bed7cee0 2019-09-13 365: xvfs_tclfs_channelType.blockModeProc = NULL;
38bed7cee0 2019-09-13 366: xvfs_tclfs_channelType.flushProc = NULL;
38bed7cee0 2019-09-13 367: xvfs_tclfs_channelType.handlerProc = NULL;
38bed7cee0 2019-09-13 368: xvfs_tclfs_channelType.wideSeekProc = NULL;
38bed7cee0 2019-09-13 369: xvfs_tclfs_channelType.threadActionProc = NULL;
38bed7cee0 2019-09-13 370: xvfs_tclfs_channelType.truncateProc = NULL;
d121970301 2019-05-02 371: }
d121970301 2019-05-02 372:
d121970301 2019-05-02 373: /*
d121970301 2019-05-02 374: * Internal Tcl_Filesystem functions, with the appropriate instance info
d121970301 2019-05-02 375: */
d121970301 2019-05-02 376: static int xvfs_tclfs_pathInFilesystem(Tcl_Obj *path, ClientData *dataPtr, struct xvfs_tclfs_instance_info *instanceInfo) {
d121970301 2019-05-02 377: const char *relativePath;
38bed7cee0 2019-09-13 378:
d121970301 2019-05-02 379: relativePath = xvfs_relativePath(path, instanceInfo);
d121970301 2019-05-02 380: if (!relativePath) {
d121970301 2019-05-02 381: return(-1);
d121970301 2019-05-02 382: }
38bed7cee0 2019-09-13 383:
d121970301 2019-05-02 384: return(TCL_OK);
d121970301 2019-05-02 385: }
d121970301 2019-05-02 386:
d121970301 2019-05-02 387: static int xvfs_tclfs_stat(Tcl_Obj *path, Tcl_StatBuf *statBuf, struct xvfs_tclfs_instance_info *instanceInfo) {
d121970301 2019-05-02 388: const char *pathStr;
d121970301 2019-05-02 389: int retval;
d121970301 2019-05-02 390:
d121970301 2019-05-02 391: pathStr = xvfs_relativePath(path, instanceInfo);
38bed7cee0 2019-09-13 392:
daf25f5222 2019-05-03 393: retval = instanceInfo->fsInfo->getStatProc(pathStr, statBuf);
149aa89b7d 2019-09-13 394: if (retval < 0) {
149aa89b7d 2019-09-13 395: retval = -1;
149aa89b7d 2019-09-13 396: }
38bed7cee0 2019-09-13 397:
d121970301 2019-05-02 398: return(retval);
d121970301 2019-05-02 399: }
d121970301 2019-05-02 400:
d121970301 2019-05-02 401: static Tcl_Obj *xvfs_tclfs_listVolumes(struct xvfs_tclfs_instance_info *instanceInfo) {
d121970301 2019-05-02 402: return(NULL);
d121970301 2019-05-02 403: }
d121970301 2019-05-02 404:
d121970301 2019-05-02 405: static Tcl_Channel xvfs_tclfs_openFileChannel(Tcl_Interp *interp, Tcl_Obj *path, int mode, int permissions, struct xvfs_tclfs_instance_info *instanceInfo) {
d121970301 2019-05-02 406: const char *pathStr;
38bed7cee0 2019-09-13 407:
38bed7cee0 2019-09-13 408: pathStr = xvfs_relativePath(path, instanceInfo);
38bed7cee0 2019-09-13 409:
38bed7cee0 2019-09-13 410: if (mode & O_WRONLY) {
38bed7cee0 2019-09-13 411: return(NULL);
38bed7cee0 2019-09-13 412: }
38bed7cee0 2019-09-13 413:
38bed7cee0 2019-09-13 414: return(xvfs_tclfs_openChannel(Tcl_NewStringObj(pathStr, -1), instanceInfo));
38bed7cee0 2019-09-13 415: }
5583d77f1c 2019-09-14 416:
5583d77f1c 2019-09-14 417: static int xvfs_tclfs_verifyType(Tcl_Obj *path, Tcl_GlobTypeData *types, struct xvfs_tclfs_instance_info *instanceInfo) {
5583d77f1c 2019-09-14 418: const char *pathStr;
5583d77f1c 2019-09-14 419: Tcl_StatBuf fileInfo;
5583d77f1c 2019-09-14 420: int statRetVal;
5583d77f1c 2019-09-14 421:
5583d77f1c 2019-09-14 422: statRetVal = xvfs_tclfs_stat(path, &fileInfo, instanceInfo);
5583d77f1c 2019-09-14 423: if (statRetVal != 0) {
5583d77f1c 2019-09-14 424: return(0);
5583d77f1c 2019-09-14 425: }
5583d77f1c 2019-09-14 426:
5583d77f1c 2019-09-14 427: if (!types) {
5583d77f1c 2019-09-14 428: return(1);
5583d77f1c 2019-09-14 429: }
5583d77f1c 2019-09-14 430:
5583d77f1c 2019-09-14 431: if (types->perm != TCL_GLOB_PERM_RONLY) {
5583d77f1c 2019-09-14 432: if (types->perm & (TCL_GLOB_PERM_W | TCL_GLOB_PERM_X | TCL_GLOB_PERM_HIDDEN)) {
5583d77f1c 2019-09-14 433: return(0);
5583d77f1c 2019-09-14 434: }
5583d77f1c 2019-09-14 435: }
5583d77f1c 2019-09-14 436:
5583d77f1c 2019-09-14 437: if (types->type & (TCL_GLOB_TYPE_BLOCK | TCL_GLOB_TYPE_CHAR | TCL_GLOB_TYPE_PIPE | TCL_GLOB_TYPE_SOCK | TCL_GLOB_TYPE_LINK)) {
5583d77f1c 2019-09-14 438: return(0);
5583d77f1c 2019-09-14 439: }
5583d77f1c 2019-09-14 440:
5583d77f1c 2019-09-14 441: if ((types->type & TCL_GLOB_TYPE_DIR) == TCL_GLOB_TYPE_DIR) {
5583d77f1c 2019-09-14 442: if (!(fileInfo.st_mode & 040000)) {
5583d77f1c 2019-09-14 443: return(0);
5583d77f1c 2019-09-14 444: }
5583d77f1c 2019-09-14 445: }
5583d77f1c 2019-09-14 446:
5583d77f1c 2019-09-14 447: if ((types->type & TCL_GLOB_TYPE_FILE) == TCL_GLOB_TYPE_FILE) {
5583d77f1c 2019-09-14 448: if (!(fileInfo.st_mode & 0100000)) {
5583d77f1c 2019-09-14 449: return(0);
5583d77f1c 2019-09-14 450: }
5583d77f1c 2019-09-14 451: }
5583d77f1c 2019-09-14 452:
5583d77f1c 2019-09-14 453: if ((types->type & TCL_GLOB_TYPE_MOUNT) == TCL_GLOB_TYPE_MOUNT) {
5583d77f1c 2019-09-14 454: pathStr = xvfs_relativePath(path, instanceInfo);
5583d77f1c 2019-09-14 455: if (!pathStr) {
5583d77f1c 2019-09-14 456: return(0);
5583d77f1c 2019-09-14 457: }
5583d77f1c 2019-09-14 458:
5583d77f1c 2019-09-14 459: if (strlen(pathStr) != 0) {
5583d77f1c 2019-09-14 460: return(0);
5583d77f1c 2019-09-14 461: }
5583d77f1c 2019-09-14 462: }
5583d77f1c 2019-09-14 463:
5583d77f1c 2019-09-14 464: return(1);
5583d77f1c 2019-09-14 465: }
5583d77f1c 2019-09-14 466:
5583d77f1c 2019-09-14 467: 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 468: const char *pathStr;
5583d77f1c 2019-09-14 469: const char **children, *child;
5583d77f1c 2019-09-14 470: Tcl_WideInt childrenCount, idx;
5583d77f1c 2019-09-14 471: Tcl_Obj *childObj;
5583d77f1c 2019-09-14 472: int tclRetVal;
5583d77f1c 2019-09-14 473:
5583d77f1c 2019-09-14 474: if (pattern == NULL) {
5583d77f1c 2019-09-14 475: if (xvfs_tclfs_verifyType(path, types, instanceInfo)) {
5583d77f1c 2019-09-14 476: return(TCL_OK);
5583d77f1c 2019-09-14 477: }
5583d77f1c 2019-09-14 478:
5583d77f1c 2019-09-14 479: return(TCL_ERROR);
5583d77f1c 2019-09-14 480: }
5583d77f1c 2019-09-14 481:
5583d77f1c 2019-09-14 482: pathStr = xvfs_relativePath(path, instanceInfo);
5583d77f1c 2019-09-14 483: if (!pathStr) {
5583d77f1c 2019-09-14 484: if (interp) {
5583d77f1c 2019-09-14 485: Tcl_SetResult(interp, (char *) xvfs_perror(XVFS_RV_ERR_ENOENT), NULL);
5583d77f1c 2019-09-14 486: }
5583d77f1c 2019-09-14 487:
5583d77f1c 2019-09-14 488: return(TCL_ERROR);
5583d77f1c 2019-09-14 489: }
5583d77f1c 2019-09-14 490:
5583d77f1c 2019-09-14 491: childrenCount = 0;
5583d77f1c 2019-09-14 492: children = instanceInfo->fsInfo->getChildrenProc(pathStr, &childrenCount);
5583d77f1c 2019-09-14 493: if (childrenCount < 0) {
5583d77f1c 2019-09-14 494: if (interp) {
5583d77f1c 2019-09-14 495: Tcl_SetResult(interp, (char *) xvfs_perror(childrenCount), NULL);
5583d77f1c 2019-09-14 496: }
5583d77f1c 2019-09-14 497:
5583d77f1c 2019-09-14 498: return(TCL_ERROR);
5583d77f1c 2019-09-14 499: }
5583d77f1c 2019-09-14 500:
5583d77f1c 2019-09-14 501: for (idx = 0; idx < childrenCount; idx++) {
5583d77f1c 2019-09-14 502: child = children[idx];
5583d77f1c 2019-09-14 503:
5583d77f1c 2019-09-14 504: if (!Tcl_StringMatch(child, pattern)) {
5583d77f1c 2019-09-14 505: continue;
5583d77f1c 2019-09-14 506: }
5583d77f1c 2019-09-14 507:
5583d77f1c 2019-09-14 508: childObj = Tcl_DuplicateObj(path);
5583d77f1c 2019-09-14 509: Tcl_AppendStringsToObj(childObj, "/", child, NULL);
5583d77f1c 2019-09-14 510: Tcl_IncrRefCount(childObj);
5583d77f1c 2019-09-14 511:
5583d77f1c 2019-09-14 512: if (!xvfs_tclfs_verifyType(childObj, types, instanceInfo)) {
5583d77f1c 2019-09-14 513: Tcl_DecrRefCount(childObj);
5583d77f1c 2019-09-14 514:
5583d77f1c 2019-09-14 515: continue;
5583d77f1c 2019-09-14 516: }
5583d77f1c 2019-09-14 517:
5583d77f1c 2019-09-14 518: tclRetVal = Tcl_ListObjAppendElement(interp, resultPtr, childObj);
5583d77f1c 2019-09-14 519: Tcl_DecrRefCount(childObj);
5583d77f1c 2019-09-14 520:
5583d77f1c 2019-09-14 521: if (tclRetVal != TCL_OK) {
5583d77f1c 2019-09-14 522: return(tclRetVal);
5583d77f1c 2019-09-14 523: }
5583d77f1c 2019-09-14 524: }
5583d77f1c 2019-09-14 525:
5583d77f1c 2019-09-14 526: return(TCL_OK);
5583d77f1c 2019-09-14 527: }
3e44e1def1 2019-05-02 528: #endif /* XVFS_MODE_SERVER || XVFS_MODE_STANDALONE || XVFS_MODE_FLEIXBLE */
d121970301 2019-05-02 529:
88f96696b7 2019-05-03 530: #if defined(XVFS_MODE_STANDALONE) || defined(XVFS_MODE_FLEXIBLE)
d121970301 2019-05-02 531: /*
d121970301 2019-05-02 532: * Tcl_Filesystem handlers for the standalone implementation
d121970301 2019-05-02 533: */
acfc5037c6 2019-05-02 534: static struct xvfs_tclfs_instance_info xvfs_tclfs_standalone_info;
d121970301 2019-05-02 535: static int xvfs_tclfs_standalone_pathInFilesystem(Tcl_Obj *path, ClientData *dataPtr) {
d121970301 2019-05-02 536: return(xvfs_tclfs_pathInFilesystem(path, dataPtr, &xvfs_tclfs_standalone_info));
d121970301 2019-05-02 537: }
d121970301 2019-05-02 538:
d121970301 2019-05-02 539: static int xvfs_tclfs_standalone_stat(Tcl_Obj *path, Tcl_StatBuf *statBuf) {
d121970301 2019-05-02 540: return(xvfs_tclfs_stat(path, statBuf, &xvfs_tclfs_standalone_info));
d121970301 2019-05-02 541: }
d121970301 2019-05-02 542:
d121970301 2019-05-02 543: static Tcl_Obj *xvfs_tclfs_standalone_listVolumes(void) {
d121970301 2019-05-02 544: return(xvfs_tclfs_listVolumes(&xvfs_tclfs_standalone_info));
e5b6962adf 2019-05-02 545: }
e5b6962adf 2019-05-02 546:
d121970301 2019-05-02 547: static Tcl_Channel xvfs_tclfs_standalone_openFileChannel(Tcl_Interp *interp, Tcl_Obj *path, int mode, int permissions) {
d121970301 2019-05-02 548: return(xvfs_tclfs_openFileChannel(interp, path, mode, permissions, &xvfs_tclfs_standalone_info));
5583d77f1c 2019-09-14 549: }
5583d77f1c 2019-09-14 550:
5583d77f1c 2019-09-14 551: 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 552: return(xvfs_tclfs_matchInDir(interp, resultPtr, pathPtr, pattern, types, &xvfs_tclfs_standalone_info));
38bed7cee0 2019-09-13 553: }
38bed7cee0 2019-09-13 554:
32b55a907b 2019-05-02 555: /*
32b55a907b 2019-05-02 556: * There are three (3) modes of operation for Xvfs_Register:
32b55a907b 2019-05-02 557: * 1. standalone -- We register our own Tcl_Filesystem
32b55a907b 2019-05-02 558: * and handle requests under `//xvfs:/<fsName>`
32b55a907b 2019-05-02 559: * 2. client -- A single Tcl_Filesystem is registered for the
32b55a907b 2019-05-02 560: * interp to handle requests under `//xvfs:/` which
32b55a907b 2019-05-02 561: * then dispatches to the appropriate registered
32b55a907b 2019-05-02 562: * handler
32b55a907b 2019-05-02 563: * 3. flexible -- Attempts to find a core Xvfs instance for the
32b55a907b 2019-05-02 564: * process at runtime, if found do #2, otherwise
32b55a907b 2019-05-02 565: * fallback to #1
32b55a907b 2019-05-02 566: *
32b55a907b 2019-05-02 567: */
cb77ecfb24 2019-05-06 568: static Tcl_Filesystem xvfs_tclfs_standalone_fs;
b8cca3a6b4 2019-05-08 569: static int xvfs_standalone_register(Tcl_Interp *interp, struct Xvfs_FSInfo *fsInfo) {
e5b6962adf 2019-05-02 570: int tcl_ret;
d121970301 2019-05-02 571: static int registered = 0;
38bed7cee0 2019-09-13 572:
d121970301 2019-05-02 573: /*
d121970301 2019-05-02 574: * Ensure this instance is not already registered
d121970301 2019-05-02 575: */
d121970301 2019-05-02 576: if (registered) {
d121970301 2019-05-02 577: return(TCL_OK);
d121970301 2019-05-02 578: }
d121970301 2019-05-02 579: registered = 1;
d121970301 2019-05-02 580:
e5b6962adf 2019-05-02 581: /*
e5b6962adf 2019-05-02 582: * In standalone mode, we only support the same protocol we are
e5b6962adf 2019-05-02 583: * compiling for.
e5b6962adf 2019-05-02 584: */
e5b6962adf 2019-05-02 585: if (fsInfo->protocolVersion != XVFS_PROTOCOL_VERSION) {
e5b6962adf 2019-05-02 586: if (interp) {
e5b6962adf 2019-05-02 587: Tcl_SetResult(interp, "Protocol mismatch", NULL);
e5b6962adf 2019-05-02 588: }
e5b6962adf 2019-05-02 589: return(TCL_ERROR);
e5b6962adf 2019-05-02 590: }
38bed7cee0 2019-09-13 591:
cb77ecfb24 2019-05-06 592: xvfs_tclfs_standalone_fs.typeName = "xvfs";
cb77ecfb24 2019-05-06 593: xvfs_tclfs_standalone_fs.structureLength = sizeof(xvfs_tclfs_standalone_fs);
cb77ecfb24 2019-05-06 594: xvfs_tclfs_standalone_fs.version = TCL_FILESYSTEM_VERSION_1;
cb77ecfb24 2019-05-06 595: xvfs_tclfs_standalone_fs.pathInFilesystemProc = xvfs_tclfs_standalone_pathInFilesystem;
cb77ecfb24 2019-05-06 596: xvfs_tclfs_standalone_fs.dupInternalRepProc = NULL;
cb77ecfb24 2019-05-06 597: xvfs_tclfs_standalone_fs.freeInternalRepProc = NULL;
cb77ecfb24 2019-05-06 598: xvfs_tclfs_standalone_fs.internalToNormalizedProc = NULL;
cb77ecfb24 2019-05-06 599: xvfs_tclfs_standalone_fs.createInternalRepProc = NULL;
cb77ecfb24 2019-05-06 600: xvfs_tclfs_standalone_fs.normalizePathProc = NULL;
cb77ecfb24 2019-05-06 601: xvfs_tclfs_standalone_fs.filesystemPathTypeProc = NULL;
cb77ecfb24 2019-05-06 602: xvfs_tclfs_standalone_fs.filesystemSeparatorProc = NULL;
cb77ecfb24 2019-05-06 603: xvfs_tclfs_standalone_fs.statProc = xvfs_tclfs_standalone_stat;
cb77ecfb24 2019-05-06 604: xvfs_tclfs_standalone_fs.accessProc = NULL;
cb77ecfb24 2019-05-06 605: xvfs_tclfs_standalone_fs.openFileChannelProc = xvfs_tclfs_standalone_openFileChannel;
5583d77f1c 2019-09-14 606: xvfs_tclfs_standalone_fs.matchInDirectoryProc = xvfs_tclfs_standalone_matchInDir;
cb77ecfb24 2019-05-06 607: xvfs_tclfs_standalone_fs.utimeProc = NULL;
cb77ecfb24 2019-05-06 608: xvfs_tclfs_standalone_fs.linkProc = NULL;
cb77ecfb24 2019-05-06 609: xvfs_tclfs_standalone_fs.listVolumesProc = xvfs_tclfs_standalone_listVolumes;
cb77ecfb24 2019-05-06 610: xvfs_tclfs_standalone_fs.fileAttrStringsProc = NULL;
cb77ecfb24 2019-05-06 611: xvfs_tclfs_standalone_fs.fileAttrsGetProc = NULL;
cb77ecfb24 2019-05-06 612: xvfs_tclfs_standalone_fs.fileAttrsSetProc = NULL;
cb77ecfb24 2019-05-06 613: xvfs_tclfs_standalone_fs.createDirectoryProc = NULL;
cb77ecfb24 2019-05-06 614: xvfs_tclfs_standalone_fs.removeDirectoryProc = NULL;
cb77ecfb24 2019-05-06 615: xvfs_tclfs_standalone_fs.deleteFileProc = NULL;
cb77ecfb24 2019-05-06 616: xvfs_tclfs_standalone_fs.copyFileProc = NULL;
cb77ecfb24 2019-05-06 617: xvfs_tclfs_standalone_fs.renameFileProc = NULL;
cb77ecfb24 2019-05-06 618: xvfs_tclfs_standalone_fs.copyDirectoryProc = NULL;
cb77ecfb24 2019-05-06 619: xvfs_tclfs_standalone_fs.lstatProc = NULL;
cb77ecfb24 2019-05-06 620: xvfs_tclfs_standalone_fs.loadFileProc = NULL;
cb77ecfb24 2019-05-06 621: xvfs_tclfs_standalone_fs.getCwdProc = NULL;
cb77ecfb24 2019-05-06 622: xvfs_tclfs_standalone_fs.chdirProc = NULL;
d121970301 2019-05-02 623:
d121970301 2019-05-02 624: xvfs_tclfs_standalone_info.fsInfo = fsInfo;
d121970301 2019-05-02 625: xvfs_tclfs_standalone_info.mountpoint = Tcl_NewObj();
d121970301 2019-05-02 626: Tcl_AppendStringsToObj(xvfs_tclfs_standalone_info.mountpoint, XVFS_ROOT_MOUNTPOINT, fsInfo->name, NULL);
38bed7cee0 2019-09-13 627:
cb77ecfb24 2019-05-06 628: tcl_ret = Tcl_FSRegister(NULL, &xvfs_tclfs_standalone_fs);
e5b6962adf 2019-05-02 629: if (tcl_ret != TCL_OK) {
e5b6962adf 2019-05-02 630: if (interp) {
e5b6962adf 2019-05-02 631: Tcl_SetResult(interp, "Tcl_FSRegister() failed", NULL);
e5b6962adf 2019-05-02 632: }
38bed7cee0 2019-09-13 633:
e5b6962adf 2019-05-02 634: return(tcl_ret);
e5b6962adf 2019-05-02 635: }
38bed7cee0 2019-09-13 636:
38bed7cee0 2019-09-13 637: xvfs_tclfs_prepareChannelType();
38bed7cee0 2019-09-13 638:
e5b6962adf 2019-05-02 639: return(TCL_OK);
e5b6962adf 2019-05-02 640: }
d92ba3d36d 2019-05-08 641: #endif /* XVFS_MODE_STANDALONE || XVFS_MODE_FLEXIBLE */
88f96696b7 2019-05-03 642:
88f96696b7 2019-05-03 643: #if defined(XVFS_MODE_FLEXIBLE)
b8cca3a6b4 2019-05-08 644: static int xvfs_flexible_register(Tcl_Interp *interp, struct Xvfs_FSInfo *fsInfo) {
9bcf758fef 2019-05-08 645: ClientData fsHandlerDataRaw;
9bcf758fef 2019-05-08 646: struct xvfs_tclfs_server_info *fsHandlerData;
9bcf758fef 2019-05-08 647: const Tcl_Filesystem *fsHandler;
9bcf758fef 2019-05-08 648: int (*xvfs_register)(Tcl_Interp *interp, struct Xvfs_FSInfo *fsInfo);
9bcf758fef 2019-05-08 649: Tcl_Obj *rootPathObj;
9bcf758fef 2019-05-08 650:
9bcf758fef 2019-05-08 651: xvfs_register = &xvfs_standalone_register;
9bcf758fef 2019-05-08 652:
9bcf758fef 2019-05-08 653: rootPathObj = Tcl_NewStringObj(XVFS_ROOT_MOUNTPOINT, -1);
9bcf758fef 2019-05-08 654: if (!rootPathObj) {
9bcf758fef 2019-05-08 655: return(xvfs_register(interp, fsInfo));
9bcf758fef 2019-05-08 656: }
9bcf758fef 2019-05-08 657:
9bcf758fef 2019-05-08 658: Tcl_IncrRefCount(rootPathObj);
9bcf758fef 2019-05-08 659: fsHandler = Tcl_FSGetFileSystemForPath(rootPathObj);
9bcf758fef 2019-05-08 660: Tcl_DecrRefCount(rootPathObj);
9bcf758fef 2019-05-08 661:
9bcf758fef 2019-05-08 662: if (!fsHandler) {
9bcf758fef 2019-05-08 663: return(xvfs_register(interp, fsInfo));
9bcf758fef 2019-05-08 664: }
9bcf758fef 2019-05-08 665:
9bcf758fef 2019-05-08 666: fsHandlerDataRaw = Tcl_FSData(fsHandler);
9bcf758fef 2019-05-08 667: if (!fsHandlerDataRaw) {
9bcf758fef 2019-05-08 668: return(xvfs_register(interp, fsInfo));
9bcf758fef 2019-05-08 669: }
9bcf758fef 2019-05-08 670:
9bcf758fef 2019-05-08 671: fsHandlerData = (struct xvfs_tclfs_server_info *) fsHandlerDataRaw;
88f96696b7 2019-05-03 672:
88f96696b7 2019-05-03 673: /*
9bcf758fef 2019-05-08 674: * XXX:TODO: What is the chance that the handler for //xvfs:/ hold
b586d5b0a1 2019-05-08 675: * client data smaller than XVFS_INTERNAL_SERVER_MAGIC_LEN ?
88f96696b7 2019-05-03 676: */
b586d5b0a1 2019-05-08 677: if (memcmp(fsHandlerData->magic, XVFS_INTERNAL_SERVER_MAGIC, sizeof(fsHandlerData->magic)) == 0) {
9bcf758fef 2019-05-08 678: xvfs_register = fsHandlerData->registerProc;
88f96696b7 2019-05-03 679: }
9bcf758fef 2019-05-08 680:
88f96696b7 2019-05-03 681: return(xvfs_register(interp, fsInfo));
88f96696b7 2019-05-03 682: }
d92ba3d36d 2019-05-08 683: #endif /* XVFS_MODE_FLEXIBLE */
3e44e1def1 2019-05-02 684:
3e44e1def1 2019-05-02 685: #if defined(XVFS_MODE_SERVER)
e5b6962adf 2019-05-02 686: int Xvfs_Register(Tcl_Interp *interp, struct Xvfs_FSInfo *fsInfo) {
acfc5037c6 2019-05-02 687: return(TCL_ERROR);
69e476dcd5 2019-05-02 688: }
d92ba3d36d 2019-05-08 689: #endif /* XVFS_MODE_SERVER */