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 6c 69 .h>.#include <li
0080: 6d 69 74 73 2e 68 3e 0a 23 69 6e 63 6c 75 64 65 mits.h>.#include
0090: 20 3c 73 74 72 69 6e 67 2e 68 3e 0a 23 69 6e 63 <string.h>.#inc
00a0: 6c 75 64 65 20 3c 73 74 64 61 72 67 2e 68 3e 0a lude <stdarg.h>.
00b0: 23 69 6e 63 6c 75 64 65 20 3c 73 74 64 6c 69 62 #include <stdlib
00c0: 2e 68 3e 0a 23 69 6e 63 6c 75 64 65 20 3c 75 6e .h>.#include <un
00d0: 69 73 74 64 2e 68 3e 0a 23 69 6e 63 6c 75 64 65 istd.h>.#include
00e0: 20 3c 65 72 72 6e 6f 2e 68 3e 0a 23 69 6e 63 6c <errno.h>.#incl
00f0: 75 64 65 20 3c 66 63 6e 74 6c 2e 68 3e 0a 23 69 ude <fcntl.h>.#i
0100: 6e 63 6c 75 64 65 20 3c 73 74 64 69 6f 2e 68 3e nclude <stdio.h>
0110: 0a 23 69 6e 63 6c 75 64 65 20 3c 66 75 73 65 2e .#include <fuse.
0120: 68 3e 0a 23 69 6e 63 6c 75 64 65 20 3c 70 77 64 h>.#include <pwd
0130: 2e 68 3e 0a 23 69 6e 63 6c 75 64 65 20 3c 74 63 .h>.#include <tc
0140: 6c 2e 68 3e 0a 0a 2f 2a 0a 20 2a 20 44 65 66 61 l.h>../*. * Defa
0150: 75 6c 74 20 63 61 63 68 65 20 64 69 72 65 63 74 ult cache direct
0160: 6f 72 79 0a 20 2a 2f 0a 23 69 66 6e 64 65 66 20 ory. */.#ifndef
0170: 41 50 50 46 53 5f 43 41 43 48 45 44 49 52 0a 23 APPFS_CACHEDIR.#
0180: 64 65 66 69 6e 65 20 41 50 50 46 53 5f 43 41 43 define APPFS_CAC
0190: 48 45 44 49 52 20 22 2f 76 61 72 2f 63 61 63 68 HEDIR "/var/cach
01a0: 65 2f 61 70 70 66 73 22 0a 23 65 6e 64 69 66 0a e/appfs".#endif.
01b0: 0a 2f 2a 20 44 65 62 75 67 67 69 6e 67 20 6d 61 ./* Debugging ma
01c0: 63 72 6f 73 20 2a 2f 0a 23 69 66 64 65 66 20 44 cros */.#ifdef D
01d0: 45 42 55 47 0a 69 6e 74 20 61 70 70 66 73 5f 64 EBUG.int appfs_d
01e0: 65 62 75 67 5f 66 64 20 3d 20 53 54 44 45 52 52 ebug_fd = STDERR
01f0: 5f 46 49 4c 45 4e 4f 3b 0a 23 64 65 66 69 6e 65 _FILENO;.#define
0200: 20 41 50 50 46 53 5f 44 45 42 55 47 28 78 2e 2e APPFS_DEBUG(x..
0210: 2e 29 20 7b 20 5c 0a 09 63 68 61 72 20 62 75 66 .) { \..char buf
0220: 5b 38 31 39 32 5d 3b 20 5c 0a 09 69 6e 74 20 62 [8192]; \..int b
0230: 75 66 6f 66 66 20 3d 20 30 3b 20 5c 0a 09 69 66 ufoff = 0; \..if
0240: 20 28 61 70 70 66 73 5f 64 65 62 75 67 5f 66 64 (appfs_debug_fd
0250: 20 3d 3d 20 2d 31 29 20 7b 20 5c 0a 09 09 61 70 == -1) { \...ap
0260: 70 66 73 5f 64 65 62 75 67 5f 66 64 20 3d 20 6f pfs_debug_fd = o
0270: 70 65 6e 28 22 2f 74 6d 70 2f 61 70 70 66 73 64 pen("/tmp/appfsd
0280: 2e 6c 6f 67 22 2c 20 4f 5f 57 52 4f 4e 4c 59 20 .log", O_WRONLY
0290: 7c 20 4f 5f 41 50 50 45 4e 44 20 7c 20 4f 5f 43 | O_APPEND | O_C
02a0: 52 45 41 54 2c 20 30 36 30 30 29 3b 20 5c 0a 09 REAT, 0600); \..
02b0: 7d 3b 20 5c 0a 09 62 75 66 6f 66 66 20 3d 20 73 }; \..bufoff = s
02c0: 6e 70 72 69 6e 74 66 28 62 75 66 2c 20 73 69 7a nprintf(buf, siz
02d0: 65 6f 66 28 62 75 66 29 2c 20 22 5b 64 65 62 75 eof(buf), "[debu
02e0: 67 5d 20 5b 74 3d 25 6c 6c 78 5d 20 25 73 3a 25 g] [t=%llx] %s:%
02f0: 69 3a 25 73 3a 20 22 2c 20 28 75 6e 73 69 67 6e i:%s: ", (unsign
0300: 65 64 20 6c 6f 6e 67 20 6c 6f 6e 67 29 20 70 74 ed long long) pt
0310: 68 72 65 61 64 5f 73 65 6c 66 28 29 2c 20 5f 5f hread_self(), __
0320: 46 49 4c 45 5f 5f 2c 20 5f 5f 4c 49 4e 45 5f 5f FILE__, __LINE__
0330: 2c 20 5f 5f 66 75 6e 63 5f 5f 29 3b 20 5c 0a 09 , __func__); \..
0340: 69 66 20 28 62 75 66 6f 66 66 20 3c 20 73 69 7a if (bufoff < siz
0350: 65 6f 66 28 62 75 66 29 29 20 7b 20 5c 0a 09 09 eof(buf)) { \...
0360: 62 75 66 6f 66 66 20 2b 3d 20 73 6e 70 72 69 6e bufoff += snprin
0370: 74 66 28 62 75 66 20 2b 20 62 75 66 6f 66 66 2c tf(buf + bufoff,
0380: 20 73 69 7a 65 6f 66 28 62 75 66 29 20 2d 20 62 sizeof(buf) - b
0390: 75 66 6f 66 66 2c 20 78 29 3b 20 5c 0a 09 7d 3b ufoff, x); \..};
03a0: 20 5c 0a 09 69 66 20 28 62 75 66 6f 66 66 20 3c \..if (bufoff <
03b0: 20 73 69 7a 65 6f 66 28 62 75 66 29 29 20 7b 20 sizeof(buf)) {
03c0: 5c 0a 09 09 62 75 66 6f 66 66 20 2b 3d 20 73 6e \...bufoff += sn
03d0: 70 72 69 6e 74 66 28 62 75 66 20 2b 20 62 75 66 printf(buf + buf
03e0: 6f 66 66 2c 20 73 69 7a 65 6f 66 28 62 75 66 29 off, sizeof(buf)
03f0: 20 2d 20 62 75 66 6f 66 66 2c 20 22 5c 6e 22 29 - bufoff, "\n")
0400: 3b 5c 0a 09 7d 20 5c 0a 09 69 66 20 28 62 75 66 ;\..} \..if (buf
0410: 6f 66 66 20 3e 20 73 69 7a 65 6f 66 28 62 75 66 off > sizeof(buf
0420: 29 29 20 7b 20 5c 0a 09 09 62 75 66 6f 66 66 20 )) { \...bufoff
0430: 3d 20 73 69 7a 65 6f 66 28 62 75 66 29 3b 20 5c = sizeof(buf); \
0440: 0a 09 7d 3b 20 5c 0a 09 77 72 69 74 65 28 61 70 ..}; \..write(ap
0450: 70 66 73 5f 64 65 62 75 67 5f 66 64 2c 20 62 75 pfs_debug_fd, bu
0460: 66 2c 20 62 75 66 6f 66 66 29 3b 20 5c 0a 7d 0a f, bufoff); \.}.
0470: 23 65 6c 73 65 0a 23 64 65 66 69 6e 65 20 41 50 #else.#define AP
0480: 50 46 53 5f 44 45 42 55 47 28 78 2e 2e 2e 29 20 PFS_DEBUG(x...)
0490: 2f 2a 2a 2f 0a 23 65 6e 64 69 66 0a 0a 2f 2a 0a /**/.#endif../*.
04a0: 20 2a 20 53 48 41 31 20 54 63 6c 20 50 61 63 6b * SHA1 Tcl Pack
04b0: 61 67 65 20 69 6e 69 74 69 61 6c 69 7a 65 72 2c age initializer,
04c0: 20 66 72 6f 6d 20 73 68 61 31 2e 6f 0a 20 2a 2f from sha1.o. */
04d0: 0a 69 6e 74 20 53 68 61 31 5f 49 6e 69 74 28 54 .int Sha1_Init(T
04e0: 63 6c 5f 49 6e 74 65 72 70 20 2a 69 6e 74 65 72 cl_Interp *inter
04f0: 70 29 3b 0a 0a 2f 2a 0a 20 2a 20 54 68 72 65 61 p);../*. * Threa
0500: 64 20 53 70 65 63 69 66 69 63 20 44 61 74 61 20 d Specific Data
0510: 28 54 53 44 29 20 66 6f 72 20 54 63 6c 20 49 6e (TSD) for Tcl In
0520: 74 65 72 70 72 65 74 65 72 20 66 6f 72 20 74 68 terpreter for th
0530: 65 20 63 75 72 72 65 6e 74 20 74 68 72 65 61 64 e current thread
0540: 0a 20 2a 2f 0a 73 74 61 74 69 63 20 70 74 68 72 . */.static pthr
0550: 65 61 64 5f 6b 65 79 5f 74 20 69 6e 74 65 72 70 ead_key_t interp
0560: 4b 65 79 3b 0a 0a 2f 2a 0a 20 2a 20 47 6c 6f 62 Key;../*. * Glob
0570: 61 6c 20 76 61 72 69 61 62 6c 65 73 2c 20 6e 65 al variables, ne
0580: 65 64 65 64 20 66 6f 72 20 61 6c 6c 20 74 68 72 eded for all thr
0590: 65 61 64 73 20 62 75 74 20 6f 6e 6c 79 20 69 6e eads but only in
05a0: 69 74 69 61 6c 69 7a 65 64 20 62 65 66 6f 72 65 itialized before
05b0: 20 61 6e 79 0a 20 2a 20 46 55 53 45 20 74 68 72 any. * FUSE thr
05c0: 65 61 64 73 20 61 72 65 20 63 72 65 61 74 65 64 eads are created
05d0: 0a 20 2a 2f 0a 63 6f 6e 73 74 20 63 68 61 72 20 . */.const char
05e0: 2a 61 70 70 66 73 5f 63 61 63 68 65 64 69 72 3b *appfs_cachedir;
05f0: 0a 74 69 6d 65 5f 74 20 61 70 70 66 73 5f 62 6f .time_t appfs_bo
0600: 6f 74 74 69 6d 65 3b 0a 69 6e 74 20 61 70 70 66 ottime;.int appf
0610: 73 5f 66 75 73 65 5f 73 74 61 72 74 65 64 20 3d s_fuse_started =
0620: 20 30 3b 0a 0a 2f 2a 0a 20 2a 20 47 6c 6f 62 61 0;../*. * Globa
0630: 6c 20 76 61 72 69 61 62 6c 65 73 20 66 6f 72 20 l variables for
0640: 41 70 70 46 53 20 63 61 63 68 69 6e 67 0a 20 2a AppFS caching. *
0650: 2f 0a 70 74 68 72 65 61 64 5f 6d 75 74 65 78 5f /.pthread_mutex_
0660: 74 20 61 70 70 66 73 5f 70 61 74 68 5f 69 6e 66 t appfs_path_inf
0670: 6f 5f 63 61 63 68 65 5f 6d 75 74 65 78 20 3d 20 o_cache_mutex =
0680: 50 54 48 52 45 41 44 5f 4d 55 54 45 58 5f 49 4e PTHREAD_MUTEX_IN
0690: 49 54 49 41 4c 49 5a 45 52 3b 0a 69 6e 74 20 61 ITIALIZER;.int a
06a0: 70 70 66 73 5f 70 61 74 68 5f 69 6e 66 6f 5f 63 ppfs_path_info_c
06b0: 61 63 68 65 5f 73 69 7a 65 20 3d 20 38 32 30 39 ache_size = 8209
06c0: 3b 0a 73 74 72 75 63 74 20 61 70 70 66 73 5f 70 ;.struct appfs_p
06d0: 61 74 68 69 6e 66 6f 20 2a 61 70 70 66 73 5f 70 athinfo *appfs_p
06e0: 61 74 68 5f 69 6e 66 6f 5f 63 61 63 68 65 20 3d ath_info_cache =
06f0: 20 4e 55 4c 4c 3b 0a 0a 23 69 66 6e 64 65 66 20 NULL;..#ifndef
0700: 54 43 4c 5f 54 48 52 45 41 44 53 0a 2f 2a 0a 20 TCL_THREADS./*.
0710: 2a 20 48 61 6e 64 6c 65 20 75 6e 74 68 72 65 61 * Handle unthrea
0720: 64 65 64 20 54 63 6c 0a 20 2a 2f 0a 70 74 68 72 ded Tcl. */.pthr
0730: 65 61 64 5f 6d 75 74 65 78 5f 74 20 61 70 70 66 ead_mutex_t appf
0740: 73 5f 74 63 6c 5f 62 69 67 5f 67 6c 6f 62 61 6c s_tcl_big_global
0750: 5f 6c 6f 63 6b 20 3d 20 50 54 48 52 45 41 44 5f _lock = PTHREAD_
0760: 4d 55 54 45 58 5f 49 4e 49 54 49 41 4c 49 5a 45 MUTEX_INITIALIZE
0770: 52 3b 0a 23 64 65 66 69 6e 65 20 61 70 70 66 73 R;.#define appfs
0780: 5f 63 61 6c 6c 5f 6c 69 62 74 63 6c 5f 65 6e 74 _call_libtcl_ent
0790: 65 72 20 70 74 68 72 65 61 64 5f 6d 75 74 65 78 er pthread_mutex
07a0: 5f 6c 6f 63 6b 28 26 61 70 70 66 73 5f 74 63 6c _lock(&appfs_tcl
07b0: 5f 62 69 67 5f 67 6c 6f 62 61 6c 5f 6c 6f 63 6b _big_global_lock
07c0: 29 3b 0a 23 64 65 66 69 6e 65 20 61 70 70 66 73 );.#define appfs
07d0: 5f 63 61 6c 6c 5f 6c 69 62 74 63 6c 5f 65 78 69 _call_libtcl_exi
07e0: 74 20 70 74 68 72 65 61 64 5f 6d 75 74 65 78 5f t pthread_mutex_
07f0: 75 6e 6c 6f 63 6b 28 26 61 70 70 66 73 5f 74 63 unlock(&appfs_tc
0800: 6c 5f 62 69 67 5f 67 6c 6f 62 61 6c 5f 6c 6f 63 l_big_global_loc
0810: 6b 29 3b 0a 23 65 6c 73 65 0a 23 77 61 72 6e 69 k);.#else.#warni
0820: 6e 67 20 55 73 69 6e 67 20 61 20 54 68 72 65 61 ng Using a Threa
0830: 64 65 64 20 54 63 6c 20 69 6e 74 65 72 70 72 65 ded Tcl interpre
0840: 74 65 72 20 6d 61 79 20 63 61 75 73 65 20 6d 65 ter may cause me
0850: 6d 6f 72 79 20 6c 65 61 6b 73 0a 23 64 65 66 69 mory leaks.#defi
0860: 6e 65 20 61 70 70 66 73 5f 63 61 6c 6c 5f 6c 69 ne appfs_call_li
0870: 62 74 63 6c 5f 65 6e 74 65 72 20 2f 2a 2a 2f 0a btcl_enter /**/.
0880: 23 64 65 66 69 6e 65 20 61 70 70 66 73 5f 63 61 #define appfs_ca
0890: 6c 6c 5f 6c 69 62 74 63 6c 5f 65 78 69 74 20 2f ll_libtcl_exit /
08a0: 2a 2a 2f 0a 23 65 6e 64 69 66 0a 23 64 65 66 69 **/.#endif.#defi
08b0: 6e 65 20 61 70 70 66 73 5f 63 61 6c 6c 5f 6c 69 ne appfs_call_li
08c0: 62 74 63 6c 28 78 2e 2e 2e 29 20 61 70 70 66 73 btcl(x...) appfs
08d0: 5f 63 61 6c 6c 5f 6c 69 62 74 63 6c 5f 65 6e 74 _call_libtcl_ent
08e0: 65 72 20 78 20 61 70 70 66 73 5f 63 61 6c 6c 5f er x appfs_call_
08f0: 6c 69 62 74 63 6c 5f 65 78 69 74 0a 0a 2f 2a 0a libtcl_exit../*.
0900: 20 2a 20 47 6c 6f 62 61 6c 20 76 61 72 69 61 62 * Global variab
0910: 6c 65 73 20 66 6f 72 20 41 70 70 46 53 20 54 63 les for AppFS Tc
0920: 6c 20 49 6e 74 65 72 70 72 65 74 65 72 20 72 65 l Interpreter re
0930: 73 74 61 72 74 69 6e 67 0a 20 2a 2f 0a 69 6e 74 starting. */.int
0940: 20 69 6e 74 65 72 70 5f 72 65 73 65 74 5f 6b 65 interp_reset_ke
0950: 79 20 3d 20 30 3b 0a 0a 2f 2a 0a 20 2a 20 41 70 y = 0;../*. * Ap
0960: 70 46 53 20 50 61 74 68 20 54 79 70 65 3a 20 20 pFS Path Type:
0970: 44 65 73 63 72 69 62 65 73 20 74 68 65 20 74 79 Describes the ty
0980: 70 65 20 6f 66 20 70 61 74 68 20 61 20 67 69 76 pe of path a giv
0990: 65 6e 20 66 69 6c 65 20 69 73 0a 20 2a 2f 0a 74 en file is. */.t
09a0: 79 70 65 64 65 66 20 65 6e 75 6d 20 7b 0a 09 41 ypedef enum {..A
09b0: 50 50 46 53 5f 50 41 54 48 54 59 50 45 5f 49 4e PPFS_PATHTYPE_IN
09c0: 56 41 4c 49 44 2c 0a 09 41 50 50 46 53 5f 50 41 VALID,..APPFS_PA
09d0: 54 48 54 59 50 45 5f 44 4f 45 53 5f 4e 4f 54 5f THTYPE_DOES_NOT_
09e0: 45 58 49 53 54 2c 0a 09 41 50 50 46 53 5f 50 41 EXIST,..APPFS_PA
09f0: 54 48 54 59 50 45 5f 46 49 4c 45 2c 0a 09 41 50 THTYPE_FILE,..AP
0a00: 50 46 53 5f 50 41 54 48 54 59 50 45 5f 44 49 52 PFS_PATHTYPE_DIR
0a10: 45 43 54 4f 52 59 2c 0a 09 41 50 50 46 53 5f 50 ECTORY,..APPFS_P
0a20: 41 54 48 54 59 50 45 5f 53 59 4d 4c 49 4e 4b 2c ATHTYPE_SYMLINK,
0a30: 0a 09 41 50 50 46 53 5f 50 41 54 48 54 59 50 45 ..APPFS_PATHTYPE
0a40: 5f 53 4f 43 4b 45 54 2c 0a 09 41 50 50 46 53 5f _SOCKET,..APPFS_
0a50: 50 41 54 48 54 59 50 45 5f 46 49 46 4f 2c 0a 7d PATHTYPE_FIFO,.}
0a60: 20 61 70 70 66 73 5f 70 61 74 68 74 79 70 65 5f appfs_pathtype_
0a70: 74 3b 0a 0a 2f 2a 0a 20 2a 20 41 70 70 46 53 20 t;../*. * AppFS
0a80: 50 61 74 68 20 49 6e 66 6f 72 6d 61 74 69 6f 6e Path Information
0a90: 3a 0a 20 2a 20 20 20 20 20 20 20 20 20 43 6f 6d :. * Com
0aa0: 70 6c 65 74 65 6c 79 20 64 65 73 63 72 69 62 65 pletely describe
0ab0: 73 20 61 20 73 70 65 63 69 66 69 63 20 70 61 74 s a specific pat
0ac0: 68 2c 20 68 6f 77 20 69 74 20 73 68 6f 75 6c 64 h, how it should
0ad0: 20 62 65 20 72 65 74 75 72 6e 65 64 20 74 6f 0a be returned to.
0ae0: 20 2a 20 20 20 20 20 20 20 20 20 74 6f 20 74 68 * to th
0af0: 65 20 6b 65 72 6e 65 6c 0a 20 2a 2f 0a 73 74 72 e kernel. */.str
0b00: 75 63 74 20 61 70 70 66 73 5f 70 61 74 68 69 6e uct appfs_pathin
0b10: 66 6f 20 7b 0a 09 61 70 70 66 73 5f 70 61 74 68 fo {..appfs_path
0b20: 74 79 70 65 5f 74 20 74 79 70 65 3b 0a 09 74 69 type_t type;..ti
0b30: 6d 65 5f 74 20 74 69 6d 65 3b 0a 09 63 68 61 72 me_t time;..char
0b40: 20 68 6f 73 74 6e 61 6d 65 5b 32 35 36 5d 3b 0a hostname[256];.
0b50: 09 69 6e 74 20 70 61 63 6b 61 67 65 64 3b 0a 09 .int packaged;..
0b60: 75 6e 73 69 67 6e 65 64 20 6c 6f 6e 67 20 6c 6f unsigned long lo
0b70: 6e 67 20 69 6e 6f 64 65 3b 0a 09 75 6e 69 6f 6e ng inode;..union
0b80: 20 7b 0a 09 09 73 74 72 75 63 74 20 7b 0a 09 09 {...struct {...
0b90: 09 69 6e 74 20 63 68 69 6c 64 63 6f 75 6e 74 3b .int childcount;
0ba0: 0a 09 09 7d 20 64 69 72 3b 0a 09 09 73 74 72 75 ...} dir;...stru
0bb0: 63 74 20 7b 0a 09 09 09 69 6e 74 20 65 78 65 63 ct {....int exec
0bc0: 75 74 61 62 6c 65 3b 0a 09 09 09 6f 66 66 5f 74 utable;....off_t
0bd0: 20 73 69 7a 65 3b 0a 09 09 7d 20 66 69 6c 65 3b size;...} file;
0be0: 0a 09 09 73 74 72 75 63 74 20 7b 0a 09 09 09 6f ...struct {....o
0bf0: 66 66 5f 74 20 73 69 7a 65 3b 0a 09 09 09 63 68 ff_t size;....ch
0c00: 61 72 20 73 6f 75 72 63 65 5b 32 35 36 5d 3b 0a ar source[256];.
0c10: 09 09 7d 20 73 79 6d 6c 69 6e 6b 3b 0a 09 7d 20 ..} symlink;..}
0c20: 74 79 70 65 69 6e 66 6f 3b 0a 0a 09 2f 2a 20 41 typeinfo;.../* A
0c30: 74 74 72 69 62 75 74 65 73 20 75 73 65 64 20 6f ttributes used o
0c40: 6e 6c 79 20 66 6f 72 20 63 61 63 68 69 6e 67 20 nly for caching
0c50: 65 6e 74 72 69 65 73 20 2a 2f 0a 09 63 68 61 72 entries */..char
0c60: 20 2a 5f 63 61 63 68 65 5f 70 61 74 68 3b 0a 09 *_cache_path;..
0c70: 75 69 64 5f 74 20 5f 63 61 63 68 65 5f 75 69 64 uid_t _cache_uid
0c80: 3b 0a 7d 3b 0a 0a 2f 2a 0a 20 2a 20 43 72 65 61 ;.};../*. * Crea
0c90: 74 65 20 61 20 6e 65 77 20 54 63 6c 20 69 6e 74 te a new Tcl int
0ca0: 65 72 70 72 65 74 65 72 20 61 6e 64 20 63 6f 6d erpreter and com
0cb0: 70 6c 65 74 65 6c 79 20 69 6e 69 74 69 61 6c 69 pletely initiali
0cc0: 7a 65 20 69 74 0a 20 2a 2f 0a 73 74 61 74 69 63 ze it. */.static
0cd0: 20 54 63 6c 5f 49 6e 74 65 72 70 20 2a 61 70 70 Tcl_Interp *app
0ce0: 66 73 5f 63 72 65 61 74 65 5f 54 63 6c 49 6e 74 fs_create_TclInt
0cf0: 65 72 70 28 63 68 61 72 20 2a 2a 65 72 72 6f 72 erp(char **error
0d00: 5f 73 74 72 69 6e 67 29 20 7b 0a 09 54 63 6c 5f _string) {..Tcl_
0d10: 49 6e 74 65 72 70 20 2a 69 6e 74 65 72 70 3b 0a Interp *interp;.
0d20: 09 69 6e 74 20 74 63 6c 5f 72 65 74 3b 0a 09 63 .int tcl_ret;..c
0d30: 6f 6e 73 74 20 63 68 61 72 20 2a 74 63 6c 5f 73 onst char *tcl_s
0d40: 65 74 76 61 72 5f 72 65 74 3b 0a 0a 09 41 50 50 etvar_ret;...APP
0d50: 46 53 5f 44 45 42 55 47 28 22 43 72 65 61 74 69 FS_DEBUG("Creati
0d60: 6e 67 20 6e 65 77 20 54 63 6c 20 69 6e 74 65 72 ng new Tcl inter
0d70: 70 72 65 74 65 72 20 66 6f 72 20 54 49 44 20 3d preter for TID =
0d80: 20 30 78 25 6c 6c 78 22 2c 20 28 75 6e 73 69 67 0x%llx", (unsig
0d90: 6e 65 64 20 6c 6f 6e 67 20 6c 6f 6e 67 29 20 70 ned long long) p
0da0: 74 68 72 65 61 64 5f 73 65 6c 66 28 29 29 3b 0a thread_self());.
0db0: 0a 09 61 70 70 66 73 5f 63 61 6c 6c 5f 6c 69 62 ..appfs_call_lib
0dc0: 74 63 6c 28 0a 09 09 69 6e 74 65 72 70 20 3d 20 tcl(...interp =
0dd0: 54 63 6c 5f 43 72 65 61 74 65 49 6e 74 65 72 70 Tcl_CreateInterp
0de0: 28 29 3b 0a 09 29 0a 09 69 66 20 28 69 6e 74 65 ();..)..if (inte
0df0: 72 70 20 3d 3d 20 4e 55 4c 4c 29 20 7b 0a 09 09 rp == NULL) {...
0e00: 66 70 72 69 6e 74 66 28 73 74 64 65 72 72 2c 20 fprintf(stderr,
0e10: 22 55 6e 61 62 6c 65 20 74 6f 20 63 72 65 61 74 "Unable to creat
0e20: 65 20 54 63 6c 20 49 6e 74 65 72 70 72 65 74 65 e Tcl Interprete
0e30: 72 2e 20 20 41 62 6f 72 74 69 6e 67 2e 5c 6e 22 r. Aborting.\n"
0e40: 29 3b 0a 0a 09 09 69 66 20 28 65 72 72 6f 72 5f );....if (error_
0e50: 73 74 72 69 6e 67 29 20 7b 0a 09 09 09 2a 65 72 string) {....*er
0e60: 72 6f 72 5f 73 74 72 69 6e 67 20 3d 20 73 74 72 ror_string = str
0e70: 64 75 70 28 22 55 6e 61 62 6c 65 20 74 6f 20 63 dup("Unable to c
0e80: 72 65 61 74 65 20 54 63 6c 20 69 6e 74 65 72 70 reate Tcl interp
0e90: 72 65 74 65 72 2e 22 29 3b 0a 09 09 7d 0a 0a 09 reter.");...}...
0ea0: 09 72 65 74 75 72 6e 28 4e 55 4c 4c 29 3b 0a 09 .return(NULL);..
0eb0: 7d 0a 0a 09 61 70 70 66 73 5f 63 61 6c 6c 5f 6c }...appfs_call_l
0ec0: 69 62 74 63 6c 28 54 63 6c 5f 50 72 65 73 65 72 ibtcl(Tcl_Preser
0ed0: 76 65 28 69 6e 74 65 72 70 29 3b 29 0a 0a 09 61 ve(interp);)...a
0ee0: 70 70 66 73 5f 63 61 6c 6c 5f 6c 69 62 74 63 6c ppfs_call_libtcl
0ef0: 28 0a 09 09 74 63 6c 5f 72 65 74 20 3d 20 54 63 (...tcl_ret = Tc
0f00: 6c 5f 49 6e 69 74 28 69 6e 74 65 72 70 29 3b 0a l_Init(interp);.
0f10: 09 29 0a 09 69 66 20 28 74 63 6c 5f 72 65 74 20 .)..if (tcl_ret
0f20: 21 3d 20 54 43 4c 5f 4f 4b 29 20 7b 0a 09 09 66 != TCL_OK) {...f
0f30: 70 72 69 6e 74 66 28 73 74 64 65 72 72 2c 20 22 printf(stderr, "
0f40: 55 6e 61 62 6c 65 20 74 6f 20 69 6e 69 74 69 61 Unable to initia
0f50: 6c 69 7a 65 20 54 63 6c 2e 20 20 41 62 6f 72 74 lize Tcl. Abort
0f60: 69 6e 67 2e 5c 6e 22 29 3b 0a 09 09 61 70 70 66 ing.\n");...appf
0f70: 73 5f 63 61 6c 6c 5f 6c 69 62 74 63 6c 28 0a 09 s_call_libtcl(..
0f80: 09 09 66 70 72 69 6e 74 66 28 73 74 64 65 72 72 ..fprintf(stderr
0f90: 2c 20 22 54 63 6c 20 45 72 72 6f 72 20 69 73 3a , "Tcl Error is:
0fa0: 20 25 73 5c 6e 22 2c 20 54 63 6c 5f 47 65 74 53 %s\n", Tcl_GetS
0fb0: 74 72 69 6e 67 52 65 73 75 6c 74 28 69 6e 74 65 tringResult(inte
0fc0: 72 70 29 29 3b 0a 09 09 29 0a 0a 09 09 69 66 20 rp));...)....if
0fd0: 28 65 72 72 6f 72 5f 73 74 72 69 6e 67 29 20 7b (error_string) {
0fe0: 0a 09 09 09 61 70 70 66 73 5f 63 61 6c 6c 5f 6c ....appfs_call_l
0ff0: 69 62 74 63 6c 28 0a 09 09 09 09 2a 65 72 72 6f ibtcl(.....*erro
1000: 72 5f 73 74 72 69 6e 67 20 3d 20 73 74 72 64 75 r_string = strdu
1010: 70 28 54 63 6c 5f 47 65 74 53 74 72 69 6e 67 52 p(Tcl_GetStringR
1020: 65 73 75 6c 74 28 69 6e 74 65 72 70 29 29 3b 0a esult(interp));.
1030: 09 09 09 29 0a 09 09 7d 0a 0a 09 09 61 70 70 66 ...)...}....appf
1040: 73 5f 63 61 6c 6c 5f 6c 69 62 74 63 6c 28 54 63 s_call_libtcl(Tc
1050: 6c 5f 52 65 6c 65 61 73 65 28 69 6e 74 65 72 70 l_Release(interp
1060: 29 3b 29 0a 0a 09 09 41 50 50 46 53 5f 44 45 42 );)....APPFS_DEB
1070: 55 47 28 22 54 65 72 6d 69 6e 61 74 69 6e 67 20 UG("Terminating
1080: 54 63 6c 20 69 6e 74 65 72 70 72 65 74 65 72 2e Tcl interpreter.
1090: 22 29 3b 0a 0a 09 09 61 70 70 66 73 5f 63 61 6c ");....appfs_cal
10a0: 6c 5f 6c 69 62 74 63 6c 28 54 63 6c 5f 44 65 6c l_libtcl(Tcl_Del
10b0: 65 74 65 49 6e 74 65 72 70 28 69 6e 74 65 72 70 eteInterp(interp
10c0: 29 3b 29 0a 0a 09 09 72 65 74 75 72 6e 28 4e 55 );)....return(NU
10d0: 4c 4c 29 3b 0a 09 7d 0a 0a 09 61 70 70 66 73 5f LL);..}...appfs_
10e0: 63 61 6c 6c 5f 6c 69 62 74 63 6c 28 0a 09 09 74 call_libtcl(...t
10f0: 63 6c 5f 72 65 74 20 3d 20 54 63 6c 5f 45 76 61 cl_ret = Tcl_Eva
1100: 6c 28 69 6e 74 65 72 70 2c 20 22 70 61 63 6b 61 l(interp, "packa
1110: 67 65 20 69 66 6e 65 65 64 65 64 20 73 68 61 31 ge ifneeded sha1
1120: 20 31 2e 30 20 5b 6c 69 73 74 20 6c 6f 61 64 20 1.0 [list load
1130: 7b 7d 20 73 68 61 31 5d 22 29 3b 0a 09 29 0a 09 {} sha1]");..)..
1140: 69 66 20 28 74 63 6c 5f 72 65 74 20 21 3d 20 54 if (tcl_ret != T
1150: 43 4c 5f 4f 4b 29 20 7b 0a 09 09 66 70 72 69 6e CL_OK) {...fprin
1160: 74 66 28 73 74 64 65 72 72 2c 20 22 55 6e 61 62 tf(stderr, "Unab
1170: 6c 65 20 74 6f 20 69 6e 69 74 69 61 6c 69 7a 65 le to initialize
1180: 20 54 63 6c 20 53 48 41 31 2e 20 20 41 62 6f 72 Tcl SHA1. Abor
1190: 74 69 6e 67 2e 5c 6e 22 29 3b 0a 09 09 61 70 70 ting.\n");...app
11a0: 66 73 5f 63 61 6c 6c 5f 6c 69 62 74 63 6c 28 0a fs_call_libtcl(.
11b0: 09 09 09 66 70 72 69 6e 74 66 28 73 74 64 65 72 ...fprintf(stder
11c0: 72 2c 20 22 54 63 6c 20 45 72 72 6f 72 20 69 73 r, "Tcl Error is
11d0: 3a 20 25 73 5c 6e 22 2c 20 54 63 6c 5f 47 65 74 : %s\n", Tcl_Get
11e0: 53 74 72 69 6e 67 52 65 73 75 6c 74 28 69 6e 74 StringResult(int
11f0: 65 72 70 29 29 3b 0a 09 09 29 0a 0a 09 09 69 66 erp));...)....if
1200: 20 28 65 72 72 6f 72 5f 73 74 72 69 6e 67 29 20 (error_string)
1210: 7b 0a 09 09 09 61 70 70 66 73 5f 63 61 6c 6c 5f {....appfs_call_
1220: 6c 69 62 74 63 6c 28 0a 09 09 09 09 2a 65 72 72 libtcl(.....*err
1230: 6f 72 5f 73 74 72 69 6e 67 20 3d 20 73 74 72 64 or_string = strd
1240: 75 70 28 54 63 6c 5f 47 65 74 53 74 72 69 6e 67 up(Tcl_GetString
1250: 52 65 73 75 6c 74 28 69 6e 74 65 72 70 29 29 3b Result(interp));
1260: 0a 09 09 09 29 0a 09 09 7d 0a 0a 09 09 61 70 70 ....)...}....app
1270: 66 73 5f 63 61 6c 6c 5f 6c 69 62 74 63 6c 28 54 fs_call_libtcl(T
1280: 63 6c 5f 52 65 6c 65 61 73 65 28 69 6e 74 65 72 cl_Release(inter
1290: 70 29 3b 29 0a 0a 09 09 41 50 50 46 53 5f 44 45 p);)....APPFS_DE
12a0: 42 55 47 28 22 54 65 72 6d 69 6e 61 74 69 6e 67 BUG("Terminating
12b0: 20 54 63 6c 20 69 6e 74 65 72 70 72 65 74 65 72 Tcl interpreter
12c0: 2e 22 29 3b 0a 0a 09 09 61 70 70 66 73 5f 63 61 .");....appfs_ca
12d0: 6c 6c 5f 6c 69 62 74 63 6c 28 54 63 6c 5f 44 65 ll_libtcl(Tcl_De
12e0: 6c 65 74 65 49 6e 74 65 72 70 28 69 6e 74 65 72 leteInterp(inter
12f0: 70 29 3b 29 0a 0a 09 09 72 65 74 75 72 6e 28 4e p);)....return(N
1300: 55 4c 4c 29 3b 0a 09 7d 0a 0a 09 61 70 70 66 73 ULL);..}...appfs
1310: 5f 63 61 6c 6c 5f 6c 69 62 74 63 6c 28 0a 09 09 _call_libtcl(...
1320: 74 63 6c 5f 72 65 74 20 3d 20 54 63 6c 5f 45 76 tcl_ret = Tcl_Ev
1330: 61 6c 28 69 6e 74 65 72 70 2c 20 22 70 61 63 6b al(interp, "pack
1340: 61 67 65 20 69 66 6e 65 65 64 65 64 20 61 70 70 age ifneeded app
1350: 66 73 64 20 31 2e 30 20 5b 6c 69 73 74 20 6c 6f fsd 1.0 [list lo
1360: 61 64 20 7b 7d 20 61 70 70 66 73 64 5d 22 29 3b ad {} appfsd]");
1370: 0a 09 29 0a 09 69 66 20 28 74 63 6c 5f 72 65 74 ..)..if (tcl_ret
1380: 20 21 3d 20 54 43 4c 5f 4f 4b 29 20 7b 0a 09 09 != TCL_OK) {...
1390: 66 70 72 69 6e 74 66 28 73 74 64 65 72 72 2c 20 fprintf(stderr,
13a0: 22 55 6e 61 62 6c 65 20 74 6f 20 69 6e 69 74 69 "Unable to initi
13b0: 61 6c 69 7a 65 20 54 63 6c 20 41 70 70 46 53 20 alize Tcl AppFS
13c0: 50 61 63 6b 61 67 65 2e 20 20 41 62 6f 72 74 69 Package. Aborti
13d0: 6e 67 2e 5c 6e 22 29 3b 0a 09 09 61 70 70 66 73 ng.\n");...appfs
13e0: 5f 63 61 6c 6c 5f 6c 69 62 74 63 6c 28 0a 09 09 _call_libtcl(...
13f0: 09 66 70 72 69 6e 74 66 28 73 74 64 65 72 72 2c .fprintf(stderr,
1400: 20 22 54 63 6c 20 45 72 72 6f 72 20 69 73 3a 20 "Tcl Error is:
1410: 25 73 5c 6e 22 2c 20 54 63 6c 5f 47 65 74 53 74 %s\n", Tcl_GetSt
1420: 72 69 6e 67 52 65 73 75 6c 74 28 69 6e 74 65 72 ringResult(inter
1430: 70 29 29 3b 0a 09 09 29 0a 0a 09 09 69 66 20 28 p));...)....if (
1440: 65 72 72 6f 72 5f 73 74 72 69 6e 67 29 20 7b 0a error_string) {.
1450: 09 09 09 61 70 70 66 73 5f 63 61 6c 6c 5f 6c 69 ...appfs_call_li
1460: 62 74 63 6c 28 0a 09 09 09 09 2a 65 72 72 6f 72 btcl(.....*error
1470: 5f 73 74 72 69 6e 67 20 3d 20 73 74 72 64 75 70 _string = strdup
1480: 28 54 63 6c 5f 47 65 74 53 74 72 69 6e 67 52 65 (Tcl_GetStringRe
1490: 73 75 6c 74 28 69 6e 74 65 72 70 29 29 3b 0a 09 sult(interp));..
14a0: 09 09 29 0a 09 09 7d 0a 0a 09 09 61 70 70 66 73 ..)...}....appfs
14b0: 5f 63 61 6c 6c 5f 6c 69 62 74 63 6c 28 54 63 6c _call_libtcl(Tcl
14c0: 5f 52 65 6c 65 61 73 65 28 69 6e 74 65 72 70 29 _Release(interp)
14d0: 3b 29 0a 0a 09 09 41 50 50 46 53 5f 44 45 42 55 ;)....APPFS_DEBU
14e0: 47 28 22 54 65 72 6d 69 6e 61 74 69 6e 67 20 54 G("Terminating T
14f0: 63 6c 20 69 6e 74 65 72 70 72 65 74 65 72 2e 22 cl interpreter."
1500: 29 3b 0a 0a 09 09 61 70 70 66 73 5f 63 61 6c 6c );....appfs_call
1510: 5f 6c 69 62 74 63 6c 28 54 63 6c 5f 44 65 6c 65 _libtcl(Tcl_Dele
1520: 74 65 49 6e 74 65 72 70 28 69 6e 74 65 72 70 29 teInterp(interp)
1530: 3b 29 0a 0a 09 09 72 65 74 75 72 6e 28 4e 55 4c ;)....return(NUL
1540: 4c 29 3b 0a 09 7d 0a 0a 09 2f 2a 0a 09 20 2a 20 L);..}.../*.. *
1550: 4c 6f 61 64 20 22 70 6b 69 2e 74 63 6c 22 20 69 Load "pki.tcl" i
1560: 6e 20 74 68 65 20 73 61 6d 65 20 77 61 79 20 61 n the same way a
1570: 73 20 61 70 70 66 73 64 2e 74 63 6c 20 28 73 65 s appfsd.tcl (se
1580: 65 20 62 65 6c 6f 77 29 0a 09 20 2a 2f 0a 09 61 e below).. */..a
1590: 70 70 66 73 5f 63 61 6c 6c 5f 6c 69 62 74 63 6c ppfs_call_libtcl
15a0: 5f 65 6e 74 65 72 0a 09 09 74 63 6c 5f 72 65 74 _enter...tcl_ret
15b0: 20 3d 20 54 63 6c 5f 45 76 61 6c 28 69 6e 74 65 = Tcl_Eval(inte
15c0: 72 70 2c 20 22 22 0a 23 69 6e 63 6c 75 64 65 20 rp, "".#include
15d0: 22 70 6b 69 2e 74 63 6c 2e 68 22 0a 09 09 22 22 "pki.tcl.h"...""
15e0: 29 3b 0a 09 61 70 70 66 73 5f 63 61 6c 6c 5f 6c );..appfs_call_l
15f0: 69 62 74 63 6c 5f 65 78 69 74 0a 09 69 66 20 28 ibtcl_exit..if (
1600: 74 63 6c 5f 72 65 74 20 21 3d 20 54 43 4c 5f 4f tcl_ret != TCL_O
1610: 4b 29 20 7b 0a 09 09 66 70 72 69 6e 74 66 28 73 K) {...fprintf(s
1620: 74 64 65 72 72 2c 20 22 55 6e 61 62 6c 65 20 74 tderr, "Unable t
1630: 6f 20 69 6e 69 74 69 61 6c 69 7a 65 20 54 63 6c o initialize Tcl
1640: 20 50 4b 49 2e 20 20 41 62 6f 72 74 69 6e 67 2e PKI. Aborting.
1650: 5c 6e 22 29 3b 0a 09 09 61 70 70 66 73 5f 63 61 \n");...appfs_ca
1660: 6c 6c 5f 6c 69 62 74 63 6c 28 0a 09 09 09 66 70 ll_libtcl(....fp
1670: 72 69 6e 74 66 28 73 74 64 65 72 72 2c 20 22 54 rintf(stderr, "T
1680: 63 6c 20 45 72 72 6f 72 20 69 73 3a 20 25 73 5c cl Error is: %s\
1690: 6e 22 2c 20 54 63 6c 5f 47 65 74 53 74 72 69 6e n", Tcl_GetStrin
16a0: 67 52 65 73 75 6c 74 28 69 6e 74 65 72 70 29 29 gResult(interp))
16b0: 3b 0a 09 09 29 0a 0a 09 09 69 66 20 28 65 72 72 ;...)....if (err
16c0: 6f 72 5f 73 74 72 69 6e 67 29 20 7b 0a 09 09 09 or_string) {....
16d0: 61 70 70 66 73 5f 63 61 6c 6c 5f 6c 69 62 74 63 appfs_call_libtc
16e0: 6c 28 0a 09 09 09 09 2a 65 72 72 6f 72 5f 73 74 l(.....*error_st
16f0: 72 69 6e 67 20 3d 20 73 74 72 64 75 70 28 54 63 ring = strdup(Tc
1700: 6c 5f 47 65 74 53 74 72 69 6e 67 52 65 73 75 6c l_GetStringResul
1710: 74 28 69 6e 74 65 72 70 29 29 3b 0a 09 09 09 29 t(interp));....)
1720: 0a 09 09 7d 0a 0a 09 09 61 70 70 66 73 5f 63 61 ...}....appfs_ca
1730: 6c 6c 5f 6c 69 62 74 63 6c 28 54 63 6c 5f 52 65 ll_libtcl(Tcl_Re
1740: 6c 65 61 73 65 28 69 6e 74 65 72 70 29 3b 29 0a lease(interp);).
1750: 0a 09 09 41 50 50 46 53 5f 44 45 42 55 47 28 22 ...APPFS_DEBUG("
1760: 54 65 72 6d 69 6e 61 74 69 6e 67 20 54 63 6c 20 Terminating Tcl
1770: 69 6e 74 65 72 70 72 65 74 65 72 2e 22 29 3b 0a interpreter.");.
1780: 0a 09 09 61 70 70 66 73 5f 63 61 6c 6c 5f 6c 69 ...appfs_call_li
1790: 62 74 63 6c 28 54 63 6c 5f 44 65 6c 65 74 65 49 btcl(Tcl_DeleteI
17a0: 6e 74 65 72 70 28 69 6e 74 65 72 70 29 3b 29 0a nterp(interp);).
17b0: 0a 09 09 72 65 74 75 72 6e 28 4e 55 4c 4c 29 3b ...return(NULL);
17c0: 0a 09 7d 0a 0a 09 2f 2a 0a 09 20 2a 20 4c 6f 61 ..}.../*.. * Loa
17d0: 64 20 74 68 65 20 22 61 70 70 66 73 64 2e 74 63 d the "appfsd.tc
17e0: 6c 22 20 73 63 72 69 70 74 2c 20 77 68 69 63 68 l" script, which
17f0: 20 69 73 20 22 63 6f 6d 70 69 6c 65 64 22 20 69 is "compiled" i
1800: 6e 74 6f 20 61 20 43 20 68 65 61 64 65 72 0a 09 nto a C header..
1810: 20 2a 20 73 6f 20 74 68 61 74 20 69 74 20 64 6f * so that it do
1820: 65 73 20 6e 6f 74 20 6e 65 65 64 20 74 6f 20 65 es not need to e
1830: 78 69 73 74 20 6f 6e 20 74 68 65 20 66 69 6c 65 xist on the file
1840: 73 79 73 74 65 6d 20 61 6e 64 20 63 61 6e 20 62 system and can b
1850: 65 0a 09 20 2a 20 64 69 72 65 63 74 6c 79 20 65 e.. * directly e
1860: 76 61 6c 75 61 74 65 64 2e 0a 09 20 2a 2f 0a 09 valuated... */..
1870: 61 70 70 66 73 5f 63 61 6c 6c 5f 6c 69 62 74 63 appfs_call_libtc
1880: 6c 5f 65 6e 74 65 72 0a 09 09 74 63 6c 5f 72 65 l_enter...tcl_re
1890: 74 20 3d 20 54 63 6c 5f 45 76 61 6c 28 69 6e 74 t = Tcl_Eval(int
18a0: 65 72 70 2c 20 22 22 0a 23 69 6e 63 6c 75 64 65 erp, "".#include
18b0: 20 22 61 70 70 66 73 64 2e 74 63 6c 2e 68 22 0a "appfsd.tcl.h".
18c0: 09 09 22 22 29 3b 0a 09 61 70 70 66 73 5f 63 61 .."");..appfs_ca
18d0: 6c 6c 5f 6c 69 62 74 63 6c 5f 65 78 69 74 0a 09 ll_libtcl_exit..
18e0: 69 66 20 28 74 63 6c 5f 72 65 74 20 21 3d 20 54 if (tcl_ret != T
18f0: 43 4c 5f 4f 4b 29 20 7b 0a 09 09 66 70 72 69 6e CL_OK) {...fprin
1900: 74 66 28 73 74 64 65 72 72 2c 20 22 55 6e 61 62 tf(stderr, "Unab
1910: 6c 65 20 74 6f 20 69 6e 69 74 69 61 6c 69 7a 65 le to initialize
1920: 20 54 63 6c 20 41 70 70 46 53 20 73 63 72 69 70 Tcl AppFS scrip
1930: 74 2e 20 20 41 62 6f 72 74 69 6e 67 2e 5c 6e 22 t. Aborting.\n"
1940: 29 3b 0a 09 09 61 70 70 66 73 5f 63 61 6c 6c 5f );...appfs_call_
1950: 6c 69 62 74 63 6c 28 0a 09 09 09 66 70 72 69 6e libtcl(....fprin
1960: 74 66 28 73 74 64 65 72 72 2c 20 22 54 63 6c 20 tf(stderr, "Tcl
1970: 45 72 72 6f 72 20 69 73 3a 20 25 73 5c 6e 22 2c Error is: %s\n",
1980: 20 54 63 6c 5f 47 65 74 53 74 72 69 6e 67 52 65 Tcl_GetStringRe
1990: 73 75 6c 74 28 69 6e 74 65 72 70 29 29 3b 0a 09 sult(interp));..
19a0: 09 29 0a 0a 09 09 69 66 20 28 65 72 72 6f 72 5f .)....if (error_
19b0: 73 74 72 69 6e 67 29 20 7b 0a 09 09 09 61 70 70 string) {....app
19c0: 66 73 5f 63 61 6c 6c 5f 6c 69 62 74 63 6c 28 0a fs_call_libtcl(.
19d0: 09 09 09 09 2a 65 72 72 6f 72 5f 73 74 72 69 6e ....*error_strin
19e0: 67 20 3d 20 73 74 72 64 75 70 28 54 63 6c 5f 47 g = strdup(Tcl_G
19f0: 65 74 53 74 72 69 6e 67 52 65 73 75 6c 74 28 69 etStringResult(i
1a00: 6e 74 65 72 70 29 29 3b 0a 09 09 09 29 0a 09 09 nterp));....)...
1a10: 7d 0a 0a 09 09 61 70 70 66 73 5f 63 61 6c 6c 5f }....appfs_call_
1a20: 6c 69 62 74 63 6c 28 54 63 6c 5f 52 65 6c 65 61 libtcl(Tcl_Relea
1a30: 73 65 28 69 6e 74 65 72 70 29 3b 29 0a 0a 09 09 se(interp);)....
1a40: 41 50 50 46 53 5f 44 45 42 55 47 28 22 54 65 72 APPFS_DEBUG("Ter
1a50: 6d 69 6e 61 74 69 6e 67 20 54 63 6c 20 69 6e 74 minating Tcl int
1a60: 65 72 70 72 65 74 65 72 2e 22 29 3b 0a 0a 09 09 erpreter.");....
1a70: 61 70 70 66 73 5f 63 61 6c 6c 5f 6c 69 62 74 63 appfs_call_libtc
1a80: 6c 28 54 63 6c 5f 44 65 6c 65 74 65 49 6e 74 65 l(Tcl_DeleteInte
1a90: 72 70 28 69 6e 74 65 72 70 29 3b 29 0a 0a 09 09 rp(interp);)....
1aa0: 72 65 74 75 72 6e 28 4e 55 4c 4c 29 3b 0a 09 7d return(NULL);..}
1ab0: 0a 0a 09 2f 2a 0a 09 20 2a 20 53 65 74 20 67 6c .../*.. * Set gl
1ac0: 6f 62 61 6c 20 76 61 72 69 61 62 6c 65 73 20 66 obal variables f
1ad0: 72 6f 6d 20 43 20 74 6f 20 54 63 6c 0a 09 20 2a rom C to Tcl.. *
1ae0: 2f 0a 09 61 70 70 66 73 5f 63 61 6c 6c 5f 6c 69 /..appfs_call_li
1af0: 62 74 63 6c 28 0a 09 09 74 63 6c 5f 73 65 74 76 btcl(...tcl_setv
1b00: 61 72 5f 72 65 74 20 3d 20 54 63 6c 5f 53 65 74 ar_ret = Tcl_Set
1b10: 56 61 72 28 69 6e 74 65 72 70 2c 20 22 3a 3a 61 Var(interp, "::a
1b20: 70 70 66 73 3a 3a 63 61 63 68 65 64 69 72 22 2c ppfs::cachedir",
1b30: 20 61 70 70 66 73 5f 63 61 63 68 65 64 69 72 2c appfs_cachedir,
1b40: 20 54 43 4c 5f 47 4c 4f 42 41 4c 5f 4f 4e 4c 59 TCL_GLOBAL_ONLY
1b50: 29 3b 0a 09 29 0a 09 69 66 20 28 74 63 6c 5f 73 );..)..if (tcl_s
1b60: 65 74 76 61 72 5f 72 65 74 20 3d 3d 20 4e 55 4c etvar_ret == NUL
1b70: 4c 29 20 7b 0a 09 09 66 70 72 69 6e 74 66 28 73 L) {...fprintf(s
1b80: 74 64 65 72 72 2c 20 22 55 6e 61 62 6c 65 20 74 tderr, "Unable t
1b90: 6f 20 73 65 74 20 63 61 63 68 65 20 64 69 72 65 o set cache dire
1ba0: 63 74 6f 72 79 2e 20 20 54 68 69 73 20 73 68 6f ctory. This sho
1bb0: 75 6c 64 20 6e 65 76 65 72 20 66 61 69 6c 2e 5c uld never fail.\
1bc0: 6e 22 29 3b 0a 0a 09 09 69 66 20 28 65 72 72 6f n");....if (erro
1bd0: 72 5f 73 74 72 69 6e 67 29 20 7b 0a 09 09 09 61 r_string) {....a
1be0: 70 70 66 73 5f 63 61 6c 6c 5f 6c 69 62 74 63 6c ppfs_call_libtcl
1bf0: 28 0a 09 09 09 09 2a 65 72 72 6f 72 5f 73 74 72 (.....*error_str
1c00: 69 6e 67 20 3d 20 73 74 72 64 75 70 28 54 63 6c ing = strdup(Tcl
1c10: 5f 47 65 74 53 74 72 69 6e 67 52 65 73 75 6c 74 _GetStringResult
1c20: 28 69 6e 74 65 72 70 29 29 3b 0a 09 09 09 29 0a (interp));....).
1c30: 09 09 7d 0a 0a 09 09 61 70 70 66 73 5f 63 61 6c ..}....appfs_cal
1c40: 6c 5f 6c 69 62 74 63 6c 28 54 63 6c 5f 52 65 6c l_libtcl(Tcl_Rel
1c50: 65 61 73 65 28 69 6e 74 65 72 70 29 3b 29 0a 0a ease(interp);)..
1c60: 09 09 41 50 50 46 53 5f 44 45 42 55 47 28 22 54 ..APPFS_DEBUG("T
1c70: 65 72 6d 69 6e 61 74 69 6e 67 20 54 63 6c 20 69 erminating Tcl i
1c80: 6e 74 65 72 70 72 65 74 65 72 2e 22 29 3b 0a 0a nterpreter.");..
1c90: 09 09 61 70 70 66 73 5f 63 61 6c 6c 5f 6c 69 62 ..appfs_call_lib
1ca0: 74 63 6c 28 54 63 6c 5f 44 65 6c 65 74 65 49 6e tcl(Tcl_DeleteIn
1cb0: 74 65 72 70 28 69 6e 74 65 72 70 29 3b 29 0a 0a terp(interp);)..
1cc0: 09 09 72 65 74 75 72 6e 28 4e 55 4c 4c 29 3b 0a ..return(NULL);.
1cd0: 09 7d 0a 0a 09 2f 2a 0a 09 20 2a 20 49 6e 69 74 .}.../*.. * Init
1ce0: 69 61 6c 69 7a 65 20 74 68 65 20 22 61 70 70 66 ialize the "appf
1cf0: 73 64 2e 74 63 6c 22 20 65 6e 76 69 72 6f 6e 6d sd.tcl" environm
1d00: 65 6e 74 2c 20 77 68 69 63 68 20 6d 75 73 74 20 ent, which must
1d10: 62 65 20 64 6f 6e 65 20 61 66 74 65 72 0a 09 20 be done after..
1d20: 2a 20 67 6c 6f 62 61 6c 20 76 61 72 69 61 62 6c * global variabl
1d30: 65 73 20 61 72 65 20 73 65 74 2e 0a 09 20 2a 2f es are set... */
1d40: 0a 09 61 70 70 66 73 5f 63 61 6c 6c 5f 6c 69 62 ..appfs_call_lib
1d50: 74 63 6c 28 0a 09 09 74 63 6c 5f 72 65 74 20 3d tcl(...tcl_ret =
1d60: 20 54 63 6c 5f 45 76 61 6c 28 69 6e 74 65 72 70 Tcl_Eval(interp
1d70: 2c 20 22 3a 3a 61 70 70 66 73 3a 3a 69 6e 69 74 , "::appfs::init
1d80: 22 29 3b 0a 09 29 0a 09 69 66 20 28 74 63 6c 5f ");..)..if (tcl_
1d90: 72 65 74 20 21 3d 20 54 43 4c 5f 4f 4b 29 20 7b ret != TCL_OK) {
1da0: 0a 09 09 66 70 72 69 6e 74 66 28 73 74 64 65 72 ...fprintf(stder
1db0: 72 2c 20 22 55 6e 61 62 6c 65 20 74 6f 20 69 6e r, "Unable to in
1dc0: 69 74 69 61 6c 69 7a 65 20 54 63 6c 20 41 70 70 itialize Tcl App
1dd0: 46 53 20 73 63 72 69 70 74 20 28 3a 3a 61 70 70 FS script (::app
1de0: 66 73 3a 3a 69 6e 69 74 29 2e 20 20 41 62 6f 72 fs::init). Abor
1df0: 74 69 6e 67 2e 5c 6e 22 29 3b 0a 09 09 61 70 70 ting.\n");...app
1e00: 66 73 5f 63 61 6c 6c 5f 6c 69 62 74 63 6c 28 0a fs_call_libtcl(.
1e10: 09 09 09 66 70 72 69 6e 74 66 28 73 74 64 65 72 ...fprintf(stder
1e20: 72 2c 20 22 54 63 6c 20 45 72 72 6f 72 20 69 73 r, "Tcl Error is
1e30: 3a 20 25 73 5c 6e 22 2c 20 54 63 6c 5f 47 65 74 : %s\n", Tcl_Get
1e40: 53 74 72 69 6e 67 52 65 73 75 6c 74 28 69 6e 74 StringResult(int
1e50: 65 72 70 29 29 3b 0a 09 09 29 0a 0a 09 09 69 66 erp));...)....if
1e60: 20 28 65 72 72 6f 72 5f 73 74 72 69 6e 67 29 20 (error_string)
1e70: 7b 0a 09 09 09 61 70 70 66 73 5f 63 61 6c 6c 5f {....appfs_call_
1e80: 6c 69 62 74 63 6c 28 0a 09 09 09 09 2a 65 72 72 libtcl(.....*err
1e90: 6f 72 5f 73 74 72 69 6e 67 20 3d 20 73 74 72 64 or_string = strd
1ea0: 75 70 28 54 63 6c 5f 47 65 74 53 74 72 69 6e 67 up(Tcl_GetString
1eb0: 52 65 73 75 6c 74 28 69 6e 74 65 72 70 29 29 3b Result(interp));
1ec0: 0a 09 09 09 29 0a 09 09 7d 0a 0a 09 09 61 70 70 ....)...}....app
1ed0: 66 73 5f 63 61 6c 6c 5f 6c 69 62 74 63 6c 28 54 fs_call_libtcl(T
1ee0: 63 6c 5f 52 65 6c 65 61 73 65 28 69 6e 74 65 72 cl_Release(inter
1ef0: 70 29 3b 29 0a 0a 09 09 41 50 50 46 53 5f 44 45 p);)....APPFS_DE
1f00: 42 55 47 28 22 54 65 72 6d 69 6e 61 74 69 6e 67 BUG("Terminating
1f10: 20 54 63 6c 20 69 6e 74 65 72 70 72 65 74 65 72 Tcl interpreter
1f20: 2e 22 29 3b 0a 0a 09 09 61 70 70 66 73 5f 63 61 .");....appfs_ca
1f30: 6c 6c 5f 6c 69 62 74 63 6c 28 54 63 6c 5f 44 65 ll_libtcl(Tcl_De
1f40: 6c 65 74 65 49 6e 74 65 72 70 28 69 6e 74 65 72 leteInterp(inter
1f50: 70 29 3b 29 0a 0a 09 09 72 65 74 75 72 6e 28 4e p);)....return(N
1f60: 55 4c 4c 29 3b 0a 09 7d 0a 0a 09 2f 2a 0a 09 20 ULL);..}.../*..
1f70: 2a 20 48 69 64 65 20 73 6f 6d 65 20 54 63 6c 20 * Hide some Tcl
1f80: 63 6f 6d 6d 61 6e 64 73 20 74 68 61 74 20 77 65 commands that we
1f90: 20 64 6f 20 6e 6f 74 20 63 61 72 65 20 74 6f 20 do not care to
1fa0: 75 73 65 20 61 6e 64 20 77 68 69 63 68 20 6d 61 use and which ma
1fb0: 79 0a 09 20 2a 20 73 6c 6f 77 20 64 6f 77 6e 20 y.. * slow down
1fc0: 72 75 6e 2d 74 69 6d 65 20 6f 70 65 72 61 74 69 run-time operati
1fd0: 6f 6e 73 2e 0a 09 20 2a 2f 0a 09 61 70 70 66 73 ons... */..appfs
1fe0: 5f 63 61 6c 6c 5f 6c 69 62 74 63 6c 28 0a 09 09 _call_libtcl(...
1ff0: 54 63 6c 5f 48 69 64 65 43 6f 6d 6d 61 6e 64 28 Tcl_HideCommand(
2000: 69 6e 74 65 72 70 2c 20 22 61 75 74 6f 5f 6c 6f interp, "auto_lo
2010: 61 64 5f 69 6e 64 65 78 22 2c 20 22 61 75 74 6f ad_index", "auto
2020: 5f 6c 6f 61 64 5f 69 6e 64 65 78 22 29 3b 0a 09 _load_index");..
2030: 09 54 63 6c 5f 48 69 64 65 43 6f 6d 6d 61 6e 64 .Tcl_HideCommand
2040: 28 69 6e 74 65 72 70 2c 20 22 75 6e 6b 6e 6f 77 (interp, "unknow
2050: 6e 22 2c 20 22 75 6e 6b 6e 6f 77 6e 22 29 3b 0a n", "unknown");.
2060: 09 09 54 63 6c 5f 48 69 64 65 43 6f 6d 6d 61 6e ..Tcl_HideComman
2070: 64 28 69 6e 74 65 72 70 2c 20 22 65 78 69 74 22 d(interp, "exit"
2080: 2c 20 22 65 78 69 74 22 29 3b 0a 09 29 0a 0a 09 , "exit");..)...
2090: 2f 2a 0a 09 20 2a 20 52 65 6c 65 61 73 65 20 74 /*.. * Release t
20a0: 68 65 20 68 6f 6c 64 20 77 65 20 68 61 76 65 20 he hold we have
20b0: 6f 6e 20 74 68 65 20 69 6e 74 65 72 70 72 65 74 on the interpret
20c0: 65 72 20 73 6f 20 74 68 61 74 20 69 74 20 6d 61 er so that it ma
20d0: 79 20 62 65 0a 09 20 2a 20 64 65 6c 65 74 65 64 y be.. * deleted
20e0: 20 69 66 20 6e 65 65 64 65 64 0a 09 20 2a 2f 0a if needed.. */.
20f0: 09 61 70 70 66 73 5f 63 61 6c 6c 5f 6c 69 62 74 .appfs_call_libt
2100: 63 6c 28 54 63 6c 5f 52 65 6c 65 61 73 65 28 69 cl(Tcl_Release(i
2110: 6e 74 65 72 70 29 3b 29 0a 0a 09 2f 2a 0a 09 20 nterp);).../*..
2120: 2a 20 52 65 74 75 72 6e 20 74 68 65 20 63 6f 6d * Return the com
2130: 70 6c 65 74 65 6c 79 20 69 6e 69 74 69 61 6c 69 pletely initiali
2140: 7a 65 64 20 69 6e 74 65 72 70 72 65 74 65 72 0a zed interpreter.
2150: 09 20 2a 2f 0a 09 72 65 74 75 72 6e 28 69 6e 74 . */..return(int
2160: 65 72 70 29 3b 0a 7d 0a 0a 2f 2a 0a 20 2a 20 52 erp);.}../*. * R
2170: 65 74 75 72 6e 20 74 68 65 20 74 68 72 65 61 64 eturn the thread
2180: 2d 73 70 65 63 69 66 69 63 20 54 63 6c 20 69 6e -specific Tcl in
2190: 74 65 72 70 72 65 74 65 72 2c 20 63 72 65 61 74 terpreter, creat
21a0: 69 6e 67 20 69 74 20 69 66 20 6e 65 65 64 65 64 ing it if needed
21b0: 0a 20 2a 2f 0a 73 74 61 74 69 63 20 54 63 6c 5f . */.static Tcl_
21c0: 49 6e 74 65 72 70 20 2a 61 70 70 66 73 5f 54 63 Interp *appfs_Tc
21d0: 6c 49 6e 74 65 72 70 28 76 6f 69 64 29 20 7b 0a lInterp(void) {.
21e0: 09 54 63 6c 5f 49 6e 74 65 72 70 20 2a 69 6e 74 .Tcl_Interp *int
21f0: 65 72 70 3b 0a 09 69 6e 74 20 70 74 68 72 65 61 erp;..int pthrea
2200: 64 5f 72 65 74 3b 0a 09 73 74 61 74 69 63 20 5f d_ret;..static _
2210: 5f 74 68 72 65 61 64 20 69 6e 74 20 74 68 72 65 _thread int thre
2220: 61 64 5f 69 6e 74 65 72 70 5f 72 65 73 65 74 5f ad_interp_reset_
2230: 6b 65 79 20 3d 20 30 3b 0a 09 69 6e 74 20 67 6c key = 0;..int gl
2240: 6f 62 61 6c 5f 69 6e 74 65 72 70 5f 72 65 73 65 obal_interp_rese
2250: 74 5f 6b 65 79 3b 0a 0a 09 67 6c 6f 62 61 6c 5f t_key;...global_
2260: 69 6e 74 65 72 70 5f 72 65 73 65 74 5f 6b 65 79 interp_reset_key
2270: 20 3d 20 5f 5f 73 79 6e 63 5f 66 65 74 63 68 5f = __sync_fetch_
2280: 61 6e 64 5f 61 64 64 28 26 69 6e 74 65 72 70 5f and_add(&interp_
2290: 72 65 73 65 74 5f 6b 65 79 2c 20 30 29 3b 0a 0a reset_key, 0);..
22a0: 09 69 6e 74 65 72 70 20 3d 20 70 74 68 72 65 61 .interp = pthrea
22b0: 64 5f 67 65 74 73 70 65 63 69 66 69 63 28 69 6e d_getspecific(in
22c0: 74 65 72 70 4b 65 79 29 3b 0a 09 69 66 20 28 69 terpKey);..if (i
22d0: 6e 74 65 72 70 20 21 3d 20 4e 55 4c 4c 20 26 26 nterp != NULL &&
22e0: 20 74 68 72 65 61 64 5f 69 6e 74 65 72 70 5f 72 thread_interp_r
22f0: 65 73 65 74 5f 6b 65 79 20 21 3d 20 67 6c 6f 62 eset_key != glob
2300: 61 6c 5f 69 6e 74 65 72 70 5f 72 65 73 65 74 5f al_interp_reset_
2310: 6b 65 79 29 20 7b 0a 09 09 41 50 50 46 53 5f 44 key) {...APPFS_D
2320: 45 42 55 47 28 22 54 65 72 6d 69 6e 61 74 69 6e EBUG("Terminatin
2330: 67 20 6f 6c 64 20 69 6e 74 65 72 70 72 65 74 65 g old interprete
2340: 72 20 61 6e 64 20 72 65 73 74 61 72 74 69 6e 67 r and restarting
2350: 20 64 75 65 20 74 6f 20 72 65 73 65 74 20 72 65 due to reset re
2360: 71 75 65 73 74 2e 22 29 3b 0a 0a 09 09 61 70 70 quest.");....app
2370: 66 73 5f 63 61 6c 6c 5f 6c 69 62 74 63 6c 28 54 fs_call_libtcl(T
2380: 63 6c 5f 44 65 6c 65 74 65 49 6e 74 65 72 70 28 cl_DeleteInterp(
2390: 69 6e 74 65 72 70 29 3b 29 0a 0a 09 09 69 6e 74 interp);)....int
23a0: 65 72 70 20 3d 20 4e 55 4c 4c 3b 0a 0a 09 09 70 erp = NULL;....p
23b0: 74 68 72 65 61 64 5f 72 65 74 20 3d 20 70 74 68 thread_ret = pth
23c0: 72 65 61 64 5f 73 65 74 73 70 65 63 69 66 69 63 read_setspecific
23d0: 28 69 6e 74 65 72 70 4b 65 79 2c 20 69 6e 74 65 (interpKey, inte
23e0: 72 70 29 3b 0a 09 7d 0a 0a 09 69 66 20 28 67 6c rp);..}...if (gl
23f0: 6f 62 61 6c 5f 69 6e 74 65 72 70 5f 72 65 73 65 obal_interp_rese
2400: 74 5f 6b 65 79 20 3d 3d 20 2d 31 29 20 7b 0a 09 t_key == -1) {..
2410: 09 41 50 50 46 53 5f 44 45 42 55 47 28 22 52 65 .APPFS_DEBUG("Re
2420: 74 75 72 6e 69 6e 67 20 4e 55 4c 4c 20 73 69 6e turning NULL sin
2430: 63 65 20 77 65 20 61 72 65 20 69 6e 20 74 68 65 ce we are in the
2440: 20 70 72 6f 63 65 73 73 20 6f 66 20 74 65 72 6d process of term
2450: 69 6e 61 74 69 6e 67 20 61 6c 6c 20 74 68 72 65 inating all thre
2460: 61 64 73 2e 22 29 3b 0a 0a 09 09 72 65 74 75 72 ads.");....retur
2470: 6e 28 4e 55 4c 4c 29 3b 0a 09 7d 0a 0a 09 74 68 n(NULL);..}...th
2480: 72 65 61 64 5f 69 6e 74 65 72 70 5f 72 65 73 65 read_interp_rese
2490: 74 5f 6b 65 79 20 3d 20 67 6c 6f 62 61 6c 5f 69 t_key = global_i
24a0: 6e 74 65 72 70 5f 72 65 73 65 74 5f 6b 65 79 3b nterp_reset_key;
24b0: 0a 0a 09 69 66 20 28 69 6e 74 65 72 70 20 3d 3d ...if (interp ==
24c0: 20 4e 55 4c 4c 29 20 7b 0a 09 09 69 6e 74 65 72 NULL) {...inter
24d0: 70 20 3d 20 61 70 70 66 73 5f 63 72 65 61 74 65 p = appfs_create
24e0: 5f 54 63 6c 49 6e 74 65 72 70 28 4e 55 4c 4c 29 _TclInterp(NULL)
24f0: 3b 0a 0a 09 09 69 66 20 28 69 6e 74 65 72 70 20 ;....if (interp
2500: 3d 3d 20 4e 55 4c 4c 29 20 7b 0a 09 09 09 41 50 == NULL) {....AP
2510: 50 46 53 5f 44 45 42 55 47 28 22 43 72 65 61 74 PFS_DEBUG("Creat
2520: 65 20 69 6e 74 65 72 70 20 66 61 69 6c 65 64 2c e interp failed,
2530: 20 72 65 74 75 72 6e 69 6e 67 69 6e 20 66 61 69 returningin fai
2540: 6c 75 72 65 2e 22 29 3b 0a 0a 09 09 09 72 65 74 lure.");.....ret
2550: 75 72 6e 28 4e 55 4c 4c 29 3b 0a 09 09 7d 0a 0a urn(NULL);...}..
2560: 09 09 70 74 68 72 65 61 64 5f 72 65 74 20 3d 20 ..pthread_ret =
2570: 70 74 68 72 65 61 64 5f 73 65 74 73 70 65 63 69 pthread_setspeci
2580: 66 69 63 28 69 6e 74 65 72 70 4b 65 79 2c 20 69 fic(interpKey, i
2590: 6e 74 65 72 70 29 3b 0a 09 09 69 66 20 28 70 74 nterp);...if (pt
25a0: 68 72 65 61 64 5f 72 65 74 20 21 3d 20 30 29 20 hread_ret != 0)
25b0: 7b 0a 09 09 09 41 50 50 46 53 5f 44 45 42 55 47 {....APPFS_DEBUG
25c0: 28 22 70 74 68 72 65 61 64 5f 73 65 74 73 70 65 ("pthread_setspe
25d0: 63 69 66 69 63 28 29 20 66 61 69 6c 65 64 2e 20 cific() failed.
25e0: 20 54 65 72 6d 69 6e 61 74 69 6e 67 20 54 63 6c Terminating Tcl
25f0: 20 69 6e 74 65 72 70 72 65 74 65 72 2e 22 29 3b interpreter.");
2600: 0a 0a 09 09 09 61 70 70 66 73 5f 63 61 6c 6c 5f .....appfs_call_
2610: 6c 69 62 74 63 6c 28 54 63 6c 5f 44 65 6c 65 74 libtcl(Tcl_Delet
2620: 65 49 6e 74 65 72 70 28 69 6e 74 65 72 70 29 3b eInterp(interp);
2630: 29 0a 0a 09 09 09 72 65 74 75 72 6e 28 4e 55 4c ).....return(NUL
2640: 4c 29 3b 0a 09 09 7d 0a 09 7d 0a 0a 09 72 65 74 L);...}..}...ret
2650: 75 72 6e 28 69 6e 74 65 72 70 29 3b 0a 7d 0a 0a urn(interp);.}..
2660: 2f 2a 0a 20 2a 20 45 76 61 6c 75 61 74 65 20 61 /*. * Evaluate a
2670: 20 54 63 6c 20 73 63 72 69 70 74 20 63 6f 6e 73 Tcl script cons
2680: 74 72 75 63 74 65 64 20 62 79 20 63 6f 6e 63 61 tructed by conca
2690: 74 65 6e 61 74 69 6e 67 20 61 20 62 75 6e 63 68 tenating a bunch
26a0: 20 6f 66 20 43 20 73 74 72 69 6e 67 73 0a 20 2a of C strings. *
26b0: 20 74 6f 67 65 74 68 65 72 2e 0a 20 2a 2f 0a 73 together.. */.s
26c0: 74 61 74 69 63 20 69 6e 74 20 61 70 70 66 73 5f tatic int appfs_
26d0: 54 63 6c 5f 45 76 61 6c 28 54 63 6c 5f 49 6e 74 Tcl_Eval(Tcl_Int
26e0: 65 72 70 20 2a 69 6e 74 65 72 70 2c 20 69 6e 74 erp *interp, int
26f0: 20 6f 62 6a 63 2c 20 63 6f 6e 73 74 20 63 68 61 objc, const cha
2700: 72 20 2a 63 6d 64 2c 20 2e 2e 2e 29 20 7b 0a 09 r *cmd, ...) {..
2710: 54 63 6c 5f 4f 62 6a 20 2a 2a 6f 62 6a 76 3b 0a Tcl_Obj **objv;.
2720: 09 63 6f 6e 73 74 20 63 68 61 72 20 2a 61 72 67 .const char *arg
2730: 3b 0a 09 76 61 5f 6c 69 73 74 20 61 72 67 70 3b ;..va_list argp;
2740: 0a 09 69 6e 74 20 72 65 74 76 61 6c 3b 0a 09 69 ..int retval;..i
2750: 6e 74 20 69 3b 0a 0a 09 69 66 20 28 69 6e 74 65 nt i;...if (inte
2760: 72 70 20 3d 3d 20 4e 55 4c 4c 29 20 7b 0a 09 09 rp == NULL) {...
2770: 41 50 50 46 53 5f 44 45 42 55 47 28 22 49 6e 76 APPFS_DEBUG("Inv
2780: 61 6c 69 64 20 69 6e 74 65 72 70 72 65 74 65 72 alid interpreter
2790: 20 70 61 73 73 65 64 20 69 6e 2c 20 72 65 74 75 passed in, retu
27a0: 72 6e 69 6e 67 20 69 6e 20 66 61 69 6c 75 72 65 rning in failure
27b0: 2e 22 29 3b 0a 0a 09 09 72 65 74 75 72 6e 28 54 .");....return(T
27c0: 43 4c 5f 45 52 52 4f 52 29 3b 0a 09 7d 0a 0a 09 CL_ERROR);..}...
27d0: 6f 62 6a 76 20 3d 20 28 76 6f 69 64 20 2a 29 20 objv = (void *)
27e0: 63 6b 61 6c 6c 6f 63 28 73 69 7a 65 6f 66 28 2a ckalloc(sizeof(*
27f0: 6f 62 6a 76 29 20 2a 20 6f 62 6a 63 29 3b 0a 0a objv) * objc);..
2800: 09 61 70 70 66 73 5f 63 61 6c 6c 5f 6c 69 62 74 .appfs_call_libt
2810: 63 6c 28 0a 09 09 6f 62 6a 76 5b 30 5d 20 3d 20 cl(...objv[0] =
2820: 54 63 6c 5f 4e 65 77 53 74 72 69 6e 67 4f 62 6a Tcl_NewStringObj
2830: 28 63 6d 64 2c 20 2d 31 29 3b 0a 0a 09 09 54 63 (cmd, -1);....Tc
2840: 6c 5f 49 6e 63 72 52 65 66 43 6f 75 6e 74 28 6f l_IncrRefCount(o
2850: 62 6a 76 5b 30 5d 29 3b 0a 0a 09 09 76 61 5f 73 bjv[0]);....va_s
2860: 74 61 72 74 28 61 72 67 70 2c 20 63 6d 64 29 3b tart(argp, cmd);
2870: 0a 09 09 66 6f 72 20 28 69 20 3d 20 31 3b 20 69 ...for (i = 1; i
2880: 20 3c 20 6f 62 6a 63 3b 20 69 2b 2b 29 20 7b 0a < objc; i++) {.
2890: 09 09 09 61 72 67 20 3d 20 76 61 5f 61 72 67 28 ...arg = va_arg(
28a0: 61 72 67 70 2c 20 63 6f 6e 73 74 20 63 68 61 72 argp, const char
28b0: 20 2a 29 3b 0a 0a 09 09 09 6f 62 6a 76 5b 69 5d *);.....objv[i]
28c0: 20 3d 20 54 63 6c 5f 4e 65 77 53 74 72 69 6e 67 = Tcl_NewString
28d0: 4f 62 6a 28 61 72 67 2c 20 2d 31 29 3b 0a 0a 09 Obj(arg, -1);...
28e0: 09 09 54 63 6c 5f 49 6e 63 72 52 65 66 43 6f 75 ..Tcl_IncrRefCou
28f0: 6e 74 28 6f 62 6a 76 5b 69 5d 29 3b 0a 09 09 7d nt(objv[i]);...}
2900: 0a 09 09 76 61 5f 65 6e 64 28 61 72 67 70 29 3b ...va_end(argp);
2910: 0a 09 29 0a 0a 09 61 70 70 66 73 5f 63 61 6c 6c ..)...appfs_call
2920: 5f 6c 69 62 74 63 6c 28 0a 09 09 72 65 74 76 61 _libtcl(...retva
2930: 6c 20 3d 20 54 63 6c 5f 45 76 61 6c 4f 62 6a 76 l = Tcl_EvalObjv
2940: 28 69 6e 74 65 72 70 2c 20 6f 62 6a 63 2c 20 6f (interp, objc, o
2950: 62 6a 76 2c 20 30 29 3b 0a 09 29 0a 0a 09 61 70 bjv, 0);..)...ap
2960: 70 66 73 5f 63 61 6c 6c 5f 6c 69 62 74 63 6c 28 pfs_call_libtcl(
2970: 0a 09 09 66 6f 72 20 28 69 20 3d 20 30 3b 20 69 ...for (i = 0; i
2980: 20 3c 20 6f 62 6a 63 3b 20 69 2b 2b 29 20 7b 0a < objc; i++) {.
2990: 09 09 09 54 63 6c 5f 44 65 63 72 52 65 66 43 6f ...Tcl_DecrRefCo
29a0: 75 6e 74 28 6f 62 6a 76 5b 69 5d 29 3b 0a 09 09 unt(objv[i]);...
29b0: 7d 0a 09 29 0a 0a 09 63 6b 66 72 65 65 28 28 76 }..)...ckfree((v
29c0: 6f 69 64 20 2a 29 20 6f 62 6a 76 29 3b 0a 0a 09 oid *) objv);...
29d0: 69 66 20 28 72 65 74 76 61 6c 20 21 3d 20 54 43 if (retval != TC
29e0: 4c 5f 4f 4b 29 20 7b 0a 09 09 61 70 70 66 73 5f L_OK) {...appfs_
29f0: 63 61 6c 6c 5f 6c 69 62 74 63 6c 28 0a 09 09 09 call_libtcl(....
2a00: 41 50 50 46 53 5f 44 45 42 55 47 28 22 54 63 6c APPFS_DEBUG("Tcl
2a10: 20 63 6f 6d 6d 61 6e 64 20 66 61 69 6c 65 64 2c command failed,
2a20: 20 3a 3a 65 72 72 6f 72 49 6e 66 6f 20 63 6f 6e ::errorInfo con
2a30: 74 61 69 6e 73 3a 20 25 73 5c 6e 22 2c 20 54 63 tains: %s\n", Tc
2a40: 6c 5f 47 65 74 56 61 72 28 69 6e 74 65 72 70 2c l_GetVar(interp,
2a50: 20 22 3a 3a 65 72 72 6f 72 49 6e 66 6f 22 2c 20 "::errorInfo",
2a60: 30 29 29 3b 0a 09 09 29 0a 09 7d 0a 0a 09 72 65 0));...)..}...re
2a70: 74 75 72 6e 28 72 65 74 76 61 6c 29 3b 0a 7d 0a turn(retval);.}.
2a80: 0a 2f 2a 0a 20 2a 20 52 65 71 75 65 73 74 20 61 ./*. * Request a
2a90: 6c 6c 20 54 63 6c 20 69 6e 74 65 72 70 72 65 74 ll Tcl interpret
2aa0: 65 72 73 20 72 65 73 74 61 72 74 0a 20 2a 2f 0a ers restart. */.
2ab0: 73 74 61 74 69 63 20 76 6f 69 64 20 61 70 70 66 static void appf
2ac0: 73 5f 74 63 6c 5f 52 65 73 65 74 49 6e 74 65 72 s_tcl_ResetInter
2ad0: 70 73 28 76 6f 69 64 29 20 7b 0a 09 41 50 50 46 ps(void) {..APPF
2ae0: 53 5f 44 45 42 55 47 28 22 52 65 71 75 65 73 74 S_DEBUG("Request
2af0: 69 6e 67 20 72 65 73 65 74 20 6f 66 20 61 6c 6c ing reset of all
2b00: 20 69 6e 74 65 72 70 72 65 74 65 72 73 2e 22 29 interpreters.")
2b10: 3b 0a 0a 09 5f 5f 73 79 6e 63 5f 61 64 64 5f 61 ;...__sync_add_a
2b20: 6e 64 5f 66 65 74 63 68 28 26 69 6e 74 65 72 70 nd_fetch(&interp
2b30: 5f 72 65 73 65 74 5f 6b 65 79 2c 20 31 29 3b 0a _reset_key, 1);.
2b40: 0a 09 72 65 74 75 72 6e 3b 0a 7d 0a 0a 2f 2a 0a ..return;.}../*.
2b50: 20 2a 20 44 65 74 65 72 6d 69 6e 65 20 74 68 65 * Determine the
2b60: 20 55 49 44 20 66 6f 72 20 74 68 65 20 75 73 65 UID for the use
2b70: 72 20 6d 61 6b 69 6e 67 20 74 68 65 20 63 75 72 r making the cur
2b80: 72 65 6e 74 20 46 55 53 45 20 66 69 6c 65 73 79 rent FUSE filesy
2b90: 73 74 65 6d 20 72 65 71 75 65 73 74 2e 0a 20 2a stem request.. *
2ba0: 20 54 68 69 73 20 77 69 6c 6c 20 62 65 20 75 73 This will be us
2bb0: 65 64 20 74 6f 20 6c 6f 6f 6b 75 70 20 74 68 65 ed to lookup the
2bc0: 20 75 73 65 72 27 73 20 68 6f 6d 65 20 64 69 72 user's home dir
2bd0: 65 63 74 6f 72 79 20 73 6f 20 77 65 20 63 61 6e ectory so we can
2be0: 20 73 65 61 72 63 68 20 66 6f 72 0a 20 2a 20 6c search for. * l
2bf0: 6f 63 61 6c 6c 79 20 6d 6f 64 69 66 69 65 64 20 ocally modified
2c00: 66 69 6c 65 73 2e 0a 20 2a 2f 0a 73 74 61 74 69 files.. */.stati
2c10: 63 20 75 69 64 5f 74 20 61 70 70 66 73 5f 67 65 c uid_t appfs_ge
2c20: 74 5f 66 73 75 69 64 28 76 6f 69 64 29 20 7b 0a t_fsuid(void) {.
2c30: 09 73 74 72 75 63 74 20 66 75 73 65 5f 63 6f 6e .struct fuse_con
2c40: 74 65 78 74 20 2a 63 74 78 3b 0a 0a 09 69 66 20 text *ctx;...if
2c50: 28 21 61 70 70 66 73 5f 66 75 73 65 5f 73 74 61 (!appfs_fuse_sta
2c60: 72 74 65 64 29 20 7b 0a 09 09 72 65 74 75 72 6e rted) {...return
2c70: 28 67 65 74 75 69 64 28 29 29 3b 0a 09 7d 0a 0a (getuid());..}..
2c80: 09 63 74 78 20 3d 20 66 75 73 65 5f 67 65 74 5f .ctx = fuse_get_
2c90: 63 6f 6e 74 65 78 74 28 29 3b 0a 09 69 66 20 28 context();..if (
2ca0: 63 74 78 20 3d 3d 20 4e 55 4c 4c 29 20 7b 0a 09 ctx == NULL) {..
2cb0: 09 2f 2a 20 55 6e 61 62 6c 65 20 74 6f 20 6c 6f ./* Unable to lo
2cc0: 6f 6b 75 70 20 75 73 65 72 20 66 6f 72 20 73 6f okup user for so
2cd0: 6d 65 20 72 65 61 73 6f 6e 20 2a 2f 0a 09 09 2f me reason */.../
2ce0: 2a 20 52 65 74 75 72 6e 20 61 6e 20 75 6e 70 72 * Return an unpr
2cf0: 69 76 69 6c 65 67 65 64 20 75 73 65 72 20 49 44 ivileged user ID
2d00: 20 2a 2f 0a 09 09 41 50 50 46 53 5f 44 45 42 55 */...APPFS_DEBU
2d10: 47 28 22 55 6e 61 62 6c 65 20 74 6f 20 6c 6f 6f G("Unable to loo
2d20: 6b 75 70 20 75 73 65 72 20 66 6f 72 20 73 6f 6d kup user for som
2d30: 65 20 72 65 61 73 6f 6e 2c 20 72 65 74 75 72 6e e reason, return
2d40: 69 6e 6e 67 20 75 73 65 72 20 49 44 20 6f 66 20 inng user ID of
2d50: 31 22 29 3b 0a 0a 09 09 72 65 74 75 72 6e 28 31 1");....return(1
2d60: 29 3b 0a 09 7d 0a 0a 09 72 65 74 75 72 6e 28 63 );..}...return(c
2d70: 74 78 2d 3e 75 69 64 29 3b 0a 7d 0a 0a 2f 2a 0a tx->uid);.}../*.
2d80: 20 2a 20 44 65 74 65 72 6d 69 6e 65 20 74 68 65 * Determine the
2d90: 20 47 49 44 20 66 6f 72 20 74 68 65 20 75 73 65 GID for the use
2da0: 72 20 6d 61 6b 69 6e 67 20 74 68 65 20 63 75 72 r making the cur
2db0: 72 65 6e 74 20 46 55 53 45 20 66 69 6c 65 73 79 rent FUSE filesy
2dc0: 73 74 65 6d 20 72 65 71 75 65 73 74 2e 0a 20 2a stem request.. *
2dd0: 20 54 68 69 73 20 77 69 6c 6c 20 62 65 20 75 73 This will be us
2de0: 65 64 20 74 6f 20 6c 6f 6f 6b 75 70 20 74 68 65 ed to lookup the
2df0: 20 75 73 65 72 27 73 20 68 6f 6d 65 20 64 69 72 user's home dir
2e00: 65 63 74 6f 72 79 20 73 6f 20 77 65 20 63 61 6e ectory so we can
2e10: 20 73 65 61 72 63 68 20 66 6f 72 0a 20 2a 20 6c search for. * l
2e20: 6f 63 61 6c 6c 79 20 6d 6f 64 69 66 69 65 64 20 ocally modified
2e30: 66 69 6c 65 73 2e 0a 20 2a 2f 0a 73 74 61 74 69 files.. */.stati
2e40: 63 20 67 69 64 5f 74 20 61 70 70 66 73 5f 67 65 c gid_t appfs_ge
2e50: 74 5f 66 73 67 69 64 28 76 6f 69 64 29 20 7b 0a t_fsgid(void) {.
2e60: 09 73 74 72 75 63 74 20 66 75 73 65 5f 63 6f 6e .struct fuse_con
2e70: 74 65 78 74 20 2a 63 74 78 3b 0a 0a 09 69 66 20 text *ctx;...if
2e80: 28 21 61 70 70 66 73 5f 66 75 73 65 5f 73 74 61 (!appfs_fuse_sta
2e90: 72 74 65 64 29 20 7b 0a 09 09 72 65 74 75 72 6e rted) {...return
2ea0: 28 67 65 74 67 69 64 28 29 29 3b 0a 09 7d 0a 0a (getgid());..}..
2eb0: 09 63 74 78 20 3d 20 66 75 73 65 5f 67 65 74 5f .ctx = fuse_get_
2ec0: 63 6f 6e 74 65 78 74 28 29 3b 0a 09 69 66 20 28 context();..if (
2ed0: 63 74 78 20 3d 3d 20 4e 55 4c 4c 29 20 7b 0a 09 ctx == NULL) {..
2ee0: 09 2f 2a 20 55 6e 61 62 6c 65 20 74 6f 20 6c 6f ./* Unable to lo
2ef0: 6f 6b 75 70 20 75 73 65 72 20 66 6f 72 20 73 6f okup user for so
2f00: 6d 65 20 72 65 61 73 6f 6e 20 2a 2f 0a 09 09 2f me reason */.../
2f10: 2a 20 52 65 74 75 72 6e 20 61 6e 20 75 6e 70 72 * Return an unpr
2f20: 69 76 69 6c 65 67 65 64 20 75 73 65 72 20 49 44 ivileged user ID
2f30: 20 2a 2f 0a 09 09 41 50 50 46 53 5f 44 45 42 55 */...APPFS_DEBU
2f40: 47 28 22 55 6e 61 62 6c 65 20 74 6f 20 6c 6f 6f G("Unable to loo
2f50: 6b 75 70 20 67 72 6f 75 70 20 66 6f 72 20 73 6f kup group for so
2f60: 6d 65 20 72 65 61 73 6f 6e 2c 20 72 65 74 75 72 me reason, retur
2f70: 6e 69 6e 6e 67 20 67 72 6f 75 70 20 49 44 20 6f ninng group ID o
2f80: 66 20 31 22 29 3b 0a 0a 09 09 72 65 74 75 72 6e f 1");....return
2f90: 28 31 29 3b 0a 09 7d 0a 0a 09 72 65 74 75 72 6e (1);..}...return
2fa0: 28 63 74 78 2d 3e 67 69 64 29 3b 0a 7d 0a 0a 73 (ctx->gid);.}..s
2fb0: 74 61 74 69 63 20 76 6f 69 64 20 61 70 70 66 73 tatic void appfs
2fc0: 5f 73 69 6d 75 6c 61 74 65 5f 75 73 65 72 5f 66 _simulate_user_f
2fd0: 73 5f 65 6e 74 65 72 28 76 6f 69 64 29 20 7b 0a s_enter(void) {.
2fe0: 09 73 65 74 66 73 75 69 64 28 61 70 70 66 73 5f .setfsuid(appfs_
2ff0: 67 65 74 5f 66 73 75 69 64 28 29 29 3b 0a 09 73 get_fsuid());..s
3000: 65 74 66 73 67 69 64 28 61 70 70 66 73 5f 67 65 etfsgid(appfs_ge
3010: 74 5f 66 73 67 69 64 28 29 29 3b 0a 7d 0a 0a 73 t_fsgid());.}..s
3020: 74 61 74 69 63 20 76 6f 69 64 20 61 70 70 66 73 tatic void appfs
3030: 5f 73 69 6d 75 6c 61 74 65 5f 75 73 65 72 5f 66 _simulate_user_f
3040: 73 5f 6c 65 61 76 65 28 76 6f 69 64 29 20 7b 0a s_leave(void) {.
3050: 09 73 65 74 66 73 75 69 64 28 30 29 3b 0a 09 73 .setfsuid(0);..s
3060: 65 74 66 73 67 69 64 28 30 29 3b 0a 7d 0a 0a 2f etfsgid(0);.}../
3070: 2a 0a 20 2a 20 4c 6f 6f 6b 20 75 70 20 74 68 65 *. * Look up the
3080: 20 68 6f 6d 65 20 64 69 72 65 63 74 6f 72 79 20 home directory
3090: 66 6f 72 20 61 20 67 69 76 65 6e 20 55 49 44 0a for a given UID.
30a0: 20 2a 20 20 20 20 20 20 20 20 52 65 74 75 72 6e * Return
30b0: 73 20 61 20 43 20 73 74 72 69 6e 67 20 63 6f 6e s a C string con
30c0: 74 61 69 6e 69 6e 67 20 74 68 65 20 75 73 65 72 taining the user
30d0: 27 73 20 68 6f 6d 65 20 64 69 72 65 63 74 6f 72 's home director
30e0: 79 20 6f 72 20 4e 55 4c 4c 20 69 66 0a 20 2a 20 y or NULL if. *
30f0: 20 20 20 20 20 20 20 74 68 65 20 75 73 65 72 27 the user'
3100: 73 20 68 6f 6d 65 20 64 69 72 65 63 74 6f 72 79 s home directory
3110: 20 64 6f 65 73 20 6e 6f 74 20 65 78 69 73 74 20 does not exist
3120: 6f 72 20 69 73 20 6e 6f 74 20 63 6f 72 72 65 63 or is not correc
3130: 74 6c 79 0a 20 2a 20 20 20 20 20 20 20 20 63 6f tly. * co
3140: 6e 66 69 67 75 72 65 64 0a 20 2a 2f 0a 73 74 61 nfigured. */.sta
3150: 74 69 63 20 63 68 61 72 20 2a 61 70 70 66 73 5f tic char *appfs_
3160: 67 65 74 5f 68 6f 6d 65 64 69 72 28 75 69 64 5f get_homedir(uid_
3170: 74 20 66 73 75 69 64 29 20 7b 0a 09 73 74 72 75 t fsuid) {..stru
3180: 63 74 20 70 61 73 73 77 64 20 65 6e 74 72 79 2c ct passwd entry,
3190: 20 2a 72 65 73 75 6c 74 3b 0a 09 73 74 72 75 63 *result;..struc
31a0: 74 20 73 74 61 74 20 73 74 62 75 66 3b 0a 09 63 t stat stbuf;..c
31b0: 68 61 72 20 62 75 66 5b 31 30 32 34 5d 2c 20 2a har buf[1024], *
31c0: 72 65 74 76 61 6c 3b 0a 09 69 6e 74 20 67 70 75 retval;..int gpu
31d0: 5f 72 65 74 2c 20 73 74 61 74 5f 72 65 74 3b 0a _ret, stat_ret;.
31e0: 0a 09 67 70 75 5f 72 65 74 20 3d 20 67 65 74 70 ..gpu_ret = getp
31f0: 77 75 69 64 5f 72 28 66 73 75 69 64 2c 20 26 65 wuid_r(fsuid, &e
3200: 6e 74 72 79 2c 20 62 75 66 2c 20 73 69 7a 65 6f ntry, buf, sizeo
3210: 66 28 62 75 66 29 2c 20 26 72 65 73 75 6c 74 29 f(buf), &result)
3220: 3b 0a 09 69 66 20 28 67 70 75 5f 72 65 74 20 21 ;..if (gpu_ret !
3230: 3d 20 30 29 20 7b 0a 09 09 41 50 50 46 53 5f 44 = 0) {...APPFS_D
3240: 45 42 55 47 28 22 67 65 74 70 77 75 69 64 5f 72 EBUG("getpwuid_r
3250: 28 25 6c 6c 75 2c 20 2e 2e 2e 29 20 72 65 74 75 (%llu, ...) retu
3260: 72 6e 65 64 20 69 6e 20 66 61 69 6c 75 72 65 22 rned in failure"
3270: 2c 20 28 75 6e 73 69 67 6e 65 64 20 6c 6f 6e 67 , (unsigned long
3280: 20 6c 6f 6e 67 29 20 66 73 75 69 64 29 3b 0a 0a long) fsuid);..
3290: 09 09 72 65 74 75 72 6e 28 4e 55 4c 4c 29 3b 0a ..return(NULL);.
32a0: 09 7d 0a 0a 09 69 66 20 28 72 65 73 75 6c 74 20 .}...if (result
32b0: 3d 3d 20 4e 55 4c 4c 29 20 7b 0a 09 09 41 50 50 == NULL) {...APP
32c0: 46 53 5f 44 45 42 55 47 28 22 67 65 74 70 77 75 FS_DEBUG("getpwu
32d0: 69 64 5f 72 28 25 6c 6c 75 2c 20 2e 2e 2e 29 20 id_r(%llu, ...)
32e0: 72 65 74 75 72 6e 65 64 20 4e 55 4c 4c 20 72 65 returned NULL re
32f0: 73 75 6c 74 22 2c 20 28 75 6e 73 69 67 6e 65 64 sult", (unsigned
3300: 20 6c 6f 6e 67 20 6c 6f 6e 67 29 20 66 73 75 69 long long) fsui
3310: 64 29 3b 0a 0a 09 09 72 65 74 75 72 6e 28 4e 55 d);....return(NU
3320: 4c 4c 29 3b 0a 09 7d 0a 0a 09 69 66 20 28 72 65 LL);..}...if (re
3330: 73 75 6c 74 2d 3e 70 77 5f 64 69 72 20 3d 3d 20 sult->pw_dir ==
3340: 4e 55 4c 4c 29 20 7b 0a 09 09 41 50 50 46 53 5f NULL) {...APPFS_
3350: 44 45 42 55 47 28 22 67 65 74 70 77 75 69 64 5f DEBUG("getpwuid_
3360: 72 28 25 6c 6c 75 2c 20 2e 2e 2e 29 20 72 65 74 r(%llu, ...) ret
3370: 75 72 6e 65 64 20 4e 55 4c 4c 20 68 6f 6d 65 20 urned NULL home
3380: 64 69 72 65 63 74 6f 72 79 22 2c 20 28 75 6e 73 directory", (uns
3390: 69 67 6e 65 64 20 6c 6f 6e 67 20 6c 6f 6e 67 29 igned long long)
33a0: 20 66 73 75 69 64 29 3b 0a 0a 09 09 72 65 74 75 fsuid);....retu
33b0: 72 6e 28 4e 55 4c 4c 29 3b 0a 09 7d 0a 0a 09 73 rn(NULL);..}...s
33c0: 74 61 74 5f 72 65 74 20 3d 20 73 74 61 74 28 72 tat_ret = stat(r
33d0: 65 73 75 6c 74 2d 3e 70 77 5f 64 69 72 2c 20 26 esult->pw_dir, &
33e0: 73 74 62 75 66 29 3b 0a 09 69 66 20 28 73 74 61 stbuf);..if (sta
33f0: 74 5f 72 65 74 20 21 3d 20 30 29 20 7b 0a 09 09 t_ret != 0) {...
3400: 41 50 50 46 53 5f 44 45 42 55 47 28 22 73 74 61 APPFS_DEBUG("sta
3410: 74 28 25 73 29 20 72 65 74 75 72 6e 65 64 20 69 t(%s) returned i
3420: 6e 20 66 61 69 6c 75 72 65 22 2c 20 72 65 73 75 n failure", resu
3430: 6c 74 2d 3e 70 77 5f 64 69 72 29 3b 0a 0a 09 09 lt->pw_dir);....
3440: 72 65 74 75 72 6e 28 4e 55 4c 4c 29 3b 0a 09 7d return(NULL);..}
3450: 0a 0a 09 69 66 20 28 73 74 62 75 66 2e 73 74 5f ...if (stbuf.st_
3460: 75 69 64 20 21 3d 20 66 73 75 69 64 29 20 7b 0a uid != fsuid) {.
3470: 09 09 41 50 50 46 53 5f 44 45 42 55 47 28 22 55 ..APPFS_DEBUG("U
3480: 49 44 20 6d 69 73 2d 6d 61 74 63 68 20 6f 6e 20 ID mis-match on
3490: 75 73 65 72 20 25 6c 6c 75 27 73 20 68 6f 6d 65 user %llu's home
34a0: 20 64 69 72 65 63 74 6f 72 79 20 28 25 73 29 2e directory (%s).
34b0: 20 20 49 74 27 73 20 6f 77 6e 65 64 20 62 79 20 It's owned by
34c0: 25 6c 6c 75 2e 22 2c 0a 09 09 20 20 20 20 28 75 %llu.",... (u
34d0: 6e 73 69 67 6e 65 64 20 6c 6f 6e 67 20 6c 6f 6e nsigned long lon
34e0: 67 29 20 66 73 75 69 64 2c 0a 09 09 20 20 20 20 g) fsuid,...
34f0: 72 65 73 75 6c 74 2d 3e 70 77 5f 64 69 72 2c 0a result->pw_dir,.
3500: 09 09 20 20 20 20 28 75 6e 73 69 67 6e 65 64 20 .. (unsigned
3510: 6c 6f 6e 67 20 6c 6f 6e 67 29 20 73 74 62 75 66 long long) stbuf
3520: 2e 73 74 5f 75 69 64 0a 09 09 29 3b 0a 0a 09 09 .st_uid...);....
3530: 72 65 74 75 72 6e 28 4e 55 4c 4c 29 3b 0a 09 7d return(NULL);..}
3540: 0a 0a 09 72 65 74 76 61 6c 20 3d 20 73 74 72 64 ...retval = strd
3550: 75 70 28 72 65 73 75 6c 74 2d 3e 70 77 5f 64 69 up(result->pw_di
3560: 72 29 3b 0a 0a 09 72 65 74 75 72 6e 28 72 65 74 r);...return(ret
3570: 76 61 6c 29 3b 0a 7d 0a 0a 2f 2a 0a 20 2a 20 47 val);.}../*. * G
3580: 65 6e 65 72 61 74 65 20 61 6e 20 69 6e 6f 64 65 enerate an inode
3590: 20 66 6f 72 20 61 20 67 69 76 65 6e 20 70 61 74 for a given pat
35a0: 68 2e 20 20 54 68 65 20 69 6e 6f 64 65 20 73 68 h. The inode sh
35b0: 6f 75 6c 64 20 62 65 20 63 6f 6d 70 75 74 65 64 ould be computed
35c0: 20 69 6e 20 73 75 63 68 0a 20 2a 20 61 20 77 61 in such. * a wa
35d0: 79 20 74 68 61 74 20 69 74 20 69 73 20 75 6e 6c y that it is unl
35e0: 69 6b 65 6c 79 20 74 6f 20 62 65 20 64 75 70 6c ikely to be dupl
35f0: 69 63 61 74 65 64 20 61 6e 64 20 72 65 6d 61 69 icated and remai
3600: 6e 73 20 74 68 65 20 73 61 6d 65 20 66 6f 72 20 ns the same for
3610: 61 20 67 69 76 65 6e 0a 20 2a 20 66 69 6c 65 0a a given. * file.
3620: 20 2a 2f 0a 23 69 66 20 55 49 4e 54 5f 4d 41 58 */.#if UINT_MAX
3630: 20 3c 20 34 32 39 34 39 36 37 32 39 35 0a 23 65 < 4294967295.#e
3640: 72 72 6f 72 20 49 6e 74 65 67 65 72 20 73 69 7a rror Integer siz
3650: 65 20 69 73 20 74 6f 6f 20 73 6d 61 6c 6c 20 0a e is too small .
3660: 23 65 6e 64 69 66 0a 73 74 61 74 69 63 20 75 6e #endif.static un
3670: 73 69 67 6e 65 64 20 6c 6f 6e 67 20 6c 6f 6e 67 signed long long
3680: 20 61 70 70 66 73 5f 67 65 74 5f 70 61 74 68 5f appfs_get_path_
3690: 69 6e 6f 64 65 28 63 6f 6e 73 74 20 63 68 61 72 inode(const char
36a0: 20 2a 70 61 74 68 29 20 7b 0a 09 69 6e 74 20 72 *path) {..int r
36b0: 65 74 76 61 6c 3b 0a 09 63 6f 6e 73 74 20 63 68 etval;..const ch
36c0: 61 72 20 2a 70 3b 0a 0a 09 72 65 74 76 61 6c 20 ar *p;...retval
36d0: 3d 20 31 30 3b 0a 0a 09 66 6f 72 20 28 70 20 3d = 10;...for (p =
36e0: 20 70 61 74 68 3b 20 2a 70 3b 20 70 2b 2b 29 20 path; *p; p++)
36f0: 7b 0a 09 09 72 65 74 76 61 6c 20 25 3d 20 34 32 {...retval %= 42
3700: 39 30 39 36 30 32 39 30 55 4c 4c 3b 0a 09 09 72 90960290ULL;...r
3710: 65 74 76 61 6c 20 2b 3d 20 2a 70 3b 0a 09 09 72 etval += *p;...r
3720: 65 74 76 61 6c 20 3c 3c 3d 20 36 3b 0a 09 7d 0a etval <<= 6;..}.
3730: 0a 09 72 65 74 76 61 6c 20 2b 3d 20 31 30 3b 0a ..retval += 10;.
3740: 09 72 65 74 76 61 6c 20 25 3d 20 34 32 39 34 39 .retval %= 42949
3750: 36 37 32 38 36 55 4c 4c 3b 0a 09 72 65 74 76 61 67286ULL;..retva
3760: 6c 20 2b 3d 20 31 30 3b 0a 0a 09 72 65 74 75 72 l += 10;...retur
3770: 6e 28 72 65 74 76 61 6c 29 3b 0a 7d 0a 0a 2f 2a n(retval);.}../*
3780: 0a 20 2a 20 43 61 63 68 65 20 47 65 74 20 50 61 . * Cache Get Pa
3790: 74 68 20 49 6e 66 6f 20 6c 6f 6f 6b 75 70 73 20 th Info lookups
37a0: 66 6f 72 20 73 70 65 65 64 0a 20 2a 2f 0a 73 74 for speed. */.st
37b0: 61 74 69 63 20 69 6e 74 20 61 70 70 66 73 5f 67 atic int appfs_g
37c0: 65 74 5f 70 61 74 68 5f 69 6e 66 6f 5f 63 61 63 et_path_info_cac
37d0: 68 65 5f 67 65 74 28 63 6f 6e 73 74 20 63 68 61 he_get(const cha
37e0: 72 20 2a 70 61 74 68 2c 20 75 69 64 5f 74 20 75 r *path, uid_t u
37f0: 69 64 2c 20 73 74 72 75 63 74 20 61 70 70 66 73 id, struct appfs
3800: 5f 70 61 74 68 69 6e 66 6f 20 2a 70 61 74 68 69 _pathinfo *pathi
3810: 6e 66 6f 29 20 7b 0a 09 75 6e 73 69 67 6e 65 64 nfo) {..unsigned
3820: 20 69 6e 74 20 68 61 73 68 5f 69 64 78 3b 0a 09 int hash_idx;..
3830: 69 6e 74 20 70 74 68 72 65 61 64 5f 72 65 74 3b int pthread_ret;
3840: 0a 09 69 6e 74 20 72 65 74 76 61 6c 3b 0a 0a 09 ..int retval;...
3850: 72 65 74 76 61 6c 20 3d 20 31 3b 0a 0a 09 70 74 retval = 1;...pt
3860: 68 72 65 61 64 5f 72 65 74 20 3d 20 70 74 68 72 hread_ret = pthr
3870: 65 61 64 5f 6d 75 74 65 78 5f 6c 6f 63 6b 28 26 ead_mutex_lock(&
3880: 61 70 70 66 73 5f 70 61 74 68 5f 69 6e 66 6f 5f appfs_path_info_
3890: 63 61 63 68 65 5f 6d 75 74 65 78 29 3b 0a 09 69 cache_mutex);..i
38a0: 66 20 28 70 74 68 72 65 61 64 5f 72 65 74 20 21 f (pthread_ret !
38b0: 3d 20 30 29 20 7b 0a 09 09 41 50 50 46 53 5f 44 = 0) {...APPFS_D
38c0: 45 42 55 47 28 22 55 6e 61 62 6c 65 20 74 6f 20 EBUG("Unable to
38d0: 6c 6f 63 6b 20 70 61 74 68 5f 69 6e 66 6f 20 63 lock path_info c
38e0: 61 63 68 65 20 6d 75 74 65 78 20 21 22 29 3b 0a ache mutex !");.
38f0: 0a 09 09 72 65 74 75 72 6e 28 2d 31 29 3b 0a 09 ...return(-1);..
3900: 7d 0a 0a 09 69 66 20 28 61 70 70 66 73 5f 70 61 }...if (appfs_pa
3910: 74 68 5f 69 6e 66 6f 5f 63 61 63 68 65 20 21 3d th_info_cache !=
3920: 20 4e 55 4c 4c 29 20 7b 0a 09 09 68 61 73 68 5f NULL) {...hash_
3930: 69 64 78 20 3d 20 28 61 70 70 66 73 5f 67 65 74 idx = (appfs_get
3940: 5f 70 61 74 68 5f 69 6e 6f 64 65 28 70 61 74 68 _path_inode(path
3950: 29 20 2b 20 75 69 64 29 20 25 20 61 70 70 66 73 ) + uid) % appfs
3960: 5f 70 61 74 68 5f 69 6e 66 6f 5f 63 61 63 68 65 _path_info_cache
3970: 5f 73 69 7a 65 3b 0a 0a 09 09 69 66 20 28 61 70 _size;....if (ap
3980: 70 66 73 5f 70 61 74 68 5f 69 6e 66 6f 5f 63 61 pfs_path_info_ca
3990: 63 68 65 5b 68 61 73 68 5f 69 64 78 5d 2e 5f 63 che[hash_idx]._c
39a0: 61 63 68 65 5f 70 61 74 68 20 21 3d 20 4e 55 4c ache_path != NUL
39b0: 4c 29 20 7b 0a 09 09 09 69 66 20 28 73 74 72 63 L) {....if (strc
39c0: 6d 70 28 61 70 70 66 73 5f 70 61 74 68 5f 69 6e mp(appfs_path_in
39d0: 66 6f 5f 63 61 63 68 65 5b 68 61 73 68 5f 69 64 fo_cache[hash_id
39e0: 78 5d 2e 5f 63 61 63 68 65 5f 70 61 74 68 2c 20 x]._cache_path,
39f0: 70 61 74 68 29 20 3d 3d 20 30 20 26 26 20 61 70 path) == 0 && ap
3a00: 70 66 73 5f 70 61 74 68 5f 69 6e 66 6f 5f 63 61 pfs_path_info_ca
3a10: 63 68 65 5b 68 61 73 68 5f 69 64 78 5d 2e 5f 63 che[hash_idx]._c
3a20: 61 63 68 65 5f 75 69 64 20 3d 3d 20 75 69 64 29 ache_uid == uid)
3a30: 20 7b 0a 09 09 09 09 72 65 74 76 61 6c 20 3d 20 {.....retval =
3a40: 30 3b 0a 0a 09 09 09 09 6d 65 6d 63 70 79 28 70 0;......memcpy(p
3a50: 61 74 68 69 6e 66 6f 2c 20 26 61 70 70 66 73 5f athinfo, &appfs_
3a60: 70 61 74 68 5f 69 6e 66 6f 5f 63 61 63 68 65 5b path_info_cache[
3a70: 68 61 73 68 5f 69 64 78 5d 2c 20 73 69 7a 65 6f hash_idx], sizeo
3a80: 66 28 2a 70 61 74 68 69 6e 66 6f 29 29 3b 0a 09 f(*pathinfo));..
3a90: 09 09 09 70 61 74 68 69 6e 66 6f 2d 3e 5f 63 61 ...pathinfo->_ca
3aa0: 63 68 65 5f 70 61 74 68 20 3d 20 4e 55 4c 4c 3b che_path = NULL;
3ab0: 0a 09 09 09 7d 0a 09 09 7d 0a 09 7d 0a 0a 09 70 ....}...}..}...p
3ac0: 74 68 72 65 61 64 5f 72 65 74 20 3d 20 70 74 68 thread_ret = pth
3ad0: 72 65 61 64 5f 6d 75 74 65 78 5f 75 6e 6c 6f 63 read_mutex_unloc
3ae0: 6b 28 26 61 70 70 66 73 5f 70 61 74 68 5f 69 6e k(&appfs_path_in
3af0: 66 6f 5f 63 61 63 68 65 5f 6d 75 74 65 78 29 3b fo_cache_mutex);
3b00: 0a 09 69 66 20 28 70 74 68 72 65 61 64 5f 72 65 ..if (pthread_re
3b10: 74 20 21 3d 20 30 29 20 7b 0a 09 09 41 50 50 46 t != 0) {...APPF
3b20: 53 5f 44 45 42 55 47 28 22 55 6e 61 62 6c 65 20 S_DEBUG("Unable
3b30: 74 6f 20 75 6e 6c 6f 63 6b 20 70 61 74 68 5f 69 to unlock path_i
3b40: 6e 66 6f 20 63 61 63 68 65 20 6d 75 74 65 78 20 nfo cache mutex
3b50: 21 22 29 3b 0a 0a 09 09 72 65 74 75 72 6e 28 2d !");....return(-
3b60: 31 29 3b 0a 09 7d 0a 0a 09 69 66 20 28 72 65 74 1);..}...if (ret
3b70: 76 61 6c 20 3d 3d 20 30 29 20 7b 0a 09 09 41 50 val == 0) {...AP
3b80: 50 46 53 5f 44 45 42 55 47 28 22 43 61 63 68 65 PFS_DEBUG("Cache
3b90: 20 68 69 74 20 6f 6e 20 25 73 22 2c 20 70 61 74 hit on %s", pat
3ba0: 68 29 3b 0a 09 7d 20 65 6c 73 65 20 7b 0a 09 09 h);..} else {...
3bb0: 41 50 50 46 53 5f 44 45 42 55 47 28 22 43 61 63 APPFS_DEBUG("Cac
3bc0: 68 65 20 6d 69 73 73 20 6f 6e 20 25 73 22 2c 20 he miss on %s",
3bd0: 70 61 74 68 29 3b 0a 09 7d 0a 0a 09 72 65 74 75 path);..}...retu
3be0: 72 6e 28 72 65 74 76 61 6c 29 3b 0a 7d 0a 0a 73 rn(retval);.}..s
3bf0: 74 61 74 69 63 20 76 6f 69 64 20 61 70 70 66 73 tatic void appfs
3c00: 5f 67 65 74 5f 70 61 74 68 5f 69 6e 66 6f 5f 63 _get_path_info_c
3c10: 61 63 68 65 5f 61 64 64 28 63 6f 6e 73 74 20 63 ache_add(const c
3c20: 68 61 72 20 2a 70 61 74 68 2c 20 75 69 64 5f 74 har *path, uid_t
3c30: 20 75 69 64 2c 20 73 74 72 75 63 74 20 61 70 70 uid, struct app
3c40: 66 73 5f 70 61 74 68 69 6e 66 6f 20 2a 70 61 74 fs_pathinfo *pat
3c50: 68 69 6e 66 6f 29 20 7b 0a 09 75 6e 73 69 67 6e hinfo) {..unsign
3c60: 65 64 20 69 6e 74 20 68 61 73 68 5f 69 64 78 3b ed int hash_idx;
3c70: 0a 09 69 6e 74 20 70 74 68 72 65 61 64 5f 72 65 ..int pthread_re
3c80: 74 3b 0a 0a 09 70 74 68 72 65 61 64 5f 72 65 74 t;...pthread_ret
3c90: 20 3d 20 70 74 68 72 65 61 64 5f 6d 75 74 65 78 = pthread_mutex
3ca0: 5f 6c 6f 63 6b 28 26 61 70 70 66 73 5f 70 61 74 _lock(&appfs_pat
3cb0: 68 5f 69 6e 66 6f 5f 63 61 63 68 65 5f 6d 75 74 h_info_cache_mut
3cc0: 65 78 29 3b 0a 09 69 66 20 28 70 74 68 72 65 61 ex);..if (pthrea
3cd0: 64 5f 72 65 74 20 21 3d 20 30 29 20 7b 0a 09 09 d_ret != 0) {...
3ce0: 41 50 50 46 53 5f 44 45 42 55 47 28 22 55 6e 61 APPFS_DEBUG("Una
3cf0: 62 6c 65 20 74 6f 20 6c 6f 63 6b 20 70 61 74 68 ble to lock path
3d00: 5f 69 6e 66 6f 20 63 61 63 68 65 20 6d 75 74 65 _info cache mute
3d10: 78 20 21 22 29 3b 0a 0a 09 09 72 65 74 75 72 6e x !");....return
3d20: 3b 0a 09 7d 0a 0a 09 69 66 20 28 61 70 70 66 73 ;..}...if (appfs
3d30: 5f 70 61 74 68 5f 69 6e 66 6f 5f 63 61 63 68 65 _path_info_cache
3d40: 20 3d 3d 20 4e 55 4c 4c 29 20 7b 0a 09 09 61 70 == NULL) {...ap
3d50: 70 66 73 5f 70 61 74 68 5f 69 6e 66 6f 5f 63 61 pfs_path_info_ca
3d60: 63 68 65 20 3d 20 63 61 6c 6c 6f 63 28 61 70 70 che = calloc(app
3d70: 66 73 5f 70 61 74 68 5f 69 6e 66 6f 5f 63 61 63 fs_path_info_cac
3d80: 68 65 5f 73 69 7a 65 2c 20 73 69 7a 65 6f 66 28 he_size, sizeof(
3d90: 2a 61 70 70 66 73 5f 70 61 74 68 5f 69 6e 66 6f *appfs_path_info
3da0: 5f 63 61 63 68 65 29 29 3b 0a 09 7d 0a 0a 09 68 _cache));..}...h
3db0: 61 73 68 5f 69 64 78 20 3d 20 28 61 70 70 66 73 ash_idx = (appfs
3dc0: 5f 67 65 74 5f 70 61 74 68 5f 69 6e 6f 64 65 28 _get_path_inode(
3dd0: 70 61 74 68 29 20 2b 20 75 69 64 29 20 25 20 61 path) + uid) % a
3de0: 70 70 66 73 5f 70 61 74 68 5f 69 6e 66 6f 5f 63 ppfs_path_info_c
3df0: 61 63 68 65 5f 73 69 7a 65 3b 0a 0a 09 69 66 20 ache_size;...if
3e00: 28 61 70 70 66 73 5f 70 61 74 68 5f 69 6e 66 6f (appfs_path_info
3e10: 5f 63 61 63 68 65 5b 68 61 73 68 5f 69 64 78 5d _cache[hash_idx]
3e20: 2e 5f 63 61 63 68 65 5f 70 61 74 68 20 21 3d 20 ._cache_path !=
3e30: 4e 55 4c 4c 29 20 7b 0a 09 09 66 72 65 65 28 61 NULL) {...free(a
3e40: 70 70 66 73 5f 70 61 74 68 5f 69 6e 66 6f 5f 63 ppfs_path_info_c
3e50: 61 63 68 65 5b 68 61 73 68 5f 69 64 78 5d 2e 5f ache[hash_idx]._
3e60: 63 61 63 68 65 5f 70 61 74 68 29 3b 0a 09 7d 0a cache_path);..}.
3e70: 0a 09 6d 65 6d 63 70 79 28 26 61 70 70 66 73 5f ..memcpy(&appfs_
3e80: 70 61 74 68 5f 69 6e 66 6f 5f 63 61 63 68 65 5b path_info_cache[
3e90: 68 61 73 68 5f 69 64 78 5d 2c 20 70 61 74 68 69 hash_idx], pathi
3ea0: 6e 66 6f 2c 20 73 69 7a 65 6f 66 28 2a 70 61 74 nfo, sizeof(*pat
3eb0: 68 69 6e 66 6f 29 29 3b 0a 0a 09 61 70 70 66 73 hinfo));...appfs
3ec0: 5f 70 61 74 68 5f 69 6e 66 6f 5f 63 61 63 68 65 _path_info_cache
3ed0: 5b 68 61 73 68 5f 69 64 78 5d 2e 5f 63 61 63 68 [hash_idx]._cach
3ee0: 65 5f 70 61 74 68 20 3d 20 73 74 72 64 75 70 28 e_path = strdup(
3ef0: 70 61 74 68 29 3b 0a 09 61 70 70 66 73 5f 70 61 path);..appfs_pa
3f00: 74 68 5f 69 6e 66 6f 5f 63 61 63 68 65 5b 68 61 th_info_cache[ha
3f10: 73 68 5f 69 64 78 5d 2e 5f 63 61 63 68 65 5f 75 sh_idx]._cache_u
3f20: 69 64 20 20 3d 20 75 69 64 3b 0a 0a 09 70 74 68 id = uid;...pth
3f30: 72 65 61 64 5f 72 65 74 20 3d 20 70 74 68 72 65 read_ret = pthre
3f40: 61 64 5f 6d 75 74 65 78 5f 75 6e 6c 6f 63 6b 28 ad_mutex_unlock(
3f50: 26 61 70 70 66 73 5f 70 61 74 68 5f 69 6e 66 6f &appfs_path_info
3f60: 5f 63 61 63 68 65 5f 6d 75 74 65 78 29 3b 0a 09 _cache_mutex);..
3f70: 69 66 20 28 70 74 68 72 65 61 64 5f 72 65 74 20 if (pthread_ret
3f80: 21 3d 20 30 29 20 7b 0a 09 09 41 50 50 46 53 5f != 0) {...APPFS_
3f90: 44 45 42 55 47 28 22 55 6e 61 62 6c 65 20 74 6f DEBUG("Unable to
3fa0: 20 75 6e 6c 6f 63 6b 20 70 61 74 68 5f 69 6e 66 unlock path_inf
3fb0: 6f 20 63 61 63 68 65 20 6d 75 74 65 78 20 21 22 o cache mutex !"
3fc0: 29 3b 0a 0a 09 09 72 65 74 75 72 6e 3b 0a 09 7d );....return;..}
3fd0: 0a 0a 09 72 65 74 75 72 6e 3b 0a 7d 0a 0a 73 74 ...return;.}..st
3fe0: 61 74 69 63 20 76 6f 69 64 20 61 70 70 66 73 5f atic void appfs_
3ff0: 67 65 74 5f 70 61 74 68 5f 69 6e 66 6f 5f 63 61 get_path_info_ca
4000: 63 68 65 5f 72 6d 28 63 6f 6e 73 74 20 63 68 61 che_rm(const cha
4010: 72 20 2a 70 61 74 68 2c 20 75 69 64 5f 74 20 75 r *path, uid_t u
4020: 69 64 29 20 7b 0a 09 75 6e 73 69 67 6e 65 64 20 id) {..unsigned
4030: 69 6e 74 20 68 61 73 68 5f 69 64 78 3b 0a 09 69 int hash_idx;..i
4040: 6e 74 20 70 74 68 72 65 61 64 5f 72 65 74 3b 0a nt pthread_ret;.
4050: 0a 09 70 74 68 72 65 61 64 5f 72 65 74 20 3d 20 ..pthread_ret =
4060: 70 74 68 72 65 61 64 5f 6d 75 74 65 78 5f 6c 6f pthread_mutex_lo
4070: 63 6b 28 26 61 70 70 66 73 5f 70 61 74 68 5f 69 ck(&appfs_path_i
4080: 6e 66 6f 5f 63 61 63 68 65 5f 6d 75 74 65 78 29 nfo_cache_mutex)
4090: 3b 0a 09 69 66 20 28 70 74 68 72 65 61 64 5f 72 ;..if (pthread_r
40a0: 65 74 20 21 3d 20 30 29 20 7b 0a 09 09 41 50 50 et != 0) {...APP
40b0: 46 53 5f 44 45 42 55 47 28 22 55 6e 61 62 6c 65 FS_DEBUG("Unable
40c0: 20 74 6f 20 6c 6f 63 6b 20 70 61 74 68 5f 69 6e to lock path_in
40d0: 66 6f 20 63 61 63 68 65 20 6d 75 74 65 78 20 21 fo cache mutex !
40e0: 22 29 3b 0a 0a 09 09 72 65 74 75 72 6e 3b 0a 09 ");....return;..
40f0: 7d 0a 0a 09 69 66 20 28 61 70 70 66 73 5f 70 61 }...if (appfs_pa
4100: 74 68 5f 69 6e 66 6f 5f 63 61 63 68 65 20 21 3d th_info_cache !=
4110: 20 4e 55 4c 4c 29 20 7b 0a 09 09 68 61 73 68 5f NULL) {...hash_
4120: 69 64 78 20 3d 20 28 61 70 70 66 73 5f 67 65 74 idx = (appfs_get
4130: 5f 70 61 74 68 5f 69 6e 6f 64 65 28 70 61 74 68 _path_inode(path
4140: 29 20 2b 20 75 69 64 29 20 25 20 61 70 70 66 73 ) + uid) % appfs
4150: 5f 70 61 74 68 5f 69 6e 66 6f 5f 63 61 63 68 65 _path_info_cache
4160: 5f 73 69 7a 65 3b 0a 0a 09 09 69 66 20 28 61 70 _size;....if (ap
4170: 70 66 73 5f 70 61 74 68 5f 69 6e 66 6f 5f 63 61 pfs_path_info_ca
4180: 63 68 65 5b 68 61 73 68 5f 69 64 78 5d 2e 5f 63 che[hash_idx]._c
4190: 61 63 68 65 5f 70 61 74 68 20 21 3d 20 4e 55 4c ache_path != NUL
41a0: 4c 29 20 7b 0a 09 09 09 66 72 65 65 28 61 70 70 L) {....free(app
41b0: 66 73 5f 70 61 74 68 5f 69 6e 66 6f 5f 63 61 63 fs_path_info_cac
41c0: 68 65 5b 68 61 73 68 5f 69 64 78 5d 2e 5f 63 61 he[hash_idx]._ca
41d0: 63 68 65 5f 70 61 74 68 29 3b 0a 0a 09 09 09 61 che_path);.....a
41e0: 70 70 66 73 5f 70 61 74 68 5f 69 6e 66 6f 5f 63 ppfs_path_info_c
41f0: 61 63 68 65 5b 68 61 73 68 5f 69 64 78 5d 2e 5f ache[hash_idx]._
4200: 63 61 63 68 65 5f 70 61 74 68 20 3d 20 4e 55 4c cache_path = NUL
4210: 4c 3b 0a 09 09 7d 0a 09 7d 0a 0a 09 70 74 68 72 L;...}..}...pthr
4220: 65 61 64 5f 72 65 74 20 3d 20 70 74 68 72 65 61 ead_ret = pthrea
4230: 64 5f 6d 75 74 65 78 5f 75 6e 6c 6f 63 6b 28 26 d_mutex_unlock(&
4240: 61 70 70 66 73 5f 70 61 74 68 5f 69 6e 66 6f 5f appfs_path_info_
4250: 63 61 63 68 65 5f 6d 75 74 65 78 29 3b 0a 09 69 cache_mutex);..i
4260: 66 20 28 70 74 68 72 65 61 64 5f 72 65 74 20 21 f (pthread_ret !
4270: 3d 20 30 29 20 7b 0a 09 09 41 50 50 46 53 5f 44 = 0) {...APPFS_D
4280: 45 42 55 47 28 22 55 6e 61 62 6c 65 20 74 6f 20 EBUG("Unable to
4290: 75 6e 6c 6f 63 6b 20 70 61 74 68 5f 69 6e 66 6f unlock path_info
42a0: 20 63 61 63 68 65 20 6d 75 74 65 78 20 21 22 29 cache mutex !")
42b0: 3b 0a 0a 09 09 72 65 74 75 72 6e 3b 0a 09 7d 0a ;....return;..}.
42c0: 0a 09 72 65 74 75 72 6e 3b 0a 7d 0a 0a 73 74 61 ..return;.}..sta
42d0: 74 69 63 20 76 6f 69 64 20 61 70 70 66 73 5f 67 tic void appfs_g
42e0: 65 74 5f 70 61 74 68 5f 69 6e 66 6f 5f 63 61 63 et_path_info_cac
42f0: 68 65 5f 66 6c 75 73 68 28 75 69 64 5f 74 20 75 he_flush(uid_t u
4300: 69 64 2c 20 69 6e 74 20 6e 65 77 5f 73 69 7a 65 id, int new_size
4310: 29 20 7b 0a 09 75 6e 73 69 67 6e 65 64 20 69 6e ) {..unsigned in
4320: 74 20 69 64 78 3b 0a 09 69 6e 74 20 70 74 68 72 t idx;..int pthr
4330: 65 61 64 5f 72 65 74 3b 0a 0a 09 41 50 50 46 53 ead_ret;...APPFS
4340: 5f 44 45 42 55 47 28 22 46 6c 75 73 68 69 6e 67 _DEBUG("Flushing
4350: 20 41 70 70 46 53 20 63 61 63 68 65 20 28 75 69 AppFS cache (ui
4360: 64 20 3d 20 25 6c 6c 69 2c 20 6e 65 77 5f 73 69 d = %lli, new_si
4370: 7a 65 20 3d 20 25 69 29 22 2c 20 28 6c 6f 6e 67 ze = %i)", (long
4380: 20 6c 6f 6e 67 29 20 75 69 64 2c 20 6e 65 77 5f long) uid, new_
4390: 73 69 7a 65 29 3b 0a 0a 09 70 74 68 72 65 61 64 size);...pthread
43a0: 5f 72 65 74 20 3d 20 70 74 68 72 65 61 64 5f 6d _ret = pthread_m
43b0: 75 74 65 78 5f 6c 6f 63 6b 28 26 61 70 70 66 73 utex_lock(&appfs
43c0: 5f 70 61 74 68 5f 69 6e 66 6f 5f 63 61 63 68 65 _path_info_cache
43d0: 5f 6d 75 74 65 78 29 3b 0a 09 69 66 20 28 70 74 _mutex);..if (pt
43e0: 68 72 65 61 64 5f 72 65 74 20 21 3d 20 30 29 20 hread_ret != 0)
43f0: 7b 0a 09 09 41 50 50 46 53 5f 44 45 42 55 47 28 {...APPFS_DEBUG(
4400: 22 55 6e 61 62 6c 65 20 74 6f 20 6c 6f 63 6b 20 "Unable to lock
4410: 70 61 74 68 5f 69 6e 66 6f 20 63 61 63 68 65 20 path_info cache
4420: 6d 75 74 65 78 20 21 22 29 3b 0a 0a 09 09 72 65 mutex !");....re
4430: 74 75 72 6e 3b 0a 09 7d 0a 0a 09 69 66 20 28 61 turn;..}...if (a
4440: 70 70 66 73 5f 70 61 74 68 5f 69 6e 66 6f 5f 63 ppfs_path_info_c
4450: 61 63 68 65 20 21 3d 20 4e 55 4c 4c 29 20 7b 0a ache != NULL) {.
4460: 09 09 66 6f 72 20 28 69 64 78 20 3d 20 30 3b 20 ..for (idx = 0;
4470: 69 64 78 20 3c 20 61 70 70 66 73 5f 70 61 74 68 idx < appfs_path
4480: 5f 69 6e 66 6f 5f 63 61 63 68 65 5f 73 69 7a 65 _info_cache_size
4490: 3b 20 69 64 78 2b 2b 29 20 7b 0a 09 09 09 69 66 ; idx++) {....if
44a0: 20 28 61 70 70 66 73 5f 70 61 74 68 5f 69 6e 66 (appfs_path_inf
44b0: 6f 5f 63 61 63 68 65 5b 69 64 78 5d 2e 5f 63 61 o_cache[idx]._ca
44c0: 63 68 65 5f 70 61 74 68 20 21 3d 20 4e 55 4c 4c che_path != NULL
44d0: 29 20 7b 0a 09 09 09 09 69 66 20 28 75 69 64 20 ) {.....if (uid
44e0: 21 3d 20 28 28 75 69 64 5f 74 29 20 2d 31 29 29 != ((uid_t) -1))
44f0: 20 7b 0a 09 09 09 09 09 69 66 20 28 61 70 70 66 {......if (appf
4500: 73 5f 70 61 74 68 5f 69 6e 66 6f 5f 63 61 63 68 s_path_info_cach
4510: 65 5b 69 64 78 5d 2e 5f 63 61 63 68 65 5f 75 69 e[idx]._cache_ui
4520: 64 20 21 3d 20 75 69 64 29 20 7b 0a 09 09 09 09 d != uid) {.....
4530: 09 09 63 6f 6e 74 69 6e 75 65 3b 0a 09 09 09 09 ..continue;.....
4540: 09 7d 0a 09 09 09 09 7d 0a 0a 09 09 09 09 66 72 .}.....}......fr
4550: 65 65 28 61 70 70 66 73 5f 70 61 74 68 5f 69 6e ee(appfs_path_in
4560: 66 6f 5f 63 61 63 68 65 5b 69 64 78 5d 2e 5f 63 fo_cache[idx]._c
4570: 61 63 68 65 5f 70 61 74 68 29 3b 0a 0a 09 09 09 ache_path);.....
4580: 09 61 70 70 66 73 5f 70 61 74 68 5f 69 6e 66 6f .appfs_path_info
4590: 5f 63 61 63 68 65 5b 69 64 78 5d 2e 5f 63 61 63 _cache[idx]._cac
45a0: 68 65 5f 70 61 74 68 20 3d 20 4e 55 4c 4c 3b 0a he_path = NULL;.
45b0: 09 09 09 7d 0a 09 09 7d 0a 09 7d 0a 0a 09 69 66 ...}...}..}...if
45c0: 20 28 75 69 64 20 3d 3d 20 28 28 75 69 64 5f 74 (uid == ((uid_t
45d0: 29 20 2d 31 29 29 20 7b 0a 09 09 66 72 65 65 28 ) -1)) {...free(
45e0: 61 70 70 66 73 5f 70 61 74 68 5f 69 6e 66 6f 5f appfs_path_info_
45f0: 63 61 63 68 65 29 3b 0a 0a 09 09 61 70 70 66 73 cache);....appfs
4600: 5f 70 61 74 68 5f 69 6e 66 6f 5f 63 61 63 68 65 _path_info_cache
4610: 20 3d 20 4e 55 4c 4c 3b 0a 0a 09 09 69 66 20 28 = NULL;....if (
4620: 6e 65 77 5f 73 69 7a 65 20 21 3d 20 2d 31 29 20 new_size != -1)
4630: 7b 0a 09 09 09 61 70 70 66 73 5f 70 61 74 68 5f {....appfs_path_
4640: 69 6e 66 6f 5f 63 61 63 68 65 5f 73 69 7a 65 20 info_cache_size
4650: 3d 20 6e 65 77 5f 73 69 7a 65 3b 0a 09 09 7d 0a = new_size;...}.
4660: 09 7d 0a 0a 09 70 74 68 72 65 61 64 5f 72 65 74 .}...pthread_ret
4670: 20 3d 20 70 74 68 72 65 61 64 5f 6d 75 74 65 78 = pthread_mutex
4680: 5f 75 6e 6c 6f 63 6b 28 26 61 70 70 66 73 5f 70 _unlock(&appfs_p
4690: 61 74 68 5f 69 6e 66 6f 5f 63 61 63 68 65 5f 6d ath_info_cache_m
46a0: 75 74 65 78 29 3b 0a 09 69 66 20 28 70 74 68 72 utex);..if (pthr
46b0: 65 61 64 5f 72 65 74 20 21 3d 20 30 29 20 7b 0a ead_ret != 0) {.
46c0: 09 09 41 50 50 46 53 5f 44 45 42 55 47 28 22 55 ..APPFS_DEBUG("U
46d0: 6e 61 62 6c 65 20 74 6f 20 75 6e 6c 6f 63 6b 20 nable to unlock
46e0: 70 61 74 68 5f 69 6e 66 6f 20 63 61 63 68 65 20 path_info cache
46f0: 6d 75 74 65 78 20 21 22 29 3b 0a 0a 09 09 72 65 mutex !");....re
4700: 74 75 72 6e 3b 0a 09 7d 0a 0a 09 72 65 74 75 72 turn;..}...retur
4710: 6e 3b 0a 7d 0a 0a 2f 2a 20 47 65 74 20 69 6e 66 n;.}../* Get inf
4720: 6f 72 6d 61 74 69 6f 6e 20 61 62 6f 75 74 20 61 ormation about a
4730: 20 70 61 74 68 2c 20 61 6e 64 20 6f 70 74 69 6f path, and optio
4740: 6e 61 6c 6c 79 20 6c 69 73 74 20 63 68 69 6c 64 nally list child
4750: 72 65 6e 20 2a 2f 0a 73 74 61 74 69 63 20 69 6e ren */.static in
4760: 74 20 61 70 70 66 73 5f 67 65 74 5f 70 61 74 68 t appfs_get_path
4770: 5f 69 6e 66 6f 28 63 6f 6e 73 74 20 63 68 61 72 _info(const char
4780: 20 2a 70 61 74 68 2c 20 73 74 72 75 63 74 20 61 *path, struct a
4790: 70 70 66 73 5f 70 61 74 68 69 6e 66 6f 20 2a 70 ppfs_pathinfo *p
47a0: 61 74 68 69 6e 66 6f 29 20 7b 0a 09 54 63 6c 5f athinfo) {..Tcl_
47b0: 49 6e 74 65 72 70 20 2a 69 6e 74 65 72 70 3b 0a Interp *interp;.
47c0: 09 54 63 6c 5f 4f 62 6a 20 2a 61 74 74 72 73 5f .Tcl_Obj *attrs_
47d0: 64 69 63 74 2c 20 2a 61 74 74 72 5f 76 61 6c 75 dict, *attr_valu
47e0: 65 3b 0a 09 63 6f 6e 73 74 20 63 68 61 72 20 2a e;..const char *
47f0: 61 74 74 72 5f 76 61 6c 75 65 5f 73 74 72 3b 0a attr_value_str;.
4800: 09 54 63 6c 5f 57 69 64 65 49 6e 74 20 61 74 74 .Tcl_WideInt att
4810: 72 5f 76 61 6c 75 65 5f 77 69 64 65 3b 0a 09 69 r_value_wide;..i
4820: 6e 74 20 61 74 74 72 5f 76 61 6c 75 65 5f 69 6e nt attr_value_in
4830: 74 3b 0a 09 73 74 61 74 69 63 20 5f 5f 74 68 72 t;..static __thr
4840: 65 61 64 20 54 63 6c 5f 4f 62 6a 20 2a 61 74 74 ead Tcl_Obj *att
4850: 72 5f 6b 65 79 5f 74 79 70 65 20 3d 20 4e 55 4c r_key_type = NUL
4860: 4c 2c 20 2a 61 74 74 72 5f 6b 65 79 5f 70 65 72 L, *attr_key_per
4870: 6d 73 20 3d 20 4e 55 4c 4c 2c 20 2a 61 74 74 72 ms = NULL, *attr
4880: 5f 6b 65 79 5f 73 69 7a 65 20 3d 20 4e 55 4c 4c _key_size = NULL
4890: 2c 20 2a 61 74 74 72 5f 6b 65 79 5f 74 69 6d 65 , *attr_key_time
48a0: 20 3d 20 4e 55 4c 4c 2c 20 2a 61 74 74 72 5f 6b = NULL, *attr_k
48b0: 65 79 5f 73 6f 75 72 63 65 20 3d 20 4e 55 4c 4c ey_source = NULL
48c0: 2c 20 2a 61 74 74 72 5f 6b 65 79 5f 63 68 69 6c , *attr_key_chil
48d0: 64 63 6f 75 6e 74 20 3d 20 4e 55 4c 4c 2c 20 2a dcount = NULL, *
48e0: 61 74 74 72 5f 6b 65 79 5f 70 61 63 6b 61 67 65 attr_key_package
48f0: 64 20 3d 20 4e 55 4c 4c 3b 0a 09 69 6e 74 20 63 d = NULL;..int c
4900: 61 63 68 65 5f 72 65 74 3b 0a 09 69 6e 74 20 74 ache_ret;..int t
4910: 63 6c 5f 72 65 74 3b 0a 09 69 6e 74 20 72 65 74 cl_ret;..int ret
4920: 76 61 6c 3b 0a 09 75 69 64 5f 74 20 66 73 75 69 val;..uid_t fsui
4930: 64 3b 0a 0a 09 72 65 74 76 61 6c 20 3d 20 30 3b d;...retval = 0;
4940: 0a 0a 09 66 73 75 69 64 20 3d 20 61 70 70 66 73 ...fsuid = appfs
4950: 5f 67 65 74 5f 66 73 75 69 64 28 29 3b 0a 0a 09 _get_fsuid();...
4960: 63 61 63 68 65 5f 72 65 74 20 3d 20 61 70 70 66 cache_ret = appf
4970: 73 5f 67 65 74 5f 70 61 74 68 5f 69 6e 66 6f 5f s_get_path_info_
4980: 63 61 63 68 65 5f 67 65 74 28 70 61 74 68 2c 20 cache_get(path,
4990: 66 73 75 69 64 2c 20 70 61 74 68 69 6e 66 6f 29 fsuid, pathinfo)
49a0: 3b 0a 09 69 66 20 28 63 61 63 68 65 5f 72 65 74 ;..if (cache_ret
49b0: 20 3d 3d 20 30 29 20 7b 0a 09 09 69 66 20 28 70 == 0) {...if (p
49c0: 61 74 68 69 6e 66 6f 2d 3e 74 79 70 65 20 3d 3d athinfo->type ==
49d0: 20 41 50 50 46 53 5f 50 41 54 48 54 59 50 45 5f APPFS_PATHTYPE_
49e0: 44 4f 45 53 5f 4e 4f 54 5f 45 58 49 53 54 29 20 DOES_NOT_EXIST)
49f0: 7b 0a 09 09 09 41 50 50 46 53 5f 44 45 42 55 47 {....APPFS_DEBUG
4a00: 28 22 52 65 74 75 72 6e 69 6e 67 20 66 72 6f 6d ("Returning from
4a10: 20 63 61 63 68 65 3a 20 64 6f 65 73 20 6e 6f 74 cache: does not
4a20: 20 65 78 69 73 74 20 5c 22 25 73 5c 22 22 2c 20 exist \"%s\"",
4a30: 70 61 74 68 29 3b 0a 0a 09 09 09 72 65 74 75 72 path);.....retur
4a40: 6e 28 2d 45 4e 4f 45 4e 54 29 3b 0a 09 09 7d 0a n(-ENOENT);...}.
4a50: 0a 09 09 69 66 20 28 70 61 74 68 69 6e 66 6f 2d ...if (pathinfo-
4a60: 3e 74 79 70 65 20 3d 3d 20 41 50 50 46 53 5f 50 >type == APPFS_P
4a70: 41 54 48 54 59 50 45 5f 49 4e 56 41 4c 49 44 29 ATHTYPE_INVALID)
4a80: 20 7b 0a 09 09 09 41 50 50 46 53 5f 44 45 42 55 {....APPFS_DEBU
4a90: 47 28 22 52 65 74 75 72 6e 69 6e 67 20 66 72 6f G("Returning fro
4aa0: 6d 20 63 61 63 68 65 3a 20 69 6e 76 61 6c 69 64 m cache: invalid
4ab0: 20 6f 62 6a 65 63 74 20 5c 22 25 73 5c 22 22 2c object \"%s\"",
4ac0: 20 70 61 74 68 29 3b 0a 0a 09 09 09 72 65 74 75 path);.....retu
4ad0: 72 6e 28 2d 45 49 4f 29 3b 0a 09 09 7d 0a 0a 09 rn(-EIO);...}...
4ae0: 09 72 65 74 75 72 6e 28 30 29 3b 0a 09 7d 0a 0a .return(0);..}..
4af0: 09 69 6e 74 65 72 70 20 3d 20 61 70 70 66 73 5f .interp = appfs_
4b00: 54 63 6c 49 6e 74 65 72 70 28 29 3b 0a 09 69 66 TclInterp();..if
4b10: 20 28 69 6e 74 65 72 70 20 3d 3d 20 4e 55 4c 4c (interp == NULL
4b20: 29 20 7b 0a 09 09 41 50 50 46 53 5f 44 45 42 55 ) {...APPFS_DEBU
4b30: 47 28 22 65 72 72 6f 72 3a 20 55 6e 61 62 6c 65 G("error: Unable
4b40: 20 74 6f 20 67 65 74 20 61 6e 20 69 6e 74 65 72 to get an inter
4b50: 70 72 65 74 65 72 22 29 3b 0a 0a 09 09 72 65 74 preter");....ret
4b60: 75 72 6e 28 2d 45 49 4f 29 3b 0a 09 7d 0a 0a 09 urn(-EIO);..}...
4b70: 61 70 70 66 73 5f 63 61 6c 6c 5f 6c 69 62 74 63 appfs_call_libtc
4b80: 6c 28 54 63 6c 5f 50 72 65 73 65 72 76 65 28 69 l(Tcl_Preserve(i
4b90: 6e 74 65 72 70 29 3b 29 0a 0a 09 74 63 6c 5f 72 nterp);)...tcl_r
4ba0: 65 74 20 3d 20 61 70 70 66 73 5f 54 63 6c 5f 45 et = appfs_Tcl_E
4bb0: 76 61 6c 28 69 6e 74 65 72 70 2c 20 32 2c 20 22 val(interp, 2, "
4bc0: 3a 3a 61 70 70 66 73 3a 3a 67 65 74 61 74 74 72 ::appfs::getattr
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 67 65 74 61 G("::appfs::geta
4c10: 74 74 72 28 25 73 29 20 66 61 69 6c 65 64 2e 22 ttr(%s) failed."
4c20: 2c 20 70 61 74 68 29 3b 0a 09 09 61 70 70 66 73 , path);...appfs
4c30: 5f 63 61 6c 6c 5f 6c 69 62 74 63 6c 28 0a 09 09 _call_libtcl(...
4c40: 09 41 50 50 46 53 5f 44 45 42 55 47 28 22 54 63 .APPFS_DEBUG("Tc
4c50: 6c 20 45 72 72 6f 72 20 69 73 3a 20 25 73 22 2c l Error is: %s",
4c60: 20 54 63 6c 5f 47 65 74 53 74 72 69 6e 67 52 65 Tcl_GetStringRe
4c70: 73 75 6c 74 28 69 6e 74 65 72 70 29 29 3b 0a 09 sult(interp));..
4c80: 09 29 0a 0a 09 09 70 61 74 68 69 6e 66 6f 2d 3e .)....pathinfo->
4c90: 74 79 70 65 20 3d 20 41 50 50 46 53 5f 50 41 54 type = APPFS_PAT
4ca0: 48 54 59 50 45 5f 44 4f 45 53 5f 4e 4f 54 5f 45 HTYPE_DOES_NOT_E
4cb0: 58 49 53 54 3b 0a 0a 09 09 61 70 70 66 73 5f 67 XIST;....appfs_g
4cc0: 65 74 5f 70 61 74 68 5f 69 6e 66 6f 5f 63 61 63 et_path_info_cac
4cd0: 68 65 5f 61 64 64 28 70 61 74 68 2c 20 66 73 75 he_add(path, fsu
4ce0: 69 64 2c 20 70 61 74 68 69 6e 66 6f 29 3b 0a 0a id, pathinfo);..
4cf0: 09 09 61 70 70 66 73 5f 63 61 6c 6c 5f 6c 69 62 ..appfs_call_lib
4d00: 74 63 6c 28 54 63 6c 5f 52 65 6c 65 61 73 65 28 tcl(Tcl_Release(
4d10: 69 6e 74 65 72 70 29 3b 29 0a 0a 09 09 72 65 74 interp);)....ret
4d20: 75 72 6e 28 2d 45 4e 4f 45 4e 54 29 3b 0a 09 7d urn(-ENOENT);..}
4d30: 0a 0a 09 69 66 20 28 61 74 74 72 5f 6b 65 79 5f ...if (attr_key_
4d40: 74 79 70 65 20 3d 3d 20 4e 55 4c 4c 29 20 7b 0a type == NULL) {.
4d50: 09 09 61 70 70 66 73 5f 63 61 6c 6c 5f 6c 69 62 ..appfs_call_lib
4d60: 74 63 6c 28 0a 09 09 09 61 74 74 72 5f 6b 65 79 tcl(....attr_key
4d70: 5f 74 79 70 65 20 20 20 20 20 20 20 3d 20 54 63 _type = Tc
4d80: 6c 5f 4e 65 77 53 74 72 69 6e 67 4f 62 6a 28 22 l_NewStringObj("
4d90: 74 79 70 65 22 2c 20 2d 31 29 3b 0a 09 09 09 61 type", -1);....a
4da0: 74 74 72 5f 6b 65 79 5f 70 65 72 6d 73 20 20 20 ttr_key_perms
4db0: 20 20 20 3d 20 54 63 6c 5f 4e 65 77 53 74 72 69 = Tcl_NewStri
4dc0: 6e 67 4f 62 6a 28 22 70 65 72 6d 73 22 2c 20 2d ngObj("perms", -
4dd0: 31 29 3b 0a 09 09 09 61 74 74 72 5f 6b 65 79 5f 1);....attr_key_
4de0: 73 69 7a 65 20 20 20 20 20 20 20 3d 20 54 63 6c size = Tcl
4df0: 5f 4e 65 77 53 74 72 69 6e 67 4f 62 6a 28 22 73 _NewStringObj("s
4e00: 69 7a 65 22 2c 20 2d 31 29 3b 0a 09 09 09 61 74 ize", -1);....at
4e10: 74 72 5f 6b 65 79 5f 74 69 6d 65 20 20 20 20 20 tr_key_time
4e20: 20 20 3d 20 54 63 6c 5f 4e 65 77 53 74 72 69 6e = Tcl_NewStrin
4e30: 67 4f 62 6a 28 22 74 69 6d 65 22 2c 20 2d 31 29 gObj("time", -1)
4e40: 3b 0a 09 09 09 61 74 74 72 5f 6b 65 79 5f 73 6f ;....attr_key_so
4e50: 75 72 63 65 20 20 20 20 20 3d 20 54 63 6c 5f 4e urce = Tcl_N
4e60: 65 77 53 74 72 69 6e 67 4f 62 6a 28 22 73 6f 75 ewStringObj("sou
4e70: 72 63 65 22 2c 20 2d 31 29 3b 0a 09 09 09 61 74 rce", -1);....at
4e80: 74 72 5f 6b 65 79 5f 63 68 69 6c 64 63 6f 75 6e tr_key_childcoun
4e90: 74 20 3d 20 54 63 6c 5f 4e 65 77 53 74 72 69 6e t = Tcl_NewStrin
4ea0: 67 4f 62 6a 28 22 63 68 69 6c 64 63 6f 75 6e 74 gObj("childcount
4eb0: 22 2c 20 2d 31 29 3b 0a 09 09 09 61 74 74 72 5f ", -1);....attr_
4ec0: 6b 65 79 5f 70 61 63 6b 61 67 65 64 20 20 20 3d key_packaged =
4ed0: 20 54 63 6c 5f 4e 65 77 53 74 72 69 6e 67 4f 62 Tcl_NewStringOb
4ee0: 6a 28 22 70 61 63 6b 61 67 65 64 22 2c 20 2d 31 j("packaged", -1
4ef0: 29 3b 0a 0a 09 09 09 54 63 6c 5f 49 6e 63 72 52 );.....Tcl_IncrR
4f00: 65 66 43 6f 75 6e 74 28 61 74 74 72 5f 6b 65 79 efCount(attr_key
4f10: 5f 74 79 70 65 29 3b 0a 09 09 09 54 63 6c 5f 49 _type);....Tcl_I
4f20: 6e 63 72 52 65 66 43 6f 75 6e 74 28 61 74 74 72 ncrRefCount(attr
4f30: 5f 6b 65 79 5f 70 65 72 6d 73 29 3b 0a 09 09 09 _key_perms);....
4f40: 54 63 6c 5f 49 6e 63 72 52 65 66 43 6f 75 6e 74 Tcl_IncrRefCount
4f50: 28 61 74 74 72 5f 6b 65 79 5f 73 69 7a 65 29 3b (attr_key_size);
4f60: 0a 09 09 09 54 63 6c 5f 49 6e 63 72 52 65 66 43 ....Tcl_IncrRefC
4f70: 6f 75 6e 74 28 61 74 74 72 5f 6b 65 79 5f 74 69 ount(attr_key_ti
4f80: 6d 65 29 3b 0a 09 09 09 54 63 6c 5f 49 6e 63 72 me);....Tcl_Incr
4f90: 52 65 66 43 6f 75 6e 74 28 61 74 74 72 5f 6b 65 RefCount(attr_ke
4fa0: 79 5f 73 6f 75 72 63 65 29 3b 0a 09 09 09 54 63 y_source);....Tc
4fb0: 6c 5f 49 6e 63 72 52 65 66 43 6f 75 6e 74 28 61 l_IncrRefCount(a
4fc0: 74 74 72 5f 6b 65 79 5f 63 68 69 6c 64 63 6f 75 ttr_key_childcou
4fd0: 6e 74 29 3b 0a 09 09 09 54 63 6c 5f 49 6e 63 72 nt);....Tcl_Incr
4fe0: 52 65 66 43 6f 75 6e 74 28 61 74 74 72 5f 6b 65 RefCount(attr_ke
4ff0: 79 5f 70 61 63 6b 61 67 65 64 29 3b 0a 09 09 29 y_packaged);...)
5000: 0a 09 7d 0a 0a 09 61 70 70 66 73 5f 63 61 6c 6c ..}...appfs_call
5010: 5f 6c 69 62 74 63 6c 28 0a 09 09 61 74 74 72 73 _libtcl(...attrs
5020: 5f 64 69 63 74 20 3d 20 54 63 6c 5f 47 65 74 4f _dict = Tcl_GetO
5030: 62 6a 52 65 73 75 6c 74 28 69 6e 74 65 72 70 29 bjResult(interp)
5040: 3b 0a 09 09 74 63 6c 5f 72 65 74 20 3d 20 54 63 ;...tcl_ret = Tc
5050: 6c 5f 44 69 63 74 4f 62 6a 47 65 74 28 69 6e 74 l_DictObjGet(int
5060: 65 72 70 2c 20 61 74 74 72 73 5f 64 69 63 74 2c erp, attrs_dict,
5070: 20 61 74 74 72 5f 6b 65 79 5f 74 79 70 65 2c 20 attr_key_type,
5080: 26 61 74 74 72 5f 76 61 6c 75 65 29 3b 0a 09 29 &attr_value);..)
5090: 0a 09 69 66 20 28 74 63 6c 5f 72 65 74 20 21 3d ..if (tcl_ret !=
50a0: 20 54 43 4c 5f 4f 4b 29 20 7b 0a 09 09 41 50 50 TCL_OK) {...APP
50b0: 46 53 5f 44 45 42 55 47 28 22 5b 64 69 63 74 20 FS_DEBUG("[dict
50c0: 67 65 74 20 5c 22 74 79 70 65 5c 22 5d 20 66 61 get \"type\"] fa
50d0: 69 6c 65 64 22 29 3b 0a 09 09 61 70 70 66 73 5f iled");...appfs_
50e0: 63 61 6c 6c 5f 6c 69 62 74 63 6c 28 0a 09 09 09 call_libtcl(....
50f0: 41 50 50 46 53 5f 44 45 42 55 47 28 22 54 63 6c APPFS_DEBUG("Tcl
5100: 20 45 72 72 6f 72 20 69 73 3a 20 25 73 22 2c 20 Error is: %s",
5110: 54 63 6c 5f 47 65 74 53 74 72 69 6e 67 52 65 73 Tcl_GetStringRes
5120: 75 6c 74 28 69 6e 74 65 72 70 29 29 3b 0a 09 09 ult(interp));...
5130: 29 0a 0a 09 09 61 70 70 66 73 5f 63 61 6c 6c 5f )....appfs_call_
5140: 6c 69 62 74 63 6c 28 54 63 6c 5f 52 65 6c 65 61 libtcl(Tcl_Relea
5150: 73 65 28 69 6e 74 65 72 70 29 3b 29 0a 0a 09 09 se(interp);)....
5160: 72 65 74 75 72 6e 28 2d 45 49 4f 29 3b 0a 09 7d return(-EIO);..}
5170: 0a 0a 09 69 66 20 28 61 74 74 72 5f 76 61 6c 75 ...if (attr_valu
5180: 65 20 3d 3d 20 4e 55 4c 4c 29 20 7b 0a 09 09 41 e == NULL) {...A
5190: 50 50 46 53 5f 44 45 42 55 47 28 22 65 72 72 6f PPFS_DEBUG("erro
51a0: 72 3a 20 55 6e 61 62 6c 65 20 74 6f 20 67 65 74 r: Unable to get
51b0: 20 74 79 70 65 20 66 6f 72 20 5c 22 25 73 5c 22 type for \"%s\"
51c0: 20 66 72 6f 6d 20 54 63 6c 22 2c 20 70 61 74 68 from Tcl", path
51d0: 29 3b 0a 0a 09 09 61 70 70 66 73 5f 63 61 6c 6c );....appfs_call
51e0: 5f 6c 69 62 74 63 6c 28 54 63 6c 5f 52 65 6c 65 _libtcl(Tcl_Rele
51f0: 61 73 65 28 69 6e 74 65 72 70 29 3b 29 0a 0a 09 ase(interp);)...
5200: 09 72 65 74 75 72 6e 28 2d 45 49 4f 29 3b 0a 09 .return(-EIO);..
5210: 7d 0a 0a 09 70 61 74 68 69 6e 66 6f 2d 3e 70 61 }...pathinfo->pa
5220: 63 6b 61 67 65 64 20 3d 20 30 3b 0a 09 70 61 74 ckaged = 0;..pat
5230: 68 69 6e 66 6f 2d 3e 69 6e 6f 64 65 20 3d 20 61 hinfo->inode = a
5240: 70 70 66 73 5f 67 65 74 5f 70 61 74 68 5f 69 6e ppfs_get_path_in
5250: 6f 64 65 28 70 61 74 68 29 3b 0a 0a 09 61 70 70 ode(path);...app
5260: 66 73 5f 63 61 6c 6c 5f 6c 69 62 74 63 6c 28 0a fs_call_libtcl(.
5270: 09 09 61 74 74 72 5f 76 61 6c 75 65 5f 73 74 72 ..attr_value_str
5280: 20 3d 20 54 63 6c 5f 47 65 74 53 74 72 69 6e 67 = Tcl_GetString
5290: 28 61 74 74 72 5f 76 61 6c 75 65 29 3b 0a 0a 09 (attr_value);...
52a0: 09 73 77 69 74 63 68 20 28 61 74 74 72 5f 76 61 .switch (attr_va
52b0: 6c 75 65 5f 73 74 72 5b 30 5d 29 20 7b 0a 09 09 lue_str[0]) {...
52c0: 09 63 61 73 65 20 27 64 27 3a 20 2f 2a 20 64 69 .case 'd': /* di
52d0: 72 65 63 74 6f 72 79 20 2a 2f 0a 09 09 09 09 70 rectory */.....p
52e0: 61 74 68 69 6e 66 6f 2d 3e 74 79 70 65 20 3d 20 athinfo->type =
52f0: 41 50 50 46 53 5f 50 41 54 48 54 59 50 45 5f 44 APPFS_PATHTYPE_D
5300: 49 52 45 43 54 4f 52 59 3b 0a 09 09 09 09 70 61 IRECTORY;.....pa
5310: 74 68 69 6e 66 6f 2d 3e 74 79 70 65 69 6e 66 6f thinfo->typeinfo
5320: 2e 64 69 72 2e 63 68 69 6c 64 63 6f 75 6e 74 20 .dir.childcount
5330: 3d 20 30 3b 0a 0a 09 09 09 09 54 63 6c 5f 44 69 = 0;......Tcl_Di
5340: 63 74 4f 62 6a 47 65 74 28 69 6e 74 65 72 70 2c ctObjGet(interp,
5350: 20 61 74 74 72 73 5f 64 69 63 74 2c 20 61 74 74 attrs_dict, att
5360: 72 5f 6b 65 79 5f 63 68 69 6c 64 63 6f 75 6e 74 r_key_childcount
5370: 2c 20 26 61 74 74 72 5f 76 61 6c 75 65 29 3b 0a , &attr_value);.
5380: 09 09 09 09 69 66 20 28 61 74 74 72 5f 76 61 6c ....if (attr_val
5390: 75 65 20 21 3d 20 4e 55 4c 4c 29 20 7b 0a 09 09 ue != NULL) {...
53a0: 09 09 09 74 63 6c 5f 72 65 74 20 3d 20 54 63 6c ...tcl_ret = Tcl
53b0: 5f 47 65 74 57 69 64 65 49 6e 74 46 72 6f 6d 4f _GetWideIntFromO
53c0: 62 6a 28 4e 55 4c 4c 2c 20 61 74 74 72 5f 76 61 bj(NULL, attr_va
53d0: 6c 75 65 2c 20 26 61 74 74 72 5f 76 61 6c 75 65 lue, &attr_value
53e0: 5f 77 69 64 65 29 3b 0a 09 09 09 09 09 69 66 20 _wide);......if
53f0: 28 74 63 6c 5f 72 65 74 20 3d 3d 20 54 43 4c 5f (tcl_ret == TCL_
5400: 4f 4b 29 20 7b 0a 09 09 09 09 09 09 70 61 74 68 OK) {.......path
5410: 69 6e 66 6f 2d 3e 74 79 70 65 69 6e 66 6f 2e 64 info->typeinfo.d
5420: 69 72 2e 63 68 69 6c 64 63 6f 75 6e 74 20 3d 20 ir.childcount =
5430: 61 74 74 72 5f 76 61 6c 75 65 5f 77 69 64 65 3b attr_value_wide;
5440: 0a 09 09 09 09 09 7d 0a 09 09 09 09 7d 0a 0a 09 ......}.....}...
5450: 09 09 09 62 72 65 61 6b 3b 0a 09 09 09 63 61 73 ...break;....cas
5460: 65 20 27 66 27 3a 20 2f 2a 20 66 69 6c 65 20 2a e 'f': /* file *
5470: 2f 0a 09 09 09 09 70 61 74 68 69 6e 66 6f 2d 3e /.....pathinfo->
5480: 74 79 70 65 20 3d 20 41 50 50 46 53 5f 50 41 54 type = APPFS_PAT
5490: 48 54 59 50 45 5f 46 49 4c 45 3b 0a 09 09 09 09 HTYPE_FILE;.....
54a0: 70 61 74 68 69 6e 66 6f 2d 3e 74 79 70 65 69 6e pathinfo->typein
54b0: 66 6f 2e 66 69 6c 65 2e 73 69 7a 65 20 3d 20 30 fo.file.size = 0
54c0: 3b 0a 09 09 09 09 70 61 74 68 69 6e 66 6f 2d 3e ;.....pathinfo->
54d0: 74 79 70 65 69 6e 66 6f 2e 66 69 6c 65 2e 65 78 typeinfo.file.ex
54e0: 65 63 75 74 61 62 6c 65 20 3d 20 30 3b 0a 0a 09 ecutable = 0;...
54f0: 09 09 09 54 63 6c 5f 44 69 63 74 4f 62 6a 47 65 ...Tcl_DictObjGe
5500: 74 28 69 6e 74 65 72 70 2c 20 61 74 74 72 73 5f t(interp, attrs_
5510: 64 69 63 74 2c 20 61 74 74 72 5f 6b 65 79 5f 73 dict, attr_key_s
5520: 69 7a 65 2c 20 26 61 74 74 72 5f 76 61 6c 75 65 ize, &attr_value
5530: 29 3b 0a 09 09 09 09 69 66 20 28 61 74 74 72 5f );.....if (attr_
5540: 76 61 6c 75 65 20 21 3d 20 4e 55 4c 4c 29 20 7b value != NULL) {
5550: 0a 09 09 09 09 09 74 63 6c 5f 72 65 74 20 3d 20 ......tcl_ret =
5560: 54 63 6c 5f 47 65 74 57 69 64 65 49 6e 74 46 72 Tcl_GetWideIntFr
5570: 6f 6d 4f 62 6a 28 4e 55 4c 4c 2c 20 61 74 74 72 omObj(NULL, attr
5580: 5f 76 61 6c 75 65 2c 20 26 61 74 74 72 5f 76 61 _value, &attr_va
5590: 6c 75 65 5f 77 69 64 65 29 3b 0a 09 09 09 09 09 lue_wide);......
55a0: 69 66 20 28 74 63 6c 5f 72 65 74 20 3d 3d 20 54 if (tcl_ret == T
55b0: 43 4c 5f 4f 4b 29 20 7b 0a 09 09 09 09 09 09 70 CL_OK) {.......p
55c0: 61 74 68 69 6e 66 6f 2d 3e 74 79 70 65 69 6e 66 athinfo->typeinf
55d0: 6f 2e 66 69 6c 65 2e 73 69 7a 65 20 3d 20 61 74 o.file.size = at
55e0: 74 72 5f 76 61 6c 75 65 5f 77 69 64 65 3b 0a 09 tr_value_wide;..
55f0: 09 09 09 09 7d 0a 09 09 09 09 7d 0a 0a 09 09 09 ....}.....}.....
5600: 09 54 63 6c 5f 44 69 63 74 4f 62 6a 47 65 74 28 .Tcl_DictObjGet(
5610: 69 6e 74 65 72 70 2c 20 61 74 74 72 73 5f 64 69 interp, attrs_di
5620: 63 74 2c 20 61 74 74 72 5f 6b 65 79 5f 70 65 72 ct, attr_key_per
5630: 6d 73 2c 20 26 61 74 74 72 5f 76 61 6c 75 65 29 ms, &attr_value)
5640: 3b 0a 09 09 09 09 69 66 20 28 61 74 74 72 5f 76 ;.....if (attr_v
5650: 61 6c 75 65 20 21 3d 20 4e 55 4c 4c 29 20 7b 0a alue != NULL) {.
5660: 09 09 09 09 09 61 74 74 72 5f 76 61 6c 75 65 5f .....attr_value_
5670: 73 74 72 20 3d 20 54 63 6c 5f 47 65 74 53 74 72 str = Tcl_GetStr
5680: 69 6e 67 28 61 74 74 72 5f 76 61 6c 75 65 29 3b ing(attr_value);
5690: 0a 09 09 09 09 09 69 66 20 28 61 74 74 72 5f 76 ......if (attr_v
56a0: 61 6c 75 65 5f 73 74 72 5b 30 5d 20 3d 3d 20 27 alue_str[0] == '
56b0: 78 27 29 20 7b 0a 09 09 09 09 09 09 70 61 74 68 x') {.......path
56c0: 69 6e 66 6f 2d 3e 74 79 70 65 69 6e 66 6f 2e 66 info->typeinfo.f
56d0: 69 6c 65 2e 65 78 65 63 75 74 61 62 6c 65 20 3d ile.executable =
56e0: 20 31 3b 0a 09 09 09 09 09 7d 0a 09 09 09 09 7d 1;......}.....}
56f0: 0a 09 09 09 09 62 72 65 61 6b 3b 0a 09 09 09 63 .....break;....c
5700: 61 73 65 20 27 73 27 3a 20 2f 2a 20 73 79 6d 6c ase 's': /* syml
5710: 69 6e 6b 20 2a 2f 0a 09 09 09 09 70 61 74 68 69 ink */.....pathi
5720: 6e 66 6f 2d 3e 74 79 70 65 20 3d 20 41 50 50 46 nfo->type = APPF
5730: 53 5f 50 41 54 48 54 59 50 45 5f 53 59 4d 4c 49 S_PATHTYPE_SYMLI
5740: 4e 4b 3b 0a 09 09 09 09 70 61 74 68 69 6e 66 6f NK;.....pathinfo
5750: 2d 3e 74 79 70 65 69 6e 66 6f 2e 73 79 6d 6c 69 ->typeinfo.symli
5760: 6e 6b 2e 73 69 7a 65 20 3d 20 30 3b 0a 09 09 09 nk.size = 0;....
5770: 09 70 61 74 68 69 6e 66 6f 2d 3e 74 79 70 65 69 .pathinfo->typei
5780: 6e 66 6f 2e 73 79 6d 6c 69 6e 6b 2e 73 6f 75 72 nfo.symlink.sour
5790: 63 65 5b 30 5d 20 3d 20 27 5c 30 27 3b 0a 0a 09 ce[0] = '\0';...
57a0: 09 09 09 54 63 6c 5f 44 69 63 74 4f 62 6a 47 65 ...Tcl_DictObjGe
57b0: 74 28 69 6e 74 65 72 70 2c 20 61 74 74 72 73 5f t(interp, attrs_
57c0: 64 69 63 74 2c 20 61 74 74 72 5f 6b 65 79 5f 73 dict, attr_key_s
57d0: 6f 75 72 63 65 2c 20 26 61 74 74 72 5f 76 61 6c ource, &attr_val
57e0: 75 65 29 3b 0a 09 09 09 09 69 66 20 28 61 74 74 ue);.....if (att
57f0: 72 5f 76 61 6c 75 65 20 21 3d 20 4e 55 4c 4c 29 r_value != NULL)
5800: 20 7b 0a 09 09 09 09 09 61 74 74 72 5f 76 61 6c {......attr_val
5810: 75 65 5f 73 74 72 20 3d 20 54 63 6c 5f 47 65 74 ue_str = Tcl_Get
5820: 53 74 72 69 6e 67 46 72 6f 6d 4f 62 6a 28 61 74 StringFromObj(at
5830: 74 72 5f 76 61 6c 75 65 2c 20 26 61 74 74 72 5f tr_value, &attr_
5840: 76 61 6c 75 65 5f 69 6e 74 29 3b 20 0a 0a 09 09 value_int); ....
5850: 09 09 09 69 66 20 28 28 61 74 74 72 5f 76 61 6c ...if ((attr_val
5860: 75 65 5f 69 6e 74 20 2b 20 31 29 20 3c 3d 20 73 ue_int + 1) <= s
5870: 69 7a 65 6f 66 28 70 61 74 68 69 6e 66 6f 2d 3e izeof(pathinfo->
5880: 74 79 70 65 69 6e 66 6f 2e 73 79 6d 6c 69 6e 6b typeinfo.symlink
5890: 2e 73 6f 75 72 63 65 29 29 20 7b 0a 09 09 09 09 .source)) {.....
58a0: 09 09 70 61 74 68 69 6e 66 6f 2d 3e 74 79 70 65 ..pathinfo->type
58b0: 69 6e 66 6f 2e 73 79 6d 6c 69 6e 6b 2e 73 69 7a info.symlink.siz
58c0: 65 20 3d 20 61 74 74 72 5f 76 61 6c 75 65 5f 69 e = attr_value_i
58d0: 6e 74 3b 0a 09 09 09 09 09 09 70 61 74 68 69 6e nt;.......pathin
58e0: 66 6f 2d 3e 74 79 70 65 69 6e 66 6f 2e 73 79 6d fo->typeinfo.sym
58f0: 6c 69 6e 6b 2e 73 6f 75 72 63 65 5b 61 74 74 72 link.source[attr
5900: 5f 76 61 6c 75 65 5f 69 6e 74 5d 20 3d 20 27 5c _value_int] = '\
5910: 30 27 3b 0a 0a 09 09 09 09 09 09 6d 65 6d 63 70 0';........memcp
5920: 79 28 70 61 74 68 69 6e 66 6f 2d 3e 74 79 70 65 y(pathinfo->type
5930: 69 6e 66 6f 2e 73 79 6d 6c 69 6e 6b 2e 73 6f 75 info.symlink.sou
5940: 72 63 65 2c 20 61 74 74 72 5f 76 61 6c 75 65 5f rce, attr_value_
5950: 73 74 72 2c 20 61 74 74 72 5f 76 61 6c 75 65 5f str, attr_value_
5960: 69 6e 74 29 3b 0a 09 09 09 09 09 7d 0a 09 09 09 int);......}....
5970: 09 7d 0a 09 09 09 09 62 72 65 61 6b 3b 0a 09 09 .}.....break;...
5980: 09 63 61 73 65 20 27 46 27 3a 20 2f 2a 20 70 69 .case 'F': /* pi
5990: 70 65 2f 66 69 66 6f 20 2a 2f 0a 09 09 09 09 70 pe/fifo */.....p
59a0: 61 74 68 69 6e 66 6f 2d 3e 74 79 70 65 20 3d 20 athinfo->type =
59b0: 41 50 50 46 53 5f 50 41 54 48 54 59 50 45 5f 46 APPFS_PATHTYPE_F
59c0: 49 46 4f 3b 0a 09 09 09 09 62 72 65 61 6b 3b 0a IFO;.....break;.
59d0: 09 09 09 63 61 73 65 20 27 53 27 3a 20 2f 2a 20 ...case 'S': /*
59e0: 55 4e 49 58 20 64 6f 6d 61 69 6e 20 73 6f 63 6b UNIX domain sock
59f0: 65 74 20 2a 2f 0a 09 09 09 09 70 61 74 68 69 6e et */.....pathin
5a00: 66 6f 2d 3e 74 79 70 65 20 3d 20 41 50 50 46 53 fo->type = APPFS
5a10: 5f 50 41 54 48 54 59 50 45 5f 53 4f 43 4b 45 54 _PATHTYPE_SOCKET
5a20: 3b 0a 09 09 09 09 62 72 65 61 6b 3b 0a 09 09 09 ;.....break;....
5a30: 64 65 66 61 75 6c 74 3a 0a 09 09 09 09 72 65 74 default:.....ret
5a40: 76 61 6c 20 3d 20 2d 45 49 4f 3b 0a 09 09 7d 0a val = -EIO;...}.
5a50: 0a 09 09 54 63 6c 5f 44 69 63 74 4f 62 6a 47 65 ...Tcl_DictObjGe
5a60: 74 28 69 6e 74 65 72 70 2c 20 61 74 74 72 73 5f t(interp, attrs_
5a70: 64 69 63 74 2c 20 61 74 74 72 5f 6b 65 79 5f 70 dict, attr_key_p
5a80: 61 63 6b 61 67 65 64 2c 20 26 61 74 74 72 5f 76 ackaged, &attr_v
5a90: 61 6c 75 65 29 3b 0a 09 09 69 66 20 28 61 74 74 alue);...if (att
5aa0: 72 5f 76 61 6c 75 65 20 21 3d 20 4e 55 4c 4c 29 r_value != NULL)
5ab0: 20 7b 0a 09 09 09 70 61 74 68 69 6e 66 6f 2d 3e {....pathinfo->
5ac0: 70 61 63 6b 61 67 65 64 20 3d 20 31 3b 0a 09 09 packaged = 1;...
5ad0: 7d 0a 0a 09 09 54 63 6c 5f 44 69 63 74 4f 62 6a }....Tcl_DictObj
5ae0: 47 65 74 28 69 6e 74 65 72 70 2c 20 61 74 74 72 Get(interp, attr
5af0: 73 5f 64 69 63 74 2c 20 61 74 74 72 5f 6b 65 79 s_dict, attr_key
5b00: 5f 74 69 6d 65 2c 20 26 61 74 74 72 5f 76 61 6c _time, &attr_val
5b10: 75 65 29 3b 0a 09 09 69 66 20 28 61 74 74 72 5f ue);...if (attr_
5b20: 76 61 6c 75 65 20 21 3d 20 4e 55 4c 4c 29 20 7b value != NULL) {
5b30: 0a 09 09 09 74 63 6c 5f 72 65 74 20 3d 20 54 63 ....tcl_ret = Tc
5b40: 6c 5f 47 65 74 57 69 64 65 49 6e 74 46 72 6f 6d l_GetWideIntFrom
5b50: 4f 62 6a 28 4e 55 4c 4c 2c 20 61 74 74 72 5f 76 Obj(NULL, attr_v
5b60: 61 6c 75 65 2c 20 26 61 74 74 72 5f 76 61 6c 75 alue, &attr_valu
5b70: 65 5f 77 69 64 65 29 3b 0a 09 09 09 69 66 20 28 e_wide);....if (
5b80: 74 63 6c 5f 72 65 74 20 3d 3d 20 54 43 4c 5f 4f tcl_ret == TCL_O
5b90: 4b 29 20 7b 0a 09 09 09 09 70 61 74 68 69 6e 66 K) {.....pathinf
5ba0: 6f 2d 3e 74 69 6d 65 20 3d 20 61 74 74 72 5f 76 o->time = attr_v
5bb0: 61 6c 75 65 5f 77 69 64 65 3b 0a 09 09 09 7d 0a alue_wide;....}.
5bc0: 09 09 7d 20 65 6c 73 65 20 7b 0a 09 09 09 70 61 ..} else {....pa
5bd0: 74 68 69 6e 66 6f 2d 3e 74 69 6d 65 20 3d 20 30 thinfo->time = 0
5be0: 3b 0a 09 09 7d 0a 0a 09 09 54 63 6c 5f 52 65 6c ;...}....Tcl_Rel
5bf0: 65 61 73 65 28 69 6e 74 65 72 70 29 3b 0a 09 29 ease(interp);..)
5c00: 0a 0a 09 69 66 20 28 72 65 74 76 61 6c 20 3d 3d ...if (retval ==
5c10: 20 30 29 20 7b 0a 09 09 61 70 70 66 73 5f 67 65 0) {...appfs_ge
5c20: 74 5f 70 61 74 68 5f 69 6e 66 6f 5f 63 61 63 68 t_path_info_cach
5c30: 65 5f 61 64 64 28 70 61 74 68 2c 20 66 73 75 69 e_add(path, fsui
5c40: 64 2c 20 70 61 74 68 69 6e 66 6f 29 3b 0a 09 7d d, pathinfo);..}
5c50: 20 65 6c 73 65 20 7b 0a 09 09 41 50 50 46 53 5f else {...APPFS_
5c60: 44 45 42 55 47 28 22 65 72 72 6f 72 3a 20 49 6e DEBUG("error: In
5c70: 76 61 6c 69 64 20 74 79 70 65 20 66 6f 72 20 5c valid type for \
5c80: 22 25 73 5c 22 20 66 72 6f 6d 20 54 63 6c 22 2c "%s\" from Tcl",
5c90: 20 70 61 74 68 29 3b 0a 09 7d 0a 0a 09 72 65 74 path);..}...ret
5ca0: 75 72 6e 28 72 65 74 76 61 6c 29 3b 0a 7d 0a 0a urn(retval);.}..
5cb0: 73 74 61 74 69 63 20 63 68 61 72 20 2a 61 70 70 static char *app
5cc0: 66 73 5f 70 72 65 70 61 72 65 5f 74 6f 5f 63 72 fs_prepare_to_cr
5cd0: 65 61 74 65 28 63 6f 6e 73 74 20 63 68 61 72 20 eate(const char
5ce0: 2a 70 61 74 68 29 20 7b 0a 09 54 63 6c 5f 49 6e *path) {..Tcl_In
5cf0: 74 65 72 70 20 2a 69 6e 74 65 72 70 3b 0a 09 63 terp *interp;..c
5d00: 6f 6e 73 74 20 63 68 61 72 20 2a 72 65 61 6c 5f onst char *real_
5d10: 70 61 74 68 3b 0a 09 69 6e 74 20 74 63 6c 5f 72 path;..int tcl_r
5d20: 65 74 3b 0a 0a 09 61 70 70 66 73 5f 67 65 74 5f et;...appfs_get_
5d30: 70 61 74 68 5f 69 6e 66 6f 5f 63 61 63 68 65 5f path_info_cache_
5d40: 66 6c 75 73 68 28 61 70 70 66 73 5f 67 65 74 5f flush(appfs_get_
5d50: 66 73 75 69 64 28 29 2c 20 2d 31 29 3b 0a 0a 09 fsuid(), -1);...
5d60: 69 6e 74 65 72 70 20 3d 20 61 70 70 66 73 5f 54 interp = appfs_T
5d70: 63 6c 49 6e 74 65 72 70 28 29 3b 0a 09 69 66 20 clInterp();..if
5d80: 28 69 6e 74 65 72 70 20 3d 3d 20 4e 55 4c 4c 29 (interp == NULL)
5d90: 20 7b 0a 09 09 72 65 74 75 72 6e 28 4e 55 4c 4c {...return(NULL
5da0: 29 3b 0a 09 7d 0a 0a 09 61 70 70 66 73 5f 63 61 );..}...appfs_ca
5db0: 6c 6c 5f 6c 69 62 74 63 6c 28 54 63 6c 5f 50 72 ll_libtcl(Tcl_Pr
5dc0: 65 73 65 72 76 65 28 69 6e 74 65 72 70 29 3b 29 eserve(interp);)
5dd0: 0a 0a 09 61 70 70 66 73 5f 63 61 6c 6c 5f 6c 69 ...appfs_call_li
5de0: 62 74 63 6c 28 0a 09 09 74 63 6c 5f 72 65 74 20 btcl(...tcl_ret
5df0: 3d 20 61 70 70 66 73 5f 54 63 6c 5f 45 76 61 6c = appfs_Tcl_Eval
5e00: 28 69 6e 74 65 72 70 2c 20 32 2c 20 22 3a 3a 61 (interp, 2, "::a
5e10: 70 70 66 73 3a 3a 70 72 65 70 61 72 65 5f 74 6f ppfs::prepare_to
5e20: 5f 63 72 65 61 74 65 22 2c 20 70 61 74 68 29 3b _create", path);
5e30: 0a 09 29 0a 09 69 66 20 28 74 63 6c 5f 72 65 74 ..)..if (tcl_ret
5e40: 20 21 3d 20 54 43 4c 5f 4f 4b 29 20 7b 0a 09 09 != TCL_OK) {...
5e50: 41 50 50 46 53 5f 44 45 42 55 47 28 22 3a 3a 61 APPFS_DEBUG("::a
5e60: 70 70 66 73 3a 3a 70 72 65 70 61 72 65 5f 74 6f ppfs::prepare_to
5e70: 5f 63 72 65 61 74 65 28 25 73 29 20 66 61 69 6c _create(%s) fail
5e80: 65 64 2e 22 2c 20 70 61 74 68 29 3b 0a 09 09 61 ed.", path);...a
5e90: 70 70 66 73 5f 63 61 6c 6c 5f 6c 69 62 74 63 6c ppfs_call_libtcl
5ea0: 28 0a 09 09 09 41 50 50 46 53 5f 44 45 42 55 47 (....APPFS_DEBUG
5eb0: 28 22 54 63 6c 20 45 72 72 6f 72 20 69 73 3a 20 ("Tcl Error is:
5ec0: 25 73 22 2c 20 54 63 6c 5f 47 65 74 53 74 72 69 %s", Tcl_GetStri
5ed0: 6e 67 52 65 73 75 6c 74 28 69 6e 74 65 72 70 29 ngResult(interp)
5ee0: 29 3b 0a 09 09 29 0a 0a 09 09 61 70 70 66 73 5f );...)....appfs_
5ef0: 63 61 6c 6c 5f 6c 69 62 74 63 6c 28 54 63 6c 5f call_libtcl(Tcl_
5f00: 52 65 6c 65 61 73 65 28 69 6e 74 65 72 70 29 3b Release(interp);
5f10: 29 0a 0a 09 09 72 65 74 75 72 6e 28 4e 55 4c 4c )....return(NULL
5f20: 29 3b 0a 09 7d 0a 0a 09 61 70 70 66 73 5f 63 61 );..}...appfs_ca
5f30: 6c 6c 5f 6c 69 62 74 63 6c 28 0a 09 09 72 65 61 ll_libtcl(...rea
5f40: 6c 5f 70 61 74 68 20 3d 20 54 63 6c 5f 47 65 74 l_path = Tcl_Get
5f50: 53 74 72 69 6e 67 52 65 73 75 6c 74 28 69 6e 74 StringResult(int
5f60: 65 72 70 29 3b 0a 09 29 0a 0a 09 61 70 70 66 73 erp);..)...appfs
5f70: 5f 63 61 6c 6c 5f 6c 69 62 74 63 6c 28 54 63 6c _call_libtcl(Tcl
5f80: 5f 52 65 6c 65 61 73 65 28 69 6e 74 65 72 70 29 _Release(interp)
5f90: 3b 29 0a 0a 09 69 66 20 28 72 65 61 6c 5f 70 61 ;)...if (real_pa
5fa0: 74 68 20 3d 3d 20 4e 55 4c 4c 29 20 7b 0a 09 09 th == NULL) {...
5fb0: 72 65 74 75 72 6e 28 4e 55 4c 4c 29 3b 0a 09 7d return(NULL);..}
5fc0: 0a 0a 09 72 65 74 75 72 6e 28 73 74 72 64 75 70 ...return(strdup
5fd0: 28 72 65 61 6c 5f 70 61 74 68 29 29 3b 0a 7d 0a (real_path));.}.
5fe0: 0a 73 74 61 74 69 63 20 63 68 61 72 20 2a 61 70 .static char *ap
5ff0: 70 66 73 5f 6c 6f 63 61 6c 70 61 74 68 28 63 6f pfs_localpath(co
6000: 6e 73 74 20 63 68 61 72 20 2a 70 61 74 68 29 20 nst char *path)
6010: 7b 0a 09 54 63 6c 5f 49 6e 74 65 72 70 20 2a 69 {..Tcl_Interp *i
6020: 6e 74 65 72 70 3b 0a 09 63 6f 6e 73 74 20 63 68 nterp;..const ch
6030: 61 72 20 2a 72 65 61 6c 5f 70 61 74 68 3b 0a 09 ar *real_path;..
6040: 69 6e 74 20 74 63 6c 5f 72 65 74 3b 0a 0a 09 69 int tcl_ret;...i
6050: 6e 74 65 72 70 20 3d 20 61 70 70 66 73 5f 54 63 nterp = appfs_Tc
6060: 6c 49 6e 74 65 72 70 28 29 3b 0a 09 69 66 20 28 lInterp();..if (
6070: 69 6e 74 65 72 70 20 3d 3d 20 4e 55 4c 4c 29 20 interp == NULL)
6080: 7b 0a 09 09 72 65 74 75 72 6e 28 4e 55 4c 4c 29 {...return(NULL)
6090: 3b 0a 09 7d 0a 0a 09 61 70 70 66 73 5f 63 61 6c ;..}...appfs_cal
60a0: 6c 5f 6c 69 62 74 63 6c 28 54 63 6c 5f 50 72 65 l_libtcl(Tcl_Pre
60b0: 73 65 72 76 65 28 69 6e 74 65 72 70 29 3b 29 0a serve(interp);).
60c0: 0a 09 61 70 70 66 73 5f 63 61 6c 6c 5f 6c 69 62 ..appfs_call_lib
60d0: 74 63 6c 28 0a 09 09 74 63 6c 5f 72 65 74 20 3d tcl(...tcl_ret =
60e0: 20 61 70 70 66 73 5f 54 63 6c 5f 45 76 61 6c 28 appfs_Tcl_Eval(
60f0: 69 6e 74 65 72 70 2c 20 32 2c 20 22 3a 3a 61 70 interp, 2, "::ap
6100: 70 66 73 3a 3a 6c 6f 63 61 6c 70 61 74 68 22 2c pfs::localpath",
6110: 20 70 61 74 68 29 3b 0a 09 29 0a 09 69 66 20 28 path);..)..if (
6120: 74 63 6c 5f 72 65 74 20 21 3d 20 54 43 4c 5f 4f tcl_ret != TCL_O
6130: 4b 29 20 7b 0a 09 09 41 50 50 46 53 5f 44 45 42 K) {...APPFS_DEB
6140: 55 47 28 22 3a 3a 61 70 70 66 73 3a 3a 6c 6f 63 UG("::appfs::loc
6150: 61 6c 70 61 74 68 28 25 73 29 20 66 61 69 6c 65 alpath(%s) faile
6160: 64 2e 22 2c 20 70 61 74 68 29 3b 0a 09 09 61 70 d.", path);...ap
6170: 70 66 73 5f 63 61 6c 6c 5f 6c 69 62 74 63 6c 28 pfs_call_libtcl(
6180: 0a 09 09 09 41 50 50 46 53 5f 44 45 42 55 47 28 ....APPFS_DEBUG(
6190: 22 54 63 6c 20 45 72 72 6f 72 20 69 73 3a 20 25 "Tcl Error is: %
61a0: 73 22 2c 20 54 63 6c 5f 47 65 74 53 74 72 69 6e s", Tcl_GetStrin
61b0: 67 52 65 73 75 6c 74 28 69 6e 74 65 72 70 29 29 gResult(interp))
61c0: 3b 0a 09 09 29 0a 0a 09 09 72 65 74 75 72 6e 28 ;...)....return(
61d0: 4e 55 4c 4c 29 3b 0a 09 7d 0a 0a 09 61 70 70 66 NULL);..}...appf
61e0: 73 5f 63 61 6c 6c 5f 6c 69 62 74 63 6c 28 0a 09 s_call_libtcl(..
61f0: 09 72 65 61 6c 5f 70 61 74 68 20 3d 20 54 63 6c .real_path = Tcl
6200: 5f 47 65 74 53 74 72 69 6e 67 52 65 73 75 6c 74 _GetStringResult
6210: 28 69 6e 74 65 72 70 29 3b 0a 09 29 0a 0a 09 61 (interp);..)...a
6220: 70 70 66 73 5f 63 61 6c 6c 5f 6c 69 62 74 63 6c ppfs_call_libtcl
6230: 28 54 63 6c 5f 52 65 6c 65 61 73 65 28 69 6e 74 (Tcl_Release(int
6240: 65 72 70 29 3b 29 0a 0a 09 69 66 20 28 72 65 61 erp);)...if (rea
6250: 6c 5f 70 61 74 68 20 3d 3d 20 4e 55 4c 4c 29 20 l_path == NULL)
6260: 7b 0a 09 09 72 65 74 75 72 6e 28 4e 55 4c 4c 29 {...return(NULL)
6270: 3b 0a 09 7d 0a 0a 09 72 65 74 75 72 6e 28 73 74 ;..}...return(st
6280: 72 64 75 70 28 72 65 61 6c 5f 70 61 74 68 29 29 rdup(real_path))
6290: 3b 0a 7d 0a 0a 23 69 66 20 28 64 65 66 69 6e 65 ;.}..#if (define
62a0: 64 28 44 45 42 55 47 29 20 26 26 20 64 65 66 69 d(DEBUG) && defi
62b0: 6e 65 64 28 41 50 50 46 53 5f 45 58 49 54 5f 50 ned(APPFS_EXIT_P
62c0: 41 54 48 29 29 20 7c 7c 20 64 65 66 69 6e 65 64 ATH)) || defined
62d0: 28 41 50 50 46 53 5f 45 58 49 54 5f 50 41 54 48 (APPFS_EXIT_PATH
62e0: 5f 45 4e 41 42 4c 45 5f 4d 41 4a 4f 52 5f 53 45 _ENABLE_MAJOR_SE
62f0: 43 55 52 49 54 59 5f 48 4f 4c 45 29 0a 73 74 61 CURITY_HOLE).sta
6300: 74 69 63 20 76 6f 69 64 20 61 70 70 66 73 5f 65 tic void appfs_e
6310: 78 69 74 28 76 6f 69 64 29 20 7b 0a 09 69 6e 74 xit(void) {..int
6320: 20 67 6c 6f 62 61 6c 5f 69 6e 74 65 72 70 5f 72 global_interp_r
6330: 65 73 65 74 5f 6b 65 79 3b 0a 0a 09 67 6c 6f 62 eset_key;...glob
6340: 61 6c 5f 69 6e 74 65 72 70 5f 72 65 73 65 74 5f al_interp_reset_
6350: 6b 65 79 20 3d 20 5f 5f 73 79 6e 63 5f 66 65 74 key = __sync_fet
6360: 63 68 5f 61 6e 64 5f 61 64 64 28 26 69 6e 74 65 ch_and_add(&inte
6370: 72 70 5f 72 65 73 65 74 5f 6b 65 79 2c 20 30 29 rp_reset_key, 0)
6380: 3b 0a 09 5f 5f 73 79 6e 63 5f 66 65 74 63 68 5f ;..__sync_fetch_
6390: 61 6e 64 5f 73 75 62 28 26 69 6e 74 65 72 70 5f and_sub(&interp_
63a0: 72 65 73 65 74 5f 6b 65 79 2c 20 67 6c 6f 62 61 reset_key, globa
63b0: 6c 5f 69 6e 74 65 72 70 5f 72 65 73 65 74 5f 6b l_interp_reset_k
63c0: 65 79 29 3b 0a 0a 09 77 68 69 6c 65 20 28 5f 5f ey);...while (__
63d0: 73 79 6e 63 5f 73 75 62 5f 61 6e 64 5f 66 65 74 sync_sub_and_fet
63e0: 63 68 28 26 69 6e 74 65 72 70 5f 72 65 73 65 74 ch(&interp_reset
63f0: 5f 6b 65 79 2c 20 31 29 20 3e 3d 20 30 29 20 7b _key, 1) >= 0) {
6400: 0a 09 09 2f 2a 20 42 75 73 79 20 4c 6f 6f 70 20 .../* Busy Loop
6410: 2a 2f 0a 09 7d 0a 0a 09 67 6c 6f 62 61 6c 5f 69 */..}...global_i
6420: 6e 74 65 72 70 5f 72 65 73 65 74 5f 6b 65 79 20 nterp_reset_key
6430: 3d 20 5f 5f 73 79 6e 63 5f 66 65 74 63 68 5f 61 = __sync_fetch_a
6440: 6e 64 5f 61 64 64 28 26 69 6e 74 65 72 70 5f 72 nd_add(&interp_r
6450: 65 73 65 74 5f 6b 65 79 2c 20 30 29 3b 0a 09 69 eset_key, 0);..i
6460: 66 20 28 67 6c 6f 62 61 6c 5f 69 6e 74 65 72 70 f (global_interp
6470: 5f 72 65 73 65 74 5f 6b 65 79 20 21 3d 20 2d 31 _reset_key != -1
6480: 29 20 7b 0a 09 09 41 50 50 46 53 5f 44 45 42 55 ) {...APPFS_DEBU
6490: 47 28 22 45 72 72 6f 72 20 73 65 6e 64 69 6e 67 G("Error sending
64a0: 20 6b 69 6c 6c 20 73 69 67 6e 61 6c 20 74 6f 20 kill signal to
64b0: 61 6c 6c 20 74 68 72 65 61 64 73 2c 20 61 62 6f all threads, abo
64c0: 72 74 69 6e 67 20 61 6e 79 77 61 79 2e 22 29 3b rting anyway.");
64d0: 0a 09 7d 0a 0a 09 61 70 70 66 73 5f 67 65 74 5f ..}...appfs_get_
64e0: 70 61 74 68 5f 69 6e 66 6f 5f 63 61 63 68 65 5f path_info_cache_
64f0: 66 6c 75 73 68 28 2d 31 2c 20 2d 31 29 3b 0a 0a flush(-1, -1);..
6500: 09 66 75 73 65 5f 65 78 69 74 28 66 75 73 65 5f .fuse_exit(fuse_
6510: 67 65 74 5f 63 6f 6e 74 65 78 74 28 29 2d 3e 66 get_context()->f
6520: 75 73 65 29 3b 0a 0a 09 72 65 74 75 72 6e 3b 0a use);...return;.
6530: 7d 0a 23 65 6e 64 69 66 0a 0a 73 74 61 74 69 63 }.#endif..static
6540: 20 69 6e 74 20 61 70 70 66 73 5f 66 75 73 65 5f int appfs_fuse_
6550: 72 65 61 64 6c 69 6e 6b 28 63 6f 6e 73 74 20 63 readlink(const c
6560: 68 61 72 20 2a 70 61 74 68 2c 20 63 68 61 72 20 har *path, char
6570: 2a 62 75 66 2c 20 73 69 7a 65 5f 74 20 73 69 7a *buf, size_t siz
6580: 65 29 20 7b 0a 09 73 74 72 75 63 74 20 61 70 70 e) {..struct app
6590: 66 73 5f 70 61 74 68 69 6e 66 6f 20 70 61 74 68 fs_pathinfo path
65a0: 69 6e 66 6f 3b 0a 09 69 6e 74 20 72 65 74 76 61 info;..int retva
65b0: 6c 20 3d 20 30 3b 0a 0a 09 41 50 50 46 53 5f 44 l = 0;...APPFS_D
65c0: 45 42 55 47 28 22 45 6e 74 65 72 20 28 70 61 74 EBUG("Enter (pat
65d0: 68 20 3d 20 25 73 2c 20 2e 2e 2e 29 22 2c 20 70 h = %s, ...)", p
65e0: 61 74 68 29 3b 0a 0a 09 70 61 74 68 69 6e 66 6f ath);...pathinfo
65f0: 2e 74 79 70 65 20 3d 20 41 50 50 46 53 5f 50 41 .type = APPFS_PA
6600: 54 48 54 59 50 45 5f 49 4e 56 41 4c 49 44 3b 0a THTYPE_INVALID;.
6610: 0a 09 72 65 74 76 61 6c 20 3d 20 61 70 70 66 73 ..retval = appfs
6620: 5f 67 65 74 5f 70 61 74 68 5f 69 6e 66 6f 28 70 _get_path_info(p
6630: 61 74 68 2c 20 26 70 61 74 68 69 6e 66 6f 29 3b ath, &pathinfo);
6640: 0a 09 69 66 20 28 72 65 74 76 61 6c 20 21 3d 20 ..if (retval !=
6650: 30 29 20 7b 0a 09 09 72 65 74 75 72 6e 28 72 65 0) {...return(re
6660: 74 76 61 6c 29 3b 0a 09 7d 0a 0a 09 69 66 20 28 tval);..}...if (
6670: 70 61 74 68 69 6e 66 6f 2e 74 79 70 65 20 21 3d pathinfo.type !=
6680: 20 41 50 50 46 53 5f 50 41 54 48 54 59 50 45 5f APPFS_PATHTYPE_
6690: 53 59 4d 4c 49 4e 4b 29 20 7b 0a 09 09 72 65 74 SYMLINK) {...ret
66a0: 75 72 6e 28 2d 45 49 4e 56 41 4c 29 3b 0a 09 7d urn(-EINVAL);..}
66b0: 0a 0a 09 69 66 20 28 28 73 74 72 6c 65 6e 28 70 ...if ((strlen(p
66c0: 61 74 68 69 6e 66 6f 2e 74 79 70 65 69 6e 66 6f athinfo.typeinfo
66d0: 2e 73 79 6d 6c 69 6e 6b 2e 73 6f 75 72 63 65 29 .symlink.source)
66e0: 20 2b 20 31 29 20 3e 20 73 69 7a 65 29 20 7b 0a + 1) > size) {.
66f0: 09 09 72 65 74 75 72 6e 28 2d 45 4e 41 4d 45 54 ..return(-ENAMET
6700: 4f 4f 4c 4f 4e 47 29 3b 0a 09 7d 0a 0a 09 6d 65 OOLONG);..}...me
6710: 6d 63 70 79 28 62 75 66 2c 20 70 61 74 68 69 6e mcpy(buf, pathin
6720: 66 6f 2e 74 79 70 65 69 6e 66 6f 2e 73 79 6d 6c fo.typeinfo.syml
6730: 69 6e 6b 2e 73 6f 75 72 63 65 2c 20 73 74 72 6c ink.source, strl
6740: 65 6e 28 70 61 74 68 69 6e 66 6f 2e 74 79 70 65 en(pathinfo.type
6750: 69 6e 66 6f 2e 73 79 6d 6c 69 6e 6b 2e 73 6f 75 info.symlink.sou
6760: 72 63 65 29 20 2b 20 31 29 3b 0a 0a 09 72 65 74 rce) + 1);...ret
6770: 75 72 6e 28 30 29 3b 0a 7d 0a 0a 73 74 61 74 69 urn(0);.}..stati
6780: 63 20 69 6e 74 20 61 70 70 66 73 5f 66 75 73 65 c int appfs_fuse
6790: 5f 67 65 74 61 74 74 72 28 63 6f 6e 73 74 20 63 _getattr(const c
67a0: 68 61 72 20 2a 70 61 74 68 2c 20 73 74 72 75 63 har *path, struc
67b0: 74 20 73 74 61 74 20 2a 73 74 62 75 66 29 20 7b t stat *stbuf) {
67c0: 0a 09 73 74 72 75 63 74 20 61 70 70 66 73 5f 70 ..struct appfs_p
67d0: 61 74 68 69 6e 66 6f 20 70 61 74 68 69 6e 66 6f athinfo pathinfo
67e0: 3b 0a 09 69 6e 74 20 72 65 74 76 61 6c 3b 0a 0a ;..int retval;..
67f0: 09 72 65 74 76 61 6c 20 3d 20 30 3b 0a 0a 09 41 .retval = 0;...A
6800: 50 50 46 53 5f 44 45 42 55 47 28 22 45 6e 74 65 PPFS_DEBUG("Ente
6810: 72 20 28 70 61 74 68 20 3d 20 25 73 2c 20 2e 2e r (path = %s, ..
6820: 2e 29 22 2c 20 70 61 74 68 29 3b 0a 0a 23 69 66 .)", path);..#if
6830: 20 28 64 65 66 69 6e 65 64 28 44 45 42 55 47 29 (defined(DEBUG)
6840: 20 26 26 20 64 65 66 69 6e 65 64 28 41 50 50 46 && defined(APPF
6850: 53 5f 45 58 49 54 5f 50 41 54 48 29 29 20 7c 7c S_EXIT_PATH)) ||
6860: 20 64 65 66 69 6e 65 64 28 41 50 50 46 53 5f 45 defined(APPFS_E
6870: 58 49 54 5f 50 41 54 48 5f 45 4e 41 42 4c 45 5f XIT_PATH_ENABLE_
6880: 4d 41 4a 4f 52 5f 53 45 43 55 52 49 54 59 5f 48 MAJOR_SECURITY_H
6890: 4f 4c 45 29 0a 09 2f 2a 0a 09 20 2a 20 54 68 69 OLE)../*.. * Thi
68a0: 73 20 69 73 20 61 20 6d 61 6a 6f 72 20 73 65 63 s is a major sec
68b0: 75 72 69 74 79 20 69 73 73 75 65 20 73 6f 20 77 urity issue so w
68c0: 65 20 63 61 6e 6e 6f 74 20 6c 65 74 20 69 74 20 e cannot let it
68d0: 62 65 20 63 6f 6d 70 69 6c 65 64 20 69 6e 74 6f be compiled into
68e0: 0a 09 20 2a 20 61 6e 79 20 72 65 6c 65 61 73 65 .. * any release
68f0: 0a 09 20 2a 2f 0a 0a 09 69 66 20 28 73 74 72 63 .. */...if (strc
6900: 6d 70 28 70 61 74 68 2c 20 22 2f 65 78 69 74 22 mp(path, "/exit"
6910: 29 20 3d 3d 20 30 29 20 7b 0a 09 09 61 70 70 66 ) == 0) {...appf
6920: 73 5f 65 78 69 74 28 29 3b 0a 09 7d 0a 23 65 6e s_exit();..}.#en
6930: 64 69 66 0a 0a 09 70 61 74 68 69 6e 66 6f 2e 74 dif...pathinfo.t
6940: 79 70 65 20 3d 20 41 50 50 46 53 5f 50 41 54 48 ype = APPFS_PATH
6950: 54 59 50 45 5f 49 4e 56 41 4c 49 44 3b 0a 0a 09 TYPE_INVALID;...
6960: 72 65 74 76 61 6c 20 3d 20 61 70 70 66 73 5f 67 retval = appfs_g
6970: 65 74 5f 70 61 74 68 5f 69 6e 66 6f 28 70 61 74 et_path_info(pat
6980: 68 2c 20 26 70 61 74 68 69 6e 66 6f 29 3b 0a 09 h, &pathinfo);..
6990: 69 66 20 28 72 65 74 76 61 6c 20 21 3d 20 30 29 if (retval != 0)
69a0: 20 7b 0a 09 09 69 66 20 28 72 65 74 76 61 6c 20 {...if (retval
69b0: 3d 3d 20 2d 45 4e 4f 45 4e 54 29 20 7b 0a 09 09 == -ENOENT) {...
69c0: 09 41 50 50 46 53 5f 44 45 42 55 47 28 22 67 65 .APPFS_DEBUG("ge
69d0: 74 5f 70 61 74 68 5f 69 6e 66 6f 20 72 65 74 75 t_path_info retu
69e0: 72 6e 65 64 20 45 4e 4f 45 4e 54 2c 20 72 65 74 rned ENOENT, ret
69f0: 75 72 6e 69 6e 67 20 69 74 20 61 73 20 77 65 6c urning it as wel
6a00: 6c 2e 22 29 3b 0a 09 09 7d 20 65 6c 73 65 20 7b l.");...} else {
6a10: 0a 09 09 09 41 50 50 46 53 5f 44 45 42 55 47 28 ....APPFS_DEBUG(
6a20: 22 65 72 72 6f 72 3a 20 67 65 74 5f 70 61 74 68 "error: get_path
6a30: 5f 69 6e 66 6f 20 66 61 69 6c 65 64 22 29 3b 0a _info failed");.
6a40: 09 09 7d 0a 0a 09 09 72 65 74 75 72 6e 28 72 65 ..}....return(re
6a50: 74 76 61 6c 29 3b 0a 09 7d 0a 0a 09 6d 65 6d 73 tval);..}...mems
6a60: 65 74 28 73 74 62 75 66 2c 20 30 2c 20 73 69 7a et(stbuf, 0, siz
6a70: 65 6f 66 28 73 74 72 75 63 74 20 73 74 61 74 29 eof(struct stat)
6a80: 29 3b 0a 0a 09 73 74 62 75 66 2d 3e 73 74 5f 6d );...stbuf->st_m
6a90: 74 69 6d 65 20 3d 20 70 61 74 68 69 6e 66 6f 2e time = pathinfo.
6aa0: 74 69 6d 65 3b 0a 09 73 74 62 75 66 2d 3e 73 74 time;..stbuf->st
6ab0: 5f 63 74 69 6d 65 20 3d 20 70 61 74 68 69 6e 66 _ctime = pathinf
6ac0: 6f 2e 74 69 6d 65 3b 0a 09 73 74 62 75 66 2d 3e o.time;..stbuf->
6ad0: 73 74 5f 61 74 69 6d 65 20 3d 20 70 61 74 68 69 st_atime = pathi
6ae0: 6e 66 6f 2e 74 69 6d 65 3b 0a 09 73 74 62 75 66 nfo.time;..stbuf
6af0: 2d 3e 73 74 5f 69 6e 6f 20 20 20 3d 20 70 61 74 ->st_ino = pat
6b00: 68 69 6e 66 6f 2e 69 6e 6f 64 65 3b 0a 09 73 74 hinfo.inode;..st
6b10: 62 75 66 2d 3e 73 74 5f 6d 6f 64 65 20 20 3d 20 buf->st_mode =
6b20: 30 3b 0a 0a 09 73 77 69 74 63 68 20 28 70 61 74 0;...switch (pat
6b30: 68 69 6e 66 6f 2e 74 79 70 65 29 20 7b 0a 09 09 hinfo.type) {...
6b40: 63 61 73 65 20 41 50 50 46 53 5f 50 41 54 48 54 case APPFS_PATHT
6b50: 59 50 45 5f 44 49 52 45 43 54 4f 52 59 3a 0a 09 YPE_DIRECTORY:..
6b60: 09 09 73 74 62 75 66 2d 3e 73 74 5f 6d 6f 64 65 ..stbuf->st_mode
6b70: 20 3d 20 53 5f 49 46 44 49 52 20 7c 20 30 35 35 = S_IFDIR | 055
6b80: 35 3b 0a 09 09 09 73 74 62 75 66 2d 3e 73 74 5f 5;....stbuf->st_
6b90: 6e 6c 69 6e 6b 20 3d 20 32 20 2b 20 70 61 74 68 nlink = 2 + path
6ba0: 69 6e 66 6f 2e 74 79 70 65 69 6e 66 6f 2e 64 69 info.typeinfo.di
6bb0: 72 2e 63 68 69 6c 64 63 6f 75 6e 74 3b 0a 09 09 r.childcount;...
6bc0: 09 62 72 65 61 6b 3b 0a 09 09 63 61 73 65 20 41 .break;...case A
6bd0: 50 50 46 53 5f 50 41 54 48 54 59 50 45 5f 46 49 PPFS_PATHTYPE_FI
6be0: 4c 45 3a 0a 09 09 09 69 66 20 28 70 61 74 68 69 LE:....if (pathi
6bf0: 6e 66 6f 2e 74 79 70 65 69 6e 66 6f 2e 66 69 6c nfo.typeinfo.fil
6c00: 65 2e 65 78 65 63 75 74 61 62 6c 65 29 20 7b 0a e.executable) {.
6c10: 09 09 09 09 73 74 62 75 66 2d 3e 73 74 5f 6d 6f ....stbuf->st_mo
6c20: 64 65 20 3d 20 53 5f 49 46 52 45 47 20 7c 20 30 de = S_IFREG | 0
6c30: 35 35 35 3b 0a 09 09 09 7d 20 65 6c 73 65 20 7b 555;....} else {
6c40: 0a 09 09 09 09 73 74 62 75 66 2d 3e 73 74 5f 6d .....stbuf->st_m
6c50: 6f 64 65 20 3d 20 53 5f 49 46 52 45 47 20 7c 20 ode = S_IFREG |
6c60: 30 34 34 34 3b 0a 09 09 09 7d 0a 0a 09 09 09 73 0444;....}.....s
6c70: 74 62 75 66 2d 3e 73 74 5f 6e 6c 69 6e 6b 20 3d tbuf->st_nlink =
6c80: 20 31 3b 0a 09 09 09 73 74 62 75 66 2d 3e 73 74 1;....stbuf->st
6c90: 5f 73 69 7a 65 20 3d 20 70 61 74 68 69 6e 66 6f _size = pathinfo
6ca0: 2e 74 79 70 65 69 6e 66 6f 2e 66 69 6c 65 2e 73 .typeinfo.file.s
6cb0: 69 7a 65 3b 0a 09 09 09 62 72 65 61 6b 3b 0a 09 ize;....break;..
6cc0: 09 63 61 73 65 20 41 50 50 46 53 5f 50 41 54 48 .case APPFS_PATH
6cd0: 54 59 50 45 5f 53 59 4d 4c 49 4e 4b 3a 0a 09 09 TYPE_SYMLINK:...
6ce0: 09 73 74 62 75 66 2d 3e 73 74 5f 6d 6f 64 65 20 .stbuf->st_mode
6cf0: 3d 20 53 5f 49 46 4c 4e 4b 20 7c 20 30 35 35 35 = S_IFLNK | 0555
6d00: 3b 0a 09 09 09 73 74 62 75 66 2d 3e 73 74 5f 6e ;....stbuf->st_n
6d10: 6c 69 6e 6b 20 3d 20 31 3b 0a 09 09 09 73 74 62 link = 1;....stb
6d20: 75 66 2d 3e 73 74 5f 73 69 7a 65 20 3d 20 70 61 uf->st_size = pa
6d30: 74 68 69 6e 66 6f 2e 74 79 70 65 69 6e 66 6f 2e thinfo.typeinfo.
6d40: 73 79 6d 6c 69 6e 6b 2e 73 69 7a 65 3b 0a 09 09 symlink.size;...
6d50: 09 62 72 65 61 6b 3b 0a 09 09 63 61 73 65 20 41 .break;...case A
6d60: 50 50 46 53 5f 50 41 54 48 54 59 50 45 5f 53 4f PPFS_PATHTYPE_SO
6d70: 43 4b 45 54 3a 0a 09 09 09 73 74 62 75 66 2d 3e CKET:....stbuf->
6d80: 73 74 5f 6d 6f 64 65 20 3d 20 53 5f 49 46 53 4f st_mode = S_IFSO
6d90: 43 4b 20 7c 20 30 35 35 35 3b 0a 09 09 09 73 74 CK | 0555;....st
6da0: 62 75 66 2d 3e 73 74 5f 6e 6c 69 6e 6b 20 3d 20 buf->st_nlink =
6db0: 31 3b 0a 09 09 09 73 74 62 75 66 2d 3e 73 74 5f 1;....stbuf->st_
6dc0: 73 69 7a 65 20 3d 20 30 3b 0a 09 09 09 62 72 65 size = 0;....bre
6dd0: 61 6b 3b 0a 09 09 63 61 73 65 20 41 50 50 46 53 ak;...case APPFS
6de0: 5f 50 41 54 48 54 59 50 45 5f 46 49 46 4f 3a 0a _PATHTYPE_FIFO:.
6df0: 09 09 09 73 74 62 75 66 2d 3e 73 74 5f 6d 6f 64 ...stbuf->st_mod
6e00: 65 20 3d 20 53 5f 49 46 49 46 4f 20 7c 20 30 35 e = S_IFIFO | 05
6e10: 35 35 3b 0a 09 09 09 73 74 62 75 66 2d 3e 73 74 55;....stbuf->st
6e20: 5f 6e 6c 69 6e 6b 20 3d 20 31 3b 0a 09 09 09 73 _nlink = 1;....s
6e30: 74 62 75 66 2d 3e 73 74 5f 73 69 7a 65 20 3d 20 tbuf->st_size =
6e40: 30 3b 0a 09 09 09 62 72 65 61 6b 3b 0a 09 09 63 0;....break;...c
6e50: 61 73 65 20 41 50 50 46 53 5f 50 41 54 48 54 59 ase APPFS_PATHTY
6e60: 50 45 5f 44 4f 45 53 5f 4e 4f 54 5f 45 58 49 53 PE_DOES_NOT_EXIS
6e70: 54 3a 0a 09 09 09 72 65 74 76 61 6c 20 3d 20 2d T:....retval = -
6e80: 45 4e 4f 45 4e 54 3b 0a 0a 09 09 09 62 72 65 61 ENOENT;.....brea
6e90: 6b 3b 0a 09 09 63 61 73 65 20 41 50 50 46 53 5f k;...case APPFS_
6ea0: 50 41 54 48 54 59 50 45 5f 49 4e 56 41 4c 49 44 PATHTYPE_INVALID
6eb0: 3a 0a 09 09 09 72 65 74 76 61 6c 20 3d 20 2d 45 :....retval = -E
6ec0: 49 4f 3b 0a 0a 09 09 09 62 72 65 61 6b 3b 0a 09 IO;.....break;..
6ed0: 7d 0a 0a 09 69 66 20 28 70 61 74 68 69 6e 66 6f }...if (pathinfo
6ee0: 2e 70 61 63 6b 61 67 65 64 29 20 7b 0a 09 09 73 .packaged) {...s
6ef0: 74 62 75 66 2d 3e 73 74 5f 75 69 64 20 20 20 3d tbuf->st_uid =
6f00: 20 61 70 70 66 73 5f 67 65 74 5f 66 73 75 69 64 appfs_get_fsuid
6f10: 28 29 3b 0a 09 09 73 74 62 75 66 2d 3e 73 74 5f ();...stbuf->st_
6f20: 67 69 64 20 20 20 3d 20 61 70 70 66 73 5f 67 65 gid = appfs_ge
6f30: 74 5f 66 73 67 69 64 28 29 3b 0a 09 09 73 74 62 t_fsgid();...stb
6f40: 75 66 2d 3e 73 74 5f 6d 6f 64 65 20 7c 3d 20 30 uf->st_mode |= 0
6f50: 32 30 30 3b 0a 09 7d 0a 0a 09 72 65 74 75 72 6e 200;..}...return
6f60: 28 72 65 74 76 61 6c 29 3b 0a 7d 0a 0a 73 74 61 (retval);.}..sta
6f70: 74 69 63 20 69 6e 74 20 61 70 70 66 73 5f 66 75 tic int appfs_fu
6f80: 73 65 5f 72 65 61 64 64 69 72 28 63 6f 6e 73 74 se_readdir(const
6f90: 20 63 68 61 72 20 2a 70 61 74 68 2c 20 76 6f 69 char *path, voi
6fa0: 64 20 2a 62 75 66 2c 20 66 75 73 65 5f 66 69 6c d *buf, fuse_fil
6fb0: 6c 5f 64 69 72 5f 74 20 66 69 6c 6c 65 72 2c 20 l_dir_t filler,
6fc0: 6f 66 66 5f 74 20 6f 66 66 73 65 74 2c 20 73 74 off_t offset, st
6fd0: 72 75 63 74 20 66 75 73 65 5f 66 69 6c 65 5f 69 ruct fuse_file_i
6fe0: 6e 66 6f 20 2a 66 69 29 20 7b 0a 09 54 63 6c 5f nfo *fi) {..Tcl_
6ff0: 49 6e 74 65 72 70 20 2a 69 6e 74 65 72 70 3b 0a Interp *interp;.
7000: 09 54 63 6c 5f 4f 62 6a 20 2a 2a 63 68 69 6c 64 .Tcl_Obj **child
7010: 72 65 6e 3b 0a 09 69 6e 74 20 63 68 69 6c 64 72 ren;..int childr
7020: 65 6e 5f 63 6f 75 6e 74 2c 20 69 64 78 3b 0a 09 en_count, idx;..
7030: 69 6e 74 20 74 63 6c 5f 72 65 74 3b 0a 0a 09 41 int tcl_ret;...A
7040: 50 50 46 53 5f 44 45 42 55 47 28 22 45 6e 74 65 PPFS_DEBUG("Ente
7050: 72 20 28 70 61 74 68 20 3d 20 25 73 2c 20 2e 2e r (path = %s, ..
7060: 2e 29 22 2c 20 70 61 74 68 29 3b 0a 0a 09 69 6e .)", path);...in
7070: 74 65 72 70 20 3d 20 61 70 70 66 73 5f 54 63 6c terp = appfs_Tcl
7080: 49 6e 74 65 72 70 28 29 3b 0a 09 69 66 20 28 69 Interp();..if (i
7090: 6e 74 65 72 70 20 3d 3d 20 4e 55 4c 4c 29 20 7b nterp == NULL) {
70a0: 0a 09 09 41 50 50 46 53 5f 44 45 42 55 47 28 22 ...APPFS_DEBUG("
70b0: 65 72 72 6f 72 3a 20 55 6e 61 62 6c 65 20 74 6f error: Unable to
70c0: 20 67 65 74 20 61 6e 20 69 6e 74 65 72 70 72 65 get an interpre
70d0: 74 65 72 22 29 3b 0a 0a 09 09 72 65 74 75 72 6e ter");....return
70e0: 28 30 29 3b 0a 09 7d 0a 0a 09 61 70 70 66 73 5f (0);..}...appfs_
70f0: 63 61 6c 6c 5f 6c 69 62 74 63 6c 28 54 63 6c 5f call_libtcl(Tcl_
7100: 50 72 65 73 65 72 76 65 28 69 6e 74 65 72 70 29 Preserve(interp)
7110: 3b 29 0a 0a 09 66 69 6c 6c 65 72 28 62 75 66 2c ;)...filler(buf,
7120: 20 22 2e 22 2c 20 4e 55 4c 4c 2c 20 30 29 3b 0a ".", NULL, 0);.
7130: 09 66 69 6c 6c 65 72 28 62 75 66 2c 20 22 2e 2e .filler(buf, "..
7140: 22 2c 20 4e 55 4c 4c 2c 20 30 29 3b 0a 0a 09 74 ", NULL, 0);...t
7150: 63 6c 5f 72 65 74 20 3d 20 61 70 70 66 73 5f 54 cl_ret = appfs_T
7160: 63 6c 5f 45 76 61 6c 28 69 6e 74 65 72 70 2c 20 cl_Eval(interp,
7170: 32 2c 20 22 3a 3a 61 70 70 66 73 3a 3a 67 65 74 2, "::appfs::get
7180: 63 68 69 6c 64 72 65 6e 22 2c 20 70 61 74 68 29 children", path)
7190: 3b 0a 09 69 66 20 28 74 63 6c 5f 72 65 74 20 21 ;..if (tcl_ret !
71a0: 3d 20 54 43 4c 5f 4f 4b 29 20 7b 0a 09 09 41 50 = TCL_OK) {...AP
71b0: 50 46 53 5f 44 45 42 55 47 28 22 3a 3a 61 70 70 PFS_DEBUG("::app
71c0: 66 73 3a 3a 67 65 74 63 68 69 6c 64 72 65 6e 28 fs::getchildren(
71d0: 25 73 29 20 66 61 69 6c 65 64 2e 22 2c 20 70 61 %s) failed.", pa
71e0: 74 68 29 3b 0a 09 09 61 70 70 66 73 5f 63 61 6c th);...appfs_cal
71f0: 6c 5f 6c 69 62 74 63 6c 28 0a 09 09 09 41 50 50 l_libtcl(....APP
7200: 46 53 5f 44 45 42 55 47 28 22 54 63 6c 20 45 72 FS_DEBUG("Tcl Er
7210: 72 6f 72 20 69 73 3a 20 25 73 22 2c 20 54 63 6c ror is: %s", Tcl
7220: 5f 47 65 74 53 74 72 69 6e 67 52 65 73 75 6c 74 _GetStringResult
7230: 28 69 6e 74 65 72 70 29 29 3b 0a 09 09 29 0a 0a (interp));...)..
7240: 09 09 61 70 70 66 73 5f 63 61 6c 6c 5f 6c 69 62 ..appfs_call_lib
7250: 74 63 6c 28 54 63 6c 5f 52 65 6c 65 61 73 65 28 tcl(Tcl_Release(
7260: 69 6e 74 65 72 70 29 3b 29 0a 0a 09 09 72 65 74 interp);)....ret
7270: 75 72 6e 28 30 29 3b 0a 09 7d 0a 0a 09 61 70 70 urn(0);..}...app
7280: 66 73 5f 63 61 6c 6c 5f 6c 69 62 74 63 6c 28 0a fs_call_libtcl(.
7290: 09 09 74 63 6c 5f 72 65 74 20 3d 20 54 63 6c 5f ..tcl_ret = Tcl_
72a0: 4c 69 73 74 4f 62 6a 47 65 74 45 6c 65 6d 65 6e ListObjGetElemen
72b0: 74 73 28 69 6e 74 65 72 70 2c 20 54 63 6c 5f 47 ts(interp, Tcl_G
72c0: 65 74 4f 62 6a 52 65 73 75 6c 74 28 69 6e 74 65 etObjResult(inte
72d0: 72 70 29 2c 20 26 63 68 69 6c 64 72 65 6e 5f 63 rp), &children_c
72e0: 6f 75 6e 74 2c 20 26 63 68 69 6c 64 72 65 6e 29 ount, &children)
72f0: 3b 0a 09 29 0a 09 69 66 20 28 74 63 6c 5f 72 65 ;..)..if (tcl_re
7300: 74 20 21 3d 20 54 43 4c 5f 4f 4b 29 20 7b 0a 09 t != TCL_OK) {..
7310: 09 41 50 50 46 53 5f 44 45 42 55 47 28 22 50 61 .APPFS_DEBUG("Pa
7320: 72 73 69 6e 67 20 6c 69 73 74 20 6f 66 20 63 68 rsing list of ch
7330: 69 6c 64 72 65 6e 20 6f 6e 20 70 61 74 68 20 25 ildren on path %
7340: 73 20 66 61 69 6c 65 64 2e 22 2c 20 70 61 74 68 s failed.", path
7350: 29 3b 0a 09 09 61 70 70 66 73 5f 63 61 6c 6c 5f );...appfs_call_
7360: 6c 69 62 74 63 6c 28 0a 09 09 09 41 50 50 46 53 libtcl(....APPFS
7370: 5f 44 45 42 55 47 28 22 54 63 6c 20 45 72 72 6f _DEBUG("Tcl Erro
7380: 72 20 69 73 3a 20 25 73 22 2c 20 54 63 6c 5f 47 r is: %s", Tcl_G
7390: 65 74 53 74 72 69 6e 67 52 65 73 75 6c 74 28 69 etStringResult(i
73a0: 6e 74 65 72 70 29 29 3b 0a 09 09 29 0a 0a 09 09 nterp));...)....
73b0: 61 70 70 66 73 5f 63 61 6c 6c 5f 6c 69 62 74 63 appfs_call_libtc
73c0: 6c 28 54 63 6c 5f 52 65 6c 65 61 73 65 28 69 6e l(Tcl_Release(in
73d0: 74 65 72 70 29 3b 29 0a 0a 09 09 72 65 74 75 72 terp);)....retur
73e0: 6e 28 30 29 3b 0a 09 7d 0a 0a 09 66 6f 72 20 28 n(0);..}...for (
73f0: 69 64 78 20 3d 20 30 3b 20 69 64 78 20 3c 20 63 idx = 0; idx < c
7400: 68 69 6c 64 72 65 6e 5f 63 6f 75 6e 74 3b 20 69 hildren_count; i
7410: 64 78 2b 2b 29 20 7b 0a 09 09 61 70 70 66 73 5f dx++) {...appfs_
7420: 63 61 6c 6c 5f 6c 69 62 74 63 6c 28 0a 09 09 09 call_libtcl(....
7430: 66 69 6c 6c 65 72 28 62 75 66 2c 20 54 63 6c 5f filler(buf, Tcl_
7440: 47 65 74 53 74 72 69 6e 67 28 63 68 69 6c 64 72 GetString(childr
7450: 65 6e 5b 69 64 78 5d 29 2c 20 4e 55 4c 4c 2c 20 en[idx]), NULL,
7460: 30 29 3b 0a 09 09 29 0a 09 7d 0a 0a 09 61 70 70 0);...)..}...app
7470: 66 73 5f 63 61 6c 6c 5f 6c 69 62 74 63 6c 28 54 fs_call_libtcl(T
7480: 63 6c 5f 52 65 6c 65 61 73 65 28 69 6e 74 65 72 cl_Release(inter
7490: 70 29 3b 29 0a 0a 09 72 65 74 75 72 6e 28 30 29 p);)...return(0)
74a0: 3b 0a 7d 0a 0a 73 74 61 74 69 63 20 69 6e 74 20 ;.}..static int
74b0: 61 70 70 66 73 5f 66 75 73 65 5f 6f 70 65 6e 28 appfs_fuse_open(
74c0: 63 6f 6e 73 74 20 63 68 61 72 20 2a 70 61 74 68 const char *path
74d0: 2c 20 73 74 72 75 63 74 20 66 75 73 65 5f 66 69 , struct fuse_fi
74e0: 6c 65 5f 69 6e 66 6f 20 2a 66 69 29 20 7b 0a 09 le_info *fi) {..
74f0: 54 63 6c 5f 49 6e 74 65 72 70 20 2a 69 6e 74 65 Tcl_Interp *inte
7500: 72 70 3b 0a 09 73 74 72 75 63 74 20 61 70 70 66 rp;..struct appf
7510: 73 5f 70 61 74 68 69 6e 66 6f 20 70 61 74 68 69 s_pathinfo pathi
7520: 6e 66 6f 3b 0a 09 63 6f 6e 73 74 20 63 68 61 72 nfo;..const char
7530: 20 2a 72 65 61 6c 5f 70 61 74 68 2c 20 2a 6d 6f *real_path, *mo
7540: 64 65 3b 0a 09 69 6e 74 20 67 70 69 5f 72 65 74 de;..int gpi_ret
7550: 2c 20 74 63 6c 5f 72 65 74 3b 0a 09 69 6e 74 20 , tcl_ret;..int
7560: 66 68 3b 0a 0a 09 41 50 50 46 53 5f 44 45 42 55 fh;...APPFS_DEBU
7570: 47 28 22 45 6e 74 65 72 20 28 70 61 74 68 20 3d G("Enter (path =
7580: 20 25 73 2c 20 2e 2e 2e 29 22 2c 20 70 61 74 68 %s, ...)", path
7590: 29 3b 0a 0a 09 67 70 69 5f 72 65 74 20 3d 20 61 );...gpi_ret = a
75a0: 70 70 66 73 5f 67 65 74 5f 70 61 74 68 5f 69 6e ppfs_get_path_in
75b0: 66 6f 28 70 61 74 68 2c 20 26 70 61 74 68 69 6e fo(path, &pathin
75c0: 66 6f 29 3b 0a 0a 09 69 66 20 28 28 66 69 2d 3e fo);...if ((fi->
75d0: 66 6c 61 67 73 20 26 20 28 4f 5f 57 52 4f 4e 4c flags & (O_WRONL
75e0: 59 7c 4f 5f 43 52 45 41 54 29 29 20 3d 3d 20 28 Y|O_CREAT)) == (
75f0: 4f 5f 43 52 45 41 54 7c 4f 5f 57 52 4f 4e 4c 59 O_CREAT|O_WRONLY
7600: 29 29 20 7b 0a 09 09 2f 2a 20 54 68 65 20 66 69 )) {.../* The fi
7610: 6c 65 20 77 69 6c 6c 20 62 65 20 63 72 65 61 74 le will be creat
7620: 65 64 20 69 66 20 69 74 20 64 6f 65 73 20 6e 6f ed if it does no
7630: 74 20 65 78 69 73 74 20 2a 2f 0a 09 09 69 66 20 t exist */...if
7640: 28 67 70 69 5f 72 65 74 20 21 3d 20 30 20 26 26 (gpi_ret != 0 &&
7650: 20 67 70 69 5f 72 65 74 20 21 3d 20 2d 45 4e 4f gpi_ret != -ENO
7660: 45 4e 54 29 20 7b 0a 09 09 09 41 50 50 46 53 5f ENT) {....APPFS_
7670: 44 45 42 55 47 28 22 65 72 72 6f 72 3a 20 67 65 DEBUG("error: ge
7680: 74 5f 70 61 74 68 5f 69 6e 66 6f 20 66 61 69 6c t_path_info fail
7690: 65 64 22 29 3b 0a 0a 09 09 09 72 65 74 75 72 6e ed");.....return
76a0: 28 67 70 69 5f 72 65 74 29 3b 0a 09 09 7d 0a 0a (gpi_ret);...}..
76b0: 09 09 6d 6f 64 65 20 3d 20 22 63 72 65 61 74 65 ..mode = "create
76c0: 22 3b 0a 0a 09 09 2f 2a 0a 09 09 20 2a 20 57 65 ";..../*... * We
76d0: 20 68 61 76 65 20 74 6f 20 63 6c 65 61 72 20 74 have to clear t
76e0: 68 65 20 63 61 63 68 65 20 68 65 72 65 20 73 6f he cache here so
76f0: 20 74 68 61 74 20 74 68 65 20 6e 75 6d 62 65 72 that the number
7700: 20 6f 66 0a 09 09 20 2a 20 6c 69 6e 6b 73 20 67 of... * links g
7710: 65 74 73 20 6d 61 69 6e 74 61 69 6e 65 64 20 6f ets maintained o
7720: 6e 20 74 68 65 20 70 61 72 65 6e 74 20 64 69 72 n the parent dir
7730: 65 63 74 6f 72 79 0a 09 09 20 2a 2f 0a 09 09 61 ectory... */...a
7740: 70 70 66 73 5f 67 65 74 5f 70 61 74 68 5f 69 6e ppfs_get_path_in
7750: 66 6f 5f 63 61 63 68 65 5f 66 6c 75 73 68 28 61 fo_cache_flush(a
7760: 70 70 66 73 5f 67 65 74 5f 66 73 75 69 64 28 29 ppfs_get_fsuid()
7770: 2c 20 2d 31 29 3b 0a 09 7d 20 65 6c 73 65 20 7b , -1);..} else {
7780: 0a 09 09 2f 2a 20 54 68 65 20 66 69 6c 65 20 6d .../* The file m
7790: 75 73 74 20 61 6c 72 65 61 64 79 20 65 78 69 73 ust already exis
77a0: 74 20 2a 2f 0a 09 09 69 66 20 28 67 70 69 5f 72 t */...if (gpi_r
77b0: 65 74 20 21 3d 20 30 29 20 7b 0a 09 09 09 41 50 et != 0) {....AP
77c0: 50 46 53 5f 44 45 42 55 47 28 22 65 72 72 6f 72 PFS_DEBUG("error
77d0: 3a 20 67 65 74 5f 70 61 74 68 5f 69 6e 66 6f 20 : get_path_info
77e0: 66 61 69 6c 65 64 22 29 3b 0a 0a 09 09 09 72 65 failed");.....re
77f0: 74 75 72 6e 28 67 70 69 5f 72 65 74 29 3b 0a 09 turn(gpi_ret);..
7800: 09 7d 0a 0a 09 09 6d 6f 64 65 20 3d 20 22 22 3b .}....mode = "";
7810: 0a 0a 09 09 69 66 20 28 28 66 69 2d 3e 66 6c 61 ....if ((fi->fla
7820: 67 73 20 26 20 4f 5f 57 52 4f 4e 4c 59 29 20 3d gs & O_WRONLY) =
7830: 3d 20 4f 5f 57 52 4f 4e 4c 59 29 20 7b 0a 09 09 = O_WRONLY) {...
7840: 09 6d 6f 64 65 20 3d 20 22 77 72 69 74 65 22 3b .mode = "write";
7850: 0a 09 09 7d 0a 09 7d 0a 0a 09 69 66 20 28 70 61 ...}..}...if (pa
7860: 74 68 69 6e 66 6f 2e 74 79 70 65 20 3d 3d 20 41 thinfo.type == A
7870: 50 50 46 53 5f 50 41 54 48 54 59 50 45 5f 44 49 PPFS_PATHTYPE_DI
7880: 52 45 43 54 4f 52 59 29 20 7b 0a 09 09 41 50 50 RECTORY) {...APP
7890: 46 53 5f 44 45 42 55 47 28 22 65 72 72 6f 72 3a FS_DEBUG("error:
78a0: 20 41 73 6b 65 64 20 74 6f 20 6f 70 65 6e 20 61 Asked to open a
78b0: 20 64 69 72 65 63 74 6f 72 79 2e 22 29 3b 0a 0a directory.");..
78c0: 09 09 72 65 74 75 72 6e 28 2d 45 49 53 44 49 52 ..return(-EISDIR
78d0: 29 3b 0a 09 7d 0a 0a 09 69 6e 74 65 72 70 20 3d );..}...interp =
78e0: 20 61 70 70 66 73 5f 54 63 6c 49 6e 74 65 72 70 appfs_TclInterp
78f0: 28 29 3b 0a 09 69 66 20 28 69 6e 74 65 72 70 20 ();..if (interp
7900: 3d 3d 20 4e 55 4c 4c 29 20 7b 0a 09 09 41 50 50 == NULL) {...APP
7910: 46 53 5f 44 45 42 55 47 28 22 65 72 72 6f 72 3a FS_DEBUG("error:
7920: 20 55 6e 61 62 6c 65 20 74 6f 20 67 65 74 20 61 Unable to get a
7930: 6e 20 69 6e 74 65 72 70 72 65 74 65 72 22 29 3b n interpreter");
7940: 0a 0a 09 09 72 65 74 75 72 6e 28 2d 45 49 4f 29 ....return(-EIO)
7950: 3b 0a 09 7d 0a 0a 09 61 70 70 66 73 5f 63 61 6c ;..}...appfs_cal
7960: 6c 5f 6c 69 62 74 63 6c 28 54 63 6c 5f 50 72 65 l_libtcl(Tcl_Pre
7970: 73 65 72 76 65 28 69 6e 74 65 72 70 29 3b 29 0a serve(interp);).
7980: 0a 09 74 63 6c 5f 72 65 74 20 3d 20 61 70 70 66 ..tcl_ret = appf
7990: 73 5f 54 63 6c 5f 45 76 61 6c 28 69 6e 74 65 72 s_Tcl_Eval(inter
79a0: 70 2c 20 33 2c 20 22 3a 3a 61 70 70 66 73 3a 3a p, 3, "::appfs::
79b0: 6f 70 65 6e 70 61 74 68 22 2c 20 70 61 74 68 2c openpath", path,
79c0: 20 6d 6f 64 65 29 3b 0a 09 69 66 20 28 74 63 6c mode);..if (tcl
79d0: 5f 72 65 74 20 21 3d 20 54 43 4c 5f 4f 4b 29 20 _ret != TCL_OK)
79e0: 7b 0a 09 09 41 50 50 46 53 5f 44 45 42 55 47 28 {...APPFS_DEBUG(
79f0: 22 3a 3a 61 70 70 66 73 3a 3a 6f 70 65 6e 70 61 "::appfs::openpa
7a00: 74 68 28 25 73 2c 20 25 73 29 20 66 61 69 6c 65 th(%s, %s) faile
7a10: 64 2e 22 2c 20 70 61 74 68 2c 20 6d 6f 64 65 29 d.", path, mode)
7a20: 3b 0a 09 09 61 70 70 66 73 5f 63 61 6c 6c 5f 6c ;...appfs_call_l
7a30: 69 62 74 63 6c 28 0a 09 09 09 41 50 50 46 53 5f ibtcl(....APPFS_
7a40: 44 45 42 55 47 28 22 54 63 6c 20 45 72 72 6f 72 DEBUG("Tcl Error
7a50: 20 69 73 3a 20 25 73 22 2c 20 54 63 6c 5f 47 65 is: %s", Tcl_Ge
7a60: 74 53 74 72 69 6e 67 52 65 73 75 6c 74 28 69 6e tStringResult(in
7a70: 74 65 72 70 29 29 3b 0a 09 09 29 0a 0a 09 09 61 terp));...)....a
7a80: 70 70 66 73 5f 63 61 6c 6c 5f 6c 69 62 74 63 6c ppfs_call_libtcl
7a90: 28 54 63 6c 5f 52 65 6c 65 61 73 65 28 69 6e 74 (Tcl_Release(int
7aa0: 65 72 70 29 3b 29 0a 0a 09 09 72 65 74 75 72 6e erp);)....return
7ab0: 28 2d 45 49 4f 29 3b 0a 09 7d 0a 0a 09 61 70 70 (-EIO);..}...app
7ac0: 66 73 5f 63 61 6c 6c 5f 6c 69 62 74 63 6c 28 0a fs_call_libtcl(.
7ad0: 09 09 72 65 61 6c 5f 70 61 74 68 20 3d 20 54 63 ..real_path = Tc
7ae0: 6c 5f 47 65 74 53 74 72 69 6e 67 52 65 73 75 6c l_GetStringResul
7af0: 74 28 69 6e 74 65 72 70 29 3b 0a 09 29 0a 0a 09 t(interp);..)...
7b00: 61 70 70 66 73 5f 63 61 6c 6c 5f 6c 69 62 74 63 appfs_call_libtc
7b10: 6c 28 54 63 6c 5f 52 65 6c 65 61 73 65 28 69 6e l(Tcl_Release(in
7b20: 74 65 72 70 29 3b 29 0a 0a 09 69 66 20 28 72 65 terp);)...if (re
7b30: 61 6c 5f 70 61 74 68 20 3d 3d 20 4e 55 4c 4c 29 al_path == NULL)
7b40: 20 7b 0a 09 09 41 50 50 46 53 5f 44 45 42 55 47 {...APPFS_DEBUG
7b50: 28 22 65 72 72 6f 72 3a 20 72 65 61 6c 5f 70 61 ("error: real_pa
7b60: 74 68 20 77 61 73 20 4e 55 4c 4c 2e 22 29 0a 0a th was NULL.")..
7b70: 09 09 72 65 74 75 72 6e 28 2d 45 49 4f 29 3b 0a ..return(-EIO);.
7b80: 09 7d 0a 0a 09 41 50 50 46 53 5f 44 45 42 55 47 .}...APPFS_DEBUG
7b90: 28 22 54 72 61 6e 73 6c 61 74 65 64 20 72 65 71 ("Translated req
7ba0: 75 65 73 74 20 74 6f 20 6f 70 65 6e 20 25 73 20 uest to open %s
7bb0: 74 6f 20 6f 70 65 6e 69 6e 67 20 25 73 20 28 6d to opening %s (m
7bc0: 6f 64 65 20 3d 20 5c 22 25 73 5c 22 29 22 2c 20 ode = \"%s\")",
7bd0: 70 61 74 68 2c 20 72 65 61 6c 5f 70 61 74 68 2c path, real_path,
7be0: 20 6d 6f 64 65 29 3b 0a 0a 09 66 68 20 3d 20 6f mode);...fh = o
7bf0: 70 65 6e 28 72 65 61 6c 5f 70 61 74 68 2c 20 66 pen(real_path, f
7c00: 69 2d 3e 66 6c 61 67 73 2c 20 30 36 30 30 29 3b i->flags, 0600);
7c10: 0a 0a 09 69 66 20 28 66 68 20 3c 20 30 29 20 7b ...if (fh < 0) {
7c20: 0a 09 09 41 50 50 46 53 5f 44 45 42 55 47 28 22 ...APPFS_DEBUG("
7c30: 65 72 72 6f 72 3a 20 6f 70 65 6e 20 66 61 69 6c error: open fail
7c40: 65 64 22 29 3b 0a 0a 09 09 72 65 74 75 72 6e 28 ed");....return(
7c50: 65 72 72 6e 6f 20 2a 20 2d 31 29 3b 0a 09 7d 0a errno * -1);..}.
7c60: 0a 09 66 69 2d 3e 66 68 20 3d 20 66 68 3b 0a 0a ..fi->fh = fh;..
7c70: 09 72 65 74 75 72 6e 28 30 29 3b 0a 7d 0a 0a 73 .return(0);.}..s
7c80: 74 61 74 69 63 20 69 6e 74 20 61 70 70 66 73 5f tatic int appfs_
7c90: 66 75 73 65 5f 63 6c 6f 73 65 28 63 6f 6e 73 74 fuse_close(const
7ca0: 20 63 68 61 72 20 2a 70 61 74 68 2c 20 73 74 72 char *path, str
7cb0: 75 63 74 20 66 75 73 65 5f 66 69 6c 65 5f 69 6e uct fuse_file_in
7cc0: 66 6f 20 2a 66 69 29 20 7b 0a 09 69 6e 74 20 63 fo *fi) {..int c
7cd0: 6c 6f 73 65 5f 72 65 74 3b 0a 0a 09 61 70 70 66 lose_ret;...appf
7ce0: 73 5f 67 65 74 5f 70 61 74 68 5f 69 6e 66 6f 5f s_get_path_info_
7cf0: 63 61 63 68 65 5f 72 6d 28 70 61 74 68 2c 20 61 cache_rm(path, a
7d00: 70 70 66 73 5f 67 65 74 5f 66 73 75 69 64 28 29 ppfs_get_fsuid()
7d10: 29 3b 0a 0a 09 63 6c 6f 73 65 5f 72 65 74 20 3d );...close_ret =
7d20: 20 63 6c 6f 73 65 28 66 69 2d 3e 66 68 29 3b 0a close(fi->fh);.
7d30: 09 69 66 20 28 63 6c 6f 73 65 5f 72 65 74 20 21 .if (close_ret !
7d40: 3d 20 30 29 20 7b 0a 09 09 41 50 50 46 53 5f 44 = 0) {...APPFS_D
7d50: 45 42 55 47 28 22 65 72 72 6f 72 3a 20 63 6c 6f EBUG("error: clo
7d60: 73 65 20 66 61 69 6c 65 64 22 29 3b 0a 0a 09 09 se failed");....
7d70: 72 65 74 75 72 6e 28 65 72 72 6e 6f 20 2a 20 2d return(errno * -
7d80: 31 29 3b 0a 09 7d 0a 0a 09 72 65 74 75 72 6e 28 1);..}...return(
7d90: 30 29 3b 0a 7d 0a 0a 73 74 61 74 69 63 20 69 6e 0);.}..static in
7da0: 74 20 61 70 70 66 73 5f 66 75 73 65 5f 72 65 61 t appfs_fuse_rea
7db0: 64 28 63 6f 6e 73 74 20 63 68 61 72 20 2a 70 61 d(const char *pa
7dc0: 74 68 2c 20 63 68 61 72 20 2a 62 75 66 2c 20 73 th, char *buf, s
7dd0: 69 7a 65 5f 74 20 73 69 7a 65 2c 20 6f 66 66 5f ize_t size, off_
7de0: 74 20 6f 66 66 73 65 74 2c 20 73 74 72 75 63 74 t offset, struct
7df0: 20 66 75 73 65 5f 66 69 6c 65 5f 69 6e 66 6f 20 fuse_file_info
7e00: 2a 66 69 29 20 7b 0a 09 73 73 69 7a 65 5f 74 20 *fi) {..ssize_t
7e10: 72 65 61 64 5f 72 65 74 3b 0a 09 69 6e 74 20 72 read_ret;..int r
7e20: 65 74 76 61 6c 3b 0a 0a 09 41 50 50 46 53 5f 44 etval;...APPFS_D
7e30: 45 42 55 47 28 22 45 6e 74 65 72 20 28 70 61 74 EBUG("Enter (pat
7e40: 68 20 3d 20 25 73 2c 20 62 75 66 2c 20 25 6c 6c h = %s, buf, %ll
7e50: 69 2c 20 25 6c 6c 69 2c 20 66 64 3d 25 6c 6c 69 i, %lli, fd=%lli
7e60: 29 22 2c 20 70 61 74 68 2c 20 28 6c 6f 6e 67 20 )", path, (long
7e70: 6c 6f 6e 67 29 20 73 69 7a 65 2c 20 28 6c 6f 6e long) size, (lon
7e80: 67 20 6c 6f 6e 67 29 20 6f 66 66 73 65 74 2c 20 g long) offset,
7e90: 28 6c 6f 6e 67 20 6c 6f 6e 67 29 20 66 69 2d 3e (long long) fi->
7ea0: 66 68 29 3b 0a 0a 09 72 65 74 76 61 6c 20 3d 20 fh);...retval =
7eb0: 30 3b 0a 0a 09 77 68 69 6c 65 20 28 73 69 7a 65 0;...while (size
7ec0: 20 21 3d 20 30 29 20 7b 0a 09 09 72 65 61 64 5f != 0) {...read_
7ed0: 72 65 74 20 3d 20 70 72 65 61 64 28 66 69 2d 3e ret = pread(fi->
7ee0: 66 68 2c 20 62 75 66 2c 20 73 69 7a 65 2c 20 6f fh, buf, size, o
7ef0: 66 66 73 65 74 29 3b 0a 0a 09 09 69 66 20 28 72 ffset);....if (r
7f00: 65 61 64 5f 72 65 74 20 3c 20 30 29 20 7b 0a 09 ead_ret < 0) {..
7f10: 09 09 41 50 50 46 53 5f 44 45 42 55 47 28 22 65 ..APPFS_DEBUG("e
7f20: 72 72 6f 72 3a 20 72 65 61 64 20 66 61 69 6c 65 rror: read faile
7f30: 64 22 29 3b 0a 0a 09 09 09 72 65 74 75 72 6e 28 d");.....return(
7f40: 65 72 72 6e 6f 20 2a 20 2d 31 29 3b 0a 09 09 7d errno * -1);...}
7f50: 0a 0a 09 09 69 66 20 28 72 65 61 64 5f 72 65 74 ....if (read_ret
7f60: 20 3d 3d 20 30 29 20 7b 0a 09 09 09 62 72 65 61 == 0) {....brea
7f70: 6b 3b 0a 09 09 7d 0a 0a 09 09 73 69 7a 65 20 2d k;...}....size -
7f80: 3d 20 72 65 61 64 5f 72 65 74 3b 0a 09 09 62 75 = read_ret;...bu
7f90: 66 20 20 2b 3d 20 72 65 61 64 5f 72 65 74 3b 0a f += read_ret;.
7fa0: 09 09 6f 66 66 73 65 74 20 2b 3d 20 72 65 61 64 ..offset += read
7fb0: 5f 72 65 74 3b 0a 09 09 72 65 74 76 61 6c 20 2b _ret;...retval +
7fc0: 3d 20 72 65 61 64 5f 72 65 74 3b 0a 09 7d 0a 0a = read_ret;..}..
7fd0: 09 69 66 20 28 73 69 7a 65 20 21 3d 20 30 29 20 .if (size != 0)
7fe0: 7b 0a 09 09 41 50 50 46 53 5f 44 45 42 55 47 28 {...APPFS_DEBUG(
7ff0: 22 65 72 72 6f 72 3a 20 69 6e 63 6f 6d 70 6c 65 "error: incomple
8000: 74 65 20 72 65 61 64 20 28 74 68 69 73 20 6d 69 te read (this mi
8010: 67 68 74 20 62 65 20 61 6e 20 65 72 72 6f 72 20 ght be an error
8020: 62 65 63 61 75 73 65 20 46 55 53 45 20 77 69 6c because FUSE wil
8030: 6c 20 72 65 71 75 65 73 74 20 74 68 65 20 65 78 l request the ex
8040: 61 63 74 20 6c 65 6e 67 74 68 20 6f 66 20 74 68 act length of th
8050: 65 20 66 69 6c 65 29 22 29 3b 0a 09 7d 0a 0a 09 e file)");..}...
8060: 41 50 50 46 53 5f 44 45 42 55 47 28 22 52 65 74 APPFS_DEBUG("Ret
8070: 75 72 6e 69 6e 67 3a 20 25 69 22 2c 20 72 65 74 urning: %i", ret
8080: 76 61 6c 29 3b 0a 0a 09 72 65 74 75 72 6e 28 72 val);...return(r
8090: 65 74 76 61 6c 29 3b 0a 7d 0a 0a 73 74 61 74 69 etval);.}..stati
80a0: 63 20 69 6e 74 20 61 70 70 66 73 5f 66 75 73 65 c int appfs_fuse
80b0: 5f 77 72 69 74 65 28 63 6f 6e 73 74 20 63 68 61 _write(const cha
80c0: 72 20 2a 70 61 74 68 2c 20 63 6f 6e 73 74 20 63 r *path, const c
80d0: 68 61 72 20 2a 62 75 66 2c 20 73 69 7a 65 5f 74 har *buf, size_t
80e0: 20 73 69 7a 65 2c 20 6f 66 66 5f 74 20 6f 66 66 size, off_t off
80f0: 73 65 74 2c 20 73 74 72 75 63 74 20 66 75 73 65 set, struct fuse
8100: 5f 66 69 6c 65 5f 69 6e 66 6f 20 2a 66 69 29 20 _file_info *fi)
8110: 7b 0a 09 73 73 69 7a 65 5f 74 20 77 72 69 74 65 {..ssize_t write
8120: 5f 72 65 74 3b 0a 09 69 6e 74 20 72 65 74 76 61 _ret;..int retva
8130: 6c 3b 0a 0a 09 41 50 50 46 53 5f 44 45 42 55 47 l;...APPFS_DEBUG
8140: 28 22 45 6e 74 65 72 20 28 70 61 74 68 20 3d 20 ("Enter (path =
8150: 25 73 2c 20 2e 2e 2e 29 22 2c 20 70 61 74 68 29 %s, ...)", path)
8160: 3b 0a 0a 09 61 70 70 66 73 5f 67 65 74 5f 70 61 ;...appfs_get_pa
8170: 74 68 5f 69 6e 66 6f 5f 63 61 63 68 65 5f 72 6d th_info_cache_rm
8180: 28 70 61 74 68 2c 20 61 70 70 66 73 5f 67 65 74 (path, appfs_get
8190: 5f 66 73 75 69 64 28 29 29 3b 0a 0a 09 72 65 74 _fsuid());...ret
81a0: 76 61 6c 20 3d 20 30 3b 0a 0a 09 77 68 69 6c 65 val = 0;...while
81b0: 20 28 73 69 7a 65 20 21 3d 20 30 29 20 7b 0a 09 (size != 0) {..
81c0: 09 77 72 69 74 65 5f 72 65 74 20 3d 20 70 77 72 .write_ret = pwr
81d0: 69 74 65 28 66 69 2d 3e 66 68 2c 20 62 75 66 2c ite(fi->fh, buf,
81e0: 20 73 69 7a 65 2c 20 6f 66 66 73 65 74 29 3b 0a size, offset);.
81f0: 0a 09 09 69 66 20 28 77 72 69 74 65 5f 72 65 74 ...if (write_ret
8200: 20 3c 20 30 29 20 7b 0a 09 09 09 41 50 50 46 53 < 0) {....APPFS
8210: 5f 44 45 42 55 47 28 22 65 72 72 6f 72 3a 20 77 _DEBUG("error: w
8220: 72 69 74 65 20 66 61 69 6c 65 64 22 29 3b 0a 0a rite failed");..
8230: 09 09 09 72 65 74 75 72 6e 28 65 72 72 6e 6f 20 ...return(errno
8240: 2a 20 2d 31 29 3b 0a 09 09 7d 0a 0a 09 09 69 66 * -1);...}....if
8250: 20 28 77 72 69 74 65 5f 72 65 74 20 3d 3d 20 30 (write_ret == 0
8260: 29 20 7b 0a 09 09 09 62 72 65 61 6b 3b 0a 09 09 ) {....break;...
8270: 7d 0a 0a 09 09 73 69 7a 65 20 2d 3d 20 77 72 69 }....size -= wri
8280: 74 65 5f 72 65 74 3b 0a 09 09 62 75 66 20 20 2b te_ret;...buf +
8290: 3d 20 77 72 69 74 65 5f 72 65 74 3b 0a 09 09 6f = write_ret;...o
82a0: 66 66 73 65 74 20 2b 3d 20 77 72 69 74 65 5f 72 ffset += write_r
82b0: 65 74 3b 0a 09 09 72 65 74 76 61 6c 20 2b 3d 20 et;...retval +=
82c0: 77 72 69 74 65 5f 72 65 74 3b 0a 09 7d 0a 0a 09 write_ret;..}...
82d0: 69 66 20 28 73 69 7a 65 20 21 3d 20 30 29 20 7b if (size != 0) {
82e0: 0a 09 09 41 50 50 46 53 5f 44 45 42 55 47 28 22 ...APPFS_DEBUG("
82f0: 65 72 72 6f 72 3a 20 69 6e 63 6f 6d 70 6c 65 74 error: incomplet
8300: 65 20 77 72 69 74 65 22 29 3b 0a 09 7d 0a 0a 09 e write");..}...
8310: 72 65 74 75 72 6e 28 72 65 74 76 61 6c 29 3b 0a return(retval);.
8320: 7d 0a 0a 73 74 61 74 69 63 20 69 6e 74 20 61 70 }..static int ap
8330: 70 66 73 5f 66 75 73 65 5f 6d 6b 6e 6f 64 28 63 pfs_fuse_mknod(c
8340: 6f 6e 73 74 20 63 68 61 72 20 2a 70 61 74 68 2c onst char *path,
8350: 20 6d 6f 64 65 5f 74 20 6d 6f 64 65 2c 20 64 65 mode_t mode, de
8360: 76 5f 74 20 64 65 76 69 63 65 29 20 7b 0a 09 63 v_t device) {..c
8370: 68 61 72 20 2a 72 65 61 6c 5f 70 61 74 68 3b 0a har *real_path;.
8380: 09 69 6e 74 20 6d 6b 6e 6f 64 5f 72 65 74 3b 0a .int mknod_ret;.
8390: 0a 09 41 50 50 46 53 5f 44 45 42 55 47 28 22 45 ..APPFS_DEBUG("E
83a0: 6e 74 65 72 20 28 70 61 74 68 20 3d 20 25 73 2c nter (path = %s,
83b0: 20 2e 2e 2e 29 22 2c 20 70 61 74 68 29 3b 0a 0a ...)", path);..
83c0: 09 69 66 20 28 28 6d 6f 64 65 20 26 20 53 5f 49 .if ((mode & S_I
83d0: 46 43 48 52 29 20 3d 3d 20 53 5f 49 46 43 48 52 FCHR) == S_IFCHR
83e0: 29 20 7b 0a 09 09 72 65 74 75 72 6e 28 2d 45 50 ) {...return(-EP
83f0: 45 52 4d 29 3b 0a 09 7d 0a 0a 09 69 66 20 28 28 ERM);..}...if ((
8400: 6d 6f 64 65 20 26 20 53 5f 49 46 42 4c 4b 29 20 mode & S_IFBLK)
8410: 3d 3d 20 53 5f 49 46 42 4c 4b 29 20 7b 0a 09 09 == S_IFBLK) {...
8420: 72 65 74 75 72 6e 28 2d 45 50 45 52 4d 29 3b 0a return(-EPERM);.
8430: 09 7d 0a 0a 09 72 65 61 6c 5f 70 61 74 68 20 3d .}...real_path =
8440: 20 61 70 70 66 73 5f 70 72 65 70 61 72 65 5f 74 appfs_prepare_t
8450: 6f 5f 63 72 65 61 74 65 28 70 61 74 68 29 3b 0a o_create(path);.
8460: 09 69 66 20 28 72 65 61 6c 5f 70 61 74 68 20 3d .if (real_path =
8470: 3d 20 4e 55 4c 4c 29 20 7b 0a 09 09 72 65 74 75 = NULL) {...retu
8480: 72 6e 28 2d 45 49 4f 29 3b 0a 09 7d 0a 0a 09 61 rn(-EIO);..}...a
8490: 70 70 66 73 5f 73 69 6d 75 6c 61 74 65 5f 75 73 ppfs_simulate_us
84a0: 65 72 5f 66 73 5f 65 6e 74 65 72 28 29 3b 0a 0a er_fs_enter();..
84b0: 09 6d 6b 6e 6f 64 5f 72 65 74 20 3d 20 6d 6b 6e .mknod_ret = mkn
84c0: 6f 64 28 72 65 61 6c 5f 70 61 74 68 2c 20 6d 6f od(real_path, mo
84d0: 64 65 2c 20 64 65 76 69 63 65 29 3b 0a 0a 09 61 de, device);...a
84e0: 70 70 66 73 5f 73 69 6d 75 6c 61 74 65 5f 75 73 ppfs_simulate_us
84f0: 65 72 5f 66 73 5f 6c 65 61 76 65 28 29 3b 0a 0a er_fs_leave();..
8500: 09 66 72 65 65 28 72 65 61 6c 5f 70 61 74 68 29 .free(real_path)
8510: 3b 0a 0a 09 69 66 20 28 6d 6b 6e 6f 64 5f 72 65 ;...if (mknod_re
8520: 74 20 21 3d 20 30 29 20 7b 0a 09 09 72 65 74 75 t != 0) {...retu
8530: 72 6e 28 65 72 72 6e 6f 20 2a 20 2d 31 29 3b 0a rn(errno * -1);.
8540: 09 7d 0a 0a 09 72 65 74 75 72 6e 28 30 29 3b 0a .}...return(0);.
8550: 7d 0a 0a 73 74 61 74 69 63 20 69 6e 74 20 61 70 }..static int ap
8560: 70 66 73 5f 66 75 73 65 5f 63 72 65 61 74 65 28 pfs_fuse_create(
8570: 63 6f 6e 73 74 20 63 68 61 72 20 2a 70 61 74 68 const char *path
8580: 2c 20 6d 6f 64 65 5f 74 20 6d 6f 64 65 2c 20 73 , mode_t mode, s
8590: 74 72 75 63 74 20 66 75 73 65 5f 66 69 6c 65 5f truct fuse_file_
85a0: 69 6e 66 6f 20 2a 66 69 29 20 7b 0a 09 63 68 61 info *fi) {..cha
85b0: 72 20 2a 72 65 61 6c 5f 70 61 74 68 3b 0a 09 69 r *real_path;..i
85c0: 6e 74 20 66 64 3b 0a 0a 09 41 50 50 46 53 5f 44 nt fd;...APPFS_D
85d0: 45 42 55 47 28 22 45 6e 74 65 72 20 28 70 61 74 EBUG("Enter (pat
85e0: 68 20 3d 20 25 73 2c 20 2e 2e 2e 29 22 2c 20 70 h = %s, ...)", p
85f0: 61 74 68 29 3b 0a 0a 09 69 66 20 28 28 6d 6f 64 ath);...if ((mod
8600: 65 20 26 20 53 5f 49 46 43 48 52 29 20 3d 3d 20 e & S_IFCHR) ==
8610: 53 5f 49 46 43 48 52 29 20 7b 0a 09 09 72 65 74 S_IFCHR) {...ret
8620: 75 72 6e 28 2d 45 50 45 52 4d 29 3b 0a 09 7d 0a urn(-EPERM);..}.
8630: 0a 09 69 66 20 28 28 6d 6f 64 65 20 26 20 53 5f ..if ((mode & S_
8640: 49 46 42 4c 4b 29 20 3d 3d 20 53 5f 49 46 42 4c IFBLK) == S_IFBL
8650: 4b 29 20 7b 0a 09 09 72 65 74 75 72 6e 28 2d 45 K) {...return(-E
8660: 50 45 52 4d 29 3b 0a 09 7d 0a 0a 09 72 65 61 6c PERM);..}...real
8670: 5f 70 61 74 68 20 3d 20 61 70 70 66 73 5f 70 72 _path = appfs_pr
8680: 65 70 61 72 65 5f 74 6f 5f 63 72 65 61 74 65 28 epare_to_create(
8690: 70 61 74 68 29 3b 0a 09 69 66 20 28 72 65 61 6c path);..if (real
86a0: 5f 70 61 74 68 20 3d 3d 20 4e 55 4c 4c 29 20 7b _path == NULL) {
86b0: 0a 09 09 72 65 74 75 72 6e 28 2d 45 49 4f 29 3b ...return(-EIO);
86c0: 0a 09 7d 0a 0a 09 61 70 70 66 73 5f 73 69 6d 75 ..}...appfs_simu
86d0: 6c 61 74 65 5f 75 73 65 72 5f 66 73 5f 65 6e 74 late_user_fs_ent
86e0: 65 72 28 29 3b 0a 0a 09 66 64 20 3d 20 63 72 65 er();...fd = cre
86f0: 61 74 28 72 65 61 6c 5f 70 61 74 68 2c 20 6d 6f at(real_path, mo
8700: 64 65 29 3b 0a 0a 09 61 70 70 66 73 5f 73 69 6d de);...appfs_sim
8710: 75 6c 61 74 65 5f 75 73 65 72 5f 66 73 5f 6c 65 ulate_user_fs_le
8720: 61 76 65 28 29 3b 0a 0a 09 66 72 65 65 28 72 65 ave();...free(re
8730: 61 6c 5f 70 61 74 68 29 3b 0a 0a 09 69 66 20 28 al_path);...if (
8740: 66 64 20 3c 20 30 29 20 7b 0a 09 09 72 65 74 75 fd < 0) {...retu
8750: 72 6e 28 65 72 72 6e 6f 20 2a 20 2d 31 29 3b 0a rn(errno * -1);.
8760: 09 7d 0a 0a 09 66 69 2d 3e 66 68 20 3d 20 66 64 .}...fi->fh = fd
8770: 3b 0a 0a 09 72 65 74 75 72 6e 28 30 29 3b 0a 7d ;...return(0);.}
8780: 0a 0a 73 74 61 74 69 63 20 69 6e 74 20 61 70 70 ..static int app
8790: 66 73 5f 66 75 73 65 5f 74 72 75 6e 63 61 74 65 fs_fuse_truncate
87a0: 28 63 6f 6e 73 74 20 63 68 61 72 20 2a 70 61 74 (const char *pat
87b0: 68 2c 20 6f 66 66 5f 74 20 73 69 7a 65 29 20 7b h, off_t size) {
87c0: 0a 09 63 68 61 72 20 2a 72 65 61 6c 5f 70 61 74 ..char *real_pat
87d0: 68 3b 0a 09 69 6e 74 20 74 72 75 6e 63 61 74 65 h;..int truncate
87e0: 5f 72 65 74 3b 0a 0a 09 41 50 50 46 53 5f 44 45 _ret;...APPFS_DE
87f0: 42 55 47 28 22 45 6e 74 65 72 20 28 70 61 74 68 BUG("Enter (path
8800: 20 3d 20 25 73 2c 20 2e 2e 2e 29 22 2c 20 70 61 = %s, ...)", pa
8810: 74 68 29 3b 0a 0a 09 72 65 61 6c 5f 70 61 74 68 th);...real_path
8820: 20 3d 20 61 70 70 66 73 5f 6c 6f 63 61 6c 70 61 = appfs_localpa
8830: 74 68 28 70 61 74 68 29 3b 0a 09 69 66 20 28 72 th(path);..if (r
8840: 65 61 6c 5f 70 61 74 68 20 3d 3d 20 4e 55 4c 4c eal_path == NULL
8850: 29 20 7b 0a 09 09 72 65 74 75 72 6e 28 2d 45 49 ) {...return(-EI
8860: 4f 29 3b 0a 09 7d 0a 0a 09 61 70 70 66 73 5f 67 O);..}...appfs_g
8870: 65 74 5f 70 61 74 68 5f 69 6e 66 6f 5f 63 61 63 et_path_info_cac
8880: 68 65 5f 72 6d 28 70 61 74 68 2c 20 61 70 70 66 he_rm(path, appf
8890: 73 5f 67 65 74 5f 66 73 75 69 64 28 29 29 3b 0a s_get_fsuid());.
88a0: 0a 09 61 70 70 66 73 5f 73 69 6d 75 6c 61 74 65 ..appfs_simulate
88b0: 5f 75 73 65 72 5f 66 73 5f 65 6e 74 65 72 28 29 _user_fs_enter()
88c0: 3b 0a 0a 09 74 72 75 6e 63 61 74 65 5f 72 65 74 ;...truncate_ret
88d0: 20 3d 20 74 72 75 6e 63 61 74 65 28 72 65 61 6c = truncate(real
88e0: 5f 70 61 74 68 2c 20 73 69 7a 65 29 3b 0a 0a 09 _path, size);...
88f0: 61 70 70 66 73 5f 73 69 6d 75 6c 61 74 65 5f 75 appfs_simulate_u
8900: 73 65 72 5f 66 73 5f 6c 65 61 76 65 28 29 3b 0a ser_fs_leave();.
8910: 0a 09 66 72 65 65 28 72 65 61 6c 5f 70 61 74 68 ..free(real_path
8920: 29 3b 0a 0a 09 69 66 20 28 74 72 75 6e 63 61 74 );...if (truncat
8930: 65 5f 72 65 74 20 21 3d 20 30 29 20 7b 0a 09 09 e_ret != 0) {...
8940: 72 65 74 75 72 6e 28 65 72 72 6e 6f 20 2a 20 2d return(errno * -
8950: 31 29 3b 0a 09 7d 0a 0a 09 72 65 74 75 72 6e 28 1);..}...return(
8960: 30 29 3b 0a 7d 0a 0a 73 74 61 74 69 63 20 69 6e 0);.}..static in
8970: 74 20 61 70 70 66 73 5f 66 75 73 65 5f 75 6e 6c t appfs_fuse_unl
8980: 69 6e 6b 5f 72 6d 64 69 72 28 63 6f 6e 73 74 20 ink_rmdir(const
8990: 63 68 61 72 20 2a 70 61 74 68 29 20 7b 0a 09 54 char *path) {..T
89a0: 63 6c 5f 49 6e 74 65 72 70 20 2a 69 6e 74 65 72 cl_Interp *inter
89b0: 70 3b 0a 09 69 6e 74 20 74 63 6c 5f 72 65 74 3b p;..int tcl_ret;
89c0: 0a 0a 09 41 50 50 46 53 5f 44 45 42 55 47 28 22 ...APPFS_DEBUG("
89d0: 45 6e 74 65 72 20 28 70 61 74 68 20 3d 20 25 73 Enter (path = %s
89e0: 2c 20 2e 2e 2e 29 22 2c 20 70 61 74 68 29 3b 0a , ...)", path);.
89f0: 0a 09 61 70 70 66 73 5f 67 65 74 5f 70 61 74 68 ..appfs_get_path
8a00: 5f 69 6e 66 6f 5f 63 61 63 68 65 5f 66 6c 75 73 _info_cache_flus
8a10: 68 28 61 70 70 66 73 5f 67 65 74 5f 66 73 75 69 h(appfs_get_fsui
8a20: 64 28 29 2c 20 2d 31 29 3b 0a 0a 09 69 6e 74 65 d(), -1);...inte
8a30: 72 70 20 3d 20 61 70 70 66 73 5f 54 63 6c 49 6e rp = appfs_TclIn
8a40: 74 65 72 70 28 29 3b 0a 09 69 66 20 28 69 6e 74 terp();..if (int
8a50: 65 72 70 20 3d 3d 20 4e 55 4c 4c 29 20 7b 0a 09 erp == NULL) {..
8a60: 09 72 65 74 75 72 6e 28 2d 45 49 4f 29 3b 0a 09 .return(-EIO);..
8a70: 7d 0a 0a 09 61 70 70 66 73 5f 63 61 6c 6c 5f 6c }...appfs_call_l
8a80: 69 62 74 63 6c 28 54 63 6c 5f 50 72 65 73 65 72 ibtcl(Tcl_Preser
8a90: 76 65 28 69 6e 74 65 72 70 29 3b 29 0a 0a 09 74 ve(interp);)...t
8aa0: 63 6c 5f 72 65 74 20 3d 20 61 70 70 66 73 5f 54 cl_ret = appfs_T
8ab0: 63 6c 5f 45 76 61 6c 28 69 6e 74 65 72 70 2c 20 cl_Eval(interp,
8ac0: 32 2c 20 22 3a 3a 61 70 70 66 73 3a 3a 75 6e 6c 2, "::appfs::unl
8ad0: 69 6e 6b 70 61 74 68 22 2c 20 70 61 74 68 29 3b inkpath", path);
8ae0: 0a 09 69 66 20 28 74 63 6c 5f 72 65 74 20 21 3d ..if (tcl_ret !=
8af0: 20 54 43 4c 5f 4f 4b 29 20 7b 0a 09 09 41 50 50 TCL_OK) {...APP
8b00: 46 53 5f 44 45 42 55 47 28 22 3a 3a 61 70 70 66 FS_DEBUG("::appf
8b10: 73 3a 3a 75 6e 6c 69 6e 6b 70 61 74 68 28 25 73 s::unlinkpath(%s
8b20: 29 20 66 61 69 6c 65 64 2e 22 2c 20 70 61 74 68 ) failed.", path
8b30: 29 3b 0a 09 09 61 70 70 66 73 5f 63 61 6c 6c 5f );...appfs_call_
8b40: 6c 69 62 74 63 6c 28 0a 09 09 09 41 50 50 46 53 libtcl(....APPFS
8b50: 5f 44 45 42 55 47 28 22 54 63 6c 20 45 72 72 6f _DEBUG("Tcl Erro
8b60: 72 20 69 73 3a 20 25 73 22 2c 20 54 63 6c 5f 47 r is: %s", Tcl_G
8b70: 65 74 53 74 72 69 6e 67 52 65 73 75 6c 74 28 69 etStringResult(i
8b80: 6e 74 65 72 70 29 29 3b 0a 09 09 29 0a 0a 09 09 nterp));...)....
8b90: 61 70 70 66 73 5f 63 61 6c 6c 5f 6c 69 62 74 63 appfs_call_libtc
8ba0: 6c 28 54 63 6c 5f 52 65 6c 65 61 73 65 28 69 6e l(Tcl_Release(in
8bb0: 74 65 72 70 29 3b 29 0a 0a 09 09 72 65 74 75 72 terp);)....retur
8bc0: 6e 28 2d 45 49 4f 29 3b 0a 09 7d 0a 0a 09 61 70 n(-EIO);..}...ap
8bd0: 70 66 73 5f 63 61 6c 6c 5f 6c 69 62 74 63 6c 28 pfs_call_libtcl(
8be0: 54 63 6c 5f 52 65 6c 65 61 73 65 28 69 6e 74 65 Tcl_Release(inte
8bf0: 72 70 29 3b 29 0a 0a 09 72 65 74 75 72 6e 28 30 rp);)...return(0
8c00: 29 3b 0a 7d 0a 0a 73 74 61 74 69 63 20 69 6e 74 );.}..static int
8c10: 20 61 70 70 66 73 5f 66 75 73 65 5f 6d 6b 64 69 appfs_fuse_mkdi
8c20: 72 28 63 6f 6e 73 74 20 63 68 61 72 20 2a 70 61 r(const char *pa
8c30: 74 68 2c 20 6d 6f 64 65 5f 74 20 6d 6f 64 65 29 th, mode_t mode)
8c40: 20 7b 0a 09 63 68 61 72 20 2a 72 65 61 6c 5f 70 {..char *real_p
8c50: 61 74 68 3b 0a 09 69 6e 74 20 6d 6b 64 69 72 5f ath;..int mkdir_
8c60: 72 65 74 3b 0a 0a 09 41 50 50 46 53 5f 44 45 42 ret;...APPFS_DEB
8c70: 55 47 28 22 45 6e 74 65 72 20 28 70 61 74 68 20 UG("Enter (path
8c80: 3d 20 25 73 2c 20 2e 2e 2e 29 22 2c 20 70 61 74 = %s, ...)", pat
8c90: 68 29 3b 0a 0a 09 72 65 61 6c 5f 70 61 74 68 20 h);...real_path
8ca0: 3d 20 61 70 70 66 73 5f 70 72 65 70 61 72 65 5f = appfs_prepare_
8cb0: 74 6f 5f 63 72 65 61 74 65 28 70 61 74 68 29 3b to_create(path);
8cc0: 0a 09 69 66 20 28 72 65 61 6c 5f 70 61 74 68 20 ..if (real_path
8cd0: 3d 3d 20 4e 55 4c 4c 29 20 7b 0a 09 09 72 65 74 == NULL) {...ret
8ce0: 75 72 6e 28 2d 45 49 4f 29 3b 0a 09 7d 0a 0a 09 urn(-EIO);..}...
8cf0: 61 70 70 66 73 5f 73 69 6d 75 6c 61 74 65 5f 75 appfs_simulate_u
8d00: 73 65 72 5f 66 73 5f 65 6e 74 65 72 28 29 3b 0a ser_fs_enter();.
8d10: 0a 09 6d 6b 64 69 72 5f 72 65 74 20 3d 20 6d 6b ..mkdir_ret = mk
8d20: 64 69 72 28 72 65 61 6c 5f 70 61 74 68 2c 20 6d dir(real_path, m
8d30: 6f 64 65 29 3b 0a 0a 09 61 70 70 66 73 5f 73 69 ode);...appfs_si
8d40: 6d 75 6c 61 74 65 5f 75 73 65 72 5f 66 73 5f 6c mulate_user_fs_l
8d50: 65 61 76 65 28 29 3b 0a 0a 09 66 72 65 65 28 72 eave();...free(r
8d60: 65 61 6c 5f 70 61 74 68 29 3b 0a 0a 09 69 66 20 eal_path);...if
8d70: 28 6d 6b 64 69 72 5f 72 65 74 20 21 3d 20 30 29 (mkdir_ret != 0)
8d80: 20 7b 0a 09 09 69 66 20 28 65 72 72 6e 6f 20 21 {...if (errno !
8d90: 3d 20 45 45 58 49 53 54 29 20 7b 0a 09 09 09 72 = EEXIST) {....r
8da0: 65 74 75 72 6e 28 65 72 72 6e 6f 20 2a 20 2d 31 eturn(errno * -1
8db0: 29 3b 0a 09 09 7d 0a 09 7d 0a 0a 09 72 65 74 75 );...}..}...retu
8dc0: 72 6e 28 30 29 3b 0a 7d 0a 0a 73 74 61 74 69 63 rn(0);.}..static
8dd0: 20 69 6e 74 20 61 70 70 66 73 5f 66 75 73 65 5f int appfs_fuse_
8de0: 63 68 6d 6f 64 28 63 6f 6e 73 74 20 63 68 61 72 chmod(const char
8df0: 20 2a 70 61 74 68 2c 20 6d 6f 64 65 5f 74 20 6d *path, mode_t m
8e00: 6f 64 65 29 20 7b 0a 09 54 63 6c 5f 49 6e 74 65 ode) {..Tcl_Inte
8e10: 72 70 20 2a 69 6e 74 65 72 70 3b 0a 09 63 6f 6e rp *interp;..con
8e20: 73 74 20 63 68 61 72 20 2a 72 65 61 6c 5f 70 61 st char *real_pa
8e30: 74 68 3b 0a 09 69 6e 74 20 74 63 6c 5f 72 65 74 th;..int tcl_ret
8e40: 2c 20 63 68 6d 6f 64 5f 72 65 74 3b 0a 0a 09 41 , chmod_ret;...A
8e50: 50 50 46 53 5f 44 45 42 55 47 28 22 45 6e 74 65 PPFS_DEBUG("Ente
8e60: 72 20 28 70 61 74 68 20 3d 20 25 73 2c 20 2e 2e r (path = %s, ..
8e70: 2e 29 22 2c 20 70 61 74 68 29 3b 0a 0a 09 61 70 .)", path);...ap
8e80: 70 66 73 5f 67 65 74 5f 70 61 74 68 5f 69 6e 66 pfs_get_path_inf
8e90: 6f 5f 63 61 63 68 65 5f 72 6d 28 70 61 74 68 2c o_cache_rm(path,
8ea0: 20 61 70 70 66 73 5f 67 65 74 5f 66 73 75 69 64 appfs_get_fsuid
8eb0: 28 29 29 3b 0a 0a 09 69 6e 74 65 72 70 20 3d 20 ());...interp =
8ec0: 61 70 70 66 73 5f 54 63 6c 49 6e 74 65 72 70 28 appfs_TclInterp(
8ed0: 29 3b 0a 09 69 66 20 28 69 6e 74 65 72 70 20 3d );..if (interp =
8ee0: 3d 20 4e 55 4c 4c 29 20 7b 0a 09 09 72 65 74 75 = NULL) {...retu
8ef0: 72 6e 28 2d 45 49 4f 29 3b 0a 09 7d 0a 0a 09 61 rn(-EIO);..}...a
8f00: 70 70 66 73 5f 63 61 6c 6c 5f 6c 69 62 74 63 6c ppfs_call_libtcl
8f10: 28 54 63 6c 5f 50 72 65 73 65 72 76 65 28 69 6e (Tcl_Preserve(in
8f20: 74 65 72 70 29 3b 29 0a 0a 09 74 63 6c 5f 72 65 terp);)...tcl_re
8f30: 74 20 3d 20 61 70 70 66 73 5f 54 63 6c 5f 45 76 t = appfs_Tcl_Ev
8f40: 61 6c 28 69 6e 74 65 72 70 2c 20 33 2c 20 22 3a al(interp, 3, ":
8f50: 3a 61 70 70 66 73 3a 3a 6f 70 65 6e 70 61 74 68 :appfs::openpath
8f60: 22 2c 20 70 61 74 68 2c 20 22 77 72 69 74 65 22 ", path, "write"
8f70: 29 3b 0a 09 69 66 20 28 74 63 6c 5f 72 65 74 20 );..if (tcl_ret
8f80: 21 3d 20 54 43 4c 5f 4f 4b 29 20 7b 0a 09 09 41 != TCL_OK) {...A
8f90: 50 50 46 53 5f 44 45 42 55 47 28 22 3a 3a 61 70 PPFS_DEBUG("::ap
8fa0: 70 66 73 3a 3a 6f 70 65 6e 70 61 74 68 28 25 73 pfs::openpath(%s
8fb0: 2c 20 25 73 29 20 66 61 69 6c 65 64 2e 22 2c 20 , %s) failed.",
8fc0: 70 61 74 68 2c 20 22 77 72 69 74 65 22 29 3b 0a path, "write");.
8fd0: 09 09 61 70 70 66 73 5f 63 61 6c 6c 5f 6c 69 62 ..appfs_call_lib
8fe0: 74 63 6c 28 0a 09 09 09 41 50 50 46 53 5f 44 45 tcl(....APPFS_DE
8ff0: 42 55 47 28 22 54 63 6c 20 45 72 72 6f 72 20 69 BUG("Tcl Error i
9000: 73 3a 20 25 73 22 2c 20 54 63 6c 5f 47 65 74 53 s: %s", Tcl_GetS
9010: 74 72 69 6e 67 52 65 73 75 6c 74 28 69 6e 74 65 tringResult(inte
9020: 72 70 29 29 3b 0a 09 09 29 0a 0a 09 09 61 70 70 rp));...)....app
9030: 66 73 5f 63 61 6c 6c 5f 6c 69 62 74 63 6c 28 54 fs_call_libtcl(T
9040: 63 6c 5f 52 65 6c 65 61 73 65 28 69 6e 74 65 72 cl_Release(inter
9050: 70 29 3b 29 0a 0a 09 09 72 65 74 75 72 6e 28 2d p);)....return(-
9060: 45 49 4f 29 3b 0a 09 7d 0a 0a 09 61 70 70 66 73 EIO);..}...appfs
9070: 5f 63 61 6c 6c 5f 6c 69 62 74 63 6c 28 0a 09 09 _call_libtcl(...
9080: 72 65 61 6c 5f 70 61 74 68 20 3d 20 54 63 6c 5f real_path = Tcl_
9090: 47 65 74 53 74 72 69 6e 67 52 65 73 75 6c 74 28 GetStringResult(
90a0: 69 6e 74 65 72 70 29 3b 0a 09 29 0a 0a 09 61 70 interp);..)...ap
90b0: 70 66 73 5f 63 61 6c 6c 5f 6c 69 62 74 63 6c 28 pfs_call_libtcl(
90c0: 54 63 6c 5f 52 65 6c 65 61 73 65 28 69 6e 74 65 Tcl_Release(inte
90d0: 72 70 29 3b 29 0a 0a 09 69 66 20 28 72 65 61 6c rp);)...if (real
90e0: 5f 70 61 74 68 20 3d 3d 20 4e 55 4c 4c 29 20 7b _path == NULL) {
90f0: 0a 09 09 72 65 74 75 72 6e 28 2d 45 49 4f 29 3b ...return(-EIO);
9100: 0a 09 7d 0a 0a 09 61 70 70 66 73 5f 73 69 6d 75 ..}...appfs_simu
9110: 6c 61 74 65 5f 75 73 65 72 5f 66 73 5f 65 6e 74 late_user_fs_ent
9120: 65 72 28 29 3b 0a 0a 09 63 68 6d 6f 64 5f 72 65 er();...chmod_re
9130: 74 20 3d 20 63 68 6d 6f 64 28 72 65 61 6c 5f 70 t = chmod(real_p
9140: 61 74 68 2c 20 6d 6f 64 65 29 3b 0a 0a 09 61 70 ath, mode);...ap
9150: 70 66 73 5f 73 69 6d 75 6c 61 74 65 5f 75 73 65 pfs_simulate_use
9160: 72 5f 66 73 5f 6c 65 61 76 65 28 29 3b 0a 0a 09 r_fs_leave();...
9170: 72 65 74 75 72 6e 28 63 68 6d 6f 64 5f 72 65 74 return(chmod_ret
9180: 29 3b 0a 7d 0a 0a 73 74 61 74 69 63 20 69 6e 74 );.}..static int
9190: 20 61 70 70 66 73 5f 66 75 73 65 5f 73 79 6d 6c appfs_fuse_syml
91a0: 69 6e 6b 28 63 6f 6e 73 74 20 63 68 61 72 20 2a ink(const char *
91b0: 6f 6c 64 70 61 74 68 2c 20 63 6f 6e 73 74 20 63 oldpath, const c
91c0: 68 61 72 20 2a 6e 65 77 70 61 74 68 29 20 7b 0a har *newpath) {.
91d0: 09 63 68 61 72 20 2a 72 65 61 6c 5f 70 61 74 68 .char *real_path
91e0: 3b 0a 09 69 6e 74 20 73 79 6d 6c 69 6e 6b 5f 72 ;..int symlink_r
91f0: 65 74 3b 0a 0a 09 41 50 50 46 53 5f 44 45 42 55 et;...APPFS_DEBU
9200: 47 28 22 45 6e 74 65 72 20 28 70 61 74 68 20 3d G("Enter (path =
9210: 20 25 73 2c 20 25 73 29 22 2c 20 6f 6c 64 70 61 %s, %s)", oldpa
9220: 74 68 2c 20 6e 65 77 70 61 74 68 29 3b 0a 0a 09 th, newpath);...
9230: 72 65 61 6c 5f 70 61 74 68 20 3d 20 61 70 70 66 real_path = appf
9240: 73 5f 70 72 65 70 61 72 65 5f 74 6f 5f 63 72 65 s_prepare_to_cre
9250: 61 74 65 28 6e 65 77 70 61 74 68 29 3b 0a 09 69 ate(newpath);..i
9260: 66 20 28 72 65 61 6c 5f 70 61 74 68 20 3d 3d 20 f (real_path ==
9270: 4e 55 4c 4c 29 20 7b 0a 09 09 72 65 74 75 72 6e NULL) {...return
9280: 28 2d 45 49 4f 29 3b 0a 09 7d 0a 0a 09 61 70 70 (-EIO);..}...app
9290: 66 73 5f 73 69 6d 75 6c 61 74 65 5f 75 73 65 72 fs_simulate_user
92a0: 5f 66 73 5f 65 6e 74 65 72 28 29 3b 0a 0a 09 73 _fs_enter();...s
92b0: 79 6d 6c 69 6e 6b 5f 72 65 74 20 3d 20 73 79 6d ymlink_ret = sym
92c0: 6c 69 6e 6b 28 6f 6c 64 70 61 74 68 2c 20 72 65 link(oldpath, re
92d0: 61 6c 5f 70 61 74 68 29 3b 0a 0a 09 61 70 70 66 al_path);...appf
92e0: 73 5f 73 69 6d 75 6c 61 74 65 5f 75 73 65 72 5f s_simulate_user_
92f0: 66 73 5f 6c 65 61 76 65 28 29 3b 0a 0a 09 66 72 fs_leave();...fr
9300: 65 65 28 72 65 61 6c 5f 70 61 74 68 29 3b 0a 0a ee(real_path);..
9310: 09 69 66 20 28 73 79 6d 6c 69 6e 6b 5f 72 65 74 .if (symlink_ret
9320: 20 21 3d 20 30 29 20 7b 0a 09 09 72 65 74 75 72 != 0) {...retur
9330: 6e 28 65 72 72 6e 6f 20 2a 20 2d 31 29 3b 0a 09 n(errno * -1);..
9340: 7d 0a 0a 09 72 65 74 75 72 6e 28 30 29 3b 0a 7d }...return(0);.}
9350: 0a 0a 2f 2a 0a 20 2a 20 53 51 4c 69 74 65 33 20 ../*. * SQLite3
9360: 6d 6f 64 65 3a 20 45 78 65 63 75 74 65 20 72 61 mode: Execute ra
9370: 77 20 53 51 4c 20 61 6e 64 20 72 65 74 75 72 6e w SQL and return
9380: 20 73 75 63 63 65 73 73 20 6f 72 20 66 61 69 6c success or fail
9390: 75 72 65 0a 20 2a 2f 0a 73 74 61 74 69 63 20 69 ure. */.static i
93a0: 6e 74 20 61 70 70 66 73 5f 73 71 6c 69 74 65 33 nt appfs_sqlite3
93b0: 28 63 6f 6e 73 74 20 63 68 61 72 20 2a 73 71 6c (const char *sql
93c0: 29 20 7b 0a 09 54 63 6c 5f 49 6e 74 65 72 70 20 ) {..Tcl_Interp
93d0: 2a 69 6e 74 65 72 70 3b 0a 09 63 6f 6e 73 74 20 *interp;..const
93e0: 63 68 61 72 20 2a 73 71 6c 5f 72 65 74 3b 0a 09 char *sql_ret;..
93f0: 69 6e 74 20 74 63 6c 5f 72 65 74 3b 0a 0a 09 69 int tcl_ret;...i
9400: 6e 74 65 72 70 20 3d 20 61 70 70 66 73 5f 63 72 nterp = appfs_cr
9410: 65 61 74 65 5f 54 63 6c 49 6e 74 65 72 70 28 4e eate_TclInterp(N
9420: 55 4c 4c 29 3b 0a 09 69 66 20 28 69 6e 74 65 72 ULL);..if (inter
9430: 70 20 3d 3d 20 4e 55 4c 4c 29 20 7b 0a 09 09 66 p == NULL) {...f
9440: 70 72 69 6e 74 66 28 73 74 64 65 72 72 2c 20 22 printf(stderr, "
9450: 55 6e 61 62 6c 65 20 74 6f 20 63 72 65 61 74 65 Unable to create
9460: 20 61 20 54 63 6c 20 69 6e 74 65 72 70 72 65 74 a Tcl interpret
9470: 65 72 2e 20 20 41 62 6f 72 74 69 6e 67 2e 5c 6e er. Aborting.\n
9480: 22 29 3b 0a 0a 09 09 72 65 74 75 72 6e 28 31 29 ");....return(1)
9490: 3b 0a 09 7d 0a 0a 09 74 63 6c 5f 72 65 74 20 3d ;..}...tcl_ret =
94a0: 20 61 70 70 66 73 5f 54 63 6c 5f 45 76 61 6c 28 appfs_Tcl_Eval(
94b0: 69 6e 74 65 72 70 2c 20 35 2c 20 22 3a 3a 61 70 interp, 5, "::ap
94c0: 70 66 73 3a 3a 64 62 22 2c 20 22 65 76 61 6c 22 pfs::db", "eval"
94d0: 2c 20 73 71 6c 2c 20 22 72 6f 77 22 2c 20 22 75 , sql, "row", "u
94e0: 6e 73 65 74 20 2d 6e 6f 63 6f 6d 70 6c 61 69 6e nset -nocomplain
94f0: 20 72 6f 77 28 2a 29 3b 20 70 61 72 72 61 79 20 row(*); parray
9500: 72 6f 77 3b 20 70 75 74 73 20 5c 22 2d 2d 2d 2d row; puts \"----
9510: 5c 22 22 29 3b 0a 09 73 71 6c 5f 72 65 74 20 3d \"");..sql_ret =
9520: 20 54 63 6c 5f 47 65 74 53 74 72 69 6e 67 52 65 Tcl_GetStringRe
9530: 73 75 6c 74 28 69 6e 74 65 72 70 29 3b 0a 0a 09 sult(interp);...
9540: 69 66 20 28 74 63 6c 5f 72 65 74 20 21 3d 20 54 if (tcl_ret != T
9550: 43 4c 5f 4f 4b 29 20 7b 0a 09 09 66 70 72 69 6e CL_OK) {...fprin
9560: 74 66 28 73 74 64 65 72 72 2c 20 22 5b 65 72 72 tf(stderr, "[err
9570: 6f 72 5d 20 25 73 5c 6e 22 2c 20 73 71 6c 5f 72 or] %s\n", sql_r
9580: 65 74 29 3b 0a 0a 09 09 72 65 74 75 72 6e 28 31 et);....return(1
9590: 29 3b 0a 09 7d 0a 0a 09 69 66 20 28 73 71 6c 5f );..}...if (sql_
95a0: 72 65 74 20 26 26 20 73 71 6c 5f 72 65 74 5b 30 ret && sql_ret[0
95b0: 5d 20 21 3d 20 27 5c 30 27 29 20 7b 0a 09 09 70 ] != '\0') {...p
95c0: 72 69 6e 74 66 28 22 25 73 5c 6e 22 2c 20 73 71 rintf("%s\n", sq
95d0: 6c 5f 72 65 74 29 3b 0a 09 7d 0a 0a 09 72 65 74 l_ret);..}...ret
95e0: 75 72 6e 28 30 29 3b 0a 7d 0a 0a 2f 2a 0a 20 2a urn(0);.}../*. *
95f0: 20 54 63 6c 20 6d 6f 64 65 3a 20 45 78 65 63 75 Tcl mode: Execu
9600: 74 65 20 72 61 77 20 54 63 6c 20 61 6e 64 20 72 te raw Tcl and r
9610: 65 74 75 72 6e 20 73 75 63 63 65 73 73 20 6f 72 eturn success or
9620: 20 66 61 69 6c 75 72 65 0a 20 2a 2f 0a 73 74 61 failure. */.sta
9630: 74 69 63 20 69 6e 74 20 61 70 70 66 73 5f 74 63 tic int appfs_tc
9640: 6c 28 63 6f 6e 73 74 20 63 68 61 72 20 2a 74 63 l(const char *tc
9650: 6c 29 20 7b 0a 09 54 63 6c 5f 49 6e 74 65 72 70 l) {..Tcl_Interp
9660: 20 2a 69 6e 74 65 72 70 3b 0a 09 63 6f 6e 73 74 *interp;..const
9670: 20 63 68 61 72 20 2a 74 63 6c 5f 72 65 73 75 6c char *tcl_resul
9680: 74 3b 0a 09 69 6e 74 20 74 63 6c 5f 72 65 74 3b t;..int tcl_ret;
9690: 0a 0a 09 69 6e 74 65 72 70 20 3d 20 61 70 70 66 ...interp = appf
96a0: 73 5f 63 72 65 61 74 65 5f 54 63 6c 49 6e 74 65 s_create_TclInte
96b0: 72 70 28 4e 55 4c 4c 29 3b 0a 09 69 66 20 28 69 rp(NULL);..if (i
96c0: 6e 74 65 72 70 20 3d 3d 20 4e 55 4c 4c 29 20 7b nterp == NULL) {
96d0: 0a 09 09 66 70 72 69 6e 74 66 28 73 74 64 65 72 ...fprintf(stder
96e0: 72 2c 20 22 55 6e 61 62 6c 65 20 74 6f 20 63 72 r, "Unable to cr
96f0: 65 61 74 65 20 61 20 54 63 6c 20 69 6e 74 65 72 eate a Tcl inter
9700: 70 72 65 74 65 72 2e 20 20 41 62 6f 72 74 69 6e preter. Abortin
9710: 67 2e 5c 6e 22 29 3b 0a 0a 09 09 72 65 74 75 72 g.\n");....retur
9720: 6e 28 31 29 3b 0a 09 7d 0a 0a 09 74 63 6c 5f 72 n(1);..}...tcl_r
9730: 65 74 20 3d 20 54 63 6c 5f 45 76 61 6c 28 69 6e et = Tcl_Eval(in
9740: 74 65 72 70 2c 20 74 63 6c 29 3b 0a 09 74 63 6c terp, tcl);..tcl
9750: 5f 72 65 73 75 6c 74 20 3d 20 54 63 6c 5f 47 65 _result = Tcl_Ge
9760: 74 53 74 72 69 6e 67 52 65 73 75 6c 74 28 69 6e tStringResult(in
9770: 74 65 72 70 29 3b 0a 0a 09 69 66 20 28 74 63 6c terp);...if (tcl
9780: 5f 72 65 74 20 21 3d 20 54 43 4c 5f 4f 4b 29 20 _ret != TCL_OK)
9790: 7b 0a 09 09 66 70 72 69 6e 74 66 28 73 74 64 65 {...fprintf(stde
97a0: 72 72 2c 20 22 5b 65 72 72 6f 72 5d 20 25 73 5c rr, "[error] %s\
97b0: 6e 22 2c 20 74 63 6c 5f 72 65 73 75 6c 74 29 3b n", tcl_result);
97c0: 0a 0a 09 09 72 65 74 75 72 6e 28 31 29 3b 0a 09 ....return(1);..
97d0: 7d 0a 0a 09 69 66 20 28 74 63 6c 5f 72 65 73 75 }...if (tcl_resu
97e0: 6c 74 20 26 26 20 74 63 6c 5f 72 65 73 75 6c 74 lt && tcl_result
97f0: 5b 30 5d 20 21 3d 20 27 5c 30 27 29 20 7b 0a 09 [0] != '\0') {..
9800: 09 70 72 69 6e 74 66 28 22 25 73 5c 6e 22 2c 20 .printf("%s\n",
9810: 74 63 6c 5f 72 65 73 75 6c 74 29 3b 0a 09 7d 0a tcl_result);..}.
9820: 0a 09 72 65 74 75 72 6e 28 30 29 3b 0a 7d 0a 0a ..return(0);.}..
9830: 2f 2a 0a 20 2a 20 41 70 70 46 53 64 20 50 61 63 /*. * AppFSd Pac
9840: 6b 61 67 65 20 66 6f 72 20 54 63 6c 3a 0a 20 2a kage for Tcl:. *
9850: 20 20 20 20 20 20 20 20 20 42 72 69 64 67 65 20 Bridge
9860: 66 6f 72 20 49 2f 4f 20 6f 70 65 72 61 74 69 6f for I/O operatio
9870: 6e 73 20 74 6f 20 72 65 71 75 65 73 74 20 69 6e ns to request in
9880: 66 6f 72 6d 61 74 69 6f 6e 20 61 62 6f 75 74 20 formation about
9890: 74 68 65 20 63 75 72 72 65 6e 74 0a 20 2a 20 20 the current. *
98a0: 20 20 20 20 20 20 20 74 72 61 6e 73 61 63 74 69 transacti
98b0: 6f 6e 0a 20 2a 2f 0a 2f 2a 0a 20 2a 20 54 63 6c on. */./*. * Tcl
98c0: 20 69 6e 74 65 72 66 61 63 65 20 74 6f 20 67 65 interface to ge
98d0: 74 20 74 68 65 20 68 6f 6d 65 20 64 69 72 65 63 t the home direc
98e0: 74 6f 72 79 20 66 6f 72 20 74 68 65 20 75 73 65 tory for the use
98f0: 72 20 6d 61 6b 69 6e 67 20 74 68 65 20 22 63 75 r making the "cu
9900: 72 72 65 6e 74 22 0a 20 2a 20 46 55 53 45 20 49 rrent". * FUSE I
9910: 2f 4f 20 72 65 71 75 65 73 74 0a 20 2a 2f 0a 73 /O request. */.s
9920: 74 61 74 69 63 20 69 6e 74 20 74 63 6c 5f 61 70 tatic int tcl_ap
9930: 70 66 73 5f 67 65 74 5f 68 6f 6d 65 64 69 72 28 pfs_get_homedir(
9940: 43 6c 69 65 6e 74 44 61 74 61 20 63 64 2c 20 54 ClientData cd, T
9950: 63 6c 5f 49 6e 74 65 72 70 20 2a 69 6e 74 65 72 cl_Interp *inter
9960: 70 2c 20 69 6e 74 20 6f 62 6a 63 2c 20 54 63 6c p, int objc, Tcl
9970: 5f 4f 62 6a 20 2a 43 4f 4e 53 54 20 6f 62 6a 76 _Obj *CONST objv
9980: 5b 5d 29 20 7b 0a 09 63 68 61 72 20 2a 68 6f 6d []) {..char *hom
9990: 65 64 69 72 3b 0a 09 54 63 6c 5f 4f 62 6a 20 2a edir;..Tcl_Obj *
99a0: 68 6f 6d 65 64 69 72 5f 6f 62 6a 3b 0a 09 75 69 homedir_obj;..ui
99b0: 64 5f 74 20 66 73 75 69 64 3b 0a 09 73 74 61 74 d_t fsuid;..stat
99c0: 69 63 20 5f 5f 74 68 72 65 61 64 20 54 63 6c 5f ic __thread Tcl_
99d0: 4f 62 6a 20 2a 6c 61 73 74 5f 68 6f 6d 65 64 69 Obj *last_homedi
99e0: 72 5f 6f 62 6a 20 3d 20 4e 55 4c 4c 3b 0a 09 73 r_obj = NULL;..s
99f0: 74 61 74 69 63 20 5f 5f 74 68 72 65 61 64 20 75 tatic __thread u
9a00: 69 64 5f 74 20 6c 61 73 74 5f 66 73 75 69 64 20 id_t last_fsuid
9a10: 3d 20 2d 31 3b 0a 0a 20 20 20 20 20 20 20 20 69 = -1;.. i
9a20: 66 20 28 6f 62 6a 63 20 21 3d 20 31 29 20 7b 0a f (objc != 1) {.
9a30: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
9a40: 54 63 6c 5f 57 72 6f 6e 67 4e 75 6d 41 72 67 73 Tcl_WrongNumArgs
9a50: 28 69 6e 74 65 72 70 2c 20 31 2c 20 6f 62 6a 76 (interp, 1, objv
9a60: 2c 20 4e 55 4c 4c 29 3b 0a 20 20 20 20 20 20 20 , NULL);.
9a70: 20 20 20 20 20 20 20 20 20 72 65 74 75 72 6e 28 return(
9a80: 54 43 4c 5f 45 52 52 4f 52 29 3b 0a 20 20 20 20 TCL_ERROR);.
9a90: 20 20 20 20 7d 0a 0a 09 66 73 75 69 64 20 3d 20 }...fsuid =
9aa0: 61 70 70 66 73 5f 67 65 74 5f 66 73 75 69 64 28 appfs_get_fsuid(
9ab0: 29 3b 0a 0a 09 69 66 20 28 66 73 75 69 64 20 3d );...if (fsuid =
9ac0: 3d 20 6c 61 73 74 5f 66 73 75 69 64 20 26 26 20 = last_fsuid &&
9ad0: 6c 61 73 74 5f 68 6f 6d 65 64 69 72 5f 6f 62 6a last_homedir_obj
9ae0: 20 21 3d 20 4e 55 4c 4c 29 20 7b 0a 09 09 68 6f != NULL) {...ho
9af0: 6d 65 64 69 72 5f 6f 62 6a 20 3d 20 6c 61 73 74 medir_obj = last
9b00: 5f 68 6f 6d 65 64 69 72 5f 6f 62 6a 3b 0a 0a 09 _homedir_obj;...
9b10: 09 54 63 6c 5f 49 6e 63 72 52 65 66 43 6f 75 6e .Tcl_IncrRefCoun
9b20: 74 28 68 6f 6d 65 64 69 72 5f 6f 62 6a 29 3b 0a t(homedir_obj);.
9b30: 09 7d 20 65 6c 73 65 20 7b 0a 09 09 68 6f 6d 65 .} else {...home
9b40: 64 69 72 20 3d 20 61 70 70 66 73 5f 67 65 74 5f dir = appfs_get_
9b50: 68 6f 6d 65 64 69 72 28 61 70 70 66 73 5f 67 65 homedir(appfs_ge
9b60: 74 5f 66 73 75 69 64 28 29 29 3b 0a 0a 09 09 69 t_fsuid());....i
9b70: 66 20 28 68 6f 6d 65 64 69 72 20 3d 3d 20 4e 55 f (homedir == NU
9b80: 4c 4c 29 20 7b 0a 09 09 09 72 65 74 75 72 6e 28 LL) {....return(
9b90: 54 43 4c 5f 45 52 52 4f 52 29 3b 0a 09 09 7d 0a TCL_ERROR);...}.
9ba0: 0a 09 09 68 6f 6d 65 64 69 72 5f 6f 62 6a 20 3d ...homedir_obj =
9bb0: 20 54 63 6c 5f 4e 65 77 53 74 72 69 6e 67 4f 62 Tcl_NewStringOb
9bc0: 6a 28 68 6f 6d 65 64 69 72 2c 20 2d 31 29 3b 0a j(homedir, -1);.
9bd0: 0a 09 09 66 72 65 65 28 68 6f 6d 65 64 69 72 29 ...free(homedir)
9be0: 3b 0a 0a 09 09 54 63 6c 5f 49 6e 63 72 52 65 66 ;....Tcl_IncrRef
9bf0: 43 6f 75 6e 74 28 68 6f 6d 65 64 69 72 5f 6f 62 Count(homedir_ob
9c00: 6a 29 3b 0a 0a 09 09 69 66 20 28 6c 61 73 74 5f j);....if (last_
9c10: 68 6f 6d 65 64 69 72 5f 6f 62 6a 20 21 3d 20 4e homedir_obj != N
9c20: 55 4c 4c 29 20 7b 0a 09 09 09 54 63 6c 5f 44 65 ULL) {....Tcl_De
9c30: 63 72 52 65 66 43 6f 75 6e 74 28 6c 61 73 74 5f crRefCount(last_
9c40: 68 6f 6d 65 64 69 72 5f 6f 62 6a 29 3b 0a 09 09 homedir_obj);...
9c50: 7d 0a 0a 09 09 6c 61 73 74 5f 68 6f 6d 65 64 69 }....last_homedi
9c60: 72 5f 6f 62 6a 20 3d 20 68 6f 6d 65 64 69 72 5f r_obj = homedir_
9c70: 6f 62 6a 3b 0a 09 09 6c 61 73 74 5f 66 73 75 69 obj;...last_fsui
9c80: 64 20 3d 20 66 73 75 69 64 3b 0a 0a 09 09 54 63 d = fsuid;....Tc
9c90: 6c 5f 49 6e 63 72 52 65 66 43 6f 75 6e 74 28 68 l_IncrRefCount(h
9ca0: 6f 6d 65 64 69 72 5f 6f 62 6a 29 3b 0a 09 7d 0a omedir_obj);..}.
9cb0: 0a 20 20 20 20 20 20 20 09 54 63 6c 5f 53 65 74 . .Tcl_Set
9cc0: 4f 62 6a 52 65 73 75 6c 74 28 69 6e 74 65 72 70 ObjResult(interp
9cd0: 2c 20 68 6f 6d 65 64 69 72 5f 6f 62 6a 29 3b 0a , homedir_obj);.
9ce0: 0a 09 54 63 6c 5f 44 65 63 72 52 65 66 43 6f 75 ..Tcl_DecrRefCou
9cf0: 6e 74 28 68 6f 6d 65 64 69 72 5f 6f 62 6a 29 3b nt(homedir_obj);
9d00: 0a 0a 20 20 20 20 20 20 20 20 72 65 74 75 72 6e .. return
9d10: 28 54 43 4c 5f 4f 4b 29 3b 0a 7d 0a 0a 73 74 61 (TCL_OK);.}..sta
9d20: 74 69 63 20 69 6e 74 20 74 63 6c 5f 61 70 70 66 tic int tcl_appf
9d30: 73 5f 73 69 6d 75 6c 61 74 65 5f 75 73 65 72 5f s_simulate_user_
9d40: 66 73 5f 65 6e 74 65 72 28 43 6c 69 65 6e 74 44 fs_enter(ClientD
9d50: 61 74 61 20 63 64 2c 20 54 63 6c 5f 49 6e 74 65 ata cd, Tcl_Inte
9d60: 72 70 20 2a 69 6e 74 65 72 70 2c 20 69 6e 74 20 rp *interp, int
9d70: 6f 62 6a 63 2c 20 54 63 6c 5f 4f 62 6a 20 2a 43 objc, Tcl_Obj *C
9d80: 4f 4e 53 54 20 6f 62 6a 76 5b 5d 29 20 7b 0a 09 ONST objv[]) {..
9d90: 61 70 70 66 73 5f 73 69 6d 75 6c 61 74 65 5f 75 appfs_simulate_u
9da0: 73 65 72 5f 66 73 5f 65 6e 74 65 72 28 29 3b 0a ser_fs_enter();.
9db0: 0a 09 72 65 74 75 72 6e 28 54 43 4c 5f 4f 4b 29 ..return(TCL_OK)
9dc0: 3b 0a 7d 0a 0a 73 74 61 74 69 63 20 69 6e 74 20 ;.}..static int
9dd0: 74 63 6c 5f 61 70 70 66 73 5f 73 69 6d 75 6c 61 tcl_appfs_simula
9de0: 74 65 5f 75 73 65 72 5f 66 73 5f 6c 65 61 76 65 te_user_fs_leave
9df0: 28 43 6c 69 65 6e 74 44 61 74 61 20 63 64 2c 20 (ClientData cd,
9e00: 54 63 6c 5f 49 6e 74 65 72 70 20 2a 69 6e 74 65 Tcl_Interp *inte
9e10: 72 70 2c 20 69 6e 74 20 6f 62 6a 63 2c 20 54 63 rp, int objc, Tc
9e20: 6c 5f 4f 62 6a 20 2a 43 4f 4e 53 54 20 6f 62 6a l_Obj *CONST obj
9e30: 76 5b 5d 29 20 7b 0a 09 61 70 70 66 73 5f 73 69 v[]) {..appfs_si
9e40: 6d 75 6c 61 74 65 5f 75 73 65 72 5f 66 73 5f 6c mulate_user_fs_l
9e50: 65 61 76 65 28 29 3b 0a 0a 09 72 65 74 75 72 6e eave();...return
9e60: 28 54 43 4c 5f 4f 4b 29 3b 0a 7d 0a 0a 73 74 61 (TCL_OK);.}..sta
9e70: 74 69 63 20 69 6e 74 20 74 63 6c 5f 61 70 70 66 tic int tcl_appf
9e80: 73 5f 67 65 74 5f 66 73 75 69 64 28 43 6c 69 65 s_get_fsuid(Clie
9e90: 6e 74 44 61 74 61 20 63 64 2c 20 54 63 6c 5f 49 ntData cd, Tcl_I
9ea0: 6e 74 65 72 70 20 2a 69 6e 74 65 72 70 2c 20 69 nterp *interp, i
9eb0: 6e 74 20 6f 62 6a 63 2c 20 54 63 6c 5f 4f 62 6a nt objc, Tcl_Obj
9ec0: 20 2a 43 4f 4e 53 54 20 6f 62 6a 76 5b 5d 29 20 *CONST objv[])
9ed0: 7b 0a 09 75 69 64 5f 74 20 66 73 75 69 64 3b 0a {..uid_t fsuid;.
9ee0: 0a 09 66 73 75 69 64 20 3d 20 61 70 70 66 73 5f ..fsuid = appfs_
9ef0: 67 65 74 5f 66 73 75 69 64 28 29 3b 0a 0a 20 20 get_fsuid();..
9f00: 20 20 20 20 20 09 54 63 6c 5f 53 65 74 4f 62 6a .Tcl_SetObj
9f10: 52 65 73 75 6c 74 28 69 6e 74 65 72 70 2c 20 54 Result(interp, T
9f20: 63 6c 5f 4e 65 77 57 69 64 65 49 6e 74 4f 62 6a cl_NewWideIntObj
9f30: 28 66 73 75 69 64 29 29 3b 0a 0a 09 72 65 74 75 (fsuid));...retu
9f40: 72 6e 28 54 43 4c 5f 4f 4b 29 3b 0a 7d 0a 0a 73 rn(TCL_OK);.}..s
9f50: 74 61 74 69 63 20 69 6e 74 20 74 63 6c 5f 61 70 tatic int tcl_ap
9f60: 70 66 73 5f 67 65 74 5f 66 73 67 69 64 28 43 6c pfs_get_fsgid(Cl
9f70: 69 65 6e 74 44 61 74 61 20 63 64 2c 20 54 63 6c ientData cd, Tcl
9f80: 5f 49 6e 74 65 72 70 20 2a 69 6e 74 65 72 70 2c _Interp *interp,
9f90: 20 69 6e 74 20 6f 62 6a 63 2c 20 54 63 6c 5f 4f int objc, Tcl_O
9fa0: 62 6a 20 2a 43 4f 4e 53 54 20 6f 62 6a 76 5b 5d bj *CONST objv[]
9fb0: 29 20 7b 0a 09 67 69 64 5f 74 20 66 73 67 69 64 ) {..gid_t fsgid
9fc0: 3b 0a 0a 09 66 73 67 69 64 20 3d 20 61 70 70 66 ;...fsgid = appf
9fd0: 73 5f 67 65 74 5f 66 73 67 69 64 28 29 3b 0a 0a s_get_fsgid();..
9fe0: 20 20 20 20 20 20 20 09 54 63 6c 5f 53 65 74 4f .Tcl_SetO
9ff0: 62 6a 52 65 73 75 6c 74 28 69 6e 74 65 72 70 2c bjResult(interp,
a000: 20 54 63 6c 5f 4e 65 77 57 69 64 65 49 6e 74 4f Tcl_NewWideIntO
a010: 62 6a 28 66 73 67 69 64 29 29 3b 0a 0a 09 72 65 bj(fsgid));...re
a020: 74 75 72 6e 28 54 43 4c 5f 4f 4b 29 3b 0a 7d 0a turn(TCL_OK);.}.
a030: 0a 73 74 61 74 69 63 20 69 6e 74 20 74 63 6c 5f .static int tcl_
a040: 61 70 70 66 73 5f 67 65 74 5f 70 61 74 68 5f 69 appfs_get_path_i
a050: 6e 66 6f 5f 63 61 63 68 65 5f 66 6c 75 73 68 28 nfo_cache_flush(
a060: 43 6c 69 65 6e 74 44 61 74 61 20 63 64 2c 20 54 ClientData cd, T
a070: 63 6c 5f 49 6e 74 65 72 70 20 2a 69 6e 74 65 72 cl_Interp *inter
a080: 70 2c 20 69 6e 74 20 6f 62 6a 63 2c 20 54 63 6c p, int objc, Tcl
a090: 5f 4f 62 6a 20 2a 43 4f 4e 53 54 20 6f 62 6a 76 _Obj *CONST objv
a0a0: 5b 5d 29 20 7b 0a 09 69 6e 74 20 74 63 6c 5f 72 []) {..int tcl_r
a0b0: 65 74 3b 0a 09 69 6e 74 20 6e 65 77 5f 73 69 7a et;..int new_siz
a0c0: 65 3b 0a 0a 09 6e 65 77 5f 73 69 7a 65 20 3d 20 e;...new_size =
a0d0: 2d 31 3b 0a 0a 09 69 66 20 28 6f 62 6a 63 20 3d -1;...if (objc =
a0e0: 3d 20 32 29 20 7b 0a 09 09 74 63 6c 5f 72 65 74 = 2) {...tcl_ret
a0f0: 20 3d 20 54 63 6c 5f 47 65 74 49 6e 74 46 72 6f = Tcl_GetIntFro
a100: 6d 4f 62 6a 28 69 6e 74 65 72 70 2c 20 6f 62 6a mObj(interp, obj
a110: 76 5b 31 5d 2c 20 26 6e 65 77 5f 73 69 7a 65 29 v[1], &new_size)
a120: 3b 0a 09 09 69 66 20 28 74 63 6c 5f 72 65 74 20 ;...if (tcl_ret
a130: 21 3d 20 54 43 4c 5f 4f 4b 29 20 7b 0a 09 09 09 != TCL_OK) {....
a140: 72 65 74 75 72 6e 28 74 63 6c 5f 72 65 74 29 3b return(tcl_ret);
a150: 0a 09 09 7d 0a 09 7d 20 65 6c 73 65 20 69 66 20 ...}..} else if
a160: 28 6f 62 6a 63 20 3e 20 32 20 7c 7c 20 6f 62 6a (objc > 2 || obj
a170: 63 20 3c 20 31 29 20 7b 0a 20 20 20 20 20 20 20 c < 1) {.
a180: 20 20 20 20 20 20 20 20 20 54 63 6c 5f 57 72 6f Tcl_Wro
a190: 6e 67 4e 75 6d 41 72 67 73 28 69 6e 74 65 72 70 ngNumArgs(interp
a1a0: 2c 20 31 2c 20 6f 62 6a 76 2c 20 22 3f 6e 65 77 , 1, objv, "?new
a1b0: 5f 63 61 63 68 65 5f 73 69 7a 65 3f 22 29 3b 0a _cache_size?");.
a1c0: 09 09 72 65 74 75 72 6e 28 54 43 4c 5f 45 52 52 ..return(TCL_ERR
a1d0: 4f 52 29 3b 0a 09 7d 0a 0a 09 61 70 70 66 73 5f OR);..}...appfs_
a1e0: 67 65 74 5f 70 61 74 68 5f 69 6e 66 6f 5f 63 61 get_path_info_ca
a1f0: 63 68 65 5f 66 6c 75 73 68 28 2d 31 2c 20 6e 65 che_flush(-1, ne
a200: 77 5f 73 69 7a 65 29 3b 0a 0a 09 72 65 74 75 72 w_size);...retur
a210: 6e 28 54 43 4c 5f 4f 4b 29 3b 0a 7d 0a 0a 73 74 n(TCL_OK);.}..st
a220: 61 74 69 63 20 69 6e 74 20 41 70 70 66 73 64 5f atic int Appfsd_
a230: 49 6e 69 74 28 54 63 6c 5f 49 6e 74 65 72 70 20 Init(Tcl_Interp
a240: 2a 69 6e 74 65 72 70 29 20 7b 0a 23 69 66 64 65 *interp) {.#ifde
a250: 66 20 55 53 45 5f 54 43 4c 5f 53 54 55 42 53 0a f USE_TCL_STUBS.
a260: 09 69 66 20 28 54 63 6c 5f 49 6e 69 74 53 74 75 .if (Tcl_InitStu
a270: 62 73 28 69 6e 74 65 72 70 2c 20 54 43 4c 5f 56 bs(interp, TCL_V
a280: 45 52 53 49 4f 4e 2c 20 30 29 20 3d 3d 20 30 4c ERSION, 0) == 0L
a290: 29 20 7b 0a 09 09 72 65 74 75 72 6e 28 54 43 4c ) {...return(TCL
a2a0: 5f 45 52 52 4f 52 29 3b 0a 09 7d 0a 23 65 6e 64 _ERROR);..}.#end
a2b0: 69 66 0a 0a 09 54 63 6c 5f 43 72 65 61 74 65 4f if...Tcl_CreateO
a2c0: 62 6a 43 6f 6d 6d 61 6e 64 28 69 6e 74 65 72 70 bjCommand(interp
a2d0: 2c 20 22 61 70 70 66 73 64 3a 3a 67 65 74 5f 68 , "appfsd::get_h
a2e0: 6f 6d 65 64 69 72 22 2c 20 74 63 6c 5f 61 70 70 omedir", tcl_app
a2f0: 66 73 5f 67 65 74 5f 68 6f 6d 65 64 69 72 2c 20 fs_get_homedir,
a300: 4e 55 4c 4c 2c 20 4e 55 4c 4c 29 3b 0a 09 54 63 NULL, NULL);..Tc
a310: 6c 5f 43 72 65 61 74 65 4f 62 6a 43 6f 6d 6d 61 l_CreateObjComma
a320: 6e 64 28 69 6e 74 65 72 70 2c 20 22 61 70 70 66 nd(interp, "appf
a330: 73 64 3a 3a 67 65 74 5f 66 73 75 69 64 22 2c 20 sd::get_fsuid",
a340: 74 63 6c 5f 61 70 70 66 73 5f 67 65 74 5f 66 73 tcl_appfs_get_fs
a350: 75 69 64 2c 20 4e 55 4c 4c 2c 20 4e 55 4c 4c 29 uid, NULL, NULL)
a360: 3b 0a 09 54 63 6c 5f 43 72 65 61 74 65 4f 62 6a ;..Tcl_CreateObj
a370: 43 6f 6d 6d 61 6e 64 28 69 6e 74 65 72 70 2c 20 Command(interp,
a380: 22 61 70 70 66 73 64 3a 3a 67 65 74 5f 66 73 67 "appfsd::get_fsg
a390: 69 64 22 2c 20 74 63 6c 5f 61 70 70 66 73 5f 67 id", tcl_appfs_g
a3a0: 65 74 5f 66 73 67 69 64 2c 20 4e 55 4c 4c 2c 20 et_fsgid, NULL,
a3b0: 4e 55 4c 4c 29 3b 0a 09 54 63 6c 5f 43 72 65 61 NULL);..Tcl_Crea
a3c0: 74 65 4f 62 6a 43 6f 6d 6d 61 6e 64 28 69 6e 74 teObjCommand(int
a3d0: 65 72 70 2c 20 22 61 70 70 66 73 64 3a 3a 73 69 erp, "appfsd::si
a3e0: 6d 75 6c 61 74 65 5f 75 73 65 72 5f 66 73 5f 65 mulate_user_fs_e
a3f0: 6e 74 65 72 22 2c 20 74 63 6c 5f 61 70 70 66 73 nter", tcl_appfs
a400: 5f 73 69 6d 75 6c 61 74 65 5f 75 73 65 72 5f 66 _simulate_user_f
a410: 73 5f 65 6e 74 65 72 2c 20 4e 55 4c 4c 2c 20 4e s_enter, NULL, N
a420: 55 4c 4c 29 3b 0a 09 54 63 6c 5f 43 72 65 61 74 ULL);..Tcl_Creat
a430: 65 4f 62 6a 43 6f 6d 6d 61 6e 64 28 69 6e 74 65 eObjCommand(inte
a440: 72 70 2c 20 22 61 70 70 66 73 64 3a 3a 73 69 6d rp, "appfsd::sim
a450: 75 6c 61 74 65 5f 75 73 65 72 5f 66 73 5f 6c 65 ulate_user_fs_le
a460: 61 76 65 22 2c 20 74 63 6c 5f 61 70 70 66 73 5f ave", tcl_appfs_
a470: 73 69 6d 75 6c 61 74 65 5f 75 73 65 72 5f 66 73 simulate_user_fs
a480: 5f 6c 65 61 76 65 2c 20 4e 55 4c 4c 2c 20 4e 55 _leave, NULL, NU
a490: 4c 4c 29 3b 0a 09 54 63 6c 5f 43 72 65 61 74 65 LL);..Tcl_Create
a4a0: 4f 62 6a 43 6f 6d 6d 61 6e 64 28 69 6e 74 65 72 ObjCommand(inter
a4b0: 70 2c 20 22 61 70 70 66 73 64 3a 3a 67 65 74 5f p, "appfsd::get_
a4c0: 70 61 74 68 5f 69 6e 66 6f 5f 63 61 63 68 65 5f path_info_cache_
a4d0: 66 6c 75 73 68 22 2c 20 74 63 6c 5f 61 70 70 66 flush", tcl_appf
a4e0: 73 5f 67 65 74 5f 70 61 74 68 5f 69 6e 66 6f 5f s_get_path_info_
a4f0: 63 61 63 68 65 5f 66 6c 75 73 68 2c 20 4e 55 4c cache_flush, NUL
a500: 4c 2c 20 4e 55 4c 4c 29 3b 0a 0a 09 54 63 6c 5f L, NULL);...Tcl_
a510: 50 6b 67 50 72 6f 76 69 64 65 28 69 6e 74 65 72 PkgProvide(inter
a520: 70 2c 20 22 61 70 70 66 73 64 22 2c 20 22 31 2e p, "appfsd", "1.
a530: 30 22 29 3b 0a 0a 09 72 65 74 75 72 6e 28 54 43 0");...return(TC
a540: 4c 5f 4f 4b 29 3b 0a 7d 0a 0a 2f 2a 0a 20 2a 20 L_OK);.}../*. *
a550: 48 6f 74 2d 72 65 73 74 61 72 74 20 73 75 70 70 Hot-restart supp
a560: 6f 72 74 0a 20 2a 2f 0a 2f 2a 20 49 6e 69 74 69 ort. */./* Initi
a570: 61 74 65 20 61 20 68 6f 74 2d 72 65 73 74 61 72 ate a hot-restar
a580: 74 20 2a 2f 0a 73 74 61 74 69 63 20 76 6f 69 64 t */.static void
a590: 20 61 70 70 66 73 5f 68 6f 74 5f 72 65 73 74 61 appfs_hot_resta
a5a0: 72 74 28 76 6f 69 64 29 20 7b 0a 09 41 50 50 46 rt(void) {..APPF
a5b0: 53 5f 44 45 42 55 47 28 22 41 73 6b 65 64 20 74 S_DEBUG("Asked t
a5c0: 6f 20 69 6e 69 74 69 61 74 65 20 68 6f 74 20 72 o initiate hot r
a5d0: 65 73 74 61 72 74 22 29 3b 0a 0a 09 61 70 70 66 estart");...appf
a5e0: 73 5f 74 63 6c 5f 52 65 73 65 74 49 6e 74 65 72 s_tcl_ResetInter
a5f0: 70 73 28 29 3b 0a 09 61 70 70 66 73 5f 67 65 74 ps();..appfs_get
a600: 5f 70 61 74 68 5f 69 6e 66 6f 5f 63 61 63 68 65 _path_info_cache
a610: 5f 66 6c 75 73 68 28 2d 31 2c 20 2d 31 29 3b 0a _flush(-1, -1);.
a620: 0a 09 72 65 74 75 72 6e 3b 0a 7d 0a 0a 2f 2a 0a ..return;.}../*.
a630: 20 2a 20 53 69 67 6e 61 6c 20 68 61 6e 64 6c 65 * Signal handle
a640: 72 0a 20 2a 20 20 20 20 20 20 20 20 20 53 49 47 r. * SIG
a650: 48 55 50 20 69 6e 69 74 69 61 74 65 73 20 61 20 HUP initiates a
a660: 68 6f 74 20 72 65 73 74 61 72 74 0a 20 2a 2f 0a hot restart. */.
a670: 73 74 61 74 69 63 20 76 6f 69 64 20 61 70 70 66 static void appf
a680: 73 5f 73 69 67 6e 61 6c 5f 68 61 6e 64 6c 65 72 s_signal_handler
a690: 28 69 6e 74 20 73 69 67 29 20 7b 0a 09 2f 2a 20 (int sig) {../*
a6a0: 44 6f 20 6e 6f 74 20 68 61 6e 64 6c 65 20 73 69 Do not handle si
a6b0: 67 6e 61 6c 73 20 75 6e 74 69 6c 20 46 55 53 45 gnals until FUSE
a6c0: 20 68 61 73 20 62 65 65 6e 20 73 74 61 72 74 65 has been starte
a6d0: 64 20 2a 2f 0a 09 69 66 20 28 21 61 70 70 66 73 d */..if (!appfs
a6e0: 5f 66 75 73 65 5f 73 74 61 72 74 65 64 29 20 7b _fuse_started) {
a6f0: 0a 09 09 72 65 74 75 72 6e 3b 0a 09 7d 0a 0a 09 ...return;..}...
a700: 2f 2a 20 52 65 71 75 65 73 74 20 74 6f 20 70 65 /* Request to pe
a710: 72 66 6f 72 6d 20 61 20 22 68 6f 74 22 20 72 65 rform a "hot" re
a720: 73 74 61 72 74 20 2a 2f 0a 09 69 66 20 28 73 69 start */..if (si
a730: 67 20 3d 3d 20 53 49 47 48 55 50 29 20 7b 0a 09 g == SIGHUP) {..
a740: 09 61 70 70 66 73 5f 68 6f 74 5f 72 65 73 74 61 .appfs_hot_resta
a750: 72 74 28 29 3b 0a 09 7d 0a 0a 09 72 65 74 75 72 rt();..}...retur
a760: 6e 3b 0a 7d 0a 0a 2f 2a 0a 20 2a 20 54 65 72 6d n;.}../*. * Term
a770: 69 6e 61 74 65 20 61 20 74 68 72 65 61 64 0a 20 inate a thread.
a780: 2a 2f 0a 73 74 61 74 69 63 20 76 6f 69 64 20 61 */.static void a
a790: 70 70 66 73 5f 74 65 72 6d 69 6e 61 74 65 5f 69 ppfs_terminate_i
a7a0: 6e 74 65 72 70 5f 61 6e 64 5f 74 68 72 65 61 64 nterp_and_thread
a7b0: 28 76 6f 69 64 20 2a 5f 69 6e 74 65 72 70 29 20 (void *_interp)
a7c0: 7b 0a 09 54 63 6c 5f 49 6e 74 65 72 70 20 2a 69 {..Tcl_Interp *i
a7d0: 6e 74 65 72 70 3b 0a 0a 09 41 50 50 46 53 5f 44 nterp;...APPFS_D
a7e0: 45 42 55 47 28 22 43 61 6c 6c 65 64 3a 20 5f 69 EBUG("Called: _i
a7f0: 6e 74 65 72 70 20 3d 20 25 70 22 2c 20 5f 69 6e nterp = %p", _in
a800: 74 65 72 70 29 3b 0a 0a 09 69 66 20 28 5f 69 6e terp);...if (_in
a810: 74 65 72 70 20 3d 3d 20 4e 55 4c 4c 29 20 7b 0a terp == NULL) {.
a820: 09 09 41 50 50 46 53 5f 44 45 42 55 47 28 22 54 ..APPFS_DEBUG("T
a830: 65 72 6d 69 6e 61 74 69 6e 67 20 74 68 72 65 61 erminating threa
a840: 64 20 77 69 74 68 20 6e 6f 20 69 6e 74 65 72 70 d with no interp
a850: 72 65 74 65 72 22 29 3b 0a 0a 09 09 72 65 74 75 reter");....retu
a860: 72 6e 3b 0a 09 7d 0a 0a 09 69 6e 74 65 72 70 20 rn;..}...interp
a870: 3d 20 5f 69 6e 74 65 72 70 3b 0a 0a 09 41 50 50 = _interp;...APP
a880: 46 53 5f 44 45 42 55 47 28 22 54 65 72 6d 69 6e FS_DEBUG("Termin
a890: 61 74 69 6e 67 20 69 6e 74 65 72 70 72 65 74 65 ating interprete
a8a0: 72 20 64 75 65 20 74 6f 20 74 68 72 65 61 64 20 r due to thread
a8b0: 74 65 72 6d 69 6e 61 74 69 6f 6e 22 29 3b 0a 0a termination");..
a8c0: 09 61 70 70 66 73 5f 63 61 6c 6c 5f 6c 69 62 74 .appfs_call_libt
a8d0: 63 6c 28 0a 09 09 54 63 6c 5f 44 65 6c 65 74 65 cl(...Tcl_Delete
a8e0: 49 6e 74 65 72 70 28 69 6e 74 65 72 70 29 3b 0a Interp(interp);.
a8f0: 09 29 0a 0a 09 54 63 6c 5f 46 69 6e 61 6c 69 7a .)...Tcl_Finaliz
a900: 65 54 68 72 65 61 64 28 29 3b 0a 0a 09 72 65 74 eThread();...ret
a910: 75 72 6e 3b 0a 7d 0a 0a 2f 2a 0a 20 2a 20 46 55 urn;.}../*. * FU
a920: 53 45 20 6f 70 65 72 61 74 69 6f 6e 73 20 73 74 SE operations st
a930: 72 75 63 74 75 72 65 0a 20 2a 2f 0a 73 74 61 74 ructure. */.stat
a940: 69 63 20 73 74 72 75 63 74 20 66 75 73 65 5f 6f ic struct fuse_o
a950: 70 65 72 61 74 69 6f 6e 73 20 61 70 70 66 73 5f perations appfs_
a960: 6f 70 65 72 61 74 69 6f 6e 73 20 3d 20 7b 0a 09 operations = {..
a970: 2e 67 65 74 61 74 74 72 20 20 20 3d 20 61 70 70 .getattr = app
a980: 66 73 5f 66 75 73 65 5f 67 65 74 61 74 74 72 2c fs_fuse_getattr,
a990: 0a 09 2e 72 65 61 64 64 69 72 20 20 20 3d 20 61 ...readdir = a
a9a0: 70 70 66 73 5f 66 75 73 65 5f 72 65 61 64 64 69 ppfs_fuse_readdi
a9b0: 72 2c 0a 09 2e 72 65 61 64 6c 69 6e 6b 20 20 3d r,...readlink =
a9c0: 20 61 70 70 66 73 5f 66 75 73 65 5f 72 65 61 64 appfs_fuse_read
a9d0: 6c 69 6e 6b 2c 0a 09 2e 6f 70 65 6e 20 20 20 20 link,...open
a9e0: 20 20 3d 20 61 70 70 66 73 5f 66 75 73 65 5f 6f = appfs_fuse_o
a9f0: 70 65 6e 2c 0a 09 2e 72 65 6c 65 61 73 65 20 20 pen,...release
aa00: 20 3d 20 61 70 70 66 73 5f 66 75 73 65 5f 63 6c = appfs_fuse_cl
aa10: 6f 73 65 2c 0a 09 2e 72 65 61 64 20 20 20 20 20 ose,...read
aa20: 20 3d 20 61 70 70 66 73 5f 66 75 73 65 5f 72 65 = appfs_fuse_re
aa30: 61 64 2c 0a 09 2e 77 72 69 74 65 20 20 20 20 20 ad,...write
aa40: 3d 20 61 70 70 66 73 5f 66 75 73 65 5f 77 72 69 = appfs_fuse_wri
aa50: 74 65 2c 0a 09 2e 6d 6b 6e 6f 64 20 20 20 20 20 te,...mknod
aa60: 3d 20 61 70 70 66 73 5f 66 75 73 65 5f 6d 6b 6e = appfs_fuse_mkn
aa70: 6f 64 2c 0a 09 2e 63 72 65 61 74 65 20 20 20 20 od,...create
aa80: 3d 20 61 70 70 66 73 5f 66 75 73 65 5f 63 72 65 = appfs_fuse_cre
aa90: 61 74 65 2c 0a 09 2e 74 72 75 6e 63 61 74 65 20 ate,...truncate
aaa0: 20 3d 20 61 70 70 66 73 5f 66 75 73 65 5f 74 72 = appfs_fuse_tr
aab0: 75 6e 63 61 74 65 2c 0a 09 2e 75 6e 6c 69 6e 6b uncate,...unlink
aac0: 20 20 20 20 3d 20 61 70 70 66 73 5f 66 75 73 65 = appfs_fuse
aad0: 5f 75 6e 6c 69 6e 6b 5f 72 6d 64 69 72 2c 0a 09 _unlink_rmdir,..
aae0: 2e 72 6d 64 69 72 20 20 20 20 20 3d 20 61 70 70 .rmdir = app
aaf0: 66 73 5f 66 75 73 65 5f 75 6e 6c 69 6e 6b 5f 72 fs_fuse_unlink_r
ab00: 6d 64 69 72 2c 0a 09 2e 6d 6b 64 69 72 20 20 20 mdir,...mkdir
ab10: 20 20 3d 20 61 70 70 66 73 5f 66 75 73 65 5f 6d = appfs_fuse_m
ab20: 6b 64 69 72 2c 0a 09 2e 63 68 6d 6f 64 20 20 20 kdir,...chmod
ab30: 20 20 3d 20 61 70 70 66 73 5f 66 75 73 65 5f 63 = appfs_fuse_c
ab40: 68 6d 6f 64 2c 0a 09 2e 73 79 6d 6c 69 6e 6b 20 hmod,...symlink
ab50: 20 20 3d 20 61 70 70 66 73 5f 66 75 73 65 5f 73 = appfs_fuse_s
ab60: 79 6d 6c 69 6e 6b 2c 0a 7d 3b 0a 0a 2f 2a 0a 20 ymlink,.};../*.
ab70: 2a 20 46 55 53 45 20 6f 70 74 69 6f 6e 20 70 61 * FUSE option pa
ab80: 72 73 69 6e 67 20 63 61 6c 6c 62 61 63 6b 0a 20 rsing callback.
ab90: 2a 2f 0a 73 74 61 74 69 63 20 69 6e 74 20 61 70 */.static int ap
aba0: 70 66 73 5f 66 75 73 65 5f 6f 70 74 5f 63 62 28 pfs_fuse_opt_cb(
abb0: 76 6f 69 64 20 2a 64 61 74 61 2c 20 63 6f 6e 73 void *data, cons
abc0: 74 20 63 68 61 72 20 2a 61 72 67 2c 20 69 6e 74 t char *arg, int
abd0: 20 6b 65 79 2c 20 73 74 72 75 63 74 20 66 75 73 key, struct fus
abe0: 65 5f 61 72 67 73 20 2a 6f 75 74 61 72 67 73 29 e_args *outargs)
abf0: 20 7b 0a 09 73 74 61 74 69 63 20 69 6e 74 20 73 {..static int s
ac00: 65 65 6e 5f 63 61 63 68 65 64 69 72 20 3d 20 30 een_cachedir = 0
ac10: 3b 0a 0a 09 69 66 20 28 6b 65 79 20 3d 3d 20 46 ;...if (key == F
ac20: 55 53 45 5f 4f 50 54 5f 4b 45 59 5f 4e 4f 4e 4f USE_OPT_KEY_NONO
ac30: 50 54 20 26 26 20 73 65 65 6e 5f 63 61 63 68 65 PT && seen_cache
ac40: 64 69 72 20 3d 3d 20 30 29 20 7b 0a 09 09 73 65 dir == 0) {...se
ac50: 65 6e 5f 63 61 63 68 65 64 69 72 20 3d 20 31 3b en_cachedir = 1;
ac60: 0a 0a 09 09 61 70 70 66 73 5f 63 61 63 68 65 64 ....appfs_cached
ac70: 69 72 20 3d 20 73 74 72 64 75 70 28 61 72 67 29 ir = strdup(arg)
ac80: 3b 0a 0a 09 09 72 65 74 75 72 6e 28 30 29 3b 0a ;....return(0);.
ac90: 09 7d 0a 0a 09 72 65 74 75 72 6e 28 31 29 3b 0a .}...return(1);.
aca0: 7d 0a 0a 2f 2a 0a 20 2a 20 45 6e 74 72 79 20 70 }../*. * Entry p
acb0: 6f 69 6e 74 20 69 6e 74 6f 20 74 68 69 73 20 70 oint into this p
acc0: 72 6f 67 72 61 6d 2e 0a 20 2a 2f 0a 69 6e 74 20 rogram.. */.int
acd0: 6d 61 69 6e 28 69 6e 74 20 61 72 67 63 2c 20 63 main(int argc, c
ace0: 68 61 72 20 2a 2a 61 72 67 76 29 20 7b 0a 09 54 har **argv) {..T
acf0: 63 6c 5f 49 6e 74 65 72 70 20 2a 74 65 73 74 5f cl_Interp *test_
ad00: 69 6e 74 65 72 70 3b 0a 09 63 68 61 72 20 2a 74 interp;..char *t
ad10: 65 73 74 5f 69 6e 74 65 72 70 5f 65 72 72 6f 72 est_interp_error
ad20: 3b 0a 09 73 74 72 75 63 74 20 66 75 73 65 5f 61 ;..struct fuse_a
ad30: 72 67 73 20 61 72 67 73 20 3d 20 46 55 53 45 5f rgs args = FUSE_
ad40: 41 52 47 53 5f 49 4e 49 54 28 61 72 67 63 2c 20 ARGS_INIT(argc,
ad50: 61 72 67 76 29 3b 0a 09 69 6e 74 20 70 74 68 72 argv);..int pthr
ad60: 65 61 64 5f 72 65 74 3b 0a 09 76 6f 69 64 20 2a ead_ret;..void *
ad70: 73 69 67 6e 61 6c 5f 72 65 74 3b 0a 0a 09 2f 2a signal_ret;.../*
ad80: 0a 09 20 2a 20 53 6b 69 70 20 70 61 73 73 65 64 .. * Skip passed
ad90: 20 70 72 6f 67 72 61 6d 20 6e 61 6d 65 0a 09 20 program name..
ada0: 2a 2f 0a 09 69 66 20 28 61 72 67 63 20 3d 3d 20 */..if (argc ==
adb0: 30 20 7c 7c 20 61 72 67 76 20 3d 3d 20 4e 55 4c 0 || argv == NUL
adc0: 4c 29 20 7b 0a 09 09 72 65 74 75 72 6e 28 31 29 L) {...return(1)
add0: 3b 0a 09 7d 0a 09 61 72 67 63 2d 2d 3b 0a 09 61 ;..}..argc--;..a
ade0: 72 67 76 2b 2b 3b 0a 0a 09 2f 2a 0a 09 20 2a 20 rgv++;.../*.. *
adf0: 53 65 74 20 67 6c 6f 62 61 6c 20 76 61 72 69 61 Set global varia
ae00: 62 6c 65 73 2c 20 74 68 65 73 65 20 73 68 6f 75 bles, these shou
ae10: 6c 64 20 62 65 20 63 6f 6e 66 69 67 75 72 61 74 ld be configurat
ae20: 69 6f 6e 20 6f 70 74 69 6f 6e 73 2e 0a 09 20 2a ion options... *
ae30: 2f 0a 09 61 70 70 66 73 5f 63 61 63 68 65 64 69 /..appfs_cachedi
ae40: 72 20 3d 20 41 50 50 46 53 5f 43 41 43 48 45 44 r = APPFS_CACHED
ae50: 49 52 3b 0a 0a 09 2f 2a 0a 09 20 2a 20 53 65 74 IR;.../*.. * Set
ae60: 20 67 6c 6f 62 61 6c 20 76 61 72 69 61 62 6c 65 global variable
ae70: 20 66 6f 72 20 22 62 6f 6f 74 20 74 69 6d 65 22 for "boot time"
ae80: 20 74 6f 20 73 65 74 20 61 20 74 69 6d 65 20 6f to set a time o
ae90: 6e 20 64 69 72 65 63 74 6f 72 69 65 73 0a 09 20 n directories..
aea0: 2a 20 74 68 61 74 20 77 65 20 66 61 6b 65 2e 0a * that we fake..
aeb0: 09 20 2a 2f 0a 09 61 70 70 66 73 5f 62 6f 6f 74 . */..appfs_boot
aec0: 74 69 6d 65 20 3d 20 74 69 6d 65 28 4e 55 4c 4c time = time(NULL
aed0: 29 3b 0a 0a 09 2f 2a 0a 09 20 2a 20 52 65 67 69 );.../*.. * Regi
aee0: 73 74 65 72 20 22 73 68 61 31 22 20 61 6e 64 20 ster "sha1" and
aef0: 22 61 70 70 66 73 64 22 20 70 61 63 6b 61 67 65 "appfsd" package
af00: 20 77 69 74 68 20 6c 69 62 74 63 6c 20 73 6f 20 with libtcl so
af10: 74 68 61 74 20 61 6e 79 20 6e 65 77 0a 09 20 2a that any new.. *
af20: 20 69 6e 74 65 72 70 72 65 74 65 72 73 20 63 72 interpreters cr
af30: 65 61 74 65 64 20 28 77 68 69 63 68 20 61 72 65 eated (which are
af40: 20 64 6f 6e 65 20 64 79 6e 61 6d 69 63 61 6c 6c done dynamicall
af50: 79 20 62 79 20 46 55 53 45 29 20 63 61 6e 20 68 y by FUSE) can h
af60: 61 76 65 0a 09 20 2a 20 74 68 65 20 61 70 70 72 ave.. * the appr
af70: 6f 70 72 69 61 74 65 20 63 6f 6e 66 69 67 75 72 opriate configur
af80: 61 74 69 6f 6e 20 64 6f 6e 65 20 61 75 74 6f 6d ation done autom
af90: 61 74 69 63 61 6c 6c 79 2e 0a 09 20 2a 2f 0a 09 atically... */..
afa0: 54 63 6c 5f 53 74 61 74 69 63 50 61 63 6b 61 67 Tcl_StaticPackag
afb0: 65 28 4e 55 4c 4c 2c 20 22 73 68 61 31 22 2c 20 e(NULL, "sha1",
afc0: 53 68 61 31 5f 49 6e 69 74 2c 20 4e 55 4c 4c 29 Sha1_Init, NULL)
afd0: 3b 0a 09 54 63 6c 5f 53 74 61 74 69 63 50 61 63 ;..Tcl_StaticPac
afe0: 6b 61 67 65 28 4e 55 4c 4c 2c 20 22 61 70 70 66 kage(NULL, "appf
aff0: 73 64 22 2c 20 41 70 70 66 73 64 5f 49 6e 69 74 sd", Appfsd_Init
b000: 2c 20 4e 55 4c 4c 29 3b 0a 0a 09 2f 2a 0a 09 20 , NULL);.../*..
b010: 2a 20 43 72 65 61 74 65 20 61 20 74 68 72 65 61 * Create a threa
b020: 64 2d 73 70 65 63 69 66 69 63 2d 64 61 74 61 20 d-specific-data
b030: 28 54 53 44 29 20 6b 65 79 20 66 6f 72 20 65 61 (TSD) key for ea
b040: 63 68 20 74 68 72 65 61 64 20 74 6f 20 72 65 66 ch thread to ref
b050: 65 72 0a 09 20 2a 20 74 6f 20 69 74 73 20 6f 77 er.. * to its ow
b060: 6e 20 54 63 6c 20 69 6e 74 65 72 70 72 65 74 65 n Tcl interprete
b070: 72 2e 20 20 54 63 6c 20 69 6e 74 65 72 70 72 65 r. Tcl interpre
b080: 74 65 72 73 20 6d 75 73 74 20 62 65 20 75 6e 69 ters must be uni
b090: 71 75 65 20 70 65 72 0a 09 20 2a 20 74 68 72 65 que per.. * thre
b0a0: 61 64 20 61 6e 64 20 6e 65 77 20 74 68 72 65 61 ad and new threa
b0b0: 64 73 20 61 72 65 20 64 79 6e 61 6d 69 63 61 6c ds are dynamical
b0c0: 6c 79 20 63 72 65 61 74 65 64 20 62 79 20 46 55 ly created by FU
b0d0: 53 45 2e 0a 09 20 2a 2f 0a 09 70 74 68 72 65 61 SE... */..pthrea
b0e0: 64 5f 72 65 74 20 3d 20 70 74 68 72 65 61 64 5f d_ret = pthread_
b0f0: 6b 65 79 5f 63 72 65 61 74 65 28 26 69 6e 74 65 key_create(&inte
b100: 72 70 4b 65 79 2c 20 61 70 70 66 73 5f 74 65 72 rpKey, appfs_ter
b110: 6d 69 6e 61 74 65 5f 69 6e 74 65 72 70 5f 61 6e minate_interp_an
b120: 64 5f 74 68 72 65 61 64 29 3b 0a 09 69 66 20 28 d_thread);..if (
b130: 70 74 68 72 65 61 64 5f 72 65 74 20 21 3d 20 30 pthread_ret != 0
b140: 29 20 7b 0a 09 09 66 70 72 69 6e 74 66 28 73 74 ) {...fprintf(st
b150: 64 65 72 72 2c 20 22 55 6e 61 62 6c 65 20 74 6f derr, "Unable to
b160: 20 63 72 65 61 74 65 20 54 53 44 20 6b 65 79 20 create TSD key
b170: 66 6f 72 20 54 63 6c 2e 20 20 41 62 6f 72 74 69 for Tcl. Aborti
b180: 6e 67 2e 5c 6e 22 29 3b 0a 0a 09 09 72 65 74 75 ng.\n");....retu
b190: 72 6e 28 31 29 3b 0a 09 7d 0a 0a 09 2f 2a 0a 09 rn(1);..}.../*..
b1a0: 20 2a 20 4d 61 6e 75 61 6c 6c 79 20 73 70 65 63 * Manually spec
b1b0: 69 66 79 20 63 61 63 68 65 20 64 69 72 65 63 74 ify cache direct
b1c0: 6f 72 79 2c 20 77 69 74 68 6f 75 74 20 46 55 53 ory, without FUS
b1d0: 45 20 63 61 6c 6c 62 61 63 6b 0a 09 20 2a 20 54 E callback.. * T
b1e0: 68 69 73 20 6f 70 74 69 6f 6e 20 6f 6e 6c 79 20 his option only
b1f0: 77 6f 72 6b 73 20 77 68 65 6e 20 6e 6f 74 20 75 works when not u
b200: 73 69 6e 67 20 46 55 53 45 2c 20 73 69 6e 63 65 sing FUSE, since
b210: 20 77 65 0a 09 20 2a 20 64 6f 20 6e 6f 74 20 70 we.. * do not p
b220: 72 6f 63 65 73 73 20 69 74 20 77 69 74 68 20 46 rocess it with F
b230: 55 53 45 73 20 6f 70 74 69 6f 6e 20 70 72 6f 63 USEs option proc
b240: 65 73 73 69 6e 67 2e 0a 09 20 2a 2f 0a 09 69 66 essing... */..if
b250: 20 28 61 72 67 63 20 3e 3d 20 32 29 20 7b 0a 09 (argc >= 2) {..
b260: 09 69 66 20 28 73 74 72 63 6d 70 28 61 72 67 76 .if (strcmp(argv
b270: 5b 30 5d 2c 20 22 2d 2d 63 61 63 68 65 64 69 72 [0], "--cachedir
b280: 22 29 20 3d 3d 20 30 29 20 7b 0a 09 09 09 61 70 ") == 0) {....ap
b290: 70 66 73 5f 63 61 63 68 65 64 69 72 20 3d 20 73 pfs_cachedir = s
b2a0: 74 72 64 75 70 28 61 72 67 76 5b 31 5d 29 3b 0a trdup(argv[1]);.
b2b0: 0a 09 09 09 61 72 67 63 20 2d 3d 20 32 3b 0a 09 ....argc -= 2;..
b2c0: 09 09 61 72 67 76 20 2b 3d 20 32 3b 0a 09 09 7d ..argv += 2;...}
b2d0: 0a 09 7d 0a 0a 09 2f 2a 0a 09 20 2a 20 53 51 4c ..}.../*.. * SQL
b2e0: 69 74 65 33 20 6d 6f 64 65 2c 20 66 6f 72 20 72 ite3 mode, for r
b2f0: 75 6e 6e 69 6e 67 20 72 61 77 20 53 51 4c 20 61 unning raw SQL a
b300: 67 61 69 6e 73 74 20 74 68 65 20 63 61 63 68 65 gainst the cache
b310: 20 64 61 74 61 62 61 73 65 0a 09 20 2a 2f 0a 09 database.. */..
b320: 69 66 20 28 61 72 67 63 20 3d 3d 20 32 20 26 26 if (argc == 2 &&
b330: 20 73 74 72 63 6d 70 28 61 72 67 76 5b 30 5d 2c strcmp(argv[0],
b340: 20 22 2d 2d 73 71 6c 69 74 65 33 22 29 20 3d 3d "--sqlite3") ==
b350: 20 30 29 20 7b 0a 09 09 72 65 74 75 72 6e 28 61 0) {...return(a
b360: 70 70 66 73 5f 73 71 6c 69 74 65 33 28 61 72 67 ppfs_sqlite3(arg
b370: 76 5b 31 5d 29 29 3b 0a 09 7d 0a 0a 09 2f 2a 0a v[1]));..}.../*.
b380: 09 20 2a 20 54 63 6c 20 6d 6f 64 65 2c 20 66 6f . * Tcl mode, fo
b390: 72 20 72 75 6e 6e 69 6e 67 20 72 61 77 20 54 63 r running raw Tc
b3a0: 6c 20 69 6e 20 74 68 65 20 73 61 6d 65 20 65 6e l in the same en
b3b0: 76 69 72 6f 6e 6d 65 6e 74 20 41 70 70 46 53 64 vironment AppFSd
b3c0: 20 77 6f 75 6c 64 0a 09 20 2a 20 72 75 6e 20 63 would.. * run c
b3d0: 6f 64 65 2e 0a 09 20 2a 2f 0a 09 69 66 20 28 61 ode... */..if (a
b3e0: 72 67 63 20 3d 3d 20 32 20 26 26 20 73 74 72 63 rgc == 2 && strc
b3f0: 6d 70 28 61 72 67 76 5b 30 5d 2c 20 22 2d 2d 74 mp(argv[0], "--t
b400: 63 6c 22 29 20 3d 3d 20 30 29 20 7b 0a 09 09 72 cl") == 0) {...r
b410: 65 74 75 72 6e 28 61 70 70 66 73 5f 74 63 6c 28 eturn(appfs_tcl(
b420: 61 72 67 76 5b 31 5d 29 29 3b 0a 09 7d 0a 0a 09 argv[1]));..}...
b430: 2f 2a 0a 09 20 2a 20 43 72 65 61 74 65 20 61 20 /*.. * Create a
b440: 54 63 6c 20 69 6e 74 65 72 70 72 65 74 65 72 20 Tcl interpreter
b450: 6a 75 73 74 20 74 6f 20 76 65 72 69 66 79 20 74 just to verify t
b460: 68 61 74 20 74 68 69 6e 67 73 20 61 72 65 20 69 hat things are i
b470: 6e 20 77 6f 72 6b 69 6e 67 20 0a 09 20 2a 20 6f n working .. * o
b480: 72 64 65 72 20 62 65 66 6f 72 65 20 77 65 20 62 rder before we b
b490: 65 63 6f 6d 65 20 61 20 64 61 65 6d 6f 6e 2e 0a ecome a daemon..
b4a0: 09 20 2a 2f 0a 09 74 65 73 74 5f 69 6e 74 65 72 . */..test_inter
b4b0: 70 20 3d 20 61 70 70 66 73 5f 63 72 65 61 74 65 p = appfs_create
b4c0: 5f 54 63 6c 49 6e 74 65 72 70 28 26 74 65 73 74 _TclInterp(&test
b4d0: 5f 69 6e 74 65 72 70 5f 65 72 72 6f 72 29 3b 0a _interp_error);.
b4e0: 09 69 66 20 28 74 65 73 74 5f 69 6e 74 65 72 70 .if (test_interp
b4f0: 20 3d 3d 20 4e 55 4c 4c 29 20 7b 0a 09 09 69 66 == NULL) {...if
b500: 20 28 74 65 73 74 5f 69 6e 74 65 72 70 5f 65 72 (test_interp_er
b510: 72 6f 72 20 3d 3d 20 4e 55 4c 4c 29 20 7b 0a 09 ror == NULL) {..
b520: 09 09 74 65 73 74 5f 69 6e 74 65 72 70 5f 65 72 ..test_interp_er
b530: 72 6f 72 20 3d 20 22 55 6e 6b 6e 6f 77 6e 20 65 ror = "Unknown e
b540: 72 72 6f 72 22 3b 0a 09 09 7d 0a 0a 09 09 66 70 rror";...}....fp
b550: 72 69 6e 74 66 28 73 74 64 65 72 72 2c 20 22 55 rintf(stderr, "U
b560: 6e 61 62 6c 65 20 74 6f 20 69 6e 69 74 69 61 6c nable to initial
b570: 69 7a 65 20 54 63 6c 20 69 6e 74 65 72 70 72 65 ize Tcl interpre
b580: 74 65 72 20 66 6f 72 20 41 70 70 46 53 64 3a 5c ter for AppFSd:\
b590: 6e 22 29 3b 0a 09 09 66 70 72 69 6e 74 66 28 73 n");...fprintf(s
b5a0: 74 64 65 72 72 2c 20 22 25 73 5c 6e 22 2c 20 74 tderr, "%s\n", t
b5b0: 65 73 74 5f 69 6e 74 65 72 70 5f 65 72 72 6f 72 est_interp_error
b5c0: 29 3b 0a 0a 09 09 72 65 74 75 72 6e 28 31 29 3b );....return(1);
b5d0: 0a 09 7d 0a 0a 09 54 63 6c 5f 44 65 6c 65 74 65 ..}...Tcl_Delete
b5e0: 49 6e 74 65 72 70 28 74 65 73 74 5f 69 6e 74 65 Interp(test_inte
b5f0: 72 70 29 3b 0a 0a 09 54 63 6c 5f 46 69 6e 61 6c rp);...Tcl_Final
b600: 69 7a 65 4e 6f 74 69 66 69 65 72 28 4e 55 4c 4c izeNotifier(NULL
b610: 29 3b 0a 0a 09 2f 2a 0a 09 20 2a 20 52 65 67 69 );.../*.. * Regi
b620: 73 74 65 72 20 61 20 73 69 67 6e 61 6c 20 68 61 ster a signal ha
b630: 6e 64 6c 65 72 20 66 6f 72 20 68 6f 74 2d 72 65 ndler for hot-re
b640: 73 74 61 72 74 20 72 65 71 75 65 73 74 73 0a 09 start requests..
b650: 20 2a 2f 0a 09 73 69 67 6e 61 6c 5f 72 65 74 20 */..signal_ret
b660: 3d 20 73 69 67 6e 61 6c 28 53 49 47 48 55 50 2c = signal(SIGHUP,
b670: 20 61 70 70 66 73 5f 73 69 67 6e 61 6c 5f 68 61 appfs_signal_ha
b680: 6e 64 6c 65 72 29 3b 0a 09 69 66 20 28 73 69 67 ndler);..if (sig
b690: 6e 61 6c 5f 72 65 74 20 3d 3d 20 53 49 47 5f 45 nal_ret == SIG_E
b6a0: 52 52 29 20 7b 0a 09 09 66 70 72 69 6e 74 66 28 RR) {...fprintf(
b6b0: 73 74 64 65 72 72 2c 20 22 55 6e 61 62 6c 65 20 stderr, "Unable
b6c0: 74 6f 20 69 6e 73 74 61 6c 6c 20 73 69 67 6e 61 to install signa
b6d0: 6c 20 68 61 6e 64 6c 65 72 20 66 6f 72 20 68 6f l handler for ho
b6e0: 74 2d 72 65 73 74 61 72 74 5c 6e 22 29 3b 0a 09 t-restart\n");..
b6f0: 09 66 70 72 69 6e 74 66 28 73 74 64 65 72 72 2c .fprintf(stderr,
b700: 20 22 48 6f 74 2d 72 65 73 74 61 72 74 20 77 69 "Hot-restart wi
b710: 6c 6c 20 6e 6f 74 20 62 65 20 61 76 61 69 6c 61 ll not be availa
b720: 62 6c 65 2e 5c 6e 22 29 3b 0a 09 7d 0a 0a 09 2f ble.\n");..}.../
b730: 2a 0a 09 20 2a 20 41 64 64 20 46 55 53 45 20 61 *.. * Add FUSE a
b740: 72 67 75 6d 65 6e 74 73 20 77 68 69 63 68 20 77 rguments which w
b750: 65 20 61 6c 77 61 79 73 20 73 75 70 70 6c 79 0a e always supply.
b760: 09 20 2a 2f 0a 09 66 75 73 65 5f 6f 70 74 5f 70 . */..fuse_opt_p
b770: 61 72 73 65 28 26 61 72 67 73 2c 20 4e 55 4c 4c arse(&args, NULL
b780: 2c 20 4e 55 4c 4c 2c 20 61 70 70 66 73 5f 66 75 , NULL, appfs_fu
b790: 73 65 5f 6f 70 74 5f 63 62 29 3b 0a 09 66 75 73 se_opt_cb);..fus
b7a0: 65 5f 6f 70 74 5f 61 64 64 5f 61 72 67 28 26 61 e_opt_add_arg(&a
b7b0: 72 67 73 2c 20 22 2d 6f 64 65 66 61 75 6c 74 5f rgs, "-odefault_
b7c0: 70 65 72 6d 69 73 73 69 6f 6e 73 2c 66 73 6e 61 permissions,fsna
b7d0: 6d 65 3d 61 70 70 66 73 2c 73 75 62 74 79 70 65 me=appfs,subtype
b7e0: 3d 61 70 70 66 73 64 2c 75 73 65 5f 69 6e 6f 2c =appfsd,use_ino,
b7f0: 6b 65 72 6e 65 6c 5f 63 61 63 68 65 2c 65 6e 74 kernel_cache,ent
b800: 72 79 5f 74 69 6d 65 6f 75 74 3d 30 2c 61 74 74 ry_timeout=0,att
b810: 72 5f 74 69 6d 65 6f 75 74 3d 30 2c 62 69 67 5f r_timeout=0,big_
b820: 77 72 69 74 65 73 2c 69 6e 74 72 2c 68 61 72 64 writes,intr,hard
b830: 5f 72 65 6d 6f 76 65 22 29 3b 0a 0a 09 69 66 20 _remove");...if
b840: 28 67 65 74 75 69 64 28 29 20 3d 3d 20 30 29 20 (getuid() == 0)
b850: 7b 0a 09 09 66 75 73 65 5f 6f 70 74 5f 70 61 72 {...fuse_opt_par
b860: 73 65 28 26 61 72 67 73 2c 20 4e 55 4c 4c 2c 20 se(&args, NULL,
b870: 4e 55 4c 4c 2c 20 4e 55 4c 4c 29 3b 0a 09 09 66 NULL, NULL);...f
b880: 75 73 65 5f 6f 70 74 5f 61 64 64 5f 61 72 67 28 use_opt_add_arg(
b890: 26 61 72 67 73 2c 20 22 2d 6f 61 6c 6c 6f 77 5f &args, "-oallow_
b8a0: 6f 74 68 65 72 22 29 3b 0a 09 7d 0a 0a 09 2f 2a other");..}.../*
b8b0: 0a 09 20 2a 20 45 6e 74 65 72 20 74 68 65 20 46 .. * Enter the F
b8c0: 55 53 45 20 6d 61 69 6e 20 6c 6f 6f 70 20 2d 2d USE main loop --
b8d0: 20 74 68 69 73 20 77 69 6c 6c 20 70 72 6f 63 65 this will proce
b8e0: 73 73 20 61 6e 79 20 61 72 67 75 6d 65 6e 74 73 ss any arguments
b8f0: 0a 09 20 2a 20 61 6e 64 20 73 74 61 72 74 20 73 .. * and start s
b900: 65 72 76 69 63 69 6e 67 20 72 65 71 75 65 73 74 ervicing request
b910: 73 2e 0a 09 20 2a 2f 0a 09 61 70 70 66 73 5f 66 s... */..appfs_f
b920: 75 73 65 5f 73 74 61 72 74 65 64 20 3d 20 31 3b use_started = 1;
b930: 0a 09 72 65 74 75 72 6e 28 66 75 73 65 5f 6d 61 ..return(fuse_ma
b940: 69 6e 28 61 72 67 73 2e 61 72 67 63 2c 20 61 72 in(args.argc, ar
b950: 67 73 2e 61 72 67 76 2c 20 26 61 70 70 66 73 5f gs.argv, &appfs_
b960: 6f 70 65 72 61 74 69 6f 6e 73 2c 20 4e 55 4c 4c operations, NULL
b970: 29 29 3b 0a 7d 0a 20 0a ));.}. .