Diff

Differences From Artifact [ecbc07c77d]:

To Artifact [20368f703a]:


167
168
169
170
171
172
173











174
175
176
177
178
179
180
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
			return(Tcl_ErrnoMsg(xvfs_errorToErrno(xvfs_error)));
		case XVFS_RV_ERR_INTERNAL:
			return("Internal error");
		default:
			return("Unknown error");
	}
}












/*
 * Xvfs Memory Channel
 */
struct xvfs_tclfs_channel_id {
	Tcl_Channel channel;
	struct xvfs_tclfs_instance_info *fsInstanceInfo;
	Tcl_Obj *path;
	Tcl_WideInt currentOffset;
	Tcl_WideInt fileSize;
	int eofMarked;
	int queuedEvents;
	int closed;
};
struct xvfs_tclfs_channel_event {
	Tcl_Event tcl;
	struct xvfs_tclfs_channel_id *channelInstanceData;
};
static Tcl_ChannelType xvfs_tclfs_channelType;

static Tcl_Channel xvfs_tclfs_openChannel(Tcl_Obj *path, struct xvfs_tclfs_instance_info *instanceInfo) {
	struct xvfs_tclfs_channel_id *channelInstanceData;
	Tcl_Channel channel;
	Tcl_StatBuf fileInfo;
	Tcl_Obj *channelName;
	int statRet;

	XVFS_DEBUG_ENTER;
	XVFS_DEBUG_PRINTF("Opening file \"%s\" ...", Tcl_GetString(path));

	statRet = instanceInfo->fsInfo->getStatProc(Tcl_GetString(path), &fileInfo);
	if (statRet < 0) {
		XVFS_DEBUG_PRINTF("... failed: %s", xvfs_perror(statRet));












		XVFS_DEBUG_LEAVE;
		return(NULL);
	}

	channelInstanceData = (struct xvfs_tclfs_channel_id *) Tcl_Alloc(sizeof(*channelInstanceData));
	channelInstanceData->currentOffset = 0;







>
>
>
>
>
>
>
>
>
>
>




















|












>
>
>
>
>
>
>
>
>
>
>







167
168
169
170
171
172
173
174
175
176
177
178
179
180
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
			return(Tcl_ErrnoMsg(xvfs_errorToErrno(xvfs_error)));
		case XVFS_RV_ERR_INTERNAL:
			return("Internal error");
		default:
			return("Unknown error");
	}
}

static void xvfs_setresults_error(Tcl_Interp *interp, int xvfs_error) {
	if (!interp) {
		return;
	}

	Tcl_SetErrno(xvfs_errorToErrno(xvfs_error));
	Tcl_SetResult(interp, (char *) xvfs_perror(xvfs_error), NULL);

	return;
}

/*
 * Xvfs Memory Channel
 */
struct xvfs_tclfs_channel_id {
	Tcl_Channel channel;
	struct xvfs_tclfs_instance_info *fsInstanceInfo;
	Tcl_Obj *path;
	Tcl_WideInt currentOffset;
	Tcl_WideInt fileSize;
	int eofMarked;
	int queuedEvents;
	int closed;
};
struct xvfs_tclfs_channel_event {
	Tcl_Event tcl;
	struct xvfs_tclfs_channel_id *channelInstanceData;
};
static Tcl_ChannelType xvfs_tclfs_channelType;

static Tcl_Channel xvfs_tclfs_openChannel(Tcl_Interp *interp, Tcl_Obj *path, struct xvfs_tclfs_instance_info *instanceInfo) {
	struct xvfs_tclfs_channel_id *channelInstanceData;
	Tcl_Channel channel;
	Tcl_StatBuf fileInfo;
	Tcl_Obj *channelName;
	int statRet;

	XVFS_DEBUG_ENTER;
	XVFS_DEBUG_PRINTF("Opening file \"%s\" ...", Tcl_GetString(path));

	statRet = instanceInfo->fsInfo->getStatProc(Tcl_GetString(path), &fileInfo);
	if (statRet < 0) {
		XVFS_DEBUG_PRINTF("... failed: %s", xvfs_perror(statRet));

		xvfs_setresults_error(interp, XVFS_RV_ERR_ENOENT);

		XVFS_DEBUG_LEAVE;
		return(NULL);
	}

	if (fileInfo.st_mode & 040000) {
		XVFS_DEBUG_PUTS("... failed (cannot open directories)");

		xvfs_setresults_error(interp, XVFS_RV_ERR_EISDIR);

		XVFS_DEBUG_LEAVE;
		return(NULL);
	}

	channelInstanceData = (struct xvfs_tclfs_channel_id *) Tcl_Alloc(sizeof(*channelInstanceData));
	channelInstanceData->currentOffset = 0;
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
	XVFS_DEBUG_ENTER;

	XVFS_DEBUG_PRINTF("Asked to open(\"%s\", %x)...", Tcl_GetString(path), mode);

	if (mode & O_WRONLY) {
		XVFS_DEBUG_PUTS("... failed (asked to open for writing)");

		if (interp) {
			Tcl_SetErrno(xvfs_errorToErrno(XVFS_RV_ERR_EROFS));
			Tcl_SetResult(interp, (char *) Tcl_PosixError(interp), NULL);
		}

		XVFS_DEBUG_LEAVE;
		return(NULL);
	}

	path = xvfs_absolutePath(path);

	pathStr = xvfs_relativePath(path, instanceInfo);

	pathRel = Tcl_NewStringObj(pathStr, -1);

	Tcl_DecrRefCount(path);

	XVFS_DEBUG_PUTS("... done, passing off to channel handler");

	retval = xvfs_tclfs_openChannel(pathRel, instanceInfo);

	XVFS_DEBUG_LEAVE;
	return(retval);
}

