Check-in [80bcdf4cb8]
Overview
Comment:Began adding support for other types of files as well as added creat() and mknod() support
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | tcl-ops
Files: files | file ages | folders
SHA1:80bcdf4cb8a216a5fbcc76c25b9248d3d11e36b3
User & Date: rkeene on 2014-11-09 07:52:03
Other Links: manifest | tags
Context
2014-11-09
08:01
Added a truncate action check-in: 8ea4ed266f user: rkeene tags: tcl-ops
07:52
Began adding support for other types of files as well as added creat() and mknod() support check-in: 80bcdf4cb8 user: rkeene tags: tcl-ops
02:14
Updated to rethrow error from local-ify file check-in: 7c53fff896 user: rkeene tags: tcl-ops
Changes

Modified appfsd.c from [ade95f924e] to [ba1c738961].

48
49
50
51
52
53
54
55


56
57
58
59
60
61
62
...
499
500
501
502
503
504
505




506
507
508
509
510
511
512
...
520
521
522
523
524
525
526


























527
528
529
530
531
532
533
...
590
591
592
593
594
595
596


597
598
599
600
601
602
603
604
605
...
749
750
751
752
753
754
755















































756
757
758
759
760
761
762
...
841
842
843
844
845
846
847
848


849
850
851
852
853
854
855
/*
 * AppFS Path Type:  Describes the type of path a given file is
 */
typedef enum {
	APPFS_PATHTYPE_INVALID,
	APPFS_PATHTYPE_FILE,
	APPFS_PATHTYPE_DIRECTORY,
	APPFS_PATHTYPE_SYMLINK


} appfs_pathtype_t;

/*
 * AppFS Path Information:
 *         Completely describes a specific path, how it should be returned to
 *         to the kernel
 */
................................................................................
					pathinfo->typeinfo.symlink.size = attr_value_int;
					pathinfo->typeinfo.symlink.source[attr_value_int] = '\0';

					memcpy(pathinfo->typeinfo.symlink.source, attr_value_str, attr_value_int);
				}
			}
			break;




		default:
			return(-EIO);
	}

	Tcl_DictObjGet(interp, attrs_dict, attr_key_packaged, &attr_value);
	if (attr_value != NULL) {
		pathinfo->packaged = 1;
................................................................................
		}
	} else {
		pathinfo->time = 0;
	}

	return(0);
}



























static int appfs_fuse_readlink(const char *path, char *buf, size_t size) {
	struct appfs_pathinfo pathinfo;
	int retval = 0;

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

................................................................................
			stbuf->st_size = pathinfo.typeinfo.file.size;
			break;
		case APPFS_PATHTYPE_SYMLINK:
			stbuf->st_mode = S_IFLNK | 0555;
			stbuf->st_nlink = 1;
			stbuf->st_size = pathinfo.typeinfo.symlink.size;
			break;


		case APPFS_PATHTYPE_INVALID:
			retval = -EIO;

			break;
	}

	if (pathinfo.packaged) {
		stbuf->st_mode |= 0222;
	}
................................................................................
		return(-EIO);
	}

	write_ret = write(fi->fh, buf, size);

	return(write_ret);
}
















































/*
 * SQLite3 mode: Execute raw SQL and return success or failure
 */
static int appfs_sqlite3(const char *sql) {
	Tcl_Interp *interp;
	const char *sql_ret;
................................................................................
static struct fuse_operations appfs_operations = {
	.getattr   = appfs_fuse_getattr,
	.readdir   = appfs_fuse_readdir,
	.readlink  = appfs_fuse_readlink,
	.open      = appfs_fuse_open,
	.release   = appfs_fuse_close,
	.read      = appfs_fuse_read,
	.write     = appfs_fuse_write


};

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







|
>
>







 







>
>
>
>







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







>
>

|







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







|
>
>







48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
...
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
...
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
...
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
...
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
...
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
/*
 * AppFS Path Type:  Describes the type of path a given file is
 */
typedef enum {
	APPFS_PATHTYPE_INVALID,
	APPFS_PATHTYPE_FILE,
	APPFS_PATHTYPE_DIRECTORY,
	APPFS_PATHTYPE_SYMLINK,
	APPFS_PATHTYPE_SOCKET,
	APPFS_PATHTYPE_FIFO,
} appfs_pathtype_t;

/*
 * AppFS Path Information:
 *         Completely describes a specific path, how it should be returned to
 *         to the kernel
 */
................................................................................
					pathinfo->typeinfo.symlink.size = attr_value_int;
					pathinfo->typeinfo.symlink.source[attr_value_int] = '\0';

					memcpy(pathinfo->typeinfo.symlink.source, attr_value_str, attr_value_int);
				}
			}
			break;
		case 'p': /* pipe/fifo */
			break;
		case 'S': /* UNIX domain socket */
			break;
		default:
			return(-EIO);
	}

	Tcl_DictObjGet(interp, attrs_dict, attr_key_packaged, &attr_value);
	if (attr_value != NULL) {
		pathinfo->packaged = 1;
................................................................................
		}
	} else {
		pathinfo->time = 0;
	}

	return(0);
}

