Check-in [9bcf758fef]
Overview
Comment:Use Tcl filesystem data to pass around a pointer to the central register proc
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 9bcf758fef4823aa3e8d4597e4ca97980bdf0081b11a979c2d4dacd2712cbec3
User & Date: rkeene on 2019-05-08 16:26:05
Other Links: manifest | tags
Context
2019-05-08
16:46
Cleanup check-in: d92ba3d36d user: rkeene tags: trunk
16:26
Use Tcl filesystem data to pass around a pointer to the central register proc check-in: 9bcf758fef user: rkeene tags: trunk
2019-05-06
16:34
Switched to static allocation for the standalone Tcl_Filesystem check-in: cb77ecfb24 user: rkeene tags: trunk
Changes

Modified Makefile from [083522c323] to [1a2e05ec17].

1
2
3
4

5
6
7
8
9
10
11
1
2
3

4
5
6
7
8
9
10
11



-
+







CPPFLAGS := -I. -DUSE_TCL_STUBS=1 -DXVFS_MODE_FLEXIBLE
CFLAGS   := -fPIC -g3 -ggdb3 -Wall
LDFLAGS  :=
LIBS     := -ltclstub8.6 -ldl
LIBS     := -ltclstub8.6

all: example.so

example.c: $(shell find example -type f) $(shell find lib -type f) xvfs.c.rvt xvfs-create Makefile
	./xvfs-create --directory example --name example > example.c.new
	mv example.c.new example.c

Modified xvfs-core.c from [5b94c341c4] to [c526fca0fb].

181
182
183
184
185
186
187
188
189
190








191



192


193






















194
195


196
197
198


199
200
201

202
203
204
205
206
207
208
181
182
183
184
185
186
187
188


189
190
191
192
193
194
195
196
197
198
199
200

201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226

227
228
229


230
231

232

233
234
235
236
237
238
239
240








-
-
+
+
+
+
+
+
+
+

+
+
+
-
+
+

+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

-
+
+

-
-
+
+
-

-
+







		
		return(tcl_ret);
	}
	
	return(TCL_OK);
}
#endif

#if defined(XVFS_MODE_FLEXIBLE)
#include <dlfcn.h>
#if defined(XVFS_MODE_FLEXIBLE) || defined(XVFS_MODE_SERVER)
struct xvfs_tclfs_server_info {
	char magic[XVFS_PROTOCOL_SERVER_MAGIC_LEN];
	int (*registerProc)(Tcl_Interp *interp, struct Xvfs_FSInfo *fsInfo);
};
#endif

#if defined(XVFS_MODE_FLEXIBLE)
int xvfs_flexible_register(Tcl_Interp *interp, struct Xvfs_FSInfo *fsInfo) {
	ClientData fsHandlerDataRaw;
	struct xvfs_tclfs_server_info *fsHandlerData;
	const Tcl_Filesystem *fsHandler;
	int (*xvfs_register)(Tcl_Interp *interp, struct Xvfs_FSInfo *fsInfo) = NULL;
	int (*xvfs_register)(Tcl_Interp *interp, struct Xvfs_FSInfo *fsInfo);
	Tcl_Obj *rootPathObj;

	xvfs_register = &xvfs_standalone_register;

	rootPathObj = Tcl_NewStringObj(XVFS_ROOT_MOUNTPOINT, -1);
	if (!rootPathObj) {
		return(xvfs_register(interp, fsInfo));
	}

	Tcl_IncrRefCount(rootPathObj);
	fsHandler = Tcl_FSGetFileSystemForPath(rootPathObj);
	Tcl_DecrRefCount(rootPathObj);

	if (!fsHandler) {
		return(xvfs_register(interp, fsInfo));
	}

	fsHandlerDataRaw = Tcl_FSData(fsHandler);
	if (!fsHandlerDataRaw) {
		return(xvfs_register(interp, fsInfo));
	}

	fsHandlerData = (struct xvfs_tclfs_server_info *) fsHandlerDataRaw;

	/*
	 * XXX:TODO: Find some way to use Tcl_FindSymbol() to do this
	 * XXX:TODO: What is the chance that the handler for //xvfs:/ hold
	 * client data smaller than XVFS_PROTOCOL_SERVER_MAGIC_LEN ?
	 */
	xvfs_register = dlsym(NULL, "Xvfs_Register");
	if (!xvfs_register) {
	if (memcmp(fsHandlerData->magic, XVFS_PROTOCOL_SERVER_MAGIC, sizeof(fsHandlerData->magic)) == 0) {
		xvfs_register = fsHandlerData->registerProc;
		xvfs_register = &xvfs_standalone_register;
	}
	

	return(xvfs_register(interp, fsInfo));
}
#endif

#if defined(XVFS_MODE_SERVER)
int Xvfs_Register(Tcl_Interp *interp, struct Xvfs_FSInfo *fsInfo) {
	return(TCL_ERROR);

Modified xvfs-core.h from [490b145452] to [21ceadd8e9].

1
2
3
4
5
6


7
8
9
10
11
12
13
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15






+
+







#ifndef XVFS_CORE_H_1B4B28D60EBAA11D5FF85642FA7CA22C29E8E817
#define XVFS_CORE_H_1B4B28D60EBAA11D5FF85642FA7CA22C29E8E817 1

#include <tcl.h>

#define XVFS_PROTOCOL_VERSION 1
#define XVFS_PROTOCOL_SERVER_MAGIC "\xD4\xF3\x05\x96\x25\xCF\xAF\xFE"
#define XVFS_PROTOCOL_SERVER_MAGIC_LEN 8

typedef const char **(*xvfs_proc_getChildren_t)(const char *path, Tcl_WideInt *count);
typedef const unsigned char *(*xvfs_proc_getData_t)(const char *path, Tcl_WideInt start, Tcl_WideInt *length);
typedef int (*xvfs_proc_getStat_t)(const char *path, Tcl_StatBuf *statBuf);

struct Xvfs_FSInfo {
	int                      protocolVersion;