Diff

Differences From Artifact [70718fd2dc]:

To Artifact [a228e5eaeb]:


381
382
383
384
385
386
387
388

389
390
391
392
393
394
395
396

397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414

415
416
417
418

419
420
421

422
423
424
425
426
427
428
381
382
383
384
385
386
387

388
389
390
391
392
393
394
395

396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413

414
415
416
417

418
419
420
421
422
423
424
425
426
427
428
429







-
+







-
+

















-
+



-
+



+







	Tcl_WideInt attr_value_wide;
	int attr_value_int;
	static __thread Tcl_Obj *attr_key_type = NULL, *attr_key_perms = NULL, *attr_key_size = NULL, *attr_key_time = NULL, *attr_key_source = NULL, *attr_key_childcount = NULL;
	int tcl_ret;

	interp = appfs_TclInterp();
	if (interp == NULL) {
		return(1);
		return(-EIO);
	}

	tcl_ret = appfs_Tcl_Eval(interp, 2, "::appfs::getattr", path);
	if (tcl_ret != TCL_OK) {
		APPFS_DEBUG("::appfs::getattr(%s) failed.", path);
		APPFS_DEBUG("Tcl Error is: %s", Tcl_GetStringResult(interp));

		return(1);
		return(-ENOENT);
	}

	if (attr_key_type == NULL) {
		attr_key_type       = Tcl_NewStringObj("type", -1);
		attr_key_perms      = Tcl_NewStringObj("perms", -1);
		attr_key_size       = Tcl_NewStringObj("size", -1);
		attr_key_time       = Tcl_NewStringObj("time", -1);
		attr_key_source     = Tcl_NewStringObj("source", -1);
		attr_key_childcount = Tcl_NewStringObj("childcount", -1);
	}

	attrs_dict = Tcl_GetObjResult(interp);
	tcl_ret = Tcl_DictObjGet(interp, attrs_dict, attr_key_type, &attr_value);
	if (tcl_ret != TCL_OK) {
		APPFS_DEBUG("[dict get \"type\"] failed");
		APPFS_DEBUG("Tcl Error is: %s", Tcl_GetStringResult(interp));

		return(1);
		return(-EIO);
	}

	if (attr_value == NULL) {
		return(1);
		return(-EIO);
	}

	pathinfo->packaged = 0;
	pathinfo->inode = appfs_get_path_inode(path);

	attr_value_str = Tcl_GetString(attr_value);
	switch (attr_value_str[0]) {
		case 'd': /* directory */
			pathinfo->type = APPFS_PATHTYPE_DIRECTORY;
			pathinfo->typeinfo.dir.childcount = 0;

470
471
472
473
474
475
476
477

478
479
480
481
482
483
484
471
472
473
474
475
476
477

478
479
480
481
482
483
484
485







-
+







					pathinfo->typeinfo.symlink.source[attr_value_int] = '\0';

					memcpy(pathinfo->typeinfo.symlink.source, attr_value_str, attr_value_int);
				}
			}
			break;
		default:
			return(1);
			return(-EIO);
	}

	Tcl_DictObjGet(interp, attrs_dict, attr_key_time, &attr_value);
	if (attr_value != NULL) {
		tcl_ret = Tcl_GetWideIntFromObj(NULL, attr_value, &attr_value_wide);
		if (tcl_ret == TCL_OK) {
			pathinfo->time = attr_value_wide;
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

607
608
609
610
611
612
613
614
615
616
617

618
619


620
621
622
623
624
625

626
627
628
629





630
631
632
633








634
635
636
637
638
639




640










641
642
643
644


645

646
647
648
649
650
651
652
653
654
655
656
657
658
659
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
607
608
609
610
611
612
613
614
615
616
617
618
619

620
621
622

623
624
625

626
627



628
629
630
631
632
633



634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651

652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667

668

669
670
671
672
673

674
675
676
677
678
679
680







-















-
+







-
+











+

-
+
+

-



-
+

-
-
-
+
+
+
+
+

-
-
-
+
+
+
+
+
+
+
+






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




+
+
-
+
-





-







}

static int appfs_fuse_readdir(const char *path, void *buf, fuse_fill_dir_t filler, off_t offset, struct fuse_file_info *fi) {
	Tcl_Interp *interp;
	Tcl_Obj **children;
	int children_count, idx;
	int tcl_ret;
	int retval;

	APPFS_DEBUG("Enter (path = %s, ...)", path);

	interp = appfs_TclInterp();
	if (interp == NULL) {
		return(0);
	}

	filler(buf, ".", NULL, 0);
	filler(buf, "..", NULL, 0);

	tcl_ret = appfs_Tcl_Eval(interp, 2, "::appfs::getchildren", path);
	if (tcl_ret != TCL_OK) {
		APPFS_DEBUG("::appfs::getchildren(%s) failed.", path);
		APPFS_DEBUG("Tcl Error is: %s", Tcl_GetStringResult(interp));
		

		return(0);
	}

	tcl_ret = Tcl_ListObjGetElements(interp, Tcl_GetObjResult(interp), &children_count, &children);
	if (tcl_ret != TCL_OK) {
		APPFS_DEBUG("Parsing list of children on path %s failed.", path);
		APPFS_DEBUG("Tcl Error is: %s", Tcl_GetStringResult(interp));
		

		return(0);
	}

	for (idx = 0; idx < children_count; idx++) {
		filler(buf, Tcl_GetString(children[idx]), NULL, 0);
	}

	return(0);
}

static int appfs_fuse_open(const char *path, struct fuse_file_info *fi) {
	Tcl_Interp *interp;
	struct appfs_pathinfo pathinfo;
	const char *real_path;
	const char *real_path, *mode;
	int gpi_ret, tcl_ret;
	int fh;
	int gpi_ret;

	APPFS_DEBUG("Enter (path = %s, ...)", path);

#if 0
	gpi_ret = appfs_get_path_info(path, &pathinfo);

	if ((fi->flags & 3) != O_RDONLY) {
                return(-EACCES);
	}
	if ((fi->flags & (O_WRONLY|O_CREAT)) == (O_CREAT|O_WRONLY)) {
		/* The file will be created if it does not exist */
		if (gpi_ret != 0 && gpi_ret != -ENOENT) {
			return(gpi_ret);
		}

	gpi_ret = appfs_get_path_info(path, &pathinfo, NULL);
	if (gpi_ret != 0) {
		return(gpi_ret);
		mode = "create";
	} else {
		/* The file must already exist */
		if (gpi_ret != 0) {
			return(gpi_ret);
		}

		mode = "";
	}

	if (pathinfo.type == APPFS_PATHTYPE_DIRECTORY) {
		return(-EISDIR);
	}

	interp = appfs_TclInterp();
	if (interp == NULL) {
		return(-EIO);
	}
	real_path = appfs_getfile(pathinfo.hostname, pathinfo.typeinfo.file.sha1);

	tcl_ret = appfs_Tcl_Eval(interp, 3, "::appfs::openpath", path, mode);
	if (tcl_ret != TCL_OK) {
		APPFS_DEBUG("::appfs::openpath(%s, %s) failed.", path, mode);
		APPFS_DEBUG("Tcl Error is: %s", Tcl_GetStringResult(interp));

		return(-EIO);
	}

	real_path = Tcl_GetStringResult(interp);
	if (real_path == NULL) {
		return(-EIO);
	}

	APPFS_DEBUG("Translated request to open %s to opening %s (mode = \"%s\")", path, real_path, mode);

	fh = open(real_path, O_RDONLY);
	fh = open(real_path, fi->flags, 0600);
	free((void *) real_path);
	if (fh < 0) {
		return(-EIO);
	}

	fi->fh = fh;
#endif

	return(0);
}

static int appfs_fuse_close(const char *path, struct fuse_file_info *fi) {
	int close_ret;

774
775
776
777
778
779
780
781

782
783
784
785
786
787
788
795
796
797
798
799
800
801

802
803
804
805
806
807
808
809







-
+







	.read      = appfs_fuse_read
};

/*
 * FUSE option parsing callback
 */
static int appfs_fuse_opt_cb(void *data, const char *arg, int key, struct fuse_args *outargs) {
	static seen_cachedir = 0;
	static int seen_cachedir = 0;

	if (key == FUSE_OPT_KEY_NONOPT && seen_cachedir == 0) {
		seen_cachedir = 1;

		appfs_cachedir = strdup(arg);

		return(0);