0000: 2f 2a 0a 20 2a 20 43 6f 70 79 72 69 67 68 74 20 /*. * Copyright
0010: 28 63 29 20 32 30 31 34 20 20 52 6f 79 20 4b 65 (c) 2014 Roy Ke
0020: 65 6e 65 0a 20 2a 0a 20 2a 20 50 65 72 6d 69 73 ene. *. * Permis
0030: 73 69 6f 6e 20 69 73 20 68 65 72 65 62 79 20 67 sion is hereby g
0040: 72 61 6e 74 65 64 2c 20 66 72 65 65 20 6f 66 20 ranted, free of
0050: 63 68 61 72 67 65 2c 20 74 6f 20 61 6e 79 20 70 charge, to any p
0060: 65 72 73 6f 6e 20 6f 62 74 61 69 6e 69 6e 67 20 erson obtaining
0070: 61 20 63 6f 70 79 0a 20 2a 20 6f 66 20 74 68 69 a copy. * of thi
0080: 73 20 73 6f 66 74 77 61 72 65 20 61 6e 64 20 61 s software and a
0090: 73 73 6f 63 69 61 74 65 64 20 64 6f 63 75 6d 65 ssociated docume
00a0: 6e 74 61 74 69 6f 6e 20 66 69 6c 65 73 20 28 74 ntation files (t
00b0: 68 65 20 22 53 6f 66 74 77 61 72 65 22 29 2c 20 he "Software"),
00c0: 74 6f 20 64 65 61 6c 0a 20 2a 20 69 6e 20 74 68 to deal. * in th
00d0: 65 20 53 6f 66 74 77 61 72 65 20 77 69 74 68 6f e Software witho
00e0: 75 74 20 72 65 73 74 72 69 63 74 69 6f 6e 2c 20 ut restriction,
00f0: 69 6e 63 6c 75 64 69 6e 67 20 77 69 74 68 6f 75 including withou
0100: 74 20 6c 69 6d 69 74 61 74 69 6f 6e 20 74 68 65 t limitation the
0110: 20 72 69 67 68 74 73 0a 20 2a 20 74 6f 20 75 73 rights. * to us
0120: 65 2c 20 63 6f 70 79 2c 20 6d 6f 64 69 66 79 2c e, copy, modify,
0130: 20 6d 65 72 67 65 2c 20 70 75 62 6c 69 73 68 2c merge, publish,
0140: 20 64 69 73 74 72 69 62 75 74 65 2c 20 73 75 62 distribute, sub
0150: 6c 69 63 65 6e 73 65 2c 20 61 6e 64 2f 6f 72 20 license, and/or
0160: 73 65 6c 6c 0a 20 2a 20 63 6f 70 69 65 73 20 6f sell. * copies o
0170: 66 20 74 68 65 20 53 6f 66 74 77 61 72 65 2c 20 f the Software,
0180: 61 6e 64 20 74 6f 20 70 65 72 6d 69 74 20 70 65 and to permit pe
0190: 72 73 6f 6e 73 20 74 6f 20 77 68 6f 6d 20 74 68 rsons to whom th
01a0: 65 20 53 6f 66 74 77 61 72 65 20 69 73 0a 20 2a e Software is. *
01b0: 20 66 75 72 6e 69 73 68 65 64 20 74 6f 20 64 6f furnished to do
01c0: 20 73 6f 2c 20 73 75 62 6a 65 63 74 20 74 6f 20 so, subject to
01d0: 74 68 65 20 66 6f 6c 6c 6f 77 69 6e 67 20 63 6f the following co
01e0: 6e 64 69 74 69 6f 6e 73 3a 0a 20 2a 0a 20 2a 20 nditions:. *. *
01f0: 54 68 65 20 61 62 6f 76 65 20 63 6f 70 79 72 69 The above copyri
0200: 67 68 74 20 6e 6f 74 69 63 65 20 61 6e 64 20 74 ght notice and t
0210: 68 69 73 20 70 65 72 6d 69 73 73 69 6f 6e 20 6e his permission n
0220: 6f 74 69 63 65 20 73 68 61 6c 6c 20 62 65 20 69 otice shall be i
0230: 6e 63 6c 75 64 65 64 20 69 6e 0a 20 2a 20 61 6c ncluded in. * al
0240: 6c 20 63 6f 70 69 65 73 20 6f 72 20 73 75 62 73 l copies or subs
0250: 74 61 6e 74 69 61 6c 20 70 6f 72 74 69 6f 6e 73 tantial portions
0260: 20 6f 66 20 74 68 65 20 53 6f 66 74 77 61 72 65 of the Software
0270: 2e 0a 20 2a 0a 20 2a 20 54 48 45 20 53 4f 46 54 .. *. * THE SOFT
0280: 57 41 52 45 20 49 53 20 50 52 4f 56 49 44 45 44 WARE IS PROVIDED
0290: 20 22 41 53 20 49 53 22 2c 20 57 49 54 48 4f 55 "AS IS", WITHOU
02a0: 54 20 57 41 52 52 41 4e 54 59 20 4f 46 20 41 4e T WARRANTY OF AN
02b0: 59 20 4b 49 4e 44 2c 20 45 58 50 52 45 53 53 20 Y KIND, EXPRESS
02c0: 4f 52 0a 20 2a 20 49 4d 50 4c 49 45 44 2c 20 49 OR. * IMPLIED, I
02d0: 4e 43 4c 55 44 49 4e 47 20 42 55 54 20 4e 4f 54 NCLUDING BUT NOT
02e0: 20 4c 49 4d 49 54 45 44 20 54 4f 20 54 48 45 20 LIMITED TO THE
02f0: 57 41 52 52 41 4e 54 49 45 53 20 4f 46 20 4d 45 WARRANTIES OF ME
0300: 52 43 48 41 4e 54 41 42 49 4c 49 54 59 2c 0a 20 RCHANTABILITY,.
0310: 2a 20 46 49 54 4e 45 53 53 20 46 4f 52 20 41 20 * FITNESS FOR A
0320: 50 41 52 54 49 43 55 4c 41 52 20 50 55 52 50 4f PARTICULAR PURPO
0330: 53 45 20 41 4e 44 20 4e 4f 4e 49 4e 46 52 49 4e SE AND NONINFRIN
0340: 47 45 4d 45 4e 54 2e 20 49 4e 20 4e 4f 20 45 56 GEMENT. IN NO EV
0350: 45 4e 54 20 53 48 41 4c 4c 20 54 48 45 0a 20 2a ENT SHALL THE. *
0360: 20 41 55 54 48 4f 52 53 20 4f 52 20 43 4f 50 59 AUTHORS OR COPY
0370: 52 49 47 48 54 20 48 4f 4c 44 45 52 53 20 42 45 RIGHT HOLDERS BE
0380: 20 4c 49 41 42 4c 45 20 46 4f 52 20 41 4e 59 20 LIABLE FOR ANY
0390: 43 4c 41 49 4d 2c 20 44 41 4d 41 47 45 53 20 4f CLAIM, DAMAGES O
03a0: 52 20 4f 54 48 45 52 0a 20 2a 20 4c 49 41 42 49 R OTHER. * LIABI
03b0: 4c 49 54 59 2c 20 57 48 45 54 48 45 52 20 49 4e LITY, WHETHER IN
03c0: 20 41 4e 20 41 43 54 49 4f 4e 20 4f 46 20 43 4f AN ACTION OF CO
03d0: 4e 54 52 41 43 54 2c 20 54 4f 52 54 20 4f 52 20 NTRACT, TORT OR
03e0: 4f 54 48 45 52 57 49 53 45 2c 20 41 52 49 53 49 OTHERWISE, ARISI
03f0: 4e 47 20 46 52 4f 4d 2c 0a 20 2a 20 4f 55 54 20 NG FROM,. * OUT
0400: 4f 46 20 4f 52 20 49 4e 20 43 4f 4e 4e 45 43 54 OF OR IN CONNECT
0410: 49 4f 4e 20 57 49 54 48 20 54 48 45 20 53 4f 46 ION WITH THE SOF
0420: 54 57 41 52 45 20 4f 52 20 54 48 45 20 55 53 45 TWARE OR THE USE
0430: 20 4f 52 20 4f 54 48 45 52 20 44 45 41 4c 49 4e OR OTHER DEALIN
0440: 47 53 20 49 4e 0a 20 2a 20 54 48 45 20 53 4f 46 GS IN. * THE SOF
0450: 54 57 41 52 45 2e 0a 20 2a 2f 0a 23 64 65 66 69 TWARE.. */.#defi
0460: 6e 65 20 46 55 53 45 5f 55 53 45 5f 56 45 52 53 ne FUSE_USE_VERS
0470: 49 4f 4e 20 32 36 0a 0a 23 69 6e 63 6c 75 64 65 ION 26..#include
0480: 20 3c 73 79 73 2f 66 73 75 69 64 2e 68 3e 0a 23 <sys/fsuid.h>.#
0490: 69 6e 63 6c 75 64 65 20 3c 73 79 73 2f 74 79 70 include <sys/typ
04a0: 65 73 2e 68 3e 0a 23 69 6e 63 6c 75 64 65 20 3c es.h>.#include <
04b0: 70 74 68 72 65 61 64 2e 68 3e 0a 23 69 6e 63 6c pthread.h>.#incl
04c0: 75 64 65 20 3c 73 69 67 6e 61 6c 2e 68 3e 0a 23 ude <signal.h>.#
04d0: 69 6e 63 6c 75 64 65 20 3c 6c 69 6d 69 74 73 2e include <limits.
04e0: 68 3e 0a 23 69 6e 63 6c 75 64 65 20 3c 73 74 72 h>.#include <str
04f0: 69 6e 67 2e 68 3e 0a 23 69 6e 63 6c 75 64 65 20 ing.h>.#include
0500: 3c 73 74 64 61 72 67 2e 68 3e 0a 23 69 6e 63 6c <stdarg.h>.#incl
0510: 75 64 65 20 3c 73 74 64 6c 69 62 2e 68 3e 0a 23 ude <stdlib.h>.#
0520: 69 6e 63 6c 75 64 65 20 3c 75 6e 69 73 74 64 2e include <unistd.
0530: 68 3e 0a 23 69 6e 63 6c 75 64 65 20 3c 65 72 72 h>.#include <err
0540: 6e 6f 2e 68 3e 0a 23 69 6e 63 6c 75 64 65 20 3c no.h>.#include <
0550: 66 63 6e 74 6c 2e 68 3e 0a 23 69 6e 63 6c 75 64 fcntl.h>.#includ
0560: 65 20 3c 73 74 64 69 6f 2e 68 3e 0a 23 69 6e 63 e <stdio.h>.#inc
0570: 6c 75 64 65 20 3c 66 75 73 65 2e 68 3e 0a 23 69 lude <fuse.h>.#i
0580: 6e 63 6c 75 64 65 20 3c 70 77 64 2e 68 3e 0a 23 nclude <pwd.h>.#
0590: 69 6e 63 6c 75 64 65 20 3c 74 63 6c 2e 68 3e 0a include <tcl.h>.
05a0: 0a 2f 2a 0a 20 2a 20 44 65 66 61 75 6c 74 20 63 ./*. * Default c
05b0: 61 63 68 65 20 64 69 72 65 63 74 6f 72 79 0a 20 ache directory.
05c0: 2a 2f 0a 23 69 66 6e 64 65 66 20 41 50 50 46 53 */.#ifndef APPFS
05d0: 5f 43 41 43 48 45 44 49 52 0a 23 64 65 66 69 6e _CACHEDIR.#defin
05e0: 65 20 41 50 50 46 53 5f 43 41 43 48 45 44 49 52 e APPFS_CACHEDIR
05f0: 20 22 2f 76 61 72 2f 63 61 63 68 65 2f 61 70 70 "/var/cache/app
0600: 66 73 22 0a 23 65 6e 64 69 66 0a 0a 2f 2a 20 44 fs".#endif../* D
0610: 65 62 75 67 67 69 6e 67 20 6d 61 63 72 6f 73 20 ebugging macros
0620: 2a 2f 0a 23 69 66 64 65 66 20 44 45 42 55 47 0a */.#ifdef DEBUG.
0630: 69 6e 74 20 61 70 70 66 73 5f 64 65 62 75 67 5f int appfs_debug_
0640: 66 64 20 3d 20 53 54 44 45 52 52 5f 46 49 4c 45 fd = STDERR_FILE
0650: 4e 4f 3b 0a 23 64 65 66 69 6e 65 20 41 50 50 46 NO;.#define APPF
0660: 53 5f 44 45 42 55 47 28 78 2e 2e 2e 29 20 7b 20 S_DEBUG(x...) {
0670: 5c 0a 09 63 68 61 72 20 62 75 66 5b 38 31 39 32 \..char buf[8192
0680: 5d 3b 20 5c 0a 09 69 6e 74 20 62 75 66 6f 66 66 ]; \..int bufoff
0690: 20 3d 20 30 3b 20 5c 0a 09 69 66 20 28 61 70 70 = 0; \..if (app
06a0: 66 73 5f 64 65 62 75 67 5f 66 64 20 3d 3d 20 2d fs_debug_fd == -
06b0: 31 29 20 7b 20 5c 0a 09 09 61 70 70 66 73 5f 64 1) { \...appfs_d
06c0: 65 62 75 67 5f 66 64 20 3d 20 6f 70 65 6e 28 22 ebug_fd = open("
06d0: 2f 74 6d 70 2f 61 70 70 66 73 64 2e 6c 6f 67 22 /tmp/appfsd.log"
06e0: 2c 20 4f 5f 57 52 4f 4e 4c 59 20 7c 20 4f 5f 41 , O_WRONLY | O_A
06f0: 50 50 45 4e 44 20 7c 20 4f 5f 43 52 45 41 54 2c PPEND | O_CREAT,
0700: 20 30 36 30 30 29 3b 20 5c 0a 09 7d 3b 20 5c 0a 0600); \..}; \.
0710: 09 62 75 66 6f 66 66 20 3d 20 73 6e 70 72 69 6e .bufoff = snprin
0720: 74 66 28 62 75 66 2c 20 73 69 7a 65 6f 66 28 62 tf(buf, sizeof(b
0730: 75 66 29 2c 20 22 5b 64 65 62 75 67 5d 20 5b 74 uf), "[debug] [t
0740: 3d 25 6c 6c 78 5d 20 25 73 3a 25 69 3a 25 73 3a =%llx] %s:%i:%s:
0750: 20 22 2c 20 28 75 6e 73 69 67 6e 65 64 20 6c 6f ", (unsigned lo
0760: 6e 67 20 6c 6f 6e 67 29 20 70 74 68 72 65 61 64 ng long) pthread
0770: 5f 73 65 6c 66 28 29 2c 20 5f 5f 46 49 4c 45 5f _self(), __FILE_
0780: 5f 2c 20 5f 5f 4c 49 4e 45 5f 5f 2c 20 5f 5f 66 _, __LINE__, __f
0790: 75 6e 63 5f 5f 29 3b 20 5c 0a 09 69 66 20 28 62 unc__); \..if (b
07a0: 75 66 6f 66 66 20 3c 20 73 69 7a 65 6f 66 28 62 ufoff < sizeof(b
07b0: 75 66 29 29 20 7b 20 5c 0a 09 09 62 75 66 6f 66 uf)) { \...bufof
07c0: 66 20 2b 3d 20 73 6e 70 72 69 6e 74 66 28 62 75 f += snprintf(bu
07d0: 66 20 2b 20 62 75 66 6f 66 66 2c 20 73 69 7a 65 f + bufoff, size
07e0: 6f 66 28 62 75 66 29 20 2d 20 62 75 66 6f 66 66 of(buf) - bufoff
07f0: 2c 20 78 29 3b 20 5c 0a 09 7d 3b 20 5c 0a 09 69 , x); \..}; \..i
0800: 66 20 28 62 75 66 6f 66 66 20 3c 20 73 69 7a 65 f (bufoff < size
0810: 6f 66 28 62 75 66 29 29 20 7b 20 5c 0a 09 09 62 of(buf)) { \...b
0820: 75 66 6f 66 66 20 2b 3d 20 73 6e 70 72 69 6e 74 ufoff += snprint
0830: 66 28 62 75 66 20 2b 20 62 75 66 6f 66 66 2c 20 f(buf + bufoff,
0840: 73 69 7a 65 6f 66 28 62 75 66 29 20 2d 20 62 75 sizeof(buf) - bu
0850: 66 6f 66 66 2c 20 22 5c 6e 22 29 3b 5c 0a 09 7d foff, "\n");\..}
0860: 20 5c 0a 09 69 66 20 28 62 75 66 6f 66 66 20 3e \..if (bufoff >
0870: 20 73 69 7a 65 6f 66 28 62 75 66 29 29 20 7b 20 sizeof(buf)) {
0880: 5c 0a 09 09 62 75 66 6f 66 66 20 3d 20 73 69 7a \...bufoff = siz
0890: 65 6f 66 28 62 75 66 29 3b 20 5c 0a 09 7d 3b 20 eof(buf); \..};
08a0: 5c 0a 09 77 72 69 74 65 28 61 70 70 66 73 5f 64 \..write(appfs_d
08b0: 65 62 75 67 5f 66 64 2c 20 62 75 66 2c 20 62 75 ebug_fd, buf, bu
08c0: 66 6f 66 66 29 3b 20 5c 0a 7d 0a 23 65 6c 73 65 foff); \.}.#else
08d0: 0a 23 64 65 66 69 6e 65 20 41 50 50 46 53 5f 44 .#define APPFS_D
08e0: 45 42 55 47 28 78 2e 2e 2e 29 20 2f 2a 2a 2f 0a EBUG(x...) /**/.
08f0: 23 65 6e 64 69 66 0a 0a 2f 2a 0a 20 2a 20 53 48 #endif../*. * SH
0900: 41 31 20 54 63 6c 20 50 61 63 6b 61 67 65 20 69 A1 Tcl Package i
0910: 6e 69 74 69 61 6c 69 7a 65 72 2c 20 66 72 6f 6d nitializer, from
0920: 20 73 68 61 31 2e 6f 0a 20 2a 2f 0a 69 6e 74 20 sha1.o. */.int
0930: 53 68 61 31 5f 49 6e 69 74 28 54 63 6c 5f 49 6e Sha1_Init(Tcl_In
0940: 74 65 72 70 20 2a 69 6e 74 65 72 70 29 3b 0a 0a terp *interp);..
0950: 2f 2a 0a 20 2a 20 54 68 72 65 61 64 20 53 70 65 /*. * Thread Spe
0960: 63 69 66 69 63 20 44 61 74 61 20 28 54 53 44 29 cific Data (TSD)
0970: 20 66 6f 72 20 54 63 6c 20 49 6e 74 65 72 70 72 for Tcl Interpr
0980: 65 74 65 72 20 66 6f 72 20 74 68 65 20 63 75 72 eter for the cur
0990: 72 65 6e 74 20 74 68 72 65 61 64 0a 20 2a 2f 0a rent thread. */.
09a0: 73 74 61 74 69 63 20 70 74 68 72 65 61 64 5f 6b static pthread_k
09b0: 65 79 5f 74 20 69 6e 74 65 72 70 4b 65 79 3b 0a ey_t interpKey;.
09c0: 0a 2f 2a 0a 20 2a 20 47 6c 6f 62 61 6c 20 76 61 ./*. * Global va
09d0: 72 69 61 62 6c 65 73 2c 20 6e 65 65 64 65 64 20 riables, needed
09e0: 66 6f 72 20 61 6c 6c 20 74 68 72 65 61 64 73 20 for all threads
09f0: 62 75 74 20 6f 6e 6c 79 20 69 6e 69 74 69 61 6c but only initial
0a00: 69 7a 65 64 20 62 65 66 6f 72 65 20 61 6e 79 0a ized before any.
0a10: 20 2a 20 46 55 53 45 20 74 68 72 65 61 64 73 20 * FUSE threads
0a20: 61 72 65 20 63 72 65 61 74 65 64 0a 20 2a 2f 0a are created. */.
0a30: 63 6f 6e 73 74 20 63 68 61 72 20 2a 61 70 70 66 const char *appf
0a40: 73 5f 63 61 63 68 65 64 69 72 3b 0a 74 69 6d 65 s_cachedir;.time
0a50: 5f 74 20 61 70 70 66 73 5f 62 6f 6f 74 74 69 6d _t appfs_boottim
0a60: 65 3b 0a 69 6e 74 20 61 70 70 66 73 5f 66 75 73 e;.int appfs_fus
0a70: 65 5f 73 74 61 72 74 65 64 20 3d 20 30 3b 0a 69 e_started = 0;.i
0a80: 6e 74 20 61 70 70 66 73 5f 74 68 72 65 61 64 65 nt appfs_threade
0a90: 64 5f 74 63 6c 3b 0a 0a 2f 2a 0a 20 2a 20 47 6c d_tcl;../*. * Gl
0aa0: 6f 62 61 6c 20 76 61 72 69 61 62 6c 65 73 20 66 obal variables f
0ab0: 6f 72 20 41 70 70 46 53 20 63 61 63 68 69 6e 67 or AppFS caching
0ac0: 0a 20 2a 2f 0a 70 74 68 72 65 61 64 5f 6d 75 74 . */.pthread_mut
0ad0: 65 78 5f 74 20 61 70 70 66 73 5f 70 61 74 68 5f ex_t appfs_path_
0ae0: 69 6e 66 6f 5f 63 61 63 68 65 5f 6d 75 74 65 78 info_cache_mutex
0af0: 20 3d 20 50 54 48 52 45 41 44 5f 4d 55 54 45 58 = PTHREAD_MUTEX
0b00: 5f 49 4e 49 54 49 41 4c 49 5a 45 52 3b 0a 69 6e _INITIALIZER;.in
0b10: 74 20 61 70 70 66 73 5f 70 61 74 68 5f 69 6e 66 t appfs_path_inf
0b20: 6f 5f 63 61 63 68 65 5f 73 69 7a 65 20 3d 20 38 o_cache_size = 8
0b30: 32 30 39 3b 0a 73 74 72 75 63 74 20 61 70 70 66 209;.struct appf
0b40: 73 5f 70 61 74 68 69 6e 66 6f 20 2a 61 70 70 66 s_pathinfo *appf
0b50: 73 5f 70 61 74 68 5f 69 6e 66 6f 5f 63 61 63 68 s_path_info_cach
0b60: 65 20 3d 20 4e 55 4c 4c 3b 0a 0a 23 69 66 6e 64 e = NULL;..#ifnd
0b70: 65 66 20 54 43 4c 5f 54 48 52 45 41 44 53 0a 2f ef TCL_THREADS./
0b80: 2a 0a 20 2a 20 48 61 6e 64 6c 65 20 75 6e 74 68 *. * Handle unth
0b90: 72 65 61 64 65 64 20 54 63 6c 0a 20 2a 2f 0a 70 readed Tcl. */.p
0ba0: 74 68 72 65 61 64 5f 6d 75 74 65 78 5f 74 20 61 thread_mutex_t a
0bb0: 70 70 66 73 5f 74 63 6c 5f 62 69 67 5f 67 6c 6f ppfs_tcl_big_glo
0bc0: 62 61 6c 5f 6c 6f 63 6b 20 3d 20 50 54 48 52 45 bal_lock = PTHRE
0bd0: 41 44 5f 4d 55 54 45 58 5f 49 4e 49 54 49 41 4c AD_MUTEX_INITIAL
0be0: 49 5a 45 52 3b 0a 23 64 65 66 69 6e 65 20 61 70 IZER;.#define ap
0bf0: 70 66 73 5f 63 61 6c 6c 5f 6c 69 62 74 63 6c 5f pfs_call_libtcl_
0c00: 65 6e 74 65 72 20 70 74 68 72 65 61 64 5f 6d 75 enter pthread_mu
0c10: 74 65 78 5f 6c 6f 63 6b 28 26 61 70 70 66 73 5f tex_lock(&appfs_
0c20: 74 63 6c 5f 62 69 67 5f 67 6c 6f 62 61 6c 5f 6c tcl_big_global_l
0c30: 6f 63 6b 29 3b 0a 23 64 65 66 69 6e 65 20 61 70 ock);.#define ap
0c40: 70 66 73 5f 63 61 6c 6c 5f 6c 69 62 74 63 6c 5f pfs_call_libtcl_
0c50: 65 78 69 74 20 70 74 68 72 65 61 64 5f 6d 75 74 exit pthread_mut
0c60: 65 78 5f 75 6e 6c 6f 63 6b 28 26 61 70 70 66 73 ex_unlock(&appfs
0c70: 5f 74 63 6c 5f 62 69 67 5f 67 6c 6f 62 61 6c 5f _tcl_big_global_
0c80: 6c 6f 63 6b 29 3b 0a 23 65 6c 73 65 0a 23 64 65 lock);.#else.#de
0c90: 66 69 6e 65 20 61 70 70 66 73 5f 63 61 6c 6c 5f fine appfs_call_
0ca0: 6c 69 62 74 63 6c 5f 65 6e 74 65 72 20 2f 2a 2a libtcl_enter /**
0cb0: 2f 0a 23 64 65 66 69 6e 65 20 61 70 70 66 73 5f /.#define appfs_
0cc0: 63 61 6c 6c 5f 6c 69 62 74 63 6c 5f 65 78 69 74 call_libtcl_exit
0cd0: 20 2f 2a 2a 2f 0a 23 65 6e 64 69 66 0a 23 64 65 /**/.#endif.#de
0ce0: 66 69 6e 65 20 61 70 70 66 73 5f 63 61 6c 6c 5f fine appfs_call_
0cf0: 6c 69 62 74 63 6c 28 78 2e 2e 2e 29 20 61 70 70 libtcl(x...) app
0d00: 66 73 5f 63 61 6c 6c 5f 6c 69 62 74 63 6c 5f 65 fs_call_libtcl_e
0d10: 6e 74 65 72 20 78 20 61 70 70 66 73 5f 63 61 6c nter x appfs_cal
0d20: 6c 5f 6c 69 62 74 63 6c 5f 65 78 69 74 0a 0a 2f l_libtcl_exit../
0d30: 2a 0a 20 2a 20 47 6c 6f 62 61 6c 20 76 61 72 69 *. * Global vari
0d40: 61 62 6c 65 73 20 66 6f 72 20 41 70 70 46 53 20 ables for AppFS
0d50: 54 63 6c 20 49 6e 74 65 72 70 72 65 74 65 72 20 Tcl Interpreter
0d60: 72 65 73 74 61 72 74 69 6e 67 0a 20 2a 2f 0a 69 restarting. */.i
0d70: 6e 74 20 69 6e 74 65 72 70 5f 72 65 73 65 74 5f nt interp_reset_
0d80: 6b 65 79 20 3d 20 30 3b 0a 0a 2f 2a 0a 20 2a 20 key = 0;../*. *
0d90: 41 70 70 46 53 20 50 61 74 68 20 54 79 70 65 3a AppFS Path Type:
0da0: 20 20 44 65 73 63 72 69 62 65 73 20 74 68 65 20 Describes the
0db0: 74 79 70 65 20 6f 66 20 70 61 74 68 20 61 20 67 type of path a g
0dc0: 69 76 65 6e 20 66 69 6c 65 20 69 73 0a 20 2a 2f iven file is. */
0dd0: 0a 74 79 70 65 64 65 66 20 65 6e 75 6d 20 7b 0a .typedef enum {.
0de0: 09 41 50 50 46 53 5f 50 41 54 48 54 59 50 45 5f .APPFS_PATHTYPE_
0df0: 49 4e 56 41 4c 49 44 2c 0a 09 41 50 50 46 53 5f INVALID,..APPFS_
0e00: 50 41 54 48 54 59 50 45 5f 44 4f 45 53 5f 4e 4f PATHTYPE_DOES_NO
0e10: 54 5f 45 58 49 53 54 2c 0a 09 41 50 50 46 53 5f T_EXIST,..APPFS_
0e20: 50 41 54 48 54 59 50 45 5f 46 49 4c 45 2c 0a 09 PATHTYPE_FILE,..
0e30: 41 50 50 46 53 5f 50 41 54 48 54 59 50 45 5f 44 APPFS_PATHTYPE_D
0e40: 49 52 45 43 54 4f 52 59 2c 0a 09 41 50 50 46 53 IRECTORY,..APPFS
0e50: 5f 50 41 54 48 54 59 50 45 5f 53 59 4d 4c 49 4e _PATHTYPE_SYMLIN
0e60: 4b 2c 0a 09 41 50 50 46 53 5f 50 41 54 48 54 59 K,..APPFS_PATHTY
0e70: 50 45 5f 53 4f 43 4b 45 54 2c 0a 09 41 50 50 46 PE_SOCKET,..APPF
0e80: 53 5f 50 41 54 48 54 59 50 45 5f 46 49 46 4f 2c S_PATHTYPE_FIFO,
0e90: 0a 7d 20 61 70 70 66 73 5f 70 61 74 68 74 79 70 .} appfs_pathtyp
0ea0: 65 5f 74 3b 0a 0a 2f 2a 0a 20 2a 20 41 70 70 46 e_t;../*. * AppF
0eb0: 53 20 50 61 74 68 20 49 6e 66 6f 72 6d 61 74 69 S Path Informati
0ec0: 6f 6e 3a 0a 20 2a 20 20 20 20 20 20 20 20 20 43 on:. * C
0ed0: 6f 6d 70 6c 65 74 65 6c 79 20 64 65 73 63 72 69 ompletely descri
0ee0: 62 65 73 20 61 20 73 70 65 63 69 66 69 63 20 70 bes a specific p
0ef0: 61 74 68 2c 20 68 6f 77 20 69 74 20 73 68 6f 75 ath, how it shou
0f00: 6c 64 20 62 65 20 72 65 74 75 72 6e 65 64 20 74 ld be returned t
0f10: 6f 0a 20 2a 20 20 20 20 20 20 20 20 20 74 6f 20 o. * to
0f20: 74 68 65 20 6b 65 72 6e 65 6c 0a 20 2a 2f 0a 73 the kernel. */.s
0f30: 74 72 75 63 74 20 61 70 70 66 73 5f 70 61 74 68 truct appfs_path
0f40: 69 6e 66 6f 20 7b 0a 09 61 70 70 66 73 5f 70 61 info {..appfs_pa
0f50: 74 68 74 79 70 65 5f 74 20 74 79 70 65 3b 0a 09 thtype_t type;..
0f60: 74 69 6d 65 5f 74 20 74 69 6d 65 3b 0a 09 63 68 time_t time;..ch
0f70: 61 72 20 68 6f 73 74 6e 61 6d 65 5b 32 35 36 5d ar hostname[256]
0f80: 3b 0a 09 69 6e 74 20 70 61 63 6b 61 67 65 64 3b ;..int packaged;
0f90: 0a 09 75 6e 73 69 67 6e 65 64 20 6c 6f 6e 67 20 ..unsigned long
0fa0: 6c 6f 6e 67 20 69 6e 6f 64 65 3b 0a 09 75 6e 69 long inode;..uni
0fb0: 6f 6e 20 7b 0a 09 09 73 74 72 75 63 74 20 7b 0a on {...struct {.
0fc0: 09 09 09 69 6e 74 20 63 68 69 6c 64 63 6f 75 6e ...int childcoun
0fd0: 74 3b 0a 09 09 7d 20 64 69 72 3b 0a 09 09 73 74 t;...} dir;...st
0fe0: 72 75 63 74 20 7b 0a 09 09 09 69 6e 74 20 65 78 ruct {....int ex
0ff0: 65 63 75 74 61 62 6c 65 3b 0a 09 09 09 69 6e 74 ecutable;....int
1000: 20 73 75 69 64 52 6f 6f 74 3b 0a 09 09 09 69 6e suidRoot;....in
1010: 74 20 77 6f 72 6c 64 61 63 63 65 73 73 69 62 6c t worldaccessibl
1020: 65 3b 0a 09 09 09 6f 66 66 5f 74 20 73 69 7a 65 e;....off_t size
1030: 3b 0a 09 09 7d 20 66 69 6c 65 3b 0a 09 09 73 74 ;...} file;...st
1040: 72 75 63 74 20 7b 0a 09 09 09 6f 66 66 5f 74 20 ruct {....off_t
1050: 73 69 7a 65 3b 0a 09 09 09 63 68 61 72 20 73 6f size;....char so
1060: 75 72 63 65 5b 32 35 36 5d 3b 0a 09 09 7d 20 73 urce[256];...} s
1070: 79 6d 6c 69 6e 6b 3b 0a 09 7d 20 74 79 70 65 69 ymlink;..} typei
1080: 6e 66 6f 3b 0a 0a 09 2f 2a 20 41 74 74 72 69 62 nfo;.../* Attrib
1090: 75 74 65 73 20 75 73 65 64 20 6f 6e 6c 79 20 66 utes used only f
10a0: 6f 72 20 63 61 63 68 69 6e 67 20 65 6e 74 72 69 or caching entri
10b0: 65 73 20 2a 2f 0a 09 63 68 61 72 20 2a 5f 63 61 es */..char *_ca
10c0: 63 68 65 5f 70 61 74 68 3b 0a 09 75 69 64 5f 74 che_path;..uid_t
10d0: 20 5f 63 61 63 68 65 5f 75 69 64 3b 0a 7d 3b 0a _cache_uid;.};.
10e0: 0a 2f 2a 0a 20 2a 20 43 72 65 61 74 65 20 61 20 ./*. * Create a
10f0: 6e 65 77 20 54 63 6c 20 69 6e 74 65 72 70 72 65 new Tcl interpre
1100: 74 65 72 20 61 6e 64 20 63 6f 6d 70 6c 65 74 65 ter and complete
1110: 6c 79 20 69 6e 69 74 69 61 6c 69 7a 65 20 69 74 ly initialize it
1120: 0a 20 2a 2f 0a 73 74 61 74 69 63 20 54 63 6c 5f . */.static Tcl_
1130: 49 6e 74 65 72 70 20 2a 61 70 70 66 73 5f 63 72 Interp *appfs_cr
1140: 65 61 74 65 5f 54 63 6c 49 6e 74 65 72 70 28 63 eate_TclInterp(c
1150: 68 61 72 20 2a 2a 65 72 72 6f 72 5f 73 74 72 69 har **error_stri
1160: 6e 67 29 20 7b 0a 09 54 63 6c 5f 49 6e 74 65 72 ng) {..Tcl_Inter
1170: 70 20 2a 69 6e 74 65 72 70 3b 0a 09 69 6e 74 20 p *interp;..int
1180: 74 63 6c 5f 72 65 74 3b 0a 09 63 6f 6e 73 74 20 tcl_ret;..const
1190: 63 68 61 72 20 2a 74 63 6c 5f 73 65 74 76 61 72 char *tcl_setvar
11a0: 5f 72 65 74 3b 0a 0a 09 41 50 50 46 53 5f 44 45 _ret;...APPFS_DE
11b0: 42 55 47 28 22 43 72 65 61 74 69 6e 67 20 6e 65 BUG("Creating ne
11c0: 77 20 54 63 6c 20 69 6e 74 65 72 70 72 65 74 65 w Tcl interprete
11d0: 72 20 66 6f 72 20 54 49 44 20 3d 20 30 78 25 6c r for TID = 0x%l
11e0: 6c 78 22 2c 20 28 75 6e 73 69 67 6e 65 64 20 6c lx", (unsigned l
11f0: 6f 6e 67 20 6c 6f 6e 67 29 20 70 74 68 72 65 61 ong long) pthrea
1200: 64 5f 73 65 6c 66 28 29 29 3b 0a 0a 09 61 70 70 d_self());...app
1210: 66 73 5f 63 61 6c 6c 5f 6c 69 62 74 63 6c 28 0a fs_call_libtcl(.
1220: 09 09 69 6e 74 65 72 70 20 3d 20 54 63 6c 5f 43 ..interp = Tcl_C
1230: 72 65 61 74 65 49 6e 74 65 72 70 28 29 3b 0a 09 reateInterp();..
1240: 29 0a 09 69 66 20 28 69 6e 74 65 72 70 20 3d 3d )..if (interp ==
1250: 20 4e 55 4c 4c 29 20 7b 0a 09 09 66 70 72 69 6e NULL) {...fprin
1260: 74 66 28 73 74 64 65 72 72 2c 20 22 55 6e 61 62 tf(stderr, "Unab
1270: 6c 65 20 74 6f 20 63 72 65 61 74 65 20 54 63 6c le to create Tcl
1280: 20 49 6e 74 65 72 70 72 65 74 65 72 2e 20 20 41 Interpreter. A
1290: 62 6f 72 74 69 6e 67 2e 5c 6e 22 29 3b 0a 0a 09 borting.\n");...
12a0: 09 69 66 20 28 65 72 72 6f 72 5f 73 74 72 69 6e .if (error_strin
12b0: 67 29 20 7b 0a 09 09 09 2a 65 72 72 6f 72 5f 73 g) {....*error_s
12c0: 74 72 69 6e 67 20 3d 20 73 74 72 64 75 70 28 22 tring = strdup("
12d0: 55 6e 61 62 6c 65 20 74 6f 20 63 72 65 61 74 65 Unable to create
12e0: 20 54 63 6c 20 69 6e 74 65 72 70 72 65 74 65 72 Tcl interpreter
12f0: 2e 22 29 3b 0a 09 09 7d 0a 0a 09 09 72 65 74 75 .");...}....retu
1300: 72 6e 28 4e 55 4c 4c 29 3b 0a 09 7d 0a 0a 09 61 rn(NULL);..}...a
1310: 70 70 66 73 5f 63 61 6c 6c 5f 6c 69 62 74 63 6c ppfs_call_libtcl
1320: 28 54 63 6c 5f 50 72 65 73 65 72 76 65 28 69 6e (Tcl_Preserve(in
1330: 74 65 72 70 29 3b 29 0a 0a 09 61 70 70 66 73 5f terp);)...appfs_
1340: 63 61 6c 6c 5f 6c 69 62 74 63 6c 28 0a 09 09 74 call_libtcl(...t
1350: 63 6c 5f 72 65 74 20 3d 20 54 63 6c 5f 49 6e 69 cl_ret = Tcl_Ini
1360: 74 28 69 6e 74 65 72 70 29 3b 0a 09 29 0a 09 69 t(interp);..)..i
1370: 66 20 28 74 63 6c 5f 72 65 74 20 21 3d 20 54 43 f (tcl_ret != TC
1380: 4c 5f 4f 4b 29 20 7b 0a 09 09 66 70 72 69 6e 74 L_OK) {...fprint
1390: 66 28 73 74 64 65 72 72 2c 20 22 55 6e 61 62 6c f(stderr, "Unabl
13a0: 65 20 74 6f 20 69 6e 69 74 69 61 6c 69 7a 65 20 e to initialize
13b0: 54 63 6c 2e 20 20 41 62 6f 72 74 69 6e 67 2e 5c Tcl. Aborting.\
13c0: 6e 22 29 3b 0a 09 09 61 70 70 66 73 5f 63 61 6c n");...appfs_cal
13d0: 6c 5f 6c 69 62 74 63 6c 28 0a 09 09 09 66 70 72 l_libtcl(....fpr
13e0: 69 6e 74 66 28 73 74 64 65 72 72 2c 20 22 54 63 intf(stderr, "Tc
13f0: 6c 20 45 72 72 6f 72 20 69 73 3a 20 25 73 5c 6e l Error is: %s\n
1400: 22 2c 20 54 63 6c 5f 47 65 74 53 74 72 69 6e 67 ", Tcl_GetString
1410: 52 65 73 75 6c 74 28 69 6e 74 65 72 70 29 29 3b Result(interp));
1420: 0a 09 09 29 0a 0a 09 09 69 66 20 28 65 72 72 6f ...)....if (erro
1430: 72 5f 73 74 72 69 6e 67 29 20 7b 0a 09 09 09 61 r_string) {....a
1440: 70 70 66 73 5f 63 61 6c 6c 5f 6c 69 62 74 63 6c ppfs_call_libtcl
1450: 28 0a 09 09 09 09 2a 65 72 72 6f 72 5f 73 74 72 (.....*error_str
1460: 69 6e 67 20 3d 20 73 74 72 64 75 70 28 54 63 6c ing = strdup(Tcl
1470: 5f 47 65 74 53 74 72 69 6e 67 52 65 73 75 6c 74 _GetStringResult
1480: 28 69 6e 74 65 72 70 29 29 3b 0a 09 09 09 29 0a (interp));....).
1490: 09 09 7d 0a 0a 09 09 61 70 70 66 73 5f 63 61 6c ..}....appfs_cal
14a0: 6c 5f 6c 69 62 74 63 6c 28 54 63 6c 5f 52 65 6c l_libtcl(Tcl_Rel
14b0: 65 61 73 65 28 69 6e 74 65 72 70 29 3b 29 0a 0a ease(interp);)..
14c0: 09 09 41 50 50 46 53 5f 44 45 42 55 47 28 22 54 ..APPFS_DEBUG("T
14d0: 65 72 6d 69 6e 61 74 69 6e 67 20 54 63 6c 20 69 erminating Tcl i
14e0: 6e 74 65 72 70 72 65 74 65 72 2e 22 29 3b 0a 0a nterpreter.");..
14f0: 09 09 61 70 70 66 73 5f 63 61 6c 6c 5f 6c 69 62 ..appfs_call_lib
1500: 74 63 6c 28 54 63 6c 5f 44 65 6c 65 74 65 49 6e tcl(Tcl_DeleteIn
1510: 74 65 72 70 28 69 6e 74 65 72 70 29 3b 29 0a 0a terp(interp);)..
1520: 09 09 72 65 74 75 72 6e 28 4e 55 4c 4c 29 3b 0a ..return(NULL);.
1530: 09 7d 0a 0a 09 61 70 70 66 73 5f 63 61 6c 6c 5f .}...appfs_call_
1540: 6c 69 62 74 63 6c 28 0a 09 09 74 63 6c 5f 72 65 libtcl(...tcl_re
1550: 74 20 3d 20 54 63 6c 5f 45 76 61 6c 28 69 6e 74 t = Tcl_Eval(int
1560: 65 72 70 2c 20 22 70 61 63 6b 61 67 65 20 69 66 erp, "package if
1570: 6e 65 65 64 65 64 20 73 68 61 31 20 31 2e 30 20 needed sha1 1.0
1580: 5b 6c 69 73 74 20 6c 6f 61 64 20 7b 7d 20 73 68 [list load {} sh
1590: 61 31 5d 22 29 3b 0a 09 29 0a 09 69 66 20 28 74 a1]");..)..if (t
15a0: 63 6c 5f 72 65 74 20 21 3d 20 54 43 4c 5f 4f 4b cl_ret != TCL_OK
15b0: 29 20 7b 0a 09 09 66 70 72 69 6e 74 66 28 73 74 ) {...fprintf(st
15c0: 64 65 72 72 2c 20 22 55 6e 61 62 6c 65 20 74 6f derr, "Unable to
15d0: 20 69 6e 69 74 69 61 6c 69 7a 65 20 54 63 6c 20 initialize Tcl
15e0: 53 48 41 31 2e 20 20 41 62 6f 72 74 69 6e 67 2e SHA1. Aborting.
15f0: 5c 6e 22 29 3b 0a 09 09 61 70 70 66 73 5f 63 61 \n");...appfs_ca
1600: 6c 6c 5f 6c 69 62 74 63 6c 28 0a 09 09 09 66 70 ll_libtcl(....fp
1610: 72 69 6e 74 66 28 73 74 64 65 72 72 2c 20 22 54 rintf(stderr, "T
1620: 63 6c 20 45 72 72 6f 72 20 69 73 3a 20 25 73 5c cl Error is: %s\
1630: 6e 22 2c 20 54 63 6c 5f 47 65 74 53 74 72 69 6e n", Tcl_GetStrin
1640: 67 52 65 73 75 6c 74 28 69 6e 74 65 72 70 29 29 gResult(interp))
1650: 3b 0a 09 09 29 0a 0a 09 09 69 66 20 28 65 72 72 ;...)....if (err
1660: 6f 72 5f 73 74 72 69 6e 67 29 20 7b 0a 09 09 09 or_string) {....
1670: 61 70 70 66 73 5f 63 61 6c 6c 5f 6c 69 62 74 63 appfs_call_libtc
1680: 6c 28 0a 09 09 09 09 2a 65 72 72 6f 72 5f 73 74 l(.....*error_st
1690: 72 69 6e 67 20 3d 20 73 74 72 64 75 70 28 54 63 ring = strdup(Tc
16a0: 6c 5f 47 65 74 53 74 72 69 6e 67 52 65 73 75 6c l_GetStringResul
16b0: 74 28 69 6e 74 65 72 70 29 29 3b 0a 09 09 09 29 t(interp));....)
16c0: 0a 09 09 7d 0a 0a 09 09 61 70 70 66 73 5f 63 61 ...}....appfs_ca
16d0: 6c 6c 5f 6c 69 62 74 63 6c 28 54 63 6c 5f 52 65 ll_libtcl(Tcl_Re
16e0: 6c 65 61 73 65 28 69 6e 74 65 72 70 29 3b 29 0a lease(interp);).
16f0: 0a 09 09 41 50 50 46 53 5f 44 45 42 55 47 28 22 ...APPFS_DEBUG("
1700: 54 65 72 6d 69 6e 61 74 69 6e 67 20 54 63 6c 20 Terminating Tcl
1710: 69 6e 74 65 72 70 72 65 74 65 72 2e 22 29 3b 0a interpreter.");.
1720: 0a 09 09 61 70 70 66 73 5f 63 61 6c 6c 5f 6c 69 ...appfs_call_li
1730: 62 74 63 6c 28 54 63 6c 5f 44 65 6c 65 74 65 49 btcl(Tcl_DeleteI
1740: 6e 74 65 72 70 28 69 6e 74 65 72 70 29 3b 29 0a nterp(interp);).
1750: 0a 09 09 72 65 74 75 72 6e 28 4e 55 4c 4c 29 3b ...return(NULL);
1760: 0a 09 7d 0a 0a 09 61 70 70 66 73 5f 63 61 6c 6c ..}...appfs_call
1770: 5f 6c 69 62 74 63 6c 28 0a 09 09 74 63 6c 5f 72 _libtcl(...tcl_r
1780: 65 74 20 3d 20 54 63 6c 5f 45 76 61 6c 28 69 6e et = Tcl_Eval(in
1790: 74 65 72 70 2c 20 22 70 61 63 6b 61 67 65 20 69 terp, "package i
17a0: 66 6e 65 65 64 65 64 20 61 70 70 66 73 64 20 31 fneeded appfsd 1
17b0: 2e 30 20 5b 6c 69 73 74 20 6c 6f 61 64 20 7b 7d .0 [list load {}
17c0: 20 61 70 70 66 73 64 5d 22 29 3b 0a 09 29 0a 09 appfsd]");..)..
17d0: 69 66 20 28 74 63 6c 5f 72 65 74 20 21 3d 20 54 if (tcl_ret != T
17e0: 43 4c 5f 4f 4b 29 20 7b 0a 09 09 66 70 72 69 6e CL_OK) {...fprin
17f0: 74 66 28 73 74 64 65 72 72 2c 20 22 55 6e 61 62 tf(stderr, "Unab
1800: 6c 65 20 74 6f 20 69 6e 69 74 69 61 6c 69 7a 65 le to initialize
1810: 20 54 63 6c 20 41 70 70 46 53 20 50 61 63 6b 61 Tcl AppFS Packa
1820: 67 65 2e 20 20 41 62 6f 72 74 69 6e 67 2e 5c 6e ge. Aborting.\n
1830: 22 29 3b 0a 09 09 61 70 70 66 73 5f 63 61 6c 6c ");...appfs_call
1840: 5f 6c 69 62 74 63 6c 28 0a 09 09 09 66 70 72 69 _libtcl(....fpri
1850: 6e 74 66 28 73 74 64 65 72 72 2c 20 22 54 63 6c ntf(stderr, "Tcl
1860: 20 45 72 72 6f 72 20 69 73 3a 20 25 73 5c 6e 22 Error is: %s\n"
1870: 2c 20 54 63 6c 5f 47 65 74 53 74 72 69 6e 67 52 , Tcl_GetStringR
1880: 65 73 75 6c 74 28 69 6e 74 65 72 70 29 29 3b 0a esult(interp));.
1890: 09 09 29 0a 0a 09 09 69 66 20 28 65 72 72 6f 72 ..)....if (error
18a0: 5f 73 74 72 69 6e 67 29 20 7b 0a 09 09 09 61 70 _string) {....ap
18b0: 70 66 73 5f 63 61 6c 6c 5f 6c 69 62 74 63 6c 28 pfs_call_libtcl(
18c0: 0a 09 09 09 09 2a 65 72 72 6f 72 5f 73 74 72 69 .....*error_stri
18d0: 6e 67 20 3d 20 73 74 72 64 75 70 28 54 63 6c 5f ng = strdup(Tcl_
18e0: 47 65 74 53 74 72 69 6e 67 52 65 73 75 6c 74 28 GetStringResult(
18f0: 69 6e 74 65 72 70 29 29 3b 0a 09 09 09 29 0a 09 interp));....)..
1900: 09 7d 0a 0a 09 09 61 70 70 66 73 5f 63 61 6c 6c .}....appfs_call
1910: 5f 6c 69 62 74 63 6c 28 54 63 6c 5f 52 65 6c 65 _libtcl(Tcl_Rele
1920: 61 73 65 28 69 6e 74 65 72 70 29 3b 29 0a 0a 09 ase(interp);)...
1930: 09 41 50 50 46 53 5f 44 45 42 55 47 28 22 54 65 .APPFS_DEBUG("Te
1940: 72 6d 69 6e 61 74 69 6e 67 20 54 63 6c 20 69 6e rminating Tcl in
1950: 74 65 72 70 72 65 74 65 72 2e 22 29 3b 0a 0a 09 terpreter.");...
1960: 09 61 70 70 66 73 5f 63 61 6c 6c 5f 6c 69 62 74 .appfs_call_libt
1970: 63 6c 28 54 63 6c 5f 44 65 6c 65 74 65 49 6e 74 cl(Tcl_DeleteInt
1980: 65 72 70 28 69 6e 74 65 72 70 29 3b 29 0a 0a 09 erp(interp);)...
1990: 09 72 65 74 75 72 6e 28 4e 55 4c 4c 29 3b 0a 09 .return(NULL);..
19a0: 7d 0a 0a 09 2f 2a 0a 09 20 2a 20 4c 6f 61 64 20 }.../*.. * Load
19b0: 22 70 6b 69 2e 74 63 6c 22 20 69 6e 20 74 68 65 "pki.tcl" in the
19c0: 20 73 61 6d 65 20 77 61 79 20 61 73 20 61 70 70 same way as app
19d0: 66 73 64 2e 74 63 6c 20 28 73 65 65 20 62 65 6c fsd.tcl (see bel
19e0: 6f 77 29 0a 09 20 2a 2f 0a 09 61 70 70 66 73 5f ow).. */..appfs_
19f0: 63 61 6c 6c 5f 6c 69 62 74 63 6c 5f 65 6e 74 65 call_libtcl_ente
1a00: 72 0a 09 09 74 63 6c 5f 72 65 74 20 3d 20 54 63 r...tcl_ret = Tc
1a10: 6c 5f 45 76 61 6c 28 69 6e 74 65 72 70 2c 20 22 l_Eval(interp, "
1a20: 22 0a 23 69 6e 63 6c 75 64 65 20 22 70 6b 69 2e ".#include "pki.
1a30: 74 63 6c 2e 68 22 0a 09 09 22 22 29 3b 0a 09 61 tcl.h"..."");..a
1a40: 70 70 66 73 5f 63 61 6c 6c 5f 6c 69 62 74 63 6c ppfs_call_libtcl
1a50: 5f 65 78 69 74 0a 09 69 66 20 28 74 63 6c 5f 72 _exit..if (tcl_r
1a60: 65 74 20 21 3d 20 54 43 4c 5f 4f 4b 29 20 7b 0a et != TCL_OK) {.
1a70: 09 09 66 70 72 69 6e 74 66 28 73 74 64 65 72 72 ..fprintf(stderr
1a80: 2c 20 22 55 6e 61 62 6c 65 20 74 6f 20 69 6e 69 , "Unable to ini
1a90: 74 69 61 6c 69 7a 65 20 54 63 6c 20 50 4b 49 2e tialize Tcl PKI.
1aa0: 20 20 41 62 6f 72 74 69 6e 67 2e 5c 6e 22 29 3b Aborting.\n");
1ab0: 0a 09 09 61 70 70 66 73 5f 63 61 6c 6c 5f 6c 69 ...appfs_call_li
1ac0: 62 74 63 6c 28 0a 09 09 09 66 70 72 69 6e 74 66 btcl(....fprintf
1ad0: 28 73 74 64 65 72 72 2c 20 22 54 63 6c 20 45 72 (stderr, "Tcl Er
1ae0: 72 6f 72 20 69 73 3a 20 25 73 5c 6e 22 2c 20 54 ror is: %s\n", T
1af0: 63 6c 5f 47 65 74 53 74 72 69 6e 67 52 65 73 75 cl_GetStringResu
1b00: 6c 74 28 69 6e 74 65 72 70 29 29 3b 0a 09 09 29 lt(interp));...)
1b10: 0a 0a 09 09 69 66 20 28 65 72 72 6f 72 5f 73 74 ....if (error_st
1b20: 72 69 6e 67 29 20 7b 0a 09 09 09 61 70 70 66 73 ring) {....appfs
1b30: 5f 63 61 6c 6c 5f 6c 69 62 74 63 6c 28 0a 09 09 _call_libtcl(...
1b40: 09 09 2a 65 72 72 6f 72 5f 73 74 72 69 6e 67 20 ..*error_string
1b50: 3d 20 73 74 72 64 75 70 28 54 63 6c 5f 47 65 74 = strdup(Tcl_Get
1b60: 53 74 72 69 6e 67 52 65 73 75 6c 74 28 69 6e 74 StringResult(int
1b70: 65 72 70 29 29 3b 0a 09 09 09 29 0a 09 09 7d 0a erp));....)...}.
1b80: 0a 09 09 61 70 70 66 73 5f 63 61 6c 6c 5f 6c 69 ...appfs_call_li
1b90: 62 74 63 6c 28 54 63 6c 5f 52 65 6c 65 61 73 65 btcl(Tcl_Release
1ba0: 28 69 6e 74 65 72 70 29 3b 29 0a 0a 09 09 41 50 (interp);)....AP
1bb0: 50 46 53 5f 44 45 42 55 47 28 22 54 65 72 6d 69 PFS_DEBUG("Termi
1bc0: 6e 61 74 69 6e 67 20 54 63 6c 20 69 6e 74 65 72 nating Tcl inter
1bd0: 70 72 65 74 65 72 2e 22 29 3b 0a 0a 09 09 61 70 preter.");....ap
1be0: 70 66 73 5f 63 61 6c 6c 5f 6c 69 62 74 63 6c 28 pfs_call_libtcl(
1bf0: 54 63 6c 5f 44 65 6c 65 74 65 49 6e 74 65 72 70 Tcl_DeleteInterp
1c00: 28 69 6e 74 65 72 70 29 3b 29 0a 0a 09 09 72 65 (interp);)....re
1c10: 74 75 72 6e 28 4e 55 4c 4c 29 3b 0a 09 7d 0a 0a turn(NULL);..}..
1c20: 09 2f 2a 0a 09 20 2a 20 4c 6f 61 64 20 74 68 65 ./*.. * Load the
1c30: 20 22 61 70 70 66 73 64 2e 74 63 6c 22 20 73 63 "appfsd.tcl" sc
1c40: 72 69 70 74 2c 20 77 68 69 63 68 20 69 73 20 22 ript, which is "
1c50: 63 6f 6d 70 69 6c 65 64 22 20 69 6e 74 6f 20 61 compiled" into a
1c60: 20 43 20 68 65 61 64 65 72 0a 09 20 2a 20 73 6f C header.. * so
1c70: 20 74 68 61 74 20 69 74 20 64 6f 65 73 20 6e 6f that it does no
1c80: 74 20 6e 65 65 64 20 74 6f 20 65 78 69 73 74 20 t need to exist
1c90: 6f 6e 20 74 68 65 20 66 69 6c 65 73 79 73 74 65 on the filesyste
1ca0: 6d 20 61 6e 64 20 63 61 6e 20 62 65 0a 09 20 2a m and can be.. *
1cb0: 20 64 69 72 65 63 74 6c 79 20 65 76 61 6c 75 61 directly evalua
1cc0: 74 65 64 2e 0a 09 20 2a 2f 0a 09 61 70 70 66 73 ted... */..appfs
1cd0: 5f 63 61 6c 6c 5f 6c 69 62 74 63 6c 5f 65 6e 74 _call_libtcl_ent
1ce0: 65 72 0a 09 09 74 63 6c 5f 72 65 74 20 3d 20 54 er...tcl_ret = T
1cf0: 63 6c 5f 45 76 61 6c 28 69 6e 74 65 72 70 2c 20 cl_Eval(interp,
1d00: 22 22 0a 23 69 6e 63 6c 75 64 65 20 22 61 70 70 "".#include "app
1d10: 66 73 64 2e 74 63 6c 2e 68 22 0a 09 09 22 22 29 fsd.tcl.h"..."")
1d20: 3b 0a 09 61 70 70 66 73 5f 63 61 6c 6c 5f 6c 69 ;..appfs_call_li
1d30: 62 74 63 6c 5f 65 78 69 74 0a 09 69 66 20 28 74 btcl_exit..if (t
1d40: 63 6c 5f 72 65 74 20 21 3d 20 54 43 4c 5f 4f 4b cl_ret != TCL_OK
1d50: 29 20 7b 0a 09 09 66 70 72 69 6e 74 66 28 73 74 ) {...fprintf(st
1d60: 64 65 72 72 2c 20 22 55 6e 61 62 6c 65 20 74 6f derr, "Unable to
1d70: 20 69 6e 69 74 69 61 6c 69 7a 65 20 54 63 6c 20 initialize Tcl
1d80: 41 70 70 46 53 20 73 63 72 69 70 74 2e 20 20 41 AppFS script. A
1d90: 62 6f 72 74 69 6e 67 2e 5c 6e 22 29 3b 0a 09 09 borting.\n");...
1da0: 61 70 70 66 73 5f 63 61 6c 6c 5f 6c 69 62 74 63 appfs_call_libtc
1db0: 6c 28 0a 09 09 09 66 70 72 69 6e 74 66 28 73 74 l(....fprintf(st
1dc0: 64 65 72 72 2c 20 22 54 63 6c 20 45 72 72 6f 72 derr, "Tcl Error
1dd0: 20 69 73 3a 20 25 73 5c 6e 22 2c 20 54 63 6c 5f is: %s\n", Tcl_
1de0: 47 65 74 53 74 72 69 6e 67 52 65 73 75 6c 74 28 GetStringResult(
1df0: 69 6e 74 65 72 70 29 29 3b 0a 09 09 29 0a 0a 09 interp));...)...
1e00: 09 69 66 20 28 65 72 72 6f 72 5f 73 74 72 69 6e .if (error_strin
1e10: 67 29 20 7b 0a 09 09 09 61 70 70 66 73 5f 63 61 g) {....appfs_ca
1e20: 6c 6c 5f 6c 69 62 74 63 6c 28 0a 09 09 09 09 2a ll_libtcl(.....*
1e30: 65 72 72 6f 72 5f 73 74 72 69 6e 67 20 3d 20 73 error_string = s
1e40: 74 72 64 75 70 28 54 63 6c 5f 47 65 74 53 74 72 trdup(Tcl_GetStr
1e50: 69 6e 67 52 65 73 75 6c 74 28 69 6e 74 65 72 70 ingResult(interp
1e60: 29 29 3b 0a 09 09 09 29 0a 09 09 7d 0a 0a 09 09 ));....)...}....
1e70: 61 70 70 66 73 5f 63 61 6c 6c 5f 6c 69 62 74 63 appfs_call_libtc
1e80: 6c 28 54 63 6c 5f 52 65 6c 65 61 73 65 28 69 6e l(Tcl_Release(in
1e90: 74 65 72 70 29 3b 29 0a 0a 09 09 41 50 50 46 53 terp);)....APPFS
1ea0: 5f 44 45 42 55 47 28 22 54 65 72 6d 69 6e 61 74 _DEBUG("Terminat
1eb0: 69 6e 67 20 54 63 6c 20 69 6e 74 65 72 70 72 65 ing Tcl interpre
1ec0: 74 65 72 2e 22 29 3b 0a 0a 09 09 61 70 70 66 73 ter.");....appfs
1ed0: 5f 63 61 6c 6c 5f 6c 69 62 74 63 6c 28 54 63 6c _call_libtcl(Tcl
1ee0: 5f 44 65 6c 65 74 65 49 6e 74 65 72 70 28 69 6e _DeleteInterp(in
1ef0: 74 65 72 70 29 3b 29 0a 0a 09 09 72 65 74 75 72 terp);)....retur
1f00: 6e 28 4e 55 4c 4c 29 3b 0a 09 7d 0a 0a 09 2f 2a n(NULL);..}.../*
1f10: 0a 09 20 2a 20 53 65 74 20 67 6c 6f 62 61 6c 20 .. * Set global
1f20: 76 61 72 69 61 62 6c 65 73 20 66 72 6f 6d 20 43 variables from C
1f30: 20 74 6f 20 54 63 6c 0a 09 20 2a 2f 0a 09 61 70 to Tcl.. */..ap
1f40: 70 66 73 5f 63 61 6c 6c 5f 6c 69 62 74 63 6c 28 pfs_call_libtcl(
1f50: 0a 09 09 74 63 6c 5f 73 65 74 76 61 72 5f 72 65 ...tcl_setvar_re
1f60: 74 20 3d 20 54 63 6c 5f 53 65 74 56 61 72 28 69 t = Tcl_SetVar(i
1f70: 6e 74 65 72 70 2c 20 22 3a 3a 61 70 70 66 73 3a nterp, "::appfs:
1f80: 3a 63 61 63 68 65 64 69 72 22 2c 20 61 70 70 66 :cachedir", appf
1f90: 73 5f 63 61 63 68 65 64 69 72 2c 20 54 43 4c 5f s_cachedir, TCL_
1fa0: 47 4c 4f 42 41 4c 5f 4f 4e 4c 59 29 3b 0a 09 29 GLOBAL_ONLY);..)
1fb0: 0a 09 69 66 20 28 74 63 6c 5f 73 65 74 76 61 72 ..if (tcl_setvar
1fc0: 5f 72 65 74 20 3d 3d 20 4e 55 4c 4c 29 20 7b 0a _ret == NULL) {.
1fd0: 09 09 66 70 72 69 6e 74 66 28 73 74 64 65 72 72 ..fprintf(stderr
1fe0: 2c 20 22 55 6e 61 62 6c 65 20 74 6f 20 73 65 74 , "Unable to set
1ff0: 20 63 61 63 68 65 20 64 69 72 65 63 74 6f 72 79 cache directory
2000: 2e 20 20 54 68 69 73 20 73 68 6f 75 6c 64 20 6e . This should n
2010: 65 76 65 72 20 66 61 69 6c 2e 5c 6e 22 29 3b 0a ever fail.\n");.
2020: 0a 09 09 69 66 20 28 65 72 72 6f 72 5f 73 74 72 ...if (error_str
2030: 69 6e 67 29 20 7b 0a 09 09 09 61 70 70 66 73 5f ing) {....appfs_
2040: 63 61 6c 6c 5f 6c 69 62 74 63 6c 28 0a 09 09 09 call_libtcl(....
2050: 09 2a 65 72 72 6f 72 5f 73 74 72 69 6e 67 20 3d .*error_string =
2060: 20 73 74 72 64 75 70 28 54 63 6c 5f 47 65 74 53 strdup(Tcl_GetS
2070: 74 72 69 6e 67 52 65 73 75 6c 74 28 69 6e 74 65 tringResult(inte
2080: 72 70 29 29 3b 0a 09 09 09 29 0a 09 09 7d 0a 0a rp));....)...}..
2090: 09 09 61 70 70 66 73 5f 63 61 6c 6c 5f 6c 69 62 ..appfs_call_lib
20a0: 74 63 6c 28 54 63 6c 5f 52 65 6c 65 61 73 65 28 tcl(Tcl_Release(
20b0: 69 6e 74 65 72 70 29 3b 29 0a 0a 09 09 41 50 50 interp);)....APP
20c0: 46 53 5f 44 45 42 55 47 28 22 54 65 72 6d 69 6e FS_DEBUG("Termin
20d0: 61 74 69 6e 67 20 54 63 6c 20 69 6e 74 65 72 70 ating Tcl interp
20e0: 72 65 74 65 72 2e 22 29 3b 0a 0a 09 09 61 70 70 reter.");....app
20f0: 66 73 5f 63 61 6c 6c 5f 6c 69 62 74 63 6c 28 54 fs_call_libtcl(T
2100: 63 6c 5f 44 65 6c 65 74 65 49 6e 74 65 72 70 28 cl_DeleteInterp(
2110: 69 6e 74 65 72 70 29 3b 29 0a 0a 09 09 72 65 74 interp);)....ret
2120: 75 72 6e 28 4e 55 4c 4c 29 3b 0a 09 7d 0a 0a 09 urn(NULL);..}...
2130: 2f 2a 0a 09 20 2a 20 49 6e 69 74 69 61 6c 69 7a /*.. * Initializ
2140: 65 20 74 68 65 20 22 61 70 70 66 73 64 2e 74 63 e the "appfsd.tc
2150: 6c 22 20 65 6e 76 69 72 6f 6e 6d 65 6e 74 2c 20 l" environment,
2160: 77 68 69 63 68 20 6d 75 73 74 20 62 65 20 64 6f which must be do
2170: 6e 65 20 61 66 74 65 72 0a 09 20 2a 20 67 6c 6f ne after.. * glo
2180: 62 61 6c 20 76 61 72 69 61 62 6c 65 73 20 61 72 bal variables ar
2190: 65 20 73 65 74 2e 0a 09 20 2a 2f 0a 09 61 70 70 e set... */..app
21a0: 66 73 5f 63 61 6c 6c 5f 6c 69 62 74 63 6c 28 0a fs_call_libtcl(.
21b0: 09 09 74 63 6c 5f 72 65 74 20 3d 20 54 63 6c 5f ..tcl_ret = Tcl_
21c0: 45 76 61 6c 28 69 6e 74 65 72 70 2c 20 22 3a 3a Eval(interp, "::
21d0: 61 70 70 66 73 3a 3a 69 6e 69 74 22 29 3b 0a 09 appfs::init");..
21e0: 29 0a 09 69 66 20 28 74 63 6c 5f 72 65 74 20 21 )..if (tcl_ret !
21f0: 3d 20 54 43 4c 5f 4f 4b 29 20 7b 0a 09 09 66 70 = TCL_OK) {...fp
2200: 72 69 6e 74 66 28 73 74 64 65 72 72 2c 20 22 55 rintf(stderr, "U
2210: 6e 61 62 6c 65 20 74 6f 20 69 6e 69 74 69 61 6c nable to initial
2220: 69 7a 65 20 54 63 6c 20 41 70 70 46 53 20 73 63 ize Tcl AppFS sc
2230: 72 69 70 74 20 28 3a 3a 61 70 70 66 73 3a 3a 69 ript (::appfs::i
2240: 6e 69 74 29 2e 20 20 41 62 6f 72 74 69 6e 67 2e nit). Aborting.
2250: 5c 6e 22 29 3b 0a 09 09 61 70 70 66 73 5f 63 61 \n");...appfs_ca
2260: 6c 6c 5f 6c 69 62 74 63 6c 28 0a 09 09 09 66 70 ll_libtcl(....fp
2270: 72 69 6e 74 66 28 73 74 64 65 72 72 2c 20 22 54 rintf(stderr, "T
2280: 63 6c 20 45 72 72 6f 72 20 69 73 3a 20 25 73 5c cl Error is: %s\
2290: 6e 22 2c 20 54 63 6c 5f 47 65 74 53 74 72 69 6e n", Tcl_GetStrin
22a0: 67 52 65 73 75 6c 74 28 69 6e 74 65 72 70 29 29 gResult(interp))
22b0: 3b 0a 09 09 29 0a 0a 09 09 69 66 20 28 65 72 72 ;...)....if (err
22c0: 6f 72 5f 73 74 72 69 6e 67 29 20 7b 0a 09 09 09 or_string) {....
22d0: 61 70 70 66 73 5f 63 61 6c 6c 5f 6c 69 62 74 63 appfs_call_libtc
22e0: 6c 28 0a 09 09 09 09 2a 65 72 72 6f 72 5f 73 74 l(.....*error_st
22f0: 72 69 6e 67 20 3d 20 73 74 72 64 75 70 28 54 63 ring = strdup(Tc
2300: 6c 5f 47 65 74 53 74 72 69 6e 67 52 65 73 75 6c l_GetStringResul
2310: 74 28 69 6e 74 65 72 70 29 29 3b 0a 09 09 09 29 t(interp));....)
2320: 0a 09 09 7d 0a 0a 09 09 61 70 70 66 73 5f 63 61 ...}....appfs_ca
2330: 6c 6c 5f 6c 69 62 74 63 6c 28 54 63 6c 5f 52 65 ll_libtcl(Tcl_Re
2340: 6c 65 61 73 65 28 69 6e 74 65 72 70 29 3b 29 0a lease(interp);).
2350: 0a 09 09 41 50 50 46 53 5f 44 45 42 55 47 28 22 ...APPFS_DEBUG("
2360: 54 65 72 6d 69 6e 61 74 69 6e 67 20 54 63 6c 20 Terminating Tcl
2370: 69 6e 74 65 72 70 72 65 74 65 72 2e 22 29 3b 0a interpreter.");.
2380: 0a 09 09 61 70 70 66 73 5f 63 61 6c 6c 5f 6c 69 ...appfs_call_li
2390: 62 74 63 6c 28 54 63 6c 5f 44 65 6c 65 74 65 49 btcl(Tcl_DeleteI
23a0: 6e 74 65 72 70 28 69 6e 74 65 72 70 29 3b 29 0a nterp(interp);).
23b0: 0a 09 09 72 65 74 75 72 6e 28 4e 55 4c 4c 29 3b ...return(NULL);
23c0: 0a 09 7d 0a 0a 09 2f 2a 0a 09 20 2a 20 48 69 64 ..}.../*.. * Hid
23d0: 65 20 73 6f 6d 65 20 54 63 6c 20 63 6f 6d 6d 61 e some Tcl comma
23e0: 6e 64 73 20 74 68 61 74 20 77 65 20 64 6f 20 6e nds that we do n
23f0: 6f 74 20 63 61 72 65 20 74 6f 20 75 73 65 20 61 ot care to use a
2400: 6e 64 20 77 68 69 63 68 20 6d 61 79 0a 09 20 2a nd which may.. *
2410: 20 73 6c 6f 77 20 64 6f 77 6e 20 72 75 6e 2d 74 slow down run-t
2420: 69 6d 65 20 6f 70 65 72 61 74 69 6f 6e 73 2e 0a ime operations..
2430: 09 20 2a 2f 0a 09 61 70 70 66 73 5f 63 61 6c 6c . */..appfs_call
2440: 5f 6c 69 62 74 63 6c 28 0a 09 09 54 63 6c 5f 48 _libtcl(...Tcl_H
2450: 69 64 65 43 6f 6d 6d 61 6e 64 28 69 6e 74 65 72 ideCommand(inter
2460: 70 2c 20 22 61 75 74 6f 5f 6c 6f 61 64 5f 69 6e p, "auto_load_in
2470: 64 65 78 22 2c 20 22 61 75 74 6f 5f 6c 6f 61 64 dex", "auto_load
2480: 5f 69 6e 64 65 78 22 29 3b 0a 09 09 54 63 6c 5f _index");...Tcl_
2490: 48 69 64 65 43 6f 6d 6d 61 6e 64 28 69 6e 74 65 HideCommand(inte
24a0: 72 70 2c 20 22 75 6e 6b 6e 6f 77 6e 22 2c 20 22 rp, "unknown", "
24b0: 75 6e 6b 6e 6f 77 6e 22 29 3b 0a 09 09 54 63 6c unknown");...Tcl
24c0: 5f 48 69 64 65 43 6f 6d 6d 61 6e 64 28 69 6e 74 _HideCommand(int
24d0: 65 72 70 2c 20 22 65 78 69 74 22 2c 20 22 65 78 erp, "exit", "ex
24e0: 69 74 22 29 3b 0a 09 29 0a 0a 09 2f 2a 0a 09 20 it");..).../*..
24f0: 2a 20 52 65 6c 65 61 73 65 20 74 68 65 20 68 6f * Release the ho
2500: 6c 64 20 77 65 20 68 61 76 65 20 6f 6e 20 74 68 ld we have on th
2510: 65 20 69 6e 74 65 72 70 72 65 74 65 72 20 73 6f e interpreter so
2520: 20 74 68 61 74 20 69 74 20 6d 61 79 20 62 65 0a that it may be.
2530: 09 20 2a 20 64 65 6c 65 74 65 64 20 69 66 20 6e . * deleted if n
2540: 65 65 64 65 64 0a 09 20 2a 2f 0a 09 61 70 70 66 eeded.. */..appf
2550: 73 5f 63 61 6c 6c 5f 6c 69 62 74 63 6c 28 54 63 s_call_libtcl(Tc
2560: 6c 5f 52 65 6c 65 61 73 65 28 69 6e 74 65 72 70 l_Release(interp
2570: 29 3b 29 0a 0a 09 2f 2a 0a 09 20 2a 20 52 65 74 );).../*.. * Ret
2580: 75 72 6e 20 74 68 65 20 63 6f 6d 70 6c 65 74 65 urn the complete
2590: 6c 79 20 69 6e 69 74 69 61 6c 69 7a 65 64 20 69 ly initialized i
25a0: 6e 74 65 72 70 72 65 74 65 72 0a 09 20 2a 2f 0a nterpreter.. */.
25b0: 09 72 65 74 75 72 6e 28 69 6e 74 65 72 70 29 3b .return(interp);
25c0: 0a 7d 0a 0a 2f 2a 0a 20 2a 20 52 65 74 75 72 6e .}../*. * Return
25d0: 20 74 68 65 20 74 68 72 65 61 64 2d 73 70 65 63 the thread-spec
25e0: 69 66 69 63 20 54 63 6c 20 69 6e 74 65 72 70 72 ific Tcl interpr
25f0: 65 74 65 72 2c 20 63 72 65 61 74 69 6e 67 20 69 eter, creating i
2600: 74 20 69 66 20 6e 65 65 64 65 64 0a 20 2a 2f 0a t if needed. */.
2610: 73 74 61 74 69 63 20 54 63 6c 5f 49 6e 74 65 72 static Tcl_Inter
2620: 70 20 2a 61 70 70 66 73 5f 54 63 6c 49 6e 74 65 p *appfs_TclInte
2630: 72 70 28 76 6f 69 64 29 20 7b 0a 09 54 63 6c 5f rp(void) {..Tcl_
2640: 49 6e 74 65 72 70 20 2a 69 6e 74 65 72 70 3b 0a Interp *interp;.
2650: 09 69 6e 74 20 70 74 68 72 65 61 64 5f 72 65 74 .int pthread_ret
2660: 3b 0a 09 73 74 61 74 69 63 20 5f 5f 74 68 72 65 ;..static __thre
2670: 61 64 20 69 6e 74 20 74 68 72 65 61 64 5f 69 6e ad int thread_in
2680: 74 65 72 70 5f 72 65 73 65 74 5f 6b 65 79 20 3d terp_reset_key =
2690: 20 30 3b 0a 09 69 6e 74 20 67 6c 6f 62 61 6c 5f 0;..int global_
26a0: 69 6e 74 65 72 70 5f 72 65 73 65 74 5f 6b 65 79 interp_reset_key
26b0: 3b 0a 0a 09 67 6c 6f 62 61 6c 5f 69 6e 74 65 72 ;...global_inter
26c0: 70 5f 72 65 73 65 74 5f 6b 65 79 20 3d 20 5f 5f p_reset_key = __
26d0: 73 79 6e 63 5f 66 65 74 63 68 5f 61 6e 64 5f 61 sync_fetch_and_a
26e0: 64 64 28 26 69 6e 74 65 72 70 5f 72 65 73 65 74 dd(&interp_reset
26f0: 5f 6b 65 79 2c 20 30 29 3b 0a 0a 09 69 6e 74 65 _key, 0);...inte
2700: 72 70 20 3d 20 70 74 68 72 65 61 64 5f 67 65 74 rp = pthread_get
2710: 73 70 65 63 69 66 69 63 28 69 6e 74 65 72 70 4b specific(interpK
2720: 65 79 29 3b 0a 09 69 66 20 28 69 6e 74 65 72 70 ey);..if (interp
2730: 20 21 3d 20 4e 55 4c 4c 20 26 26 20 74 68 72 65 != NULL && thre
2740: 61 64 5f 69 6e 74 65 72 70 5f 72 65 73 65 74 5f ad_interp_reset_
2750: 6b 65 79 20 21 3d 20 67 6c 6f 62 61 6c 5f 69 6e key != global_in
2760: 74 65 72 70 5f 72 65 73 65 74 5f 6b 65 79 29 20 terp_reset_key)
2770: 7b 0a 09 09 41 50 50 46 53 5f 44 45 42 55 47 28 {...APPFS_DEBUG(
2780: 22 54 65 72 6d 69 6e 61 74 69 6e 67 20 6f 6c 64 "Terminating old
2790: 20 69 6e 74 65 72 70 72 65 74 65 72 20 61 6e 64 interpreter and
27a0: 20 72 65 73 74 61 72 74 69 6e 67 20 64 75 65 20 restarting due
27b0: 74 6f 20 72 65 73 65 74 20 72 65 71 75 65 73 74 to reset request
27c0: 2e 22 29 3b 0a 0a 09 09 61 70 70 66 73 5f 63 61 .");....appfs_ca
27d0: 6c 6c 5f 6c 69 62 74 63 6c 28 54 63 6c 5f 44 65 ll_libtcl(Tcl_De
27e0: 6c 65 74 65 49 6e 74 65 72 70 28 69 6e 74 65 72 leteInterp(inter
27f0: 70 29 3b 29 0a 0a 09 09 69 6e 74 65 72 70 20 3d p);)....interp =
2800: 20 4e 55 4c 4c 3b 0a 0a 09 09 70 74 68 72 65 61 NULL;....pthrea
2810: 64 5f 72 65 74 20 3d 20 70 74 68 72 65 61 64 5f d_ret = pthread_
2820: 73 65 74 73 70 65 63 69 66 69 63 28 69 6e 74 65 setspecific(inte
2830: 72 70 4b 65 79 2c 20 69 6e 74 65 72 70 29 3b 0a rpKey, interp);.
2840: 09 7d 0a 0a 09 69 66 20 28 67 6c 6f 62 61 6c 5f .}...if (global_
2850: 69 6e 74 65 72 70 5f 72 65 73 65 74 5f 6b 65 79 interp_reset_key
2860: 20 3d 3d 20 2d 31 29 20 7b 0a 09 09 41 50 50 46 == -1) {...APPF
2870: 53 5f 44 45 42 55 47 28 22 52 65 74 75 72 6e 69 S_DEBUG("Returni
2880: 6e 67 20 4e 55 4c 4c 20 73 69 6e 63 65 20 77 65 ng NULL since we
2890: 20 61 72 65 20 69 6e 20 74 68 65 20 70 72 6f 63 are in the proc
28a0: 65 73 73 20 6f 66 20 74 65 72 6d 69 6e 61 74 69 ess of terminati
28b0: 6e 67 20 61 6c 6c 20 74 68 72 65 61 64 73 2e 22 ng all threads."
28c0: 29 3b 0a 0a 09 09 72 65 74 75 72 6e 28 4e 55 4c );....return(NUL
28d0: 4c 29 3b 0a 09 7d 0a 0a 09 74 68 72 65 61 64 5f L);..}...thread_
28e0: 69 6e 74 65 72 70 5f 72 65 73 65 74 5f 6b 65 79 interp_reset_key
28f0: 20 3d 20 67 6c 6f 62 61 6c 5f 69 6e 74 65 72 70 = global_interp
2900: 5f 72 65 73 65 74 5f 6b 65 79 3b 0a 0a 09 69 66 _reset_key;...if
2910: 20 28 69 6e 74 65 72 70 20 3d 3d 20 4e 55 4c 4c (interp == NULL
2920: 29 20 7b 0a 09 09 69 6e 74 65 72 70 20 3d 20 61 ) {...interp = a
2930: 70 70 66 73 5f 63 72 65 61 74 65 5f 54 63 6c 49 ppfs_create_TclI
2940: 6e 74 65 72 70 28 4e 55 4c 4c 29 3b 0a 0a 09 09 nterp(NULL);....
2950: 69 66 20 28 69 6e 74 65 72 70 20 3d 3d 20 4e 55 if (interp == NU
2960: 4c 4c 29 20 7b 0a 09 09 09 41 50 50 46 53 5f 44 LL) {....APPFS_D
2970: 45 42 55 47 28 22 43 72 65 61 74 65 20 69 6e 74 EBUG("Create int
2980: 65 72 70 20 66 61 69 6c 65 64 2c 20 72 65 74 75 erp failed, retu
2990: 72 6e 69 6e 67 69 6e 20 66 61 69 6c 75 72 65 2e rningin failure.
29a0: 22 29 3b 0a 0a 09 09 09 72 65 74 75 72 6e 28 4e ");.....return(N
29b0: 55 4c 4c 29 3b 0a 09 09 7d 0a 0a 09 09 70 74 68 ULL);...}....pth
29c0: 72 65 61 64 5f 72 65 74 20 3d 20 70 74 68 72 65 read_ret = pthre
29d0: 61 64 5f 73 65 74 73 70 65 63 69 66 69 63 28 69 ad_setspecific(i
29e0: 6e 74 65 72 70 4b 65 79 2c 20 69 6e 74 65 72 70 nterpKey, interp
29f0: 29 3b 0a 09 09 69 66 20 28 70 74 68 72 65 61 64 );...if (pthread
2a00: 5f 72 65 74 20 21 3d 20 30 29 20 7b 0a 09 09 09 _ret != 0) {....
2a10: 41 50 50 46 53 5f 44 45 42 55 47 28 22 70 74 68 APPFS_DEBUG("pth
2a20: 72 65 61 64 5f 73 65 74 73 70 65 63 69 66 69 63 read_setspecific
2a30: 28 29 20 66 61 69 6c 65 64 2e 20 20 54 65 72 6d () failed. Term
2a40: 69 6e 61 74 69 6e 67 20 54 63 6c 20 69 6e 74 65 inating Tcl inte
2a50: 72 70 72 65 74 65 72 2e 22 29 3b 0a 0a 09 09 09 rpreter.");.....
2a60: 61 70 70 66 73 5f 63 61 6c 6c 5f 6c 69 62 74 63 appfs_call_libtc
2a70: 6c 28 54 63 6c 5f 44 65 6c 65 74 65 49 6e 74 65 l(Tcl_DeleteInte
2a80: 72 70 28 69 6e 74 65 72 70 29 3b 29 0a 0a 09 09 rp(interp);)....
2a90: 09 72 65 74 75 72 6e 28 4e 55 4c 4c 29 3b 0a 09 .return(NULL);..
2aa0: 09 7d 0a 09 7d 0a 0a 09 72 65 74 75 72 6e 28 69 .}..}...return(i
2ab0: 6e 74 65 72 70 29 3b 0a 7d 0a 0a 2f 2a 0a 20 2a nterp);.}../*. *
2ac0: 20 45 76 61 6c 75 61 74 65 20 61 20 54 63 6c 20 Evaluate a Tcl
2ad0: 73 63 72 69 70 74 20 63 6f 6e 73 74 72 75 63 74 script construct
2ae0: 65 64 20 62 79 20 63 6f 6e 63 61 74 65 6e 61 74 ed by concatenat
2af0: 69 6e 67 20 61 20 62 75 6e 63 68 20 6f 66 20 43 ing a bunch of C
2b00: 20 73 74 72 69 6e 67 73 0a 20 2a 20 74 6f 67 65 strings. * toge
2b10: 74 68 65 72 2e 0a 20 2a 2f 0a 73 74 61 74 69 63 ther.. */.static
2b20: 20 69 6e 74 20 61 70 70 66 73 5f 54 63 6c 5f 45 int appfs_Tcl_E
2b30: 76 61 6c 28 54 63 6c 5f 49 6e 74 65 72 70 20 2a val(Tcl_Interp *
2b40: 69 6e 74 65 72 70 2c 20 69 6e 74 20 6f 62 6a 63 interp, int objc
2b50: 2c 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 63 6d , const char *cm
2b60: 64 2c 20 2e 2e 2e 29 20 7b 0a 09 54 63 6c 5f 4f d, ...) {..Tcl_O
2b70: 62 6a 20 2a 2a 6f 62 6a 76 3b 0a 09 63 6f 6e 73 bj **objv;..cons
2b80: 74 20 63 68 61 72 20 2a 61 72 67 3b 0a 09 76 61 t char *arg;..va
2b90: 5f 6c 69 73 74 20 61 72 67 70 3b 0a 09 69 6e 74 _list argp;..int
2ba0: 20 72 65 74 76 61 6c 3b 0a 09 69 6e 74 20 69 3b retval;..int i;
2bb0: 0a 0a 09 69 66 20 28 69 6e 74 65 72 70 20 3d 3d ...if (interp ==
2bc0: 20 4e 55 4c 4c 29 20 7b 0a 09 09 41 50 50 46 53 NULL) {...APPFS
2bd0: 5f 44 45 42 55 47 28 22 49 6e 76 61 6c 69 64 20 _DEBUG("Invalid
2be0: 69 6e 74 65 72 70 72 65 74 65 72 20 70 61 73 73 interpreter pass
2bf0: 65 64 20 69 6e 2c 20 72 65 74 75 72 6e 69 6e 67 ed in, returning
2c00: 20 69 6e 20 66 61 69 6c 75 72 65 2e 22 29 3b 0a in failure.");.
2c10: 0a 09 09 72 65 74 75 72 6e 28 54 43 4c 5f 45 52 ...return(TCL_ER
2c20: 52 4f 52 29 3b 0a 09 7d 0a 0a 09 6f 62 6a 76 20 ROR);..}...objv
2c30: 3d 20 28 76 6f 69 64 20 2a 29 20 63 6b 61 6c 6c = (void *) ckall
2c40: 6f 63 28 73 69 7a 65 6f 66 28 2a 6f 62 6a 76 29 oc(sizeof(*objv)
2c50: 20 2a 20 6f 62 6a 63 29 3b 0a 0a 09 61 70 70 66 * objc);...appf
2c60: 73 5f 63 61 6c 6c 5f 6c 69 62 74 63 6c 28 0a 09 s_call_libtcl(..
2c70: 09 6f 62 6a 76 5b 30 5d 20 3d 20 54 63 6c 5f 4e .objv[0] = Tcl_N
2c80: 65 77 53 74 72 69 6e 67 4f 62 6a 28 63 6d 64 2c ewStringObj(cmd,
2c90: 20 2d 31 29 3b 0a 0a 09 09 54 63 6c 5f 49 6e 63 -1);....Tcl_Inc
2ca0: 72 52 65 66 43 6f 75 6e 74 28 6f 62 6a 76 5b 30 rRefCount(objv[0
2cb0: 5d 29 3b 0a 0a 09 09 76 61 5f 73 74 61 72 74 28 ]);....va_start(
2cc0: 61 72 67 70 2c 20 63 6d 64 29 3b 0a 09 09 66 6f argp, cmd);...fo
2cd0: 72 20 28 69 20 3d 20 31 3b 20 69 20 3c 20 6f 62 r (i = 1; i < ob
2ce0: 6a 63 3b 20 69 2b 2b 29 20 7b 0a 09 09 09 61 72 jc; i++) {....ar
2cf0: 67 20 3d 20 76 61 5f 61 72 67 28 61 72 67 70 2c g = va_arg(argp,
2d00: 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 29 3b 0a const char *);.
2d10: 0a 09 09 09 6f 62 6a 76 5b 69 5d 20 3d 20 54 63 ....objv[i] = Tc
2d20: 6c 5f 4e 65 77 53 74 72 69 6e 67 4f 62 6a 28 61 l_NewStringObj(a
2d30: 72 67 2c 20 2d 31 29 3b 0a 0a 09 09 09 54 63 6c rg, -1);.....Tcl
2d40: 5f 49 6e 63 72 52 65 66 43 6f 75 6e 74 28 6f 62 _IncrRefCount(ob
2d50: 6a 76 5b 69 5d 29 3b 0a 09 09 7d 0a 09 09 76 61 jv[i]);...}...va
2d60: 5f 65 6e 64 28 61 72 67 70 29 3b 0a 09 29 0a 0a _end(argp);..)..
2d70: 09 61 70 70 66 73 5f 63 61 6c 6c 5f 6c 69 62 74 .appfs_call_libt
2d80: 63 6c 28 0a 09 09 72 65 74 76 61 6c 20 3d 20 54 cl(...retval = T
2d90: 63 6c 5f 45 76 61 6c 4f 62 6a 76 28 69 6e 74 65 cl_EvalObjv(inte
2da0: 72 70 2c 20 6f 62 6a 63 2c 20 6f 62 6a 76 2c 20 rp, objc, objv,
2db0: 30 29 3b 0a 09 29 0a 0a 09 61 70 70 66 73 5f 63 0);..)...appfs_c
2dc0: 61 6c 6c 5f 6c 69 62 74 63 6c 28 0a 09 09 66 6f all_libtcl(...fo
2dd0: 72 20 28 69 20 3d 20 30 3b 20 69 20 3c 20 6f 62 r (i = 0; i < ob
2de0: 6a 63 3b 20 69 2b 2b 29 20 7b 0a 09 09 09 54 63 jc; i++) {....Tc
2df0: 6c 5f 44 65 63 72 52 65 66 43 6f 75 6e 74 28 6f l_DecrRefCount(o
2e00: 62 6a 76 5b 69 5d 29 3b 0a 09 09 7d 0a 09 29 0a bjv[i]);...}..).
2e10: 0a 09 63 6b 66 72 65 65 28 28 76 6f 69 64 20 2a ..ckfree((void *
2e20: 29 20 6f 62 6a 76 29 3b 0a 0a 09 69 66 20 28 72 ) objv);...if (r
2e30: 65 74 76 61 6c 20 21 3d 20 54 43 4c 5f 4f 4b 29 etval != TCL_OK)
2e40: 20 7b 0a 09 09 61 70 70 66 73 5f 63 61 6c 6c 5f {...appfs_call_
2e50: 6c 69 62 74 63 6c 28 0a 09 09 09 41 50 50 46 53 libtcl(....APPFS
2e60: 5f 44 45 42 55 47 28 22 54 63 6c 20 63 6f 6d 6d _DEBUG("Tcl comm
2e70: 61 6e 64 20 66 61 69 6c 65 64 2c 20 3a 3a 65 72 and failed, ::er
2e80: 72 6f 72 49 6e 66 6f 20 63 6f 6e 74 61 69 6e 73 rorInfo contains
2e90: 3a 20 25 73 5c 6e 22 2c 20 54 63 6c 5f 47 65 74 : %s\n", Tcl_Get
2ea0: 56 61 72 28 69 6e 74 65 72 70 2c 20 22 3a 3a 65 Var(interp, "::e
2eb0: 72 72 6f 72 49 6e 66 6f 22 2c 20 30 29 29 3b 0a rrorInfo", 0));.
2ec0: 09 09 29 0a 09 7d 0a 0a 09 72 65 74 75 72 6e 28 ..)..}...return(
2ed0: 72 65 74 76 61 6c 29 3b 0a 7d 0a 0a 2f 2a 0a 20 retval);.}../*.
2ee0: 2a 20 52 65 71 75 65 73 74 20 61 6c 6c 20 54 63 * Request all Tc
2ef0: 6c 20 69 6e 74 65 72 70 72 65 74 65 72 73 20 72 l interpreters r
2f00: 65 73 74 61 72 74 0a 20 2a 2f 0a 73 74 61 74 69 estart. */.stati
2f10: 63 20 76 6f 69 64 20 61 70 70 66 73 5f 74 63 6c c void appfs_tcl
2f20: 5f 52 65 73 65 74 49 6e 74 65 72 70 73 28 76 6f _ResetInterps(vo
2f30: 69 64 29 20 7b 0a 09 41 50 50 46 53 5f 44 45 42 id) {..APPFS_DEB
2f40: 55 47 28 22 52 65 71 75 65 73 74 69 6e 67 20 72 UG("Requesting r
2f50: 65 73 65 74 20 6f 66 20 61 6c 6c 20 69 6e 74 65 eset of all inte
2f60: 72 70 72 65 74 65 72 73 2e 22 29 3b 0a 0a 09 5f rpreters.");..._
2f70: 5f 73 79 6e 63 5f 61 64 64 5f 61 6e 64 5f 66 65 _sync_add_and_fe
2f80: 74 63 68 28 26 69 6e 74 65 72 70 5f 72 65 73 65 tch(&interp_rese
2f90: 74 5f 6b 65 79 2c 20 31 29 3b 0a 0a 09 72 65 74 t_key, 1);...ret
2fa0: 75 72 6e 3b 0a 7d 0a 0a 2f 2a 0a 20 2a 20 44 65 urn;.}../*. * De
2fb0: 74 65 72 6d 69 6e 65 20 74 68 65 20 55 49 44 20 termine the UID
2fc0: 66 6f 72 20 74 68 65 20 75 73 65 72 20 6d 61 6b for the user mak
2fd0: 69 6e 67 20 74 68 65 20 63 75 72 72 65 6e 74 20 ing the current
2fe0: 46 55 53 45 20 66 69 6c 65 73 79 73 74 65 6d 20 FUSE filesystem
2ff0: 72 65 71 75 65 73 74 2e 0a 20 2a 20 54 68 69 73 request.. * This
3000: 20 77 69 6c 6c 20 62 65 20 75 73 65 64 20 74 6f will be used to
3010: 20 6c 6f 6f 6b 75 70 20 74 68 65 20 75 73 65 72 lookup the user
3020: 27 73 20 68 6f 6d 65 20 64 69 72 65 63 74 6f 72 's home director
3030: 79 20 73 6f 20 77 65 20 63 61 6e 20 73 65 61 72 y so we can sear
3040: 63 68 20 66 6f 72 0a 20 2a 20 6c 6f 63 61 6c 6c ch for. * locall
3050: 79 20 6d 6f 64 69 66 69 65 64 20 66 69 6c 65 73 y modified files
3060: 2e 0a 20 2a 2f 0a 73 74 61 74 69 63 20 75 69 64 .. */.static uid
3070: 5f 74 20 61 70 70 66 73 5f 67 65 74 5f 66 73 75 _t appfs_get_fsu
3080: 69 64 28 76 6f 69 64 29 20 7b 0a 09 73 74 72 75 id(void) {..stru
3090: 63 74 20 66 75 73 65 5f 63 6f 6e 74 65 78 74 20 ct fuse_context
30a0: 2a 63 74 78 3b 0a 0a 09 69 66 20 28 21 61 70 70 *ctx;...if (!app
30b0: 66 73 5f 66 75 73 65 5f 73 74 61 72 74 65 64 29 fs_fuse_started)
30c0: 20 7b 0a 09 09 72 65 74 75 72 6e 28 67 65 74 75 {...return(getu
30d0: 69 64 28 29 29 3b 0a 09 7d 0a 0a 09 63 74 78 20 id());..}...ctx
30e0: 3d 20 66 75 73 65 5f 67 65 74 5f 63 6f 6e 74 65 = fuse_get_conte
30f0: 78 74 28 29 3b 0a 09 69 66 20 28 63 74 78 20 3d xt();..if (ctx =
3100: 3d 20 4e 55 4c 4c 29 20 7b 0a 09 09 2f 2a 20 55 = NULL) {.../* U
3110: 6e 61 62 6c 65 20 74 6f 20 6c 6f 6f 6b 75 70 20 nable to lookup
3120: 75 73 65 72 20 66 6f 72 20 73 6f 6d 65 20 72 65 user for some re
3130: 61 73 6f 6e 20 2a 2f 0a 09 09 2f 2a 20 52 65 74 ason */.../* Ret
3140: 75 72 6e 20 61 6e 20 75 6e 70 72 69 76 69 6c 65 urn an unprivile
3150: 67 65 64 20 75 73 65 72 20 49 44 20 2a 2f 0a 09 ged user ID */..
3160: 09 41 50 50 46 53 5f 44 45 42 55 47 28 22 55 6e .APPFS_DEBUG("Un
3170: 61 62 6c 65 20 74 6f 20 6c 6f 6f 6b 75 70 20 75 able to lookup u
3180: 73 65 72 20 66 6f 72 20 73 6f 6d 65 20 72 65 61 ser for some rea
3190: 73 6f 6e 2c 20 72 65 74 75 72 6e 69 6e 6e 67 20 son, returninng
31a0: 75 73 65 72 20 49 44 20 6f 66 20 31 22 29 3b 0a user ID of 1");.
31b0: 0a 09 09 72 65 74 75 72 6e 28 31 29 3b 0a 09 7d ...return(1);..}
31c0: 0a 0a 09 72 65 74 75 72 6e 28 63 74 78 2d 3e 75 ...return(ctx->u
31d0: 69 64 29 3b 0a 7d 0a 0a 2f 2a 0a 20 2a 20 44 65 id);.}../*. * De
31e0: 74 65 72 6d 69 6e 65 20 74 68 65 20 47 49 44 20 termine the GID
31f0: 66 6f 72 20 74 68 65 20 75 73 65 72 20 6d 61 6b for the user mak
3200: 69 6e 67 20 74 68 65 20 63 75 72 72 65 6e 74 20 ing the current
3210: 46 55 53 45 20 66 69 6c 65 73 79 73 74 65 6d 20 FUSE filesystem
3220: 72 65 71 75 65 73 74 2e 0a 20 2a 20 54 68 69 73 request.. * This
3230: 20 77 69 6c 6c 20 62 65 20 75 73 65 64 20 74 6f will be used to
3240: 20 6c 6f 6f 6b 75 70 20 74 68 65 20 75 73 65 72 lookup the user
3250: 27 73 20 68 6f 6d 65 20 64 69 72 65 63 74 6f 72 's home director
3260: 79 20 73 6f 20 77 65 20 63 61 6e 20 73 65 61 72 y so we can sear
3270: 63 68 20 66 6f 72 0a 20 2a 20 6c 6f 63 61 6c 6c ch for. * locall
3280: 79 20 6d 6f 64 69 66 69 65 64 20 66 69 6c 65 73 y modified files
3290: 2e 0a 20 2a 2f 0a 73 74 61 74 69 63 20 67 69 64 .. */.static gid
32a0: 5f 74 20 61 70 70 66 73 5f 67 65 74 5f 66 73 67 _t appfs_get_fsg
32b0: 69 64 28 76 6f 69 64 29 20 7b 0a 09 73 74 72 75 id(void) {..stru
32c0: 63 74 20 66 75 73 65 5f 63 6f 6e 74 65 78 74 20 ct fuse_context
32d0: 2a 63 74 78 3b 0a 0a 09 69 66 20 28 21 61 70 70 *ctx;...if (!app
32e0: 66 73 5f 66 75 73 65 5f 73 74 61 72 74 65 64 29 fs_fuse_started)
32f0: 20 7b 0a 09 09 72 65 74 75 72 6e 28 67 65 74 67 {...return(getg
3300: 69 64 28 29 29 3b 0a 09 7d 0a 0a 09 63 74 78 20 id());..}...ctx
3310: 3d 20 66 75 73 65 5f 67 65 74 5f 63 6f 6e 74 65 = fuse_get_conte
3320: 78 74 28 29 3b 0a 09 69 66 20 28 63 74 78 20 3d xt();..if (ctx =
3330: 3d 20 4e 55 4c 4c 29 20 7b 0a 09 09 2f 2a 20 55 = NULL) {.../* U
3340: 6e 61 62 6c 65 20 74 6f 20 6c 6f 6f 6b 75 70 20 nable to lookup
3350: 75 73 65 72 20 66 6f 72 20 73 6f 6d 65 20 72 65 user for some re
3360: 61 73 6f 6e 20 2a 2f 0a 09 09 2f 2a 20 52 65 74 ason */.../* Ret
3370: 75 72 6e 20 61 6e 20 75 6e 70 72 69 76 69 6c 65 urn an unprivile
3380: 67 65 64 20 75 73 65 72 20 49 44 20 2a 2f 0a 09 ged user ID */..
3390: 09 41 50 50 46 53 5f 44 45 42 55 47 28 22 55 6e .APPFS_DEBUG("Un
33a0: 61 62 6c 65 20 74 6f 20 6c 6f 6f 6b 75 70 20 67 able to lookup g
33b0: 72 6f 75 70 20 66 6f 72 20 73 6f 6d 65 20 72 65 roup for some re
33c0: 61 73 6f 6e 2c 20 72 65 74 75 72 6e 69 6e 6e 67 ason, returninng
33d0: 20 67 72 6f 75 70 20 49 44 20 6f 66 20 31 22 29 group ID of 1")
33e0: 3b 0a 0a 09 09 72 65 74 75 72 6e 28 31 29 3b 0a ;....return(1);.
33f0: 09 7d 0a 0a 09 72 65 74 75 72 6e 28 63 74 78 2d .}...return(ctx-
3400: 3e 67 69 64 29 3b 0a 7d 0a 0a 73 74 61 74 69 63 >gid);.}..static
3410: 20 76 6f 69 64 20 61 70 70 66 73 5f 73 69 6d 75 void appfs_simu
3420: 6c 61 74 65 5f 75 73 65 72 5f 66 73 5f 65 6e 74 late_user_fs_ent
3430: 65 72 28 76 6f 69 64 29 20 7b 0a 09 73 65 74 66 er(void) {..setf
3440: 73 75 69 64 28 61 70 70 66 73 5f 67 65 74 5f 66 suid(appfs_get_f
3450: 73 75 69 64 28 29 29 3b 0a 09 73 65 74 66 73 67 suid());..setfsg
3460: 69 64 28 61 70 70 66 73 5f 67 65 74 5f 66 73 67 id(appfs_get_fsg
3470: 69 64 28 29 29 3b 0a 7d 0a 0a 73 74 61 74 69 63 id());.}..static
3480: 20 76 6f 69 64 20 61 70 70 66 73 5f 73 69 6d 75 void appfs_simu
3490: 6c 61 74 65 5f 75 73 65 72 5f 66 73 5f 6c 65 61 late_user_fs_lea
34a0: 76 65 28 76 6f 69 64 29 20 7b 0a 09 73 65 74 66 ve(void) {..setf
34b0: 73 75 69 64 28 30 29 3b 0a 09 73 65 74 66 73 67 suid(0);..setfsg
34c0: 69 64 28 30 29 3b 0a 7d 0a 0a 2f 2a 0a 20 2a 20 id(0);.}../*. *
34d0: 4c 6f 6f 6b 20 75 70 20 74 68 65 20 68 6f 6d 65 Look up the home
34e0: 20 64 69 72 65 63 74 6f 72 79 20 66 6f 72 20 61 directory for a
34f0: 20 67 69 76 65 6e 20 55 49 44 0a 20 2a 20 20 20 given UID. *
3500: 20 20 20 20 20 52 65 74 75 72 6e 73 20 61 20 43 Returns a C
3510: 20 73 74 72 69 6e 67 20 63 6f 6e 74 61 69 6e 69 string containi
3520: 6e 67 20 74 68 65 20 75 73 65 72 27 73 20 68 6f ng the user's ho
3530: 6d 65 20 64 69 72 65 63 74 6f 72 79 20 6f 72 20 me directory or
3540: 4e 55 4c 4c 20 69 66 0a 20 2a 20 20 20 20 20 20 NULL if. *
3550: 20 20 74 68 65 20 75 73 65 72 27 73 20 68 6f 6d the user's hom
3560: 65 20 64 69 72 65 63 74 6f 72 79 20 64 6f 65 73 e directory does
3570: 20 6e 6f 74 20 65 78 69 73 74 20 6f 72 20 69 73 not exist or is
3580: 20 6e 6f 74 20 63 6f 72 72 65 63 74 6c 79 0a 20 not correctly.
3590: 2a 20 20 20 20 20 20 20 20 63 6f 6e 66 69 67 75 * configu
35a0: 72 65 64 0a 20 2a 2f 0a 73 74 61 74 69 63 20 63 red. */.static c
35b0: 68 61 72 20 2a 61 70 70 66 73 5f 67 65 74 5f 68 har *appfs_get_h
35c0: 6f 6d 65 64 69 72 28 75 69 64 5f 74 20 66 73 75 omedir(uid_t fsu
35d0: 69 64 29 20 7b 0a 09 73 74 72 75 63 74 20 70 61 id) {..struct pa
35e0: 73 73 77 64 20 65 6e 74 72 79 2c 20 2a 72 65 73 sswd entry, *res
35f0: 75 6c 74 3b 0a 09 73 74 72 75 63 74 20 73 74 61 ult;..struct sta
3600: 74 20 73 74 62 75 66 3b 0a 09 63 68 61 72 20 62 t stbuf;..char b
3610: 75 66 5b 31 30 32 34 5d 2c 20 2a 72 65 74 76 61 uf[1024], *retva
3620: 6c 3b 0a 09 69 6e 74 20 67 70 75 5f 72 65 74 2c l;..int gpu_ret,
3630: 20 73 74 61 74 5f 72 65 74 3b 0a 0a 09 67 70 75 stat_ret;...gpu
3640: 5f 72 65 74 20 3d 20 67 65 74 70 77 75 69 64 5f _ret = getpwuid_
3650: 72 28 66 73 75 69 64 2c 20 26 65 6e 74 72 79 2c r(fsuid, &entry,
3660: 20 62 75 66 2c 20 73 69 7a 65 6f 66 28 62 75 66 buf, sizeof(buf
3670: 29 2c 20 26 72 65 73 75 6c 74 29 3b 0a 09 69 66 ), &result);..if
3680: 20 28 67 70 75 5f 72 65 74 20 21 3d 20 30 29 20 (gpu_ret != 0)
3690: 7b 0a 09 09 41 50 50 46 53 5f 44 45 42 55 47 28 {...APPFS_DEBUG(
36a0: 22 67 65 74 70 77 75 69 64 5f 72 28 25 6c 6c 75 "getpwuid_r(%llu
36b0: 2c 20 2e 2e 2e 29 20 72 65 74 75 72 6e 65 64 20 , ...) returned
36c0: 69 6e 20 66 61 69 6c 75 72 65 22 2c 20 28 75 6e in failure", (un
36d0: 73 69 67 6e 65 64 20 6c 6f 6e 67 20 6c 6f 6e 67 signed long long
36e0: 29 20 66 73 75 69 64 29 3b 0a 0a 09 09 72 65 74 ) fsuid);....ret
36f0: 75 72 6e 28 4e 55 4c 4c 29 3b 0a 09 7d 0a 0a 09 urn(NULL);..}...
3700: 69 66 20 28 72 65 73 75 6c 74 20 3d 3d 20 4e 55 if (result == NU
3710: 4c 4c 29 20 7b 0a 09 09 41 50 50 46 53 5f 44 45 LL) {...APPFS_DE
3720: 42 55 47 28 22 67 65 74 70 77 75 69 64 5f 72 28 BUG("getpwuid_r(
3730: 25 6c 6c 75 2c 20 2e 2e 2e 29 20 72 65 74 75 72 %llu, ...) retur
3740: 6e 65 64 20 4e 55 4c 4c 20 72 65 73 75 6c 74 22 ned NULL result"
3750: 2c 20 28 75 6e 73 69 67 6e 65 64 20 6c 6f 6e 67 , (unsigned long
3760: 20 6c 6f 6e 67 29 20 66 73 75 69 64 29 3b 0a 0a long) fsuid);..
3770: 09 09 72 65 74 75 72 6e 28 4e 55 4c 4c 29 3b 0a ..return(NULL);.
3780: 09 7d 0a 0a 09 69 66 20 28 72 65 73 75 6c 74 2d .}...if (result-
3790: 3e 70 77 5f 64 69 72 20 3d 3d 20 4e 55 4c 4c 29 >pw_dir == NULL)
37a0: 20 7b 0a 09 09 41 50 50 46 53 5f 44 45 42 55 47 {...APPFS_DEBUG
37b0: 28 22 67 65 74 70 77 75 69 64 5f 72 28 25 6c 6c ("getpwuid_r(%ll
37c0: 75 2c 20 2e 2e 2e 29 20 72 65 74 75 72 6e 65 64 u, ...) returned
37d0: 20 4e 55 4c 4c 20 68 6f 6d 65 20 64 69 72 65 63 NULL home direc
37e0: 74 6f 72 79 22 2c 20 28 75 6e 73 69 67 6e 65 64 tory", (unsigned
37f0: 20 6c 6f 6e 67 20 6c 6f 6e 67 29 20 66 73 75 69 long long) fsui
3800: 64 29 3b 0a 0a 09 09 72 65 74 75 72 6e 28 4e 55 d);....return(NU
3810: 4c 4c 29 3b 0a 09 7d 0a 0a 09 73 74 61 74 5f 72 LL);..}...stat_r
3820: 65 74 20 3d 20 73 74 61 74 28 72 65 73 75 6c 74 et = stat(result
3830: 2d 3e 70 77 5f 64 69 72 2c 20 26 73 74 62 75 66 ->pw_dir, &stbuf
3840: 29 3b 0a 09 69 66 20 28 73 74 61 74 5f 72 65 74 );..if (stat_ret
3850: 20 21 3d 20 30 29 20 7b 0a 09 09 41 50 50 46 53 != 0) {...APPFS
3860: 5f 44 45 42 55 47 28 22 73 74 61 74 28 25 73 29 _DEBUG("stat(%s)
3870: 20 72 65 74 75 72 6e 65 64 20 69 6e 20 66 61 69 returned in fai
3880: 6c 75 72 65 22 2c 20 72 65 73 75 6c 74 2d 3e 70 lure", result->p
3890: 77 5f 64 69 72 29 3b 0a 0a 09 09 72 65 74 75 72 w_dir);....retur
38a0: 6e 28 4e 55 4c 4c 29 3b 0a 09 7d 0a 0a 09 69 66 n(NULL);..}...if
38b0: 20 28 73 74 62 75 66 2e 73 74 5f 75 69 64 20 21 (stbuf.st_uid !
38c0: 3d 20 66 73 75 69 64 29 20 7b 0a 09 09 41 50 50 = fsuid) {...APP
38d0: 46 53 5f 44 45 42 55 47 28 22 55 49 44 20 6d 69 FS_DEBUG("UID mi
38e0: 73 2d 6d 61 74 63 68 20 6f 6e 20 75 73 65 72 20 s-match on user
38f0: 25 6c 6c 75 27 73 20 68 6f 6d 65 20 64 69 72 65 %llu's home dire
3900: 63 74 6f 72 79 20 28 25 73 29 2e 20 20 49 74 27 ctory (%s). It'
3910: 73 20 6f 77 6e 65 64 20 62 79 20 25 6c 6c 75 2e s owned by %llu.
3920: 22 2c 0a 09 09 20 20 20 20 28 75 6e 73 69 67 6e ",... (unsign
3930: 65 64 20 6c 6f 6e 67 20 6c 6f 6e 67 29 20 66 73 ed long long) fs
3940: 75 69 64 2c 0a 09 09 20 20 20 20 72 65 73 75 6c uid,... resul
3950: 74 2d 3e 70 77 5f 64 69 72 2c 0a 09 09 20 20 20 t->pw_dir,...
3960: 20 28 75 6e 73 69 67 6e 65 64 20 6c 6f 6e 67 20 (unsigned long
3970: 6c 6f 6e 67 29 20 73 74 62 75 66 2e 73 74 5f 75 long) stbuf.st_u
3980: 69 64 0a 09 09 29 3b 0a 0a 09 09 72 65 74 75 72 id...);....retur
3990: 6e 28 4e 55 4c 4c 29 3b 0a 09 7d 0a 0a 09 72 65 n(NULL);..}...re
39a0: 74 76 61 6c 20 3d 20 73 74 72 64 75 70 28 72 65 tval = strdup(re
39b0: 73 75 6c 74 2d 3e 70 77 5f 64 69 72 29 3b 0a 0a sult->pw_dir);..
39c0: 09 72 65 74 75 72 6e 28 72 65 74 76 61 6c 29 3b .return(retval);
39d0: 0a 7d 0a 0a 2f 2a 0a 20 2a 20 47 65 6e 65 72 61 .}../*. * Genera
39e0: 74 65 20 61 6e 20 69 6e 6f 64 65 20 66 6f 72 20 te an inode for
39f0: 61 20 67 69 76 65 6e 20 70 61 74 68 2e 20 20 54 a given path. T
3a00: 68 65 20 69 6e 6f 64 65 20 73 68 6f 75 6c 64 20 he inode should
3a10: 62 65 20 63 6f 6d 70 75 74 65 64 20 69 6e 20 73 be computed in s
3a20: 75 63 68 0a 20 2a 20 61 20 77 61 79 20 74 68 61 uch. * a way tha
3a30: 74 20 69 74 20 69 73 20 75 6e 6c 69 6b 65 6c 79 t it is unlikely
3a40: 20 74 6f 20 62 65 20 64 75 70 6c 69 63 61 74 65 to be duplicate
3a50: 64 20 61 6e 64 20 72 65 6d 61 69 6e 73 20 74 68 d and remains th
3a60: 65 20 73 61 6d 65 20 66 6f 72 20 61 20 67 69 76 e same for a giv
3a70: 65 6e 0a 20 2a 20 66 69 6c 65 0a 20 2a 0a 20 2a en. * file. *. *
3a80: 20 43 75 72 72 65 6e 74 20 69 6d 70 6c 65 6d 65 Current impleme
3a90: 6e 74 61 74 69 6f 6e 20 69 73 20 61 6e 20 46 4e ntation is an FN
3aa0: 56 2d 31 61 20 33 32 2d 62 69 74 0a 20 2a 2f 0a V-1a 32-bit. */.
3ab0: 23 69 66 20 55 49 4e 54 5f 4d 41 58 20 3c 20 34 #if UINT_MAX < 4
3ac0: 32 39 34 39 36 37 32 39 35 0a 23 65 72 72 6f 72 294967295.#error
3ad0: 20 49 6e 74 65 67 65 72 20 73 69 7a 65 20 69 73 Integer size is
3ae0: 20 74 6f 6f 20 73 6d 61 6c 6c 20 0a 23 65 6e 64 too small .#end
3af0: 69 66 0a 73 74 61 74 69 63 20 75 6e 73 69 67 6e if.static unsign
3b00: 65 64 20 6c 6f 6e 67 20 6c 6f 6e 67 20 61 70 70 ed long long app
3b10: 66 73 5f 67 65 74 5f 70 61 74 68 5f 69 6e 6f 64 fs_get_path_inod
3b20: 65 28 63 6f 6e 73 74 20 63 68 61 72 20 2a 70 61 e(const char *pa
3b30: 74 68 2c 20 69 6e 74 20 75 69 64 29 20 7b 0a 09 th, int uid) {..
3b40: 75 6e 73 69 67 6e 65 64 20 69 6e 74 20 72 65 74 unsigned int ret
3b50: 76 61 6c 3b 0a 09 63 6f 6e 73 74 20 75 6e 73 69 val;..const unsi
3b60: 67 6e 65 64 20 63 68 61 72 20 2a 70 3b 0a 0a 09 gned char *p;...
3b70: 72 65 74 76 61 6c 20 3d 20 32 31 36 36 31 33 36 retval = 2166136
3b80: 32 36 31 3b 20 2f 2a 20 46 4e 56 2d 31 61 20 33 261; /* FNV-1a 3
3b90: 32 2d 62 69 74 20 6f 66 66 73 65 74 5f 62 61 73 2-bit offset_bas
3ba0: 69 73 20 2a 2f 0a 0a 09 66 6f 72 20 28 70 20 3d is */...for (p =
3bb0: 20 28 75 6e 73 69 67 6e 65 64 20 63 68 61 72 20 (unsigned char
3bc0: 2a 29 20 70 61 74 68 3b 20 2a 70 3b 20 70 2b 2b *) path; *p; p++
3bd0: 29 20 7b 0a 09 09 72 65 74 76 61 6c 20 5e 3d 20 ) {...retval ^=
3be0: 28 69 6e 74 29 20 2a 70 3b 0a 23 69 66 20 30 0a (int) *p;.#if 0.
3bf0: 09 09 72 65 74 76 61 6c 20 2a 3d 20 31 36 37 37 ..retval *= 1677
3c00: 37 36 31 39 3b 20 2f 2a 20 46 4e 56 2d 31 61 20 7619; /* FNV-1a
3c10: 33 32 2d 62 69 74 20 70 72 69 6d 65 20 2a 2f 0a 32-bit prime */.
3c20: 23 65 6c 73 65 0a 09 09 2f 2a 20 47 43 43 20 4f #else.../* GCC O
3c30: 70 74 69 6d 69 7a 65 64 20 72 65 70 6c 61 63 65 ptimized replace
3c40: 6d 65 6e 74 20 2a 2f 0a 09 09 72 65 74 76 61 6c ment */...retval
3c50: 20 2b 3d 20 28 72 65 74 76 61 6c 20 3c 3c 20 31 += (retval << 1
3c60: 29 20 2b 20 28 72 65 74 76 61 6c 20 3c 3c 20 34 ) + (retval << 4
3c70: 29 20 2b 20 28 72 65 74 76 61 6c 20 3c 3c 20 37 ) + (retval << 7
3c80: 29 20 2b 20 28 72 65 74 76 61 6c 20 3c 3c 20 38 ) + (retval << 8
3c90: 29 20 2b 20 28 72 65 74 76 61 6c 20 3c 3c 20 32 ) + (retval << 2
3ca0: 34 29 3b 0a 23 65 6e 64 69 66 0a 09 7d 0a 0a 09 4);.#endif..}...
3cb0: 69 66 20 28 75 69 64 20 3e 3d 20 30 29 20 7b 0a if (uid >= 0) {.
3cc0: 09 09 72 65 74 76 61 6c 20 2b 3d 20 75 69 64 3b ..retval += uid;
3cd0: 0a 09 09 72 65 74 76 61 6c 2b 2b 3b 0a 09 7d 0a ...retval++;..}.
3ce0: 0a 09 41 50 50 46 53 5f 44 45 42 55 47 28 22 4c ..APPFS_DEBUG("L
3cf0: 6f 6f 6b 65 64 20 75 70 20 69 6e 6f 64 65 20 6e ooked up inode n
3d00: 75 6d 62 65 72 20 66 6f 72 20 70 61 74 68 3d 25 umber for path=%
3d10: 73 2c 75 69 64 3d 25 69 3a 20 25 75 22 2c 20 70 s,uid=%i: %u", p
3d20: 61 74 68 2c 20 75 69 64 2c 20 72 65 74 76 61 6c ath, uid, retval
3d30: 29 3b 0a 0a 09 72 65 74 75 72 6e 28 72 65 74 76 );...return(retv
3d40: 61 6c 29 3b 0a 7d 0a 0a 2f 2a 0a 20 2a 20 43 61 al);.}../*. * Ca
3d50: 63 68 65 20 47 65 74 20 50 61 74 68 20 49 6e 66 che Get Path Inf
3d60: 6f 20 6c 6f 6f 6b 75 70 73 20 66 6f 72 20 73 70 o lookups for sp
3d70: 65 65 64 0a 20 2a 2f 0a 73 74 61 74 69 63 20 69 eed. */.static i
3d80: 6e 74 20 61 70 70 66 73 5f 67 65 74 5f 70 61 74 nt appfs_get_pat
3d90: 68 5f 69 6e 66 6f 5f 63 61 63 68 65 5f 67 65 74 h_info_cache_get
3da0: 28 63 6f 6e 73 74 20 63 68 61 72 20 2a 70 61 74 (const char *pat
3db0: 68 2c 20 75 69 64 5f 74 20 75 69 64 2c 20 73 74 h, uid_t uid, st
3dc0: 72 75 63 74 20 61 70 70 66 73 5f 70 61 74 68 69 ruct appfs_pathi
3dd0: 6e 66 6f 20 2a 70 61 74 68 69 6e 66 6f 29 20 7b nfo *pathinfo) {
3de0: 0a 09 75 6e 73 69 67 6e 65 64 20 69 6e 74 20 68 ..unsigned int h
3df0: 61 73 68 5f 69 64 78 3b 0a 09 69 6e 74 20 70 74 ash_idx;..int pt
3e00: 68 72 65 61 64 5f 72 65 74 3b 0a 09 69 6e 74 20 hread_ret;..int
3e10: 72 65 74 76 61 6c 3b 0a 0a 09 72 65 74 76 61 6c retval;...retval
3e20: 20 3d 20 31 3b 0a 0a 09 70 74 68 72 65 61 64 5f = 1;...pthread_
3e30: 72 65 74 20 3d 20 70 74 68 72 65 61 64 5f 6d 75 ret = pthread_mu
3e40: 74 65 78 5f 6c 6f 63 6b 28 26 61 70 70 66 73 5f tex_lock(&appfs_
3e50: 70 61 74 68 5f 69 6e 66 6f 5f 63 61 63 68 65 5f path_info_cache_
3e60: 6d 75 74 65 78 29 3b 0a 09 69 66 20 28 70 74 68 mutex);..if (pth
3e70: 72 65 61 64 5f 72 65 74 20 21 3d 20 30 29 20 7b read_ret != 0) {
3e80: 0a 09 09 41 50 50 46 53 5f 44 45 42 55 47 28 22 ...APPFS_DEBUG("
3e90: 55 6e 61 62 6c 65 20 74 6f 20 6c 6f 63 6b 20 70 Unable to lock p
3ea0: 61 74 68 5f 69 6e 66 6f 20 63 61 63 68 65 20 6d ath_info cache m
3eb0: 75 74 65 78 20 21 22 29 3b 0a 0a 09 09 72 65 74 utex !");....ret
3ec0: 75 72 6e 28 2d 31 29 3b 0a 09 7d 0a 0a 09 41 50 urn(-1);..}...AP
3ed0: 50 46 53 5f 44 45 42 55 47 28 22 4c 6f 6f 6b 69 PFS_DEBUG("Looki
3ee0: 6e 67 20 75 70 20 63 61 63 68 65 20 65 6e 74 72 ng up cache entr
3ef0: 79 20 66 6f 72 20 70 61 74 68 3d 25 73 2c 75 69 y for path=%s,ui
3f00: 64 3d 25 6c 6c 69 2e 2e 2e 22 2c 20 70 61 74 68 d=%lli...", path
3f10: 2c 20 28 6c 6f 6e 67 20 6c 6f 6e 67 29 20 75 69 , (long long) ui
3f20: 64 29 3b 0a 0a 09 69 66 20 28 61 70 70 66 73 5f d);...if (appfs_
3f30: 70 61 74 68 5f 69 6e 66 6f 5f 63 61 63 68 65 20 path_info_cache
3f40: 21 3d 20 4e 55 4c 4c 29 20 7b 0a 09 09 68 61 73 != NULL) {...has
3f50: 68 5f 69 64 78 20 3d 20 28 61 70 70 66 73 5f 67 h_idx = (appfs_g
3f60: 65 74 5f 70 61 74 68 5f 69 6e 6f 64 65 28 70 61 et_path_inode(pa
3f70: 74 68 2c 20 75 69 64 29 29 20 25 20 61 70 70 66 th, uid)) % appf
3f80: 73 5f 70 61 74 68 5f 69 6e 66 6f 5f 63 61 63 68 s_path_info_cach
3f90: 65 5f 73 69 7a 65 3b 0a 0a 09 09 69 66 20 28 61 e_size;....if (a
3fa0: 70 70 66 73 5f 70 61 74 68 5f 69 6e 66 6f 5f 63 ppfs_path_info_c
3fb0: 61 63 68 65 5b 68 61 73 68 5f 69 64 78 5d 2e 5f ache[hash_idx]._
3fc0: 63 61 63 68 65 5f 70 61 74 68 20 21 3d 20 4e 55 cache_path != NU
3fd0: 4c 4c 29 20 7b 0a 09 09 09 69 66 20 28 73 74 72 LL) {....if (str
3fe0: 63 6d 70 28 61 70 70 66 73 5f 70 61 74 68 5f 69 cmp(appfs_path_i
3ff0: 6e 66 6f 5f 63 61 63 68 65 5b 68 61 73 68 5f 69 nfo_cache[hash_i
4000: 64 78 5d 2e 5f 63 61 63 68 65 5f 70 61 74 68 2c dx]._cache_path,
4010: 20 70 61 74 68 29 20 3d 3d 20 30 20 26 26 20 61 path) == 0 && a
4020: 70 70 66 73 5f 70 61 74 68 5f 69 6e 66 6f 5f 63 ppfs_path_info_c
4030: 61 63 68 65 5b 68 61 73 68 5f 69 64 78 5d 2e 5f ache[hash_idx]._
4040: 63 61 63 68 65 5f 75 69 64 20 3d 3d 20 75 69 64 cache_uid == uid
4050: 29 20 7b 0a 09 09 09 09 72 65 74 76 61 6c 20 3d ) {.....retval =
4060: 20 30 3b 0a 0a 09 09 09 09 6d 65 6d 63 70 79 28 0;......memcpy(
4070: 70 61 74 68 69 6e 66 6f 2c 20 26 61 70 70 66 73 pathinfo, &appfs
4080: 5f 70 61 74 68 5f 69 6e 66 6f 5f 63 61 63 68 65 _path_info_cache
4090: 5b 68 61 73 68 5f 69 64 78 5d 2c 20 73 69 7a 65 [hash_idx], size
40a0: 6f 66 28 2a 70 61 74 68 69 6e 66 6f 29 29 3b 0a of(*pathinfo));.
40b0: 09 09 09 09 70 61 74 68 69 6e 66 6f 2d 3e 5f 63 ....pathinfo->_c
40c0: 61 63 68 65 5f 70 61 74 68 20 3d 20 4e 55 4c 4c ache_path = NULL
40d0: 3b 0a 09 09 09 7d 0a 09 09 7d 0a 09 7d 0a 0a 09 ;....}...}..}...
40e0: 70 74 68 72 65 61 64 5f 72 65 74 20 3d 20 70 74 pthread_ret = pt
40f0: 68 72 65 61 64 5f 6d 75 74 65 78 5f 75 6e 6c 6f hread_mutex_unlo
4100: 63 6b 28 26 61 70 70 66 73 5f 70 61 74 68 5f 69 ck(&appfs_path_i
4110: 6e 66 6f 5f 63 61 63 68 65 5f 6d 75 74 65 78 29 nfo_cache_mutex)
4120: 3b 0a 09 69 66 20 28 70 74 68 72 65 61 64 5f 72 ;..if (pthread_r
4130: 65 74 20 21 3d 20 30 29 20 7b 0a 09 09 41 50 50 et != 0) {...APP
4140: 46 53 5f 44 45 42 55 47 28 22 55 6e 61 62 6c 65 FS_DEBUG("Unable
4150: 20 74 6f 20 75 6e 6c 6f 63 6b 20 70 61 74 68 5f to unlock path_
4160: 69 6e 66 6f 20 63 61 63 68 65 20 6d 75 74 65 78 info cache mutex
4170: 20 21 22 29 3b 0a 0a 09 09 72 65 74 75 72 6e 28 !");....return(
4180: 2d 31 29 3b 0a 09 7d 0a 0a 09 69 66 20 28 72 65 -1);..}...if (re
4190: 74 76 61 6c 20 3d 3d 20 30 29 20 7b 0a 09 09 41 tval == 0) {...A
41a0: 50 50 46 53 5f 44 45 42 55 47 28 22 43 61 63 68 PPFS_DEBUG("Cach
41b0: 65 20 68 69 74 20 6f 6e 20 70 61 74 68 3d 25 73 e hit on path=%s
41c0: 2c 75 69 64 3d 25 6c 6c 69 22 2c 20 70 61 74 68 ,uid=%lli", path
41d0: 2c 20 28 6c 6f 6e 67 20 6c 6f 6e 67 29 20 75 69 , (long long) ui
41e0: 64 29 3b 0a 09 7d 20 65 6c 73 65 20 7b 0a 09 09 d);..} else {...
41f0: 41 50 50 46 53 5f 44 45 42 55 47 28 22 43 61 63 APPFS_DEBUG("Cac
4200: 68 65 20 6d 69 73 73 20 6f 6e 20 70 61 74 68 3d he miss on path=
4210: 25 73 2c 75 69 64 3d 25 6c 6c 69 22 2c 20 70 61 %s,uid=%lli", pa
4220: 74 68 2c 20 28 6c 6f 6e 67 20 6c 6f 6e 67 29 20 th, (long long)
4230: 75 69 64 29 3b 0a 09 7d 0a 0a 09 72 65 74 75 72 uid);..}...retur
4240: 6e 28 72 65 74 76 61 6c 29 3b 0a 7d 0a 0a 73 74 n(retval);.}..st
4250: 61 74 69 63 20 76 6f 69 64 20 61 70 70 66 73 5f atic void appfs_
4260: 67 65 74 5f 70 61 74 68 5f 69 6e 66 6f 5f 63 61 get_path_info_ca
4270: 63 68 65 5f 61 64 64 28 63 6f 6e 73 74 20 63 68 che_add(const ch
4280: 61 72 20 2a 70 61 74 68 2c 20 75 69 64 5f 74 20 ar *path, uid_t
4290: 75 69 64 2c 20 73 74 72 75 63 74 20 61 70 70 66 uid, struct appf
42a0: 73 5f 70 61 74 68 69 6e 66 6f 20 2a 70 61 74 68 s_pathinfo *path
42b0: 69 6e 66 6f 29 20 7b 0a 09 75 6e 73 69 67 6e 65 info) {..unsigne
42c0: 64 20 69 6e 74 20 68 61 73 68 5f 69 64 78 3b 0a d int hash_idx;.
42d0: 09 69 6e 74 20 70 74 68 72 65 61 64 5f 72 65 74 .int pthread_ret
42e0: 3b 0a 0a 09 70 74 68 72 65 61 64 5f 72 65 74 20 ;...pthread_ret
42f0: 3d 20 70 74 68 72 65 61 64 5f 6d 75 74 65 78 5f = pthread_mutex_
4300: 6c 6f 63 6b 28 26 61 70 70 66 73 5f 70 61 74 68 lock(&appfs_path
4310: 5f 69 6e 66 6f 5f 63 61 63 68 65 5f 6d 75 74 65 _info_cache_mute
4320: 78 29 3b 0a 09 69 66 20 28 70 74 68 72 65 61 64 x);..if (pthread
4330: 5f 72 65 74 20 21 3d 20 30 29 20 7b 0a 09 09 41 _ret != 0) {...A
4340: 50 50 46 53 5f 44 45 42 55 47 28 22 55 6e 61 62 PPFS_DEBUG("Unab
4350: 6c 65 20 74 6f 20 6c 6f 63 6b 20 70 61 74 68 5f le to lock path_
4360: 69 6e 66 6f 20 63 61 63 68 65 20 6d 75 74 65 78 info cache mutex
4370: 20 21 22 29 3b 0a 0a 09 09 72 65 74 75 72 6e 3b !");....return;
4380: 0a 09 7d 0a 0a 09 69 66 20 28 61 70 70 66 73 5f ..}...if (appfs_
4390: 70 61 74 68 5f 69 6e 66 6f 5f 63 61 63 68 65 20 path_info_cache
43a0: 3d 3d 20 4e 55 4c 4c 29 20 7b 0a 09 09 61 70 70 == NULL) {...app
43b0: 66 73 5f 70 61 74 68 5f 69 6e 66 6f 5f 63 61 63 fs_path_info_cac
43c0: 68 65 20 3d 20 63 61 6c 6c 6f 63 28 61 70 70 66 he = calloc(appf
43d0: 73 5f 70 61 74 68 5f 69 6e 66 6f 5f 63 61 63 68 s_path_info_cach
43e0: 65 5f 73 69 7a 65 2c 20 73 69 7a 65 6f 66 28 2a e_size, sizeof(*
43f0: 61 70 70 66 73 5f 70 61 74 68 5f 69 6e 66 6f 5f appfs_path_info_
4400: 63 61 63 68 65 29 29 3b 0a 09 7d 0a 0a 09 68 61 cache));..}...ha
4410: 73 68 5f 69 64 78 20 3d 20 28 61 70 70 66 73 5f sh_idx = (appfs_
4420: 67 65 74 5f 70 61 74 68 5f 69 6e 6f 64 65 28 70 get_path_inode(p
4430: 61 74 68 2c 20 75 69 64 29 29 20 25 20 61 70 70 ath, uid)) % app
4440: 66 73 5f 70 61 74 68 5f 69 6e 66 6f 5f 63 61 63 fs_path_info_cac
4450: 68 65 5f 73 69 7a 65 3b 0a 0a 09 69 66 20 28 61 he_size;...if (a
4460: 70 70 66 73 5f 70 61 74 68 5f 69 6e 66 6f 5f 63 ppfs_path_info_c
4470: 61 63 68 65 5b 68 61 73 68 5f 69 64 78 5d 2e 5f ache[hash_idx]._
4480: 63 61 63 68 65 5f 70 61 74 68 20 21 3d 20 4e 55 cache_path != NU
4490: 4c 4c 29 20 7b 0a 09 09 66 72 65 65 28 61 70 70 LL) {...free(app
44a0: 66 73 5f 70 61 74 68 5f 69 6e 66 6f 5f 63 61 63 fs_path_info_cac
44b0: 68 65 5b 68 61 73 68 5f 69 64 78 5d 2e 5f 63 61 he[hash_idx]._ca
44c0: 63 68 65 5f 70 61 74 68 29 3b 0a 09 7d 0a 0a 09 che_path);..}...
44d0: 6d 65 6d 63 70 79 28 26 61 70 70 66 73 5f 70 61 memcpy(&appfs_pa
44e0: 74 68 5f 69 6e 66 6f 5f 63 61 63 68 65 5b 68 61 th_info_cache[ha
44f0: 73 68 5f 69 64 78 5d 2c 20 70 61 74 68 69 6e 66 sh_idx], pathinf
4500: 6f 2c 20 73 69 7a 65 6f 66 28 2a 70 61 74 68 69 o, sizeof(*pathi
4510: 6e 66 6f 29 29 3b 0a 0a 09 61 70 70 66 73 5f 70 nfo));...appfs_p
4520: 61 74 68 5f 69 6e 66 6f 5f 63 61 63 68 65 5b 68 ath_info_cache[h
4530: 61 73 68 5f 69 64 78 5d 2e 5f 63 61 63 68 65 5f ash_idx]._cache_
4540: 70 61 74 68 20 3d 20 73 74 72 64 75 70 28 70 61 path = strdup(pa
4550: 74 68 29 3b 0a 09 61 70 70 66 73 5f 70 61 74 68 th);..appfs_path
4560: 5f 69 6e 66 6f 5f 63 61 63 68 65 5b 68 61 73 68 _info_cache[hash
4570: 5f 69 64 78 5d 2e 5f 63 61 63 68 65 5f 75 69 64 _idx]._cache_uid
4580: 20 20 3d 20 75 69 64 3b 0a 0a 09 70 74 68 72 65 = uid;...pthre
4590: 61 64 5f 72 65 74 20 3d 20 70 74 68 72 65 61 64 ad_ret = pthread
45a0: 5f 6d 75 74 65 78 5f 75 6e 6c 6f 63 6b 28 26 61 _mutex_unlock(&a
45b0: 70 70 66 73 5f 70 61 74 68 5f 69 6e 66 6f 5f 63 ppfs_path_info_c
45c0: 61 63 68 65 5f 6d 75 74 65 78 29 3b 0a 09 69 66 ache_mutex);..if
45d0: 20 28 70 74 68 72 65 61 64 5f 72 65 74 20 21 3d (pthread_ret !=
45e0: 20 30 29 20 7b 0a 09 09 41 50 50 46 53 5f 44 45 0) {...APPFS_DE
45f0: 42 55 47 28 22 55 6e 61 62 6c 65 20 74 6f 20 75 BUG("Unable to u
4600: 6e 6c 6f 63 6b 20 70 61 74 68 5f 69 6e 66 6f 20 nlock path_info
4610: 63 61 63 68 65 20 6d 75 74 65 78 20 21 22 29 3b cache mutex !");
4620: 0a 0a 09 09 72 65 74 75 72 6e 3b 0a 09 7d 0a 0a ....return;..}..
4630: 09 72 65 74 75 72 6e 3b 0a 7d 0a 0a 73 74 61 74 .return;.}..stat
4640: 69 63 20 76 6f 69 64 20 61 70 70 66 73 5f 67 65 ic void appfs_ge
4650: 74 5f 70 61 74 68 5f 69 6e 66 6f 5f 63 61 63 68 t_path_info_cach
4660: 65 5f 72 6d 28 63 6f 6e 73 74 20 63 68 61 72 20 e_rm(const char
4670: 2a 70 61 74 68 2c 20 75 69 64 5f 74 20 75 69 64 *path, uid_t uid
4680: 29 20 7b 0a 09 75 6e 73 69 67 6e 65 64 20 69 6e ) {..unsigned in
4690: 74 20 68 61 73 68 5f 69 64 78 3b 0a 09 69 6e 74 t hash_idx;..int
46a0: 20 70 74 68 72 65 61 64 5f 72 65 74 3b 0a 0a 09 pthread_ret;...
46b0: 70 74 68 72 65 61 64 5f 72 65 74 20 3d 20 70 74 pthread_ret = pt
46c0: 68 72 65 61 64 5f 6d 75 74 65 78 5f 6c 6f 63 6b hread_mutex_lock
46d0: 28 26 61 70 70 66 73 5f 70 61 74 68 5f 69 6e 66 (&appfs_path_inf
46e0: 6f 5f 63 61 63 68 65 5f 6d 75 74 65 78 29 3b 0a o_cache_mutex);.
46f0: 09 69 66 20 28 70 74 68 72 65 61 64 5f 72 65 74 .if (pthread_ret
4700: 20 21 3d 20 30 29 20 7b 0a 09 09 41 50 50 46 53 != 0) {...APPFS
4710: 5f 44 45 42 55 47 28 22 55 6e 61 62 6c 65 20 74 _DEBUG("Unable t
4720: 6f 20 6c 6f 63 6b 20 70 61 74 68 5f 69 6e 66 6f o lock path_info
4730: 20 63 61 63 68 65 20 6d 75 74 65 78 20 21 22 29 cache mutex !")
4740: 3b 0a 0a 09 09 72 65 74 75 72 6e 3b 0a 09 7d 0a ;....return;..}.
4750: 0a 09 69 66 20 28 61 70 70 66 73 5f 70 61 74 68 ..if (appfs_path
4760: 5f 69 6e 66 6f 5f 63 61 63 68 65 20 21 3d 20 4e _info_cache != N
4770: 55 4c 4c 29 20 7b 0a 09 09 68 61 73 68 5f 69 64 ULL) {...hash_id
4780: 78 20 3d 20 28 61 70 70 66 73 5f 67 65 74 5f 70 x = (appfs_get_p
4790: 61 74 68 5f 69 6e 6f 64 65 28 70 61 74 68 2c 20 ath_inode(path,
47a0: 75 69 64 29 29 20 25 20 61 70 70 66 73 5f 70 61 uid)) % appfs_pa
47b0: 74 68 5f 69 6e 66 6f 5f 63 61 63 68 65 5f 73 69 th_info_cache_si
47c0: 7a 65 3b 0a 0a 09 09 69 66 20 28 61 70 70 66 73 ze;....if (appfs
47d0: 5f 70 61 74 68 5f 69 6e 66 6f 5f 63 61 63 68 65 _path_info_cache
47e0: 5b 68 61 73 68 5f 69 64 78 5d 2e 5f 63 61 63 68 [hash_idx]._cach
47f0: 65 5f 70 61 74 68 20 21 3d 20 4e 55 4c 4c 29 20 e_path != NULL)
4800: 7b 0a 09 09 09 66 72 65 65 28 61 70 70 66 73 5f {....free(appfs_
4810: 70 61 74 68 5f 69 6e 66 6f 5f 63 61 63 68 65 5b path_info_cache[
4820: 68 61 73 68 5f 69 64 78 5d 2e 5f 63 61 63 68 65 hash_idx]._cache
4830: 5f 70 61 74 68 29 3b 0a 0a 09 09 09 61 70 70 66 _path);.....appf
4840: 73 5f 70 61 74 68 5f 69 6e 66 6f 5f 63 61 63 68 s_path_info_cach
4850: 65 5b 68 61 73 68 5f 69 64 78 5d 2e 5f 63 61 63 e[hash_idx]._cac
4860: 68 65 5f 70 61 74 68 20 3d 20 4e 55 4c 4c 3b 0a he_path = NULL;.
4870: 09 09 7d 0a 09 7d 0a 0a 09 70 74 68 72 65 61 64 ..}..}...pthread
4880: 5f 72 65 74 20 3d 20 70 74 68 72 65 61 64 5f 6d _ret = pthread_m
4890: 75 74 65 78 5f 75 6e 6c 6f 63 6b 28 26 61 70 70 utex_unlock(&app
48a0: 66 73 5f 70 61 74 68 5f 69 6e 66 6f 5f 63 61 63 fs_path_info_cac
48b0: 68 65 5f 6d 75 74 65 78 29 3b 0a 09 69 66 20 28 he_mutex);..if (
48c0: 70 74 68 72 65 61 64 5f 72 65 74 20 21 3d 20 30 pthread_ret != 0
48d0: 29 20 7b 0a 09 09 41 50 50 46 53 5f 44 45 42 55 ) {...APPFS_DEBU
48e0: 47 28 22 55 6e 61 62 6c 65 20 74 6f 20 75 6e 6c G("Unable to unl
48f0: 6f 63 6b 20 70 61 74 68 5f 69 6e 66 6f 20 63 61 ock path_info ca
4900: 63 68 65 20 6d 75 74 65 78 20 21 22 29 3b 0a 0a che mutex !");..
4910: 09 09 72 65 74 75 72 6e 3b 0a 09 7d 0a 0a 09 72 ..return;..}...r
4920: 65 74 75 72 6e 3b 0a 7d 0a 0a 73 74 61 74 69 63 eturn;.}..static
4930: 20 76 6f 69 64 20 61 70 70 66 73 5f 67 65 74 5f void appfs_get_
4940: 70 61 74 68 5f 69 6e 66 6f 5f 63 61 63 68 65 5f path_info_cache_
4950: 66 6c 75 73 68 28 75 69 64 5f 74 20 75 69 64 2c flush(uid_t uid,
4960: 20 69 6e 74 20 6e 65 77 5f 73 69 7a 65 29 20 7b int new_size) {
4970: 0a 09 75 6e 73 69 67 6e 65 64 20 69 6e 74 20 69 ..unsigned int i
4980: 64 78 3b 0a 09 69 6e 74 20 70 74 68 72 65 61 64 dx;..int pthread
4990: 5f 72 65 74 3b 0a 0a 09 41 50 50 46 53 5f 44 45 _ret;...APPFS_DE
49a0: 42 55 47 28 22 46 6c 75 73 68 69 6e 67 20 41 70 BUG("Flushing Ap
49b0: 70 46 53 20 63 61 63 68 65 20 28 75 69 64 20 3d pFS cache (uid =
49c0: 20 25 6c 6c 69 2c 20 6e 65 77 5f 73 69 7a 65 20 %lli, new_size
49d0: 3d 20 25 69 29 22 2c 20 28 6c 6f 6e 67 20 6c 6f = %i)", (long lo
49e0: 6e 67 29 20 75 69 64 2c 20 6e 65 77 5f 73 69 7a ng) uid, new_siz
49f0: 65 29 3b 0a 0a 09 70 74 68 72 65 61 64 5f 72 65 e);...pthread_re
4a00: 74 20 3d 20 70 74 68 72 65 61 64 5f 6d 75 74 65 t = pthread_mute
4a10: 78 5f 6c 6f 63 6b 28 26 61 70 70 66 73 5f 70 61 x_lock(&appfs_pa
4a20: 74 68 5f 69 6e 66 6f 5f 63 61 63 68 65 5f 6d 75 th_info_cache_mu
4a30: 74 65 78 29 3b 0a 09 69 66 20 28 70 74 68 72 65 tex);..if (pthre
4a40: 61 64 5f 72 65 74 20 21 3d 20 30 29 20 7b 0a 09 ad_ret != 0) {..
4a50: 09 41 50 50 46 53 5f 44 45 42 55 47 28 22 55 6e .APPFS_DEBUG("Un
4a60: 61 62 6c 65 20 74 6f 20 6c 6f 63 6b 20 70 61 74 able to lock pat
4a70: 68 5f 69 6e 66 6f 20 63 61 63 68 65 20 6d 75 74 h_info cache mut
4a80: 65 78 20 21 22 29 3b 0a 0a 09 09 72 65 74 75 72 ex !");....retur
4a90: 6e 3b 0a 09 7d 0a 0a 09 69 66 20 28 61 70 70 66 n;..}...if (appf
4aa0: 73 5f 70 61 74 68 5f 69 6e 66 6f 5f 63 61 63 68 s_path_info_cach
4ab0: 65 20 21 3d 20 4e 55 4c 4c 29 20 7b 0a 09 09 66 e != NULL) {...f
4ac0: 6f 72 20 28 69 64 78 20 3d 20 30 3b 20 69 64 78 or (idx = 0; idx
4ad0: 20 3c 20 61 70 70 66 73 5f 70 61 74 68 5f 69 6e < appfs_path_in
4ae0: 66 6f 5f 63 61 63 68 65 5f 73 69 7a 65 3b 20 69 fo_cache_size; i
4af0: 64 78 2b 2b 29 20 7b 0a 09 09 09 69 66 20 28 61 dx++) {....if (a
4b00: 70 70 66 73 5f 70 61 74 68 5f 69 6e 66 6f 5f 63 ppfs_path_info_c
4b10: 61 63 68 65 5b 69 64 78 5d 2e 5f 63 61 63 68 65 ache[idx]._cache
4b20: 5f 70 61 74 68 20 21 3d 20 4e 55 4c 4c 29 20 7b _path != NULL) {
4b30: 0a 09 09 09 09 69 66 20 28 75 69 64 20 21 3d 20 .....if (uid !=
4b40: 28 28 75 69 64 5f 74 29 20 2d 31 29 29 20 7b 0a ((uid_t) -1)) {.
4b50: 09 09 09 09 09 69 66 20 28 61 70 70 66 73 5f 70 .....if (appfs_p
4b60: 61 74 68 5f 69 6e 66 6f 5f 63 61 63 68 65 5b 69 ath_info_cache[i
4b70: 64 78 5d 2e 5f 63 61 63 68 65 5f 75 69 64 20 21 dx]._cache_uid !
4b80: 3d 20 75 69 64 29 20 7b 0a 09 09 09 09 09 09 63 = uid) {.......c
4b90: 6f 6e 74 69 6e 75 65 3b 0a 09 09 09 09 09 7d 0a ontinue;......}.
4ba0: 09 09 09 09 7d 0a 0a 09 09 09 09 66 72 65 65 28 ....}......free(
4bb0: 61 70 70 66 73 5f 70 61 74 68 5f 69 6e 66 6f 5f appfs_path_info_
4bc0: 63 61 63 68 65 5b 69 64 78 5d 2e 5f 63 61 63 68 cache[idx]._cach
4bd0: 65 5f 70 61 74 68 29 3b 0a 0a 09 09 09 09 61 70 e_path);......ap
4be0: 70 66 73 5f 70 61 74 68 5f 69 6e 66 6f 5f 63 61 pfs_path_info_ca
4bf0: 63 68 65 5b 69 64 78 5d 2e 5f 63 61 63 68 65 5f che[idx]._cache_
4c00: 70 61 74 68 20 3d 20 4e 55 4c 4c 3b 0a 09 09 09 path = NULL;....
4c10: 7d 0a 09 09 7d 0a 09 7d 0a 0a 09 69 66 20 28 75 }...}..}...if (u
4c20: 69 64 20 3d 3d 20 28 28 75 69 64 5f 74 29 20 2d id == ((uid_t) -
4c30: 31 29 29 20 7b 0a 09 09 66 72 65 65 28 61 70 70 1)) {...free(app
4c40: 66 73 5f 70 61 74 68 5f 69 6e 66 6f 5f 63 61 63 fs_path_info_cac
4c50: 68 65 29 3b 0a 0a 09 09 61 70 70 66 73 5f 70 61 he);....appfs_pa
4c60: 74 68 5f 69 6e 66 6f 5f 63 61 63 68 65 20 3d 20 th_info_cache =
4c70: 4e 55 4c 4c 3b 0a 0a 09 09 69 66 20 28 6e 65 77 NULL;....if (new
4c80: 5f 73 69 7a 65 20 21 3d 20 2d 31 29 20 7b 0a 09 _size != -1) {..
4c90: 09 09 61 70 70 66 73 5f 70 61 74 68 5f 69 6e 66 ..appfs_path_inf
4ca0: 6f 5f 63 61 63 68 65 5f 73 69 7a 65 20 3d 20 6e o_cache_size = n
4cb0: 65 77 5f 73 69 7a 65 3b 0a 09 09 7d 0a 09 7d 0a ew_size;...}..}.
4cc0: 0a 09 70 74 68 72 65 61 64 5f 72 65 74 20 3d 20 ..pthread_ret =
4cd0: 70 74 68 72 65 61 64 5f 6d 75 74 65 78 5f 75 6e pthread_mutex_un
4ce0: 6c 6f 63 6b 28 26 61 70 70 66 73 5f 70 61 74 68 lock(&appfs_path
4cf0: 5f 69 6e 66 6f 5f 63 61 63 68 65 5f 6d 75 74 65 _info_cache_mute
4d00: 78 29 3b 0a 09 69 66 20 28 70 74 68 72 65 61 64 x);..if (pthread
4d10: 5f 72 65 74 20 21 3d 20 30 29 20 7b 0a 09 09 41 _ret != 0) {...A
4d20: 50 50 46 53 5f 44 45 42 55 47 28 22 55 6e 61 62 PPFS_DEBUG("Unab
4d30: 6c 65 20 74 6f 20 75 6e 6c 6f 63 6b 20 70 61 74 le to unlock pat
4d40: 68 5f 69 6e 66 6f 20 63 61 63 68 65 20 6d 75 74 h_info cache mut
4d50: 65 78 20 21 22 29 3b 0a 0a 09 09 72 65 74 75 72 ex !");....retur
4d60: 6e 3b 0a 09 7d 0a 0a 09 72 65 74 75 72 6e 3b 0a n;..}...return;.
4d70: 7d 0a 0a 2f 2a 20 47 65 74 20 69 6e 66 6f 72 6d }../* Get inform
4d80: 61 74 69 6f 6e 20 61 62 6f 75 74 20 61 20 70 61 ation about a pa
4d90: 74 68 2c 20 61 6e 64 20 6f 70 74 69 6f 6e 61 6c th, and optional
4da0: 6c 79 20 6c 69 73 74 20 63 68 69 6c 64 72 65 6e ly list children
4db0: 20 2a 2f 0a 73 74 61 74 69 63 20 69 6e 74 20 61 */.static int a
4dc0: 70 70 66 73 5f 67 65 74 5f 70 61 74 68 5f 69 6e ppfs_get_path_in
4dd0: 66 6f 28 63 6f 6e 73 74 20 63 68 61 72 20 2a 70 fo(const char *p
4de0: 61 74 68 2c 20 73 74 72 75 63 74 20 61 70 70 66 ath, struct appf
4df0: 73 5f 70 61 74 68 69 6e 66 6f 20 2a 70 61 74 68 s_pathinfo *path
4e00: 69 6e 66 6f 29 20 7b 0a 09 54 63 6c 5f 49 6e 74 info) {..Tcl_Int
4e10: 65 72 70 20 2a 69 6e 74 65 72 70 3b 0a 09 54 63 erp *interp;..Tc
4e20: 6c 5f 4f 62 6a 20 2a 61 74 74 72 73 5f 64 69 63 l_Obj *attrs_dic
4e30: 74 2c 20 2a 61 74 74 72 5f 76 61 6c 75 65 3b 0a t, *attr_value;.
4e40: 09 63 6f 6e 73 74 20 63 68 61 72 20 2a 61 74 74 .const char *att
4e50: 72 5f 76 61 6c 75 65 5f 73 74 72 2c 20 2a 61 74 r_value_str, *at
4e60: 74 72 5f 76 61 6c 75 65 5f 73 74 72 5f 69 3b 0a tr_value_str_i;.
4e70: 09 54 63 6c 5f 57 69 64 65 49 6e 74 20 61 74 74 .Tcl_WideInt att
4e80: 72 5f 76 61 6c 75 65 5f 77 69 64 65 3b 0a 09 69 r_value_wide;..i
4e90: 6e 74 20 61 74 74 72 5f 76 61 6c 75 65 5f 69 6e nt attr_value_in
4ea0: 74 3b 0a 09 73 74 61 74 69 63 20 5f 5f 74 68 72 t;..static __thr
4eb0: 65 61 64 20 54 63 6c 5f 4f 62 6a 20 2a 61 74 74 ead Tcl_Obj *att
4ec0: 72 5f 6b 65 79 5f 74 79 70 65 20 3d 20 4e 55 4c r_key_type = NUL
4ed0: 4c 2c 20 2a 61 74 74 72 5f 6b 65 79 5f 70 65 72 L, *attr_key_per
4ee0: 6d 73 20 3d 20 4e 55 4c 4c 2c 20 2a 61 74 74 72 ms = NULL, *attr
4ef0: 5f 6b 65 79 5f 73 69 7a 65 20 3d 20 4e 55 4c 4c _key_size = NULL
4f00: 2c 20 2a 61 74 74 72 5f 6b 65 79 5f 74 69 6d 65 , *attr_key_time
4f10: 20 3d 20 4e 55 4c 4c 2c 20 2a 61 74 74 72 5f 6b = NULL, *attr_k
4f20: 65 79 5f 73 6f 75 72 63 65 20 3d 20 4e 55 4c 4c ey_source = NULL
4f30: 2c 20 2a 61 74 74 72 5f 6b 65 79 5f 63 68 69 6c , *attr_key_chil
4f40: 64 63 6f 75 6e 74 20 3d 20 4e 55 4c 4c 2c 20 2a dcount = NULL, *
4f50: 61 74 74 72 5f 6b 65 79 5f 70 61 63 6b 61 67 65 attr_key_package
4f60: 64 20 3d 20 4e 55 4c 4c 3b 0a 09 69 6e 74 20 63 d = NULL;..int c
4f70: 61 63 68 65 5f 72 65 74 3b 0a 09 69 6e 74 20 74 ache_ret;..int t
4f80: 63 6c 5f 72 65 74 3b 0a 09 69 6e 74 20 72 65 74 cl_ret;..int ret
4f90: 76 61 6c 3b 0a 09 75 69 64 5f 74 20 66 73 75 69 val;..uid_t fsui
4fa0: 64 3b 0a 0a 09 72 65 74 76 61 6c 20 3d 20 30 3b d;...retval = 0;
4fb0: 0a 0a 09 66 73 75 69 64 20 3d 20 61 70 70 66 73 ...fsuid = appfs
4fc0: 5f 67 65 74 5f 66 73 75 69 64 28 29 3b 0a 0a 09 _get_fsuid();...
4fd0: 63 61 63 68 65 5f 72 65 74 20 3d 20 61 70 70 66 cache_ret = appf
4fe0: 73 5f 67 65 74 5f 70 61 74 68 5f 69 6e 66 6f 5f s_get_path_info_
4ff0: 63 61 63 68 65 5f 67 65 74 28 70 61 74 68 2c 20 cache_get(path,
5000: 66 73 75 69 64 2c 20 70 61 74 68 69 6e 66 6f 29 fsuid, pathinfo)
5010: 3b 0a 09 69 66 20 28 63 61 63 68 65 5f 72 65 74 ;..if (cache_ret
5020: 20 3d 3d 20 30 29 20 7b 0a 09 09 69 66 20 28 70 == 0) {...if (p
5030: 61 74 68 69 6e 66 6f 2d 3e 74 79 70 65 20 3d 3d athinfo->type ==
5040: 20 41 50 50 46 53 5f 50 41 54 48 54 59 50 45 5f APPFS_PATHTYPE_
5050: 44 4f 45 53 5f 4e 4f 54 5f 45 58 49 53 54 29 20 DOES_NOT_EXIST)
5060: 7b 0a 09 09 09 41 50 50 46 53 5f 44 45 42 55 47 {....APPFS_DEBUG
5070: 28 22 52 65 74 75 72 6e 69 6e 67 20 66 72 6f 6d ("Returning from
5080: 20 63 61 63 68 65 3a 20 64 6f 65 73 20 6e 6f 74 cache: does not
5090: 20 65 78 69 73 74 20 5c 22 25 73 5c 22 22 2c 20 exist \"%s\"",
50a0: 70 61 74 68 29 3b 0a 0a 09 09 09 72 65 74 75 72 path);.....retur
50b0: 6e 28 2d 45 4e 4f 45 4e 54 29 3b 0a 09 09 7d 0a n(-ENOENT);...}.
50c0: 0a 09 09 69 66 20 28 70 61 74 68 69 6e 66 6f 2d ...if (pathinfo-
50d0: 3e 74 79 70 65 20 3d 3d 20 41 50 50 46 53 5f 50 >type == APPFS_P
50e0: 41 54 48 54 59 50 45 5f 49 4e 56 41 4c 49 44 29 ATHTYPE_INVALID)
50f0: 20 7b 0a 09 09 09 41 50 50 46 53 5f 44 45 42 55 {....APPFS_DEBU
5100: 47 28 22 52 65 74 75 72 6e 69 6e 67 20 66 72 6f G("Returning fro
5110: 6d 20 63 61 63 68 65 3a 20 69 6e 76 61 6c 69 64 m cache: invalid
5120: 20 6f 62 6a 65 63 74 20 5c 22 25 73 5c 22 22 2c object \"%s\"",
5130: 20 70 61 74 68 29 3b 0a 0a 09 09 09 72 65 74 75 path);.....retu
5140: 72 6e 28 2d 45 49 4f 29 3b 0a 09 09 7d 0a 0a 09 rn(-EIO);...}...
5150: 09 72 65 74 75 72 6e 28 30 29 3b 0a 09 7d 0a 0a .return(0);..}..
5160: 09 69 6e 74 65 72 70 20 3d 20 61 70 70 66 73 5f .interp = appfs_
5170: 54 63 6c 49 6e 74 65 72 70 28 29 3b 0a 09 69 66 TclInterp();..if
5180: 20 28 69 6e 74 65 72 70 20 3d 3d 20 4e 55 4c 4c (interp == NULL
5190: 29 20 7b 0a 09 09 41 50 50 46 53 5f 44 45 42 55 ) {...APPFS_DEBU
51a0: 47 28 22 65 72 72 6f 72 3a 20 55 6e 61 62 6c 65 G("error: Unable
51b0: 20 74 6f 20 67 65 74 20 61 6e 20 69 6e 74 65 72 to get an inter
51c0: 70 72 65 74 65 72 22 29 3b 0a 0a 09 09 72 65 74 preter");....ret
51d0: 75 72 6e 28 2d 45 49 4f 29 3b 0a 09 7d 0a 0a 09 urn(-EIO);..}...
51e0: 61 70 70 66 73 5f 63 61 6c 6c 5f 6c 69 62 74 63 appfs_call_libtc
51f0: 6c 28 54 63 6c 5f 50 72 65 73 65 72 76 65 28 69 l(Tcl_Preserve(i
5200: 6e 74 65 72 70 29 3b 29 0a 0a 09 74 63 6c 5f 72 nterp);)...tcl_r
5210: 65 74 20 3d 20 61 70 70 66 73 5f 54 63 6c 5f 45 et = appfs_Tcl_E
5220: 76 61 6c 28 69 6e 74 65 72 70 2c 20 32 2c 20 22 val(interp, 2, "
5230: 3a 3a 61 70 70 66 73 3a 3a 67 65 74 61 74 74 72 ::appfs::getattr
5240: 22 2c 20 70 61 74 68 29 3b 0a 09 69 66 20 28 74 ", path);..if (t
5250: 63 6c 5f 72 65 74 20 21 3d 20 54 43 4c 5f 4f 4b cl_ret != TCL_OK
5260: 29 20 7b 0a 09 09 41 50 50 46 53 5f 44 45 42 55 ) {...APPFS_DEBU
5270: 47 28 22 3a 3a 61 70 70 66 73 3a 3a 67 65 74 61 G("::appfs::geta
5280: 74 74 72 28 25 73 29 20 66 61 69 6c 65 64 2e 22 ttr(%s) failed."
5290: 2c 20 70 61 74 68 29 3b 0a 09 09 61 70 70 66 73 , path);...appfs
52a0: 5f 63 61 6c 6c 5f 6c 69 62 74 63 6c 28 0a 09 09 _call_libtcl(...
52b0: 09 41 50 50 46 53 5f 44 45 42 55 47 28 22 54 63 .APPFS_DEBUG("Tc
52c0: 6c 20 45 72 72 6f 72 20 69 73 3a 20 25 73 22 2c l Error is: %s",
52d0: 20 54 63 6c 5f 47 65 74 53 74 72 69 6e 67 52 65 Tcl_GetStringRe
52e0: 73 75 6c 74 28 69 6e 74 65 72 70 29 29 3b 0a 09 sult(interp));..
52f0: 09 29 0a 0a 09 09 70 61 74 68 69 6e 66 6f 2d 3e .)....pathinfo->
5300: 74 79 70 65 20 3d 20 41 50 50 46 53 5f 50 41 54 type = APPFS_PAT
5310: 48 54 59 50 45 5f 44 4f 45 53 5f 4e 4f 54 5f 45 HTYPE_DOES_NOT_E
5320: 58 49 53 54 3b 0a 0a 09 09 61 70 70 66 73 5f 67 XIST;....appfs_g
5330: 65 74 5f 70 61 74 68 5f 69 6e 66 6f 5f 63 61 63 et_path_info_cac
5340: 68 65 5f 61 64 64 28 70 61 74 68 2c 20 66 73 75 he_add(path, fsu
5350: 69 64 2c 20 70 61 74 68 69 6e 66 6f 29 3b 0a 0a id, pathinfo);..
5360: 09 09 61 70 70 66 73 5f 63 61 6c 6c 5f 6c 69 62 ..appfs_call_lib
5370: 74 63 6c 28 54 63 6c 5f 52 65 6c 65 61 73 65 28 tcl(Tcl_Release(
5380: 69 6e 74 65 72 70 29 3b 29 0a 0a 09 09 72 65 74 interp);)....ret
5390: 75 72 6e 28 2d 45 4e 4f 45 4e 54 29 3b 0a 09 7d urn(-ENOENT);..}
53a0: 0a 0a 09 69 66 20 28 61 74 74 72 5f 6b 65 79 5f ...if (attr_key_
53b0: 74 79 70 65 20 3d 3d 20 4e 55 4c 4c 29 20 7b 0a type == NULL) {.
53c0: 09 09 61 70 70 66 73 5f 63 61 6c 6c 5f 6c 69 62 ..appfs_call_lib
53d0: 74 63 6c 28 0a 09 09 09 61 74 74 72 5f 6b 65 79 tcl(....attr_key
53e0: 5f 74 79 70 65 20 20 20 20 20 20 20 3d 20 54 63 _type = Tc
53f0: 6c 5f 4e 65 77 53 74 72 69 6e 67 4f 62 6a 28 22 l_NewStringObj("
5400: 74 79 70 65 22 2c 20 2d 31 29 3b 0a 09 09 09 61 type", -1);....a
5410: 74 74 72 5f 6b 65 79 5f 70 65 72 6d 73 20 20 20 ttr_key_perms
5420: 20 20 20 3d 20 54 63 6c 5f 4e 65 77 53 74 72 69 = Tcl_NewStri
5430: 6e 67 4f 62 6a 28 22 70 65 72 6d 73 22 2c 20 2d ngObj("perms", -
5440: 31 29 3b 0a 09 09 09 61 74 74 72 5f 6b 65 79 5f 1);....attr_key_
5450: 73 69 7a 65 20 20 20 20 20 20 20 3d 20 54 63 6c size = Tcl
5460: 5f 4e 65 77 53 74 72 69 6e 67 4f 62 6a 28 22 73 _NewStringObj("s
5470: 69 7a 65 22 2c 20 2d 31 29 3b 0a 09 09 09 61 74 ize", -1);....at
5480: 74 72 5f 6b 65 79 5f 74 69 6d 65 20 20 20 20 20 tr_key_time
5490: 20 20 3d 20 54 63 6c 5f 4e 65 77 53 74 72 69 6e = Tcl_NewStrin
54a0: 67 4f 62 6a 28 22 74 69 6d 65 22 2c 20 2d 31 29 gObj("time", -1)
54b0: 3b 0a 09 09 09 61 74 74 72 5f 6b 65 79 5f 73 6f ;....attr_key_so
54c0: 75 72 63 65 20 20 20 20 20 3d 20 54 63 6c 5f 4e urce = Tcl_N
54d0: 65 77 53 74 72 69 6e 67 4f 62 6a 28 22 73 6f 75 ewStringObj("sou
54e0: 72 63 65 22 2c 20 2d 31 29 3b 0a 09 09 09 61 74 rce", -1);....at
54f0: 74 72 5f 6b 65 79 5f 63 68 69 6c 64 63 6f 75 6e tr_key_childcoun
5500: 74 20 3d 20 54 63 6c 5f 4e 65 77 53 74 72 69 6e t = Tcl_NewStrin
5510: 67 4f 62 6a 28 22 63 68 69 6c 64 63 6f 75 6e 74 gObj("childcount
5520: 22 2c 20 2d 31 29 3b 0a 09 09 09 61 74 74 72 5f ", -1);....attr_
5530: 6b 65 79 5f 70 61 63 6b 61 67 65 64 20 20 20 3d key_packaged =
5540: 20 54 63 6c 5f 4e 65 77 53 74 72 69 6e 67 4f 62 Tcl_NewStringOb
5550: 6a 28 22 70 61 63 6b 61 67 65 64 22 2c 20 2d 31 j("packaged", -1
5560: 29 3b 0a 0a 09 09 09 54 63 6c 5f 49 6e 63 72 52 );.....Tcl_IncrR
5570: 65 66 43 6f 75 6e 74 28 61 74 74 72 5f 6b 65 79 efCount(attr_key
5580: 5f 74 79 70 65 29 3b 0a 09 09 09 54 63 6c 5f 49 _type);....Tcl_I
5590: 6e 63 72 52 65 66 43 6f 75 6e 74 28 61 74 74 72 ncrRefCount(attr
55a0: 5f 6b 65 79 5f 70 65 72 6d 73 29 3b 0a 09 09 09 _key_perms);....
55b0: 54 63 6c 5f 49 6e 63 72 52 65 66 43 6f 75 6e 74 Tcl_IncrRefCount
55c0: 28 61 74 74 72 5f 6b 65 79 5f 73 69 7a 65 29 3b (attr_key_size);
55d0: 0a 09 09 09 54 63 6c 5f 49 6e 63 72 52 65 66 43 ....Tcl_IncrRefC
55e0: 6f 75 6e 74 28 61 74 74 72 5f 6b 65 79 5f 74 69 ount(attr_key_ti
55f0: 6d 65 29 3b 0a 09 09 09 54 63 6c 5f 49 6e 63 72 me);....Tcl_Incr
5600: 52 65 66 43 6f 75 6e 74 28 61 74 74 72 5f 6b 65 RefCount(attr_ke
5610: 79 5f 73 6f 75 72 63 65 29 3b 0a 09 09 09 54 63 y_source);....Tc
5620: 6c 5f 49 6e 63 72 52 65 66 43 6f 75 6e 74 28 61 l_IncrRefCount(a
5630: 74 74 72 5f 6b 65 79 5f 63 68 69 6c 64 63 6f 75 ttr_key_childcou
5640: 6e 74 29 3b 0a 09 09 09 54 63 6c 5f 49 6e 63 72 nt);....Tcl_Incr
5650: 52 65 66 43 6f 75 6e 74 28 61 74 74 72 5f 6b 65 RefCount(attr_ke
5660: 79 5f 70 61 63 6b 61 67 65 64 29 3b 0a 09 09 29 y_packaged);...)
5670: 0a 09 7d 0a 0a 09 61 70 70 66 73 5f 63 61 6c 6c ..}...appfs_call
5680: 5f 6c 69 62 74 63 6c 28 0a 09 09 61 74 74 72 73 _libtcl(...attrs
5690: 5f 64 69 63 74 20 3d 20 54 63 6c 5f 47 65 74 4f _dict = Tcl_GetO
56a0: 62 6a 52 65 73 75 6c 74 28 69 6e 74 65 72 70 29 bjResult(interp)
56b0: 3b 0a 09 09 74 63 6c 5f 72 65 74 20 3d 20 54 63 ;...tcl_ret = Tc
56c0: 6c 5f 44 69 63 74 4f 62 6a 47 65 74 28 69 6e 74 l_DictObjGet(int
56d0: 65 72 70 2c 20 61 74 74 72 73 5f 64 69 63 74 2c erp, attrs_dict,
56e0: 20 61 74 74 72 5f 6b 65 79 5f 74 79 70 65 2c 20 attr_key_type,
56f0: 26 61 74 74 72 5f 76 61 6c 75 65 29 3b 0a 09 29 &attr_value);..)
5700: 0a 09 69 66 20 28 74 63 6c 5f 72 65 74 20 21 3d ..if (tcl_ret !=
5710: 20 54 43 4c 5f 4f 4b 29 20 7b 0a 09 09 41 50 50 TCL_OK) {...APP
5720: 46 53 5f 44 45 42 55 47 28 22 5b 64 69 63 74 20 FS_DEBUG("[dict
5730: 67 65 74 20 5c 22 74 79 70 65 5c 22 5d 20 66 61 get \"type\"] fa
5740: 69 6c 65 64 22 29 3b 0a 09 09 61 70 70 66 73 5f iled");...appfs_
5750: 63 61 6c 6c 5f 6c 69 62 74 63 6c 28 0a 09 09 09 call_libtcl(....
5760: 41 50 50 46 53 5f 44 45 42 55 47 28 22 54 63 6c APPFS_DEBUG("Tcl
5770: 20 45 72 72 6f 72 20 69 73 3a 20 25 73 22 2c 20 Error is: %s",
5780: 54 63 6c 5f 47 65 74 53 74 72 69 6e 67 52 65 73 Tcl_GetStringRes
5790: 75 6c 74 28 69 6e 74 65 72 70 29 29 3b 0a 09 09 ult(interp));...
57a0: 29 0a 0a 09 09 61 70 70 66 73 5f 63 61 6c 6c 5f )....appfs_call_
57b0: 6c 69 62 74 63 6c 28 54 63 6c 5f 52 65 6c 65 61 libtcl(Tcl_Relea
57c0: 73 65 28 69 6e 74 65 72 70 29 3b 29 0a 0a 09 09 se(interp);)....
57d0: 72 65 74 75 72 6e 28 2d 45 49 4f 29 3b 0a 09 7d return(-EIO);..}
57e0: 0a 0a 09 69 66 20 28 61 74 74 72 5f 76 61 6c 75 ...if (attr_valu
57f0: 65 20 3d 3d 20 4e 55 4c 4c 29 20 7b 0a 09 09 41 e == NULL) {...A
5800: 50 50 46 53 5f 44 45 42 55 47 28 22 65 72 72 6f PPFS_DEBUG("erro
5810: 72 3a 20 55 6e 61 62 6c 65 20 74 6f 20 67 65 74 r: Unable to get
5820: 20 74 79 70 65 20 66 6f 72 20 5c 22 25 73 5c 22 type for \"%s\"
5830: 20 66 72 6f 6d 20 54 63 6c 22 2c 20 70 61 74 68 from Tcl", path
5840: 29 3b 0a 0a 09 09 61 70 70 66 73 5f 63 61 6c 6c );....appfs_call
5850: 5f 6c 69 62 74 63 6c 28 54 63 6c 5f 52 65 6c 65 _libtcl(Tcl_Rele
5860: 61 73 65 28 69 6e 74 65 72 70 29 3b 29 0a 0a 09 ase(interp);)...
5870: 09 72 65 74 75 72 6e 28 2d 45 49 4f 29 3b 0a 09 .return(-EIO);..
5880: 7d 0a 0a 09 70 61 74 68 69 6e 66 6f 2d 3e 70 61 }...pathinfo->pa
5890: 63 6b 61 67 65 64 20 3d 20 30 3b 0a 0a 09 61 70 ckaged = 0;...ap
58a0: 70 66 73 5f 63 61 6c 6c 5f 6c 69 62 74 63 6c 28 pfs_call_libtcl(
58b0: 0a 09 09 61 74 74 72 5f 76 61 6c 75 65 5f 73 74 ...attr_value_st
58c0: 72 20 3d 20 54 63 6c 5f 47 65 74 53 74 72 69 6e r = Tcl_GetStrin
58d0: 67 28 61 74 74 72 5f 76 61 6c 75 65 29 3b 0a 0a g(attr_value);..
58e0: 09 09 73 77 69 74 63 68 20 28 61 74 74 72 5f 76 ..switch (attr_v
58f0: 61 6c 75 65 5f 73 74 72 5b 30 5d 29 20 7b 0a 09 alue_str[0]) {..
5900: 09 09 63 61 73 65 20 27 64 27 3a 20 2f 2a 20 64 ..case 'd': /* d
5910: 69 72 65 63 74 6f 72 79 20 2a 2f 0a 09 09 09 09 irectory */.....
5920: 70 61 74 68 69 6e 66 6f 2d 3e 74 79 70 65 20 3d pathinfo->type =
5930: 20 41 50 50 46 53 5f 50 41 54 48 54 59 50 45 5f APPFS_PATHTYPE_
5940: 44 49 52 45 43 54 4f 52 59 3b 0a 09 09 09 09 70 DIRECTORY;.....p
5950: 61 74 68 69 6e 66 6f 2d 3e 74 79 70 65 69 6e 66 athinfo->typeinf
5960: 6f 2e 64 69 72 2e 63 68 69 6c 64 63 6f 75 6e 74 o.dir.childcount
5970: 20 3d 20 30 3b 0a 0a 09 09 09 09 54 63 6c 5f 44 = 0;......Tcl_D
5980: 69 63 74 4f 62 6a 47 65 74 28 69 6e 74 65 72 70 ictObjGet(interp
5990: 2c 20 61 74 74 72 73 5f 64 69 63 74 2c 20 61 74 , attrs_dict, at
59a0: 74 72 5f 6b 65 79 5f 63 68 69 6c 64 63 6f 75 6e tr_key_childcoun
59b0: 74 2c 20 26 61 74 74 72 5f 76 61 6c 75 65 29 3b t, &attr_value);
59c0: 0a 09 09 09 09 69 66 20 28 61 74 74 72 5f 76 61 .....if (attr_va
59d0: 6c 75 65 20 21 3d 20 4e 55 4c 4c 29 20 7b 0a 09 lue != NULL) {..
59e0: 09 09 09 09 74 63 6c 5f 72 65 74 20 3d 20 54 63 ....tcl_ret = Tc
59f0: 6c 5f 47 65 74 57 69 64 65 49 6e 74 46 72 6f 6d l_GetWideIntFrom
5a00: 4f 62 6a 28 4e 55 4c 4c 2c 20 61 74 74 72 5f 76 Obj(NULL, attr_v
5a10: 61 6c 75 65 2c 20 26 61 74 74 72 5f 76 61 6c 75 alue, &attr_valu
5a20: 65 5f 77 69 64 65 29 3b 0a 09 09 09 09 09 69 66 e_wide);......if
5a30: 20 28 74 63 6c 5f 72 65 74 20 3d 3d 20 54 43 4c (tcl_ret == TCL
5a40: 5f 4f 4b 29 20 7b 0a 09 09 09 09 09 09 70 61 74 _OK) {.......pat
5a50: 68 69 6e 66 6f 2d 3e 74 79 70 65 69 6e 66 6f 2e hinfo->typeinfo.
5a60: 64 69 72 2e 63 68 69 6c 64 63 6f 75 6e 74 20 3d dir.childcount =
5a70: 20 61 74 74 72 5f 76 61 6c 75 65 5f 77 69 64 65 attr_value_wide
5a80: 3b 0a 09 09 09 09 09 7d 0a 09 09 09 09 7d 0a 0a ;......}.....}..
5a90: 09 09 09 09 62 72 65 61 6b 3b 0a 09 09 09 63 61 ....break;....ca
5aa0: 73 65 20 27 66 27 3a 20 2f 2a 20 66 69 6c 65 20 se 'f': /* file
5ab0: 2a 2f 0a 09 09 09 09 70 61 74 68 69 6e 66 6f 2d */.....pathinfo-
5ac0: 3e 74 79 70 65 20 3d 20 41 50 50 46 53 5f 50 41 >type = APPFS_PA
5ad0: 54 48 54 59 50 45 5f 46 49 4c 45 3b 0a 09 09 09 THTYPE_FILE;....
5ae0: 09 70 61 74 68 69 6e 66 6f 2d 3e 74 79 70 65 69 .pathinfo->typei
5af0: 6e 66 6f 2e 66 69 6c 65 2e 73 69 7a 65 20 3d 20 nfo.file.size =
5b00: 30 3b 0a 09 09 09 09 70 61 74 68 69 6e 66 6f 2d 0;.....pathinfo-
5b10: 3e 74 79 70 65 69 6e 66 6f 2e 66 69 6c 65 2e 65 >typeinfo.file.e
5b20: 78 65 63 75 74 61 62 6c 65 20 3d 20 30 3b 0a 09 xecutable = 0;..
5b30: 09 09 09 70 61 74 68 69 6e 66 6f 2d 3e 74 79 70 ...pathinfo->typ
5b40: 65 69 6e 66 6f 2e 66 69 6c 65 2e 73 75 69 64 52 einfo.file.suidR
5b50: 6f 6f 74 20 3d 20 30 3b 0a 09 09 09 09 70 61 74 oot = 0;.....pat
5b60: 68 69 6e 66 6f 2d 3e 74 79 70 65 69 6e 66 6f 2e hinfo->typeinfo.
5b70: 66 69 6c 65 2e 77 6f 72 6c 64 61 63 63 65 73 73 file.worldaccess
5b80: 69 62 6c 65 20 3d 20 30 3b 0a 0a 09 09 09 09 54 ible = 0;......T
5b90: 63 6c 5f 44 69 63 74 4f 62 6a 47 65 74 28 69 6e cl_DictObjGet(in
5ba0: 74 65 72 70 2c 20 61 74 74 72 73 5f 64 69 63 74 terp, attrs_dict
5bb0: 2c 20 61 74 74 72 5f 6b 65 79 5f 73 69 7a 65 2c , attr_key_size,
5bc0: 20 26 61 74 74 72 5f 76 61 6c 75 65 29 3b 0a 09 &attr_value);..
5bd0: 09 09 09 69 66 20 28 61 74 74 72 5f 76 61 6c 75 ...if (attr_valu
5be0: 65 20 21 3d 20 4e 55 4c 4c 29 20 7b 0a 09 09 09 e != NULL) {....
5bf0: 09 09 74 63 6c 5f 72 65 74 20 3d 20 54 63 6c 5f ..tcl_ret = Tcl_
5c00: 47 65 74 57 69 64 65 49 6e 74 46 72 6f 6d 4f 62 GetWideIntFromOb
5c10: 6a 28 4e 55 4c 4c 2c 20 61 74 74 72 5f 76 61 6c j(NULL, attr_val
5c20: 75 65 2c 20 26 61 74 74 72 5f 76 61 6c 75 65 5f ue, &attr_value_
5c30: 77 69 64 65 29 3b 0a 09 09 09 09 09 69 66 20 28 wide);......if (
5c40: 74 63 6c 5f 72 65 74 20 3d 3d 20 54 43 4c 5f 4f tcl_ret == TCL_O
5c50: 4b 29 20 7b 0a 09 09 09 09 09 09 70 61 74 68 69 K) {.......pathi
5c60: 6e 66 6f 2d 3e 74 79 70 65 69 6e 66 6f 2e 66 69 nfo->typeinfo.fi
5c70: 6c 65 2e 73 69 7a 65 20 3d 20 61 74 74 72 5f 76 le.size = attr_v
5c80: 61 6c 75 65 5f 77 69 64 65 3b 0a 09 09 09 09 09 alue_wide;......
5c90: 7d 0a 09 09 09 09 7d 0a 0a 09 09 09 09 54 63 6c }.....}......Tcl
5ca0: 5f 44 69 63 74 4f 62 6a 47 65 74 28 69 6e 74 65 _DictObjGet(inte
5cb0: 72 70 2c 20 61 74 74 72 73 5f 64 69 63 74 2c 20 rp, attrs_dict,
5cc0: 61 74 74 72 5f 6b 65 79 5f 70 65 72 6d 73 2c 20 attr_key_perms,
5cd0: 26 61 74 74 72 5f 76 61 6c 75 65 29 3b 0a 09 09 &attr_value);...
5ce0: 09 09 69 66 20 28 61 74 74 72 5f 76 61 6c 75 65 ..if (attr_value
5cf0: 20 21 3d 20 4e 55 4c 4c 29 20 7b 0a 09 09 09 09 != NULL) {.....
5d00: 09 61 74 74 72 5f 76 61 6c 75 65 5f 73 74 72 20 .attr_value_str
5d10: 3d 20 54 63 6c 5f 47 65 74 53 74 72 69 6e 67 28 = Tcl_GetString(
5d20: 61 74 74 72 5f 76 61 6c 75 65 29 3b 0a 09 09 09 attr_value);....
5d30: 09 09 66 6f 72 20 28 61 74 74 72 5f 76 61 6c 75 ..for (attr_valu
5d40: 65 5f 73 74 72 5f 69 20 3d 20 26 61 74 74 72 5f e_str_i = &attr_
5d50: 76 61 6c 75 65 5f 73 74 72 5b 30 5d 3b 20 2a 61 value_str[0]; *a
5d60: 74 74 72 5f 76 61 6c 75 65 5f 73 74 72 5f 69 20 ttr_value_str_i
5d70: 21 3d 20 27 5c 30 27 3b 20 61 74 74 72 5f 76 61 != '\0'; attr_va
5d80: 6c 75 65 5f 73 74 72 5f 69 2b 2b 29 20 7b 0a 09 lue_str_i++) {..
5d90: 09 09 09 09 09 73 77 69 74 63 68 20 28 2a 61 74 .....switch (*at
5da0: 74 72 5f 76 61 6c 75 65 5f 73 74 72 5f 69 29 20 tr_value_str_i)
5db0: 7b 0a 09 09 09 09 09 09 09 63 61 73 65 20 27 78 {........case 'x
5dc0: 27 3a 0a 09 09 09 09 09 09 09 09 70 61 74 68 69 ':.........pathi
5dd0: 6e 66 6f 2d 3e 74 79 70 65 69 6e 66 6f 2e 66 69 nfo->typeinfo.fi
5de0: 6c 65 2e 65 78 65 63 75 74 61 62 6c 65 20 3d 20 le.executable =
5df0: 31 3b 0a 0a 09 09 09 09 09 09 09 09 62 72 65 61 1;..........brea
5e00: 6b 3b 0a 09 09 09 09 09 09 09 63 61 73 65 20 27 k;........case '
5e10: 55 27 3a 0a 09 09 09 09 09 09 09 09 70 61 74 68 U':.........path
5e20: 69 6e 66 6f 2d 3e 74 79 70 65 69 6e 66 6f 2e 66 info->typeinfo.f
5e30: 69 6c 65 2e 73 75 69 64 52 6f 6f 74 20 3d 20 31 ile.suidRoot = 1
5e40: 3b 0a 0a 09 09 09 09 09 09 09 09 62 72 65 61 6b ;..........break
5e50: 3b 0a 09 09 09 09 09 09 09 63 61 73 65 20 27 2d ;........case '-
5e60: 27 3a 0a 09 09 09 09 09 09 09 09 70 61 74 68 69 ':.........pathi
5e70: 6e 66 6f 2d 3e 74 79 70 65 69 6e 66 6f 2e 66 69 nfo->typeinfo.fi
5e80: 6c 65 2e 77 6f 72 6c 64 61 63 63 65 73 73 69 62 le.worldaccessib
5e90: 6c 65 20 3d 20 31 3b 0a 0a 09 09 09 09 09 09 09 le = 1;.........
5ea0: 09 62 72 65 61 6b 3b 0a 09 09 09 09 09 09 7d 0a .break;.......}.
5eb0: 09 09 09 09 09 7d 0a 09 09 09 09 7d 0a 09 09 09 .....}.....}....
5ec0: 09 62 72 65 61 6b 3b 0a 09 09 09 63 61 73 65 20 .break;....case
5ed0: 27 73 27 3a 20 2f 2a 20 73 79 6d 6c 69 6e 6b 20 's': /* symlink
5ee0: 2a 2f 0a 09 09 09 09 70 61 74 68 69 6e 66 6f 2d */.....pathinfo-
5ef0: 3e 74 79 70 65 20 3d 20 41 50 50 46 53 5f 50 41 >type = APPFS_PA
5f00: 54 48 54 59 50 45 5f 53 59 4d 4c 49 4e 4b 3b 0a THTYPE_SYMLINK;.
5f10: 09 09 09 09 70 61 74 68 69 6e 66 6f 2d 3e 74 79 ....pathinfo->ty
5f20: 70 65 69 6e 66 6f 2e 73 79 6d 6c 69 6e 6b 2e 73 peinfo.symlink.s
5f30: 69 7a 65 20 3d 20 30 3b 0a 09 09 09 09 70 61 74 ize = 0;.....pat
5f40: 68 69 6e 66 6f 2d 3e 74 79 70 65 69 6e 66 6f 2e hinfo->typeinfo.
5f50: 73 79 6d 6c 69 6e 6b 2e 73 6f 75 72 63 65 5b 30 symlink.source[0
5f60: 5d 20 3d 20 27 5c 30 27 3b 0a 0a 09 09 09 09 54 ] = '\0';......T
5f70: 63 6c 5f 44 69 63 74 4f 62 6a 47 65 74 28 69 6e cl_DictObjGet(in
5f80: 74 65 72 70 2c 20 61 74 74 72 73 5f 64 69 63 74 terp, attrs_dict
5f90: 2c 20 61 74 74 72 5f 6b 65 79 5f 73 6f 75 72 63 , attr_key_sourc
5fa0: 65 2c 20 26 61 74 74 72 5f 76 61 6c 75 65 29 3b e, &attr_value);
5fb0: 0a 09 09 09 09 69 66 20 28 61 74 74 72 5f 76 61 .....if (attr_va
5fc0: 6c 75 65 20 21 3d 20 4e 55 4c 4c 29 20 7b 0a 09 lue != NULL) {..
5fd0: 09 09 09 09 61 74 74 72 5f 76 61 6c 75 65 5f 73 ....attr_value_s
5fe0: 74 72 20 3d 20 54 63 6c 5f 47 65 74 53 74 72 69 tr = Tcl_GetStri
5ff0: 6e 67 46 72 6f 6d 4f 62 6a 28 61 74 74 72 5f 76 ngFromObj(attr_v
6000: 61 6c 75 65 2c 20 26 61 74 74 72 5f 76 61 6c 75 alue, &attr_valu
6010: 65 5f 69 6e 74 29 3b 20 0a 0a 09 09 09 09 09 69 e_int); .......i
6020: 66 20 28 28 61 74 74 72 5f 76 61 6c 75 65 5f 69 f ((attr_value_i
6030: 6e 74 20 2b 20 31 29 20 3c 3d 20 73 69 7a 65 6f nt + 1) <= sizeo
6040: 66 28 70 61 74 68 69 6e 66 6f 2d 3e 74 79 70 65 f(pathinfo->type
6050: 69 6e 66 6f 2e 73 79 6d 6c 69 6e 6b 2e 73 6f 75 info.symlink.sou
6060: 72 63 65 29 29 20 7b 0a 09 09 09 09 09 09 70 61 rce)) {.......pa
6070: 74 68 69 6e 66 6f 2d 3e 74 79 70 65 69 6e 66 6f thinfo->typeinfo
6080: 2e 73 79 6d 6c 69 6e 6b 2e 73 69 7a 65 20 3d 20 .symlink.size =
6090: 61 74 74 72 5f 76 61 6c 75 65 5f 69 6e 74 3b 0a attr_value_int;.
60a0: 09 09 09 09 09 09 70 61 74 68 69 6e 66 6f 2d 3e ......pathinfo->
60b0: 74 79 70 65 69 6e 66 6f 2e 73 79 6d 6c 69 6e 6b typeinfo.symlink
60c0: 2e 73 6f 75 72 63 65 5b 61 74 74 72 5f 76 61 6c .source[attr_val
60d0: 75 65 5f 69 6e 74 5d 20 3d 20 27 5c 30 27 3b 0a ue_int] = '\0';.
60e0: 0a 09 09 09 09 09 09 6d 65 6d 63 70 79 28 70 61 .......memcpy(pa
60f0: 74 68 69 6e 66 6f 2d 3e 74 79 70 65 69 6e 66 6f thinfo->typeinfo
6100: 2e 73 79 6d 6c 69 6e 6b 2e 73 6f 75 72 63 65 2c .symlink.source,
6110: 20 61 74 74 72 5f 76 61 6c 75 65 5f 73 74 72 2c attr_value_str,
6120: 20 61 74 74 72 5f 76 61 6c 75 65 5f 69 6e 74 29 attr_value_int)
6130: 3b 0a 09 09 09 09 09 7d 0a 09 09 09 09 7d 0a 09 ;......}.....}..
6140: 09 09 09 62 72 65 61 6b 3b 0a 09 09 09 63 61 73 ...break;....cas
6150: 65 20 27 46 27 3a 20 2f 2a 20 70 69 70 65 2f 66 e 'F': /* pipe/f
6160: 69 66 6f 20 2a 2f 0a 09 09 09 09 70 61 74 68 69 ifo */.....pathi
6170: 6e 66 6f 2d 3e 74 79 70 65 20 3d 20 41 50 50 46 nfo->type = APPF
6180: 53 5f 50 41 54 48 54 59 50 45 5f 46 49 46 4f 3b S_PATHTYPE_FIFO;
6190: 0a 09 09 09 09 62 72 65 61 6b 3b 0a 09 09 09 63 .....break;....c
61a0: 61 73 65 20 27 53 27 3a 20 2f 2a 20 55 4e 49 58 ase 'S': /* UNIX
61b0: 20 64 6f 6d 61 69 6e 20 73 6f 63 6b 65 74 20 2a domain socket *
61c0: 2f 0a 09 09 09 09 70 61 74 68 69 6e 66 6f 2d 3e /.....pathinfo->
61d0: 74 79 70 65 20 3d 20 41 50 50 46 53 5f 50 41 54 type = APPFS_PAT
61e0: 48 54 59 50 45 5f 53 4f 43 4b 45 54 3b 0a 09 09 HTYPE_SOCKET;...
61f0: 09 09 62 72 65 61 6b 3b 0a 09 09 09 64 65 66 61 ..break;....defa
6200: 75 6c 74 3a 0a 09 09 09 09 72 65 74 76 61 6c 20 ult:.....retval
6210: 3d 20 2d 45 49 4f 3b 0a 09 09 7d 0a 0a 09 09 54 = -EIO;...}....T
6220: 63 6c 5f 44 69 63 74 4f 62 6a 47 65 74 28 69 6e cl_DictObjGet(in
6230: 74 65 72 70 2c 20 61 74 74 72 73 5f 64 69 63 74 terp, attrs_dict
6240: 2c 20 61 74 74 72 5f 6b 65 79 5f 70 61 63 6b 61 , attr_key_packa
6250: 67 65 64 2c 20 26 61 74 74 72 5f 76 61 6c 75 65 ged, &attr_value
6260: 29 3b 0a 09 09 69 66 20 28 61 74 74 72 5f 76 61 );...if (attr_va
6270: 6c 75 65 20 21 3d 20 4e 55 4c 4c 29 20 7b 0a 09 lue != NULL) {..
6280: 09 09 70 61 74 68 69 6e 66 6f 2d 3e 70 61 63 6b ..pathinfo->pack
6290: 61 67 65 64 20 3d 20 31 3b 0a 09 09 7d 0a 0a 09 aged = 1;...}...
62a0: 09 54 63 6c 5f 44 69 63 74 4f 62 6a 47 65 74 28 .Tcl_DictObjGet(
62b0: 69 6e 74 65 72 70 2c 20 61 74 74 72 73 5f 64 69 interp, attrs_di
62c0: 63 74 2c 20 61 74 74 72 5f 6b 65 79 5f 74 69 6d ct, attr_key_tim
62d0: 65 2c 20 26 61 74 74 72 5f 76 61 6c 75 65 29 3b e, &attr_value);
62e0: 0a 09 09 69 66 20 28 61 74 74 72 5f 76 61 6c 75 ...if (attr_valu
62f0: 65 20 21 3d 20 4e 55 4c 4c 29 20 7b 0a 09 09 09 e != NULL) {....
6300: 74 63 6c 5f 72 65 74 20 3d 20 54 63 6c 5f 47 65 tcl_ret = Tcl_Ge
6310: 74 57 69 64 65 49 6e 74 46 72 6f 6d 4f 62 6a 28 tWideIntFromObj(
6320: 4e 55 4c 4c 2c 20 61 74 74 72 5f 76 61 6c 75 65 NULL, attr_value
6330: 2c 20 26 61 74 74 72 5f 76 61 6c 75 65 5f 77 69 , &attr_value_wi
6340: 64 65 29 3b 0a 09 09 09 69 66 20 28 74 63 6c 5f de);....if (tcl_
6350: 72 65 74 20 3d 3d 20 54 43 4c 5f 4f 4b 29 20 7b ret == TCL_OK) {
6360: 0a 09 09 09 09 70 61 74 68 69 6e 66 6f 2d 3e 74 .....pathinfo->t
6370: 69 6d 65 20 3d 20 61 74 74 72 5f 76 61 6c 75 65 ime = attr_value
6380: 5f 77 69 64 65 3b 0a 09 09 09 7d 0a 09 09 7d 20 _wide;....}...}
6390: 65 6c 73 65 20 7b 0a 09 09 09 70 61 74 68 69 6e else {....pathin
63a0: 66 6f 2d 3e 74 69 6d 65 20 3d 20 61 70 70 66 73 fo->time = appfs
63b0: 5f 62 6f 6f 74 74 69 6d 65 3b 0a 09 09 7d 0a 0a _boottime;...}..
63c0: 09 09 54 63 6c 5f 52 65 6c 65 61 73 65 28 69 6e ..Tcl_Release(in
63d0: 74 65 72 70 29 3b 0a 09 29 0a 0a 09 69 66 20 28 terp);..)...if (
63e0: 70 61 74 68 69 6e 66 6f 2d 3e 70 61 63 6b 61 67 pathinfo->packag
63f0: 65 64 29 20 7b 0a 09 09 70 61 74 68 69 6e 66 6f ed) {...pathinfo
6400: 2d 3e 69 6e 6f 64 65 20 3d 20 61 70 70 66 73 5f ->inode = appfs_
6410: 67 65 74 5f 70 61 74 68 5f 69 6e 6f 64 65 28 70 get_path_inode(p
6420: 61 74 68 2c 20 2d 31 29 3b 0a 09 7d 20 65 6c 73 ath, -1);..} els
6430: 65 20 7b 0a 09 09 70 61 74 68 69 6e 66 6f 2d 3e e {...pathinfo->
6440: 69 6e 6f 64 65 20 3d 20 61 70 70 66 73 5f 67 65 inode = appfs_ge
6450: 74 5f 70 61 74 68 5f 69 6e 6f 64 65 28 70 61 74 t_path_inode(pat
6460: 68 2c 20 66 73 75 69 64 29 3b 0a 09 7d 0a 0a 09 h, fsuid);..}...
6470: 41 50 50 46 53 5f 44 45 42 55 47 28 22 43 61 63 APPFS_DEBUG("Cac
6480: 68 69 6e 67 20 69 6e 6f 64 65 20 66 6f 72 20 70 hing inode for p
6490: 61 74 68 3d 25 73 2c 75 69 64 3d 25 6c 6c 69 20 ath=%s,uid=%lli
64a0: 61 73 20 25 6c 6c 75 20 28 70 61 63 6b 61 67 65 as %llu (package
64b0: 64 20 3d 20 25 69 29 22 2c 20 70 61 74 68 2c 20 d = %i)", path,
64c0: 28 6c 6f 6e 67 20 6c 6f 6e 67 29 20 66 73 75 69 (long long) fsui
64d0: 64 2c 20 70 61 74 68 69 6e 66 6f 2d 3e 69 6e 6f d, pathinfo->ino
64e0: 64 65 2c 20 70 61 74 68 69 6e 66 6f 2d 3e 70 61 de, pathinfo->pa
64f0: 63 6b 61 67 65 64 29 3b 0a 0a 09 69 66 20 28 72 ckaged);...if (r
6500: 65 74 76 61 6c 20 3d 3d 20 30 29 20 7b 0a 09 09 etval == 0) {...
6510: 61 70 70 66 73 5f 67 65 74 5f 70 61 74 68 5f 69 appfs_get_path_i
6520: 6e 66 6f 5f 63 61 63 68 65 5f 61 64 64 28 70 61 nfo_cache_add(pa
6530: 74 68 2c 20 66 73 75 69 64 2c 20 70 61 74 68 69 th, fsuid, pathi
6540: 6e 66 6f 29 3b 0a 09 7d 20 65 6c 73 65 20 7b 0a nfo);..} else {.
6550: 09 09 41 50 50 46 53 5f 44 45 42 55 47 28 22 65 ..APPFS_DEBUG("e
6560: 72 72 6f 72 3a 20 49 6e 76 61 6c 69 64 20 74 79 rror: Invalid ty
6570: 70 65 20 66 6f 72 20 5c 22 25 73 5c 22 20 66 72 pe for \"%s\" fr
6580: 6f 6d 20 54 63 6c 22 2c 20 70 61 74 68 29 3b 0a om Tcl", path);.
6590: 09 7d 0a 0a 09 72 65 74 75 72 6e 28 72 65 74 76 .}...return(retv
65a0: 61 6c 29 3b 0a 7d 0a 0a 73 74 61 74 69 63 20 63 al);.}..static c
65b0: 68 61 72 20 2a 61 70 70 66 73 5f 70 72 65 70 61 har *appfs_prepa
65c0: 72 65 5f 74 6f 5f 63 72 65 61 74 65 28 63 6f 6e re_to_create(con
65d0: 73 74 20 63 68 61 72 20 2a 70 61 74 68 29 20 7b st char *path) {
65e0: 0a 09 54 63 6c 5f 49 6e 74 65 72 70 20 2a 69 6e ..Tcl_Interp *in
65f0: 74 65 72 70 3b 0a 09 63 6f 6e 73 74 20 63 68 61 terp;..const cha
6600: 72 20 2a 72 65 61 6c 5f 70 61 74 68 3b 0a 09 69 r *real_path;..i
6610: 6e 74 20 74 63 6c 5f 72 65 74 3b 0a 0a 09 61 70 nt tcl_ret;...ap
6620: 70 66 73 5f 67 65 74 5f 70 61 74 68 5f 69 6e 66 pfs_get_path_inf
6630: 6f 5f 63 61 63 68 65 5f 66 6c 75 73 68 28 61 70 o_cache_flush(ap
6640: 70 66 73 5f 67 65 74 5f 66 73 75 69 64 28 29 2c pfs_get_fsuid(),
6650: 20 2d 31 29 3b 0a 0a 09 69 6e 74 65 72 70 20 3d -1);...interp =
6660: 20 61 70 70 66 73 5f 54 63 6c 49 6e 74 65 72 70 appfs_TclInterp
6670: 28 29 3b 0a 09 69 66 20 28 69 6e 74 65 72 70 20 ();..if (interp
6680: 3d 3d 20 4e 55 4c 4c 29 20 7b 0a 09 09 72 65 74 == NULL) {...ret
6690: 75 72 6e 28 4e 55 4c 4c 29 3b 0a 09 7d 0a 0a 09 urn(NULL);..}...
66a0: 61 70 70 66 73 5f 63 61 6c 6c 5f 6c 69 62 74 63 appfs_call_libtc
66b0: 6c 28 54 63 6c 5f 50 72 65 73 65 72 76 65 28 69 l(Tcl_Preserve(i
66c0: 6e 74 65 72 70 29 3b 29 0a 0a 09 61 70 70 66 73 nterp);)...appfs
66d0: 5f 63 61 6c 6c 5f 6c 69 62 74 63 6c 28 0a 09 09 _call_libtcl(...
66e0: 74 63 6c 5f 72 65 74 20 3d 20 61 70 70 66 73 5f tcl_ret = appfs_
66f0: 54 63 6c 5f 45 76 61 6c 28 69 6e 74 65 72 70 2c Tcl_Eval(interp,
6700: 20 32 2c 20 22 3a 3a 61 70 70 66 73 3a 3a 70 72 2, "::appfs::pr
6710: 65 70 61 72 65 5f 74 6f 5f 63 72 65 61 74 65 22 epare_to_create"
6720: 2c 20 70 61 74 68 29 3b 0a 09 29 0a 09 69 66 20 , path);..)..if
6730: 28 74 63 6c 5f 72 65 74 20 21 3d 20 54 43 4c 5f (tcl_ret != TCL_
6740: 4f 4b 29 20 7b 0a 09 09 41 50 50 46 53 5f 44 45 OK) {...APPFS_DE
6750: 42 55 47 28 22 3a 3a 61 70 70 66 73 3a 3a 70 72 BUG("::appfs::pr
6760: 65 70 61 72 65 5f 74 6f 5f 63 72 65 61 74 65 28 epare_to_create(
6770: 25 73 29 20 66 61 69 6c 65 64 2e 22 2c 20 70 61 %s) failed.", pa
6780: 74 68 29 3b 0a 09 09 61 70 70 66 73 5f 63 61 6c th);...appfs_cal
6790: 6c 5f 6c 69 62 74 63 6c 28 0a 09 09 09 41 50 50 l_libtcl(....APP
67a0: 46 53 5f 44 45 42 55 47 28 22 54 63 6c 20 45 72 FS_DEBUG("Tcl Er
67b0: 72 6f 72 20 69 73 3a 20 25 73 22 2c 20 54 63 6c ror is: %s", Tcl
67c0: 5f 47 65 74 53 74 72 69 6e 67 52 65 73 75 6c 74 _GetStringResult
67d0: 28 69 6e 74 65 72 70 29 29 3b 0a 09 09 29 0a 0a (interp));...)..
67e0: 09 09 61 70 70 66 73 5f 63 61 6c 6c 5f 6c 69 62 ..appfs_call_lib
67f0: 74 63 6c 28 54 63 6c 5f 52 65 6c 65 61 73 65 28 tcl(Tcl_Release(
6800: 69 6e 74 65 72 70 29 3b 29 0a 0a 09 09 72 65 74 interp);)....ret
6810: 75 72 6e 28 4e 55 4c 4c 29 3b 0a 09 7d 0a 0a 09 urn(NULL);..}...
6820: 61 70 70 66 73 5f 63 61 6c 6c 5f 6c 69 62 74 63 appfs_call_libtc
6830: 6c 28 0a 09 09 72 65 61 6c 5f 70 61 74 68 20 3d l(...real_path =
6840: 20 54 63 6c 5f 47 65 74 53 74 72 69 6e 67 52 65 Tcl_GetStringRe
6850: 73 75 6c 74 28 69 6e 74 65 72 70 29 3b 0a 09 29 sult(interp);..)
6860: 0a 0a 09 61 70 70 66 73 5f 63 61 6c 6c 5f 6c 69 ...appfs_call_li
6870: 62 74 63 6c 28 54 63 6c 5f 52 65 6c 65 61 73 65 btcl(Tcl_Release
6880: 28 69 6e 74 65 72 70 29 3b 29 0a 0a 09 69 66 20 (interp);)...if
6890: 28 72 65 61 6c 5f 70 61 74 68 20 3d 3d 20 4e 55 (real_path == NU
68a0: 4c 4c 29 20 7b 0a 09 09 72 65 74 75 72 6e 28 4e LL) {...return(N
68b0: 55 4c 4c 29 3b 0a 09 7d 0a 0a 09 72 65 74 75 72 ULL);..}...retur
68c0: 6e 28 73 74 72 64 75 70 28 72 65 61 6c 5f 70 61 n(strdup(real_pa
68d0: 74 68 29 29 3b 0a 7d 0a 0a 73 74 61 74 69 63 20 th));.}..static
68e0: 63 68 61 72 20 2a 61 70 70 66 73 5f 6c 6f 63 61 char *appfs_loca
68f0: 6c 70 61 74 68 28 63 6f 6e 73 74 20 63 68 61 72 lpath(const char
6900: 20 2a 70 61 74 68 29 20 7b 0a 09 54 63 6c 5f 49 *path) {..Tcl_I
6910: 6e 74 65 72 70 20 2a 69 6e 74 65 72 70 3b 0a 09 nterp *interp;..
6920: 63 6f 6e 73 74 20 63 68 61 72 20 2a 72 65 61 6c const char *real
6930: 5f 70 61 74 68 3b 0a 09 69 6e 74 20 74 63 6c 5f _path;..int tcl_
6940: 72 65 74 3b 0a 0a 09 69 6e 74 65 72 70 20 3d 20 ret;...interp =
6950: 61 70 70 66 73 5f 54 63 6c 49 6e 74 65 72 70 28 appfs_TclInterp(
6960: 29 3b 0a 09 69 66 20 28 69 6e 74 65 72 70 20 3d );..if (interp =
6970: 3d 20 4e 55 4c 4c 29 20 7b 0a 09 09 72 65 74 75 = NULL) {...retu
6980: 72 6e 28 4e 55 4c 4c 29 3b 0a 09 7d 0a 0a 09 61 rn(NULL);..}...a
6990: 70 70 66 73 5f 63 61 6c 6c 5f 6c 69 62 74 63 6c ppfs_call_libtcl
69a0: 28 54 63 6c 5f 50 72 65 73 65 72 76 65 28 69 6e (Tcl_Preserve(in
69b0: 74 65 72 70 29 3b 29 0a 0a 09 61 70 70 66 73 5f terp);)...appfs_
69c0: 63 61 6c 6c 5f 6c 69 62 74 63 6c 28 0a 09 09 74 call_libtcl(...t
69d0: 63 6c 5f 72 65 74 20 3d 20 61 70 70 66 73 5f 54 cl_ret = appfs_T
69e0: 63 6c 5f 45 76 61 6c 28 69 6e 74 65 72 70 2c 20 cl_Eval(interp,
69f0: 32 2c 20 22 3a 3a 61 70 70 66 73 3a 3a 6c 6f 63 2, "::appfs::loc
6a00: 61 6c 70 61 74 68 22 2c 20 70 61 74 68 29 3b 0a alpath", path);.
6a10: 09 29 0a 09 69 66 20 28 74 63 6c 5f 72 65 74 20 .)..if (tcl_ret
6a20: 21 3d 20 54 43 4c 5f 4f 4b 29 20 7b 0a 09 09 41 != TCL_OK) {...A
6a30: 50 50 46 53 5f 44 45 42 55 47 28 22 3a 3a 61 70 PPFS_DEBUG("::ap
6a40: 70 66 73 3a 3a 6c 6f 63 61 6c 70 61 74 68 28 25 pfs::localpath(%
6a50: 73 29 20 66 61 69 6c 65 64 2e 22 2c 20 70 61 74 s) failed.", pat
6a60: 68 29 3b 0a 09 09 61 70 70 66 73 5f 63 61 6c 6c h);...appfs_call
6a70: 5f 6c 69 62 74 63 6c 28 0a 09 09 09 41 50 50 46 _libtcl(....APPF
6a80: 53 5f 44 45 42 55 47 28 22 54 63 6c 20 45 72 72 S_DEBUG("Tcl Err
6a90: 6f 72 20 69 73 3a 20 25 73 22 2c 20 54 63 6c 5f or is: %s", Tcl_
6aa0: 47 65 74 53 74 72 69 6e 67 52 65 73 75 6c 74 28 GetStringResult(
6ab0: 69 6e 74 65 72 70 29 29 3b 0a 09 09 29 0a 0a 09 interp));...)...
6ac0: 09 72 65 74 75 72 6e 28 4e 55 4c 4c 29 3b 0a 09 .return(NULL);..
6ad0: 7d 0a 0a 09 61 70 70 66 73 5f 63 61 6c 6c 5f 6c }...appfs_call_l
6ae0: 69 62 74 63 6c 28 0a 09 09 72 65 61 6c 5f 70 61 ibtcl(...real_pa
6af0: 74 68 20 3d 20 54 63 6c 5f 47 65 74 53 74 72 69 th = Tcl_GetStri
6b00: 6e 67 52 65 73 75 6c 74 28 69 6e 74 65 72 70 29 ngResult(interp)
6b10: 3b 0a 09 29 0a 0a 09 61 70 70 66 73 5f 63 61 6c ;..)...appfs_cal
6b20: 6c 5f 6c 69 62 74 63 6c 28 54 63 6c 5f 52 65 6c l_libtcl(Tcl_Rel
6b30: 65 61 73 65 28 69 6e 74 65 72 70 29 3b 29 0a 0a ease(interp);)..
6b40: 09 69 66 20 28 72 65 61 6c 5f 70 61 74 68 20 3d .if (real_path =
6b50: 3d 20 4e 55 4c 4c 29 20 7b 0a 09 09 72 65 74 75 = NULL) {...retu
6b60: 72 6e 28 4e 55 4c 4c 29 3b 0a 09 7d 0a 0a 09 72 rn(NULL);..}...r
6b70: 65 74 75 72 6e 28 73 74 72 64 75 70 28 72 65 61 eturn(strdup(rea
6b80: 6c 5f 70 61 74 68 29 29 3b 0a 7d 0a 0a 23 69 66 l_path));.}..#if
6b90: 20 28 64 65 66 69 6e 65 64 28 44 45 42 55 47 29 (defined(DEBUG)
6ba0: 20 26 26 20 64 65 66 69 6e 65 64 28 41 50 50 46 && defined(APPF
6bb0: 53 5f 45 58 49 54 5f 50 41 54 48 29 29 20 7c 7c S_EXIT_PATH)) ||
6bc0: 20 64 65 66 69 6e 65 64 28 41 50 50 46 53 5f 45 defined(APPFS_E
6bd0: 58 49 54 5f 50 41 54 48 5f 45 4e 41 42 4c 45 5f XIT_PATH_ENABLE_
6be0: 4d 41 4a 4f 52 5f 53 45 43 55 52 49 54 59 5f 48 MAJOR_SECURITY_H
6bf0: 4f 4c 45 29 0a 73 74 61 74 69 63 20 76 6f 69 64 OLE).static void
6c00: 20 61 70 70 66 73 5f 65 78 69 74 28 76 6f 69 64 appfs_exit(void
6c10: 29 20 7b 0a 09 69 6e 74 20 67 6c 6f 62 61 6c 5f ) {..int global_
6c20: 69 6e 74 65 72 70 5f 72 65 73 65 74 5f 6b 65 79 interp_reset_key
6c30: 3b 0a 0a 09 67 6c 6f 62 61 6c 5f 69 6e 74 65 72 ;...global_inter
6c40: 70 5f 72 65 73 65 74 5f 6b 65 79 20 3d 20 5f 5f p_reset_key = __
6c50: 73 79 6e 63 5f 66 65 74 63 68 5f 61 6e 64 5f 61 sync_fetch_and_a
6c60: 64 64 28 26 69 6e 74 65 72 70 5f 72 65 73 65 74 dd(&interp_reset
6c70: 5f 6b 65 79 2c 20 30 29 3b 0a 09 5f 5f 73 79 6e _key, 0);..__syn
6c80: 63 5f 66 65 74 63 68 5f 61 6e 64 5f 73 75 62 28 c_fetch_and_sub(
6c90: 26 69 6e 74 65 72 70 5f 72 65 73 65 74 5f 6b 65 &interp_reset_ke
6ca0: 79 2c 20 67 6c 6f 62 61 6c 5f 69 6e 74 65 72 70 y, global_interp
6cb0: 5f 72 65 73 65 74 5f 6b 65 79 29 3b 0a 0a 09 77 _reset_key);...w
6cc0: 68 69 6c 65 20 28 5f 5f 73 79 6e 63 5f 73 75 62 hile (__sync_sub
6cd0: 5f 61 6e 64 5f 66 65 74 63 68 28 26 69 6e 74 65 _and_fetch(&inte
6ce0: 72 70 5f 72 65 73 65 74 5f 6b 65 79 2c 20 31 29 rp_reset_key, 1)
6cf0: 20 3e 3d 20 30 29 20 7b 0a 09 09 2f 2a 20 42 75 >= 0) {.../* Bu
6d00: 73 79 20 4c 6f 6f 70 20 2a 2f 0a 09 7d 0a 0a 09 sy Loop */..}...
6d10: 67 6c 6f 62 61 6c 5f 69 6e 74 65 72 70 5f 72 65 global_interp_re
6d20: 73 65 74 5f 6b 65 79 20 3d 20 5f 5f 73 79 6e 63 set_key = __sync
6d30: 5f 66 65 74 63 68 5f 61 6e 64 5f 61 64 64 28 26 _fetch_and_add(&
6d40: 69 6e 74 65 72 70 5f 72 65 73 65 74 5f 6b 65 79 interp_reset_key
6d50: 2c 20 30 29 3b 0a 09 69 66 20 28 67 6c 6f 62 61 , 0);..if (globa
6d60: 6c 5f 69 6e 74 65 72 70 5f 72 65 73 65 74 5f 6b l_interp_reset_k
6d70: 65 79 20 21 3d 20 2d 31 29 20 7b 0a 09 09 41 50 ey != -1) {...AP
6d80: 50 46 53 5f 44 45 42 55 47 28 22 45 72 72 6f 72 PFS_DEBUG("Error
6d90: 20 73 65 6e 64 69 6e 67 20 6b 69 6c 6c 20 73 69 sending kill si
6da0: 67 6e 61 6c 20 74 6f 20 61 6c 6c 20 74 68 72 65 gnal to all thre
6db0: 61 64 73 2c 20 61 62 6f 72 74 69 6e 67 20 61 6e ads, aborting an
6dc0: 79 77 61 79 2e 22 29 3b 0a 09 7d 0a 0a 09 61 70 yway.");..}...ap
6dd0: 70 66 73 5f 67 65 74 5f 70 61 74 68 5f 69 6e 66 pfs_get_path_inf
6de0: 6f 5f 63 61 63 68 65 5f 66 6c 75 73 68 28 2d 31 o_cache_flush(-1
6df0: 2c 20 2d 31 29 3b 0a 0a 09 66 75 73 65 5f 65 78 , -1);...fuse_ex
6e00: 69 74 28 66 75 73 65 5f 67 65 74 5f 63 6f 6e 74 it(fuse_get_cont
6e10: 65 78 74 28 29 2d 3e 66 75 73 65 29 3b 0a 0a 09 ext()->fuse);...
6e20: 72 65 74 75 72 6e 3b 0a 7d 0a 23 65 6e 64 69 66 return;.}.#endif
6e30: 0a 0a 73 74 61 74 69 63 20 69 6e 74 20 61 70 70 ..static int app
6e40: 66 73 5f 66 75 73 65 5f 72 65 61 64 6c 69 6e 6b fs_fuse_readlink
6e50: 28 63 6f 6e 73 74 20 63 68 61 72 20 2a 70 61 74 (const char *pat
6e60: 68 2c 20 63 68 61 72 20 2a 62 75 66 2c 20 73 69 h, char *buf, si
6e70: 7a 65 5f 74 20 73 69 7a 65 29 20 7b 0a 09 73 74 ze_t size) {..st
6e80: 72 75 63 74 20 61 70 70 66 73 5f 70 61 74 68 69 ruct appfs_pathi
6e90: 6e 66 6f 20 70 61 74 68 69 6e 66 6f 3b 0a 09 69 nfo pathinfo;..i
6ea0: 6e 74 20 72 65 74 76 61 6c 20 3d 20 30 3b 0a 0a nt retval = 0;..
6eb0: 09 41 50 50 46 53 5f 44 45 42 55 47 28 22 45 6e .APPFS_DEBUG("En
6ec0: 74 65 72 20 28 70 61 74 68 20 3d 20 25 73 2c 20 ter (path = %s,
6ed0: 2e 2e 2e 29 22 2c 20 70 61 74 68 29 3b 0a 0a 09 ...)", path);...
6ee0: 70 61 74 68 69 6e 66 6f 2e 74 79 70 65 20 3d 20 pathinfo.type =
6ef0: 41 50 50 46 53 5f 50 41 54 48 54 59 50 45 5f 49 APPFS_PATHTYPE_I
6f00: 4e 56 41 4c 49 44 3b 0a 0a 09 72 65 74 76 61 6c NVALID;...retval
6f10: 20 3d 20 61 70 70 66 73 5f 67 65 74 5f 70 61 74 = appfs_get_pat
6f20: 68 5f 69 6e 66 6f 28 70 61 74 68 2c 20 26 70 61 h_info(path, &pa
6f30: 74 68 69 6e 66 6f 29 3b 0a 09 69 66 20 28 72 65 thinfo);..if (re
6f40: 74 76 61 6c 20 21 3d 20 30 29 20 7b 0a 09 09 72 tval != 0) {...r
6f50: 65 74 75 72 6e 28 72 65 74 76 61 6c 29 3b 0a 09 eturn(retval);..
6f60: 7d 0a 0a 09 69 66 20 28 70 61 74 68 69 6e 66 6f }...if (pathinfo
6f70: 2e 74 79 70 65 20 21 3d 20 41 50 50 46 53 5f 50 .type != APPFS_P
6f80: 41 54 48 54 59 50 45 5f 53 59 4d 4c 49 4e 4b 29 ATHTYPE_SYMLINK)
6f90: 20 7b 0a 09 09 72 65 74 75 72 6e 28 2d 45 49 4e {...return(-EIN
6fa0: 56 41 4c 29 3b 0a 09 7d 0a 0a 09 69 66 20 28 28 VAL);..}...if ((
6fb0: 73 74 72 6c 65 6e 28 70 61 74 68 69 6e 66 6f 2e strlen(pathinfo.
6fc0: 74 79 70 65 69 6e 66 6f 2e 73 79 6d 6c 69 6e 6b typeinfo.symlink
6fd0: 2e 73 6f 75 72 63 65 29 20 2b 20 31 29 20 3e 20 .source) + 1) >
6fe0: 73 69 7a 65 29 20 7b 0a 09 09 72 65 74 75 72 6e size) {...return
6ff0: 28 2d 45 4e 41 4d 45 54 4f 4f 4c 4f 4e 47 29 3b (-ENAMETOOLONG);
7000: 0a 09 7d 0a 0a 09 6d 65 6d 63 70 79 28 62 75 66 ..}...memcpy(buf
7010: 2c 20 70 61 74 68 69 6e 66 6f 2e 74 79 70 65 69 , pathinfo.typei
7020: 6e 66 6f 2e 73 79 6d 6c 69 6e 6b 2e 73 6f 75 72 nfo.symlink.sour
7030: 63 65 2c 20 73 74 72 6c 65 6e 28 70 61 74 68 69 ce, strlen(pathi
7040: 6e 66 6f 2e 74 79 70 65 69 6e 66 6f 2e 73 79 6d nfo.typeinfo.sym
7050: 6c 69 6e 6b 2e 73 6f 75 72 63 65 29 20 2b 20 31 link.source) + 1
7060: 29 3b 0a 0a 09 72 65 74 75 72 6e 28 30 29 3b 0a );...return(0);.
7070: 7d 0a 0a 73 74 61 74 69 63 20 69 6e 74 20 61 70 }..static int ap
7080: 70 66 73 5f 66 75 73 65 5f 67 65 74 61 74 74 72 pfs_fuse_getattr
7090: 28 63 6f 6e 73 74 20 63 68 61 72 20 2a 70 61 74 (const char *pat
70a0: 68 2c 20 73 74 72 75 63 74 20 73 74 61 74 20 2a h, struct stat *
70b0: 73 74 62 75 66 29 20 7b 0a 09 73 74 72 75 63 74 stbuf) {..struct
70c0: 20 61 70 70 66 73 5f 70 61 74 68 69 6e 66 6f 20 appfs_pathinfo
70d0: 70 61 74 68 69 6e 66 6f 3b 0a 09 69 6e 74 20 63 pathinfo;..int c
70e0: 68 61 6e 67 65 4f 77 6e 65 72 54 6f 55 73 65 72 hangeOwnerToUser
70f0: 49 66 50 61 63 6b 61 67 65 64 3b 0a 09 69 6e 74 IfPackaged;..int
7100: 20 72 65 74 76 61 6c 3b 0a 0a 09 72 65 74 76 61 retval;...retva
7110: 6c 20 3d 20 30 3b 0a 0a 09 41 50 50 46 53 5f 44 l = 0;...APPFS_D
7120: 45 42 55 47 28 22 45 6e 74 65 72 20 28 70 61 74 EBUG("Enter (pat
7130: 68 20 3d 20 25 73 2c 20 2e 2e 2e 29 22 2c 20 70 h = %s, ...)", p
7140: 61 74 68 29 3b 0a 0a 23 69 66 20 28 64 65 66 69 ath);..#if (defi
7150: 6e 65 64 28 44 45 42 55 47 29 20 26 26 20 64 65 ned(DEBUG) && de
7160: 66 69 6e 65 64 28 41 50 50 46 53 5f 45 58 49 54 fined(APPFS_EXIT
7170: 5f 50 41 54 48 29 29 20 7c 7c 20 64 65 66 69 6e _PATH)) || defin
7180: 65 64 28 41 50 50 46 53 5f 45 58 49 54 5f 50 41 ed(APPFS_EXIT_PA
7190: 54 48 5f 45 4e 41 42 4c 45 5f 4d 41 4a 4f 52 5f TH_ENABLE_MAJOR_
71a0: 53 45 43 55 52 49 54 59 5f 48 4f 4c 45 29 0a 09 SECURITY_HOLE)..
71b0: 2f 2a 0a 09 20 2a 20 54 68 69 73 20 69 73 20 61 /*.. * This is a
71c0: 20 6d 61 6a 6f 72 20 73 65 63 75 72 69 74 79 20 major security
71d0: 69 73 73 75 65 20 73 6f 20 77 65 20 63 61 6e 6e issue so we cann
71e0: 6f 74 20 6c 65 74 20 69 74 20 62 65 20 63 6f 6d ot let it be com
71f0: 70 69 6c 65 64 20 69 6e 74 6f 0a 09 20 2a 20 61 piled into.. * a
7200: 6e 79 20 72 65 6c 65 61 73 65 0a 09 20 2a 2f 0a ny release.. */.
7210: 0a 09 69 66 20 28 73 74 72 63 6d 70 28 70 61 74 ..if (strcmp(pat
7220: 68 2c 20 22 2f 65 78 69 74 22 29 20 3d 3d 20 30 h, "/exit") == 0
7230: 29 20 7b 0a 09 09 61 70 70 66 73 5f 65 78 69 74 ) {...appfs_exit
7240: 28 29 3b 0a 09 7d 0a 23 65 6e 64 69 66 0a 0a 09 ();..}.#endif...
7250: 70 61 74 68 69 6e 66 6f 2e 74 79 70 65 20 3d 20 pathinfo.type =
7260: 41 50 50 46 53 5f 50 41 54 48 54 59 50 45 5f 49 APPFS_PATHTYPE_I
7270: 4e 56 41 4c 49 44 3b 0a 0a 09 72 65 74 76 61 6c NVALID;...retval
7280: 20 3d 20 61 70 70 66 73 5f 67 65 74 5f 70 61 74 = appfs_get_pat
7290: 68 5f 69 6e 66 6f 28 70 61 74 68 2c 20 26 70 61 h_info(path, &pa
72a0: 74 68 69 6e 66 6f 29 3b 0a 09 69 66 20 28 72 65 thinfo);..if (re
72b0: 74 76 61 6c 20 21 3d 20 30 29 20 7b 0a 09 09 69 tval != 0) {...i
72c0: 66 20 28 72 65 74 76 61 6c 20 3d 3d 20 2d 45 4e f (retval == -EN
72d0: 4f 45 4e 54 29 20 7b 0a 09 09 09 41 50 50 46 53 OENT) {....APPFS
72e0: 5f 44 45 42 55 47 28 22 67 65 74 5f 70 61 74 68 _DEBUG("get_path
72f0: 5f 69 6e 66 6f 20 72 65 74 75 72 6e 65 64 20 45 _info returned E
7300: 4e 4f 45 4e 54 2c 20 72 65 74 75 72 6e 69 6e 67 NOENT, returning
7310: 20 69 74 20 61 73 20 77 65 6c 6c 2e 22 29 3b 0a it as well.");.
7320: 09 09 7d 20 65 6c 73 65 20 7b 0a 09 09 09 41 50 ..} else {....AP
7330: 50 46 53 5f 44 45 42 55 47 28 22 65 72 72 6f 72 PFS_DEBUG("error
7340: 3a 20 67 65 74 5f 70 61 74 68 5f 69 6e 66 6f 20 : get_path_info
7350: 66 61 69 6c 65 64 22 29 3b 0a 09 09 7d 0a 0a 09 failed");...}...
7360: 09 72 65 74 75 72 6e 28 72 65 74 76 61 6c 29 3b .return(retval);
7370: 0a 09 7d 0a 0a 09 6d 65 6d 73 65 74 28 73 74 62 ..}...memset(stb
7380: 75 66 2c 20 30 2c 20 73 69 7a 65 6f 66 28 73 74 uf, 0, sizeof(st
7390: 72 75 63 74 20 73 74 61 74 29 29 3b 0a 0a 09 73 ruct stat));...s
73a0: 74 62 75 66 2d 3e 73 74 5f 6d 74 69 6d 65 20 3d tbuf->st_mtime =
73b0: 20 70 61 74 68 69 6e 66 6f 2e 74 69 6d 65 3b 0a pathinfo.time;.
73c0: 09 73 74 62 75 66 2d 3e 73 74 5f 63 74 69 6d 65 .stbuf->st_ctime
73d0: 20 3d 20 70 61 74 68 69 6e 66 6f 2e 74 69 6d 65 = pathinfo.time
73e0: 3b 0a 09 73 74 62 75 66 2d 3e 73 74 5f 61 74 69 ;..stbuf->st_ati
73f0: 6d 65 20 3d 20 70 61 74 68 69 6e 66 6f 2e 74 69 me = pathinfo.ti
7400: 6d 65 3b 0a 09 73 74 62 75 66 2d 3e 73 74 5f 69 me;..stbuf->st_i
7410: 6e 6f 20 20 20 3d 20 70 61 74 68 69 6e 66 6f 2e no = pathinfo.
7420: 69 6e 6f 64 65 3b 0a 09 73 74 62 75 66 2d 3e 73 inode;..stbuf->s
7430: 74 5f 6d 6f 64 65 20 20 3d 20 30 3b 0a 0a 09 63 t_mode = 0;...c
7440: 68 61 6e 67 65 4f 77 6e 65 72 54 6f 55 73 65 72 hangeOwnerToUser
7450: 49 66 50 61 63 6b 61 67 65 64 20 3d 20 31 3b 0a IfPackaged = 1;.
7460: 0a 09 73 77 69 74 63 68 20 28 70 61 74 68 69 6e ..switch (pathin
7470: 66 6f 2e 74 79 70 65 29 20 7b 0a 09 09 63 61 73 fo.type) {...cas
7480: 65 20 41 50 50 46 53 5f 50 41 54 48 54 59 50 45 e APPFS_PATHTYPE
7490: 5f 44 49 52 45 43 54 4f 52 59 3a 0a 09 09 09 73 _DIRECTORY:....s
74a0: 74 62 75 66 2d 3e 73 74 5f 6d 6f 64 65 20 3d 20 tbuf->st_mode =
74b0: 53 5f 49 46 44 49 52 20 7c 20 30 35 35 35 3b 0a S_IFDIR | 0555;.
74c0: 09 09 09 73 74 62 75 66 2d 3e 73 74 5f 6e 6c 69 ...stbuf->st_nli
74d0: 6e 6b 20 3d 20 32 20 2b 20 70 61 74 68 69 6e 66 nk = 2 + pathinf
74e0: 6f 2e 74 79 70 65 69 6e 66 6f 2e 64 69 72 2e 63 o.typeinfo.dir.c
74f0: 68 69 6c 64 63 6f 75 6e 74 3b 0a 09 09 09 62 72 hildcount;....br
7500: 65 61 6b 3b 0a 09 09 63 61 73 65 20 41 50 50 46 eak;...case APPF
7510: 53 5f 50 41 54 48 54 59 50 45 5f 46 49 4c 45 3a S_PATHTYPE_FILE:
7520: 0a 09 09 09 73 74 62 75 66 2d 3e 73 74 5f 6d 6f ....stbuf->st_mo
7530: 64 65 20 3d 20 53 5f 49 46 52 45 47 20 7c 20 30 de = S_IFREG | 0
7540: 34 34 34 3b 0a 0a 09 09 09 69 66 20 28 70 61 74 444;.....if (pat
7550: 68 69 6e 66 6f 2e 74 79 70 65 69 6e 66 6f 2e 66 hinfo.typeinfo.f
7560: 69 6c 65 2e 65 78 65 63 75 74 61 62 6c 65 29 20 ile.executable)
7570: 7b 0a 09 09 09 09 73 74 62 75 66 2d 3e 73 74 5f {.....stbuf->st_
7580: 6d 6f 64 65 20 7c 3d 20 30 31 31 31 3b 0a 09 09 mode |= 0111;...
7590: 09 7d 0a 0a 09 09 09 69 66 20 28 70 61 74 68 69 .}.....if (pathi
75a0: 6e 66 6f 2e 70 61 63 6b 61 67 65 64 29 20 7b 0a nfo.packaged) {.
75b0: 09 09 09 09 69 66 20 28 70 61 74 68 69 6e 66 6f ....if (pathinfo
75c0: 2e 74 79 70 65 69 6e 66 6f 2e 66 69 6c 65 2e 73 .typeinfo.file.s
75d0: 75 69 64 52 6f 6f 74 29 20 7b 0a 09 09 09 09 09 uidRoot) {......
75e0: 63 68 61 6e 67 65 4f 77 6e 65 72 54 6f 55 73 65 changeOwnerToUse
75f0: 72 49 66 50 61 63 6b 61 67 65 64 20 3d 20 30 3b rIfPackaged = 0;
7600: 0a 0a 09 09 09 09 09 73 74 62 75 66 2d 3e 73 74 .......stbuf->st
7610: 5f 6d 6f 64 65 20 7c 3d 20 30 34 30 30 30 3b 0a _mode |= 04000;.
7620: 09 09 09 09 7d 0a 09 09 09 7d 0a 0a 09 09 09 69 ....}....}.....i
7630: 66 20 28 70 61 74 68 69 6e 66 6f 2e 74 79 70 65 f (pathinfo.type
7640: 69 6e 66 6f 2e 66 69 6c 65 2e 77 6f 72 6c 64 61 info.file.worlda
7650: 63 63 65 73 73 69 62 6c 65 29 20 7b 0a 09 09 09 ccessible) {....
7660: 09 73 74 62 75 66 2d 3e 73 74 5f 6d 6f 64 65 20 .stbuf->st_mode
7670: 26 3d 20 7e 30 37 37 3b 0a 09 09 09 7d 0a 0a 09 &= ~077;....}...
7680: 09 09 73 74 62 75 66 2d 3e 73 74 5f 6e 6c 69 6e ..stbuf->st_nlin
7690: 6b 20 3d 20 31 3b 0a 09 09 09 73 74 62 75 66 2d k = 1;....stbuf-
76a0: 3e 73 74 5f 73 69 7a 65 20 3d 20 70 61 74 68 69 >st_size = pathi
76b0: 6e 66 6f 2e 74 79 70 65 69 6e 66 6f 2e 66 69 6c nfo.typeinfo.fil
76c0: 65 2e 73 69 7a 65 3b 0a 0a 09 09 09 62 72 65 61 e.size;.....brea
76d0: 6b 3b 0a 09 09 63 61 73 65 20 41 50 50 46 53 5f k;...case APPFS_
76e0: 50 41 54 48 54 59 50 45 5f 53 59 4d 4c 49 4e 4b PATHTYPE_SYMLINK
76f0: 3a 0a 09 09 09 73 74 62 75 66 2d 3e 73 74 5f 6d :....stbuf->st_m
7700: 6f 64 65 20 3d 20 53 5f 49 46 4c 4e 4b 20 7c 20 ode = S_IFLNK |
7710: 30 35 35 35 3b 0a 09 09 09 73 74 62 75 66 2d 3e 0555;....stbuf->
7720: 73 74 5f 6e 6c 69 6e 6b 20 3d 20 31 3b 0a 09 09 st_nlink = 1;...
7730: 09 73 74 62 75 66 2d 3e 73 74 5f 73 69 7a 65 20 .stbuf->st_size
7740: 3d 20 70 61 74 68 69 6e 66 6f 2e 74 79 70 65 69 = pathinfo.typei
7750: 6e 66 6f 2e 73 79 6d 6c 69 6e 6b 2e 73 69 7a 65 nfo.symlink.size
7760: 3b 0a 09 09 09 62 72 65 61 6b 3b 0a 09 09 63 61 ;....break;...ca
7770: 73 65 20 41 50 50 46 53 5f 50 41 54 48 54 59 50 se APPFS_PATHTYP
7780: 45 5f 53 4f 43 4b 45 54 3a 0a 09 09 09 73 74 62 E_SOCKET:....stb
7790: 75 66 2d 3e 73 74 5f 6d 6f 64 65 20 3d 20 53 5f uf->st_mode = S_
77a0: 49 46 53 4f 43 4b 20 7c 20 30 35 35 35 3b 0a 09 IFSOCK | 0555;..
77b0: 09 09 73 74 62 75 66 2d 3e 73 74 5f 6e 6c 69 6e ..stbuf->st_nlin
77c0: 6b 20 3d 20 31 3b 0a 09 09 09 73 74 62 75 66 2d k = 1;....stbuf-
77d0: 3e 73 74 5f 73 69 7a 65 20 3d 20 30 3b 0a 09 09 >st_size = 0;...
77e0: 09 62 72 65 61 6b 3b 0a 09 09 63 61 73 65 20 41 .break;...case A
77f0: 50 50 46 53 5f 50 41 54 48 54 59 50 45 5f 46 49 PPFS_PATHTYPE_FI
7800: 46 4f 3a 0a 09 09 09 73 74 62 75 66 2d 3e 73 74 FO:....stbuf->st
7810: 5f 6d 6f 64 65 20 3d 20 53 5f 49 46 49 46 4f 20 _mode = S_IFIFO
7820: 7c 20 30 35 35 35 3b 0a 09 09 09 73 74 62 75 66 | 0555;....stbuf
7830: 2d 3e 73 74 5f 6e 6c 69 6e 6b 20 3d 20 31 3b 0a ->st_nlink = 1;.
7840: 09 09 09 73 74 62 75 66 2d 3e 73 74 5f 73 69 7a ...stbuf->st_siz
7850: 65 20 3d 20 30 3b 0a 09 09 09 62 72 65 61 6b 3b e = 0;....break;
7860: 0a 09 09 63 61 73 65 20 41 50 50 46 53 5f 50 41 ...case APPFS_PA
7870: 54 48 54 59 50 45 5f 44 4f 45 53 5f 4e 4f 54 5f THTYPE_DOES_NOT_
7880: 45 58 49 53 54 3a 0a 09 09 09 72 65 74 76 61 6c EXIST:....retval
7890: 20 3d 20 2d 45 4e 4f 45 4e 54 3b 0a 0a 09 09 09 = -ENOENT;.....
78a0: 62 72 65 61 6b 3b 0a 09 09 63 61 73 65 20 41 50 break;...case AP
78b0: 50 46 53 5f 50 41 54 48 54 59 50 45 5f 49 4e 56 PFS_PATHTYPE_INV
78c0: 41 4c 49 44 3a 0a 09 09 09 72 65 74 76 61 6c 20 ALID:....retval
78d0: 3d 20 2d 45 49 4f 3b 0a 0a 09 09 09 62 72 65 61 = -EIO;.....brea
78e0: 6b 3b 0a 09 7d 0a 0a 09 69 66 20 28 28 70 61 74 k;..}...if ((pat
78f0: 68 69 6e 66 6f 2e 70 61 63 6b 61 67 65 64 20 26 hinfo.packaged &
7900: 26 20 63 68 61 6e 67 65 4f 77 6e 65 72 54 6f 55 & changeOwnerToU
7910: 73 65 72 49 66 50 61 63 6b 61 67 65 64 29 20 7c serIfPackaged) |
7920: 7c 20 28 21 70 61 74 68 69 6e 66 6f 2e 70 61 63 | (!pathinfo.pac
7930: 6b 61 67 65 64 29 29 20 7b 0a 09 09 73 74 62 75 kaged)) {...stbu
7940: 66 2d 3e 73 74 5f 75 69 64 20 20 20 3d 20 61 70 f->st_uid = ap
7950: 70 66 73 5f 67 65 74 5f 66 73 75 69 64 28 29 3b pfs_get_fsuid();
7960: 0a 09 09 73 74 62 75 66 2d 3e 73 74 5f 67 69 64 ...stbuf->st_gid
7970: 20 20 20 3d 20 61 70 70 66 73 5f 67 65 74 5f 66 = appfs_get_f
7980: 73 67 69 64 28 29 3b 0a 09 09 73 74 62 75 66 2d sgid();...stbuf-
7990: 3e 73 74 5f 6d 6f 64 65 20 7c 3d 20 30 32 30 30 >st_mode |= 0200
79a0: 3b 0a 09 7d 0a 0a 09 72 65 74 75 72 6e 28 72 65 ;..}...return(re
79b0: 74 76 61 6c 29 3b 0a 7d 0a 0a 73 74 61 74 69 63 tval);.}..static
79c0: 20 69 6e 74 20 61 70 70 66 73 5f 66 75 73 65 5f int appfs_fuse_
79d0: 72 65 61 64 64 69 72 28 63 6f 6e 73 74 20 63 68 readdir(const ch
79e0: 61 72 20 2a 70 61 74 68 2c 20 76 6f 69 64 20 2a ar *path, void *
79f0: 62 75 66 2c 20 66 75 73 65 5f 66 69 6c 6c 5f 64 buf, fuse_fill_d
7a00: 69 72 5f 74 20 66 69 6c 6c 65 72 2c 20 6f 66 66 ir_t filler, off
7a10: 5f 74 20 6f 66 66 73 65 74 2c 20 73 74 72 75 63 _t offset, struc
7a20: 74 20 66 75 73 65 5f 66 69 6c 65 5f 69 6e 66 6f t fuse_file_info
7a30: 20 2a 66 69 29 20 7b 0a 09 54 63 6c 5f 49 6e 74 *fi) {..Tcl_Int
7a40: 65 72 70 20 2a 69 6e 74 65 72 70 3b 0a 09 54 63 erp *interp;..Tc
7a50: 6c 5f 4f 62 6a 20 2a 2a 63 68 69 6c 64 72 65 6e l_Obj **children
7a60: 3b 0a 09 69 6e 74 20 63 68 69 6c 64 72 65 6e 5f ;..int children_
7a70: 63 6f 75 6e 74 2c 20 69 64 78 3b 0a 09 69 6e 74 count, idx;..int
7a80: 20 74 63 6c 5f 72 65 74 3b 0a 0a 09 41 50 50 46 tcl_ret;...APPF
7a90: 53 5f 44 45 42 55 47 28 22 45 6e 74 65 72 20 28 S_DEBUG("Enter (
7aa0: 70 61 74 68 20 3d 20 25 73 2c 20 2e 2e 2e 29 22 path = %s, ...)"
7ab0: 2c 20 70 61 74 68 29 3b 0a 0a 09 69 6e 74 65 72 , path);...inter
7ac0: 70 20 3d 20 61 70 70 66 73 5f 54 63 6c 49 6e 74 p = appfs_TclInt
7ad0: 65 72 70 28 29 3b 0a 09 69 66 20 28 69 6e 74 65 erp();..if (inte
7ae0: 72 70 20 3d 3d 20 4e 55 4c 4c 29 20 7b 0a 09 09 rp == NULL) {...
7af0: 41 50 50 46 53 5f 44 45 42 55 47 28 22 65 72 72 APPFS_DEBUG("err
7b00: 6f 72 3a 20 55 6e 61 62 6c 65 20 74 6f 20 67 65 or: Unable to ge
7b10: 74 20 61 6e 20 69 6e 74 65 72 70 72 65 74 65 72 t an interpreter
7b20: 22 29 3b 0a 0a 09 09 72 65 74 75 72 6e 28 30 29 ");....return(0)
7b30: 3b 0a 09 7d 0a 0a 09 61 70 70 66 73 5f 63 61 6c ;..}...appfs_cal
7b40: 6c 5f 6c 69 62 74 63 6c 28 54 63 6c 5f 50 72 65 l_libtcl(Tcl_Pre
7b50: 73 65 72 76 65 28 69 6e 74 65 72 70 29 3b 29 0a serve(interp);).
7b60: 0a 09 66 69 6c 6c 65 72 28 62 75 66 2c 20 22 2e ..filler(buf, ".
7b70: 22 2c 20 4e 55 4c 4c 2c 20 30 29 3b 0a 09 66 69 ", NULL, 0);..fi
7b80: 6c 6c 65 72 28 62 75 66 2c 20 22 2e 2e 22 2c 20 ller(buf, "..",
7b90: 4e 55 4c 4c 2c 20 30 29 3b 0a 0a 09 74 63 6c 5f NULL, 0);...tcl_
7ba0: 72 65 74 20 3d 20 61 70 70 66 73 5f 54 63 6c 5f ret = appfs_Tcl_
7bb0: 45 76 61 6c 28 69 6e 74 65 72 70 2c 20 32 2c 20 Eval(interp, 2,
7bc0: 22 3a 3a 61 70 70 66 73 3a 3a 67 65 74 63 68 69 "::appfs::getchi
7bd0: 6c 64 72 65 6e 22 2c 20 70 61 74 68 29 3b 0a 09 ldren", path);..
7be0: 69 66 20 28 74 63 6c 5f 72 65 74 20 21 3d 20 54 if (tcl_ret != T
7bf0: 43 4c 5f 4f 4b 29 20 7b 0a 09 09 41 50 50 46 53 CL_OK) {...APPFS
7c00: 5f 44 45 42 55 47 28 22 3a 3a 61 70 70 66 73 3a _DEBUG("::appfs:
7c10: 3a 67 65 74 63 68 69 6c 64 72 65 6e 28 25 73 29 :getchildren(%s)
7c20: 20 66 61 69 6c 65 64 2e 22 2c 20 70 61 74 68 29 failed.", path)
7c30: 3b 0a 09 09 61 70 70 66 73 5f 63 61 6c 6c 5f 6c ;...appfs_call_l
7c40: 69 62 74 63 6c 28 0a 09 09 09 41 50 50 46 53 5f ibtcl(....APPFS_
7c50: 44 45 42 55 47 28 22 54 63 6c 20 45 72 72 6f 72 DEBUG("Tcl Error
7c60: 20 69 73 3a 20 25 73 22 2c 20 54 63 6c 5f 47 65 is: %s", Tcl_Ge
7c70: 74 53 74 72 69 6e 67 52 65 73 75 6c 74 28 69 6e tStringResult(in
7c80: 74 65 72 70 29 29 3b 0a 09 09 29 0a 0a 09 09 61 terp));...)....a
7c90: 70 70 66 73 5f 63 61 6c 6c 5f 6c 69 62 74 63 6c ppfs_call_libtcl
7ca0: 28 54 63 6c 5f 52 65 6c 65 61 73 65 28 69 6e 74 (Tcl_Release(int
7cb0: 65 72 70 29 3b 29 0a 0a 09 09 72 65 74 75 72 6e erp);)....return
7cc0: 28 30 29 3b 0a 09 7d 0a 0a 09 61 70 70 66 73 5f (0);..}...appfs_
7cd0: 63 61 6c 6c 5f 6c 69 62 74 63 6c 28 0a 09 09 74 call_libtcl(...t
7ce0: 63 6c 5f 72 65 74 20 3d 20 54 63 6c 5f 4c 69 73 cl_ret = Tcl_Lis
7cf0: 74 4f 62 6a 47 65 74 45 6c 65 6d 65 6e 74 73 28 tObjGetElements(
7d00: 69 6e 74 65 72 70 2c 20 54 63 6c 5f 47 65 74 4f interp, Tcl_GetO
7d10: 62 6a 52 65 73 75 6c 74 28 69 6e 74 65 72 70 29 bjResult(interp)
7d20: 2c 20 26 63 68 69 6c 64 72 65 6e 5f 63 6f 75 6e , &children_coun
7d30: 74 2c 20 26 63 68 69 6c 64 72 65 6e 29 3b 0a 09 t, &children);..
7d40: 29 0a 09 69 66 20 28 74 63 6c 5f 72 65 74 20 21 )..if (tcl_ret !
7d50: 3d 20 54 43 4c 5f 4f 4b 29 20 7b 0a 09 09 41 50 = TCL_OK) {...AP
7d60: 50 46 53 5f 44 45 42 55 47 28 22 50 61 72 73 69 PFS_DEBUG("Parsi
7d70: 6e 67 20 6c 69 73 74 20 6f 66 20 63 68 69 6c 64 ng list of child
7d80: 72 65 6e 20 6f 6e 20 70 61 74 68 20 25 73 20 66 ren on path %s f
7d90: 61 69 6c 65 64 2e 22 2c 20 70 61 74 68 29 3b 0a ailed.", path);.
7da0: 09 09 61 70 70 66 73 5f 63 61 6c 6c 5f 6c 69 62 ..appfs_call_lib
7db0: 74 63 6c 28 0a 09 09 09 41 50 50 46 53 5f 44 45 tcl(....APPFS_DE
7dc0: 42 55 47 28 22 54 63 6c 20 45 72 72 6f 72 20 69 BUG("Tcl Error i
7dd0: 73 3a 20 25 73 22 2c 20 54 63 6c 5f 47 65 74 53 s: %s", Tcl_GetS
7de0: 74 72 69 6e 67 52 65 73 75 6c 74 28 69 6e 74 65 tringResult(inte
7df0: 72 70 29 29 3b 0a 09 09 29 0a 0a 09 09 61 70 70 rp));...)....app
7e00: 66 73 5f 63 61 6c 6c 5f 6c 69 62 74 63 6c 28 54 fs_call_libtcl(T
7e10: 63 6c 5f 52 65 6c 65 61 73 65 28 69 6e 74 65 72 cl_Release(inter
7e20: 70 29 3b 29 0a 0a 09 09 72 65 74 75 72 6e 28 30 p);)....return(0
7e30: 29 3b 0a 09 7d 0a 0a 09 66 6f 72 20 28 69 64 78 );..}...for (idx
7e40: 20 3d 20 30 3b 20 69 64 78 20 3c 20 63 68 69 6c = 0; idx < chil
7e50: 64 72 65 6e 5f 63 6f 75 6e 74 3b 20 69 64 78 2b dren_count; idx+
7e60: 2b 29 20 7b 0a 09 09 61 70 70 66 73 5f 63 61 6c +) {...appfs_cal
7e70: 6c 5f 6c 69 62 74 63 6c 28 0a 09 09 09 66 69 6c l_libtcl(....fil
7e80: 6c 65 72 28 62 75 66 2c 20 54 63 6c 5f 47 65 74 ler(buf, Tcl_Get
7e90: 53 74 72 69 6e 67 28 63 68 69 6c 64 72 65 6e 5b String(children[
7ea0: 69 64 78 5d 29 2c 20 4e 55 4c 4c 2c 20 30 29 3b idx]), NULL, 0);
7eb0: 0a 09 09 29 0a 09 7d 0a 0a 09 61 70 70 66 73 5f ...)..}...appfs_
7ec0: 63 61 6c 6c 5f 6c 69 62 74 63 6c 28 54 63 6c 5f call_libtcl(Tcl_
7ed0: 52 65 6c 65 61 73 65 28 69 6e 74 65 72 70 29 3b Release(interp);
7ee0: 29 0a 0a 09 72 65 74 75 72 6e 28 30 29 3b 0a 7d )...return(0);.}
7ef0: 0a 0a 73 74 61 74 69 63 20 69 6e 74 20 61 70 70 ..static int app
7f00: 66 73 5f 66 75 73 65 5f 6f 70 65 6e 28 63 6f 6e fs_fuse_open(con
7f10: 73 74 20 63 68 61 72 20 2a 70 61 74 68 2c 20 73 st char *path, s
7f20: 74 72 75 63 74 20 66 75 73 65 5f 66 69 6c 65 5f truct fuse_file_
7f30: 69 6e 66 6f 20 2a 66 69 29 20 7b 0a 09 54 63 6c info *fi) {..Tcl
7f40: 5f 49 6e 74 65 72 70 20 2a 69 6e 74 65 72 70 3b _Interp *interp;
7f50: 0a 09 73 74 72 75 63 74 20 61 70 70 66 73 5f 70 ..struct appfs_p
7f60: 61 74 68 69 6e 66 6f 20 70 61 74 68 69 6e 66 6f athinfo pathinfo
7f70: 3b 0a 09 63 6f 6e 73 74 20 63 68 61 72 20 2a 72 ;..const char *r
7f80: 65 61 6c 5f 70 61 74 68 2c 20 2a 6d 6f 64 65 3b eal_path, *mode;
7f90: 0a 09 69 6e 74 20 67 70 69 5f 72 65 74 2c 20 74 ..int gpi_ret, t
7fa0: 63 6c 5f 72 65 74 3b 0a 09 69 6e 74 20 66 68 3b cl_ret;..int fh;
7fb0: 0a 0a 09 41 50 50 46 53 5f 44 45 42 55 47 28 22 ...APPFS_DEBUG("
7fc0: 45 6e 74 65 72 20 28 70 61 74 68 20 3d 20 25 73 Enter (path = %s
7fd0: 2c 20 2e 2e 2e 29 22 2c 20 70 61 74 68 29 3b 0a , ...)", path);.
7fe0: 0a 09 67 70 69 5f 72 65 74 20 3d 20 61 70 70 66 ..gpi_ret = appf
7ff0: 73 5f 67 65 74 5f 70 61 74 68 5f 69 6e 66 6f 28 s_get_path_info(
8000: 70 61 74 68 2c 20 26 70 61 74 68 69 6e 66 6f 29 path, &pathinfo)
8010: 3b 0a 0a 09 69 66 20 28 28 66 69 2d 3e 66 6c 61 ;...if ((fi->fla
8020: 67 73 20 26 20 28 4f 5f 57 52 4f 4e 4c 59 7c 4f gs & (O_WRONLY|O
8030: 5f 43 52 45 41 54 29 29 20 3d 3d 20 28 4f 5f 43 _CREAT)) == (O_C
8040: 52 45 41 54 7c 4f 5f 57 52 4f 4e 4c 59 29 29 20 REAT|O_WRONLY))
8050: 7b 0a 09 09 2f 2a 20 54 68 65 20 66 69 6c 65 20 {.../* The file
8060: 77 69 6c 6c 20 62 65 20 63 72 65 61 74 65 64 20 will be created
8070: 69 66 20 69 74 20 64 6f 65 73 20 6e 6f 74 20 65 if it does not e
8080: 78 69 73 74 20 2a 2f 0a 09 09 69 66 20 28 67 70 xist */...if (gp
8090: 69 5f 72 65 74 20 21 3d 20 30 20 26 26 20 67 70 i_ret != 0 && gp
80a0: 69 5f 72 65 74 20 21 3d 20 2d 45 4e 4f 45 4e 54 i_ret != -ENOENT
80b0: 29 20 7b 0a 09 09 09 41 50 50 46 53 5f 44 45 42 ) {....APPFS_DEB
80c0: 55 47 28 22 65 72 72 6f 72 3a 20 67 65 74 5f 70 UG("error: get_p
80d0: 61 74 68 5f 69 6e 66 6f 20 66 61 69 6c 65 64 22 ath_info failed"
80e0: 29 3b 0a 0a 09 09 09 72 65 74 75 72 6e 28 67 70 );.....return(gp
80f0: 69 5f 72 65 74 29 3b 0a 09 09 7d 0a 0a 09 09 6d i_ret);...}....m
8100: 6f 64 65 20 3d 20 22 63 72 65 61 74 65 22 3b 0a ode = "create";.
8110: 0a 09 09 2f 2a 0a 09 09 20 2a 20 57 65 20 68 61 .../*... * We ha
8120: 76 65 20 74 6f 20 63 6c 65 61 72 20 74 68 65 20 ve to clear the
8130: 63 61 63 68 65 20 68 65 72 65 20 73 6f 20 74 68 cache here so th
8140: 61 74 20 74 68 65 20 6e 75 6d 62 65 72 20 6f 66 at the number of
8150: 0a 09 09 20 2a 20 6c 69 6e 6b 73 20 67 65 74 73 ... * links gets
8160: 20 6d 61 69 6e 74 61 69 6e 65 64 20 6f 6e 20 74 maintained on t
8170: 68 65 20 70 61 72 65 6e 74 20 64 69 72 65 63 74 he parent direct
8180: 6f 72 79 0a 09 09 20 2a 2f 0a 09 09 61 70 70 66 ory... */...appf
8190: 73 5f 67 65 74 5f 70 61 74 68 5f 69 6e 66 6f 5f s_get_path_info_
81a0: 63 61 63 68 65 5f 66 6c 75 73 68 28 61 70 70 66 cache_flush(appf
81b0: 73 5f 67 65 74 5f 66 73 75 69 64 28 29 2c 20 2d s_get_fsuid(), -
81c0: 31 29 3b 0a 09 7d 20 65 6c 73 65 20 7b 0a 09 09 1);..} else {...
81d0: 2f 2a 20 54 68 65 20 66 69 6c 65 20 6d 75 73 74 /* The file must
81e0: 20 61 6c 72 65 61 64 79 20 65 78 69 73 74 20 2a already exist *
81f0: 2f 0a 09 09 69 66 20 28 67 70 69 5f 72 65 74 20 /...if (gpi_ret
8200: 21 3d 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 67 _DEBUG("error: g
8220: 65 74 5f 70 61 74 68 5f 69 6e 66 6f 20 66 61 69 et_path_info fai
8230: 6c 65 64 22 29 3b 0a 0a 09 09 09 72 65 74 75 72 led");.....retur
8240: 6e 28 67 70 69 5f 72 65 74 29 3b 0a 09 09 7d 0a n(gpi_ret);...}.
8250: 0a 09 09 6d 6f 64 65 20 3d 20 22 22 3b 0a 0a 09 ...mode = "";...
8260: 09 69 66 20 28 28 66 69 2d 3e 66 6c 61 67 73 20 .if ((fi->flags
8270: 26 20 4f 5f 57 52 4f 4e 4c 59 29 20 3d 3d 20 4f & O_WRONLY) == O
8280: 5f 57 52 4f 4e 4c 59 29 20 7b 0a 09 09 09 6d 6f _WRONLY) {....mo
8290: 64 65 20 3d 20 22 77 72 69 74 65 22 3b 0a 09 09 de = "write";...
82a0: 7d 0a 09 7d 0a 0a 09 69 66 20 28 70 61 74 68 69 }..}...if (pathi
82b0: 6e 66 6f 2e 74 79 70 65 20 3d 3d 20 41 50 50 46 nfo.type == APPF
82c0: 53 5f 50 41 54 48 54 59 50 45 5f 44 49 52 45 43 S_PATHTYPE_DIREC
82d0: 54 4f 52 59 29 20 7b 0a 09 09 41 50 50 46 53 5f TORY) {...APPFS_
82e0: 44 45 42 55 47 28 22 65 72 72 6f 72 3a 20 41 73 DEBUG("error: As
82f0: 6b 65 64 20 74 6f 20 6f 70 65 6e 20 61 20 64 69 ked to open a di
8300: 72 65 63 74 6f 72 79 2e 22 29 3b 0a 0a 09 09 72 rectory.");....r
8310: 65 74 75 72 6e 28 2d 45 49 53 44 49 52 29 3b 0a eturn(-EISDIR);.
8320: 09 7d 0a 0a 09 69 6e 74 65 72 70 20 3d 20 61 70 .}...interp = ap
8330: 70 66 73 5f 54 63 6c 49 6e 74 65 72 70 28 29 3b pfs_TclInterp();
8340: 0a 09 69 66 20 28 69 6e 74 65 72 70 20 3d 3d 20 ..if (interp ==
8350: 4e 55 4c 4c 29 20 7b 0a 09 09 41 50 50 46 53 5f NULL) {...APPFS_
8360: 44 45 42 55 47 28 22 65 72 72 6f 72 3a 20 55 6e DEBUG("error: Un
8370: 61 62 6c 65 20 74 6f 20 67 65 74 20 61 6e 20 69 able to get an i
8380: 6e 74 65 72 70 72 65 74 65 72 22 29 3b 0a 0a 09 nterpreter");...
8390: 09 72 65 74 75 72 6e 28 2d 45 49 4f 29 3b 0a 09 .return(-EIO);..
83a0: 7d 0a 0a 09 61 70 70 66 73 5f 63 61 6c 6c 5f 6c }...appfs_call_l
83b0: 69 62 74 63 6c 28 54 63 6c 5f 50 72 65 73 65 72 ibtcl(Tcl_Preser
83c0: 76 65 28 69 6e 74 65 72 70 29 3b 29 0a 0a 09 74 ve(interp);)...t
83d0: 63 6c 5f 72 65 74 20 3d 20 61 70 70 66 73 5f 54 cl_ret = appfs_T
83e0: 63 6c 5f 45 76 61 6c 28 69 6e 74 65 72 70 2c 20 cl_Eval(interp,
83f0: 33 2c 20 22 3a 3a 61 70 70 66 73 3a 3a 6f 70 65 3, "::appfs::ope
8400: 6e 70 61 74 68 22 2c 20 70 61 74 68 2c 20 6d 6f npath", path, mo
8410: 64 65 29 3b 0a 09 69 66 20 28 74 63 6c 5f 72 65 de);..if (tcl_re
8420: 74 20 21 3d 20 54 43 4c 5f 4f 4b 29 20 7b 0a 09 t != TCL_OK) {..
8430: 09 41 50 50 46 53 5f 44 45 42 55 47 28 22 3a 3a .APPFS_DEBUG("::
8440: 61 70 70 66 73 3a 3a 6f 70 65 6e 70 61 74 68 28 appfs::openpath(
8450: 25 73 2c 20 25 73 29 20 66 61 69 6c 65 64 2e 22 %s, %s) failed."
8460: 2c 20 70 61 74 68 2c 20 6d 6f 64 65 29 3b 0a 09 , path, mode);..
8470: 09 61 70 70 66 73 5f 63 61 6c 6c 5f 6c 69 62 74 .appfs_call_libt
8480: 63 6c 28 0a 09 09 09 41 50 50 46 53 5f 44 45 42 cl(....APPFS_DEB
8490: 55 47 28 22 54 63 6c 20 45 72 72 6f 72 20 69 73 UG("Tcl Error is
84a0: 3a 20 25 73 22 2c 20 54 63 6c 5f 47 65 74 53 74 : %s", Tcl_GetSt
84b0: 72 69 6e 67 52 65 73 75 6c 74 28 69 6e 74 65 72 ringResult(inter
84c0: 70 29 29 3b 0a 09 09 29 0a 0a 09 09 61 70 70 66 p));...)....appf
84d0: 73 5f 63 61 6c 6c 5f 6c 69 62 74 63 6c 28 54 63 s_call_libtcl(Tc
84e0: 6c 5f 52 65 6c 65 61 73 65 28 69 6e 74 65 72 70 l_Release(interp
84f0: 29 3b 29 0a 0a 09 09 72 65 74 75 72 6e 28 2d 45 );)....return(-E
8500: 49 4f 29 3b 0a 09 7d 0a 0a 09 61 70 70 66 73 5f IO);..}...appfs_
8510: 63 61 6c 6c 5f 6c 69 62 74 63 6c 28 0a 09 09 72 call_libtcl(...r
8520: 65 61 6c 5f 70 61 74 68 20 3d 20 54 63 6c 5f 47 eal_path = Tcl_G
8530: 65 74 53 74 72 69 6e 67 52 65 73 75 6c 74 28 69 etStringResult(i
8540: 6e 74 65 72 70 29 3b 0a 09 29 0a 0a 09 61 70 70 nterp);..)...app
8550: 66 73 5f 63 61 6c 6c 5f 6c 69 62 74 63 6c 28 54 fs_call_libtcl(T
8560: 63 6c 5f 52 65 6c 65 61 73 65 28 69 6e 74 65 72 cl_Release(inter
8570: 70 29 3b 29 0a 0a 09 69 66 20 28 72 65 61 6c 5f p);)...if (real_
8580: 70 61 74 68 20 3d 3d 20 4e 55 4c 4c 29 20 7b 0a path == NULL) {.
8590: 09 09 41 50 50 46 53 5f 44 45 42 55 47 28 22 65 ..APPFS_DEBUG("e
85a0: 72 72 6f 72 3a 20 72 65 61 6c 5f 70 61 74 68 20 rror: real_path
85b0: 77 61 73 20 4e 55 4c 4c 2e 22 29 0a 0a 09 09 72 was NULL.")....r
85c0: 65 74 75 72 6e 28 2d 45 49 4f 29 3b 0a 09 7d 0a eturn(-EIO);..}.
85d0: 0a 09 41 50 50 46 53 5f 44 45 42 55 47 28 22 54 ..APPFS_DEBUG("T
85e0: 72 61 6e 73 6c 61 74 65 64 20 72 65 71 75 65 73 ranslated reques
85f0: 74 20 74 6f 20 6f 70 65 6e 20 25 73 20 74 6f 20 t to open %s to
8600: 6f 70 65 6e 69 6e 67 20 25 73 20 28 6d 6f 64 65 opening %s (mode
8610: 20 3d 20 5c 22 25 73 5c 22 29 22 2c 20 70 61 74 = \"%s\")", pat
8620: 68 2c 20 72 65 61 6c 5f 70 61 74 68 2c 20 6d 6f h, real_path, mo
8630: 64 65 29 3b 0a 0a 09 66 68 20 3d 20 6f 70 65 6e de);...fh = open
8640: 28 72 65 61 6c 5f 70 61 74 68 2c 20 66 69 2d 3e (real_path, fi->
8650: 66 6c 61 67 73 2c 20 30 36 30 30 29 3b 0a 0a 09 flags, 0600);...
8660: 69 66 20 28 66 68 20 3c 20 30 29 20 7b 0a 09 09 if (fh < 0) {...
8670: 41 50 50 46 53 5f 44 45 42 55 47 28 22 65 72 72 APPFS_DEBUG("err
8680: 6f 72 3a 20 6f 70 65 6e 20 66 61 69 6c 65 64 22 or: open failed"
8690: 29 3b 0a 0a 09 09 72 65 74 75 72 6e 28 65 72 72 );....return(err
86a0: 6e 6f 20 2a 20 2d 31 29 3b 0a 09 7d 0a 0a 09 66 no * -1);..}...f
86b0: 69 2d 3e 66 68 20 3d 20 66 68 3b 0a 0a 09 72 65 i->fh = fh;...re
86c0: 74 75 72 6e 28 30 29 3b 0a 7d 0a 0a 73 74 61 74 turn(0);.}..stat
86d0: 69 63 20 69 6e 74 20 61 70 70 66 73 5f 66 75 73 ic int appfs_fus
86e0: 65 5f 63 6c 6f 73 65 28 63 6f 6e 73 74 20 63 68 e_close(const ch
86f0: 61 72 20 2a 70 61 74 68 2c 20 73 74 72 75 63 74 ar *path, struct
8700: 20 66 75 73 65 5f 66 69 6c 65 5f 69 6e 66 6f 20 fuse_file_info
8710: 2a 66 69 29 20 7b 0a 09 69 6e 74 20 63 6c 6f 73 *fi) {..int clos
8720: 65 5f 72 65 74 3b 0a 0a 09 61 70 70 66 73 5f 67 e_ret;...appfs_g
8730: 65 74 5f 70 61 74 68 5f 69 6e 66 6f 5f 63 61 63 et_path_info_cac
8740: 68 65 5f 72 6d 28 70 61 74 68 2c 20 61 70 70 66 he_rm(path, appf
8750: 73 5f 67 65 74 5f 66 73 75 69 64 28 29 29 3b 0a s_get_fsuid());.
8760: 0a 09 63 6c 6f 73 65 5f 72 65 74 20 3d 20 63 6c ..close_ret = cl
8770: 6f 73 65 28 66 69 2d 3e 66 68 29 3b 0a 09 69 66 ose(fi->fh);..if
8780: 20 28 63 6c 6f 73 65 5f 72 65 74 20 21 3d 20 30 (close_ret != 0
8790: 29 20 7b 0a 09 09 41 50 50 46 53 5f 44 45 42 55 ) {...APPFS_DEBU
87a0: 47 28 22 65 72 72 6f 72 3a 20 63 6c 6f 73 65 20 G("error: close
87b0: 66 61 69 6c 65 64 22 29 3b 0a 0a 09 09 72 65 74 failed");....ret
87c0: 75 72 6e 28 65 72 72 6e 6f 20 2a 20 2d 31 29 3b urn(errno * -1);
87d0: 0a 09 7d 0a 0a 09 72 65 74 75 72 6e 28 30 29 3b ..}...return(0);
87e0: 0a 7d 0a 0a 73 74 61 74 69 63 20 69 6e 74 20 61 .}..static int a
87f0: 70 70 66 73 5f 66 75 73 65 5f 72 65 61 64 28 63 ppfs_fuse_read(c
8800: 6f 6e 73 74 20 63 68 61 72 20 2a 70 61 74 68 2c onst char *path,
8810: 20 63 68 61 72 20 2a 62 75 66 2c 20 73 69 7a 65 char *buf, size
8820: 5f 74 20 73 69 7a 65 2c 20 6f 66 66 5f 74 20 6f _t size, off_t o
8830: 66 66 73 65 74 2c 20 73 74 72 75 63 74 20 66 75 ffset, struct fu
8840: 73 65 5f 66 69 6c 65 5f 69 6e 66 6f 20 2a 66 69 se_file_info *fi
8850: 29 20 7b 0a 09 73 73 69 7a 65 5f 74 20 72 65 61 ) {..ssize_t rea
8860: 64 5f 72 65 74 3b 0a 09 69 6e 74 20 72 65 74 76 d_ret;..int retv
8870: 61 6c 3b 0a 0a 09 41 50 50 46 53 5f 44 45 42 55 al;...APPFS_DEBU
8880: 47 28 22 45 6e 74 65 72 20 28 70 61 74 68 20 3d G("Enter (path =
8890: 20 25 73 2c 20 62 75 66 2c 20 25 6c 6c 69 2c 20 %s, buf, %lli,
88a0: 25 6c 6c 69 2c 20 66 64 3d 25 6c 6c 69 29 22 2c %lli, fd=%lli)",
88b0: 20 70 61 74 68 2c 20 28 6c 6f 6e 67 20 6c 6f 6e path, (long lon
88c0: 67 29 20 73 69 7a 65 2c 20 28 6c 6f 6e 67 20 6c g) size, (long l
88d0: 6f 6e 67 29 20 6f 66 66 73 65 74 2c 20 28 6c 6f ong) offset, (lo
88e0: 6e 67 20 6c 6f 6e 67 29 20 66 69 2d 3e 66 68 29 ng long) fi->fh)
88f0: 3b 0a 0a 09 72 65 74 76 61 6c 20 3d 20 30 3b 0a ;...retval = 0;.
8900: 0a 09 77 68 69 6c 65 20 28 73 69 7a 65 20 21 3d ..while (size !=
8910: 20 30 29 20 7b 0a 09 09 72 65 61 64 5f 72 65 74 0) {...read_ret
8920: 20 3d 20 70 72 65 61 64 28 66 69 2d 3e 66 68 2c = pread(fi->fh,
8930: 20 62 75 66 2c 20 73 69 7a 65 2c 20 6f 66 66 73 buf, size, offs
8940: 65 74 29 3b 0a 0a 09 09 69 66 20 28 72 65 61 64 et);....if (read
8950: 5f 72 65 74 20 3c 20 30 29 20 7b 0a 09 09 09 41 _ret < 0) {....A
8960: 50 50 46 53 5f 44 45 42 55 47 28 22 65 72 72 6f PPFS_DEBUG("erro
8970: 72 3a 20 72 65 61 64 20 66 61 69 6c 65 64 22 29 r: read failed")
8980: 3b 0a 0a 09 09 09 72 65 74 75 72 6e 28 65 72 72 ;.....return(err
8990: 6e 6f 20 2a 20 2d 31 29 3b 0a 09 09 7d 0a 0a 09 no * -1);...}...
89a0: 09 69 66 20 28 72 65 61 64 5f 72 65 74 20 3d 3d .if (read_ret ==
89b0: 20 30 29 20 7b 0a 09 09 09 62 72 65 61 6b 3b 0a 0) {....break;.
89c0: 09 09 7d 0a 0a 09 09 73 69 7a 65 20 2d 3d 20 72 ..}....size -= r
89d0: 65 61 64 5f 72 65 74 3b 0a 09 09 62 75 66 20 20 ead_ret;...buf
89e0: 2b 3d 20 72 65 61 64 5f 72 65 74 3b 0a 09 09 6f += read_ret;...o
89f0: 66 66 73 65 74 20 2b 3d 20 72 65 61 64 5f 72 65 ffset += read_re
8a00: 74 3b 0a 09 09 72 65 74 76 61 6c 20 2b 3d 20 72 t;...retval += r
8a10: 65 61 64 5f 72 65 74 3b 0a 09 7d 0a 0a 09 69 66 ead_ret;..}...if
8a20: 20 28 73 69 7a 65 20 21 3d 20 30 29 20 7b 0a 09 (size != 0) {..
8a30: 09 41 50 50 46 53 5f 44 45 42 55 47 28 22 65 72 .APPFS_DEBUG("er
8a40: 72 6f 72 3a 20 69 6e 63 6f 6d 70 6c 65 74 65 20 ror: incomplete
8a50: 72 65 61 64 20 28 74 68 69 73 20 6d 69 67 68 74 read (this might
8a60: 20 62 65 20 61 6e 20 65 72 72 6f 72 20 62 65 63 be an error bec
8a70: 61 75 73 65 20 46 55 53 45 20 77 69 6c 6c 20 72 ause FUSE will r
8a80: 65 71 75 65 73 74 20 74 68 65 20 65 78 61 63 74 equest the exact
8a90: 20 6c 65 6e 67 74 68 20 6f 66 20 74 68 65 20 66 length of the f
8aa0: 69 6c 65 29 22 29 3b 0a 09 7d 0a 0a 09 41 50 50 ile)");..}...APP
8ab0: 46 53 5f 44 45 42 55 47 28 22 52 65 74 75 72 6e FS_DEBUG("Return
8ac0: 69 6e 67 3a 20 25 69 22 2c 20 72 65 74 76 61 6c ing: %i", retval
8ad0: 29 3b 0a 0a 09 72 65 74 75 72 6e 28 72 65 74 76 );...return(retv
8ae0: 61 6c 29 3b 0a 7d 0a 0a 73 74 61 74 69 63 20 69 al);.}..static i
8af0: 6e 74 20 61 70 70 66 73 5f 66 75 73 65 5f 77 72 nt appfs_fuse_wr
8b00: 69 74 65 28 63 6f 6e 73 74 20 63 68 61 72 20 2a ite(const char *
8b10: 70 61 74 68 2c 20 63 6f 6e 73 74 20 63 68 61 72 path, const char
8b20: 20 2a 62 75 66 2c 20 73 69 7a 65 5f 74 20 73 69 *buf, size_t si
8b30: 7a 65 2c 20 6f 66 66 5f 74 20 6f 66 66 73 65 74 ze, off_t offset
8b40: 2c 20 73 74 72 75 63 74 20 66 75 73 65 5f 66 69 , struct fuse_fi
8b50: 6c 65 5f 69 6e 66 6f 20 2a 66 69 29 20 7b 0a 09 le_info *fi) {..
8b60: 73 73 69 7a 65 5f 74 20 77 72 69 74 65 5f 72 65 ssize_t write_re
8b70: 74 3b 0a 09 69 6e 74 20 72 65 74 76 61 6c 3b 0a t;..int retval;.
8b80: 0a 09 41 50 50 46 53 5f 44 45 42 55 47 28 22 45 ..APPFS_DEBUG("E
8b90: 6e 74 65 72 20 28 70 61 74 68 20 3d 20 25 73 2c nter (path = %s,
8ba0: 20 2e 2e 2e 29 22 2c 20 70 61 74 68 29 3b 0a 0a ...)", path);..
8bb0: 09 61 70 70 66 73 5f 67 65 74 5f 70 61 74 68 5f .appfs_get_path_
8bc0: 69 6e 66 6f 5f 63 61 63 68 65 5f 72 6d 28 70 61 info_cache_rm(pa
8bd0: 74 68 2c 20 61 70 70 66 73 5f 67 65 74 5f 66 73 th, appfs_get_fs
8be0: 75 69 64 28 29 29 3b 0a 0a 09 72 65 74 76 61 6c uid());...retval
8bf0: 20 3d 20 30 3b 0a 0a 09 77 68 69 6c 65 20 28 73 = 0;...while (s
8c00: 69 7a 65 20 21 3d 20 30 29 20 7b 0a 09 09 77 72 ize != 0) {...wr
8c10: 69 74 65 5f 72 65 74 20 3d 20 70 77 72 69 74 65 ite_ret = pwrite
8c20: 28 66 69 2d 3e 66 68 2c 20 62 75 66 2c 20 73 69 (fi->fh, buf, si
8c30: 7a 65 2c 20 6f 66 66 73 65 74 29 3b 0a 0a 09 09 ze, offset);....
8c40: 69 66 20 28 77 72 69 74 65 5f 72 65 74 20 3c 20 if (write_ret <
8c50: 30 29 20 7b 0a 09 09 09 41 50 50 46 53 5f 44 45 0) {....APPFS_DE
8c60: 42 55 47 28 22 65 72 72 6f 72 3a 20 77 72 69 74 BUG("error: writ
8c70: 65 20 66 61 69 6c 65 64 22 29 3b 0a 0a 09 09 09 e failed");.....
8c80: 72 65 74 75 72 6e 28 65 72 72 6e 6f 20 2a 20 2d return(errno * -
8c90: 31 29 3b 0a 09 09 7d 0a 0a 09 09 69 66 20 28 77 1);...}....if (w
8ca0: 72 69 74 65 5f 72 65 74 20 3d 3d 20 30 29 20 7b rite_ret == 0) {
8cb0: 0a 09 09 09 62 72 65 61 6b 3b 0a 09 09 7d 0a 0a ....break;...}..
8cc0: 09 09 73 69 7a 65 20 2d 3d 20 77 72 69 74 65 5f ..size -= write_
8cd0: 72 65 74 3b 0a 09 09 62 75 66 20 20 2b 3d 20 77 ret;...buf += w
8ce0: 72 69 74 65 5f 72 65 74 3b 0a 09 09 6f 66 66 73 rite_ret;...offs
8cf0: 65 74 20 2b 3d 20 77 72 69 74 65 5f 72 65 74 3b et += write_ret;
8d00: 0a 09 09 72 65 74 76 61 6c 20 2b 3d 20 77 72 69 ...retval += wri
8d10: 74 65 5f 72 65 74 3b 0a 09 7d 0a 0a 09 69 66 20 te_ret;..}...if
8d20: 28 73 69 7a 65 20 21 3d 20 30 29 20 7b 0a 09 09 (size != 0) {...
8d30: 41 50 50 46 53 5f 44 45 42 55 47 28 22 65 72 72 APPFS_DEBUG("err
8d40: 6f 72 3a 20 69 6e 63 6f 6d 70 6c 65 74 65 20 77 or: incomplete w
8d50: 72 69 74 65 22 29 3b 0a 09 7d 0a 0a 09 72 65 74 rite");..}...ret
8d60: 75 72 6e 28 72 65 74 76 61 6c 29 3b 0a 7d 0a 0a urn(retval);.}..
8d70: 73 74 61 74 69 63 20 69 6e 74 20 61 70 70 66 73 static int appfs
8d80: 5f 66 75 73 65 5f 6d 6b 6e 6f 64 28 63 6f 6e 73 _fuse_mknod(cons
8d90: 74 20 63 68 61 72 20 2a 70 61 74 68 2c 20 6d 6f t char *path, mo
8da0: 64 65 5f 74 20 6d 6f 64 65 2c 20 64 65 76 5f 74 de_t mode, dev_t
8db0: 20 64 65 76 69 63 65 29 20 7b 0a 09 63 68 61 72 device) {..char
8dc0: 20 2a 72 65 61 6c 5f 70 61 74 68 3b 0a 09 69 6e *real_path;..in
8dd0: 74 20 6d 6b 6e 6f 64 5f 72 65 74 3b 0a 0a 09 41 t mknod_ret;...A
8de0: 50 50 46 53 5f 44 45 42 55 47 28 22 45 6e 74 65 PPFS_DEBUG("Ente
8df0: 72 20 28 70 61 74 68 20 3d 20 25 73 2c 20 2e 2e r (path = %s, ..
8e00: 2e 29 22 2c 20 70 61 74 68 29 3b 0a 0a 09 69 66 .)", path);...if
8e10: 20 28 28 6d 6f 64 65 20 26 20 53 5f 49 46 43 48 ((mode & S_IFCH
8e20: 52 29 20 3d 3d 20 53 5f 49 46 43 48 52 29 20 7b R) == S_IFCHR) {
8e30: 0a 09 09 72 65 74 75 72 6e 28 2d 45 50 45 52 4d ...return(-EPERM
8e40: 29 3b 0a 09 7d 0a 0a 09 69 66 20 28 28 6d 6f 64 );..}...if ((mod
8e50: 65 20 26 20 53 5f 49 46 42 4c 4b 29 20 3d 3d 20 e & S_IFBLK) ==
8e60: 53 5f 49 46 42 4c 4b 29 20 7b 0a 09 09 72 65 74 S_IFBLK) {...ret
8e70: 75 72 6e 28 2d 45 50 45 52 4d 29 3b 0a 09 7d 0a urn(-EPERM);..}.
8e80: 0a 09 72 65 61 6c 5f 70 61 74 68 20 3d 20 61 70 ..real_path = ap
8e90: 70 66 73 5f 70 72 65 70 61 72 65 5f 74 6f 5f 63 pfs_prepare_to_c
8ea0: 72 65 61 74 65 28 70 61 74 68 29 3b 0a 09 69 66 reate(path);..if
8eb0: 20 28 72 65 61 6c 5f 70 61 74 68 20 3d 3d 20 4e (real_path == N
8ec0: 55 4c 4c 29 20 7b 0a 09 09 72 65 74 75 72 6e 28 ULL) {...return(
8ed0: 2d 45 49 4f 29 3b 0a 09 7d 0a 0a 09 61 70 70 66 -EIO);..}...appf
8ee0: 73 5f 73 69 6d 75 6c 61 74 65 5f 75 73 65 72 5f s_simulate_user_
8ef0: 66 73 5f 65 6e 74 65 72 28 29 3b 0a 0a 09 6d 6b fs_enter();...mk
8f00: 6e 6f 64 5f 72 65 74 20 3d 20 6d 6b 6e 6f 64 28 nod_ret = mknod(
8f10: 72 65 61 6c 5f 70 61 74 68 2c 20 6d 6f 64 65 2c real_path, mode,
8f20: 20 64 65 76 69 63 65 29 3b 0a 0a 09 61 70 70 66 device);...appf
8f30: 73 5f 73 69 6d 75 6c 61 74 65 5f 75 73 65 72 5f s_simulate_user_
8f40: 66 73 5f 6c 65 61 76 65 28 29 3b 0a 0a 09 66 72 fs_leave();...fr
8f50: 65 65 28 72 65 61 6c 5f 70 61 74 68 29 3b 0a 0a ee(real_path);..
8f60: 09 69 66 20 28 6d 6b 6e 6f 64 5f 72 65 74 20 21 .if (mknod_ret !
8f70: 3d 20 30 29 20 7b 0a 09 09 72 65 74 75 72 6e 28 = 0) {...return(
8f80: 65 72 72 6e 6f 20 2a 20 2d 31 29 3b 0a 09 7d 0a errno * -1);..}.
8f90: 0a 09 72 65 74 75 72 6e 28 30 29 3b 0a 7d 0a 0a ..return(0);.}..
8fa0: 73 74 61 74 69 63 20 69 6e 74 20 61 70 70 66 73 static int appfs
8fb0: 5f 66 75 73 65 5f 63 72 65 61 74 65 28 63 6f 6e _fuse_create(con
8fc0: 73 74 20 63 68 61 72 20 2a 70 61 74 68 2c 20 6d st char *path, m
8fd0: 6f 64 65 5f 74 20 6d 6f 64 65 2c 20 73 74 72 75 ode_t mode, stru
8fe0: 63 74 20 66 75 73 65 5f 66 69 6c 65 5f 69 6e 66 ct fuse_file_inf
8ff0: 6f 20 2a 66 69 29 20 7b 0a 09 63 68 61 72 20 2a o *fi) {..char *
9000: 72 65 61 6c 5f 70 61 74 68 3b 0a 09 69 6e 74 20 real_path;..int
9010: 66 64 3b 0a 0a 09 41 50 50 46 53 5f 44 45 42 55 fd;...APPFS_DEBU
9020: 47 28 22 45 6e 74 65 72 20 28 70 61 74 68 20 3d G("Enter (path =
9030: 20 25 73 2c 20 2e 2e 2e 29 22 2c 20 70 61 74 68 %s, ...)", path
9040: 29 3b 0a 0a 09 69 66 20 28 28 6d 6f 64 65 20 26 );...if ((mode &
9050: 20 53 5f 49 46 43 48 52 29 20 3d 3d 20 53 5f 49 S_IFCHR) == S_I
9060: 46 43 48 52 29 20 7b 0a 09 09 72 65 74 75 72 6e FCHR) {...return
9070: 28 2d 45 50 45 52 4d 29 3b 0a 09 7d 0a 0a 09 69 (-EPERM);..}...i
9080: 66 20 28 28 6d 6f 64 65 20 26 20 53 5f 49 46 42 f ((mode & S_IFB
9090: 4c 4b 29 20 3d 3d 20 53 5f 49 46 42 4c 4b 29 20 LK) == S_IFBLK)
90a0: 7b 0a 09 09 72 65 74 75 72 6e 28 2d 45 50 45 52 {...return(-EPER
90b0: 4d 29 3b 0a 09 7d 0a 0a 09 72 65 61 6c 5f 70 61 M);..}...real_pa
90c0: 74 68 20 3d 20 61 70 70 66 73 5f 70 72 65 70 61 th = appfs_prepa
90d0: 72 65 5f 74 6f 5f 63 72 65 61 74 65 28 70 61 74 re_to_create(pat
90e0: 68 29 3b 0a 09 69 66 20 28 72 65 61 6c 5f 70 61 h);..if (real_pa
90f0: 74 68 20 3d 3d 20 4e 55 4c 4c 29 20 7b 0a 09 09 th == NULL) {...
9100: 72 65 74 75 72 6e 28 2d 45 49 4f 29 3b 0a 09 7d return(-EIO);..}
9110: 0a 0a 09 61 70 70 66 73 5f 73 69 6d 75 6c 61 74 ...appfs_simulat
9120: 65 5f 75 73 65 72 5f 66 73 5f 65 6e 74 65 72 28 e_user_fs_enter(
9130: 29 3b 0a 0a 09 66 64 20 3d 20 63 72 65 61 74 28 );...fd = creat(
9140: 72 65 61 6c 5f 70 61 74 68 2c 20 6d 6f 64 65 29 real_path, mode)
9150: 3b 0a 0a 09 61 70 70 66 73 5f 73 69 6d 75 6c 61 ;...appfs_simula
9160: 74 65 5f 75 73 65 72 5f 66 73 5f 6c 65 61 76 65 te_user_fs_leave
9170: 28 29 3b 0a 0a 09 66 72 65 65 28 72 65 61 6c 5f ();...free(real_
9180: 70 61 74 68 29 3b 0a 0a 09 69 66 20 28 66 64 20 path);...if (fd
9190: 3c 20 30 29 20 7b 0a 09 09 72 65 74 75 72 6e 28 < 0) {...return(
91a0: 65 72 72 6e 6f 20 2a 20 2d 31 29 3b 0a 09 7d 0a errno * -1);..}.
91b0: 0a 09 66 69 2d 3e 66 68 20 3d 20 66 64 3b 0a 0a ..fi->fh = fd;..
91c0: 09 72 65 74 75 72 6e 28 30 29 3b 0a 7d 0a 0a 73 .return(0);.}..s
91d0: 74 61 74 69 63 20 69 6e 74 20 61 70 70 66 73 5f tatic int appfs_
91e0: 66 75 73 65 5f 74 72 75 6e 63 61 74 65 28 63 6f fuse_truncate(co
91f0: 6e 73 74 20 63 68 61 72 20 2a 70 61 74 68 2c 20 nst char *path,
9200: 6f 66 66 5f 74 20 73 69 7a 65 29 20 7b 0a 09 63 off_t size) {..c
9210: 68 61 72 20 2a 72 65 61 6c 5f 70 61 74 68 3b 0a har *real_path;.
9220: 09 69 6e 74 20 74 72 75 6e 63 61 74 65 5f 72 65 .int truncate_re
9230: 74 3b 0a 0a 09 41 50 50 46 53 5f 44 45 42 55 47 t;...APPFS_DEBUG
9240: 28 22 45 6e 74 65 72 20 28 70 61 74 68 20 3d 20 ("Enter (path =
9250: 25 73 2c 20 2e 2e 2e 29 22 2c 20 70 61 74 68 29 %s, ...)", path)
9260: 3b 0a 0a 09 72 65 61 6c 5f 70 61 74 68 20 3d 20 ;...real_path =
9270: 61 70 70 66 73 5f 6c 6f 63 61 6c 70 61 74 68 28 appfs_localpath(
9280: 70 61 74 68 29 3b 0a 09 69 66 20 28 72 65 61 6c path);..if (real
9290: 5f 70 61 74 68 20 3d 3d 20 4e 55 4c 4c 29 20 7b _path == NULL) {
92a0: 0a 09 09 72 65 74 75 72 6e 28 2d 45 49 4f 29 3b ...return(-EIO);
92b0: 0a 09 7d 0a 0a 09 61 70 70 66 73 5f 67 65 74 5f ..}...appfs_get_
92c0: 70 61 74 68 5f 69 6e 66 6f 5f 63 61 63 68 65 5f path_info_cache_
92d0: 72 6d 28 70 61 74 68 2c 20 61 70 70 66 73 5f 67 rm(path, appfs_g
92e0: 65 74 5f 66 73 75 69 64 28 29 29 3b 0a 0a 09 61 et_fsuid());...a
92f0: 70 70 66 73 5f 73 69 6d 75 6c 61 74 65 5f 75 73 ppfs_simulate_us
9300: 65 72 5f 66 73 5f 65 6e 74 65 72 28 29 3b 0a 0a er_fs_enter();..
9310: 09 74 72 75 6e 63 61 74 65 5f 72 65 74 20 3d 20 .truncate_ret =
9320: 74 72 75 6e 63 61 74 65 28 72 65 61 6c 5f 70 61 truncate(real_pa
9330: 74 68 2c 20 73 69 7a 65 29 3b 0a 0a 09 61 70 70 th, size);...app
9340: 66 73 5f 73 69 6d 75 6c 61 74 65 5f 75 73 65 72 fs_simulate_user
9350: 5f 66 73 5f 6c 65 61 76 65 28 29 3b 0a 0a 09 66 _fs_leave();...f
9360: 72 65 65 28 72 65 61 6c 5f 70 61 74 68 29 3b 0a ree(real_path);.
9370: 0a 09 69 66 20 28 74 72 75 6e 63 61 74 65 5f 72 ..if (truncate_r
9380: 65 74 20 21 3d 20 30 29 20 7b 0a 09 09 72 65 74 et != 0) {...ret
9390: 75 72 6e 28 65 72 72 6e 6f 20 2a 20 2d 31 29 3b urn(errno * -1);
93a0: 0a 09 7d 0a 0a 09 72 65 74 75 72 6e 28 30 29 3b ..}...return(0);
93b0: 0a 7d 0a 0a 73 74 61 74 69 63 20 69 6e 74 20 61 .}..static int a
93c0: 70 70 66 73 5f 66 75 73 65 5f 75 6e 6c 69 6e 6b ppfs_fuse_unlink
93d0: 5f 72 6d 64 69 72 28 63 6f 6e 73 74 20 63 68 61 _rmdir(const cha
93e0: 72 20 2a 70 61 74 68 29 20 7b 0a 09 54 63 6c 5f r *path) {..Tcl_
93f0: 49 6e 74 65 72 70 20 2a 69 6e 74 65 72 70 3b 0a Interp *interp;.
9400: 09 69 6e 74 20 74 63 6c 5f 72 65 74 3b 0a 0a 09 .int tcl_ret;...
9410: 41 50 50 46 53 5f 44 45 42 55 47 28 22 45 6e 74 APPFS_DEBUG("Ent
9420: 65 72 20 28 70 61 74 68 20 3d 20 25 73 2c 20 2e er (path = %s, .
9430: 2e 2e 29 22 2c 20 70 61 74 68 29 3b 0a 0a 09 61 ..)", path);...a
9440: 70 70 66 73 5f 67 65 74 5f 70 61 74 68 5f 69 6e ppfs_get_path_in
9450: 66 6f 5f 63 61 63 68 65 5f 66 6c 75 73 68 28 61 fo_cache_flush(a
9460: 70 70 66 73 5f 67 65 74 5f 66 73 75 69 64 28 29 ppfs_get_fsuid()
9470: 2c 20 2d 31 29 3b 0a 0a 09 69 6e 74 65 72 70 20 , -1);...interp
9480: 3d 20 61 70 70 66 73 5f 54 63 6c 49 6e 74 65 72 = appfs_TclInter
9490: 70 28 29 3b 0a 09 69 66 20 28 69 6e 74 65 72 70 p();..if (interp
94a0: 20 3d 3d 20 4e 55 4c 4c 29 20 7b 0a 09 09 72 65 == NULL) {...re
94b0: 74 75 72 6e 28 2d 45 49 4f 29 3b 0a 09 7d 0a 0a turn(-EIO);..}..
94c0: 09 61 70 70 66 73 5f 63 61 6c 6c 5f 6c 69 62 74 .appfs_call_libt
94d0: 63 6c 28 54 63 6c 5f 50 72 65 73 65 72 76 65 28 cl(Tcl_Preserve(
94e0: 69 6e 74 65 72 70 29 3b 29 0a 0a 09 74 63 6c 5f interp);)...tcl_
94f0: 72 65 74 20 3d 20 61 70 70 66 73 5f 54 63 6c 5f ret = appfs_Tcl_
9500: 45 76 61 6c 28 69 6e 74 65 72 70 2c 20 32 2c 20 Eval(interp, 2,
9510: 22 3a 3a 61 70 70 66 73 3a 3a 75 6e 6c 69 6e 6b "::appfs::unlink
9520: 70 61 74 68 22 2c 20 70 61 74 68 29 3b 0a 09 69 path", path);..i
9530: 66 20 28 74 63 6c 5f 72 65 74 20 21 3d 20 54 43 f (tcl_ret != TC
9540: 4c 5f 4f 4b 29 20 7b 0a 09 09 41 50 50 46 53 5f L_OK) {...APPFS_
9550: 44 45 42 55 47 28 22 3a 3a 61 70 70 66 73 3a 3a DEBUG("::appfs::
9560: 75 6e 6c 69 6e 6b 70 61 74 68 28 25 73 29 20 66 unlinkpath(%s) f
9570: 61 69 6c 65 64 2e 22 2c 20 70 61 74 68 29 3b 0a ailed.", path);.
9580: 09 09 61 70 70 66 73 5f 63 61 6c 6c 5f 6c 69 62 ..appfs_call_lib
9590: 74 63 6c 28 0a 09 09 09 41 50 50 46 53 5f 44 45 tcl(....APPFS_DE
95a0: 42 55 47 28 22 54 63 6c 20 45 72 72 6f 72 20 69 BUG("Tcl Error i
95b0: 73 3a 20 25 73 22 2c 20 54 63 6c 5f 47 65 74 53 s: %s", Tcl_GetS
95c0: 74 72 69 6e 67 52 65 73 75 6c 74 28 69 6e 74 65 tringResult(inte
95d0: 72 70 29 29 3b 0a 09 09 29 0a 0a 09 09 61 70 70 rp));...)....app
95e0: 66 73 5f 63 61 6c 6c 5f 6c 69 62 74 63 6c 28 54 fs_call_libtcl(T
95f0: 63 6c 5f 52 65 6c 65 61 73 65 28 69 6e 74 65 72 cl_Release(inter
9600: 70 29 3b 29 0a 0a 09 09 72 65 74 75 72 6e 28 2d p);)....return(-
9610: 45 49 4f 29 3b 0a 09 7d 0a 0a 09 61 70 70 66 73 EIO);..}...appfs
9620: 5f 63 61 6c 6c 5f 6c 69 62 74 63 6c 28 54 63 6c _call_libtcl(Tcl
9630: 5f 52 65 6c 65 61 73 65 28 69 6e 74 65 72 70 29 _Release(interp)
9640: 3b 29 0a 0a 09 72 65 74 75 72 6e 28 30 29 3b 0a ;)...return(0);.
9650: 7d 0a 0a 73 74 61 74 69 63 20 69 6e 74 20 61 70 }..static int ap
9660: 70 66 73 5f 66 75 73 65 5f 6d 6b 64 69 72 28 63 pfs_fuse_mkdir(c
9670: 6f 6e 73 74 20 63 68 61 72 20 2a 70 61 74 68 2c onst char *path,
9680: 20 6d 6f 64 65 5f 74 20 6d 6f 64 65 29 20 7b 0a mode_t mode) {.
9690: 09 63 68 61 72 20 2a 72 65 61 6c 5f 70 61 74 68 .char *real_path
96a0: 3b 0a 09 69 6e 74 20 6d 6b 64 69 72 5f 72 65 74 ;..int mkdir_ret
96b0: 3b 0a 0a 09 41 50 50 46 53 5f 44 45 42 55 47 28 ;...APPFS_DEBUG(
96c0: 22 45 6e 74 65 72 20 28 70 61 74 68 20 3d 20 25 "Enter (path = %
96d0: 73 2c 20 2e 2e 2e 29 22 2c 20 70 61 74 68 29 3b s, ...)", path);
96e0: 0a 0a 09 72 65 61 6c 5f 70 61 74 68 20 3d 20 61 ...real_path = a
96f0: 70 70 66 73 5f 70 72 65 70 61 72 65 5f 74 6f 5f ppfs_prepare_to_
9700: 63 72 65 61 74 65 28 70 61 74 68 29 3b 0a 09 69 create(path);..i
9710: 66 20 28 72 65 61 6c 5f 70 61 74 68 20 3d 3d 20 f (real_path ==
9720: 4e 55 4c 4c 29 20 7b 0a 09 09 72 65 74 75 72 6e NULL) {...return
9730: 28 2d 45 49 4f 29 3b 0a 09 7d 0a 0a 09 61 70 70 (-EIO);..}...app
9740: 66 73 5f 73 69 6d 75 6c 61 74 65 5f 75 73 65 72 fs_simulate_user
9750: 5f 66 73 5f 65 6e 74 65 72 28 29 3b 0a 0a 09 6d _fs_enter();...m
9760: 6b 64 69 72 5f 72 65 74 20 3d 20 6d 6b 64 69 72 kdir_ret = mkdir
9770: 28 72 65 61 6c 5f 70 61 74 68 2c 20 6d 6f 64 65 (real_path, mode
9780: 29 3b 0a 0a 09 61 70 70 66 73 5f 73 69 6d 75 6c );...appfs_simul
9790: 61 74 65 5f 75 73 65 72 5f 66 73 5f 6c 65 61 76 ate_user_fs_leav
97a0: 65 28 29 3b 0a 0a 09 66 72 65 65 28 72 65 61 6c e();...free(real
97b0: 5f 70 61 74 68 29 3b 0a 0a 09 69 66 20 28 6d 6b _path);...if (mk
97c0: 64 69 72 5f 72 65 74 20 21 3d 20 30 29 20 7b 0a dir_ret != 0) {.
97d0: 09 09 69 66 20 28 65 72 72 6e 6f 20 21 3d 20 45 ..if (errno != E
97e0: 45 58 49 53 54 29 20 7b 0a 09 09 09 72 65 74 75 EXIST) {....retu
97f0: 72 6e 28 65 72 72 6e 6f 20 2a 20 2d 31 29 3b 0a rn(errno * -1);.
9800: 09 09 7d 0a 09 7d 0a 0a 09 72 65 74 75 72 6e 28 ..}..}...return(
9810: 30 29 3b 0a 7d 0a 0a 73 74 61 74 69 63 20 69 6e 0);.}..static in
9820: 74 20 61 70 70 66 73 5f 66 75 73 65 5f 63 68 6d t appfs_fuse_chm
9830: 6f 64 28 63 6f 6e 73 74 20 63 68 61 72 20 2a 70 od(const char *p
9840: 61 74 68 2c 20 6d 6f 64 65 5f 74 20 6d 6f 64 65 ath, mode_t mode
9850: 29 20 7b 0a 09 54 63 6c 5f 49 6e 74 65 72 70 20 ) {..Tcl_Interp
9860: 2a 69 6e 74 65 72 70 3b 0a 09 63 6f 6e 73 74 20 *interp;..const
9870: 63 68 61 72 20 2a 72 65 61 6c 5f 70 61 74 68 3b char *real_path;
9880: 0a 09 69 6e 74 20 74 63 6c 5f 72 65 74 2c 20 63 ..int tcl_ret, c
9890: 68 6d 6f 64 5f 72 65 74 3b 0a 0a 09 41 50 50 46 hmod_ret;...APPF
98a0: 53 5f 44 45 42 55 47 28 22 45 6e 74 65 72 20 28 S_DEBUG("Enter (
98b0: 70 61 74 68 20 3d 20 25 73 2c 20 2e 2e 2e 29 22 path = %s, ...)"
98c0: 2c 20 70 61 74 68 29 3b 0a 0a 09 61 70 70 66 73 , path);...appfs
98d0: 5f 67 65 74 5f 70 61 74 68 5f 69 6e 66 6f 5f 63 _get_path_info_c
98e0: 61 63 68 65 5f 72 6d 28 70 61 74 68 2c 20 61 70 ache_rm(path, ap
98f0: 70 66 73 5f 67 65 74 5f 66 73 75 69 64 28 29 29 pfs_get_fsuid())
9900: 3b 0a 0a 09 69 6e 74 65 72 70 20 3d 20 61 70 70 ;...interp = app
9910: 66 73 5f 54 63 6c 49 6e 74 65 72 70 28 29 3b 0a fs_TclInterp();.
9920: 09 69 66 20 28 69 6e 74 65 72 70 20 3d 3d 20 4e .if (interp == N
9930: 55 4c 4c 29 20 7b 0a 09 09 72 65 74 75 72 6e 28 ULL) {...return(
9940: 2d 45 49 4f 29 3b 0a 09 7d 0a 0a 09 61 70 70 66 -EIO);..}...appf
9950: 73 5f 63 61 6c 6c 5f 6c 69 62 74 63 6c 28 54 63 s_call_libtcl(Tc
9960: 6c 5f 50 72 65 73 65 72 76 65 28 69 6e 74 65 72 l_Preserve(inter
9970: 70 29 3b 29 0a 0a 09 74 63 6c 5f 72 65 74 20 3d p);)...tcl_ret =
9980: 20 61 70 70 66 73 5f 54 63 6c 5f 45 76 61 6c 28 appfs_Tcl_Eval(
9990: 69 6e 74 65 72 70 2c 20 33 2c 20 22 3a 3a 61 70 interp, 3, "::ap
99a0: 70 66 73 3a 3a 6f 70 65 6e 70 61 74 68 22 2c 20 pfs::openpath",
99b0: 70 61 74 68 2c 20 22 77 72 69 74 65 22 29 3b 0a path, "write");.
99c0: 09 69 66 20 28 74 63 6c 5f 72 65 74 20 21 3d 20 .if (tcl_ret !=
99d0: 54 43 4c 5f 4f 4b 29 20 7b 0a 09 09 41 50 50 46 TCL_OK) {...APPF
99e0: 53 5f 44 45 42 55 47 28 22 3a 3a 61 70 70 66 73 S_DEBUG("::appfs
99f0: 3a 3a 6f 70 65 6e 70 61 74 68 28 25 73 2c 20 25 ::openpath(%s, %
9a00: 73 29 20 66 61 69 6c 65 64 2e 22 2c 20 70 61 74 s) failed.", pat
9a10: 68 2c 20 22 77 72 69 74 65 22 29 3b 0a 09 09 61 h, "write");...a
9a20: 70 70 66 73 5f 63 61 6c 6c 5f 6c 69 62 74 63 6c ppfs_call_libtcl
9a30: 28 0a 09 09 09 41 50 50 46 53 5f 44 45 42 55 47 (....APPFS_DEBUG
9a40: 28 22 54 63 6c 20 45 72 72 6f 72 20 69 73 3a 20 ("Tcl Error is:
9a50: 25 73 22 2c 20 54 63 6c 5f 47 65 74 53 74 72 69 %s", Tcl_GetStri
9a60: 6e 67 52 65 73 75 6c 74 28 69 6e 74 65 72 70 29 ngResult(interp)
9a70: 29 3b 0a 09 09 29 0a 0a 09 09 61 70 70 66 73 5f );...)....appfs_
9a80: 63 61 6c 6c 5f 6c 69 62 74 63 6c 28 54 63 6c 5f call_libtcl(Tcl_
9a90: 52 65 6c 65 61 73 65 28 69 6e 74 65 72 70 29 3b Release(interp);
9aa0: 29 0a 0a 09 09 72 65 74 75 72 6e 28 2d 45 49 4f )....return(-EIO
9ab0: 29 3b 0a 09 7d 0a 0a 09 61 70 70 66 73 5f 63 61 );..}...appfs_ca
9ac0: 6c 6c 5f 6c 69 62 74 63 6c 28 0a 09 09 72 65 61 ll_libtcl(...rea
9ad0: 6c 5f 70 61 74 68 20 3d 20 54 63 6c 5f 47 65 74 l_path = Tcl_Get
9ae0: 53 74 72 69 6e 67 52 65 73 75 6c 74 28 69 6e 74 StringResult(int
9af0: 65 72 70 29 3b 0a 09 29 0a 0a 09 61 70 70 66 73 erp);..)...appfs
9b00: 5f 63 61 6c 6c 5f 6c 69 62 74 63 6c 28 54 63 6c _call_libtcl(Tcl
9b10: 5f 52 65 6c 65 61 73 65 28 69 6e 74 65 72 70 29 _Release(interp)
9b20: 3b 29 0a 0a 09 69 66 20 28 72 65 61 6c 5f 70 61 ;)...if (real_pa
9b30: 74 68 20 3d 3d 20 4e 55 4c 4c 29 20 7b 0a 09 09 th == NULL) {...
9b40: 72 65 74 75 72 6e 28 2d 45 49 4f 29 3b 0a 09 7d return(-EIO);..}
9b50: 0a 0a 09 61 70 70 66 73 5f 73 69 6d 75 6c 61 74 ...appfs_simulat
9b60: 65 5f 75 73 65 72 5f 66 73 5f 65 6e 74 65 72 28 e_user_fs_enter(
9b70: 29 3b 0a 0a 09 63 68 6d 6f 64 5f 72 65 74 20 3d );...chmod_ret =
9b80: 20 63 68 6d 6f 64 28 72 65 61 6c 5f 70 61 74 68 chmod(real_path
9b90: 2c 20 6d 6f 64 65 29 3b 0a 0a 09 61 70 70 66 73 , mode);...appfs
9ba0: 5f 73 69 6d 75 6c 61 74 65 5f 75 73 65 72 5f 66 _simulate_user_f
9bb0: 73 5f 6c 65 61 76 65 28 29 3b 0a 0a 09 72 65 74 s_leave();...ret
9bc0: 75 72 6e 28 63 68 6d 6f 64 5f 72 65 74 29 3b 0a urn(chmod_ret);.
9bd0: 7d 0a 0a 73 74 61 74 69 63 20 69 6e 74 20 61 70 }..static int ap
9be0: 70 66 73 5f 66 75 73 65 5f 73 79 6d 6c 69 6e 6b pfs_fuse_symlink
9bf0: 28 63 6f 6e 73 74 20 63 68 61 72 20 2a 6f 6c 64 (const char *old
9c00: 70 61 74 68 2c 20 63 6f 6e 73 74 20 63 68 61 72 path, const char
9c10: 20 2a 6e 65 77 70 61 74 68 29 20 7b 0a 09 63 68 *newpath) {..ch
9c20: 61 72 20 2a 72 65 61 6c 5f 70 61 74 68 3b 0a 09 ar *real_path;..
9c30: 69 6e 74 20 73 79 6d 6c 69 6e 6b 5f 72 65 74 3b int symlink_ret;
9c40: 0a 0a 09 41 50 50 46 53 5f 44 45 42 55 47 28 22 ...APPFS_DEBUG("
9c50: 45 6e 74 65 72 20 28 70 61 74 68 20 3d 20 25 73 Enter (path = %s
9c60: 2c 20 25 73 29 22 2c 20 6f 6c 64 70 61 74 68 2c , %s)", oldpath,
9c70: 20 6e 65 77 70 61 74 68 29 3b 0a 0a 09 72 65 61 newpath);...rea
9c80: 6c 5f 70 61 74 68 20 3d 20 61 70 70 66 73 5f 70 l_path = appfs_p
9c90: 72 65 70 61 72 65 5f 74 6f 5f 63 72 65 61 74 65 repare_to_create
9ca0: 28 6e 65 77 70 61 74 68 29 3b 0a 09 69 66 20 28 (newpath);..if (
9cb0: 72 65 61 6c 5f 70 61 74 68 20 3d 3d 20 4e 55 4c real_path == NUL
9cc0: 4c 29 20 7b 0a 09 09 72 65 74 75 72 6e 28 2d 45 L) {...return(-E
9cd0: 49 4f 29 3b 0a 09 7d 0a 0a 09 61 70 70 66 73 5f IO);..}...appfs_
9ce0: 73 69 6d 75 6c 61 74 65 5f 75 73 65 72 5f 66 73 simulate_user_fs
9cf0: 5f 65 6e 74 65 72 28 29 3b 0a 0a 09 73 79 6d 6c _enter();...syml
9d00: 69 6e 6b 5f 72 65 74 20 3d 20 73 79 6d 6c 69 6e ink_ret = symlin
9d10: 6b 28 6f 6c 64 70 61 74 68 2c 20 72 65 61 6c 5f k(oldpath, real_
9d20: 70 61 74 68 29 3b 0a 0a 09 61 70 70 66 73 5f 73 path);...appfs_s
9d30: 69 6d 75 6c 61 74 65 5f 75 73 65 72 5f 66 73 5f imulate_user_fs_
9d40: 6c 65 61 76 65 28 29 3b 0a 0a 09 66 72 65 65 28 leave();...free(
9d50: 72 65 61 6c 5f 70 61 74 68 29 3b 0a 0a 09 69 66 real_path);...if
9d60: 20 28 73 79 6d 6c 69 6e 6b 5f 72 65 74 20 21 3d (symlink_ret !=
9d70: 20 30 29 20 7b 0a 09 09 72 65 74 75 72 6e 28 65 0) {...return(e
9d80: 72 72 6e 6f 20 2a 20 2d 31 29 3b 0a 09 7d 0a 0a rrno * -1);..}..
9d90: 09 72 65 74 75 72 6e 28 30 29 3b 0a 7d 0a 0a 2f .return(0);.}../
9da0: 2a 0a 20 2a 20 53 51 4c 69 74 65 33 20 6d 6f 64 *. * SQLite3 mod
9db0: 65 3a 20 45 78 65 63 75 74 65 20 72 61 77 20 53 e: Execute raw S
9dc0: 51 4c 20 61 6e 64 20 72 65 74 75 72 6e 20 73 75 QL and return su
9dd0: 63 63 65 73 73 20 6f 72 20 66 61 69 6c 75 72 65 ccess or failure
9de0: 0a 20 2a 2f 0a 73 74 61 74 69 63 20 69 6e 74 20 . */.static int
9df0: 61 70 70 66 73 5f 73 71 6c 69 74 65 33 28 63 6f appfs_sqlite3(co
9e00: 6e 73 74 20 63 68 61 72 20 2a 73 71 6c 29 20 7b nst char *sql) {
9e10: 0a 09 54 63 6c 5f 49 6e 74 65 72 70 20 2a 69 6e ..Tcl_Interp *in
9e20: 74 65 72 70 3b 0a 09 63 6f 6e 73 74 20 63 68 61 terp;..const cha
9e30: 72 20 2a 73 71 6c 5f 72 65 74 3b 0a 09 69 6e 74 r *sql_ret;..int
9e40: 20 74 63 6c 5f 72 65 74 3b 0a 0a 09 69 6e 74 65 tcl_ret;...inte
9e50: 72 70 20 3d 20 61 70 70 66 73 5f 63 72 65 61 74 rp = appfs_creat
9e60: 65 5f 54 63 6c 49 6e 74 65 72 70 28 4e 55 4c 4c e_TclInterp(NULL
9e70: 29 3b 0a 09 69 66 20 28 69 6e 74 65 72 70 20 3d );..if (interp =
9e80: 3d 20 4e 55 4c 4c 29 20 7b 0a 09 09 66 70 72 69 = NULL) {...fpri
9e90: 6e 74 66 28 73 74 64 65 72 72 2c 20 22 55 6e 61 ntf(stderr, "Una
9ea0: 62 6c 65 20 74 6f 20 63 72 65 61 74 65 20 61 20 ble to create a
9eb0: 54 63 6c 20 69 6e 74 65 72 70 72 65 74 65 72 2e Tcl interpreter.
9ec0: 20 20 41 62 6f 72 74 69 6e 67 2e 5c 6e 22 29 3b Aborting.\n");
9ed0: 0a 0a 09 09 72 65 74 75 72 6e 28 31 29 3b 0a 09 ....return(1);..
9ee0: 7d 0a 0a 09 74 63 6c 5f 72 65 74 20 3d 20 61 70 }...tcl_ret = ap
9ef0: 70 66 73 5f 54 63 6c 5f 45 76 61 6c 28 69 6e 74 pfs_Tcl_Eval(int
9f00: 65 72 70 2c 20 35 2c 20 22 3a 3a 61 70 70 66 73 erp, 5, "::appfs
9f10: 3a 3a 64 62 22 2c 20 22 65 76 61 6c 22 2c 20 73 ::db", "eval", s
9f20: 71 6c 2c 20 22 72 6f 77 22 2c 20 22 75 6e 73 65 ql, "row", "unse
9f30: 74 20 2d 6e 6f 63 6f 6d 70 6c 61 69 6e 20 72 6f t -nocomplain ro
9f40: 77 28 2a 29 3b 20 70 61 72 72 61 79 20 72 6f 77 w(*); parray row
9f50: 3b 20 70 75 74 73 20 5c 22 2d 2d 2d 2d 5c 22 22 ; puts \"----\""
9f60: 29 3b 0a 09 73 71 6c 5f 72 65 74 20 3d 20 54 63 );..sql_ret = Tc
9f70: 6c 5f 47 65 74 53 74 72 69 6e 67 52 65 73 75 6c l_GetStringResul
9f80: 74 28 69 6e 74 65 72 70 29 3b 0a 0a 09 69 66 20 t(interp);...if
9f90: 28 74 63 6c 5f 72 65 74 20 21 3d 20 54 43 4c 5f (tcl_ret != TCL_
9fa0: 4f 4b 29 20 7b 0a 09 09 66 70 72 69 6e 74 66 28 OK) {...fprintf(
9fb0: 73 74 64 65 72 72 2c 20 22 5b 65 72 72 6f 72 5d stderr, "[error]
9fc0: 20 25 73 5c 6e 22 2c 20 73 71 6c 5f 72 65 74 29 %s\n", sql_ret)
9fd0: 3b 0a 0a 09 09 72 65 74 75 72 6e 28 31 29 3b 0a ;....return(1);.
9fe0: 09 7d 0a 0a 09 69 66 20 28 73 71 6c 5f 72 65 74 .}...if (sql_ret
9ff0: 20 26 26 20 73 71 6c 5f 72 65 74 5b 30 5d 20 21 && sql_ret[0] !
a000: 3d 20 27 5c 30 27 29 20 7b 0a 09 09 70 72 69 6e = '\0') {...prin
a010: 74 66 28 22 25 73 5c 6e 22 2c 20 73 71 6c 5f 72 tf("%s\n", sql_r
a020: 65 74 29 3b 0a 09 7d 0a 0a 09 72 65 74 75 72 6e et);..}...return
a030: 28 30 29 3b 0a 7d 0a 0a 2f 2a 0a 20 2a 20 54 63 (0);.}../*. * Tc
a040: 6c 20 6d 6f 64 65 3a 20 45 78 65 63 75 74 65 20 l mode: Execute
a050: 72 61 77 20 54 63 6c 20 61 6e 64 20 72 65 74 75 raw Tcl and retu
a060: 72 6e 20 73 75 63 63 65 73 73 20 6f 72 20 66 61 rn success or fa
a070: 69 6c 75 72 65 0a 20 2a 2f 0a 73 74 61 74 69 63 ilure. */.static
a080: 20 69 6e 74 20 61 70 70 66 73 5f 74 63 6c 28 63 int appfs_tcl(c
a090: 6f 6e 73 74 20 63 68 61 72 20 2a 74 63 6c 29 20 onst char *tcl)
a0a0: 7b 0a 09 54 63 6c 5f 49 6e 74 65 72 70 20 2a 69 {..Tcl_Interp *i
a0b0: 6e 74 65 72 70 3b 0a 09 63 6f 6e 73 74 20 63 68 nterp;..const ch
a0c0: 61 72 20 2a 74 63 6c 5f 72 65 73 75 6c 74 3b 0a ar *tcl_result;.
a0d0: 09 69 6e 74 20 74 63 6c 5f 72 65 74 3b 0a 0a 09 .int tcl_ret;...
a0e0: 69 6e 74 65 72 70 20 3d 20 61 70 70 66 73 5f 63 interp = appfs_c
a0f0: 72 65 61 74 65 5f 54 63 6c 49 6e 74 65 72 70 28 reate_TclInterp(
a100: 4e 55 4c 4c 29 3b 0a 09 69 66 20 28 69 6e 74 65 NULL);..if (inte
a110: 72 70 20 3d 3d 20 4e 55 4c 4c 29 20 7b 0a 09 09 rp == NULL) {...
a120: 66 70 72 69 6e 74 66 28 73 74 64 65 72 72 2c 20 fprintf(stderr,
a130: 22 55 6e 61 62 6c 65 20 74 6f 20 63 72 65 61 74 "Unable to creat
a140: 65 20 61 20 54 63 6c 20 69 6e 74 65 72 70 72 65 e a Tcl interpre
a150: 74 65 72 2e 20 20 41 62 6f 72 74 69 6e 67 2e 5c ter. Aborting.\
a160: 6e 22 29 3b 0a 0a 09 09 72 65 74 75 72 6e 28 31 n");....return(1
a170: 29 3b 0a 09 7d 0a 0a 09 74 63 6c 5f 72 65 74 20 );..}...tcl_ret
a180: 3d 20 54 63 6c 5f 45 76 61 6c 28 69 6e 74 65 72 = Tcl_Eval(inter
a190: 70 2c 20 74 63 6c 29 3b 0a 09 74 63 6c 5f 72 65 p, tcl);..tcl_re
a1a0: 73 75 6c 74 20 3d 20 54 63 6c 5f 47 65 74 53 74 sult = Tcl_GetSt
a1b0: 72 69 6e 67 52 65 73 75 6c 74 28 69 6e 74 65 72 ringResult(inter
a1c0: 70 29 3b 0a 0a 09 69 66 20 28 74 63 6c 5f 72 65 p);...if (tcl_re
a1d0: 74 20 21 3d 20 54 43 4c 5f 4f 4b 29 20 7b 0a 09 t != TCL_OK) {..
a1e0: 09 66 70 72 69 6e 74 66 28 73 74 64 65 72 72 2c .fprintf(stderr,
a1f0: 20 22 5b 65 72 72 6f 72 5d 20 25 73 5c 6e 22 2c "[error] %s\n",
a200: 20 54 63 6c 5f 47 65 74 56 61 72 28 69 6e 74 65 Tcl_GetVar(inte
a210: 72 70 2c 20 22 65 72 72 6f 72 49 6e 66 6f 22 2c rp, "errorInfo",
a220: 20 54 43 4c 5f 47 4c 4f 42 41 4c 5f 4f 4e 4c 59 TCL_GLOBAL_ONLY
a230: 29 29 3b 0a 0a 09 09 72 65 74 75 72 6e 28 31 29 ));....return(1)
a240: 3b 0a 09 7d 0a 0a 09 69 66 20 28 74 63 6c 5f 72 ;..}...if (tcl_r
a250: 65 73 75 6c 74 20 26 26 20 74 63 6c 5f 72 65 73 esult && tcl_res
a260: 75 6c 74 5b 30 5d 20 21 3d 20 27 5c 30 27 29 20 ult[0] != '\0')
a270: 7b 0a 09 09 70 72 69 6e 74 66 28 22 25 73 5c 6e {...printf("%s\n
a280: 22 2c 20 74 63 6c 5f 72 65 73 75 6c 74 29 3b 0a ", tcl_result);.
a290: 09 7d 0a 0a 09 72 65 74 75 72 6e 28 30 29 3b 0a .}...return(0);.
a2a0: 7d 0a 0a 2f 2a 0a 20 2a 20 41 70 70 46 53 64 20 }../*. * AppFSd
a2b0: 50 61 63 6b 61 67 65 20 66 6f 72 20 54 63 6c 3a Package for Tcl:
a2c0: 0a 20 2a 20 20 20 20 20 20 20 20 20 42 72 69 64 . * Brid
a2d0: 67 65 20 66 6f 72 20 49 2f 4f 20 6f 70 65 72 61 ge for I/O opera
a2e0: 74 69 6f 6e 73 20 74 6f 20 72 65 71 75 65 73 74 tions to request
a2f0: 20 69 6e 66 6f 72 6d 61 74 69 6f 6e 20 61 62 6f information abo
a300: 75 74 20 74 68 65 20 63 75 72 72 65 6e 74 0a 20 ut the current.
a310: 2a 20 20 20 20 20 20 20 20 20 74 72 61 6e 73 61 * transa
a320: 63 74 69 6f 6e 0a 20 2a 2f 0a 2f 2a 0a 20 2a 20 ction. */./*. *
a330: 54 63 6c 20 69 6e 74 65 72 66 61 63 65 20 74 6f Tcl interface to
a340: 20 67 65 74 20 74 68 65 20 68 6f 6d 65 20 64 69 get the home di
a350: 72 65 63 74 6f 72 79 20 66 6f 72 20 74 68 65 20 rectory for the
a360: 75 73 65 72 20 6d 61 6b 69 6e 67 20 74 68 65 20 user making the
a370: 22 63 75 72 72 65 6e 74 22 0a 20 2a 20 46 55 53 "current". * FUS
a380: 45 20 49 2f 4f 20 72 65 71 75 65 73 74 0a 20 2a E I/O request. *
a390: 2f 0a 73 74 61 74 69 63 20 69 6e 74 20 74 63 6c /.static int tcl
a3a0: 5f 61 70 70 66 73 5f 67 65 74 5f 68 6f 6d 65 64 _appfs_get_homed
a3b0: 69 72 28 43 6c 69 65 6e 74 44 61 74 61 20 63 64 ir(ClientData cd
a3c0: 2c 20 54 63 6c 5f 49 6e 74 65 72 70 20 2a 69 6e , Tcl_Interp *in
a3d0: 74 65 72 70 2c 20 69 6e 74 20 6f 62 6a 63 2c 20 terp, int objc,
a3e0: 54 63 6c 5f 4f 62 6a 20 2a 43 4f 4e 53 54 20 6f Tcl_Obj *CONST o
a3f0: 62 6a 76 5b 5d 29 20 7b 0a 09 63 68 61 72 20 2a bjv[]) {..char *
a400: 68 6f 6d 65 64 69 72 3b 0a 09 54 63 6c 5f 4f 62 homedir;..Tcl_Ob
a410: 6a 20 2a 68 6f 6d 65 64 69 72 5f 6f 62 6a 3b 0a j *homedir_obj;.
a420: 09 75 69 64 5f 74 20 66 73 75 69 64 3b 0a 09 73 .uid_t fsuid;..s
a430: 74 61 74 69 63 20 5f 5f 74 68 72 65 61 64 20 54 tatic __thread T
a440: 63 6c 5f 4f 62 6a 20 2a 6c 61 73 74 5f 68 6f 6d cl_Obj *last_hom
a450: 65 64 69 72 5f 6f 62 6a 20 3d 20 4e 55 4c 4c 3b edir_obj = NULL;
a460: 0a 09 73 74 61 74 69 63 20 5f 5f 74 68 72 65 61 ..static __threa
a470: 64 20 75 69 64 5f 74 20 6c 61 73 74 5f 66 73 75 d uid_t last_fsu
a480: 69 64 20 3d 20 2d 31 3b 0a 0a 20 20 20 20 20 20 id = -1;..
a490: 20 20 69 66 20 28 6f 62 6a 63 20 21 3d 20 31 29 if (objc != 1)
a4a0: 20 7b 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 {.
a4b0: 20 20 20 54 63 6c 5f 57 72 6f 6e 67 4e 75 6d 41 Tcl_WrongNumA
a4c0: 72 67 73 28 69 6e 74 65 72 70 2c 20 31 2c 20 6f rgs(interp, 1, o
a4d0: 62 6a 76 2c 20 4e 55 4c 4c 29 3b 0a 20 20 20 20 bjv, NULL);.
a4e0: 20 20 20 20 20 20 20 20 20 20 20 20 72 65 74 75 retu
a4f0: 72 6e 28 54 43 4c 5f 45 52 52 4f 52 29 3b 0a 20 rn(TCL_ERROR);.
a500: 20 20 20 20 20 20 20 7d 0a 0a 09 66 73 75 69 64 }...fsuid
a510: 20 3d 20 61 70 70 66 73 5f 67 65 74 5f 66 73 75 = appfs_get_fsu
a520: 69 64 28 29 3b 0a 0a 09 69 66 20 28 66 73 75 69 id();...if (fsui
a530: 64 20 3d 3d 20 6c 61 73 74 5f 66 73 75 69 64 20 d == last_fsuid
a540: 26 26 20 6c 61 73 74 5f 68 6f 6d 65 64 69 72 5f && last_homedir_
a550: 6f 62 6a 20 21 3d 20 4e 55 4c 4c 29 20 7b 0a 09 obj != NULL) {..
a560: 09 68 6f 6d 65 64 69 72 5f 6f 62 6a 20 3d 20 6c .homedir_obj = l
a570: 61 73 74 5f 68 6f 6d 65 64 69 72 5f 6f 62 6a 3b ast_homedir_obj;
a580: 0a 0a 09 09 54 63 6c 5f 49 6e 63 72 52 65 66 43 ....Tcl_IncrRefC
a590: 6f 75 6e 74 28 68 6f 6d 65 64 69 72 5f 6f 62 6a ount(homedir_obj
a5a0: 29 3b 0a 09 7d 20 65 6c 73 65 20 7b 0a 09 09 68 );..} else {...h
a5b0: 6f 6d 65 64 69 72 20 3d 20 61 70 70 66 73 5f 67 omedir = appfs_g
a5c0: 65 74 5f 68 6f 6d 65 64 69 72 28 61 70 70 66 73 et_homedir(appfs
a5d0: 5f 67 65 74 5f 66 73 75 69 64 28 29 29 3b 0a 0a _get_fsuid());..
a5e0: 09 09 69 66 20 28 68 6f 6d 65 64 69 72 20 3d 3d ..if (homedir ==
a5f0: 20 4e 55 4c 4c 29 20 7b 0a 09 09 09 72 65 74 75 NULL) {....retu
a600: 72 6e 28 54 43 4c 5f 45 52 52 4f 52 29 3b 0a 09 rn(TCL_ERROR);..
a610: 09 7d 0a 0a 09 09 68 6f 6d 65 64 69 72 5f 6f 62 .}....homedir_ob
a620: 6a 20 3d 20 54 63 6c 5f 4e 65 77 53 74 72 69 6e j = Tcl_NewStrin
a630: 67 4f 62 6a 28 68 6f 6d 65 64 69 72 2c 20 2d 31 gObj(homedir, -1
a640: 29 3b 0a 0a 09 09 66 72 65 65 28 68 6f 6d 65 64 );....free(homed
a650: 69 72 29 3b 0a 0a 09 09 54 63 6c 5f 49 6e 63 72 ir);....Tcl_Incr
a660: 52 65 66 43 6f 75 6e 74 28 68 6f 6d 65 64 69 72 RefCount(homedir
a670: 5f 6f 62 6a 29 3b 0a 0a 09 09 69 66 20 28 6c 61 _obj);....if (la
a680: 73 74 5f 68 6f 6d 65 64 69 72 5f 6f 62 6a 20 21 st_homedir_obj !
a690: 3d 20 4e 55 4c 4c 29 20 7b 0a 09 09 09 54 63 6c = NULL) {....Tcl
a6a0: 5f 44 65 63 72 52 65 66 43 6f 75 6e 74 28 6c 61 _DecrRefCount(la
a6b0: 73 74 5f 68 6f 6d 65 64 69 72 5f 6f 62 6a 29 3b st_homedir_obj);
a6c0: 0a 09 09 7d 0a 0a 09 09 6c 61 73 74 5f 68 6f 6d ...}....last_hom
a6d0: 65 64 69 72 5f 6f 62 6a 20 3d 20 68 6f 6d 65 64 edir_obj = homed
a6e0: 69 72 5f 6f 62 6a 3b 0a 09 09 6c 61 73 74 5f 66 ir_obj;...last_f
a6f0: 73 75 69 64 20 3d 20 66 73 75 69 64 3b 0a 0a 09 suid = fsuid;...
a700: 09 54 63 6c 5f 49 6e 63 72 52 65 66 43 6f 75 6e .Tcl_IncrRefCoun
a710: 74 28 68 6f 6d 65 64 69 72 5f 6f 62 6a 29 3b 0a t(homedir_obj);.
a720: 09 7d 0a 0a 20 20 20 20 20 20 20 09 54 63 6c 5f .}.. .Tcl_
a730: 53 65 74 4f 62 6a 52 65 73 75 6c 74 28 69 6e 74 SetObjResult(int
a740: 65 72 70 2c 20 68 6f 6d 65 64 69 72 5f 6f 62 6a erp, homedir_obj
a750: 29 3b 0a 0a 09 54 63 6c 5f 44 65 63 72 52 65 66 );...Tcl_DecrRef
a760: 43 6f 75 6e 74 28 68 6f 6d 65 64 69 72 5f 6f 62 Count(homedir_ob
a770: 6a 29 3b 0a 0a 20 20 20 20 20 20 20 20 72 65 74 j);.. ret
a780: 75 72 6e 28 54 43 4c 5f 4f 4b 29 3b 0a 7d 0a 0a urn(TCL_OK);.}..
a790: 73 74 61 74 69 63 20 69 6e 74 20 74 63 6c 5f 61 static int tcl_a
a7a0: 70 70 66 73 5f 73 69 6d 75 6c 61 74 65 5f 75 73 ppfs_simulate_us
a7b0: 65 72 5f 66 73 5f 65 6e 74 65 72 28 43 6c 69 65 er_fs_enter(Clie
a7c0: 6e 74 44 61 74 61 20 63 64 2c 20 54 63 6c 5f 49 ntData cd, Tcl_I
a7d0: 6e 74 65 72 70 20 2a 69 6e 74 65 72 70 2c 20 69 nterp *interp, i
a7e0: 6e 74 20 6f 62 6a 63 2c 20 54 63 6c 5f 4f 62 6a nt objc, Tcl_Obj
a7f0: 20 2a 43 4f 4e 53 54 20 6f 62 6a 76 5b 5d 29 20 *CONST objv[])
a800: 7b 0a 09 61 70 70 66 73 5f 73 69 6d 75 6c 61 74 {..appfs_simulat
a810: 65 5f 75 73 65 72 5f 66 73 5f 65 6e 74 65 72 28 e_user_fs_enter(
a820: 29 3b 0a 0a 09 72 65 74 75 72 6e 28 54 43 4c 5f );...return(TCL_
a830: 4f 4b 29 3b 0a 7d 0a 0a 73 74 61 74 69 63 20 69 OK);.}..static i
a840: 6e 74 20 74 63 6c 5f 61 70 70 66 73 5f 73 69 6d nt tcl_appfs_sim
a850: 75 6c 61 74 65 5f 75 73 65 72 5f 66 73 5f 6c 65 ulate_user_fs_le
a860: 61 76 65 28 43 6c 69 65 6e 74 44 61 74 61 20 63 ave(ClientData c
a870: 64 2c 20 54 63 6c 5f 49 6e 74 65 72 70 20 2a 69 d, Tcl_Interp *i
a880: 6e 74 65 72 70 2c 20 69 6e 74 20 6f 62 6a 63 2c nterp, int objc,
a890: 20 54 63 6c 5f 4f 62 6a 20 2a 43 4f 4e 53 54 20 Tcl_Obj *CONST
a8a0: 6f 62 6a 76 5b 5d 29 20 7b 0a 09 61 70 70 66 73 objv[]) {..appfs
a8b0: 5f 73 69 6d 75 6c 61 74 65 5f 75 73 65 72 5f 66 _simulate_user_f
a8c0: 73 5f 6c 65 61 76 65 28 29 3b 0a 0a 09 72 65 74 s_leave();...ret
a8d0: 75 72 6e 28 54 43 4c 5f 4f 4b 29 3b 0a 7d 0a 0a urn(TCL_OK);.}..
a8e0: 73 74 61 74 69 63 20 69 6e 74 20 74 63 6c 5f 61 static int tcl_a
a8f0: 70 70 66 73 5f 67 65 74 5f 66 73 75 69 64 28 43 ppfs_get_fsuid(C
a900: 6c 69 65 6e 74 44 61 74 61 20 63 64 2c 20 54 63 lientData cd, Tc
a910: 6c 5f 49 6e 74 65 72 70 20 2a 69 6e 74 65 72 70 l_Interp *interp
a920: 2c 20 69 6e 74 20 6f 62 6a 63 2c 20 54 63 6c 5f , int objc, Tcl_
a930: 4f 62 6a 20 2a 43 4f 4e 53 54 20 6f 62 6a 76 5b Obj *CONST objv[
a940: 5d 29 20 7b 0a 09 75 69 64 5f 74 20 66 73 75 69 ]) {..uid_t fsui
a950: 64 3b 0a 0a 09 66 73 75 69 64 20 3d 20 61 70 70 d;...fsuid = app
a960: 66 73 5f 67 65 74 5f 66 73 75 69 64 28 29 3b 0a fs_get_fsuid();.
a970: 0a 20 20 20 20 20 20 20 09 54 63 6c 5f 53 65 74 . .Tcl_Set
a980: 4f 62 6a 52 65 73 75 6c 74 28 69 6e 74 65 72 70 ObjResult(interp
a990: 2c 20 54 63 6c 5f 4e 65 77 57 69 64 65 49 6e 74 , Tcl_NewWideInt
a9a0: 4f 62 6a 28 66 73 75 69 64 29 29 3b 0a 0a 09 72 Obj(fsuid));...r
a9b0: 65 74 75 72 6e 28 54 43 4c 5f 4f 4b 29 3b 0a 7d eturn(TCL_OK);.}
a9c0: 0a 0a 73 74 61 74 69 63 20 69 6e 74 20 74 63 6c ..static int tcl
a9d0: 5f 61 70 70 66 73 5f 67 65 74 5f 66 73 67 69 64 _appfs_get_fsgid
a9e0: 28 43 6c 69 65 6e 74 44 61 74 61 20 63 64 2c 20 (ClientData cd,
a9f0: 54 63 6c 5f 49 6e 74 65 72 70 20 2a 69 6e 74 65 Tcl_Interp *inte
aa00: 72 70 2c 20 69 6e 74 20 6f 62 6a 63 2c 20 54 63 rp, int objc, Tc
aa10: 6c 5f 4f 62 6a 20 2a 43 4f 4e 53 54 20 6f 62 6a l_Obj *CONST obj
aa20: 76 5b 5d 29 20 7b 0a 09 67 69 64 5f 74 20 66 73 v[]) {..gid_t fs
aa30: 67 69 64 3b 0a 0a 09 66 73 67 69 64 20 3d 20 61 gid;...fsgid = a
aa40: 70 70 66 73 5f 67 65 74 5f 66 73 67 69 64 28 29 ppfs_get_fsgid()
aa50: 3b 0a 0a 20 20 20 20 20 20 20 09 54 63 6c 5f 53 ;.. .Tcl_S
aa60: 65 74 4f 62 6a 52 65 73 75 6c 74 28 69 6e 74 65 etObjResult(inte
aa70: 72 70 2c 20 54 63 6c 5f 4e 65 77 57 69 64 65 49 rp, Tcl_NewWideI
aa80: 6e 74 4f 62 6a 28 66 73 67 69 64 29 29 3b 0a 0a ntObj(fsgid));..
aa90: 09 72 65 74 75 72 6e 28 54 43 4c 5f 4f 4b 29 3b .return(TCL_OK);
aaa0: 0a 7d 0a 0a 73 74 61 74 69 63 20 69 6e 74 20 74 .}..static int t
aab0: 63 6c 5f 61 70 70 66 73 5f 67 65 74 5f 70 61 74 cl_appfs_get_pat
aac0: 68 5f 69 6e 66 6f 5f 63 61 63 68 65 5f 66 6c 75 h_info_cache_flu
aad0: 73 68 28 43 6c 69 65 6e 74 44 61 74 61 20 63 64 sh(ClientData cd
aae0: 2c 20 54 63 6c 5f 49 6e 74 65 72 70 20 2a 69 6e , Tcl_Interp *in
aaf0: 74 65 72 70 2c 20 69 6e 74 20 6f 62 6a 63 2c 20 terp, int objc,
ab00: 54 63 6c 5f 4f 62 6a 20 2a 43 4f 4e 53 54 20 6f Tcl_Obj *CONST o
ab10: 62 6a 76 5b 5d 29 20 7b 0a 09 69 6e 74 20 74 63 bjv[]) {..int tc
ab20: 6c 5f 72 65 74 3b 0a 09 69 6e 74 20 6e 65 77 5f l_ret;..int new_
ab30: 73 69 7a 65 3b 0a 0a 09 6e 65 77 5f 73 69 7a 65 size;...new_size
ab40: 20 3d 20 2d 31 3b 0a 0a 09 69 66 20 28 6f 62 6a = -1;...if (obj
ab50: 63 20 3d 3d 20 32 29 20 7b 0a 09 09 74 63 6c 5f c == 2) {...tcl_
ab60: 72 65 74 20 3d 20 54 63 6c 5f 47 65 74 49 6e 74 ret = Tcl_GetInt
ab70: 46 72 6f 6d 4f 62 6a 28 69 6e 74 65 72 70 2c 20 FromObj(interp,
ab80: 6f 62 6a 76 5b 31 5d 2c 20 26 6e 65 77 5f 73 69 objv[1], &new_si
ab90: 7a 65 29 3b 0a 09 09 69 66 20 28 74 63 6c 5f 72 ze);...if (tcl_r
aba0: 65 74 20 21 3d 20 54 43 4c 5f 4f 4b 29 20 7b 0a et != TCL_OK) {.
abb0: 09 09 09 72 65 74 75 72 6e 28 74 63 6c 5f 72 65 ...return(tcl_re
abc0: 74 29 3b 0a 09 09 7d 0a 09 7d 20 65 6c 73 65 20 t);...}..} else
abd0: 69 66 20 28 6f 62 6a 63 20 3e 20 32 20 7c 7c 20 if (objc > 2 ||
abe0: 6f 62 6a 63 20 3c 20 31 29 20 7b 0a 20 20 20 20 objc < 1) {.
abf0: 20 20 20 20 20 20 20 20 20 20 20 20 54 63 6c 5f Tcl_
ac00: 57 72 6f 6e 67 4e 75 6d 41 72 67 73 28 69 6e 74 WrongNumArgs(int
ac10: 65 72 70 2c 20 31 2c 20 6f 62 6a 76 2c 20 22 3f erp, 1, objv, "?
ac20: 6e 65 77 5f 63 61 63 68 65 5f 73 69 7a 65 3f 22 new_cache_size?"
ac30: 29 3b 0a 09 09 72 65 74 75 72 6e 28 54 43 4c 5f );...return(TCL_
ac40: 45 52 52 4f 52 29 3b 0a 09 7d 0a 0a 09 61 70 70 ERROR);..}...app
ac50: 66 73 5f 67 65 74 5f 70 61 74 68 5f 69 6e 66 6f fs_get_path_info
ac60: 5f 63 61 63 68 65 5f 66 6c 75 73 68 28 2d 31 2c _cache_flush(-1,
ac70: 20 6e 65 77 5f 73 69 7a 65 29 3b 0a 0a 09 72 65 new_size);...re
ac80: 74 75 72 6e 28 54 43 4c 5f 4f 4b 29 3b 0a 7d 0a turn(TCL_OK);.}.
ac90: 0a 73 74 61 74 69 63 20 69 6e 74 20 41 70 70 66 .static int Appf
aca0: 73 64 5f 49 6e 69 74 28 54 63 6c 5f 49 6e 74 65 sd_Init(Tcl_Inte
acb0: 72 70 20 2a 69 6e 74 65 72 70 29 20 7b 0a 23 69 rp *interp) {.#i
acc0: 66 64 65 66 20 55 53 45 5f 54 43 4c 5f 53 54 55 fdef USE_TCL_STU
acd0: 42 53 0a 09 69 66 20 28 54 63 6c 5f 49 6e 69 74 BS..if (Tcl_Init
ace0: 53 74 75 62 73 28 69 6e 74 65 72 70 2c 20 54 43 Stubs(interp, TC
acf0: 4c 5f 56 45 52 53 49 4f 4e 2c 20 30 29 20 3d 3d L_VERSION, 0) ==
ad00: 20 30 4c 29 20 7b 0a 09 09 72 65 74 75 72 6e 28 0L) {...return(
ad10: 54 43 4c 5f 45 52 52 4f 52 29 3b 0a 09 7d 0a 23 TCL_ERROR);..}.#
ad20: 65 6e 64 69 66 0a 0a 09 54 63 6c 5f 43 72 65 61 endif...Tcl_Crea
ad30: 74 65 4f 62 6a 43 6f 6d 6d 61 6e 64 28 69 6e 74 teObjCommand(int
ad40: 65 72 70 2c 20 22 61 70 70 66 73 64 3a 3a 67 65 erp, "appfsd::ge
ad50: 74 5f 68 6f 6d 65 64 69 72 22 2c 20 74 63 6c 5f t_homedir", tcl_
ad60: 61 70 70 66 73 5f 67 65 74 5f 68 6f 6d 65 64 69 appfs_get_homedi
ad70: 72 2c 20 4e 55 4c 4c 2c 20 4e 55 4c 4c 29 3b 0a r, NULL, NULL);.
ad80: 09 54 63 6c 5f 43 72 65 61 74 65 4f 62 6a 43 6f .Tcl_CreateObjCo
ad90: 6d 6d 61 6e 64 28 69 6e 74 65 72 70 2c 20 22 61 mmand(interp, "a
ada0: 70 70 66 73 64 3a 3a 67 65 74 5f 66 73 75 69 64 ppfsd::get_fsuid
adb0: 22 2c 20 74 63 6c 5f 61 70 70 66 73 5f 67 65 74 ", tcl_appfs_get
adc0: 5f 66 73 75 69 64 2c 20 4e 55 4c 4c 2c 20 4e 55 _fsuid, NULL, NU
add0: 4c 4c 29 3b 0a 09 54 63 6c 5f 43 72 65 61 74 65 LL);..Tcl_Create
ade0: 4f 62 6a 43 6f 6d 6d 61 6e 64 28 69 6e 74 65 72 ObjCommand(inter
adf0: 70 2c 20 22 61 70 70 66 73 64 3a 3a 67 65 74 5f p, "appfsd::get_
ae00: 66 73 67 69 64 22 2c 20 74 63 6c 5f 61 70 70 66 fsgid", tcl_appf
ae10: 73 5f 67 65 74 5f 66 73 67 69 64 2c 20 4e 55 4c s_get_fsgid, NUL
ae20: 4c 2c 20 4e 55 4c 4c 29 3b 0a 09 54 63 6c 5f 43 L, NULL);..Tcl_C
ae30: 72 65 61 74 65 4f 62 6a 43 6f 6d 6d 61 6e 64 28 reateObjCommand(
ae40: 69 6e 74 65 72 70 2c 20 22 61 70 70 66 73 64 3a interp, "appfsd:
ae50: 3a 73 69 6d 75 6c 61 74 65 5f 75 73 65 72 5f 66 :simulate_user_f
ae60: 73 5f 65 6e 74 65 72 22 2c 20 74 63 6c 5f 61 70 s_enter", tcl_ap
ae70: 70 66 73 5f 73 69 6d 75 6c 61 74 65 5f 75 73 65 pfs_simulate_use
ae80: 72 5f 66 73 5f 65 6e 74 65 72 2c 20 4e 55 4c 4c r_fs_enter, NULL
ae90: 2c 20 4e 55 4c 4c 29 3b 0a 09 54 63 6c 5f 43 72 , NULL);..Tcl_Cr
aea0: 65 61 74 65 4f 62 6a 43 6f 6d 6d 61 6e 64 28 69 eateObjCommand(i
aeb0: 6e 74 65 72 70 2c 20 22 61 70 70 66 73 64 3a 3a nterp, "appfsd::
aec0: 73 69 6d 75 6c 61 74 65 5f 75 73 65 72 5f 66 73 simulate_user_fs
aed0: 5f 6c 65 61 76 65 22 2c 20 74 63 6c 5f 61 70 70 _leave", tcl_app
aee0: 66 73 5f 73 69 6d 75 6c 61 74 65 5f 75 73 65 72 fs_simulate_user
aef0: 5f 66 73 5f 6c 65 61 76 65 2c 20 4e 55 4c 4c 2c _fs_leave, NULL,
af00: 20 4e 55 4c 4c 29 3b 0a 09 54 63 6c 5f 43 72 65 NULL);..Tcl_Cre
af10: 61 74 65 4f 62 6a 43 6f 6d 6d 61 6e 64 28 69 6e ateObjCommand(in
af20: 74 65 72 70 2c 20 22 61 70 70 66 73 64 3a 3a 67 terp, "appfsd::g
af30: 65 74 5f 70 61 74 68 5f 69 6e 66 6f 5f 63 61 63 et_path_info_cac
af40: 68 65 5f 66 6c 75 73 68 22 2c 20 74 63 6c 5f 61 he_flush", tcl_a
af50: 70 70 66 73 5f 67 65 74 5f 70 61 74 68 5f 69 6e ppfs_get_path_in
af60: 66 6f 5f 63 61 63 68 65 5f 66 6c 75 73 68 2c 20 fo_cache_flush,
af70: 4e 55 4c 4c 2c 20 4e 55 4c 4c 29 3b 0a 0a 09 54 NULL, NULL);...T
af80: 63 6c 5f 50 6b 67 50 72 6f 76 69 64 65 28 69 6e cl_PkgProvide(in
af90: 74 65 72 70 2c 20 22 61 70 70 66 73 64 22 2c 20 terp, "appfsd",
afa0: 22 31 2e 30 22 29 3b 0a 0a 09 72 65 74 75 72 6e "1.0");...return
afb0: 28 54 43 4c 5f 4f 4b 29 3b 0a 7d 0a 0a 2f 2a 0a (TCL_OK);.}../*.
afc0: 20 2a 20 48 6f 74 2d 72 65 73 74 61 72 74 20 73 * Hot-restart s
afd0: 75 70 70 6f 72 74 0a 20 2a 2f 0a 2f 2a 20 49 6e upport. */./* In
afe0: 69 74 69 61 74 65 20 61 20 68 6f 74 2d 72 65 73 itiate a hot-res
aff0: 74 61 72 74 20 2a 2f 0a 73 74 61 74 69 63 20 76 tart */.static v
b000: 6f 69 64 20 61 70 70 66 73 5f 68 6f 74 5f 72 65 oid appfs_hot_re
b010: 73 74 61 72 74 28 76 6f 69 64 29 20 7b 0a 09 41 start(void) {..A
b020: 50 50 46 53 5f 44 45 42 55 47 28 22 41 73 6b 65 PPFS_DEBUG("Aske
b030: 64 20 74 6f 20 69 6e 69 74 69 61 74 65 20 68 6f d to initiate ho
b040: 74 20 72 65 73 74 61 72 74 22 29 3b 0a 0a 09 61 t restart");...a
b050: 70 70 66 73 5f 74 63 6c 5f 52 65 73 65 74 49 6e ppfs_tcl_ResetIn
b060: 74 65 72 70 73 28 29 3b 0a 0a 09 61 70 70 66 73 terps();...appfs
b070: 5f 67 65 74 5f 70 61 74 68 5f 69 6e 66 6f 5f 63 _get_path_info_c
b080: 61 63 68 65 5f 66 6c 75 73 68 28 2d 31 2c 20 2d ache_flush(-1, -
b090: 31 29 3b 0a 0a 09 72 65 74 75 72 6e 3b 0a 7d 0a 1);...return;.}.
b0a0: 0a 2f 2a 0a 20 2a 20 53 69 67 6e 61 6c 20 68 61 ./*. * Signal ha
b0b0: 6e 64 6c 65 72 0a 20 2a 20 20 20 20 20 20 20 20 ndler. *
b0c0: 20 53 49 47 48 55 50 20 69 6e 69 74 69 61 74 65 SIGHUP initiate
b0d0: 73 20 61 20 68 6f 74 20 72 65 73 74 61 72 74 0a s a hot restart.
b0e0: 20 2a 2f 0a 73 74 61 74 69 63 20 76 6f 69 64 20 */.static void
b0f0: 61 70 70 66 73 5f 73 69 67 6e 61 6c 5f 68 61 6e appfs_signal_han
b100: 64 6c 65 72 28 69 6e 74 20 73 69 67 29 20 7b 0a dler(int sig) {.
b110: 09 2f 2a 20 44 6f 20 6e 6f 74 20 68 61 6e 64 6c ./* Do not handl
b120: 65 20 73 69 67 6e 61 6c 73 20 75 6e 74 69 6c 20 e signals until
b130: 46 55 53 45 20 68 61 73 20 62 65 65 6e 20 73 74 FUSE has been st
b140: 61 72 74 65 64 20 2a 2f 0a 09 69 66 20 28 21 61 arted */..if (!a
b150: 70 70 66 73 5f 66 75 73 65 5f 73 74 61 72 74 65 ppfs_fuse_starte
b160: 64 29 20 7b 0a 09 09 72 65 74 75 72 6e 3b 0a 09 d) {...return;..
b170: 7d 0a 0a 09 2f 2a 20 52 65 71 75 65 73 74 20 74 }.../* Request t
b180: 6f 20 70 65 72 66 6f 72 6d 20 61 20 22 68 6f 74 o perform a "hot
b190: 22 20 72 65 73 74 61 72 74 20 2a 2f 0a 09 69 66 " restart */..if
b1a0: 20 28 73 69 67 20 3d 3d 20 53 49 47 48 55 50 29 (sig == SIGHUP)
b1b0: 20 7b 0a 09 09 61 70 70 66 73 5f 68 6f 74 5f 72 {...appfs_hot_r
b1c0: 65 73 74 61 72 74 28 29 3b 0a 09 7d 0a 0a 09 72 estart();..}...r
b1d0: 65 74 75 72 6e 3b 0a 7d 0a 0a 2f 2a 0a 20 2a 20 eturn;.}../*. *
b1e0: 54 65 72 6d 69 6e 61 74 65 20 61 20 74 68 72 65 Terminate a thre
b1f0: 61 64 0a 20 2a 2f 0a 73 74 61 74 69 63 20 76 6f ad. */.static vo
b200: 69 64 20 61 70 70 66 73 5f 74 65 72 6d 69 6e 61 id appfs_termina
b210: 74 65 5f 69 6e 74 65 72 70 5f 61 6e 64 5f 74 68 te_interp_and_th
b220: 72 65 61 64 28 76 6f 69 64 20 2a 5f 69 6e 74 65 read(void *_inte
b230: 72 70 29 20 7b 0a 09 54 63 6c 5f 49 6e 74 65 72 rp) {..Tcl_Inter
b240: 70 20 2a 69 6e 74 65 72 70 3b 0a 0a 09 41 50 50 p *interp;...APP
b250: 46 53 5f 44 45 42 55 47 28 22 43 61 6c 6c 65 64 FS_DEBUG("Called
b260: 3a 20 5f 69 6e 74 65 72 70 20 3d 20 25 70 22 2c : _interp = %p",
b270: 20 5f 69 6e 74 65 72 70 29 3b 0a 0a 09 69 66 20 _interp);...if
b280: 28 5f 69 6e 74 65 72 70 20 3d 3d 20 4e 55 4c 4c (_interp == NULL
b290: 29 20 7b 0a 09 09 41 50 50 46 53 5f 44 45 42 55 ) {...APPFS_DEBU
b2a0: 47 28 22 54 65 72 6d 69 6e 61 74 69 6e 67 20 74 G("Terminating t
b2b0: 68 72 65 61 64 20 77 69 74 68 20 6e 6f 20 69 6e hread with no in
b2c0: 74 65 72 70 72 65 74 65 72 22 29 3b 0a 0a 09 09 terpreter");....
b2d0: 72 65 74 75 72 6e 3b 0a 09 7d 0a 0a 09 69 6e 74 return;..}...int
b2e0: 65 72 70 20 3d 20 5f 69 6e 74 65 72 70 3b 0a 0a erp = _interp;..
b2f0: 09 41 50 50 46 53 5f 44 45 42 55 47 28 22 54 65 .APPFS_DEBUG("Te
b300: 72 6d 69 6e 61 74 69 6e 67 20 69 6e 74 65 72 70 rminating interp
b310: 72 65 74 65 72 20 64 75 65 20 74 6f 20 74 68 72 reter due to thr
b320: 65 61 64 20 74 65 72 6d 69 6e 61 74 69 6f 6e 22 ead termination"
b330: 29 3b 0a 0a 09 61 70 70 66 73 5f 63 61 6c 6c 5f );...appfs_call_
b340: 6c 69 62 74 63 6c 28 0a 09 09 54 63 6c 5f 44 65 libtcl(...Tcl_De
b350: 6c 65 74 65 49 6e 74 65 72 70 28 69 6e 74 65 72 leteInterp(inter
b360: 70 29 3b 0a 09 29 0a 0a 09 61 70 70 66 73 5f 63 p);..)...appfs_c
b370: 61 6c 6c 5f 6c 69 62 74 63 6c 28 0a 09 09 54 63 all_libtcl(...Tc
b380: 6c 5f 46 69 6e 61 6c 69 7a 65 54 68 72 65 61 64 l_FinalizeThread
b390: 28 29 3b 0a 09 29 0a 0a 09 72 65 74 75 72 6e 3b ();..)...return;
b3a0: 0a 7d 0a 0a 2f 2a 0a 20 2a 20 43 6f 6d 6d 61 6e .}../*. * Comman
b3b0: 64 2d 6c 69 6e 65 20 70 61 72 73 69 6e 67 20 74 d-line parsing t
b3c0: 6f 6f 6c 73 0a 20 2a 2f 0a 73 74 61 74 69 63 20 ools. */.static
b3d0: 76 6f 69 64 20 61 70 70 66 73 5f 70 72 69 6e 74 void appfs_print
b3e0: 5f 68 65 6c 70 28 46 49 4c 45 20 2a 63 68 61 6e _help(FILE *chan
b3f0: 6e 65 6c 29 20 7b 0a 09 66 70 72 69 6e 74 66 28 nel) {..fprintf(
b400: 63 68 61 6e 6e 65 6c 2c 20 22 55 73 61 67 65 3a channel, "Usage:
b410: 20 7b 61 70 70 66 73 64 7c 6d 6f 75 6e 74 2e 61 {appfsd|mount.a
b420: 70 70 66 73 7d 20 5b 2d 6f 20 3c 6f 70 74 69 6f ppfs} [-o <optio
b430: 6e 3e 5d 20 5b 2d 64 66 73 68 5d 20 3c 63 61 63 n>] [-dfsh] <cac
b440: 68 65 64 69 72 3e 20 3c 6d 6f 75 6e 74 70 6f 69 hedir> <mountpoi
b450: 6e 74 3e 5c 6e 22 29 3b 0a 09 66 70 72 69 6e 74 nt>\n");..fprint
b460: 66 28 63 68 61 6e 6e 65 6c 2c 20 22 5c 6e 22 29 f(channel, "\n")
b470: 3b 0a 09 66 70 72 69 6e 74 66 28 63 68 61 6e 6e ;..fprintf(chann
b480: 65 6c 2c 20 22 4f 70 74 69 6f 6e 73 3a 5c 6e 22 el, "Options:\n"
b490: 29 3b 0a 09 66 70 72 69 6e 74 66 28 63 68 61 6e );..fprintf(chan
b4a0: 6e 65 6c 2c 20 22 20 20 2d 64 20 20 20 20 20 20 nel, " -d
b4b0: 20 20 20 20 20 20 20 20 45 6e 61 62 6c 65 20 46 Enable F
b4c0: 55 53 45 20 64 65 62 75 67 20 6d 6f 64 65 2e 5c USE debug mode.\
b4d0: 6e 22 29 3b 0a 09 66 70 72 69 6e 74 66 28 63 68 n");..fprintf(ch
b4e0: 61 6e 6e 65 6c 2c 20 22 20 20 2d 66 20 20 20 20 annel, " -f
b4f0: 20 20 20 20 20 20 20 20 20 20 52 75 6e 20 69 6e Run in
b500: 20 66 6f 72 65 67 72 6f 75 6e 64 2e 5c 6e 22 29 foreground.\n")
b510: 3b 0a 09 66 70 72 69 6e 74 66 28 63 68 61 6e 6e ;..fprintf(chann
b520: 65 6c 2c 20 22 20 20 2d 73 20 20 20 20 20 20 20 el, " -s
b530: 20 20 20 20 20 20 20 45 6e 61 62 6c 65 20 73 69 Enable si
b540: 6e 67 6c 65 20 74 68 72 65 61 64 65 64 20 6d 6f ngle threaded mo
b550: 64 65 2e 5c 6e 22 29 3b 0a 09 66 70 72 69 6e 74 de.\n");..fprint
b560: 66 28 63 68 61 6e 6e 65 6c 2c 20 22 20 20 2d 68 f(channel, " -h
b570: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 47 69 Gi
b580: 76 65 20 74 68 69 73 20 68 65 6c 70 2e 5c 6e 22 ve this help.\n"
b590: 29 3b 0a 09 66 70 72 69 6e 74 66 28 63 68 61 6e );..fprintf(chan
b5a0: 6e 65 6c 2c 20 22 20 20 2d 6f 20 6e 6f 74 68 72 nel, " -o nothr
b5b0: 65 61 64 73 20 20 20 20 45 6e 61 62 6c 65 20 73 eads Enable s
b5c0: 69 6e 67 6c 65 20 74 68 72 65 61 64 65 64 20 6d ingle threaded m
b5d0: 6f 64 65 2e 5c 6e 22 29 3b 0a 09 66 70 72 69 6e ode.\n");..fprin
b5e0: 74 66 28 63 68 61 6e 6e 65 6c 2c 20 22 20 20 2d tf(channel, " -
b5f0: 6f 20 61 6c 6c 6f 77 5f 6f 74 68 65 72 20 20 41 o allow_other A
b600: 6c 6c 6f 77 20 6f 74 68 65 72 20 75 73 65 72 73 llow other users
b610: 20 74 6f 20 61 63 63 65 73 73 20 74 68 69 73 20 to access this
b620: 6d 6f 75 6e 74 70 6f 69 6e 74 20 28 64 65 66 61 mountpoint (defa
b630: 75 6c 74 5c 6e 22 29 3b 0a 09 66 70 72 69 6e 74 ult\n");..fprint
b640: 66 28 63 68 61 6e 6e 65 6c 2c 20 22 20 20 20 20 f(channel, "
b650: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 69 66 if
b660: 20 72 6f 6f 74 29 2e 5c 6e 22 29 3b 0a 0a 09 72 root).\n");...r
b670: 65 74 75 72 6e 3b 0a 7d 0a 0a 73 74 61 74 69 63 eturn;.}..static
b680: 20 69 6e 74 20 61 70 70 66 73 5f 6f 70 74 5f 70 int appfs_opt_p
b690: 61 72 73 65 28 69 6e 74 20 61 72 67 63 2c 20 63 arse(int argc, c
b6a0: 68 61 72 20 2a 2a 61 72 67 76 2c 20 20 73 74 72 har **argv, str
b6b0: 75 63 74 20 66 75 73 65 5f 61 72 67 73 20 2a 61 uct fuse_args *a
b6c0: 72 67 73 29 20 7b 0a 09 69 6e 74 20 63 68 3b 0a rgs) {..int ch;.
b6d0: 09 63 68 61 72 20 2a 6f 70 74 73 74 72 2c 20 2a .char *optstr, *
b6e0: 6f 70 74 73 74 72 5f 6e 65 78 74 2c 20 2a 6f 70 optstr_next, *op
b6f0: 74 73 74 72 5f 73 3b 0a 09 63 68 61 72 20 66 61 tstr_s;..char fa
b700: 6b 65 5f 61 72 67 5b 33 5d 20 3d 20 7b 27 2d 27 ke_arg[3] = {'-'
b710: 2c 20 30 2c 20 30 7d 3b 0a 0a 09 2f 2a 0a 09 20 , 0, 0};.../*..
b720: 2a 20 44 65 66 61 75 6c 74 20 76 61 6c 75 65 73 * Default values
b730: 0a 09 20 2a 2f 0a 23 69 66 64 65 66 20 54 43 4c .. */.#ifdef TCL
b740: 5f 54 48 52 45 41 44 53 0a 09 61 70 70 66 73 5f _THREADS..appfs_
b750: 74 68 72 65 61 64 65 64 5f 74 63 6c 20 3d 20 31 threaded_tcl = 1
b760: 3b 0a 23 65 6c 73 65 0a 09 61 70 70 66 73 5f 74 ;.#else..appfs_t
b770: 68 72 65 61 64 65 64 5f 74 63 6c 20 3d 20 30 3b hreaded_tcl = 0;
b780: 0a 23 65 6e 64 69 66 0a 0a 09 2f 2a 2a 0a 09 20 .#endif.../**..
b790: 2a 2a 20 41 64 64 20 46 55 53 45 20 61 72 67 75 ** Add FUSE argu
b7a0: 6d 65 6e 74 73 20 77 68 69 63 68 20 77 65 20 61 ments which we a
b7b0: 6c 77 61 79 73 20 73 75 70 70 6c 79 0a 09 20 2a lways supply.. *
b7c0: 2a 2f 0a 09 66 75 73 65 5f 6f 70 74 5f 61 64 64 */..fuse_opt_add
b7d0: 5f 61 72 67 28 61 72 67 73 2c 20 22 2d 6f 64 65 _arg(args, "-ode
b7e0: 66 61 75 6c 74 5f 70 65 72 6d 69 73 73 69 6f 6e fault_permission
b7f0: 73 2c 66 73 6e 61 6d 65 3d 61 70 70 66 73 2c 73 s,fsname=appfs,s
b800: 75 62 74 79 70 65 3d 61 70 70 66 73 64 2c 75 73 ubtype=appfsd,us
b810: 65 5f 69 6e 6f 2c 64 69 72 65 63 74 5f 69 6f 2c e_ino,direct_io,
b820: 65 6e 74 72 79 5f 74 69 6d 65 6f 75 74 3d 30 2c entry_timeout=0,
b830: 61 74 74 72 5f 74 69 6d 65 6f 75 74 3d 30 2c 62 attr_timeout=0,b
b840: 69 67 5f 77 72 69 74 65 73 2c 69 6e 74 72 2c 68 ig_writes,intr,h
b850: 61 72 64 5f 72 65 6d 6f 76 65 22 29 3b 0a 0a 09 ard_remove");...
b860: 69 66 20 28 67 65 74 75 69 64 28 29 20 3d 3d 20 if (getuid() ==
b870: 30 29 20 7b 0a 09 09 66 75 73 65 5f 6f 70 74 5f 0) {...fuse_opt_
b880: 70 61 72 73 65 28 61 72 67 73 2c 20 4e 55 4c 4c parse(args, NULL
b890: 2c 20 4e 55 4c 4c 2c 20 4e 55 4c 4c 29 3b 0a 09 , NULL, NULL);..
b8a0: 09 66 75 73 65 5f 6f 70 74 5f 61 64 64 5f 61 72 .fuse_opt_add_ar
b8b0: 67 28 61 72 67 73 2c 20 22 2d 6f 61 6c 6c 6f 77 g(args, "-oallow
b8c0: 5f 6f 74 68 65 72 22 29 3b 0a 0a 09 09 2f 2a 0a _other");..../*.
b8d0: 09 09 20 2a 20 54 68 69 73 20 73 68 6f 75 6c 64 .. * This should
b8e0: 20 67 65 6e 65 72 61 6c 6c 79 20 62 65 20 61 76 generally be av
b8f0: 6f 69 64 65 64 2c 20 62 75 74 20 69 66 20 74 68 oided, but if th
b900: 65 72 65 20 61 72 65 20 73 65 63 75 72 69 74 79 ere are security
b910: 0a 09 09 20 2a 20 63 6f 6e 63 65 72 6e 73 20 73 ... * concerns s
b920: 75 69 64 20 63 61 6e 20 62 65 20 64 69 73 61 62 uid can be disab
b930: 6c 65 64 20 63 6f 6d 70 6c 65 74 65 6c 79 20 6f led completely o
b940: 6e 20 74 68 65 20 63 6f 6d 6d 61 6e 64 6c 69 6e n the commandlin
b950: 65 0a 09 09 20 2a 2f 0a 09 09 66 75 73 65 5f 6f e... */...fuse_o
b960: 70 74 5f 70 61 72 73 65 28 61 72 67 73 2c 20 4e pt_parse(args, N
b970: 55 4c 4c 2c 20 4e 55 4c 4c 2c 20 4e 55 4c 4c 29 ULL, NULL, NULL)
b980: 3b 0a 09 09 66 75 73 65 5f 6f 70 74 5f 61 64 64 ;...fuse_opt_add
b990: 5f 61 72 67 28 61 72 67 73 2c 20 22 2d 6f 73 75 _arg(args, "-osu
b9a0: 69 64 22 29 3b 0a 09 7d 0a 0a 09 77 68 69 6c 65 id");..}...while
b9b0: 20 28 28 63 68 20 3d 20 67 65 74 6f 70 74 28 61 ((ch = getopt(a
b9c0: 72 67 63 2c 20 61 72 67 76 2c 20 22 64 66 73 68 rgc, argv, "dfsh
b9d0: 76 6f 3a 22 29 29 20 21 3d 20 2d 31 29 20 7b 0a vo:")) != -1) {.
b9e0: 09 09 73 77 69 74 63 68 20 28 63 68 29 20 7b 0a ..switch (ch) {.
b9f0: 09 09 09 63 61 73 65 20 27 76 27 3a 0a 09 09 09 ...case 'v':....
ba00: 09 2f 2a 20 49 67 6e 6f 72 65 64 20 2a 2f 0a 09 ./* Ignored */..
ba10: 09 09 09 62 72 65 61 6b 3b 0a 09 09 09 63 61 73 ...break;....cas
ba20: 65 20 27 6f 27 3a 0a 09 09 09 09 6f 70 74 73 74 e 'o':.....optst
ba30: 72 5f 6e 65 78 74 20 3d 20 6f 70 74 73 74 72 20 r_next = optstr
ba40: 3d 20 6f 70 74 73 74 72 5f 73 20 3d 20 73 74 72 = optstr_s = str
ba50: 64 75 70 28 6f 70 74 61 72 67 29 3b 0a 0a 09 09 dup(optarg);....
ba60: 09 09 77 68 69 6c 65 20 28 31 29 20 7b 0a 09 09 ..while (1) {...
ba70: 09 09 09 6f 70 74 73 74 72 20 3d 20 6f 70 74 73 ...optstr = opts
ba80: 74 72 5f 6e 65 78 74 3b 0a 0a 09 09 09 09 09 69 tr_next;.......i
ba90: 66 20 28 21 6f 70 74 73 74 72 29 20 7b 0a 09 09 f (!optstr) {...
baa0: 09 09 09 09 62 72 65 61 6b 3b 0a 09 09 09 09 09 ....break;......
bab0: 7d 0a 0a 09 09 09 09 09 6f 70 74 73 74 72 5f 6e }.......optstr_n
bac0: 65 78 74 20 3d 20 73 74 72 63 68 72 28 6f 70 74 ext = strchr(opt
bad0: 73 74 72 2c 20 27 2c 27 29 3b 0a 09 09 09 09 09 str, ',');......
bae0: 69 66 20 28 6f 70 74 73 74 72 5f 6e 65 78 74 29 if (optstr_next)
baf0: 20 7b 0a 09 09 09 09 09 09 2a 6f 70 74 73 74 72 {.......*optstr
bb00: 5f 6e 65 78 74 20 3d 20 27 5c 30 27 3b 0a 09 09 _next = '\0';...
bb10: 09 09 09 09 6f 70 74 73 74 72 5f 6e 65 78 74 2b ....optstr_next+
bb20: 2b 3b 0a 09 09 09 09 09 7d 0a 0a 09 09 09 09 09 +;......}.......
bb30: 69 66 20 28 73 74 72 63 6d 70 28 6f 70 74 73 74 if (strcmp(optst
bb40: 72 2c 20 22 6e 6f 74 68 72 65 61 64 73 22 29 20 r, "nothreads")
bb50: 3d 3d 20 30 29 20 7b 0a 09 09 09 09 09 09 41 50 == 0) {.......AP
bb60: 50 46 53 5f 44 45 42 55 47 28 22 50 61 73 73 69 PFS_DEBUG("Passi
bb70: 6e 67 20 6f 70 74 69 6f 6e 20 74 6f 20 46 55 53 ng option to FUS
bb80: 45 3a 20 2d 73 22 29 3b 0a 0a 09 09 09 09 09 09 E: -s");........
bb90: 66 75 73 65 5f 6f 70 74 5f 70 61 72 73 65 28 61 fuse_opt_parse(a
bba0: 72 67 73 2c 20 4e 55 4c 4c 2c 20 4e 55 4c 4c 2c rgs, NULL, NULL,
bbb0: 20 4e 55 4c 4c 29 3b 0a 09 09 09 09 09 09 66 75 NULL);.......fu
bbc0: 73 65 5f 6f 70 74 5f 61 64 64 5f 61 72 67 28 61 se_opt_add_arg(a
bbd0: 72 67 73 2c 20 22 2d 73 22 29 3b 0a 0a 09 09 09 rgs, "-s");.....
bbe0: 09 09 09 61 70 70 66 73 5f 74 68 72 65 61 64 65 ...appfs_threade
bbf0: 64 5f 74 63 6c 20 3d 20 30 3b 0a 09 09 09 09 09 d_tcl = 0;......
bc00: 7d 20 65 6c 73 65 20 69 66 20 28 73 74 72 63 6d } else if (strcm
bc10: 70 28 6f 70 74 73 74 72 2c 20 22 61 6c 6c 6f 77 p(optstr, "allow
bc20: 5f 6f 74 68 65 72 22 29 20 3d 3d 20 30 29 20 7b _other") == 0) {
bc30: 0a 09 09 09 09 09 09 41 50 50 46 53 5f 44 45 42 .......APPFS_DEB
bc40: 55 47 28 22 50 61 73 73 69 6e 67 20 6f 70 74 69 UG("Passing opti
bc50: 6f 6e 20 74 6f 20 46 55 53 45 3a 20 2d 6f 20 61 on to FUSE: -o a
bc60: 6c 6c 6f 77 5f 4f 74 68 65 72 22 29 3b 0a 0a 09 llow_Other");...
bc70: 09 09 09 09 09 66 75 73 65 5f 6f 70 74 5f 70 61 .....fuse_opt_pa
bc80: 72 73 65 28 61 72 67 73 2c 20 4e 55 4c 4c 2c 20 rse(args, NULL,
bc90: 4e 55 4c 4c 2c 20 4e 55 4c 4c 29 3b 0a 09 09 09 NULL, NULL);....
bca0: 09 09 09 66 75 73 65 5f 6f 70 74 5f 61 64 64 5f ...fuse_opt_add_
bcb0: 61 72 67 28 61 72 67 73 2c 20 22 2d 6f 61 6c 6c arg(args, "-oall
bcc0: 6f 77 5f 6f 74 68 65 72 22 29 3b 0a 09 09 09 09 ow_other");.....
bcd0: 09 7d 20 65 6c 73 65 20 69 66 20 28 73 74 72 63 .} else if (strc
bce0: 6d 70 28 6f 70 74 73 74 72 2c 20 22 72 77 22 29 mp(optstr, "rw")
bcf0: 20 3d 3d 20 30 29 20 7b 0a 09 09 09 09 09 09 2f == 0) {......./
bd00: 2a 20 49 67 6e 6f 72 65 64 20 2a 2f 0a 09 09 09 * Ignored */....
bd10: 09 09 7d 20 65 6c 73 65 20 7b 0a 09 09 09 09 09 ..} else {......
bd20: 09 66 70 72 69 6e 74 66 28 73 74 64 65 72 72 2c .fprintf(stderr,
bd30: 20 22 61 70 70 66 73 64 3a 20 69 6e 76 61 6c 69 "appfsd: invali
bd40: 64 20 6f 70 74 69 6f 6e 3a 20 5c 22 2d 6f 20 25 d option: \"-o %
bd50: 73 5c 22 5c 6e 22 2c 20 6f 70 74 73 74 72 29 3b s\"\n", optstr);
bd60: 0a 0a 09 09 09 09 09 09 66 72 65 65 28 6f 70 74 ........free(opt
bd70: 73 74 72 5f 73 29 3b 0a 0a 09 09 09 09 09 09 72 str_s);........r
bd80: 65 74 75 72 6e 28 31 29 3b 0a 09 09 09 09 09 7d eturn(1);......}
bd90: 0a 09 09 09 09 7d 0a 0a 09 09 09 09 66 72 65 65 .....}......free
bda0: 28 6f 70 74 73 74 72 5f 73 29 3b 0a 0a 09 09 09 (optstr_s);.....
bdb0: 09 62 72 65 61 6b 3b 0a 09 09 09 63 61 73 65 20 .break;....case
bdc0: 27 64 27 3a 0a 09 09 09 63 61 73 65 20 27 66 27 'd':....case 'f'
bdd0: 3a 0a 09 09 09 63 61 73 65 20 27 73 27 3a 0a 09 :....case 's':..
bde0: 09 09 09 69 66 20 28 63 68 20 3d 3d 20 27 73 27 ...if (ch == 's'
bdf0: 29 20 7b 0a 09 09 09 09 09 61 70 70 66 73 5f 74 ) {......appfs_t
be00: 68 72 65 61 64 65 64 5f 74 63 6c 20 3d 20 30 3b hreaded_tcl = 0;
be10: 0a 09 09 09 09 7d 0a 0a 09 09 09 09 66 61 6b 65 .....}......fake
be20: 5f 61 72 67 5b 31 5d 20 3d 20 63 68 3b 0a 0a 09 _arg[1] = ch;...
be30: 09 09 09 41 50 50 46 53 5f 44 45 42 55 47 28 22 ...APPFS_DEBUG("
be40: 50 61 73 73 69 6e 67 20 6f 70 74 69 6f 6e 20 74 Passing option t
be50: 6f 20 46 55 53 45 3a 20 25 73 22 2c 20 66 61 6b o FUSE: %s", fak
be60: 65 5f 61 72 67 29 3b 0a 0a 09 09 09 09 66 75 73 e_arg);......fus
be70: 65 5f 6f 70 74 5f 70 61 72 73 65 28 61 72 67 73 e_opt_parse(args
be80: 2c 20 4e 55 4c 4c 2c 20 4e 55 4c 4c 2c 20 4e 55 , NULL, NULL, NU
be90: 4c 4c 29 3b 0a 09 09 09 09 66 75 73 65 5f 6f 70 LL);.....fuse_op
bea0: 74 5f 61 64 64 5f 61 72 67 28 61 72 67 73 2c 20 t_add_arg(args,
beb0: 66 61 6b 65 5f 61 72 67 29 3b 0a 09 09 09 09 62 fake_arg);.....b
bec0: 72 65 61 6b 3b 0a 09 09 09 63 61 73 65 20 27 68 reak;....case 'h
bed0: 27 3a 0a 09 09 09 09 61 70 70 66 73 5f 70 72 69 ':.....appfs_pri
bee0: 6e 74 5f 68 65 6c 70 28 73 74 64 6f 75 74 29 3b nt_help(stdout);
bef0: 0a 0a 09 09 09 09 72 65 74 75 72 6e 28 2d 31 29 ......return(-1)
bf00: 3b 0a 09 09 09 63 61 73 65 20 27 3a 27 3a 0a 09 ;....case ':':..
bf10: 09 09 63 61 73 65 20 27 3f 27 3a 0a 09 09 09 64 ..case '?':....d
bf20: 65 66 61 75 6c 74 3a 0a 09 09 09 09 61 70 70 66 efault:.....appf
bf30: 73 5f 70 72 69 6e 74 5f 68 65 6c 70 28 73 74 64 s_print_help(std
bf40: 65 72 72 29 3b 0a 0a 09 09 09 09 72 65 74 75 72 err);......retur
bf50: 6e 28 31 29 3b 0a 09 09 7d 0a 09 7d 0a 0a 09 69 n(1);...}..}...i
bf60: 66 20 28 28 6f 70 74 69 6e 64 20 2b 20 32 29 20 f ((optind + 2)
bf70: 21 3d 20 61 72 67 63 29 20 7b 0a 09 09 69 66 20 != argc) {...if
bf80: 28 28 6f 70 74 69 6e 64 20 2b 20 32 29 20 3c 20 ((optind + 2) <
bf90: 61 72 67 63 29 20 7b 0a 09 09 09 66 70 72 69 6e argc) {....fprin
bfa0: 74 66 28 73 74 64 65 72 72 2c 20 22 54 6f 6f 20 tf(stderr, "Too
bfb0: 6d 61 6e 79 20 61 72 67 75 6d 65 6e 74 73 5c 6e many arguments\n
bfc0: 22 29 3b 0a 09 09 7d 20 65 6c 73 65 20 7b 0a 09 ");...} else {..
bfd0: 09 09 66 70 72 69 6e 74 66 28 73 74 64 65 72 72 ..fprintf(stderr
bfe0: 2c 20 22 4d 69 73 73 69 6e 67 20 63 61 63 68 65 , "Missing cache
bff0: 64 69 72 20 6f 72 20 6d 6f 75 6e 74 70 6f 69 6e dir or mountpoin
c000: 74 5c 6e 22 29 3b 0a 09 09 7d 0a 0a 09 09 61 70 t\n");...}....ap
c010: 70 66 73 5f 70 72 69 6e 74 5f 68 65 6c 70 28 73 pfs_print_help(s
c020: 74 64 65 72 72 29 3b 0a 0a 09 09 72 65 74 75 72 tderr);....retur
c030: 6e 28 31 29 3b 0a 09 7d 0a 0a 09 2f 2a 0a 09 20 n(1);..}.../*..
c040: 2a 20 53 65 74 20 63 61 63 68 65 20 64 69 72 20 * Set cache dir
c050: 61 73 20 66 69 72 73 74 20 61 72 67 75 6d 65 6e as first argumen
c060: 74 20 28 74 68 65 20 22 64 65 76 69 63 65 22 2c t (the "device",
c070: 20 65 73 73 65 6e 74 69 61 6c 6c 79 29 0a 09 20 essentially)..
c080: 2a 2f 0a 09 61 70 70 66 73 5f 63 61 63 68 65 64 */..appfs_cached
c090: 69 72 20 3d 20 61 72 67 76 5b 6f 70 74 69 6e 64 ir = argv[optind
c0a0: 5d 3b 0a 0a 09 2f 2a 0a 09 20 2a 20 50 61 73 73 ];.../*.. * Pass
c0b0: 20 74 68 65 20 72 65 6d 61 69 6e 69 6e 67 20 61 the remaining a
c0c0: 72 67 75 6d 65 6e 74 20 74 6f 20 46 55 53 45 20 rgument to FUSE
c0d0: 61 73 20 74 68 65 20 64 69 72 65 63 74 6f 72 79 as the directory
c0e0: 0a 09 20 2a 2f 0a 09 66 75 73 65 5f 6f 70 74 5f .. */..fuse_opt_
c0f0: 70 61 72 73 65 28 61 72 67 73 2c 20 4e 55 4c 4c parse(args, NULL
c100: 2c 20 4e 55 4c 4c 2c 20 4e 55 4c 4c 29 3b 0a 09 , NULL, NULL);..
c110: 66 75 73 65 5f 6f 70 74 5f 61 64 64 5f 61 72 67 fuse_opt_add_arg
c120: 28 61 72 67 73 2c 20 61 72 67 76 5b 6f 70 74 69 (args, argv[opti
c130: 6e 64 20 2b 20 31 5d 29 3b 0a 0a 09 72 65 74 75 nd + 1]);...retu
c140: 72 6e 28 30 29 3b 0a 7d 0a 0a 0a 2f 2a 0a 20 2a rn(0);.}.../*. *
c150: 20 46 55 53 45 20 6f 70 65 72 61 74 69 6f 6e 73 FUSE operations
c160: 20 73 74 72 75 63 74 75 72 65 0a 20 2a 2f 0a 73 structure. */.s
c170: 74 61 74 69 63 20 73 74 72 75 63 74 20 66 75 73 tatic struct fus
c180: 65 5f 6f 70 65 72 61 74 69 6f 6e 73 20 61 70 70 e_operations app
c190: 66 73 5f 6f 70 65 72 61 74 69 6f 6e 73 20 3d 20 fs_operations =
c1a0: 7b 0a 09 2e 67 65 74 61 74 74 72 20 20 20 3d 20 {...getattr =
c1b0: 61 70 70 66 73 5f 66 75 73 65 5f 67 65 74 61 74 appfs_fuse_getat
c1c0: 74 72 2c 0a 09 2e 72 65 61 64 64 69 72 20 20 20 tr,...readdir
c1d0: 3d 20 61 70 70 66 73 5f 66 75 73 65 5f 72 65 61 = appfs_fuse_rea
c1e0: 64 64 69 72 2c 0a 09 2e 72 65 61 64 6c 69 6e 6b ddir,...readlink
c1f0: 20 20 3d 20 61 70 70 66 73 5f 66 75 73 65 5f 72 = appfs_fuse_r
c200: 65 61 64 6c 69 6e 6b 2c 0a 09 2e 6f 70 65 6e 20 eadlink,...open
c210: 20 20 20 20 20 3d 20 61 70 70 66 73 5f 66 75 73 = appfs_fus
c220: 65 5f 6f 70 65 6e 2c 0a 09 2e 72 65 6c 65 61 73 e_open,...releas
c230: 65 20 20 20 3d 20 61 70 70 66 73 5f 66 75 73 65 e = appfs_fuse
c240: 5f 63 6c 6f 73 65 2c 0a 09 2e 72 65 61 64 20 20 _close,...read
c250: 20 20 20 20 3d 20 61 70 70 66 73 5f 66 75 73 65 = appfs_fuse
c260: 5f 72 65 61 64 2c 0a 09 2e 77 72 69 74 65 20 20 _read,...write
c270: 20 20 20 3d 20 61 70 70 66 73 5f 66 75 73 65 5f = appfs_fuse_
c280: 77 72 69 74 65 2c 0a 09 2e 6d 6b 6e 6f 64 20 20 write,...mknod
c290: 20 20 20 3d 20 61 70 70 66 73 5f 66 75 73 65 5f = appfs_fuse_
c2a0: 6d 6b 6e 6f 64 2c 0a 09 2e 63 72 65 61 74 65 20 mknod,...create
c2b0: 20 20 20 3d 20 61 70 70 66 73 5f 66 75 73 65 5f = appfs_fuse_
c2c0: 63 72 65 61 74 65 2c 0a 09 2e 74 72 75 6e 63 61 create,...trunca
c2d0: 74 65 20 20 3d 20 61 70 70 66 73 5f 66 75 73 65 te = appfs_fuse
c2e0: 5f 74 72 75 6e 63 61 74 65 2c 0a 09 2e 75 6e 6c _truncate,...unl
c2f0: 69 6e 6b 20 20 20 20 3d 20 61 70 70 66 73 5f 66 ink = appfs_f
c300: 75 73 65 5f 75 6e 6c 69 6e 6b 5f 72 6d 64 69 72 use_unlink_rmdir
c310: 2c 0a 09 2e 72 6d 64 69 72 20 20 20 20 20 3d 20 ,...rmdir =
c320: 61 70 70 66 73 5f 66 75 73 65 5f 75 6e 6c 69 6e appfs_fuse_unlin
c330: 6b 5f 72 6d 64 69 72 2c 0a 09 2e 6d 6b 64 69 72 k_rmdir,...mkdir
c340: 20 20 20 20 20 3d 20 61 70 70 66 73 5f 66 75 73 = appfs_fus
c350: 65 5f 6d 6b 64 69 72 2c 0a 09 2e 63 68 6d 6f 64 e_mkdir,...chmod
c360: 20 20 20 20 20 3d 20 61 70 70 66 73 5f 66 75 73 = appfs_fus
c370: 65 5f 63 68 6d 6f 64 2c 0a 09 2e 73 79 6d 6c 69 e_chmod,...symli
c380: 6e 6b 20 20 20 3d 20 61 70 70 66 73 5f 66 75 73 nk = appfs_fus
c390: 65 5f 73 79 6d 6c 69 6e 6b 2c 0a 7d 3b 0a 0a 2f e_symlink,.};../
c3a0: 2a 0a 20 2a 20 45 6e 74 72 79 20 70 6f 69 6e 74 *. * Entry point
c3b0: 20 69 6e 74 6f 20 74 68 69 73 20 70 72 6f 67 72 into this progr
c3c0: 61 6d 2e 0a 20 2a 2f 0a 69 6e 74 20 6d 61 69 6e am.. */.int main
c3d0: 28 69 6e 74 20 61 72 67 63 2c 20 63 68 61 72 20 (int argc, char
c3e0: 2a 2a 61 72 67 76 29 20 7b 0a 09 54 63 6c 5f 49 **argv) {..Tcl_I
c3f0: 6e 74 65 72 70 20 2a 74 65 73 74 5f 69 6e 74 65 nterp *test_inte
c400: 72 70 3b 0a 09 63 68 61 72 20 2a 74 65 73 74 5f rp;..char *test_
c410: 69 6e 74 65 72 70 5f 65 72 72 6f 72 3b 0a 09 73 interp_error;..s
c420: 74 72 75 63 74 20 66 75 73 65 5f 61 72 67 73 20 truct fuse_args
c430: 61 72 67 73 20 3d 20 46 55 53 45 5f 41 52 47 53 args = FUSE_ARGS
c440: 5f 49 4e 49 54 28 30 2c 20 4e 55 4c 4c 29 3b 0a _INIT(0, NULL);.
c450: 09 69 6e 74 20 70 74 68 72 65 61 64 5f 72 65 74 .int pthread_ret
c460: 2c 20 61 6f 70 5f 72 65 74 3b 0a 09 76 6f 69 64 , aop_ret;..void
c470: 20 2a 73 69 67 6e 61 6c 5f 72 65 74 3b 0a 09 63 *signal_ret;..c
c480: 68 61 72 20 2a 61 72 67 76 30 3b 0a 0a 09 2f 2a har *argv0;.../*
c490: 0a 09 20 2a 20 53 6b 69 70 20 70 61 73 73 65 64 .. * Skip passed
c4a0: 20 70 72 6f 67 72 61 6d 20 6e 61 6d 65 0a 09 20 program name..
c4b0: 2a 2f 0a 09 69 66 20 28 61 72 67 63 20 3d 3d 20 */..if (argc ==
c4c0: 30 20 7c 7c 20 61 72 67 76 20 3d 3d 20 4e 55 4c 0 || argv == NUL
c4d0: 4c 29 20 7b 0a 09 09 72 65 74 75 72 6e 28 31 29 L) {...return(1)
c4e0: 3b 0a 09 7d 0a 0a 09 61 72 67 76 30 20 3d 20 61 ;..}...argv0 = a
c4f0: 72 67 76 5b 30 5d 3b 0a 0a 09 61 72 67 63 2d 2d rgv[0];...argc--
c500: 3b 0a 09 61 72 67 76 2b 2b 3b 0a 0a 09 2f 2a 0a ;..argv++;.../*.
c510: 09 20 2a 20 53 65 74 20 61 70 70 72 6f 70 72 69 . * Set appropri
c520: 61 74 65 20 75 6d 61 73 6b 0a 09 20 2a 2f 0a 09 ate umask.. */..
c530: 75 6d 61 73 6b 28 30 32 32 29 3b 0a 0a 09 2f 2a umask(022);.../*
c540: 0a 09 20 2a 20 53 65 74 20 67 6c 6f 62 61 6c 20 .. * Set global
c550: 76 61 72 69 61 62 6c 65 73 2c 20 74 68 65 73 65 variables, these
c560: 20 73 68 6f 75 6c 64 20 62 65 20 63 6f 6e 66 69 should be confi
c570: 67 75 72 61 74 69 6f 6e 20 6f 70 74 69 6f 6e 73 guration options
c580: 2e 0a 09 20 2a 2f 0a 09 61 70 70 66 73 5f 63 61 ... */..appfs_ca
c590: 63 68 65 64 69 72 20 3d 20 41 50 50 46 53 5f 43 chedir = APPFS_C
c5a0: 41 43 48 45 44 49 52 3b 0a 0a 09 2f 2a 0a 09 20 ACHEDIR;.../*..
c5b0: 2a 20 53 65 74 20 67 6c 6f 62 61 6c 20 76 61 72 * Set global var
c5c0: 69 61 62 6c 65 20 66 6f 72 20 22 62 6f 6f 74 20 iable for "boot
c5d0: 74 69 6d 65 22 20 74 6f 20 73 65 74 20 61 20 74 time" to set a t
c5e0: 69 6d 65 20 6f 6e 20 64 69 72 65 63 74 6f 72 69 ime on directori
c5f0: 65 73 0a 09 20 2a 20 74 68 61 74 20 77 65 20 66 es.. * that we f
c600: 61 6b 65 2e 0a 09 20 2a 2f 0a 09 61 70 70 66 73 ake... */..appfs
c610: 5f 62 6f 6f 74 74 69 6d 65 20 3d 20 74 69 6d 65 _boottime = time
c620: 28 4e 55 4c 4c 29 3b 0a 0a 09 2f 2a 0a 09 20 2a (NULL);.../*.. *
c630: 20 52 65 67 69 73 74 65 72 20 22 73 68 61 31 22 Register "sha1"
c640: 20 61 6e 64 20 22 61 70 70 66 73 64 22 20 70 61 and "appfsd" pa
c650: 63 6b 61 67 65 20 77 69 74 68 20 6c 69 62 74 63 ckage with libtc
c660: 6c 20 73 6f 20 74 68 61 74 20 61 6e 79 20 6e 65 l so that any ne
c670: 77 0a 09 20 2a 20 69 6e 74 65 72 70 72 65 74 65 w.. * interprete
c680: 72 73 20 63 72 65 61 74 65 64 20 28 77 68 69 63 rs created (whic
c690: 68 20 61 72 65 20 64 6f 6e 65 20 64 79 6e 61 6d h are done dynam
c6a0: 69 63 61 6c 6c 79 20 62 79 20 46 55 53 45 29 20 ically by FUSE)
c6b0: 63 61 6e 20 68 61 76 65 0a 09 20 2a 20 74 68 65 can have.. * the
c6c0: 20 61 70 70 72 6f 70 72 69 61 74 65 20 63 6f 6e appropriate con
c6d0: 66 69 67 75 72 61 74 69 6f 6e 20 64 6f 6e 65 20 figuration done
c6e0: 61 75 74 6f 6d 61 74 69 63 61 6c 6c 79 2e 0a 09 automatically...
c6f0: 20 2a 2f 0a 09 54 63 6c 5f 53 74 61 74 69 63 50 */..Tcl_StaticP
c700: 61 63 6b 61 67 65 28 4e 55 4c 4c 2c 20 22 73 68 ackage(NULL, "sh
c710: 61 31 22 2c 20 53 68 61 31 5f 49 6e 69 74 2c 20 a1", Sha1_Init,
c720: 4e 55 4c 4c 29 3b 0a 09 54 63 6c 5f 53 74 61 74 NULL);..Tcl_Stat
c730: 69 63 50 61 63 6b 61 67 65 28 4e 55 4c 4c 2c 20 icPackage(NULL,
c740: 22 61 70 70 66 73 64 22 2c 20 41 70 70 66 73 64 "appfsd", Appfsd
c750: 5f 49 6e 69 74 2c 20 4e 55 4c 4c 29 3b 0a 0a 09 _Init, NULL);...
c760: 2f 2a 0a 09 20 2a 20 43 72 65 61 74 65 20 61 20 /*.. * Create a
c770: 74 68 72 65 61 64 2d 73 70 65 63 69 66 69 63 2d thread-specific-
c780: 64 61 74 61 20 28 54 53 44 29 20 6b 65 79 20 66 data (TSD) key f
c790: 6f 72 20 65 61 63 68 20 74 68 72 65 61 64 20 74 or each thread t
c7a0: 6f 20 72 65 66 65 72 0a 09 20 2a 20 74 6f 20 69 o refer.. * to i
c7b0: 74 73 20 6f 77 6e 20 54 63 6c 20 69 6e 74 65 72 ts own Tcl inter
c7c0: 70 72 65 74 65 72 2e 20 20 54 63 6c 20 69 6e 74 preter. Tcl int
c7d0: 65 72 70 72 65 74 65 72 73 20 6d 75 73 74 20 62 erpreters must b
c7e0: 65 20 75 6e 69 71 75 65 20 70 65 72 0a 09 20 2a e unique per.. *
c7f0: 20 74 68 72 65 61 64 20 61 6e 64 20 6e 65 77 20 thread and new
c800: 74 68 72 65 61 64 73 20 61 72 65 20 64 79 6e 61 threads are dyna
c810: 6d 69 63 61 6c 6c 79 20 63 72 65 61 74 65 64 20 mically created
c820: 62 79 20 46 55 53 45 2e 0a 09 20 2a 2f 0a 09 70 by FUSE... */..p
c830: 74 68 72 65 61 64 5f 72 65 74 20 3d 20 70 74 68 thread_ret = pth
c840: 72 65 61 64 5f 6b 65 79 5f 63 72 65 61 74 65 28 read_key_create(
c850: 26 69 6e 74 65 72 70 4b 65 79 2c 20 61 70 70 66 &interpKey, appf
c860: 73 5f 74 65 72 6d 69 6e 61 74 65 5f 69 6e 74 65 s_terminate_inte
c870: 72 70 5f 61 6e 64 5f 74 68 72 65 61 64 29 3b 0a rp_and_thread);.
c880: 09 69 66 20 28 70 74 68 72 65 61 64 5f 72 65 74 .if (pthread_ret
c890: 20 21 3d 20 30 29 20 7b 0a 09 09 66 70 72 69 6e != 0) {...fprin
c8a0: 74 66 28 73 74 64 65 72 72 2c 20 22 55 6e 61 62 tf(stderr, "Unab
c8b0: 6c 65 20 74 6f 20 63 72 65 61 74 65 20 54 53 44 le to create TSD
c8c0: 20 6b 65 79 20 66 6f 72 20 54 63 6c 2e 20 20 41 key for Tcl. A
c8d0: 62 6f 72 74 69 6e 67 2e 5c 6e 22 29 3b 0a 0a 09 borting.\n");...
c8e0: 09 72 65 74 75 72 6e 28 31 29 3b 0a 09 7d 0a 0a .return(1);..}..
c8f0: 09 2f 2a 0a 09 20 2a 20 4d 61 6e 75 61 6c 6c 79 ./*.. * Manually
c900: 20 73 70 65 63 69 66 79 20 63 61 63 68 65 20 64 specify cache d
c910: 69 72 65 63 74 6f 72 79 2c 20 77 69 74 68 6f 75 irectory, withou
c920: 74 20 46 55 53 45 20 63 61 6c 6c 62 61 63 6b 0a t FUSE callback.
c930: 09 20 2a 20 54 68 69 73 20 6f 70 74 69 6f 6e 20 . * This option
c940: 6f 6e 6c 79 20 77 6f 72 6b 73 20 77 68 65 6e 20 only works when
c950: 6e 6f 74 20 75 73 69 6e 67 20 46 55 53 45 2c 20 not using FUSE,
c960: 73 69 6e 63 65 20 77 65 0a 09 20 2a 20 64 6f 20 since we.. * do
c970: 6e 6f 74 20 70 72 6f 63 65 73 73 20 69 74 20 77 not process it w
c980: 69 74 68 20 46 55 53 45 73 20 6f 70 74 69 6f 6e ith FUSEs option
c990: 20 70 72 6f 63 65 73 73 69 6e 67 2e 0a 09 20 2a processing... *
c9a0: 2f 0a 09 69 66 20 28 61 72 67 63 20 3e 3d 20 32 /..if (argc >= 2
c9b0: 29 20 7b 0a 09 09 69 66 20 28 73 74 72 63 6d 70 ) {...if (strcmp
c9c0: 28 61 72 67 76 5b 30 5d 2c 20 22 2d 2d 63 61 63 (argv[0], "--cac
c9d0: 68 65 64 69 72 22 29 20 3d 3d 20 30 29 20 7b 0a hedir") == 0) {.
c9e0: 09 09 09 61 70 70 66 73 5f 63 61 63 68 65 64 69 ...appfs_cachedi
c9f0: 72 20 3d 20 73 74 72 64 75 70 28 61 72 67 76 5b r = strdup(argv[
ca00: 31 5d 29 3b 0a 0a 09 09 09 61 72 67 63 20 2d 3d 1]);.....argc -=
ca10: 20 32 3b 0a 09 09 09 61 72 67 76 20 2b 3d 20 32 2;....argv += 2
ca20: 3b 0a 09 09 7d 0a 09 7d 0a 0a 09 2f 2a 0a 09 20 ;...}..}.../*..
ca30: 2a 20 53 51 4c 69 74 65 33 20 6d 6f 64 65 2c 20 * SQLite3 mode,
ca40: 66 6f 72 20 72 75 6e 6e 69 6e 67 20 72 61 77 20 for running raw
ca50: 53 51 4c 20 61 67 61 69 6e 73 74 20 74 68 65 20 SQL against the
ca60: 63 61 63 68 65 20 64 61 74 61 62 61 73 65 0a 09 cache database..
ca70: 20 2a 2f 0a 09 69 66 20 28 61 72 67 63 20 3d 3d */..if (argc ==
ca80: 20 32 20 26 26 20 73 74 72 63 6d 70 28 61 72 67 2 && strcmp(arg
ca90: 76 5b 30 5d 2c 20 22 2d 2d 73 71 6c 69 74 65 33 v[0], "--sqlite3
caa0: 22 29 20 3d 3d 20 30 29 20 7b 0a 09 09 72 65 74 ") == 0) {...ret
cab0: 75 72 6e 28 61 70 70 66 73 5f 73 71 6c 69 74 65 urn(appfs_sqlite
cac0: 33 28 61 72 67 76 5b 31 5d 29 29 3b 0a 09 7d 0a 3(argv[1]));..}.
cad0: 0a 09 2f 2a 0a 09 20 2a 20 54 63 6c 20 6d 6f 64 ../*.. * Tcl mod
cae0: 65 2c 20 66 6f 72 20 72 75 6e 6e 69 6e 67 20 72 e, for running r
caf0: 61 77 20 54 63 6c 20 69 6e 20 74 68 65 20 73 61 aw Tcl in the sa
cb00: 6d 65 20 65 6e 76 69 72 6f 6e 6d 65 6e 74 20 41 me environment A
cb10: 70 70 46 53 64 20 77 6f 75 6c 64 0a 09 20 2a 20 ppFSd would.. *
cb20: 72 75 6e 20 63 6f 64 65 2e 0a 09 20 2a 2f 0a 09 run code... */..
cb30: 69 66 20 28 61 72 67 63 20 3d 3d 20 32 20 26 26 if (argc == 2 &&
cb40: 20 73 74 72 63 6d 70 28 61 72 67 76 5b 30 5d 2c strcmp(argv[0],
cb50: 20 22 2d 2d 74 63 6c 22 29 20 3d 3d 20 30 29 20 "--tcl") == 0)
cb60: 7b 0a 09 09 72 65 74 75 72 6e 28 61 70 70 66 73 {...return(appfs
cb70: 5f 74 63 6c 28 61 72 67 76 5b 31 5d 29 29 3b 0a _tcl(argv[1]));.
cb80: 09 7d 0a 0a 09 2f 2a 0a 09 20 2a 20 52 65 67 69 .}.../*.. * Regi
cb90: 73 74 65 72 20 61 20 73 69 67 6e 61 6c 20 68 61 ster a signal ha
cba0: 6e 64 6c 65 72 20 66 6f 72 20 68 6f 74 2d 72 65 ndler for hot-re
cbb0: 73 74 61 72 74 20 72 65 71 75 65 73 74 73 0a 09 start requests..
cbc0: 20 2a 2f 0a 09 73 69 67 6e 61 6c 5f 72 65 74 20 */..signal_ret
cbd0: 3d 20 73 69 67 6e 61 6c 28 53 49 47 48 55 50 2c = signal(SIGHUP,
cbe0: 20 61 70 70 66 73 5f 73 69 67 6e 61 6c 5f 68 61 appfs_signal_ha
cbf0: 6e 64 6c 65 72 29 3b 0a 09 69 66 20 28 73 69 67 ndler);..if (sig
cc00: 6e 61 6c 5f 72 65 74 20 3d 3d 20 53 49 47 5f 45 nal_ret == SIG_E
cc10: 52 52 29 20 7b 0a 09 09 66 70 72 69 6e 74 66 28 RR) {...fprintf(
cc20: 73 74 64 65 72 72 2c 20 22 55 6e 61 62 6c 65 20 stderr, "Unable
cc30: 74 6f 20 69 6e 73 74 61 6c 6c 20 73 69 67 6e 61 to install signa
cc40: 6c 20 68 61 6e 64 6c 65 72 20 66 6f 72 20 68 6f l handler for ho
cc50: 74 2d 72 65 73 74 61 72 74 5c 6e 22 29 3b 0a 09 t-restart\n");..
cc60: 09 66 70 72 69 6e 74 66 28 73 74 64 65 72 72 2c .fprintf(stderr,
cc70: 20 22 48 6f 74 2d 72 65 73 74 61 72 74 20 77 69 "Hot-restart wi
cc80: 6c 6c 20 6e 6f 74 20 62 65 20 61 76 61 69 6c 61 ll not be availa
cc90: 62 6c 65 2e 5c 6e 22 29 3b 0a 09 7d 0a 0a 09 2f ble.\n");..}.../
cca0: 2a 0a 09 20 2a 20 50 61 72 73 65 20 63 6f 6d 6d *.. * Parse comm
ccb0: 61 6e 64 20 6c 69 6e 65 20 61 72 67 75 6d 65 6e and line argumen
ccc0: 74 73 0a 09 20 2a 2f 0a 09 2f 2a 2a 0a 09 20 2a ts.. */../**.. *
ccd0: 2a 20 52 65 73 74 6f 72 65 20 61 72 67 63 2f 61 * Restore argc/a
cce0: 72 67 76 20 74 6f 20 6f 72 69 67 69 6e 61 6c 20 rgv to original
ccf0: 76 61 6c 75 65 73 2c 20 72 65 70 6c 61 63 69 6e values, replacin
cd00: 67 20 61 72 67 76 5b 30 5d 20 69 6e 20 63 61 73 g argv[0] in cas
cd10: 65 0a 09 20 2a 2a 20 69 74 20 77 61 73 20 6d 6f e.. ** it was mo
cd20: 69 66 69 65 64 20 62 79 20 2d 2d 63 61 63 68 65 ified by --cache
cd30: 64 69 72 20 6f 70 74 69 6f 6e 2e 0a 09 20 2a 2a dir option... **
cd40: 2f 0a 09 61 72 67 63 2b 2b 3b 0a 09 61 72 67 76 /..argc++;..argv
cd50: 2d 2d 3b 0a 09 61 72 67 76 5b 30 5d 20 3d 20 61 --;..argv[0] = a
cd60: 72 67 76 30 3b 0a 0a 09 2f 2a 2a 0a 09 20 2a 2a rgv0;.../**.. **
cd70: 20 50 65 72 66 6f 72 6d 20 74 68 65 20 61 72 67 Perform the arg
cd80: 75 6d 65 6e 74 20 70 61 72 73 69 6e 67 0a 09 20 ument parsing..
cd90: 2a 2a 2f 0a 09 61 6f 70 5f 72 65 74 20 3d 20 61 **/..aop_ret = a
cda0: 70 70 66 73 5f 6f 70 74 5f 70 61 72 73 65 28 61 ppfs_opt_parse(a
cdb0: 72 67 63 2c 20 61 72 67 76 2c 20 26 61 72 67 73 rgc, argv, &args
cdc0: 29 3b 0a 09 69 66 20 28 61 6f 70 5f 72 65 74 20 );..if (aop_ret
cdd0: 21 3d 20 30 29 20 7b 0a 09 09 69 66 20 28 61 6f != 0) {...if (ao
cde0: 70 5f 72 65 74 20 3c 20 30 29 20 7b 0a 09 09 09 p_ret < 0) {....
cdf0: 72 65 74 75 72 6e 28 30 29 3b 0a 09 09 7d 0a 0a return(0);...}..
ce00: 09 09 72 65 74 75 72 6e 28 61 6f 70 5f 72 65 74 ..return(aop_ret
ce10: 29 3b 0a 09 7d 0a 0a 09 2f 2a 0a 09 20 2a 20 43 );..}.../*.. * C
ce20: 72 65 61 74 65 20 61 20 54 63 6c 20 69 6e 74 65 reate a Tcl inte
ce30: 72 70 72 65 74 65 72 20 6a 75 73 74 20 74 6f 20 rpreter just to
ce40: 76 65 72 69 66 79 20 74 68 61 74 20 74 68 69 6e verify that thin
ce50: 67 73 20 61 72 65 20 69 6e 20 77 6f 72 6b 69 6e gs are in workin
ce60: 67 20 0a 09 20 2a 20 6f 72 64 65 72 20 62 65 66 g .. * order bef
ce70: 6f 72 65 20 77 65 20 62 65 63 6f 6d 65 20 61 20 ore we become a
ce80: 64 61 65 6d 6f 6e 2e 0a 09 20 2a 2f 0a 09 74 65 daemon... */..te
ce90: 73 74 5f 69 6e 74 65 72 70 20 3d 20 61 70 70 66 st_interp = appf
cea0: 73 5f 63 72 65 61 74 65 5f 54 63 6c 49 6e 74 65 s_create_TclInte
ceb0: 72 70 28 26 74 65 73 74 5f 69 6e 74 65 72 70 5f rp(&test_interp_
cec0: 65 72 72 6f 72 29 3b 0a 09 69 66 20 28 74 65 73 error);..if (tes
ced0: 74 5f 69 6e 74 65 72 70 20 3d 3d 20 4e 55 4c 4c t_interp == NULL
cee0: 29 20 7b 0a 09 09 69 66 20 28 74 65 73 74 5f 69 ) {...if (test_i
cef0: 6e 74 65 72 70 5f 65 72 72 6f 72 20 3d 3d 20 4e nterp_error == N
cf00: 55 4c 4c 29 20 7b 0a 09 09 09 74 65 73 74 5f 69 ULL) {....test_i
cf10: 6e 74 65 72 70 5f 65 72 72 6f 72 20 3d 20 22 55 nterp_error = "U
cf20: 6e 6b 6e 6f 77 6e 20 65 72 72 6f 72 22 3b 0a 09 nknown error";..
cf30: 09 7d 0a 0a 09 09 66 70 72 69 6e 74 66 28 73 74 .}....fprintf(st
cf40: 64 65 72 72 2c 20 22 55 6e 61 62 6c 65 20 74 6f derr, "Unable to
cf50: 20 69 6e 69 74 69 61 6c 69 7a 65 20 54 63 6c 20 initialize Tcl
cf60: 69 6e 74 65 72 70 72 65 74 65 72 20 66 6f 72 20 interpreter for
cf70: 41 70 70 46 53 64 3a 5c 6e 22 29 3b 0a 09 09 66 AppFSd:\n");...f
cf80: 70 72 69 6e 74 66 28 73 74 64 65 72 72 2c 20 22 printf(stderr, "
cf90: 25 73 5c 6e 22 2c 20 74 65 73 74 5f 69 6e 74 65 %s\n", test_inte
cfa0: 72 70 5f 65 72 72 6f 72 29 3b 0a 0a 09 09 72 65 rp_error);....re
cfb0: 74 75 72 6e 28 31 29 3b 0a 09 7d 0a 0a 09 54 63 turn(1);..}...Tc
cfc0: 6c 5f 44 65 6c 65 74 65 49 6e 74 65 72 70 28 74 l_DeleteInterp(t
cfd0: 65 73 74 5f 69 6e 74 65 72 70 29 3b 0a 0a 09 69 est_interp);...i
cfe0: 66 20 28 61 70 70 66 73 5f 74 68 72 65 61 64 65 f (appfs_threade
cff0: 64 5f 74 63 6c 29 20 7b 0a 09 09 54 63 6c 5f 46 d_tcl) {...Tcl_F
d000: 69 6e 61 6c 69 7a 65 4e 6f 74 69 66 69 65 72 28 inalizeNotifier(
d010: 4e 55 4c 4c 29 3b 0a 09 7d 0a 0a 09 2f 2a 0a 09 NULL);..}.../*..
d020: 20 2a 20 45 6e 74 65 72 20 74 68 65 20 46 55 53 * Enter the FUS
d030: 45 20 6d 61 69 6e 20 6c 6f 6f 70 20 2d 2d 20 74 E main loop -- t
d040: 68 69 73 20 77 69 6c 6c 20 70 72 6f 63 65 73 73 his will process
d050: 20 61 6e 79 20 61 72 67 75 6d 65 6e 74 73 0a 09 any arguments..
d060: 20 2a 20 61 6e 64 20 73 74 61 72 74 20 73 65 72 * and start ser
d070: 76 69 63 69 6e 67 20 72 65 71 75 65 73 74 73 2e vicing requests.
d080: 0a 09 20 2a 2f 0a 09 61 70 70 66 73 5f 66 75 73 .. */..appfs_fus
d090: 65 5f 73 74 61 72 74 65 64 20 3d 20 31 3b 0a 09 e_started = 1;..
d0a0: 72 65 74 75 72 6e 28 66 75 73 65 5f 6d 61 69 6e return(fuse_main
d0b0: 28 61 72 67 73 2e 61 72 67 63 2c 20 61 72 67 73 (args.argc, args
d0c0: 2e 61 72 67 76 2c 20 26 61 70 70 66 73 5f 6f 70 .argv, &appfs_op
d0d0: 65 72 61 74 69 6f 6e 73 2c 20 4e 55 4c 4c 29 29 erations, NULL))
d0e0: 3b 0a 7d 0a ;.}.