Diff

Differences From Artifact [acc58f104b]:

To Artifact [49217ccb09]:


197
198
199
200
201
202
203
204

205
206
207
208
209
210
211
197
198
199
200
201
202
203

204
205
206
207
208
209
210
211







-
+








/*
 * Xvfs Memory Channel
 */
struct xvfs_tclfs_channel_id {
	Tcl_Channel channel;
	struct xvfs_tclfs_instance_info *fsInstanceInfo;
	Tcl_Obj *path;
	long inode;
	Tcl_WideInt currentOffset;
	Tcl_WideInt fileSize;
	int eofMarked;
	int queuedEvents;
	int closed;
};
struct xvfs_tclfs_channel_event {
220
221
222
223
224
225
226
227

228
229
230
231
232
233
234
220
221
222
223
224
225
226

227
228
229
230
231
232
233
234







-
+







	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);
	statRet = instanceInfo->fsInfo->getStatProc(Tcl_GetString(path), XVFS_INODE_NULL, &fileInfo);
	if (statRet < 0) {
		XVFS_DEBUG_PRINTF("... failed: %s", xvfs_strerror(statRet));

		xvfs_setresults_error(interp, XVFS_RV_ERR_ENOENT);

		XVFS_DEBUG_LEAVE;
		return(NULL);
245
246
247
248
249
250
251

252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266


267
268
269
270
271
272
273







+














-
-








	channelInstanceData = (struct xvfs_tclfs_channel_id *) Tcl_Alloc(sizeof(*channelInstanceData));
	channelInstanceData->currentOffset = 0;
	channelInstanceData->eofMarked = 0;
	channelInstanceData->queuedEvents = 0;
	channelInstanceData->closed = 0;
	channelInstanceData->channel = NULL;
	channelInstanceData->inode = fileInfo.st_ino;

	channelName = Tcl_ObjPrintf("xvfs0x%llx", (unsigned long long) channelInstanceData);
	if (!channelName) {
		XVFS_DEBUG_PUTS("... failed");

		Tcl_Free((char *) channelInstanceData);

		XVFS_DEBUG_LEAVE;
		return(NULL);
	}
	Tcl_IncrRefCount(channelName);

	channelInstanceData->fsInstanceInfo = instanceInfo;
	channelInstanceData->fileSize = fileInfo.st_size;
	channelInstanceData->path = path;
	Tcl_IncrRefCount(path);

	channel = Tcl_CreateChannel(&xvfs_tclfs_channelType, Tcl_GetString(channelName), channelInstanceData, TCL_READABLE);
	Tcl_DecrRefCount(channelName);
	if (!channel) {
		XVFS_DEBUG_PUTS("... failed");

		Tcl_DecrRefCount(path);
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344

345
346
347
348
349
350
351
352
353
354
355
356

357
358
359
360

361
362
363
364
365
366
367
323
324
325
326
327
328
329

330
331
332
333
334
335
336
337
338
339
340
341

342
343
344
345
346
347
348
349
350
351
352
353

354
355
356
357

358
359
360
361
362
363
364
365







-












-
+











-
+



-
+








		Tcl_QueueEvent((Tcl_Event *) event, TCL_QUEUE_TAIL);

		XVFS_DEBUG_LEAVE;
		return(0);
	}

	Tcl_DecrRefCount(channelInstanceData->path);
	Tcl_Free((char *) channelInstanceData);

	XVFS_DEBUG_PUTS("... ok");

	XVFS_DEBUG_LEAVE;
	return(0);
}

static int xvfs_tclfs_readChannel(ClientData channelInstanceData_p, char *buf, int bufSize, int *errorCodePtr) {
	struct xvfs_tclfs_channel_id *channelInstanceData;
	const unsigned char *data;
	Tcl_WideInt offset, length;
	char *path;
	long inode;

	channelInstanceData = (struct xvfs_tclfs_channel_id *) channelInstanceData_p;

	/*
	 * If we are already at the end of the file we can skip
	 * attempting to read it
	 */
	if (channelInstanceData->eofMarked) {
		return(0);
	}

	path = Tcl_GetString(channelInstanceData->path);
	inode = channelInstanceData->inode;
	offset = channelInstanceData->currentOffset;
	length = bufSize;

	data = channelInstanceData->fsInstanceInfo->fsInfo->getDataProc(path, offset, &length);
	data = channelInstanceData->fsInstanceInfo->fsInfo->getDataProc(NULL, inode, offset, &length);

	if (length < 0) {
		*errorCodePtr = xvfs_errorToErrno(length);

		return(-1);
	}

516
517
518
519
520
521
522
523

524
525
526
527
528
529
530
514
515
516
517
518
519
520

521
522
523
524
525
526
527
528







-
+








	XVFS_DEBUG_PRINTF("Getting stat() on \"%s\" ...", Tcl_GetString(path));

	path = xvfs_absolutePath(path);

	pathStr = xvfs_relativePath(path, instanceInfo);

	retval = instanceInfo->fsInfo->getStatProc(pathStr, statBuf);
	retval = instanceInfo->fsInfo->getStatProc(pathStr, XVFS_INODE_NULL, statBuf);
	if (retval < 0) {
		XVFS_DEBUG_PRINTF("... failed: %s", xvfs_strerror(retval));

		Tcl_SetErrno(xvfs_errorToErrno(retval));

		retval = -1;
	} else {
561
562
563
564
565
566
567
568

569
570
571
572
573
574
575
559
560
561
562
563
564
565

566
567
568
569
570
571
572
573







-
+








		Tcl_DecrRefCount(path);

		XVFS_DEBUG_LEAVE;
		return(-1);
	}

	statRetVal = instanceInfo->fsInfo->getStatProc(pathStr, &fileInfo);
	statRetVal = instanceInfo->fsInfo->getStatProc(pathStr, XVFS_INODE_NULL, &fileInfo);
	if (statRetVal < 0) {
		XVFS_DEBUG_PUTS("... no (not statable)");

		Tcl_DecrRefCount(path);

		XVFS_DEBUG_LEAVE;
		return(-1);
763
764
765
766
767
768
769
770

771
772
773
774
775
776
777
761
762
763
764
765
766
767

768
769
770
771
772
773
774
775







-
+







		xvfs_setresults_error(interp, XVFS_RV_ERR_ENOENT);

		XVFS_DEBUG_LEAVE;
		return(TCL_OK);
	}

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

		Tcl_DecrRefCount(path);

		xvfs_setresults_error(interp, childrenCount);