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 66 73 75 69 64 clude <sys/fsuid
0030: 2e 68 3e 0a 23 69 6e 63 6c 75 64 65 20 3c 73 79 .h>.#include <sy
0040: 73 2f 74 79 70 65 73 2e 68 3e 0a 23 69 6e 63 6c s/types.h>.#incl
0050: 75 64 65 20 3c 70 74 68 72 65 61 64 2e 68 3e 0a ude <pthread.h>.
0060: 23 69 6e 63 6c 75 64 65 20 3c 73 69 67 6e 61 6c #include <signal
0070: 2e 68 3e 0a 23 69 6e 63 6c 75 64 65 20 3c 73 74 .h>.#include <st
0080: 72 69 6e 67 2e 68 3e 0a 23 69 6e 63 6c 75 64 65 ring.h>.#include
0090: 20 3c 73 74 64 61 72 67 2e 68 3e 0a 23 69 6e 63 <stdarg.h>.#inc
00a0: 6c 75 64 65 20 3c 73 74 64 6c 69 62 2e 68 3e 0a lude <stdlib.h>.
00b0: 23 69 6e 63 6c 75 64 65 20 3c 75 6e 69 73 74 64 #include <unistd
00c0: 2e 68 3e 0a 23 69 6e 63 6c 75 64 65 20 3c 65 72 .h>.#include <er
00d0: 72 6e 6f 2e 68 3e 0a 23 69 6e 63 6c 75 64 65 20 rno.h>.#include
00e0: 3c 66 63 6e 74 6c 2e 68 3e 0a 23 69 6e 63 6c 75 <fcntl.h>.#inclu
00f0: 64 65 20 3c 73 74 64 69 6f 2e 68 3e 0a 23 69 6e de <stdio.h>.#in
0100: 63 6c 75 64 65 20 3c 66 75 73 65 2e 68 3e 0a 23 clude <fuse.h>.#
0110: 69 6e 63 6c 75 64 65 20 3c 70 77 64 2e 68 3e 0a include <pwd.h>.
0120: 23 69 6e 63 6c 75 64 65 20 3c 74 63 6c 2e 68 3e #include <tcl.h>
0130: 0a 0a 2f 2a 0a 20 2a 20 44 65 66 61 75 6c 74 20 ../*. * Default
0140: 63 61 63 68 65 20 64 69 72 65 63 74 6f 72 79 0a cache directory.
0150: 20 2a 2f 0a 23 69 66 6e 64 65 66 20 41 50 50 46 */.#ifndef APPF
0160: 53 5f 43 41 43 48 45 44 49 52 0a 23 64 65 66 69 S_CACHEDIR.#defi
0170: 6e 65 20 41 50 50 46 53 5f 43 41 43 48 45 44 49 ne APPFS_CACHEDI
0180: 52 20 22 2f 76 61 72 2f 63 61 63 68 65 2f 61 70 R "/var/cache/ap
0190: 70 66 73 22 0a 23 65 6e 64 69 66 0a 0a 2f 2a 20 pfs".#endif../*
01a0: 44 65 62 75 67 67 69 6e 67 20 6d 61 63 72 6f 73 Debugging macros
01b0: 20 2a 2f 0a 23 69 66 64 65 66 20 44 45 42 55 47 */.#ifdef DEBUG
01c0: 0a 23 64 65 66 69 6e 65 20 41 50 50 46 53 5f 44 .#define APPFS_D
01d0: 45 42 55 47 28 78 2e 2e 2e 29 20 7b 20 66 70 72 EBUG(x...) { fpr
01e0: 69 6e 74 66 28 73 74 64 65 72 72 2c 20 22 5b 64 intf(stderr, "[d
01f0: 65 62 75 67 5d 20 25 73 3a 25 69 3a 25 73 3a 20 ebug] %s:%i:%s:
0200: 22 2c 20 5f 5f 46 49 4c 45 5f 5f 2c 20 5f 5f 4c ", __FILE__, __L
0210: 49 4e 45 5f 5f 2c 20 5f 5f 66 75 6e 63 5f 5f 29 INE__, __func__)
0220: 3b 20 66 70 72 69 6e 74 66 28 73 74 64 65 72 72 ; fprintf(stderr
0230: 2c 20 78 29 3b 20 66 70 72 69 6e 74 66 28 73 74 , x); fprintf(st
0240: 64 65 72 72 2c 20 22 5c 6e 22 29 3b 20 7d 0a 23 derr, "\n"); }.#
0250: 65 6c 73 65 0a 23 64 65 66 69 6e 65 20 41 50 50 else.#define APP
0260: 46 53 5f 44 45 42 55 47 28 78 2e 2e 2e 29 20 2f FS_DEBUG(x...) /
0270: 2a 2a 2f 0a 23 65 6e 64 69 66 0a 0a 2f 2a 0a 20 **/.#endif../*.
0280: 2a 20 53 48 41 31 20 54 63 6c 20 50 61 63 6b 61 * SHA1 Tcl Packa
0290: 67 65 20 69 6e 69 74 69 61 6c 69 7a 65 72 2c 20 ge initializer,
02a0: 66 72 6f 6d 20 73 68 61 31 2e 6f 0a 20 2a 2f 0a from sha1.o. */.
02b0: 69 6e 74 20 53 68 61 31 5f 49 6e 69 74 28 54 63 int Sha1_Init(Tc
02c0: 6c 5f 49 6e 74 65 72 70 20 2a 69 6e 74 65 72 70 l_Interp *interp
02d0: 29 3b 0a 0a 2f 2a 0a 20 2a 20 54 68 72 65 61 64 );../*. * Thread
02e0: 20 53 70 65 63 69 66 69 63 20 44 61 74 61 20 28 Specific Data (
02f0: 54 53 44 29 20 66 6f 72 20 54 63 6c 20 49 6e 74 TSD) for Tcl Int
0300: 65 72 70 72 65 74 65 72 20 66 6f 72 20 74 68 65 erpreter for the
0310: 20 63 75 72 72 65 6e 74 20 74 68 72 65 61 64 0a current thread.
0320: 20 2a 2f 0a 73 74 61 74 69 63 20 70 74 68 72 65 */.static pthre
0330: 61 64 5f 6b 65 79 5f 74 20 69 6e 74 65 72 70 4b ad_key_t interpK
0340: 65 79 3b 0a 0a 2f 2a 0a 20 2a 20 47 6c 6f 62 61 ey;../*. * Globa
0350: 6c 20 76 61 72 69 61 62 6c 65 73 2c 20 6e 65 65 l variables, nee
0360: 64 65 64 20 66 6f 72 20 61 6c 6c 20 74 68 72 65 ded for all thre
0370: 61 64 73 20 62 75 74 20 6f 6e 6c 79 20 69 6e 69 ads but only ini
0380: 74 69 61 6c 69 7a 65 64 20 62 65 66 6f 72 65 20 tialized before
0390: 61 6e 79 0a 20 2a 20 46 55 53 45 20 74 68 72 65 any. * FUSE thre
03a0: 61 64 73 20 61 72 65 20 63 72 65 61 74 65 64 0a ads are created.
03b0: 20 2a 2f 0a 63 6f 6e 73 74 20 63 68 61 72 20 2a */.const char *
03c0: 61 70 70 66 73 5f 63 61 63 68 65 64 69 72 3b 0a appfs_cachedir;.
03d0: 74 69 6d 65 5f 74 20 61 70 70 66 73 5f 62 6f 6f time_t appfs_boo
03e0: 74 74 69 6d 65 3b 0a 69 6e 74 20 61 70 70 66 73 ttime;.int appfs
03f0: 5f 66 75 73 65 5f 73 74 61 72 74 65 64 20 3d 20 _fuse_started =
0400: 30 3b 0a 0a 2f 2a 0a 20 2a 20 47 6c 6f 62 61 6c 0;../*. * Global
0410: 20 76 61 72 69 61 62 6c 65 73 20 66 6f 72 20 41 variables for A
0420: 70 70 46 53 20 63 61 63 68 69 6e 67 0a 20 2a 2f ppFS caching. */
0430: 0a 70 74 68 72 65 61 64 5f 6d 75 74 65 78 5f 74 .pthread_mutex_t
0440: 20 61 70 70 66 73 5f 70 61 74 68 5f 69 6e 66 6f appfs_path_info
0450: 5f 63 61 63 68 65 5f 6d 75 74 65 78 20 3d 20 50 _cache_mutex = P
0460: 54 48 52 45 41 44 5f 4d 55 54 45 58 5f 49 4e 49 THREAD_MUTEX_INI
0470: 54 49 41 4c 49 5a 45 52 3b 0a 69 6e 74 20 61 70 TIALIZER;.int ap
0480: 70 66 73 5f 70 61 74 68 5f 69 6e 66 6f 5f 63 61 pfs_path_info_ca
0490: 63 68 65 5f 73 69 7a 65 20 3d 20 38 32 30 39 3b che_size = 8209;
04a0: 0a 73 74 72 75 63 74 20 61 70 70 66 73 5f 70 61 .struct appfs_pa
04b0: 74 68 69 6e 66 6f 20 2a 61 70 70 66 73 5f 70 61 thinfo *appfs_pa
04c0: 74 68 5f 69 6e 66 6f 5f 63 61 63 68 65 20 3d 20 th_info_cache =
04d0: 4e 55 4c 4c 3b 0a 0a 2f 2a 0a 20 2a 20 47 6c 6f NULL;../*. * Glo
04e0: 62 61 6c 20 76 61 72 69 61 62 6c 65 73 20 66 6f bal variables fo
04f0: 72 20 41 70 70 46 53 20 54 63 6c 20 49 6e 74 65 r AppFS Tcl Inte
0500: 72 70 72 65 74 65 72 20 72 65 73 74 61 72 74 69 rpreter restarti
0510: 6e 67 0a 20 2a 2f 0a 69 6e 74 20 69 6e 74 65 72 ng. */.int inter
0520: 70 5f 72 65 73 65 74 5f 6b 65 79 20 3d 20 30 3b p_reset_key = 0;
0530: 0a 0a 2f 2a 0a 20 2a 20 41 70 70 46 53 20 50 61 ../*. * AppFS Pa
0540: 74 68 20 54 79 70 65 3a 20 20 44 65 73 63 72 69 th Type: Descri
0550: 62 65 73 20 74 68 65 20 74 79 70 65 20 6f 66 20 bes the type of
0560: 70 61 74 68 20 61 20 67 69 76 65 6e 20 66 69 6c path a given fil
0570: 65 20 69 73 0a 20 2a 2f 0a 74 79 70 65 64 65 66 e is. */.typedef
0580: 20 65 6e 75 6d 20 7b 0a 09 41 50 50 46 53 5f 50 enum {..APPFS_P
0590: 41 54 48 54 59 50 45 5f 49 4e 56 41 4c 49 44 2c ATHTYPE_INVALID,
05a0: 0a 09 41 50 50 46 53 5f 50 41 54 48 54 59 50 45 ..APPFS_PATHTYPE
05b0: 5f 44 4f 45 53 5f 4e 4f 54 5f 45 58 49 53 54 2c _DOES_NOT_EXIST,
05c0: 0a 09 41 50 50 46 53 5f 50 41 54 48 54 59 50 45 ..APPFS_PATHTYPE
05d0: 5f 46 49 4c 45 2c 0a 09 41 50 50 46 53 5f 50 41 _FILE,..APPFS_PA
05e0: 54 48 54 59 50 45 5f 44 49 52 45 43 54 4f 52 59 THTYPE_DIRECTORY
05f0: 2c 0a 09 41 50 50 46 53 5f 50 41 54 48 54 59 50 ,..APPFS_PATHTYP
0600: 45 5f 53 59 4d 4c 49 4e 4b 2c 0a 09 41 50 50 46 E_SYMLINK,..APPF
0610: 53 5f 50 41 54 48 54 59 50 45 5f 53 4f 43 4b 45 S_PATHTYPE_SOCKE
0620: 54 2c 0a 09 41 50 50 46 53 5f 50 41 54 48 54 59 T,..APPFS_PATHTY
0630: 50 45 5f 46 49 46 4f 2c 0a 7d 20 61 70 70 66 73 PE_FIFO,.} appfs
0640: 5f 70 61 74 68 74 79 70 65 5f 74 3b 0a 0a 2f 2a _pathtype_t;../*
0650: 0a 20 2a 20 41 70 70 46 53 20 50 61 74 68 20 49 . * AppFS Path I
0660: 6e 66 6f 72 6d 61 74 69 6f 6e 3a 0a 20 2a 20 20 nformation:. *
0670: 20 20 20 20 20 20 20 43 6f 6d 70 6c 65 74 65 6c Completel
0680: 79 20 64 65 73 63 72 69 62 65 73 20 61 20 73 70 y describes a sp
0690: 65 63 69 66 69 63 20 70 61 74 68 2c 20 68 6f 77 ecific path, how
06a0: 20 69 74 20 73 68 6f 75 6c 64 20 62 65 20 72 65 it should be re
06b0: 74 75 72 6e 65 64 20 74 6f 0a 20 2a 20 20 20 20 turned to. *
06c0: 20 20 20 20 20 74 6f 20 74 68 65 20 6b 65 72 6e to the kern
06d0: 65 6c 0a 20 2a 2f 0a 73 74 72 75 63 74 20 61 70 el. */.struct ap
06e0: 70 66 73 5f 70 61 74 68 69 6e 66 6f 20 7b 0a 09 pfs_pathinfo {..
06f0: 61 70 70 66 73 5f 70 61 74 68 74 79 70 65 5f 74 appfs_pathtype_t
0700: 20 74 79 70 65 3b 0a 09 74 69 6d 65 5f 74 20 74 type;..time_t t
0710: 69 6d 65 3b 0a 09 63 68 61 72 20 68 6f 73 74 6e ime;..char hostn
0720: 61 6d 65 5b 32 35 36 5d 3b 0a 09 69 6e 74 20 70 ame[256];..int p
0730: 61 63 6b 61 67 65 64 3b 0a 09 75 6e 73 69 67 6e ackaged;..unsign
0740: 65 64 20 6c 6f 6e 67 20 6c 6f 6e 67 20 69 6e 6f ed long long ino
0750: 64 65 3b 0a 09 75 6e 69 6f 6e 20 7b 0a 09 09 73 de;..union {...s
0760: 74 72 75 63 74 20 7b 0a 09 09 09 69 6e 74 20 63 truct {....int c
0770: 68 69 6c 64 63 6f 75 6e 74 3b 0a 09 09 7d 20 64 hildcount;...} d
0780: 69 72 3b 0a 09 09 73 74 72 75 63 74 20 7b 0a 09 ir;...struct {..
0790: 09 09 69 6e 74 20 65 78 65 63 75 74 61 62 6c 65 ..int executable
07a0: 3b 0a 09 09 09 6f 66 66 5f 74 20 73 69 7a 65 3b ;....off_t size;
07b0: 0a 09 09 7d 20 66 69 6c 65 3b 0a 09 09 73 74 72 ...} file;...str
07c0: 75 63 74 20 7b 0a 09 09 09 6f 66 66 5f 74 20 73 uct {....off_t s
07d0: 69 7a 65 3b 0a 09 09 09 63 68 61 72 20 73 6f 75 ize;....char sou
07e0: 72 63 65 5b 32 35 36 5d 3b 0a 09 09 7d 20 73 79 rce[256];...} sy
07f0: 6d 6c 69 6e 6b 3b 0a 09 7d 20 74 79 70 65 69 6e mlink;..} typein
0800: 66 6f 3b 0a 0a 09 2f 2a 20 41 74 74 72 69 62 75 fo;.../* Attribu
0810: 74 65 73 20 75 73 65 64 20 6f 6e 6c 79 20 66 6f tes used only fo
0820: 72 20 63 61 63 68 69 6e 67 20 65 6e 74 72 69 65 r caching entrie
0830: 73 20 2a 2f 0a 09 63 68 61 72 20 2a 5f 63 61 63 s */..char *_cac
0840: 68 65 5f 70 61 74 68 3b 0a 09 75 69 64 5f 74 20 he_path;..uid_t
0850: 5f 63 61 63 68 65 5f 75 69 64 3b 0a 7d 3b 0a 0a _cache_uid;.};..
0860: 2f 2a 0a 20 2a 20 43 72 65 61 74 65 20 61 20 6e /*. * Create a n
0870: 65 77 20 54 63 6c 20 69 6e 74 65 72 70 72 65 74 ew Tcl interpret
0880: 65 72 20 61 6e 64 20 63 6f 6d 70 6c 65 74 65 6c er and completel
0890: 79 20 69 6e 69 74 69 61 6c 69 7a 65 20 69 74 0a y initialize it.
08a0: 20 2a 2f 0a 73 74 61 74 69 63 20 54 63 6c 5f 49 */.static Tcl_I
08b0: 6e 74 65 72 70 20 2a 61 70 70 66 73 5f 63 72 65 nterp *appfs_cre
08c0: 61 74 65 5f 54 63 6c 49 6e 74 65 72 70 28 63 68 ate_TclInterp(ch
08d0: 61 72 20 2a 2a 65 72 72 6f 72 5f 73 74 72 69 6e ar **error_strin
08e0: 67 29 20 7b 0a 09 54 63 6c 5f 49 6e 74 65 72 70 g) {..Tcl_Interp
08f0: 20 2a 69 6e 74 65 72 70 3b 0a 09 69 6e 74 20 74 *interp;..int t
0900: 63 6c 5f 72 65 74 3b 0a 0a 09 41 50 50 46 53 5f cl_ret;...APPFS_
0910: 44 45 42 55 47 28 22 43 72 65 61 74 69 6e 67 20 DEBUG("Creating
0920: 6e 65 77 20 54 63 6c 20 69 6e 74 65 72 70 72 65 new Tcl interpre
0930: 74 65 72 20 66 6f 72 20 54 49 44 20 3d 20 30 78 ter for TID = 0x
0940: 25 6c 6c 78 22 2c 20 28 75 6e 73 69 67 6e 65 64 %llx", (unsigned
0950: 20 6c 6f 6e 67 20 6c 6f 6e 67 29 20 70 74 68 72 long long) pthr
0960: 65 61 64 5f 73 65 6c 66 28 29 29 3b 0a 0a 09 69 ead_self());...i
0970: 6e 74 65 72 70 20 3d 20 54 63 6c 5f 43 72 65 61 nterp = Tcl_Crea
0980: 74 65 49 6e 74 65 72 70 28 29 3b 0a 09 69 66 20 teInterp();..if
0990: 28 69 6e 74 65 72 70 20 3d 3d 20 4e 55 4c 4c 29 (interp == NULL)
09a0: 20 7b 0a 09 09 66 70 72 69 6e 74 66 28 73 74 64 {...fprintf(std
09b0: 65 72 72 2c 20 22 55 6e 61 62 6c 65 20 74 6f 20 err, "Unable to
09c0: 63 72 65 61 74 65 20 54 63 6c 20 49 6e 74 65 72 create Tcl Inter
09d0: 70 72 65 74 65 72 2e 20 20 41 62 6f 72 74 69 6e preter. Abortin
09e0: 67 2e 5c 6e 22 29 3b 0a 0a 09 09 69 66 20 28 65 g.\n");....if (e
09f0: 72 72 6f 72 5f 73 74 72 69 6e 67 29 20 7b 0a 09 rror_string) {..
0a00: 09 09 2a 65 72 72 6f 72 5f 73 74 72 69 6e 67 20 ..*error_string
0a10: 3d 20 73 74 72 64 75 70 28 22 55 6e 61 62 6c 65 = strdup("Unable
0a20: 20 74 6f 20 63 72 65 61 74 65 20 54 63 6c 20 69 to create Tcl i
0a30: 6e 74 65 72 70 72 65 74 65 72 2e 22 29 3b 0a 09 nterpreter.");..
0a40: 09 7d 0a 0a 09 09 72 65 74 75 72 6e 28 4e 55 4c .}....return(NUL
0a50: 4c 29 3b 0a 09 7d 0a 0a 09 74 63 6c 5f 72 65 74 L);..}...tcl_ret
0a60: 20 3d 20 54 63 6c 5f 49 6e 69 74 28 69 6e 74 65 = Tcl_Init(inte
0a70: 72 70 29 3b 0a 09 69 66 20 28 74 63 6c 5f 72 65 rp);..if (tcl_re
0a80: 74 20 21 3d 20 54 43 4c 5f 4f 4b 29 20 7b 0a 09 t != TCL_OK) {..
0a90: 09 66 70 72 69 6e 74 66 28 73 74 64 65 72 72 2c .fprintf(stderr,
0aa0: 20 22 55 6e 61 62 6c 65 20 74 6f 20 69 6e 69 74 "Unable to init
0ab0: 69 61 6c 69 7a 65 20 54 63 6c 2e 20 20 41 62 6f ialize Tcl. Abo
0ac0: 72 74 69 6e 67 2e 5c 6e 22 29 3b 0a 09 09 66 70 rting.\n");...fp
0ad0: 72 69 6e 74 66 28 73 74 64 65 72 72 2c 20 22 54 rintf(stderr, "T
0ae0: 63 6c 20 45 72 72 6f 72 20 69 73 3a 20 25 73 5c cl Error is: %s\
0af0: 6e 22 2c 20 54 63 6c 5f 47 65 74 53 74 72 69 6e n", Tcl_GetStrin
0b00: 67 52 65 73 75 6c 74 28 69 6e 74 65 72 70 29 29 gResult(interp))
0b10: 3b 0a 0a 09 09 69 66 20 28 65 72 72 6f 72 5f 73 ;....if (error_s
0b20: 74 72 69 6e 67 29 20 7b 0a 09 09 09 2a 65 72 72 tring) {....*err
0b30: 6f 72 5f 73 74 72 69 6e 67 20 3d 20 73 74 72 64 or_string = strd
0b40: 75 70 28 54 63 6c 5f 47 65 74 53 74 72 69 6e 67 up(Tcl_GetString
0b50: 52 65 73 75 6c 74 28 69 6e 74 65 72 70 29 29 3b Result(interp));
0b60: 0a 09 09 7d 0a 0a 09 09 54 63 6c 5f 44 65 6c 65 ...}....Tcl_Dele
0b70: 74 65 49 6e 74 65 72 70 28 69 6e 74 65 72 70 29 teInterp(interp)
0b80: 3b 0a 0a 09 09 72 65 74 75 72 6e 28 4e 55 4c 4c ;....return(NULL
0b90: 29 3b 0a 09 7d 0a 0a 09 74 63 6c 5f 72 65 74 20 );..}...tcl_ret
0ba0: 3d 20 54 63 6c 5f 45 76 61 6c 28 69 6e 74 65 72 = Tcl_Eval(inter
0bb0: 70 2c 20 22 70 61 63 6b 61 67 65 20 69 66 6e 65 p, "package ifne
0bc0: 65 64 65 64 20 73 68 61 31 20 31 2e 30 20 5b 6c eded sha1 1.0 [l
0bd0: 69 73 74 20 6c 6f 61 64 20 7b 7d 20 73 68 61 31 ist load {} sha1
0be0: 5d 22 29 3b 0a 09 69 66 20 28 74 63 6c 5f 72 65 ]");..if (tcl_re
0bf0: 74 20 21 3d 20 54 43 4c 5f 4f 4b 29 20 7b 0a 09 t != TCL_OK) {..
0c00: 09 66 70 72 69 6e 74 66 28 73 74 64 65 72 72 2c .fprintf(stderr,
0c10: 20 22 55 6e 61 62 6c 65 20 74 6f 20 69 6e 69 74 "Unable to init
0c20: 69 61 6c 69 7a 65 20 54 63 6c 20 53 48 41 31 2e ialize Tcl SHA1.
0c30: 20 20 41 62 6f 72 74 69 6e 67 2e 5c 6e 22 29 3b Aborting.\n");
0c40: 0a 09 09 66 70 72 69 6e 74 66 28 73 74 64 65 72 ...fprintf(stder
0c50: 72 2c 20 22 54 63 6c 20 45 72 72 6f 72 20 69 73 r, "Tcl Error is
0c60: 3a 20 25 73 5c 6e 22 2c 20 54 63 6c 5f 47 65 74 : %s\n", Tcl_Get
0c70: 53 74 72 69 6e 67 52 65 73 75 6c 74 28 69 6e 74 StringResult(int
0c80: 65 72 70 29 29 3b 0a 0a 09 09 69 66 20 28 65 72 erp));....if (er
0c90: 72 6f 72 5f 73 74 72 69 6e 67 29 20 7b 0a 09 09 ror_string) {...
0ca0: 09 2a 65 72 72 6f 72 5f 73 74 72 69 6e 67 20 3d .*error_string =
0cb0: 20 73 74 72 64 75 70 28 54 63 6c 5f 47 65 74 53 strdup(Tcl_GetS
0cc0: 74 72 69 6e 67 52 65 73 75 6c 74 28 69 6e 74 65 tringResult(inte
0cd0: 72 70 29 29 3b 0a 09 09 7d 0a 0a 09 09 54 63 6c rp));...}....Tcl
0ce0: 5f 44 65 6c 65 74 65 49 6e 74 65 72 70 28 69 6e _DeleteInterp(in
0cf0: 74 65 72 70 29 3b 0a 0a 09 09 72 65 74 75 72 6e terp);....return
0d00: 28 4e 55 4c 4c 29 3b 0a 09 7d 0a 0a 09 74 63 6c (NULL);..}...tcl
0d10: 5f 72 65 74 20 3d 20 54 63 6c 5f 45 76 61 6c 28 _ret = Tcl_Eval(
0d20: 69 6e 74 65 72 70 2c 20 22 70 61 63 6b 61 67 65 interp, "package
0d30: 20 69 66 6e 65 65 64 65 64 20 61 70 70 66 73 64 ifneeded appfsd
0d40: 20 31 2e 30 20 5b 6c 69 73 74 20 6c 6f 61 64 20 1.0 [list load
0d50: 7b 7d 20 61 70 70 66 73 64 5d 22 29 3b 0a 09 69 {} appfsd]");..i
0d60: 66 20 28 74 63 6c 5f 72 65 74 20 21 3d 20 54 43 f (tcl_ret != TC
0d70: 4c 5f 4f 4b 29 20 7b 0a 09 09 66 70 72 69 6e 74 L_OK) {...fprint
0d80: 66 28 73 74 64 65 72 72 2c 20 22 55 6e 61 62 6c f(stderr, "Unabl
0d90: 65 20 74 6f 20 69 6e 69 74 69 61 6c 69 7a 65 20 e to initialize
0da0: 54 63 6c 20 41 70 70 46 53 20 50 61 63 6b 61 67 Tcl AppFS Packag
0db0: 65 2e 20 20 41 62 6f 72 74 69 6e 67 2e 5c 6e 22 e. Aborting.\n"
0dc0: 29 3b 0a 09 09 66 70 72 69 6e 74 66 28 73 74 64 );...fprintf(std
0dd0: 65 72 72 2c 20 22 54 63 6c 20 45 72 72 6f 72 20 err, "Tcl Error
0de0: 69 73 3a 20 25 73 5c 6e 22 2c 20 54 63 6c 5f 47 is: %s\n", Tcl_G
0df0: 65 74 53 74 72 69 6e 67 52 65 73 75 6c 74 28 69 etStringResult(i
0e00: 6e 74 65 72 70 29 29 3b 0a 0a 09 09 69 66 20 28 nterp));....if (
0e10: 65 72 72 6f 72 5f 73 74 72 69 6e 67 29 20 7b 0a error_string) {.
0e20: 09 09 09 2a 65 72 72 6f 72 5f 73 74 72 69 6e 67 ...*error_string
0e30: 20 3d 20 73 74 72 64 75 70 28 54 63 6c 5f 47 65 = strdup(Tcl_Ge
0e40: 74 53 74 72 69 6e 67 52 65 73 75 6c 74 28 69 6e tStringResult(in
0e50: 74 65 72 70 29 29 3b 0a 09 09 7d 0a 0a 09 09 54 terp));...}....T
0e60: 63 6c 5f 44 65 6c 65 74 65 49 6e 74 65 72 70 28 cl_DeleteInterp(
0e70: 69 6e 74 65 72 70 29 3b 0a 0a 09 09 72 65 74 75 interp);....retu
0e80: 72 6e 28 4e 55 4c 4c 29 3b 0a 09 7d 0a 0a 09 2f rn(NULL);..}.../
0e90: 2a 0a 09 20 2a 20 4c 6f 61 64 20 22 70 6b 69 2e *.. * Load "pki.
0ea0: 74 63 6c 22 20 69 6e 20 74 68 65 20 73 61 6d 65 tcl" in the same
0eb0: 20 77 61 79 20 61 73 20 61 70 70 66 73 64 2e 74 way as appfsd.t
0ec0: 63 6c 20 28 73 65 65 20 62 65 6c 6f 77 29 0a 09 cl (see below)..
0ed0: 20 2a 2f 0a 09 74 63 6c 5f 72 65 74 20 3d 20 54 */..tcl_ret = T
0ee0: 63 6c 5f 45 76 61 6c 28 69 6e 74 65 72 70 2c 20 cl_Eval(interp,
0ef0: 22 22 0a 23 69 6e 63 6c 75 64 65 20 22 70 6b 69 "".#include "pki
0f00: 2e 74 63 6c 2e 68 22 0a 09 22 22 29 3b 0a 09 69 .tcl.h".."");..i
0f10: 66 20 28 74 63 6c 5f 72 65 74 20 21 3d 20 54 43 f (tcl_ret != TC
0f20: 4c 5f 4f 4b 29 20 7b 0a 09 09 66 70 72 69 6e 74 L_OK) {...fprint
0f30: 66 28 73 74 64 65 72 72 2c 20 22 55 6e 61 62 6c f(stderr, "Unabl
0f40: 65 20 74 6f 20 69 6e 69 74 69 61 6c 69 7a 65 20 e to initialize
0f50: 54 63 6c 20 50 4b 49 2e 20 20 41 62 6f 72 74 69 Tcl PKI. Aborti
0f60: 6e 67 2e 5c 6e 22 29 3b 0a 09 09 66 70 72 69 6e ng.\n");...fprin
0f70: 74 66 28 73 74 64 65 72 72 2c 20 22 54 63 6c 20 tf(stderr, "Tcl
0f80: 45 72 72 6f 72 20 69 73 3a 20 25 73 5c 6e 22 2c Error is: %s\n",
0f90: 20 54 63 6c 5f 47 65 74 53 74 72 69 6e 67 52 65 Tcl_GetStringRe
0fa0: 73 75 6c 74 28 69 6e 74 65 72 70 29 29 3b 0a 0a sult(interp));..
0fb0: 09 09 69 66 20 28 65 72 72 6f 72 5f 73 74 72 69 ..if (error_stri
0fc0: 6e 67 29 20 7b 0a 09 09 09 2a 65 72 72 6f 72 5f ng) {....*error_
0fd0: 73 74 72 69 6e 67 20 3d 20 73 74 72 64 75 70 28 string = strdup(
0fe0: 54 63 6c 5f 47 65 74 53 74 72 69 6e 67 52 65 73 Tcl_GetStringRes
0ff0: 75 6c 74 28 69 6e 74 65 72 70 29 29 3b 0a 09 09 ult(interp));...
1000: 7d 0a 0a 09 09 54 63 6c 5f 44 65 6c 65 74 65 49 }....Tcl_DeleteI
1010: 6e 74 65 72 70 28 69 6e 74 65 72 70 29 3b 0a 0a nterp(interp);..
1020: 09 09 72 65 74 75 72 6e 28 4e 55 4c 4c 29 3b 0a ..return(NULL);.
1030: 09 7d 0a 0a 09 2f 2a 0a 09 20 2a 20 4c 6f 61 64 .}.../*.. * Load
1040: 20 74 68 65 20 22 61 70 70 66 73 64 2e 74 63 6c the "appfsd.tcl
1050: 22 20 73 63 72 69 70 74 2c 20 77 68 69 63 68 20 " script, which
1060: 69 73 20 22 63 6f 6d 70 69 6c 65 64 22 20 69 6e is "compiled" in
1070: 74 6f 20 61 20 43 20 68 65 61 64 65 72 0a 09 20 to a C header..
1080: 2a 20 73 6f 20 74 68 61 74 20 69 74 20 64 6f 65 * so that it doe
1090: 73 20 6e 6f 74 20 6e 65 65 64 20 74 6f 20 65 78 s not need to ex
10a0: 69 73 74 20 6f 6e 20 74 68 65 20 66 69 6c 65 73 ist on the files
10b0: 79 73 74 65 6d 20 61 6e 64 20 63 61 6e 20 62 65 ystem and can be
10c0: 0a 09 20 2a 20 64 69 72 65 63 74 6c 79 20 65 76 .. * directly ev
10d0: 61 6c 75 61 74 65 64 2e 0a 09 20 2a 2f 0a 09 74 aluated... */..t
10e0: 63 6c 5f 72 65 74 20 3d 20 54 63 6c 5f 45 76 61 cl_ret = Tcl_Eva
10f0: 6c 28 69 6e 74 65 72 70 2c 20 22 22 0a 23 69 6e l(interp, "".#in
1100: 63 6c 75 64 65 20 22 61 70 70 66 73 64 2e 74 63 clude "appfsd.tc
1110: 6c 2e 68 22 0a 09 22 22 29 3b 0a 09 69 66 20 28 l.h".."");..if (
1120: 74 63 6c 5f 72 65 74 20 21 3d 20 54 43 4c 5f 4f tcl_ret != TCL_O
1130: 4b 29 20 7b 0a 09 09 66 70 72 69 6e 74 66 28 73 K) {...fprintf(s
1140: 74 64 65 72 72 2c 20 22 55 6e 61 62 6c 65 20 74 tderr, "Unable t
1150: 6f 20 69 6e 69 74 69 61 6c 69 7a 65 20 54 63 6c o initialize Tcl
1160: 20 41 70 70 46 53 20 73 63 72 69 70 74 2e 20 20 AppFS script.
1170: 41 62 6f 72 74 69 6e 67 2e 5c 6e 22 29 3b 0a 09 Aborting.\n");..
1180: 09 66 70 72 69 6e 74 66 28 73 74 64 65 72 72 2c .fprintf(stderr,
1190: 20 22 54 63 6c 20 45 72 72 6f 72 20 69 73 3a 20 "Tcl Error is:
11a0: 25 73 5c 6e 22 2c 20 54 63 6c 5f 47 65 74 53 74 %s\n", Tcl_GetSt
11b0: 72 69 6e 67 52 65 73 75 6c 74 28 69 6e 74 65 72 ringResult(inter
11c0: 70 29 29 3b 0a 0a 09 09 69 66 20 28 65 72 72 6f p));....if (erro
11d0: 72 5f 73 74 72 69 6e 67 29 20 7b 0a 09 09 09 2a r_string) {....*
11e0: 65 72 72 6f 72 5f 73 74 72 69 6e 67 20 3d 20 73 error_string = s
11f0: 74 72 64 75 70 28 54 63 6c 5f 47 65 74 53 74 72 trdup(Tcl_GetStr
1200: 69 6e 67 52 65 73 75 6c 74 28 69 6e 74 65 72 70 ingResult(interp
1210: 29 29 3b 0a 09 09 7d 0a 0a 09 09 54 63 6c 5f 44 ));...}....Tcl_D
1220: 65 6c 65 74 65 49 6e 74 65 72 70 28 69 6e 74 65 eleteInterp(inte
1230: 72 70 29 3b 0a 0a 09 09 72 65 74 75 72 6e 28 4e rp);....return(N
1240: 55 4c 4c 29 3b 0a 09 7d 0a 0a 09 2f 2a 0a 09 20 ULL);..}.../*..
1250: 2a 20 53 65 74 20 67 6c 6f 62 61 6c 20 76 61 72 * Set global var
1260: 69 61 62 6c 65 73 20 66 72 6f 6d 20 43 20 74 6f iables from C to
1270: 20 54 63 6c 0a 09 20 2a 2f 0a 09 69 66 20 28 54 Tcl.. */..if (T
1280: 63 6c 5f 53 65 74 56 61 72 28 69 6e 74 65 72 70 cl_SetVar(interp
1290: 2c 20 22 3a 3a 61 70 70 66 73 3a 3a 63 61 63 68 , "::appfs::cach
12a0: 65 64 69 72 22 2c 20 61 70 70 66 73 5f 63 61 63 edir", appfs_cac
12b0: 68 65 64 69 72 2c 20 54 43 4c 5f 47 4c 4f 42 41 hedir, TCL_GLOBA
12c0: 4c 5f 4f 4e 4c 59 29 20 3d 3d 20 4e 55 4c 4c 29 L_ONLY) == NULL)
12d0: 20 7b 0a 09 09 66 70 72 69 6e 74 66 28 73 74 64 {...fprintf(std
12e0: 65 72 72 2c 20 22 55 6e 61 62 6c 65 20 74 6f 20 err, "Unable to
12f0: 73 65 74 20 63 61 63 68 65 20 64 69 72 65 63 74 set cache direct
1300: 6f 72 79 2e 20 20 54 68 69 73 20 73 68 6f 75 6c ory. This shoul
1310: 64 20 6e 65 76 65 72 20 66 61 69 6c 2e 5c 6e 22 d never fail.\n"
1320: 29 3b 0a 0a 09 09 69 66 20 28 65 72 72 6f 72 5f );....if (error_
1330: 73 74 72 69 6e 67 29 20 7b 0a 09 09 09 2a 65 72 string) {....*er
1340: 72 6f 72 5f 73 74 72 69 6e 67 20 3d 20 73 74 72 ror_string = str
1350: 64 75 70 28 54 63 6c 5f 47 65 74 53 74 72 69 6e dup(Tcl_GetStrin
1360: 67 52 65 73 75 6c 74 28 69 6e 74 65 72 70 29 29 gResult(interp))
1370: 3b 0a 09 09 7d 0a 0a 09 09 54 63 6c 5f 44 65 6c ;...}....Tcl_Del
1380: 65 74 65 49 6e 74 65 72 70 28 69 6e 74 65 72 70 eteInterp(interp
1390: 29 3b 0a 0a 09 09 72 65 74 75 72 6e 28 4e 55 4c );....return(NUL
13a0: 4c 29 3b 0a 09 7d 0a 0a 09 2f 2a 0a 09 20 2a 20 L);..}.../*.. *
13b0: 49 6e 69 74 69 61 6c 69 7a 65 20 74 68 65 20 22 Initialize the "
13c0: 61 70 70 66 73 64 2e 74 63 6c 22 20 65 6e 76 69 appfsd.tcl" envi
13d0: 72 6f 6e 6d 65 6e 74 2c 20 77 68 69 63 68 20 6d ronment, which m
13e0: 75 73 74 20 62 65 20 64 6f 6e 65 20 61 66 74 65 ust be done afte
13f0: 72 0a 09 20 2a 20 67 6c 6f 62 61 6c 20 76 61 72 r.. * global var
1400: 69 61 62 6c 65 73 20 61 72 65 20 73 65 74 2e 0a iables are set..
1410: 09 20 2a 2f 0a 09 74 63 6c 5f 72 65 74 20 3d 20 . */..tcl_ret =
1420: 54 63 6c 5f 45 76 61 6c 28 69 6e 74 65 72 70 2c Tcl_Eval(interp,
1430: 20 22 3a 3a 61 70 70 66 73 3a 3a 69 6e 69 74 22 "::appfs::init"
1440: 29 3b 0a 09 69 66 20 28 74 63 6c 5f 72 65 74 20 );..if (tcl_ret
1450: 21 3d 20 54 43 4c 5f 4f 4b 29 20 7b 0a 09 09 66 != TCL_OK) {...f
1460: 70 72 69 6e 74 66 28 73 74 64 65 72 72 2c 20 22 printf(stderr, "
1470: 55 6e 61 62 6c 65 20 74 6f 20 69 6e 69 74 69 61 Unable to initia
1480: 6c 69 7a 65 20 54 63 6c 20 41 70 70 46 53 20 73 lize Tcl AppFS s
1490: 63 72 69 70 74 20 28 3a 3a 61 70 70 66 73 3a 3a cript (::appfs::
14a0: 69 6e 69 74 29 2e 20 20 41 62 6f 72 74 69 6e 67 init). Aborting
14b0: 2e 5c 6e 22 29 3b 0a 09 09 66 70 72 69 6e 74 66 .\n");...fprintf
14c0: 28 73 74 64 65 72 72 2c 20 22 54 63 6c 20 45 72 (stderr, "Tcl Er
14d0: 72 6f 72 20 69 73 3a 20 25 73 5c 6e 22 2c 20 54 ror is: %s\n", T
14e0: 63 6c 5f 47 65 74 53 74 72 69 6e 67 52 65 73 75 cl_GetStringResu
14f0: 6c 74 28 69 6e 74 65 72 70 29 29 3b 0a 0a 09 09 lt(interp));....
1500: 69 66 20 28 65 72 72 6f 72 5f 73 74 72 69 6e 67 if (error_string
1510: 29 20 7b 0a 09 09 09 2a 65 72 72 6f 72 5f 73 74 ) {....*error_st
1520: 72 69 6e 67 20 3d 20 73 74 72 64 75 70 28 54 63 ring = strdup(Tc
1530: 6c 5f 47 65 74 53 74 72 69 6e 67 52 65 73 75 6c l_GetStringResul
1540: 74 28 69 6e 74 65 72 70 29 29 3b 0a 09 09 7d 0a t(interp));...}.
1550: 0a 09 09 54 63 6c 5f 44 65 6c 65 74 65 49 6e 74 ...Tcl_DeleteInt
1560: 65 72 70 28 69 6e 74 65 72 70 29 3b 0a 0a 09 09 erp(interp);....
1570: 72 65 74 75 72 6e 28 4e 55 4c 4c 29 3b 0a 09 7d return(NULL);..}
1580: 0a 0a 09 2f 2a 0a 09 20 2a 20 48 69 64 65 20 73 .../*.. * Hide s
1590: 6f 6d 65 20 54 63 6c 20 63 6f 6d 6d 61 6e 64 73 ome Tcl commands
15a0: 20 74 68 61 74 20 77 65 20 64 6f 20 6e 6f 74 20 that we do not
15b0: 63 61 72 65 20 74 6f 20 75 73 65 20 61 6e 64 20 care to use and
15c0: 77 68 69 63 68 20 6d 61 79 0a 09 20 2a 20 73 6c which may.. * sl
15d0: 6f 77 20 64 6f 77 6e 20 72 75 6e 2d 74 69 6d 65 ow down run-time
15e0: 20 6f 70 65 72 61 74 69 6f 6e 73 2e 0a 09 20 2a operations... *
15f0: 2f 0a 09 54 63 6c 5f 48 69 64 65 43 6f 6d 6d 61 /..Tcl_HideComma
1600: 6e 64 28 69 6e 74 65 72 70 2c 20 22 61 75 74 6f nd(interp, "auto
1610: 5f 6c 6f 61 64 5f 69 6e 64 65 78 22 2c 20 22 61 _load_index", "a
1620: 75 74 6f 5f 6c 6f 61 64 5f 69 6e 64 65 78 22 29 uto_load_index")
1630: 3b 0a 09 54 63 6c 5f 48 69 64 65 43 6f 6d 6d 61 ;..Tcl_HideComma
1640: 6e 64 28 69 6e 74 65 72 70 2c 20 22 75 6e 6b 6e nd(interp, "unkn
1650: 6f 77 6e 22 2c 20 22 75 6e 6b 6e 6f 77 6e 22 29 own", "unknown")
1660: 3b 0a 0a 09 2f 2a 0a 09 20 2a 20 52 65 74 75 72 ;.../*.. * Retur
1670: 6e 20 74 68 65 20 63 6f 6d 70 6c 65 74 65 6c 79 n the completely
1680: 20 69 6e 69 74 69 61 6c 69 7a 65 64 20 69 6e 74 initialized int
1690: 65 72 70 72 65 74 65 72 0a 09 20 2a 2f 0a 09 72 erpreter.. */..r
16a0: 65 74 75 72 6e 28 69 6e 74 65 72 70 29 3b 0a 7d eturn(interp);.}
16b0: 0a 0a 2f 2a 0a 20 2a 20 52 65 74 75 72 6e 20 74 ../*. * Return t
16c0: 68 65 20 74 68 72 65 61 64 2d 73 70 65 63 69 66 he thread-specif
16d0: 69 63 20 54 63 6c 20 69 6e 74 65 72 70 72 65 74 ic Tcl interpret
16e0: 65 72 2c 20 63 72 65 61 74 69 6e 67 20 69 74 20 er, creating it
16f0: 69 66 20 6e 65 65 64 65 64 0a 20 2a 2f 0a 73 74 if needed. */.st
1700: 61 74 69 63 20 54 63 6c 5f 49 6e 74 65 72 70 20 atic Tcl_Interp
1710: 2a 61 70 70 66 73 5f 54 63 6c 49 6e 74 65 72 70 *appfs_TclInterp
1720: 28 76 6f 69 64 29 20 7b 0a 09 54 63 6c 5f 49 6e (void) {..Tcl_In
1730: 74 65 72 70 20 2a 69 6e 74 65 72 70 3b 0a 09 69 terp *interp;..i
1740: 6e 74 20 70 74 68 72 65 61 64 5f 72 65 74 3b 0a nt pthread_ret;.
1750: 09 73 74 61 74 69 63 20 5f 5f 74 68 72 65 61 64 .static __thread
1760: 20 69 6e 74 20 74 68 72 65 61 64 5f 69 6e 74 65 int thread_inte
1770: 72 70 5f 72 65 73 65 74 5f 6b 65 79 20 3d 20 30 rp_reset_key = 0
1780: 3b 0a 09 69 6e 74 20 67 6c 6f 62 61 6c 5f 69 6e ;..int global_in
1790: 74 65 72 70 5f 72 65 73 65 74 5f 6b 65 79 3b 0a terp_reset_key;.
17a0: 0a 09 67 6c 6f 62 61 6c 5f 69 6e 74 65 72 70 5f ..global_interp_
17b0: 72 65 73 65 74 5f 6b 65 79 20 3d 20 5f 5f 73 79 reset_key = __sy
17c0: 6e 63 5f 66 65 74 63 68 5f 61 6e 64 5f 61 64 64 nc_fetch_and_add
17d0: 28 26 69 6e 74 65 72 70 5f 72 65 73 65 74 5f 6b (&interp_reset_k
17e0: 65 79 2c 20 30 29 3b 0a 0a 09 69 6e 74 65 72 70 ey, 0);...interp
17f0: 20 3d 20 70 74 68 72 65 61 64 5f 67 65 74 73 70 = pthread_getsp
1800: 65 63 69 66 69 63 28 69 6e 74 65 72 70 4b 65 79 ecific(interpKey
1810: 29 3b 0a 09 69 66 20 28 69 6e 74 65 72 70 20 21 );..if (interp !
1820: 3d 20 4e 55 4c 4c 20 26 26 20 74 68 72 65 61 64 = NULL && thread
1830: 5f 69 6e 74 65 72 70 5f 72 65 73 65 74 5f 6b 65 _interp_reset_ke
1840: 79 20 21 3d 20 67 6c 6f 62 61 6c 5f 69 6e 74 65 y != global_inte
1850: 72 70 5f 72 65 73 65 74 5f 6b 65 79 29 20 7b 0a rp_reset_key) {.
1860: 09 09 41 50 50 46 53 5f 44 45 42 55 47 28 22 54 ..APPFS_DEBUG("T
1870: 65 72 6d 69 6e 61 74 69 6e 67 20 6f 6c 64 20 69 erminating old i
1880: 6e 74 65 72 70 72 65 74 65 72 20 61 6e 64 20 72 nterpreter and r
1890: 65 73 74 61 72 74 69 6e 67 20 64 75 65 20 74 6f estarting due to
18a0: 20 72 65 73 65 74 20 72 65 71 75 65 73 74 2e 22 reset request."
18b0: 29 3b 0a 0a 09 09 54 63 6c 5f 44 65 6c 65 74 65 );....Tcl_Delete
18c0: 49 6e 74 65 72 70 28 69 6e 74 65 72 70 29 3b 0a Interp(interp);.
18d0: 0a 09 09 69 6e 74 65 72 70 20 3d 20 4e 55 4c 4c ...interp = NULL
18e0: 3b 0a 0a 09 09 74 68 72 65 61 64 5f 69 6e 74 65 ;....thread_inte
18f0: 72 70 5f 72 65 73 65 74 5f 6b 65 79 20 3d 20 67 rp_reset_key = g
1900: 6c 6f 62 61 6c 5f 69 6e 74 65 72 70 5f 72 65 73 lobal_interp_res
1910: 65 74 5f 6b 65 79 3b 0a 09 7d 0a 0a 09 69 66 20 et_key;..}...if
1920: 28 69 6e 74 65 72 70 20 3d 3d 20 4e 55 4c 4c 29 (interp == NULL)
1930: 20 7b 0a 09 09 69 6e 74 65 72 70 20 3d 20 61 70 {...interp = ap
1940: 70 66 73 5f 63 72 65 61 74 65 5f 54 63 6c 49 6e pfs_create_TclIn
1950: 74 65 72 70 28 4e 55 4c 4c 29 3b 0a 0a 09 09 69 terp(NULL);....i
1960: 66 20 28 69 6e 74 65 72 70 20 3d 3d 20 4e 55 4c f (interp == NUL
1970: 4c 29 20 7b 0a 09 09 09 72 65 74 75 72 6e 28 4e L) {....return(N
1980: 55 4c 4c 29 3b 0a 09 09 7d 0a 0a 09 09 70 74 68 ULL);...}....pth
1990: 72 65 61 64 5f 72 65 74 20 3d 20 70 74 68 72 65 read_ret = pthre
19a0: 61 64 5f 73 65 74 73 70 65 63 69 66 69 63 28 69 ad_setspecific(i
19b0: 6e 74 65 72 70 4b 65 79 2c 20 69 6e 74 65 72 70 nterpKey, interp
19c0: 29 3b 0a 09 09 69 66 20 28 70 74 68 72 65 61 64 );...if (pthread
19d0: 5f 72 65 74 20 21 3d 20 30 29 20 7b 0a 09 09 09 _ret != 0) {....
19e0: 54 63 6c 5f 44 65 6c 65 74 65 49 6e 74 65 72 70 Tcl_DeleteInterp
19f0: 28 69 6e 74 65 72 70 29 3b 0a 0a 09 09 09 72 65 (interp);.....re
1a00: 74 75 72 6e 28 4e 55 4c 4c 29 3b 0a 09 09 7d 0a turn(NULL);...}.
1a10: 09 7d 0a 0a 09 72 65 74 75 72 6e 28 69 6e 74 65 .}...return(inte
1a20: 72 70 29 3b 0a 7d 0a 0a 2f 2a 0a 20 2a 20 45 76 rp);.}../*. * Ev
1a30: 61 6c 75 61 74 65 20 61 20 54 63 6c 20 73 63 72 aluate a Tcl scr
1a40: 69 70 74 20 63 6f 6e 73 74 72 75 63 74 65 64 20 ipt constructed
1a50: 62 79 20 63 6f 6e 63 61 74 65 6e 61 74 69 6e 67 by concatenating
1a60: 20 61 20 62 75 6e 63 68 20 6f 66 20 43 20 73 74 a bunch of C st
1a70: 72 69 6e 67 73 0a 20 2a 20 74 6f 67 65 74 68 65 rings. * togethe
1a80: 72 2e 0a 20 2a 2f 0a 73 74 61 74 69 63 20 69 6e r.. */.static in
1a90: 74 20 61 70 70 66 73 5f 54 63 6c 5f 45 76 61 6c t appfs_Tcl_Eval
1aa0: 28 54 63 6c 5f 49 6e 74 65 72 70 20 2a 69 6e 74 (Tcl_Interp *int
1ab0: 65 72 70 2c 20 69 6e 74 20 6f 62 6a 63 2c 20 63 erp, int objc, c
1ac0: 6f 6e 73 74 20 63 68 61 72 20 2a 63 6d 64 2c 20 onst char *cmd,
1ad0: 2e 2e 2e 29 20 7b 0a 09 54 63 6c 5f 4f 62 6a 20 ...) {..Tcl_Obj
1ae0: 2a 2a 6f 62 6a 76 3b 0a 09 63 6f 6e 73 74 20 63 **objv;..const c
1af0: 68 61 72 20 2a 61 72 67 3b 0a 09 76 61 5f 6c 69 har *arg;..va_li
1b00: 73 74 20 61 72 67 70 3b 0a 09 69 6e 74 20 72 65 st argp;..int re
1b10: 74 76 61 6c 3b 0a 09 69 6e 74 20 69 3b 0a 0a 09 tval;..int i;...
1b20: 69 66 20 28 69 6e 74 65 72 70 20 3d 3d 20 4e 55 if (interp == NU
1b30: 4c 4c 29 20 7b 0a 09 09 72 65 74 75 72 6e 28 54 LL) {...return(T
1b40: 43 4c 5f 45 52 52 4f 52 29 3b 0a 09 7d 0a 0a 09 CL_ERROR);..}...
1b50: 6f 62 6a 76 20 3d 20 28 76 6f 69 64 20 2a 29 20 objv = (void *)
1b60: 63 6b 61 6c 6c 6f 63 28 73 69 7a 65 6f 66 28 2a ckalloc(sizeof(*
1b70: 6f 62 6a 76 29 20 2a 20 6f 62 6a 63 29 3b 0a 09 objv) * objc);..
1b80: 6f 62 6a 76 5b 30 5d 20 3d 20 54 63 6c 5f 4e 65 objv[0] = Tcl_Ne
1b90: 77 53 74 72 69 6e 67 4f 62 6a 28 63 6d 64 2c 20 wStringObj(cmd,
1ba0: 2d 31 29 3b 0a 09 54 63 6c 5f 49 6e 63 72 52 65 -1);..Tcl_IncrRe
1bb0: 66 43 6f 75 6e 74 28 6f 62 6a 76 5b 30 5d 29 3b fCount(objv[0]);
1bc0: 0a 0a 09 76 61 5f 73 74 61 72 74 28 61 72 67 70 ...va_start(argp
1bd0: 2c 20 63 6d 64 29 3b 0a 09 66 6f 72 20 28 69 20 , cmd);..for (i
1be0: 3d 20 31 3b 20 69 20 3c 20 6f 62 6a 63 3b 20 69 = 1; i < objc; i
1bf0: 2b 2b 29 20 7b 0a 09 09 61 72 67 20 3d 20 76 61 ++) {...arg = va
1c00: 5f 61 72 67 28 61 72 67 70 2c 20 63 6f 6e 73 74 _arg(argp, const
1c10: 20 63 68 61 72 20 2a 29 3b 0a 09 09 6f 62 6a 76 char *);...objv
1c20: 5b 69 5d 20 3d 20 54 63 6c 5f 4e 65 77 53 74 72 [i] = Tcl_NewStr
1c30: 69 6e 67 4f 62 6a 28 61 72 67 2c 20 2d 31 29 3b ingObj(arg, -1);
1c40: 0a 09 09 54 63 6c 5f 49 6e 63 72 52 65 66 43 6f ...Tcl_IncrRefCo
1c50: 75 6e 74 28 6f 62 6a 76 5b 69 5d 29 3b 0a 09 7d unt(objv[i]);..}
1c60: 0a 09 76 61 5f 65 6e 64 28 61 72 67 70 29 3b 0a ..va_end(argp);.
1c70: 0a 09 72 65 74 76 61 6c 20 3d 20 54 63 6c 5f 45 ..retval = Tcl_E
1c80: 76 61 6c 4f 62 6a 76 28 69 6e 74 65 72 70 2c 20 valObjv(interp,
1c90: 6f 62 6a 63 2c 20 6f 62 6a 76 2c 20 30 29 3b 0a objc, objv, 0);.
1ca0: 0a 09 66 6f 72 20 28 69 20 3d 20 30 3b 20 69 20 ..for (i = 0; i
1cb0: 3c 20 6f 62 6a 63 3b 20 69 2b 2b 29 20 7b 0a 09 < objc; i++) {..
1cc0: 09 54 63 6c 5f 44 65 63 72 52 65 66 43 6f 75 6e .Tcl_DecrRefCoun
1cd0: 74 28 6f 62 6a 76 5b 69 5d 29 3b 0a 09 7d 0a 0a t(objv[i]);..}..
1ce0: 09 63 6b 66 72 65 65 28 28 76 6f 69 64 20 2a 29 .ckfree((void *)
1cf0: 20 6f 62 6a 76 29 3b 0a 0a 09 69 66 20 28 72 65 objv);...if (re
1d00: 74 76 61 6c 20 21 3d 20 54 43 4c 5f 4f 4b 29 20 tval != TCL_OK)
1d10: 7b 0a 09 09 41 50 50 46 53 5f 44 45 42 55 47 28 {...APPFS_DEBUG(
1d20: 22 54 63 6c 20 63 6f 6d 6d 61 6e 64 20 66 61 69 "Tcl command fai
1d30: 6c 65 64 2c 20 3a 3a 65 72 72 6f 72 49 6e 66 6f led, ::errorInfo
1d40: 20 63 6f 6e 74 61 69 6e 73 3a 20 25 73 5c 6e 22 contains: %s\n"
1d50: 2c 20 54 63 6c 5f 47 65 74 56 61 72 28 69 6e 74 , Tcl_GetVar(int
1d60: 65 72 70 2c 20 22 3a 3a 65 72 72 6f 72 49 6e 66 erp, "::errorInf
1d70: 6f 22 2c 20 30 29 29 3b 0a 09 7d 0a 0a 09 72 65 o", 0));..}...re
1d80: 74 75 72 6e 28 72 65 74 76 61 6c 29 3b 0a 7d 0a turn(retval);.}.
1d90: 0a 2f 2a 0a 20 2a 20 52 65 71 75 65 73 74 20 61 ./*. * Request a
1da0: 6c 6c 20 54 63 6c 20 69 6e 74 65 72 70 72 65 74 ll Tcl interpret
1db0: 65 72 73 20 72 65 73 74 61 72 74 0a 20 2a 2f 0a ers restart. */.
1dc0: 73 74 61 74 69 63 20 76 6f 69 64 20 61 70 70 66 static void appf
1dd0: 73 5f 74 63 6c 5f 52 65 73 65 74 49 6e 74 65 72 s_tcl_ResetInter
1de0: 70 73 28 76 6f 69 64 29 20 7b 0a 09 41 50 50 46 ps(void) {..APPF
1df0: 53 5f 44 45 42 55 47 28 22 52 65 71 75 65 73 74 S_DEBUG("Request
1e00: 69 6e 67 20 72 65 73 65 74 20 6f 66 20 61 6c 6c ing reset of all
1e10: 20 69 6e 74 65 72 70 72 65 74 65 72 73 2e 22 29 interpreters.")
1e20: 3b 0a 0a 09 5f 5f 73 79 6e 63 5f 61 64 64 5f 61 ;...__sync_add_a
1e30: 6e 64 5f 66 65 74 63 68 28 26 69 6e 74 65 72 70 nd_fetch(&interp
1e40: 5f 72 65 73 65 74 5f 6b 65 79 2c 20 31 29 3b 0a _reset_key, 1);.
1e50: 0a 09 72 65 74 75 72 6e 3b 0a 7d 0a 0a 2f 2a 0a ..return;.}../*.
1e60: 20 2a 20 44 65 74 65 72 6d 69 6e 65 20 74 68 65 * Determine the
1e70: 20 55 49 44 20 66 6f 72 20 74 68 65 20 75 73 65 UID for the use
1e80: 72 20 6d 61 6b 69 6e 67 20 74 68 65 20 63 75 72 r making the cur
1e90: 72 65 6e 74 20 46 55 53 45 20 66 69 6c 65 73 79 rent FUSE filesy
1ea0: 73 74 65 6d 20 72 65 71 75 65 73 74 2e 0a 20 2a stem request.. *
1eb0: 20 54 68 69 73 20 77 69 6c 6c 20 62 65 20 75 73 This will be us
1ec0: 65 64 20 74 6f 20 6c 6f 6f 6b 75 70 20 74 68 65 ed to lookup the
1ed0: 20 75 73 65 72 27 73 20 68 6f 6d 65 20 64 69 72 user's home dir
1ee0: 65 63 74 6f 72 79 20 73 6f 20 77 65 20 63 61 6e ectory so we can
1ef0: 20 73 65 61 72 63 68 20 66 6f 72 0a 20 2a 20 6c search for. * l
1f00: 6f 63 61 6c 6c 79 20 6d 6f 64 69 66 69 65 64 20 ocally modified
1f10: 66 69 6c 65 73 2e 0a 20 2a 2f 0a 73 74 61 74 69 files.. */.stati
1f20: 63 20 75 69 64 5f 74 20 61 70 70 66 73 5f 67 65 c uid_t appfs_ge
1f30: 74 5f 66 73 75 69 64 28 76 6f 69 64 29 20 7b 0a t_fsuid(void) {.
1f40: 09 73 74 72 75 63 74 20 66 75 73 65 5f 63 6f 6e .struct fuse_con
1f50: 74 65 78 74 20 2a 63 74 78 3b 0a 0a 09 69 66 20 text *ctx;...if
1f60: 28 21 61 70 70 66 73 5f 66 75 73 65 5f 73 74 61 (!appfs_fuse_sta
1f70: 72 74 65 64 29 20 7b 0a 09 09 72 65 74 75 72 6e rted) {...return
1f80: 28 67 65 74 75 69 64 28 29 29 3b 0a 09 7d 0a 0a (getuid());..}..
1f90: 09 63 74 78 20 3d 20 66 75 73 65 5f 67 65 74 5f .ctx = fuse_get_
1fa0: 63 6f 6e 74 65 78 74 28 29 3b 0a 09 69 66 20 28 context();..if (
1fb0: 63 74 78 20 3d 3d 20 4e 55 4c 4c 29 20 7b 0a 09 ctx == NULL) {..
1fc0: 09 2f 2a 20 55 6e 61 62 6c 65 20 74 6f 20 6c 6f ./* Unable to lo
1fd0: 6f 6b 75 70 20 75 73 65 72 20 66 6f 72 20 73 6f okup user for so
1fe0: 6d 65 20 72 65 61 73 6f 6e 20 2a 2f 0a 09 09 2f me reason */.../
1ff0: 2a 20 52 65 74 75 72 6e 20 61 6e 20 75 6e 70 72 * Return an unpr
2000: 69 76 69 6c 65 67 65 64 20 75 73 65 72 20 49 44 ivileged user ID
2010: 20 2a 2f 0a 09 09 72 65 74 75 72 6e 28 31 29 3b */...return(1);
2020: 0a 09 7d 0a 0a 09 72 65 74 75 72 6e 28 63 74 78 ..}...return(ctx
2030: 2d 3e 75 69 64 29 3b 0a 7d 0a 0a 2f 2a 0a 20 2a ->uid);.}../*. *
2040: 20 44 65 74 65 72 6d 69 6e 65 20 74 68 65 20 47 Determine the G
2050: 49 44 20 66 6f 72 20 74 68 65 20 75 73 65 72 20 ID for the user
2060: 6d 61 6b 69 6e 67 20 74 68 65 20 63 75 72 72 65 making the curre
2070: 6e 74 20 46 55 53 45 20 66 69 6c 65 73 79 73 74 nt FUSE filesyst
2080: 65 6d 20 72 65 71 75 65 73 74 2e 0a 20 2a 20 54 em request.. * T
2090: 68 69 73 20 77 69 6c 6c 20 62 65 20 75 73 65 64 his will be used
20a0: 20 74 6f 20 6c 6f 6f 6b 75 70 20 74 68 65 20 75 to lookup the u
20b0: 73 65 72 27 73 20 68 6f 6d 65 20 64 69 72 65 63 ser's home direc
20c0: 74 6f 72 79 20 73 6f 20 77 65 20 63 61 6e 20 73 tory so we can s
20d0: 65 61 72 63 68 20 66 6f 72 0a 20 2a 20 6c 6f 63 earch for. * loc
20e0: 61 6c 6c 79 20 6d 6f 64 69 66 69 65 64 20 66 69 ally modified fi
20f0: 6c 65 73 2e 0a 20 2a 2f 0a 73 74 61 74 69 63 20 les.. */.static
2100: 67 69 64 5f 74 20 61 70 70 66 73 5f 67 65 74 5f gid_t appfs_get_
2110: 66 73 67 69 64 28 76 6f 69 64 29 20 7b 0a 09 73 fsgid(void) {..s
2120: 74 72 75 63 74 20 66 75 73 65 5f 63 6f 6e 74 65 truct fuse_conte
2130: 78 74 20 2a 63 74 78 3b 0a 0a 09 69 66 20 28 21 xt *ctx;...if (!
2140: 61 70 70 66 73 5f 66 75 73 65 5f 73 74 61 72 74 appfs_fuse_start
2150: 65 64 29 20 7b 0a 09 09 72 65 74 75 72 6e 28 67 ed) {...return(g
2160: 65 74 67 69 64 28 29 29 3b 0a 09 7d 0a 0a 09 63 etgid());..}...c
2170: 74 78 20 3d 20 66 75 73 65 5f 67 65 74 5f 63 6f tx = fuse_get_co
2180: 6e 74 65 78 74 28 29 3b 0a 09 69 66 20 28 63 74 ntext();..if (ct
2190: 78 20 3d 3d 20 4e 55 4c 4c 29 20 7b 0a 09 09 2f x == NULL) {.../
21a0: 2a 20 55 6e 61 62 6c 65 20 74 6f 20 6c 6f 6f 6b * Unable to look
21b0: 75 70 20 75 73 65 72 20 66 6f 72 20 73 6f 6d 65 up user for some
21c0: 20 72 65 61 73 6f 6e 20 2a 2f 0a 09 09 2f 2a 20 reason */.../*
21d0: 52 65 74 75 72 6e 20 61 6e 20 75 6e 70 72 69 76 Return an unpriv
21e0: 69 6c 65 67 65 64 20 75 73 65 72 20 49 44 20 2a ileged user ID *
21f0: 2f 0a 09 09 72 65 74 75 72 6e 28 31 29 3b 0a 09 /...return(1);..
2200: 7d 0a 0a 09 72 65 74 75 72 6e 28 63 74 78 2d 3e }...return(ctx->
2210: 67 69 64 29 3b 0a 7d 0a 0a 73 74 61 74 69 63 20 gid);.}..static
2220: 76 6f 69 64 20 61 70 70 66 73 5f 73 69 6d 75 6c void appfs_simul
2230: 61 74 65 5f 75 73 65 72 5f 66 73 5f 65 6e 74 65 ate_user_fs_ente
2240: 72 28 76 6f 69 64 29 20 7b 0a 09 73 65 74 66 73 r(void) {..setfs
2250: 75 69 64 28 61 70 70 66 73 5f 67 65 74 5f 66 73 uid(appfs_get_fs
2260: 75 69 64 28 29 29 3b 0a 09 73 65 74 66 73 67 69 uid());..setfsgi
2270: 64 28 61 70 70 66 73 5f 67 65 74 5f 66 73 67 69 d(appfs_get_fsgi
2280: 64 28 29 29 3b 0a 7d 0a 0a 73 74 61 74 69 63 20 d());.}..static
2290: 76 6f 69 64 20 61 70 70 66 73 5f 73 69 6d 75 6c void appfs_simul
22a0: 61 74 65 5f 75 73 65 72 5f 66 73 5f 6c 65 61 76 ate_user_fs_leav
22b0: 65 28 76 6f 69 64 29 20 7b 0a 09 73 65 74 66 73 e(void) {..setfs
22c0: 75 69 64 28 30 29 3b 0a 09 73 65 74 66 73 67 69 uid(0);..setfsgi
22d0: 64 28 30 29 3b 0a 7d 0a 0a 2f 2a 0a 20 2a 20 4c d(0);.}../*. * L
22e0: 6f 6f 6b 20 75 70 20 74 68 65 20 68 6f 6d 65 20 ook up the home
22f0: 64 69 72 65 63 74 6f 72 79 20 66 6f 72 20 61 20 directory for a
2300: 67 69 76 65 6e 20 55 49 44 0a 20 2a 20 20 20 20 given UID. *
2310: 20 20 20 20 52 65 74 75 72 6e 73 20 61 20 43 20 Returns a C
2320: 73 74 72 69 6e 67 20 63 6f 6e 74 61 69 6e 69 6e string containin
2330: 67 20 74 68 65 20 75 73 65 72 27 73 20 68 6f 6d g the user's hom
2340: 65 20 64 69 72 65 63 74 6f 72 79 20 6f 72 20 4e e directory or N
2350: 55 4c 4c 20 69 66 0a 20 2a 20 20 20 20 20 20 20 ULL if. *
2360: 20 74 68 65 20 75 73 65 72 27 73 20 68 6f 6d 65 the user's home
2370: 20 64 69 72 65 63 74 6f 72 79 20 64 6f 65 73 20 directory does
2380: 6e 6f 74 20 65 78 69 73 74 20 6f 72 20 69 73 20 not exist or is
2390: 6e 6f 74 20 63 6f 72 72 65 63 74 6c 79 0a 20 2a not correctly. *
23a0: 20 20 20 20 20 20 20 20 63 6f 6e 66 69 67 75 72 configur
23b0: 65 64 0a 20 2a 2f 0a 73 74 61 74 69 63 20 63 68 ed. */.static ch
23c0: 61 72 20 2a 61 70 70 66 73 5f 67 65 74 5f 68 6f ar *appfs_get_ho
23d0: 6d 65 64 69 72 28 75 69 64 5f 74 20 66 73 75 69 medir(uid_t fsui
23e0: 64 29 20 7b 0a 09 73 74 72 75 63 74 20 70 61 73 d) {..struct pas
23f0: 73 77 64 20 65 6e 74 72 79 2c 20 2a 72 65 73 75 swd entry, *resu
2400: 6c 74 3b 0a 09 73 74 72 75 63 74 20 73 74 61 74 lt;..struct stat
2410: 20 73 74 62 75 66 3b 0a 09 63 68 61 72 20 62 75 stbuf;..char bu
2420: 66 5b 31 30 32 34 5d 2c 20 2a 72 65 74 76 61 6c f[1024], *retval
2430: 3b 0a 09 69 6e 74 20 67 70 75 5f 72 65 74 2c 20 ;..int gpu_ret,
2440: 73 74 61 74 5f 72 65 74 3b 0a 0a 09 67 70 75 5f stat_ret;...gpu_
2450: 72 65 74 20 3d 20 67 65 74 70 77 75 69 64 5f 72 ret = getpwuid_r
2460: 28 66 73 75 69 64 2c 20 26 65 6e 74 72 79 2c 20 (fsuid, &entry,
2470: 62 75 66 2c 20 73 69 7a 65 6f 66 28 62 75 66 29 buf, sizeof(buf)
2480: 2c 20 26 72 65 73 75 6c 74 29 3b 0a 09 69 66 20 , &result);..if
2490: 28 67 70 75 5f 72 65 74 20 21 3d 20 30 29 20 7b (gpu_ret != 0) {
24a0: 0a 09 09 41 50 50 46 53 5f 44 45 42 55 47 28 22 ...APPFS_DEBUG("
24b0: 67 65 74 70 77 75 69 64 5f 72 28 25 6c 6c 75 2c getpwuid_r(%llu,
24c0: 20 2e 2e 2e 29 20 72 65 74 75 72 6e 65 64 20 69 ...) returned i
24d0: 6e 20 66 61 69 6c 75 72 65 22 2c 20 28 75 6e 73 n failure", (uns
24e0: 69 67 6e 65 64 20 6c 6f 6e 67 20 6c 6f 6e 67 29 igned long long)
24f0: 20 66 73 75 69 64 29 3b 0a 0a 09 09 72 65 74 75 fsuid);....retu
2500: 72 6e 28 4e 55 4c 4c 29 3b 0a 09 7d 0a 0a 09 69 rn(NULL);..}...i
2510: 66 20 28 72 65 73 75 6c 74 20 3d 3d 20 4e 55 4c f (result == NUL
2520: 4c 29 20 7b 0a 09 09 41 50 50 46 53 5f 44 45 42 L) {...APPFS_DEB
2530: 55 47 28 22 67 65 74 70 77 75 69 64 5f 72 28 25 UG("getpwuid_r(%
2540: 6c 6c 75 2c 20 2e 2e 2e 29 20 72 65 74 75 72 6e llu, ...) return
2550: 65 64 20 4e 55 4c 4c 20 72 65 73 75 6c 74 22 2c ed NULL result",
2560: 20 28 75 6e 73 69 67 6e 65 64 20 6c 6f 6e 67 20 (unsigned long
2570: 6c 6f 6e 67 29 20 66 73 75 69 64 29 3b 0a 0a 09 long) fsuid);...
2580: 09 72 65 74 75 72 6e 28 4e 55 4c 4c 29 3b 0a 09 .return(NULL);..
2590: 7d 0a 0a 09 69 66 20 28 72 65 73 75 6c 74 2d 3e }...if (result->
25a0: 70 77 5f 64 69 72 20 3d 3d 20 4e 55 4c 4c 29 20 pw_dir == NULL)
25b0: 7b 0a 09 09 41 50 50 46 53 5f 44 45 42 55 47 28 {...APPFS_DEBUG(
25c0: 22 67 65 74 70 77 75 69 64 5f 72 28 25 6c 6c 75 "getpwuid_r(%llu
25d0: 2c 20 2e 2e 2e 29 20 72 65 74 75 72 6e 65 64 20 , ...) returned
25e0: 4e 55 4c 4c 20 68 6f 6d 65 20 64 69 72 65 63 74 NULL home direct
25f0: 6f 72 79 22 2c 20 28 75 6e 73 69 67 6e 65 64 20 ory", (unsigned
2600: 6c 6f 6e 67 20 6c 6f 6e 67 29 20 66 73 75 69 64 long long) fsuid
2610: 29 3b 0a 0a 09 09 72 65 74 75 72 6e 28 4e 55 4c );....return(NUL
2620: 4c 29 3b 0a 09 7d 0a 0a 09 73 74 61 74 5f 72 65 L);..}...stat_re
2630: 74 20 3d 20 73 74 61 74 28 72 65 73 75 6c 74 2d t = stat(result-
2640: 3e 70 77 5f 64 69 72 2c 20 26 73 74 62 75 66 29 >pw_dir, &stbuf)
2650: 3b 0a 09 69 66 20 28 73 74 61 74 5f 72 65 74 20 ;..if (stat_ret
2660: 21 3d 20 30 29 20 7b 0a 09 09 41 50 50 46 53 5f != 0) {...APPFS_
2670: 44 45 42 55 47 28 22 73 74 61 74 28 25 73 29 20 DEBUG("stat(%s)
2680: 72 65 74 75 72 6e 65 64 20 69 6e 20 66 61 69 6c returned in fail
2690: 75 72 65 22 2c 20 72 65 73 75 6c 74 2d 3e 70 77 ure", result->pw
26a0: 5f 64 69 72 29 3b 0a 0a 09 09 72 65 74 75 72 6e _dir);....return
26b0: 28 4e 55 4c 4c 29 3b 0a 09 7d 0a 0a 09 69 66 20 (NULL);..}...if
26c0: 28 73 74 62 75 66 2e 73 74 5f 75 69 64 20 21 3d (stbuf.st_uid !=
26d0: 20 66 73 75 69 64 29 20 7b 0a 09 09 41 50 50 46 fsuid) {...APPF
26e0: 53 5f 44 45 42 55 47 28 22 55 49 44 20 6d 69 73 S_DEBUG("UID mis
26f0: 2d 6d 61 74 63 68 20 6f 6e 20 75 73 65 72 20 25 -match on user %
2700: 6c 6c 75 27 73 20 68 6f 6d 65 20 64 69 72 65 63 llu's home direc
2710: 74 6f 72 79 20 28 25 73 29 2e 20 20 49 74 27 73 tory (%s). It's
2720: 20 6f 77 6e 65 64 20 62 79 20 25 6c 6c 75 2e 22 owned by %llu."
2730: 2c 0a 09 09 20 20 20 20 28 75 6e 73 69 67 6e 65 ,... (unsigne
2740: 64 20 6c 6f 6e 67 20 6c 6f 6e 67 29 20 66 73 75 d long long) fsu
2750: 69 64 2c 0a 09 09 20 20 20 20 72 65 73 75 6c 74 id,... result
2760: 2d 3e 70 77 5f 64 69 72 2c 0a 09 09 20 20 20 20 ->pw_dir,...
2770: 28 75 6e 73 69 67 6e 65 64 20 6c 6f 6e 67 20 6c (unsigned long l
2780: 6f 6e 67 29 20 73 74 62 75 66 2e 73 74 5f 75 69 ong) stbuf.st_ui
2790: 64 0a 09 09 29 3b 0a 0a 09 09 72 65 74 75 72 6e d...);....return
27a0: 28 4e 55 4c 4c 29 3b 0a 09 7d 0a 0a 09 72 65 74 (NULL);..}...ret
27b0: 76 61 6c 20 3d 20 73 74 72 64 75 70 28 72 65 73 val = strdup(res
27c0: 75 6c 74 2d 3e 70 77 5f 64 69 72 29 3b 0a 0a 09 ult->pw_dir);...
27d0: 72 65 74 75 72 6e 28 72 65 74 76 61 6c 29 3b 0a return(retval);.
27e0: 7d 0a 0a 2f 2a 0a 20 2a 20 47 65 6e 65 72 61 74 }../*. * Generat
27f0: 65 20 61 6e 20 69 6e 6f 64 65 20 66 6f 72 20 61 e an inode for a
2800: 20 67 69 76 65 6e 20 70 61 74 68 2e 20 20 54 68 given path. Th
2810: 65 20 69 6e 6f 64 65 20 73 68 6f 75 6c 64 20 62 e inode should b
2820: 65 20 63 6f 6d 70 75 74 65 64 20 69 6e 20 73 75 e computed in su
2830: 63 68 0a 20 2a 20 61 20 77 61 79 20 74 68 61 74 ch. * a way that
2840: 20 69 74 20 69 73 20 75 6e 6c 69 6b 65 6c 79 20 it is unlikely
2850: 74 6f 20 62 65 20 64 75 70 6c 69 63 61 74 65 64 to be duplicated
2860: 20 61 6e 64 20 72 65 6d 61 69 6e 73 20 74 68 65 and remains the
2870: 20 73 61 6d 65 20 66 6f 72 20 61 20 67 69 76 65 same for a give
2880: 6e 0a 20 2a 20 66 69 6c 65 0a 20 2a 2f 0a 73 74 n. * file. */.st
2890: 61 74 69 63 20 6c 6f 6e 67 20 6c 6f 6e 67 20 61 atic long long a
28a0: 70 70 66 73 5f 67 65 74 5f 70 61 74 68 5f 69 6e ppfs_get_path_in
28b0: 6f 64 65 28 63 6f 6e 73 74 20 63 68 61 72 20 2a ode(const char *
28c0: 70 61 74 68 29 20 7b 0a 09 6c 6f 6e 67 20 6c 6f path) {..long lo
28d0: 6e 67 20 72 65 74 76 61 6c 3b 0a 09 63 6f 6e 73 ng retval;..cons
28e0: 74 20 63 68 61 72 20 2a 70 3b 0a 0a 09 72 65 74 t char *p;...ret
28f0: 76 61 6c 20 3d 20 31 30 3b 0a 0a 09 66 6f 72 20 val = 10;...for
2900: 28 70 20 3d 20 70 61 74 68 3b 20 2a 70 3b 20 70 (p = path; *p; p
2910: 2b 2b 29 20 7b 0a 09 09 72 65 74 76 61 6c 20 25 ++) {...retval %
2920: 3d 20 34 32 39 30 39 36 30 32 39 30 55 4c 4c 3b = 4290960290ULL;
2930: 0a 09 09 72 65 74 76 61 6c 20 2b 3d 20 2a 70 3b ...retval += *p;
2940: 0a 09 09 72 65 74 76 61 6c 20 3c 3c 3d 20 37 3b ...retval <<= 7;
2950: 0a 09 7d 0a 0a 09 72 65 74 76 61 6c 20 2b 3d 20 ..}...retval +=
2960: 31 30 3b 0a 09 72 65 74 76 61 6c 20 25 3d 20 34 10;..retval %= 4
2970: 32 39 34 39 36 37 32 39 36 55 4c 4c 3b 0a 0a 09 294967296ULL;...
2980: 72 65 74 75 72 6e 28 72 65 74 76 61 6c 29 3b 0a return(retval);.
2990: 7d 0a 0a 2f 2a 0a 20 2a 20 43 61 63 68 65 20 47 }../*. * Cache G
29a0: 65 74 20 50 61 74 68 20 49 6e 66 6f 20 6c 6f 6f et Path Info loo
29b0: 6b 75 70 73 20 66 6f 72 20 73 70 65 65 64 0a 20 kups for speed.
29c0: 2a 2f 0a 73 74 61 74 69 63 20 69 6e 74 20 61 70 */.static int ap
29d0: 70 66 73 5f 67 65 74 5f 70 61 74 68 5f 69 6e 66 pfs_get_path_inf
29e0: 6f 5f 63 61 63 68 65 5f 67 65 74 28 63 6f 6e 73 o_cache_get(cons
29f0: 74 20 63 68 61 72 20 2a 70 61 74 68 2c 20 75 69 t char *path, ui
2a00: 64 5f 74 20 75 69 64 2c 20 73 74 72 75 63 74 20 d_t uid, struct
2a10: 61 70 70 66 73 5f 70 61 74 68 69 6e 66 6f 20 2a appfs_pathinfo *
2a20: 70 61 74 68 69 6e 66 6f 29 20 7b 0a 09 75 6e 73 pathinfo) {..uns
2a30: 69 67 6e 65 64 20 69 6e 74 20 68 61 73 68 5f 69 igned int hash_i
2a40: 64 78 3b 0a 09 69 6e 74 20 70 74 68 72 65 61 64 dx;..int pthread
2a50: 5f 72 65 74 3b 0a 09 69 6e 74 20 72 65 74 76 61 _ret;..int retva
2a60: 6c 3b 0a 0a 09 72 65 74 76 61 6c 20 3d 20 31 3b l;...retval = 1;
2a70: 0a 0a 09 70 74 68 72 65 61 64 5f 72 65 74 20 3d ...pthread_ret =
2a80: 20 70 74 68 72 65 61 64 5f 6d 75 74 65 78 5f 6c pthread_mutex_l
2a90: 6f 63 6b 28 26 61 70 70 66 73 5f 70 61 74 68 5f ock(&appfs_path_
2aa0: 69 6e 66 6f 5f 63 61 63 68 65 5f 6d 75 74 65 78 info_cache_mutex
2ab0: 29 3b 0a 09 69 66 20 28 70 74 68 72 65 61 64 5f );..if (pthread_
2ac0: 72 65 74 20 21 3d 20 30 29 20 7b 0a 09 09 41 50 ret != 0) {...AP
2ad0: 50 46 53 5f 44 45 42 55 47 28 22 55 6e 61 62 6c PFS_DEBUG("Unabl
2ae0: 65 20 74 6f 20 6c 6f 63 6b 20 70 61 74 68 5f 69 e to lock path_i
2af0: 6e 66 6f 20 63 61 63 68 65 20 6d 75 74 65 78 20 nfo cache mutex
2b00: 21 22 29 3b 0a 0a 09 09 72 65 74 75 72 6e 28 2d !");....return(-
2b10: 31 29 3b 0a 09 7d 0a 0a 09 69 66 20 28 61 70 70 1);..}...if (app
2b20: 66 73 5f 70 61 74 68 5f 69 6e 66 6f 5f 63 61 63 fs_path_info_cac
2b30: 68 65 20 21 3d 20 4e 55 4c 4c 29 20 7b 0a 09 09 he != NULL) {...
2b40: 68 61 73 68 5f 69 64 78 20 3d 20 28 61 70 70 66 hash_idx = (appf
2b50: 73 5f 67 65 74 5f 70 61 74 68 5f 69 6e 6f 64 65 s_get_path_inode
2b60: 28 70 61 74 68 29 20 2b 20 75 69 64 29 20 25 20 (path) + uid) %
2b70: 61 70 70 66 73 5f 70 61 74 68 5f 69 6e 66 6f 5f appfs_path_info_
2b80: 63 61 63 68 65 5f 73 69 7a 65 3b 0a 0a 09 09 69 cache_size;....i
2b90: 66 20 28 61 70 70 66 73 5f 70 61 74 68 5f 69 6e f (appfs_path_in
2ba0: 66 6f 5f 63 61 63 68 65 5b 68 61 73 68 5f 69 64 fo_cache[hash_id
2bb0: 78 5d 2e 5f 63 61 63 68 65 5f 70 61 74 68 20 21 x]._cache_path !
2bc0: 3d 20 4e 55 4c 4c 29 20 7b 0a 09 09 09 69 66 20 = NULL) {....if
2bd0: 28 73 74 72 63 6d 70 28 61 70 70 66 73 5f 70 61 (strcmp(appfs_pa
2be0: 74 68 5f 69 6e 66 6f 5f 63 61 63 68 65 5b 68 61 th_info_cache[ha
2bf0: 73 68 5f 69 64 78 5d 2e 5f 63 61 63 68 65 5f 70 sh_idx]._cache_p
2c00: 61 74 68 2c 20 70 61 74 68 29 20 3d 3d 20 30 20 ath, path) == 0
2c10: 26 26 20 61 70 70 66 73 5f 70 61 74 68 5f 69 6e && appfs_path_in
2c20: 66 6f 5f 63 61 63 68 65 5b 68 61 73 68 5f 69 64 fo_cache[hash_id
2c30: 78 5d 2e 5f 63 61 63 68 65 5f 75 69 64 20 3d 3d x]._cache_uid ==
2c40: 20 75 69 64 29 20 7b 0a 09 09 09 09 72 65 74 76 uid) {.....retv
2c50: 61 6c 20 3d 20 30 3b 0a 0a 09 09 09 09 6d 65 6d al = 0;......mem
2c60: 63 70 79 28 70 61 74 68 69 6e 66 6f 2c 20 26 61 cpy(pathinfo, &a
2c70: 70 70 66 73 5f 70 61 74 68 5f 69 6e 66 6f 5f 63 ppfs_path_info_c
2c80: 61 63 68 65 5b 68 61 73 68 5f 69 64 78 5d 2c 20 ache[hash_idx],
2c90: 73 69 7a 65 6f 66 28 2a 70 61 74 68 69 6e 66 6f sizeof(*pathinfo
2ca0: 29 29 3b 0a 09 09 09 09 70 61 74 68 69 6e 66 6f ));.....pathinfo
2cb0: 2d 3e 5f 63 61 63 68 65 5f 70 61 74 68 20 3d 20 ->_cache_path =
2cc0: 4e 55 4c 4c 3b 0a 09 09 09 7d 0a 09 09 7d 0a 09 NULL;....}...}..
2cd0: 7d 0a 0a 09 70 74 68 72 65 61 64 5f 72 65 74 20 }...pthread_ret
2ce0: 3d 20 70 74 68 72 65 61 64 5f 6d 75 74 65 78 5f = pthread_mutex_
2cf0: 75 6e 6c 6f 63 6b 28 26 61 70 70 66 73 5f 70 61 unlock(&appfs_pa
2d00: 74 68 5f 69 6e 66 6f 5f 63 61 63 68 65 5f 6d 75 th_info_cache_mu
2d10: 74 65 78 29 3b 0a 09 69 66 20 28 70 74 68 72 65 tex);..if (pthre
2d20: 61 64 5f 72 65 74 20 21 3d 20 30 29 20 7b 0a 09 ad_ret != 0) {..
2d30: 09 41 50 50 46 53 5f 44 45 42 55 47 28 22 55 6e .APPFS_DEBUG("Un
2d40: 61 62 6c 65 20 74 6f 20 75 6e 6c 6f 63 6b 20 70 able to unlock p
2d50: 61 74 68 5f 69 6e 66 6f 20 63 61 63 68 65 20 6d ath_info cache m
2d60: 75 74 65 78 20 21 22 29 3b 0a 0a 09 09 72 65 74 utex !");....ret
2d70: 75 72 6e 28 2d 31 29 3b 0a 09 7d 0a 0a 09 69 66 urn(-1);..}...if
2d80: 20 28 72 65 74 76 61 6c 20 3d 3d 20 30 29 20 7b (retval == 0) {
2d90: 0a 09 09 41 50 50 46 53 5f 44 45 42 55 47 28 22 ...APPFS_DEBUG("
2da0: 43 61 63 68 65 20 68 69 74 20 6f 6e 20 25 73 22 Cache hit on %s"
2db0: 2c 20 70 61 74 68 29 3b 0a 09 7d 20 65 6c 73 65 , path);..} else
2dc0: 20 7b 0a 09 09 41 50 50 46 53 5f 44 45 42 55 47 {...APPFS_DEBUG
2dd0: 28 22 43 61 63 68 65 20 6d 69 73 73 20 6f 6e 20 ("Cache miss on
2de0: 25 73 22 2c 20 70 61 74 68 29 3b 0a 09 7d 0a 0a %s", path);..}..
2df0: 09 72 65 74 75 72 6e 28 72 65 74 76 61 6c 29 3b .return(retval);
2e00: 0a 7d 0a 0a 73 74 61 74 69 63 20 76 6f 69 64 20 .}..static void
2e10: 61 70 70 66 73 5f 67 65 74 5f 70 61 74 68 5f 69 appfs_get_path_i
2e20: 6e 66 6f 5f 63 61 63 68 65 5f 61 64 64 28 63 6f nfo_cache_add(co
2e30: 6e 73 74 20 63 68 61 72 20 2a 70 61 74 68 2c 20 nst char *path,
2e40: 75 69 64 5f 74 20 75 69 64 2c 20 73 74 72 75 63 uid_t uid, struc
2e50: 74 20 61 70 70 66 73 5f 70 61 74 68 69 6e 66 6f t appfs_pathinfo
2e60: 20 2a 70 61 74 68 69 6e 66 6f 29 20 7b 0a 09 75 *pathinfo) {..u
2e70: 6e 73 69 67 6e 65 64 20 69 6e 74 20 68 61 73 68 nsigned int hash
2e80: 5f 69 64 78 3b 0a 09 69 6e 74 20 70 74 68 72 65 _idx;..int pthre
2e90: 61 64 5f 72 65 74 3b 0a 0a 09 70 74 68 72 65 61 ad_ret;...pthrea
2ea0: 64 5f 72 65 74 20 3d 20 70 74 68 72 65 61 64 5f d_ret = pthread_
2eb0: 6d 75 74 65 78 5f 6c 6f 63 6b 28 26 61 70 70 66 mutex_lock(&appf
2ec0: 73 5f 70 61 74 68 5f 69 6e 66 6f 5f 63 61 63 68 s_path_info_cach
2ed0: 65 5f 6d 75 74 65 78 29 3b 0a 09 69 66 20 28 70 e_mutex);..if (p
2ee0: 74 68 72 65 61 64 5f 72 65 74 20 21 3d 20 30 29 thread_ret != 0)
2ef0: 20 7b 0a 09 09 41 50 50 46 53 5f 44 45 42 55 47 {...APPFS_DEBUG
2f00: 28 22 55 6e 61 62 6c 65 20 74 6f 20 6c 6f 63 6b ("Unable to lock
2f10: 20 70 61 74 68 5f 69 6e 66 6f 20 63 61 63 68 65 path_info cache
2f20: 20 6d 75 74 65 78 20 21 22 29 3b 0a 0a 09 09 72 mutex !");....r
2f30: 65 74 75 72 6e 3b 0a 09 7d 0a 0a 09 69 66 20 28 eturn;..}...if (
2f40: 61 70 70 66 73 5f 70 61 74 68 5f 69 6e 66 6f 5f appfs_path_info_
2f50: 63 61 63 68 65 20 3d 3d 20 4e 55 4c 4c 29 20 7b cache == NULL) {
2f60: 0a 09 09 61 70 70 66 73 5f 70 61 74 68 5f 69 6e ...appfs_path_in
2f70: 66 6f 5f 63 61 63 68 65 20 3d 20 63 61 6c 6c 6f fo_cache = callo
2f80: 63 28 61 70 70 66 73 5f 70 61 74 68 5f 69 6e 66 c(appfs_path_inf
2f90: 6f 5f 63 61 63 68 65 5f 73 69 7a 65 2c 20 73 69 o_cache_size, si
2fa0: 7a 65 6f 66 28 2a 61 70 70 66 73 5f 70 61 74 68 zeof(*appfs_path
2fb0: 5f 69 6e 66 6f 5f 63 61 63 68 65 29 29 3b 0a 09 _info_cache));..
2fc0: 7d 0a 0a 09 68 61 73 68 5f 69 64 78 20 3d 20 28 }...hash_idx = (
2fd0: 61 70 70 66 73 5f 67 65 74 5f 70 61 74 68 5f 69 appfs_get_path_i
2fe0: 6e 6f 64 65 28 70 61 74 68 29 20 2b 20 75 69 64 node(path) + uid
2ff0: 29 20 25 20 61 70 70 66 73 5f 70 61 74 68 5f 69 ) % appfs_path_i
3000: 6e 66 6f 5f 63 61 63 68 65 5f 73 69 7a 65 3b 0a nfo_cache_size;.
3010: 0a 09 69 66 20 28 61 70 70 66 73 5f 70 61 74 68 ..if (appfs_path
3020: 5f 69 6e 66 6f 5f 63 61 63 68 65 5b 68 61 73 68 _info_cache[hash
3030: 5f 69 64 78 5d 2e 5f 63 61 63 68 65 5f 70 61 74 _idx]._cache_pat
3040: 68 20 21 3d 20 4e 55 4c 4c 29 20 7b 0a 09 09 66 h != NULL) {...f
3050: 72 65 65 28 61 70 70 66 73 5f 70 61 74 68 5f 69 ree(appfs_path_i
3060: 6e 66 6f 5f 63 61 63 68 65 5b 68 61 73 68 5f 69 nfo_cache[hash_i
3070: 64 78 5d 2e 5f 63 61 63 68 65 5f 70 61 74 68 29 dx]._cache_path)
3080: 3b 0a 09 7d 0a 0a 09 6d 65 6d 63 70 79 28 26 61 ;..}...memcpy(&a
3090: 70 70 66 73 5f 70 61 74 68 5f 69 6e 66 6f 5f 63 ppfs_path_info_c
30a0: 61 63 68 65 5b 68 61 73 68 5f 69 64 78 5d 2c 20 ache[hash_idx],
30b0: 70 61 74 68 69 6e 66 6f 2c 20 73 69 7a 65 6f 66 pathinfo, sizeof
30c0: 28 2a 70 61 74 68 69 6e 66 6f 29 29 3b 0a 0a 09 (*pathinfo));...
30d0: 61 70 70 66 73 5f 70 61 74 68 5f 69 6e 66 6f 5f appfs_path_info_
30e0: 63 61 63 68 65 5b 68 61 73 68 5f 69 64 78 5d 2e cache[hash_idx].
30f0: 5f 63 61 63 68 65 5f 70 61 74 68 20 3d 20 73 74 _cache_path = st
3100: 72 64 75 70 28 70 61 74 68 29 3b 0a 09 61 70 70 rdup(path);..app
3110: 66 73 5f 70 61 74 68 5f 69 6e 66 6f 5f 63 61 63 fs_path_info_cac
3120: 68 65 5b 68 61 73 68 5f 69 64 78 5d 2e 5f 63 61 he[hash_idx]._ca
3130: 63 68 65 5f 75 69 64 20 20 3d 20 75 69 64 3b 0a che_uid = uid;.
3140: 0a 09 70 74 68 72 65 61 64 5f 72 65 74 20 3d 20 ..pthread_ret =
3150: 70 74 68 72 65 61 64 5f 6d 75 74 65 78 5f 75 6e pthread_mutex_un
3160: 6c 6f 63 6b 28 26 61 70 70 66 73 5f 70 61 74 68 lock(&appfs_path
3170: 5f 69 6e 66 6f 5f 63 61 63 68 65 5f 6d 75 74 65 _info_cache_mute
3180: 78 29 3b 0a 09 69 66 20 28 70 74 68 72 65 61 64 x);..if (pthread
3190: 5f 72 65 74 20 21 3d 20 30 29 20 7b 0a 09 09 41 _ret != 0) {...A
31a0: 50 50 46 53 5f 44 45 42 55 47 28 22 55 6e 61 62 PPFS_DEBUG("Unab
31b0: 6c 65 20 74 6f 20 75 6e 6c 6f 63 6b 20 70 61 74 le to unlock pat
31c0: 68 5f 69 6e 66 6f 20 63 61 63 68 65 20 6d 75 74 h_info cache mut
31d0: 65 78 20 21 22 29 3b 0a 0a 09 09 72 65 74 75 72 ex !");....retur
31e0: 6e 3b 0a 09 7d 0a 09 72 65 74 75 72 6e 3b 0a 7d n;..}..return;.}
31f0: 0a 0a 73 74 61 74 69 63 20 76 6f 69 64 20 61 70 ..static void ap
3200: 70 66 73 5f 67 65 74 5f 70 61 74 68 5f 69 6e 66 pfs_get_path_inf
3210: 6f 5f 63 61 63 68 65 5f 72 6d 28 63 6f 6e 73 74 o_cache_rm(const
3220: 20 63 68 61 72 20 2a 70 61 74 68 2c 20 75 69 64 char *path, uid
3230: 5f 74 20 75 69 64 29 20 7b 0a 09 75 6e 73 69 67 _t uid) {..unsig
3240: 6e 65 64 20 69 6e 74 20 68 61 73 68 5f 69 64 78 ned int hash_idx
3250: 3b 0a 09 69 6e 74 20 70 74 68 72 65 61 64 5f 72 ;..int pthread_r
3260: 65 74 3b 0a 0a 09 70 74 68 72 65 61 64 5f 72 65 et;...pthread_re
3270: 74 20 3d 20 70 74 68 72 65 61 64 5f 6d 75 74 65 t = pthread_mute
3280: 78 5f 6c 6f 63 6b 28 26 61 70 70 66 73 5f 70 61 x_lock(&appfs_pa
3290: 74 68 5f 69 6e 66 6f 5f 63 61 63 68 65 5f 6d 75 th_info_cache_mu
32a0: 74 65 78 29 3b 0a 09 69 66 20 28 70 74 68 72 65 tex);..if (pthre
32b0: 61 64 5f 72 65 74 20 21 3d 20 30 29 20 7b 0a 09 ad_ret != 0) {..
32c0: 09 41 50 50 46 53 5f 44 45 42 55 47 28 22 55 6e .APPFS_DEBUG("Un
32d0: 61 62 6c 65 20 74 6f 20 6c 6f 63 6b 20 70 61 74 able to lock pat
32e0: 68 5f 69 6e 66 6f 20 63 61 63 68 65 20 6d 75 74 h_info cache mut
32f0: 65 78 20 21 22 29 3b 0a 0a 09 09 72 65 74 75 72 ex !");....retur
3300: 6e 3b 0a 09 7d 0a 0a 09 69 66 20 28 61 70 70 66 n;..}...if (appf
3310: 73 5f 70 61 74 68 5f 69 6e 66 6f 5f 63 61 63 68 s_path_info_cach
3320: 65 20 21 3d 20 4e 55 4c 4c 29 20 7b 0a 09 09 68 e != NULL) {...h
3330: 61 73 68 5f 69 64 78 20 3d 20 28 61 70 70 66 73 ash_idx = (appfs
3340: 5f 67 65 74 5f 70 61 74 68 5f 69 6e 6f 64 65 28 _get_path_inode(
3350: 70 61 74 68 29 20 2b 20 75 69 64 29 20 25 20 61 path) + uid) % a
3360: 70 70 66 73 5f 70 61 74 68 5f 69 6e 66 6f 5f 63 ppfs_path_info_c
3370: 61 63 68 65 5f 73 69 7a 65 3b 0a 0a 09 09 69 66 ache_size;....if
3380: 20 28 61 70 70 66 73 5f 70 61 74 68 5f 69 6e 66 (appfs_path_inf
3390: 6f 5f 63 61 63 68 65 5b 68 61 73 68 5f 69 64 78 o_cache[hash_idx
33a0: 5d 2e 5f 63 61 63 68 65 5f 70 61 74 68 20 21 3d ]._cache_path !=
33b0: 20 4e 55 4c 4c 29 20 7b 0a 09 09 09 66 72 65 65 NULL) {....free
33c0: 28 61 70 70 66 73 5f 70 61 74 68 5f 69 6e 66 6f (appfs_path_info
33d0: 5f 63 61 63 68 65 5b 68 61 73 68 5f 69 64 78 5d _cache[hash_idx]
33e0: 2e 5f 63 61 63 68 65 5f 70 61 74 68 29 3b 0a 0a ._cache_path);..
33f0: 09 09 09 61 70 70 66 73 5f 70 61 74 68 5f 69 6e ...appfs_path_in
3400: 66 6f 5f 63 61 63 68 65 5b 68 61 73 68 5f 69 64 fo_cache[hash_id
3410: 78 5d 2e 5f 63 61 63 68 65 5f 70 61 74 68 20 3d x]._cache_path =
3420: 20 4e 55 4c 4c 3b 0a 09 09 7d 0a 09 7d 0a 0a 09 NULL;...}..}...
3430: 70 74 68 72 65 61 64 5f 72 65 74 20 3d 20 70 74 pthread_ret = pt
3440: 68 72 65 61 64 5f 6d 75 74 65 78 5f 75 6e 6c 6f hread_mutex_unlo
3450: 63 6b 28 26 61 70 70 66 73 5f 70 61 74 68 5f 69 ck(&appfs_path_i
3460: 6e 66 6f 5f 63 61 63 68 65 5f 6d 75 74 65 78 29 nfo_cache_mutex)
3470: 3b 0a 09 69 66 20 28 70 74 68 72 65 61 64 5f 72 ;..if (pthread_r
3480: 65 74 20 21 3d 20 30 29 20 7b 0a 09 09 41 50 50 et != 0) {...APP
3490: 46 53 5f 44 45 42 55 47 28 22 55 6e 61 62 6c 65 FS_DEBUG("Unable
34a0: 20 74 6f 20 75 6e 6c 6f 63 6b 20 70 61 74 68 5f to unlock path_
34b0: 69 6e 66 6f 20 63 61 63 68 65 20 6d 75 74 65 78 info cache mutex
34c0: 20 21 22 29 3b 0a 0a 09 09 72 65 74 75 72 6e 3b !");....return;
34d0: 0a 09 7d 0a 0a 09 72 65 74 75 72 6e 3b 0a 7d 0a ..}...return;.}.
34e0: 0a 73 74 61 74 69 63 20 76 6f 69 64 20 61 70 70 .static void app
34f0: 66 73 5f 67 65 74 5f 70 61 74 68 5f 69 6e 66 6f fs_get_path_info
3500: 5f 63 61 63 68 65 5f 66 6c 75 73 68 28 75 69 64 _cache_flush(uid
3510: 5f 74 20 75 69 64 2c 20 69 6e 74 20 6e 65 77 5f _t uid, int new_
3520: 73 69 7a 65 29 20 7b 0a 09 75 6e 73 69 67 6e 65 size) {..unsigne
3530: 64 20 69 6e 74 20 69 64 78 3b 0a 09 69 6e 74 20 d int idx;..int
3540: 70 74 68 72 65 61 64 5f 72 65 74 3b 0a 0a 09 41 pthread_ret;...A
3550: 50 50 46 53 5f 44 45 42 55 47 28 22 46 6c 75 73 PPFS_DEBUG("Flus
3560: 68 69 6e 67 20 41 70 70 46 53 20 63 61 63 68 65 hing AppFS cache
3570: 20 28 75 69 64 20 3d 20 25 6c 6c 69 2c 20 6e 65 (uid = %lli, ne
3580: 77 5f 73 69 7a 65 20 3d 20 25 69 29 22 2c 20 28 w_size = %i)", (
3590: 6c 6f 6e 67 20 6c 6f 6e 67 29 20 75 69 64 2c 20 long long) uid,
35a0: 6e 65 77 5f 73 69 7a 65 29 3b 0a 0a 09 70 74 68 new_size);...pth
35b0: 72 65 61 64 5f 72 65 74 20 3d 20 70 74 68 72 65 read_ret = pthre
35c0: 61 64 5f 6d 75 74 65 78 5f 6c 6f 63 6b 28 26 61 ad_mutex_lock(&a
35d0: 70 70 66 73 5f 70 61 74 68 5f 69 6e 66 6f 5f 63 ppfs_path_info_c
35e0: 61 63 68 65 5f 6d 75 74 65 78 29 3b 0a 09 69 66 ache_mutex);..if
35f0: 20 28 70 74 68 72 65 61 64 5f 72 65 74 20 21 3d (pthread_ret !=
3600: 20 30 29 20 7b 0a 09 09 41 50 50 46 53 5f 44 45 0) {...APPFS_DE
3610: 42 55 47 28 22 55 6e 61 62 6c 65 20 74 6f 20 6c BUG("Unable to l
3620: 6f 63 6b 20 70 61 74 68 5f 69 6e 66 6f 20 63 61 ock path_info ca
3630: 63 68 65 20 6d 75 74 65 78 20 21 22 29 3b 0a 0a che mutex !");..
3640: 09 09 72 65 74 75 72 6e 3b 0a 09 7d 0a 0a 09 69 ..return;..}...i
3650: 66 20 28 61 70 70 66 73 5f 70 61 74 68 5f 69 6e f (appfs_path_in
3660: 66 6f 5f 63 61 63 68 65 20 21 3d 20 4e 55 4c 4c fo_cache != NULL
3670: 29 20 7b 0a 09 09 66 6f 72 20 28 69 64 78 20 3d ) {...for (idx =
3680: 20 30 3b 20 69 64 78 20 3c 20 61 70 70 66 73 5f 0; idx < appfs_
3690: 70 61 74 68 5f 69 6e 66 6f 5f 63 61 63 68 65 5f path_info_cache_
36a0: 73 69 7a 65 3b 20 69 64 78 2b 2b 29 20 7b 0a 09 size; idx++) {..
36b0: 09 09 69 66 20 28 61 70 70 66 73 5f 70 61 74 68 ..if (appfs_path
36c0: 5f 69 6e 66 6f 5f 63 61 63 68 65 5b 69 64 78 5d _info_cache[idx]
36d0: 2e 5f 63 61 63 68 65 5f 70 61 74 68 20 21 3d 20 ._cache_path !=
36e0: 4e 55 4c 4c 29 20 7b 0a 09 09 09 09 69 66 20 28 NULL) {.....if (
36f0: 75 69 64 20 21 3d 20 28 28 75 69 64 5f 74 29 20 uid != ((uid_t)
3700: 2d 31 29 29 20 7b 0a 09 09 09 09 09 69 66 20 28 -1)) {......if (
3710: 61 70 70 66 73 5f 70 61 74 68 5f 69 6e 66 6f 5f appfs_path_info_
3720: 63 61 63 68 65 5b 69 64 78 5d 2e 5f 63 61 63 68 cache[idx]._cach
3730: 65 5f 75 69 64 20 21 3d 20 75 69 64 29 20 7b 0a e_uid != uid) {.
3740: 09 09 09 09 09 09 63 6f 6e 74 69 6e 75 65 3b 0a ......continue;.
3750: 09 09 09 09 09 7d 0a 09 09 09 09 7d 0a 0a 09 09 .....}.....}....
3760: 09 09 66 72 65 65 28 61 70 70 66 73 5f 70 61 74 ..free(appfs_pat
3770: 68 5f 69 6e 66 6f 5f 63 61 63 68 65 5b 69 64 78 h_info_cache[idx
3780: 5d 2e 5f 63 61 63 68 65 5f 70 61 74 68 29 3b 0a ]._cache_path);.
3790: 0a 09 09 09 09 61 70 70 66 73 5f 70 61 74 68 5f .....appfs_path_
37a0: 69 6e 66 6f 5f 63 61 63 68 65 5b 69 64 78 5d 2e info_cache[idx].
37b0: 5f 63 61 63 68 65 5f 70 61 74 68 20 3d 20 4e 55 _cache_path = NU
37c0: 4c 4c 3b 0a 09 09 09 7d 0a 09 09 7d 0a 09 7d 0a LL;....}...}..}.
37d0: 0a 09 69 66 20 28 75 69 64 20 3d 3d 20 28 28 75 ..if (uid == ((u
37e0: 69 64 5f 74 29 20 2d 31 29 29 20 7b 0a 09 09 66 id_t) -1)) {...f
37f0: 72 65 65 28 61 70 70 66 73 5f 70 61 74 68 5f 69 ree(appfs_path_i
3800: 6e 66 6f 5f 63 61 63 68 65 29 3b 0a 0a 09 09 61 nfo_cache);....a
3810: 70 70 66 73 5f 70 61 74 68 5f 69 6e 66 6f 5f 63 ppfs_path_info_c
3820: 61 63 68 65 20 3d 20 4e 55 4c 4c 3b 0a 0a 09 09 ache = NULL;....
3830: 69 66 20 28 6e 65 77 5f 73 69 7a 65 20 21 3d 20 if (new_size !=
3840: 2d 31 29 20 7b 0a 09 09 09 61 70 70 66 73 5f 70 -1) {....appfs_p
3850: 61 74 68 5f 69 6e 66 6f 5f 63 61 63 68 65 5f 73 ath_info_cache_s
3860: 69 7a 65 20 3d 20 6e 65 77 5f 73 69 7a 65 3b 0a ize = new_size;.
3870: 09 09 7d 0a 09 7d 0a 0a 09 70 74 68 72 65 61 64 ..}..}...pthread
3880: 5f 72 65 74 20 3d 20 70 74 68 72 65 61 64 5f 6d _ret = pthread_m
3890: 75 74 65 78 5f 75 6e 6c 6f 63 6b 28 26 61 70 70 utex_unlock(&app
38a0: 66 73 5f 70 61 74 68 5f 69 6e 66 6f 5f 63 61 63 fs_path_info_cac
38b0: 68 65 5f 6d 75 74 65 78 29 3b 0a 09 69 66 20 28 he_mutex);..if (
38c0: 70 74 68 72 65 61 64 5f 72 65 74 20 21 3d 20 30 pthread_ret != 0
38d0: 29 20 7b 0a 09 09 41 50 50 46 53 5f 44 45 42 55 ) {...APPFS_DEBU
38e0: 47 28 22 55 6e 61 62 6c 65 20 74 6f 20 75 6e 6c G("Unable to unl
38f0: 6f 63 6b 20 70 61 74 68 5f 69 6e 66 6f 20 63 61 ock path_info ca
3900: 63 68 65 20 6d 75 74 65 78 20 21 22 29 3b 0a 0a che mutex !");..
3910: 09 09 72 65 74 75 72 6e 3b 0a 09 7d 0a 0a 09 72 ..return;..}...r
3920: 65 74 75 72 6e 3b 0a 7d 0a 0a 2f 2a 20 47 65 74 eturn;.}../* Get
3930: 20 69 6e 66 6f 72 6d 61 74 69 6f 6e 20 61 62 6f information abo
3940: 75 74 20 61 20 70 61 74 68 2c 20 61 6e 64 20 6f ut a path, and o
3950: 70 74 69 6f 6e 61 6c 6c 79 20 6c 69 73 74 20 63 ptionally list c
3960: 68 69 6c 64 72 65 6e 20 2a 2f 0a 73 74 61 74 69 hildren */.stati
3970: 63 20 69 6e 74 20 61 70 70 66 73 5f 67 65 74 5f c int appfs_get_
3980: 70 61 74 68 5f 69 6e 66 6f 28 63 6f 6e 73 74 20 path_info(const
3990: 63 68 61 72 20 2a 70 61 74 68 2c 20 73 74 72 75 char *path, stru
39a0: 63 74 20 61 70 70 66 73 5f 70 61 74 68 69 6e 66 ct appfs_pathinf
39b0: 6f 20 2a 70 61 74 68 69 6e 66 6f 29 20 7b 0a 09 o *pathinfo) {..
39c0: 54 63 6c 5f 49 6e 74 65 72 70 20 2a 69 6e 74 65 Tcl_Interp *inte
39d0: 72 70 3b 0a 09 54 63 6c 5f 4f 62 6a 20 2a 61 74 rp;..Tcl_Obj *at
39e0: 74 72 73 5f 64 69 63 74 2c 20 2a 61 74 74 72 5f trs_dict, *attr_
39f0: 76 61 6c 75 65 3b 0a 09 63 6f 6e 73 74 20 63 68 value;..const ch
3a00: 61 72 20 2a 61 74 74 72 5f 76 61 6c 75 65 5f 73 ar *attr_value_s
3a10: 74 72 3b 0a 09 54 63 6c 5f 57 69 64 65 49 6e 74 tr;..Tcl_WideInt
3a20: 20 61 74 74 72 5f 76 61 6c 75 65 5f 77 69 64 65 attr_value_wide
3a30: 3b 0a 09 69 6e 74 20 61 74 74 72 5f 76 61 6c 75 ;..int attr_valu
3a40: 65 5f 69 6e 74 3b 0a 09 73 74 61 74 69 63 20 5f e_int;..static _
3a50: 5f 74 68 72 65 61 64 20 54 63 6c 5f 4f 62 6a 20 _thread Tcl_Obj
3a60: 2a 61 74 74 72 5f 6b 65 79 5f 74 79 70 65 20 3d *attr_key_type =
3a70: 20 4e 55 4c 4c 2c 20 2a 61 74 74 72 5f 6b 65 79 NULL, *attr_key
3a80: 5f 70 65 72 6d 73 20 3d 20 4e 55 4c 4c 2c 20 2a _perms = NULL, *
3a90: 61 74 74 72 5f 6b 65 79 5f 73 69 7a 65 20 3d 20 attr_key_size =
3aa0: 4e 55 4c 4c 2c 20 2a 61 74 74 72 5f 6b 65 79 5f NULL, *attr_key_
3ab0: 74 69 6d 65 20 3d 20 4e 55 4c 4c 2c 20 2a 61 74 time = NULL, *at
3ac0: 74 72 5f 6b 65 79 5f 73 6f 75 72 63 65 20 3d 20 tr_key_source =
3ad0: 4e 55 4c 4c 2c 20 2a 61 74 74 72 5f 6b 65 79 5f NULL, *attr_key_
3ae0: 63 68 69 6c 64 63 6f 75 6e 74 20 3d 20 4e 55 4c childcount = NUL
3af0: 4c 2c 20 2a 61 74 74 72 5f 6b 65 79 5f 70 61 63 L, *attr_key_pac
3b00: 6b 61 67 65 64 20 3d 20 4e 55 4c 4c 3b 0a 09 69 kaged = NULL;..i
3b10: 6e 74 20 63 61 63 68 65 5f 72 65 74 3b 0a 09 69 nt cache_ret;..i
3b20: 6e 74 20 74 63 6c 5f 72 65 74 3b 0a 0a 09 63 61 nt tcl_ret;...ca
3b30: 63 68 65 5f 72 65 74 20 3d 20 61 70 70 66 73 5f che_ret = appfs_
3b40: 67 65 74 5f 70 61 74 68 5f 69 6e 66 6f 5f 63 61 get_path_info_ca
3b50: 63 68 65 5f 67 65 74 28 70 61 74 68 2c 20 61 70 che_get(path, ap
3b60: 70 66 73 5f 67 65 74 5f 66 73 75 69 64 28 29 2c pfs_get_fsuid(),
3b70: 20 70 61 74 68 69 6e 66 6f 29 3b 0a 09 69 66 20 pathinfo);..if
3b80: 28 63 61 63 68 65 5f 72 65 74 20 3d 3d 20 30 29 (cache_ret == 0)
3b90: 20 7b 0a 09 09 69 66 20 28 70 61 74 68 69 6e 66 {...if (pathinf
3ba0: 6f 2d 3e 74 79 70 65 20 3d 3d 20 41 50 50 46 53 o->type == APPFS
3bb0: 5f 50 41 54 48 54 59 50 45 5f 44 4f 45 53 5f 4e _PATHTYPE_DOES_N
3bc0: 4f 54 5f 45 58 49 53 54 29 20 7b 0a 09 09 09 72 OT_EXIST) {....r
3bd0: 65 74 75 72 6e 28 2d 45 4e 4f 45 4e 54 29 3b 0a eturn(-ENOENT);.
3be0: 09 09 7d 0a 0a 09 09 69 66 20 28 70 61 74 68 69 ..}....if (pathi
3bf0: 6e 66 6f 2d 3e 74 79 70 65 20 3d 3d 20 41 50 50 nfo->type == APP
3c00: 46 53 5f 50 41 54 48 54 59 50 45 5f 49 4e 56 41 FS_PATHTYPE_INVA
3c10: 4c 49 44 29 20 7b 0a 09 09 09 72 65 74 75 72 6e LID) {....return
3c20: 28 2d 45 49 4f 29 3b 0a 09 09 7d 0a 0a 09 09 72 (-EIO);...}....r
3c30: 65 74 75 72 6e 28 30 29 3b 0a 09 7d 0a 0a 09 69 eturn(0);..}...i
3c40: 6e 74 65 72 70 20 3d 20 61 70 70 66 73 5f 54 63 nterp = appfs_Tc
3c50: 6c 49 6e 74 65 72 70 28 29 3b 0a 09 69 66 20 28 lInterp();..if (
3c60: 69 6e 74 65 72 70 20 3d 3d 20 4e 55 4c 4c 29 20 interp == NULL)
3c70: 7b 0a 09 09 72 65 74 75 72 6e 28 2d 45 49 4f 29 {...return(-EIO)
3c80: 3b 0a 09 7d 0a 0a 09 74 63 6c 5f 72 65 74 20 3d ;..}...tcl_ret =
3c90: 20 61 70 70 66 73 5f 54 63 6c 5f 45 76 61 6c 28 appfs_Tcl_Eval(
3ca0: 69 6e 74 65 72 70 2c 20 32 2c 20 22 3a 3a 61 70 interp, 2, "::ap
3cb0: 70 66 73 3a 3a 67 65 74 61 74 74 72 22 2c 20 70 pfs::getattr", p
3cc0: 61 74 68 29 3b 0a 09 69 66 20 28 74 63 6c 5f 72 ath);..if (tcl_r
3cd0: 65 74 20 21 3d 20 54 43 4c 5f 4f 4b 29 20 7b 0a et != TCL_OK) {.
3ce0: 09 09 41 50 50 46 53 5f 44 45 42 55 47 28 22 3a ..APPFS_DEBUG(":
3cf0: 3a 61 70 70 66 73 3a 3a 67 65 74 61 74 74 72 28 :appfs::getattr(
3d00: 25 73 29 20 66 61 69 6c 65 64 2e 22 2c 20 70 61 %s) failed.", pa
3d10: 74 68 29 3b 0a 09 09 41 50 50 46 53 5f 44 45 42 th);...APPFS_DEB
3d20: 55 47 28 22 54 63 6c 20 45 72 72 6f 72 20 69 73 UG("Tcl Error is
3d30: 3a 20 25 73 22 2c 20 54 63 6c 5f 47 65 74 53 74 : %s", Tcl_GetSt
3d40: 72 69 6e 67 52 65 73 75 6c 74 28 69 6e 74 65 72 ringResult(inter
3d50: 70 29 29 3b 0a 0a 09 09 70 61 74 68 69 6e 66 6f p));....pathinfo
3d60: 2d 3e 74 79 70 65 20 3d 20 41 50 50 46 53 5f 50 ->type = APPFS_P
3d70: 41 54 48 54 59 50 45 5f 44 4f 45 53 5f 4e 4f 54 ATHTYPE_DOES_NOT
3d80: 5f 45 58 49 53 54 3b 0a 0a 09 09 61 70 70 66 73 _EXIST;....appfs
3d90: 5f 67 65 74 5f 70 61 74 68 5f 69 6e 66 6f 5f 63 _get_path_info_c
3da0: 61 63 68 65 5f 61 64 64 28 70 61 74 68 2c 20 61 ache_add(path, a
3db0: 70 70 66 73 5f 67 65 74 5f 66 73 75 69 64 28 29 ppfs_get_fsuid()
3dc0: 2c 20 70 61 74 68 69 6e 66 6f 29 3b 0a 0a 09 09 , pathinfo);....
3dd0: 72 65 74 75 72 6e 28 2d 45 4e 4f 45 4e 54 29 3b return(-ENOENT);
3de0: 0a 09 7d 0a 0a 09 69 66 20 28 61 74 74 72 5f 6b ..}...if (attr_k
3df0: 65 79 5f 74 79 70 65 20 3d 3d 20 4e 55 4c 4c 29 ey_type == NULL)
3e00: 20 7b 0a 09 09 61 74 74 72 5f 6b 65 79 5f 74 79 {...attr_key_ty
3e10: 70 65 20 20 20 20 20 20 20 3d 20 54 63 6c 5f 4e pe = Tcl_N
3e20: 65 77 53 74 72 69 6e 67 4f 62 6a 28 22 74 79 70 ewStringObj("typ
3e30: 65 22 2c 20 2d 31 29 3b 0a 09 09 61 74 74 72 5f e", -1);...attr_
3e40: 6b 65 79 5f 70 65 72 6d 73 20 20 20 20 20 20 3d key_perms =
3e50: 20 54 63 6c 5f 4e 65 77 53 74 72 69 6e 67 4f 62 Tcl_NewStringOb
3e60: 6a 28 22 70 65 72 6d 73 22 2c 20 2d 31 29 3b 0a j("perms", -1);.
3e70: 09 09 61 74 74 72 5f 6b 65 79 5f 73 69 7a 65 20 ..attr_key_size
3e80: 20 20 20 20 20 20 3d 20 54 63 6c 5f 4e 65 77 53 = Tcl_NewS
3e90: 74 72 69 6e 67 4f 62 6a 28 22 73 69 7a 65 22 2c tringObj("size",
3ea0: 20 2d 31 29 3b 0a 09 09 61 74 74 72 5f 6b 65 79 -1);...attr_key
3eb0: 5f 74 69 6d 65 20 20 20 20 20 20 20 3d 20 54 63 _time = Tc
3ec0: 6c 5f 4e 65 77 53 74 72 69 6e 67 4f 62 6a 28 22 l_NewStringObj("
3ed0: 74 69 6d 65 22 2c 20 2d 31 29 3b 0a 09 09 61 74 time", -1);...at
3ee0: 74 72 5f 6b 65 79 5f 73 6f 75 72 63 65 20 20 20 tr_key_source
3ef0: 20 20 3d 20 54 63 6c 5f 4e 65 77 53 74 72 69 6e = Tcl_NewStrin
3f00: 67 4f 62 6a 28 22 73 6f 75 72 63 65 22 2c 20 2d gObj("source", -
3f10: 31 29 3b 0a 09 09 61 74 74 72 5f 6b 65 79 5f 63 1);...attr_key_c
3f20: 68 69 6c 64 63 6f 75 6e 74 20 3d 20 54 63 6c 5f hildcount = Tcl_
3f30: 4e 65 77 53 74 72 69 6e 67 4f 62 6a 28 22 63 68 NewStringObj("ch
3f40: 69 6c 64 63 6f 75 6e 74 22 2c 20 2d 31 29 3b 0a ildcount", -1);.
3f50: 09 09 61 74 74 72 5f 6b 65 79 5f 70 61 63 6b 61 ..attr_key_packa
3f60: 67 65 64 20 20 20 3d 20 54 63 6c 5f 4e 65 77 53 ged = Tcl_NewS
3f70: 74 72 69 6e 67 4f 62 6a 28 22 70 61 63 6b 61 67 tringObj("packag
3f80: 65 64 22 2c 20 2d 31 29 3b 0a 09 7d 0a 0a 09 61 ed", -1);..}...a
3f90: 74 74 72 73 5f 64 69 63 74 20 3d 20 54 63 6c 5f ttrs_dict = Tcl_
3fa0: 47 65 74 4f 62 6a 52 65 73 75 6c 74 28 69 6e 74 GetObjResult(int
3fb0: 65 72 70 29 3b 0a 09 74 63 6c 5f 72 65 74 20 3d erp);..tcl_ret =
3fc0: 20 54 63 6c 5f 44 69 63 74 4f 62 6a 47 65 74 28 Tcl_DictObjGet(
3fd0: 69 6e 74 65 72 70 2c 20 61 74 74 72 73 5f 64 69 interp, attrs_di
3fe0: 63 74 2c 20 61 74 74 72 5f 6b 65 79 5f 74 79 70 ct, attr_key_typ
3ff0: 65 2c 20 26 61 74 74 72 5f 76 61 6c 75 65 29 3b e, &attr_value);
4000: 0a 09 69 66 20 28 74 63 6c 5f 72 65 74 20 21 3d ..if (tcl_ret !=
4010: 20 54 43 4c 5f 4f 4b 29 20 7b 0a 09 09 41 50 50 TCL_OK) {...APP
4020: 46 53 5f 44 45 42 55 47 28 22 5b 64 69 63 74 20 FS_DEBUG("[dict
4030: 67 65 74 20 5c 22 74 79 70 65 5c 22 5d 20 66 61 get \"type\"] fa
4040: 69 6c 65 64 22 29 3b 0a 09 09 41 50 50 46 53 5f iled");...APPFS_
4050: 44 45 42 55 47 28 22 54 63 6c 20 45 72 72 6f 72 DEBUG("Tcl Error
4060: 20 69 73 3a 20 25 73 22 2c 20 54 63 6c 5f 47 65 is: %s", Tcl_Ge
4070: 74 53 74 72 69 6e 67 52 65 73 75 6c 74 28 69 6e tStringResult(in
4080: 74 65 72 70 29 29 3b 0a 0a 09 09 72 65 74 75 72 terp));....retur
4090: 6e 28 2d 45 49 4f 29 3b 0a 09 7d 0a 0a 09 69 66 n(-EIO);..}...if
40a0: 20 28 61 74 74 72 5f 76 61 6c 75 65 20 3d 3d 20 (attr_value ==
40b0: 4e 55 4c 4c 29 20 7b 0a 09 09 72 65 74 75 72 6e NULL) {...return
40c0: 28 2d 45 49 4f 29 3b 0a 09 7d 0a 0a 09 70 61 74 (-EIO);..}...pat
40d0: 68 69 6e 66 6f 2d 3e 70 61 63 6b 61 67 65 64 20 hinfo->packaged
40e0: 3d 20 30 3b 0a 09 70 61 74 68 69 6e 66 6f 2d 3e = 0;..pathinfo->
40f0: 69 6e 6f 64 65 20 3d 20 61 70 70 66 73 5f 67 65 inode = appfs_ge
4100: 74 5f 70 61 74 68 5f 69 6e 6f 64 65 28 70 61 74 t_path_inode(pat
4110: 68 29 3b 0a 0a 09 61 74 74 72 5f 76 61 6c 75 65 h);...attr_value
4120: 5f 73 74 72 20 3d 20 54 63 6c 5f 47 65 74 53 74 _str = Tcl_GetSt
4130: 72 69 6e 67 28 61 74 74 72 5f 76 61 6c 75 65 29 ring(attr_value)
4140: 3b 0a 09 73 77 69 74 63 68 20 28 61 74 74 72 5f ;..switch (attr_
4150: 76 61 6c 75 65 5f 73 74 72 5b 30 5d 29 20 7b 0a value_str[0]) {.
4160: 09 09 63 61 73 65 20 27 64 27 3a 20 2f 2a 20 64 ..case 'd': /* d
4170: 69 72 65 63 74 6f 72 79 20 2a 2f 0a 09 09 09 70 irectory */....p
4180: 61 74 68 69 6e 66 6f 2d 3e 74 79 70 65 20 3d 20 athinfo->type =
4190: 41 50 50 46 53 5f 50 41 54 48 54 59 50 45 5f 44 APPFS_PATHTYPE_D
41a0: 49 52 45 43 54 4f 52 59 3b 0a 09 09 09 70 61 74 IRECTORY;....pat
41b0: 68 69 6e 66 6f 2d 3e 74 79 70 65 69 6e 66 6f 2e hinfo->typeinfo.
41c0: 64 69 72 2e 63 68 69 6c 64 63 6f 75 6e 74 20 3d dir.childcount =
41d0: 20 30 3b 0a 0a 09 09 09 54 63 6c 5f 44 69 63 74 0;.....Tcl_Dict
41e0: 4f 62 6a 47 65 74 28 69 6e 74 65 72 70 2c 20 61 ObjGet(interp, a
41f0: 74 74 72 73 5f 64 69 63 74 2c 20 61 74 74 72 5f ttrs_dict, attr_
4200: 6b 65 79 5f 63 68 69 6c 64 63 6f 75 6e 74 2c 20 key_childcount,
4210: 26 61 74 74 72 5f 76 61 6c 75 65 29 3b 0a 09 09 &attr_value);...
4220: 09 69 66 20 28 61 74 74 72 5f 76 61 6c 75 65 20 .if (attr_value
4230: 21 3d 20 4e 55 4c 4c 29 20 7b 0a 09 09 09 09 74 != NULL) {.....t
4240: 63 6c 5f 72 65 74 20 3d 20 54 63 6c 5f 47 65 74 cl_ret = Tcl_Get
4250: 57 69 64 65 49 6e 74 46 72 6f 6d 4f 62 6a 28 4e WideIntFromObj(N
4260: 55 4c 4c 2c 20 61 74 74 72 5f 76 61 6c 75 65 2c ULL, attr_value,
4270: 20 26 61 74 74 72 5f 76 61 6c 75 65 5f 77 69 64 &attr_value_wid
4280: 65 29 3b 0a 09 09 09 09 69 66 20 28 74 63 6c 5f e);.....if (tcl_
4290: 72 65 74 20 3d 3d 20 54 43 4c 5f 4f 4b 29 20 7b ret == TCL_OK) {
42a0: 0a 09 09 09 09 09 70 61 74 68 69 6e 66 6f 2d 3e ......pathinfo->
42b0: 74 79 70 65 69 6e 66 6f 2e 64 69 72 2e 63 68 69 typeinfo.dir.chi
42c0: 6c 64 63 6f 75 6e 74 20 3d 20 61 74 74 72 5f 76 ldcount = attr_v
42d0: 61 6c 75 65 5f 77 69 64 65 3b 0a 09 09 09 09 7d alue_wide;.....}
42e0: 0a 09 09 09 7d 0a 0a 09 09 09 62 72 65 61 6b 3b ....}.....break;
42f0: 0a 09 09 63 61 73 65 20 27 66 27 3a 20 2f 2a 20 ...case 'f': /*
4300: 66 69 6c 65 20 2a 2f 0a 09 09 09 70 61 74 68 69 file */....pathi
4310: 6e 66 6f 2d 3e 74 79 70 65 20 3d 20 41 50 50 46 nfo->type = APPF
4320: 53 5f 50 41 54 48 54 59 50 45 5f 46 49 4c 45 3b S_PATHTYPE_FILE;
4330: 0a 09 09 09 70 61 74 68 69 6e 66 6f 2d 3e 74 79 ....pathinfo->ty
4340: 70 65 69 6e 66 6f 2e 66 69 6c 65 2e 73 69 7a 65 peinfo.file.size
4350: 20 3d 20 30 3b 0a 09 09 09 70 61 74 68 69 6e 66 = 0;....pathinf
4360: 6f 2d 3e 74 79 70 65 69 6e 66 6f 2e 66 69 6c 65 o->typeinfo.file
4370: 2e 65 78 65 63 75 74 61 62 6c 65 20 3d 20 30 3b .executable = 0;
4380: 0a 0a 09 09 09 54 63 6c 5f 44 69 63 74 4f 62 6a .....Tcl_DictObj
4390: 47 65 74 28 69 6e 74 65 72 70 2c 20 61 74 74 72 Get(interp, attr
43a0: 73 5f 64 69 63 74 2c 20 61 74 74 72 5f 6b 65 79 s_dict, attr_key
43b0: 5f 73 69 7a 65 2c 20 26 61 74 74 72 5f 76 61 6c _size, &attr_val
43c0: 75 65 29 3b 0a 09 09 09 69 66 20 28 61 74 74 72 ue);....if (attr
43d0: 5f 76 61 6c 75 65 20 21 3d 20 4e 55 4c 4c 29 20 _value != NULL)
43e0: 7b 0a 09 09 09 09 74 63 6c 5f 72 65 74 20 3d 20 {.....tcl_ret =
43f0: 54 63 6c 5f 47 65 74 57 69 64 65 49 6e 74 46 72 Tcl_GetWideIntFr
4400: 6f 6d 4f 62 6a 28 4e 55 4c 4c 2c 20 61 74 74 72 omObj(NULL, attr
4410: 5f 76 61 6c 75 65 2c 20 26 61 74 74 72 5f 76 61 _value, &attr_va
4420: 6c 75 65 5f 77 69 64 65 29 3b 0a 09 09 09 09 69 lue_wide);.....i
4430: 66 20 28 74 63 6c 5f 72 65 74 20 3d 3d 20 54 43 f (tcl_ret == TC
4440: 4c 5f 4f 4b 29 20 7b 0a 09 09 09 09 09 70 61 74 L_OK) {......pat
4450: 68 69 6e 66 6f 2d 3e 74 79 70 65 69 6e 66 6f 2e hinfo->typeinfo.
4460: 66 69 6c 65 2e 73 69 7a 65 20 3d 20 61 74 74 72 file.size = attr
4470: 5f 76 61 6c 75 65 5f 77 69 64 65 3b 0a 09 09 09 _value_wide;....
4480: 09 7d 0a 09 09 09 7d 0a 0a 09 09 09 54 63 6c 5f .}....}.....Tcl_
4490: 44 69 63 74 4f 62 6a 47 65 74 28 69 6e 74 65 72 DictObjGet(inter
44a0: 70 2c 20 61 74 74 72 73 5f 64 69 63 74 2c 20 61 p, attrs_dict, a
44b0: 74 74 72 5f 6b 65 79 5f 70 65 72 6d 73 2c 20 26 ttr_key_perms, &
44c0: 61 74 74 72 5f 76 61 6c 75 65 29 3b 0a 09 09 09 attr_value);....
44d0: 69 66 20 28 61 74 74 72 5f 76 61 6c 75 65 20 21 if (attr_value !
44e0: 3d 20 4e 55 4c 4c 29 20 7b 0a 09 09 09 09 61 74 = NULL) {.....at
44f0: 74 72 5f 76 61 6c 75 65 5f 73 74 72 20 3d 20 54 tr_value_str = T
4500: 63 6c 5f 47 65 74 53 74 72 69 6e 67 28 61 74 74 cl_GetString(att
4510: 72 5f 76 61 6c 75 65 29 3b 0a 09 09 09 09 69 66 r_value);.....if
4520: 20 28 61 74 74 72 5f 76 61 6c 75 65 5f 73 74 72 (attr_value_str
4530: 5b 30 5d 20 3d 3d 20 27 78 27 29 20 7b 0a 09 09 [0] == 'x') {...
4540: 09 09 09 70 61 74 68 69 6e 66 6f 2d 3e 74 79 70 ...pathinfo->typ
4550: 65 69 6e 66 6f 2e 66 69 6c 65 2e 65 78 65 63 75 einfo.file.execu
4560: 74 61 62 6c 65 20 3d 20 31 3b 0a 09 09 09 09 7d table = 1;.....}
4570: 0a 09 09 09 7d 0a 09 09 09 62 72 65 61 6b 3b 0a ....}....break;.
4580: 09 09 63 61 73 65 20 27 73 27 3a 20 2f 2a 20 73 ..case 's': /* s
4590: 79 6d 6c 69 6e 6b 20 2a 2f 0a 09 09 09 70 61 74 ymlink */....pat
45a0: 68 69 6e 66 6f 2d 3e 74 79 70 65 20 3d 20 41 50 hinfo->type = AP
45b0: 50 46 53 5f 50 41 54 48 54 59 50 45 5f 53 59 4d PFS_PATHTYPE_SYM
45c0: 4c 49 4e 4b 3b 0a 09 09 09 70 61 74 68 69 6e 66 LINK;....pathinf
45d0: 6f 2d 3e 74 79 70 65 69 6e 66 6f 2e 73 79 6d 6c o->typeinfo.syml
45e0: 69 6e 6b 2e 73 69 7a 65 20 3d 20 30 3b 0a 09 09 ink.size = 0;...
45f0: 09 70 61 74 68 69 6e 66 6f 2d 3e 74 79 70 65 69 .pathinfo->typei
4600: 6e 66 6f 2e 73 79 6d 6c 69 6e 6b 2e 73 6f 75 72 nfo.symlink.sour
4610: 63 65 5b 30 5d 20 3d 20 27 5c 30 27 3b 0a 0a 09 ce[0] = '\0';...
4620: 09 09 54 63 6c 5f 44 69 63 74 4f 62 6a 47 65 74 ..Tcl_DictObjGet
4630: 28 69 6e 74 65 72 70 2c 20 61 74 74 72 73 5f 64 (interp, attrs_d
4640: 69 63 74 2c 20 61 74 74 72 5f 6b 65 79 5f 73 6f ict, attr_key_so
4650: 75 72 63 65 2c 20 26 61 74 74 72 5f 76 61 6c 75 urce, &attr_valu
4660: 65 29 3b 0a 09 09 09 69 66 20 28 61 74 74 72 5f e);....if (attr_
4670: 76 61 6c 75 65 20 21 3d 20 4e 55 4c 4c 29 20 7b value != NULL) {
4680: 0a 09 09 09 09 61 74 74 72 5f 76 61 6c 75 65 5f .....attr_value_
4690: 73 74 72 20 3d 20 54 63 6c 5f 47 65 74 53 74 72 str = Tcl_GetStr
46a0: 69 6e 67 46 72 6f 6d 4f 62 6a 28 61 74 74 72 5f ingFromObj(attr_
46b0: 76 61 6c 75 65 2c 20 26 61 74 74 72 5f 76 61 6c value, &attr_val
46c0: 75 65 5f 69 6e 74 29 3b 20 0a 0a 09 09 09 09 69 ue_int); ......i
46d0: 66 20 28 28 61 74 74 72 5f 76 61 6c 75 65 5f 69 f ((attr_value_i
46e0: 6e 74 20 2b 20 31 29 20 3c 3d 20 73 69 7a 65 6f nt + 1) <= sizeo
46f0: 66 28 70 61 74 68 69 6e 66 6f 2d 3e 74 79 70 65 f(pathinfo->type
4700: 69 6e 66 6f 2e 73 79 6d 6c 69 6e 6b 2e 73 6f 75 info.symlink.sou
4710: 72 63 65 29 29 20 7b 0a 09 09 09 09 09 70 61 74 rce)) {......pat
4720: 68 69 6e 66 6f 2d 3e 74 79 70 65 69 6e 66 6f 2e hinfo->typeinfo.
4730: 73 79 6d 6c 69 6e 6b 2e 73 69 7a 65 20 3d 20 61 symlink.size = a
4740: 74 74 72 5f 76 61 6c 75 65 5f 69 6e 74 3b 0a 09 ttr_value_int;..
4750: 09 09 09 09 70 61 74 68 69 6e 66 6f 2d 3e 74 79 ....pathinfo->ty
4760: 70 65 69 6e 66 6f 2e 73 79 6d 6c 69 6e 6b 2e 73 peinfo.symlink.s
4770: 6f 75 72 63 65 5b 61 74 74 72 5f 76 61 6c 75 65 ource[attr_value
4780: 5f 69 6e 74 5d 20 3d 20 27 5c 30 27 3b 0a 0a 09 _int] = '\0';...
4790: 09 09 09 09 6d 65 6d 63 70 79 28 70 61 74 68 69 ....memcpy(pathi
47a0: 6e 66 6f 2d 3e 74 79 70 65 69 6e 66 6f 2e 73 79 nfo->typeinfo.sy
47b0: 6d 6c 69 6e 6b 2e 73 6f 75 72 63 65 2c 20 61 74 mlink.source, at
47c0: 74 72 5f 76 61 6c 75 65 5f 73 74 72 2c 20 61 74 tr_value_str, at
47d0: 74 72 5f 76 61 6c 75 65 5f 69 6e 74 29 3b 0a 09 tr_value_int);..
47e0: 09 09 09 7d 0a 09 09 09 7d 0a 09 09 09 62 72 65 ...}....}....bre
47f0: 61 6b 3b 0a 09 09 63 61 73 65 20 27 46 27 3a 20 ak;...case 'F':
4800: 2f 2a 20 70 69 70 65 2f 66 69 66 6f 20 2a 2f 0a /* pipe/fifo */.
4810: 09 09 09 70 61 74 68 69 6e 66 6f 2d 3e 74 79 70 ...pathinfo->typ
4820: 65 20 3d 20 41 50 50 46 53 5f 50 41 54 48 54 59 e = APPFS_PATHTY
4830: 50 45 5f 46 49 46 4f 3b 0a 09 09 09 62 72 65 61 PE_FIFO;....brea
4840: 6b 3b 0a 09 09 63 61 73 65 20 27 53 27 3a 20 2f k;...case 'S': /
4850: 2a 20 55 4e 49 58 20 64 6f 6d 61 69 6e 20 73 6f * UNIX domain so
4860: 63 6b 65 74 20 2a 2f 0a 09 09 09 70 61 74 68 69 cket */....pathi
4870: 6e 66 6f 2d 3e 74 79 70 65 20 3d 20 41 50 50 46 nfo->type = APPF
4880: 53 5f 50 41 54 48 54 59 50 45 5f 53 4f 43 4b 45 S_PATHTYPE_SOCKE
4890: 54 3b 0a 09 09 09 62 72 65 61 6b 3b 0a 09 09 64 T;....break;...d
48a0: 65 66 61 75 6c 74 3a 0a 09 09 09 72 65 74 75 72 efault:....retur
48b0: 6e 28 2d 45 49 4f 29 3b 0a 09 7d 0a 0a 09 54 63 n(-EIO);..}...Tc
48c0: 6c 5f 44 69 63 74 4f 62 6a 47 65 74 28 69 6e 74 l_DictObjGet(int
48d0: 65 72 70 2c 20 61 74 74 72 73 5f 64 69 63 74 2c erp, attrs_dict,
48e0: 20 61 74 74 72 5f 6b 65 79 5f 70 61 63 6b 61 67 attr_key_packag
48f0: 65 64 2c 20 26 61 74 74 72 5f 76 61 6c 75 65 29 ed, &attr_value)
4900: 3b 0a 09 69 66 20 28 61 74 74 72 5f 76 61 6c 75 ;..if (attr_valu
4910: 65 20 21 3d 20 4e 55 4c 4c 29 20 7b 0a 09 09 70 e != NULL) {...p
4920: 61 74 68 69 6e 66 6f 2d 3e 70 61 63 6b 61 67 65 athinfo->package
4930: 64 20 3d 20 31 3b 0a 09 7d 0a 0a 09 54 63 6c 5f d = 1;..}...Tcl_
4940: 44 69 63 74 4f 62 6a 47 65 74 28 69 6e 74 65 72 DictObjGet(inter
4950: 70 2c 20 61 74 74 72 73 5f 64 69 63 74 2c 20 61 p, attrs_dict, a
4960: 74 74 72 5f 6b 65 79 5f 74 69 6d 65 2c 20 26 61 ttr_key_time, &a
4970: 74 74 72 5f 76 61 6c 75 65 29 3b 0a 09 69 66 20 ttr_value);..if
4980: 28 61 74 74 72 5f 76 61 6c 75 65 20 21 3d 20 4e (attr_value != N
4990: 55 4c 4c 29 20 7b 0a 09 09 74 63 6c 5f 72 65 74 ULL) {...tcl_ret
49a0: 20 3d 20 54 63 6c 5f 47 65 74 57 69 64 65 49 6e = Tcl_GetWideIn
49b0: 74 46 72 6f 6d 4f 62 6a 28 4e 55 4c 4c 2c 20 61 tFromObj(NULL, a
49c0: 74 74 72 5f 76 61 6c 75 65 2c 20 26 61 74 74 72 ttr_value, &attr
49d0: 5f 76 61 6c 75 65 5f 77 69 64 65 29 3b 0a 09 09 _value_wide);...
49e0: 69 66 20 28 74 63 6c 5f 72 65 74 20 3d 3d 20 54 if (tcl_ret == T
49f0: 43 4c 5f 4f 4b 29 20 7b 0a 09 09 09 70 61 74 68 CL_OK) {....path
4a00: 69 6e 66 6f 2d 3e 74 69 6d 65 20 3d 20 61 74 74 info->time = att
4a10: 72 5f 76 61 6c 75 65 5f 77 69 64 65 3b 0a 09 09 r_value_wide;...
4a20: 7d 0a 09 7d 20 65 6c 73 65 20 7b 0a 09 09 70 61 }..} else {...pa
4a30: 74 68 69 6e 66 6f 2d 3e 74 69 6d 65 20 3d 20 30 thinfo->time = 0
4a40: 3b 0a 09 7d 0a 0a 09 61 70 70 66 73 5f 67 65 74 ;..}...appfs_get
4a50: 5f 70 61 74 68 5f 69 6e 66 6f 5f 63 61 63 68 65 _path_info_cache
4a60: 5f 61 64 64 28 70 61 74 68 2c 20 61 70 70 66 73 _add(path, appfs
4a70: 5f 67 65 74 5f 66 73 75 69 64 28 29 2c 20 70 61 _get_fsuid(), pa
4a80: 74 68 69 6e 66 6f 29 3b 0a 0a 09 72 65 74 75 72 thinfo);...retur
4a90: 6e 28 30 29 3b 0a 7d 0a 0a 73 74 61 74 69 63 20 n(0);.}..static
4aa0: 63 68 61 72 20 2a 61 70 70 66 73 5f 70 72 65 70 char *appfs_prep
4ab0: 61 72 65 5f 74 6f 5f 63 72 65 61 74 65 28 63 6f are_to_create(co
4ac0: 6e 73 74 20 63 68 61 72 20 2a 70 61 74 68 29 20 nst char *path)
4ad0: 7b 0a 09 54 63 6c 5f 49 6e 74 65 72 70 20 2a 69 {..Tcl_Interp *i
4ae0: 6e 74 65 72 70 3b 0a 09 63 6f 6e 73 74 20 63 68 nterp;..const ch
4af0: 61 72 20 2a 72 65 61 6c 5f 70 61 74 68 3b 0a 09 ar *real_path;..
4b00: 69 6e 74 20 74 63 6c 5f 72 65 74 3b 0a 0a 09 61 int tcl_ret;...a
4b10: 70 70 66 73 5f 67 65 74 5f 70 61 74 68 5f 69 6e ppfs_get_path_in
4b20: 66 6f 5f 63 61 63 68 65 5f 66 6c 75 73 68 28 61 fo_cache_flush(a
4b30: 70 70 66 73 5f 67 65 74 5f 66 73 75 69 64 28 29 ppfs_get_fsuid()
4b40: 2c 20 2d 31 29 3b 0a 0a 09 69 6e 74 65 72 70 20 , -1);...interp
4b50: 3d 20 61 70 70 66 73 5f 54 63 6c 49 6e 74 65 72 = appfs_TclInter
4b60: 70 28 29 3b 0a 09 69 66 20 28 69 6e 74 65 72 70 p();..if (interp
4b70: 20 3d 3d 20 4e 55 4c 4c 29 20 7b 0a 09 09 72 65 == NULL) {...re
4b80: 74 75 72 6e 28 4e 55 4c 4c 29 3b 0a 09 7d 0a 0a turn(NULL);..}..
4b90: 09 74 63 6c 5f 72 65 74 20 3d 20 61 70 70 66 73 .tcl_ret = appfs
4ba0: 5f 54 63 6c 5f 45 76 61 6c 28 69 6e 74 65 72 70 _Tcl_Eval(interp
4bb0: 2c 20 32 2c 20 22 3a 3a 61 70 70 66 73 3a 3a 70 , 2, "::appfs::p
4bc0: 72 65 70 61 72 65 5f 74 6f 5f 63 72 65 61 74 65 repare_to_create
4bd0: 22 2c 20 70 61 74 68 29 3b 0a 09 69 66 20 28 74 ", path);..if (t
4be0: 63 6c 5f 72 65 74 20 21 3d 20 54 43 4c 5f 4f 4b cl_ret != TCL_OK
4bf0: 29 20 7b 0a 09 09 41 50 50 46 53 5f 44 45 42 55 ) {...APPFS_DEBU
4c00: 47 28 22 3a 3a 61 70 70 66 73 3a 3a 70 72 65 70 G("::appfs::prep
4c10: 61 72 65 5f 74 6f 5f 63 72 65 61 74 65 28 25 73 are_to_create(%s
4c20: 29 20 66 61 69 6c 65 64 2e 22 2c 20 70 61 74 68 ) failed.", path
4c30: 29 3b 0a 09 09 41 50 50 46 53 5f 44 45 42 55 47 );...APPFS_DEBUG
4c40: 28 22 54 63 6c 20 45 72 72 6f 72 20 69 73 3a 20 ("Tcl Error is:
4c50: 25 73 22 2c 20 54 63 6c 5f 47 65 74 53 74 72 69 %s", Tcl_GetStri
4c60: 6e 67 52 65 73 75 6c 74 28 69 6e 74 65 72 70 29 ngResult(interp)
4c70: 29 3b 0a 0a 09 09 72 65 74 75 72 6e 28 4e 55 4c );....return(NUL
4c80: 4c 29 3b 0a 09 7d 0a 0a 09 72 65 61 6c 5f 70 61 L);..}...real_pa
4c90: 74 68 20 3d 20 54 63 6c 5f 47 65 74 53 74 72 69 th = Tcl_GetStri
4ca0: 6e 67 52 65 73 75 6c 74 28 69 6e 74 65 72 70 29 ngResult(interp)
4cb0: 3b 0a 09 69 66 20 28 72 65 61 6c 5f 70 61 74 68 ;..if (real_path
4cc0: 20 3d 3d 20 4e 55 4c 4c 29 20 7b 0a 09 09 72 65 == NULL) {...re
4cd0: 74 75 72 6e 28 4e 55 4c 4c 29 3b 0a 09 7d 0a 0a turn(NULL);..}..
4ce0: 09 72 65 74 75 72 6e 28 73 74 72 64 75 70 28 72 .return(strdup(r
4cf0: 65 61 6c 5f 70 61 74 68 29 29 3b 0a 7d 0a 0a 73 eal_path));.}..s
4d00: 74 61 74 69 63 20 63 68 61 72 20 2a 61 70 70 66 tatic char *appf
4d10: 73 5f 6c 6f 63 61 6c 70 61 74 68 28 63 6f 6e 73 s_localpath(cons
4d20: 74 20 63 68 61 72 20 2a 70 61 74 68 29 20 7b 0a t char *path) {.
4d30: 09 54 63 6c 5f 49 6e 74 65 72 70 20 2a 69 6e 74 .Tcl_Interp *int
4d40: 65 72 70 3b 0a 09 63 6f 6e 73 74 20 63 68 61 72 erp;..const char
4d50: 20 2a 72 65 61 6c 5f 70 61 74 68 3b 0a 09 69 6e *real_path;..in
4d60: 74 20 74 63 6c 5f 72 65 74 3b 0a 0a 09 69 6e 74 t tcl_ret;...int
4d70: 65 72 70 20 3d 20 61 70 70 66 73 5f 54 63 6c 49 erp = appfs_TclI
4d80: 6e 74 65 72 70 28 29 3b 0a 09 69 66 20 28 69 6e nterp();..if (in
4d90: 74 65 72 70 20 3d 3d 20 4e 55 4c 4c 29 20 7b 0a terp == NULL) {.
4da0: 09 09 72 65 74 75 72 6e 28 4e 55 4c 4c 29 3b 0a ..return(NULL);.
4db0: 09 7d 0a 0a 09 74 63 6c 5f 72 65 74 20 3d 20 61 .}...tcl_ret = a
4dc0: 70 70 66 73 5f 54 63 6c 5f 45 76 61 6c 28 69 6e ppfs_Tcl_Eval(in
4dd0: 74 65 72 70 2c 20 32 2c 20 22 3a 3a 61 70 70 66 terp, 2, "::appf
4de0: 73 3a 3a 6c 6f 63 61 6c 70 61 74 68 22 2c 20 70 s::localpath", p
4df0: 61 74 68 29 3b 0a 09 69 66 20 28 74 63 6c 5f 72 ath);..if (tcl_r
4e00: 65 74 20 21 3d 20 54 43 4c 5f 4f 4b 29 20 7b 0a et != TCL_OK) {.
4e10: 09 09 41 50 50 46 53 5f 44 45 42 55 47 28 22 3a ..APPFS_DEBUG(":
4e20: 3a 61 70 70 66 73 3a 3a 6c 6f 63 61 6c 70 61 74 :appfs::localpat
4e30: 68 28 25 73 29 20 66 61 69 6c 65 64 2e 22 2c 20 h(%s) failed.",
4e40: 70 61 74 68 29 3b 0a 09 09 41 50 50 46 53 5f 44 path);...APPFS_D
4e50: 45 42 55 47 28 22 54 63 6c 20 45 72 72 6f 72 20 EBUG("Tcl Error
4e60: 69 73 3a 20 25 73 22 2c 20 54 63 6c 5f 47 65 74 is: %s", Tcl_Get
4e70: 53 74 72 69 6e 67 52 65 73 75 6c 74 28 69 6e 74 StringResult(int
4e80: 65 72 70 29 29 3b 0a 0a 09 09 72 65 74 75 72 6e erp));....return
4e90: 28 4e 55 4c 4c 29 3b 0a 09 7d 0a 0a 09 72 65 61 (NULL);..}...rea
4ea0: 6c 5f 70 61 74 68 20 3d 20 54 63 6c 5f 47 65 74 l_path = Tcl_Get
4eb0: 53 74 72 69 6e 67 52 65 73 75 6c 74 28 69 6e 74 StringResult(int
4ec0: 65 72 70 29 3b 0a 09 69 66 20 28 72 65 61 6c 5f erp);..if (real_
4ed0: 70 61 74 68 20 3d 3d 20 4e 55 4c 4c 29 20 7b 0a path == NULL) {.
4ee0: 09 09 72 65 74 75 72 6e 28 4e 55 4c 4c 29 3b 0a ..return(NULL);.
4ef0: 09 7d 0a 0a 09 72 65 74 75 72 6e 28 73 74 72 64 .}...return(strd
4f00: 75 70 28 72 65 61 6c 5f 70 61 74 68 29 29 3b 0a up(real_path));.
4f10: 7d 0a 0a 73 74 61 74 69 63 20 69 6e 74 20 61 70 }..static int ap
4f20: 70 66 73 5f 66 75 73 65 5f 72 65 61 64 6c 69 6e pfs_fuse_readlin
4f30: 6b 28 63 6f 6e 73 74 20 63 68 61 72 20 2a 70 61 k(const char *pa
4f40: 74 68 2c 20 63 68 61 72 20 2a 62 75 66 2c 20 73 th, char *buf, s
4f50: 69 7a 65 5f 74 20 73 69 7a 65 29 20 7b 0a 09 73 ize_t size) {..s
4f60: 74 72 75 63 74 20 61 70 70 66 73 5f 70 61 74 68 truct appfs_path
4f70: 69 6e 66 6f 20 70 61 74 68 69 6e 66 6f 3b 0a 09 info pathinfo;..
4f80: 69 6e 74 20 72 65 74 76 61 6c 20 3d 20 30 3b 0a int retval = 0;.
4f90: 0a 09 41 50 50 46 53 5f 44 45 42 55 47 28 22 45 ..APPFS_DEBUG("E
4fa0: 6e 74 65 72 20 28 70 61 74 68 20 3d 20 25 73 2c nter (path = %s,
4fb0: 20 2e 2e 2e 29 22 2c 20 70 61 74 68 29 3b 0a 0a ...)", path);..
4fc0: 09 70 61 74 68 69 6e 66 6f 2e 74 79 70 65 20 3d .pathinfo.type =
4fd0: 20 41 50 50 46 53 5f 50 41 54 48 54 59 50 45 5f APPFS_PATHTYPE_
4fe0: 49 4e 56 41 4c 49 44 3b 0a 0a 09 72 65 74 76 61 INVALID;...retva
4ff0: 6c 20 3d 20 61 70 70 66 73 5f 67 65 74 5f 70 61 l = appfs_get_pa
5000: 74 68 5f 69 6e 66 6f 28 70 61 74 68 2c 20 26 70 th_info(path, &p
5010: 61 74 68 69 6e 66 6f 29 3b 0a 09 69 66 20 28 72 athinfo);..if (r
5020: 65 74 76 61 6c 20 21 3d 20 30 29 20 7b 0a 09 09 etval != 0) {...
5030: 72 65 74 75 72 6e 28 72 65 74 76 61 6c 29 3b 0a return(retval);.
5040: 09 7d 0a 0a 09 69 66 20 28 70 61 74 68 69 6e 66 .}...if (pathinf
5050: 6f 2e 74 79 70 65 20 21 3d 20 41 50 50 46 53 5f o.type != APPFS_
5060: 50 41 54 48 54 59 50 45 5f 53 59 4d 4c 49 4e 4b PATHTYPE_SYMLINK
5070: 29 20 7b 0a 09 09 72 65 74 75 72 6e 28 2d 45 49 ) {...return(-EI
5080: 4e 56 41 4c 29 3b 0a 09 7d 0a 0a 09 69 66 20 28 NVAL);..}...if (
5090: 28 73 74 72 6c 65 6e 28 70 61 74 68 69 6e 66 6f (strlen(pathinfo
50a0: 2e 74 79 70 65 69 6e 66 6f 2e 73 79 6d 6c 69 6e .typeinfo.symlin
50b0: 6b 2e 73 6f 75 72 63 65 29 20 2b 20 31 29 20 3e k.source) + 1) >
50c0: 20 73 69 7a 65 29 20 7b 0a 09 09 72 65 74 75 72 size) {...retur
50d0: 6e 28 2d 45 4e 41 4d 45 54 4f 4f 4c 4f 4e 47 29 n(-ENAMETOOLONG)
50e0: 3b 0a 09 7d 0a 0a 09 6d 65 6d 63 70 79 28 62 75 ;..}...memcpy(bu
50f0: 66 2c 20 70 61 74 68 69 6e 66 6f 2e 74 79 70 65 f, pathinfo.type
5100: 69 6e 66 6f 2e 73 79 6d 6c 69 6e 6b 2e 73 6f 75 info.symlink.sou
5110: 72 63 65 2c 20 73 74 72 6c 65 6e 28 70 61 74 68 rce, strlen(path
5120: 69 6e 66 6f 2e 74 79 70 65 69 6e 66 6f 2e 73 79 info.typeinfo.sy
5130: 6d 6c 69 6e 6b 2e 73 6f 75 72 63 65 29 20 2b 20 mlink.source) +
5140: 31 29 3b 0a 0a 09 72 65 74 75 72 6e 28 30 29 3b 1);...return(0);
5150: 0a 7d 0a 0a 73 74 61 74 69 63 20 69 6e 74 20 61 .}..static int a
5160: 70 70 66 73 5f 66 75 73 65 5f 67 65 74 61 74 74 ppfs_fuse_getatt
5170: 72 28 63 6f 6e 73 74 20 63 68 61 72 20 2a 70 61 r(const char *pa
5180: 74 68 2c 20 73 74 72 75 63 74 20 73 74 61 74 20 th, struct stat
5190: 2a 73 74 62 75 66 29 20 7b 0a 09 73 74 72 75 63 *stbuf) {..struc
51a0: 74 20 61 70 70 66 73 5f 70 61 74 68 69 6e 66 6f t appfs_pathinfo
51b0: 20 70 61 74 68 69 6e 66 6f 3b 0a 09 69 6e 74 20 pathinfo;..int
51c0: 72 65 74 76 61 6c 3b 0a 0a 09 72 65 74 76 61 6c retval;...retval
51d0: 20 3d 20 30 3b 0a 0a 09 41 50 50 46 53 5f 44 45 = 0;...APPFS_DE
51e0: 42 55 47 28 22 45 6e 74 65 72 20 28 70 61 74 68 BUG("Enter (path
51f0: 20 3d 20 25 73 2c 20 2e 2e 2e 29 22 2c 20 70 61 = %s, ...)", pa
5200: 74 68 29 3b 0a 0a 09 70 61 74 68 69 6e 66 6f 2e th);...pathinfo.
5210: 74 79 70 65 20 3d 20 41 50 50 46 53 5f 50 41 54 type = APPFS_PAT
5220: 48 54 59 50 45 5f 49 4e 56 41 4c 49 44 3b 0a 0a HTYPE_INVALID;..
5230: 09 72 65 74 76 61 6c 20 3d 20 61 70 70 66 73 5f .retval = appfs_
5240: 67 65 74 5f 70 61 74 68 5f 69 6e 66 6f 28 70 61 get_path_info(pa
5250: 74 68 2c 20 26 70 61 74 68 69 6e 66 6f 29 3b 0a th, &pathinfo);.
5260: 09 69 66 20 28 72 65 74 76 61 6c 20 21 3d 20 30 .if (retval != 0
5270: 29 20 7b 0a 09 09 72 65 74 75 72 6e 28 72 65 74 ) {...return(ret
5280: 76 61 6c 29 3b 0a 09 7d 0a 0a 09 6d 65 6d 73 65 val);..}...memse
5290: 74 28 73 74 62 75 66 2c 20 30 2c 20 73 69 7a 65 t(stbuf, 0, size
52a0: 6f 66 28 73 74 72 75 63 74 20 73 74 61 74 29 29 of(struct stat))
52b0: 3b 0a 0a 09 73 74 62 75 66 2d 3e 73 74 5f 6d 74 ;...stbuf->st_mt
52c0: 69 6d 65 20 3d 20 70 61 74 68 69 6e 66 6f 2e 74 ime = pathinfo.t
52d0: 69 6d 65 3b 0a 09 73 74 62 75 66 2d 3e 73 74 5f ime;..stbuf->st_
52e0: 63 74 69 6d 65 20 3d 20 70 61 74 68 69 6e 66 6f ctime = pathinfo
52f0: 2e 74 69 6d 65 3b 0a 09 73 74 62 75 66 2d 3e 73 .time;..stbuf->s
5300: 74 5f 61 74 69 6d 65 20 3d 20 70 61 74 68 69 6e t_atime = pathin
5310: 66 6f 2e 74 69 6d 65 3b 0a 09 73 74 62 75 66 2d fo.time;..stbuf-
5320: 3e 73 74 5f 69 6e 6f 20 20 20 3d 20 70 61 74 68 >st_ino = path
5330: 69 6e 66 6f 2e 69 6e 6f 64 65 3b 0a 09 73 74 62 info.inode;..stb
5340: 75 66 2d 3e 73 74 5f 6d 6f 64 65 20 20 3d 20 30 uf->st_mode = 0
5350: 3b 0a 0a 09 73 77 69 74 63 68 20 28 70 61 74 68 ;...switch (path
5360: 69 6e 66 6f 2e 74 79 70 65 29 20 7b 0a 09 09 63 info.type) {...c
5370: 61 73 65 20 41 50 50 46 53 5f 50 41 54 48 54 59 ase APPFS_PATHTY
5380: 50 45 5f 44 49 52 45 43 54 4f 52 59 3a 0a 09 09 PE_DIRECTORY:...
5390: 09 73 74 62 75 66 2d 3e 73 74 5f 6d 6f 64 65 20 .stbuf->st_mode
53a0: 3d 20 53 5f 49 46 44 49 52 20 7c 20 30 35 35 35 = S_IFDIR | 0555
53b0: 3b 0a 09 09 09 73 74 62 75 66 2d 3e 73 74 5f 6e ;....stbuf->st_n
53c0: 6c 69 6e 6b 20 3d 20 32 20 2b 20 70 61 74 68 69 link = 2 + pathi
53d0: 6e 66 6f 2e 74 79 70 65 69 6e 66 6f 2e 64 69 72 nfo.typeinfo.dir
53e0: 2e 63 68 69 6c 64 63 6f 75 6e 74 3b 0a 09 09 09 .childcount;....
53f0: 62 72 65 61 6b 3b 0a 09 09 63 61 73 65 20 41 50 break;...case AP
5400: 50 46 53 5f 50 41 54 48 54 59 50 45 5f 46 49 4c PFS_PATHTYPE_FIL
5410: 45 3a 0a 09 09 09 69 66 20 28 70 61 74 68 69 6e E:....if (pathin
5420: 66 6f 2e 74 79 70 65 69 6e 66 6f 2e 66 69 6c 65 fo.typeinfo.file
5430: 2e 65 78 65 63 75 74 61 62 6c 65 29 20 7b 0a 09 .executable) {..
5440: 09 09 09 73 74 62 75 66 2d 3e 73 74 5f 6d 6f 64 ...stbuf->st_mod
5450: 65 20 3d 20 53 5f 49 46 52 45 47 20 7c 20 30 35 e = S_IFREG | 05
5460: 35 35 3b 0a 09 09 09 7d 20 65 6c 73 65 20 7b 0a 55;....} else {.
5470: 09 09 09 09 73 74 62 75 66 2d 3e 73 74 5f 6d 6f ....stbuf->st_mo
5480: 64 65 20 3d 20 53 5f 49 46 52 45 47 20 7c 20 30 de = S_IFREG | 0
5490: 34 34 34 3b 0a 09 09 09 7d 0a 0a 09 09 09 73 74 444;....}.....st
54a0: 62 75 66 2d 3e 73 74 5f 6e 6c 69 6e 6b 20 3d 20 buf->st_nlink =
54b0: 31 3b 0a 09 09 09 73 74 62 75 66 2d 3e 73 74 5f 1;....stbuf->st_
54c0: 73 69 7a 65 20 3d 20 70 61 74 68 69 6e 66 6f 2e size = pathinfo.
54d0: 74 79 70 65 69 6e 66 6f 2e 66 69 6c 65 2e 73 69 typeinfo.file.si
54e0: 7a 65 3b 0a 09 09 09 62 72 65 61 6b 3b 0a 09 09 ze;....break;...
54f0: 63 61 73 65 20 41 50 50 46 53 5f 50 41 54 48 54 case APPFS_PATHT
5500: 59 50 45 5f 53 59 4d 4c 49 4e 4b 3a 0a 09 09 09 YPE_SYMLINK:....
5510: 73 74 62 75 66 2d 3e 73 74 5f 6d 6f 64 65 20 3d stbuf->st_mode =
5520: 20 53 5f 49 46 4c 4e 4b 20 7c 20 30 35 35 35 3b S_IFLNK | 0555;
5530: 0a 09 09 09 73 74 62 75 66 2d 3e 73 74 5f 6e 6c ....stbuf->st_nl
5540: 69 6e 6b 20 3d 20 31 3b 0a 09 09 09 73 74 62 75 ink = 1;....stbu
5550: 66 2d 3e 73 74 5f 73 69 7a 65 20 3d 20 70 61 74 f->st_size = pat
5560: 68 69 6e 66 6f 2e 74 79 70 65 69 6e 66 6f 2e 73 hinfo.typeinfo.s
5570: 79 6d 6c 69 6e 6b 2e 73 69 7a 65 3b 0a 09 09 09 ymlink.size;....
5580: 62 72 65 61 6b 3b 0a 09 09 63 61 73 65 20 41 50 break;...case AP
5590: 50 46 53 5f 50 41 54 48 54 59 50 45 5f 53 4f 43 PFS_PATHTYPE_SOC
55a0: 4b 45 54 3a 0a 09 09 09 73 74 62 75 66 2d 3e 73 KET:....stbuf->s
55b0: 74 5f 6d 6f 64 65 20 3d 20 53 5f 49 46 53 4f 43 t_mode = S_IFSOC
55c0: 4b 20 7c 20 30 35 35 35 3b 0a 09 09 09 73 74 62 K | 0555;....stb
55d0: 75 66 2d 3e 73 74 5f 6e 6c 69 6e 6b 20 3d 20 31 uf->st_nlink = 1
55e0: 3b 0a 09 09 09 73 74 62 75 66 2d 3e 73 74 5f 73 ;....stbuf->st_s
55f0: 69 7a 65 20 3d 20 30 3b 0a 09 09 09 62 72 65 61 ize = 0;....brea
5600: 6b 3b 0a 09 09 63 61 73 65 20 41 50 50 46 53 5f k;...case APPFS_
5610: 50 41 54 48 54 59 50 45 5f 46 49 46 4f 3a 0a 09 PATHTYPE_FIFO:..
5620: 09 09 73 74 62 75 66 2d 3e 73 74 5f 6d 6f 64 65 ..stbuf->st_mode
5630: 20 3d 20 53 5f 49 46 49 46 4f 20 7c 20 30 35 35 = S_IFIFO | 055
5640: 35 3b 0a 09 09 09 73 74 62 75 66 2d 3e 73 74 5f 5;....stbuf->st_
5650: 6e 6c 69 6e 6b 20 3d 20 31 3b 0a 09 09 09 73 74 nlink = 1;....st
5660: 62 75 66 2d 3e 73 74 5f 73 69 7a 65 20 3d 20 30 buf->st_size = 0
5670: 3b 0a 09 09 09 62 72 65 61 6b 3b 0a 09 09 63 61 ;....break;...ca
5680: 73 65 20 41 50 50 46 53 5f 50 41 54 48 54 59 50 se APPFS_PATHTYP
5690: 45 5f 44 4f 45 53 5f 4e 4f 54 5f 45 58 49 53 54 E_DOES_NOT_EXIST
56a0: 3a 0a 09 09 09 72 65 74 76 61 6c 20 3d 20 2d 45 :....retval = -E
56b0: 4e 4f 45 4e 54 3b 0a 0a 09 09 09 62 72 65 61 6b NOENT;.....break
56c0: 3b 0a 09 09 63 61 73 65 20 41 50 50 46 53 5f 50 ;...case APPFS_P
56d0: 41 54 48 54 59 50 45 5f 49 4e 56 41 4c 49 44 3a ATHTYPE_INVALID:
56e0: 0a 09 09 09 72 65 74 76 61 6c 20 3d 20 2d 45 49 ....retval = -EI
56f0: 4f 3b 0a 0a 09 09 09 62 72 65 61 6b 3b 0a 09 7d O;.....break;..}
5700: 0a 0a 09 69 66 20 28 70 61 74 68 69 6e 66 6f 2e ...if (pathinfo.
5710: 70 61 63 6b 61 67 65 64 29 20 7b 0a 09 09 73 74 packaged) {...st
5720: 62 75 66 2d 3e 73 74 5f 75 69 64 20 20 20 3d 20 buf->st_uid =
5730: 61 70 70 66 73 5f 67 65 74 5f 66 73 75 69 64 28 appfs_get_fsuid(
5740: 29 3b 0a 09 09 73 74 62 75 66 2d 3e 73 74 5f 67 );...stbuf->st_g
5750: 69 64 20 20 20 3d 20 61 70 70 66 73 5f 67 65 74 id = appfs_get
5760: 5f 66 73 67 69 64 28 29 3b 0a 09 09 73 74 62 75 _fsgid();...stbu
5770: 66 2d 3e 73 74 5f 6d 6f 64 65 20 7c 3d 20 30 32 f->st_mode |= 02
5780: 30 30 3b 0a 09 7d 0a 0a 09 72 65 74 75 72 6e 28 00;..}...return(
5790: 72 65 74 76 61 6c 29 3b 0a 7d 0a 0a 73 74 61 74 retval);.}..stat
57a0: 69 63 20 69 6e 74 20 61 70 70 66 73 5f 66 75 73 ic int appfs_fus
57b0: 65 5f 72 65 61 64 64 69 72 28 63 6f 6e 73 74 20 e_readdir(const
57c0: 63 68 61 72 20 2a 70 61 74 68 2c 20 76 6f 69 64 char *path, void
57d0: 20 2a 62 75 66 2c 20 66 75 73 65 5f 66 69 6c 6c *buf, fuse_fill
57e0: 5f 64 69 72 5f 74 20 66 69 6c 6c 65 72 2c 20 6f _dir_t filler, o
57f0: 66 66 5f 74 20 6f 66 66 73 65 74 2c 20 73 74 72 ff_t offset, str
5800: 75 63 74 20 66 75 73 65 5f 66 69 6c 65 5f 69 6e uct fuse_file_in
5810: 66 6f 20 2a 66 69 29 20 7b 0a 09 54 63 6c 5f 49 fo *fi) {..Tcl_I
5820: 6e 74 65 72 70 20 2a 69 6e 74 65 72 70 3b 0a 09 nterp *interp;..
5830: 54 63 6c 5f 4f 62 6a 20 2a 2a 63 68 69 6c 64 72 Tcl_Obj **childr
5840: 65 6e 3b 0a 09 69 6e 74 20 63 68 69 6c 64 72 65 en;..int childre
5850: 6e 5f 63 6f 75 6e 74 2c 20 69 64 78 3b 0a 09 69 n_count, idx;..i
5860: 6e 74 20 74 63 6c 5f 72 65 74 3b 0a 0a 09 41 50 nt tcl_ret;...AP
5870: 50 46 53 5f 44 45 42 55 47 28 22 45 6e 74 65 72 PFS_DEBUG("Enter
5880: 20 28 70 61 74 68 20 3d 20 25 73 2c 20 2e 2e 2e (path = %s, ...
5890: 29 22 2c 20 70 61 74 68 29 3b 0a 0a 09 69 6e 74 )", path);...int
58a0: 65 72 70 20 3d 20 61 70 70 66 73 5f 54 63 6c 49 erp = appfs_TclI
58b0: 6e 74 65 72 70 28 29 3b 0a 09 69 66 20 28 69 6e nterp();..if (in
58c0: 74 65 72 70 20 3d 3d 20 4e 55 4c 4c 29 20 7b 0a terp == NULL) {.
58d0: 09 09 72 65 74 75 72 6e 28 30 29 3b 0a 09 7d 0a ..return(0);..}.
58e0: 0a 09 66 69 6c 6c 65 72 28 62 75 66 2c 20 22 2e ..filler(buf, ".
58f0: 22 2c 20 4e 55 4c 4c 2c 20 30 29 3b 0a 09 66 69 ", NULL, 0);..fi
5900: 6c 6c 65 72 28 62 75 66 2c 20 22 2e 2e 22 2c 20 ller(buf, "..",
5910: 4e 55 4c 4c 2c 20 30 29 3b 0a 0a 09 74 63 6c 5f NULL, 0);...tcl_
5920: 72 65 74 20 3d 20 61 70 70 66 73 5f 54 63 6c 5f ret = appfs_Tcl_
5930: 45 76 61 6c 28 69 6e 74 65 72 70 2c 20 32 2c 20 Eval(interp, 2,
5940: 22 3a 3a 61 70 70 66 73 3a 3a 67 65 74 63 68 69 "::appfs::getchi
5950: 6c 64 72 65 6e 22 2c 20 70 61 74 68 29 3b 0a 09 ldren", path);..
5960: 69 66 20 28 74 63 6c 5f 72 65 74 20 21 3d 20 54 if (tcl_ret != T
5970: 43 4c 5f 4f 4b 29 20 7b 0a 09 09 41 50 50 46 53 CL_OK) {...APPFS
5980: 5f 44 45 42 55 47 28 22 3a 3a 61 70 70 66 73 3a _DEBUG("::appfs:
5990: 3a 67 65 74 63 68 69 6c 64 72 65 6e 28 25 73 29 :getchildren(%s)
59a0: 20 66 61 69 6c 65 64 2e 22 2c 20 70 61 74 68 29 failed.", path)
59b0: 3b 0a 09 09 41 50 50 46 53 5f 44 45 42 55 47 28 ;...APPFS_DEBUG(
59c0: 22 54 63 6c 20 45 72 72 6f 72 20 69 73 3a 20 25 "Tcl Error is: %
59d0: 73 22 2c 20 54 63 6c 5f 47 65 74 53 74 72 69 6e s", Tcl_GetStrin
59e0: 67 52 65 73 75 6c 74 28 69 6e 74 65 72 70 29 29 gResult(interp))
59f0: 3b 0a 0a 09 09 72 65 74 75 72 6e 28 30 29 3b 0a ;....return(0);.
5a00: 09 7d 0a 0a 09 74 63 6c 5f 72 65 74 20 3d 20 54 .}...tcl_ret = T
5a10: 63 6c 5f 4c 69 73 74 4f 62 6a 47 65 74 45 6c 65 cl_ListObjGetEle
5a20: 6d 65 6e 74 73 28 69 6e 74 65 72 70 2c 20 54 63 ments(interp, Tc
5a30: 6c 5f 47 65 74 4f 62 6a 52 65 73 75 6c 74 28 69 l_GetObjResult(i
5a40: 6e 74 65 72 70 29 2c 20 26 63 68 69 6c 64 72 65 nterp), &childre
5a50: 6e 5f 63 6f 75 6e 74 2c 20 26 63 68 69 6c 64 72 n_count, &childr
5a60: 65 6e 29 3b 0a 09 69 66 20 28 74 63 6c 5f 72 65 en);..if (tcl_re
5a70: 74 20 21 3d 20 54 43 4c 5f 4f 4b 29 20 7b 0a 09 t != TCL_OK) {..
5a80: 09 41 50 50 46 53 5f 44 45 42 55 47 28 22 50 61 .APPFS_DEBUG("Pa
5a90: 72 73 69 6e 67 20 6c 69 73 74 20 6f 66 20 63 68 rsing list of ch
5aa0: 69 6c 64 72 65 6e 20 6f 6e 20 70 61 74 68 20 25 ildren on path %
5ab0: 73 20 66 61 69 6c 65 64 2e 22 2c 20 70 61 74 68 s failed.", path
5ac0: 29 3b 0a 09 09 41 50 50 46 53 5f 44 45 42 55 47 );...APPFS_DEBUG
5ad0: 28 22 54 63 6c 20 45 72 72 6f 72 20 69 73 3a 20 ("Tcl Error is:
5ae0: 25 73 22 2c 20 54 63 6c 5f 47 65 74 53 74 72 69 %s", Tcl_GetStri
5af0: 6e 67 52 65 73 75 6c 74 28 69 6e 74 65 72 70 29 ngResult(interp)
5b00: 29 3b 0a 0a 09 09 72 65 74 75 72 6e 28 30 29 3b );....return(0);
5b10: 0a 09 7d 0a 0a 09 66 6f 72 20 28 69 64 78 20 3d ..}...for (idx =
5b20: 20 30 3b 20 69 64 78 20 3c 20 63 68 69 6c 64 72 0; idx < childr
5b30: 65 6e 5f 63 6f 75 6e 74 3b 20 69 64 78 2b 2b 29 en_count; idx++)
5b40: 20 7b 0a 09 09 66 69 6c 6c 65 72 28 62 75 66 2c {...filler(buf,
5b50: 20 54 63 6c 5f 47 65 74 53 74 72 69 6e 67 28 63 Tcl_GetString(c
5b60: 68 69 6c 64 72 65 6e 5b 69 64 78 5d 29 2c 20 4e hildren[idx]), N
5b70: 55 4c 4c 2c 20 30 29 3b 0a 09 7d 0a 0a 09 72 65 ULL, 0);..}...re
5b80: 74 75 72 6e 28 30 29 3b 0a 7d 0a 0a 73 74 61 74 turn(0);.}..stat
5b90: 69 63 20 69 6e 74 20 61 70 70 66 73 5f 66 75 73 ic int appfs_fus
5ba0: 65 5f 6f 70 65 6e 28 63 6f 6e 73 74 20 63 68 61 e_open(const cha
5bb0: 72 20 2a 70 61 74 68 2c 20 73 74 72 75 63 74 20 r *path, struct
5bc0: 66 75 73 65 5f 66 69 6c 65 5f 69 6e 66 6f 20 2a fuse_file_info *
5bd0: 66 69 29 20 7b 0a 09 54 63 6c 5f 49 6e 74 65 72 fi) {..Tcl_Inter
5be0: 70 20 2a 69 6e 74 65 72 70 3b 0a 09 73 74 72 75 p *interp;..stru
5bf0: 63 74 20 61 70 70 66 73 5f 70 61 74 68 69 6e 66 ct appfs_pathinf
5c00: 6f 20 70 61 74 68 69 6e 66 6f 3b 0a 09 63 6f 6e o pathinfo;..con
5c10: 73 74 20 63 68 61 72 20 2a 72 65 61 6c 5f 70 61 st char *real_pa
5c20: 74 68 2c 20 2a 6d 6f 64 65 3b 0a 09 69 6e 74 20 th, *mode;..int
5c30: 67 70 69 5f 72 65 74 2c 20 74 63 6c 5f 72 65 74 gpi_ret, tcl_ret
5c40: 3b 0a 09 69 6e 74 20 66 68 3b 0a 0a 09 41 50 50 ;..int fh;...APP
5c50: 46 53 5f 44 45 42 55 47 28 22 45 6e 74 65 72 20 FS_DEBUG("Enter
5c60: 28 70 61 74 68 20 3d 20 25 73 2c 20 2e 2e 2e 29 (path = %s, ...)
5c70: 22 2c 20 70 61 74 68 29 3b 0a 0a 09 67 70 69 5f ", path);...gpi_
5c80: 72 65 74 20 3d 20 61 70 70 66 73 5f 67 65 74 5f ret = appfs_get_
5c90: 70 61 74 68 5f 69 6e 66 6f 28 70 61 74 68 2c 20 path_info(path,
5ca0: 26 70 61 74 68 69 6e 66 6f 29 3b 0a 0a 09 69 66 &pathinfo);...if
5cb0: 20 28 28 66 69 2d 3e 66 6c 61 67 73 20 26 20 28 ((fi->flags & (
5cc0: 4f 5f 57 52 4f 4e 4c 59 7c 4f 5f 43 52 45 41 54 O_WRONLY|O_CREAT
5cd0: 29 29 20 3d 3d 20 28 4f 5f 43 52 45 41 54 7c 4f )) == (O_CREAT|O
5ce0: 5f 57 52 4f 4e 4c 59 29 29 20 7b 0a 09 09 2f 2a _WRONLY)) {.../*
5cf0: 20 54 68 65 20 66 69 6c 65 20 77 69 6c 6c 20 62 The file will b
5d00: 65 20 63 72 65 61 74 65 64 20 69 66 20 69 74 20 e created if it
5d10: 64 6f 65 73 20 6e 6f 74 20 65 78 69 73 74 20 2a does not exist *
5d20: 2f 0a 09 09 69 66 20 28 67 70 69 5f 72 65 74 20 /...if (gpi_ret
5d30: 21 3d 20 30 20 26 26 20 67 70 69 5f 72 65 74 20 != 0 && gpi_ret
5d40: 21 3d 20 2d 45 4e 4f 45 4e 54 29 20 7b 0a 09 09 != -ENOENT) {...
5d50: 09 72 65 74 75 72 6e 28 67 70 69 5f 72 65 74 29 .return(gpi_ret)
5d60: 3b 0a 09 09 7d 0a 0a 09 09 6d 6f 64 65 20 3d 20 ;...}....mode =
5d70: 22 63 72 65 61 74 65 22 3b 0a 0a 09 09 2f 2a 0a "create";..../*.
5d80: 09 09 20 2a 20 57 65 20 68 61 76 65 20 74 6f 20 .. * We have to
5d90: 63 6c 65 61 72 20 74 68 65 20 63 61 63 68 65 20 clear the cache
5da0: 68 65 72 65 20 73 6f 20 74 68 61 74 20 74 68 65 here so that the
5db0: 20 6e 75 6d 62 65 72 20 6f 66 0a 09 09 20 2a 20 number of... *
5dc0: 6c 69 6e 6b 73 20 67 65 74 73 20 6d 61 69 6e 74 links gets maint
5dd0: 61 69 6e 65 64 20 6f 6e 20 74 68 65 20 70 61 72 ained on the par
5de0: 65 6e 74 20 64 69 72 65 63 74 6f 72 79 0a 09 09 ent directory...
5df0: 20 2a 2f 0a 09 09 61 70 70 66 73 5f 67 65 74 5f */...appfs_get_
5e00: 70 61 74 68 5f 69 6e 66 6f 5f 63 61 63 68 65 5f path_info_cache_
5e10: 66 6c 75 73 68 28 61 70 70 66 73 5f 67 65 74 5f flush(appfs_get_
5e20: 66 73 75 69 64 28 29 2c 20 2d 31 29 3b 0a 09 7d fsuid(), -1);..}
5e30: 20 65 6c 73 65 20 7b 0a 09 09 2f 2a 20 54 68 65 else {.../* The
5e40: 20 66 69 6c 65 20 6d 75 73 74 20 61 6c 72 65 61 file must alrea
5e50: 64 79 20 65 78 69 73 74 20 2a 2f 0a 09 09 69 66 dy exist */...if
5e60: 20 28 67 70 69 5f 72 65 74 20 21 3d 20 30 29 20 (gpi_ret != 0)
5e70: 7b 0a 09 09 09 72 65 74 75 72 6e 28 67 70 69 5f {....return(gpi_
5e80: 72 65 74 29 3b 0a 09 09 7d 0a 0a 09 09 6d 6f 64 ret);...}....mod
5e90: 65 20 3d 20 22 22 3b 0a 0a 09 09 69 66 20 28 28 e = "";....if ((
5ea0: 66 69 2d 3e 66 6c 61 67 73 20 26 20 4f 5f 57 52 fi->flags & O_WR
5eb0: 4f 4e 4c 59 29 20 3d 3d 20 4f 5f 57 52 4f 4e 4c ONLY) == O_WRONL
5ec0: 59 29 20 7b 0a 09 09 09 6d 6f 64 65 20 3d 20 22 Y) {....mode = "
5ed0: 77 72 69 74 65 22 3b 0a 09 09 7d 0a 09 7d 0a 0a write";...}..}..
5ee0: 09 69 66 20 28 70 61 74 68 69 6e 66 6f 2e 74 79 .if (pathinfo.ty
5ef0: 70 65 20 3d 3d 20 41 50 50 46 53 5f 50 41 54 48 pe == APPFS_PATH
5f00: 54 59 50 45 5f 44 49 52 45 43 54 4f 52 59 29 20 TYPE_DIRECTORY)
5f10: 7b 0a 09 09 72 65 74 75 72 6e 28 2d 45 49 53 44 {...return(-EISD
5f20: 49 52 29 3b 0a 09 7d 0a 0a 09 69 6e 74 65 72 70 IR);..}...interp
5f30: 20 3d 20 61 70 70 66 73 5f 54 63 6c 49 6e 74 65 = appfs_TclInte
5f40: 72 70 28 29 3b 0a 09 69 66 20 28 69 6e 74 65 72 rp();..if (inter
5f50: 70 20 3d 3d 20 4e 55 4c 4c 29 20 7b 0a 09 09 72 p == NULL) {...r
5f60: 65 74 75 72 6e 28 2d 45 49 4f 29 3b 0a 09 7d 0a eturn(-EIO);..}.
5f70: 0a 09 74 63 6c 5f 72 65 74 20 3d 20 61 70 70 66 ..tcl_ret = appf
5f80: 73 5f 54 63 6c 5f 45 76 61 6c 28 69 6e 74 65 72 s_Tcl_Eval(inter
5f90: 70 2c 20 33 2c 20 22 3a 3a 61 70 70 66 73 3a 3a p, 3, "::appfs::
5fa0: 6f 70 65 6e 70 61 74 68 22 2c 20 70 61 74 68 2c openpath", path,
5fb0: 20 6d 6f 64 65 29 3b 0a 09 69 66 20 28 74 63 6c mode);..if (tcl
5fc0: 5f 72 65 74 20 21 3d 20 54 43 4c 5f 4f 4b 29 20 _ret != TCL_OK)
5fd0: 7b 0a 09 09 41 50 50 46 53 5f 44 45 42 55 47 28 {...APPFS_DEBUG(
5fe0: 22 3a 3a 61 70 70 66 73 3a 3a 6f 70 65 6e 70 61 "::appfs::openpa
5ff0: 74 68 28 25 73 2c 20 25 73 29 20 66 61 69 6c 65 th(%s, %s) faile
6000: 64 2e 22 2c 20 70 61 74 68 2c 20 6d 6f 64 65 29 d.", path, mode)
6010: 3b 0a 09 09 41 50 50 46 53 5f 44 45 42 55 47 28 ;...APPFS_DEBUG(
6020: 22 54 63 6c 20 45 72 72 6f 72 20 69 73 3a 20 25 "Tcl Error is: %
6030: 73 22 2c 20 54 63 6c 5f 47 65 74 53 74 72 69 6e s", Tcl_GetStrin
6040: 67 52 65 73 75 6c 74 28 69 6e 74 65 72 70 29 29 gResult(interp))
6050: 3b 0a 0a 09 09 72 65 74 75 72 6e 28 2d 45 49 4f ;....return(-EIO
6060: 29 3b 0a 09 7d 0a 0a 09 72 65 61 6c 5f 70 61 74 );..}...real_pat
6070: 68 20 3d 20 54 63 6c 5f 47 65 74 53 74 72 69 6e h = Tcl_GetStrin
6080: 67 52 65 73 75 6c 74 28 69 6e 74 65 72 70 29 3b gResult(interp);
6090: 0a 09 69 66 20 28 72 65 61 6c 5f 70 61 74 68 20 ..if (real_path
60a0: 3d 3d 20 4e 55 4c 4c 29 20 7b 0a 09 09 72 65 74 == NULL) {...ret
60b0: 75 72 6e 28 2d 45 49 4f 29 3b 0a 09 7d 0a 0a 09 urn(-EIO);..}...
60c0: 41 50 50 46 53 5f 44 45 42 55 47 28 22 54 72 61 APPFS_DEBUG("Tra
60d0: 6e 73 6c 61 74 65 64 20 72 65 71 75 65 73 74 20 nslated request
60e0: 74 6f 20 6f 70 65 6e 20 25 73 20 74 6f 20 6f 70 to open %s to op
60f0: 65 6e 69 6e 67 20 25 73 20 28 6d 6f 64 65 20 3d ening %s (mode =
6100: 20 5c 22 25 73 5c 22 29 22 2c 20 70 61 74 68 2c \"%s\")", path,
6110: 20 72 65 61 6c 5f 70 61 74 68 2c 20 6d 6f 64 65 real_path, mode
6120: 29 3b 0a 0a 09 66 68 20 3d 20 6f 70 65 6e 28 72 );...fh = open(r
6130: 65 61 6c 5f 70 61 74 68 2c 20 66 69 2d 3e 66 6c eal_path, fi->fl
6140: 61 67 73 2c 20 30 36 30 30 29 3b 0a 0a 09 69 66 ags, 0600);...if
6150: 20 28 66 68 20 3c 20 30 29 20 7b 0a 09 09 72 65 (fh < 0) {...re
6160: 74 75 72 6e 28 2d 45 49 4f 29 3b 0a 09 7d 0a 0a turn(-EIO);..}..
6170: 09 66 69 2d 3e 66 68 20 3d 20 66 68 3b 0a 0a 09 .fi->fh = fh;...
6180: 72 65 74 75 72 6e 28 30 29 3b 0a 7d 0a 0a 73 74 return(0);.}..st
6190: 61 74 69 63 20 69 6e 74 20 61 70 70 66 73 5f 66 atic int appfs_f
61a0: 75 73 65 5f 63 6c 6f 73 65 28 63 6f 6e 73 74 20 use_close(const
61b0: 63 68 61 72 20 2a 70 61 74 68 2c 20 73 74 72 75 char *path, stru
61c0: 63 74 20 66 75 73 65 5f 66 69 6c 65 5f 69 6e 66 ct fuse_file_inf
61d0: 6f 20 2a 66 69 29 20 7b 0a 09 69 6e 74 20 63 6c o *fi) {..int cl
61e0: 6f 73 65 5f 72 65 74 3b 0a 0a 09 61 70 70 66 73 ose_ret;...appfs
61f0: 5f 67 65 74 5f 70 61 74 68 5f 69 6e 66 6f 5f 63 _get_path_info_c
6200: 61 63 68 65 5f 72 6d 28 70 61 74 68 2c 20 61 70 ache_rm(path, ap
6210: 70 66 73 5f 67 65 74 5f 66 73 75 69 64 28 29 29 pfs_get_fsuid())
6220: 3b 0a 0a 09 63 6c 6f 73 65 5f 72 65 74 20 3d 20 ;...close_ret =
6230: 63 6c 6f 73 65 28 66 69 2d 3e 66 68 29 3b 0a 09 close(fi->fh);..
6240: 69 66 20 28 63 6c 6f 73 65 5f 72 65 74 20 21 3d if (close_ret !=
6250: 20 30 29 20 7b 0a 09 09 72 65 74 75 72 6e 28 2d 0) {...return(-
6260: 45 49 4f 29 3b 0a 09 7d 0a 0a 09 72 65 74 75 72 EIO);..}...retur
6270: 6e 28 30 29 3b 0a 7d 0a 0a 73 74 61 74 69 63 20 n(0);.}..static
6280: 69 6e 74 20 61 70 70 66 73 5f 66 75 73 65 5f 72 int appfs_fuse_r
6290: 65 61 64 28 63 6f 6e 73 74 20 63 68 61 72 20 2a ead(const char *
62a0: 70 61 74 68 2c 20 63 68 61 72 20 2a 62 75 66 2c path, char *buf,
62b0: 20 73 69 7a 65 5f 74 20 73 69 7a 65 2c 20 6f 66 size_t size, of
62c0: 66 5f 74 20 6f 66 66 73 65 74 2c 20 73 74 72 75 f_t offset, stru
62d0: 63 74 20 66 75 73 65 5f 66 69 6c 65 5f 69 6e 66 ct fuse_file_inf
62e0: 6f 20 2a 66 69 29 20 7b 0a 09 6f 66 66 5f 74 20 o *fi) {..off_t
62f0: 6c 73 65 65 6b 5f 72 65 74 3b 0a 09 73 73 69 7a lseek_ret;..ssiz
6300: 65 5f 74 20 72 65 61 64 5f 72 65 74 3b 0a 0a 09 e_t read_ret;...
6310: 41 50 50 46 53 5f 44 45 42 55 47 28 22 45 6e 74 APPFS_DEBUG("Ent
6320: 65 72 20 28 70 61 74 68 20 3d 20 25 73 2c 20 2e er (path = %s, .
6330: 2e 2e 29 22 2c 20 70 61 74 68 29 3b 0a 0a 09 6c ..)", path);...l
6340: 73 65 65 6b 5f 72 65 74 20 3d 20 6c 73 65 65 6b seek_ret = lseek
6350: 28 66 69 2d 3e 66 68 2c 20 6f 66 66 73 65 74 2c (fi->fh, offset,
6360: 20 53 45 45 4b 5f 53 45 54 29 3b 0a 09 69 66 20 SEEK_SET);..if
6370: 28 6c 73 65 65 6b 5f 72 65 74 20 21 3d 20 6f 66 (lseek_ret != of
6380: 66 73 65 74 29 20 7b 0a 09 09 72 65 74 75 72 6e fset) {...return
6390: 28 2d 45 49 4f 29 3b 0a 09 7d 0a 0a 09 72 65 61 (-EIO);..}...rea
63a0: 64 5f 72 65 74 20 3d 20 72 65 61 64 28 66 69 2d d_ret = read(fi-
63b0: 3e 66 68 2c 20 62 75 66 2c 20 73 69 7a 65 29 3b >fh, buf, size);
63c0: 0a 0a 09 72 65 74 75 72 6e 28 72 65 61 64 5f 72 ...return(read_r
63d0: 65 74 29 3b 0a 7d 0a 0a 73 74 61 74 69 63 20 69 et);.}..static i
63e0: 6e 74 20 61 70 70 66 73 5f 66 75 73 65 5f 77 72 nt appfs_fuse_wr
63f0: 69 74 65 28 63 6f 6e 73 74 20 63 68 61 72 20 2a ite(const char *
6400: 70 61 74 68 2c 20 63 6f 6e 73 74 20 63 68 61 72 path, const char
6410: 20 2a 62 75 66 2c 20 73 69 7a 65 5f 74 20 73 69 *buf, size_t si
6420: 7a 65 2c 20 6f 66 66 5f 74 20 6f 66 66 73 65 74 ze, off_t offset
6430: 2c 20 73 74 72 75 63 74 20 66 75 73 65 5f 66 69 , struct fuse_fi
6440: 6c 65 5f 69 6e 66 6f 20 2a 66 69 29 20 7b 0a 09 le_info *fi) {..
6450: 6f 66 66 5f 74 20 6c 73 65 65 6b 5f 72 65 74 3b off_t lseek_ret;
6460: 0a 09 73 73 69 7a 65 5f 74 20 77 72 69 74 65 5f ..ssize_t write_
6470: 72 65 74 3b 0a 0a 09 41 50 50 46 53 5f 44 45 42 ret;...APPFS_DEB
6480: 55 47 28 22 45 6e 74 65 72 20 28 70 61 74 68 20 UG("Enter (path
6490: 3d 20 25 73 2c 20 2e 2e 2e 29 22 2c 20 70 61 74 = %s, ...)", pat
64a0: 68 29 3b 0a 0a 09 61 70 70 66 73 5f 67 65 74 5f h);...appfs_get_
64b0: 70 61 74 68 5f 69 6e 66 6f 5f 63 61 63 68 65 5f path_info_cache_
64c0: 72 6d 28 70 61 74 68 2c 20 61 70 70 66 73 5f 67 rm(path, appfs_g
64d0: 65 74 5f 66 73 75 69 64 28 29 29 3b 0a 0a 09 6c et_fsuid());...l
64e0: 73 65 65 6b 5f 72 65 74 20 3d 20 6c 73 65 65 6b seek_ret = lseek
64f0: 28 66 69 2d 3e 66 68 2c 20 6f 66 66 73 65 74 2c (fi->fh, offset,
6500: 20 53 45 45 4b 5f 53 45 54 29 3b 0a 09 69 66 20 SEEK_SET);..if
6510: 28 6c 73 65 65 6b 5f 72 65 74 20 21 3d 20 6f 66 (lseek_ret != of
6520: 66 73 65 74 29 20 7b 0a 09 09 72 65 74 75 72 6e fset) {...return
6530: 28 2d 45 49 4f 29 3b 0a 09 7d 0a 0a 09 77 72 69 (-EIO);..}...wri
6540: 74 65 5f 72 65 74 20 3d 20 77 72 69 74 65 28 66 te_ret = write(f
6550: 69 2d 3e 66 68 2c 20 62 75 66 2c 20 73 69 7a 65 i->fh, buf, size
6560: 29 3b 0a 0a 09 72 65 74 75 72 6e 28 77 72 69 74 );...return(writ
6570: 65 5f 72 65 74 29 3b 0a 7d 0a 0a 73 74 61 74 69 e_ret);.}..stati
6580: 63 20 69 6e 74 20 61 70 70 66 73 5f 66 75 73 65 c int appfs_fuse
6590: 5f 6d 6b 6e 6f 64 28 63 6f 6e 73 74 20 63 68 61 _mknod(const cha
65a0: 72 20 2a 70 61 74 68 2c 20 6d 6f 64 65 5f 74 20 r *path, mode_t
65b0: 6d 6f 64 65 2c 20 64 65 76 5f 74 20 64 65 76 69 mode, dev_t devi
65c0: 63 65 29 20 7b 0a 09 63 68 61 72 20 2a 72 65 61 ce) {..char *rea
65d0: 6c 5f 70 61 74 68 3b 0a 09 69 6e 74 20 6d 6b 6e l_path;..int mkn
65e0: 6f 64 5f 72 65 74 3b 0a 0a 09 41 50 50 46 53 5f od_ret;...APPFS_
65f0: 44 45 42 55 47 28 22 45 6e 74 65 72 20 28 70 61 DEBUG("Enter (pa
6600: 74 68 20 3d 20 25 73 2c 20 2e 2e 2e 29 22 2c 20 th = %s, ...)",
6610: 70 61 74 68 29 3b 0a 0a 09 69 66 20 28 28 6d 6f path);...if ((mo
6620: 64 65 20 26 20 53 5f 49 46 43 48 52 29 20 3d 3d de & S_IFCHR) ==
6630: 20 53 5f 49 46 43 48 52 29 20 7b 0a 09 09 72 65 S_IFCHR) {...re
6640: 74 75 72 6e 28 2d 45 50 45 52 4d 29 3b 0a 09 7d turn(-EPERM);..}
6650: 0a 0a 09 69 66 20 28 28 6d 6f 64 65 20 26 20 53 ...if ((mode & S
6660: 5f 49 46 42 4c 4b 29 20 3d 3d 20 53 5f 49 46 42 _IFBLK) == S_IFB
6670: 4c 4b 29 20 7b 0a 09 09 72 65 74 75 72 6e 28 2d LK) {...return(-
6680: 45 50 45 52 4d 29 3b 0a 09 7d 0a 0a 09 72 65 61 EPERM);..}...rea
6690: 6c 5f 70 61 74 68 20 3d 20 61 70 70 66 73 5f 70 l_path = appfs_p
66a0: 72 65 70 61 72 65 5f 74 6f 5f 63 72 65 61 74 65 repare_to_create
66b0: 28 70 61 74 68 29 3b 0a 09 69 66 20 28 72 65 61 (path);..if (rea
66c0: 6c 5f 70 61 74 68 20 3d 3d 20 4e 55 4c 4c 29 20 l_path == NULL)
66d0: 7b 0a 09 09 72 65 74 75 72 6e 28 2d 45 49 4f 29 {...return(-EIO)
66e0: 3b 0a 09 7d 0a 0a 09 61 70 70 66 73 5f 73 69 6d ;..}...appfs_sim
66f0: 75 6c 61 74 65 5f 75 73 65 72 5f 66 73 5f 65 6e ulate_user_fs_en
6700: 74 65 72 28 29 3b 0a 0a 09 6d 6b 6e 6f 64 5f 72 ter();...mknod_r
6710: 65 74 20 3d 20 6d 6b 6e 6f 64 28 72 65 61 6c 5f et = mknod(real_
6720: 70 61 74 68 2c 20 6d 6f 64 65 2c 20 64 65 76 69 path, mode, devi
6730: 63 65 29 3b 0a 0a 09 61 70 70 66 73 5f 73 69 6d ce);...appfs_sim
6740: 75 6c 61 74 65 5f 75 73 65 72 5f 66 73 5f 6c 65 ulate_user_fs_le
6750: 61 76 65 28 29 3b 0a 0a 09 66 72 65 65 28 72 65 ave();...free(re
6760: 61 6c 5f 70 61 74 68 29 3b 0a 0a 09 69 66 20 28 al_path);...if (
6770: 6d 6b 6e 6f 64 5f 72 65 74 20 21 3d 20 30 29 20 mknod_ret != 0)
6780: 7b 0a 09 09 72 65 74 75 72 6e 28 65 72 72 6e 6f {...return(errno
6790: 20 2a 20 2d 31 29 3b 0a 09 7d 0a 0a 09 72 65 74 * -1);..}...ret
67a0: 75 72 6e 28 30 29 3b 0a 7d 0a 0a 73 74 61 74 69 urn(0);.}..stati
67b0: 63 20 69 6e 74 20 61 70 70 66 73 5f 66 75 73 65 c int appfs_fuse
67c0: 5f 63 72 65 61 74 65 28 63 6f 6e 73 74 20 63 68 _create(const ch
67d0: 61 72 20 2a 70 61 74 68 2c 20 6d 6f 64 65 5f 74 ar *path, mode_t
67e0: 20 6d 6f 64 65 2c 20 73 74 72 75 63 74 20 66 75 mode, struct fu
67f0: 73 65 5f 66 69 6c 65 5f 69 6e 66 6f 20 2a 66 69 se_file_info *fi
6800: 29 20 7b 0a 09 63 68 61 72 20 2a 72 65 61 6c 5f ) {..char *real_
6810: 70 61 74 68 3b 0a 09 69 6e 74 20 66 64 3b 0a 0a path;..int fd;..
6820: 09 41 50 50 46 53 5f 44 45 42 55 47 28 22 45 6e .APPFS_DEBUG("En
6830: 74 65 72 20 28 70 61 74 68 20 3d 20 25 73 2c 20 ter (path = %s,
6840: 2e 2e 2e 29 22 2c 20 70 61 74 68 29 3b 0a 0a 09 ...)", path);...
6850: 69 66 20 28 28 6d 6f 64 65 20 26 20 53 5f 49 46 if ((mode & S_IF
6860: 43 48 52 29 20 3d 3d 20 53 5f 49 46 43 48 52 29 CHR) == S_IFCHR)
6870: 20 7b 0a 09 09 72 65 74 75 72 6e 28 2d 45 50 45 {...return(-EPE
6880: 52 4d 29 3b 0a 09 7d 0a 0a 09 69 66 20 28 28 6d RM);..}...if ((m
6890: 6f 64 65 20 26 20 53 5f 49 46 42 4c 4b 29 20 3d ode & S_IFBLK) =
68a0: 3d 20 53 5f 49 46 42 4c 4b 29 20 7b 0a 09 09 72 = S_IFBLK) {...r
68b0: 65 74 75 72 6e 28 2d 45 50 45 52 4d 29 3b 0a 09 eturn(-EPERM);..
68c0: 7d 0a 0a 09 72 65 61 6c 5f 70 61 74 68 20 3d 20 }...real_path =
68d0: 61 70 70 66 73 5f 70 72 65 70 61 72 65 5f 74 6f appfs_prepare_to
68e0: 5f 63 72 65 61 74 65 28 70 61 74 68 29 3b 0a 09 _create(path);..
68f0: 69 66 20 28 72 65 61 6c 5f 70 61 74 68 20 3d 3d if (real_path ==
6900: 20 4e 55 4c 4c 29 20 7b 0a 09 09 72 65 74 75 72 NULL) {...retur
6910: 6e 28 2d 45 49 4f 29 3b 0a 09 7d 0a 0a 09 61 70 n(-EIO);..}...ap
6920: 70 66 73 5f 73 69 6d 75 6c 61 74 65 5f 75 73 65 pfs_simulate_use
6930: 72 5f 66 73 5f 65 6e 74 65 72 28 29 3b 0a 0a 09 r_fs_enter();...
6940: 66 64 20 3d 20 63 72 65 61 74 28 72 65 61 6c 5f fd = creat(real_
6950: 70 61 74 68 2c 20 6d 6f 64 65 29 3b 0a 0a 09 61 path, mode);...a
6960: 70 70 66 73 5f 73 69 6d 75 6c 61 74 65 5f 75 73 ppfs_simulate_us
6970: 65 72 5f 66 73 5f 6c 65 61 76 65 28 29 3b 0a 0a er_fs_leave();..
6980: 09 66 72 65 65 28 72 65 61 6c 5f 70 61 74 68 29 .free(real_path)
6990: 3b 0a 0a 09 69 66 20 28 66 64 20 3c 20 30 29 20 ;...if (fd < 0)
69a0: 7b 0a 09 09 72 65 74 75 72 6e 28 65 72 72 6e 6f {...return(errno
69b0: 20 2a 20 2d 31 29 3b 0a 09 7d 0a 0a 09 66 69 2d * -1);..}...fi-
69c0: 3e 66 68 20 3d 20 66 64 3b 0a 0a 09 72 65 74 75 >fh = fd;...retu
69d0: 72 6e 28 30 29 3b 0a 7d 0a 0a 73 74 61 74 69 63 rn(0);.}..static
69e0: 20 69 6e 74 20 61 70 70 66 73 5f 66 75 73 65 5f int appfs_fuse_
69f0: 74 72 75 6e 63 61 74 65 28 63 6f 6e 73 74 20 63 truncate(const c
6a00: 68 61 72 20 2a 70 61 74 68 2c 20 6f 66 66 5f 74 har *path, off_t
6a10: 20 73 69 7a 65 29 20 7b 0a 09 63 68 61 72 20 2a size) {..char *
6a20: 72 65 61 6c 5f 70 61 74 68 3b 0a 09 69 6e 74 20 real_path;..int
6a30: 74 72 75 6e 63 61 74 65 5f 72 65 74 3b 0a 0a 09 truncate_ret;...
6a40: 41 50 50 46 53 5f 44 45 42 55 47 28 22 45 6e 74 APPFS_DEBUG("Ent
6a50: 65 72 20 28 70 61 74 68 20 3d 20 25 73 2c 20 2e er (path = %s, .
6a60: 2e 2e 29 22 2c 20 70 61 74 68 29 3b 0a 0a 09 72 ..)", path);...r
6a70: 65 61 6c 5f 70 61 74 68 20 3d 20 61 70 70 66 73 eal_path = appfs
6a80: 5f 6c 6f 63 61 6c 70 61 74 68 28 70 61 74 68 29 _localpath(path)
6a90: 3b 0a 09 69 66 20 28 72 65 61 6c 5f 70 61 74 68 ;..if (real_path
6aa0: 20 3d 3d 20 4e 55 4c 4c 29 20 7b 0a 09 09 72 65 == NULL) {...re
6ab0: 74 75 72 6e 28 2d 45 49 4f 29 3b 0a 09 7d 0a 0a turn(-EIO);..}..
6ac0: 09 61 70 70 66 73 5f 67 65 74 5f 70 61 74 68 5f .appfs_get_path_
6ad0: 69 6e 66 6f 5f 63 61 63 68 65 5f 72 6d 28 70 61 info_cache_rm(pa
6ae0: 74 68 2c 20 61 70 70 66 73 5f 67 65 74 5f 66 73 th, appfs_get_fs
6af0: 75 69 64 28 29 29 3b 0a 0a 09 61 70 70 66 73 5f uid());...appfs_
6b00: 73 69 6d 75 6c 61 74 65 5f 75 73 65 72 5f 66 73 simulate_user_fs
6b10: 5f 65 6e 74 65 72 28 29 3b 0a 0a 09 74 72 75 6e _enter();...trun
6b20: 63 61 74 65 5f 72 65 74 20 3d 20 74 72 75 6e 63 cate_ret = trunc
6b30: 61 74 65 28 72 65 61 6c 5f 70 61 74 68 2c 20 73 ate(real_path, s
6b40: 69 7a 65 29 3b 0a 0a 09 61 70 70 66 73 5f 73 69 ize);...appfs_si
6b50: 6d 75 6c 61 74 65 5f 75 73 65 72 5f 66 73 5f 6c mulate_user_fs_l
6b60: 65 61 76 65 28 29 3b 0a 0a 09 66 72 65 65 28 72 eave();...free(r
6b70: 65 61 6c 5f 70 61 74 68 29 3b 0a 0a 09 69 66 20 eal_path);...if
6b80: 28 74 72 75 6e 63 61 74 65 5f 72 65 74 20 21 3d (truncate_ret !=
6b90: 20 30 29 20 7b 0a 09 09 72 65 74 75 72 6e 28 65 0) {...return(e
6ba0: 72 72 6e 6f 20 2a 20 2d 31 29 3b 0a 09 7d 0a 0a rrno * -1);..}..
6bb0: 09 72 65 74 75 72 6e 28 30 29 3b 0a 7d 0a 0a 73 .return(0);.}..s
6bc0: 74 61 74 69 63 20 69 6e 74 20 61 70 70 66 73 5f tatic int appfs_
6bd0: 66 75 73 65 5f 75 6e 6c 69 6e 6b 5f 72 6d 64 69 fuse_unlink_rmdi
6be0: 72 28 63 6f 6e 73 74 20 63 68 61 72 20 2a 70 61 r(const char *pa
6bf0: 74 68 29 20 7b 0a 09 54 63 6c 5f 49 6e 74 65 72 th) {..Tcl_Inter
6c00: 70 20 2a 69 6e 74 65 72 70 3b 0a 09 69 6e 74 20 p *interp;..int
6c10: 74 63 6c 5f 72 65 74 3b 0a 0a 09 41 50 50 46 53 tcl_ret;...APPFS
6c20: 5f 44 45 42 55 47 28 22 45 6e 74 65 72 20 28 70 _DEBUG("Enter (p
6c30: 61 74 68 20 3d 20 25 73 2c 20 2e 2e 2e 29 22 2c ath = %s, ...)",
6c40: 20 70 61 74 68 29 3b 0a 0a 09 61 70 70 66 73 5f path);...appfs_
6c50: 67 65 74 5f 70 61 74 68 5f 69 6e 66 6f 5f 63 61 get_path_info_ca
6c60: 63 68 65 5f 66 6c 75 73 68 28 61 70 70 66 73 5f che_flush(appfs_
6c70: 67 65 74 5f 66 73 75 69 64 28 29 2c 20 2d 31 29 get_fsuid(), -1)
6c80: 3b 0a 0a 09 69 6e 74 65 72 70 20 3d 20 61 70 70 ;...interp = app
6c90: 66 73 5f 54 63 6c 49 6e 74 65 72 70 28 29 3b 0a fs_TclInterp();.
6ca0: 09 69 66 20 28 69 6e 74 65 72 70 20 3d 3d 20 4e .if (interp == N
6cb0: 55 4c 4c 29 20 7b 0a 09 09 72 65 74 75 72 6e 28 ULL) {...return(
6cc0: 2d 45 49 4f 29 3b 0a 09 7d 0a 0a 09 74 63 6c 5f -EIO);..}...tcl_
6cd0: 72 65 74 20 3d 20 61 70 70 66 73 5f 54 63 6c 5f ret = appfs_Tcl_
6ce0: 45 76 61 6c 28 69 6e 74 65 72 70 2c 20 32 2c 20 Eval(interp, 2,
6cf0: 22 3a 3a 61 70 70 66 73 3a 3a 75 6e 6c 69 6e 6b "::appfs::unlink
6d00: 70 61 74 68 22 2c 20 70 61 74 68 29 3b 0a 09 69 path", path);..i
6d10: 66 20 28 74 63 6c 5f 72 65 74 20 21 3d 20 54 43 f (tcl_ret != TC
6d20: 4c 5f 4f 4b 29 20 7b 0a 09 09 41 50 50 46 53 5f L_OK) {...APPFS_
6d30: 44 45 42 55 47 28 22 3a 3a 61 70 70 66 73 3a 3a DEBUG("::appfs::
6d40: 75 6e 6c 69 6e 6b 70 61 74 68 28 25 73 29 20 66 unlinkpath(%s) f
6d50: 61 69 6c 65 64 2e 22 2c 20 70 61 74 68 29 3b 0a ailed.", path);.
6d60: 09 09 41 50 50 46 53 5f 44 45 42 55 47 28 22 54 ..APPFS_DEBUG("T
6d70: 63 6c 20 45 72 72 6f 72 20 69 73 3a 20 25 73 22 cl Error is: %s"
6d80: 2c 20 54 63 6c 5f 47 65 74 53 74 72 69 6e 67 52 , Tcl_GetStringR
6d90: 65 73 75 6c 74 28 69 6e 74 65 72 70 29 29 3b 0a esult(interp));.
6da0: 0a 09 09 72 65 74 75 72 6e 28 2d 45 49 4f 29 3b ...return(-EIO);
6db0: 0a 09 7d 0a 0a 09 72 65 74 75 72 6e 28 30 29 3b ..}...return(0);
6dc0: 0a 7d 0a 0a 73 74 61 74 69 63 20 69 6e 74 20 61 .}..static int a
6dd0: 70 70 66 73 5f 66 75 73 65 5f 6d 6b 64 69 72 28 ppfs_fuse_mkdir(
6de0: 63 6f 6e 73 74 20 63 68 61 72 20 2a 70 61 74 68 const char *path
6df0: 2c 20 6d 6f 64 65 5f 74 20 6d 6f 64 65 29 20 7b , mode_t mode) {
6e00: 0a 09 63 68 61 72 20 2a 72 65 61 6c 5f 70 61 74 ..char *real_pat
6e10: 68 3b 0a 09 69 6e 74 20 6d 6b 64 69 72 5f 72 65 h;..int mkdir_re
6e20: 74 3b 0a 0a 09 41 50 50 46 53 5f 44 45 42 55 47 t;...APPFS_DEBUG
6e30: 28 22 45 6e 74 65 72 20 28 70 61 74 68 20 3d 20 ("Enter (path =
6e40: 25 73 2c 20 2e 2e 2e 29 22 2c 20 70 61 74 68 29 %s, ...)", path)
6e50: 3b 0a 0a 09 72 65 61 6c 5f 70 61 74 68 20 3d 20 ;...real_path =
6e60: 61 70 70 66 73 5f 70 72 65 70 61 72 65 5f 74 6f appfs_prepare_to
6e70: 5f 63 72 65 61 74 65 28 70 61 74 68 29 3b 0a 09 _create(path);..
6e80: 69 66 20 28 72 65 61 6c 5f 70 61 74 68 20 3d 3d if (real_path ==
6e90: 20 4e 55 4c 4c 29 20 7b 0a 09 09 72 65 74 75 72 NULL) {...retur
6ea0: 6e 28 2d 45 49 4f 29 3b 0a 09 7d 0a 0a 09 61 70 n(-EIO);..}...ap
6eb0: 70 66 73 5f 73 69 6d 75 6c 61 74 65 5f 75 73 65 pfs_simulate_use
6ec0: 72 5f 66 73 5f 65 6e 74 65 72 28 29 3b 0a 0a 09 r_fs_enter();...
6ed0: 6d 6b 64 69 72 5f 72 65 74 20 3d 20 6d 6b 64 69 mkdir_ret = mkdi
6ee0: 72 28 72 65 61 6c 5f 70 61 74 68 2c 20 6d 6f 64 r(real_path, mod
6ef0: 65 29 3b 0a 0a 09 61 70 70 66 73 5f 73 69 6d 75 e);...appfs_simu
6f00: 6c 61 74 65 5f 75 73 65 72 5f 66 73 5f 6c 65 61 late_user_fs_lea
6f10: 76 65 28 29 3b 0a 0a 09 66 72 65 65 28 72 65 61 ve();...free(rea
6f20: 6c 5f 70 61 74 68 29 3b 0a 0a 09 69 66 20 28 6d l_path);...if (m
6f30: 6b 64 69 72 5f 72 65 74 20 21 3d 20 30 29 20 7b kdir_ret != 0) {
6f40: 0a 09 09 69 66 20 28 65 72 72 6e 6f 20 21 3d 20 ...if (errno !=
6f50: 45 45 58 49 53 54 29 20 7b 0a 09 09 09 72 65 74 EEXIST) {....ret
6f60: 75 72 6e 28 65 72 72 6e 6f 20 2a 20 2d 31 29 3b urn(errno * -1);
6f70: 0a 09 09 7d 0a 09 7d 0a 0a 09 72 65 74 75 72 6e ...}..}...return
6f80: 28 30 29 3b 0a 7d 0a 0a 73 74 61 74 69 63 20 69 (0);.}..static i
6f90: 6e 74 20 61 70 70 66 73 5f 66 75 73 65 5f 63 68 nt appfs_fuse_ch
6fa0: 6d 6f 64 28 63 6f 6e 73 74 20 63 68 61 72 20 2a mod(const char *
6fb0: 70 61 74 68 2c 20 6d 6f 64 65 5f 74 20 6d 6f 64 path, mode_t mod
6fc0: 65 29 20 7b 0a 09 54 63 6c 5f 49 6e 74 65 72 70 e) {..Tcl_Interp
6fd0: 20 2a 69 6e 74 65 72 70 3b 0a 09 63 6f 6e 73 74 *interp;..const
6fe0: 20 63 68 61 72 20 2a 72 65 61 6c 5f 70 61 74 68 char *real_path
6ff0: 3b 0a 09 69 6e 74 20 74 63 6c 5f 72 65 74 2c 20 ;..int tcl_ret,
7000: 63 68 6d 6f 64 5f 72 65 74 3b 0a 0a 09 41 50 50 chmod_ret;...APP
7010: 46 53 5f 44 45 42 55 47 28 22 45 6e 74 65 72 20 FS_DEBUG("Enter
7020: 28 70 61 74 68 20 3d 20 25 73 2c 20 2e 2e 2e 29 (path = %s, ...)
7030: 22 2c 20 70 61 74 68 29 3b 0a 0a 09 61 70 70 66 ", path);...appf
7040: 73 5f 67 65 74 5f 70 61 74 68 5f 69 6e 66 6f 5f s_get_path_info_
7050: 63 61 63 68 65 5f 72 6d 28 70 61 74 68 2c 20 61 cache_rm(path, a
7060: 70 70 66 73 5f 67 65 74 5f 66 73 75 69 64 28 29 ppfs_get_fsuid()
7070: 29 3b 0a 0a 09 69 6e 74 65 72 70 20 3d 20 61 70 );...interp = ap
7080: 70 66 73 5f 54 63 6c 49 6e 74 65 72 70 28 29 3b pfs_TclInterp();
7090: 0a 09 69 66 20 28 69 6e 74 65 72 70 20 3d 3d 20 ..if (interp ==
70a0: 4e 55 4c 4c 29 20 7b 0a 09 09 72 65 74 75 72 6e NULL) {...return
70b0: 28 2d 45 49 4f 29 3b 0a 09 7d 0a 0a 09 74 63 6c (-EIO);..}...tcl
70c0: 5f 72 65 74 20 3d 20 61 70 70 66 73 5f 54 63 6c _ret = appfs_Tcl
70d0: 5f 45 76 61 6c 28 69 6e 74 65 72 70 2c 20 33 2c _Eval(interp, 3,
70e0: 20 22 3a 3a 61 70 70 66 73 3a 3a 6f 70 65 6e 70 "::appfs::openp
70f0: 61 74 68 22 2c 20 70 61 74 68 2c 20 22 77 72 69 ath", path, "wri
7100: 74 65 22 29 3b 0a 09 69 66 20 28 74 63 6c 5f 72 te");..if (tcl_r
7110: 65 74 20 21 3d 20 54 43 4c 5f 4f 4b 29 20 7b 0a et != TCL_OK) {.
7120: 09 09 41 50 50 46 53 5f 44 45 42 55 47 28 22 3a ..APPFS_DEBUG(":
7130: 3a 61 70 70 66 73 3a 3a 6f 70 65 6e 70 61 74 68 :appfs::openpath
7140: 28 25 73 2c 20 25 73 29 20 66 61 69 6c 65 64 2e (%s, %s) failed.
7150: 22 2c 20 70 61 74 68 2c 20 22 77 72 69 74 65 22 ", path, "write"
7160: 29 3b 0a 09 09 41 50 50 46 53 5f 44 45 42 55 47 );...APPFS_DEBUG
7170: 28 22 54 63 6c 20 45 72 72 6f 72 20 69 73 3a 20 ("Tcl Error is:
7180: 25 73 22 2c 20 54 63 6c 5f 47 65 74 53 74 72 69 %s", Tcl_GetStri
7190: 6e 67 52 65 73 75 6c 74 28 69 6e 74 65 72 70 29 ngResult(interp)
71a0: 29 3b 0a 0a 09 09 72 65 74 75 72 6e 28 2d 45 49 );....return(-EI
71b0: 4f 29 3b 0a 09 7d 0a 0a 09 72 65 61 6c 5f 70 61 O);..}...real_pa
71c0: 74 68 20 3d 20 54 63 6c 5f 47 65 74 53 74 72 69 th = Tcl_GetStri
71d0: 6e 67 52 65 73 75 6c 74 28 69 6e 74 65 72 70 29 ngResult(interp)
71e0: 3b 0a 09 69 66 20 28 72 65 61 6c 5f 70 61 74 68 ;..if (real_path
71f0: 20 3d 3d 20 4e 55 4c 4c 29 20 7b 0a 09 09 72 65 == NULL) {...re
7200: 74 75 72 6e 28 2d 45 49 4f 29 3b 0a 09 7d 0a 0a turn(-EIO);..}..
7210: 09 61 70 70 66 73 5f 73 69 6d 75 6c 61 74 65 5f .appfs_simulate_
7220: 75 73 65 72 5f 66 73 5f 65 6e 74 65 72 28 29 3b user_fs_enter();
7230: 0a 0a 09 63 68 6d 6f 64 5f 72 65 74 20 3d 20 63 ...chmod_ret = c
7240: 68 6d 6f 64 28 72 65 61 6c 5f 70 61 74 68 2c 20 hmod(real_path,
7250: 6d 6f 64 65 29 3b 0a 0a 09 61 70 70 66 73 5f 73 mode);...appfs_s
7260: 69 6d 75 6c 61 74 65 5f 75 73 65 72 5f 66 73 5f imulate_user_fs_
7270: 6c 65 61 76 65 28 29 3b 0a 0a 09 72 65 74 75 72 leave();...retur
7280: 6e 28 63 68 6d 6f 64 5f 72 65 74 29 3b 0a 7d 0a n(chmod_ret);.}.
7290: 0a 2f 2a 0a 20 2a 20 53 51 4c 69 74 65 33 20 6d ./*. * SQLite3 m
72a0: 6f 64 65 3a 20 45 78 65 63 75 74 65 20 72 61 77 ode: Execute raw
72b0: 20 53 51 4c 20 61 6e 64 20 72 65 74 75 72 6e 20 SQL and return
72c0: 73 75 63 63 65 73 73 20 6f 72 20 66 61 69 6c 75 success or failu
72d0: 72 65 0a 20 2a 2f 0a 73 74 61 74 69 63 20 69 6e re. */.static in
72e0: 74 20 61 70 70 66 73 5f 73 71 6c 69 74 65 33 28 t appfs_sqlite3(
72f0: 63 6f 6e 73 74 20 63 68 61 72 20 2a 73 71 6c 29 const char *sql)
7300: 20 7b 0a 09 54 63 6c 5f 49 6e 74 65 72 70 20 2a {..Tcl_Interp *
7310: 69 6e 74 65 72 70 3b 0a 09 63 6f 6e 73 74 20 63 interp;..const c
7320: 68 61 72 20 2a 73 71 6c 5f 72 65 74 3b 0a 09 69 har *sql_ret;..i
7330: 6e 74 20 74 63 6c 5f 72 65 74 3b 0a 0a 09 69 6e nt tcl_ret;...in
7340: 74 65 72 70 20 3d 20 61 70 70 66 73 5f 63 72 65 terp = appfs_cre
7350: 61 74 65 5f 54 63 6c 49 6e 74 65 72 70 28 4e 55 ate_TclInterp(NU
7360: 4c 4c 29 3b 0a 09 69 66 20 28 69 6e 74 65 72 70 LL);..if (interp
7370: 20 3d 3d 20 4e 55 4c 4c 29 20 7b 0a 09 09 66 70 == NULL) {...fp
7380: 72 69 6e 74 66 28 73 74 64 65 72 72 2c 20 22 55 rintf(stderr, "U
7390: 6e 61 62 6c 65 20 74 6f 20 63 72 65 61 74 65 20 nable to create
73a0: 61 20 54 63 6c 20 69 6e 74 65 72 70 72 65 74 65 a Tcl interprete
73b0: 72 2e 20 20 41 62 6f 72 74 69 6e 67 2e 5c 6e 22 r. Aborting.\n"
73c0: 29 3b 0a 0a 09 09 72 65 74 75 72 6e 28 31 29 3b );....return(1);
73d0: 0a 09 7d 0a 0a 09 74 63 6c 5f 72 65 74 20 3d 20 ..}...tcl_ret =
73e0: 61 70 70 66 73 5f 54 63 6c 5f 45 76 61 6c 28 69 appfs_Tcl_Eval(i
73f0: 6e 74 65 72 70 2c 20 35 2c 20 22 3a 3a 61 70 70 nterp, 5, "::app
7400: 66 73 3a 3a 64 62 22 2c 20 22 65 76 61 6c 22 2c fs::db", "eval",
7410: 20 73 71 6c 2c 20 22 72 6f 77 22 2c 20 22 75 6e sql, "row", "un
7420: 73 65 74 20 2d 6e 6f 63 6f 6d 70 6c 61 69 6e 20 set -nocomplain
7430: 72 6f 77 28 2a 29 3b 20 70 61 72 72 61 79 20 72 row(*); parray r
7440: 6f 77 3b 20 70 75 74 73 20 5c 22 2d 2d 2d 2d 5c ow; puts \"----\
7450: 22 22 29 3b 0a 09 73 71 6c 5f 72 65 74 20 3d 20 "");..sql_ret =
7460: 54 63 6c 5f 47 65 74 53 74 72 69 6e 67 52 65 73 Tcl_GetStringRes
7470: 75 6c 74 28 69 6e 74 65 72 70 29 3b 0a 0a 09 69 ult(interp);...i
7480: 66 20 28 74 63 6c 5f 72 65 74 20 21 3d 20 54 43 f (tcl_ret != TC
7490: 4c 5f 4f 4b 29 20 7b 0a 09 09 66 70 72 69 6e 74 L_OK) {...fprint
74a0: 66 28 73 74 64 65 72 72 2c 20 22 5b 65 72 72 6f f(stderr, "[erro
74b0: 72 5d 20 25 73 5c 6e 22 2c 20 73 71 6c 5f 72 65 r] %s\n", sql_re
74c0: 74 29 3b 0a 0a 09 09 72 65 74 75 72 6e 28 31 29 t);....return(1)
74d0: 3b 0a 09 7d 0a 0a 09 69 66 20 28 73 71 6c 5f 72 ;..}...if (sql_r
74e0: 65 74 20 26 26 20 73 71 6c 5f 72 65 74 5b 30 5d et && sql_ret[0]
74f0: 20 21 3d 20 27 5c 30 27 29 20 7b 0a 09 09 70 72 != '\0') {...pr
7500: 69 6e 74 66 28 22 25 73 5c 6e 22 2c 20 73 71 6c intf("%s\n", sql
7510: 5f 72 65 74 29 3b 0a 09 7d 0a 0a 09 72 65 74 75 _ret);..}...retu
7520: 72 6e 28 30 29 3b 0a 7d 0a 0a 2f 2a 0a 20 2a 20 rn(0);.}../*. *
7530: 54 63 6c 20 6d 6f 64 65 3a 20 45 78 65 63 75 74 Tcl mode: Execut
7540: 65 20 72 61 77 20 54 63 6c 20 61 6e 64 20 72 65 e raw Tcl and re
7550: 74 75 72 6e 20 73 75 63 63 65 73 73 20 6f 72 20 turn success or
7560: 66 61 69 6c 75 72 65 0a 20 2a 2f 0a 73 74 61 74 failure. */.stat
7570: 69 63 20 69 6e 74 20 61 70 70 66 73 5f 74 63 6c ic int appfs_tcl
7580: 28 63 6f 6e 73 74 20 63 68 61 72 20 2a 74 63 6c (const char *tcl
7590: 29 20 7b 0a 09 54 63 6c 5f 49 6e 74 65 72 70 20 ) {..Tcl_Interp
75a0: 2a 69 6e 74 65 72 70 3b 0a 09 63 6f 6e 73 74 20 *interp;..const
75b0: 63 68 61 72 20 2a 74 63 6c 5f 72 65 73 75 6c 74 char *tcl_result
75c0: 3b 0a 09 69 6e 74 20 74 63 6c 5f 72 65 74 3b 0a ;..int tcl_ret;.
75d0: 0a 09 69 6e 74 65 72 70 20 3d 20 61 70 70 66 73 ..interp = appfs
75e0: 5f 63 72 65 61 74 65 5f 54 63 6c 49 6e 74 65 72 _create_TclInter
75f0: 70 28 4e 55 4c 4c 29 3b 0a 09 69 66 20 28 69 6e p(NULL);..if (in
7600: 74 65 72 70 20 3d 3d 20 4e 55 4c 4c 29 20 7b 0a terp == NULL) {.
7610: 09 09 66 70 72 69 6e 74 66 28 73 74 64 65 72 72 ..fprintf(stderr
7620: 2c 20 22 55 6e 61 62 6c 65 20 74 6f 20 63 72 65 , "Unable to cre
7630: 61 74 65 20 61 20 54 63 6c 20 69 6e 74 65 72 70 ate a Tcl interp
7640: 72 65 74 65 72 2e 20 20 41 62 6f 72 74 69 6e 67 reter. Aborting
7650: 2e 5c 6e 22 29 3b 0a 0a 09 09 72 65 74 75 72 6e .\n");....return
7660: 28 31 29 3b 0a 09 7d 0a 0a 09 74 63 6c 5f 72 65 (1);..}...tcl_re
7670: 74 20 3d 20 54 63 6c 5f 45 76 61 6c 28 69 6e 74 t = Tcl_Eval(int
7680: 65 72 70 2c 20 74 63 6c 29 3b 0a 09 74 63 6c 5f erp, tcl);..tcl_
7690: 72 65 73 75 6c 74 20 3d 20 54 63 6c 5f 47 65 74 result = Tcl_Get
76a0: 53 74 72 69 6e 67 52 65 73 75 6c 74 28 69 6e 74 StringResult(int
76b0: 65 72 70 29 3b 0a 0a 09 69 66 20 28 74 63 6c 5f erp);...if (tcl_
76c0: 72 65 74 20 21 3d 20 54 43 4c 5f 4f 4b 29 20 7b ret != TCL_OK) {
76d0: 0a 09 09 66 70 72 69 6e 74 66 28 73 74 64 65 72 ...fprintf(stder
76e0: 72 2c 20 22 5b 65 72 72 6f 72 5d 20 25 73 5c 6e r, "[error] %s\n
76f0: 22 2c 20 74 63 6c 5f 72 65 73 75 6c 74 29 3b 0a ", tcl_result);.
7700: 0a 09 09 72 65 74 75 72 6e 28 31 29 3b 0a 09 7d ...return(1);..}
7710: 0a 0a 09 69 66 20 28 74 63 6c 5f 72 65 73 75 6c ...if (tcl_resul
7720: 74 20 26 26 20 74 63 6c 5f 72 65 73 75 6c 74 5b t && tcl_result[
7730: 30 5d 20 21 3d 20 27 5c 30 27 29 20 7b 0a 09 09 0] != '\0') {...
7740: 70 72 69 6e 74 66 28 22 25 73 5c 6e 22 2c 20 74 printf("%s\n", t
7750: 63 6c 5f 72 65 73 75 6c 74 29 3b 0a 09 7d 0a 0a cl_result);..}..
7760: 09 72 65 74 75 72 6e 28 30 29 3b 0a 7d 0a 0a 2f .return(0);.}../
7770: 2a 0a 20 2a 20 41 70 70 46 53 64 20 50 61 63 6b *. * AppFSd Pack
7780: 61 67 65 20 66 6f 72 20 54 63 6c 3a 0a 20 2a 20 age for Tcl:. *
7790: 20 20 20 20 20 20 20 20 42 72 69 64 67 65 20 66 Bridge f
77a0: 6f 72 20 49 2f 4f 20 6f 70 65 72 61 74 69 6f 6e or I/O operation
77b0: 73 20 74 6f 20 72 65 71 75 65 73 74 20 69 6e 66 s to request inf
77c0: 6f 72 6d 61 74 69 6f 6e 20 61 62 6f 75 74 20 74 ormation about t
77d0: 68 65 20 63 75 72 72 65 6e 74 0a 20 2a 20 20 20 he current. *
77e0: 20 20 20 20 20 20 74 72 61 6e 73 61 63 74 69 6f transactio
77f0: 6e 0a 20 2a 2f 0a 2f 2a 0a 20 2a 20 54 63 6c 20 n. */./*. * Tcl
7800: 69 6e 74 65 72 66 61 63 65 20 74 6f 20 67 65 74 interface to get
7810: 20 74 68 65 20 68 6f 6d 65 20 64 69 72 65 63 74 the home direct
7820: 6f 72 79 20 66 6f 72 20 74 68 65 20 75 73 65 72 ory for the user
7830: 20 6d 61 6b 69 6e 67 20 74 68 65 20 22 63 75 72 making the "cur
7840: 72 65 6e 74 22 0a 20 2a 20 46 55 53 45 20 49 2f rent". * FUSE I/
7850: 4f 20 72 65 71 75 65 73 74 0a 20 2a 2f 0a 73 74 O request. */.st
7860: 61 74 69 63 20 69 6e 74 20 74 63 6c 5f 61 70 70 atic int tcl_app
7870: 66 73 5f 67 65 74 5f 68 6f 6d 65 64 69 72 28 43 fs_get_homedir(C
7880: 6c 69 65 6e 74 44 61 74 61 20 63 64 2c 20 54 63 lientData cd, Tc
7890: 6c 5f 49 6e 74 65 72 70 20 2a 69 6e 74 65 72 70 l_Interp *interp
78a0: 2c 20 69 6e 74 20 6f 62 6a 63 2c 20 54 63 6c 5f , int objc, Tcl_
78b0: 4f 62 6a 20 2a 43 4f 4e 53 54 20 6f 62 6a 76 5b Obj *CONST objv[
78c0: 5d 29 20 7b 0a 09 63 68 61 72 20 2a 68 6f 6d 65 ]) {..char *home
78d0: 64 69 72 3b 0a 09 54 63 6c 5f 4f 62 6a 20 2a 68 dir;..Tcl_Obj *h
78e0: 6f 6d 65 64 69 72 5f 6f 62 6a 3b 0a 09 75 69 64 omedir_obj;..uid
78f0: 5f 74 20 66 73 75 69 64 3b 0a 09 73 74 61 74 69 _t fsuid;..stati
7900: 63 20 5f 5f 74 68 72 65 61 64 20 54 63 6c 5f 4f c __thread Tcl_O
7910: 62 6a 20 2a 6c 61 73 74 5f 68 6f 6d 65 64 69 72 bj *last_homedir
7920: 5f 6f 62 6a 20 3d 20 4e 55 4c 4c 3b 0a 09 73 74 _obj = NULL;..st
7930: 61 74 69 63 20 5f 5f 74 68 72 65 61 64 20 75 69 atic __thread ui
7940: 64 5f 74 20 6c 61 73 74 5f 66 73 75 69 64 20 3d d_t last_fsuid =
7950: 20 2d 31 3b 0a 0a 20 20 20 20 20 20 20 20 69 66 -1;.. if
7960: 20 28 6f 62 6a 63 20 21 3d 20 31 29 20 7b 0a 20 (objc != 1) {.
7970: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 54 T
7980: 63 6c 5f 57 72 6f 6e 67 4e 75 6d 41 72 67 73 28 cl_WrongNumArgs(
7990: 69 6e 74 65 72 70 2c 20 31 2c 20 6f 62 6a 76 2c interp, 1, objv,
79a0: 20 4e 55 4c 4c 29 3b 0a 20 20 20 20 20 20 20 20 NULL);.
79b0: 20 20 20 20 20 20 20 20 72 65 74 75 72 6e 28 54 return(T
79c0: 43 4c 5f 45 52 52 4f 52 29 3b 0a 20 20 20 20 20 CL_ERROR);.
79d0: 20 20 20 7d 0a 0a 09 66 73 75 69 64 20 3d 20 61 }...fsuid = a
79e0: 70 70 66 73 5f 67 65 74 5f 66 73 75 69 64 28 29 ppfs_get_fsuid()
79f0: 3b 0a 0a 09 69 66 20 28 66 73 75 69 64 20 3d 3d ;...if (fsuid ==
7a00: 20 6c 61 73 74 5f 66 73 75 69 64 20 26 26 20 6c last_fsuid && l
7a10: 61 73 74 5f 68 6f 6d 65 64 69 72 5f 6f 62 6a 20 ast_homedir_obj
7a20: 21 3d 20 4e 55 4c 4c 29 20 7b 0a 09 09 68 6f 6d != NULL) {...hom
7a30: 65 64 69 72 5f 6f 62 6a 20 3d 20 6c 61 73 74 5f edir_obj = last_
7a40: 68 6f 6d 65 64 69 72 5f 6f 62 6a 3b 0a 09 7d 20 homedir_obj;..}
7a50: 65 6c 73 65 20 7b 0a 09 09 68 6f 6d 65 64 69 72 else {...homedir
7a60: 20 3d 20 61 70 70 66 73 5f 67 65 74 5f 68 6f 6d = appfs_get_hom
7a70: 65 64 69 72 28 61 70 70 66 73 5f 67 65 74 5f 66 edir(appfs_get_f
7a80: 73 75 69 64 28 29 29 3b 0a 0a 09 09 69 66 20 28 suid());....if (
7a90: 68 6f 6d 65 64 69 72 20 3d 3d 20 4e 55 4c 4c 29 homedir == NULL)
7aa0: 20 7b 0a 09 09 09 72 65 74 75 72 6e 28 54 43 4c {....return(TCL
7ab0: 5f 45 52 52 4f 52 29 3b 0a 09 09 7d 0a 0a 09 09 _ERROR);...}....
7ac0: 68 6f 6d 65 64 69 72 5f 6f 62 6a 20 3d 20 54 63 homedir_obj = Tc
7ad0: 6c 5f 4e 65 77 53 74 72 69 6e 67 4f 62 6a 28 68 l_NewStringObj(h
7ae0: 6f 6d 65 64 69 72 2c 20 2d 31 29 3b 0a 0a 09 09 omedir, -1);....
7af0: 66 72 65 65 28 68 6f 6d 65 64 69 72 29 3b 0a 0a free(homedir);..
7b00: 09 09 69 66 20 28 6c 61 73 74 5f 68 6f 6d 65 64 ..if (last_homed
7b10: 69 72 5f 6f 62 6a 20 21 3d 20 4e 55 4c 4c 29 20 ir_obj != NULL)
7b20: 7b 0a 09 09 09 54 63 6c 5f 44 65 63 72 52 65 66 {....Tcl_DecrRef
7b30: 43 6f 75 6e 74 28 6c 61 73 74 5f 68 6f 6d 65 64 Count(last_homed
7b40: 69 72 5f 6f 62 6a 29 3b 0a 09 09 7d 0a 0a 09 09 ir_obj);...}....
7b50: 6c 61 73 74 5f 68 6f 6d 65 64 69 72 5f 6f 62 6a last_homedir_obj
7b60: 20 3d 20 68 6f 6d 65 64 69 72 5f 6f 62 6a 3b 0a = homedir_obj;.
7b70: 09 09 6c 61 73 74 5f 66 73 75 69 64 20 3d 20 66 ..last_fsuid = f
7b80: 73 75 69 64 3b 0a 0a 09 09 54 63 6c 5f 49 6e 63 suid;....Tcl_Inc
7b90: 72 52 65 66 43 6f 75 6e 74 28 6c 61 73 74 5f 68 rRefCount(last_h
7ba0: 6f 6d 65 64 69 72 5f 6f 62 6a 29 3b 0a 09 7d 0a omedir_obj);..}.
7bb0: 0a 20 20 20 20 20 20 20 09 54 63 6c 5f 53 65 74 . .Tcl_Set
7bc0: 4f 62 6a 52 65 73 75 6c 74 28 69 6e 74 65 72 70 ObjResult(interp
7bd0: 2c 20 68 6f 6d 65 64 69 72 5f 6f 62 6a 29 3b 0a , homedir_obj);.
7be0: 0a 20 20 20 20 20 20 20 20 72 65 74 75 72 6e 28 . return(
7bf0: 54 43 4c 5f 4f 4b 29 3b 0a 7d 0a 0a 73 74 61 74 TCL_OK);.}..stat
7c00: 69 63 20 69 6e 74 20 74 63 6c 5f 61 70 70 66 73 ic int tcl_appfs
7c10: 5f 73 69 6d 75 6c 61 74 65 5f 75 73 65 72 5f 66 _simulate_user_f
7c20: 73 5f 65 6e 74 65 72 28 43 6c 69 65 6e 74 44 61 s_enter(ClientDa
7c30: 74 61 20 63 64 2c 20 54 63 6c 5f 49 6e 74 65 72 ta cd, Tcl_Inter
7c40: 70 20 2a 69 6e 74 65 72 70 2c 20 69 6e 74 20 6f p *interp, int o
7c50: 62 6a 63 2c 20 54 63 6c 5f 4f 62 6a 20 2a 43 4f bjc, Tcl_Obj *CO
7c60: 4e 53 54 20 6f 62 6a 76 5b 5d 29 20 7b 0a 09 61 NST objv[]) {..a
7c70: 70 70 66 73 5f 73 69 6d 75 6c 61 74 65 5f 75 73 ppfs_simulate_us
7c80: 65 72 5f 66 73 5f 65 6e 74 65 72 28 29 3b 0a 0a er_fs_enter();..
7c90: 09 72 65 74 75 72 6e 28 54 43 4c 5f 4f 4b 29 3b .return(TCL_OK);
7ca0: 0a 7d 0a 0a 73 74 61 74 69 63 20 69 6e 74 20 74 .}..static int t
7cb0: 63 6c 5f 61 70 70 66 73 5f 73 69 6d 75 6c 61 74 cl_appfs_simulat
7cc0: 65 5f 75 73 65 72 5f 66 73 5f 6c 65 61 76 65 28 e_user_fs_leave(
7cd0: 43 6c 69 65 6e 74 44 61 74 61 20 63 64 2c 20 54 ClientData cd, T
7ce0: 63 6c 5f 49 6e 74 65 72 70 20 2a 69 6e 74 65 72 cl_Interp *inter
7cf0: 70 2c 20 69 6e 74 20 6f 62 6a 63 2c 20 54 63 6c p, int objc, Tcl
7d00: 5f 4f 62 6a 20 2a 43 4f 4e 53 54 20 6f 62 6a 76 _Obj *CONST objv
7d10: 5b 5d 29 20 7b 0a 09 61 70 70 66 73 5f 73 69 6d []) {..appfs_sim
7d20: 75 6c 61 74 65 5f 75 73 65 72 5f 66 73 5f 6c 65 ulate_user_fs_le
7d30: 61 76 65 28 29 3b 0a 0a 09 72 65 74 75 72 6e 28 ave();...return(
7d40: 54 43 4c 5f 4f 4b 29 3b 0a 7d 0a 0a 73 74 61 74 TCL_OK);.}..stat
7d50: 69 63 20 69 6e 74 20 74 63 6c 5f 61 70 70 66 73 ic int tcl_appfs
7d60: 5f 67 65 74 5f 66 73 75 69 64 28 43 6c 69 65 6e _get_fsuid(Clien
7d70: 74 44 61 74 61 20 63 64 2c 20 54 63 6c 5f 49 6e tData cd, Tcl_In
7d80: 74 65 72 70 20 2a 69 6e 74 65 72 70 2c 20 69 6e terp *interp, in
7d90: 74 20 6f 62 6a 63 2c 20 54 63 6c 5f 4f 62 6a 20 t objc, Tcl_Obj
7da0: 2a 43 4f 4e 53 54 20 6f 62 6a 76 5b 5d 29 20 7b *CONST objv[]) {
7db0: 0a 09 75 69 64 5f 74 20 66 73 75 69 64 3b 0a 0a ..uid_t fsuid;..
7dc0: 09 66 73 75 69 64 20 3d 20 61 70 70 66 73 5f 67 .fsuid = appfs_g
7dd0: 65 74 5f 66 73 75 69 64 28 29 3b 0a 0a 20 20 20 et_fsuid();..
7de0: 20 20 20 20 09 54 63 6c 5f 53 65 74 4f 62 6a 52 .Tcl_SetObjR
7df0: 65 73 75 6c 74 28 69 6e 74 65 72 70 2c 20 54 63 esult(interp, Tc
7e00: 6c 5f 4e 65 77 57 69 64 65 49 6e 74 4f 62 6a 28 l_NewWideIntObj(
7e10: 66 73 75 69 64 29 29 3b 0a 0a 09 72 65 74 75 72 fsuid));...retur
7e20: 6e 28 54 43 4c 5f 4f 4b 29 3b 0a 7d 0a 0a 73 74 n(TCL_OK);.}..st
7e30: 61 74 69 63 20 69 6e 74 20 74 63 6c 5f 61 70 70 atic int tcl_app
7e40: 66 73 5f 67 65 74 5f 66 73 67 69 64 28 43 6c 69 fs_get_fsgid(Cli
7e50: 65 6e 74 44 61 74 61 20 63 64 2c 20 54 63 6c 5f entData cd, Tcl_
7e60: 49 6e 74 65 72 70 20 2a 69 6e 74 65 72 70 2c 20 Interp *interp,
7e70: 69 6e 74 20 6f 62 6a 63 2c 20 54 63 6c 5f 4f 62 int objc, Tcl_Ob
7e80: 6a 20 2a 43 4f 4e 53 54 20 6f 62 6a 76 5b 5d 29 j *CONST objv[])
7e90: 20 7b 0a 09 67 69 64 5f 74 20 66 73 67 69 64 3b {..gid_t fsgid;
7ea0: 0a 0a 09 66 73 67 69 64 20 3d 20 61 70 70 66 73 ...fsgid = appfs
7eb0: 5f 67 65 74 5f 66 73 67 69 64 28 29 3b 0a 0a 20 _get_fsgid();..
7ec0: 20 20 20 20 20 20 09 54 63 6c 5f 53 65 74 4f 62 .Tcl_SetOb
7ed0: 6a 52 65 73 75 6c 74 28 69 6e 74 65 72 70 2c 20 jResult(interp,
7ee0: 54 63 6c 5f 4e 65 77 57 69 64 65 49 6e 74 4f 62 Tcl_NewWideIntOb
7ef0: 6a 28 66 73 67 69 64 29 29 3b 0a 0a 09 72 65 74 j(fsgid));...ret
7f00: 75 72 6e 28 54 43 4c 5f 4f 4b 29 3b 0a 7d 0a 0a urn(TCL_OK);.}..
7f10: 73 74 61 74 69 63 20 69 6e 74 20 74 63 6c 5f 61 static int tcl_a
7f20: 70 70 66 73 5f 67 65 74 5f 70 61 74 68 5f 69 6e ppfs_get_path_in
7f30: 66 6f 5f 63 61 63 68 65 5f 66 6c 75 73 68 28 43 fo_cache_flush(C
7f40: 6c 69 65 6e 74 44 61 74 61 20 63 64 2c 20 54 63 lientData cd, Tc
7f50: 6c 5f 49 6e 74 65 72 70 20 2a 69 6e 74 65 72 70 l_Interp *interp
7f60: 2c 20 69 6e 74 20 6f 62 6a 63 2c 20 54 63 6c 5f , int objc, Tcl_
7f70: 4f 62 6a 20 2a 43 4f 4e 53 54 20 6f 62 6a 76 5b Obj *CONST objv[
7f80: 5d 29 20 7b 0a 09 69 6e 74 20 74 63 6c 5f 72 65 ]) {..int tcl_re
7f90: 74 3b 0a 09 69 6e 74 20 6e 65 77 5f 73 69 7a 65 t;..int new_size
7fa0: 3b 0a 0a 09 6e 65 77 5f 73 69 7a 65 20 3d 20 2d ;...new_size = -
7fb0: 31 3b 0a 0a 09 69 66 20 28 6f 62 6a 63 20 3d 3d 1;...if (objc ==
7fc0: 20 32 29 20 7b 0a 09 09 74 63 6c 5f 72 65 74 20 2) {...tcl_ret
7fd0: 3d 20 54 63 6c 5f 47 65 74 49 6e 74 46 72 6f 6d = Tcl_GetIntFrom
7fe0: 4f 62 6a 28 69 6e 74 65 72 70 2c 20 6f 62 6a 76 Obj(interp, objv
7ff0: 5b 31 5d 2c 20 26 6e 65 77 5f 73 69 7a 65 29 3b [1], &new_size);
8000: 0a 09 09 69 66 20 28 74 63 6c 5f 72 65 74 20 21 ...if (tcl_ret !
8010: 3d 20 54 43 4c 5f 4f 4b 29 20 7b 0a 09 09 09 72 = TCL_OK) {....r
8020: 65 74 75 72 6e 28 74 63 6c 5f 72 65 74 29 3b 0a eturn(tcl_ret);.
8030: 09 09 7d 0a 09 7d 20 65 6c 73 65 20 69 66 20 28 ..}..} else if (
8040: 6f 62 6a 63 20 3e 20 32 20 7c 7c 20 6f 62 6a 63 objc > 2 || objc
8050: 20 3c 20 31 29 20 7b 0a 20 20 20 20 20 20 20 20 < 1) {.
8060: 20 20 20 20 20 20 20 20 54 63 6c 5f 57 72 6f 6e Tcl_Wron
8070: 67 4e 75 6d 41 72 67 73 28 69 6e 74 65 72 70 2c gNumArgs(interp,
8080: 20 31 2c 20 6f 62 6a 76 2c 20 22 3f 6e 65 77 5f 1, objv, "?new_
8090: 63 61 63 68 65 5f 73 69 7a 65 3f 22 29 3b 0a 09 cache_size?");..
80a0: 09 72 65 74 75 72 6e 28 54 43 4c 5f 45 52 52 4f .return(TCL_ERRO
80b0: 52 29 3b 0a 09 7d 0a 0a 09 61 70 70 66 73 5f 67 R);..}...appfs_g
80c0: 65 74 5f 70 61 74 68 5f 69 6e 66 6f 5f 63 61 63 et_path_info_cac
80d0: 68 65 5f 66 6c 75 73 68 28 2d 31 2c 20 6e 65 77 he_flush(-1, new
80e0: 5f 73 69 7a 65 29 3b 0a 0a 09 72 65 74 75 72 6e _size);...return
80f0: 28 54 43 4c 5f 4f 4b 29 3b 0a 7d 0a 0a 73 74 61 (TCL_OK);.}..sta
8100: 74 69 63 20 69 6e 74 20 41 70 70 66 73 64 5f 49 tic int Appfsd_I
8110: 6e 69 74 28 54 63 6c 5f 49 6e 74 65 72 70 20 2a nit(Tcl_Interp *
8120: 69 6e 74 65 72 70 29 20 7b 0a 23 69 66 64 65 66 interp) {.#ifdef
8130: 20 55 53 45 5f 54 43 4c 5f 53 54 55 42 53 0a 09 USE_TCL_STUBS..
8140: 69 66 20 28 54 63 6c 5f 49 6e 69 74 53 74 75 62 if (Tcl_InitStub
8150: 73 28 69 6e 74 65 72 70 2c 20 54 43 4c 5f 56 45 s(interp, TCL_VE
8160: 52 53 49 4f 4e 2c 20 30 29 20 3d 3d 20 30 4c 29 RSION, 0) == 0L)
8170: 20 7b 0a 09 09 72 65 74 75 72 6e 28 54 43 4c 5f {...return(TCL_
8180: 45 52 52 4f 52 29 3b 0a 09 7d 0a 23 65 6e 64 69 ERROR);..}.#endi
8190: 66 0a 0a 09 54 63 6c 5f 43 72 65 61 74 65 4f 62 f...Tcl_CreateOb
81a0: 6a 43 6f 6d 6d 61 6e 64 28 69 6e 74 65 72 70 2c jCommand(interp,
81b0: 20 22 61 70 70 66 73 64 3a 3a 67 65 74 5f 68 6f "appfsd::get_ho
81c0: 6d 65 64 69 72 22 2c 20 74 63 6c 5f 61 70 70 66 medir", tcl_appf
81d0: 73 5f 67 65 74 5f 68 6f 6d 65 64 69 72 2c 20 4e s_get_homedir, N
81e0: 55 4c 4c 2c 20 4e 55 4c 4c 29 3b 0a 09 54 63 6c ULL, NULL);..Tcl
81f0: 5f 43 72 65 61 74 65 4f 62 6a 43 6f 6d 6d 61 6e _CreateObjComman
8200: 64 28 69 6e 74 65 72 70 2c 20 22 61 70 70 66 73 d(interp, "appfs
8210: 64 3a 3a 67 65 74 5f 66 73 75 69 64 22 2c 20 74 d::get_fsuid", t
8220: 63 6c 5f 61 70 70 66 73 5f 67 65 74 5f 66 73 75 cl_appfs_get_fsu
8230: 69 64 2c 20 4e 55 4c 4c 2c 20 4e 55 4c 4c 29 3b id, NULL, NULL);
8240: 0a 09 54 63 6c 5f 43 72 65 61 74 65 4f 62 6a 43 ..Tcl_CreateObjC
8250: 6f 6d 6d 61 6e 64 28 69 6e 74 65 72 70 2c 20 22 ommand(interp, "
8260: 61 70 70 66 73 64 3a 3a 67 65 74 5f 66 73 67 69 appfsd::get_fsgi
8270: 64 22 2c 20 74 63 6c 5f 61 70 70 66 73 5f 67 65 d", tcl_appfs_ge
8280: 74 5f 66 73 67 69 64 2c 20 4e 55 4c 4c 2c 20 4e t_fsgid, NULL, N
8290: 55 4c 4c 29 3b 0a 09 54 63 6c 5f 43 72 65 61 74 ULL);..Tcl_Creat
82a0: 65 4f 62 6a 43 6f 6d 6d 61 6e 64 28 69 6e 74 65 eObjCommand(inte
82b0: 72 70 2c 20 22 61 70 70 66 73 64 3a 3a 73 69 6d rp, "appfsd::sim
82c0: 75 6c 61 74 65 5f 75 73 65 72 5f 66 73 5f 65 6e ulate_user_fs_en
82d0: 74 65 72 22 2c 20 74 63 6c 5f 61 70 70 66 73 5f ter", tcl_appfs_
82e0: 73 69 6d 75 6c 61 74 65 5f 75 73 65 72 5f 66 73 simulate_user_fs
82f0: 5f 65 6e 74 65 72 2c 20 4e 55 4c 4c 2c 20 4e 55 _enter, NULL, NU
8300: 4c 4c 29 3b 0a 09 54 63 6c 5f 43 72 65 61 74 65 LL);..Tcl_Create
8310: 4f 62 6a 43 6f 6d 6d 61 6e 64 28 69 6e 74 65 72 ObjCommand(inter
8320: 70 2c 20 22 61 70 70 66 73 64 3a 3a 73 69 6d 75 p, "appfsd::simu
8330: 6c 61 74 65 5f 75 73 65 72 5f 66 73 5f 6c 65 61 late_user_fs_lea
8340: 76 65 22 2c 20 74 63 6c 5f 61 70 70 66 73 5f 73 ve", tcl_appfs_s
8350: 69 6d 75 6c 61 74 65 5f 75 73 65 72 5f 66 73 5f imulate_user_fs_
8360: 6c 65 61 76 65 2c 20 4e 55 4c 4c 2c 20 4e 55 4c leave, NULL, NUL
8370: 4c 29 3b 0a 09 54 63 6c 5f 43 72 65 61 74 65 4f L);..Tcl_CreateO
8380: 62 6a 43 6f 6d 6d 61 6e 64 28 69 6e 74 65 72 70 bjCommand(interp
8390: 2c 20 22 61 70 70 66 73 64 3a 3a 67 65 74 5f 70 , "appfsd::get_p
83a0: 61 74 68 5f 69 6e 66 6f 5f 63 61 63 68 65 5f 66 ath_info_cache_f
83b0: 6c 75 73 68 22 2c 20 74 63 6c 5f 61 70 70 66 73 lush", tcl_appfs
83c0: 5f 67 65 74 5f 70 61 74 68 5f 69 6e 66 6f 5f 63 _get_path_info_c
83d0: 61 63 68 65 5f 66 6c 75 73 68 2c 20 4e 55 4c 4c ache_flush, NULL
83e0: 2c 20 4e 55 4c 4c 29 3b 0a 0a 09 54 63 6c 5f 50 , NULL);...Tcl_P
83f0: 6b 67 50 72 6f 76 69 64 65 28 69 6e 74 65 72 70 kgProvide(interp
8400: 2c 20 22 61 70 70 66 73 64 22 2c 20 22 31 2e 30 , "appfsd", "1.0
8410: 22 29 3b 0a 0a 09 72 65 74 75 72 6e 28 54 43 4c ");...return(TCL
8420: 5f 4f 4b 29 3b 0a 7d 0a 0a 2f 2a 0a 20 2a 20 48 _OK);.}../*. * H
8430: 6f 74 2d 72 65 73 74 61 72 74 20 73 75 70 70 6f ot-restart suppo
8440: 72 74 0a 20 2a 2f 0a 2f 2a 20 49 6e 69 74 69 61 rt. */./* Initia
8450: 74 65 20 61 20 68 6f 74 2d 72 65 73 74 61 72 74 te a hot-restart
8460: 20 2a 2f 0a 73 74 61 74 69 63 20 76 6f 69 64 20 */.static void
8470: 61 70 70 66 73 5f 68 6f 74 5f 72 65 73 74 61 72 appfs_hot_restar
8480: 74 28 76 6f 69 64 29 20 7b 0a 09 61 70 70 66 73 t(void) {..appfs
8490: 5f 74 63 6c 5f 52 65 73 65 74 49 6e 74 65 72 70 _tcl_ResetInterp
84a0: 73 28 29 3b 0a 09 61 70 70 66 73 5f 67 65 74 5f s();..appfs_get_
84b0: 70 61 74 68 5f 69 6e 66 6f 5f 63 61 63 68 65 5f path_info_cache_
84c0: 66 6c 75 73 68 28 2d 31 2c 20 2d 31 29 3b 0a 0a flush(-1, -1);..
84d0: 09 72 65 74 75 72 6e 3b 0a 7d 0a 0a 2f 2a 0a 20 .return;.}../*.
84e0: 2a 20 53 69 67 6e 61 6c 20 68 61 6e 64 6c 65 72 * Signal handler
84f0: 20 74 6f 20 69 6e 69 74 69 61 74 65 20 61 20 68 to initiate a h
8500: 6f 74 2d 72 65 73 74 61 72 74 0a 20 2a 2f 0a 73 ot-restart. */.s
8510: 74 61 74 69 63 20 76 6f 69 64 20 61 70 70 66 73 tatic void appfs
8520: 5f 73 69 67 6e 61 6c 5f 68 61 6e 64 6c 65 72 28 _signal_handler(
8530: 69 6e 74 20 73 69 67 29 20 7b 0a 09 2f 2a 20 44 int sig) {../* D
8540: 6f 20 6e 6f 74 20 68 61 6e 64 6c 65 20 73 69 67 o not handle sig
8550: 6e 61 6c 73 20 75 6e 74 69 6c 20 46 55 53 45 20 nals until FUSE
8560: 68 61 73 20 62 65 65 6e 20 73 74 61 72 74 65 64 has been started
8570: 20 2a 2f 0a 09 69 66 20 28 21 61 70 70 66 73 5f */..if (!appfs_
8580: 66 75 73 65 5f 73 74 61 72 74 65 64 29 20 7b 0a fuse_started) {.
8590: 09 09 72 65 74 75 72 6e 3b 0a 09 7d 0a 0a 09 69 ..return;..}...i
85a0: 66 20 28 73 69 67 20 3d 3d 20 53 49 47 48 55 50 f (sig == SIGHUP
85b0: 29 20 7b 0a 09 09 61 70 70 66 73 5f 68 6f 74 5f ) {...appfs_hot_
85c0: 72 65 73 74 61 72 74 28 29 3b 0a 09 7d 0a 0a 09 restart();..}...
85d0: 72 65 74 75 72 6e 3b 0a 7d 0a 0a 2f 2a 0a 20 2a return;.}../*. *
85e0: 20 46 55 53 45 20 6f 70 65 72 61 74 69 6f 6e 73 FUSE operations
85f0: 20 73 74 72 75 63 74 75 72 65 0a 20 2a 2f 0a 73 structure. */.s
8600: 74 61 74 69 63 20 73 74 72 75 63 74 20 66 75 73 tatic struct fus
8610: 65 5f 6f 70 65 72 61 74 69 6f 6e 73 20 61 70 70 e_operations app
8620: 66 73 5f 6f 70 65 72 61 74 69 6f 6e 73 20 3d 20 fs_operations =
8630: 7b 0a 09 2e 67 65 74 61 74 74 72 20 20 20 3d 20 {...getattr =
8640: 61 70 70 66 73 5f 66 75 73 65 5f 67 65 74 61 74 appfs_fuse_getat
8650: 74 72 2c 0a 09 2e 72 65 61 64 64 69 72 20 20 20 tr,...readdir
8660: 3d 20 61 70 70 66 73 5f 66 75 73 65 5f 72 65 61 = appfs_fuse_rea
8670: 64 64 69 72 2c 0a 09 2e 72 65 61 64 6c 69 6e 6b ddir,...readlink
8680: 20 20 3d 20 61 70 70 66 73 5f 66 75 73 65 5f 72 = appfs_fuse_r
8690: 65 61 64 6c 69 6e 6b 2c 0a 09 2e 6f 70 65 6e 20 eadlink,...open
86a0: 20 20 20 20 20 3d 20 61 70 70 66 73 5f 66 75 73 = appfs_fus
86b0: 65 5f 6f 70 65 6e 2c 0a 09 2e 72 65 6c 65 61 73 e_open,...releas
86c0: 65 20 20 20 3d 20 61 70 70 66 73 5f 66 75 73 65 e = appfs_fuse
86d0: 5f 63 6c 6f 73 65 2c 0a 09 2e 72 65 61 64 20 20 _close,...read
86e0: 20 20 20 20 3d 20 61 70 70 66 73 5f 66 75 73 65 = appfs_fuse
86f0: 5f 72 65 61 64 2c 0a 09 2e 77 72 69 74 65 20 20 _read,...write
8700: 20 20 20 3d 20 61 70 70 66 73 5f 66 75 73 65 5f = appfs_fuse_
8710: 77 72 69 74 65 2c 0a 09 2e 6d 6b 6e 6f 64 20 20 write,...mknod
8720: 20 20 20 3d 20 61 70 70 66 73 5f 66 75 73 65 5f = appfs_fuse_
8730: 6d 6b 6e 6f 64 2c 0a 09 2e 63 72 65 61 74 65 20 mknod,...create
8740: 20 20 20 3d 20 61 70 70 66 73 5f 66 75 73 65 5f = appfs_fuse_
8750: 63 72 65 61 74 65 2c 0a 09 2e 74 72 75 6e 63 61 create,...trunca
8760: 74 65 20 20 3d 20 61 70 70 66 73 5f 66 75 73 65 te = appfs_fuse
8770: 5f 74 72 75 6e 63 61 74 65 2c 0a 09 2e 75 6e 6c _truncate,...unl
8780: 69 6e 6b 20 20 20 20 3d 20 61 70 70 66 73 5f 66 ink = appfs_f
8790: 75 73 65 5f 75 6e 6c 69 6e 6b 5f 72 6d 64 69 72 use_unlink_rmdir
87a0: 2c 0a 09 2e 72 6d 64 69 72 20 20 20 20 20 3d 20 ,...rmdir =
87b0: 61 70 70 66 73 5f 66 75 73 65 5f 75 6e 6c 69 6e appfs_fuse_unlin
87c0: 6b 5f 72 6d 64 69 72 2c 0a 09 2e 6d 6b 64 69 72 k_rmdir,...mkdir
87d0: 20 20 20 20 20 3d 20 61 70 70 66 73 5f 66 75 73 = appfs_fus
87e0: 65 5f 6d 6b 64 69 72 2c 0a 09 2e 63 68 6d 6f 64 e_mkdir,...chmod
87f0: 20 20 20 20 20 3d 20 61 70 70 66 73 5f 66 75 73 = appfs_fus
8800: 65 5f 63 68 6d 6f 64 2c 0a 7d 3b 0a 0a 2f 2a 0a e_chmod,.};../*.
8810: 20 2a 20 46 55 53 45 20 6f 70 74 69 6f 6e 20 70 * FUSE option p
8820: 61 72 73 69 6e 67 20 63 61 6c 6c 62 61 63 6b 0a arsing callback.
8830: 20 2a 2f 0a 73 74 61 74 69 63 20 69 6e 74 20 61 */.static int a
8840: 70 70 66 73 5f 66 75 73 65 5f 6f 70 74 5f 63 62 ppfs_fuse_opt_cb
8850: 28 76 6f 69 64 20 2a 64 61 74 61 2c 20 63 6f 6e (void *data, con
8860: 73 74 20 63 68 61 72 20 2a 61 72 67 2c 20 69 6e st char *arg, in
8870: 74 20 6b 65 79 2c 20 73 74 72 75 63 74 20 66 75 t key, struct fu
8880: 73 65 5f 61 72 67 73 20 2a 6f 75 74 61 72 67 73 se_args *outargs
8890: 29 20 7b 0a 09 73 74 61 74 69 63 20 69 6e 74 20 ) {..static int
88a0: 73 65 65 6e 5f 63 61 63 68 65 64 69 72 20 3d 20 seen_cachedir =
88b0: 30 3b 0a 0a 09 69 66 20 28 6b 65 79 20 3d 3d 20 0;...if (key ==
88c0: 46 55 53 45 5f 4f 50 54 5f 4b 45 59 5f 4e 4f 4e FUSE_OPT_KEY_NON
88d0: 4f 50 54 20 26 26 20 73 65 65 6e 5f 63 61 63 68 OPT && seen_cach
88e0: 65 64 69 72 20 3d 3d 20 30 29 20 7b 0a 09 09 73 edir == 0) {...s
88f0: 65 65 6e 5f 63 61 63 68 65 64 69 72 20 3d 20 31 een_cachedir = 1
8900: 3b 0a 0a 09 09 61 70 70 66 73 5f 63 61 63 68 65 ;....appfs_cache
8910: 64 69 72 20 3d 20 73 74 72 64 75 70 28 61 72 67 dir = strdup(arg
8920: 29 3b 0a 0a 09 09 72 65 74 75 72 6e 28 30 29 3b );....return(0);
8930: 0a 09 7d 0a 0a 09 72 65 74 75 72 6e 28 31 29 3b ..}...return(1);
8940: 0a 7d 0a 0a 2f 2a 0a 20 2a 20 45 6e 74 72 79 20 .}../*. * Entry
8950: 70 6f 69 6e 74 20 69 6e 74 6f 20 74 68 69 73 20 point into this
8960: 70 72 6f 67 72 61 6d 2e 0a 20 2a 2f 0a 69 6e 74 program.. */.int
8970: 20 6d 61 69 6e 28 69 6e 74 20 61 72 67 63 2c 20 main(int argc,
8980: 63 68 61 72 20 2a 2a 61 72 67 76 29 20 7b 0a 09 char **argv) {..
8990: 54 63 6c 5f 49 6e 74 65 72 70 20 2a 74 65 73 74 Tcl_Interp *test
89a0: 5f 69 6e 74 65 72 70 3b 0a 09 63 68 61 72 20 2a _interp;..char *
89b0: 74 65 73 74 5f 69 6e 74 65 72 70 5f 65 72 72 6f test_interp_erro
89c0: 72 3b 0a 09 73 74 72 75 63 74 20 66 75 73 65 5f r;..struct fuse_
89d0: 61 72 67 73 20 61 72 67 73 20 3d 20 46 55 53 45 args args = FUSE
89e0: 5f 41 52 47 53 5f 49 4e 49 54 28 61 72 67 63 2c _ARGS_INIT(argc,
89f0: 20 61 72 67 76 29 3b 0a 09 69 6e 74 20 70 74 68 argv);..int pth
8a00: 72 65 61 64 5f 72 65 74 3b 0a 09 76 6f 69 64 20 read_ret;..void
8a10: 2a 73 69 67 6e 61 6c 5f 72 65 74 3b 0a 0a 09 2f *signal_ret;.../
8a20: 2a 0a 09 20 2a 20 53 6b 69 70 20 70 61 73 73 65 *.. * Skip passe
8a30: 64 20 70 72 6f 67 72 61 6d 20 6e 61 6d 65 0a 09 d program name..
8a40: 20 2a 2f 0a 09 69 66 20 28 61 72 67 63 20 3d 3d */..if (argc ==
8a50: 20 30 20 7c 7c 20 61 72 67 76 20 3d 3d 20 4e 55 0 || argv == NU
8a60: 4c 4c 29 20 7b 0a 09 09 72 65 74 75 72 6e 28 31 LL) {...return(1
8a70: 29 3b 0a 09 7d 0a 09 61 72 67 63 2d 2d 3b 0a 09 );..}..argc--;..
8a80: 61 72 67 76 2b 2b 3b 0a 0a 09 2f 2a 0a 09 20 2a argv++;.../*.. *
8a90: 20 53 65 74 20 67 6c 6f 62 61 6c 20 76 61 72 69 Set global vari
8aa0: 61 62 6c 65 73 2c 20 74 68 65 73 65 20 73 68 6f ables, these sho
8ab0: 75 6c 64 20 62 65 20 63 6f 6e 66 69 67 75 72 61 uld be configura
8ac0: 74 69 6f 6e 20 6f 70 74 69 6f 6e 73 2e 0a 09 20 tion options...
8ad0: 2a 2f 0a 09 61 70 70 66 73 5f 63 61 63 68 65 64 */..appfs_cached
8ae0: 69 72 20 3d 20 41 50 50 46 53 5f 43 41 43 48 45 ir = APPFS_CACHE
8af0: 44 49 52 3b 0a 0a 09 2f 2a 0a 09 20 2a 20 53 65 DIR;.../*.. * Se
8b00: 74 20 67 6c 6f 62 61 6c 20 76 61 72 69 61 62 6c t global variabl
8b10: 65 20 66 6f 72 20 22 62 6f 6f 74 20 74 69 6d 65 e for "boot time
8b20: 22 20 74 6f 20 73 65 74 20 61 20 74 69 6d 65 20 " to set a time
8b30: 6f 6e 20 64 69 72 65 63 74 6f 72 69 65 73 0a 09 on directories..
8b40: 20 2a 20 74 68 61 74 20 77 65 20 66 61 6b 65 2e * that we fake.
8b50: 0a 09 20 2a 2f 0a 09 61 70 70 66 73 5f 62 6f 6f .. */..appfs_boo
8b60: 74 74 69 6d 65 20 3d 20 74 69 6d 65 28 4e 55 4c ttime = time(NUL
8b70: 4c 29 3b 0a 0a 09 2f 2a 0a 09 20 2a 20 52 65 67 L);.../*.. * Reg
8b80: 69 73 74 65 72 20 22 73 68 61 31 22 20 61 6e 64 ister "sha1" and
8b90: 20 22 61 70 70 66 73 64 22 20 70 61 63 6b 61 67 "appfsd" packag
8ba0: 65 20 77 69 74 68 20 6c 69 62 74 63 6c 20 73 6f e with libtcl so
8bb0: 20 74 68 61 74 20 61 6e 79 20 6e 65 77 0a 09 20 that any new..
8bc0: 2a 20 69 6e 74 65 72 70 72 65 74 65 72 73 20 63 * interpreters c
8bd0: 72 65 61 74 65 64 20 28 77 68 69 63 68 20 61 72 reated (which ar
8be0: 65 20 64 6f 6e 65 20 64 79 6e 61 6d 69 63 61 6c e done dynamical
8bf0: 6c 79 20 62 79 20 46 55 53 45 29 20 63 61 6e 20 ly by FUSE) can
8c00: 68 61 76 65 0a 09 20 2a 20 74 68 65 20 61 70 70 have.. * the app
8c10: 72 6f 70 72 69 61 74 65 20 63 6f 6e 66 69 67 75 ropriate configu
8c20: 72 61 74 69 6f 6e 20 64 6f 6e 65 20 61 75 74 6f ration done auto
8c30: 6d 61 74 69 63 61 6c 6c 79 2e 0a 09 20 2a 2f 0a matically... */.
8c40: 09 54 63 6c 5f 53 74 61 74 69 63 50 61 63 6b 61 .Tcl_StaticPacka
8c50: 67 65 28 4e 55 4c 4c 2c 20 22 73 68 61 31 22 2c ge(NULL, "sha1",
8c60: 20 53 68 61 31 5f 49 6e 69 74 2c 20 4e 55 4c 4c Sha1_Init, NULL
8c70: 29 3b 0a 09 54 63 6c 5f 53 74 61 74 69 63 50 61 );..Tcl_StaticPa
8c80: 63 6b 61 67 65 28 4e 55 4c 4c 2c 20 22 61 70 70 ckage(NULL, "app
8c90: 66 73 64 22 2c 20 41 70 70 66 73 64 5f 49 6e 69 fsd", Appfsd_Ini
8ca0: 74 2c 20 4e 55 4c 4c 29 3b 0a 0a 09 2f 2a 0a 09 t, NULL);.../*..
8cb0: 20 2a 20 43 72 65 61 74 65 20 61 20 74 68 72 65 * Create a thre
8cc0: 61 64 2d 73 70 65 63 69 66 69 63 2d 64 61 74 61 ad-specific-data
8cd0: 20 28 54 53 44 29 20 6b 65 79 20 66 6f 72 20 65 (TSD) key for e
8ce0: 61 63 68 20 74 68 72 65 61 64 20 74 6f 20 72 65 ach thread to re
8cf0: 66 65 72 0a 09 20 2a 20 74 6f 20 69 74 73 20 6f fer.. * to its o
8d00: 77 6e 20 54 63 6c 20 69 6e 74 65 72 70 72 65 74 wn Tcl interpret
8d10: 65 72 2e 20 20 54 63 6c 20 69 6e 74 65 72 70 72 er. Tcl interpr
8d20: 65 74 65 72 73 20 6d 75 73 74 20 62 65 20 75 6e eters must be un
8d30: 69 71 75 65 20 70 65 72 0a 09 20 2a 20 74 68 72 ique per.. * thr
8d40: 65 61 64 20 61 6e 64 20 6e 65 77 20 74 68 72 65 ead and new thre
8d50: 61 64 73 20 61 72 65 20 64 79 6e 61 6d 69 63 61 ads are dynamica
8d60: 6c 6c 79 20 63 72 65 61 74 65 64 20 62 79 20 46 lly created by F
8d70: 55 53 45 2e 0a 09 20 2a 2f 0a 09 70 74 68 72 65 USE... */..pthre
8d80: 61 64 5f 72 65 74 20 3d 20 70 74 68 72 65 61 64 ad_ret = pthread
8d90: 5f 6b 65 79 5f 63 72 65 61 74 65 28 26 69 6e 74 _key_create(&int
8da0: 65 72 70 4b 65 79 2c 20 4e 55 4c 4c 29 3b 0a 09 erpKey, NULL);..
8db0: 69 66 20 28 70 74 68 72 65 61 64 5f 72 65 74 20 if (pthread_ret
8dc0: 21 3d 20 30 29 20 7b 0a 09 09 66 70 72 69 6e 74 != 0) {...fprint
8dd0: 66 28 73 74 64 65 72 72 2c 20 22 55 6e 61 62 6c f(stderr, "Unabl
8de0: 65 20 74 6f 20 63 72 65 61 74 65 20 54 53 44 20 e to create TSD
8df0: 6b 65 79 20 66 6f 72 20 54 63 6c 2e 20 20 41 62 key for Tcl. Ab
8e00: 6f 72 74 69 6e 67 2e 5c 6e 22 29 3b 0a 0a 09 09 orting.\n");....
8e10: 72 65 74 75 72 6e 28 31 29 3b 0a 09 7d 0a 0a 09 return(1);..}...
8e20: 2f 2a 0a 09 20 2a 20 4d 61 6e 75 61 6c 6c 79 20 /*.. * Manually
8e30: 73 70 65 63 69 66 79 20 63 61 63 68 65 20 64 69 specify cache di
8e40: 72 65 63 74 6f 72 79 2c 20 77 69 74 68 6f 75 74 rectory, without
8e50: 20 46 55 53 45 20 63 61 6c 6c 62 61 63 6b 0a 09 FUSE callback..
8e60: 20 2a 20 54 68 69 73 20 6f 70 74 69 6f 6e 20 6f * This option o
8e70: 6e 6c 79 20 77 6f 72 6b 73 20 77 68 65 6e 20 6e nly works when n
8e80: 6f 74 20 75 73 69 6e 67 20 46 55 53 45 2c 20 73 ot using FUSE, s
8e90: 69 6e 63 65 20 77 65 0a 09 20 2a 20 64 6f 20 6e ince we.. * do n
8ea0: 6f 74 20 70 72 6f 63 65 73 73 20 69 74 20 77 69 ot process it wi
8eb0: 74 68 20 46 55 53 45 73 20 6f 70 74 69 6f 6e 20 th FUSEs option
8ec0: 70 72 6f 63 65 73 73 69 6e 67 2e 0a 09 20 2a 2f processing... */
8ed0: 0a 09 69 66 20 28 61 72 67 63 20 3e 3d 20 32 29 ..if (argc >= 2)
8ee0: 20 7b 0a 09 09 69 66 20 28 73 74 72 63 6d 70 28 {...if (strcmp(
8ef0: 61 72 67 76 5b 30 5d 2c 20 22 2d 2d 63 61 63 68 argv[0], "--cach
8f00: 65 64 69 72 22 29 20 3d 3d 20 30 29 20 7b 0a 09 edir") == 0) {..
8f10: 09 09 61 70 70 66 73 5f 63 61 63 68 65 64 69 72 ..appfs_cachedir
8f20: 20 3d 20 73 74 72 64 75 70 28 61 72 67 76 5b 31 = strdup(argv[1
8f30: 5d 29 3b 0a 0a 09 09 09 61 72 67 63 20 2d 3d 20 ]);.....argc -=
8f40: 32 3b 0a 09 09 09 61 72 67 76 20 2b 3d 20 32 3b 2;....argv += 2;
8f50: 0a 09 09 7d 0a 09 7d 0a 0a 09 2f 2a 0a 09 20 2a ...}..}.../*.. *
8f60: 20 53 51 4c 69 74 65 33 20 6d 6f 64 65 2c 20 66 SQLite3 mode, f
8f70: 6f 72 20 72 75 6e 6e 69 6e 67 20 72 61 77 20 53 or running raw S
8f80: 51 4c 20 61 67 61 69 6e 73 74 20 74 68 65 20 63 QL against the c
8f90: 61 63 68 65 20 64 61 74 61 62 61 73 65 0a 09 20 ache database..
8fa0: 2a 2f 0a 09 69 66 20 28 61 72 67 63 20 3d 3d 20 */..if (argc ==
8fb0: 32 20 26 26 20 73 74 72 63 6d 70 28 61 72 67 76 2 && strcmp(argv
8fc0: 5b 30 5d 2c 20 22 2d 2d 73 71 6c 69 74 65 33 22 [0], "--sqlite3"
8fd0: 29 20 3d 3d 20 30 29 20 7b 0a 09 09 72 65 74 75 ) == 0) {...retu
8fe0: 72 6e 28 61 70 70 66 73 5f 73 71 6c 69 74 65 33 rn(appfs_sqlite3
8ff0: 28 61 72 67 76 5b 31 5d 29 29 3b 0a 09 7d 0a 0a (argv[1]));..}..
9000: 09 2f 2a 0a 09 20 2a 20 54 63 6c 20 6d 6f 64 65 ./*.. * Tcl mode
9010: 2c 20 66 6f 72 20 72 75 6e 6e 69 6e 67 20 72 61 , for running ra
9020: 77 20 54 63 6c 20 69 6e 20 74 68 65 20 73 61 6d w Tcl in the sam
9030: 65 20 65 6e 76 69 72 6f 6e 6d 65 6e 74 20 41 70 e environment Ap
9040: 70 46 53 64 20 77 6f 75 6c 64 0a 09 20 2a 20 72 pFSd would.. * r
9050: 75 6e 20 63 6f 64 65 2e 0a 09 20 2a 2f 0a 09 69 un code... */..i
9060: 66 20 28 61 72 67 63 20 3d 3d 20 32 20 26 26 20 f (argc == 2 &&
9070: 73 74 72 63 6d 70 28 61 72 67 76 5b 30 5d 2c 20 strcmp(argv[0],
9080: 22 2d 2d 74 63 6c 22 29 20 3d 3d 20 30 29 20 7b "--tcl") == 0) {
9090: 0a 09 09 72 65 74 75 72 6e 28 61 70 70 66 73 5f ...return(appfs_
90a0: 74 63 6c 28 61 72 67 76 5b 31 5d 29 29 3b 0a 09 tcl(argv[1]));..
90b0: 7d 0a 0a 09 2f 2a 0a 09 20 2a 20 43 72 65 61 74 }.../*.. * Creat
90c0: 65 20 61 20 54 63 6c 20 69 6e 74 65 72 70 72 65 e a Tcl interpre
90d0: 74 65 72 20 6a 75 73 74 20 74 6f 20 76 65 72 69 ter just to veri
90e0: 66 79 20 74 68 61 74 20 74 68 69 6e 67 73 20 61 fy that things a
90f0: 72 65 20 69 6e 20 77 6f 72 6b 69 6e 67 20 0a 09 re in working ..
9100: 20 2a 20 6f 72 64 65 72 20 62 65 66 6f 72 65 20 * order before
9110: 77 65 20 62 65 63 6f 6d 65 20 61 20 64 61 65 6d we become a daem
9120: 6f 6e 2e 0a 09 20 2a 2f 0a 09 74 65 73 74 5f 69 on... */..test_i
9130: 6e 74 65 72 70 20 3d 20 61 70 70 66 73 5f 63 72 nterp = appfs_cr
9140: 65 61 74 65 5f 54 63 6c 49 6e 74 65 72 70 28 26 eate_TclInterp(&
9150: 74 65 73 74 5f 69 6e 74 65 72 70 5f 65 72 72 6f test_interp_erro
9160: 72 29 3b 0a 09 69 66 20 28 74 65 73 74 5f 69 6e r);..if (test_in
9170: 74 65 72 70 20 3d 3d 20 4e 55 4c 4c 29 20 7b 0a terp == NULL) {.
9180: 09 09 69 66 20 28 74 65 73 74 5f 69 6e 74 65 72 ..if (test_inter
9190: 70 5f 65 72 72 6f 72 20 3d 3d 20 4e 55 4c 4c 29 p_error == NULL)
91a0: 20 7b 0a 09 09 09 74 65 73 74 5f 69 6e 74 65 72 {....test_inter
91b0: 70 5f 65 72 72 6f 72 20 3d 20 22 55 6e 6b 6e 6f p_error = "Unkno
91c0: 77 6e 20 65 72 72 6f 72 22 3b 0a 09 09 7d 0a 0a wn error";...}..
91d0: 09 09 66 70 72 69 6e 74 66 28 73 74 64 65 72 72 ..fprintf(stderr
91e0: 2c 20 22 55 6e 61 62 6c 65 20 74 6f 20 69 6e 69 , "Unable to ini
91f0: 74 69 61 6c 69 7a 65 20 54 63 6c 20 69 6e 74 65 tialize Tcl inte
9200: 72 70 72 65 74 65 72 20 66 6f 72 20 41 70 70 46 rpreter for AppF
9210: 53 64 3a 5c 6e 22 29 3b 0a 09 09 66 70 72 69 6e Sd:\n");...fprin
9220: 74 66 28 73 74 64 65 72 72 2c 20 22 25 73 5c 6e tf(stderr, "%s\n
9230: 22 2c 20 74 65 73 74 5f 69 6e 74 65 72 70 5f 65 ", test_interp_e
9240: 72 72 6f 72 29 3b 0a 0a 09 09 72 65 74 75 72 6e rror);....return
9250: 28 31 29 3b 0a 09 7d 0a 09 54 63 6c 5f 44 65 6c (1);..}..Tcl_Del
9260: 65 74 65 49 6e 74 65 72 70 28 74 65 73 74 5f 69 eteInterp(test_i
9270: 6e 74 65 72 70 29 3b 0a 0a 09 2f 2a 0a 09 20 2a nterp);.../*.. *
9280: 20 52 65 67 69 73 74 65 72 20 61 20 73 69 67 6e Register a sign
9290: 61 6c 20 68 61 6e 64 6c 65 72 20 66 6f 72 20 68 al handler for h
92a0: 6f 74 2d 72 65 73 74 61 72 74 20 72 65 71 75 65 ot-restart reque
92b0: 73 74 73 0a 09 20 2a 2f 0a 09 73 69 67 6e 61 6c sts.. */..signal
92c0: 5f 72 65 74 20 3d 20 73 69 67 6e 61 6c 28 53 49 _ret = signal(SI
92d0: 47 48 55 50 2c 20 61 70 70 66 73 5f 73 69 67 6e GHUP, appfs_sign
92e0: 61 6c 5f 68 61 6e 64 6c 65 72 29 3b 0a 09 69 66 al_handler);..if
92f0: 20 28 73 69 67 6e 61 6c 5f 72 65 74 20 3d 3d 20 (signal_ret ==
9300: 53 49 47 5f 45 52 52 29 20 7b 0a 09 09 66 70 72 SIG_ERR) {...fpr
9310: 69 6e 74 66 28 73 74 64 65 72 72 2c 20 22 55 6e intf(stderr, "Un
9320: 61 62 6c 65 20 74 6f 20 69 6e 73 74 61 6c 6c 20 able to install
9330: 73 69 67 6e 61 6c 20 68 61 6e 64 6c 65 72 20 66 signal handler f
9340: 6f 72 20 68 6f 74 2d 72 65 73 74 61 72 74 5c 6e or hot-restart\n
9350: 22 29 3b 0a 09 09 66 70 72 69 6e 74 66 28 73 74 ");...fprintf(st
9360: 64 65 72 72 2c 20 22 48 6f 74 2d 72 65 73 74 61 derr, "Hot-resta
9370: 72 74 20 77 69 6c 6c 20 6e 6f 74 20 62 65 20 61 rt will not be a
9380: 76 61 69 6c 61 62 6c 65 2e 5c 6e 22 29 3b 0a 09 vailable.\n");..
9390: 7d 0a 0a 09 2f 2a 0a 09 20 2a 20 41 64 64 20 46 }.../*.. * Add F
93a0: 55 53 45 20 61 72 67 75 6d 65 6e 74 73 20 77 68 USE arguments wh
93b0: 69 63 68 20 77 65 20 61 6c 77 61 79 73 20 73 75 ich we always su
93c0: 70 70 6c 79 0a 09 20 2a 2f 0a 09 66 75 73 65 5f pply.. */..fuse_
93d0: 6f 70 74 5f 70 61 72 73 65 28 26 61 72 67 73 2c opt_parse(&args,
93e0: 20 4e 55 4c 4c 2c 20 4e 55 4c 4c 2c 20 61 70 70 NULL, NULL, app
93f0: 66 73 5f 66 75 73 65 5f 6f 70 74 5f 63 62 29 3b fs_fuse_opt_cb);
9400: 0a 09 66 75 73 65 5f 6f 70 74 5f 61 64 64 5f 61 ..fuse_opt_add_a
9410: 72 67 28 26 61 72 67 73 2c 20 22 2d 6f 64 65 66 rg(&args, "-odef
9420: 61 75 6c 74 5f 70 65 72 6d 69 73 73 69 6f 6e 73 ault_permissions
9430: 2c 66 73 6e 61 6d 65 3d 61 70 70 66 73 2c 73 75 ,fsname=appfs,su
9440: 62 74 79 70 65 3d 61 70 70 66 73 64 2c 75 73 65 btype=appfsd,use
9450: 5f 69 6e 6f 2c 6b 65 72 6e 65 6c 5f 63 61 63 68 _ino,kernel_cach
9460: 65 2c 65 6e 74 72 79 5f 74 69 6d 65 6f 75 74 3d e,entry_timeout=
9470: 30 2c 61 74 74 72 5f 74 69 6d 65 6f 75 74 3d 30 0,attr_timeout=0
9480: 2c 69 6e 74 72 2c 62 69 67 5f 77 72 69 74 65 73 ,intr,big_writes
9490: 2c 68 61 72 64 5f 72 65 6d 6f 76 65 22 29 3b 0a ,hard_remove");.
94a0: 0a 09 69 66 20 28 67 65 74 75 69 64 28 29 20 3d ..if (getuid() =
94b0: 3d 20 30 29 20 7b 0a 09 09 66 75 73 65 5f 6f 70 = 0) {...fuse_op
94c0: 74 5f 70 61 72 73 65 28 26 61 72 67 73 2c 20 4e t_parse(&args, N
94d0: 55 4c 4c 2c 20 4e 55 4c 4c 2c 20 4e 55 4c 4c 29 ULL, NULL, NULL)
94e0: 3b 0a 09 09 66 75 73 65 5f 6f 70 74 5f 61 64 64 ;...fuse_opt_add
94f0: 5f 61 72 67 28 26 61 72 67 73 2c 20 22 2d 6f 61 _arg(&args, "-oa
9500: 6c 6c 6f 77 5f 6f 74 68 65 72 22 29 3b 0a 09 7d llow_other");..}
9510: 0a 0a 09 2f 2a 0a 09 20 2a 20 45 6e 74 65 72 20 .../*.. * Enter
9520: 74 68 65 20 46 55 53 45 20 6d 61 69 6e 20 6c 6f the FUSE main lo
9530: 6f 70 20 2d 2d 20 74 68 69 73 20 77 69 6c 6c 20 op -- this will
9540: 70 72 6f 63 65 73 73 20 61 6e 79 20 61 72 67 75 process any argu
9550: 6d 65 6e 74 73 0a 09 20 2a 20 61 6e 64 20 73 74 ments.. * and st
9560: 61 72 74 20 73 65 72 76 69 63 69 6e 67 20 72 65 art servicing re
9570: 71 75 65 73 74 73 2e 0a 09 20 2a 2f 0a 09 61 70 quests... */..ap
9580: 70 66 73 5f 66 75 73 65 5f 73 74 61 72 74 65 64 pfs_fuse_started
9590: 20 3d 20 31 3b 0a 09 72 65 74 75 72 6e 28 66 75 = 1;..return(fu
95a0: 73 65 5f 6d 61 69 6e 28 61 72 67 73 2e 61 72 67 se_main(args.arg
95b0: 63 2c 20 61 72 67 73 2e 61 72 67 76 2c 20 26 61 c, args.argv, &a
95c0: 70 70 66 73 5f 6f 70 65 72 61 74 69 6f 6e 73 2c ppfs_operations,
95d0: 20 4e 55 4c 4c 29 29 3b 0a 7d 0a 20 0a NULL));.}. .