Annotation For xvfs-core.c

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

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