static int xvfs_tclfs_verifyType(Tcl_Obj *path, Tcl_GlobTypeData *types, struct xvfs_tclfs_instance_info *instanceInfo) {
	const char *pathStr;







<
|
<
<















|







595
596
597
598
599
600
601

602


603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
	XVFS_DEBUG_ENTER;

	XVFS_DEBUG_PRINTF("Asked to open(\"%s\", %x)...", Tcl_GetString(path), mode);

	if (mode & O_WRONLY) {
		XVFS_DEBUG_PUTS("... failed (asked to open for writing)");


		xvfs_setresults_error(interp, XVFS_RV_ERR_EROFS);



		XVFS_DEBUG_LEAVE;
		return(NULL);
	}

	path = xvfs_absolutePath(path);

	pathStr = xvfs_relativePath(path, instanceInfo);

	pathRel = Tcl_NewStringObj(pathStr, -1);

	Tcl_DecrRefCount(path);

	XVFS_DEBUG_PUTS("... done, passing off to channel handler");

	retval = xvfs_tclfs_openChannel(interp, pathRel, instanceInfo);

	XVFS_DEBUG_LEAVE;
	return(retval);
}

static int xvfs_tclfs_verifyType(Tcl_Obj *path, Tcl_GlobTypeData *types, struct xvfs_tclfs_instance_info *instanceInfo) {
	const char *pathStr;
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761

	pathStr = xvfs_relativePath(path, instanceInfo);
	if (!pathStr) {
		XVFS_DEBUG_PUTS("... error (not in our VFS)");

		Tcl_DecrRefCount(path);

		if (interp) {
			Tcl_SetResult(interp, (char *) xvfs_perror(XVFS_RV_ERR_ENOENT), NULL);
		}

		XVFS_DEBUG_LEAVE;
		return(TCL_OK);
	}

	childrenCount = 0;
	children = instanceInfo->fsInfo->getChildrenProc(pathStr, &childrenCount);
	if (childrenCount < 0) {
		XVFS_DEBUG_PRINTF("... error: %s", xvfs_perror(childrenCount));

		Tcl_DecrRefCount(path);

		if (interp) {
			Tcl_SetResult(interp, (char *) xvfs_perror(childrenCount), NULL);
		}

		XVFS_DEBUG_LEAVE;
		return(TCL_ERROR);
	}

	for (idx = 0; idx < childrenCount; idx++) {
		child = children[idx];







<
|
<












<
|
<







749
750
751
752
753
754
755

756

757
758
759
760
761
762
763
764
765
766
767
768

769

770
771
772
773
774
775
776

	pathStr = xvfs_relativePath(path, instanceInfo);
	if (!pathStr) {
		XVFS_DEBUG_PUTS("... error (not in our VFS)");

		Tcl_DecrRefCount(path);


		xvfs_setresults_error(interp, XVFS_RV_ERR_ENOENT);


		XVFS_DEBUG_LEAVE;
		return(TCL_OK);
	}

	childrenCount = 0;
	children = instanceInfo->fsInfo->getChildrenProc(pathStr, &childrenCount);
	if (childrenCount < 0) {
		XVFS_DEBUG_PRINTF("... error: %s", xvfs_perror(childrenCount));

		Tcl_DecrRefCount(path);


		xvfs_setresults_error(interp, childrenCount);


		XVFS_DEBUG_LEAVE;
		return(TCL_ERROR);
	}

	for (idx = 0; idx < childrenCount; idx++) {
		child = children[idx];