Diff

Differences From Artifact [514749566d]:

To Artifact [0880d8a507]:


23
24
25
26
27
28
29


30
31
32
33
34
35
36
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38







+
+








#if defined(XVFS_MODE_FLEXIBLE) || defined(XVFS_MODE_SERVER)
#define XVFS_INTERNAL_SERVER_MAGIC "\xD4\xF3\x05\x96\x25\xCF\xAF\xFE"
#define XVFS_INTERNAL_SERVER_MAGIC_LEN 8

struct xvfs_tclfs_server_info {
	char magic[XVFS_INTERNAL_SERVER_MAGIC_LEN];
	int protocolVersion;
	const char *rootMountpoint;
	int (*registerProc)(Tcl_Interp *interp, struct Xvfs_FSInfo *fsInfo);
};
#endif /* XVFS_MODE_FLEXIBLE || XVFS_MODE_SERVER */

#if defined(XVFS_MODE_SERVER) || defined(XVFS_MODE_STANDALONE) || defined(XVFS_MODE_FLEXIBLE)
#ifndef XVFS_ROOT_MOUNTPOINT
#  define XVFS_ROOT_MOUNTPOINT "//xvfs:/"
978
979
980
981
982
983
984




985
986















987
988
989
990
991
992
993
994
995
996
997
998
999
1000

1001
1002
1003
1004
1005
1006
1007
980
981
982
983
984
985
986
987
988
989
990


991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018

1019
1020
1021
1022
1023
1024
1025
1026







+
+
+
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+













-
+







	fsHandlerData = (struct xvfs_tclfs_server_info *) fsHandlerDataRaw;

	/*
	 * XXX:TODO: What is the chance that the handler for //xvfs:/ hold
	 * client data smaller than XVFS_INTERNAL_SERVER_MAGIC_LEN ?
	 */
	if (memcmp(fsHandlerData->magic, XVFS_INTERNAL_SERVER_MAGIC, sizeof(fsHandlerData->magic)) == 0) {
		/*
		 * Refuse to talk to the in-core implementation if it is a lower
		 * version.
		 */
		XVFS_DEBUG_PUTS("Found a server handler");
		xvfs_register = fsHandlerData->registerProc;
		XVFS_DEBUG_PUTS("Found a server handler, checking for compatible version");
		if (fsHandlerData->protocolVersion >= XVFS_PROTOCOL_VERSION) {
			XVFS_DEBUG_PUTS("Found a server handler with a compatible version, checking for compatible root");
			if (strcmp(XVFS_ROOT_MOUNTPOINT, fsHandlerData->rootMountpoint) == 0) {
				XVFS_DEBUG_PUTS("Found a server handler with a compatible version and checking for compatible root");

				xvfs_register = fsHandlerData->registerProc;
			}
		}
	}

	if (xvfs_register == &xvfs_standalone_register) {
		XVFS_DEBUG_PUTS("Using xvfs_standalone_register");
	} else {
		XVFS_DEBUG_PUTS("Using Xvfs_Register from Xvfs Server Core");
	}

	XVFS_DEBUG_LEAVE;

	return(xvfs_register(interp, fsInfo));
}
#endif /* XVFS_MODE_FLEXIBLE */

#if defined(XVFS_MODE_SERVER)
static Tcl_Filesystem xvfs_tclfs_dispatch_fs;
static Tcl_HashTable xvfs_tclfs_dispatch_map;
static struct xvfs_tclfs_server_info xvfs_tclfs_dispatch_fsdata;

static int xvfs_tclfs_dispatch_pathInFS(Tcl_Obj *path, ClientData *dataPtr) {
static int xvfs_tclfs_dispatch_pathInXVFS(Tcl_Obj *path) {
	const char *pathStr, *rootStr;
	int pathLen, rootLen;

	XVFS_DEBUG_ENTER;

	XVFS_DEBUG_PRINTF("Verifying that \"%s\" belongs in XVFS ...", Tcl_GetString(path));

1043
1044
1045
1046
1047
1048
1049
1050

1051
1052
1053
1054
1055
1056
1057
1062
1063
1064
1065
1066
1067
1068

1069
1070
1071
1072
1073
1074
1075
1076







-
+







	int rootLen;
	char *pathStr, *fsName, *fsNameEnds, origSep;

	XVFS_DEBUG_ENTER;

	path = xvfs_absolutePath(path);

	if (xvfs_tclfs_dispatch_pathInFS(path, NULL) != TCL_OK) {
	if (xvfs_tclfs_dispatch_pathInXVFS(path) != TCL_OK) {
		Tcl_DecrRefCount(path);

		XVFS_DEBUG_LEAVE;

		return(NULL);
	}

1091
1092
1093
1094
1095
1096
1097











1098
1099
1100
1101
1102
1103
1104
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134







+
+
+
+
+
+
+
+
+
+
+







	 * UNREACH: We do no need the more specific check because we
	 * claim everything under the root, but we want to suppress
	 * a warning about it not being used.
	 */
	xvfs_tclfs_pathInFilesystem(NULL, NULL, NULL);
	return(NULL);
}

static int xvfs_tclfs_dispatch_pathInFS(Tcl_Obj *path, ClientData *dataPtr) {
	struct xvfs_tclfs_instance_info *instanceInfo;

	instanceInfo = xvfs_tclfs_dispatch_pathToInfo(path);
	if (!instanceInfo) {
		return(-1);
	}

	return(TCL_OK);
}

static int xvfs_tclfs_dispatch_stat(Tcl_Obj *path, Tcl_StatBuf *statBuf) {
	struct xvfs_tclfs_instance_info *instanceInfo;

	instanceInfo = xvfs_tclfs_dispatch_pathToInfo(path);
	if (!instanceInfo) {
		Tcl_SetErrno(xvfs_errorToErrno(XVFS_RV_ERR_ENOENT));
1192
1193
1194
1195
1196
1197
1198
1199



1200
1201
1202
1203
1204
1205
1206
1222
1223
1224
1225
1226
1227
1228

1229
1230
1231
1232
1233
1234
1235
1236
1237
1238







-
+
+
+







	xvfs_tclfs_dispatch_fs.copyDirectoryProc          = NULL;
	xvfs_tclfs_dispatch_fs.lstatProc                  = NULL;
	xvfs_tclfs_dispatch_fs.loadFileProc               = NULL;
	xvfs_tclfs_dispatch_fs.getCwdProc                 = NULL;
	xvfs_tclfs_dispatch_fs.chdirProc                  = NULL;

	memcpy(xvfs_tclfs_dispatch_fsdata.magic, XVFS_INTERNAL_SERVER_MAGIC, XVFS_INTERNAL_SERVER_MAGIC_LEN);
	xvfs_tclfs_dispatch_fsdata.registerProc = Xvfs_Register;
	xvfs_tclfs_dispatch_fsdata.registerProc    = Xvfs_Register;
	xvfs_tclfs_dispatch_fsdata.protocolVersion = XVFS_PROTOCOL_VERSION;
	xvfs_tclfs_dispatch_fsdata.rootMountpoint  = XVFS_ROOT_MOUNTPOINT;

	tclRet = Tcl_FSRegister((ClientData) &xvfs_tclfs_dispatch_fsdata, &xvfs_tclfs_dispatch_fs);
	if (tclRet != TCL_OK) {
		if (interp) {
			Tcl_SetResult(interp, "Tcl_FSRegister() failed", NULL);
		}