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: 47 6c 6f 62 61 6c 20 76 61 72 69 61 62 6c 65 73 Global variables
0330: 2c 20 6e 65 65 64 65 64 20 66 6f 72 20 61 6c 6c , needed for all
0340: 20 74 68 72 65 61 64 73 20 62 75 74 20 6f 6e 6c threads but onl
0350: 79 20 69 6e 69 74 69 61 6c 69 7a 65 64 20 62 65 y initialized be
0360: 66 6f 72 65 20 61 6e 79 0a 20 2a 20 46 55 53 45 fore any. * FUSE
0370: 20 74 68 72 65 61 64 73 20 61 72 65 20 63 72 65 threads are cre
0380: 61 74 65 64 0a 20 2a 2f 0a 63 6f 6e 73 74 20 63 ated. */.const c
0390: 68 61 72 20 2a 61 70 70 66 73 5f 63 61 63 68 65 har *appfs_cache
03a0: 64 69 72 3b 0a 74 69 6d 65 5f 74 20 61 70 70 66 dir;.time_t appf
03b0: 73 5f 62 6f 6f 74 74 69 6d 65 3b 0a 0a 2f 2a 0a s_boottime;../*.
03c0: 20 2a 20 41 70 70 46 53 20 50 61 74 68 20 54 79 * AppFS Path Ty
03d0: 70 65 3a 20 20 44 65 73 63 72 69 62 65 73 20 74 pe: Describes t
03e0: 68 65 20 74 79 70 65 20 6f 66 20 70 61 74 68 20 he type of path
03f0: 61 20 67 69 76 65 6e 20 66 69 6c 65 20 69 73 0a a given file is.
0400: 20 2a 2f 0a 74 79 70 65 64 65 66 20 65 6e 75 6d */.typedef enum
0410: 20 7b 0a 09 41 50 50 46 53 5f 50 41 54 48 54 59 {..APPFS_PATHTY
0420: 50 45 5f 49 4e 56 41 4c 49 44 2c 0a 09 41 50 50 PE_INVALID,..APP
0430: 46 53 5f 50 41 54 48 54 59 50 45 5f 46 49 4c 45 FS_PATHTYPE_FILE
0440: 2c 0a 09 41 50 50 46 53 5f 50 41 54 48 54 59 50 ,..APPFS_PATHTYP
0450: 45 5f 44 49 52 45 43 54 4f 52 59 2c 0a 09 41 50 E_DIRECTORY,..AP
0460: 50 46 53 5f 50 41 54 48 54 59 50 45 5f 53 59 4d PFS_PATHTYPE_SYM
0470: 4c 49 4e 4b 0a 7d 20 61 70 70 66 73 5f 70 61 74 LINK.} appfs_pat
0480: 68 74 79 70 65 5f 74 3b 0a 0a 2f 2a 0a 20 2a 20 htype_t;../*. *
0490: 41 70 70 46 53 20 43 68 69 6c 64 72 65 6e 20 46 AppFS Children F
04a0: 69 6c 65 73 20 6c 69 6e 6b 65 64 2d 6c 69 73 74 iles linked-list
04b0: 0a 20 2a 2f 0a 73 74 72 75 63 74 20 61 70 70 66 . */.struct appf
04c0: 73 5f 63 68 69 6c 64 72 65 6e 20 7b 0a 09 73 74 s_children {..st
04d0: 72 75 63 74 20 61 70 70 66 73 5f 63 68 69 6c 64 ruct appfs_child
04e0: 72 65 6e 20 2a 5f 6e 65 78 74 3b 0a 09 63 68 61 ren *_next;..cha
04f0: 72 20 6e 61 6d 65 5b 32 35 36 5d 3b 0a 7d 3b 0a r name[256];.};.
0500: 0a 2f 2a 0a 20 2a 20 41 70 70 46 53 20 50 61 74 ./*. * AppFS Pat
0510: 68 20 49 6e 66 6f 72 6d 61 74 69 6f 6e 3a 0a 20 h Information:.
0520: 2a 20 20 20 20 20 20 20 20 20 43 6f 6d 70 6c 65 * Comple
0530: 74 65 6c 79 20 64 65 73 63 72 69 62 65 73 20 61 tely describes a
0540: 20 73 70 65 63 69 66 69 63 20 70 61 74 68 2c 20 specific path,
0550: 68 6f 77 20 69 74 20 73 68 6f 75 6c 64 20 62 65 how it should be
0560: 20 72 65 74 75 72 6e 65 64 20 74 6f 0a 20 2a 20 returned to. *
0570: 20 20 20 20 20 20 20 20 74 6f 20 74 68 65 20 6b to the k
0580: 65 72 6e 65 6c 0a 20 2a 2f 0a 73 74 72 75 63 74 ernel. */.struct
0590: 20 61 70 70 66 73 5f 70 61 74 68 69 6e 66 6f 20 appfs_pathinfo
05a0: 7b 0a 09 61 70 70 66 73 5f 70 61 74 68 74 79 70 {..appfs_pathtyp
05b0: 65 5f 74 20 74 79 70 65 3b 0a 09 74 69 6d 65 5f e_t type;..time_
05c0: 74 20 74 69 6d 65 3b 0a 09 63 68 61 72 20 68 6f t time;..char ho
05d0: 73 74 6e 61 6d 65 5b 32 35 36 5d 3b 0a 09 69 6e stname[256];..in
05e0: 74 20 70 61 63 6b 61 67 65 64 3b 0a 09 75 6e 73 t packaged;..uns
05f0: 69 67 6e 65 64 20 6c 6f 6e 67 20 6c 6f 6e 67 20 igned long long
0600: 69 6e 6f 64 65 3b 0a 09 75 6e 69 6f 6e 20 7b 0a inode;..union {.
0610: 09 09 73 74 72 75 63 74 20 7b 0a 09 09 09 69 6e ..struct {....in
0620: 74 20 63 68 69 6c 64 63 6f 75 6e 74 3b 0a 09 09 t childcount;...
0630: 7d 20 64 69 72 3b 0a 09 09 73 74 72 75 63 74 20 } dir;...struct
0640: 7b 0a 09 09 09 69 6e 74 20 65 78 65 63 75 74 61 {....int executa
0650: 62 6c 65 3b 0a 09 09 09 6f 66 66 5f 74 20 73 69 ble;....off_t si
0660: 7a 65 3b 0a 09 09 7d 20 66 69 6c 65 3b 0a 09 09 ze;...} file;...
0670: 73 74 72 75 63 74 20 7b 0a 09 09 09 6f 66 66 5f struct {....off_
0680: 74 20 73 69 7a 65 3b 0a 09 09 09 63 68 61 72 20 t size;....char
0690: 73 6f 75 72 63 65 5b 32 35 36 5d 3b 0a 09 09 7d source[256];...}
06a0: 20 73 79 6d 6c 69 6e 6b 3b 0a 09 7d 20 74 79 70 symlink;..} typ
06b0: 65 69 6e 66 6f 3b 0a 7d 3b 0a 0a 2f 2a 0a 20 2a einfo;.};../*. *
06c0: 20 43 72 65 61 74 65 20 61 20 6e 65 77 20 54 63 Create a new Tc
06d0: 6c 20 69 6e 74 65 72 70 72 65 74 65 72 20 61 6e l interpreter an
06e0: 64 20 63 6f 6d 70 6c 65 74 65 6c 79 20 69 6e 69 d completely ini
06f0: 74 69 61 6c 69 7a 65 20 69 74 0a 20 2a 2f 0a 73 tialize it. */.s
0700: 74 61 74 69 63 20 54 63 6c 5f 49 6e 74 65 72 70 tatic Tcl_Interp
0710: 20 2a 61 70 70 66 73 5f 63 72 65 61 74 65 5f 54 *appfs_create_T
0720: 63 6c 49 6e 74 65 72 70 28 76 6f 69 64 29 20 7b clInterp(void) {
0730: 0a 09 54 63 6c 5f 49 6e 74 65 72 70 20 2a 69 6e ..Tcl_Interp *in
0740: 74 65 72 70 3b 0a 09 69 6e 74 20 74 63 6c 5f 72 terp;..int tcl_r
0750: 65 74 3b 0a 0a 09 41 50 50 46 53 5f 44 45 42 55 et;...APPFS_DEBU
0760: 47 28 22 43 72 65 61 74 69 6e 67 20 6e 65 77 20 G("Creating new
0770: 54 63 6c 20 69 6e 74 65 72 70 72 65 74 65 72 20 Tcl interpreter
0780: 66 6f 72 20 54 49 44 20 3d 20 30 78 25 6c 6c 78 for TID = 0x%llx
0790: 22 2c 20 28 75 6e 73 69 67 6e 65 64 20 6c 6f 6e ", (unsigned lon
07a0: 67 20 6c 6f 6e 67 29 20 70 74 68 72 65 61 64 5f g long) pthread_
07b0: 73 65 6c 66 28 29 29 3b 0a 0a 09 69 6e 74 65 72 self());...inter
07c0: 70 20 3d 20 54 63 6c 5f 43 72 65 61 74 65 49 6e p = Tcl_CreateIn
07d0: 74 65 72 70 28 29 3b 0a 09 69 66 20 28 69 6e 74 terp();..if (int
07e0: 65 72 70 20 3d 3d 20 4e 55 4c 4c 29 20 7b 0a 09 erp == NULL) {..
07f0: 09 66 70 72 69 6e 74 66 28 73 74 64 65 72 72 2c .fprintf(stderr,
0800: 20 22 55 6e 61 62 6c 65 20 74 6f 20 63 72 65 61 "Unable to crea
0810: 74 65 20 54 63 6c 20 49 6e 74 65 72 70 72 65 74 te Tcl Interpret
0820: 65 72 2e 20 20 41 62 6f 72 74 69 6e 67 2e 5c 6e er. Aborting.\n
0830: 22 29 3b 0a 0a 09 09 72 65 74 75 72 6e 28 4e 55 ");....return(NU
0840: 4c 4c 29 3b 0a 09 7d 0a 0a 09 74 63 6c 5f 72 65 LL);..}...tcl_re
0850: 74 20 3d 20 54 63 6c 5f 49 6e 69 74 28 69 6e 74 t = Tcl_Init(int
0860: 65 72 70 29 3b 0a 09 69 66 20 28 74 63 6c 5f 72 erp);..if (tcl_r
0870: 65 74 20 21 3d 20 54 43 4c 5f 4f 4b 29 20 7b 0a et != TCL_OK) {.
0880: 09 09 66 70 72 69 6e 74 66 28 73 74 64 65 72 72 ..fprintf(stderr
0890: 2c 20 22 55 6e 61 62 6c 65 20 74 6f 20 69 6e 69 , "Unable to ini
08a0: 74 69 61 6c 69 7a 65 20 54 63 6c 2e 20 20 41 62 tialize Tcl. Ab
08b0: 6f 72 74 69 6e 67 2e 5c 6e 22 29 3b 0a 09 09 66 orting.\n");...f
08c0: 70 72 69 6e 74 66 28 73 74 64 65 72 72 2c 20 22 printf(stderr, "
08d0: 54 63 6c 20 45 72 72 6f 72 20 69 73 3a 20 25 73 Tcl Error is: %s
08e0: 5c 6e 22 2c 20 54 63 6c 5f 47 65 74 53 74 72 69 \n", Tcl_GetStri
08f0: 6e 67 52 65 73 75 6c 74 28 69 6e 74 65 72 70 29 ngResult(interp)
0900: 29 3b 0a 0a 09 09 54 63 6c 5f 44 65 6c 65 74 65 );....Tcl_Delete
0910: 49 6e 74 65 72 70 28 69 6e 74 65 72 70 29 3b 0a Interp(interp);.
0920: 0a 09 09 72 65 74 75 72 6e 28 4e 55 4c 4c 29 3b ...return(NULL);
0930: 0a 09 7d 0a 0a 09 74 63 6c 5f 72 65 74 20 3d 20 ..}...tcl_ret =
0940: 54 63 6c 5f 45 76 61 6c 28 69 6e 74 65 72 70 2c Tcl_Eval(interp,
0950: 20 22 70 61 63 6b 61 67 65 20 69 66 6e 65 65 64 "package ifneed
0960: 65 64 20 73 68 61 31 20 31 2e 30 20 5b 6c 69 73 ed sha1 1.0 [lis
0970: 74 20 6c 6f 61 64 20 7b 7d 20 73 68 61 31 5d 22 t load {} sha1]"
0980: 29 3b 0a 09 69 66 20 28 74 63 6c 5f 72 65 74 20 );..if (tcl_ret
0990: 21 3d 20 54 43 4c 5f 4f 4b 29 20 7b 0a 09 09 66 != TCL_OK) {...f
09a0: 70 72 69 6e 74 66 28 73 74 64 65 72 72 2c 20 22 printf(stderr, "
09b0: 55 6e 61 62 6c 65 20 74 6f 20 69 6e 69 74 69 61 Unable to initia
09c0: 6c 69 7a 65 20 54 63 6c 20 53 48 41 31 2e 20 20 lize Tcl SHA1.
09d0: 41 62 6f 72 74 69 6e 67 2e 5c 6e 22 29 3b 0a 09 Aborting.\n");..
09e0: 09 66 70 72 69 6e 74 66 28 73 74 64 65 72 72 2c .fprintf(stderr,
09f0: 20 22 54 63 6c 20 45 72 72 6f 72 20 69 73 3a 20 "Tcl Error is:
0a00: 25 73 5c 6e 22 2c 20 54 63 6c 5f 47 65 74 53 74 %s\n", Tcl_GetSt
0a10: 72 69 6e 67 52 65 73 75 6c 74 28 69 6e 74 65 72 ringResult(inter
0a20: 70 29 29 3b 0a 0a 09 09 54 63 6c 5f 44 65 6c 65 p));....Tcl_Dele
0a30: 74 65 49 6e 74 65 72 70 28 69 6e 74 65 72 70 29 teInterp(interp)
0a40: 3b 0a 0a 09 09 72 65 74 75 72 6e 28 4e 55 4c 4c ;....return(NULL
0a50: 29 3b 0a 09 7d 0a 0a 09 74 63 6c 5f 72 65 74 20 );..}...tcl_ret
0a60: 3d 20 54 63 6c 5f 45 76 61 6c 28 69 6e 74 65 72 = Tcl_Eval(inter
0a70: 70 2c 20 22 70 61 63 6b 61 67 65 20 69 66 6e 65 p, "package ifne
0a80: 65 64 65 64 20 61 70 70 66 73 64 20 31 2e 30 20 eded appfsd 1.0
0a90: 5b 6c 69 73 74 20 6c 6f 61 64 20 7b 7d 20 61 70 [list load {} ap
0aa0: 70 66 73 64 5d 22 29 3b 0a 09 69 66 20 28 74 63 pfsd]");..if (tc
0ab0: 6c 5f 72 65 74 20 21 3d 20 54 43 4c 5f 4f 4b 29 l_ret != TCL_OK)
0ac0: 20 7b 0a 09 09 66 70 72 69 6e 74 66 28 73 74 64 {...fprintf(std
0ad0: 65 72 72 2c 20 22 55 6e 61 62 6c 65 20 74 6f 20 err, "Unable to
0ae0: 69 6e 69 74 69 61 6c 69 7a 65 20 54 63 6c 20 41 initialize Tcl A
0af0: 70 70 46 53 20 50 61 63 6b 61 67 65 2e 20 20 41 ppFS Package. A
0b00: 62 6f 72 74 69 6e 67 2e 5c 6e 22 29 3b 0a 09 09 borting.\n");...
0b10: 66 70 72 69 6e 74 66 28 73 74 64 65 72 72 2c 20 fprintf(stderr,
0b20: 22 54 63 6c 20 45 72 72 6f 72 20 69 73 3a 20 25 "Tcl Error is: %
0b30: 73 5c 6e 22 2c 20 54 63 6c 5f 47 65 74 53 74 72 s\n", Tcl_GetStr
0b40: 69 6e 67 52 65 73 75 6c 74 28 69 6e 74 65 72 70 ingResult(interp
0b50: 29 29 3b 0a 0a 09 09 54 63 6c 5f 44 65 6c 65 74 ));....Tcl_Delet
0b60: 65 49 6e 74 65 72 70 28 69 6e 74 65 72 70 29 3b eInterp(interp);
0b70: 0a 0a 09 09 72 65 74 75 72 6e 28 4e 55 4c 4c 29 ....return(NULL)
0b80: 3b 0a 09 7d 0a 0a 09 2f 2a 0a 09 20 2a 20 4c 6f ;..}.../*.. * Lo
0b90: 61 64 20 74 68 65 20 22 61 70 70 66 73 64 2e 74 ad the "appfsd.t
0ba0: 63 6c 22 20 73 63 72 69 70 74 2c 20 77 68 69 63 cl" script, whic
0bb0: 68 20 69 73 20 22 63 6f 6d 70 69 6c 65 64 22 20 h is "compiled"
0bc0: 69 6e 74 6f 20 61 20 43 20 68 65 61 64 65 72 0a into a C header.
0bd0: 09 20 2a 20 73 6f 20 74 68 61 74 20 69 74 20 64 . * so that it d
0be0: 6f 65 73 20 6e 6f 74 20 6e 65 65 64 20 74 6f 20 oes not need to
0bf0: 65 78 69 73 74 20 6f 6e 20 74 68 65 20 66 69 6c exist on the fil
0c00: 65 73 79 73 74 65 6d 20 61 6e 64 20 63 61 6e 20 esystem and can
0c10: 62 65 0a 09 20 2a 20 64 69 72 65 63 74 6c 79 20 be.. * directly
0c20: 65 76 61 6c 75 61 74 65 64 2e 0a 09 20 2a 2f 0a evaluated... */.
0c30: 09 74 63 6c 5f 72 65 74 20 3d 20 54 63 6c 5f 45 .tcl_ret = Tcl_E
0c40: 76 61 6c 28 69 6e 74 65 72 70 2c 20 22 22 0a 23 val(interp, "".#
0c50: 69 6e 63 6c 75 64 65 20 22 61 70 70 66 73 64 2e include "appfsd.
0c60: 74 63 6c 2e 68 22 0a 09 22 22 29 3b 0a 09 69 66 tcl.h".."");..if
0c70: 20 28 74 63 6c 5f 72 65 74 20 21 3d 20 54 43 4c (tcl_ret != TCL
0c80: 5f 4f 4b 29 20 7b 0a 09 09 66 70 72 69 6e 74 66 _OK) {...fprintf
0c90: 28 73 74 64 65 72 72 2c 20 22 55 6e 61 62 6c 65 (stderr, "Unable
0ca0: 20 74 6f 20 69 6e 69 74 69 61 6c 69 7a 65 20 54 to initialize T
0cb0: 63 6c 20 41 70 70 46 53 20 73 63 72 69 70 74 2e cl AppFS script.
0cc0: 20 20 41 62 6f 72 74 69 6e 67 2e 5c 6e 22 29 3b Aborting.\n");
0cd0: 0a 09 09 66 70 72 69 6e 74 66 28 73 74 64 65 72 ...fprintf(stder
0ce0: 72 2c 20 22 54 63 6c 20 45 72 72 6f 72 20 69 73 r, "Tcl Error is
0cf0: 3a 20 25 73 5c 6e 22 2c 20 54 63 6c 5f 47 65 74 : %s\n", Tcl_Get
0d00: 53 74 72 69 6e 67 52 65 73 75 6c 74 28 69 6e 74 StringResult(int
0d10: 65 72 70 29 29 3b 0a 0a 09 09 54 63 6c 5f 44 65 erp));....Tcl_De
0d20: 6c 65 74 65 49 6e 74 65 72 70 28 69 6e 74 65 72 leteInterp(inter
0d30: 70 29 3b 0a 0a 09 09 72 65 74 75 72 6e 28 4e 55 p);....return(NU
0d40: 4c 4c 29 3b 0a 09 7d 0a 0a 09 2f 2a 0a 09 20 2a LL);..}.../*.. *
0d50: 20 53 65 74 20 67 6c 6f 62 61 6c 20 76 61 72 69 Set global vari
0d60: 61 62 6c 65 73 20 66 72 6f 6d 20 43 20 74 6f 20 ables from C to
0d70: 54 63 6c 0a 09 20 2a 2f 0a 09 69 66 20 28 54 63 Tcl.. */..if (Tc
0d80: 6c 5f 53 65 74 56 61 72 28 69 6e 74 65 72 70 2c l_SetVar(interp,
0d90: 20 22 3a 3a 61 70 70 66 73 3a 3a 63 61 63 68 65 "::appfs::cache
0da0: 64 69 72 22 2c 20 61 70 70 66 73 5f 63 61 63 68 dir", appfs_cach
0db0: 65 64 69 72 2c 20 54 43 4c 5f 47 4c 4f 42 41 4c edir, TCL_GLOBAL
0dc0: 5f 4f 4e 4c 59 29 20 3d 3d 20 4e 55 4c 4c 29 20 _ONLY) == NULL)
0dd0: 7b 0a 09 09 66 70 72 69 6e 74 66 28 73 74 64 65 {...fprintf(stde
0de0: 72 72 2c 20 22 55 6e 61 62 6c 65 20 74 6f 20 73 rr, "Unable to s
0df0: 65 74 20 63 61 63 68 65 20 64 69 72 65 63 74 6f et cache directo
0e00: 72 79 2e 20 20 54 68 69 73 20 73 68 6f 75 6c 64 ry. This should
0e10: 20 6e 65 76 65 72 20 66 61 69 6c 2e 5c 6e 22 29 never fail.\n")
0e20: 3b 0a 0a 09 09 54 63 6c 5f 44 65 6c 65 74 65 49 ;....Tcl_DeleteI
0e30: 6e 74 65 72 70 28 69 6e 74 65 72 70 29 3b 0a 0a nterp(interp);..
0e40: 09 09 72 65 74 75 72 6e 28 4e 55 4c 4c 29 3b 0a ..return(NULL);.
0e50: 09 7d 0a 0a 09 2f 2a 0a 09 20 2a 20 49 6e 69 74 .}.../*.. * Init
0e60: 69 61 6c 69 7a 65 20 74 68 65 20 22 61 70 70 66 ialize the "appf
0e70: 73 64 2e 74 63 6c 22 20 65 6e 76 69 72 6f 6e 6d sd.tcl" environm
0e80: 65 6e 74 2c 20 77 68 69 63 68 20 6d 75 73 74 20 ent, which must
0e90: 62 65 20 64 6f 6e 65 20 61 66 74 65 72 0a 09 20 be done after..
0ea0: 2a 20 67 6c 6f 62 61 6c 20 76 61 72 69 61 62 6c * global variabl
0eb0: 65 73 20 61 72 65 20 73 65 74 2e 0a 09 20 2a 2f es are set... */
0ec0: 0a 09 74 63 6c 5f 72 65 74 20 3d 20 54 63 6c 5f ..tcl_ret = Tcl_
0ed0: 45 76 61 6c 28 69 6e 74 65 72 70 2c 20 22 3a 3a Eval(interp, "::
0ee0: 61 70 70 66 73 3a 3a 69 6e 69 74 22 29 3b 0a 09 appfs::init");..
0ef0: 69 66 20 28 74 63 6c 5f 72 65 74 20 21 3d 20 54 if (tcl_ret != T
0f00: 43 4c 5f 4f 4b 29 20 7b 0a 09 09 66 70 72 69 6e CL_OK) {...fprin
0f10: 74 66 28 73 74 64 65 72 72 2c 20 22 55 6e 61 62 tf(stderr, "Unab
0f20: 6c 65 20 74 6f 20 69 6e 69 74 69 61 6c 69 7a 65 le to initialize
0f30: 20 54 63 6c 20 41 70 70 46 53 20 73 63 72 69 70 Tcl AppFS scrip
0f40: 74 20 28 3a 3a 61 70 70 66 73 3a 3a 69 6e 69 74 t (::appfs::init
0f50: 29 2e 20 20 41 62 6f 72 74 69 6e 67 2e 5c 6e 22 ). Aborting.\n"
0f60: 29 3b 0a 09 09 66 70 72 69 6e 74 66 28 73 74 64 );...fprintf(std
0f70: 65 72 72 2c 20 22 54 63 6c 20 45 72 72 6f 72 20 err, "Tcl Error
0f80: 69 73 3a 20 25 73 5c 6e 22 2c 20 54 63 6c 5f 47 is: %s\n", Tcl_G
0f90: 65 74 53 74 72 69 6e 67 52 65 73 75 6c 74 28 69 etStringResult(i
0fa0: 6e 74 65 72 70 29 29 3b 0a 0a 09 09 54 63 6c 5f nterp));....Tcl_
0fb0: 44 65 6c 65 74 65 49 6e 74 65 72 70 28 69 6e 74 DeleteInterp(int
0fc0: 65 72 70 29 3b 0a 0a 09 09 72 65 74 75 72 6e 28 erp);....return(
0fd0: 4e 55 4c 4c 29 3b 0a 09 7d 0a 0a 09 2f 2a 0a 09 NULL);..}.../*..
0fe0: 20 2a 20 48 69 64 65 20 73 6f 6d 65 20 54 63 6c * Hide some Tcl
0ff0: 20 63 6f 6d 6d 61 6e 64 73 20 74 68 61 74 20 77 commands that w
1000: 65 20 64 6f 20 6e 6f 74 20 63 61 72 65 20 74 6f e do not care to
1010: 20 75 73 65 20 61 6e 64 20 77 68 69 63 68 20 6d use and which m
1020: 61 79 0a 09 20 2a 20 73 6c 6f 77 20 64 6f 77 6e ay.. * slow down
1030: 20 72 75 6e 2d 74 69 6d 65 20 6f 70 65 72 61 74 run-time operat
1040: 69 6f 6e 73 2e 0a 09 20 2a 2f 0a 09 54 63 6c 5f ions... */..Tcl_
1050: 48 69 64 65 43 6f 6d 6d 61 6e 64 28 69 6e 74 65 HideCommand(inte
1060: 72 70 2c 20 22 61 75 74 6f 5f 6c 6f 61 64 5f 69 rp, "auto_load_i
1070: 6e 64 65 78 22 2c 20 22 61 75 74 6f 5f 6c 6f 61 ndex", "auto_loa
1080: 64 5f 69 6e 64 65 78 22 29 3b 0a 09 54 63 6c 5f d_index");..Tcl_
1090: 48 69 64 65 43 6f 6d 6d 61 6e 64 28 69 6e 74 65 HideCommand(inte
10a0: 72 70 2c 20 22 75 6e 6b 6e 6f 77 6e 22 2c 20 22 rp, "unknown", "
10b0: 75 6e 6b 6e 6f 77 6e 22 29 3b 0a 0a 09 2f 2a 0a unknown");.../*.
10c0: 09 20 2a 20 52 65 74 75 72 6e 20 74 68 65 20 63 . * Return the c
10d0: 6f 6d 70 6c 65 74 65 6c 79 20 69 6e 69 74 69 61 ompletely initia
10e0: 6c 69 7a 65 64 20 69 6e 74 65 72 70 72 65 74 65 lized interprete
10f0: 72 0a 09 20 2a 2f 0a 09 72 65 74 75 72 6e 28 69 r.. */..return(i
1100: 6e 74 65 72 70 29 3b 0a 7d 0a 0a 2f 2a 0a 20 2a nterp);.}../*. *
1110: 20 52 65 74 75 72 6e 20 74 68 65 20 74 68 72 65 Return the thre
1120: 61 64 2d 73 70 65 63 69 66 69 63 20 54 63 6c 20 ad-specific Tcl
1130: 69 6e 74 65 72 70 72 65 74 65 72 2c 20 63 72 65 interpreter, cre
1140: 61 74 69 6e 67 20 69 74 20 69 66 20 6e 65 65 64 ating it if need
1150: 65 64 0a 20 2a 2f 0a 73 74 61 74 69 63 20 54 63 ed. */.static Tc
1160: 6c 5f 49 6e 74 65 72 70 20 2a 61 70 70 66 73 5f l_Interp *appfs_
1170: 54 63 6c 49 6e 74 65 72 70 28 76 6f 69 64 29 20 TclInterp(void)
1180: 7b 0a 09 54 63 6c 5f 49 6e 74 65 72 70 20 2a 69 {..Tcl_Interp *i
1190: 6e 74 65 72 70 3b 0a 09 69 6e 74 20 70 74 68 72 nterp;..int pthr
11a0: 65 61 64 5f 72 65 74 3b 0a 0a 09 69 6e 74 65 72 ead_ret;...inter
11b0: 70 20 3d 20 70 74 68 72 65 61 64 5f 67 65 74 73 p = pthread_gets
11c0: 70 65 63 69 66 69 63 28 69 6e 74 65 72 70 4b 65 pecific(interpKe
11d0: 79 29 3b 0a 09 69 66 20 28 69 6e 74 65 72 70 20 y);..if (interp
11e0: 3d 3d 20 4e 55 4c 4c 29 20 7b 0a 09 09 69 6e 74 == NULL) {...int
11f0: 65 72 70 20 3d 20 61 70 70 66 73 5f 63 72 65 61 erp = appfs_crea
1200: 74 65 5f 54 63 6c 49 6e 74 65 72 70 28 29 3b 0a te_TclInterp();.
1210: 0a 09 09 69 66 20 28 69 6e 74 65 72 70 20 3d 3d ...if (interp ==
1220: 20 4e 55 4c 4c 29 20 7b 0a 09 09 09 72 65 74 75 NULL) {....retu
1230: 72 6e 28 4e 55 4c 4c 29 3b 0a 09 09 7d 0a 0a 09 rn(NULL);...}...
1240: 09 70 74 68 72 65 61 64 5f 72 65 74 20 3d 20 70 .pthread_ret = p
1250: 74 68 72 65 61 64 5f 73 65 74 73 70 65 63 69 66 thread_setspecif
1260: 69 63 28 69 6e 74 65 72 70 4b 65 79 2c 20 69 6e ic(interpKey, in
1270: 74 65 72 70 29 3b 0a 09 09 69 66 20 28 70 74 68 terp);...if (pth
1280: 72 65 61 64 5f 72 65 74 20 21 3d 20 30 29 20 7b read_ret != 0) {
1290: 0a 09 09 09 54 63 6c 5f 44 65 6c 65 74 65 49 6e ....Tcl_DeleteIn
12a0: 74 65 72 70 28 69 6e 74 65 72 70 29 3b 0a 0a 09 terp(interp);...
12b0: 09 09 72 65 74 75 72 6e 28 4e 55 4c 4c 29 3b 0a ..return(NULL);.
12c0: 09 09 7d 0a 09 7d 0a 0a 09 72 65 74 75 72 6e 28 ..}..}...return(
12d0: 69 6e 74 65 72 70 29 3b 0a 7d 0a 0a 2f 2a 0a 20 interp);.}../*.
12e0: 2a 20 45 76 61 6c 75 61 74 65 20 61 20 54 63 6c * Evaluate a Tcl
12f0: 20 73 63 72 69 70 74 20 63 6f 6e 73 74 72 75 63 script construc
1300: 74 65 64 20 62 79 20 63 6f 6e 63 61 74 65 6e 61 ted by concatena
1310: 74 69 6e 67 20 61 20 62 75 6e 63 68 20 6f 66 20 ting a bunch of
1320: 43 20 73 74 72 69 6e 67 73 0a 20 2a 20 74 6f 67 C strings. * tog
1330: 65 74 68 65 72 2e 0a 20 2a 2f 0a 73 74 61 74 69 ether.. */.stati
1340: 63 20 69 6e 74 20 61 70 70 66 73 5f 54 63 6c 5f c int appfs_Tcl_
1350: 45 76 61 6c 28 54 63 6c 5f 49 6e 74 65 72 70 20 Eval(Tcl_Interp
1360: 2a 69 6e 74 65 72 70 2c 20 69 6e 74 20 6f 62 6a *interp, int obj
1370: 63 2c 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 63 c, const char *c
1380: 6d 64 2c 20 2e 2e 2e 29 20 7b 0a 09 54 63 6c 5f md, ...) {..Tcl_
1390: 4f 62 6a 20 2a 2a 6f 62 6a 76 3b 0a 09 63 6f 6e Obj **objv;..con
13a0: 73 74 20 63 68 61 72 20 2a 61 72 67 3b 0a 09 76 st char *arg;..v
13b0: 61 5f 6c 69 73 74 20 61 72 67 70 3b 0a 09 69 6e a_list argp;..in
13c0: 74 20 72 65 74 76 61 6c 3b 0a 09 69 6e 74 20 69 t retval;..int i
13d0: 3b 0a 0a 09 69 66 20 28 69 6e 74 65 72 70 20 3d ;...if (interp =
13e0: 3d 20 4e 55 4c 4c 29 20 7b 0a 09 09 72 65 74 75 = NULL) {...retu
13f0: 72 6e 28 54 43 4c 5f 45 52 52 4f 52 29 3b 0a 09 rn(TCL_ERROR);..
1400: 7d 0a 0a 09 6f 62 6a 76 20 3d 20 28 76 6f 69 64 }...objv = (void
1410: 20 2a 29 20 63 6b 61 6c 6c 6f 63 28 73 69 7a 65 *) ckalloc(size
1420: 6f 66 28 2a 6f 62 6a 76 29 20 2a 20 6f 62 6a 63 of(*objv) * objc
1430: 29 3b 0a 09 6f 62 6a 76 5b 30 5d 20 3d 20 54 63 );..objv[0] = Tc
1440: 6c 5f 4e 65 77 53 74 72 69 6e 67 4f 62 6a 28 63 l_NewStringObj(c
1450: 6d 64 2c 20 2d 31 29 3b 0a 09 54 63 6c 5f 49 6e md, -1);..Tcl_In
1460: 63 72 52 65 66 43 6f 75 6e 74 28 6f 62 6a 76 5b crRefCount(objv[
1470: 30 5d 29 3b 0a 0a 09 76 61 5f 73 74 61 72 74 28 0]);...va_start(
1480: 61 72 67 70 2c 20 63 6d 64 29 3b 0a 09 66 6f 72 argp, cmd);..for
1490: 20 28 69 20 3d 20 31 3b 20 69 20 3c 20 6f 62 6a (i = 1; i < obj
14a0: 63 3b 20 69 2b 2b 29 20 7b 0a 09 09 61 72 67 20 c; i++) {...arg
14b0: 3d 20 76 61 5f 61 72 67 28 61 72 67 70 2c 20 63 = va_arg(argp, c
14c0: 6f 6e 73 74 20 63 68 61 72 20 2a 29 3b 0a 09 09 onst char *);...
14d0: 6f 62 6a 76 5b 69 5d 20 3d 20 54 63 6c 5f 4e 65 objv[i] = Tcl_Ne
14e0: 77 53 74 72 69 6e 67 4f 62 6a 28 61 72 67 2c 20 wStringObj(arg,
14f0: 2d 31 29 3b 0a 09 09 54 63 6c 5f 49 6e 63 72 52 -1);...Tcl_IncrR
1500: 65 66 43 6f 75 6e 74 28 6f 62 6a 76 5b 69 5d 29 efCount(objv[i])
1510: 3b 0a 09 7d 0a 09 76 61 5f 65 6e 64 28 61 72 67 ;..}..va_end(arg
1520: 70 29 3b 0a 0a 09 72 65 74 76 61 6c 20 3d 20 54 p);...retval = T
1530: 63 6c 5f 45 76 61 6c 4f 62 6a 76 28 69 6e 74 65 cl_EvalObjv(inte
1540: 72 70 2c 20 6f 62 6a 63 2c 20 6f 62 6a 76 2c 20 rp, objc, objv,
1550: 30 29 3b 0a 0a 09 66 6f 72 20 28 69 20 3d 20 30 0);...for (i = 0
1560: 3b 20 69 20 3c 20 6f 62 6a 63 3b 20 69 2b 2b 29 ; i < objc; i++)
1570: 20 7b 0a 09 09 54 63 6c 5f 44 65 63 72 52 65 66 {...Tcl_DecrRef
1580: 43 6f 75 6e 74 28 6f 62 6a 76 5b 69 5d 29 3b 0a Count(objv[i]);.
1590: 09 7d 0a 0a 09 63 6b 66 72 65 65 28 28 76 6f 69 .}...ckfree((voi
15a0: 64 20 2a 29 20 6f 62 6a 76 29 3b 0a 0a 09 69 66 d *) objv);...if
15b0: 20 28 72 65 74 76 61 6c 20 21 3d 20 54 43 4c 5f (retval != TCL_
15c0: 4f 4b 29 20 7b 0a 09 09 41 50 50 46 53 5f 44 45 OK) {...APPFS_DE
15d0: 42 55 47 28 22 54 63 6c 20 63 6f 6d 6d 61 6e 64 BUG("Tcl command
15e0: 20 66 61 69 6c 65 64 2c 20 3a 3a 65 72 72 6f 72 failed, ::error
15f0: 49 6e 66 6f 20 63 6f 6e 74 61 69 6e 73 3a 20 25 Info contains: %
1600: 73 5c 6e 22 2c 20 54 63 6c 5f 47 65 74 56 61 72 s\n", Tcl_GetVar
1610: 28 69 6e 74 65 72 70 2c 20 22 3a 3a 65 72 72 6f (interp, "::erro
1620: 72 49 6e 66 6f 22 2c 20 30 29 29 3b 0a 09 7d 0a rInfo", 0));..}.
1630: 0a 09 72 65 74 75 72 6e 28 72 65 74 76 61 6c 29 ..return(retval)
1640: 3b 0a 7d 0a 0a 2f 2a 0a 20 2a 20 41 70 70 46 53 ;.}../*. * AppFS
1650: 3a 20 52 65 71 75 65 73 74 20 74 68 61 74 20 61 : Request that a
1660: 20 68 6f 73 74 27 73 20 70 61 63 6b 61 67 65 20 host's package
1670: 69 6e 64 65 78 20 62 65 20 75 70 64 61 74 65 64 index be updated
1680: 20 6c 6f 63 61 6c 6c 79 0a 20 2a 2f 0a 73 74 61 locally. */.sta
1690: 74 69 63 20 76 6f 69 64 20 61 70 70 66 73 5f 75 tic void appfs_u
16a0: 70 64 61 74 65 5f 69 6e 64 65 78 28 63 6f 6e 73 pdate_index(cons
16b0: 74 20 63 68 61 72 20 2a 68 6f 73 74 6e 61 6d 65 t char *hostname
16c0: 29 20 7b 0a 09 54 63 6c 5f 49 6e 74 65 72 70 20 ) {..Tcl_Interp
16d0: 2a 69 6e 74 65 72 70 3b 0a 09 69 6e 74 20 74 63 *interp;..int tc
16e0: 6c 5f 72 65 74 3b 0a 0a 09 41 50 50 46 53 5f 44 l_ret;...APPFS_D
16f0: 45 42 55 47 28 22 45 6e 74 65 72 3a 20 68 6f 73 EBUG("Enter: hos
1700: 74 6e 61 6d 65 20 3d 20 25 73 22 2c 20 68 6f 73 tname = %s", hos
1710: 74 6e 61 6d 65 29 3b 0a 0a 09 69 6e 74 65 72 70 tname);...interp
1720: 20 3d 20 61 70 70 66 73 5f 54 63 6c 49 6e 74 65 = appfs_TclInte
1730: 72 70 28 29 3b 0a 09 69 66 20 28 69 6e 74 65 72 rp();..if (inter
1740: 70 20 3d 3d 20 4e 55 4c 4c 29 20 7b 0a 09 09 72 p == NULL) {...r
1750: 65 74 75 72 6e 3b 0a 09 7d 0a 0a 09 74 63 6c 5f eturn;..}...tcl_
1760: 72 65 74 20 3d 20 61 70 70 66 73 5f 54 63 6c 5f ret = appfs_Tcl_
1770: 45 76 61 6c 28 69 6e 74 65 72 70 2c 20 32 2c 20 Eval(interp, 2,
1780: 22 3a 3a 61 70 70 66 73 3a 3a 67 65 74 69 6e 64 "::appfs::getind
1790: 65 78 22 2c 20 68 6f 73 74 6e 61 6d 65 29 3b 0a ex", hostname);.
17a0: 09 69 66 20 28 74 63 6c 5f 72 65 74 20 21 3d 20 .if (tcl_ret !=
17b0: 54 43 4c 5f 4f 4b 29 20 7b 0a 09 09 41 50 50 46 TCL_OK) {...APPF
17c0: 53 5f 44 45 42 55 47 28 22 43 61 6c 6c 20 74 6f S_DEBUG("Call to
17d0: 20 3a 3a 61 70 70 66 73 3a 3a 67 65 74 69 6e 64 ::appfs::getind
17e0: 65 78 20 66 61 69 6c 65 64 3a 20 25 73 22 2c 20 ex failed: %s",
17f0: 54 63 6c 5f 47 65 74 53 74 72 69 6e 67 52 65 73 Tcl_GetStringRes
1800: 75 6c 74 28 69 6e 74 65 72 70 29 29 3b 0a 0a 09 ult(interp));...
1810: 09 72 65 74 75 72 6e 3b 0a 09 7d 0a 0a 09 72 65 .return;..}...re
1820: 74 75 72 6e 3b 0a 7d 0a 0a 2f 2a 0a 20 2a 20 41 turn;.}../*. * A
1830: 70 70 46 53 3a 20 47 65 74 20 61 20 53 48 41 31 ppFS: Get a SHA1
1840: 20 66 72 6f 6d 20 61 20 68 6f 73 74 0a 20 2a 20 from a host. *
1850: 20 20 20 20 20 20 20 20 52 65 74 75 72 6e 73 20 Returns
1860: 61 20 6c 6f 63 61 6c 20 66 69 6c 65 20 6e 61 6d a local file nam
1870: 65 2c 20 6f 72 20 4e 55 4c 4c 20 69 66 20 69 74 e, or NULL if it
1880: 20 63 61 6e 6e 6f 74 20 62 65 20 66 65 74 63 68 cannot be fetch
1890: 65 64 0a 20 2a 2f 0a 73 74 61 74 69 63 20 63 6f ed. */.static co
18a0: 6e 73 74 20 63 68 61 72 20 2a 61 70 70 66 73 5f nst char *appfs_
18b0: 67 65 74 66 69 6c 65 28 63 6f 6e 73 74 20 63 68 getfile(const ch
18c0: 61 72 20 2a 68 6f 73 74 6e 61 6d 65 2c 20 63 6f ar *hostname, co
18d0: 6e 73 74 20 63 68 61 72 20 2a 73 68 61 31 29 20 nst char *sha1)
18e0: 7b 0a 09 54 63 6c 5f 49 6e 74 65 72 70 20 2a 69 {..Tcl_Interp *i
18f0: 6e 74 65 72 70 3b 0a 09 63 68 61 72 20 2a 72 65 nterp;..char *re
1900: 74 76 61 6c 3b 0a 09 69 6e 74 20 74 63 6c 5f 72 tval;..int tcl_r
1910: 65 74 3b 0a 0a 09 69 6e 74 65 72 70 20 3d 20 61 et;...interp = a
1920: 70 70 66 73 5f 54 63 6c 49 6e 74 65 72 70 28 29 ppfs_TclInterp()
1930: 3b 0a 09 69 66 20 28 69 6e 74 65 72 70 20 3d 3d ;..if (interp ==
1940: 20 4e 55 4c 4c 29 20 7b 0a 09 09 72 65 74 75 72 NULL) {...retur
1950: 6e 28 4e 55 4c 4c 29 3b 0a 09 7d 0a 0a 09 74 63 n(NULL);..}...tc
1960: 6c 5f 72 65 74 20 3d 20 61 70 70 66 73 5f 54 63 l_ret = appfs_Tc
1970: 6c 5f 45 76 61 6c 28 69 6e 74 65 72 70 2c 20 33 l_Eval(interp, 3
1980: 2c 20 22 3a 3a 61 70 70 66 73 3a 3a 64 6f 77 6e , "::appfs::down
1990: 6c 6f 61 64 22 2c 20 68 6f 73 74 6e 61 6d 65 2c load", hostname,
19a0: 20 73 68 61 31 29 3b 0a 09 69 66 20 28 74 63 6c sha1);..if (tcl
19b0: 5f 72 65 74 20 21 3d 20 54 43 4c 5f 4f 4b 29 20 _ret != TCL_OK)
19c0: 7b 0a 09 09 41 50 50 46 53 5f 44 45 42 55 47 28 {...APPFS_DEBUG(
19d0: 22 43 61 6c 6c 20 74 6f 20 3a 3a 61 70 70 66 73 "Call to ::appfs
19e0: 3a 3a 64 6f 77 6e 6c 6f 61 64 20 66 61 69 6c 65 ::download faile
19f0: 64 3a 20 25 73 22 2c 20 54 63 6c 5f 47 65 74 53 d: %s", Tcl_GetS
1a00: 74 72 69 6e 67 52 65 73 75 6c 74 28 69 6e 74 65 tringResult(inte
1a10: 72 70 29 29 3b 0a 0a 09 09 72 65 74 75 72 6e 28 rp));....return(
1a20: 4e 55 4c 4c 29 3b 0a 09 7d 0a 0a 09 72 65 74 76 NULL);..}...retv
1a30: 61 6c 20 3d 20 73 74 72 64 75 70 28 54 63 6c 5f al = strdup(Tcl_
1a40: 47 65 74 53 74 72 69 6e 67 52 65 73 75 6c 74 28 GetStringResult(
1a50: 69 6e 74 65 72 70 29 29 3b 0a 0a 09 72 65 74 75 interp));...retu
1a60: 72 6e 28 72 65 74 76 61 6c 29 3b 0a 7d 0a 0a 2f rn(retval);.}../
1a70: 2a 0a 20 2a 20 41 70 70 46 53 3a 20 55 70 64 61 *. * AppFS: Upda
1a80: 74 65 20 74 68 65 20 6d 61 6e 69 66 65 73 74 20 te the manifest
1a90: 66 6f 72 20 61 20 73 70 65 63 69 66 69 63 20 70 for a specific p
1aa0: 61 63 6b 61 67 65 20 28 62 79 20 74 68 65 20 70 ackage (by the p
1ab0: 61 63 6b 61 67 65 20 53 48 41 31 29 20 6f 6e 0a ackage SHA1) on.
1ac0: 20 2a 20 61 20 67 69 76 65 6e 20 68 6f 73 74 0a * a given host.
1ad0: 20 2a 2f 0a 73 74 61 74 69 63 20 76 6f 69 64 20 */.static void
1ae0: 61 70 70 66 73 5f 75 70 64 61 74 65 5f 6d 61 6e appfs_update_man
1af0: 69 66 65 73 74 28 63 6f 6e 73 74 20 63 68 61 72 ifest(const char
1b00: 20 2a 68 6f 73 74 6e 61 6d 65 2c 20 63 6f 6e 73 *hostname, cons
1b10: 74 20 63 68 61 72 20 2a 73 68 61 31 29 20 7b 0a t char *sha1) {.
1b20: 09 54 63 6c 5f 49 6e 74 65 72 70 20 2a 69 6e 74 .Tcl_Interp *int
1b30: 65 72 70 3b 0a 09 69 6e 74 20 74 63 6c 5f 72 65 erp;..int tcl_re
1b40: 74 3b 0a 0a 09 69 6e 74 65 72 70 20 3d 20 61 70 t;...interp = ap
1b50: 70 66 73 5f 54 63 6c 49 6e 74 65 72 70 28 29 3b pfs_TclInterp();
1b60: 0a 09 69 66 20 28 69 6e 74 65 72 70 20 3d 3d 20 ..if (interp ==
1b70: 4e 55 4c 4c 29 20 7b 0a 09 09 72 65 74 75 72 6e NULL) {...return
1b80: 3b 0a 09 7d 0a 0a 09 74 63 6c 5f 72 65 74 20 3d ;..}...tcl_ret =
1b90: 20 61 70 70 66 73 5f 54 63 6c 5f 45 76 61 6c 28 appfs_Tcl_Eval(
1ba0: 69 6e 74 65 72 70 2c 20 33 2c 20 22 3a 3a 61 70 interp, 3, "::ap
1bb0: 70 66 73 3a 3a 67 65 74 70 6b 67 6d 61 6e 69 66 pfs::getpkgmanif
1bc0: 65 73 74 22 2c 20 68 6f 73 74 6e 61 6d 65 2c 20 est", hostname,
1bd0: 73 68 61 31 29 3b 0a 09 69 66 20 28 74 63 6c 5f sha1);..if (tcl_
1be0: 72 65 74 20 21 3d 20 54 43 4c 5f 4f 4b 29 20 7b ret != TCL_OK) {
1bf0: 0a 09 09 41 50 50 46 53 5f 44 45 42 55 47 28 22 ...APPFS_DEBUG("
1c00: 43 61 6c 6c 20 74 6f 20 3a 3a 61 70 70 66 73 3a Call to ::appfs:
1c10: 3a 67 65 74 70 6b 67 6d 61 6e 69 66 65 73 74 20 :getpkgmanifest
1c20: 66 61 69 6c 65 64 3a 20 25 73 22 2c 20 54 63 6c failed: %s", Tcl
1c30: 5f 47 65 74 53 74 72 69 6e 67 52 65 73 75 6c 74 _GetStringResult
1c40: 28 69 6e 74 65 72 70 29 29 3b 0a 0a 09 09 72 65 (interp));....re
1c50: 74 75 72 6e 3b 0a 09 7d 0a 0a 09 72 65 74 75 72 turn;..}...retur
1c60: 6e 3b 0a 7d 0a 0a 2f 2a 0a 20 2a 20 44 65 74 65 n;.}../*. * Dete
1c70: 72 6d 69 6e 65 20 74 68 65 20 55 49 44 20 66 6f rmine the UID fo
1c80: 72 20 74 68 65 20 75 73 65 72 20 6d 61 6b 69 6e r the user makin
1c90: 67 20 74 68 65 20 63 75 72 72 65 6e 74 20 46 55 g the current FU
1ca0: 53 45 20 66 69 6c 65 73 79 73 74 65 6d 20 72 65 SE filesystem re
1cb0: 71 75 65 73 74 2e 0a 20 2a 20 54 68 69 73 20 77 quest.. * This w
1cc0: 69 6c 6c 20 62 65 20 75 73 65 64 20 74 6f 20 6c ill be used to l
1cd0: 6f 6f 6b 75 70 20 74 68 65 20 75 73 65 72 27 73 ookup the user's
1ce0: 20 68 6f 6d 65 20 64 69 72 65 63 74 6f 72 79 20 home directory
1cf0: 73 6f 20 77 65 20 63 61 6e 20 73 65 61 72 63 68 so we can search
1d00: 20 66 6f 72 0a 20 2a 20 6c 6f 63 61 6c 6c 79 20 for. * locally
1d10: 6d 6f 64 69 66 69 65 64 20 66 69 6c 65 73 2e 0a modified files..
1d20: 20 2a 2f 0a 73 74 61 74 69 63 20 75 69 64 5f 74 */.static uid_t
1d30: 20 61 70 70 66 73 5f 67 65 74 5f 66 73 75 69 64 appfs_get_fsuid
1d40: 28 76 6f 69 64 29 20 7b 0a 09 73 74 72 75 63 74 (void) {..struct
1d50: 20 66 75 73 65 5f 63 6f 6e 74 65 78 74 20 2a 63 fuse_context *c
1d60: 74 78 3b 0a 0a 09 63 74 78 20 3d 20 66 75 73 65 tx;...ctx = fuse
1d70: 5f 67 65 74 5f 63 6f 6e 74 65 78 74 28 29 3b 0a _get_context();.
1d80: 09 69 66 20 28 63 74 78 20 3d 3d 20 4e 55 4c 4c .if (ctx == NULL
1d90: 29 20 7b 0a 09 09 2f 2a 20 55 6e 61 62 6c 65 20 ) {.../* Unable
1da0: 74 6f 20 6c 6f 6f 6b 75 70 20 75 73 65 72 20 66 to lookup user f
1db0: 6f 72 20 73 6f 6d 65 20 72 65 61 73 6f 6e 20 2a or some reason *
1dc0: 2f 0a 09 09 2f 2a 20 52 65 74 75 72 6e 20 61 6e /.../* Return an
1dd0: 20 75 6e 70 72 69 76 69 6c 65 67 65 64 20 75 73 unprivileged us
1de0: 65 72 20 49 44 20 2a 2f 0a 09 09 72 65 74 75 72 er ID */...retur
1df0: 6e 28 31 29 3b 0a 09 7d 0a 0a 09 72 65 74 75 72 n(1);..}...retur
1e00: 6e 28 63 74 78 2d 3e 75 69 64 29 3b 0a 7d 0a 0a n(ctx->uid);.}..
1e10: 2f 2a 0a 20 2a 20 4c 6f 6f 6b 20 75 70 20 74 68 /*. * Look up th
1e20: 65 20 68 6f 6d 65 20 64 69 72 65 63 74 6f 72 79 e home directory
1e30: 20 66 6f 72 20 61 20 67 69 76 65 6e 20 55 49 44 for a given UID
1e40: 0a 20 2a 20 20 20 20 20 20 20 20 52 65 74 75 72 . * Retur
1e50: 6e 73 20 61 20 43 20 73 74 72 69 6e 67 20 63 6f ns a C string co
1e60: 6e 74 61 69 6e 69 6e 67 20 74 68 65 20 75 73 65 ntaining the use
1e70: 72 27 73 20 68 6f 6d 65 20 64 69 72 65 63 74 6f r's home directo
1e80: 72 79 20 6f 72 20 4e 55 4c 4c 20 69 66 0a 20 2a ry or NULL if. *
1e90: 20 20 20 20 20 20 20 20 74 68 65 20 75 73 65 72 the user
1ea0: 27 73 20 68 6f 6d 65 20 64 69 72 65 63 74 6f 72 's home director
1eb0: 79 20 64 6f 65 73 20 6e 6f 74 20 65 78 69 73 74 y does not exist
1ec0: 20 6f 72 20 69 73 20 6e 6f 74 20 63 6f 72 72 65 or is not corre
1ed0: 63 74 6c 79 0a 20 2a 20 20 20 20 20 20 20 20 63 ctly. * c
1ee0: 6f 6e 66 69 67 75 72 65 64 0a 20 2a 2f 0a 73 74 onfigured. */.st
1ef0: 61 74 69 63 20 63 68 61 72 20 2a 61 70 70 66 73 atic char *appfs
1f00: 5f 67 65 74 5f 68 6f 6d 65 64 69 72 28 75 69 64 _get_homedir(uid
1f10: 5f 74 20 66 73 75 69 64 29 20 7b 0a 09 73 74 72 _t fsuid) {..str
1f20: 75 63 74 20 70 61 73 73 77 64 20 65 6e 74 72 79 uct passwd entry
1f30: 2c 20 2a 72 65 73 75 6c 74 3b 0a 09 73 74 72 75 , *result;..stru
1f40: 63 74 20 73 74 61 74 20 73 74 62 75 66 3b 0a 09 ct stat stbuf;..
1f50: 63 68 61 72 20 62 75 66 5b 31 30 32 34 5d 2c 20 char buf[1024],
1f60: 2a 72 65 74 76 61 6c 3b 0a 09 69 6e 74 20 67 70 *retval;..int gp
1f70: 75 5f 72 65 74 2c 20 73 74 61 74 5f 72 65 74 3b u_ret, stat_ret;
1f80: 0a 0a 09 67 70 75 5f 72 65 74 20 3d 20 67 65 74 ...gpu_ret = get
1f90: 70 77 75 69 64 5f 72 28 66 73 75 69 64 2c 20 26 pwuid_r(fsuid, &
1fa0: 65 6e 74 72 79 2c 20 62 75 66 2c 20 73 69 7a 65 entry, buf, size
1fb0: 6f 66 28 62 75 66 29 2c 20 26 72 65 73 75 6c 74 of(buf), &result
1fc0: 29 3b 0a 09 69 66 20 28 67 70 75 5f 72 65 74 20 );..if (gpu_ret
1fd0: 21 3d 20 30 29 20 7b 0a 09 09 41 50 50 46 53 5f != 0) {...APPFS_
1fe0: 44 45 42 55 47 28 22 67 65 74 70 77 75 69 64 5f DEBUG("getpwuid_
1ff0: 72 28 25 6c 6c 75 2c 20 2e 2e 2e 29 20 72 65 74 r(%llu, ...) ret
2000: 75 72 6e 65 64 20 69 6e 20 66 61 69 6c 75 72 65 urned in failure
2010: 22 2c 20 28 75 6e 73 69 67 6e 65 64 20 6c 6f 6e ", (unsigned lon
2020: 67 20 6c 6f 6e 67 29 20 66 73 75 69 64 29 3b 0a g long) fsuid);.
2030: 0a 09 09 72 65 74 75 72 6e 28 4e 55 4c 4c 29 3b ...return(NULL);
2040: 0a 09 7d 0a 0a 09 69 66 20 28 72 65 73 75 6c 74 ..}...if (result
2050: 20 3d 3d 20 4e 55 4c 4c 29 20 7b 0a 09 09 41 50 == NULL) {...AP
2060: 50 46 53 5f 44 45 42 55 47 28 22 67 65 74 70 77 PFS_DEBUG("getpw
2070: 75 69 64 5f 72 28 25 6c 6c 75 2c 20 2e 2e 2e 29 uid_r(%llu, ...)
2080: 20 72 65 74 75 72 6e 65 64 20 4e 55 4c 4c 20 72 returned NULL r
2090: 65 73 75 6c 74 22 2c 20 28 75 6e 73 69 67 6e 65 esult", (unsigne
20a0: 64 20 6c 6f 6e 67 20 6c 6f 6e 67 29 20 66 73 75 d long long) fsu
20b0: 69 64 29 3b 0a 0a 09 09 72 65 74 75 72 6e 28 4e id);....return(N
20c0: 55 4c 4c 29 3b 0a 09 7d 0a 0a 09 69 66 20 28 72 ULL);..}...if (r
20d0: 65 73 75 6c 74 2d 3e 70 77 5f 64 69 72 20 3d 3d esult->pw_dir ==
20e0: 20 4e 55 4c 4c 29 20 7b 0a 09 09 41 50 50 46 53 NULL) {...APPFS
20f0: 5f 44 45 42 55 47 28 22 67 65 74 70 77 75 69 64 _DEBUG("getpwuid
2100: 5f 72 28 25 6c 6c 75 2c 20 2e 2e 2e 29 20 72 65 _r(%llu, ...) re
2110: 74 75 72 6e 65 64 20 4e 55 4c 4c 20 68 6f 6d 65 turned NULL home
2120: 20 64 69 72 65 63 74 6f 72 79 22 2c 20 28 75 6e directory", (un
2130: 73 69 67 6e 65 64 20 6c 6f 6e 67 20 6c 6f 6e 67 signed long long
2140: 29 20 66 73 75 69 64 29 3b 0a 0a 09 09 72 65 74 ) fsuid);....ret
2150: 75 72 6e 28 4e 55 4c 4c 29 3b 0a 09 7d 0a 0a 09 urn(NULL);..}...
2160: 73 74 61 74 5f 72 65 74 20 3d 20 73 74 61 74 28 stat_ret = stat(
2170: 72 65 73 75 6c 74 2d 3e 70 77 5f 64 69 72 2c 20 result->pw_dir,
2180: 26 73 74 62 75 66 29 3b 0a 09 69 66 20 28 73 74 &stbuf);..if (st
2190: 61 74 5f 72 65 74 20 21 3d 20 30 29 20 7b 0a 09 at_ret != 0) {..
21a0: 09 41 50 50 46 53 5f 44 45 42 55 47 28 22 73 74 .APPFS_DEBUG("st
21b0: 61 74 28 25 73 29 20 72 65 74 75 72 6e 65 64 20 at(%s) returned
21c0: 69 6e 20 66 61 69 6c 75 72 65 22 2c 20 72 65 73 in failure", res
21d0: 75 6c 74 2d 3e 70 77 5f 64 69 72 29 3b 0a 0a 09 ult->pw_dir);...
21e0: 09 72 65 74 75 72 6e 28 4e 55 4c 4c 29 3b 0a 09 .return(NULL);..
21f0: 7d 0a 0a 09 69 66 20 28 73 74 62 75 66 2e 73 74 }...if (stbuf.st
2200: 5f 75 69 64 20 21 3d 20 66 73 75 69 64 29 20 7b _uid != fsuid) {
2210: 0a 09 09 41 50 50 46 53 5f 44 45 42 55 47 28 22 ...APPFS_DEBUG("
2220: 55 49 44 20 6d 69 73 2d 6d 61 74 63 68 20 6f 6e UID mis-match on
2230: 20 75 73 65 72 20 25 6c 6c 75 27 73 20 68 6f 6d user %llu's hom
2240: 65 20 64 69 72 65 63 74 6f 72 79 20 28 25 73 29 e directory (%s)
2250: 2e 20 20 49 74 27 73 20 6f 77 6e 65 64 20 62 79 . It's owned by
2260: 20 25 6c 6c 75 2e 22 2c 0a 09 09 20 20 20 20 28 %llu.",... (
2270: 75 6e 73 69 67 6e 65 64 20 6c 6f 6e 67 20 6c 6f unsigned long lo
2280: 6e 67 29 20 66 73 75 69 64 2c 0a 09 09 20 20 20 ng) fsuid,...
2290: 20 72 65 73 75 6c 74 2d 3e 70 77 5f 64 69 72 2c result->pw_dir,
22a0: 0a 09 09 20 20 20 20 28 75 6e 73 69 67 6e 65 64 ... (unsigned
22b0: 20 6c 6f 6e 67 20 6c 6f 6e 67 29 20 73 74 62 75 long long) stbu
22c0: 66 2e 73 74 5f 75 69 64 0a 09 09 29 3b 0a 0a 09 f.st_uid...);...
22d0: 09 72 65 74 75 72 6e 28 4e 55 4c 4c 29 3b 0a 09 .return(NULL);..
22e0: 7d 0a 0a 09 72 65 74 76 61 6c 20 3d 20 73 74 72 }...retval = str
22f0: 64 75 70 28 72 65 73 75 6c 74 2d 3e 70 77 5f 64 dup(result->pw_d
2300: 69 72 29 3b 0a 0a 09 72 65 74 75 72 6e 28 72 65 ir);...return(re
2310: 74 76 61 6c 29 3b 0a 7d 0a 0a 2f 2a 0a 20 2a 20 tval);.}../*. *
2320: 54 63 6c 20 69 6e 74 65 72 66 61 63 65 20 74 6f Tcl interface to
2330: 20 67 65 74 20 74 68 65 20 68 6f 6d 65 20 64 69 get the home di
2340: 72 65 63 74 6f 72 79 20 66 6f 72 20 74 68 65 20 rectory for the
2350: 75 73 65 72 20 6d 61 6b 69 6e 67 20 74 68 65 20 user making the
2360: 22 63 75 72 72 65 6e 74 22 0a 20 2a 20 46 55 53 "current". * FUS
2370: 45 20 49 2f 4f 20 72 65 71 75 65 73 74 0a 20 2a E I/O request. *
2380: 2f 0a 73 74 61 74 69 63 20 69 6e 74 20 74 63 6c /.static int tcl
2390: 5f 61 70 70 66 73 5f 67 65 74 5f 68 6f 6d 65 64 _appfs_get_homed
23a0: 69 72 28 43 6c 69 65 6e 74 44 61 74 61 20 63 64 ir(ClientData cd
23b0: 2c 20 54 63 6c 5f 49 6e 74 65 72 70 20 2a 69 6e , Tcl_Interp *in
23c0: 74 65 72 70 2c 20 69 6e 74 20 6f 62 6a 63 2c 20 terp, int objc,
23d0: 54 63 6c 5f 4f 62 6a 20 2a 43 4f 4e 53 54 20 6f Tcl_Obj *CONST o
23e0: 62 6a 76 5b 5d 29 20 7b 0a 09 63 68 61 72 20 2a bjv[]) {..char *
23f0: 68 6f 6d 65 64 69 72 3b 0a 0a 20 20 20 20 20 20 homedir;..
2400: 20 20 69 66 20 28 6f 62 6a 63 20 21 3d 20 31 29 if (objc != 1)
2410: 20 7b 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 {.
2420: 20 20 20 54 63 6c 5f 57 72 6f 6e 67 4e 75 6d 41 Tcl_WrongNumA
2430: 72 67 73 28 69 6e 74 65 72 70 2c 20 31 2c 20 6f rgs(interp, 1, o
2440: 62 6a 76 2c 20 4e 55 4c 4c 29 3b 0a 20 20 20 20 bjv, NULL);.
2450: 20 20 20 20 20 20 20 20 20 20 20 20 72 65 74 75 retu
2460: 72 6e 28 54 43 4c 5f 45 52 52 4f 52 29 3b 0a 20 rn(TCL_ERROR);.
2470: 20 20 20 20 20 20 20 7d 0a 0a 09 68 6f 6d 65 64 }...homed
2480: 69 72 20 3d 20 61 70 70 66 73 5f 67 65 74 5f 68 ir = appfs_get_h
2490: 6f 6d 65 64 69 72 28 61 70 70 66 73 5f 67 65 74 omedir(appfs_get
24a0: 5f 66 73 75 69 64 28 29 29 3b 0a 0a 09 69 66 20 _fsuid());...if
24b0: 28 68 6f 6d 65 64 69 72 20 3d 3d 20 4e 55 4c 4c (homedir == NULL
24c0: 29 20 7b 0a 09 09 72 65 74 75 72 6e 28 54 43 4c ) {...return(TCL
24d0: 5f 45 52 52 4f 52 29 3b 0a 09 7d 0a 0a 20 20 20 _ERROR);..}..
24e0: 20 20 20 20 20 54 63 6c 5f 53 65 74 4f 62 6a 52 Tcl_SetObjR
24f0: 65 73 75 6c 74 28 69 6e 74 65 72 70 2c 20 54 63 esult(interp, Tc
2500: 6c 5f 4e 65 77 53 74 72 69 6e 67 4f 62 6a 28 68 l_NewStringObj(h
2510: 6f 6d 65 64 69 72 2c 20 2d 31 29 29 3b 0a 0a 09 omedir, -1));...
2520: 66 72 65 65 28 68 6f 6d 65 64 69 72 29 3b 0a 0a free(homedir);..
2530: 20 20 20 20 20 20 20 20 72 65 74 75 72 6e 28 54 return(T
2540: 43 4c 5f 4f 4b 29 3b 0a 7d 0a 0a 2f 2a 0a 20 2a CL_OK);.}../*. *
2550: 20 47 65 6e 65 72 61 74 65 20 61 6e 20 69 6e 6f Generate an ino
2560: 64 65 20 66 6f 72 20 61 20 67 69 76 65 6e 20 70 de for a given p
2570: 61 74 68 2e 20 20 54 68 65 20 69 6e 6f 64 65 20 ath. The inode
2580: 73 68 6f 75 6c 64 20 62 65 20 63 6f 6d 70 75 74 should be comput
2590: 65 64 20 69 6e 20 73 75 63 68 0a 20 2a 20 61 20 ed in such. * a
25a0: 77 61 79 20 74 68 61 74 20 69 74 20 69 73 20 75 way that it is u
25b0: 6e 6c 69 6b 65 6c 79 20 74 6f 20 62 65 20 64 75 nlikely to be du
25c0: 70 6c 69 63 61 74 65 64 20 61 6e 64 20 72 65 6d plicated and rem
25d0: 61 69 6e 73 20 74 68 65 20 73 61 6d 65 20 66 6f ains the same fo
25e0: 72 20 61 20 67 69 76 65 6e 0a 20 2a 20 66 69 6c r a given. * fil
25f0: 65 0a 20 2a 2f 0a 73 74 61 74 69 63 20 6c 6f 6e e. */.static lon
2600: 67 20 6c 6f 6e 67 20 61 70 70 66 73 5f 67 65 74 g long appfs_get
2610: 5f 70 61 74 68 5f 69 6e 6f 64 65 28 63 6f 6e 73 _path_inode(cons
2620: 74 20 63 68 61 72 20 2a 70 61 74 68 29 20 7b 0a t char *path) {.
2630: 09 6c 6f 6e 67 20 6c 6f 6e 67 20 72 65 74 76 61 .long long retva
2640: 6c 3b 0a 09 63 6f 6e 73 74 20 63 68 61 72 20 2a l;..const char *
2650: 70 3b 0a 0a 09 72 65 74 76 61 6c 20 3d 20 31 30 p;...retval = 10
2660: 3b 0a 0a 09 66 6f 72 20 28 70 20 3d 20 70 61 74 ;...for (p = pat
2670: 68 3b 20 2a 70 3b 20 70 2b 2b 29 20 7b 0a 09 09 h; *p; p++) {...
2680: 72 65 74 76 61 6c 20 25 3d 20 34 32 39 30 39 36 retval %= 429096
2690: 30 32 39 30 55 4c 4c 3b 0a 09 09 72 65 74 76 61 0290ULL;...retva
26a0: 6c 20 2b 3d 20 2a 70 3b 0a 09 09 72 65 74 76 61 l += *p;...retva
26b0: 6c 20 3c 3c 3d 20 37 3b 0a 09 7d 0a 0a 09 72 65 l <<= 7;..}...re
26c0: 74 76 61 6c 20 2b 3d 20 31 30 3b 0a 09 72 65 74 tval += 10;..ret
26d0: 76 61 6c 20 25 3d 20 34 32 39 34 39 36 37 32 39 val %= 429496729
26e0: 36 55 4c 4c 3b 0a 0a 09 72 65 74 75 72 6e 28 72 6ULL;...return(r
26f0: 65 74 76 61 6c 29 3b 0a 7d 0a 0a 2f 2a 20 47 65 etval);.}../* Ge
2700: 74 20 69 6e 66 6f 72 6d 61 74 69 6f 6e 20 61 62 t information ab
2710: 6f 75 74 20 61 20 70 61 74 68 2c 20 61 6e 64 20 out a path, and
2720: 6f 70 74 69 6f 6e 61 6c 6c 79 20 6c 69 73 74 20 optionally list
2730: 63 68 69 6c 64 72 65 6e 20 2a 2f 0a 73 74 61 74 children */.stat
2740: 69 63 20 69 6e 74 20 61 70 70 66 73 5f 67 65 74 ic int appfs_get
2750: 5f 70 61 74 68 5f 69 6e 66 6f 28 63 6f 6e 73 74 _path_info(const
2760: 20 63 68 61 72 20 2a 5f 70 61 74 68 2c 20 73 74 char *_path, st
2770: 72 75 63 74 20 61 70 70 66 73 5f 70 61 74 68 69 ruct appfs_pathi
2780: 6e 66 6f 20 2a 70 61 74 68 69 6e 66 6f 2c 20 73 nfo *pathinfo, s
2790: 74 72 75 63 74 20 61 70 70 66 73 5f 63 68 69 6c truct appfs_chil
27a0: 64 72 65 6e 20 2a 2a 63 68 69 6c 64 72 65 6e 29 dren **children)
27b0: 20 7b 0a 7d 0a 0a 73 74 61 74 69 63 20 69 6e 74 {.}..static int
27c0: 20 61 70 70 66 73 5f 66 75 73 65 5f 72 65 61 64 appfs_fuse_read
27d0: 6c 69 6e 6b 28 63 6f 6e 73 74 20 63 68 61 72 20 link(const char
27e0: 2a 70 61 74 68 2c 20 63 68 61 72 20 2a 62 75 66 *path, char *buf
27f0: 2c 20 73 69 7a 65 5f 74 20 73 69 7a 65 29 20 7b , size_t size) {
2800: 0a 09 73 74 72 75 63 74 20 61 70 70 66 73 5f 70 ..struct appfs_p
2810: 61 74 68 69 6e 66 6f 20 70 61 74 68 69 6e 66 6f athinfo pathinfo
2820: 3b 0a 09 69 6e 74 20 72 65 73 20 3d 20 30 3b 0a ;..int res = 0;.
2830: 0a 09 41 50 50 46 53 5f 44 45 42 55 47 28 22 45 ..APPFS_DEBUG("E
2840: 6e 74 65 72 20 28 70 61 74 68 20 3d 20 25 73 2c nter (path = %s,
2850: 20 2e 2e 2e 29 22 2c 20 70 61 74 68 29 3b 0a 0a ...)", path);..
2860: 09 70 61 74 68 69 6e 66 6f 2e 74 79 70 65 20 3d .pathinfo.type =
2870: 20 41 50 50 46 53 5f 50 41 54 48 54 59 50 45 5f APPFS_PATHTYPE_
2880: 49 4e 56 41 4c 49 44 3b 0a 0a 09 72 65 73 20 3d INVALID;...res =
2890: 20 61 70 70 66 73 5f 67 65 74 5f 70 61 74 68 5f appfs_get_path_
28a0: 69 6e 66 6f 28 70 61 74 68 2c 20 26 70 61 74 68 info(path, &path
28b0: 69 6e 66 6f 2c 20 4e 55 4c 4c 29 3b 0a 09 69 66 info, NULL);..if
28c0: 20 28 72 65 73 20 21 3d 20 30 29 20 7b 0a 09 09 (res != 0) {...
28d0: 72 65 74 75 72 6e 28 72 65 73 29 3b 0a 09 7d 0a return(res);..}.
28e0: 0a 09 69 66 20 28 70 61 74 68 69 6e 66 6f 2e 74 ..if (pathinfo.t
28f0: 79 70 65 20 21 3d 20 41 50 50 46 53 5f 50 41 54 ype != APPFS_PAT
2900: 48 54 59 50 45 5f 53 59 4d 4c 49 4e 4b 29 20 7b HTYPE_SYMLINK) {
2910: 0a 09 09 72 65 74 75 72 6e 28 2d 45 49 4e 56 41 ...return(-EINVA
2920: 4c 29 3b 0a 09 7d 0a 0a 09 69 66 20 28 28 73 74 L);..}...if ((st
2930: 72 6c 65 6e 28 70 61 74 68 69 6e 66 6f 2e 74 79 rlen(pathinfo.ty
2940: 70 65 69 6e 66 6f 2e 73 79 6d 6c 69 6e 6b 2e 73 peinfo.symlink.s
2950: 6f 75 72 63 65 29 20 2b 20 31 29 20 3e 20 73 69 ource) + 1) > si
2960: 7a 65 29 20 7b 0a 09 09 72 65 74 75 72 6e 28 2d ze) {...return(-
2970: 45 4e 41 4d 45 54 4f 4f 4c 4f 4e 47 29 3b 0a 09 ENAMETOOLONG);..
2980: 7d 0a 0a 09 6d 65 6d 63 70 79 28 62 75 66 2c 20 }...memcpy(buf,
2990: 70 61 74 68 69 6e 66 6f 2e 74 79 70 65 69 6e 66 pathinfo.typeinf
29a0: 6f 2e 73 79 6d 6c 69 6e 6b 2e 73 6f 75 72 63 65 o.symlink.source
29b0: 2c 20 73 74 72 6c 65 6e 28 70 61 74 68 69 6e 66 , strlen(pathinf
29c0: 6f 2e 74 79 70 65 69 6e 66 6f 2e 73 79 6d 6c 69 o.typeinfo.symli
29d0: 6e 6b 2e 73 6f 75 72 63 65 29 20 2b 20 31 29 3b nk.source) + 1);
29e0: 0a 0a 09 72 65 74 75 72 6e 28 30 29 3b 0a 7d 0a ...return(0);.}.
29f0: 0a 73 74 61 74 69 63 20 69 6e 74 20 61 70 70 66 .static int appf
2a00: 73 5f 66 75 73 65 5f 67 65 74 61 74 74 72 28 63 s_fuse_getattr(c
2a10: 6f 6e 73 74 20 63 68 61 72 20 2a 70 61 74 68 2c onst char *path,
2a20: 20 73 74 72 75 63 74 20 73 74 61 74 20 2a 73 74 struct stat *st
2a30: 62 75 66 29 20 7b 0a 09 73 74 72 75 63 74 20 61 buf) {..struct a
2a40: 70 70 66 73 5f 70 61 74 68 69 6e 66 6f 20 70 61 ppfs_pathinfo pa
2a50: 74 68 69 6e 66 6f 3b 0a 09 69 6e 74 20 72 65 73 thinfo;..int res
2a60: 20 3d 20 30 3b 0a 0a 09 41 50 50 46 53 5f 44 45 = 0;...APPFS_DE
2a70: 42 55 47 28 22 45 6e 74 65 72 20 28 70 61 74 68 BUG("Enter (path
2a80: 20 3d 20 25 73 2c 20 2e 2e 2e 29 22 2c 20 70 61 = %s, ...)", pa
2a90: 74 68 29 3b 0a 0a 09 70 61 74 68 69 6e 66 6f 2e th);...pathinfo.
2aa0: 74 79 70 65 20 3d 20 41 50 50 46 53 5f 50 41 54 type = APPFS_PAT
2ab0: 48 54 59 50 45 5f 49 4e 56 41 4c 49 44 3b 0a 0a HTYPE_INVALID;..
2ac0: 09 72 65 73 20 3d 20 61 70 70 66 73 5f 67 65 74 .res = appfs_get
2ad0: 5f 70 61 74 68 5f 69 6e 66 6f 28 70 61 74 68 2c _path_info(path,
2ae0: 20 26 70 61 74 68 69 6e 66 6f 2c 20 4e 55 4c 4c &pathinfo, NULL
2af0: 29 3b 0a 09 69 66 20 28 72 65 73 20 21 3d 20 30 );..if (res != 0
2b00: 29 20 7b 0a 09 09 72 65 74 75 72 6e 28 72 65 73 ) {...return(res
2b10: 29 3b 0a 09 7d 0a 0a 09 6d 65 6d 73 65 74 28 73 );..}...memset(s
2b20: 74 62 75 66 2c 20 30 2c 20 73 69 7a 65 6f 66 28 tbuf, 0, sizeof(
2b30: 73 74 72 75 63 74 20 73 74 61 74 29 29 3b 0a 0a struct stat));..
2b40: 09 73 74 62 75 66 2d 3e 73 74 5f 6d 74 69 6d 65 .stbuf->st_mtime
2b50: 20 3d 20 70 61 74 68 69 6e 66 6f 2e 74 69 6d 65 = pathinfo.time
2b60: 3b 0a 09 73 74 62 75 66 2d 3e 73 74 5f 63 74 69 ;..stbuf->st_cti
2b70: 6d 65 20 3d 20 70 61 74 68 69 6e 66 6f 2e 74 69 me = pathinfo.ti
2b80: 6d 65 3b 0a 09 73 74 62 75 66 2d 3e 73 74 5f 61 me;..stbuf->st_a
2b90: 74 69 6d 65 20 3d 20 70 61 74 68 69 6e 66 6f 2e time = pathinfo.
2ba0: 74 69 6d 65 3b 0a 09 73 74 62 75 66 2d 3e 73 74 time;..stbuf->st
2bb0: 5f 69 6e 6f 20 20 20 3d 20 70 61 74 68 69 6e 66 _ino = pathinf
2bc0: 6f 2e 69 6e 6f 64 65 3b 0a 09 73 74 62 75 66 2d o.inode;..stbuf-
2bd0: 3e 73 74 5f 6d 6f 64 65 20 20 3d 20 30 3b 0a 0a >st_mode = 0;..
2be0: 09 73 77 69 74 63 68 20 28 70 61 74 68 69 6e 66 .switch (pathinf
2bf0: 6f 2e 74 79 70 65 29 20 7b 0a 09 09 63 61 73 65 o.type) {...case
2c00: 20 41 50 50 46 53 5f 50 41 54 48 54 59 50 45 5f APPFS_PATHTYPE_
2c10: 44 49 52 45 43 54 4f 52 59 3a 0a 09 09 09 73 74 DIRECTORY:....st
2c20: 62 75 66 2d 3e 73 74 5f 6d 6f 64 65 20 3d 20 53 buf->st_mode = S
2c30: 5f 49 46 44 49 52 20 7c 20 30 35 35 35 3b 0a 09 _IFDIR | 0555;..
2c40: 09 09 73 74 62 75 66 2d 3e 73 74 5f 6e 6c 69 6e ..stbuf->st_nlin
2c50: 6b 20 3d 20 32 20 2b 20 70 61 74 68 69 6e 66 6f k = 2 + pathinfo
2c60: 2e 74 79 70 65 69 6e 66 6f 2e 64 69 72 2e 63 68 .typeinfo.dir.ch
2c70: 69 6c 64 63 6f 75 6e 74 3b 0a 09 09 09 62 72 65 ildcount;....bre
2c80: 61 6b 3b 0a 09 09 63 61 73 65 20 41 50 50 46 53 ak;...case APPFS
2c90: 5f 50 41 54 48 54 59 50 45 5f 46 49 4c 45 3a 0a _PATHTYPE_FILE:.
2ca0: 09 09 09 69 66 20 28 70 61 74 68 69 6e 66 6f 2e ...if (pathinfo.
2cb0: 74 79 70 65 69 6e 66 6f 2e 66 69 6c 65 2e 65 78 typeinfo.file.ex
2cc0: 65 63 75 74 61 62 6c 65 29 20 7b 0a 09 09 09 09 ecutable) {.....
2cd0: 73 74 62 75 66 2d 3e 73 74 5f 6d 6f 64 65 20 3d stbuf->st_mode =
2ce0: 20 53 5f 49 46 52 45 47 20 7c 20 30 35 35 35 3b S_IFREG | 0555;
2cf0: 0a 09 09 09 7d 20 65 6c 73 65 20 7b 0a 09 09 09 ....} else {....
2d00: 09 73 74 62 75 66 2d 3e 73 74 5f 6d 6f 64 65 20 .stbuf->st_mode
2d10: 3d 20 53 5f 49 46 52 45 47 20 7c 20 30 34 34 34 = S_IFREG | 0444
2d20: 3b 0a 09 09 09 7d 0a 0a 09 09 09 73 74 62 75 66 ;....}.....stbuf
2d30: 2d 3e 73 74 5f 6e 6c 69 6e 6b 20 3d 20 31 3b 0a ->st_nlink = 1;.
2d40: 09 09 09 73 74 62 75 66 2d 3e 73 74 5f 73 69 7a ...stbuf->st_siz
2d50: 65 20 3d 20 70 61 74 68 69 6e 66 6f 2e 74 79 70 e = pathinfo.typ
2d60: 65 69 6e 66 6f 2e 66 69 6c 65 2e 73 69 7a 65 3b einfo.file.size;
2d70: 0a 09 09 09 62 72 65 61 6b 3b 0a 09 09 63 61 73 ....break;...cas
2d80: 65 20 41 50 50 46 53 5f 50 41 54 48 54 59 50 45 e APPFS_PATHTYPE
2d90: 5f 53 59 4d 4c 49 4e 4b 3a 0a 09 09 09 73 74 62 _SYMLINK:....stb
2da0: 75 66 2d 3e 73 74 5f 6d 6f 64 65 20 3d 20 53 5f uf->st_mode = S_
2db0: 49 46 4c 4e 4b 20 7c 20 30 35 35 35 3b 0a 09 09 IFLNK | 0555;...
2dc0: 09 73 74 62 75 66 2d 3e 73 74 5f 6e 6c 69 6e 6b .stbuf->st_nlink
2dd0: 20 3d 20 31 3b 0a 09 09 09 73 74 62 75 66 2d 3e = 1;....stbuf->
2de0: 73 74 5f 73 69 7a 65 20 3d 20 70 61 74 68 69 6e st_size = pathin
2df0: 66 6f 2e 74 79 70 65 69 6e 66 6f 2e 73 79 6d 6c fo.typeinfo.syml
2e00: 69 6e 6b 2e 73 69 7a 65 3b 0a 09 09 09 62 72 65 ink.size;....bre
2e10: 61 6b 3b 0a 09 09 63 61 73 65 20 41 50 50 46 53 ak;...case APPFS
2e20: 5f 50 41 54 48 54 59 50 45 5f 49 4e 56 41 4c 49 _PATHTYPE_INVALI
2e30: 44 3a 0a 09 09 09 72 65 73 20 3d 20 2d 45 49 4f D:....res = -EIO
2e40: 3b 0a 0a 09 09 09 62 72 65 61 6b 3b 0a 09 7d 0a ;.....break;..}.
2e50: 0a 09 69 66 20 28 70 61 74 68 69 6e 66 6f 2e 70 ..if (pathinfo.p
2e60: 61 63 6b 61 67 65 64 29 20 7b 0a 09 09 69 66 20 ackaged) {...if
2e70: 28 30 29 20 7b 0a 09 09 09 73 74 62 75 66 2d 3e (0) {....stbuf->
2e80: 73 74 5f 6d 6f 64 65 20 7c 3d 20 30 32 32 32 3b st_mode |= 0222;
2e90: 0a 09 09 7d 0a 09 7d 0a 0a 09 72 65 74 75 72 6e ...}..}...return
2ea0: 20 72 65 73 3b 0a 7d 0a 0a 73 74 61 74 69 63 20 res;.}..static
2eb0: 69 6e 74 20 61 70 70 66 73 5f 66 75 73 65 5f 72 int appfs_fuse_r
2ec0: 65 61 64 64 69 72 28 63 6f 6e 73 74 20 63 68 61 eaddir(const cha
2ed0: 72 20 2a 70 61 74 68 2c 20 76 6f 69 64 20 2a 62 r *path, void *b
2ee0: 75 66 2c 20 66 75 73 65 5f 66 69 6c 6c 5f 64 69 uf, fuse_fill_di
2ef0: 72 5f 74 20 66 69 6c 6c 65 72 2c 20 6f 66 66 5f r_t filler, off_
2f00: 74 20 6f 66 66 73 65 74 2c 20 73 74 72 75 63 74 t offset, struct
2f10: 20 66 75 73 65 5f 66 69 6c 65 5f 69 6e 66 6f 20 fuse_file_info
2f20: 2a 66 69 29 20 7b 0a 09 73 74 72 75 63 74 20 61 *fi) {..struct a
2f30: 70 70 66 73 5f 70 61 74 68 69 6e 66 6f 20 70 61 ppfs_pathinfo pa
2f40: 74 68 69 6e 66 6f 3b 0a 09 73 74 72 75 63 74 20 thinfo;..struct
2f50: 61 70 70 66 73 5f 63 68 69 6c 64 72 65 6e 20 2a appfs_children *
2f60: 63 68 69 6c 64 72 65 6e 2c 20 2a 63 68 69 6c 64 children, *child
2f70: 3b 0a 09 69 6e 74 20 72 65 74 76 61 6c 3b 0a 0a ;..int retval;..
2f80: 09 41 50 50 46 53 5f 44 45 42 55 47 28 22 45 6e .APPFS_DEBUG("En
2f90: 74 65 72 20 28 70 61 74 68 20 3d 20 25 73 2c 20 ter (path = %s,
2fa0: 2e 2e 2e 29 22 2c 20 70 61 74 68 29 3b 0a 0a 09 ...)", path);...
2fb0: 72 65 74 76 61 6c 20 3d 20 61 70 70 66 73 5f 67 retval = appfs_g
2fc0: 65 74 5f 70 61 74 68 5f 69 6e 66 6f 28 70 61 74 et_path_info(pat
2fd0: 68 2c 20 26 70 61 74 68 69 6e 66 6f 2c 20 26 63 h, &pathinfo, &c
2fe0: 68 69 6c 64 72 65 6e 29 3b 0a 09 69 66 20 28 72 hildren);..if (r
2ff0: 65 74 76 61 6c 20 21 3d 20 30 29 20 7b 0a 09 09 etval != 0) {...
3000: 72 65 74 75 72 6e 28 72 65 74 76 61 6c 29 3b 0a return(retval);.
3010: 09 7d 0a 0a 09 66 69 6c 6c 65 72 28 62 75 66 2c .}...filler(buf,
3020: 20 22 2e 22 2c 20 4e 55 4c 4c 2c 20 30 29 3b 0a ".", NULL, 0);.
3030: 09 66 69 6c 6c 65 72 28 62 75 66 2c 20 22 2e 2e .filler(buf, "..
3040: 22 2c 20 4e 55 4c 4c 2c 20 30 29 3b 0a 0a 09 66 ", NULL, 0);...f
3050: 6f 72 20 28 63 68 69 6c 64 20 3d 20 63 68 69 6c or (child = chil
3060: 64 72 65 6e 3b 20 63 68 69 6c 64 3b 20 63 68 69 dren; child; chi
3070: 6c 64 20 3d 20 63 68 69 6c 64 2d 3e 5f 6e 65 78 ld = child->_nex
3080: 74 29 20 7b 0a 09 09 66 69 6c 6c 65 72 28 62 75 t) {...filler(bu
3090: 66 2c 20 63 68 69 6c 64 2d 3e 6e 61 6d 65 2c 20 f, child->name,
30a0: 4e 55 4c 4c 2c 20 30 29 3b 0a 09 7d 0a 0a 2f 2f NULL, 0);..}..//
30b0: 09 61 70 70 66 73 5f 66 72 65 65 5f 6c 69 73 74 .appfs_free_list
30c0: 5f 63 68 69 6c 64 72 65 6e 28 63 68 69 6c 64 72 _children(childr
30d0: 65 6e 29 3b 0a 0a 09 72 65 74 75 72 6e 28 30 29 en);...return(0)
30e0: 3b 0a 7d 0a 0a 73 74 61 74 69 63 20 69 6e 74 20 ;.}..static int
30f0: 61 70 70 66 73 5f 66 75 73 65 5f 6f 70 65 6e 28 appfs_fuse_open(
3100: 63 6f 6e 73 74 20 63 68 61 72 20 2a 70 61 74 68 const char *path
3110: 2c 20 73 74 72 75 63 74 20 66 75 73 65 5f 66 69 , struct fuse_fi
3120: 6c 65 5f 69 6e 66 6f 20 2a 66 69 29 20 7b 0a 09 le_info *fi) {..
3130: 73 74 72 75 63 74 20 61 70 70 66 73 5f 70 61 74 struct appfs_pat
3140: 68 69 6e 66 6f 20 70 61 74 68 69 6e 66 6f 3b 0a hinfo pathinfo;.
3150: 09 63 6f 6e 73 74 20 63 68 61 72 20 2a 72 65 61 .const char *rea
3160: 6c 5f 70 61 74 68 3b 0a 09 69 6e 74 20 66 68 3b l_path;..int fh;
3170: 0a 09 69 6e 74 20 67 70 69 5f 72 65 74 3b 0a 0a ..int gpi_ret;..
3180: 09 41 50 50 46 53 5f 44 45 42 55 47 28 22 45 6e .APPFS_DEBUG("En
3190: 74 65 72 20 28 70 61 74 68 20 3d 20 25 73 2c 20 ter (path = %s,
31a0: 2e 2e 2e 29 22 2c 20 70 61 74 68 29 3b 0a 0a 23 ...)", path);..#
31b0: 69 66 20 30 0a 0a 09 69 66 20 28 28 66 69 2d 3e if 0...if ((fi->
31c0: 66 6c 61 67 73 20 26 20 33 29 20 21 3d 20 4f 5f flags & 3) != O_
31d0: 52 44 4f 4e 4c 59 29 20 7b 0a 20 20 20 20 20 20 RDONLY) {.
31e0: 20 20 20 20 20 20 20 20 20 20 72 65 74 75 72 6e return
31f0: 28 2d 45 41 43 43 45 53 29 3b 0a 09 7d 0a 0a 09 (-EACCES);..}...
3200: 67 70 69 5f 72 65 74 20 3d 20 61 70 70 66 73 5f gpi_ret = appfs_
3210: 67 65 74 5f 70 61 74 68 5f 69 6e 66 6f 28 70 61 get_path_info(pa
3220: 74 68 2c 20 26 70 61 74 68 69 6e 66 6f 2c 20 4e th, &pathinfo, N
3230: 55 4c 4c 29 3b 0a 09 69 66 20 28 67 70 69 5f 72 ULL);..if (gpi_r
3240: 65 74 20 21 3d 20 30 29 20 7b 0a 09 09 72 65 74 et != 0) {...ret
3250: 75 72 6e 28 67 70 69 5f 72 65 74 29 3b 0a 09 7d urn(gpi_ret);..}
3260: 0a 0a 09 69 66 20 28 70 61 74 68 69 6e 66 6f 2e ...if (pathinfo.
3270: 74 79 70 65 20 3d 3d 20 41 50 50 46 53 5f 50 41 type == APPFS_PA
3280: 54 48 54 59 50 45 5f 44 49 52 45 43 54 4f 52 59 THTYPE_DIRECTORY
3290: 29 20 7b 0a 09 09 72 65 74 75 72 6e 28 2d 45 49 ) {...return(-EI
32a0: 53 44 49 52 29 3b 0a 09 7d 0a 0a 09 72 65 61 6c SDIR);..}...real
32b0: 5f 70 61 74 68 20 3d 20 61 70 70 66 73 5f 67 65 _path = appfs_ge
32c0: 74 66 69 6c 65 28 70 61 74 68 69 6e 66 6f 2e 68 tfile(pathinfo.h
32d0: 6f 73 74 6e 61 6d 65 2c 20 70 61 74 68 69 6e 66 ostname, pathinf
32e0: 6f 2e 74 79 70 65 69 6e 66 6f 2e 66 69 6c 65 2e o.typeinfo.file.
32f0: 73 68 61 31 29 3b 0a 09 69 66 20 28 72 65 61 6c sha1);..if (real
3300: 5f 70 61 74 68 20 3d 3d 20 4e 55 4c 4c 29 20 7b _path == NULL) {
3310: 0a 09 09 72 65 74 75 72 6e 28 2d 45 49 4f 29 3b ...return(-EIO);
3320: 0a 09 7d 0a 0a 09 66 68 20 3d 20 6f 70 65 6e 28 ..}...fh = open(
3330: 72 65 61 6c 5f 70 61 74 68 2c 20 4f 5f 52 44 4f real_path, O_RDO
3340: 4e 4c 59 29 3b 0a 09 66 72 65 65 28 28 76 6f 69 NLY);..free((voi
3350: 64 20 2a 29 20 72 65 61 6c 5f 70 61 74 68 29 3b d *) real_path);
3360: 0a 09 69 66 20 28 66 68 20 3c 20 30 29 20 7b 0a ..if (fh < 0) {.
3370: 09 09 72 65 74 75 72 6e 28 2d 45 49 4f 29 3b 0a ..return(-EIO);.
3380: 09 7d 0a 0a 09 66 69 2d 3e 66 68 20 3d 20 66 68 .}...fi->fh = fh
3390: 3b 0a 23 65 6e 64 69 66 0a 0a 09 72 65 74 75 72 ;.#endif...retur
33a0: 6e 28 30 29 3b 0a 7d 0a 0a 73 74 61 74 69 63 20 n(0);.}..static
33b0: 69 6e 74 20 61 70 70 66 73 5f 66 75 73 65 5f 63 int appfs_fuse_c
33c0: 6c 6f 73 65 28 63 6f 6e 73 74 20 63 68 61 72 20 lose(const char
33d0: 2a 70 61 74 68 2c 20 73 74 72 75 63 74 20 66 75 *path, struct fu
33e0: 73 65 5f 66 69 6c 65 5f 69 6e 66 6f 20 2a 66 69 se_file_info *fi
33f0: 29 20 7b 0a 09 69 6e 74 20 63 6c 6f 73 65 5f 72 ) {..int close_r
3400: 65 74 3b 0a 0a 09 63 6c 6f 73 65 5f 72 65 74 20 et;...close_ret
3410: 3d 20 63 6c 6f 73 65 28 66 69 2d 3e 66 68 29 3b = close(fi->fh);
3420: 0a 09 69 66 20 28 63 6c 6f 73 65 5f 72 65 74 20 ..if (close_ret
3430: 21 3d 20 30 29 20 7b 0a 09 09 72 65 74 75 72 6e != 0) {...return
3440: 28 2d 45 49 4f 29 3b 0a 09 7d 0a 0a 09 72 65 74 (-EIO);..}...ret
3450: 75 72 6e 28 30 29 3b 0a 7d 0a 0a 73 74 61 74 69 urn(0);.}..stati
3460: 63 20 69 6e 74 20 61 70 70 66 73 5f 66 75 73 65 c int appfs_fuse
3470: 5f 72 65 61 64 28 63 6f 6e 73 74 20 63 68 61 72 _read(const char
3480: 20 2a 70 61 74 68 2c 20 63 68 61 72 20 2a 62 75 *path, char *bu
3490: 66 2c 20 73 69 7a 65 5f 74 20 73 69 7a 65 2c 20 f, size_t size,
34a0: 6f 66 66 5f 74 20 6f 66 66 73 65 74 2c 20 73 74 off_t offset, st
34b0: 72 75 63 74 20 66 75 73 65 5f 66 69 6c 65 5f 69 ruct fuse_file_i
34c0: 6e 66 6f 20 2a 66 69 29 20 7b 0a 09 6f 66 66 5f nfo *fi) {..off_
34d0: 74 20 6c 73 65 65 6b 5f 72 65 74 3b 0a 09 73 73 t lseek_ret;..ss
34e0: 69 7a 65 5f 74 20 72 65 61 64 5f 72 65 74 3b 0a ize_t read_ret;.
34f0: 0a 09 41 50 50 46 53 5f 44 45 42 55 47 28 22 45 ..APPFS_DEBUG("E
3500: 6e 74 65 72 20 28 70 61 74 68 20 3d 20 25 73 2c nter (path = %s,
3510: 20 2e 2e 2e 29 22 2c 20 70 61 74 68 29 3b 0a 0a ...)", path);..
3520: 09 6c 73 65 65 6b 5f 72 65 74 20 3d 20 6c 73 65 .lseek_ret = lse
3530: 65 6b 28 66 69 2d 3e 66 68 2c 20 6f 66 66 73 65 ek(fi->fh, offse
3540: 74 2c 20 53 45 45 4b 5f 53 45 54 29 3b 0a 09 69 t, SEEK_SET);..i
3550: 66 20 28 6c 73 65 65 6b 5f 72 65 74 20 21 3d 20 f (lseek_ret !=
3560: 6f 66 66 73 65 74 29 20 7b 0a 09 09 72 65 74 75 offset) {...retu
3570: 72 6e 28 2d 45 49 4f 29 3b 0a 09 7d 0a 0a 09 72 rn(-EIO);..}...r
3580: 65 61 64 5f 72 65 74 20 3d 20 72 65 61 64 28 66 ead_ret = read(f
3590: 69 2d 3e 66 68 2c 20 62 75 66 2c 20 73 69 7a 65 i->fh, buf, size
35a0: 29 3b 0a 0a 09 72 65 74 75 72 6e 28 72 65 61 64 );...return(read
35b0: 5f 72 65 74 29 3b 0a 7d 0a 0a 2f 2a 0a 20 2a 20 _ret);.}../*. *
35c0: 53 51 4c 69 74 65 33 20 6d 6f 64 65 3a 20 45 78 SQLite3 mode: Ex
35d0: 65 63 75 74 65 20 72 61 77 20 53 51 4c 20 61 6e ecute raw SQL an
35e0: 64 20 72 65 74 75 72 6e 20 73 75 63 63 65 73 73 d return success
35f0: 20 6f 72 20 66 61 69 6c 75 72 65 0a 20 2a 2f 0a or failure. */.
3600: 73 74 61 74 69 63 20 69 6e 74 20 61 70 70 66 73 static int appfs
3610: 5f 73 71 6c 69 74 65 33 28 63 6f 6e 73 74 20 63 _sqlite3(const c
3620: 68 61 72 20 2a 73 71 6c 29 20 7b 0a 09 54 63 6c har *sql) {..Tcl
3630: 5f 49 6e 74 65 72 70 20 2a 69 6e 74 65 72 70 3b _Interp *interp;
3640: 0a 09 63 6f 6e 73 74 20 63 68 61 72 20 2a 73 71 ..const char *sq
3650: 6c 5f 72 65 74 3b 0a 09 69 6e 74 20 74 63 6c 5f l_ret;..int tcl_
3660: 72 65 74 3b 0a 0a 09 69 6e 74 65 72 70 20 3d 20 ret;...interp =
3670: 61 70 70 66 73 5f 63 72 65 61 74 65 5f 54 63 6c appfs_create_Tcl
3680: 49 6e 74 65 72 70 28 29 3b 0a 09 69 66 20 28 69 Interp();..if (i
3690: 6e 74 65 72 70 20 3d 3d 20 4e 55 4c 4c 29 20 7b nterp == NULL) {
36a0: 0a 09 09 66 70 72 69 6e 74 66 28 73 74 64 65 72 ...fprintf(stder
36b0: 72 2c 20 22 55 6e 61 62 6c 65 20 74 6f 20 63 72 r, "Unable to cr
36c0: 65 61 74 65 20 61 20 54 63 6c 20 69 6e 74 65 72 eate a Tcl inter
36d0: 70 72 65 74 65 72 2e 20 20 41 62 6f 72 74 69 6e preter. Abortin
36e0: 67 2e 5c 6e 22 29 3b 0a 0a 09 09 72 65 74 75 72 g.\n");....retur
36f0: 6e 28 31 29 3b 0a 09 7d 0a 0a 09 74 63 6c 5f 72 n(1);..}...tcl_r
3700: 65 74 20 3d 20 61 70 70 66 73 5f 54 63 6c 5f 45 et = appfs_Tcl_E
3710: 76 61 6c 28 69 6e 74 65 72 70 2c 20 35 2c 20 22 val(interp, 5, "
3720: 3a 3a 61 70 70 66 73 3a 3a 64 62 22 2c 20 22 65 ::appfs::db", "e
3730: 76 61 6c 22 2c 20 73 71 6c 2c 20 22 72 6f 77 22 val", sql, "row"
3740: 2c 20 22 75 6e 73 65 74 20 2d 6e 6f 63 6f 6d 70 , "unset -nocomp
3750: 6c 61 69 6e 20 72 6f 77 28 2a 29 3b 20 70 61 72 lain row(*); par
3760: 72 61 79 20 72 6f 77 3b 20 70 75 74 73 20 5c 22 ray row; puts \"
3770: 2d 2d 2d 2d 5c 22 22 29 3b 0a 09 73 71 6c 5f 72 ----\"");..sql_r
3780: 65 74 20 3d 20 54 63 6c 5f 47 65 74 53 74 72 69 et = Tcl_GetStri
3790: 6e 67 52 65 73 75 6c 74 28 69 6e 74 65 72 70 29 ngResult(interp)
37a0: 3b 0a 0a 09 69 66 20 28 74 63 6c 5f 72 65 74 20 ;...if (tcl_ret
37b0: 21 3d 20 54 43 4c 5f 4f 4b 29 20 7b 0a 09 09 66 != TCL_OK) {...f
37c0: 70 72 69 6e 74 66 28 73 74 64 65 72 72 2c 20 22 printf(stderr, "
37d0: 5b 65 72 72 6f 72 5d 20 25 73 5c 6e 22 2c 20 73 [error] %s\n", s
37e0: 71 6c 5f 72 65 74 29 3b 0a 0a 09 09 72 65 74 75 ql_ret);....retu
37f0: 72 6e 28 31 29 3b 0a 09 7d 0a 0a 09 69 66 20 28 rn(1);..}...if (
3800: 73 71 6c 5f 72 65 74 20 26 26 20 73 71 6c 5f 72 sql_ret && sql_r
3810: 65 74 5b 30 5d 20 21 3d 20 27 5c 30 27 29 20 7b et[0] != '\0') {
3820: 0a 09 09 70 72 69 6e 74 66 28 22 25 73 5c 6e 22 ...printf("%s\n"
3830: 2c 20 73 71 6c 5f 72 65 74 29 3b 0a 09 7d 0a 0a , sql_ret);..}..
3840: 09 72 65 74 75 72 6e 28 30 29 3b 0a 7d 0a 0a 2f .return(0);.}../
3850: 2a 0a 20 2a 20 54 63 6c 20 6d 6f 64 65 3a 20 45 *. * Tcl mode: E
3860: 78 65 63 75 74 65 20 72 61 77 20 54 63 6c 20 61 xecute raw Tcl a
3870: 6e 64 20 72 65 74 75 72 6e 20 73 75 63 63 65 73 nd return succes
3880: 73 20 6f 72 20 66 61 69 6c 75 72 65 0a 20 2a 2f s or failure. */
3890: 0a 73 74 61 74 69 63 20 69 6e 74 20 61 70 70 66 .static int appf
38a0: 73 5f 74 63 6c 28 63 6f 6e 73 74 20 63 68 61 72 s_tcl(const char
38b0: 20 2a 74 63 6c 29 20 7b 0a 09 54 63 6c 5f 49 6e *tcl) {..Tcl_In
38c0: 74 65 72 70 20 2a 69 6e 74 65 72 70 3b 0a 09 63 terp *interp;..c
38d0: 6f 6e 73 74 20 63 68 61 72 20 2a 74 63 6c 5f 72 onst char *tcl_r
38e0: 65 73 75 6c 74 3b 0a 09 69 6e 74 20 74 63 6c 5f esult;..int tcl_
38f0: 72 65 74 3b 0a 0a 09 69 6e 74 65 72 70 20 3d 20 ret;...interp =
3900: 61 70 70 66 73 5f 63 72 65 61 74 65 5f 54 63 6c appfs_create_Tcl
3910: 49 6e 74 65 72 70 28 29 3b 0a 09 69 66 20 28 69 Interp();..if (i
3920: 6e 74 65 72 70 20 3d 3d 20 4e 55 4c 4c 29 20 7b nterp == NULL) {
3930: 0a 09 09 66 70 72 69 6e 74 66 28 73 74 64 65 72 ...fprintf(stder
3940: 72 2c 20 22 55 6e 61 62 6c 65 20 74 6f 20 63 72 r, "Unable to cr
3950: 65 61 74 65 20 61 20 54 63 6c 20 69 6e 74 65 72 eate a Tcl inter
3960: 70 72 65 74 65 72 2e 20 20 41 62 6f 72 74 69 6e preter. Abortin
3970: 67 2e 5c 6e 22 29 3b 0a 0a 09 09 72 65 74 75 72 g.\n");....retur
3980: 6e 28 31 29 3b 0a 09 7d 0a 0a 09 74 63 6c 5f 72 n(1);..}...tcl_r
3990: 65 74 20 3d 20 54 63 6c 5f 45 76 61 6c 28 69 6e et = Tcl_Eval(in
39a0: 74 65 72 70 2c 20 74 63 6c 29 3b 0a 09 74 63 6c terp, tcl);..tcl
39b0: 5f 72 65 73 75 6c 74 20 3d 20 54 63 6c 5f 47 65 _result = Tcl_Ge
39c0: 74 53 74 72 69 6e 67 52 65 73 75 6c 74 28 69 6e tStringResult(in
39d0: 74 65 72 70 29 3b 0a 0a 09 69 66 20 28 74 63 6c terp);...if (tcl
39e0: 5f 72 65 74 20 21 3d 20 54 43 4c 5f 4f 4b 29 20 _ret != TCL_OK)
39f0: 7b 0a 09 09 66 70 72 69 6e 74 66 28 73 74 64 65 {...fprintf(stde
3a00: 72 72 2c 20 22 5b 65 72 72 6f 72 5d 20 25 73 5c rr, "[error] %s\
3a10: 6e 22 2c 20 74 63 6c 5f 72 65 73 75 6c 74 29 3b n", tcl_result);
3a20: 0a 0a 09 09 72 65 74 75 72 6e 28 31 29 3b 0a 09 ....return(1);..
3a30: 7d 0a 0a 09 69 66 20 28 74 63 6c 5f 72 65 73 75 }...if (tcl_resu
3a40: 6c 74 20 26 26 20 74 63 6c 5f 72 65 73 75 6c 74 lt && tcl_result
3a50: 5b 30 5d 20 21 3d 20 27 5c 30 27 29 20 7b 0a 09 [0] != '\0') {..
3a60: 09 70 72 69 6e 74 66 28 22 25 73 5c 6e 22 2c 20 .printf("%s\n",
3a70: 74 63 6c 5f 72 65 73 75 6c 74 29 3b 0a 09 7d 0a tcl_result);..}.
3a80: 0a 09 72 65 74 75 72 6e 28 30 29 3b 0a 7d 0a 0a ..return(0);.}..
3a90: 2f 2a 0a 20 2a 20 41 70 70 46 53 64 20 50 61 63 /*. * AppFSd Pac
3aa0: 6b 61 67 65 20 66 6f 72 20 54 63 6c 3a 0a 20 2a kage for Tcl:. *
3ab0: 20 20 20 20 20 20 20 20 20 42 72 69 64 67 65 20 Bridge
3ac0: 66 6f 72 20 49 2f 4f 20 6f 70 65 72 61 74 69 6f for I/O operatio
3ad0: 6e 73 20 74 6f 20 72 65 71 75 65 73 74 20 69 6e ns to request in
3ae0: 66 6f 72 6d 61 74 69 6f 6e 20 61 62 6f 75 74 20 formation about
3af0: 74 68 65 20 63 75 72 72 65 6e 74 0a 20 2a 20 20 the current. *
3b00: 20 20 20 20 20 20 20 74 72 61 6e 73 61 63 74 69 transacti
3b10: 6f 6e 0a 20 2a 2f 0a 73 74 61 74 69 63 20 69 6e on. */.static in
3b20: 74 20 41 70 70 66 73 64 5f 49 6e 69 74 28 54 63 t Appfsd_Init(Tc
3b30: 6c 5f 49 6e 74 65 72 70 20 2a 69 6e 74 65 72 70 l_Interp *interp
3b40: 29 20 7b 0a 23 69 66 64 65 66 20 55 53 45 5f 54 ) {.#ifdef USE_T
3b50: 43 4c 5f 53 54 55 42 53 0a 09 69 66 20 28 54 63 CL_STUBS..if (Tc
3b60: 6c 5f 49 6e 69 74 53 74 75 62 73 28 69 6e 74 65 l_InitStubs(inte
3b70: 72 70 2c 20 54 43 4c 5f 56 45 52 53 49 4f 4e 2c rp, TCL_VERSION,
3b80: 20 30 29 20 3d 3d 20 30 4c 29 20 7b 0a 09 09 72 0) == 0L) {...r
3b90: 65 74 75 72 6e 28 54 43 4c 5f 45 52 52 4f 52 29 eturn(TCL_ERROR)
3ba0: 3b 0a 09 7d 0a 23 65 6e 64 69 66 0a 0a 09 54 63 ;..}.#endif...Tc
3bb0: 6c 5f 43 72 65 61 74 65 4f 62 6a 43 6f 6d 6d 61 l_CreateObjComma
3bc0: 6e 64 28 69 6e 74 65 72 70 2c 20 22 61 70 70 66 nd(interp, "appf
3bd0: 73 64 3a 3a 67 65 74 5f 68 6f 6d 65 64 69 72 22 sd::get_homedir"
3be0: 2c 20 74 63 6c 5f 61 70 70 66 73 5f 67 65 74 5f , tcl_appfs_get_
3bf0: 68 6f 6d 65 64 69 72 2c 20 4e 55 4c 4c 2c 20 4e homedir, NULL, N
3c00: 55 4c 4c 29 3b 0a 0a 09 54 63 6c 5f 50 6b 67 50 ULL);...Tcl_PkgP
3c10: 72 6f 76 69 64 65 28 69 6e 74 65 72 70 2c 20 22 rovide(interp, "
3c20: 61 70 70 66 73 64 22 2c 20 22 31 2e 30 22 29 3b appfsd", "1.0");
3c30: 0a 0a 09 72 65 74 75 72 6e 28 54 43 4c 5f 4f 4b ...return(TCL_OK
3c40: 29 3b 0a 7d 0a 0a 2f 2a 0a 20 2a 20 46 55 53 45 );.}../*. * FUSE
3c50: 20 6f 70 65 72 61 74 69 6f 6e 73 20 73 74 72 75 operations stru
3c60: 63 74 75 72 65 0a 20 2a 2f 0a 73 74 61 74 69 63 cture. */.static
3c70: 20 73 74 72 75 63 74 20 66 75 73 65 5f 6f 70 65 struct fuse_ope
3c80: 72 61 74 69 6f 6e 73 20 61 70 70 66 73 5f 6f 70 rations appfs_op
3c90: 65 72 61 74 69 6f 6e 73 20 3d 20 7b 0a 09 2e 67 erations = {...g
3ca0: 65 74 61 74 74 72 20 20 20 3d 20 61 70 70 66 73 etattr = appfs
3cb0: 5f 66 75 73 65 5f 67 65 74 61 74 74 72 2c 0a 09 _fuse_getattr,..
3cc0: 2e 72 65 61 64 64 69 72 20 20 20 3d 20 61 70 70 .readdir = app
3cd0: 66 73 5f 66 75 73 65 5f 72 65 61 64 64 69 72 2c fs_fuse_readdir,
3ce0: 0a 09 2e 72 65 61 64 6c 69 6e 6b 20 20 3d 20 61 ...readlink = a
3cf0: 70 70 66 73 5f 66 75 73 65 5f 72 65 61 64 6c 69 ppfs_fuse_readli
3d00: 6e 6b 2c 0a 09 2e 6f 70 65 6e 20 20 20 20 20 20 nk,...open
3d10: 3d 20 61 70 70 66 73 5f 66 75 73 65 5f 6f 70 65 = appfs_fuse_ope
3d20: 6e 2c 0a 09 2e 72 65 6c 65 61 73 65 20 20 20 3d n,...release =
3d30: 20 61 70 70 66 73 5f 66 75 73 65 5f 63 6c 6f 73 appfs_fuse_clos
3d40: 65 2c 0a 09 2e 72 65 61 64 20 20 20 20 20 20 3d e,...read =
3d50: 20 61 70 70 66 73 5f 66 75 73 65 5f 72 65 61 64 appfs_fuse_read
3d60: 0a 7d 3b 0a 0a 2f 2a 0a 20 2a 20 46 55 53 45 20 .};../*. * FUSE
3d70: 6f 70 74 69 6f 6e 20 70 61 72 73 69 6e 67 20 63 option parsing c
3d80: 61 6c 6c 62 61 63 6b 0a 20 2a 2f 0a 73 74 61 74 allback. */.stat
3d90: 69 63 20 69 6e 74 20 61 70 70 66 73 5f 66 75 73 ic int appfs_fus
3da0: 65 5f 6f 70 74 5f 63 62 28 76 6f 69 64 20 2a 64 e_opt_cb(void *d
3db0: 61 74 61 2c 20 63 6f 6e 73 74 20 63 68 61 72 20 ata, const char
3dc0: 2a 61 72 67 2c 20 69 6e 74 20 6b 65 79 2c 20 73 *arg, int key, s
3dd0: 74 72 75 63 74 20 66 75 73 65 5f 61 72 67 73 20 truct fuse_args
3de0: 2a 6f 75 74 61 72 67 73 29 20 7b 0a 09 73 74 61 *outargs) {..sta
3df0: 74 69 63 20 73 65 65 6e 5f 63 61 63 68 65 64 69 tic seen_cachedi
3e00: 72 20 3d 20 30 3b 0a 0a 09 69 66 20 28 6b 65 79 r = 0;...if (key
3e10: 20 3d 3d 20 46 55 53 45 5f 4f 50 54 5f 4b 45 59 == FUSE_OPT_KEY
3e20: 5f 4e 4f 4e 4f 50 54 20 26 26 20 73 65 65 6e 5f _NONOPT && seen_
3e30: 63 61 63 68 65 64 69 72 20 3d 3d 20 30 29 20 7b cachedir == 0) {
3e40: 0a 09 09 73 65 65 6e 5f 63 61 63 68 65 64 69 72 ...seen_cachedir
3e50: 20 3d 20 31 3b 0a 0a 09 09 61 70 70 66 73 5f 63 = 1;....appfs_c
3e60: 61 63 68 65 64 69 72 20 3d 20 73 74 72 64 75 70 achedir = strdup
3e70: 28 61 72 67 29 3b 0a 0a 09 09 72 65 74 75 72 6e (arg);....return
3e80: 28 30 29 3b 0a 09 7d 0a 0a 09 72 65 74 75 72 6e (0);..}...return
3e90: 28 31 29 3b 0a 7d 0a 0a 2f 2a 0a 20 2a 20 45 6e (1);.}../*. * En
3ea0: 74 72 79 20 70 6f 69 6e 74 20 69 6e 74 6f 20 74 try point into t
3eb0: 68 69 73 20 70 72 6f 67 72 61 6d 2e 0a 20 2a 2f his program.. */
3ec0: 0a 69 6e 74 20 6d 61 69 6e 28 69 6e 74 20 61 72 .int main(int ar
3ed0: 67 63 2c 20 63 68 61 72 20 2a 2a 61 72 67 76 29 gc, char **argv)
3ee0: 20 7b 0a 09 73 74 72 75 63 74 20 66 75 73 65 5f {..struct fuse_
3ef0: 61 72 67 73 20 61 72 67 73 20 3d 20 46 55 53 45 args args = FUSE
3f00: 5f 41 52 47 53 5f 49 4e 49 54 28 61 72 67 63 2c _ARGS_INIT(argc,
3f10: 20 61 72 67 76 29 3b 0a 09 69 6e 74 20 70 74 68 argv);..int pth
3f20: 72 65 61 64 5f 72 65 74 3b 0a 0a 09 2f 2a 0a 09 read_ret;.../*..
3f30: 20 2a 20 53 6b 69 70 20 70 61 73 73 65 64 20 70 * Skip passed p
3f40: 72 6f 67 72 61 6d 20 6e 61 6d 65 0a 09 20 2a 2f rogram name.. */
3f50: 0a 09 69 66 20 28 61 72 67 63 20 3d 3d 20 30 20 ..if (argc == 0
3f60: 7c 7c 20 61 72 67 76 20 3d 3d 20 4e 55 4c 4c 29 || argv == NULL)
3f70: 20 7b 0a 09 09 72 65 74 75 72 6e 28 31 29 3b 0a {...return(1);.
3f80: 09 7d 0a 09 61 72 67 63 2d 2d 3b 0a 09 61 72 67 .}..argc--;..arg
3f90: 76 2b 2b 3b 0a 0a 09 2f 2a 0a 09 20 2a 20 53 65 v++;.../*.. * Se
3fa0: 74 20 67 6c 6f 62 61 6c 20 76 61 72 69 61 62 6c t global variabl
3fb0: 65 73 2c 20 74 68 65 73 65 20 73 68 6f 75 6c 64 es, these should
3fc0: 20 62 65 20 63 6f 6e 66 69 67 75 72 61 74 69 6f be configuratio
3fd0: 6e 20 6f 70 74 69 6f 6e 73 2e 0a 09 20 2a 2f 0a n options... */.
3fe0: 09 61 70 70 66 73 5f 63 61 63 68 65 64 69 72 20 .appfs_cachedir
3ff0: 3d 20 41 50 50 46 53 5f 43 41 43 48 45 44 49 52 = APPFS_CACHEDIR
4000: 3b 0a 0a 09 2f 2a 0a 09 20 2a 20 53 65 74 20 67 ;.../*.. * Set g
4010: 6c 6f 62 61 6c 20 76 61 72 69 61 62 6c 65 20 66 lobal variable f
4020: 6f 72 20 22 62 6f 6f 74 20 74 69 6d 65 22 20 74 or "boot time" t
4030: 6f 20 73 65 74 20 61 20 74 69 6d 65 20 6f 6e 20 o set a time on
4040: 64 69 72 65 63 74 6f 72 69 65 73 0a 09 20 2a 20 directories.. *
4050: 74 68 61 74 20 77 65 20 66 61 6b 65 2e 0a 09 20 that we fake...
4060: 2a 2f 0a 09 61 70 70 66 73 5f 62 6f 6f 74 74 69 */..appfs_bootti
4070: 6d 65 20 3d 20 74 69 6d 65 28 4e 55 4c 4c 29 3b me = time(NULL);
4080: 0a 0a 09 2f 2a 0a 09 20 2a 20 52 65 67 69 73 74 .../*.. * Regist
4090: 65 72 20 22 73 68 61 31 22 20 61 6e 64 20 22 61 er "sha1" and "a
40a0: 70 70 66 73 64 22 20 70 61 63 6b 61 67 65 20 77 ppfsd" package w
40b0: 69 74 68 20 6c 69 62 74 63 6c 20 73 6f 20 74 68 ith libtcl so th
40c0: 61 74 20 61 6e 79 20 6e 65 77 0a 09 20 2a 20 69 at any new.. * i
40d0: 6e 74 65 72 70 72 65 74 65 72 73 20 63 72 65 61 nterpreters crea
40e0: 74 65 64 20 28 77 68 69 63 68 20 61 72 65 20 64 ted (which are d
40f0: 6f 6e 65 20 64 79 6e 61 6d 69 63 61 6c 6c 79 20 one dynamically
4100: 62 79 20 46 55 53 45 29 20 63 61 6e 20 68 61 76 by FUSE) can hav
4110: 65 0a 09 20 2a 20 74 68 65 20 61 70 70 72 6f 70 e.. * the approp
4120: 72 69 61 74 65 20 63 6f 6e 66 69 67 75 72 61 74 riate configurat
4130: 69 6f 6e 20 64 6f 6e 65 20 61 75 74 6f 6d 61 74 ion done automat
4140: 69 63 61 6c 6c 79 2e 0a 09 20 2a 2f 0a 09 54 63 ically... */..Tc
4150: 6c 5f 53 74 61 74 69 63 50 61 63 6b 61 67 65 28 l_StaticPackage(
4160: 4e 55 4c 4c 2c 20 22 73 68 61 31 22 2c 20 53 68 NULL, "sha1", Sh
4170: 61 31 5f 49 6e 69 74 2c 20 4e 55 4c 4c 29 3b 0a a1_Init, NULL);.
4180: 09 54 63 6c 5f 53 74 61 74 69 63 50 61 63 6b 61 .Tcl_StaticPacka
4190: 67 65 28 4e 55 4c 4c 2c 20 22 61 70 70 66 73 64 ge(NULL, "appfsd
41a0: 22 2c 20 41 70 70 66 73 64 5f 49 6e 69 74 2c 20 ", Appfsd_Init,
41b0: 4e 55 4c 4c 29 3b 0a 0a 09 2f 2a 0a 09 20 2a 20 NULL);.../*.. *
41c0: 43 72 65 61 74 65 20 61 20 74 68 72 65 61 64 2d Create a thread-
41d0: 73 70 65 63 69 66 69 63 2d 64 61 74 61 20 28 54 specific-data (T
41e0: 53 44 29 20 6b 65 79 20 66 6f 72 20 65 61 63 68 SD) key for each
41f0: 20 74 68 72 65 61 64 20 74 6f 20 72 65 66 65 72 thread to refer
4200: 0a 09 20 2a 20 74 6f 20 69 74 73 20 6f 77 6e 20 .. * to its own
4210: 54 63 6c 20 69 6e 74 65 72 70 72 65 74 65 72 2e Tcl interpreter.
4220: 20 20 54 63 6c 20 69 6e 74 65 72 70 72 65 74 65 Tcl interprete
4230: 72 73 20 6d 75 73 74 20 62 65 20 75 6e 69 71 75 rs must be uniqu
4240: 65 20 70 65 72 0a 09 20 2a 20 74 68 72 65 61 64 e per.. * thread
4250: 20 61 6e 64 20 6e 65 77 20 74 68 72 65 61 64 73 and new threads
4260: 20 61 72 65 20 64 79 6e 61 6d 69 63 61 6c 6c 79 are dynamically
4270: 20 63 72 65 61 74 65 64 20 62 79 20 46 55 53 45 created by FUSE
4280: 2e 0a 09 20 2a 2f 0a 09 70 74 68 72 65 61 64 5f ... */..pthread_
4290: 72 65 74 20 3d 20 70 74 68 72 65 61 64 5f 6b 65 ret = pthread_ke
42a0: 79 5f 63 72 65 61 74 65 28 26 69 6e 74 65 72 70 y_create(&interp
42b0: 4b 65 79 2c 20 4e 55 4c 4c 29 3b 0a 09 69 66 20 Key, NULL);..if
42c0: 28 70 74 68 72 65 61 64 5f 72 65 74 20 21 3d 20 (pthread_ret !=
42d0: 30 29 20 7b 0a 09 09 66 70 72 69 6e 74 66 28 73 0) {...fprintf(s
42e0: 74 64 65 72 72 2c 20 22 55 6e 61 62 6c 65 20 74 tderr, "Unable t
42f0: 6f 20 63 72 65 61 74 65 20 54 53 44 20 6b 65 79 o create TSD key
4300: 20 66 6f 72 20 54 63 6c 2e 20 20 41 62 6f 72 74 for Tcl. Abort
4310: 69 6e 67 2e 5c 6e 22 29 3b 0a 0a 09 09 72 65 74 ing.\n");....ret
4320: 75 72 6e 28 31 29 3b 0a 09 7d 0a 0a 09 2f 2a 0a urn(1);..}.../*.
4330: 09 20 2a 20 4d 61 6e 75 61 6c 6c 79 20 73 70 65 . * Manually spe
4340: 63 69 66 79 20 63 61 63 68 65 20 64 69 72 65 63 cify cache direc
4350: 74 6f 72 79 2c 20 77 69 74 68 6f 75 74 20 46 55 tory, without FU
4360: 53 45 20 63 61 6c 6c 62 61 63 6b 0a 09 20 2a 20 SE callback.. *
4370: 54 68 69 73 20 6f 70 74 69 6f 6e 20 6f 6e 6c 79 This option only
4380: 20 77 6f 72 6b 73 20 77 68 65 6e 20 6e 6f 74 20 works when not
4390: 75 73 69 6e 67 20 46 55 53 45 2c 20 73 69 6e 63 using FUSE, sinc
43a0: 65 20 77 65 0a 09 20 2a 20 64 6f 20 6e 6f 74 20 e we.. * do not
43b0: 70 72 6f 63 65 73 73 20 69 74 20 77 69 74 68 20 process it with
43c0: 46 55 53 45 73 20 6f 70 74 69 6f 6e 20 70 72 6f FUSEs option pro
43d0: 63 65 73 73 69 6e 67 2e 0a 09 20 2a 2f 0a 09 69 cessing... */..i
43e0: 66 20 28 61 72 67 63 20 3e 3d 20 32 29 20 7b 0a f (argc >= 2) {.
43f0: 09 09 69 66 20 28 73 74 72 63 6d 70 28 61 72 67 ..if (strcmp(arg
4400: 76 5b 30 5d 2c 20 22 2d 2d 63 61 63 68 65 64 69 v[0], "--cachedi
4410: 72 22 29 20 3d 3d 20 30 29 20 7b 0a 09 09 09 61 r") == 0) {....a
4420: 70 70 66 73 5f 63 61 63 68 65 64 69 72 20 3d 20 ppfs_cachedir =
4430: 73 74 72 64 75 70 28 61 72 67 76 5b 31 5d 29 3b strdup(argv[1]);
4440: 0a 0a 09 09 09 61 72 67 63 20 2d 3d 20 32 3b 0a .....argc -= 2;.
4450: 09 09 09 61 72 67 76 20 2b 3d 20 32 3b 0a 09 09 ...argv += 2;...
4460: 7d 0a 09 7d 0a 0a 09 2f 2a 0a 09 20 2a 20 53 51 }..}.../*.. * SQ
4470: 4c 69 74 65 33 20 6d 6f 64 65 2c 20 66 6f 72 20 Lite3 mode, for
4480: 72 75 6e 6e 69 6e 67 20 72 61 77 20 53 51 4c 20 running raw SQL
4490: 61 67 61 69 6e 73 74 20 74 68 65 20 63 61 63 68 against the cach
44a0: 65 20 64 61 74 61 62 61 73 65 0a 09 20 2a 2f 0a e database.. */.
44b0: 09 69 66 20 28 61 72 67 63 20 3d 3d 20 32 20 26 .if (argc == 2 &
44c0: 26 20 73 74 72 63 6d 70 28 61 72 67 76 5b 30 5d & strcmp(argv[0]
44d0: 2c 20 22 2d 2d 73 71 6c 69 74 65 33 22 29 20 3d , "--sqlite3") =
44e0: 3d 20 30 29 20 7b 0a 09 09 72 65 74 75 72 6e 28 = 0) {...return(
44f0: 61 70 70 66 73 5f 73 71 6c 69 74 65 33 28 61 72 appfs_sqlite3(ar
4500: 67 76 5b 31 5d 29 29 3b 0a 09 7d 0a 0a 09 2f 2a gv[1]));..}.../*
4510: 0a 09 20 2a 20 54 63 6c 20 6d 6f 64 65 2c 20 66 .. * Tcl mode, f
4520: 6f 72 20 72 75 6e 6e 69 6e 67 20 72 61 77 20 54 or running raw T
4530: 63 6c 20 69 6e 20 74 68 65 20 73 61 6d 65 20 65 cl in the same e
4540: 6e 76 69 72 6f 6e 6d 65 6e 74 20 41 70 70 46 53 nvironment AppFS
4550: 64 20 77 6f 75 6c 64 0a 09 20 2a 20 72 75 6e 20 d would.. * run
4560: 63 6f 64 65 2e 0a 09 20 2a 2f 0a 09 69 66 20 28 code... */..if (
4570: 61 72 67 63 20 3d 3d 20 32 20 26 26 20 73 74 72 argc == 2 && str
4580: 63 6d 70 28 61 72 67 76 5b 30 5d 2c 20 22 2d 2d cmp(argv[0], "--
4590: 74 63 6c 22 29 20 3d 3d 20 30 29 20 7b 0a 09 09 tcl") == 0) {...
45a0: 72 65 74 75 72 6e 28 61 70 70 66 73 5f 74 63 6c return(appfs_tcl
45b0: 28 61 72 67 76 5b 31 5d 29 29 3b 0a 09 7d 0a 0a (argv[1]));..}..
45c0: 09 2f 2a 0a 09 20 2a 20 41 64 64 20 46 55 53 45 ./*.. * Add FUSE
45d0: 20 61 72 67 75 6d 65 6e 74 73 20 77 68 69 63 68 arguments which
45e0: 20 77 65 20 61 6c 77 61 79 73 20 73 75 70 70 6c we always suppl
45f0: 79 0a 09 20 2a 2f 0a 09 66 75 73 65 5f 6f 70 74 y.. */..fuse_opt
4600: 5f 70 61 72 73 65 28 26 61 72 67 73 2c 20 4e 55 _parse(&args, NU
4610: 4c 4c 2c 20 4e 55 4c 4c 2c 20 61 70 70 66 73 5f LL, NULL, appfs_
4620: 66 75 73 65 5f 6f 70 74 5f 63 62 29 3b 0a 09 66 fuse_opt_cb);..f
4630: 75 73 65 5f 6f 70 74 5f 61 64 64 5f 61 72 67 28 use_opt_add_arg(
4640: 26 61 72 67 73 2c 20 22 2d 6f 64 65 66 61 75 6c &args, "-odefaul
4650: 74 5f 70 65 72 6d 69 73 73 69 6f 6e 73 2c 66 73 t_permissions,fs
4660: 6e 61 6d 65 3d 61 70 70 66 73 2c 73 75 62 74 79 name=appfs,subty
4670: 70 65 3d 61 70 70 66 73 64 2c 75 73 65 5f 69 6e pe=appfsd,use_in
4680: 6f 2c 6b 65 72 6e 65 6c 5f 63 61 63 68 65 2c 65 o,kernel_cache,e
4690: 6e 74 72 79 5f 74 69 6d 65 6f 75 74 3d 36 30 2c ntry_timeout=60,
46a0: 61 74 74 72 5f 74 69 6d 65 6f 75 74 3d 33 36 30 attr_timeout=360
46b0: 30 2c 69 6e 74 72 2c 62 69 67 5f 77 72 69 74 65 0,intr,big_write
46c0: 73 22 29 3b 0a 0a 09 69 66 20 28 67 65 74 75 69 s");...if (getui
46d0: 64 28 29 20 3d 3d 20 30 29 20 7b 0a 09 09 66 75 d() == 0) {...fu
46e0: 73 65 5f 6f 70 74 5f 70 61 72 73 65 28 26 61 72 se_opt_parse(&ar
46f0: 67 73 2c 20 4e 55 4c 4c 2c 20 4e 55 4c 4c 2c 20 gs, NULL, NULL,
4700: 4e 55 4c 4c 29 3b 0a 09 09 66 75 73 65 5f 6f 70 NULL);...fuse_op
4710: 74 5f 61 64 64 5f 61 72 67 28 26 61 72 67 73 2c t_add_arg(&args,
4720: 20 22 2d 6f 61 6c 6c 6f 77 5f 6f 74 68 65 72 22 "-oallow_other"
4730: 29 3b 0a 09 7d 0a 0a 09 2f 2a 0a 09 20 2a 20 45 );..}.../*.. * E
4740: 6e 74 65 72 20 74 68 65 20 46 55 53 45 20 6d 61 nter the FUSE ma
4750: 69 6e 20 6c 6f 6f 70 20 2d 2d 20 74 68 69 73 20 in loop -- this
4760: 77 69 6c 6c 20 70 72 6f 63 65 73 73 20 61 6e 79 will process any
4770: 20 61 72 67 75 6d 65 6e 74 73 0a 09 20 2a 20 61 arguments.. * a
4780: 6e 64 20 73 74 61 72 74 20 73 65 72 76 69 63 69 nd start servici
4790: 6e 67 20 72 65 71 75 65 73 74 73 2e 0a 09 20 2a ng requests... *
47a0: 2f 0a 09 72 65 74 75 72 6e 28 66 75 73 65 5f 6d /..return(fuse_m
47b0: 61 69 6e 28 61 72 67 73 2e 61 72 67 63 2c 20 61 ain(args.argc, a
47c0: 72 67 73 2e 61 72 67 76 2c 20 26 61 70 70 66 73 rgs.argv, &appfs
47d0: 5f 6f 70 65 72 61 74 69 6f 6e 73 2c 20 4e 55 4c _operations, NUL
47e0: 4c 29 29 3b 0a 7d 0a 20 0a L));.}. .