static char *appfs_prepare_to_create(const char *path) {
	Tcl_Interp *interp;
	const char *real_path;
	int tcl_ret;

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

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

		return(NULL);
	}

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

	return(strdup(real_path));
}

static int appfs_fuse_readlink(const char *path, char *buf, size_t size) {
	struct appfs_pathinfo pathinfo;
	int retval = 0;

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

................................................................................
			stbuf->st_size = pathinfo.typeinfo.file.size;
			break;
		case APPFS_PATHTYPE_SYMLINK:
			stbuf->st_mode = S_IFLNK | 0555;
			stbuf->st_nlink = 1;
			stbuf->st_size = pathinfo.typeinfo.symlink.size;
			break;
		case APPFS_PATHTYPE_SOCKET:
		case APPFS_PATHTYPE_FIFO:
		case APPFS_PATHTYPE_INVALID:
			retval = -ENOENT;

			break;
	}

	if (pathinfo.packaged) {
		stbuf->st_mode |= 0222;
	}
................................................................................
		return(-EIO);
	}

	write_ret = write(fi->fh, buf, size);

	return(write_ret);
}

static int appfs_fuse_mknod(const char *path, mode_t mode, dev_t device) {
	char *real_path;
	int mknod_ret;

	if ((mode & S_IFCHR) == S_IFCHR) {
		return(-EPERM);
	}

	if ((mode & S_IFBLK) == S_IFBLK) {
		return(-EPERM);
	}

	real_path = appfs_prepare_to_create(path);
	if (real_path == NULL) {
		return(-EIO);
	}

	mknod_ret = mknod(real_path, mode, device);

	free(real_path);

	if (mknod_ret != 0) {
		return(errno * -1);
	}

	return(0);
}

static int appfs_fuse_create(const char *path, mode_t mode, struct fuse_file_info *fi) {
	int fd;
	int chmod_ret;

	fd = appfs_fuse_open(path, fi);
	if (fd < 0) {
		return(fd);
	}

	chmod_ret = fchmod(fd, mode);
	if (chmod_ret != 0) {
		close(fd);

		return(-EIO);
	}

	return(fd);
}

/*
 * SQLite3 mode: Execute raw SQL and return success or failure
 */
static int appfs_sqlite3(const char *sql) {
	Tcl_Interp *interp;
	const char *sql_ret;
................................................................................
static struct fuse_operations appfs_operations = {
	.getattr   = appfs_fuse_getattr,
	.readdir   = appfs_fuse_readdir,
	.readlink  = appfs_fuse_readlink,
	.open      = appfs_fuse_open,
	.release   = appfs_fuse_close,
	.read      = appfs_fuse_read,
	.write     = appfs_fuse_write,
	.mknod     = appfs_fuse_mknod,
	.create    = appfs_fuse_create,
};

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

Modified appfsd.tcl from [ce277262eb] to [a96ad61fba].

531
532
533
534
535
536
537



538
539
540
541
542
543
544
...
631
632
633
634
635
636
637
638






























				}
			}
			"files" {

				set retval(packaged) 1

				set localpath [_localpath $pathinfo(package) $pathinfo(hostname) $pathinfo(file)]



				if {[file exists $localpath]} {
					catch {
						file lstat $localpath localpathinfo
						set retval(time) $localpathinfo(mtime)

						switch -- $localpathinfo(type) {
							"directory" {
................................................................................
			}

			return $localpath
		}

		return $localcachefile
	}
}





































>
>
>







 







|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
...
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
				}
			}
			"files" {

				set retval(packaged) 1

				set localpath [_localpath $pathinfo(package) $pathinfo(hostname) $pathinfo(file)]

				set retval(localpath) $localpath

				if {[file exists $localpath]} {
					catch {
						file lstat $localpath localpathinfo
						set retval(time) $localpathinfo(mtime)

						switch -- $localpathinfo(type) {
							"directory" {
................................................................................
			}

			return $localpath
		}

		return $localcachefile
	}

	proc exists {path} {
		catch {
			set info [getattr $path]
		} err

		if {![info exists info]} {
			if {$err == "No such file or directory"} {
				return [list]
			} else {
				return -code error $err
			}
		}

		return $info
	}

	proc prepare_to_create {path} {
		if {[exists $path] != ""} {
			return -code error "File already exists"
		}

		set filename [openpath $path "create"]

		set dirname [file dirname $filename]

		file mkdir $dirname

		return $filename
	}
}