Annotation For xvfs-core.c

Origin for each line in xvfs-core.c from check-in d80c88cee0:

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>
38bed7cee0 2019-09-13    7: 
d80c88cee0 2019-09-16    8: #ifdef XVFS_DEBUG
d80c88cee0 2019-09-16    9: #include <stdio.h> /* Needed for XVFS_DEBUG_PRINTF */
d80c88cee0 2019-09-16   10: static int xvfs_debug_depth = 0;
d80c88cee0 2019-09-16   11: #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   12: #define XVFS_DEBUG_PUTS(str) XVFS_DEBUG_PRINTF("%s", str);
d80c88cee0 2019-09-16   13: #define XVFS_DEBUG_ENTER { xvfs_debug_depth++; XVFS_DEBUG_PUTS("Entered"); }
d80c88cee0 2019-09-16   14: #define XVFS_DEBUG_LEAVE { XVFS_DEBUG_PUTS("Returning"); xvfs_debug_depth--; }
d80c88cee0 2019-09-16   15: #else /* XVFS_DEBUG */
d80c88cee0 2019-09-16   16: #define XVFS_DEBUG_PRINTF(fmt, ...) /**/
d80c88cee0 2019-09-16   17: #define XVFS_DEBUG_PUTS(str) /**/
d80c88cee0 2019-09-16   18: #define XVFS_DEBUG_ENTER /**/
d80c88cee0 2019-09-16   19: #define XVFS_DEBUG_LEAVE /**/
d80c88cee0 2019-09-16   20: #endif /* XVFS_DEBUG */
d80c88cee0 2019-09-16   21: 
d92ba3d36d 2019-05-08   22: #if defined(XVFS_MODE_FLEXIBLE) || defined(XVFS_MODE_SERVER)
d92ba3d36d 2019-05-08   23: #define XVFS_INTERNAL_SERVER_MAGIC "\xD4\xF3\x05\x96\x25\xCF\xAF\xFE"
d92ba3d36d 2019-05-08   24: #define XVFS_INTERNAL_SERVER_MAGIC_LEN 8
d92ba3d36d 2019-05-08   25: 
d92ba3d36d 2019-05-08   26: struct xvfs_tclfs_server_info {
b586d5b0a1 2019-05-08   27: 	char magic[XVFS_INTERNAL_SERVER_MAGIC_LEN];
d92ba3d36d 2019-05-08   28: 	int (*registerProc)(Tcl_Interp *interp, struct Xvfs_FSInfo *fsInfo);
d92ba3d36d 2019-05-08   29: };
d92ba3d36d 2019-05-08   30: #endif /* XVFS_MODE_FLEXIBLE || XVFS_MODE_SERVER */
3e44e1def1 2019-05-02   31: 
3e44e1def1 2019-05-02   32: #if defined(XVFS_MODE_SERVER) || defined(XVFS_MODE_STANDALONE) || defined(XVFS_MODE_FLEXIBLE)
d121970301 2019-05-02   33: #define XVFS_ROOT_MOUNTPOINT "//xvfs:/"
d121970301 2019-05-02   34: 
d121970301 2019-05-02   35: struct xvfs_tclfs_instance_info {
d121970301 2019-05-02   36: 	struct Xvfs_FSInfo *fsInfo;
d121970301 2019-05-02   37: 	Tcl_Obj            *mountpoint;
d121970301 2019-05-02   38: };
d121970301 2019-05-02   39: 
d121970301 2019-05-02   40: /*
d121970301 2019-05-02   41:  * Internal Core Utilities
d121970301 2019-05-02   42:  */
d80c88cee0 2019-09-16   43: static Tcl_Obj *xvfs_absolutePath(Tcl_Obj *path) {
5ae034e55e 2019-09-14   44: 	Tcl_Obj *currentDirectory;
d80c88cee0 2019-09-16   45: 	const char *pathStr;
5ae034e55e 2019-09-14   46: 
d80c88cee0 2019-09-16   47: 	XVFS_DEBUG_ENTER;
d80c88cee0 2019-09-16   48: 
d80c88cee0 2019-09-16   49: 	pathStr = Tcl_GetString(path);
d80c88cee0 2019-09-16   50: 
5ae034e55e 2019-09-14   51: 	if (pathStr[0] != '/') {
5ae034e55e 2019-09-14   52: 		currentDirectory = Tcl_FSGetCwd(NULL);
5ae034e55e 2019-09-14   53: 		Tcl_IncrRefCount(currentDirectory);
5ae034e55e 2019-09-14   54: 
5ae034e55e 2019-09-14   55: 		path = Tcl_ObjPrintf("%s/%s", Tcl_GetString(currentDirectory), pathStr);
5ae034e55e 2019-09-14   56: 		Tcl_IncrRefCount(path);
5ae034e55e 2019-09-14   57: 		Tcl_DecrRefCount(currentDirectory);
d80c88cee0 2019-09-16   58: 	} else {
d80c88cee0 2019-09-16   59: 		Tcl_IncrRefCount(path);
5ae034e55e 2019-09-14   60: 	}
d80c88cee0 2019-09-16   61: 
d80c88cee0 2019-09-16   62: 	XVFS_DEBUG_PRINTF("Converted path \"%s\" to absolute path: \"%s\"", pathStr, Tcl_GetString(path));
d80c88cee0 2019-09-16   63: 
d80c88cee0 2019-09-16   64: 	XVFS_DEBUG_LEAVE;
d80c88cee0 2019-09-16   65: 	return(path);
d80c88cee0 2019-09-16   66: }
d80c88cee0 2019-09-16   67: 
d80c88cee0 2019-09-16   68: static const char *xvfs_relativePath(Tcl_Obj *path, struct xvfs_tclfs_instance_info *info) {
d80c88cee0 2019-09-16   69: 	const char *pathStr, *rootStr;
d80c88cee0 2019-09-16   70: 	const char *pathFinal;
d80c88cee0 2019-09-16   71: 	int pathLen, rootLen;
d80c88cee0 2019-09-16   72: 
d80c88cee0 2019-09-16   73: 	XVFS_DEBUG_ENTER;
d80c88cee0 2019-09-16   74: 
d80c88cee0 2019-09-16   75: 	rootStr = Tcl_GetStringFromObj(info->mountpoint, &rootLen);
d80c88cee0 2019-09-16   76: 	pathStr = Tcl_GetStringFromObj(path, &pathLen);
d80c88cee0 2019-09-16   77: 
d80c88cee0 2019-09-16   78: 	XVFS_DEBUG_PRINTF("Finding relative path of \"%s\" from \"%s\" ...", pathStr, rootStr);
38bed7cee0 2019-09-13   79: 
d121970301 2019-05-02   80: 	if (pathLen < rootLen) {
d80c88cee0 2019-09-16   81: 		XVFS_DEBUG_PUTS("... none possible (length)");
d80c88cee0 2019-09-16   82: 
d80c88cee0 2019-09-16   83: 		XVFS_DEBUG_LEAVE;
d121970301 2019-05-02   84: 		return(NULL);
d121970301 2019-05-02   85: 	}
38bed7cee0 2019-09-13   86: 
d121970301 2019-05-02   87: 	if (memcmp(pathStr, rootStr, rootLen) != 0) {
d80c88cee0 2019-09-16   88: 		XVFS_DEBUG_PUTS("... none possible (prefix differs)");
d80c88cee0 2019-09-16   89: 
d80c88cee0 2019-09-16   90: 		XVFS_DEBUG_LEAVE;
d121970301 2019-05-02   91: 		return(NULL);
d121970301 2019-05-02   92: 	}
38bed7cee0 2019-09-13   93: 
d121970301 2019-05-02   94: 	if (pathLen == rootLen) {
d80c88cee0 2019-09-16   95: 		XVFS_DEBUG_PUTS("... short circuit: \"\"");
d80c88cee0 2019-09-16   96: 
d80c88cee0 2019-09-16   97: 		XVFS_DEBUG_LEAVE;
d121970301 2019-05-02   98: 		return("");
d121970301 2019-05-02   99: 	}
d121970301 2019-05-02  100: 
d121970301 2019-05-02  101: 	/* XXX:TODO: Should this use the native OS path separator ? */
d121970301 2019-05-02  102: 	if (pathStr[rootLen] != '/') {
d80c88cee0 2019-09-16  103: 		XVFS_DEBUG_PUTS("... none possible (no seperator)");
d80c88cee0 2019-09-16  104: 
d80c88cee0 2019-09-16  105: 		XVFS_DEBUG_LEAVE;
149aa89b7d 2019-09-13  106: 		return(NULL);
149aa89b7d 2019-09-13  107: 	}
38bed7cee0 2019-09-13  108: 
5583d77f1c 2019-09-14  109: 	pathFinal = pathStr + rootLen + 1;
5583d77f1c 2019-09-14  110: 	pathLen  -= rootLen + 1;
5583d77f1c 2019-09-14  111: 
5583d77f1c 2019-09-14  112: 	if (pathLen == 1 && memcmp(pathFinal, ".", 1) == 0) {
d80c88cee0 2019-09-16  113: 		XVFS_DEBUG_PUTS("... short circuit: \".\" -> \"\"");
d80c88cee0 2019-09-16  114: 
d80c88cee0 2019-09-16  115: 		XVFS_DEBUG_LEAVE;
5583d77f1c 2019-09-14  116: 		return("");
5583d77f1c 2019-09-14  117: 	}
5583d77f1c 2019-09-14  118: 
5583d77f1c 2019-09-14  119: 	while (pathLen >= 2 && memcmp(pathFinal, "./", 2) == 0) {
5583d77f1c 2019-09-14  120: 		pathFinal += 2;
5583d77f1c 2019-09-14  121: 		pathLen   -= 2;
5583d77f1c 2019-09-14  122: 	}
5583d77f1c 2019-09-14  123: 
d80c88cee0 2019-09-16  124: 	XVFS_DEBUG_PRINTF("... relative path: \"%s\"", pathFinal);
d80c88cee0 2019-09-16  125: 
d80c88cee0 2019-09-16  126: 	XVFS_DEBUG_LEAVE;
5583d77f1c 2019-09-14  127: 	return(pathFinal);
149aa89b7d 2019-09-13  128: }
149aa89b7d 2019-09-13  129: 
149aa89b7d 2019-09-13  130: static const char *xvfs_perror(int xvfs_error) {
149aa89b7d 2019-09-13  131: 	if (xvfs_error >= 0) {
149aa89b7d 2019-09-13  132: 		return("Not an error");
149aa89b7d 2019-09-13  133: 	}
149aa89b7d 2019-09-13  134: 
149aa89b7d 2019-09-13  135: 	switch (xvfs_error) {
149aa89b7d 2019-09-13  136: 		case XVFS_RV_ERR_ENOENT:
149aa89b7d 2019-09-13  137: 			return("No such file or directory");
149aa89b7d 2019-09-13  138: 		case XVFS_RV_ERR_EINVAL:
149aa89b7d 2019-09-13  139: 			return("Invalid argument");
149aa89b7d 2019-09-13  140: 		case XVFS_RV_ERR_EISDIR:
149aa89b7d 2019-09-13  141: 			return("Is a directory");
149aa89b7d 2019-09-13  142: 		case XVFS_RV_ERR_ENOTDIR:
149aa89b7d 2019-09-13  143: 			return("Not a directory");
149aa89b7d 2019-09-13  144: 		case XVFS_RV_ERR_EFAULT:
149aa89b7d 2019-09-13  145: 			return("Bad address");
5583d77f1c 2019-09-14  146: 		case XVFS_RV_ERR_INTERNAL:
5583d77f1c 2019-09-14  147: 			return("Internal error");
149aa89b7d 2019-09-13  148: 		default:
149aa89b7d 2019-09-13  149: 			return("Unknown error");
149aa89b7d 2019-09-13  150: 	}
38bed7cee0 2019-09-13  151: }
38bed7cee0 2019-09-13  152: 
38bed7cee0 2019-09-13  153: static int xvfs_errorToErrno(int xvfs_error) {
38bed7cee0 2019-09-13  154: 	if (xvfs_error >= 0) {
38bed7cee0 2019-09-13  155: 		return(0);
38bed7cee0 2019-09-13  156: 	}
38bed7cee0 2019-09-13  157: 
38bed7cee0 2019-09-13  158: 	switch (xvfs_error) {
38bed7cee0 2019-09-13  159: 		case XVFS_RV_ERR_ENOENT:
38bed7cee0 2019-09-13  160: 			return(ENOENT);
38bed7cee0 2019-09-13  161: 		case XVFS_RV_ERR_EINVAL:
38bed7cee0 2019-09-13  162: 			return(EINVAL);
38bed7cee0 2019-09-13  163: 		case XVFS_RV_ERR_EISDIR:
38bed7cee0 2019-09-13  164: 			return(EISDIR);
38bed7cee0 2019-09-13  165: 		case XVFS_RV_ERR_ENOTDIR:
38bed7cee0 2019-09-13  166: 			return(ENOTDIR);
38bed7cee0 2019-09-13  167: 		case XVFS_RV_ERR_EFAULT:
38bed7cee0 2019-09-13  168: 			return(EFAULT);
5583d77f1c 2019-09-14  169: 		case XVFS_RV_ERR_INTERNAL:
5583d77f1c 2019-09-14  170: 			return(EINVAL);
38bed7cee0 2019-09-13  171: 		default:
38bed7cee0 2019-09-13  172: 			return(ERANGE);
38bed7cee0 2019-09-13  173: 	}
38bed7cee0 2019-09-13  174: }
38bed7cee0 2019-09-13  175: 
38bed7cee0 2019-09-13  176: /*
38bed7cee0 2019-09-13  177:  * Xvfs Memory Channel
38bed7cee0 2019-09-13  178:  */
38bed7cee0 2019-09-13  179: struct xvfs_tclfs_channel_id {
38bed7cee0 2019-09-13  180: 	Tcl_Channel channel;
38bed7cee0 2019-09-13  181: 	struct xvfs_tclfs_instance_info *fsInstanceInfo;
38bed7cee0 2019-09-13  182: 	Tcl_Obj *path;
38bed7cee0 2019-09-13  183: 	Tcl_WideInt currentOffset;
38bed7cee0 2019-09-13  184: 	Tcl_WideInt fileSize;
7d74392642 2019-09-13  185: 	int eofMarked;
aa08a4a749 2019-09-14  186: 	int queuedEvents;
aa08a4a749 2019-09-14  187: 	int closed;
7d74392642 2019-09-13  188: };
7d74392642 2019-09-13  189: struct xvfs_tclfs_channel_event {
7d74392642 2019-09-13  190: 	Tcl_Event tcl;
7d74392642 2019-09-13  191: 	struct xvfs_tclfs_channel_id *channelInstanceData;
38bed7cee0 2019-09-13  192: };
38bed7cee0 2019-09-13  193: static Tcl_ChannelType xvfs_tclfs_channelType;
38bed7cee0 2019-09-13  194: 
38bed7cee0 2019-09-13  195: static Tcl_Channel xvfs_tclfs_openChannel(Tcl_Obj *path, struct xvfs_tclfs_instance_info *instanceInfo) {
38bed7cee0 2019-09-13  196: 	struct xvfs_tclfs_channel_id *channelInstanceData;
38bed7cee0 2019-09-13  197: 	Tcl_Channel channel;
38bed7cee0 2019-09-13  198: 	Tcl_StatBuf fileInfo;
7d74392642 2019-09-13  199: 	Tcl_Obj *channelName;
38bed7cee0 2019-09-13  200: 	int statRet;
7d74392642 2019-09-13  201: 
d80c88cee0 2019-09-16  202: 	XVFS_DEBUG_ENTER;
d80c88cee0 2019-09-16  203: 	XVFS_DEBUG_PRINTF("Opening file \"%s\" ...", Tcl_GetString(path));
d80c88cee0 2019-09-16  204: 
38bed7cee0 2019-09-13  205: 	statRet = instanceInfo->fsInfo->getStatProc(Tcl_GetString(path), &fileInfo);
38bed7cee0 2019-09-13  206: 	if (statRet < 0) {
d80c88cee0 2019-09-16  207: 		XVFS_DEBUG_PRINTF("... failed: %s", xvfs_perror(statRet));
d80c88cee0 2019-09-16  208: 
d80c88cee0 2019-09-16  209: 		XVFS_DEBUG_LEAVE;
38bed7cee0 2019-09-13  210: 		return(NULL);
38bed7cee0 2019-09-13  211: 	}
38bed7cee0 2019-09-13  212: 
38bed7cee0 2019-09-13  213: 	channelInstanceData = (struct xvfs_tclfs_channel_id *) Tcl_Alloc(sizeof(*channelInstanceData));
38bed7cee0 2019-09-13  214: 	channelInstanceData->currentOffset = 0;
7d74392642 2019-09-13  215: 	channelInstanceData->eofMarked = 0;
aa08a4a749 2019-09-14  216: 	channelInstanceData->queuedEvents = 0;
aa08a4a749 2019-09-14  217: 	channelInstanceData->closed = 0;
38bed7cee0 2019-09-13  218: 	channelInstanceData->channel = NULL;
38bed7cee0 2019-09-13  219: 
7d74392642 2019-09-13  220: 	channelName = Tcl_ObjPrintf("xvfs0x%llx", (unsigned long long) channelInstanceData);
7d74392642 2019-09-13  221: 	if (!channelName) {
d80c88cee0 2019-09-16  222: 		XVFS_DEBUG_PUTS("... failed");
d80c88cee0 2019-09-16  223: 
7d74392642 2019-09-13  224: 		Tcl_Free((char *) channelInstanceData);
7d74392642 2019-09-13  225: 
d80c88cee0 2019-09-16  226: 		XVFS_DEBUG_LEAVE;
7d74392642 2019-09-13  227: 		return(NULL);
7d74392642 2019-09-13  228: 	}
7d74392642 2019-09-13  229: 	Tcl_IncrRefCount(channelName);
7d74392642 2019-09-13  230: 
38bed7cee0 2019-09-13  231: 	channelInstanceData->fsInstanceInfo = instanceInfo;
38bed7cee0 2019-09-13  232: 	channelInstanceData->fileSize = fileInfo.st_size;
7d74392642 2019-09-13  233: 	channelInstanceData->path = path;
38bed7cee0 2019-09-13  234: 	Tcl_IncrRefCount(path);
38bed7cee0 2019-09-13  235: 
7d74392642 2019-09-13  236: 	channel = Tcl_CreateChannel(&xvfs_tclfs_channelType, Tcl_GetString(channelName), channelInstanceData, TCL_READABLE);
7d74392642 2019-09-13  237: 	Tcl_DecrRefCount(channelName);
38bed7cee0 2019-09-13  238: 	if (!channel) {
d80c88cee0 2019-09-16  239: 		XVFS_DEBUG_PUTS("... failed");
d80c88cee0 2019-09-16  240: 
38bed7cee0 2019-09-13  241: 		Tcl_DecrRefCount(path);
38bed7cee0 2019-09-13  242: 		Tcl_Free((char *) channelInstanceData);
38bed7cee0 2019-09-13  243: 
d80c88cee0 2019-09-16  244: 		XVFS_DEBUG_LEAVE;
38bed7cee0 2019-09-13  245: 		return(NULL);
38bed7cee0 2019-09-13  246: 	}
38bed7cee0 2019-09-13  247: 
38bed7cee0 2019-09-13  248: 	channelInstanceData->channel = channel;
38bed7cee0 2019-09-13  249: 
d80c88cee0 2019-09-16  250: 	XVFS_DEBUG_PRINTF("... ok (%p)", channelInstanceData);
d80c88cee0 2019-09-16  251: 
d80c88cee0 2019-09-16  252: 	XVFS_DEBUG_LEAVE;
38bed7cee0 2019-09-13  253: 	return(channel);
aa08a4a749 2019-09-14  254: }
aa08a4a749 2019-09-14  255: 
aa08a4a749 2019-09-14  256: static int xvfs_tclfs_closeChannel(ClientData channelInstanceData_p, Tcl_Interp *interp);
aa08a4a749 2019-09-14  257: static int xvfs_tclfs_closeChannelEvent(Tcl_Event *event_p, int flags) {
aa08a4a749 2019-09-14  258: 	struct xvfs_tclfs_channel_id *channelInstanceData;
aa08a4a749 2019-09-14  259: 	struct xvfs_tclfs_channel_event *event;
aa08a4a749 2019-09-14  260: 
aa08a4a749 2019-09-14  261: 	event = (struct xvfs_tclfs_channel_event *) event_p;
aa08a4a749 2019-09-14  262: 	channelInstanceData = event->channelInstanceData;
aa08a4a749 2019-09-14  263: 
aa08a4a749 2019-09-14  264: 	channelInstanceData->queuedEvents--;
aa08a4a749 2019-09-14  265: 
aa08a4a749 2019-09-14  266: 	xvfs_tclfs_closeChannel((ClientData) channelInstanceData, NULL);
aa08a4a749 2019-09-14  267: 
aa08a4a749 2019-09-14  268: 	return(1);
38bed7cee0 2019-09-13  269: }
38bed7cee0 2019-09-13  270: 
38bed7cee0 2019-09-13  271: static int xvfs_tclfs_closeChannel(ClientData channelInstanceData_p, Tcl_Interp *interp) {
38bed7cee0 2019-09-13  272: 	struct xvfs_tclfs_channel_id *channelInstanceData;
aa08a4a749 2019-09-14  273: 	struct xvfs_tclfs_channel_event *event;
aa08a4a749 2019-09-14  274: 
d80c88cee0 2019-09-16  275: 	XVFS_DEBUG_ENTER;
d80c88cee0 2019-09-16  276: 	XVFS_DEBUG_PRINTF("Closing channel %p ...", channelInstanceData_p);
d80c88cee0 2019-09-16  277: 
38bed7cee0 2019-09-13  278: 	channelInstanceData = (struct xvfs_tclfs_channel_id *) channelInstanceData_p;
aa08a4a749 2019-09-14  279: 
aa08a4a749 2019-09-14  280: 	channelInstanceData->closed = 1;
aa08a4a749 2019-09-14  281: 
aa08a4a749 2019-09-14  282: 	if (channelInstanceData->queuedEvents != 0) {
d80c88cee0 2019-09-16  283: 		XVFS_DEBUG_PUTS("... queued");
d80c88cee0 2019-09-16  284: 
aa08a4a749 2019-09-14  285: 		event = (struct xvfs_tclfs_channel_event *) Tcl_Alloc(sizeof(*event));
aa08a4a749 2019-09-14  286: 		event->tcl.proc = xvfs_tclfs_closeChannelEvent;
aa08a4a749 2019-09-14  287: 		event->tcl.nextPtr = NULL;
aa08a4a749 2019-09-14  288: 		event->channelInstanceData = channelInstanceData;
aa08a4a749 2019-09-14  289: 
aa08a4a749 2019-09-14  290: 		channelInstanceData->queuedEvents++;
aa08a4a749 2019-09-14  291: 
aa08a4a749 2019-09-14  292: 		Tcl_QueueEvent((Tcl_Event *) event, TCL_QUEUE_TAIL);
aa08a4a749 2019-09-14  293: 
d80c88cee0 2019-09-16  294: 		XVFS_DEBUG_LEAVE;
aa08a4a749 2019-09-14  295: 		return(0);
aa08a4a749 2019-09-14  296: 	}
38bed7cee0 2019-09-13  297: 
38bed7cee0 2019-09-13  298: 	Tcl_DecrRefCount(channelInstanceData->path);
38bed7cee0 2019-09-13  299: 	Tcl_Free((char *) channelInstanceData);
38bed7cee0 2019-09-13  300: 
d80c88cee0 2019-09-16  301: 	XVFS_DEBUG_PUTS("... ok");
d80c88cee0 2019-09-16  302: 
d80c88cee0 2019-09-16  303: 	XVFS_DEBUG_LEAVE;
38bed7cee0 2019-09-13  304: 	return(0);
38bed7cee0 2019-09-13  305: }
38bed7cee0 2019-09-13  306: 
38bed7cee0 2019-09-13  307: static int xvfs_tclfs_readChannel(ClientData channelInstanceData_p, char *buf, int bufSize, int *errorCodePtr) {
38bed7cee0 2019-09-13  308: 	struct xvfs_tclfs_channel_id *channelInstanceData;
38bed7cee0 2019-09-13  309: 	const unsigned char *data;
38bed7cee0 2019-09-13  310: 	Tcl_WideInt offset, length;
38bed7cee0 2019-09-13  311: 	char *path;
38bed7cee0 2019-09-13  312: 
38bed7cee0 2019-09-13  313: 	channelInstanceData = (struct xvfs_tclfs_channel_id *) channelInstanceData_p;
7d74392642 2019-09-13  314: 
7d74392642 2019-09-13  315: 	/*
7d74392642 2019-09-13  316: 	 * If we are already at the end of the file we can skip
7d74392642 2019-09-13  317: 	 * attempting to read it
7d74392642 2019-09-13  318: 	 */
7d74392642 2019-09-13  319: 	if (channelInstanceData->eofMarked) {
7d74392642 2019-09-13  320: 		return(0);
7d74392642 2019-09-13  321: 	}
38bed7cee0 2019-09-13  322: 
38bed7cee0 2019-09-13  323: 	path = Tcl_GetString(channelInstanceData->path);
38bed7cee0 2019-09-13  324: 	offset = channelInstanceData->currentOffset;
38bed7cee0 2019-09-13  325: 	length = bufSize;
38bed7cee0 2019-09-13  326: 
38bed7cee0 2019-09-13  327: 	data = channelInstanceData->fsInstanceInfo->fsInfo->getDataProc(path, offset, &length);
38bed7cee0 2019-09-13  328: 
38bed7cee0 2019-09-13  329: 	if (length < 0) {
38bed7cee0 2019-09-13  330: 		*errorCodePtr = xvfs_errorToErrno(length);
38bed7cee0 2019-09-13  331: 
38bed7cee0 2019-09-13  332: 		return(-1);
38bed7cee0 2019-09-13  333: 	}
38bed7cee0 2019-09-13  334: 
7d74392642 2019-09-13  335: 	if (length == 0) {
7d74392642 2019-09-13  336: 		channelInstanceData->eofMarked = 1;
7d74392642 2019-09-13  337: 	} else {
7d74392642 2019-09-13  338: 		memcpy(buf, data, length);
38bed7cee0 2019-09-13  339: 
7d74392642 2019-09-13  340: 		channelInstanceData->currentOffset += length;
7d74392642 2019-09-13  341: 	}
38bed7cee0 2019-09-13  342: 
38bed7cee0 2019-09-13  343: 	return(length);
38bed7cee0 2019-09-13  344: }
38bed7cee0 2019-09-13  345: 
7d74392642 2019-09-13  346: static int xvfs_tclfs_watchChannelEvent(Tcl_Event *event_p, int flags) {
7d74392642 2019-09-13  347: 	struct xvfs_tclfs_channel_id *channelInstanceData;
7d74392642 2019-09-13  348: 	struct xvfs_tclfs_channel_event *event;
7d74392642 2019-09-13  349: 
7d74392642 2019-09-13  350: 	event = (struct xvfs_tclfs_channel_event *) event_p;
7d74392642 2019-09-13  351: 	channelInstanceData = event->channelInstanceData;
7d74392642 2019-09-13  352: 
aa08a4a749 2019-09-14  353: 	channelInstanceData->queuedEvents--;
aa08a4a749 2019-09-14  354: 
aa08a4a749 2019-09-14  355: 	if (channelInstanceData->closed) {
aa08a4a749 2019-09-14  356: 		return(1);
aa08a4a749 2019-09-14  357: 	}
aa08a4a749 2019-09-14  358: 
7d74392642 2019-09-13  359: 	Tcl_NotifyChannel(channelInstanceData->channel, TCL_READABLE);
7d74392642 2019-09-13  360: 
aa08a4a749 2019-09-14  361: 	return(1);
7d74392642 2019-09-13  362: }
7d74392642 2019-09-13  363: 
38bed7cee0 2019-09-13  364: static void xvfs_tclfs_watchChannel(ClientData channelInstanceData_p, int mask) {
7d74392642 2019-09-13  365: 	struct xvfs_tclfs_channel_id *channelInstanceData;
7d74392642 2019-09-13  366: 	struct xvfs_tclfs_channel_event *event;
7d74392642 2019-09-13  367: 
38bed7cee0 2019-09-13  368: 	if ((mask & TCL_READABLE) != TCL_READABLE) {
38bed7cee0 2019-09-13  369: 		return;
38bed7cee0 2019-09-13  370: 	}
38bed7cee0 2019-09-13  371: 
7d74392642 2019-09-13  372: 	channelInstanceData = (struct xvfs_tclfs_channel_id *) channelInstanceData_p;
7d74392642 2019-09-13  373: 
7d74392642 2019-09-13  374: 	/*
7d74392642 2019-09-13  375: 	 * If the read call has marked that we have reached EOF,
7d74392642 2019-09-13  376: 	 * do not signal any further
7d74392642 2019-09-13  377: 	 */
7d74392642 2019-09-13  378: 	if (channelInstanceData->eofMarked) {
7d74392642 2019-09-13  379: 		return;
7d74392642 2019-09-13  380: 	}
7d74392642 2019-09-13  381: 
7d74392642 2019-09-13  382: 	event = (struct xvfs_tclfs_channel_event *) Tcl_Alloc(sizeof(*event));
7d74392642 2019-09-13  383: 	event->tcl.proc = xvfs_tclfs_watchChannelEvent;
7d74392642 2019-09-13  384: 	event->tcl.nextPtr = NULL;
7d74392642 2019-09-13  385: 	event->channelInstanceData = channelInstanceData;
aa08a4a749 2019-09-14  386: 
aa08a4a749 2019-09-14  387: 	channelInstanceData->queuedEvents++;
7d74392642 2019-09-13  388: 
7d74392642 2019-09-13  389: 	Tcl_QueueEvent((Tcl_Event *) event, TCL_QUEUE_TAIL);
7d74392642 2019-09-13  390: 
38bed7cee0 2019-09-13  391: 	return;
38bed7cee0 2019-09-13  392: }
38bed7cee0 2019-09-13  393: 
38bed7cee0 2019-09-13  394: static int xvfs_tclfs_seekChannel(ClientData channelInstanceData_p, long offset, int mode, int *errorCodePtr) {
38bed7cee0 2019-09-13  395: 	struct xvfs_tclfs_channel_id *channelInstanceData;
38bed7cee0 2019-09-13  396: 	Tcl_WideInt newOffset, fileSize;
38bed7cee0 2019-09-13  397: 
38bed7cee0 2019-09-13  398: 	channelInstanceData = (struct xvfs_tclfs_channel_id *) channelInstanceData_p;
38bed7cee0 2019-09-13  399: 
38bed7cee0 2019-09-13  400: 	newOffset = channelInstanceData->currentOffset;
38bed7cee0 2019-09-13  401: 	fileSize = channelInstanceData->fileSize;
38bed7cee0 2019-09-13  402: 
38bed7cee0 2019-09-13  403: 	switch (mode) {
38bed7cee0 2019-09-13  404: 		case SEEK_CUR:
38bed7cee0 2019-09-13  405: 			newOffset += offset;
38bed7cee0 2019-09-13  406: 			break;
38bed7cee0 2019-09-13  407: 		case SEEK_SET:
38bed7cee0 2019-09-13  408: 			newOffset = offset;
38bed7cee0 2019-09-13  409: 			break;
38bed7cee0 2019-09-13  410: 		case SEEK_END:
38bed7cee0 2019-09-13  411: 			newOffset = fileSize + offset;
38bed7cee0 2019-09-13  412: 			break;
38bed7cee0 2019-09-13  413: 		default:
38bed7cee0 2019-09-13  414: 			*errorCodePtr = xvfs_errorToErrno(XVFS_RV_ERR_EINVAL);
38bed7cee0 2019-09-13  415: 
38bed7cee0 2019-09-13  416: 			return(-1);
38bed7cee0 2019-09-13  417: 	}
38bed7cee0 2019-09-13  418: 
38bed7cee0 2019-09-13  419: 	/*
38bed7cee0 2019-09-13  420: 	 * We allow users to seek right up to the end of the buffer, but
38bed7cee0 2019-09-13  421: 	 * no further, this way if they want to seek backwards from there
38bed7cee0 2019-09-13  422: 	 * it is possible to do so.
38bed7cee0 2019-09-13  423: 	 */
38bed7cee0 2019-09-13  424: 	if (newOffset < 0 || newOffset > fileSize) {
38bed7cee0 2019-09-13  425: 		*errorCodePtr = xvfs_errorToErrno(XVFS_RV_ERR_EINVAL);
38bed7cee0 2019-09-13  426: 
38bed7cee0 2019-09-13  427: 		return(-1);
38bed7cee0 2019-09-13  428: 	}
38bed7cee0 2019-09-13  429: 
7d74392642 2019-09-13  430: 	if (newOffset != channelInstanceData->currentOffset) {
7d74392642 2019-09-13  431: 		channelInstanceData->eofMarked = 0;
7d74392642 2019-09-13  432: 		channelInstanceData->currentOffset = newOffset;
7d74392642 2019-09-13  433: 	}
38bed7cee0 2019-09-13  434: 
38bed7cee0 2019-09-13  435: 	return(channelInstanceData->currentOffset);
38bed7cee0 2019-09-13  436: }
38bed7cee0 2019-09-13  437: 
38bed7cee0 2019-09-13  438: static void xvfs_tclfs_prepareChannelType(void) {
38bed7cee0 2019-09-13  439: 	xvfs_tclfs_channelType.typeName = "xvfs";
38bed7cee0 2019-09-13  440: 	xvfs_tclfs_channelType.version = TCL_CHANNEL_VERSION_2;
38bed7cee0 2019-09-13  441: 	xvfs_tclfs_channelType.closeProc = xvfs_tclfs_closeChannel;
38bed7cee0 2019-09-13  442: 	xvfs_tclfs_channelType.inputProc = xvfs_tclfs_readChannel;
38bed7cee0 2019-09-13  443: 	xvfs_tclfs_channelType.outputProc = NULL;
38bed7cee0 2019-09-13  444: 	xvfs_tclfs_channelType.watchProc = xvfs_tclfs_watchChannel;
38bed7cee0 2019-09-13  445: 	xvfs_tclfs_channelType.getHandleProc = NULL;
38bed7cee0 2019-09-13  446: 	xvfs_tclfs_channelType.seekProc = xvfs_tclfs_seekChannel;
38bed7cee0 2019-09-13  447: 	xvfs_tclfs_channelType.setOptionProc = NULL;
38bed7cee0 2019-09-13  448: 	xvfs_tclfs_channelType.getOptionProc = NULL;
38bed7cee0 2019-09-13  449: 	xvfs_tclfs_channelType.close2Proc = NULL;
38bed7cee0 2019-09-13  450: 	xvfs_tclfs_channelType.blockModeProc = NULL;
38bed7cee0 2019-09-13  451: 	xvfs_tclfs_channelType.flushProc = NULL;
38bed7cee0 2019-09-13  452: 	xvfs_tclfs_channelType.handlerProc = NULL;
38bed7cee0 2019-09-13  453: 	xvfs_tclfs_channelType.wideSeekProc = NULL;
38bed7cee0 2019-09-13  454: 	xvfs_tclfs_channelType.threadActionProc = NULL;
38bed7cee0 2019-09-13  455: 	xvfs_tclfs_channelType.truncateProc = NULL;
d121970301 2019-05-02  456: }
d121970301 2019-05-02  457: 
d121970301 2019-05-02  458: /*
d121970301 2019-05-02  459:  * Internal Tcl_Filesystem functions, with the appropriate instance info
d121970301 2019-05-02  460:  */
d121970301 2019-05-02  461: static int xvfs_tclfs_pathInFilesystem(Tcl_Obj *path, ClientData *dataPtr, struct xvfs_tclfs_instance_info *instanceInfo) {
d121970301 2019-05-02  462: 	const char *relativePath;
d80c88cee0 2019-09-16  463: 	int retval;
d80c88cee0 2019-09-16  464: 
d80c88cee0 2019-09-16  465: 	XVFS_DEBUG_ENTER;
d80c88cee0 2019-09-16  466: 
d80c88cee0 2019-09-16  467: 	XVFS_DEBUG_PRINTF("Checking to see if path \"%s\" is in the filesystem ...", Tcl_GetString(path));
d80c88cee0 2019-09-16  468: 
d80c88cee0 2019-09-16  469: 	path = xvfs_absolutePath(path);
38bed7cee0 2019-09-13  470: 
d121970301 2019-05-02  471: 	relativePath = xvfs_relativePath(path, instanceInfo);
d80c88cee0 2019-09-16  472: 
d80c88cee0 2019-09-16  473: 	retval = TCL_OK;
d121970301 2019-05-02  474: 	if (!relativePath) {
d80c88cee0 2019-09-16  475: 		retval = -1;
d121970301 2019-05-02  476: 	}
38bed7cee0 2019-09-13  477: 
d80c88cee0 2019-09-16  478: 	Tcl_DecrRefCount(path);
d80c88cee0 2019-09-16  479: 
d80c88cee0 2019-09-16  480: 	XVFS_DEBUG_PRINTF("... %s", retval == -1 ? "no" : "yes");
d80c88cee0 2019-09-16  481: 
d80c88cee0 2019-09-16  482: 	XVFS_DEBUG_LEAVE;
d80c88cee0 2019-09-16  483: 	return(retval);
d121970301 2019-05-02  484: }
d121970301 2019-05-02  485: 
d121970301 2019-05-02  486: static int xvfs_tclfs_stat(Tcl_Obj *path, Tcl_StatBuf *statBuf, struct xvfs_tclfs_instance_info *instanceInfo) {
d121970301 2019-05-02  487: 	const char *pathStr;
d121970301 2019-05-02  488: 	int retval;
d121970301 2019-05-02  489: 
d80c88cee0 2019-09-16  490: 	XVFS_DEBUG_ENTER;
d80c88cee0 2019-09-16  491: 
d80c88cee0 2019-09-16  492: 	XVFS_DEBUG_PRINTF("Getting stat() on \"%s\" ...", Tcl_GetString(path));
d80c88cee0 2019-09-16  493: 
d80c88cee0 2019-09-16  494: 	path = xvfs_absolutePath(path);
d80c88cee0 2019-09-16  495: 
d121970301 2019-05-02  496: 	pathStr = xvfs_relativePath(path, instanceInfo);
38bed7cee0 2019-09-13  497: 
daf25f5222 2019-05-03  498: 	retval = instanceInfo->fsInfo->getStatProc(pathStr, statBuf);
149aa89b7d 2019-09-13  499: 	if (retval < 0) {
d80c88cee0 2019-09-16  500: 		XVFS_DEBUG_PRINTF("... failed: %s", xvfs_perror(retval));
149aa89b7d 2019-09-13  501: 		retval = -1;
d80c88cee0 2019-09-16  502: 	} else {
d80c88cee0 2019-09-16  503: 		XVFS_DEBUG_PUTS("... ok");
149aa89b7d 2019-09-13  504: 	}
38bed7cee0 2019-09-13  505: 
d80c88cee0 2019-09-16  506: 	Tcl_DecrRefCount(path);
d80c88cee0 2019-09-16  507: 
d80c88cee0 2019-09-16  508: 	XVFS_DEBUG_LEAVE;
d121970301 2019-05-02  509: 	return(retval);
d121970301 2019-05-02  510: }
d121970301 2019-05-02  511: 
12ff77016f 2019-09-14  512: static int xvfs_tclfs_access(Tcl_Obj *path, int mode, struct xvfs_tclfs_instance_info *instanceInfo) {
12ff77016f 2019-09-14  513: 	const char *pathStr;
12ff77016f 2019-09-14  514: 	Tcl_StatBuf fileInfo;
12ff77016f 2019-09-14  515: 	int statRetVal;
12ff77016f 2019-09-14  516: 
d80c88cee0 2019-09-16  517: 	XVFS_DEBUG_ENTER;
d80c88cee0 2019-09-16  518: 
d80c88cee0 2019-09-16  519: 	XVFS_DEBUG_PRINTF("Getting access(..., %i) on \"%s\" ...", mode, Tcl_GetString(path));
12ff77016f 2019-09-14  520: 
12ff77016f 2019-09-14  521: 	if (mode & W_OK) {
d80c88cee0 2019-09-16  522: 		XVFS_DEBUG_PUTS("... no (not writable)");
d80c88cee0 2019-09-16  523: 
d80c88cee0 2019-09-16  524: 		XVFS_DEBUG_LEAVE;
d80c88cee0 2019-09-16  525: 		return(-1);
d80c88cee0 2019-09-16  526: 	}
d80c88cee0 2019-09-16  527: 
d80c88cee0 2019-09-16  528: 	path = xvfs_absolutePath(path);
d80c88cee0 2019-09-16  529: 
d80c88cee0 2019-09-16  530: 	pathStr = xvfs_relativePath(path, instanceInfo);
d80c88cee0 2019-09-16  531: 	if (!pathStr) {
d80c88cee0 2019-09-16  532: 		XVFS_DEBUG_PUTS("... no (not in our path)");
d80c88cee0 2019-09-16  533: 
d80c88cee0 2019-09-16  534: 		Tcl_DecrRefCount(path);
d80c88cee0 2019-09-16  535: 
d80c88cee0 2019-09-16  536: 		XVFS_DEBUG_LEAVE;
12ff77016f 2019-09-14  537: 		return(-1);
12ff77016f 2019-09-14  538: 	}
12ff77016f 2019-09-14  539: 
12ff77016f 2019-09-14  540: 	statRetVal = instanceInfo->fsInfo->getStatProc(pathStr, &fileInfo);
12ff77016f 2019-09-14  541: 	if (statRetVal < 0) {
d80c88cee0 2019-09-16  542: 		XVFS_DEBUG_PUTS("... no (not statable)");
d80c88cee0 2019-09-16  543: 
d80c88cee0 2019-09-16  544: 		Tcl_DecrRefCount(path);
d80c88cee0 2019-09-16  545: 
d80c88cee0 2019-09-16  546: 		XVFS_DEBUG_LEAVE;
12ff77016f 2019-09-14  547: 		return(-1);
12ff77016f 2019-09-14  548: 	}
12ff77016f 2019-09-14  549: 
12ff77016f 2019-09-14  550: 	if (mode & X_OK) {
12ff77016f 2019-09-14  551: 		if (!(fileInfo.st_mode & 040000)) {
d80c88cee0 2019-09-16  552: 			XVFS_DEBUG_PUTS("... no (not a directory and X_OK specified)");
d80c88cee0 2019-09-16  553: 
d80c88cee0 2019-09-16  554: 			Tcl_DecrRefCount(path);
d80c88cee0 2019-09-16  555: 
d80c88cee0 2019-09-16  556: 			XVFS_DEBUG_LEAVE;
12ff77016f 2019-09-14  557: 			return(-1);
12ff77016f 2019-09-14  558: 		}
12ff77016f 2019-09-14  559: 	}
12ff77016f 2019-09-14  560: 
d80c88cee0 2019-09-16  561: 	Tcl_DecrRefCount(path);
d80c88cee0 2019-09-16  562: 
d80c88cee0 2019-09-16  563: 	XVFS_DEBUG_PUTS("... ok");
d80c88cee0 2019-09-16  564: 
d80c88cee0 2019-09-16  565: 	XVFS_DEBUG_LEAVE;
12ff77016f 2019-09-14  566: 	return(0);
d121970301 2019-05-02  567: }
d121970301 2019-05-02  568: 
d121970301 2019-05-02  569: 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  570: 	Tcl_Channel retval;
d80c88cee0 2019-09-16  571: 	Tcl_Obj *pathRel;
38bed7cee0 2019-09-13  572: 	const char *pathStr;
38bed7cee0 2019-09-13  573: 
d80c88cee0 2019-09-16  574: 	XVFS_DEBUG_ENTER;
d80c88cee0 2019-09-16  575: 
d80c88cee0 2019-09-16  576: 	XVFS_DEBUG_PRINTF("Asked to open(\"%s\", %x)...", Tcl_GetString(path), mode);
38bed7cee0 2019-09-13  577: 
38bed7cee0 2019-09-13  578: 	if (mode & O_WRONLY) {
d80c88cee0 2019-09-16  579: 		XVFS_DEBUG_PUTS("... failed (asked to open for writing");
d80c88cee0 2019-09-16  580: 
d80c88cee0 2019-09-16  581: 		XVFS_DEBUG_LEAVE;
38bed7cee0 2019-09-13  582: 		return(NULL);
38bed7cee0 2019-09-13  583: 	}
38bed7cee0 2019-09-13  584: 
d80c88cee0 2019-09-16  585: 	path = xvfs_absolutePath(path);
d80c88cee0 2019-09-16  586: 
d80c88cee0 2019-09-16  587: 	pathStr = xvfs_relativePath(path, instanceInfo);
d80c88cee0 2019-09-16  588: 
d80c88cee0 2019-09-16  589: 	pathRel = Tcl_NewStringObj(pathStr, -1);
d80c88cee0 2019-09-16  590: 
d80c88cee0 2019-09-16  591: 	Tcl_DecrRefCount(path);
d80c88cee0 2019-09-16  592: 
d80c88cee0 2019-09-16  593: 	XVFS_DEBUG_PUTS("... done, passing off to channel handler");
d80c88cee0 2019-09-16  594: 
d80c88cee0 2019-09-16  595: 	retval = xvfs_tclfs_openChannel(pathRel, instanceInfo);
d80c88cee0 2019-09-16  596: 
d80c88cee0 2019-09-16  597: 	XVFS_DEBUG_LEAVE;
d80c88cee0 2019-09-16  598: 	return(retval);
5583d77f1c 2019-09-14  599: }
5583d77f1c 2019-09-14  600: 
5583d77f1c 2019-09-14  601: static int xvfs_tclfs_verifyType(Tcl_Obj *path, Tcl_GlobTypeData *types, struct xvfs_tclfs_instance_info *instanceInfo) {
5583d77f1c 2019-09-14  602: 	const char *pathStr;
5583d77f1c 2019-09-14  603: 	Tcl_StatBuf fileInfo;
5583d77f1c 2019-09-14  604: 	int statRetVal;
5583d77f1c 2019-09-14  605: 
d80c88cee0 2019-09-16  606: 	XVFS_DEBUG_ENTER;
d80c88cee0 2019-09-16  607: 
d80c88cee0 2019-09-16  608: 	if (types) {
d80c88cee0 2019-09-16  609: 		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  610: 	} else {
d80c88cee0 2019-09-16  611: 		XVFS_DEBUG_PRINTF("Asked to verify the existence \"%s\" ...", Tcl_GetString(path));
d80c88cee0 2019-09-16  612: 	}
d80c88cee0 2019-09-16  613: 
5583d77f1c 2019-09-14  614: 	statRetVal = xvfs_tclfs_stat(path, &fileInfo, instanceInfo);
5583d77f1c 2019-09-14  615: 	if (statRetVal != 0) {
d80c88cee0 2019-09-16  616: 		XVFS_DEBUG_PUTS("... no (cannot stat)");
d80c88cee0 2019-09-16  617: 
d80c88cee0 2019-09-16  618: 		XVFS_DEBUG_LEAVE;
5583d77f1c 2019-09-14  619: 		return(0);
5583d77f1c 2019-09-14  620: 	}
5583d77f1c 2019-09-14  621: 
5583d77f1c 2019-09-14  622: 	if (!types) {
d80c88cee0 2019-09-16  623: 		XVFS_DEBUG_PUTS("... yes");
d80c88cee0 2019-09-16  624: 
d80c88cee0 2019-09-16  625: 		XVFS_DEBUG_LEAVE;
5583d77f1c 2019-09-14  626: 		return(1);
5583d77f1c 2019-09-14  627: 	}
5583d77f1c 2019-09-14  628: 
5583d77f1c 2019-09-14  629: 	if (types->perm != TCL_GLOB_PERM_RONLY) {
12ff77016f 2019-09-14  630: 		if (types->perm & (TCL_GLOB_PERM_W | TCL_GLOB_PERM_HIDDEN)) {
d80c88cee0 2019-09-16  631: 			XVFS_DEBUG_PUTS("... no (checked for writable or hidden, not supported)");
d80c88cee0 2019-09-16  632: 
d80c88cee0 2019-09-16  633: 			XVFS_DEBUG_LEAVE;
5583d77f1c 2019-09-14  634: 			return(0);
12ff77016f 2019-09-14  635: 		}
12ff77016f 2019-09-14  636: 
12ff77016f 2019-09-14  637: 		if ((types->perm & TCL_GLOB_PERM_X) == TCL_GLOB_PERM_X) {
12ff77016f 2019-09-14  638: 			if (!(fileInfo.st_mode & 040000)) {
d80c88cee0 2019-09-16  639: 				XVFS_DEBUG_PUTS("... no (checked for executable but not a directory)");
d80c88cee0 2019-09-16  640: 
d80c88cee0 2019-09-16  641: 				XVFS_DEBUG_LEAVE;
12ff77016f 2019-09-14  642: 				return(0);
12ff77016f 2019-09-14  643: 			}
5583d77f1c 2019-09-14  644: 		}
5583d77f1c 2019-09-14  645: 	}
5583d77f1c 2019-09-14  646: 
5583d77f1c 2019-09-14  647: 	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  648: 		XVFS_DEBUG_PUTS("... no (checked for block, char, pipe, sock, or link, not supported)");
d80c88cee0 2019-09-16  649: 
d80c88cee0 2019-09-16  650: 		XVFS_DEBUG_LEAVE;
5583d77f1c 2019-09-14  651: 		return(0);
5583d77f1c 2019-09-14  652: 	}
5583d77f1c 2019-09-14  653: 
5583d77f1c 2019-09-14  654: 	if ((types->type & TCL_GLOB_TYPE_DIR) == TCL_GLOB_TYPE_DIR) {
5583d77f1c 2019-09-14  655: 		if (!(fileInfo.st_mode & 040000)) {
d80c88cee0 2019-09-16  656: 			XVFS_DEBUG_PUTS("... no (checked for directory but not a directory)");
d80c88cee0 2019-09-16  657: 
d80c88cee0 2019-09-16  658: 			XVFS_DEBUG_LEAVE;
5583d77f1c 2019-09-14  659: 			return(0);
5583d77f1c 2019-09-14  660: 		}
5583d77f1c 2019-09-14  661: 	}
5583d77f1c 2019-09-14  662: 
5583d77f1c 2019-09-14  663: 	if ((types->type & TCL_GLOB_TYPE_FILE) == TCL_GLOB_TYPE_FILE) {
5583d77f1c 2019-09-14  664: 		if (!(fileInfo.st_mode & 0100000)) {
d80c88cee0 2019-09-16  665: 			XVFS_DEBUG_PUTS("... no (checked for file but not a file)");
d80c88cee0 2019-09-16  666: 
d80c88cee0 2019-09-16  667: 			XVFS_DEBUG_LEAVE;
5583d77f1c 2019-09-14  668: 			return(0);
5583d77f1c 2019-09-14  669: 		}
5583d77f1c 2019-09-14  670: 	}
5583d77f1c 2019-09-14  671: 
5583d77f1c 2019-09-14  672: 	if ((types->type & TCL_GLOB_TYPE_MOUNT) == TCL_GLOB_TYPE_MOUNT) {
d80c88cee0 2019-09-16  673: 		path = xvfs_absolutePath(path);
5583d77f1c 2019-09-14  674: 		pathStr = xvfs_relativePath(path, instanceInfo);
5583d77f1c 2019-09-14  675: 		if (!pathStr) {
d80c88cee0 2019-09-16  676: 			XVFS_DEBUG_PUTS("... no (checked for mount but not able to resolve path)");
d80c88cee0 2019-09-16  677: 
d80c88cee0 2019-09-16  678: 			Tcl_DecrRefCount(path);
d80c88cee0 2019-09-16  679: 
d80c88cee0 2019-09-16  680: 			XVFS_DEBUG_LEAVE;
5583d77f1c 2019-09-14  681: 			return(0);
5583d77f1c 2019-09-14  682: 		}
5583d77f1c 2019-09-14  683: 
5583d77f1c 2019-09-14  684: 		if (strlen(pathStr) != 0) {
d80c88cee0 2019-09-16  685: 			XVFS_DEBUG_PUTS("... no (checked for mount but not our top-level directory)");
d80c88cee0 2019-09-16  686: 
d80c88cee0 2019-09-16  687: 			Tcl_DecrRefCount(path);
d80c88cee0 2019-09-16  688: 
d80c88cee0 2019-09-16  689: 			XVFS_DEBUG_LEAVE;
5583d77f1c 2019-09-14  690: 			return(0);
5583d77f1c 2019-09-14  691: 		}
d80c88cee0 2019-09-16  692: 
d80c88cee0 2019-09-16  693: 		Tcl_DecrRefCount(path);
5583d77f1c 2019-09-14  694: 	}
5583d77f1c 2019-09-14  695: 
d80c88cee0 2019-09-16  696: 	XVFS_DEBUG_PUTS("... yes");
d80c88cee0 2019-09-16  697: 
d80c88cee0 2019-09-16  698: 	XVFS_DEBUG_LEAVE;
5583d77f1c 2019-09-14  699: 	return(1);
5583d77f1c 2019-09-14  700: }
5583d77f1c 2019-09-14  701: 
5583d77f1c 2019-09-14  702: 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  703: 	const char *pathStr;
5583d77f1c 2019-09-14  704: 	const char **children, *child;
5583d77f1c 2019-09-14  705: 	Tcl_WideInt childrenCount, idx;
5583d77f1c 2019-09-14  706: 	Tcl_Obj *childObj;
5583d77f1c 2019-09-14  707: 	int tclRetVal;
5583d77f1c 2019-09-14  708: 
5583d77f1c 2019-09-14  709: 	if (pattern == NULL) {
5583d77f1c 2019-09-14  710: 		if (xvfs_tclfs_verifyType(path, types, instanceInfo)) {
5583d77f1c 2019-09-14  711: 			return(TCL_OK);
5583d77f1c 2019-09-14  712: 		}
5583d77f1c 2019-09-14  713: 
5583d77f1c 2019-09-14  714: 		return(TCL_ERROR);
5583d77f1c 2019-09-14  715: 	}
5583d77f1c 2019-09-14  716: 
d80c88cee0 2019-09-16  717: 	XVFS_DEBUG_ENTER;
d80c88cee0 2019-09-16  718: 
d80c88cee0 2019-09-16  719: 	path = xvfs_absolutePath(path);
d80c88cee0 2019-09-16  720: 
d80c88cee0 2019-09-16  721: 	if (types) {
d80c88cee0 2019-09-16  722: 		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  723: 	} else {
d80c88cee0 2019-09-16  724: 		XVFS_DEBUG_PRINTF("Checking for files matching %s in \"%s\" ...", pattern, Tcl_GetString(path));
d80c88cee0 2019-09-16  725: 	}
d80c88cee0 2019-09-16  726: 
5583d77f1c 2019-09-14  727: 	pathStr = xvfs_relativePath(path, instanceInfo);
5583d77f1c 2019-09-14  728: 	if (!pathStr) {
d80c88cee0 2019-09-16  729: 		XVFS_DEBUG_PUTS("... error (not in our VFS)");
d80c88cee0 2019-09-16  730: 
d80c88cee0 2019-09-16  731: 		Tcl_DecrRefCount(path);
d80c88cee0 2019-09-16  732: 
5583d77f1c 2019-09-14  733: 		if (interp) {
5583d77f1c 2019-09-14  734: 			Tcl_SetResult(interp, (char *) xvfs_perror(XVFS_RV_ERR_ENOENT), NULL);
5583d77f1c 2019-09-14  735: 		}
5583d77f1c 2019-09-14  736: 
d80c88cee0 2019-09-16  737: 		XVFS_DEBUG_LEAVE;
d80c88cee0 2019-09-16  738: 		return(TCL_OK);
5583d77f1c 2019-09-14  739: 	}
5583d77f1c 2019-09-14  740: 
5583d77f1c 2019-09-14  741: 	childrenCount = 0;
5583d77f1c 2019-09-14  742: 	children = instanceInfo->fsInfo->getChildrenProc(pathStr, &childrenCount);
5583d77f1c 2019-09-14  743: 	if (childrenCount < 0) {
d80c88cee0 2019-09-16  744: 		XVFS_DEBUG_PRINTF("... error: %s", xvfs_perror(childrenCount));
d80c88cee0 2019-09-16  745: 
d80c88cee0 2019-09-16  746: 		Tcl_DecrRefCount(path);
d80c88cee0 2019-09-16  747: 
5583d77f1c 2019-09-14  748: 		if (interp) {
5583d77f1c 2019-09-14  749: 			Tcl_SetResult(interp, (char *) xvfs_perror(childrenCount), NULL);
5583d77f1c 2019-09-14  750: 		}
5583d77f1c 2019-09-14  751: 
d80c88cee0 2019-09-16  752: 		XVFS_DEBUG_LEAVE;
5583d77f1c 2019-09-14  753: 		return(TCL_ERROR);
5583d77f1c 2019-09-14  754: 	}
5583d77f1c 2019-09-14  755: 
5583d77f1c 2019-09-14  756: 	for (idx = 0; idx < childrenCount; idx++) {
5583d77f1c 2019-09-14  757: 		child = children[idx];
5583d77f1c 2019-09-14  758: 
5583d77f1c 2019-09-14  759: 		if (!Tcl_StringMatch(child, pattern)) {
5583d77f1c 2019-09-14  760: 			continue;
5583d77f1c 2019-09-14  761: 		}
5583d77f1c 2019-09-14  762: 
5583d77f1c 2019-09-14  763: 		childObj = Tcl_DuplicateObj(path);
5583d77f1c 2019-09-14  764: 		Tcl_IncrRefCount(childObj);
5ae034e55e 2019-09-14  765: 		Tcl_AppendStringsToObj(childObj, "/", child, NULL);
5583d77f1c 2019-09-14  766: 
5583d77f1c 2019-09-14  767: 		if (!xvfs_tclfs_verifyType(childObj, types, instanceInfo)) {
5583d77f1c 2019-09-14  768: 			Tcl_DecrRefCount(childObj);
5583d77f1c 2019-09-14  769: 
5583d77f1c 2019-09-14  770: 			continue;
5583d77f1c 2019-09-14  771: 		}
5583d77f1c 2019-09-14  772: 
5583d77f1c 2019-09-14  773: 		tclRetVal = Tcl_ListObjAppendElement(interp, resultPtr, childObj);
5583d77f1c 2019-09-14  774: 		Tcl_DecrRefCount(childObj);
5583d77f1c 2019-09-14  775: 
5583d77f1c 2019-09-14  776: 		if (tclRetVal != TCL_OK) {
d80c88cee0 2019-09-16  777: 			XVFS_DEBUG_PUTS("... error (lappend)");
d80c88cee0 2019-09-16  778: 			Tcl_DecrRefCount(path);
d80c88cee0 2019-09-16  779: 
d80c88cee0 2019-09-16  780: 			XVFS_DEBUG_LEAVE;
5583d77f1c 2019-09-14  781: 			return(tclRetVal);
5583d77f1c 2019-09-14  782: 		}
5583d77f1c 2019-09-14  783: 	}
5583d77f1c 2019-09-14  784: 
d80c88cee0 2019-09-16  785: 	Tcl_DecrRefCount(path);
d80c88cee0 2019-09-16  786: 
d80c88cee0 2019-09-16  787: 	XVFS_DEBUG_PRINTF("... ok (returning items: %s)", Tcl_GetString(resultPtr));
d80c88cee0 2019-09-16  788: 
d80c88cee0 2019-09-16  789: 	XVFS_DEBUG_LEAVE;
5583d77f1c 2019-09-14  790: 	return(TCL_OK);
d121970301 2019-05-02  791: }
3e44e1def1 2019-05-02  792: #endif /* XVFS_MODE_SERVER || XVFS_MODE_STANDALONE || XVFS_MODE_FLEIXBLE */
d121970301 2019-05-02  793: 
88f96696b7 2019-05-03  794: #if defined(XVFS_MODE_STANDALONE) || defined(XVFS_MODE_FLEXIBLE)
d121970301 2019-05-02  795: /*
d121970301 2019-05-02  796:  * Tcl_Filesystem handlers for the standalone implementation
d121970301 2019-05-02  797:  */
acfc5037c6 2019-05-02  798: static struct xvfs_tclfs_instance_info xvfs_tclfs_standalone_info;
d121970301 2019-05-02  799: static int xvfs_tclfs_standalone_pathInFilesystem(Tcl_Obj *path, ClientData *dataPtr) {
d121970301 2019-05-02  800: 	return(xvfs_tclfs_pathInFilesystem(path, dataPtr, &xvfs_tclfs_standalone_info));
d121970301 2019-05-02  801: }
d121970301 2019-05-02  802: 
d121970301 2019-05-02  803: static int xvfs_tclfs_standalone_stat(Tcl_Obj *path, Tcl_StatBuf *statBuf) {
d121970301 2019-05-02  804: 	return(xvfs_tclfs_stat(path, statBuf, &xvfs_tclfs_standalone_info));
d121970301 2019-05-02  805: }
d121970301 2019-05-02  806: 
12ff77016f 2019-09-14  807: static int xvfs_tclfs_standalone_access(Tcl_Obj *path, int mode) {
12ff77016f 2019-09-14  808: 	return(xvfs_tclfs_access(path, mode, &xvfs_tclfs_standalone_info));
e5b6962adf 2019-05-02  809: }
e5b6962adf 2019-05-02  810: 
d121970301 2019-05-02  811: static Tcl_Channel xvfs_tclfs_standalone_openFileChannel(Tcl_Interp *interp, Tcl_Obj *path, int mode, int permissions) {
d121970301 2019-05-02  812: 	return(xvfs_tclfs_openFileChannel(interp, path, mode, permissions, &xvfs_tclfs_standalone_info));
5583d77f1c 2019-09-14  813: }
5583d77f1c 2019-09-14  814: 
5583d77f1c 2019-09-14  815: 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  816: 	return(xvfs_tclfs_matchInDir(interp, resultPtr, pathPtr, pattern, types, &xvfs_tclfs_standalone_info));
e5b6962adf 2019-05-02  817: }
32b55a907b 2019-05-02  818: 
32b55a907b 2019-05-02  819: /*
32b55a907b 2019-05-02  820:  * There are three (3) modes of operation for Xvfs_Register:
32b55a907b 2019-05-02  821:  *    1. standalone -- We register our own Tcl_Filesystem
32b55a907b 2019-05-02  822:  *                     and handle requests under `//xvfs:/<fsName>`
32b55a907b 2019-05-02  823:  *    2. client -- A single Tcl_Filesystem is registered for the
32b55a907b 2019-05-02  824:  *                 interp to handle requests under `//xvfs:/` which
32b55a907b 2019-05-02  825:  *                 then dispatches to the appropriate registered
32b55a907b 2019-05-02  826:  *                 handler
32b55a907b 2019-05-02  827:  *    3. flexible -- Attempts to find a core Xvfs instance for the
32b55a907b 2019-05-02  828:  *                   process at runtime, if found do #2, otherwise
32b55a907b 2019-05-02  829:  *                   fallback to #1
32b55a907b 2019-05-02  830:  *
32b55a907b 2019-05-02  831:  */
cb77ecfb24 2019-05-06  832: static Tcl_Filesystem xvfs_tclfs_standalone_fs;
b8cca3a6b4 2019-05-08  833: static int xvfs_standalone_register(Tcl_Interp *interp, struct Xvfs_FSInfo *fsInfo) {
e5b6962adf 2019-05-02  834: 	int tcl_ret;
d121970301 2019-05-02  835: 	static int registered = 0;
38bed7cee0 2019-09-13  836: 
d121970301 2019-05-02  837: 	/*
d121970301 2019-05-02  838: 	 * Ensure this instance is not already registered
d121970301 2019-05-02  839: 	 */
d121970301 2019-05-02  840: 	if (registered) {
d121970301 2019-05-02  841: 		return(TCL_OK);
d121970301 2019-05-02  842: 	}
d121970301 2019-05-02  843: 	registered = 1;
d121970301 2019-05-02  844: 
e5b6962adf 2019-05-02  845: 	/*
e5b6962adf 2019-05-02  846: 	 * In standalone mode, we only support the same protocol we are
e5b6962adf 2019-05-02  847: 	 * compiling for.
e5b6962adf 2019-05-02  848: 	 */
e5b6962adf 2019-05-02  849: 	if (fsInfo->protocolVersion != XVFS_PROTOCOL_VERSION) {
e5b6962adf 2019-05-02  850: 		if (interp) {
e5b6962adf 2019-05-02  851: 			Tcl_SetResult(interp, "Protocol mismatch", NULL);
e5b6962adf 2019-05-02  852: 		}
e5b6962adf 2019-05-02  853: 		return(TCL_ERROR);
e5b6962adf 2019-05-02  854: 	}
38bed7cee0 2019-09-13  855: 
cb77ecfb24 2019-05-06  856: 	xvfs_tclfs_standalone_fs.typeName                   = "xvfs";
cb77ecfb24 2019-05-06  857: 	xvfs_tclfs_standalone_fs.structureLength            = sizeof(xvfs_tclfs_standalone_fs);
cb77ecfb24 2019-05-06  858: 	xvfs_tclfs_standalone_fs.version                    = TCL_FILESYSTEM_VERSION_1;
cb77ecfb24 2019-05-06  859: 	xvfs_tclfs_standalone_fs.pathInFilesystemProc       = xvfs_tclfs_standalone_pathInFilesystem;
cb77ecfb24 2019-05-06  860: 	xvfs_tclfs_standalone_fs.dupInternalRepProc         = NULL;
cb77ecfb24 2019-05-06  861: 	xvfs_tclfs_standalone_fs.freeInternalRepProc        = NULL;
cb77ecfb24 2019-05-06  862: 	xvfs_tclfs_standalone_fs.internalToNormalizedProc   = NULL;
cb77ecfb24 2019-05-06  863: 	xvfs_tclfs_standalone_fs.createInternalRepProc      = NULL;
cb77ecfb24 2019-05-06  864: 	xvfs_tclfs_standalone_fs.normalizePathProc          = NULL;
cb77ecfb24 2019-05-06  865: 	xvfs_tclfs_standalone_fs.filesystemPathTypeProc     = NULL;
cb77ecfb24 2019-05-06  866: 	xvfs_tclfs_standalone_fs.filesystemSeparatorProc    = NULL;
cb77ecfb24 2019-05-06  867: 	xvfs_tclfs_standalone_fs.statProc                   = xvfs_tclfs_standalone_stat;
12ff77016f 2019-09-14  868: 	xvfs_tclfs_standalone_fs.accessProc                 = xvfs_tclfs_standalone_access;
cb77ecfb24 2019-05-06  869: 	xvfs_tclfs_standalone_fs.openFileChannelProc        = xvfs_tclfs_standalone_openFileChannel;
5583d77f1c 2019-09-14  870: 	xvfs_tclfs_standalone_fs.matchInDirectoryProc       = xvfs_tclfs_standalone_matchInDir;
cb77ecfb24 2019-05-06  871: 	xvfs_tclfs_standalone_fs.utimeProc                  = NULL;
cb77ecfb24 2019-05-06  872: 	xvfs_tclfs_standalone_fs.linkProc                   = NULL;
d80c88cee0 2019-09-16  873: 	xvfs_tclfs_standalone_fs.listVolumesProc            = NULL;
cb77ecfb24 2019-05-06  874: 	xvfs_tclfs_standalone_fs.fileAttrStringsProc        = NULL;
cb77ecfb24 2019-05-06  875: 	xvfs_tclfs_standalone_fs.fileAttrsGetProc           = NULL;
cb77ecfb24 2019-05-06  876: 	xvfs_tclfs_standalone_fs.fileAttrsSetProc           = NULL;
cb77ecfb24 2019-05-06  877: 	xvfs_tclfs_standalone_fs.createDirectoryProc        = NULL;
cb77ecfb24 2019-05-06  878: 	xvfs_tclfs_standalone_fs.removeDirectoryProc        = NULL;
cb77ecfb24 2019-05-06  879: 	xvfs_tclfs_standalone_fs.deleteFileProc             = NULL;
cb77ecfb24 2019-05-06  880: 	xvfs_tclfs_standalone_fs.copyFileProc               = NULL;
cb77ecfb24 2019-05-06  881: 	xvfs_tclfs_standalone_fs.renameFileProc             = NULL;
cb77ecfb24 2019-05-06  882: 	xvfs_tclfs_standalone_fs.copyDirectoryProc          = NULL;
cb77ecfb24 2019-05-06  883: 	xvfs_tclfs_standalone_fs.lstatProc                  = NULL;
cb77ecfb24 2019-05-06  884: 	xvfs_tclfs_standalone_fs.loadFileProc               = NULL;
cb77ecfb24 2019-05-06  885: 	xvfs_tclfs_standalone_fs.getCwdProc                 = NULL;
cb77ecfb24 2019-05-06  886: 	xvfs_tclfs_standalone_fs.chdirProc                  = NULL;
d121970301 2019-05-02  887: 
d121970301 2019-05-02  888: 	xvfs_tclfs_standalone_info.fsInfo = fsInfo;
d121970301 2019-05-02  889: 	xvfs_tclfs_standalone_info.mountpoint = Tcl_NewObj();
5ae034e55e 2019-09-14  890: 
5ae034e55e 2019-09-14  891: 	Tcl_IncrRefCount(xvfs_tclfs_standalone_info.mountpoint);
d121970301 2019-05-02  892: 	Tcl_AppendStringsToObj(xvfs_tclfs_standalone_info.mountpoint, XVFS_ROOT_MOUNTPOINT, fsInfo->name, NULL);
5ae034e55e 2019-09-14  893: 	
cb77ecfb24 2019-05-06  894: 	tcl_ret = Tcl_FSRegister(NULL, &xvfs_tclfs_standalone_fs);
e5b6962adf 2019-05-02  895: 	if (tcl_ret != TCL_OK) {
5ae034e55e 2019-09-14  896: 		Tcl_DecrRefCount(xvfs_tclfs_standalone_info.mountpoint);
5ae034e55e 2019-09-14  897: 
e5b6962adf 2019-05-02  898: 		if (interp) {
e5b6962adf 2019-05-02  899: 			Tcl_SetResult(interp, "Tcl_FSRegister() failed", NULL);
e5b6962adf 2019-05-02  900: 		}
38bed7cee0 2019-09-13  901: 
e5b6962adf 2019-05-02  902: 		return(tcl_ret);
e5b6962adf 2019-05-02  903: 	}
38bed7cee0 2019-09-13  904: 
38bed7cee0 2019-09-13  905: 	xvfs_tclfs_prepareChannelType();
38bed7cee0 2019-09-13  906: 
e5b6962adf 2019-05-02  907: 	return(TCL_OK);
e5b6962adf 2019-05-02  908: }
d92ba3d36d 2019-05-08  909: #endif /* XVFS_MODE_STANDALONE || XVFS_MODE_FLEXIBLE */
88f96696b7 2019-05-03  910: 
88f96696b7 2019-05-03  911: #if defined(XVFS_MODE_FLEXIBLE)
b8cca3a6b4 2019-05-08  912: static int xvfs_flexible_register(Tcl_Interp *interp, struct Xvfs_FSInfo *fsInfo) {
9bcf758fef 2019-05-08  913: 	ClientData fsHandlerDataRaw;
9bcf758fef 2019-05-08  914: 	struct xvfs_tclfs_server_info *fsHandlerData;
9bcf758fef 2019-05-08  915: 	const Tcl_Filesystem *fsHandler;
9bcf758fef 2019-05-08  916: 	int (*xvfs_register)(Tcl_Interp *interp, struct Xvfs_FSInfo *fsInfo);
9bcf758fef 2019-05-08  917: 	Tcl_Obj *rootPathObj;
9bcf758fef 2019-05-08  918: 
9bcf758fef 2019-05-08  919: 	xvfs_register = &xvfs_standalone_register;
9bcf758fef 2019-05-08  920: 
9bcf758fef 2019-05-08  921: 	rootPathObj = Tcl_NewStringObj(XVFS_ROOT_MOUNTPOINT, -1);
9bcf758fef 2019-05-08  922: 	if (!rootPathObj) {
9bcf758fef 2019-05-08  923: 		return(xvfs_register(interp, fsInfo));
9bcf758fef 2019-05-08  924: 	}
9bcf758fef 2019-05-08  925: 
9bcf758fef 2019-05-08  926: 	Tcl_IncrRefCount(rootPathObj);
9bcf758fef 2019-05-08  927: 	fsHandler = Tcl_FSGetFileSystemForPath(rootPathObj);
9bcf758fef 2019-05-08  928: 	Tcl_DecrRefCount(rootPathObj);
9bcf758fef 2019-05-08  929: 
9bcf758fef 2019-05-08  930: 	if (!fsHandler) {
9bcf758fef 2019-05-08  931: 		return(xvfs_register(interp, fsInfo));
9bcf758fef 2019-05-08  932: 	}
9bcf758fef 2019-05-08  933: 
9bcf758fef 2019-05-08  934: 	fsHandlerDataRaw = Tcl_FSData(fsHandler);
9bcf758fef 2019-05-08  935: 	if (!fsHandlerDataRaw) {
9bcf758fef 2019-05-08  936: 		return(xvfs_register(interp, fsInfo));
9bcf758fef 2019-05-08  937: 	}
9bcf758fef 2019-05-08  938: 
9bcf758fef 2019-05-08  939: 	fsHandlerData = (struct xvfs_tclfs_server_info *) fsHandlerDataRaw;
88f96696b7 2019-05-03  940: 
88f96696b7 2019-05-03  941: 	/*
9bcf758fef 2019-05-08  942: 	 * XXX:TODO: What is the chance that the handler for //xvfs:/ hold
b586d5b0a1 2019-05-08  943: 	 * client data smaller than XVFS_INTERNAL_SERVER_MAGIC_LEN ?
88f96696b7 2019-05-03  944: 	 */
b586d5b0a1 2019-05-08  945: 	if (memcmp(fsHandlerData->magic, XVFS_INTERNAL_SERVER_MAGIC, sizeof(fsHandlerData->magic)) == 0) {
9bcf758fef 2019-05-08  946: 		xvfs_register = fsHandlerData->registerProc;
88f96696b7 2019-05-03  947: 	}
9bcf758fef 2019-05-08  948: 
88f96696b7 2019-05-03  949: 	return(xvfs_register(interp, fsInfo));
88f96696b7 2019-05-03  950: }
d92ba3d36d 2019-05-08  951: #endif /* XVFS_MODE_FLEXIBLE */
3e44e1def1 2019-05-02  952: 
3e44e1def1 2019-05-02  953: #if defined(XVFS_MODE_SERVER)
e5b6962adf 2019-05-02  954: int Xvfs_Register(Tcl_Interp *interp, struct Xvfs_FSInfo *fsInfo) {
acfc5037c6 2019-05-02  955: 	return(TCL_ERROR);
69e476dcd5 2019-05-02  956: }
d92ba3d36d 2019-05-08  957: #endif /* XVFS_MODE_SERVER */