0000: 23 64 65 66 69 6e 65 20 46 55 53 45 5f 55 53 45 #define FUSE_USE
0010: 5f 56 45 52 53 49 4f 4e 20 32 36 0a 0a 23 69 6e _VERSION 26..#in
0020: 63 6c 75 64 65 20 3c 73 79 73 2f 74 79 70 65 73 clude <sys/types
0030: 2e 68 3e 0a 23 69 6e 63 6c 75 64 65 20 3c 70 74 .h>.#include <pt
0040: 68 72 65 61 64 2e 68 3e 0a 23 69 6e 63 6c 75 64 hread.h>.#includ
0050: 65 20 3c 73 74 72 69 6e 67 2e 68 3e 0a 23 69 6e e <string.h>.#in
0060: 63 6c 75 64 65 20 3c 73 74 64 61 72 67 2e 68 3e clude <stdarg.h>
0070: 0a 23 69 6e 63 6c 75 64 65 20 3c 73 74 64 6c 69 .#include <stdli
0080: 62 2e 68 3e 0a 23 69 6e 63 6c 75 64 65 20 3c 75 b.h>.#include <u
0090: 6e 69 73 74 64 2e 68 3e 0a 23 69 6e 63 6c 75 64 nistd.h>.#includ
00a0: 65 20 3c 65 72 72 6e 6f 2e 68 3e 0a 23 69 6e 63 e <errno.h>.#inc
00b0: 6c 75 64 65 20 3c 66 63 6e 74 6c 2e 68 3e 0a 23 lude <fcntl.h>.#
00c0: 69 6e 63 6c 75 64 65 20 3c 73 74 64 69 6f 2e 68 include <stdio.h
00d0: 3e 0a 23 69 6e 63 6c 75 64 65 20 3c 66 75 73 65 >.#include <fuse
00e0: 2e 68 3e 0a 23 69 6e 63 6c 75 64 65 20 3c 70 77 .h>.#include <pw
00f0: 64 2e 68 3e 0a 23 69 6e 63 6c 75 64 65 20 3c 74 d.h>.#include <t
0100: 63 6c 2e 68 3e 0a 0a 2f 2a 0a 20 2a 20 44 65 66 cl.h>../*. * Def
0110: 61 75 6c 74 20 63 61 63 68 65 20 64 69 72 65 63 ault cache direc
0120: 74 6f 72 79 0a 20 2a 2f 0a 23 69 66 6e 64 65 66 tory. */.#ifndef
0130: 20 41 50 50 46 53 5f 43 41 43 48 45 44 49 52 0a APPFS_CACHEDIR.
0140: 23 64 65 66 69 6e 65 20 41 50 50 46 53 5f 43 41 #define APPFS_CA
0150: 43 48 45 44 49 52 20 22 2f 76 61 72 2f 63 61 63 CHEDIR "/var/cac
0160: 68 65 2f 61 70 70 66 73 22 0a 23 65 6e 64 69 66 he/appfs".#endif
0170: 0a 0a 2f 2a 20 44 65 62 75 67 67 69 6e 67 20 6d ../* Debugging m
0180: 61 63 72 6f 73 20 2a 2f 0a 23 69 66 64 65 66 20 acros */.#ifdef
0190: 44 45 42 55 47 0a 23 64 65 66 69 6e 65 20 41 50 DEBUG.#define AP
01a0: 50 46 53 5f 44 45 42 55 47 28 78 2e 2e 2e 29 20 PFS_DEBUG(x...)
01b0: 7b 20 66 70 72 69 6e 74 66 28 73 74 64 65 72 72 { fprintf(stderr
01c0: 2c 20 22 5b 64 65 62 75 67 5d 20 25 73 3a 25 69 , "[debug] %s:%i
01d0: 3a 25 73 3a 20 22 2c 20 5f 5f 46 49 4c 45 5f 5f :%s: ", __FILE__
01e0: 2c 20 5f 5f 4c 49 4e 45 5f 5f 2c 20 5f 5f 66 75 , __LINE__, __fu
01f0: 6e 63 5f 5f 29 3b 20 66 70 72 69 6e 74 66 28 73 nc__); fprintf(s
0200: 74 64 65 72 72 2c 20 78 29 3b 20 66 70 72 69 6e tderr, x); fprin
0210: 74 66 28 73 74 64 65 72 72 2c 20 22 5c 6e 22 29 tf(stderr, "\n")
0220: 3b 20 7d 0a 23 65 6c 73 65 0a 23 64 65 66 69 6e ; }.#else.#defin
0230: 65 20 41 50 50 46 53 5f 44 45 42 55 47 28 78 2e e APPFS_DEBUG(x.
0240: 2e 2e 29 20 2f 2a 2a 2f 0a 23 65 6e 64 69 66 0a ..) /**/.#endif.
0250: 0a 2f 2a 0a 20 2a 20 53 48 41 31 20 54 63 6c 20 ./*. * SHA1 Tcl
0260: 50 61 63 6b 61 67 65 20 69 6e 69 74 69 61 6c 69 Package initiali
0270: 7a 65 72 2c 20 66 72 6f 6d 20 73 68 61 31 2e 6f zer, from sha1.o
0280: 0a 20 2a 2f 0a 69 6e 74 20 53 68 61 31 5f 49 6e . */.int Sha1_In
0290: 69 74 28 54 63 6c 5f 49 6e 74 65 72 70 20 2a 69 it(Tcl_Interp *i
02a0: 6e 74 65 72 70 29 3b 0a 0a 2f 2a 0a 20 2a 20 54 nterp);../*. * T
02b0: 68 72 65 61 64 20 53 70 65 63 69 66 69 63 20 44 hread Specific D
02c0: 61 74 61 20 28 54 53 44 29 20 66 6f 72 20 54 63 ata (TSD) for Tc
02d0: 6c 20 49 6e 74 65 72 70 72 65 74 65 72 20 66 6f l Interpreter fo
02e0: 72 20 74 68 65 20 63 75 72 72 65 6e 74 20 74 68 r the current th
02f0: 72 65 61 64 0a 20 2a 2f 0a 73 74 61 74 69 63 20 read. */.static
0300: 70 74 68 72 65 61 64 5f 6b 65 79 5f 74 20 69 6e pthread_key_t in
0310: 74 65 72 70 4b 65 79 3b 0a 0a 2f 2a 0a 20 2a 20 terpKey;../*. *
0320: 44 61 74 61 20 66 6f 72 20 61 20 67 69 76 65 6e Data for a given
0330: 20 74 68 72 65 61 64 20 28 6d 6f 73 74 20 6c 69 thread (most li
0340: 6b 65 6c 79 20 74 68 65 73 65 20 77 69 6c 6c 20 kely these will
0350: 62 65 63 6f 6d 65 20 6a 75 73 74 20 67 6c 6f 62 become just glob
0360: 61 62 6c 65 20 76 61 72 69 61 62 6c 65 73 20 73 able variables s
0370: 6f 6f 6e 2e 29 0a 20 2a 2f 0a 73 74 72 75 63 74 oon.). */.struct
0380: 20 61 70 70 66 73 5f 74 68 72 65 61 64 5f 64 61 appfs_thread_da
0390: 74 61 20 7b 0a 09 63 6f 6e 73 74 20 63 68 61 72 ta {..const char
03a0: 20 2a 63 61 63 68 65 64 69 72 3b 0a 09 74 69 6d *cachedir;..tim
03b0: 65 5f 74 20 62 6f 6f 74 74 69 6d 65 3b 0a 09 73 e_t boottime;..s
03c0: 74 72 75 63 74 20 7b 0a 09 09 69 6e 74 20 77 72 truct {...int wr
03d0: 69 74 61 62 6c 65 3b 0a 09 7d 20 6f 70 74 69 6f itable;..} optio
03e0: 6e 73 3b 0a 7d 3b 0a 0a 2f 2a 20 54 68 65 20 67 ns;.};../* The g
03f0: 6c 6f 62 61 6c 20 74 68 72 65 61 64 20 64 61 74 lobal thread dat
0400: 61 20 28 6c 69 6b 65 6c 79 20 74 6f 20 67 6f 20 a (likely to go
0410: 61 77 61 79 29 20 2a 2f 0a 73 74 72 75 63 74 20 away) */.struct
0420: 61 70 70 66 73 5f 74 68 72 65 61 64 5f 64 61 74 appfs_thread_dat
0430: 61 20 67 6c 6f 62 61 6c 54 68 72 65 61 64 3b 0a a globalThread;.
0440: 0a 2f 2a 0a 20 2a 20 41 70 70 46 53 20 50 61 74 ./*. * AppFS Pat
0450: 68 20 54 79 70 65 3a 20 20 44 65 73 63 72 69 62 h Type: Describ
0460: 65 73 20 74 68 65 20 74 79 70 65 20 6f 66 20 70 es the type of p
0470: 61 74 68 20 61 20 67 69 76 65 6e 20 66 69 6c 65 ath a given file
0480: 20 69 73 0a 20 2a 2f 0a 74 79 70 65 64 65 66 20 is. */.typedef
0490: 65 6e 75 6d 20 7b 0a 09 41 50 50 46 53 5f 50 41 enum {..APPFS_PA
04a0: 54 48 54 59 50 45 5f 49 4e 56 41 4c 49 44 2c 0a THTYPE_INVALID,.
04b0: 09 41 50 50 46 53 5f 50 41 54 48 54 59 50 45 5f .APPFS_PATHTYPE_
04c0: 46 49 4c 45 2c 0a 09 41 50 50 46 53 5f 50 41 54 FILE,..APPFS_PAT
04d0: 48 54 59 50 45 5f 44 49 52 45 43 54 4f 52 59 2c HTYPE_DIRECTORY,
04e0: 0a 09 41 50 50 46 53 5f 50 41 54 48 54 59 50 45 ..APPFS_PATHTYPE
04f0: 5f 53 59 4d 4c 49 4e 4b 0a 7d 20 61 70 70 66 73 _SYMLINK.} appfs
0500: 5f 70 61 74 68 74 79 70 65 5f 74 3b 0a 0a 2f 2a _pathtype_t;../*
0510: 0a 20 2a 20 41 70 70 46 53 20 43 68 69 6c 64 72 . * AppFS Childr
0520: 65 6e 20 46 69 6c 65 73 20 6c 69 6e 6b 65 64 2d en Files linked-
0530: 6c 69 73 74 0a 20 2a 2f 0a 73 74 72 75 63 74 20 list. */.struct
0540: 61 70 70 66 73 5f 63 68 69 6c 64 72 65 6e 20 7b appfs_children {
0550: 0a 09 73 74 72 75 63 74 20 61 70 70 66 73 5f 63 ..struct appfs_c
0560: 68 69 6c 64 72 65 6e 20 2a 5f 6e 65 78 74 3b 0a hildren *_next;.
0570: 09 63 68 61 72 20 6e 61 6d 65 5b 32 35 36 5d 3b .char name[256];
0580: 0a 7d 3b 0a 0a 2f 2a 0a 20 2a 20 41 70 70 46 53 .};../*. * AppFS
0590: 20 50 61 74 68 20 49 6e 66 6f 72 6d 61 74 69 6f Path Informatio
05a0: 6e 3a 0a 20 2a 20 20 20 20 20 20 20 20 20 43 6f n:. * Co
05b0: 6d 70 6c 65 74 65 6c 79 20 64 65 73 63 72 69 62 mpletely describ
05c0: 65 73 20 61 20 73 70 65 63 69 66 69 63 20 70 61 es a specific pa
05d0: 74 68 2c 20 68 6f 77 20 69 74 20 73 68 6f 75 6c th, how it shoul
05e0: 64 20 62 65 20 72 65 74 75 72 6e 65 64 20 74 6f d be returned to
05f0: 0a 20 2a 20 20 20 20 20 20 20 20 20 74 6f 20 74 . * to t
0600: 68 65 20 6b 65 72 6e 65 6c 0a 20 2a 2f 0a 73 74 he kernel. */.st
0610: 72 75 63 74 20 61 70 70 66 73 5f 70 61 74 68 69 ruct appfs_pathi
0620: 6e 66 6f 20 7b 0a 09 61 70 70 66 73 5f 70 61 74 nfo {..appfs_pat
0630: 68 74 79 70 65 5f 74 20 74 79 70 65 3b 0a 09 74 htype_t type;..t
0640: 69 6d 65 5f 74 20 74 69 6d 65 3b 0a 09 63 68 61 ime_t time;..cha
0650: 72 20 68 6f 73 74 6e 61 6d 65 5b 32 35 36 5d 3b r hostname[256];
0660: 0a 09 69 6e 74 20 70 61 63 6b 61 67 65 64 3b 0a ..int packaged;.
0670: 09 75 6e 73 69 67 6e 65 64 20 6c 6f 6e 67 20 6c .unsigned long l
0680: 6f 6e 67 20 69 6e 6f 64 65 3b 0a 09 75 6e 69 6f ong inode;..unio
0690: 6e 20 7b 0a 09 09 73 74 72 75 63 74 20 7b 0a 09 n {...struct {..
06a0: 09 09 69 6e 74 20 63 68 69 6c 64 63 6f 75 6e 74 ..int childcount
06b0: 3b 0a 09 09 7d 20 64 69 72 3b 0a 09 09 73 74 72 ;...} dir;...str
06c0: 75 63 74 20 7b 0a 09 09 09 69 6e 74 20 65 78 65 uct {....int exe
06d0: 63 75 74 61 62 6c 65 3b 0a 09 09 09 6f 66 66 5f cutable;....off_
06e0: 74 20 73 69 7a 65 3b 0a 09 09 7d 20 66 69 6c 65 t size;...} file
06f0: 3b 0a 09 09 73 74 72 75 63 74 20 7b 0a 09 09 09 ;...struct {....
0700: 6f 66 66 5f 74 20 73 69 7a 65 3b 0a 09 09 09 63 off_t size;....c
0710: 68 61 72 20 73 6f 75 72 63 65 5b 32 35 36 5d 3b har source[256];
0720: 0a 09 09 7d 20 73 79 6d 6c 69 6e 6b 3b 0a 09 7d ...} symlink;..}
0730: 20 74 79 70 65 69 6e 66 6f 3b 0a 7d 3b 0a 0a 2f typeinfo;.};../
0740: 2a 0a 20 2a 20 43 72 65 61 74 65 20 61 20 6e 65 *. * Create a ne
0750: 77 20 54 63 6c 20 69 6e 74 65 72 70 72 65 74 65 w Tcl interprete
0760: 72 20 61 6e 64 20 63 6f 6d 70 6c 65 74 65 6c 79 r and completely
0770: 20 69 6e 69 74 69 61 6c 69 7a 65 20 69 74 0a 20 initialize it.
0780: 2a 2f 0a 73 74 61 74 69 63 20 54 63 6c 5f 49 6e */.static Tcl_In
0790: 74 65 72 70 20 2a 61 70 70 66 73 5f 63 72 65 61 terp *appfs_crea
07a0: 74 65 5f 54 63 6c 49 6e 74 65 72 70 28 76 6f 69 te_TclInterp(voi
07b0: 64 29 20 7b 0a 09 54 63 6c 5f 49 6e 74 65 72 70 d) {..Tcl_Interp
07c0: 20 2a 69 6e 74 65 72 70 3b 0a 09 63 6f 6e 73 74 *interp;..const
07d0: 20 63 68 61 72 20 2a 63 61 63 68 65 64 69 72 20 char *cachedir
07e0: 3d 20 67 6c 6f 62 61 6c 54 68 72 65 61 64 2e 63 = globalThread.c
07f0: 61 63 68 65 64 69 72 3b 0a 09 69 6e 74 20 74 63 achedir;..int tc
0800: 6c 5f 72 65 74 3b 0a 0a 09 41 50 50 46 53 5f 44 l_ret;...APPFS_D
0810: 45 42 55 47 28 22 43 72 65 61 74 69 6e 67 20 6e EBUG("Creating n
0820: 65 77 20 54 63 6c 20 69 6e 74 65 72 70 72 65 74 ew Tcl interpret
0830: 65 72 20 66 6f 72 20 54 49 44 20 3d 20 30 78 25 er for TID = 0x%
0840: 6c 6c 78 22 2c 20 28 75 6e 73 69 67 6e 65 64 20 llx", (unsigned
0850: 6c 6f 6e 67 20 6c 6f 6e 67 29 20 70 74 68 72 65 long long) pthre
0860: 61 64 5f 73 65 6c 66 28 29 29 3b 0a 0a 09 69 6e ad_self());...in
0870: 74 65 72 70 20 3d 20 54 63 6c 5f 43 72 65 61 74 terp = Tcl_Creat
0880: 65 49 6e 74 65 72 70 28 29 3b 0a 09 69 66 20 28 eInterp();..if (
0890: 69 6e 74 65 72 70 20 3d 3d 20 4e 55 4c 4c 29 20 interp == NULL)
08a0: 7b 0a 09 09 66 70 72 69 6e 74 66 28 73 74 64 65 {...fprintf(stde
08b0: 72 72 2c 20 22 55 6e 61 62 6c 65 20 74 6f 20 63 rr, "Unable to c
08c0: 72 65 61 74 65 20 54 63 6c 20 49 6e 74 65 72 70 reate Tcl Interp
08d0: 72 65 74 65 72 2e 20 20 41 62 6f 72 74 69 6e 67 reter. Aborting
08e0: 2e 5c 6e 22 29 3b 0a 0a 09 09 72 65 74 75 72 6e .\n");....return
08f0: 28 4e 55 4c 4c 29 3b 0a 09 7d 0a 0a 09 74 63 6c (NULL);..}...tcl
0900: 5f 72 65 74 20 3d 20 54 63 6c 5f 49 6e 69 74 28 _ret = Tcl_Init(
0910: 69 6e 74 65 72 70 29 3b 0a 09 69 66 20 28 74 63 interp);..if (tc
0920: 6c 5f 72 65 74 20 21 3d 20 54 43 4c 5f 4f 4b 29 l_ret != TCL_OK)
0930: 20 7b 0a 09 09 66 70 72 69 6e 74 66 28 73 74 64 {...fprintf(std
0940: 65 72 72 2c 20 22 55 6e 61 62 6c 65 20 74 6f 20 err, "Unable to
0950: 69 6e 69 74 69 61 6c 69 7a 65 20 54 63 6c 2e 20 initialize Tcl.
0960: 20 41 62 6f 72 74 69 6e 67 2e 5c 6e 22 29 3b 0a Aborting.\n");.
0970: 09 09 66 70 72 69 6e 74 66 28 73 74 64 65 72 72 ..fprintf(stderr
0980: 2c 20 22 54 63 6c 20 45 72 72 6f 72 20 69 73 3a , "Tcl Error is:
0990: 20 25 73 5c 6e 22 2c 20 54 63 6c 5f 47 65 74 53 %s\n", Tcl_GetS
09a0: 74 72 69 6e 67 52 65 73 75 6c 74 28 69 6e 74 65 tringResult(inte
09b0: 72 70 29 29 3b 0a 0a 09 09 54 63 6c 5f 44 65 6c rp));....Tcl_Del
09c0: 65 74 65 49 6e 74 65 72 70 28 69 6e 74 65 72 70 eteInterp(interp
09d0: 29 3b 0a 0a 09 09 72 65 74 75 72 6e 28 4e 55 4c );....return(NUL
09e0: 4c 29 3b 0a 09 7d 0a 0a 09 74 63 6c 5f 72 65 74 L);..}...tcl_ret
09f0: 20 3d 20 54 63 6c 5f 45 76 61 6c 28 69 6e 74 65 = Tcl_Eval(inte
0a00: 72 70 2c 20 22 70 61 63 6b 61 67 65 20 69 66 6e rp, "package ifn
0a10: 65 65 64 65 64 20 73 68 61 31 20 31 2e 30 20 5b eeded sha1 1.0 [
0a20: 6c 69 73 74 20 6c 6f 61 64 20 7b 7d 20 73 68 61 list load {} sha
0a30: 31 5d 22 29 3b 0a 09 69 66 20 28 74 63 6c 5f 72 1]");..if (tcl_r
0a40: 65 74 20 21 3d 20 54 43 4c 5f 4f 4b 29 20 7b 0a et != TCL_OK) {.
0a50: 09 09 66 70 72 69 6e 74 66 28 73 74 64 65 72 72 ..fprintf(stderr
0a60: 2c 20 22 55 6e 61 62 6c 65 20 74 6f 20 69 6e 69 , "Unable to ini
0a70: 74 69 61 6c 69 7a 65 20 54 63 6c 20 53 48 41 31 tialize Tcl SHA1
0a80: 2e 20 20 41 62 6f 72 74 69 6e 67 2e 5c 6e 22 29 . Aborting.\n")
0a90: 3b 0a 09 09 66 70 72 69 6e 74 66 28 73 74 64 65 ;...fprintf(stde
0aa0: 72 72 2c 20 22 54 63 6c 20 45 72 72 6f 72 20 69 rr, "Tcl Error i
0ab0: 73 3a 20 25 73 5c 6e 22 2c 20 54 63 6c 5f 47 65 s: %s\n", Tcl_Ge
0ac0: 74 53 74 72 69 6e 67 52 65 73 75 6c 74 28 69 6e tStringResult(in
0ad0: 74 65 72 70 29 29 3b 0a 0a 09 09 54 63 6c 5f 44 terp));....Tcl_D
0ae0: 65 6c 65 74 65 49 6e 74 65 72 70 28 69 6e 74 65 eleteInterp(inte
0af0: 72 70 29 3b 0a 0a 09 09 72 65 74 75 72 6e 28 4e rp);....return(N
0b00: 55 4c 4c 29 3b 0a 09 7d 0a 0a 09 74 63 6c 5f 72 ULL);..}...tcl_r
0b10: 65 74 20 3d 20 54 63 6c 5f 45 76 61 6c 28 69 6e et = Tcl_Eval(in
0b20: 74 65 72 70 2c 20 22 70 61 63 6b 61 67 65 20 69 terp, "package i
0b30: 66 6e 65 65 64 65 64 20 61 70 70 66 73 64 20 31 fneeded appfsd 1
0b40: 2e 30 20 5b 6c 69 73 74 20 6c 6f 61 64 20 7b 7d .0 [list load {}
0b50: 20 61 70 70 66 73 64 5d 22 29 3b 0a 09 69 66 20 appfsd]");..if
0b60: 28 74 63 6c 5f 72 65 74 20 21 3d 20 54 43 4c 5f (tcl_ret != TCL_
0b70: 4f 4b 29 20 7b 0a 09 09 66 70 72 69 6e 74 66 28 OK) {...fprintf(
0b80: 73 74 64 65 72 72 2c 20 22 55 6e 61 62 6c 65 20 stderr, "Unable
0b90: 74 6f 20 69 6e 69 74 69 61 6c 69 7a 65 20 54 63 to initialize Tc
0ba0: 6c 20 41 70 70 46 53 20 50 61 63 6b 61 67 65 2e l AppFS Package.
0bb0: 20 20 41 62 6f 72 74 69 6e 67 2e 5c 6e 22 29 3b Aborting.\n");
0bc0: 0a 09 09 66 70 72 69 6e 74 66 28 73 74 64 65 72 ...fprintf(stder
0bd0: 72 2c 20 22 54 63 6c 20 45 72 72 6f 72 20 69 73 r, "Tcl Error is
0be0: 3a 20 25 73 5c 6e 22 2c 20 54 63 6c 5f 47 65 74 : %s\n", Tcl_Get
0bf0: 53 74 72 69 6e 67 52 65 73 75 6c 74 28 69 6e 74 StringResult(int
0c00: 65 72 70 29 29 3b 0a 0a 09 09 54 63 6c 5f 44 65 erp));....Tcl_De
0c10: 6c 65 74 65 49 6e 74 65 72 70 28 69 6e 74 65 72 leteInterp(inter
0c20: 70 29 3b 0a 0a 09 09 72 65 74 75 72 6e 28 4e 55 p);....return(NU
0c30: 4c 4c 29 3b 0a 09 7d 0a 0a 09 2f 2a 0a 09 20 2a LL);..}.../*.. *
0c40: 20 4c 6f 61 64 20 74 68 65 20 22 61 70 70 66 73 Load the "appfs
0c50: 64 2e 74 63 6c 22 20 73 63 72 69 70 74 2c 20 77 d.tcl" script, w
0c60: 68 69 63 68 20 69 73 20 22 63 6f 6d 70 69 6c 65 hich is "compile
0c70: 64 22 20 69 6e 74 6f 20 61 20 43 20 68 65 61 64 d" into a C head
0c80: 65 72 0a 09 20 2a 20 73 6f 20 74 68 61 74 20 69 er.. * so that i
0c90: 74 20 64 6f 65 73 20 6e 6f 74 20 6e 65 65 64 20 t does not need
0ca0: 74 6f 20 65 78 69 73 74 20 6f 6e 20 74 68 65 20 to exist on the
0cb0: 66 69 6c 65 73 79 73 74 65 6d 20 61 6e 64 20 63 filesystem and c
0cc0: 61 6e 20 62 65 0a 09 20 2a 20 64 69 72 65 63 74 an be.. * direct
0cd0: 6c 79 20 65 76 61 6c 75 61 74 65 64 2e 0a 09 20 ly evaluated...
0ce0: 2a 2f 0a 09 74 63 6c 5f 72 65 74 20 3d 20 54 63 */..tcl_ret = Tc
0cf0: 6c 5f 45 76 61 6c 28 69 6e 74 65 72 70 2c 20 22 l_Eval(interp, "
0d00: 22 0a 23 69 6e 63 6c 75 64 65 20 22 61 70 70 66 ".#include "appf
0d10: 73 64 2e 74 63 6c 2e 68 22 0a 09 22 22 29 3b 0a sd.tcl.h".."");.
0d20: 09 69 66 20 28 74 63 6c 5f 72 65 74 20 21 3d 20 .if (tcl_ret !=
0d30: 54 43 4c 5f 4f 4b 29 20 7b 0a 09 09 66 70 72 69 TCL_OK) {...fpri
0d40: 6e 74 66 28 73 74 64 65 72 72 2c 20 22 55 6e 61 ntf(stderr, "Una
0d50: 62 6c 65 20 74 6f 20 69 6e 69 74 69 61 6c 69 7a ble to initializ
0d60: 65 20 54 63 6c 20 41 70 70 46 53 20 73 63 72 69 e Tcl AppFS scri
0d70: 70 74 2e 20 20 41 62 6f 72 74 69 6e 67 2e 5c 6e pt. Aborting.\n
0d80: 22 29 3b 0a 09 09 66 70 72 69 6e 74 66 28 73 74 ");...fprintf(st
0d90: 64 65 72 72 2c 20 22 54 63 6c 20 45 72 72 6f 72 derr, "Tcl Error
0da0: 20 69 73 3a 20 25 73 5c 6e 22 2c 20 54 63 6c 5f is: %s\n", Tcl_
0db0: 47 65 74 53 74 72 69 6e 67 52 65 73 75 6c 74 28 GetStringResult(
0dc0: 69 6e 74 65 72 70 29 29 3b 0a 0a 09 09 54 63 6c interp));....Tcl
0dd0: 5f 44 65 6c 65 74 65 49 6e 74 65 72 70 28 69 6e _DeleteInterp(in
0de0: 74 65 72 70 29 3b 0a 0a 09 09 72 65 74 75 72 6e terp);....return
0df0: 28 4e 55 4c 4c 29 3b 0a 09 7d 0a 0a 09 2f 2a 0a (NULL);..}.../*.
0e00: 09 20 2a 20 53 65 74 20 67 6c 6f 62 61 6c 20 76 . * Set global v
0e10: 61 72 69 61 62 6c 65 73 20 66 72 6f 6d 20 43 20 ariables from C
0e20: 74 6f 20 54 63 6c 0a 09 20 2a 2f 0a 09 69 66 20 to Tcl.. */..if
0e30: 28 54 63 6c 5f 53 65 74 56 61 72 28 69 6e 74 65 (Tcl_SetVar(inte
0e40: 72 70 2c 20 22 3a 3a 61 70 70 66 73 3a 3a 63 61 rp, "::appfs::ca
0e50: 63 68 65 64 69 72 22 2c 20 63 61 63 68 65 64 69 chedir", cachedi
0e60: 72 2c 20 54 43 4c 5f 47 4c 4f 42 41 4c 5f 4f 4e r, TCL_GLOBAL_ON
0e70: 4c 59 29 20 3d 3d 20 4e 55 4c 4c 29 20 7b 0a 09 LY) == NULL) {..
0e80: 09 66 70 72 69 6e 74 66 28 73 74 64 65 72 72 2c .fprintf(stderr,
0e90: 20 22 55 6e 61 62 6c 65 20 74 6f 20 73 65 74 20 "Unable to set
0ea0: 63 61 63 68 65 20 64 69 72 65 63 74 6f 72 79 2e cache directory.
0eb0: 20 20 54 68 69 73 20 73 68 6f 75 6c 64 20 6e 65 This should ne
0ec0: 76 65 72 20 66 61 69 6c 2e 5c 6e 22 29 3b 0a 0a ver fail.\n");..
0ed0: 09 09 54 63 6c 5f 44 65 6c 65 74 65 49 6e 74 65 ..Tcl_DeleteInte
0ee0: 72 70 28 69 6e 74 65 72 70 29 3b 0a 0a 09 09 72 rp(interp);....r
0ef0: 65 74 75 72 6e 28 4e 55 4c 4c 29 3b 0a 09 7d 0a eturn(NULL);..}.
0f00: 0a 09 2f 2a 0a 09 20 2a 20 49 6e 69 74 69 61 6c ../*.. * Initial
0f10: 69 7a 65 20 74 68 65 20 22 61 70 70 66 73 64 2e ize the "appfsd.
0f20: 74 63 6c 22 20 65 6e 76 69 72 6f 6e 6d 65 6e 74 tcl" environment
0f30: 2c 20 77 68 69 63 68 20 6d 75 73 74 20 62 65 20 , which must be
0f40: 64 6f 6e 65 20 61 66 74 65 72 0a 09 20 2a 20 67 done after.. * g
0f50: 6c 6f 62 61 6c 20 76 61 72 69 61 62 6c 65 73 20 lobal variables
0f60: 61 72 65 20 73 65 74 2e 0a 09 20 2a 2f 0a 09 74 are set... */..t
0f70: 63 6c 5f 72 65 74 20 3d 20 54 63 6c 5f 45 76 61 cl_ret = Tcl_Eva
0f80: 6c 28 69 6e 74 65 72 70 2c 20 22 3a 3a 61 70 70 l(interp, "::app
0f90: 66 73 3a 3a 69 6e 69 74 22 29 3b 0a 09 69 66 20 fs::init");..if
0fa0: 28 74 63 6c 5f 72 65 74 20 21 3d 20 54 43 4c 5f (tcl_ret != TCL_
0fb0: 4f 4b 29 20 7b 0a 09 09 66 70 72 69 6e 74 66 28 OK) {...fprintf(
0fc0: 73 74 64 65 72 72 2c 20 22 55 6e 61 62 6c 65 20 stderr, "Unable
0fd0: 74 6f 20 69 6e 69 74 69 61 6c 69 7a 65 20 54 63 to initialize Tc
0fe0: 6c 20 41 70 70 46 53 20 73 63 72 69 70 74 20 28 l AppFS script (
0ff0: 3a 3a 61 70 70 66 73 3a 3a 69 6e 69 74 29 2e 20 ::appfs::init).
1000: 20 41 62 6f 72 74 69 6e 67 2e 5c 6e 22 29 3b 0a Aborting.\n");.
1010: 09 09 66 70 72 69 6e 74 66 28 73 74 64 65 72 72 ..fprintf(stderr
1020: 2c 20 22 54 63 6c 20 45 72 72 6f 72 20 69 73 3a , "Tcl Error is:
1030: 20 25 73 5c 6e 22 2c 20 54 63 6c 5f 47 65 74 53 %s\n", Tcl_GetS
1040: 74 72 69 6e 67 52 65 73 75 6c 74 28 69 6e 74 65 tringResult(inte
1050: 72 70 29 29 3b 0a 0a 09 09 54 63 6c 5f 44 65 6c rp));....Tcl_Del
1060: 65 74 65 49 6e 74 65 72 70 28 69 6e 74 65 72 70 eteInterp(interp
1070: 29 3b 0a 0a 09 09 72 65 74 75 72 6e 28 4e 55 4c );....return(NUL
1080: 4c 29 3b 0a 09 7d 0a 0a 09 2f 2a 0a 09 20 2a 20 L);..}.../*.. *
1090: 48 69 64 65 20 73 6f 6d 65 20 54 63 6c 20 63 6f Hide some Tcl co
10a0: 6d 6d 61 6e 64 73 20 74 68 61 74 20 77 65 20 64 mmands that we d
10b0: 6f 20 6e 6f 74 20 63 61 72 65 20 74 6f 20 75 73 o not care to us
10c0: 65 20 61 6e 64 20 77 68 69 63 68 20 6d 61 79 0a e and which may.
10d0: 09 20 2a 20 73 6c 6f 77 20 64 6f 77 6e 20 72 75 . * slow down ru
10e0: 6e 2d 74 69 6d 65 20 6f 70 65 72 61 74 69 6f 6e n-time operation
10f0: 73 2e 0a 09 20 2a 2f 0a 09 54 63 6c 5f 48 69 64 s... */..Tcl_Hid
1100: 65 43 6f 6d 6d 61 6e 64 28 69 6e 74 65 72 70 2c eCommand(interp,
1110: 20 22 61 75 74 6f 5f 6c 6f 61 64 5f 69 6e 64 65 "auto_load_inde
1120: 78 22 2c 20 22 61 75 74 6f 5f 6c 6f 61 64 5f 69 x", "auto_load_i
1130: 6e 64 65 78 22 29 3b 0a 09 54 63 6c 5f 48 69 64 ndex");..Tcl_Hid
1140: 65 43 6f 6d 6d 61 6e 64 28 69 6e 74 65 72 70 2c eCommand(interp,
1150: 20 22 75 6e 6b 6e 6f 77 6e 22 2c 20 22 75 6e 6b "unknown", "unk
1160: 6e 6f 77 6e 22 29 3b 0a 0a 09 2f 2a 0a 09 20 2a nown");.../*.. *
1170: 20 52 65 74 75 72 6e 20 74 68 65 20 63 6f 6d 70 Return the comp
1180: 6c 65 74 65 6c 79 20 69 6e 69 74 69 61 6c 69 7a letely initializ
1190: 65 64 20 69 6e 74 65 72 70 72 65 74 65 72 0a 09 ed interpreter..
11a0: 20 2a 2f 0a 09 72 65 74 75 72 6e 28 69 6e 74 65 */..return(inte
11b0: 72 70 29 3b 0a 7d 0a 0a 2f 2a 0a 20 2a 20 52 65 rp);.}../*. * Re
11c0: 74 75 72 6e 20 74 68 65 20 74 68 72 65 61 64 2d turn the thread-
11d0: 73 70 65 63 69 66 69 63 20 54 63 6c 20 69 6e 74 specific Tcl int
11e0: 65 72 70 72 65 74 65 72 2c 20 63 72 65 61 74 69 erpreter, creati
11f0: 6e 67 20 69 74 20 69 66 20 6e 65 65 64 65 64 0a ng it if needed.
1200: 20 2a 2f 0a 73 74 61 74 69 63 20 54 63 6c 5f 49 */.static Tcl_I
1210: 6e 74 65 72 70 20 2a 61 70 70 66 73 5f 54 63 6c nterp *appfs_Tcl
1220: 49 6e 74 65 72 70 28 76 6f 69 64 29 20 7b 0a 09 Interp(void) {..
1230: 54 63 6c 5f 49 6e 74 65 72 70 20 2a 69 6e 74 65 Tcl_Interp *inte
1240: 72 70 3b 0a 09 69 6e 74 20 70 74 68 72 65 61 64 rp;..int pthread
1250: 5f 72 65 74 3b 0a 0a 09 69 6e 74 65 72 70 20 3d _ret;...interp =
1260: 20 70 74 68 72 65 61 64 5f 67 65 74 73 70 65 63 pthread_getspec
1270: 69 66 69 63 28 69 6e 74 65 72 70 4b 65 79 29 3b ific(interpKey);
1280: 0a 09 69 66 20 28 69 6e 74 65 72 70 20 3d 3d 20 ..if (interp ==
1290: 4e 55 4c 4c 29 20 7b 0a 09 09 69 6e 74 65 72 70 NULL) {...interp
12a0: 20 3d 20 61 70 70 66 73 5f 63 72 65 61 74 65 5f = appfs_create_
12b0: 54 63 6c 49 6e 74 65 72 70 28 29 3b 0a 0a 09 09 TclInterp();....
12c0: 69 66 20 28 69 6e 74 65 72 70 20 3d 3d 20 4e 55 if (interp == NU
12d0: 4c 4c 29 20 7b 0a 09 09 09 72 65 74 75 72 6e 28 LL) {....return(
12e0: 4e 55 4c 4c 29 3b 0a 09 09 7d 0a 0a 09 09 70 74 NULL);...}....pt
12f0: 68 72 65 61 64 5f 72 65 74 20 3d 20 70 74 68 72 hread_ret = pthr
1300: 65 61 64 5f 73 65 74 73 70 65 63 69 66 69 63 28 ead_setspecific(
1310: 69 6e 74 65 72 70 4b 65 79 2c 20 69 6e 74 65 72 interpKey, inter
1320: 70 29 3b 0a 09 09 69 66 20 28 70 74 68 72 65 61 p);...if (pthrea
1330: 64 5f 72 65 74 20 21 3d 20 30 29 20 7b 0a 09 09 d_ret != 0) {...
1340: 09 54 63 6c 5f 44 65 6c 65 74 65 49 6e 74 65 72 .Tcl_DeleteInter
1350: 70 28 69 6e 74 65 72 70 29 3b 0a 0a 09 09 09 72 p(interp);.....r
1360: 65 74 75 72 6e 28 4e 55 4c 4c 29 3b 0a 09 09 7d eturn(NULL);...}
1370: 0a 09 7d 0a 0a 09 72 65 74 75 72 6e 28 69 6e 74 ..}...return(int
1380: 65 72 70 29 3b 0a 7d 0a 0a 2f 2a 0a 20 2a 20 45 erp);.}../*. * E
1390: 76 61 6c 75 61 74 65 20 61 20 54 63 6c 20 73 63 valuate a Tcl sc
13a0: 72 69 70 74 20 63 6f 6e 73 74 72 75 63 74 65 64 ript constructed
13b0: 20 62 79 20 63 6f 6e 63 61 74 65 6e 61 74 69 6e by concatenatin
13c0: 67 20 61 20 62 75 6e 63 68 20 6f 66 20 43 20 73 g a bunch of C s
13d0: 74 72 69 6e 67 73 0a 20 2a 20 74 6f 67 65 74 68 trings. * togeth
13e0: 65 72 2e 0a 20 2a 2f 0a 73 74 61 74 69 63 20 69 er.. */.static i
13f0: 6e 74 20 61 70 70 66 73 5f 54 63 6c 5f 45 76 61 nt appfs_Tcl_Eva
1400: 6c 28 54 63 6c 5f 49 6e 74 65 72 70 20 2a 69 6e l(Tcl_Interp *in
1410: 74 65 72 70 2c 20 69 6e 74 20 6f 62 6a 63 2c 20 terp, int objc,
1420: 63 6f 6e 73 74 20 63 68 61 72 20 2a 63 6d 64 2c const char *cmd,
1430: 20 2e 2e 2e 29 20 7b 0a 09 54 63 6c 5f 4f 62 6a ...) {..Tcl_Obj
1440: 20 2a 2a 6f 62 6a 76 3b 0a 09 63 6f 6e 73 74 20 **objv;..const
1450: 63 68 61 72 20 2a 61 72 67 3b 0a 09 76 61 5f 6c char *arg;..va_l
1460: 69 73 74 20 61 72 67 70 3b 0a 09 69 6e 74 20 72 ist argp;..int r
1470: 65 74 76 61 6c 3b 0a 09 69 6e 74 20 69 3b 0a 0a etval;..int i;..
1480: 09 69 66 20 28 69 6e 74 65 72 70 20 3d 3d 20 4e .if (interp == N
1490: 55 4c 4c 29 20 7b 0a 09 09 72 65 74 75 72 6e 28 ULL) {...return(
14a0: 54 43 4c 5f 45 52 52 4f 52 29 3b 0a 09 7d 0a 0a TCL_ERROR);..}..
14b0: 09 6f 62 6a 76 20 3d 20 28 76 6f 69 64 20 2a 29 .objv = (void *)
14c0: 20 63 6b 61 6c 6c 6f 63 28 73 69 7a 65 6f 66 28 ckalloc(sizeof(
14d0: 2a 6f 62 6a 76 29 20 2a 20 6f 62 6a 63 29 3b 0a *objv) * objc);.
14e0: 09 6f 62 6a 76 5b 30 5d 20 3d 20 54 63 6c 5f 4e .objv[0] = Tcl_N
14f0: 65 77 53 74 72 69 6e 67 4f 62 6a 28 63 6d 64 2c ewStringObj(cmd,
1500: 20 2d 31 29 3b 0a 09 54 63 6c 5f 49 6e 63 72 52 -1);..Tcl_IncrR
1510: 65 66 43 6f 75 6e 74 28 6f 62 6a 76 5b 30 5d 29 efCount(objv[0])
1520: 3b 0a 0a 09 76 61 5f 73 74 61 72 74 28 61 72 67 ;...va_start(arg
1530: 70 2c 20 63 6d 64 29 3b 0a 09 66 6f 72 20 28 69 p, cmd);..for (i
1540: 20 3d 20 31 3b 20 69 20 3c 20 6f 62 6a 63 3b 20 = 1; i < objc;
1550: 69 2b 2b 29 20 7b 0a 09 09 61 72 67 20 3d 20 76 i++) {...arg = v
1560: 61 5f 61 72 67 28 61 72 67 70 2c 20 63 6f 6e 73 a_arg(argp, cons
1570: 74 20 63 68 61 72 20 2a 29 3b 0a 09 09 6f 62 6a t char *);...obj
1580: 76 5b 69 5d 20 3d 20 54 63 6c 5f 4e 65 77 53 74 v[i] = Tcl_NewSt
1590: 72 69 6e 67 4f 62 6a 28 61 72 67 2c 20 2d 31 29 ringObj(arg, -1)
15a0: 3b 0a 09 09 54 63 6c 5f 49 6e 63 72 52 65 66 43 ;...Tcl_IncrRefC
15b0: 6f 75 6e 74 28 6f 62 6a 76 5b 69 5d 29 3b 0a 09 ount(objv[i]);..
15c0: 7d 0a 09 76 61 5f 65 6e 64 28 61 72 67 70 29 3b }..va_end(argp);
15d0: 0a 0a 09 72 65 74 76 61 6c 20 3d 20 54 63 6c 5f ...retval = Tcl_
15e0: 45 76 61 6c 4f 62 6a 76 28 69 6e 74 65 72 70 2c EvalObjv(interp,
15f0: 20 6f 62 6a 63 2c 20 6f 62 6a 76 2c 20 30 29 3b objc, objv, 0);
1600: 0a 0a 09 66 6f 72 20 28 69 20 3d 20 30 3b 20 69 ...for (i = 0; i
1610: 20 3c 20 6f 62 6a 63 3b 20 69 2b 2b 29 20 7b 0a < objc; i++) {.
1620: 09 09 54 63 6c 5f 44 65 63 72 52 65 66 43 6f 75 ..Tcl_DecrRefCou
1630: 6e 74 28 6f 62 6a 76 5b 69 5d 29 3b 0a 09 7d 0a nt(objv[i]);..}.
1640: 0a 09 63 6b 66 72 65 65 28 28 76 6f 69 64 20 2a ..ckfree((void *
1650: 29 20 6f 62 6a 76 29 3b 0a 0a 09 69 66 20 28 72 ) objv);...if (r
1660: 65 74 76 61 6c 20 21 3d 20 54 43 4c 5f 4f 4b 29 etval != TCL_OK)
1670: 20 7b 0a 09 09 41 50 50 46 53 5f 44 45 42 55 47 {...APPFS_DEBUG
1680: 28 22 54 63 6c 20 63 6f 6d 6d 61 6e 64 20 66 61 ("Tcl command fa
1690: 69 6c 65 64 2c 20 3a 3a 65 72 72 6f 72 49 6e 66 iled, ::errorInf
16a0: 6f 20 63 6f 6e 74 61 69 6e 73 3a 20 25 73 5c 6e o contains: %s\n
16b0: 22 2c 20 54 63 6c 5f 47 65 74 56 61 72 28 69 6e ", Tcl_GetVar(in
16c0: 74 65 72 70 2c 20 22 3a 3a 65 72 72 6f 72 49 6e terp, "::errorIn
16d0: 66 6f 22 2c 20 30 29 29 3b 0a 09 7d 0a 0a 09 72 fo", 0));..}...r
16e0: 65 74 75 72 6e 28 72 65 74 76 61 6c 29 3b 0a 7d eturn(retval);.}
16f0: 0a 0a 2f 2a 0a 20 2a 20 41 70 70 46 53 3a 20 52 ../*. * AppFS: R
1700: 65 71 75 65 73 74 20 74 68 61 74 20 61 20 68 6f equest that a ho
1710: 73 74 27 73 20 70 61 63 6b 61 67 65 20 69 6e 64 st's package ind
1720: 65 78 20 62 65 20 75 70 64 61 74 65 64 20 6c 6f ex be updated lo
1730: 63 61 6c 6c 79 0a 20 2a 2f 0a 73 74 61 74 69 63 cally. */.static
1740: 20 76 6f 69 64 20 61 70 70 66 73 5f 75 70 64 61 void appfs_upda
1750: 74 65 5f 69 6e 64 65 78 28 63 6f 6e 73 74 20 63 te_index(const c
1760: 68 61 72 20 2a 68 6f 73 74 6e 61 6d 65 29 20 7b har *hostname) {
1770: 0a 09 54 63 6c 5f 49 6e 74 65 72 70 20 2a 69 6e ..Tcl_Interp *in
1780: 74 65 72 70 3b 0a 09 69 6e 74 20 74 63 6c 5f 72 terp;..int tcl_r
1790: 65 74 3b 0a 0a 09 41 50 50 46 53 5f 44 45 42 55 et;...APPFS_DEBU
17a0: 47 28 22 45 6e 74 65 72 3a 20 68 6f 73 74 6e 61 G("Enter: hostna
17b0: 6d 65 20 3d 20 25 73 22 2c 20 68 6f 73 74 6e 61 me = %s", hostna
17c0: 6d 65 29 3b 0a 0a 09 69 6e 74 65 72 70 20 3d 20 me);...interp =
17d0: 61 70 70 66 73 5f 54 63 6c 49 6e 74 65 72 70 28 appfs_TclInterp(
17e0: 29 3b 0a 09 69 66 20 28 69 6e 74 65 72 70 20 3d );..if (interp =
17f0: 3d 20 4e 55 4c 4c 29 20 7b 0a 09 09 72 65 74 75 = NULL) {...retu
1800: 72 6e 3b 0a 09 7d 0a 0a 09 74 63 6c 5f 72 65 74 rn;..}...tcl_ret
1810: 20 3d 20 61 70 70 66 73 5f 54 63 6c 5f 45 76 61 = appfs_Tcl_Eva
1820: 6c 28 69 6e 74 65 72 70 2c 20 32 2c 20 22 3a 3a l(interp, 2, "::
1830: 61 70 70 66 73 3a 3a 67 65 74 69 6e 64 65 78 22 appfs::getindex"
1840: 2c 20 68 6f 73 74 6e 61 6d 65 29 3b 0a 09 69 66 , hostname);..if
1850: 20 28 74 63 6c 5f 72 65 74 20 21 3d 20 54 43 4c (tcl_ret != TCL
1860: 5f 4f 4b 29 20 7b 0a 09 09 41 50 50 46 53 5f 44 _OK) {...APPFS_D
1870: 45 42 55 47 28 22 43 61 6c 6c 20 74 6f 20 3a 3a EBUG("Call to ::
1880: 61 70 70 66 73 3a 3a 67 65 74 69 6e 64 65 78 20 appfs::getindex
1890: 66 61 69 6c 65 64 3a 20 25 73 22 2c 20 54 63 6c failed: %s", Tcl
18a0: 5f 47 65 74 53 74 72 69 6e 67 52 65 73 75 6c 74 _GetStringResult
18b0: 28 69 6e 74 65 72 70 29 29 3b 0a 0a 09 09 72 65 (interp));....re
18c0: 74 75 72 6e 3b 0a 09 7d 0a 0a 09 72 65 74 75 72 turn;..}...retur
18d0: 6e 3b 0a 7d 0a 0a 2f 2a 0a 20 2a 20 41 70 70 46 n;.}../*. * AppF
18e0: 53 3a 20 47 65 74 20 61 20 53 48 41 31 20 66 72 S: Get a SHA1 fr
18f0: 6f 6d 20 61 20 68 6f 73 74 0a 20 2a 20 20 20 20 om a host. *
1900: 20 20 20 20 20 52 65 74 75 72 6e 73 20 61 20 6c Returns a l
1910: 6f 63 61 6c 20 66 69 6c 65 20 6e 61 6d 65 2c 20 ocal file name,
1920: 6f 72 20 4e 55 4c 4c 20 69 66 20 69 74 20 63 61 or NULL if it ca
1930: 6e 6e 6f 74 20 62 65 20 66 65 74 63 68 65 64 0a nnot be fetched.
1940: 20 2a 2f 0a 73 74 61 74 69 63 20 63 6f 6e 73 74 */.static const
1950: 20 63 68 61 72 20 2a 61 70 70 66 73 5f 67 65 74 char *appfs_get
1960: 66 69 6c 65 28 63 6f 6e 73 74 20 63 68 61 72 20 file(const char
1970: 2a 68 6f 73 74 6e 61 6d 65 2c 20 63 6f 6e 73 74 *hostname, const
1980: 20 63 68 61 72 20 2a 73 68 61 31 29 20 7b 0a 09 char *sha1) {..
1990: 54 63 6c 5f 49 6e 74 65 72 70 20 2a 69 6e 74 65 Tcl_Interp *inte
19a0: 72 70 3b 0a 09 63 68 61 72 20 2a 72 65 74 76 61 rp;..char *retva
19b0: 6c 3b 0a 09 69 6e 74 20 74 63 6c 5f 72 65 74 3b l;..int tcl_ret;
19c0: 0a 0a 09 69 6e 74 65 72 70 20 3d 20 61 70 70 66 ...interp = appf
19d0: 73 5f 54 63 6c 49 6e 74 65 72 70 28 29 3b 0a 09 s_TclInterp();..
19e0: 69 66 20 28 69 6e 74 65 72 70 20 3d 3d 20 4e 55 if (interp == NU
19f0: 4c 4c 29 20 7b 0a 09 09 72 65 74 75 72 6e 28 4e LL) {...return(N
1a00: 55 4c 4c 29 3b 0a 09 7d 0a 0a 09 74 63 6c 5f 72 ULL);..}...tcl_r
1a10: 65 74 20 3d 20 61 70 70 66 73 5f 54 63 6c 5f 45 et = appfs_Tcl_E
1a20: 76 61 6c 28 69 6e 74 65 72 70 2c 20 33 2c 20 22 val(interp, 3, "
1a30: 3a 3a 61 70 70 66 73 3a 3a 64 6f 77 6e 6c 6f 61 ::appfs::downloa
1a40: 64 22 2c 20 68 6f 73 74 6e 61 6d 65 2c 20 73 68 d", hostname, sh
1a50: 61 31 29 3b 0a 09 69 66 20 28 74 63 6c 5f 72 65 a1);..if (tcl_re
1a60: 74 20 21 3d 20 54 43 4c 5f 4f 4b 29 20 7b 0a 09 t != TCL_OK) {..
1a70: 09 41 50 50 46 53 5f 44 45 42 55 47 28 22 43 61 .APPFS_DEBUG("Ca
1a80: 6c 6c 20 74 6f 20 3a 3a 61 70 70 66 73 3a 3a 64 ll to ::appfs::d
1a90: 6f 77 6e 6c 6f 61 64 20 66 61 69 6c 65 64 3a 20 ownload failed:
1aa0: 25 73 22 2c 20 54 63 6c 5f 47 65 74 53 74 72 69 %s", Tcl_GetStri
1ab0: 6e 67 52 65 73 75 6c 74 28 69 6e 74 65 72 70 29 ngResult(interp)
1ac0: 29 3b 0a 0a 09 09 72 65 74 75 72 6e 28 4e 55 4c );....return(NUL
1ad0: 4c 29 3b 0a 09 7d 0a 0a 09 72 65 74 76 61 6c 20 L);..}...retval
1ae0: 3d 20 73 74 72 64 75 70 28 54 63 6c 5f 47 65 74 = strdup(Tcl_Get
1af0: 53 74 72 69 6e 67 52 65 73 75 6c 74 28 69 6e 74 StringResult(int
1b00: 65 72 70 29 29 3b 0a 0a 09 72 65 74 75 72 6e 28 erp));...return(
1b10: 72 65 74 76 61 6c 29 3b 0a 7d 0a 0a 2f 2a 0a 20 retval);.}../*.
1b20: 2a 20 41 70 70 46 53 3a 20 55 70 64 61 74 65 20 * AppFS: Update
1b30: 74 68 65 20 6d 61 6e 69 66 65 73 74 20 66 6f 72 the manifest for
1b40: 20 61 20 73 70 65 63 69 66 69 63 20 70 61 63 6b a specific pack
1b50: 61 67 65 20 28 62 79 20 74 68 65 20 70 61 63 6b age (by the pack
1b60: 61 67 65 20 53 48 41 31 29 20 6f 6e 0a 20 2a 20 age SHA1) on. *
1b70: 61 20 67 69 76 65 6e 20 68 6f 73 74 0a 20 2a 2f a given host. */
1b80: 0a 73 74 61 74 69 63 20 76 6f 69 64 20 61 70 70 .static void app
1b90: 66 73 5f 75 70 64 61 74 65 5f 6d 61 6e 69 66 65 fs_update_manife
1ba0: 73 74 28 63 6f 6e 73 74 20 63 68 61 72 20 2a 68 st(const char *h
1bb0: 6f 73 74 6e 61 6d 65 2c 20 63 6f 6e 73 74 20 63 ostname, const c
1bc0: 68 61 72 20 2a 73 68 61 31 29 20 7b 0a 09 54 63 har *sha1) {..Tc
1bd0: 6c 5f 49 6e 74 65 72 70 20 2a 69 6e 74 65 72 70 l_Interp *interp
1be0: 3b 0a 09 69 6e 74 20 74 63 6c 5f 72 65 74 3b 0a ;..int tcl_ret;.
1bf0: 0a 09 69 6e 74 65 72 70 20 3d 20 61 70 70 66 73 ..interp = appfs
1c00: 5f 54 63 6c 49 6e 74 65 72 70 28 29 3b 0a 09 69 _TclInterp();..i
1c10: 66 20 28 69 6e 74 65 72 70 20 3d 3d 20 4e 55 4c f (interp == NUL
1c20: 4c 29 20 7b 0a 09 09 72 65 74 75 72 6e 3b 0a 09 L) {...return;..
1c30: 7d 0a 0a 09 74 63 6c 5f 72 65 74 20 3d 20 61 70 }...tcl_ret = ap
1c40: 70 66 73 5f 54 63 6c 5f 45 76 61 6c 28 69 6e 74 pfs_Tcl_Eval(int
1c50: 65 72 70 2c 20 33 2c 20 22 3a 3a 61 70 70 66 73 erp, 3, "::appfs
1c60: 3a 3a 67 65 74 70 6b 67 6d 61 6e 69 66 65 73 74 ::getpkgmanifest
1c70: 22 2c 20 68 6f 73 74 6e 61 6d 65 2c 20 73 68 61 ", hostname, sha
1c80: 31 29 3b 0a 09 69 66 20 28 74 63 6c 5f 72 65 74 1);..if (tcl_ret
1c90: 20 21 3d 20 54 43 4c 5f 4f 4b 29 20 7b 0a 09 09 != TCL_OK) {...
1ca0: 41 50 50 46 53 5f 44 45 42 55 47 28 22 43 61 6c APPFS_DEBUG("Cal
1cb0: 6c 20 74 6f 20 3a 3a 61 70 70 66 73 3a 3a 67 65 l to ::appfs::ge
1cc0: 74 70 6b 67 6d 61 6e 69 66 65 73 74 20 66 61 69 tpkgmanifest fai
1cd0: 6c 65 64 3a 20 25 73 22 2c 20 54 63 6c 5f 47 65 led: %s", Tcl_Ge
1ce0: 74 53 74 72 69 6e 67 52 65 73 75 6c 74 28 69 6e tStringResult(in
1cf0: 74 65 72 70 29 29 3b 0a 0a 09 09 72 65 74 75 72 terp));....retur
1d00: 6e 3b 0a 09 7d 0a 0a 09 72 65 74 75 72 6e 3b 0a n;..}...return;.
1d10: 7d 0a 0a 2f 2a 0a 20 2a 20 44 65 74 65 72 6d 69 }../*. * Determi
1d20: 6e 65 20 74 68 65 20 55 49 44 20 66 6f 72 20 74 ne the UID for t
1d30: 68 65 20 75 73 65 72 20 6d 61 6b 69 6e 67 20 74 he user making t
1d40: 68 65 20 63 75 72 72 65 6e 74 20 46 55 53 45 20 he current FUSE
1d50: 66 69 6c 65 73 79 73 74 65 6d 20 72 65 71 75 65 filesystem reque
1d60: 73 74 2e 0a 20 2a 20 54 68 69 73 20 77 69 6c 6c st.. * This will
1d70: 20 62 65 20 75 73 65 64 20 74 6f 20 6c 6f 6f 6b be used to look
1d80: 75 70 20 74 68 65 20 75 73 65 72 27 73 20 68 6f up the user's ho
1d90: 6d 65 20 64 69 72 65 63 74 6f 72 79 20 73 6f 20 me directory so
1da0: 77 65 20 63 61 6e 20 73 65 61 72 63 68 20 66 6f we can search fo
1db0: 72 0a 20 2a 20 6c 6f 63 61 6c 6c 79 20 6d 6f 64 r. * locally mod
1dc0: 69 66 69 65 64 20 66 69 6c 65 73 2e 0a 20 2a 2f ified files.. */
1dd0: 0a 73 74 61 74 69 63 20 75 69 64 5f 74 20 61 70 .static uid_t ap
1de0: 70 66 73 5f 67 65 74 5f 66 73 75 69 64 28 76 6f pfs_get_fsuid(vo
1df0: 69 64 29 20 7b 0a 09 73 74 72 75 63 74 20 66 75 id) {..struct fu
1e00: 73 65 5f 63 6f 6e 74 65 78 74 20 2a 63 74 78 3b se_context *ctx;
1e10: 0a 0a 09 63 74 78 20 3d 20 66 75 73 65 5f 67 65 ...ctx = fuse_ge
1e20: 74 5f 63 6f 6e 74 65 78 74 28 29 3b 0a 09 69 66 t_context();..if
1e30: 20 28 63 74 78 20 3d 3d 20 4e 55 4c 4c 29 20 7b (ctx == NULL) {
1e40: 0a 09 09 2f 2a 20 55 6e 61 62 6c 65 20 74 6f 20 .../* Unable to
1e50: 6c 6f 6f 6b 75 70 20 75 73 65 72 20 66 6f 72 20 lookup user for
1e60: 73 6f 6d 65 20 72 65 61 73 6f 6e 20 2a 2f 0a 09 some reason */..
1e70: 09 2f 2a 20 52 65 74 75 72 6e 20 61 6e 20 75 6e ./* Return an un
1e80: 70 72 69 76 69 6c 65 67 65 64 20 75 73 65 72 20 privileged user
1e90: 49 44 20 2a 2f 0a 09 09 72 65 74 75 72 6e 28 31 ID */...return(1
1ea0: 29 3b 0a 09 7d 0a 0a 09 72 65 74 75 72 6e 28 63 );..}...return(c
1eb0: 74 78 2d 3e 75 69 64 29 3b 0a 7d 0a 0a 2f 2a 0a tx->uid);.}../*.
1ec0: 20 2a 20 4c 6f 6f 6b 20 75 70 20 74 68 65 20 68 * Look up the h
1ed0: 6f 6d 65 20 64 69 72 65 63 74 6f 72 79 20 66 6f ome directory fo
1ee0: 72 20 61 20 67 69 76 65 6e 20 55 49 44 0a 20 2a r a given UID. *
1ef0: 20 20 20 20 20 20 20 20 52 65 74 75 72 6e 73 20 Returns
1f00: 61 20 43 20 73 74 72 69 6e 67 20 63 6f 6e 74 61 a C string conta
1f10: 69 6e 69 6e 67 20 74 68 65 20 75 73 65 72 27 73 ining the user's
1f20: 20 68 6f 6d 65 20 64 69 72 65 63 74 6f 72 79 20 home directory
1f30: 6f 72 20 4e 55 4c 4c 20 69 66 0a 20 2a 20 20 20 or NULL if. *
1f40: 20 20 20 20 20 74 68 65 20 75 73 65 72 27 73 20 the user's
1f50: 68 6f 6d 65 20 64 69 72 65 63 74 6f 72 79 20 64 home directory d
1f60: 6f 65 73 20 6e 6f 74 20 65 78 69 73 74 20 6f 72 oes not exist or
1f70: 20 69 73 20 6e 6f 74 20 63 6f 72 72 65 63 74 6c is not correctl
1f80: 79 0a 20 2a 20 20 20 20 20 20 20 20 63 6f 6e 66 y. * conf
1f90: 69 67 75 72 65 64 0a 20 2a 2f 0a 73 74 61 74 69 igured. */.stati
1fa0: 63 20 63 68 61 72 20 2a 61 70 70 66 73 5f 67 65 c char *appfs_ge
1fb0: 74 5f 68 6f 6d 65 64 69 72 28 75 69 64 5f 74 20 t_homedir(uid_t
1fc0: 66 73 75 69 64 29 20 7b 0a 09 73 74 72 75 63 74 fsuid) {..struct
1fd0: 20 70 61 73 73 77 64 20 65 6e 74 72 79 2c 20 2a passwd entry, *
1fe0: 72 65 73 75 6c 74 3b 0a 09 73 74 72 75 63 74 20 result;..struct
1ff0: 73 74 61 74 20 73 74 62 75 66 3b 0a 09 63 68 61 stat stbuf;..cha
2000: 72 20 62 75 66 5b 31 30 32 34 5d 2c 20 2a 72 65 r buf[1024], *re
2010: 74 76 61 6c 3b 0a 09 69 6e 74 20 67 70 75 5f 72 tval;..int gpu_r
2020: 65 74 2c 20 73 74 61 74 5f 72 65 74 3b 0a 0a 09 et, stat_ret;...
2030: 67 70 75 5f 72 65 74 20 3d 20 67 65 74 70 77 75 gpu_ret = getpwu
2040: 69 64 5f 72 28 66 73 75 69 64 2c 20 26 65 6e 74 id_r(fsuid, &ent
2050: 72 79 2c 20 62 75 66 2c 20 73 69 7a 65 6f 66 28 ry, buf, sizeof(
2060: 62 75 66 29 2c 20 26 72 65 73 75 6c 74 29 3b 0a buf), &result);.
2070: 09 69 66 20 28 67 70 75 5f 72 65 74 20 21 3d 20 .if (gpu_ret !=
2080: 30 29 20 7b 0a 09 09 41 50 50 46 53 5f 44 45 42 0) {...APPFS_DEB
2090: 55 47 28 22 67 65 74 70 77 75 69 64 5f 72 28 25 UG("getpwuid_r(%
20a0: 6c 6c 75 2c 20 2e 2e 2e 29 20 72 65 74 75 72 6e llu, ...) return
20b0: 65 64 20 69 6e 20 66 61 69 6c 75 72 65 22 2c 20 ed in failure",
20c0: 28 75 6e 73 69 67 6e 65 64 20 6c 6f 6e 67 20 6c (unsigned long l
20d0: 6f 6e 67 29 20 66 73 75 69 64 29 3b 0a 0a 09 09 ong) fsuid);....
20e0: 72 65 74 75 72 6e 28 4e 55 4c 4c 29 3b 0a 09 7d return(NULL);..}
20f0: 0a 0a 09 69 66 20 28 72 65 73 75 6c 74 20 3d 3d ...if (result ==
2100: 20 4e 55 4c 4c 29 20 7b 0a 09 09 41 50 50 46 53 NULL) {...APPFS
2110: 5f 44 45 42 55 47 28 22 67 65 74 70 77 75 69 64 _DEBUG("getpwuid
2120: 5f 72 28 25 6c 6c 75 2c 20 2e 2e 2e 29 20 72 65 _r(%llu, ...) re
2130: 74 75 72 6e 65 64 20 4e 55 4c 4c 20 72 65 73 75 turned NULL resu
2140: 6c 74 22 2c 20 28 75 6e 73 69 67 6e 65 64 20 6c lt", (unsigned l
2150: 6f 6e 67 20 6c 6f 6e 67 29 20 66 73 75 69 64 29 ong long) fsuid)
2160: 3b 0a 0a 09 09 72 65 74 75 72 6e 28 4e 55 4c 4c ;....return(NULL
2170: 29 3b 0a 09 7d 0a 0a 09 69 66 20 28 72 65 73 75 );..}...if (resu
2180: 6c 74 2d 3e 70 77 5f 64 69 72 20 3d 3d 20 4e 55 lt->pw_dir == NU
2190: 4c 4c 29 20 7b 0a 09 09 41 50 50 46 53 5f 44 45 LL) {...APPFS_DE
21a0: 42 55 47 28 22 67 65 74 70 77 75 69 64 5f 72 28 BUG("getpwuid_r(
21b0: 25 6c 6c 75 2c 20 2e 2e 2e 29 20 72 65 74 75 72 %llu, ...) retur
21c0: 6e 65 64 20 4e 55 4c 4c 20 68 6f 6d 65 20 64 69 ned NULL home di
21d0: 72 65 63 74 6f 72 79 22 2c 20 28 75 6e 73 69 67 rectory", (unsig
21e0: 6e 65 64 20 6c 6f 6e 67 20 6c 6f 6e 67 29 20 66 ned long long) f
21f0: 73 75 69 64 29 3b 0a 0a 09 09 72 65 74 75 72 6e suid);....return
2200: 28 4e 55 4c 4c 29 3b 0a 09 7d 0a 0a 09 73 74 61 (NULL);..}...sta
2210: 74 5f 72 65 74 20 3d 20 73 74 61 74 28 72 65 73 t_ret = stat(res
2220: 75 6c 74 2d 3e 70 77 5f 64 69 72 2c 20 26 73 74 ult->pw_dir, &st
2230: 62 75 66 29 3b 0a 09 69 66 20 28 73 74 61 74 5f buf);..if (stat_
2240: 72 65 74 20 21 3d 20 30 29 20 7b 0a 09 09 41 50 ret != 0) {...AP
2250: 50 46 53 5f 44 45 42 55 47 28 22 73 74 61 74 28 PFS_DEBUG("stat(
2260: 25 73 29 20 72 65 74 75 72 6e 65 64 20 69 6e 20 %s) returned in
2270: 66 61 69 6c 75 72 65 22 2c 20 72 65 73 75 6c 74 failure", result
2280: 2d 3e 70 77 5f 64 69 72 29 3b 0a 0a 09 09 72 65 ->pw_dir);....re
2290: 74 75 72 6e 28 4e 55 4c 4c 29 3b 0a 09 7d 0a 0a turn(NULL);..}..
22a0: 09 69 66 20 28 73 74 62 75 66 2e 73 74 5f 75 69 .if (stbuf.st_ui
22b0: 64 20 21 3d 20 66 73 75 69 64 29 20 7b 0a 09 09 d != fsuid) {...
22c0: 41 50 50 46 53 5f 44 45 42 55 47 28 22 55 49 44 APPFS_DEBUG("UID
22d0: 20 6d 69 73 2d 6d 61 74 63 68 20 6f 6e 20 75 73 mis-match on us
22e0: 65 72 20 25 6c 6c 75 27 73 20 68 6f 6d 65 20 64 er %llu's home d
22f0: 69 72 65 63 74 6f 72 79 20 28 25 73 29 2e 20 20 irectory (%s).
2300: 49 74 27 73 20 6f 77 6e 65 64 20 62 79 20 25 6c It's owned by %l
2310: 6c 75 2e 22 2c 0a 09 09 20 20 20 20 28 75 6e 73 lu.",... (uns
2320: 69 67 6e 65 64 20 6c 6f 6e 67 20 6c 6f 6e 67 29 igned long long)
2330: 20 66 73 75 69 64 2c 0a 09 09 20 20 20 20 72 65 fsuid,... re
2340: 73 75 6c 74 2d 3e 70 77 5f 64 69 72 2c 0a 09 09 sult->pw_dir,...
2350: 20 20 20 20 28 75 6e 73 69 67 6e 65 64 20 6c 6f (unsigned lo
2360: 6e 67 20 6c 6f 6e 67 29 20 73 74 62 75 66 2e 73 ng long) stbuf.s
2370: 74 5f 75 69 64 0a 09 09 29 3b 0a 0a 09 09 72 65 t_uid...);....re
2380: 74 75 72 6e 28 4e 55 4c 4c 29 3b 0a 09 7d 0a 0a turn(NULL);..}..
2390: 09 72 65 74 76 61 6c 20 3d 20 73 74 72 64 75 70 .retval = strdup
23a0: 28 72 65 73 75 6c 74 2d 3e 70 77 5f 64 69 72 29 (result->pw_dir)
23b0: 3b 0a 0a 09 72 65 74 75 72 6e 28 72 65 74 76 61 ;...return(retva
23c0: 6c 29 3b 0a 7d 0a 0a 2f 2a 0a 20 2a 20 54 63 6c l);.}../*. * Tcl
23d0: 20 69 6e 74 65 72 66 61 63 65 20 74 6f 20 67 65 interface to ge
23e0: 74 20 74 68 65 20 68 6f 6d 65 20 64 69 72 65 63 t the home direc
23f0: 74 6f 72 79 20 66 6f 72 20 74 68 65 20 75 73 65 tory for the use
2400: 72 20 6d 61 6b 69 6e 67 20 74 68 65 20 22 63 75 r making the "cu
2410: 72 72 65 6e 74 22 0a 20 2a 20 46 55 53 45 20 49 rrent". * FUSE I
2420: 2f 4f 20 72 65 71 75 65 73 74 0a 20 2a 2f 0a 73 /O request. */.s
2430: 74 61 74 69 63 20 69 6e 74 20 74 63 6c 5f 61 70 tatic int tcl_ap
2440: 70 66 73 5f 67 65 74 5f 68 6f 6d 65 64 69 72 28 pfs_get_homedir(
2450: 43 6c 69 65 6e 74 44 61 74 61 20 63 64 2c 20 54 ClientData cd, T
2460: 63 6c 5f 49 6e 74 65 72 70 20 2a 69 6e 74 65 72 cl_Interp *inter
2470: 70 2c 20 69 6e 74 20 6f 62 6a 63 2c 20 54 63 6c p, int objc, Tcl
2480: 5f 4f 62 6a 20 2a 43 4f 4e 53 54 20 6f 62 6a 76 _Obj *CONST objv
2490: 5b 5d 29 20 7b 0a 09 63 68 61 72 20 2a 68 6f 6d []) {..char *hom
24a0: 65 64 69 72 3b 0a 0a 20 20 20 20 20 20 20 20 69 edir;.. i
24b0: 66 20 28 6f 62 6a 63 20 21 3d 20 31 29 20 7b 0a f (objc != 1) {.
24c0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
24d0: 54 63 6c 5f 57 72 6f 6e 67 4e 75 6d 41 72 67 73 Tcl_WrongNumArgs
24e0: 28 69 6e 74 65 72 70 2c 20 31 2c 20 6f 62 6a 76 (interp, 1, objv
24f0: 2c 20 4e 55 4c 4c 29 3b 0a 20 20 20 20 20 20 20 , NULL);.
2500: 20 20 20 20 20 20 20 20 20 72 65 74 75 72 6e 28 return(
2510: 54 43 4c 5f 45 52 52 4f 52 29 3b 0a 20 20 20 20 TCL_ERROR);.
2520: 20 20 20 20 7d 0a 0a 09 68 6f 6d 65 64 69 72 20 }...homedir
2530: 3d 20 61 70 70 66 73 5f 67 65 74 5f 68 6f 6d 65 = appfs_get_home
2540: 64 69 72 28 61 70 70 66 73 5f 67 65 74 5f 66 73 dir(appfs_get_fs
2550: 75 69 64 28 29 29 3b 0a 0a 09 69 66 20 28 68 6f uid());...if (ho
2560: 6d 65 64 69 72 20 3d 3d 20 4e 55 4c 4c 29 20 7b medir == NULL) {
2570: 0a 09 09 72 65 74 75 72 6e 28 54 43 4c 5f 45 52 ...return(TCL_ER
2580: 52 4f 52 29 3b 0a 09 7d 0a 0a 20 20 20 20 20 20 ROR);..}..
2590: 20 20 54 63 6c 5f 53 65 74 4f 62 6a 52 65 73 75 Tcl_SetObjResu
25a0: 6c 74 28 69 6e 74 65 72 70 2c 20 54 63 6c 5f 4e lt(interp, Tcl_N
25b0: 65 77 53 74 72 69 6e 67 4f 62 6a 28 68 6f 6d 65 ewStringObj(home
25c0: 64 69 72 2c 20 2d 31 29 29 3b 0a 0a 09 66 72 65 dir, -1));...fre
25d0: 65 28 68 6f 6d 65 64 69 72 29 3b 0a 0a 20 20 20 e(homedir);..
25e0: 20 20 20 20 20 72 65 74 75 72 6e 28 54 43 4c 5f return(TCL_
25f0: 4f 4b 29 3b 0a 7d 0a 0a 2f 2a 0a 20 2a 20 47 65 OK);.}../*. * Ge
2600: 6e 65 72 61 74 65 20 61 6e 20 69 6e 6f 64 65 20 nerate an inode
2610: 66 6f 72 20 61 20 67 69 76 65 6e 20 70 61 74 68 for a given path
2620: 2e 20 20 54 68 65 20 69 6e 6f 64 65 20 73 68 6f . The inode sho
2630: 75 6c 64 20 62 65 20 63 6f 6d 70 75 74 65 64 20 uld be computed
2640: 69 6e 20 73 75 63 68 0a 20 2a 20 61 20 77 61 79 in such. * a way
2650: 20 74 68 61 74 20 69 74 20 69 73 20 75 6e 6c 69 that it is unli
2660: 6b 65 6c 79 20 74 6f 20 62 65 20 64 75 70 6c 69 kely to be dupli
2670: 63 61 74 65 64 20 61 6e 64 20 72 65 6d 61 69 6e cated and remain
2680: 73 20 74 68 65 20 73 61 6d 65 20 66 6f 72 20 61 s the same for a
2690: 20 67 69 76 65 6e 0a 20 2a 20 66 69 6c 65 0a 20 given. * file.
26a0: 2a 2f 0a 73 74 61 74 69 63 20 6c 6f 6e 67 20 6c */.static long l
26b0: 6f 6e 67 20 61 70 70 66 73 5f 67 65 74 5f 70 61 ong appfs_get_pa
26c0: 74 68 5f 69 6e 6f 64 65 28 63 6f 6e 73 74 20 63 th_inode(const c
26d0: 68 61 72 20 2a 70 61 74 68 29 20 7b 0a 09 6c 6f har *path) {..lo
26e0: 6e 67 20 6c 6f 6e 67 20 72 65 74 76 61 6c 3b 0a ng long retval;.
26f0: 09 63 6f 6e 73 74 20 63 68 61 72 20 2a 70 3b 0a .const char *p;.
2700: 0a 09 72 65 74 76 61 6c 20 3d 20 31 30 3b 0a 0a ..retval = 10;..
2710: 09 66 6f 72 20 28 70 20 3d 20 70 61 74 68 3b 20 .for (p = path;
2720: 2a 70 3b 20 70 2b 2b 29 20 7b 0a 09 09 72 65 74 *p; p++) {...ret
2730: 76 61 6c 20 25 3d 20 34 32 39 30 39 36 30 32 39 val %= 429096029
2740: 30 55 4c 4c 3b 0a 09 09 72 65 74 76 61 6c 20 2b 0ULL;...retval +
2750: 3d 20 2a 70 3b 0a 09 09 72 65 74 76 61 6c 20 3c = *p;...retval <
2760: 3c 3d 20 37 3b 0a 09 7d 0a 0a 09 72 65 74 76 61 <= 7;..}...retva
2770: 6c 20 2b 3d 20 31 30 3b 0a 09 72 65 74 76 61 6c l += 10;..retval
2780: 20 25 3d 20 34 32 39 34 39 36 37 32 39 36 55 4c %= 4294967296UL
2790: 4c 3b 0a 0a 09 72 65 74 75 72 6e 28 72 65 74 76 L;...return(retv
27a0: 61 6c 29 3b 0a 7d 0a 0a 2f 2a 20 47 65 74 20 69 al);.}../* Get i
27b0: 6e 66 6f 72 6d 61 74 69 6f 6e 20 61 62 6f 75 74 nformation about
27c0: 20 61 20 70 61 74 68 2c 20 61 6e 64 20 6f 70 74 a path, and opt
27d0: 69 6f 6e 61 6c 6c 79 20 6c 69 73 74 20 63 68 69 ionally list chi
27e0: 6c 64 72 65 6e 20 2a 2f 0a 73 74 61 74 69 63 20 ldren */.static
27f0: 69 6e 74 20 61 70 70 66 73 5f 67 65 74 5f 70 61 int appfs_get_pa
2800: 74 68 5f 69 6e 66 6f 28 63 6f 6e 73 74 20 63 68 th_info(const ch
2810: 61 72 20 2a 5f 70 61 74 68 2c 20 73 74 72 75 63 ar *_path, struc
2820: 74 20 61 70 70 66 73 5f 70 61 74 68 69 6e 66 6f t appfs_pathinfo
2830: 20 2a 70 61 74 68 69 6e 66 6f 2c 20 73 74 72 75 *pathinfo, stru
2840: 63 74 20 61 70 70 66 73 5f 63 68 69 6c 64 72 65 ct appfs_childre
2850: 6e 20 2a 2a 63 68 69 6c 64 72 65 6e 29 20 7b 0a n **children) {.
2860: 7d 0a 0a 73 74 61 74 69 63 20 69 6e 74 20 61 70 }..static int ap
2870: 70 66 73 5f 66 75 73 65 5f 72 65 61 64 6c 69 6e pfs_fuse_readlin
2880: 6b 28 63 6f 6e 73 74 20 63 68 61 72 20 2a 70 61 k(const char *pa
2890: 74 68 2c 20 63 68 61 72 20 2a 62 75 66 2c 20 73 th, char *buf, s
28a0: 69 7a 65 5f 74 20 73 69 7a 65 29 20 7b 0a 09 73 ize_t size) {..s
28b0: 74 72 75 63 74 20 61 70 70 66 73 5f 70 61 74 68 truct appfs_path
28c0: 69 6e 66 6f 20 70 61 74 68 69 6e 66 6f 3b 0a 09 info pathinfo;..
28d0: 69 6e 74 20 72 65 73 20 3d 20 30 3b 0a 0a 09 41 int res = 0;...A
28e0: 50 50 46 53 5f 44 45 42 55 47 28 22 45 6e 74 65 PPFS_DEBUG("Ente
28f0: 72 20 28 70 61 74 68 20 3d 20 25 73 2c 20 2e 2e r (path = %s, ..
2900: 2e 29 22 2c 20 70 61 74 68 29 3b 0a 0a 09 70 61 .)", path);...pa
2910: 74 68 69 6e 66 6f 2e 74 79 70 65 20 3d 20 41 50 thinfo.type = AP
2920: 50 46 53 5f 50 41 54 48 54 59 50 45 5f 49 4e 56 PFS_PATHTYPE_INV
2930: 41 4c 49 44 3b 0a 0a 09 72 65 73 20 3d 20 61 70 ALID;...res = ap
2940: 70 66 73 5f 67 65 74 5f 70 61 74 68 5f 69 6e 66 pfs_get_path_inf
2950: 6f 28 70 61 74 68 2c 20 26 70 61 74 68 69 6e 66 o(path, &pathinf
2960: 6f 2c 20 4e 55 4c 4c 29 3b 0a 09 69 66 20 28 72 o, NULL);..if (r
2970: 65 73 20 21 3d 20 30 29 20 7b 0a 09 09 72 65 74 es != 0) {...ret
2980: 75 72 6e 28 72 65 73 29 3b 0a 09 7d 0a 0a 09 69 urn(res);..}...i
2990: 66 20 28 70 61 74 68 69 6e 66 6f 2e 74 79 70 65 f (pathinfo.type
29a0: 20 21 3d 20 41 50 50 46 53 5f 50 41 54 48 54 59 != APPFS_PATHTY
29b0: 50 45 5f 53 59 4d 4c 49 4e 4b 29 20 7b 0a 09 09 PE_SYMLINK) {...
29c0: 72 65 74 75 72 6e 28 2d 45 49 4e 56 41 4c 29 3b return(-EINVAL);
29d0: 0a 09 7d 0a 0a 09 69 66 20 28 28 73 74 72 6c 65 ..}...if ((strle
29e0: 6e 28 70 61 74 68 69 6e 66 6f 2e 74 79 70 65 69 n(pathinfo.typei
29f0: 6e 66 6f 2e 73 79 6d 6c 69 6e 6b 2e 73 6f 75 72 nfo.symlink.sour
2a00: 63 65 29 20 2b 20 31 29 20 3e 20 73 69 7a 65 29 ce) + 1) > size)
2a10: 20 7b 0a 09 09 72 65 74 75 72 6e 28 2d 45 4e 41 {...return(-ENA
2a20: 4d 45 54 4f 4f 4c 4f 4e 47 29 3b 0a 09 7d 0a 0a METOOLONG);..}..
2a30: 09 6d 65 6d 63 70 79 28 62 75 66 2c 20 70 61 74 .memcpy(buf, pat
2a40: 68 69 6e 66 6f 2e 74 79 70 65 69 6e 66 6f 2e 73 hinfo.typeinfo.s
2a50: 79 6d 6c 69 6e 6b 2e 73 6f 75 72 63 65 2c 20 73 ymlink.source, s
2a60: 74 72 6c 65 6e 28 70 61 74 68 69 6e 66 6f 2e 74 trlen(pathinfo.t
2a70: 79 70 65 69 6e 66 6f 2e 73 79 6d 6c 69 6e 6b 2e ypeinfo.symlink.
2a80: 73 6f 75 72 63 65 29 20 2b 20 31 29 3b 0a 0a 09 source) + 1);...
2a90: 72 65 74 75 72 6e 28 30 29 3b 0a 7d 0a 0a 73 74 return(0);.}..st
2aa0: 61 74 69 63 20 69 6e 74 20 61 70 70 66 73 5f 66 atic int appfs_f
2ab0: 75 73 65 5f 67 65 74 61 74 74 72 28 63 6f 6e 73 use_getattr(cons
2ac0: 74 20 63 68 61 72 20 2a 70 61 74 68 2c 20 73 74 t char *path, st
2ad0: 72 75 63 74 20 73 74 61 74 20 2a 73 74 62 75 66 ruct stat *stbuf
2ae0: 29 20 7b 0a 09 73 74 72 75 63 74 20 61 70 70 66 ) {..struct appf
2af0: 73 5f 70 61 74 68 69 6e 66 6f 20 70 61 74 68 69 s_pathinfo pathi
2b00: 6e 66 6f 3b 0a 09 69 6e 74 20 72 65 73 20 3d 20 nfo;..int res =
2b10: 30 3b 0a 0a 09 41 50 50 46 53 5f 44 45 42 55 47 0;...APPFS_DEBUG
2b20: 28 22 45 6e 74 65 72 20 28 70 61 74 68 20 3d 20 ("Enter (path =
2b30: 25 73 2c 20 2e 2e 2e 29 22 2c 20 70 61 74 68 29 %s, ...)", path)
2b40: 3b 0a 0a 09 70 61 74 68 69 6e 66 6f 2e 74 79 70 ;...pathinfo.typ
2b50: 65 20 3d 20 41 50 50 46 53 5f 50 41 54 48 54 59 e = APPFS_PATHTY
2b60: 50 45 5f 49 4e 56 41 4c 49 44 3b 0a 0a 09 72 65 PE_INVALID;...re
2b70: 73 20 3d 20 61 70 70 66 73 5f 67 65 74 5f 70 61 s = appfs_get_pa
2b80: 74 68 5f 69 6e 66 6f 28 70 61 74 68 2c 20 26 70 th_info(path, &p
2b90: 61 74 68 69 6e 66 6f 2c 20 4e 55 4c 4c 29 3b 0a athinfo, NULL);.
2ba0: 09 69 66 20 28 72 65 73 20 21 3d 20 30 29 20 7b .if (res != 0) {
2bb0: 0a 09 09 72 65 74 75 72 6e 28 72 65 73 29 3b 0a ...return(res);.
2bc0: 09 7d 0a 0a 09 6d 65 6d 73 65 74 28 73 74 62 75 .}...memset(stbu
2bd0: 66 2c 20 30 2c 20 73 69 7a 65 6f 66 28 73 74 72 f, 0, sizeof(str
2be0: 75 63 74 20 73 74 61 74 29 29 3b 0a 0a 09 73 74 uct stat));...st
2bf0: 62 75 66 2d 3e 73 74 5f 6d 74 69 6d 65 20 3d 20 buf->st_mtime =
2c00: 70 61 74 68 69 6e 66 6f 2e 74 69 6d 65 3b 0a 09 pathinfo.time;..
2c10: 73 74 62 75 66 2d 3e 73 74 5f 63 74 69 6d 65 20 stbuf->st_ctime
2c20: 3d 20 70 61 74 68 69 6e 66 6f 2e 74 69 6d 65 3b = pathinfo.time;
2c30: 0a 09 73 74 62 75 66 2d 3e 73 74 5f 61 74 69 6d ..stbuf->st_atim
2c40: 65 20 3d 20 70 61 74 68 69 6e 66 6f 2e 74 69 6d e = pathinfo.tim
2c50: 65 3b 0a 09 73 74 62 75 66 2d 3e 73 74 5f 69 6e e;..stbuf->st_in
2c60: 6f 20 20 20 3d 20 70 61 74 68 69 6e 66 6f 2e 69 o = pathinfo.i
2c70: 6e 6f 64 65 3b 0a 09 73 74 62 75 66 2d 3e 73 74 node;..stbuf->st
2c80: 5f 6d 6f 64 65 20 20 3d 20 30 3b 0a 0a 09 73 77 _mode = 0;...sw
2c90: 69 74 63 68 20 28 70 61 74 68 69 6e 66 6f 2e 74 itch (pathinfo.t
2ca0: 79 70 65 29 20 7b 0a 09 09 63 61 73 65 20 41 50 ype) {...case AP
2cb0: 50 46 53 5f 50 41 54 48 54 59 50 45 5f 44 49 52 PFS_PATHTYPE_DIR
2cc0: 45 43 54 4f 52 59 3a 0a 09 09 09 73 74 62 75 66 ECTORY:....stbuf
2cd0: 2d 3e 73 74 5f 6d 6f 64 65 20 3d 20 53 5f 49 46 ->st_mode = S_IF
2ce0: 44 49 52 20 7c 20 30 35 35 35 3b 0a 09 09 09 73 DIR | 0555;....s
2cf0: 74 62 75 66 2d 3e 73 74 5f 6e 6c 69 6e 6b 20 3d tbuf->st_nlink =
2d00: 20 32 20 2b 20 70 61 74 68 69 6e 66 6f 2e 74 79 2 + pathinfo.ty
2d10: 70 65 69 6e 66 6f 2e 64 69 72 2e 63 68 69 6c 64 peinfo.dir.child
2d20: 63 6f 75 6e 74 3b 0a 09 09 09 62 72 65 61 6b 3b count;....break;
2d30: 0a 09 09 63 61 73 65 20 41 50 50 46 53 5f 50 41 ...case APPFS_PA
2d40: 54 48 54 59 50 45 5f 46 49 4c 45 3a 0a 09 09 09 THTYPE_FILE:....
2d50: 69 66 20 28 70 61 74 68 69 6e 66 6f 2e 74 79 70 if (pathinfo.typ
2d60: 65 69 6e 66 6f 2e 66 69 6c 65 2e 65 78 65 63 75 einfo.file.execu
2d70: 74 61 62 6c 65 29 20 7b 0a 09 09 09 09 73 74 62 table) {.....stb
2d80: 75 66 2d 3e 73 74 5f 6d 6f 64 65 20 3d 20 53 5f uf->st_mode = S_
2d90: 49 46 52 45 47 20 7c 20 30 35 35 35 3b 0a 09 09 IFREG | 0555;...
2da0: 09 7d 20 65 6c 73 65 20 7b 0a 09 09 09 09 73 74 .} else {.....st
2db0: 62 75 66 2d 3e 73 74 5f 6d 6f 64 65 20 3d 20 53 buf->st_mode = S
2dc0: 5f 49 46 52 45 47 20 7c 20 30 34 34 34 3b 0a 09 _IFREG | 0444;..
2dd0: 09 09 7d 0a 0a 09 09 09 73 74 62 75 66 2d 3e 73 ..}.....stbuf->s
2de0: 74 5f 6e 6c 69 6e 6b 20 3d 20 31 3b 0a 09 09 09 t_nlink = 1;....
2df0: 73 74 62 75 66 2d 3e 73 74 5f 73 69 7a 65 20 3d stbuf->st_size =
2e00: 20 70 61 74 68 69 6e 66 6f 2e 74 79 70 65 69 6e pathinfo.typein
2e10: 66 6f 2e 66 69 6c 65 2e 73 69 7a 65 3b 0a 09 09 fo.file.size;...
2e20: 09 62 72 65 61 6b 3b 0a 09 09 63 61 73 65 20 41 .break;...case A
2e30: 50 50 46 53 5f 50 41 54 48 54 59 50 45 5f 53 59 PPFS_PATHTYPE_SY
2e40: 4d 4c 49 4e 4b 3a 0a 09 09 09 73 74 62 75 66 2d MLINK:....stbuf-
2e50: 3e 73 74 5f 6d 6f 64 65 20 3d 20 53 5f 49 46 4c >st_mode = S_IFL
2e60: 4e 4b 20 7c 20 30 35 35 35 3b 0a 09 09 09 73 74 NK | 0555;....st
2e70: 62 75 66 2d 3e 73 74 5f 6e 6c 69 6e 6b 20 3d 20 buf->st_nlink =
2e80: 31 3b 0a 09 09 09 73 74 62 75 66 2d 3e 73 74 5f 1;....stbuf->st_
2e90: 73 69 7a 65 20 3d 20 70 61 74 68 69 6e 66 6f 2e size = pathinfo.
2ea0: 74 79 70 65 69 6e 66 6f 2e 73 79 6d 6c 69 6e 6b typeinfo.symlink
2eb0: 2e 73 69 7a 65 3b 0a 09 09 09 62 72 65 61 6b 3b .size;....break;
2ec0: 0a 09 09 63 61 73 65 20 41 50 50 46 53 5f 50 41 ...case APPFS_PA
2ed0: 54 48 54 59 50 45 5f 49 4e 56 41 4c 49 44 3a 0a THTYPE_INVALID:.
2ee0: 09 09 09 72 65 73 20 3d 20 2d 45 49 4f 3b 0a 0a ...res = -EIO;..
2ef0: 09 09 09 62 72 65 61 6b 3b 0a 09 7d 0a 0a 09 69 ...break;..}...i
2f00: 66 20 28 70 61 74 68 69 6e 66 6f 2e 70 61 63 6b f (pathinfo.pack
2f10: 61 67 65 64 29 20 7b 0a 09 09 69 66 20 28 67 6c aged) {...if (gl
2f20: 6f 62 61 6c 54 68 72 65 61 64 2e 6f 70 74 69 6f obalThread.optio
2f30: 6e 73 2e 77 72 69 74 61 62 6c 65 29 20 7b 0a 09 ns.writable) {..
2f40: 09 09 73 74 62 75 66 2d 3e 73 74 5f 6d 6f 64 65 ..stbuf->st_mode
2f50: 20 7c 3d 20 30 32 32 32 3b 0a 09 09 7d 0a 09 7d |= 0222;...}..}
2f60: 0a 0a 09 72 65 74 75 72 6e 20 72 65 73 3b 0a 7d ...return res;.}
2f70: 0a 0a 73 74 61 74 69 63 20 69 6e 74 20 61 70 70 ..static int app
2f80: 66 73 5f 66 75 73 65 5f 72 65 61 64 64 69 72 28 fs_fuse_readdir(
2f90: 63 6f 6e 73 74 20 63 68 61 72 20 2a 70 61 74 68 const char *path
2fa0: 2c 20 76 6f 69 64 20 2a 62 75 66 2c 20 66 75 73 , void *buf, fus
2fb0: 65 5f 66 69 6c 6c 5f 64 69 72 5f 74 20 66 69 6c e_fill_dir_t fil
2fc0: 6c 65 72 2c 20 6f 66 66 5f 74 20 6f 66 66 73 65 ler, off_t offse
2fd0: 74 2c 20 73 74 72 75 63 74 20 66 75 73 65 5f 66 t, struct fuse_f
2fe0: 69 6c 65 5f 69 6e 66 6f 20 2a 66 69 29 20 7b 0a ile_info *fi) {.
2ff0: 09 73 74 72 75 63 74 20 61 70 70 66 73 5f 70 61 .struct appfs_pa
3000: 74 68 69 6e 66 6f 20 70 61 74 68 69 6e 66 6f 3b thinfo pathinfo;
3010: 0a 09 73 74 72 75 63 74 20 61 70 70 66 73 5f 63 ..struct appfs_c
3020: 68 69 6c 64 72 65 6e 20 2a 63 68 69 6c 64 72 65 hildren *childre
3030: 6e 2c 20 2a 63 68 69 6c 64 3b 0a 09 69 6e 74 20 n, *child;..int
3040: 72 65 74 76 61 6c 3b 0a 0a 09 41 50 50 46 53 5f retval;...APPFS_
3050: 44 45 42 55 47 28 22 45 6e 74 65 72 20 28 70 61 DEBUG("Enter (pa
3060: 74 68 20 3d 20 25 73 2c 20 2e 2e 2e 29 22 2c 20 th = %s, ...)",
3070: 70 61 74 68 29 3b 0a 0a 09 72 65 74 76 61 6c 20 path);...retval
3080: 3d 20 61 70 70 66 73 5f 67 65 74 5f 70 61 74 68 = appfs_get_path
3090: 5f 69 6e 66 6f 28 70 61 74 68 2c 20 26 70 61 74 _info(path, &pat
30a0: 68 69 6e 66 6f 2c 20 26 63 68 69 6c 64 72 65 6e hinfo, &children
30b0: 29 3b 0a 09 69 66 20 28 72 65 74 76 61 6c 20 21 );..if (retval !
30c0: 3d 20 30 29 20 7b 0a 09 09 72 65 74 75 72 6e 28 = 0) {...return(
30d0: 72 65 74 76 61 6c 29 3b 0a 09 7d 0a 0a 09 66 69 retval);..}...fi
30e0: 6c 6c 65 72 28 62 75 66 2c 20 22 2e 22 2c 20 4e ller(buf, ".", N
30f0: 55 4c 4c 2c 20 30 29 3b 0a 09 66 69 6c 6c 65 72 ULL, 0);..filler
3100: 28 62 75 66 2c 20 22 2e 2e 22 2c 20 4e 55 4c 4c (buf, "..", NULL
3110: 2c 20 30 29 3b 0a 0a 09 66 6f 72 20 28 63 68 69 , 0);...for (chi
3120: 6c 64 20 3d 20 63 68 69 6c 64 72 65 6e 3b 20 63 ld = children; c
3130: 68 69 6c 64 3b 20 63 68 69 6c 64 20 3d 20 63 68 hild; child = ch
3140: 69 6c 64 2d 3e 5f 6e 65 78 74 29 20 7b 0a 09 09 ild->_next) {...
3150: 66 69 6c 6c 65 72 28 62 75 66 2c 20 63 68 69 6c filler(buf, chil
3160: 64 2d 3e 6e 61 6d 65 2c 20 4e 55 4c 4c 2c 20 30 d->name, NULL, 0
3170: 29 3b 0a 09 7d 0a 0a 2f 2f 09 61 70 70 66 73 5f );..}..//.appfs_
3180: 66 72 65 65 5f 6c 69 73 74 5f 63 68 69 6c 64 72 free_list_childr
3190: 65 6e 28 63 68 69 6c 64 72 65 6e 29 3b 0a 0a 09 en(children);...
31a0: 72 65 74 75 72 6e 28 30 29 3b 0a 7d 0a 0a 73 74 return(0);.}..st
31b0: 61 74 69 63 20 69 6e 74 20 61 70 70 66 73 5f 66 atic int appfs_f
31c0: 75 73 65 5f 6f 70 65 6e 28 63 6f 6e 73 74 20 63 use_open(const c
31d0: 68 61 72 20 2a 70 61 74 68 2c 20 73 74 72 75 63 har *path, struc
31e0: 74 20 66 75 73 65 5f 66 69 6c 65 5f 69 6e 66 6f t fuse_file_info
31f0: 20 2a 66 69 29 20 7b 0a 09 73 74 72 75 63 74 20 *fi) {..struct
3200: 61 70 70 66 73 5f 70 61 74 68 69 6e 66 6f 20 70 appfs_pathinfo p
3210: 61 74 68 69 6e 66 6f 3b 0a 09 63 6f 6e 73 74 20 athinfo;..const
3220: 63 68 61 72 20 2a 72 65 61 6c 5f 70 61 74 68 3b char *real_path;
3230: 0a 09 69 6e 74 20 66 68 3b 0a 09 69 6e 74 20 67 ..int fh;..int g
3240: 70 69 5f 72 65 74 3b 0a 0a 09 41 50 50 46 53 5f pi_ret;...APPFS_
3250: 44 45 42 55 47 28 22 45 6e 74 65 72 20 28 70 61 DEBUG("Enter (pa
3260: 74 68 20 3d 20 25 73 2c 20 2e 2e 2e 29 22 2c 20 th = %s, ...)",
3270: 70 61 74 68 29 3b 0a 0a 23 69 66 20 30 0a 0a 09 path);..#if 0...
3280: 69 66 20 28 28 66 69 2d 3e 66 6c 61 67 73 20 26 if ((fi->flags &
3290: 20 33 29 20 21 3d 20 4f 5f 52 44 4f 4e 4c 59 29 3) != O_RDONLY)
32a0: 20 7b 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 {.
32b0: 20 20 20 72 65 74 75 72 6e 28 2d 45 41 43 43 45 return(-EACCE
32c0: 53 29 3b 0a 09 7d 0a 0a 09 67 70 69 5f 72 65 74 S);..}...gpi_ret
32d0: 20 3d 20 61 70 70 66 73 5f 67 65 74 5f 70 61 74 = appfs_get_pat
32e0: 68 5f 69 6e 66 6f 28 70 61 74 68 2c 20 26 70 61 h_info(path, &pa
32f0: 74 68 69 6e 66 6f 2c 20 4e 55 4c 4c 29 3b 0a 09 thinfo, NULL);..
3300: 69 66 20 28 67 70 69 5f 72 65 74 20 21 3d 20 30 if (gpi_ret != 0
3310: 29 20 7b 0a 09 09 72 65 74 75 72 6e 28 67 70 69 ) {...return(gpi
3320: 5f 72 65 74 29 3b 0a 09 7d 0a 0a 09 69 66 20 28 _ret);..}...if (
3330: 70 61 74 68 69 6e 66 6f 2e 74 79 70 65 20 3d 3d pathinfo.type ==
3340: 20 41 50 50 46 53 5f 50 41 54 48 54 59 50 45 5f APPFS_PATHTYPE_
3350: 44 49 52 45 43 54 4f 52 59 29 20 7b 0a 09 09 72 DIRECTORY) {...r
3360: 65 74 75 72 6e 28 2d 45 49 53 44 49 52 29 3b 0a eturn(-EISDIR);.
3370: 09 7d 0a 0a 09 72 65 61 6c 5f 70 61 74 68 20 3d .}...real_path =
3380: 20 61 70 70 66 73 5f 67 65 74 66 69 6c 65 28 70 appfs_getfile(p
3390: 61 74 68 69 6e 66 6f 2e 68 6f 73 74 6e 61 6d 65 athinfo.hostname
33a0: 2c 20 70 61 74 68 69 6e 66 6f 2e 74 79 70 65 69 , pathinfo.typei
33b0: 6e 66 6f 2e 66 69 6c 65 2e 73 68 61 31 29 3b 0a nfo.file.sha1);.
33c0: 09 69 66 20 28 72 65 61 6c 5f 70 61 74 68 20 3d .if (real_path =
33d0: 3d 20 4e 55 4c 4c 29 20 7b 0a 09 09 72 65 74 75 = NULL) {...retu
33e0: 72 6e 28 2d 45 49 4f 29 3b 0a 09 7d 0a 0a 09 66 rn(-EIO);..}...f
33f0: 68 20 3d 20 6f 70 65 6e 28 72 65 61 6c 5f 70 61 h = open(real_pa
3400: 74 68 2c 20 4f 5f 52 44 4f 4e 4c 59 29 3b 0a 09 th, O_RDONLY);..
3410: 66 72 65 65 28 28 76 6f 69 64 20 2a 29 20 72 65 free((void *) re
3420: 61 6c 5f 70 61 74 68 29 3b 0a 09 69 66 20 28 66 al_path);..if (f
3430: 68 20 3c 20 30 29 20 7b 0a 09 09 72 65 74 75 72 h < 0) {...retur
3440: 6e 28 2d 45 49 4f 29 3b 0a 09 7d 0a 0a 09 66 69 n(-EIO);..}...fi
3450: 2d 3e 66 68 20 3d 20 66 68 3b 0a 23 65 6e 64 69 ->fh = fh;.#endi
3460: 66 0a 0a 09 72 65 74 75 72 6e 28 30 29 3b 0a 7d f...return(0);.}
3470: 0a 0a 73 74 61 74 69 63 20 69 6e 74 20 61 70 70 ..static int app
3480: 66 73 5f 66 75 73 65 5f 63 6c 6f 73 65 28 63 6f fs_fuse_close(co
3490: 6e 73 74 20 63 68 61 72 20 2a 70 61 74 68 2c 20 nst char *path,
34a0: 73 74 72 75 63 74 20 66 75 73 65 5f 66 69 6c 65 struct fuse_file
34b0: 5f 69 6e 66 6f 20 2a 66 69 29 20 7b 0a 09 69 6e _info *fi) {..in
34c0: 74 20 63 6c 6f 73 65 5f 72 65 74 3b 0a 0a 09 63 t close_ret;...c
34d0: 6c 6f 73 65 5f 72 65 74 20 3d 20 63 6c 6f 73 65 lose_ret = close
34e0: 28 66 69 2d 3e 66 68 29 3b 0a 09 69 66 20 28 63 (fi->fh);..if (c
34f0: 6c 6f 73 65 5f 72 65 74 20 21 3d 20 30 29 20 7b lose_ret != 0) {
3500: 0a 09 09 72 65 74 75 72 6e 28 2d 45 49 4f 29 3b ...return(-EIO);
3510: 0a 09 7d 0a 0a 09 72 65 74 75 72 6e 28 30 29 3b ..}...return(0);
3520: 0a 7d 0a 0a 73 74 61 74 69 63 20 69 6e 74 20 61 .}..static int a
3530: 70 70 66 73 5f 66 75 73 65 5f 72 65 61 64 28 63 ppfs_fuse_read(c
3540: 6f 6e 73 74 20 63 68 61 72 20 2a 70 61 74 68 2c onst char *path,
3550: 20 63 68 61 72 20 2a 62 75 66 2c 20 73 69 7a 65 char *buf, size
3560: 5f 74 20 73 69 7a 65 2c 20 6f 66 66 5f 74 20 6f _t size, off_t o
3570: 66 66 73 65 74 2c 20 73 74 72 75 63 74 20 66 75 ffset, struct fu
3580: 73 65 5f 66 69 6c 65 5f 69 6e 66 6f 20 2a 66 69 se_file_info *fi
3590: 29 20 7b 0a 09 6f 66 66 5f 74 20 6c 73 65 65 6b ) {..off_t lseek
35a0: 5f 72 65 74 3b 0a 09 73 73 69 7a 65 5f 74 20 72 _ret;..ssize_t r
35b0: 65 61 64 5f 72 65 74 3b 0a 0a 09 41 50 50 46 53 ead_ret;...APPFS
35c0: 5f 44 45 42 55 47 28 22 45 6e 74 65 72 20 28 70 _DEBUG("Enter (p
35d0: 61 74 68 20 3d 20 25 73 2c 20 2e 2e 2e 29 22 2c ath = %s, ...)",
35e0: 20 70 61 74 68 29 3b 0a 0a 09 6c 73 65 65 6b 5f path);...lseek_
35f0: 72 65 74 20 3d 20 6c 73 65 65 6b 28 66 69 2d 3e ret = lseek(fi->
3600: 66 68 2c 20 6f 66 66 73 65 74 2c 20 53 45 45 4b fh, offset, SEEK
3610: 5f 53 45 54 29 3b 0a 09 69 66 20 28 6c 73 65 65 _SET);..if (lsee
3620: 6b 5f 72 65 74 20 21 3d 20 6f 66 66 73 65 74 29 k_ret != offset)
3630: 20 7b 0a 09 09 72 65 74 75 72 6e 28 2d 45 49 4f {...return(-EIO
3640: 29 3b 0a 09 7d 0a 0a 09 72 65 61 64 5f 72 65 74 );..}...read_ret
3650: 20 3d 20 72 65 61 64 28 66 69 2d 3e 66 68 2c 20 = read(fi->fh,
3660: 62 75 66 2c 20 73 69 7a 65 29 3b 0a 0a 09 72 65 buf, size);...re
3670: 74 75 72 6e 28 72 65 61 64 5f 72 65 74 29 3b 0a turn(read_ret);.
3680: 7d 0a 0a 2f 2a 0a 20 2a 20 53 51 4c 69 74 65 33 }../*. * SQLite3
3690: 20 6d 6f 64 65 3a 20 45 78 65 63 75 74 65 20 72 mode: Execute r
36a0: 61 77 20 53 51 4c 20 61 6e 64 20 72 65 74 75 72 aw SQL and retur
36b0: 6e 20 73 75 63 63 65 73 73 20 6f 72 20 66 61 69 n success or fai
36c0: 6c 75 72 65 0a 20 2a 2f 0a 73 74 61 74 69 63 20 lure. */.static
36d0: 69 6e 74 20 61 70 70 66 73 5f 73 71 6c 69 74 65 int appfs_sqlite
36e0: 33 28 63 6f 6e 73 74 20 63 68 61 72 20 2a 73 71 3(const char *sq
36f0: 6c 29 20 7b 0a 09 54 63 6c 5f 49 6e 74 65 72 70 l) {..Tcl_Interp
3700: 20 2a 69 6e 74 65 72 70 3b 0a 09 63 6f 6e 73 74 *interp;..const
3710: 20 63 68 61 72 20 2a 73 71 6c 5f 72 65 74 3b 0a char *sql_ret;.
3720: 09 69 6e 74 20 74 63 6c 5f 72 65 74 3b 0a 0a 09 .int tcl_ret;...
3730: 69 6e 74 65 72 70 20 3d 20 61 70 70 66 73 5f 63 interp = appfs_c
3740: 72 65 61 74 65 5f 54 63 6c 49 6e 74 65 72 70 28 reate_TclInterp(
3750: 29 3b 0a 09 69 66 20 28 69 6e 74 65 72 70 20 3d );..if (interp =
3760: 3d 20 4e 55 4c 4c 29 20 7b 0a 09 09 66 70 72 69 = NULL) {...fpri
3770: 6e 74 66 28 73 74 64 65 72 72 2c 20 22 55 6e 61 ntf(stderr, "Una
3780: 62 6c 65 20 74 6f 20 63 72 65 61 74 65 20 61 20 ble to create a
3790: 54 63 6c 20 69 6e 74 65 72 70 72 65 74 65 72 2e Tcl interpreter.
37a0: 20 20 41 62 6f 72 74 69 6e 67 2e 5c 6e 22 29 3b Aborting.\n");
37b0: 0a 0a 09 09 72 65 74 75 72 6e 28 31 29 3b 0a 09 ....return(1);..
37c0: 7d 0a 0a 09 74 63 6c 5f 72 65 74 20 3d 20 61 70 }...tcl_ret = ap
37d0: 70 66 73 5f 54 63 6c 5f 45 76 61 6c 28 69 6e 74 pfs_Tcl_Eval(int
37e0: 65 72 70 2c 20 35 2c 20 22 3a 3a 61 70 70 66 73 erp, 5, "::appfs
37f0: 3a 3a 64 62 22 2c 20 22 65 76 61 6c 22 2c 20 73 ::db", "eval", s
3800: 71 6c 2c 20 22 72 6f 77 22 2c 20 22 75 6e 73 65 ql, "row", "unse
3810: 74 20 2d 6e 6f 63 6f 6d 70 6c 61 69 6e 20 72 6f t -nocomplain ro
3820: 77 28 2a 29 3b 20 70 61 72 72 61 79 20 72 6f 77 w(*); parray row
3830: 3b 20 70 75 74 73 20 5c 22 2d 2d 2d 2d 5c 22 22 ; puts \"----\""
3840: 29 3b 0a 09 73 71 6c 5f 72 65 74 20 3d 20 54 63 );..sql_ret = Tc
3850: 6c 5f 47 65 74 53 74 72 69 6e 67 52 65 73 75 6c l_GetStringResul
3860: 74 28 69 6e 74 65 72 70 29 3b 0a 0a 09 69 66 20 t(interp);...if
3870: 28 74 63 6c 5f 72 65 74 20 21 3d 20 54 43 4c 5f (tcl_ret != TCL_
3880: 4f 4b 29 20 7b 0a 09 09 66 70 72 69 6e 74 66 28 OK) {...fprintf(
3890: 73 74 64 65 72 72 2c 20 22 5b 65 72 72 6f 72 5d stderr, "[error]
38a0: 20 25 73 5c 6e 22 2c 20 73 71 6c 5f 72 65 74 29 %s\n", sql_ret)
38b0: 3b 0a 0a 09 09 72 65 74 75 72 6e 28 31 29 3b 0a ;....return(1);.
38c0: 09 7d 0a 0a 09 69 66 20 28 73 71 6c 5f 72 65 74 .}...if (sql_ret
38d0: 20 26 26 20 73 71 6c 5f 72 65 74 5b 30 5d 20 21 && sql_ret[0] !
38e0: 3d 20 27 5c 30 27 29 20 7b 0a 09 09 70 72 69 6e = '\0') {...prin
38f0: 74 66 28 22 25 73 5c 6e 22 2c 20 73 71 6c 5f 72 tf("%s\n", sql_r
3900: 65 74 29 3b 0a 09 7d 0a 0a 09 72 65 74 75 72 6e et);..}...return
3910: 28 30 29 3b 0a 7d 0a 0a 2f 2a 0a 20 2a 20 54 63 (0);.}../*. * Tc
3920: 6c 20 6d 6f 64 65 3a 20 45 78 65 63 75 74 65 20 l mode: Execute
3930: 72 61 77 20 54 63 6c 20 61 6e 64 20 72 65 74 75 raw Tcl and retu
3940: 72 6e 20 73 75 63 63 65 73 73 20 6f 72 20 66 61 rn success or fa
3950: 69 6c 75 72 65 0a 20 2a 2f 0a 73 74 61 74 69 63 ilure. */.static
3960: 20 69 6e 74 20 61 70 70 66 73 5f 74 63 6c 28 63 int appfs_tcl(c
3970: 6f 6e 73 74 20 63 68 61 72 20 2a 74 63 6c 29 20 onst char *tcl)
3980: 7b 0a 09 54 63 6c 5f 49 6e 74 65 72 70 20 2a 69 {..Tcl_Interp *i
3990: 6e 74 65 72 70 3b 0a 09 63 6f 6e 73 74 20 63 68 nterp;..const ch
39a0: 61 72 20 2a 74 63 6c 5f 72 65 73 75 6c 74 3b 0a ar *tcl_result;.
39b0: 09 69 6e 74 20 74 63 6c 5f 72 65 74 3b 0a 0a 09 .int tcl_ret;...
39c0: 69 6e 74 65 72 70 20 3d 20 61 70 70 66 73 5f 63 interp = appfs_c
39d0: 72 65 61 74 65 5f 54 63 6c 49 6e 74 65 72 70 28 reate_TclInterp(
39e0: 29 3b 0a 09 69 66 20 28 69 6e 74 65 72 70 20 3d );..if (interp =
39f0: 3d 20 4e 55 4c 4c 29 20 7b 0a 09 09 66 70 72 69 = NULL) {...fpri
3a00: 6e 74 66 28 73 74 64 65 72 72 2c 20 22 55 6e 61 ntf(stderr, "Una
3a10: 62 6c 65 20 74 6f 20 63 72 65 61 74 65 20 61 20 ble to create a
3a20: 54 63 6c 20 69 6e 74 65 72 70 72 65 74 65 72 2e Tcl interpreter.
3a30: 20 20 41 62 6f 72 74 69 6e 67 2e 5c 6e 22 29 3b Aborting.\n");
3a40: 0a 0a 09 09 72 65 74 75 72 6e 28 31 29 3b 0a 09 ....return(1);..
3a50: 7d 0a 0a 09 74 63 6c 5f 72 65 74 20 3d 20 54 63 }...tcl_ret = Tc
3a60: 6c 5f 45 76 61 6c 28 69 6e 74 65 72 70 2c 20 74 l_Eval(interp, t
3a70: 63 6c 29 3b 0a 09 74 63 6c 5f 72 65 73 75 6c 74 cl);..tcl_result
3a80: 20 3d 20 54 63 6c 5f 47 65 74 53 74 72 69 6e 67 = Tcl_GetString
3a90: 52 65 73 75 6c 74 28 69 6e 74 65 72 70 29 3b 0a Result(interp);.
3aa0: 0a 09 69 66 20 28 74 63 6c 5f 72 65 74 20 21 3d ..if (tcl_ret !=
3ab0: 20 54 43 4c 5f 4f 4b 29 20 7b 0a 09 09 66 70 72 TCL_OK) {...fpr
3ac0: 69 6e 74 66 28 73 74 64 65 72 72 2c 20 22 5b 65 intf(stderr, "[e
3ad0: 72 72 6f 72 5d 20 25 73 5c 6e 22 2c 20 74 63 6c rror] %s\n", tcl
3ae0: 5f 72 65 73 75 6c 74 29 3b 0a 0a 09 09 72 65 74 _result);....ret
3af0: 75 72 6e 28 31 29 3b 0a 09 7d 0a 0a 09 69 66 20 urn(1);..}...if
3b00: 28 74 63 6c 5f 72 65 73 75 6c 74 20 26 26 20 74 (tcl_result && t
3b10: 63 6c 5f 72 65 73 75 6c 74 5b 30 5d 20 21 3d 20 cl_result[0] !=
3b20: 27 5c 30 27 29 20 7b 0a 09 09 70 72 69 6e 74 66 '\0') {...printf
3b30: 28 22 25 73 5c 6e 22 2c 20 74 63 6c 5f 72 65 73 ("%s\n", tcl_res
3b40: 75 6c 74 29 3b 0a 09 7d 0a 0a 09 72 65 74 75 72 ult);..}...retur
3b50: 6e 28 30 29 3b 0a 7d 0a 0a 2f 2a 0a 20 2a 20 41 n(0);.}../*. * A
3b60: 70 70 46 53 64 20 50 61 63 6b 61 67 65 20 66 6f ppFSd Package fo
3b70: 72 20 54 63 6c 3a 0a 20 2a 20 20 20 20 20 20 20 r Tcl:. *
3b80: 20 20 42 72 69 64 67 65 20 66 6f 72 20 49 2f 4f Bridge for I/O
3b90: 20 6f 70 65 72 61 74 69 6f 6e 73 20 74 6f 20 72 operations to r
3ba0: 65 71 75 65 73 74 20 69 6e 66 6f 72 6d 61 74 69 equest informati
3bb0: 6f 6e 20 61 62 6f 75 74 20 74 68 65 20 63 75 72 on about the cur
3bc0: 72 65 6e 74 0a 20 2a 20 20 20 20 20 20 20 20 20 rent. *
3bd0: 74 72 61 6e 73 61 63 74 69 6f 6e 0a 20 2a 2f 0a transaction. */.
3be0: 73 74 61 74 69 63 20 69 6e 74 20 41 70 70 66 73 static int Appfs
3bf0: 64 5f 49 6e 69 74 28 54 63 6c 5f 49 6e 74 65 72 d_Init(Tcl_Inter
3c00: 70 20 2a 69 6e 74 65 72 70 29 20 7b 0a 23 69 66 p *interp) {.#if
3c10: 64 65 66 20 55 53 45 5f 54 43 4c 5f 53 54 55 42 def USE_TCL_STUB
3c20: 53 0a 09 69 66 20 28 54 63 6c 5f 49 6e 69 74 53 S..if (Tcl_InitS
3c30: 74 75 62 73 28 69 6e 74 65 72 70 2c 20 54 43 4c tubs(interp, TCL
3c40: 5f 56 45 52 53 49 4f 4e 2c 20 30 29 20 3d 3d 20 _VERSION, 0) ==
3c50: 30 4c 29 20 7b 0a 09 09 72 65 74 75 72 6e 28 54 0L) {...return(T
3c60: 43 4c 5f 45 52 52 4f 52 29 3b 0a 09 7d 0a 23 65 CL_ERROR);..}.#e
3c70: 6e 64 69 66 0a 0a 09 54 63 6c 5f 43 72 65 61 74 ndif...Tcl_Creat
3c80: 65 4f 62 6a 43 6f 6d 6d 61 6e 64 28 69 6e 74 65 eObjCommand(inte
3c90: 72 70 2c 20 22 61 70 70 66 73 64 3a 3a 67 65 74 rp, "appfsd::get
3ca0: 5f 68 6f 6d 65 64 69 72 22 2c 20 74 63 6c 5f 61 _homedir", tcl_a
3cb0: 70 70 66 73 5f 67 65 74 5f 68 6f 6d 65 64 69 72 ppfs_get_homedir
3cc0: 2c 20 4e 55 4c 4c 2c 20 4e 55 4c 4c 29 3b 0a 0a , NULL, NULL);..
3cd0: 09 54 63 6c 5f 50 6b 67 50 72 6f 76 69 64 65 28 .Tcl_PkgProvide(
3ce0: 69 6e 74 65 72 70 2c 20 22 61 70 70 66 73 64 22 interp, "appfsd"
3cf0: 2c 20 22 31 2e 30 22 29 3b 0a 0a 09 72 65 74 75 , "1.0");...retu
3d00: 72 6e 28 54 43 4c 5f 4f 4b 29 3b 0a 7d 0a 0a 2f rn(TCL_OK);.}../
3d10: 2a 0a 20 2a 20 46 55 53 45 20 6f 70 65 72 61 74 *. * FUSE operat
3d20: 69 6f 6e 73 20 73 74 72 75 63 74 75 72 65 0a 20 ions structure.
3d30: 2a 2f 0a 73 74 61 74 69 63 20 73 74 72 75 63 74 */.static struct
3d40: 20 66 75 73 65 5f 6f 70 65 72 61 74 69 6f 6e 73 fuse_operations
3d50: 20 61 70 70 66 73 5f 6f 70 65 72 61 74 69 6f 6e appfs_operation
3d60: 73 20 3d 20 7b 0a 09 2e 67 65 74 61 74 74 72 20 s = {...getattr
3d70: 20 20 3d 20 61 70 70 66 73 5f 66 75 73 65 5f 67 = appfs_fuse_g
3d80: 65 74 61 74 74 72 2c 0a 09 2e 72 65 61 64 64 69 etattr,...readdi
3d90: 72 20 20 20 3d 20 61 70 70 66 73 5f 66 75 73 65 r = appfs_fuse
3da0: 5f 72 65 61 64 64 69 72 2c 0a 09 2e 72 65 61 64 _readdir,...read
3db0: 6c 69 6e 6b 20 20 3d 20 61 70 70 66 73 5f 66 75 link = appfs_fu
3dc0: 73 65 5f 72 65 61 64 6c 69 6e 6b 2c 0a 09 2e 6f se_readlink,...o
3dd0: 70 65 6e 20 20 20 20 20 20 3d 20 61 70 70 66 73 pen = appfs
3de0: 5f 66 75 73 65 5f 6f 70 65 6e 2c 0a 09 2e 72 65 _fuse_open,...re
3df0: 6c 65 61 73 65 20 20 20 3d 20 61 70 70 66 73 5f lease = appfs_
3e00: 66 75 73 65 5f 63 6c 6f 73 65 2c 0a 09 2e 72 65 fuse_close,...re
3e10: 61 64 20 20 20 20 20 20 3d 20 61 70 70 66 73 5f ad = appfs_
3e20: 66 75 73 65 5f 72 65 61 64 0a 7d 3b 0a 0a 2f 2a fuse_read.};../*
3e30: 0a 20 2a 20 45 6e 74 72 79 20 70 6f 69 6e 74 20 . * Entry point
3e40: 69 6e 74 6f 20 74 68 69 73 20 70 72 6f 67 72 61 into this progra
3e50: 6d 2e 0a 20 2a 2f 0a 69 6e 74 20 6d 61 69 6e 28 m.. */.int main(
3e60: 69 6e 74 20 61 72 67 63 2c 20 63 68 61 72 20 2a int argc, char *
3e70: 2a 61 72 67 76 29 20 7b 0a 09 73 74 72 75 63 74 *argv) {..struct
3e80: 20 66 75 73 65 5f 61 72 67 73 20 61 72 67 73 20 fuse_args args
3e90: 3d 20 46 55 53 45 5f 41 52 47 53 5f 49 4e 49 54 = FUSE_ARGS_INIT
3ea0: 28 61 72 67 63 2c 20 61 72 67 76 29 3b 0a 09 63 (argc, argv);..c
3eb0: 6f 6e 73 74 20 63 68 61 72 20 2a 63 61 63 68 65 onst char *cache
3ec0: 64 69 72 20 3d 20 41 50 50 46 53 5f 43 41 43 48 dir = APPFS_CACH
3ed0: 45 44 49 52 3b 0a 09 69 6e 74 20 70 74 68 72 65 EDIR;..int pthre
3ee0: 61 64 5f 72 65 74 3b 0a 0a 09 2f 2a 0a 09 20 2a ad_ret;.../*.. *
3ef0: 20 53 65 74 20 67 6c 6f 62 61 6c 20 76 61 72 69 Set global vari
3f00: 61 62 6c 65 73 2c 20 74 68 65 73 65 20 73 68 6f ables, these sho
3f10: 75 6c 64 20 62 65 20 63 6f 6e 66 69 67 75 72 61 uld be configura
3f20: 74 69 6f 6e 20 6f 70 74 69 6f 6e 73 2e 0a 09 20 tion options...
3f30: 2a 2f 0a 09 67 6c 6f 62 61 6c 54 68 72 65 61 64 */..globalThread
3f40: 2e 63 61 63 68 65 64 69 72 20 3d 20 63 61 63 68 .cachedir = cach
3f50: 65 64 69 72 3b 0a 09 67 6c 6f 62 61 6c 54 68 72 edir;..globalThr
3f60: 65 61 64 2e 6f 70 74 69 6f 6e 73 2e 77 72 69 74 ead.options.writ
3f70: 61 62 6c 65 20 3d 20 31 3b 0a 0a 09 2f 2a 0a 09 able = 1;.../*..
3f80: 20 2a 20 53 65 74 20 67 6c 6f 62 61 6c 20 76 61 * Set global va
3f90: 72 69 61 62 6c 65 20 66 6f 72 20 22 62 6f 6f 74 riable for "boot
3fa0: 20 74 69 6d 65 22 20 74 6f 20 73 65 74 20 61 20 time" to set a
3fb0: 74 69 6d 65 20 6f 6e 20 64 69 72 65 63 74 6f 72 time on director
3fc0: 69 65 73 0a 09 20 2a 20 74 68 61 74 20 77 65 20 ies.. * that we
3fd0: 66 61 6b 65 2e 0a 09 20 2a 2f 0a 09 67 6c 6f 62 fake... */..glob
3fe0: 61 6c 54 68 72 65 61 64 2e 62 6f 6f 74 74 69 6d alThread.boottim
3ff0: 65 20 3d 20 74 69 6d 65 28 4e 55 4c 4c 29 3b 0a e = time(NULL);.
4000: 0a 09 2f 2a 0a 09 20 2a 20 52 65 67 69 73 74 65 ../*.. * Registe
4010: 72 20 22 73 68 61 31 22 20 61 6e 64 20 22 61 70 r "sha1" and "ap
4020: 70 66 73 64 22 20 70 61 63 6b 61 67 65 20 77 69 pfsd" package wi
4030: 74 68 20 6c 69 62 74 63 6c 20 73 6f 20 74 68 61 th libtcl so tha
4040: 74 20 61 6e 79 20 6e 65 77 0a 09 20 2a 20 69 6e t any new.. * in
4050: 74 65 72 70 72 65 74 65 72 73 20 63 72 65 61 74 terpreters creat
4060: 65 64 20 28 77 68 69 63 68 20 61 72 65 20 64 6f ed (which are do
4070: 6e 65 20 64 79 6e 61 6d 69 63 61 6c 6c 79 20 62 ne dynamically b
4080: 79 20 46 55 53 45 29 20 63 61 6e 20 68 61 76 65 y FUSE) can have
4090: 0a 09 20 2a 20 74 68 65 20 61 70 70 72 6f 70 72 .. * the appropr
40a0: 69 61 74 65 20 63 6f 6e 66 69 67 75 72 61 74 69 iate configurati
40b0: 6f 6e 20 64 6f 6e 65 20 61 75 74 6f 6d 61 74 69 on done automati
40c0: 63 61 6c 6c 79 2e 0a 09 20 2a 2f 0a 09 54 63 6c cally... */..Tcl
40d0: 5f 53 74 61 74 69 63 50 61 63 6b 61 67 65 28 4e _StaticPackage(N
40e0: 55 4c 4c 2c 20 22 73 68 61 31 22 2c 20 53 68 61 ULL, "sha1", Sha
40f0: 31 5f 49 6e 69 74 2c 20 4e 55 4c 4c 29 3b 0a 09 1_Init, NULL);..
4100: 54 63 6c 5f 53 74 61 74 69 63 50 61 63 6b 61 67 Tcl_StaticPackag
4110: 65 28 4e 55 4c 4c 2c 20 22 61 70 70 66 73 64 22 e(NULL, "appfsd"
4120: 2c 20 41 70 70 66 73 64 5f 49 6e 69 74 2c 20 4e , Appfsd_Init, N
4130: 55 4c 4c 29 3b 0a 0a 09 2f 2a 0a 09 20 2a 20 43 ULL);.../*.. * C
4140: 72 65 61 74 65 20 61 20 74 68 72 65 61 64 2d 73 reate a thread-s
4150: 70 65 63 69 66 69 63 2d 64 61 74 61 20 28 54 53 pecific-data (TS
4160: 44 29 20 6b 65 79 20 66 6f 72 20 65 61 63 68 20 D) key for each
4170: 74 68 72 65 61 64 20 74 6f 20 72 65 66 65 72 0a thread to refer.
4180: 09 20 2a 20 74 6f 20 69 74 73 20 6f 77 6e 20 54 . * to its own T
4190: 63 6c 20 69 6e 74 65 72 70 72 65 74 65 72 2e 20 cl interpreter.
41a0: 20 54 63 6c 20 69 6e 74 65 72 70 72 65 74 65 72 Tcl interpreter
41b0: 73 20 6d 75 73 74 20 62 65 20 75 6e 69 71 75 65 s must be unique
41c0: 20 70 65 72 0a 09 20 2a 20 74 68 72 65 61 64 20 per.. * thread
41d0: 61 6e 64 20 6e 65 77 20 74 68 72 65 61 64 73 20 and new threads
41e0: 61 72 65 20 64 79 6e 61 6d 69 63 61 6c 6c 79 20 are dynamically
41f0: 63 72 65 61 74 65 64 20 62 79 20 46 55 53 45 2e created by FUSE.
4200: 0a 09 20 2a 2f 0a 09 70 74 68 72 65 61 64 5f 72 .. */..pthread_r
4210: 65 74 20 3d 20 70 74 68 72 65 61 64 5f 6b 65 79 et = pthread_key
4220: 5f 63 72 65 61 74 65 28 26 69 6e 74 65 72 70 4b _create(&interpK
4230: 65 79 2c 20 4e 55 4c 4c 29 3b 0a 09 69 66 20 28 ey, NULL);..if (
4240: 70 74 68 72 65 61 64 5f 72 65 74 20 21 3d 20 30 pthread_ret != 0
4250: 29 20 7b 0a 09 09 66 70 72 69 6e 74 66 28 73 74 ) {...fprintf(st
4260: 64 65 72 72 2c 20 22 55 6e 61 62 6c 65 20 74 6f derr, "Unable to
4270: 20 63 72 65 61 74 65 20 54 53 44 20 6b 65 79 20 create TSD key
4280: 66 6f 72 20 54 63 6c 2e 20 20 41 62 6f 72 74 69 for Tcl. Aborti
4290: 6e 67 2e 5c 6e 22 29 3b 0a 0a 09 09 72 65 74 75 ng.\n");....retu
42a0: 72 6e 28 31 29 3b 0a 09 7d 0a 0a 09 2f 2a 0a 09 rn(1);..}.../*..
42b0: 20 2a 20 53 51 4c 69 74 65 33 20 6d 6f 64 65 2c * SQLite3 mode,
42c0: 20 66 6f 72 20 72 75 6e 6e 69 6e 67 20 72 61 77 for running raw
42d0: 20 53 51 4c 20 61 67 61 69 6e 73 74 20 74 68 65 SQL against the
42e0: 20 63 61 63 68 65 20 64 61 74 61 62 61 73 65 0a cache database.
42f0: 09 20 2a 2f 0a 09 69 66 20 28 61 72 67 63 20 3d . */..if (argc =
4300: 3d 20 33 20 26 26 20 73 74 72 63 6d 70 28 61 72 = 3 && strcmp(ar
4310: 67 76 5b 31 5d 2c 20 22 2d 73 71 6c 69 74 65 33 gv[1], "-sqlite3
4320: 22 29 20 3d 3d 20 30 29 20 7b 0a 09 09 72 65 74 ") == 0) {...ret
4330: 75 72 6e 28 61 70 70 66 73 5f 73 71 6c 69 74 65 urn(appfs_sqlite
4340: 33 28 61 72 67 76 5b 32 5d 29 29 3b 0a 09 7d 0a 3(argv[2]));..}.
4350: 0a 09 2f 2a 0a 09 20 2a 20 54 63 6c 20 6d 6f 64 ../*.. * Tcl mod
4360: 65 2c 20 66 6f 72 20 72 75 6e 6e 69 6e 67 20 72 e, for running r
4370: 61 77 20 54 63 6c 20 69 6e 20 74 68 65 20 73 61 aw Tcl in the sa
4380: 6d 65 20 65 6e 76 69 72 6f 6e 6d 65 6e 74 20 41 me environment A
4390: 70 70 46 53 64 20 77 6f 75 6c 64 0a 09 20 2a 20 ppFSd would.. *
43a0: 72 75 6e 20 63 6f 64 65 2e 0a 09 20 2a 2f 0a 09 run code... */..
43b0: 69 66 20 28 61 72 67 63 20 3d 3d 20 33 20 26 26 if (argc == 3 &&
43c0: 20 73 74 72 63 6d 70 28 61 72 67 76 5b 31 5d 2c strcmp(argv[1],
43d0: 20 22 2d 74 63 6c 22 29 20 3d 3d 20 30 29 20 7b "-tcl") == 0) {
43e0: 0a 09 09 72 65 74 75 72 6e 28 61 70 70 66 73 5f ...return(appfs_
43f0: 74 63 6c 28 61 72 67 76 5b 32 5d 29 29 3b 0a 09 tcl(argv[2]));..
4400: 7d 0a 0a 09 2f 2a 0a 09 20 2a 20 41 64 64 20 46 }.../*.. * Add F
4410: 55 53 45 20 61 72 67 75 6d 65 6e 74 73 20 77 68 USE arguments wh
4420: 69 63 68 20 77 65 20 61 6c 77 61 79 73 20 73 75 ich we always su
4430: 70 70 6c 79 0a 09 20 2a 2f 0a 09 66 75 73 65 5f pply.. */..fuse_
4440: 6f 70 74 5f 70 61 72 73 65 28 26 61 72 67 73 2c opt_parse(&args,
4450: 20 4e 55 4c 4c 2c 20 4e 55 4c 4c 2c 20 4e 55 4c NULL, NULL, NUL
4460: 4c 29 3b 0a 09 66 75 73 65 5f 6f 70 74 5f 61 64 L);..fuse_opt_ad
4470: 64 5f 61 72 67 28 26 61 72 67 73 2c 20 22 2d 6f d_arg(&args, "-o
4480: 64 65 66 61 75 6c 74 5f 70 65 72 6d 69 73 73 69 default_permissi
4490: 6f 6e 73 2c 66 73 6e 61 6d 65 3d 61 70 70 66 73 ons,fsname=appfs
44a0: 2c 73 75 62 74 79 70 65 3d 61 70 70 66 73 64 2c ,subtype=appfsd,
44b0: 75 73 65 5f 69 6e 6f 2c 6b 65 72 6e 65 6c 5f 63 use_ino,kernel_c
44c0: 61 63 68 65 2c 65 6e 74 72 79 5f 74 69 6d 65 6f ache,entry_timeo
44d0: 75 74 3d 36 30 2c 61 74 74 72 5f 74 69 6d 65 6f ut=60,attr_timeo
44e0: 75 74 3d 33 36 30 30 2c 69 6e 74 72 2c 62 69 67 ut=3600,intr,big
44f0: 5f 77 72 69 74 65 73 22 29 3b 0a 0a 09 69 66 20 _writes");...if
4500: 28 67 65 74 75 69 64 28 29 20 3d 3d 20 30 29 20 (getuid() == 0)
4510: 7b 0a 09 09 66 75 73 65 5f 6f 70 74 5f 70 61 72 {...fuse_opt_par
4520: 73 65 28 26 61 72 67 73 2c 20 4e 55 4c 4c 2c 20 se(&args, NULL,
4530: 4e 55 4c 4c 2c 20 4e 55 4c 4c 29 3b 0a 09 09 66 NULL, NULL);...f
4540: 75 73 65 5f 6f 70 74 5f 61 64 64 5f 61 72 67 28 use_opt_add_arg(
4550: 26 61 72 67 73 2c 20 22 2d 6f 61 6c 6c 6f 77 5f &args, "-oallow_
4560: 6f 74 68 65 72 22 29 3b 0a 09 7d 0a 0a 09 2f 2a other");..}.../*
4570: 0a 09 20 2a 20 45 6e 74 65 72 20 74 68 65 20 46 .. * Enter the F
4580: 55 53 45 20 6d 61 69 6e 20 6c 6f 6f 70 20 2d 2d USE main loop --
4590: 20 74 68 69 73 20 77 69 6c 6c 20 70 72 6f 63 65 this will proce
45a0: 73 73 20 61 6e 79 20 61 72 67 75 6d 65 6e 74 73 ss any arguments
45b0: 0a 09 20 2a 20 61 6e 64 20 73 74 61 72 74 20 73 .. * and start s
45c0: 65 72 76 69 63 69 6e 67 20 72 65 71 75 65 73 74 ervicing request
45d0: 73 2e 0a 09 20 2a 2f 0a 09 72 65 74 75 72 6e 28 s... */..return(
45e0: 66 75 73 65 5f 6d 61 69 6e 28 61 72 67 73 2e 61 fuse_main(args.a
45f0: 72 67 63 2c 20 61 72 67 73 2e 61 72 67 76 2c 20 rgc, args.argv,
4600: 26 61 70 70 66 73 5f 6f 70 65 72 61 74 69 6f 6e &appfs_operation
4610: 73 2c 20 4e 55 4c 4c 29 29 3b 0a 7d 0a 20 0a s, NULL));.}. .