Diff

Differences From Artifact [169ff6cab0]:

To Artifact [206ee97d58]:


    69     69   		struct {
    70     70   			off_t size;
    71     71   			char source[256];
    72     72   		} symlink;
    73     73   	} typeinfo;
    74     74   };
    75     75   
    76         -static Tcl_Interp *appfs_create_TclInterp(const char *cachedir) {
           76  +static Tcl_Interp *appfs_create_TclInterp(void) {
    77     77   	Tcl_Interp *interp;
           78  +	const char *cachedir = globalThread.cachedir;
    78     79   	int tcl_ret;
    79     80   
    80     81   	APPFS_DEBUG("Creating new Tcl interpreter for TID = 0x%llx", (unsigned long long) pthread_self());
    81     82   
    82     83   	interp = Tcl_CreateInterp();
    83     84   	if (interp == NULL) {
    84     85   		fprintf(stderr, "Unable to create Tcl Interpreter.  Aborting.\n");
................................................................................
   197    198   	Tcl_Interp *interp;
   198    199   	int tcl_ret;
   199    200   
   200    201   	APPFS_DEBUG("Enter: hostname = %s", hostname);
   201    202   
   202    203   	interp = pthread_getspecific(interpKey);
   203    204   	if (interp == NULL) {
   204         -		interp = appfs_create_TclInterp(globalThread.cachedir);
          205  +		interp = appfs_create_TclInterp();
   205    206   
   206    207   		if (interp == NULL) {
   207    208   			return;
   208    209   		}
   209    210   
   210    211   		pthread_setspecific(interpKey, interp);
   211    212   	}
................................................................................
   223    224   static const char *appfs_getfile(const char *hostname, const char *sha1) {
   224    225   	Tcl_Interp *interp;
   225    226   	char *retval;
   226    227   	int tcl_ret;
   227    228   
   228    229   	interp = pthread_getspecific(interpKey);
   229    230   	if (interp == NULL) {
   230         -		interp = appfs_create_TclInterp(globalThread.cachedir);
          231  +		interp = appfs_create_TclInterp();
   231    232   
   232    233   		if (interp == NULL) {
   233    234   			return(NULL);
   234    235   		}
   235    236   
   236    237   		pthread_setspecific(interpKey, interp);
   237    238   	}
................................................................................
   250    251   
   251    252   static void appfs_update_manifest(const char *hostname, const char *sha1) {
   252    253   	Tcl_Interp *interp;
   253    254   	int tcl_ret;
   254    255   
   255    256   	interp = pthread_getspecific(interpKey);
   256    257   	if (interp == NULL) {
   257         -		interp = appfs_create_TclInterp(globalThread.cachedir);
          258  +		interp = appfs_create_TclInterp();
   258    259   
   259    260   		if (interp == NULL) {
   260    261   			return;
   261    262   		}
   262    263   
   263    264   		pthread_setspecific(interpKey, interp);
   264    265   	}
................................................................................
   379    380   
   380    381   	return(retval);
   381    382   }
   382    383   
   383    384   /* Get information about a path, and optionally list children */
   384    385   static int appfs_get_path_info(const char *_path, struct appfs_pathinfo *pathinfo, struct appfs_children **children) {
   385    386   }
          387  +
          388  +static int appfs_fuse_readlink(const char *path, char *buf, size_t size) {
          389  +	struct appfs_pathinfo pathinfo;
          390  +	int res = 0;
          391  +
          392  +	APPFS_DEBUG("Enter (path = %s, ...)", path);
          393  +
          394  +	pathinfo.type = APPFS_PATHTYPE_INVALID;
          395  +
          396  +	res = appfs_get_path_info(path, &pathinfo, NULL);
          397  +	if (res != 0) {
          398  +		return(res);
          399  +	}
          400  +
          401  +	if (pathinfo.type != APPFS_PATHTYPE_SYMLINK) {
          402  +		return(-EINVAL);
          403  +	}
          404  +
          405  +	if ((strlen(pathinfo.typeinfo.symlink.source) + 1) > size) {
          406  +		return(-ENAMETOOLONG);
          407  +	}
          408  +
          409  +	memcpy(buf, pathinfo.typeinfo.symlink.source, strlen(pathinfo.typeinfo.symlink.source) + 1);
          410  +
          411  +	return(0);
          412  +}
   386    413   
   387    414   static int appfs_fuse_getattr(const char *path, struct stat *stbuf) {
   388    415   	struct appfs_pathinfo pathinfo;
   389    416   	int res = 0;
   390    417   
   391    418   	APPFS_DEBUG("Enter (path = %s, ...)", path);
   392    419   
................................................................................
   455    482   	filler(buf, ".", NULL, 0);
   456    483   	filler(buf, "..", NULL, 0);
   457    484   
   458    485   	for (child = children; child; child = child->_next) {
   459    486   		filler(buf, child->name, NULL, 0);
   460    487   	}
   461    488   
   462         -	appfs_free_list_children(children);
          489  +//	appfs_free_list_children(children);
   463    490   
   464    491   	return(0);
   465    492   }
   466    493   
   467    494   static int appfs_fuse_open(const char *path, struct fuse_file_info *fi) {
   468    495   	struct appfs_pathinfo pathinfo;
   469    496   	const char *real_path;
   470    497   	int fh;
   471    498   	int gpi_ret;
   472    499   
   473    500   	APPFS_DEBUG("Enter (path = %s, ...)", path);
          501  +
          502  +#if 0
   474    503   
   475    504   	if ((fi->flags & 3) != O_RDONLY) {
   476    505                   return(-EACCES);
   477    506   	}
   478    507   
   479    508   	gpi_ret = appfs_get_path_info(path, &pathinfo, NULL);
   480    509   	if (gpi_ret != 0) {
................................................................................
   493    522   	fh = open(real_path, O_RDONLY);
   494    523   	free((void *) real_path);
   495    524   	if (fh < 0) {
   496    525   		return(-EIO);
   497    526   	}
   498    527   
   499    528   	fi->fh = fh;
          529  +#endif
   500    530   
   501    531   	return(0);
   502    532   }
   503    533   
   504    534   static int appfs_fuse_close(const char *path, struct fuse_file_info *fi) {
   505    535   	int close_ret;
   506    536   
................................................................................
   524    554   	}
   525    555   
   526    556   	read_ret = read(fi->fh, buf, size);
   527    557   
   528    558   	return(read_ret);
   529    559   }
   530    560   
   531         -static struct fuse_operations appfs_oper = {
   532         -	.getattr   = appfs_fuse_getattr,
   533         -	.readdir   = appfs_fuse_readdir,
   534         -	.readlink  = appfs_fuse_readlink,
   535         -	.open      = appfs_fuse_open,
   536         -	.release   = appfs_fuse_close,
   537         -	.read      = appfs_fuse_read
   538         -};
          561  +static int appfs_sqlite3(const char *sql) {
          562  +	Tcl_Interp *interp;
          563  +	const char *sql_ret;
          564  +	int tcl_ret;
          565  +
          566  +	interp = appfs_create_TclInterp();
          567  +	if (interp == NULL) {
          568  +		fprintf(stderr, "Unable to create a Tcl interpreter.  Aborting.\n");
          569  +
          570  +		return(1);
          571  +	}
          572  +
          573  +	tcl_ret = appfs_Tcl_Eval(interp, 5, "::appfs::db", "eval", sql, "row", "unset -nocomplain row(*); parray row; puts \"----\"");
          574  +	sql_ret = Tcl_GetStringResult(interp);
          575  +
          576  +	if (tcl_ret != TCL_OK) {
          577  +		fprintf(stderr, "[error] %s\n", sql_ret);
          578  +
          579  +		return(1);
          580  +	}
          581  +
          582  +	printf("%s\n", sql_ret);
          583  +
          584  +	return(0);
          585  +}
   539    586   
   540         -int Appfsd_Init(Tcl_Interp *interp) {
          587  +static int Appfsd_Init(Tcl_Interp *interp) {
   541    588   #ifdef USE_TCL_STUBS
   542    589   	if (Tcl_InitStubs(interp, TCL_VERSION, 0) == 0L) {
   543    590   		return(TCL_ERROR);
   544    591   	}
   545    592   #endif
   546    593   
   547    594   	Tcl_CreateObjCommand(interp, "appfsd::get_homedir", tcl_appfs_get_homedir, NULL, NULL);
   548    595   
   549    596   	Tcl_PkgProvide(interp, "appfsd", "1.0");
   550    597   
   551    598   	return(TCL_OK);
   552    599   }
          600  +
          601  +static struct fuse_operations appfs_oper = {
          602  +	.getattr   = appfs_fuse_getattr,
          603  +	.readdir   = appfs_fuse_readdir,
          604  +	.readlink  = appfs_fuse_readlink,
          605  +	.open      = appfs_fuse_open,
          606  +	.release   = appfs_fuse_close,
          607  +	.read      = appfs_fuse_read
          608  +};
   553    609   
   554    610   int main(int argc, char **argv) {
   555    611   	const char *cachedir = APPFS_CACHEDIR;
   556         -	char dbfilename[1024];
   557         -	int pthread_ret, snprintf_ret;
          612  +	int pthread_ret;
   558    613   
   559    614   	globalThread.cachedir = cachedir;
   560    615   	globalThread.boottime = time(NULL);
   561    616   	globalThread.options.writable = 1;
   562    617   
   563    618   	Tcl_StaticPackage(NULL, "sha1", Sha1_Init, NULL);
   564    619   	Tcl_StaticPackage(NULL, "appfsd", Appfsd_Init, NULL);
................................................................................
   566    621   	pthread_ret = pthread_key_create(&interpKey, NULL);
   567    622   	if (pthread_ret != 0) {
   568    623   		fprintf(stderr, "Unable to create TSD key for Tcl.  Aborting.\n");
   569    624   
   570    625   		return(1);
   571    626   	}
   572    627   
   573         -	snprintf_ret = snprintf(dbfilename, sizeof(dbfilename), "%s/%s", cachedir, "cache.db");
   574         -	if (snprintf_ret >= sizeof(dbfilename)) {
   575         -		fprintf(stderr, "Unable to set database filename.  Aborting.\n");
   576         -
   577         -		return(1);
          628  +	if (argc == 3 && strcmp(argv[1], "-sqlite3") == 0) {
          629  +		return(appfs_sqlite3(argv[2]));
   578    630   	}
   579    631   
   580    632   	return(fuse_main(argc, argv, &appfs_oper, NULL));
   581    633   }
   582    634