Hex Artifact Content

Artifact f0663dcc45e2ae3e685d6773b2c6c37f29ade31b:


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 2c 20 32 30 31 35 20 20  (c) 2014, 2015  
0020: 52 6f 79 20 4b 65 65 6e 65 0a 20 2a 0a 20 2a 20  Roy Keene. *. * 
0030: 50 65 72 6d 69 73 73 69 6f 6e 20 69 73 20 68 65  Permission is he
0040: 72 65 62 79 20 67 72 61 6e 74 65 64 2c 20 66 72  reby granted, fr
0050: 65 65 20 6f 66 20 63 68 61 72 67 65 2c 20 74 6f  ee of charge, to
0060: 20 61 6e 79 20 70 65 72 73 6f 6e 20 6f 62 74 61   any person obta
0070: 69 6e 69 6e 67 20 61 20 63 6f 70 79 0a 20 2a 20  ining a copy. * 
0080: 6f 66 20 74 68 69 73 20 73 6f 66 74 77 61 72 65  of this software
0090: 20 61 6e 64 20 61 73 73 6f 63 69 61 74 65 64 20   and associated 
00a0: 64 6f 63 75 6d 65 6e 74 61 74 69 6f 6e 20 66 69  documentation fi
00b0: 6c 65 73 20 28 74 68 65 20 22 53 6f 66 74 77 61  les (the "Softwa
00c0: 72 65 22 29 2c 20 74 6f 20 64 65 61 6c 0a 20 2a  re"), to deal. *
00d0: 20 69 6e 20 74 68 65 20 53 6f 66 74 77 61 72 65   in the Software
00e0: 20 77 69 74 68 6f 75 74 20 72 65 73 74 72 69 63   without restric
00f0: 74 69 6f 6e 2c 20 69 6e 63 6c 75 64 69 6e 67 20  tion, including 
0100: 77 69 74 68 6f 75 74 20 6c 69 6d 69 74 61 74 69  without limitati
0110: 6f 6e 20 74 68 65 20 72 69 67 68 74 73 0a 20 2a  on the rights. *
0120: 20 74 6f 20 75 73 65 2c 20 63 6f 70 79 2c 20 6d   to use, copy, m
0130: 6f 64 69 66 79 2c 20 6d 65 72 67 65 2c 20 70 75  odify, merge, pu
0140: 62 6c 69 73 68 2c 20 64 69 73 74 72 69 62 75 74  blish, distribut
0150: 65 2c 20 73 75 62 6c 69 63 65 6e 73 65 2c 20 61  e, sublicense, a
0160: 6e 64 2f 6f 72 20 73 65 6c 6c 0a 20 2a 20 63 6f  nd/or sell. * co
0170: 70 69 65 73 20 6f 66 20 74 68 65 20 53 6f 66 74  pies of the Soft
0180: 77 61 72 65 2c 20 61 6e 64 20 74 6f 20 70 65 72  ware, and to per
0190: 6d 69 74 20 70 65 72 73 6f 6e 73 20 74 6f 20 77  mit persons to w
01a0: 68 6f 6d 20 74 68 65 20 53 6f 66 74 77 61 72 65  hom the Software
01b0: 20 69 73 0a 20 2a 20 66 75 72 6e 69 73 68 65 64   is. * furnished
01c0: 20 74 6f 20 64 6f 20 73 6f 2c 20 73 75 62 6a 65   to do so, subje
01d0: 63 74 20 74 6f 20 74 68 65 20 66 6f 6c 6c 6f 77  ct to the follow
01e0: 69 6e 67 20 63 6f 6e 64 69 74 69 6f 6e 73 3a 0a  ing conditions:.
01f0: 20 2a 0a 20 2a 20 54 68 65 20 61 62 6f 76 65 20   *. * The above 
0200: 63 6f 70 79 72 69 67 68 74 20 6e 6f 74 69 63 65  copyright notice
0210: 20 61 6e 64 20 74 68 69 73 20 70 65 72 6d 69 73   and this permis
0220: 73 69 6f 6e 20 6e 6f 74 69 63 65 20 73 68 61 6c  sion notice shal
0230: 6c 20 62 65 20 69 6e 63 6c 75 64 65 64 20 69 6e  l be included in
0240: 0a 20 2a 20 61 6c 6c 20 63 6f 70 69 65 73 20 6f  . * all copies o
0250: 72 20 73 75 62 73 74 61 6e 74 69 61 6c 20 70 6f  r substantial po
0260: 72 74 69 6f 6e 73 20 6f 66 20 74 68 65 20 53 6f  rtions of the So
0270: 66 74 77 61 72 65 2e 0a 20 2a 0a 20 2a 20 54 48  ftware.. *. * TH
0280: 45 20 53 4f 46 54 57 41 52 45 20 49 53 20 50 52  E SOFTWARE IS PR
0290: 4f 56 49 44 45 44 20 22 41 53 20 49 53 22 2c 20  OVIDED "AS IS", 
02a0: 57 49 54 48 4f 55 54 20 57 41 52 52 41 4e 54 59  WITHOUT WARRANTY
02b0: 20 4f 46 20 41 4e 59 20 4b 49 4e 44 2c 20 45 58   OF ANY KIND, EX
02c0: 50 52 45 53 53 20 4f 52 0a 20 2a 20 49 4d 50 4c  PRESS OR. * IMPL
02d0: 49 45 44 2c 20 49 4e 43 4c 55 44 49 4e 47 20 42  IED, INCLUDING B
02e0: 55 54 20 4e 4f 54 20 4c 49 4d 49 54 45 44 20 54  UT NOT LIMITED T
02f0: 4f 20 54 48 45 20 57 41 52 52 41 4e 54 49 45 53  O THE WARRANTIES
0300: 20 4f 46 20 4d 45 52 43 48 41 4e 54 41 42 49 4c   OF MERCHANTABIL
0310: 49 54 59 2c 0a 20 2a 20 46 49 54 4e 45 53 53 20  ITY,. * FITNESS 
0320: 46 4f 52 20 41 20 50 41 52 54 49 43 55 4c 41 52  FOR A PARTICULAR
0330: 20 50 55 52 50 4f 53 45 20 41 4e 44 20 4e 4f 4e   PURPOSE AND NON
0340: 49 4e 46 52 49 4e 47 45 4d 45 4e 54 2e 20 49 4e  INFRINGEMENT. IN
0350: 20 4e 4f 20 45 56 45 4e 54 20 53 48 41 4c 4c 20   NO EVENT SHALL 
0360: 54 48 45 0a 20 2a 20 41 55 54 48 4f 52 53 20 4f  THE. * AUTHORS O
0370: 52 20 43 4f 50 59 52 49 47 48 54 20 48 4f 4c 44  R COPYRIGHT HOLD
0380: 45 52 53 20 42 45 20 4c 49 41 42 4c 45 20 46 4f  ERS BE LIABLE FO
0390: 52 20 41 4e 59 20 43 4c 41 49 4d 2c 20 44 41 4d  R ANY CLAIM, DAM
03a0: 41 47 45 53 20 4f 52 20 4f 54 48 45 52 0a 20 2a  AGES OR OTHER. *
03b0: 20 4c 49 41 42 49 4c 49 54 59 2c 20 57 48 45 54   LIABILITY, WHET
03c0: 48 45 52 20 49 4e 20 41 4e 20 41 43 54 49 4f 4e  HER IN AN ACTION
03d0: 20 4f 46 20 43 4f 4e 54 52 41 43 54 2c 20 54 4f   OF CONTRACT, TO
03e0: 52 54 20 4f 52 20 4f 54 48 45 52 57 49 53 45 2c  RT OR OTHERWISE,
03f0: 20 41 52 49 53 49 4e 47 20 46 52 4f 4d 2c 0a 20   ARISING FROM,. 
0400: 2a 20 4f 55 54 20 4f 46 20 4f 52 20 49 4e 20 43  * OUT OF OR IN C
0410: 4f 4e 4e 45 43 54 49 4f 4e 20 57 49 54 48 20 54  ONNECTION WITH T
0420: 48 45 20 53 4f 46 54 57 41 52 45 20 4f 52 20 54  HE SOFTWARE OR T
0430: 48 45 20 55 53 45 20 4f 52 20 4f 54 48 45 52 20  HE USE OR OTHER 
0440: 44 45 41 4c 49 4e 47 53 20 49 4e 0a 20 2a 20 54  DEALINGS IN. * T
0450: 48 45 20 53 4f 46 54 57 41 52 45 2e 0a 20 2a 2f  HE SOFTWARE.. */
0460: 0a 23 64 65 66 69 6e 65 20 46 55 53 45 5f 55 53  .#define FUSE_US
0470: 45 5f 56 45 52 53 49 4f 4e 20 32 36 0a 0a 23 69  E_VERSION 26..#i
0480: 6e 63 6c 75 64 65 20 3c 73 79 73 2f 72 65 73 6f  nclude <sys/reso
0490: 75 72 63 65 2e 68 3e 20 20 0a 23 69 6e 63 6c 75  urce.h>  .#inclu
04a0: 64 65 20 3c 73 79 73 2f 66 73 75 69 64 2e 68 3e  de <sys/fsuid.h>
04b0: 0a 23 69 6e 63 6c 75 64 65 20 3c 73 79 73 2f 74  .#include <sys/t
04c0: 79 70 65 73 2e 68 3e 0a 23 69 6e 63 6c 75 64 65  ypes.h>.#include
04d0: 20 3c 73 79 73 2f 74 69 6d 65 2e 68 3e 0a 23 69   <sys/time.h>.#i
04e0: 6e 63 6c 75 64 65 20 3c 70 74 68 72 65 61 64 2e  nclude <pthread.
04f0: 68 3e 0a 23 69 6e 63 6c 75 64 65 20 3c 73 69 67  h>.#include <sig
0500: 6e 61 6c 2e 68 3e 0a 23 69 6e 63 6c 75 64 65 20  nal.h>.#include 
0510: 3c 6c 69 6d 69 74 73 2e 68 3e 0a 23 69 6e 63 6c  <limits.h>.#incl
0520: 75 64 65 20 3c 73 74 72 69 6e 67 2e 68 3e 0a 23  ude <string.h>.#
0530: 69 6e 63 6c 75 64 65 20 3c 73 74 64 61 72 67 2e  include <stdarg.
0540: 68 3e 0a 23 69 6e 63 6c 75 64 65 20 3c 73 74 64  h>.#include <std
0550: 6c 69 62 2e 68 3e 0a 23 69 6e 63 6c 75 64 65 20  lib.h>.#include 
0560: 3c 75 6e 69 73 74 64 2e 68 3e 0a 23 69 6e 63 6c  <unistd.h>.#incl
0570: 75 64 65 20 3c 65 72 72 6e 6f 2e 68 3e 0a 23 69  ude <errno.h>.#i
0580: 6e 63 6c 75 64 65 20 3c 66 63 6e 74 6c 2e 68 3e  nclude <fcntl.h>
0590: 0a 23 69 6e 63 6c 75 64 65 20 3c 73 74 64 69 6f  .#include <stdio
05a0: 2e 68 3e 0a 23 69 6e 63 6c 75 64 65 20 3c 66 75  .h>.#include <fu
05b0: 73 65 2e 68 3e 0a 23 69 6e 63 6c 75 64 65 20 3c  se.h>.#include <
05c0: 70 77 64 2e 68 3e 0a 23 69 6e 63 6c 75 64 65 20  pwd.h>.#include 
05d0: 3c 74 63 6c 2e 68 3e 0a 0a 2f 2a 0a 20 2a 20 44  <tcl.h>../*. * D
05e0: 65 66 61 75 6c 74 20 63 61 63 68 65 20 64 69 72  efault cache dir
05f0: 65 63 74 6f 72 79 0a 20 2a 2f 0a 23 69 66 6e 64  ectory. */.#ifnd
0600: 65 66 20 41 50 50 46 53 5f 43 41 43 48 45 44 49  ef APPFS_CACHEDI
0610: 52 0a 23 64 65 66 69 6e 65 20 41 50 50 46 53 5f  R.#define APPFS_
0620: 43 41 43 48 45 44 49 52 20 22 2f 76 61 72 2f 63  CACHEDIR "/var/c
0630: 61 63 68 65 2f 61 70 70 66 73 22 0a 23 65 6e 64  ache/appfs".#end
0640: 69 66 0a 0a 2f 2a 20 44 65 62 75 67 67 69 6e 67  if../* Debugging
0650: 20 6d 61 63 72 6f 73 20 2a 2f 0a 23 69 66 64 65   macros */.#ifde
0660: 66 20 44 45 42 55 47 0a 69 6e 74 20 61 70 70 66  f DEBUG.int appf
0670: 73 5f 64 65 62 75 67 5f 66 64 20 3d 20 53 54 44  s_debug_fd = STD
0680: 45 52 52 5f 46 49 4c 45 4e 4f 3b 0a 23 64 65 66  ERR_FILENO;.#def
0690: 69 6e 65 20 41 50 50 46 53 5f 44 45 42 55 47 28  ine APPFS_DEBUG(
06a0: 78 2e 2e 2e 29 20 7b 20 5c 0a 09 63 68 61 72 20  x...) { \..char 
06b0: 62 75 66 5b 38 31 39 32 5d 3b 20 5c 0a 09 69 6e  buf[8192]; \..in
06c0: 74 20 62 75 66 6f 66 66 20 3d 20 30 3b 20 5c 0a  t bufoff = 0; \.
06d0: 09 69 66 20 28 61 70 70 66 73 5f 64 65 62 75 67  .if (appfs_debug
06e0: 5f 66 64 20 3d 3d 20 2d 31 29 20 7b 20 5c 0a 09  _fd == -1) { \..
06f0: 09 61 70 70 66 73 5f 64 65 62 75 67 5f 66 64 20  .appfs_debug_fd 
0700: 3d 20 6f 70 65 6e 28 22 2f 74 6d 70 2f 61 70 70  = open("/tmp/app
0710: 66 73 64 2e 6c 6f 67 22 2c 20 4f 5f 57 52 4f 4e  fsd.log", O_WRON
0720: 4c 59 20 7c 20 4f 5f 41 50 50 45 4e 44 20 7c 20  LY | O_APPEND | 
0730: 4f 5f 43 52 45 41 54 2c 20 30 36 30 30 29 3b 20  O_CREAT, 0600); 
0740: 5c 0a 09 7d 3b 20 5c 0a 09 62 75 66 6f 66 66 20  \..}; \..bufoff 
0750: 3d 20 73 6e 70 72 69 6e 74 66 28 62 75 66 2c 20  = snprintf(buf, 
0760: 73 69 7a 65 6f 66 28 62 75 66 29 2c 20 22 5b 64  sizeof(buf), "[d
0770: 65 62 75 67 5d 20 5b 74 3d 25 6c 6c 78 5d 20 25  ebug] [t=%llx] %
0780: 73 3a 25 69 3a 25 73 3a 20 22 2c 20 28 75 6e 73  s:%i:%s: ", (uns
0790: 69 67 6e 65 64 20 6c 6f 6e 67 20 6c 6f 6e 67 29  igned long long)
07a0: 20 70 74 68 72 65 61 64 5f 73 65 6c 66 28 29 2c   pthread_self(),
07b0: 20 5f 5f 46 49 4c 45 5f 5f 2c 20 5f 5f 4c 49 4e   __FILE__, __LIN
07c0: 45 5f 5f 2c 20 5f 5f 66 75 6e 63 5f 5f 29 3b 20  E__, __func__); 
07d0: 5c 0a 09 69 66 20 28 62 75 66 6f 66 66 20 3c 20  \..if (bufoff < 
07e0: 73 69 7a 65 6f 66 28 62 75 66 29 29 20 7b 20 5c  sizeof(buf)) { \
07f0: 0a 09 09 62 75 66 6f 66 66 20 2b 3d 20 73 6e 70  ...bufoff += snp
0800: 72 69 6e 74 66 28 62 75 66 20 2b 20 62 75 66 6f  rintf(buf + bufo
0810: 66 66 2c 20 73 69 7a 65 6f 66 28 62 75 66 29 20  ff, sizeof(buf) 
0820: 2d 20 62 75 66 6f 66 66 2c 20 78 29 3b 20 5c 0a  - bufoff, x); \.
0830: 09 7d 3b 20 5c 0a 09 69 66 20 28 62 75 66 6f 66  .}; \..if (bufof
0840: 66 20 3c 20 73 69 7a 65 6f 66 28 62 75 66 29 29  f < sizeof(buf))
0850: 20 7b 20 5c 0a 09 09 62 75 66 6f 66 66 20 2b 3d   { \...bufoff +=
0860: 20 73 6e 70 72 69 6e 74 66 28 62 75 66 20 2b 20   snprintf(buf + 
0870: 62 75 66 6f 66 66 2c 20 73 69 7a 65 6f 66 28 62  bufoff, sizeof(b
0880: 75 66 29 20 2d 20 62 75 66 6f 66 66 2c 20 22 5c  uf) - bufoff, "\
0890: 6e 22 29 3b 5c 0a 09 7d 20 5c 0a 09 69 66 20 28  n");\..} \..if (
08a0: 62 75 66 6f 66 66 20 3e 20 73 69 7a 65 6f 66 28  bufoff > sizeof(
08b0: 62 75 66 29 29 20 7b 20 5c 0a 09 09 62 75 66 6f  buf)) { \...bufo
08c0: 66 66 20 3d 20 73 69 7a 65 6f 66 28 62 75 66 29  ff = sizeof(buf)
08d0: 3b 20 5c 0a 09 7d 3b 20 5c 0a 09 77 72 69 74 65  ; \..}; \..write
08e0: 28 61 70 70 66 73 5f 64 65 62 75 67 5f 66 64 2c  (appfs_debug_fd,
08f0: 20 62 75 66 2c 20 62 75 66 6f 66 66 29 3b 20 5c   buf, bufoff); \
0900: 0a 7d 0a 23 65 6c 73 65 0a 23 64 65 66 69 6e 65  .}.#else.#define
0910: 20 41 50 50 46 53 5f 44 45 42 55 47 28 78 2e 2e   APPFS_DEBUG(x..
0920: 2e 29 20 2f 2a 2a 2f 0a 23 65 6e 64 69 66 0a 0a  .) /**/.#endif..
0930: 2f 2a 0a 20 2a 20 53 48 41 31 20 54 63 6c 20 50  /*. * SHA1 Tcl P
0940: 61 63 6b 61 67 65 20 69 6e 69 74 69 61 6c 69 7a  ackage initializ
0950: 65 72 2c 20 66 72 6f 6d 20 73 68 61 31 2e 6f 0a  er, from sha1.o.
0960: 20 2a 2f 0a 69 6e 74 20 53 68 61 31 5f 49 6e 69   */.int Sha1_Ini
0970: 74 28 54 63 6c 5f 49 6e 74 65 72 70 20 2a 69 6e  t(Tcl_Interp *in
0980: 74 65 72 70 29 3b 0a 0a 2f 2a 0a 20 2a 20 54 68  terp);../*. * Th
0990: 72 65 61 64 20 53 70 65 63 69 66 69 63 20 44 61  read Specific Da
09a0: 74 61 20 28 54 53 44 29 20 66 6f 72 20 54 63 6c  ta (TSD) for Tcl
09b0: 20 49 6e 74 65 72 70 72 65 74 65 72 20 66 6f 72   Interpreter for
09c0: 20 74 68 65 20 63 75 72 72 65 6e 74 20 74 68 72   the current thr
09d0: 65 61 64 0a 20 2a 2f 0a 73 74 61 74 69 63 20 70  ead. */.static p
09e0: 74 68 72 65 61 64 5f 6b 65 79 5f 74 20 69 6e 74  thread_key_t int
09f0: 65 72 70 4b 65 79 3b 0a 0a 2f 2a 0a 20 2a 20 47  erpKey;../*. * G
0a00: 6c 6f 62 61 6c 20 76 61 72 69 61 62 6c 65 73 2c  lobal variables,
0a10: 20 6e 65 65 64 65 64 20 66 6f 72 20 61 6c 6c 20   needed for all 
0a20: 74 68 72 65 61 64 73 20 62 75 74 20 6f 6e 6c 79  threads but only
0a30: 20 69 6e 69 74 69 61 6c 69 7a 65 64 20 62 65 66   initialized bef
0a40: 6f 72 65 20 61 6e 79 0a 20 2a 20 46 55 53 45 20  ore any. * FUSE 
0a50: 74 68 72 65 61 64 73 20 61 72 65 20 63 72 65 61  threads are crea
0a60: 74 65 64 0a 20 2a 2f 0a 63 6f 6e 73 74 20 63 68  ted. */.const ch
0a70: 61 72 20 2a 61 70 70 66 73 5f 63 61 63 68 65 64  ar *appfs_cached
0a80: 69 72 3b 0a 74 69 6d 65 5f 74 20 61 70 70 66 73  ir;.time_t appfs
0a90: 5f 62 6f 6f 74 74 69 6d 65 3b 0a 69 6e 74 20 61  _boottime;.int a
0aa0: 70 70 66 73 5f 66 75 73 65 5f 73 74 61 72 74 65  ppfs_fuse_starte
0ab0: 64 20 3d 20 30 3b 0a 69 6e 74 20 61 70 70 66 73  d = 0;.int appfs
0ac0: 5f 74 68 72 65 61 64 65 64 5f 74 63 6c 3b 0a 0a  _threaded_tcl;..
0ad0: 2f 2a 0a 20 2a 20 47 6c 6f 62 61 6c 20 76 61 72  /*. * Global var
0ae0: 69 61 62 6c 65 73 20 66 6f 72 20 41 70 70 46 53  iables for AppFS
0af0: 20 63 61 63 68 69 6e 67 0a 20 2a 2f 0a 70 74 68   caching. */.pth
0b00: 72 65 61 64 5f 6d 75 74 65 78 5f 74 20 61 70 70  read_mutex_t app
0b10: 66 73 5f 70 61 74 68 5f 69 6e 66 6f 5f 63 61 63  fs_path_info_cac
0b20: 68 65 5f 6d 75 74 65 78 20 3d 20 50 54 48 52 45  he_mutex = PTHRE
0b30: 41 44 5f 4d 55 54 45 58 5f 49 4e 49 54 49 41 4c  AD_MUTEX_INITIAL
0b40: 49 5a 45 52 3b 0a 69 6e 74 20 61 70 70 66 73 5f  IZER;.int appfs_
0b50: 70 61 74 68 5f 69 6e 66 6f 5f 63 61 63 68 65 5f  path_info_cache_
0b60: 73 69 7a 65 20 3d 20 38 32 30 39 3b 0a 73 74 72  size = 8209;.str
0b70: 75 63 74 20 61 70 70 66 73 5f 70 61 74 68 69 6e  uct appfs_pathin
0b80: 66 6f 20 2a 61 70 70 66 73 5f 70 61 74 68 5f 69  fo *appfs_path_i
0b90: 6e 66 6f 5f 63 61 63 68 65 20 3d 20 4e 55 4c 4c  nfo_cache = NULL
0ba0: 3b 0a 0a 23 69 66 6e 64 65 66 20 54 43 4c 5f 54  ;..#ifndef TCL_T
0bb0: 48 52 45 41 44 53 0a 2f 2a 0a 20 2a 20 48 61 6e  HREADS./*. * Han
0bc0: 64 6c 65 20 75 6e 74 68 72 65 61 64 65 64 20 54  dle unthreaded T
0bd0: 63 6c 0a 20 2a 2f 0a 70 74 68 72 65 61 64 5f 6d  cl. */.pthread_m
0be0: 75 74 65 78 5f 74 20 61 70 70 66 73 5f 74 63 6c  utex_t appfs_tcl
0bf0: 5f 62 69 67 5f 67 6c 6f 62 61 6c 5f 6c 6f 63 6b  _big_global_lock
0c00: 20 3d 20 50 54 48 52 45 41 44 5f 4d 55 54 45 58   = PTHREAD_MUTEX
0c10: 5f 49 4e 49 54 49 41 4c 49 5a 45 52 3b 0a 23 64  _INITIALIZER;.#d
0c20: 65 66 69 6e 65 20 61 70 70 66 73 5f 63 61 6c 6c  efine appfs_call
0c30: 5f 6c 69 62 74 63 6c 5f 65 6e 74 65 72 20 70 74  _libtcl_enter pt
0c40: 68 72 65 61 64 5f 6d 75 74 65 78 5f 6c 6f 63 6b  hread_mutex_lock
0c50: 28 26 61 70 70 66 73 5f 74 63 6c 5f 62 69 67 5f  (&appfs_tcl_big_
0c60: 67 6c 6f 62 61 6c 5f 6c 6f 63 6b 29 3b 0a 23 64  global_lock);.#d
0c70: 65 66 69 6e 65 20 61 70 70 66 73 5f 63 61 6c 6c  efine appfs_call
0c80: 5f 6c 69 62 74 63 6c 5f 65 78 69 74 20 70 74 68  _libtcl_exit pth
0c90: 72 65 61 64 5f 6d 75 74 65 78 5f 75 6e 6c 6f 63  read_mutex_unloc
0ca0: 6b 28 26 61 70 70 66 73 5f 74 63 6c 5f 62 69 67  k(&appfs_tcl_big
0cb0: 5f 67 6c 6f 62 61 6c 5f 6c 6f 63 6b 29 3b 0a 23  _global_lock);.#
0cc0: 65 6c 73 65 0a 23 64 65 66 69 6e 65 20 61 70 70  else.#define app
0cd0: 66 73 5f 63 61 6c 6c 5f 6c 69 62 74 63 6c 5f 65  fs_call_libtcl_e
0ce0: 6e 74 65 72 20 2f 2a 2a 2f 0a 23 64 65 66 69 6e  nter /**/.#defin
0cf0: 65 20 61 70 70 66 73 5f 63 61 6c 6c 5f 6c 69 62  e appfs_call_lib
0d00: 74 63 6c 5f 65 78 69 74 20 2f 2a 2a 2f 0a 23 65  tcl_exit /**/.#e
0d10: 6e 64 69 66 0a 23 64 65 66 69 6e 65 20 61 70 70  ndif.#define app
0d20: 66 73 5f 63 61 6c 6c 5f 6c 69 62 74 63 6c 28 78  fs_call_libtcl(x
0d30: 2e 2e 2e 29 20 61 70 70 66 73 5f 63 61 6c 6c 5f  ...) appfs_call_
0d40: 6c 69 62 74 63 6c 5f 65 6e 74 65 72 20 78 20 61  libtcl_enter x a
0d50: 70 70 66 73 5f 63 61 6c 6c 5f 6c 69 62 74 63 6c  ppfs_call_libtcl
0d60: 5f 65 78 69 74 0a 0a 2f 2a 0a 20 2a 20 47 6c 6f  _exit../*. * Glo
0d70: 62 61 6c 20 76 61 72 69 61 62 6c 65 73 20 66 6f  bal variables fo
0d80: 72 20 41 70 70 46 53 20 54 63 6c 20 49 6e 74 65  r AppFS Tcl Inte
0d90: 72 70 72 65 74 65 72 20 72 65 73 74 61 72 74 69  rpreter restarti
0da0: 6e 67 0a 20 2a 2f 0a 69 6e 74 20 69 6e 74 65 72  ng. */.int inter
0db0: 70 5f 72 65 73 65 74 5f 6b 65 79 20 3d 20 30 3b  p_reset_key = 0;
0dc0: 0a 0a 2f 2a 0a 20 2a 20 41 70 70 46 53 20 50 61  ../*. * AppFS Pa
0dd0: 74 68 20 54 79 70 65 3a 20 20 44 65 73 63 72 69  th Type:  Descri
0de0: 62 65 73 20 74 68 65 20 74 79 70 65 20 6f 66 20  bes the type of 
0df0: 70 61 74 68 20 61 20 67 69 76 65 6e 20 66 69 6c  path a given fil
0e00: 65 20 69 73 0a 20 2a 2f 0a 74 79 70 65 64 65 66  e is. */.typedef
0e10: 20 65 6e 75 6d 20 7b 0a 09 41 50 50 46 53 5f 50   enum {..APPFS_P
0e20: 41 54 48 54 59 50 45 5f 49 4e 56 41 4c 49 44 2c  ATHTYPE_INVALID,
0e30: 0a 09 41 50 50 46 53 5f 50 41 54 48 54 59 50 45  ..APPFS_PATHTYPE
0e40: 5f 44 4f 45 53 5f 4e 4f 54 5f 45 58 49 53 54 2c  _DOES_NOT_EXIST,
0e50: 0a 09 41 50 50 46 53 5f 50 41 54 48 54 59 50 45  ..APPFS_PATHTYPE
0e60: 5f 46 49 4c 45 2c 0a 09 41 50 50 46 53 5f 50 41  _FILE,..APPFS_PA
0e70: 54 48 54 59 50 45 5f 44 49 52 45 43 54 4f 52 59  THTYPE_DIRECTORY
0e80: 2c 0a 09 41 50 50 46 53 5f 50 41 54 48 54 59 50  ,..APPFS_PATHTYP
0e90: 45 5f 53 59 4d 4c 49 4e 4b 2c 0a 09 41 50 50 46  E_SYMLINK,..APPF
0ea0: 53 5f 50 41 54 48 54 59 50 45 5f 53 4f 43 4b 45  S_PATHTYPE_SOCKE
0eb0: 54 2c 0a 09 41 50 50 46 53 5f 50 41 54 48 54 59  T,..APPFS_PATHTY
0ec0: 50 45 5f 46 49 46 4f 2c 0a 7d 20 61 70 70 66 73  PE_FIFO,.} appfs
0ed0: 5f 70 61 74 68 74 79 70 65 5f 74 3b 0a 0a 2f 2a  _pathtype_t;../*
0ee0: 0a 20 2a 20 41 70 70 46 53 20 50 61 74 68 20 49  . * AppFS Path I
0ef0: 6e 66 6f 72 6d 61 74 69 6f 6e 3a 0a 20 2a 20 20  nformation:. *  
0f00: 20 20 20 20 20 20 20 43 6f 6d 70 6c 65 74 65 6c         Completel
0f10: 79 20 64 65 73 63 72 69 62 65 73 20 61 20 73 70  y describes a sp
0f20: 65 63 69 66 69 63 20 70 61 74 68 2c 20 68 6f 77  ecific path, how
0f30: 20 69 74 20 73 68 6f 75 6c 64 20 62 65 20 72 65   it should be re
0f40: 74 75 72 6e 65 64 20 74 6f 0a 20 2a 20 20 20 20  turned to. *    
0f50: 20 20 20 20 20 74 6f 20 74 68 65 20 6b 65 72 6e       to the kern
0f60: 65 6c 0a 20 2a 2f 0a 73 74 72 75 63 74 20 61 70  el. */.struct ap
0f70: 70 66 73 5f 70 61 74 68 69 6e 66 6f 20 7b 0a 09  pfs_pathinfo {..
0f80: 61 70 70 66 73 5f 70 61 74 68 74 79 70 65 5f 74  appfs_pathtype_t
0f90: 20 74 79 70 65 3b 0a 09 74 69 6d 65 5f 74 20 74   type;..time_t t
0fa0: 69 6d 65 3b 0a 09 63 68 61 72 20 68 6f 73 74 6e  ime;..char hostn
0fb0: 61 6d 65 5b 32 35 36 5d 3b 0a 09 69 6e 74 20 70  ame[256];..int p
0fc0: 61 63 6b 61 67 65 64 3b 0a 09 75 6e 73 69 67 6e  ackaged;..unsign
0fd0: 65 64 20 6c 6f 6e 67 20 6c 6f 6e 67 20 69 6e 6f  ed long long ino
0fe0: 64 65 3b 0a 09 75 6e 69 6f 6e 20 7b 0a 09 09 73  de;..union {...s
0ff0: 74 72 75 63 74 20 7b 0a 09 09 09 69 6e 74 20 63  truct {....int c
1000: 68 69 6c 64 63 6f 75 6e 74 3b 0a 09 09 7d 20 64  hildcount;...} d
1010: 69 72 3b 0a 09 09 73 74 72 75 63 74 20 7b 0a 09  ir;...struct {..
1020: 09 09 69 6e 74 20 65 78 65 63 75 74 61 62 6c 65  ..int executable
1030: 3b 0a 09 09 09 69 6e 74 20 73 75 69 64 52 6f 6f  ;....int suidRoo
1040: 74 3b 0a 09 09 09 69 6e 74 20 77 6f 72 6c 64 61  t;....int worlda
1050: 63 63 65 73 73 69 62 6c 65 3b 0a 09 09 09 6f 66  ccessible;....of
1060: 66 5f 74 20 73 69 7a 65 3b 0a 09 09 7d 20 66 69  f_t size;...} fi
1070: 6c 65 3b 0a 09 09 73 74 72 75 63 74 20 7b 0a 09  le;...struct {..
1080: 09 09 6f 66 66 5f 74 20 73 69 7a 65 3b 0a 09 09  ..off_t size;...
1090: 09 63 68 61 72 20 73 6f 75 72 63 65 5b 32 35 36  .char source[256
10a0: 5d 3b 0a 09 09 7d 20 73 79 6d 6c 69 6e 6b 3b 0a  ];...} symlink;.
10b0: 09 7d 20 74 79 70 65 69 6e 66 6f 3b 0a 0a 09 2f  .} typeinfo;.../
10c0: 2a 20 41 74 74 72 69 62 75 74 65 73 20 75 73 65  * Attributes use
10d0: 64 20 6f 6e 6c 79 20 66 6f 72 20 63 61 63 68 69  d only for cachi
10e0: 6e 67 20 65 6e 74 72 69 65 73 20 2a 2f 0a 09 63  ng entries */..c
10f0: 68 61 72 20 2a 5f 63 61 63 68 65 5f 70 61 74 68  har *_cache_path
1100: 3b 0a 09 75 69 64 5f 74 20 5f 63 61 63 68 65 5f  ;..uid_t _cache_
1110: 75 69 64 3b 0a 7d 3b 0a 0a 2f 2a 0a 20 2a 20 43  uid;.};../*. * C
1120: 72 65 61 74 65 20 61 20 6e 65 77 20 54 63 6c 20  reate a new Tcl 
1130: 69 6e 74 65 72 70 72 65 74 65 72 20 61 6e 64 20  interpreter and 
1140: 63 6f 6d 70 6c 65 74 65 6c 79 20 69 6e 69 74 69  completely initi
1150: 61 6c 69 7a 65 20 69 74 0a 20 2a 2f 0a 73 74 61  alize it. */.sta
1160: 74 69 63 20 54 63 6c 5f 49 6e 74 65 72 70 20 2a  tic Tcl_Interp *
1170: 61 70 70 66 73 5f 63 72 65 61 74 65 5f 54 63 6c  appfs_create_Tcl
1180: 49 6e 74 65 72 70 28 63 68 61 72 20 2a 2a 65 72  Interp(char **er
1190: 72 6f 72 5f 73 74 72 69 6e 67 29 20 7b 0a 09 54  ror_string) {..T
11a0: 63 6c 5f 49 6e 74 65 72 70 20 2a 69 6e 74 65 72  cl_Interp *inter
11b0: 70 3b 0a 09 69 6e 74 20 74 63 6c 5f 72 65 74 3b  p;..int tcl_ret;
11c0: 0a 09 63 6f 6e 73 74 20 63 68 61 72 20 2a 74 63  ..const char *tc
11d0: 6c 5f 73 65 74 76 61 72 5f 72 65 74 3b 0a 0a 09  l_setvar_ret;...
11e0: 41 50 50 46 53 5f 44 45 42 55 47 28 22 43 72 65  APPFS_DEBUG("Cre
11f0: 61 74 69 6e 67 20 6e 65 77 20 54 63 6c 20 69 6e  ating new Tcl in
1200: 74 65 72 70 72 65 74 65 72 20 66 6f 72 20 54 49  terpreter for TI
1210: 44 20 3d 20 30 78 25 6c 6c 78 22 2c 20 28 75 6e  D = 0x%llx", (un
1220: 73 69 67 6e 65 64 20 6c 6f 6e 67 20 6c 6f 6e 67  signed long long
1230: 29 20 70 74 68 72 65 61 64 5f 73 65 6c 66 28 29  ) pthread_self()
1240: 29 3b 0a 0a 09 61 70 70 66 73 5f 63 61 6c 6c 5f  );...appfs_call_
1250: 6c 69 62 74 63 6c 28 0a 09 09 69 6e 74 65 72 70  libtcl(...interp
1260: 20 3d 20 54 63 6c 5f 43 72 65 61 74 65 49 6e 74   = Tcl_CreateInt
1270: 65 72 70 28 29 3b 0a 09 29 0a 09 69 66 20 28 69  erp();..)..if (i
1280: 6e 74 65 72 70 20 3d 3d 20 4e 55 4c 4c 29 20 7b  nterp == NULL) {
1290: 0a 09 09 66 70 72 69 6e 74 66 28 73 74 64 65 72  ...fprintf(stder
12a0: 72 2c 20 22 55 6e 61 62 6c 65 20 74 6f 20 63 72  r, "Unable to cr
12b0: 65 61 74 65 20 54 63 6c 20 49 6e 74 65 72 70 72  eate Tcl Interpr
12c0: 65 74 65 72 2e 20 20 41 62 6f 72 74 69 6e 67 2e  eter.  Aborting.
12d0: 5c 6e 22 29 3b 0a 0a 09 09 69 66 20 28 65 72 72  \n");....if (err
12e0: 6f 72 5f 73 74 72 69 6e 67 29 20 7b 0a 09 09 09  or_string) {....
12f0: 2a 65 72 72 6f 72 5f 73 74 72 69 6e 67 20 3d 20  *error_string = 
1300: 73 74 72 64 75 70 28 22 55 6e 61 62 6c 65 20 74  strdup("Unable t
1310: 6f 20 63 72 65 61 74 65 20 54 63 6c 20 69 6e 74  o create Tcl int
1320: 65 72 70 72 65 74 65 72 2e 22 29 3b 0a 09 09 7d  erpreter.");...}
1330: 0a 0a 09 09 72 65 74 75 72 6e 28 4e 55 4c 4c 29  ....return(NULL)
1340: 3b 0a 09 7d 0a 0a 09 61 70 70 66 73 5f 63 61 6c  ;..}...appfs_cal
1350: 6c 5f 6c 69 62 74 63 6c 28 54 63 6c 5f 50 72 65  l_libtcl(Tcl_Pre
1360: 73 65 72 76 65 28 69 6e 74 65 72 70 29 3b 29 0a  serve(interp);).
1370: 0a 09 61 70 70 66 73 5f 63 61 6c 6c 5f 6c 69 62  ..appfs_call_lib
1380: 74 63 6c 28 0a 09 09 74 63 6c 5f 72 65 74 20 3d  tcl(...tcl_ret =
1390: 20 54 63 6c 5f 49 6e 69 74 28 69 6e 74 65 72 70   Tcl_Init(interp
13a0: 29 3b 0a 09 29 0a 09 69 66 20 28 74 63 6c 5f 72  );..)..if (tcl_r
13b0: 65 74 20 21 3d 20 54 43 4c 5f 4f 4b 29 20 7b 0a  et != TCL_OK) {.
13c0: 09 09 66 70 72 69 6e 74 66 28 73 74 64 65 72 72  ..fprintf(stderr
13d0: 2c 20 22 55 6e 61 62 6c 65 20 74 6f 20 69 6e 69  , "Unable to ini
13e0: 74 69 61 6c 69 7a 65 20 54 63 6c 2e 20 20 41 62  tialize Tcl.  Ab
13f0: 6f 72 74 69 6e 67 2e 5c 6e 22 29 3b 0a 09 09 61  orting.\n");...a
1400: 70 70 66 73 5f 63 61 6c 6c 5f 6c 69 62 74 63 6c  ppfs_call_libtcl
1410: 28 0a 09 09 09 66 70 72 69 6e 74 66 28 73 74 64  (....fprintf(std
1420: 65 72 72 2c 20 22 54 63 6c 20 45 72 72 6f 72 20  err, "Tcl Error 
1430: 69 73 3a 20 25 73 5c 6e 22 2c 20 54 63 6c 5f 47  is: %s\n", Tcl_G
1440: 65 74 53 74 72 69 6e 67 52 65 73 75 6c 74 28 69  etStringResult(i
1450: 6e 74 65 72 70 29 29 3b 0a 09 09 29 0a 0a 09 09  nterp));...)....
1460: 69 66 20 28 65 72 72 6f 72 5f 73 74 72 69 6e 67  if (error_string
1470: 29 20 7b 0a 09 09 09 61 70 70 66 73 5f 63 61 6c  ) {....appfs_cal
1480: 6c 5f 6c 69 62 74 63 6c 28 0a 09 09 09 09 2a 65  l_libtcl(.....*e
1490: 72 72 6f 72 5f 73 74 72 69 6e 67 20 3d 20 73 74  rror_string = st
14a0: 72 64 75 70 28 54 63 6c 5f 47 65 74 53 74 72 69  rdup(Tcl_GetStri
14b0: 6e 67 52 65 73 75 6c 74 28 69 6e 74 65 72 70 29  ngResult(interp)
14c0: 29 3b 0a 09 09 09 29 0a 09 09 7d 0a 0a 09 09 61  );....)...}....a
14d0: 70 70 66 73 5f 63 61 6c 6c 5f 6c 69 62 74 63 6c  ppfs_call_libtcl
14e0: 28 54 63 6c 5f 52 65 6c 65 61 73 65 28 69 6e 74  (Tcl_Release(int
14f0: 65 72 70 29 3b 29 0a 0a 09 09 41 50 50 46 53 5f  erp);)....APPFS_
1500: 44 45 42 55 47 28 22 54 65 72 6d 69 6e 61 74 69  DEBUG("Terminati
1510: 6e 67 20 54 63 6c 20 69 6e 74 65 72 70 72 65 74  ng Tcl interpret
1520: 65 72 2e 22 29 3b 0a 0a 09 09 61 70 70 66 73 5f  er.");....appfs_
1530: 63 61 6c 6c 5f 6c 69 62 74 63 6c 28 54 63 6c 5f  call_libtcl(Tcl_
1540: 44 65 6c 65 74 65 49 6e 74 65 72 70 28 69 6e 74  DeleteInterp(int
1550: 65 72 70 29 3b 29 0a 0a 09 09 72 65 74 75 72 6e  erp);)....return
1560: 28 4e 55 4c 4c 29 3b 0a 09 7d 0a 0a 09 61 70 70  (NULL);..}...app
1570: 66 73 5f 63 61 6c 6c 5f 6c 69 62 74 63 6c 28 0a  fs_call_libtcl(.
1580: 09 09 74 63 6c 5f 72 65 74 20 3d 20 54 63 6c 5f  ..tcl_ret = Tcl_
1590: 45 76 61 6c 28 69 6e 74 65 72 70 2c 20 22 70 61  Eval(interp, "pa
15a0: 63 6b 61 67 65 20 69 66 6e 65 65 64 65 64 20 73  ckage ifneeded s
15b0: 68 61 31 20 31 2e 30 20 5b 6c 69 73 74 20 6c 6f  ha1 1.0 [list lo
15c0: 61 64 20 7b 7d 20 73 68 61 31 5d 22 29 3b 0a 09  ad {} sha1]");..
15d0: 29 0a 09 69 66 20 28 74 63 6c 5f 72 65 74 20 21  )..if (tcl_ret !
15e0: 3d 20 54 43 4c 5f 4f 4b 29 20 7b 0a 09 09 66 70  = TCL_OK) {...fp
15f0: 72 69 6e 74 66 28 73 74 64 65 72 72 2c 20 22 55  rintf(stderr, "U
1600: 6e 61 62 6c 65 20 74 6f 20 69 6e 69 74 69 61 6c  nable to initial
1610: 69 7a 65 20 54 63 6c 20 53 48 41 31 2e 20 20 41  ize Tcl SHA1.  A
1620: 62 6f 72 74 69 6e 67 2e 5c 6e 22 29 3b 0a 09 09  borting.\n");...
1630: 61 70 70 66 73 5f 63 61 6c 6c 5f 6c 69 62 74 63  appfs_call_libtc
1640: 6c 28 0a 09 09 09 66 70 72 69 6e 74 66 28 73 74  l(....fprintf(st
1650: 64 65 72 72 2c 20 22 54 63 6c 20 45 72 72 6f 72  derr, "Tcl Error
1660: 20 69 73 3a 20 25 73 5c 6e 22 2c 20 54 63 6c 5f   is: %s\n", Tcl_
1670: 47 65 74 53 74 72 69 6e 67 52 65 73 75 6c 74 28  GetStringResult(
1680: 69 6e 74 65 72 70 29 29 3b 0a 09 09 29 0a 0a 09  interp));...)...
1690: 09 69 66 20 28 65 72 72 6f 72 5f 73 74 72 69 6e  .if (error_strin
16a0: 67 29 20 7b 0a 09 09 09 61 70 70 66 73 5f 63 61  g) {....appfs_ca
16b0: 6c 6c 5f 6c 69 62 74 63 6c 28 0a 09 09 09 09 2a  ll_libtcl(.....*
16c0: 65 72 72 6f 72 5f 73 74 72 69 6e 67 20 3d 20 73  error_string = s
16d0: 74 72 64 75 70 28 54 63 6c 5f 47 65 74 53 74 72  trdup(Tcl_GetStr
16e0: 69 6e 67 52 65 73 75 6c 74 28 69 6e 74 65 72 70  ingResult(interp
16f0: 29 29 3b 0a 09 09 09 29 0a 09 09 7d 0a 0a 09 09  ));....)...}....
1700: 61 70 70 66 73 5f 63 61 6c 6c 5f 6c 69 62 74 63  appfs_call_libtc
1710: 6c 28 54 63 6c 5f 52 65 6c 65 61 73 65 28 69 6e  l(Tcl_Release(in
1720: 74 65 72 70 29 3b 29 0a 0a 09 09 41 50 50 46 53  terp);)....APPFS
1730: 5f 44 45 42 55 47 28 22 54 65 72 6d 69 6e 61 74  _DEBUG("Terminat
1740: 69 6e 67 20 54 63 6c 20 69 6e 74 65 72 70 72 65  ing Tcl interpre
1750: 74 65 72 2e 22 29 3b 0a 0a 09 09 61 70 70 66 73  ter.");....appfs
1760: 5f 63 61 6c 6c 5f 6c 69 62 74 63 6c 28 54 63 6c  _call_libtcl(Tcl
1770: 5f 44 65 6c 65 74 65 49 6e 74 65 72 70 28 69 6e  _DeleteInterp(in
1780: 74 65 72 70 29 3b 29 0a 0a 09 09 72 65 74 75 72  terp);)....retur
1790: 6e 28 4e 55 4c 4c 29 3b 0a 09 7d 0a 0a 09 61 70  n(NULL);..}...ap
17a0: 70 66 73 5f 63 61 6c 6c 5f 6c 69 62 74 63 6c 28  pfs_call_libtcl(
17b0: 0a 09 09 74 63 6c 5f 72 65 74 20 3d 20 54 63 6c  ...tcl_ret = Tcl
17c0: 5f 45 76 61 6c 28 69 6e 74 65 72 70 2c 20 22 70  _Eval(interp, "p
17d0: 61 63 6b 61 67 65 20 69 66 6e 65 65 64 65 64 20  ackage ifneeded 
17e0: 61 70 70 66 73 64 20 31 2e 30 20 5b 6c 69 73 74  appfsd 1.0 [list
17f0: 20 6c 6f 61 64 20 7b 7d 20 61 70 70 66 73 64 5d   load {} appfsd]
1800: 22 29 3b 0a 09 29 0a 09 69 66 20 28 74 63 6c 5f  ");..)..if (tcl_
1810: 72 65 74 20 21 3d 20 54 43 4c 5f 4f 4b 29 20 7b  ret != TCL_OK) {
1820: 0a 09 09 66 70 72 69 6e 74 66 28 73 74 64 65 72  ...fprintf(stder
1830: 72 2c 20 22 55 6e 61 62 6c 65 20 74 6f 20 69 6e  r, "Unable to in
1840: 69 74 69 61 6c 69 7a 65 20 54 63 6c 20 41 70 70  itialize Tcl App
1850: 46 53 20 50 61 63 6b 61 67 65 2e 20 20 41 62 6f  FS Package.  Abo
1860: 72 74 69 6e 67 2e 5c 6e 22 29 3b 0a 09 09 61 70  rting.\n");...ap
1870: 70 66 73 5f 63 61 6c 6c 5f 6c 69 62 74 63 6c 28  pfs_call_libtcl(
1880: 0a 09 09 09 66 70 72 69 6e 74 66 28 73 74 64 65  ....fprintf(stde
1890: 72 72 2c 20 22 54 63 6c 20 45 72 72 6f 72 20 69  rr, "Tcl Error i
18a0: 73 3a 20 25 73 5c 6e 22 2c 20 54 63 6c 5f 47 65  s: %s\n", Tcl_Ge
18b0: 74 53 74 72 69 6e 67 52 65 73 75 6c 74 28 69 6e  tStringResult(in
18c0: 74 65 72 70 29 29 3b 0a 09 09 29 0a 0a 09 09 69  terp));...)....i
18d0: 66 20 28 65 72 72 6f 72 5f 73 74 72 69 6e 67 29  f (error_string)
18e0: 20 7b 0a 09 09 09 61 70 70 66 73 5f 63 61 6c 6c   {....appfs_call
18f0: 5f 6c 69 62 74 63 6c 28 0a 09 09 09 09 2a 65 72  _libtcl(.....*er
1900: 72 6f 72 5f 73 74 72 69 6e 67 20 3d 20 73 74 72  ror_string = str
1910: 64 75 70 28 54 63 6c 5f 47 65 74 53 74 72 69 6e  dup(Tcl_GetStrin
1920: 67 52 65 73 75 6c 74 28 69 6e 74 65 72 70 29 29  gResult(interp))
1930: 3b 0a 09 09 09 29 0a 09 09 7d 0a 0a 09 09 61 70  ;....)...}....ap
1940: 70 66 73 5f 63 61 6c 6c 5f 6c 69 62 74 63 6c 28  pfs_call_libtcl(
1950: 54 63 6c 5f 52 65 6c 65 61 73 65 28 69 6e 74 65  Tcl_Release(inte
1960: 72 70 29 3b 29 0a 0a 09 09 41 50 50 46 53 5f 44  rp);)....APPFS_D
1970: 45 42 55 47 28 22 54 65 72 6d 69 6e 61 74 69 6e  EBUG("Terminatin
1980: 67 20 54 63 6c 20 69 6e 74 65 72 70 72 65 74 65  g Tcl interprete
1990: 72 2e 22 29 3b 0a 0a 09 09 61 70 70 66 73 5f 63  r.");....appfs_c
19a0: 61 6c 6c 5f 6c 69 62 74 63 6c 28 54 63 6c 5f 44  all_libtcl(Tcl_D
19b0: 65 6c 65 74 65 49 6e 74 65 72 70 28 69 6e 74 65  eleteInterp(inte
19c0: 72 70 29 3b 29 0a 0a 09 09 72 65 74 75 72 6e 28  rp);)....return(
19d0: 4e 55 4c 4c 29 3b 0a 09 7d 0a 0a 09 2f 2a 0a 09  NULL);..}.../*..
19e0: 20 2a 20 4c 6f 61 64 20 22 70 6b 69 2e 74 63 6c   * Load "pki.tcl
19f0: 22 20 69 6e 20 74 68 65 20 73 61 6d 65 20 77 61  " in the same wa
1a00: 79 20 61 73 20 61 70 70 66 73 64 2e 74 63 6c 20  y as appfsd.tcl 
1a10: 28 73 65 65 20 62 65 6c 6f 77 29 0a 09 20 2a 2f  (see below).. */
1a20: 0a 09 61 70 70 66 73 5f 63 61 6c 6c 5f 6c 69 62  ..appfs_call_lib
1a30: 74 63 6c 5f 65 6e 74 65 72 0a 09 09 74 63 6c 5f  tcl_enter...tcl_
1a40: 72 65 74 20 3d 20 54 63 6c 5f 45 76 61 6c 28 69  ret = Tcl_Eval(i
1a50: 6e 74 65 72 70 2c 20 22 22 0a 23 69 6e 63 6c 75  nterp, "".#inclu
1a60: 64 65 20 22 70 6b 69 2e 74 63 6c 2e 68 22 0a 09  de "pki.tcl.h"..
1a70: 09 22 22 29 3b 0a 09 61 70 70 66 73 5f 63 61 6c  ."");..appfs_cal
1a80: 6c 5f 6c 69 62 74 63 6c 5f 65 78 69 74 0a 09 69  l_libtcl_exit..i
1a90: 66 20 28 74 63 6c 5f 72 65 74 20 21 3d 20 54 43  f (tcl_ret != TC
1aa0: 4c 5f 4f 4b 29 20 7b 0a 09 09 66 70 72 69 6e 74  L_OK) {...fprint
1ab0: 66 28 73 74 64 65 72 72 2c 20 22 55 6e 61 62 6c  f(stderr, "Unabl
1ac0: 65 20 74 6f 20 69 6e 69 74 69 61 6c 69 7a 65 20  e to initialize 
1ad0: 54 63 6c 20 50 4b 49 2e 20 20 41 62 6f 72 74 69  Tcl PKI.  Aborti
1ae0: 6e 67 2e 5c 6e 22 29 3b 0a 09 09 61 70 70 66 73  ng.\n");...appfs
1af0: 5f 63 61 6c 6c 5f 6c 69 62 74 63 6c 28 0a 09 09  _call_libtcl(...
1b00: 09 66 70 72 69 6e 74 66 28 73 74 64 65 72 72 2c  .fprintf(stderr,
1b10: 20 22 54 63 6c 20 45 72 72 6f 72 20 69 73 3a 20   "Tcl Error is: 
1b20: 25 73 5c 6e 22 2c 20 54 63 6c 5f 47 65 74 53 74  %s\n", Tcl_GetSt
1b30: 72 69 6e 67 52 65 73 75 6c 74 28 69 6e 74 65 72  ringResult(inter
1b40: 70 29 29 3b 0a 09 09 29 0a 0a 09 09 69 66 20 28  p));...)....if (
1b50: 65 72 72 6f 72 5f 73 74 72 69 6e 67 29 20 7b 0a  error_string) {.
1b60: 09 09 09 61 70 70 66 73 5f 63 61 6c 6c 5f 6c 69  ...appfs_call_li
1b70: 62 74 63 6c 28 0a 09 09 09 09 2a 65 72 72 6f 72  btcl(.....*error
1b80: 5f 73 74 72 69 6e 67 20 3d 20 73 74 72 64 75 70  _string = strdup
1b90: 28 54 63 6c 5f 47 65 74 53 74 72 69 6e 67 52 65  (Tcl_GetStringRe
1ba0: 73 75 6c 74 28 69 6e 74 65 72 70 29 29 3b 0a 09  sult(interp));..
1bb0: 09 09 29 0a 09 09 7d 0a 0a 09 09 61 70 70 66 73  ..)...}....appfs
1bc0: 5f 63 61 6c 6c 5f 6c 69 62 74 63 6c 28 54 63 6c  _call_libtcl(Tcl
1bd0: 5f 52 65 6c 65 61 73 65 28 69 6e 74 65 72 70 29  _Release(interp)
1be0: 3b 29 0a 0a 09 09 41 50 50 46 53 5f 44 45 42 55  ;)....APPFS_DEBU
1bf0: 47 28 22 54 65 72 6d 69 6e 61 74 69 6e 67 20 54  G("Terminating T
1c00: 63 6c 20 69 6e 74 65 72 70 72 65 74 65 72 2e 22  cl interpreter."
1c10: 29 3b 0a 0a 09 09 61 70 70 66 73 5f 63 61 6c 6c  );....appfs_call
1c20: 5f 6c 69 62 74 63 6c 28 54 63 6c 5f 44 65 6c 65  _libtcl(Tcl_Dele
1c30: 74 65 49 6e 74 65 72 70 28 69 6e 74 65 72 70 29  teInterp(interp)
1c40: 3b 29 0a 0a 09 09 72 65 74 75 72 6e 28 4e 55 4c  ;)....return(NUL
1c50: 4c 29 3b 0a 09 7d 0a 0a 09 2f 2a 0a 09 20 2a 20  L);..}.../*.. * 
1c60: 4c 6f 61 64 20 74 68 65 20 22 61 70 70 66 73 64  Load the "appfsd
1c70: 2e 74 63 6c 22 20 73 63 72 69 70 74 2c 20 77 68  .tcl" script, wh
1c80: 69 63 68 20 69 73 20 22 63 6f 6d 70 69 6c 65 64  ich is "compiled
1c90: 22 20 69 6e 74 6f 20 61 20 43 20 68 65 61 64 65  " into a C heade
1ca0: 72 0a 09 20 2a 20 73 6f 20 74 68 61 74 20 69 74  r.. * so that it
1cb0: 20 64 6f 65 73 20 6e 6f 74 20 6e 65 65 64 20 74   does not need t
1cc0: 6f 20 65 78 69 73 74 20 6f 6e 20 74 68 65 20 66  o exist on the f
1cd0: 69 6c 65 73 79 73 74 65 6d 20 61 6e 64 20 63 61  ilesystem and ca
1ce0: 6e 20 62 65 0a 09 20 2a 20 64 69 72 65 63 74 6c  n be.. * directl
1cf0: 79 20 65 76 61 6c 75 61 74 65 64 2e 0a 09 20 2a  y evaluated... *
1d00: 2f 0a 09 61 70 70 66 73 5f 63 61 6c 6c 5f 6c 69  /..appfs_call_li
1d10: 62 74 63 6c 5f 65 6e 74 65 72 0a 09 09 74 63 6c  btcl_enter...tcl
1d20: 5f 72 65 74 20 3d 20 54 63 6c 5f 45 76 61 6c 28  _ret = Tcl_Eval(
1d30: 69 6e 74 65 72 70 2c 20 22 22 0a 23 69 6e 63 6c  interp, "".#incl
1d40: 75 64 65 20 22 61 70 70 66 73 64 2e 74 63 6c 2e  ude "appfsd.tcl.
1d50: 68 22 0a 09 09 22 22 29 3b 0a 09 61 70 70 66 73  h"..."");..appfs
1d60: 5f 63 61 6c 6c 5f 6c 69 62 74 63 6c 5f 65 78 69  _call_libtcl_exi
1d70: 74 0a 09 69 66 20 28 74 63 6c 5f 72 65 74 20 21  t..if (tcl_ret !
1d80: 3d 20 54 43 4c 5f 4f 4b 29 20 7b 0a 09 09 66 70  = TCL_OK) {...fp
1d90: 72 69 6e 74 66 28 73 74 64 65 72 72 2c 20 22 55  rintf(stderr, "U
1da0: 6e 61 62 6c 65 20 74 6f 20 69 6e 69 74 69 61 6c  nable to initial
1db0: 69 7a 65 20 54 63 6c 20 41 70 70 46 53 20 73 63  ize Tcl AppFS sc
1dc0: 72 69 70 74 2e 20 20 41 62 6f 72 74 69 6e 67 2e  ript.  Aborting.
1dd0: 5c 6e 22 29 3b 0a 09 09 61 70 70 66 73 5f 63 61  \n");...appfs_ca
1de0: 6c 6c 5f 6c 69 62 74 63 6c 28 0a 09 09 09 66 70  ll_libtcl(....fp
1df0: 72 69 6e 74 66 28 73 74 64 65 72 72 2c 20 22 54  rintf(stderr, "T
1e00: 63 6c 20 45 72 72 6f 72 20 69 73 3a 20 25 73 5c  cl Error is: %s\
1e10: 6e 22 2c 20 54 63 6c 5f 47 65 74 53 74 72 69 6e  n", Tcl_GetStrin
1e20: 67 52 65 73 75 6c 74 28 69 6e 74 65 72 70 29 29  gResult(interp))
1e30: 3b 0a 09 09 29 0a 0a 09 09 69 66 20 28 65 72 72  ;...)....if (err
1e40: 6f 72 5f 73 74 72 69 6e 67 29 20 7b 0a 09 09 09  or_string) {....
1e50: 61 70 70 66 73 5f 63 61 6c 6c 5f 6c 69 62 74 63  appfs_call_libtc
1e60: 6c 28 0a 09 09 09 09 2a 65 72 72 6f 72 5f 73 74  l(.....*error_st
1e70: 72 69 6e 67 20 3d 20 73 74 72 64 75 70 28 54 63  ring = strdup(Tc
1e80: 6c 5f 47 65 74 53 74 72 69 6e 67 52 65 73 75 6c  l_GetStringResul
1e90: 74 28 69 6e 74 65 72 70 29 29 3b 0a 09 09 09 29  t(interp));....)
1ea0: 0a 09 09 7d 0a 0a 09 09 61 70 70 66 73 5f 63 61  ...}....appfs_ca
1eb0: 6c 6c 5f 6c 69 62 74 63 6c 28 54 63 6c 5f 52 65  ll_libtcl(Tcl_Re
1ec0: 6c 65 61 73 65 28 69 6e 74 65 72 70 29 3b 29 0a  lease(interp);).
1ed0: 0a 09 09 41 50 50 46 53 5f 44 45 42 55 47 28 22  ...APPFS_DEBUG("
1ee0: 54 65 72 6d 69 6e 61 74 69 6e 67 20 54 63 6c 20  Terminating Tcl 
1ef0: 69 6e 74 65 72 70 72 65 74 65 72 2e 22 29 3b 0a  interpreter.");.
1f00: 0a 09 09 61 70 70 66 73 5f 63 61 6c 6c 5f 6c 69  ...appfs_call_li
1f10: 62 74 63 6c 28 54 63 6c 5f 44 65 6c 65 74 65 49  btcl(Tcl_DeleteI
1f20: 6e 74 65 72 70 28 69 6e 74 65 72 70 29 3b 29 0a  nterp(interp);).
1f30: 0a 09 09 72 65 74 75 72 6e 28 4e 55 4c 4c 29 3b  ...return(NULL);
1f40: 0a 09 7d 0a 0a 09 2f 2a 0a 09 20 2a 20 53 65 74  ..}.../*.. * Set
1f50: 20 67 6c 6f 62 61 6c 20 76 61 72 69 61 62 6c 65   global variable
1f60: 73 20 66 72 6f 6d 20 43 20 74 6f 20 54 63 6c 0a  s from C to Tcl.
1f70: 09 20 2a 2f 0a 09 61 70 70 66 73 5f 63 61 6c 6c  . */..appfs_call
1f80: 5f 6c 69 62 74 63 6c 28 0a 09 09 74 63 6c 5f 73  _libtcl(...tcl_s
1f90: 65 74 76 61 72 5f 72 65 74 20 3d 20 54 63 6c 5f  etvar_ret = Tcl_
1fa0: 53 65 74 56 61 72 28 69 6e 74 65 72 70 2c 20 22  SetVar(interp, "
1fb0: 3a 3a 61 70 70 66 73 3a 3a 63 61 63 68 65 64 69  ::appfs::cachedi
1fc0: 72 22 2c 20 61 70 70 66 73 5f 63 61 63 68 65 64  r", appfs_cached
1fd0: 69 72 2c 20 54 43 4c 5f 47 4c 4f 42 41 4c 5f 4f  ir, TCL_GLOBAL_O
1fe0: 4e 4c 59 29 3b 0a 09 29 0a 09 69 66 20 28 74 63  NLY);..)..if (tc
1ff0: 6c 5f 73 65 74 76 61 72 5f 72 65 74 20 3d 3d 20  l_setvar_ret == 
2000: 4e 55 4c 4c 29 20 7b 0a 09 09 66 70 72 69 6e 74  NULL) {...fprint
2010: 66 28 73 74 64 65 72 72 2c 20 22 55 6e 61 62 6c  f(stderr, "Unabl
2020: 65 20 74 6f 20 73 65 74 20 63 61 63 68 65 20 64  e to set cache d
2030: 69 72 65 63 74 6f 72 79 2e 20 20 54 68 69 73 20  irectory.  This 
2040: 73 68 6f 75 6c 64 20 6e 65 76 65 72 20 66 61 69  should never fai
2050: 6c 2e 5c 6e 22 29 3b 0a 0a 09 09 69 66 20 28 65  l.\n");....if (e
2060: 72 72 6f 72 5f 73 74 72 69 6e 67 29 20 7b 0a 09  rror_string) {..
2070: 09 09 61 70 70 66 73 5f 63 61 6c 6c 5f 6c 69 62  ..appfs_call_lib
2080: 74 63 6c 28 0a 09 09 09 09 2a 65 72 72 6f 72 5f  tcl(.....*error_
2090: 73 74 72 69 6e 67 20 3d 20 73 74 72 64 75 70 28  string = strdup(
20a0: 54 63 6c 5f 47 65 74 53 74 72 69 6e 67 52 65 73  Tcl_GetStringRes
20b0: 75 6c 74 28 69 6e 74 65 72 70 29 29 3b 0a 09 09  ult(interp));...
20c0: 09 29 0a 09 09 7d 0a 0a 09 09 61 70 70 66 73 5f  .)...}....appfs_
20d0: 63 61 6c 6c 5f 6c 69 62 74 63 6c 28 54 63 6c 5f  call_libtcl(Tcl_
20e0: 52 65 6c 65 61 73 65 28 69 6e 74 65 72 70 29 3b  Release(interp);
20f0: 29 0a 0a 09 09 41 50 50 46 53 5f 44 45 42 55 47  )....APPFS_DEBUG
2100: 28 22 54 65 72 6d 69 6e 61 74 69 6e 67 20 54 63  ("Terminating Tc
2110: 6c 20 69 6e 74 65 72 70 72 65 74 65 72 2e 22 29  l interpreter.")
2120: 3b 0a 0a 09 09 61 70 70 66 73 5f 63 61 6c 6c 5f  ;....appfs_call_
2130: 6c 69 62 74 63 6c 28 54 63 6c 5f 44 65 6c 65 74  libtcl(Tcl_Delet
2140: 65 49 6e 74 65 72 70 28 69 6e 74 65 72 70 29 3b  eInterp(interp);
2150: 29 0a 0a 09 09 72 65 74 75 72 6e 28 4e 55 4c 4c  )....return(NULL
2160: 29 3b 0a 09 7d 0a 0a 09 2f 2a 0a 09 20 2a 20 49  );..}.../*.. * I
2170: 6e 69 74 69 61 6c 69 7a 65 20 74 68 65 20 22 61  nitialize the "a
2180: 70 70 66 73 64 2e 74 63 6c 22 20 65 6e 76 69 72  ppfsd.tcl" envir
2190: 6f 6e 6d 65 6e 74 2c 20 77 68 69 63 68 20 6d 75  onment, which mu
21a0: 73 74 20 62 65 20 64 6f 6e 65 20 61 66 74 65 72  st be done after
21b0: 0a 09 20 2a 20 67 6c 6f 62 61 6c 20 76 61 72 69  .. * global vari
21c0: 61 62 6c 65 73 20 61 72 65 20 73 65 74 2e 0a 09  ables are set...
21d0: 20 2a 2f 0a 09 61 70 70 66 73 5f 63 61 6c 6c 5f   */..appfs_call_
21e0: 6c 69 62 74 63 6c 28 0a 09 09 74 63 6c 5f 72 65  libtcl(...tcl_re
21f0: 74 20 3d 20 54 63 6c 5f 45 76 61 6c 28 69 6e 74  t = Tcl_Eval(int
2200: 65 72 70 2c 20 22 3a 3a 61 70 70 66 73 3a 3a 69  erp, "::appfs::i
2210: 6e 69 74 22 29 3b 0a 09 29 0a 09 69 66 20 28 74  nit");..)..if (t
2220: 63 6c 5f 72 65 74 20 21 3d 20 54 43 4c 5f 4f 4b  cl_ret != TCL_OK
2230: 29 20 7b 0a 09 09 66 70 72 69 6e 74 66 28 73 74  ) {...fprintf(st
2240: 64 65 72 72 2c 20 22 55 6e 61 62 6c 65 20 74 6f  derr, "Unable to
2250: 20 69 6e 69 74 69 61 6c 69 7a 65 20 54 63 6c 20   initialize Tcl 
2260: 41 70 70 46 53 20 73 63 72 69 70 74 20 28 3a 3a  AppFS script (::
2270: 61 70 70 66 73 3a 3a 69 6e 69 74 29 2e 20 20 41  appfs::init).  A
2280: 62 6f 72 74 69 6e 67 2e 5c 6e 22 29 3b 0a 09 09  borting.\n");...
2290: 61 70 70 66 73 5f 63 61 6c 6c 5f 6c 69 62 74 63  appfs_call_libtc
22a0: 6c 28 0a 09 09 09 66 70 72 69 6e 74 66 28 73 74  l(....fprintf(st
22b0: 64 65 72 72 2c 20 22 54 63 6c 20 45 72 72 6f 72  derr, "Tcl Error
22c0: 20 69 73 3a 20 25 73 5c 6e 22 2c 20 54 63 6c 5f   is: %s\n", Tcl_
22d0: 47 65 74 53 74 72 69 6e 67 52 65 73 75 6c 74 28  GetStringResult(
22e0: 69 6e 74 65 72 70 29 29 3b 0a 09 09 29 0a 0a 09  interp));...)...
22f0: 09 69 66 20 28 65 72 72 6f 72 5f 73 74 72 69 6e  .if (error_strin
2300: 67 29 20 7b 0a 09 09 09 61 70 70 66 73 5f 63 61  g) {....appfs_ca
2310: 6c 6c 5f 6c 69 62 74 63 6c 28 0a 09 09 09 09 2a  ll_libtcl(.....*
2320: 65 72 72 6f 72 5f 73 74 72 69 6e 67 20 3d 20 73  error_string = s
2330: 74 72 64 75 70 28 54 63 6c 5f 47 65 74 53 74 72  trdup(Tcl_GetStr
2340: 69 6e 67 52 65 73 75 6c 74 28 69 6e 74 65 72 70  ingResult(interp
2350: 29 29 3b 0a 09 09 09 29 0a 09 09 7d 0a 0a 09 09  ));....)...}....
2360: 61 70 70 66 73 5f 63 61 6c 6c 5f 6c 69 62 74 63  appfs_call_libtc
2370: 6c 28 54 63 6c 5f 52 65 6c 65 61 73 65 28 69 6e  l(Tcl_Release(in
2380: 74 65 72 70 29 3b 29 0a 0a 09 09 41 50 50 46 53  terp);)....APPFS
2390: 5f 44 45 42 55 47 28 22 54 65 72 6d 69 6e 61 74  _DEBUG("Terminat
23a0: 69 6e 67 20 54 63 6c 20 69 6e 74 65 72 70 72 65  ing Tcl interpre
23b0: 74 65 72 2e 22 29 3b 0a 0a 09 09 61 70 70 66 73  ter.");....appfs
23c0: 5f 63 61 6c 6c 5f 6c 69 62 74 63 6c 28 54 63 6c  _call_libtcl(Tcl
23d0: 5f 44 65 6c 65 74 65 49 6e 74 65 72 70 28 69 6e  _DeleteInterp(in
23e0: 74 65 72 70 29 3b 29 0a 0a 09 09 72 65 74 75 72  terp);)....retur
23f0: 6e 28 4e 55 4c 4c 29 3b 0a 09 7d 0a 0a 09 2f 2a  n(NULL);..}.../*
2400: 0a 09 20 2a 20 48 69 64 65 20 73 6f 6d 65 20 54  .. * Hide some T
2410: 63 6c 20 63 6f 6d 6d 61 6e 64 73 20 74 68 61 74  cl commands that
2420: 20 77 65 20 64 6f 20 6e 6f 74 20 63 61 72 65 20   we do not care 
2430: 74 6f 20 75 73 65 20 61 6e 64 20 77 68 69 63 68  to use and which
2440: 20 6d 61 79 0a 09 20 2a 20 73 6c 6f 77 20 64 6f   may.. * slow do
2450: 77 6e 20 72 75 6e 2d 74 69 6d 65 20 6f 70 65 72  wn run-time oper
2460: 61 74 69 6f 6e 73 2e 0a 09 20 2a 2f 0a 09 61 70  ations... */..ap
2470: 70 66 73 5f 63 61 6c 6c 5f 6c 69 62 74 63 6c 28  pfs_call_libtcl(
2480: 0a 09 09 54 63 6c 5f 48 69 64 65 43 6f 6d 6d 61  ...Tcl_HideComma
2490: 6e 64 28 69 6e 74 65 72 70 2c 20 22 61 75 74 6f  nd(interp, "auto
24a0: 5f 6c 6f 61 64 5f 69 6e 64 65 78 22 2c 20 22 61  _load_index", "a
24b0: 75 74 6f 5f 6c 6f 61 64 5f 69 6e 64 65 78 22 29  uto_load_index")
24c0: 3b 0a 09 09 54 63 6c 5f 48 69 64 65 43 6f 6d 6d  ;...Tcl_HideComm
24d0: 61 6e 64 28 69 6e 74 65 72 70 2c 20 22 75 6e 6b  and(interp, "unk
24e0: 6e 6f 77 6e 22 2c 20 22 75 6e 6b 6e 6f 77 6e 22  nown", "unknown"
24f0: 29 3b 0a 09 09 54 63 6c 5f 48 69 64 65 43 6f 6d  );...Tcl_HideCom
2500: 6d 61 6e 64 28 69 6e 74 65 72 70 2c 20 22 65 78  mand(interp, "ex
2510: 69 74 22 2c 20 22 65 78 69 74 22 29 3b 0a 09 29  it", "exit");..)
2520: 0a 0a 09 2f 2a 0a 09 20 2a 20 52 65 6c 65 61 73  .../*.. * Releas
2530: 65 20 74 68 65 20 68 6f 6c 64 20 77 65 20 68 61  e the hold we ha
2540: 76 65 20 6f 6e 20 74 68 65 20 69 6e 74 65 72 70  ve on the interp
2550: 72 65 74 65 72 20 73 6f 20 74 68 61 74 20 69 74  reter so that it
2560: 20 6d 61 79 20 62 65 0a 09 20 2a 20 64 65 6c 65   may be.. * dele
2570: 74 65 64 20 69 66 20 6e 65 65 64 65 64 0a 09 20  ted if needed.. 
2580: 2a 2f 0a 09 61 70 70 66 73 5f 63 61 6c 6c 5f 6c  */..appfs_call_l
2590: 69 62 74 63 6c 28 54 63 6c 5f 52 65 6c 65 61 73  ibtcl(Tcl_Releas
25a0: 65 28 69 6e 74 65 72 70 29 3b 29 0a 0a 09 2f 2a  e(interp);).../*
25b0: 0a 09 20 2a 20 52 65 74 75 72 6e 20 74 68 65 20  .. * Return the 
25c0: 63 6f 6d 70 6c 65 74 65 6c 79 20 69 6e 69 74 69  completely initi
25d0: 61 6c 69 7a 65 64 20 69 6e 74 65 72 70 72 65 74  alized interpret
25e0: 65 72 0a 09 20 2a 2f 0a 09 72 65 74 75 72 6e 28  er.. */..return(
25f0: 69 6e 74 65 72 70 29 3b 0a 7d 0a 0a 2f 2a 0a 20  interp);.}../*. 
2600: 2a 20 52 65 74 75 72 6e 20 74 68 65 20 74 68 72  * Return the thr
2610: 65 61 64 2d 73 70 65 63 69 66 69 63 20 54 63 6c  ead-specific Tcl
2620: 20 69 6e 74 65 72 70 72 65 74 65 72 2c 20 63 72   interpreter, cr
2630: 65 61 74 69 6e 67 20 69 74 20 69 66 20 6e 65 65  eating it if nee
2640: 64 65 64 0a 20 2a 2f 0a 73 74 61 74 69 63 20 54  ded. */.static T
2650: 63 6c 5f 49 6e 74 65 72 70 20 2a 61 70 70 66 73  cl_Interp *appfs
2660: 5f 54 63 6c 49 6e 74 65 72 70 28 76 6f 69 64 29  _TclInterp(void)
2670: 20 7b 0a 09 54 63 6c 5f 49 6e 74 65 72 70 20 2a   {..Tcl_Interp *
2680: 69 6e 74 65 72 70 3b 0a 09 69 6e 74 20 70 74 68  interp;..int pth
2690: 72 65 61 64 5f 72 65 74 3b 0a 09 73 74 61 74 69  read_ret;..stati
26a0: 63 20 5f 5f 74 68 72 65 61 64 20 69 6e 74 20 74  c __thread int t
26b0: 68 72 65 61 64 5f 69 6e 74 65 72 70 5f 72 65 73  hread_interp_res
26c0: 65 74 5f 6b 65 79 20 3d 20 30 3b 0a 09 69 6e 74  et_key = 0;..int
26d0: 20 67 6c 6f 62 61 6c 5f 69 6e 74 65 72 70 5f 72   global_interp_r
26e0: 65 73 65 74 5f 6b 65 79 3b 0a 0a 09 67 6c 6f 62  eset_key;...glob
26f0: 61 6c 5f 69 6e 74 65 72 70 5f 72 65 73 65 74 5f  al_interp_reset_
2700: 6b 65 79 20 3d 20 5f 5f 73 79 6e 63 5f 66 65 74  key = __sync_fet
2710: 63 68 5f 61 6e 64 5f 61 64 64 28 26 69 6e 74 65  ch_and_add(&inte
2720: 72 70 5f 72 65 73 65 74 5f 6b 65 79 2c 20 30 29  rp_reset_key, 0)
2730: 3b 0a 0a 09 69 6e 74 65 72 70 20 3d 20 70 74 68  ;...interp = pth
2740: 72 65 61 64 5f 67 65 74 73 70 65 63 69 66 69 63  read_getspecific
2750: 28 69 6e 74 65 72 70 4b 65 79 29 3b 0a 09 69 66  (interpKey);..if
2760: 20 28 69 6e 74 65 72 70 20 21 3d 20 4e 55 4c 4c   (interp != NULL
2770: 20 26 26 20 74 68 72 65 61 64 5f 69 6e 74 65 72   && thread_inter
2780: 70 5f 72 65 73 65 74 5f 6b 65 79 20 21 3d 20 67  p_reset_key != g
2790: 6c 6f 62 61 6c 5f 69 6e 74 65 72 70 5f 72 65 73  lobal_interp_res
27a0: 65 74 5f 6b 65 79 29 20 7b 0a 09 09 41 50 50 46  et_key) {...APPF
27b0: 53 5f 44 45 42 55 47 28 22 54 65 72 6d 69 6e 61  S_DEBUG("Termina
27c0: 74 69 6e 67 20 6f 6c 64 20 69 6e 74 65 72 70 72  ting old interpr
27d0: 65 74 65 72 20 61 6e 64 20 72 65 73 74 61 72 74  eter and restart
27e0: 69 6e 67 20 64 75 65 20 74 6f 20 72 65 73 65 74  ing due to reset
27f0: 20 72 65 71 75 65 73 74 2e 22 29 3b 0a 0a 09 09   request.");....
2800: 61 70 70 66 73 5f 63 61 6c 6c 5f 6c 69 62 74 63  appfs_call_libtc
2810: 6c 28 54 63 6c 5f 44 65 6c 65 74 65 49 6e 74 65  l(Tcl_DeleteInte
2820: 72 70 28 69 6e 74 65 72 70 29 3b 29 0a 0a 09 09  rp(interp);)....
2830: 69 6e 74 65 72 70 20 3d 20 4e 55 4c 4c 3b 0a 0a  interp = NULL;..
2840: 09 09 70 74 68 72 65 61 64 5f 72 65 74 20 3d 20  ..pthread_ret = 
2850: 70 74 68 72 65 61 64 5f 73 65 74 73 70 65 63 69  pthread_setspeci
2860: 66 69 63 28 69 6e 74 65 72 70 4b 65 79 2c 20 69  fic(interpKey, i
2870: 6e 74 65 72 70 29 3b 0a 09 7d 0a 0a 09 69 66 20  nterp);..}...if 
2880: 28 67 6c 6f 62 61 6c 5f 69 6e 74 65 72 70 5f 72  (global_interp_r
2890: 65 73 65 74 5f 6b 65 79 20 3d 3d 20 2d 31 29 20  eset_key == -1) 
28a0: 7b 0a 09 09 41 50 50 46 53 5f 44 45 42 55 47 28  {...APPFS_DEBUG(
28b0: 22 52 65 74 75 72 6e 69 6e 67 20 4e 55 4c 4c 20  "Returning NULL 
28c0: 73 69 6e 63 65 20 77 65 20 61 72 65 20 69 6e 20  since we are in 
28d0: 74 68 65 20 70 72 6f 63 65 73 73 20 6f 66 20 74  the process of t
28e0: 65 72 6d 69 6e 61 74 69 6e 67 20 61 6c 6c 20 74  erminating all t
28f0: 68 72 65 61 64 73 2e 22 29 3b 0a 0a 09 09 72 65  hreads.");....re
2900: 74 75 72 6e 28 4e 55 4c 4c 29 3b 0a 09 7d 0a 0a  turn(NULL);..}..
2910: 09 74 68 72 65 61 64 5f 69 6e 74 65 72 70 5f 72  .thread_interp_r
2920: 65 73 65 74 5f 6b 65 79 20 3d 20 67 6c 6f 62 61  eset_key = globa
2930: 6c 5f 69 6e 74 65 72 70 5f 72 65 73 65 74 5f 6b  l_interp_reset_k
2940: 65 79 3b 0a 0a 09 69 66 20 28 69 6e 74 65 72 70  ey;...if (interp
2950: 20 3d 3d 20 4e 55 4c 4c 29 20 7b 0a 09 09 69 6e   == NULL) {...in
2960: 74 65 72 70 20 3d 20 61 70 70 66 73 5f 63 72 65  terp = appfs_cre
2970: 61 74 65 5f 54 63 6c 49 6e 74 65 72 70 28 4e 55  ate_TclInterp(NU
2980: 4c 4c 29 3b 0a 0a 09 09 69 66 20 28 69 6e 74 65  LL);....if (inte
2990: 72 70 20 3d 3d 20 4e 55 4c 4c 29 20 7b 0a 09 09  rp == NULL) {...
29a0: 09 41 50 50 46 53 5f 44 45 42 55 47 28 22 43 72  .APPFS_DEBUG("Cr
29b0: 65 61 74 65 20 69 6e 74 65 72 70 20 66 61 69 6c  eate interp fail
29c0: 65 64 2c 20 72 65 74 75 72 6e 69 6e 67 20 69 6e  ed, returning in
29d0: 20 66 61 69 6c 75 72 65 2e 22 29 3b 0a 0a 09 09   failure.");....
29e0: 09 72 65 74 75 72 6e 28 4e 55 4c 4c 29 3b 0a 09  .return(NULL);..
29f0: 09 7d 0a 0a 09 09 70 74 68 72 65 61 64 5f 72 65  .}....pthread_re
2a00: 74 20 3d 20 70 74 68 72 65 61 64 5f 73 65 74 73  t = pthread_sets
2a10: 70 65 63 69 66 69 63 28 69 6e 74 65 72 70 4b 65  pecific(interpKe
2a20: 79 2c 20 69 6e 74 65 72 70 29 3b 0a 09 09 69 66  y, interp);...if
2a30: 20 28 70 74 68 72 65 61 64 5f 72 65 74 20 21 3d   (pthread_ret !=
2a40: 20 30 29 20 7b 0a 09 09 09 41 50 50 46 53 5f 44   0) {....APPFS_D
2a50: 45 42 55 47 28 22 70 74 68 72 65 61 64 5f 73 65  EBUG("pthread_se
2a60: 74 73 70 65 63 69 66 69 63 28 29 20 66 61 69 6c  tspecific() fail
2a70: 65 64 2e 20 20 54 65 72 6d 69 6e 61 74 69 6e 67  ed.  Terminating
2a80: 20 54 63 6c 20 69 6e 74 65 72 70 72 65 74 65 72   Tcl interpreter
2a90: 2e 22 29 3b 0a 0a 09 09 09 61 70 70 66 73 5f 63  .");.....appfs_c
2aa0: 61 6c 6c 5f 6c 69 62 74 63 6c 28 54 63 6c 5f 44  all_libtcl(Tcl_D
2ab0: 65 6c 65 74 65 49 6e 74 65 72 70 28 69 6e 74 65  eleteInterp(inte
2ac0: 72 70 29 3b 29 0a 0a 09 09 09 72 65 74 75 72 6e  rp);).....return
2ad0: 28 4e 55 4c 4c 29 3b 0a 09 09 7d 0a 09 7d 0a 0a  (NULL);...}..}..
2ae0: 09 72 65 74 75 72 6e 28 69 6e 74 65 72 70 29 3b  .return(interp);
2af0: 0a 7d 0a 0a 2f 2a 0a 20 2a 20 45 76 61 6c 75 61  .}../*. * Evalua
2b00: 74 65 20 61 20 54 63 6c 20 73 63 72 69 70 74 20  te a Tcl script 
2b10: 63 6f 6e 73 74 72 75 63 74 65 64 20 62 79 20 63  constructed by c
2b20: 6f 6e 63 61 74 65 6e 61 74 69 6e 67 20 61 20 62  oncatenating a b
2b30: 75 6e 63 68 20 6f 66 20 43 20 73 74 72 69 6e 67  unch of C string
2b40: 73 0a 20 2a 20 74 6f 67 65 74 68 65 72 2e 0a 20  s. * together.. 
2b50: 2a 2f 0a 73 74 61 74 69 63 20 69 6e 74 20 61 70  */.static int ap
2b60: 70 66 73 5f 54 63 6c 5f 45 76 61 6c 28 54 63 6c  pfs_Tcl_Eval(Tcl
2b70: 5f 49 6e 74 65 72 70 20 2a 69 6e 74 65 72 70 2c  _Interp *interp,
2b80: 20 69 6e 74 20 6f 62 6a 63 2c 20 63 6f 6e 73 74   int objc, const
2b90: 20 63 68 61 72 20 2a 63 6d 64 2c 20 2e 2e 2e 29   char *cmd, ...)
2ba0: 20 7b 0a 09 54 63 6c 5f 4f 62 6a 20 2a 2a 6f 62   {..Tcl_Obj **ob
2bb0: 6a 76 3b 0a 09 63 6f 6e 73 74 20 63 68 61 72 20  jv;..const char 
2bc0: 2a 61 72 67 3b 0a 09 76 61 5f 6c 69 73 74 20 61  *arg;..va_list a
2bd0: 72 67 70 3b 0a 09 69 6e 74 20 72 65 74 76 61 6c  rgp;..int retval
2be0: 3b 0a 09 69 6e 74 20 69 3b 0a 0a 09 69 66 20 28  ;..int i;...if (
2bf0: 69 6e 74 65 72 70 20 3d 3d 20 4e 55 4c 4c 29 20  interp == NULL) 
2c00: 7b 0a 09 09 41 50 50 46 53 5f 44 45 42 55 47 28  {...APPFS_DEBUG(
2c10: 22 49 6e 76 61 6c 69 64 20 69 6e 74 65 72 70 72  "Invalid interpr
2c20: 65 74 65 72 20 70 61 73 73 65 64 20 69 6e 2c 20  eter passed in, 
2c30: 72 65 74 75 72 6e 69 6e 67 20 69 6e 20 66 61 69  returning in fai
2c40: 6c 75 72 65 2e 22 29 3b 0a 0a 09 09 72 65 74 75  lure.");....retu
2c50: 72 6e 28 54 43 4c 5f 45 52 52 4f 52 29 3b 0a 09  rn(TCL_ERROR);..
2c60: 7d 0a 0a 09 6f 62 6a 76 20 3d 20 28 76 6f 69 64  }...objv = (void
2c70: 20 2a 29 20 63 6b 61 6c 6c 6f 63 28 73 69 7a 65   *) ckalloc(size
2c80: 6f 66 28 2a 6f 62 6a 76 29 20 2a 20 6f 62 6a 63  of(*objv) * objc
2c90: 29 3b 0a 0a 09 61 70 70 66 73 5f 63 61 6c 6c 5f  );...appfs_call_
2ca0: 6c 69 62 74 63 6c 28 0a 09 09 6f 62 6a 76 5b 30  libtcl(...objv[0
2cb0: 5d 20 3d 20 54 63 6c 5f 4e 65 77 53 74 72 69 6e  ] = Tcl_NewStrin
2cc0: 67 4f 62 6a 28 63 6d 64 2c 20 2d 31 29 3b 0a 0a  gObj(cmd, -1);..
2cd0: 09 09 54 63 6c 5f 49 6e 63 72 52 65 66 43 6f 75  ..Tcl_IncrRefCou
2ce0: 6e 74 28 6f 62 6a 76 5b 30 5d 29 3b 0a 0a 09 09  nt(objv[0]);....
2cf0: 76 61 5f 73 74 61 72 74 28 61 72 67 70 2c 20 63  va_start(argp, c
2d00: 6d 64 29 3b 0a 09 09 66 6f 72 20 28 69 20 3d 20  md);...for (i = 
2d10: 31 3b 20 69 20 3c 20 6f 62 6a 63 3b 20 69 2b 2b  1; i < objc; i++
2d20: 29 20 7b 0a 09 09 09 61 72 67 20 3d 20 76 61 5f  ) {....arg = va_
2d30: 61 72 67 28 61 72 67 70 2c 20 63 6f 6e 73 74 20  arg(argp, const 
2d40: 63 68 61 72 20 2a 29 3b 0a 0a 09 09 09 6f 62 6a  char *);.....obj
2d50: 76 5b 69 5d 20 3d 20 54 63 6c 5f 4e 65 77 53 74  v[i] = Tcl_NewSt
2d60: 72 69 6e 67 4f 62 6a 28 61 72 67 2c 20 2d 31 29  ringObj(arg, -1)
2d70: 3b 0a 0a 09 09 09 54 63 6c 5f 49 6e 63 72 52 65  ;.....Tcl_IncrRe
2d80: 66 43 6f 75 6e 74 28 6f 62 6a 76 5b 69 5d 29 3b  fCount(objv[i]);
2d90: 0a 09 09 7d 0a 09 09 76 61 5f 65 6e 64 28 61 72  ...}...va_end(ar
2da0: 67 70 29 3b 0a 09 29 0a 0a 09 61 70 70 66 73 5f  gp);..)...appfs_
2db0: 63 61 6c 6c 5f 6c 69 62 74 63 6c 28 0a 09 09 72  call_libtcl(...r
2dc0: 65 74 76 61 6c 20 3d 20 54 63 6c 5f 45 76 61 6c  etval = Tcl_Eval
2dd0: 4f 62 6a 76 28 69 6e 74 65 72 70 2c 20 6f 62 6a  Objv(interp, obj
2de0: 63 2c 20 6f 62 6a 76 2c 20 30 29 3b 0a 09 29 0a  c, objv, 0);..).
2df0: 0a 09 61 70 70 66 73 5f 63 61 6c 6c 5f 6c 69 62  ..appfs_call_lib
2e00: 74 63 6c 28 0a 09 09 66 6f 72 20 28 69 20 3d 20  tcl(...for (i = 
2e10: 30 3b 20 69 20 3c 20 6f 62 6a 63 3b 20 69 2b 2b  0; i < objc; i++
2e20: 29 20 7b 0a 09 09 09 54 63 6c 5f 44 65 63 72 52  ) {....Tcl_DecrR
2e30: 65 66 43 6f 75 6e 74 28 6f 62 6a 76 5b 69 5d 29  efCount(objv[i])
2e40: 3b 0a 09 09 7d 0a 09 29 0a 0a 09 63 6b 66 72 65  ;...}..)...ckfre
2e50: 65 28 28 76 6f 69 64 20 2a 29 20 6f 62 6a 76 29  e((void *) objv)
2e60: 3b 0a 0a 09 69 66 20 28 72 65 74 76 61 6c 20 21  ;...if (retval !
2e70: 3d 20 54 43 4c 5f 4f 4b 29 20 7b 0a 09 09 61 70  = TCL_OK) {...ap
2e80: 70 66 73 5f 63 61 6c 6c 5f 6c 69 62 74 63 6c 28  pfs_call_libtcl(
2e90: 0a 09 09 09 41 50 50 46 53 5f 44 45 42 55 47 28  ....APPFS_DEBUG(
2ea0: 22 54 63 6c 20 63 6f 6d 6d 61 6e 64 20 66 61 69  "Tcl command fai
2eb0: 6c 65 64 2c 20 3a 3a 65 72 72 6f 72 49 6e 66 6f  led, ::errorInfo
2ec0: 20 63 6f 6e 74 61 69 6e 73 3a 20 25 73 5c 6e 22   contains: %s\n"
2ed0: 2c 20 54 63 6c 5f 47 65 74 56 61 72 28 69 6e 74  , Tcl_GetVar(int
2ee0: 65 72 70 2c 20 22 3a 3a 65 72 72 6f 72 49 6e 66  erp, "::errorInf
2ef0: 6f 22 2c 20 30 29 29 3b 0a 09 09 29 0a 09 7d 0a  o", 0));...)..}.
2f00: 0a 09 72 65 74 75 72 6e 28 72 65 74 76 61 6c 29  ..return(retval)
2f10: 3b 0a 7d 0a 0a 2f 2a 0a 20 2a 20 52 65 71 75 65  ;.}../*. * Reque
2f20: 73 74 20 61 6c 6c 20 54 63 6c 20 69 6e 74 65 72  st all Tcl inter
2f30: 70 72 65 74 65 72 73 20 72 65 73 74 61 72 74 0a  preters restart.
2f40: 20 2a 2f 0a 73 74 61 74 69 63 20 76 6f 69 64 20   */.static void 
2f50: 61 70 70 66 73 5f 74 63 6c 5f 52 65 73 65 74 49  appfs_tcl_ResetI
2f60: 6e 74 65 72 70 73 28 76 6f 69 64 29 20 7b 0a 09  nterps(void) {..
2f70: 41 50 50 46 53 5f 44 45 42 55 47 28 22 52 65 71  APPFS_DEBUG("Req
2f80: 75 65 73 74 69 6e 67 20 72 65 73 65 74 20 6f 66  uesting reset of
2f90: 20 61 6c 6c 20 69 6e 74 65 72 70 72 65 74 65 72   all interpreter
2fa0: 73 2e 22 29 3b 0a 0a 09 5f 5f 73 79 6e 63 5f 61  s.");...__sync_a
2fb0: 64 64 5f 61 6e 64 5f 66 65 74 63 68 28 26 69 6e  dd_and_fetch(&in
2fc0: 74 65 72 70 5f 72 65 73 65 74 5f 6b 65 79 2c 20  terp_reset_key, 
2fd0: 31 29 3b 0a 0a 09 72 65 74 75 72 6e 3b 0a 7d 0a  1);...return;.}.
2fe0: 0a 2f 2a 0a 20 2a 20 44 65 74 65 72 6d 69 6e 65  ./*. * Determine
2ff0: 20 74 68 65 20 55 49 44 20 66 6f 72 20 74 68 65   the UID for the
3000: 20 75 73 65 72 20 6d 61 6b 69 6e 67 20 74 68 65   user making the
3010: 20 63 75 72 72 65 6e 74 20 46 55 53 45 20 66 69   current FUSE fi
3020: 6c 65 73 79 73 74 65 6d 20 72 65 71 75 65 73 74  lesystem request
3030: 2e 0a 20 2a 20 54 68 69 73 20 77 69 6c 6c 20 62  .. * This will b
3040: 65 20 75 73 65 64 20 74 6f 20 6c 6f 6f 6b 75 70  e used to lookup
3050: 20 74 68 65 20 75 73 65 72 27 73 20 68 6f 6d 65   the user's home
3060: 20 64 69 72 65 63 74 6f 72 79 20 73 6f 20 77 65   directory so we
3070: 20 63 61 6e 20 73 65 61 72 63 68 20 66 6f 72 0a   can search for.
3080: 20 2a 20 6c 6f 63 61 6c 6c 79 20 6d 6f 64 69 66   * locally modif
3090: 69 65 64 20 66 69 6c 65 73 2e 0a 20 2a 2f 0a 73  ied files.. */.s
30a0: 74 61 74 69 63 20 75 69 64 5f 74 20 61 70 70 66  tatic uid_t appf
30b0: 73 5f 67 65 74 5f 66 73 75 69 64 28 76 6f 69 64  s_get_fsuid(void
30c0: 29 20 7b 0a 09 73 74 72 75 63 74 20 66 75 73 65  ) {..struct fuse
30d0: 5f 63 6f 6e 74 65 78 74 20 2a 63 74 78 3b 0a 0a  _context *ctx;..
30e0: 09 69 66 20 28 21 61 70 70 66 73 5f 66 75 73 65  .if (!appfs_fuse
30f0: 5f 73 74 61 72 74 65 64 29 20 7b 0a 09 09 72 65  _started) {...re
3100: 74 75 72 6e 28 67 65 74 75 69 64 28 29 29 3b 0a  turn(getuid());.
3110: 09 7d 0a 0a 09 63 74 78 20 3d 20 66 75 73 65 5f  .}...ctx = fuse_
3120: 67 65 74 5f 63 6f 6e 74 65 78 74 28 29 3b 0a 09  get_context();..
3130: 69 66 20 28 63 74 78 20 3d 3d 20 4e 55 4c 4c 29  if (ctx == NULL)
3140: 20 7b 0a 09 09 2f 2a 20 55 6e 61 62 6c 65 20 74   {.../* Unable t
3150: 6f 20 6c 6f 6f 6b 75 70 20 75 73 65 72 20 66 6f  o lookup user fo
3160: 72 20 73 6f 6d 65 20 72 65 61 73 6f 6e 20 2a 2f  r some reason */
3170: 0a 09 09 2f 2a 20 52 65 74 75 72 6e 20 61 6e 20  .../* Return an 
3180: 75 6e 70 72 69 76 69 6c 65 67 65 64 20 75 73 65  unprivileged use
3190: 72 20 49 44 20 2a 2f 0a 09 09 41 50 50 46 53 5f  r ID */...APPFS_
31a0: 44 45 42 55 47 28 22 55 6e 61 62 6c 65 20 74 6f  DEBUG("Unable to
31b0: 20 6c 6f 6f 6b 75 70 20 75 73 65 72 20 66 6f 72   lookup user for
31c0: 20 73 6f 6d 65 20 72 65 61 73 6f 6e 2c 20 72 65   some reason, re
31d0: 74 75 72 6e 69 6e 6e 67 20 75 73 65 72 20 49 44  turninng user ID
31e0: 20 6f 66 20 31 22 29 3b 0a 0a 09 09 72 65 74 75   of 1");....retu
31f0: 72 6e 28 31 29 3b 0a 09 7d 0a 0a 09 72 65 74 75  rn(1);..}...retu
3200: 72 6e 28 63 74 78 2d 3e 75 69 64 29 3b 0a 7d 0a  rn(ctx->uid);.}.
3210: 0a 2f 2a 0a 20 2a 20 44 65 74 65 72 6d 69 6e 65  ./*. * Determine
3220: 20 74 68 65 20 47 49 44 20 66 6f 72 20 74 68 65   the GID for the
3230: 20 75 73 65 72 20 6d 61 6b 69 6e 67 20 74 68 65   user making the
3240: 20 63 75 72 72 65 6e 74 20 46 55 53 45 20 66 69   current FUSE fi
3250: 6c 65 73 79 73 74 65 6d 20 72 65 71 75 65 73 74  lesystem request
3260: 2e 0a 20 2a 2f 0a 73 74 61 74 69 63 20 67 69 64  .. */.static gid
3270: 5f 74 20 61 70 70 66 73 5f 67 65 74 5f 66 73 67  _t appfs_get_fsg
3280: 69 64 28 76 6f 69 64 29 20 7b 0a 09 73 74 72 75  id(void) {..stru
3290: 63 74 20 66 75 73 65 5f 63 6f 6e 74 65 78 74 20  ct fuse_context 
32a0: 2a 63 74 78 3b 0a 0a 09 69 66 20 28 21 61 70 70  *ctx;...if (!app
32b0: 66 73 5f 66 75 73 65 5f 73 74 61 72 74 65 64 29  fs_fuse_started)
32c0: 20 7b 0a 09 09 72 65 74 75 72 6e 28 67 65 74 67   {...return(getg
32d0: 69 64 28 29 29 3b 0a 09 7d 0a 0a 09 63 74 78 20  id());..}...ctx 
32e0: 3d 20 66 75 73 65 5f 67 65 74 5f 63 6f 6e 74 65  = fuse_get_conte
32f0: 78 74 28 29 3b 0a 09 69 66 20 28 63 74 78 20 3d  xt();..if (ctx =
3300: 3d 20 4e 55 4c 4c 29 20 7b 0a 09 09 2f 2a 20 55  = NULL) {.../* U
3310: 6e 61 62 6c 65 20 74 6f 20 6c 6f 6f 6b 75 70 20  nable to lookup 
3320: 75 73 65 72 20 66 6f 72 20 73 6f 6d 65 20 72 65  user for some re
3330: 61 73 6f 6e 20 2a 2f 0a 09 09 2f 2a 20 52 65 74  ason */.../* Ret
3340: 75 72 6e 20 61 6e 20 75 6e 70 72 69 76 69 6c 65  urn an unprivile
3350: 67 65 64 20 75 73 65 72 20 49 44 20 2a 2f 0a 09  ged user ID */..
3360: 09 41 50 50 46 53 5f 44 45 42 55 47 28 22 55 6e  .APPFS_DEBUG("Un
3370: 61 62 6c 65 20 74 6f 20 6c 6f 6f 6b 75 70 20 67  able to lookup g
3380: 72 6f 75 70 20 66 6f 72 20 73 6f 6d 65 20 72 65  roup for some re
3390: 61 73 6f 6e 2c 20 72 65 74 75 72 6e 69 6e 6e 67  ason, returninng
33a0: 20 67 72 6f 75 70 20 49 44 20 6f 66 20 31 22 29   group ID of 1")
33b0: 3b 0a 0a 09 09 72 65 74 75 72 6e 28 31 29 3b 0a  ;....return(1);.
33c0: 09 7d 0a 0a 09 72 65 74 75 72 6e 28 63 74 78 2d  .}...return(ctx-
33d0: 3e 67 69 64 29 3b 0a 7d 0a 0a 73 74 61 74 69 63  >gid);.}..static
33e0: 20 76 6f 69 64 20 61 70 70 66 73 5f 73 69 6d 75   void appfs_simu
33f0: 6c 61 74 65 5f 75 73 65 72 5f 66 73 5f 65 6e 74  late_user_fs_ent
3400: 65 72 28 76 6f 69 64 29 20 7b 0a 09 73 65 74 66  er(void) {..setf
3410: 73 75 69 64 28 61 70 70 66 73 5f 67 65 74 5f 66  suid(appfs_get_f
3420: 73 75 69 64 28 29 29 3b 0a 09 73 65 74 66 73 67  suid());..setfsg
3430: 69 64 28 61 70 70 66 73 5f 67 65 74 5f 66 73 67  id(appfs_get_fsg
3440: 69 64 28 29 29 3b 0a 7d 0a 0a 73 74 61 74 69 63  id());.}..static
3450: 20 76 6f 69 64 20 61 70 70 66 73 5f 73 69 6d 75   void appfs_simu
3460: 6c 61 74 65 5f 75 73 65 72 5f 66 73 5f 6c 65 61  late_user_fs_lea
3470: 76 65 28 76 6f 69 64 29 20 7b 0a 09 73 65 74 66  ve(void) {..setf
3480: 73 75 69 64 28 30 29 3b 0a 09 73 65 74 66 73 67  suid(0);..setfsg
3490: 69 64 28 30 29 3b 0a 7d 0a 0a 2f 2a 0a 20 2a 20  id(0);.}../*. * 
34a0: 4c 6f 6f 6b 20 75 70 20 74 68 65 20 68 6f 6d 65  Look up the home
34b0: 20 64 69 72 65 63 74 6f 72 79 20 66 6f 72 20 61   directory for a
34c0: 20 67 69 76 65 6e 20 55 49 44 0a 20 2a 20 20 20   given UID. *   
34d0: 20 20 20 20 20 52 65 74 75 72 6e 73 20 61 20 43       Returns a C
34e0: 20 73 74 72 69 6e 67 20 63 6f 6e 74 61 69 6e 69   string containi
34f0: 6e 67 20 74 68 65 20 75 73 65 72 27 73 20 68 6f  ng the user's ho
3500: 6d 65 20 64 69 72 65 63 74 6f 72 79 20 6f 72 20  me directory or 
3510: 4e 55 4c 4c 20 69 66 0a 20 2a 20 20 20 20 20 20  NULL if. *      
3520: 20 20 74 68 65 20 75 73 65 72 27 73 20 68 6f 6d    the user's hom
3530: 65 20 64 69 72 65 63 74 6f 72 79 20 64 6f 65 73  e directory does
3540: 20 6e 6f 74 20 65 78 69 73 74 20 6f 72 20 69 73   not exist or is
3550: 20 6e 6f 74 20 63 6f 72 72 65 63 74 6c 79 0a 20   not correctly. 
3560: 2a 20 20 20 20 20 20 20 20 63 6f 6e 66 69 67 75  *        configu
3570: 72 65 64 0a 20 2a 2f 0a 73 74 61 74 69 63 20 63  red. */.static c
3580: 68 61 72 20 2a 61 70 70 66 73 5f 67 65 74 5f 68  har *appfs_get_h
3590: 6f 6d 65 64 69 72 28 75 69 64 5f 74 20 66 73 75  omedir(uid_t fsu
35a0: 69 64 29 20 7b 0a 09 73 74 72 75 63 74 20 70 61  id) {..struct pa
35b0: 73 73 77 64 20 65 6e 74 72 79 2c 20 2a 72 65 73  sswd entry, *res
35c0: 75 6c 74 3b 0a 09 73 74 72 75 63 74 20 73 74 61  ult;..struct sta
35d0: 74 20 73 74 62 75 66 3b 0a 09 63 68 61 72 20 62  t stbuf;..char b
35e0: 75 66 5b 31 30 32 34 5d 2c 20 2a 72 65 74 76 61  uf[1024], *retva
35f0: 6c 3b 0a 09 69 6e 74 20 67 70 75 5f 72 65 74 2c  l;..int gpu_ret,
3600: 20 73 74 61 74 5f 72 65 74 3b 0a 0a 09 67 70 75   stat_ret;...gpu
3610: 5f 72 65 74 20 3d 20 67 65 74 70 77 75 69 64 5f  _ret = getpwuid_
3620: 72 28 66 73 75 69 64 2c 20 26 65 6e 74 72 79 2c  r(fsuid, &entry,
3630: 20 62 75 66 2c 20 73 69 7a 65 6f 66 28 62 75 66   buf, sizeof(buf
3640: 29 2c 20 26 72 65 73 75 6c 74 29 3b 0a 09 69 66  ), &result);..if
3650: 20 28 67 70 75 5f 72 65 74 20 21 3d 20 30 29 20   (gpu_ret != 0) 
3660: 7b 0a 09 09 41 50 50 46 53 5f 44 45 42 55 47 28  {...APPFS_DEBUG(
3670: 22 67 65 74 70 77 75 69 64 5f 72 28 25 6c 6c 75  "getpwuid_r(%llu
3680: 2c 20 2e 2e 2e 29 20 72 65 74 75 72 6e 65 64 20  , ...) returned 
3690: 69 6e 20 66 61 69 6c 75 72 65 22 2c 20 28 75 6e  in failure", (un
36a0: 73 69 67 6e 65 64 20 6c 6f 6e 67 20 6c 6f 6e 67  signed long long
36b0: 29 20 66 73 75 69 64 29 3b 0a 0a 09 09 72 65 74  ) fsuid);....ret
36c0: 75 72 6e 28 4e 55 4c 4c 29 3b 0a 09 7d 0a 0a 09  urn(NULL);..}...
36d0: 69 66 20 28 72 65 73 75 6c 74 20 3d 3d 20 4e 55  if (result == NU
36e0: 4c 4c 29 20 7b 0a 09 09 41 50 50 46 53 5f 44 45  LL) {...APPFS_DE
36f0: 42 55 47 28 22 67 65 74 70 77 75 69 64 5f 72 28  BUG("getpwuid_r(
3700: 25 6c 6c 75 2c 20 2e 2e 2e 29 20 72 65 74 75 72  %llu, ...) retur
3710: 6e 65 64 20 4e 55 4c 4c 20 72 65 73 75 6c 74 22  ned NULL result"
3720: 2c 20 28 75 6e 73 69 67 6e 65 64 20 6c 6f 6e 67  , (unsigned long
3730: 20 6c 6f 6e 67 29 20 66 73 75 69 64 29 3b 0a 0a   long) fsuid);..
3740: 09 09 72 65 74 75 72 6e 28 4e 55 4c 4c 29 3b 0a  ..return(NULL);.
3750: 09 7d 0a 0a 09 69 66 20 28 72 65 73 75 6c 74 2d  .}...if (result-
3760: 3e 70 77 5f 64 69 72 20 3d 3d 20 4e 55 4c 4c 29  >pw_dir == NULL)
3770: 20 7b 0a 09 09 41 50 50 46 53 5f 44 45 42 55 47   {...APPFS_DEBUG
3780: 28 22 67 65 74 70 77 75 69 64 5f 72 28 25 6c 6c  ("getpwuid_r(%ll
3790: 75 2c 20 2e 2e 2e 29 20 72 65 74 75 72 6e 65 64  u, ...) returned
37a0: 20 4e 55 4c 4c 20 68 6f 6d 65 20 64 69 72 65 63   NULL home direc
37b0: 74 6f 72 79 22 2c 20 28 75 6e 73 69 67 6e 65 64  tory", (unsigned
37c0: 20 6c 6f 6e 67 20 6c 6f 6e 67 29 20 66 73 75 69   long long) fsui
37d0: 64 29 3b 0a 0a 09 09 72 65 74 75 72 6e 28 4e 55  d);....return(NU
37e0: 4c 4c 29 3b 0a 09 7d 0a 0a 09 73 74 61 74 5f 72  LL);..}...stat_r
37f0: 65 74 20 3d 20 73 74 61 74 28 72 65 73 75 6c 74  et = stat(result
3800: 2d 3e 70 77 5f 64 69 72 2c 20 26 73 74 62 75 66  ->pw_dir, &stbuf
3810: 29 3b 0a 09 69 66 20 28 73 74 61 74 5f 72 65 74  );..if (stat_ret
3820: 20 21 3d 20 30 29 20 7b 0a 09 09 41 50 50 46 53   != 0) {...APPFS
3830: 5f 44 45 42 55 47 28 22 73 74 61 74 28 25 73 29  _DEBUG("stat(%s)
3840: 20 72 65 74 75 72 6e 65 64 20 69 6e 20 66 61 69   returned in fai
3850: 6c 75 72 65 22 2c 20 72 65 73 75 6c 74 2d 3e 70  lure", result->p
3860: 77 5f 64 69 72 29 3b 0a 0a 09 09 72 65 74 75 72  w_dir);....retur
3870: 6e 28 4e 55 4c 4c 29 3b 0a 09 7d 0a 0a 09 69 66  n(NULL);..}...if
3880: 20 28 73 74 62 75 66 2e 73 74 5f 75 69 64 20 21   (stbuf.st_uid !
3890: 3d 20 66 73 75 69 64 29 20 7b 0a 09 09 41 50 50  = fsuid) {...APP
38a0: 46 53 5f 44 45 42 55 47 28 22 55 49 44 20 6d 69  FS_DEBUG("UID mi
38b0: 73 2d 6d 61 74 63 68 20 6f 6e 20 75 73 65 72 20  s-match on user 
38c0: 25 6c 6c 75 27 73 20 68 6f 6d 65 20 64 69 72 65  %llu's home dire
38d0: 63 74 6f 72 79 20 28 25 73 29 2e 20 20 49 74 27  ctory (%s).  It'
38e0: 73 20 6f 77 6e 65 64 20 62 79 20 25 6c 6c 75 2e  s owned by %llu.
38f0: 22 2c 0a 09 09 20 20 20 20 28 75 6e 73 69 67 6e  ",...    (unsign
3900: 65 64 20 6c 6f 6e 67 20 6c 6f 6e 67 29 20 66 73  ed long long) fs
3910: 75 69 64 2c 0a 09 09 20 20 20 20 72 65 73 75 6c  uid,...    resul
3920: 74 2d 3e 70 77 5f 64 69 72 2c 0a 09 09 20 20 20  t->pw_dir,...   
3930: 20 28 75 6e 73 69 67 6e 65 64 20 6c 6f 6e 67 20   (unsigned long 
3940: 6c 6f 6e 67 29 20 73 74 62 75 66 2e 73 74 5f 75  long) stbuf.st_u
3950: 69 64 0a 09 09 29 3b 0a 0a 09 09 72 65 74 75 72  id...);....retur
3960: 6e 28 4e 55 4c 4c 29 3b 0a 09 7d 0a 0a 09 72 65  n(NULL);..}...re
3970: 74 76 61 6c 20 3d 20 73 74 72 64 75 70 28 72 65  tval = strdup(re
3980: 73 75 6c 74 2d 3e 70 77 5f 64 69 72 29 3b 0a 0a  sult->pw_dir);..
3990: 09 72 65 74 75 72 6e 28 72 65 74 76 61 6c 29 3b  .return(retval);
39a0: 0a 7d 0a 0a 2f 2a 0a 20 2a 20 47 65 6e 65 72 61  .}../*. * Genera
39b0: 74 65 20 61 6e 20 69 6e 6f 64 65 20 66 6f 72 20  te an inode for 
39c0: 61 20 67 69 76 65 6e 20 70 61 74 68 2e 20 20 54  a given path.  T
39d0: 68 65 20 69 6e 6f 64 65 20 73 68 6f 75 6c 64 20  he inode should 
39e0: 62 65 20 63 6f 6d 70 75 74 65 64 20 69 6e 20 73  be computed in s
39f0: 75 63 68 0a 20 2a 20 61 20 77 61 79 20 74 68 61  uch. * a way tha
3a00: 74 20 69 74 20 69 73 20 75 6e 6c 69 6b 65 6c 79  t it is unlikely
3a10: 20 74 6f 20 62 65 20 64 75 70 6c 69 63 61 74 65   to be duplicate
3a20: 64 20 61 6e 64 20 72 65 6d 61 69 6e 73 20 74 68  d and remains th
3a30: 65 20 73 61 6d 65 20 66 6f 72 20 61 20 67 69 76  e same for a giv
3a40: 65 6e 0a 20 2a 20 66 69 6c 65 0a 20 2a 0a 20 2a  en. * file. *. *
3a50: 20 43 75 72 72 65 6e 74 20 69 6d 70 6c 65 6d 65   Current impleme
3a60: 6e 74 61 74 69 6f 6e 20 69 73 20 61 6e 20 46 4e  ntation is an FN
3a70: 56 2d 31 61 20 33 32 2d 62 69 74 0a 20 2a 2f 0a  V-1a 32-bit. */.
3a80: 23 69 66 20 55 49 4e 54 5f 4d 41 58 20 3c 20 34  #if UINT_MAX < 4
3a90: 32 39 34 39 36 37 32 39 35 0a 23 65 72 72 6f 72  294967295.#error
3aa0: 20 49 6e 74 65 67 65 72 20 73 69 7a 65 20 69 73   Integer size is
3ab0: 20 74 6f 6f 20 73 6d 61 6c 6c 20 0a 23 65 6e 64   too small .#end
3ac0: 69 66 0a 73 74 61 74 69 63 20 75 6e 73 69 67 6e  if.static unsign
3ad0: 65 64 20 6c 6f 6e 67 20 6c 6f 6e 67 20 61 70 70  ed long long app
3ae0: 66 73 5f 67 65 74 5f 70 61 74 68 5f 69 6e 6f 64  fs_get_path_inod
3af0: 65 28 63 6f 6e 73 74 20 63 68 61 72 20 2a 70 61  e(const char *pa
3b00: 74 68 2c 20 69 6e 74 20 75 69 64 29 20 7b 0a 09  th, int uid) {..
3b10: 75 6e 73 69 67 6e 65 64 20 69 6e 74 20 72 65 74  unsigned int ret
3b20: 76 61 6c 3b 0a 09 63 6f 6e 73 74 20 75 6e 73 69  val;..const unsi
3b30: 67 6e 65 64 20 63 68 61 72 20 2a 70 3b 0a 0a 09  gned char *p;...
3b40: 72 65 74 76 61 6c 20 3d 20 32 31 36 36 31 33 36  retval = 2166136
3b50: 32 36 31 55 3b 20 2f 2a 20 46 4e 56 2d 31 61 20  261U; /* FNV-1a 
3b60: 33 32 2d 62 69 74 20 6f 66 66 73 65 74 5f 62 61  32-bit offset_ba
3b70: 73 69 73 20 2a 2f 0a 0a 09 66 6f 72 20 28 70 20  sis */...for (p 
3b80: 3d 20 28 75 6e 73 69 67 6e 65 64 20 63 68 61 72  = (unsigned char
3b90: 20 2a 29 20 70 61 74 68 3b 20 2a 70 3b 20 70 2b   *) path; *p; p+
3ba0: 2b 29 20 7b 0a 09 09 72 65 74 76 61 6c 20 5e 3d  +) {...retval ^=
3bb0: 20 28 69 6e 74 29 20 2a 70 3b 0a 23 69 66 20 30   (int) *p;.#if 0
3bc0: 0a 09 09 72 65 74 76 61 6c 20 2a 3d 20 31 36 37  ...retval *= 167
3bd0: 37 37 36 31 39 3b 20 2f 2a 20 46 4e 56 2d 31 61  77619; /* FNV-1a
3be0: 20 33 32 2d 62 69 74 20 70 72 69 6d 65 20 2a 2f   32-bit prime */
3bf0: 0a 23 65 6c 73 65 0a 09 09 2f 2a 20 47 43 43 20  .#else.../* GCC 
3c00: 4f 70 74 69 6d 69 7a 65 64 20 72 65 70 6c 61 63  Optimized replac
3c10: 65 6d 65 6e 74 20 2a 2f 0a 09 09 72 65 74 76 61  ement */...retva
3c20: 6c 20 2b 3d 20 28 72 65 74 76 61 6c 20 3c 3c 20  l += (retval << 
3c30: 31 29 20 2b 20 28 72 65 74 76 61 6c 20 3c 3c 20  1) + (retval << 
3c40: 34 29 20 2b 20 28 72 65 74 76 61 6c 20 3c 3c 20  4) + (retval << 
3c50: 37 29 20 2b 20 28 72 65 74 76 61 6c 20 3c 3c 20  7) + (retval << 
3c60: 38 29 20 2b 20 28 72 65 74 76 61 6c 20 3c 3c 20  8) + (retval << 
3c70: 32 34 29 3b 0a 23 65 6e 64 69 66 0a 09 7d 0a 0a  24);.#endif..}..
3c80: 09 69 66 20 28 75 69 64 20 3e 3d 20 30 29 20 7b  .if (uid >= 0) {
3c90: 0a 09 09 72 65 74 76 61 6c 20 2b 3d 20 75 69 64  ...retval += uid
3ca0: 3b 0a 09 09 72 65 74 76 61 6c 2b 2b 3b 0a 09 7d  ;...retval++;..}
3cb0: 0a 0a 09 41 50 50 46 53 5f 44 45 42 55 47 28 22  ...APPFS_DEBUG("
3cc0: 4c 6f 6f 6b 65 64 20 75 70 20 69 6e 6f 64 65 20  Looked up inode 
3cd0: 6e 75 6d 62 65 72 20 66 6f 72 20 70 61 74 68 3d  number for path=
3ce0: 25 73 2c 75 69 64 3d 25 69 3a 20 25 75 22 2c 20  %s,uid=%i: %u", 
3cf0: 70 61 74 68 2c 20 75 69 64 2c 20 72 65 74 76 61  path, uid, retva
3d00: 6c 29 3b 0a 0a 09 72 65 74 75 72 6e 28 72 65 74  l);...return(ret
3d10: 76 61 6c 29 3b 0a 7d 0a 0a 2f 2a 0a 20 2a 20 43  val);.}../*. * C
3d20: 61 63 68 65 20 47 65 74 20 50 61 74 68 20 49 6e  ache Get Path In
3d30: 66 6f 20 6c 6f 6f 6b 75 70 73 20 66 6f 72 20 73  fo lookups for s
3d40: 70 65 65 64 0a 20 2a 2f 0a 73 74 61 74 69 63 20  peed. */.static 
3d50: 69 6e 74 20 61 70 70 66 73 5f 67 65 74 5f 70 61  int appfs_get_pa
3d60: 74 68 5f 69 6e 66 6f 5f 63 61 63 68 65 5f 67 65  th_info_cache_ge
3d70: 74 28 63 6f 6e 73 74 20 63 68 61 72 20 2a 70 61  t(const char *pa
3d80: 74 68 2c 20 75 69 64 5f 74 20 75 69 64 2c 20 73  th, uid_t uid, s
3d90: 74 72 75 63 74 20 61 70 70 66 73 5f 70 61 74 68  truct appfs_path
3da0: 69 6e 66 6f 20 2a 70 61 74 68 69 6e 66 6f 29 20  info *pathinfo) 
3db0: 7b 0a 09 75 6e 73 69 67 6e 65 64 20 69 6e 74 20  {..unsigned int 
3dc0: 68 61 73 68 5f 69 64 78 3b 0a 09 69 6e 74 20 70  hash_idx;..int p
3dd0: 74 68 72 65 61 64 5f 72 65 74 3b 0a 09 69 6e 74  thread_ret;..int
3de0: 20 72 65 74 76 61 6c 3b 0a 0a 09 72 65 74 76 61   retval;...retva
3df0: 6c 20 3d 20 31 3b 0a 0a 09 70 74 68 72 65 61 64  l = 1;...pthread
3e00: 5f 72 65 74 20 3d 20 70 74 68 72 65 61 64 5f 6d  _ret = pthread_m
3e10: 75 74 65 78 5f 6c 6f 63 6b 28 26 61 70 70 66 73  utex_lock(&appfs
3e20: 5f 70 61 74 68 5f 69 6e 66 6f 5f 63 61 63 68 65  _path_info_cache
3e30: 5f 6d 75 74 65 78 29 3b 0a 09 69 66 20 28 70 74  _mutex);..if (pt
3e40: 68 72 65 61 64 5f 72 65 74 20 21 3d 20 30 29 20  hread_ret != 0) 
3e50: 7b 0a 09 09 41 50 50 46 53 5f 44 45 42 55 47 28  {...APPFS_DEBUG(
3e60: 22 55 6e 61 62 6c 65 20 74 6f 20 6c 6f 63 6b 20  "Unable to lock 
3e70: 70 61 74 68 5f 69 6e 66 6f 20 63 61 63 68 65 20  path_info cache 
3e80: 6d 75 74 65 78 20 21 22 29 3b 0a 0a 09 09 72 65  mutex !");....re
3e90: 74 75 72 6e 28 2d 31 29 3b 0a 09 7d 0a 0a 09 41  turn(-1);..}...A
3ea0: 50 50 46 53 5f 44 45 42 55 47 28 22 4c 6f 6f 6b  PPFS_DEBUG("Look
3eb0: 69 6e 67 20 75 70 20 63 61 63 68 65 20 65 6e 74  ing up cache ent
3ec0: 72 79 20 66 6f 72 20 70 61 74 68 3d 25 73 2c 75  ry for path=%s,u
3ed0: 69 64 3d 25 6c 6c 69 2e 2e 2e 22 2c 20 70 61 74  id=%lli...", pat
3ee0: 68 2c 20 28 6c 6f 6e 67 20 6c 6f 6e 67 29 20 75  h, (long long) u
3ef0: 69 64 29 3b 0a 0a 09 69 66 20 28 61 70 70 66 73  id);...if (appfs
3f00: 5f 70 61 74 68 5f 69 6e 66 6f 5f 63 61 63 68 65  _path_info_cache
3f10: 20 21 3d 20 4e 55 4c 4c 29 20 7b 0a 09 09 68 61   != NULL) {...ha
3f20: 73 68 5f 69 64 78 20 3d 20 28 61 70 70 66 73 5f  sh_idx = (appfs_
3f30: 67 65 74 5f 70 61 74 68 5f 69 6e 6f 64 65 28 70  get_path_inode(p
3f40: 61 74 68 2c 20 75 69 64 29 29 20 25 20 61 70 70  ath, uid)) % app
3f50: 66 73 5f 70 61 74 68 5f 69 6e 66 6f 5f 63 61 63  fs_path_info_cac
3f60: 68 65 5f 73 69 7a 65 3b 0a 0a 09 09 69 66 20 28  he_size;....if (
3f70: 61 70 70 66 73 5f 70 61 74 68 5f 69 6e 66 6f 5f  appfs_path_info_
3f80: 63 61 63 68 65 5b 68 61 73 68 5f 69 64 78 5d 2e  cache[hash_idx].
3f90: 5f 63 61 63 68 65 5f 70 61 74 68 20 21 3d 20 4e  _cache_path != N
3fa0: 55 4c 4c 29 20 7b 0a 09 09 09 69 66 20 28 73 74  ULL) {....if (st
3fb0: 72 63 6d 70 28 61 70 70 66 73 5f 70 61 74 68 5f  rcmp(appfs_path_
3fc0: 69 6e 66 6f 5f 63 61 63 68 65 5b 68 61 73 68 5f  info_cache[hash_
3fd0: 69 64 78 5d 2e 5f 63 61 63 68 65 5f 70 61 74 68  idx]._cache_path
3fe0: 2c 20 70 61 74 68 29 20 3d 3d 20 30 20 26 26 20  , path) == 0 && 
3ff0: 61 70 70 66 73 5f 70 61 74 68 5f 69 6e 66 6f 5f  appfs_path_info_
4000: 63 61 63 68 65 5b 68 61 73 68 5f 69 64 78 5d 2e  cache[hash_idx].
4010: 5f 63 61 63 68 65 5f 75 69 64 20 3d 3d 20 75 69  _cache_uid == ui
4020: 64 29 20 7b 0a 09 09 09 09 72 65 74 76 61 6c 20  d) {.....retval 
4030: 3d 20 30 3b 0a 0a 09 09 09 09 6d 65 6d 63 70 79  = 0;......memcpy
4040: 28 70 61 74 68 69 6e 66 6f 2c 20 26 61 70 70 66  (pathinfo, &appf
4050: 73 5f 70 61 74 68 5f 69 6e 66 6f 5f 63 61 63 68  s_path_info_cach
4060: 65 5b 68 61 73 68 5f 69 64 78 5d 2c 20 73 69 7a  e[hash_idx], siz
4070: 65 6f 66 28 2a 70 61 74 68 69 6e 66 6f 29 29 3b  eof(*pathinfo));
4080: 0a 09 09 09 09 70 61 74 68 69 6e 66 6f 2d 3e 5f  .....pathinfo->_
4090: 63 61 63 68 65 5f 70 61 74 68 20 3d 20 4e 55 4c  cache_path = NUL
40a0: 4c 3b 0a 09 09 09 7d 0a 09 09 7d 0a 09 7d 0a 0a  L;....}...}..}..
40b0: 09 70 74 68 72 65 61 64 5f 72 65 74 20 3d 20 70  .pthread_ret = p
40c0: 74 68 72 65 61 64 5f 6d 75 74 65 78 5f 75 6e 6c  thread_mutex_unl
40d0: 6f 63 6b 28 26 61 70 70 66 73 5f 70 61 74 68 5f  ock(&appfs_path_
40e0: 69 6e 66 6f 5f 63 61 63 68 65 5f 6d 75 74 65 78  info_cache_mutex
40f0: 29 3b 0a 09 69 66 20 28 70 74 68 72 65 61 64 5f  );..if (pthread_
4100: 72 65 74 20 21 3d 20 30 29 20 7b 0a 09 09 41 50  ret != 0) {...AP
4110: 50 46 53 5f 44 45 42 55 47 28 22 55 6e 61 62 6c  PFS_DEBUG("Unabl
4120: 65 20 74 6f 20 75 6e 6c 6f 63 6b 20 70 61 74 68  e to unlock path
4130: 5f 69 6e 66 6f 20 63 61 63 68 65 20 6d 75 74 65  _info cache mute
4140: 78 20 21 22 29 3b 0a 0a 09 09 72 65 74 75 72 6e  x !");....return
4150: 28 2d 31 29 3b 0a 09 7d 0a 0a 09 69 66 20 28 72  (-1);..}...if (r
4160: 65 74 76 61 6c 20 3d 3d 20 30 29 20 7b 0a 09 09  etval == 0) {...
4170: 41 50 50 46 53 5f 44 45 42 55 47 28 22 43 61 63  APPFS_DEBUG("Cac
4180: 68 65 20 68 69 74 20 6f 6e 20 70 61 74 68 3d 25  he hit on path=%
4190: 73 2c 75 69 64 3d 25 6c 6c 69 22 2c 20 70 61 74  s,uid=%lli", pat
41a0: 68 2c 20 28 6c 6f 6e 67 20 6c 6f 6e 67 29 20 75  h, (long long) u
41b0: 69 64 29 3b 0a 09 7d 20 65 6c 73 65 20 7b 0a 09  id);..} else {..
41c0: 09 41 50 50 46 53 5f 44 45 42 55 47 28 22 43 61  .APPFS_DEBUG("Ca
41d0: 63 68 65 20 6d 69 73 73 20 6f 6e 20 70 61 74 68  che miss on path
41e0: 3d 25 73 2c 75 69 64 3d 25 6c 6c 69 22 2c 20 70  =%s,uid=%lli", p
41f0: 61 74 68 2c 20 28 6c 6f 6e 67 20 6c 6f 6e 67 29  ath, (long long)
4200: 20 75 69 64 29 3b 0a 09 7d 0a 0a 09 72 65 74 75   uid);..}...retu
4210: 72 6e 28 72 65 74 76 61 6c 29 3b 0a 7d 0a 0a 73  rn(retval);.}..s
4220: 74 61 74 69 63 20 76 6f 69 64 20 61 70 70 66 73  tatic void appfs
4230: 5f 67 65 74 5f 70 61 74 68 5f 69 6e 66 6f 5f 63  _get_path_info_c
4240: 61 63 68 65 5f 61 64 64 28 63 6f 6e 73 74 20 63  ache_add(const c
4250: 68 61 72 20 2a 70 61 74 68 2c 20 75 69 64 5f 74  har *path, uid_t
4260: 20 75 69 64 2c 20 73 74 72 75 63 74 20 61 70 70   uid, struct app
4270: 66 73 5f 70 61 74 68 69 6e 66 6f 20 2a 70 61 74  fs_pathinfo *pat
4280: 68 69 6e 66 6f 29 20 7b 0a 09 75 6e 73 69 67 6e  hinfo) {..unsign
4290: 65 64 20 69 6e 74 20 68 61 73 68 5f 69 64 78 3b  ed int hash_idx;
42a0: 0a 09 69 6e 74 20 70 74 68 72 65 61 64 5f 72 65  ..int pthread_re
42b0: 74 3b 0a 0a 09 70 74 68 72 65 61 64 5f 72 65 74  t;...pthread_ret
42c0: 20 3d 20 70 74 68 72 65 61 64 5f 6d 75 74 65 78   = pthread_mutex
42d0: 5f 6c 6f 63 6b 28 26 61 70 70 66 73 5f 70 61 74  _lock(&appfs_pat
42e0: 68 5f 69 6e 66 6f 5f 63 61 63 68 65 5f 6d 75 74  h_info_cache_mut
42f0: 65 78 29 3b 0a 09 69 66 20 28 70 74 68 72 65 61  ex);..if (pthrea
4300: 64 5f 72 65 74 20 21 3d 20 30 29 20 7b 0a 09 09  d_ret != 0) {...
4310: 41 50 50 46 53 5f 44 45 42 55 47 28 22 55 6e 61  APPFS_DEBUG("Una
4320: 62 6c 65 20 74 6f 20 6c 6f 63 6b 20 70 61 74 68  ble to lock path
4330: 5f 69 6e 66 6f 20 63 61 63 68 65 20 6d 75 74 65  _info cache mute
4340: 78 20 21 22 29 3b 0a 0a 09 09 72 65 74 75 72 6e  x !");....return
4350: 3b 0a 09 7d 0a 0a 09 69 66 20 28 61 70 70 66 73  ;..}...if (appfs
4360: 5f 70 61 74 68 5f 69 6e 66 6f 5f 63 61 63 68 65  _path_info_cache
4370: 20 3d 3d 20 4e 55 4c 4c 29 20 7b 0a 09 09 61 70   == NULL) {...ap
4380: 70 66 73 5f 70 61 74 68 5f 69 6e 66 6f 5f 63 61  pfs_path_info_ca
4390: 63 68 65 20 3d 20 63 61 6c 6c 6f 63 28 61 70 70  che = calloc(app
43a0: 66 73 5f 70 61 74 68 5f 69 6e 66 6f 5f 63 61 63  fs_path_info_cac
43b0: 68 65 5f 73 69 7a 65 2c 20 73 69 7a 65 6f 66 28  he_size, sizeof(
43c0: 2a 61 70 70 66 73 5f 70 61 74 68 5f 69 6e 66 6f  *appfs_path_info
43d0: 5f 63 61 63 68 65 29 29 3b 0a 09 7d 0a 0a 09 68  _cache));..}...h
43e0: 61 73 68 5f 69 64 78 20 3d 20 28 61 70 70 66 73  ash_idx = (appfs
43f0: 5f 67 65 74 5f 70 61 74 68 5f 69 6e 6f 64 65 28  _get_path_inode(
4400: 70 61 74 68 2c 20 75 69 64 29 29 20 25 20 61 70  path, uid)) % ap
4410: 70 66 73 5f 70 61 74 68 5f 69 6e 66 6f 5f 63 61  pfs_path_info_ca
4420: 63 68 65 5f 73 69 7a 65 3b 0a 0a 09 69 66 20 28  che_size;...if (
4430: 61 70 70 66 73 5f 70 61 74 68 5f 69 6e 66 6f 5f  appfs_path_info_
4440: 63 61 63 68 65 5b 68 61 73 68 5f 69 64 78 5d 2e  cache[hash_idx].
4450: 5f 63 61 63 68 65 5f 70 61 74 68 20 21 3d 20 4e  _cache_path != N
4460: 55 4c 4c 29 20 7b 0a 09 09 66 72 65 65 28 61 70  ULL) {...free(ap
4470: 70 66 73 5f 70 61 74 68 5f 69 6e 66 6f 5f 63 61  pfs_path_info_ca
4480: 63 68 65 5b 68 61 73 68 5f 69 64 78 5d 2e 5f 63  che[hash_idx]._c
4490: 61 63 68 65 5f 70 61 74 68 29 3b 0a 09 7d 0a 0a  ache_path);..}..
44a0: 09 6d 65 6d 63 70 79 28 26 61 70 70 66 73 5f 70  .memcpy(&appfs_p
44b0: 61 74 68 5f 69 6e 66 6f 5f 63 61 63 68 65 5b 68  ath_info_cache[h
44c0: 61 73 68 5f 69 64 78 5d 2c 20 70 61 74 68 69 6e  ash_idx], pathin
44d0: 66 6f 2c 20 73 69 7a 65 6f 66 28 2a 70 61 74 68  fo, sizeof(*path
44e0: 69 6e 66 6f 29 29 3b 0a 0a 09 61 70 70 66 73 5f  info));...appfs_
44f0: 70 61 74 68 5f 69 6e 66 6f 5f 63 61 63 68 65 5b  path_info_cache[
4500: 68 61 73 68 5f 69 64 78 5d 2e 5f 63 61 63 68 65  hash_idx]._cache
4510: 5f 70 61 74 68 20 3d 20 73 74 72 64 75 70 28 70  _path = strdup(p
4520: 61 74 68 29 3b 0a 09 61 70 70 66 73 5f 70 61 74  ath);..appfs_pat
4530: 68 5f 69 6e 66 6f 5f 63 61 63 68 65 5b 68 61 73  h_info_cache[has
4540: 68 5f 69 64 78 5d 2e 5f 63 61 63 68 65 5f 75 69  h_idx]._cache_ui
4550: 64 20 20 3d 20 75 69 64 3b 0a 0a 09 70 74 68 72  d  = uid;...pthr
4560: 65 61 64 5f 72 65 74 20 3d 20 70 74 68 72 65 61  ead_ret = pthrea
4570: 64 5f 6d 75 74 65 78 5f 75 6e 6c 6f 63 6b 28 26  d_mutex_unlock(&
4580: 61 70 70 66 73 5f 70 61 74 68 5f 69 6e 66 6f 5f  appfs_path_info_
4590: 63 61 63 68 65 5f 6d 75 74 65 78 29 3b 0a 09 69  cache_mutex);..i
45a0: 66 20 28 70 74 68 72 65 61 64 5f 72 65 74 20 21  f (pthread_ret !
45b0: 3d 20 30 29 20 7b 0a 09 09 41 50 50 46 53 5f 44  = 0) {...APPFS_D
45c0: 45 42 55 47 28 22 55 6e 61 62 6c 65 20 74 6f 20  EBUG("Unable to 
45d0: 75 6e 6c 6f 63 6b 20 70 61 74 68 5f 69 6e 66 6f  unlock path_info
45e0: 20 63 61 63 68 65 20 6d 75 74 65 78 20 21 22 29   cache mutex !")
45f0: 3b 0a 0a 09 09 72 65 74 75 72 6e 3b 0a 09 7d 0a  ;....return;..}.
4600: 0a 09 72 65 74 75 72 6e 3b 0a 7d 0a 0a 73 74 61  ..return;.}..sta
4610: 74 69 63 20 76 6f 69 64 20 61 70 70 66 73 5f 67  tic void appfs_g
4620: 65 74 5f 70 61 74 68 5f 69 6e 66 6f 5f 63 61 63  et_path_info_cac
4630: 68 65 5f 72 6d 28 63 6f 6e 73 74 20 63 68 61 72  he_rm(const char
4640: 20 2a 70 61 74 68 2c 20 75 69 64 5f 74 20 75 69   *path, uid_t ui
4650: 64 29 20 7b 0a 09 75 6e 73 69 67 6e 65 64 20 69  d) {..unsigned i
4660: 6e 74 20 68 61 73 68 5f 69 64 78 3b 0a 09 69 6e  nt hash_idx;..in
4670: 74 20 70 74 68 72 65 61 64 5f 72 65 74 3b 0a 0a  t pthread_ret;..
4680: 09 70 74 68 72 65 61 64 5f 72 65 74 20 3d 20 70  .pthread_ret = p
4690: 74 68 72 65 61 64 5f 6d 75 74 65 78 5f 6c 6f 63  thread_mutex_loc
46a0: 6b 28 26 61 70 70 66 73 5f 70 61 74 68 5f 69 6e  k(&appfs_path_in
46b0: 66 6f 5f 63 61 63 68 65 5f 6d 75 74 65 78 29 3b  fo_cache_mutex);
46c0: 0a 09 69 66 20 28 70 74 68 72 65 61 64 5f 72 65  ..if (pthread_re
46d0: 74 20 21 3d 20 30 29 20 7b 0a 09 09 41 50 50 46  t != 0) {...APPF
46e0: 53 5f 44 45 42 55 47 28 22 55 6e 61 62 6c 65 20  S_DEBUG("Unable 
46f0: 74 6f 20 6c 6f 63 6b 20 70 61 74 68 5f 69 6e 66  to lock path_inf
4700: 6f 20 63 61 63 68 65 20 6d 75 74 65 78 20 21 22  o cache mutex !"
4710: 29 3b 0a 0a 09 09 72 65 74 75 72 6e 3b 0a 09 7d  );....return;..}
4720: 0a 0a 09 69 66 20 28 61 70 70 66 73 5f 70 61 74  ...if (appfs_pat
4730: 68 5f 69 6e 66 6f 5f 63 61 63 68 65 20 21 3d 20  h_info_cache != 
4740: 4e 55 4c 4c 29 20 7b 0a 09 09 68 61 73 68 5f 69  NULL) {...hash_i
4750: 64 78 20 3d 20 28 61 70 70 66 73 5f 67 65 74 5f  dx = (appfs_get_
4760: 70 61 74 68 5f 69 6e 6f 64 65 28 70 61 74 68 2c  path_inode(path,
4770: 20 75 69 64 29 29 20 25 20 61 70 70 66 73 5f 70   uid)) % appfs_p
4780: 61 74 68 5f 69 6e 66 6f 5f 63 61 63 68 65 5f 73  ath_info_cache_s
4790: 69 7a 65 3b 0a 0a 09 09 69 66 20 28 61 70 70 66  ize;....if (appf
47a0: 73 5f 70 61 74 68 5f 69 6e 66 6f 5f 63 61 63 68  s_path_info_cach
47b0: 65 5b 68 61 73 68 5f 69 64 78 5d 2e 5f 63 61 63  e[hash_idx]._cac
47c0: 68 65 5f 70 61 74 68 20 21 3d 20 4e 55 4c 4c 29  he_path != NULL)
47d0: 20 7b 0a 09 09 09 66 72 65 65 28 61 70 70 66 73   {....free(appfs
47e0: 5f 70 61 74 68 5f 69 6e 66 6f 5f 63 61 63 68 65  _path_info_cache
47f0: 5b 68 61 73 68 5f 69 64 78 5d 2e 5f 63 61 63 68  [hash_idx]._cach
4800: 65 5f 70 61 74 68 29 3b 0a 0a 09 09 09 61 70 70  e_path);.....app
4810: 66 73 5f 70 61 74 68 5f 69 6e 66 6f 5f 63 61 63  fs_path_info_cac
4820: 68 65 5b 68 61 73 68 5f 69 64 78 5d 2e 5f 63 61  he[hash_idx]._ca
4830: 63 68 65 5f 70 61 74 68 20 3d 20 4e 55 4c 4c 3b  che_path = NULL;
4840: 0a 09 09 7d 0a 09 7d 0a 0a 09 70 74 68 72 65 61  ...}..}...pthrea
4850: 64 5f 72 65 74 20 3d 20 70 74 68 72 65 61 64 5f  d_ret = pthread_
4860: 6d 75 74 65 78 5f 75 6e 6c 6f 63 6b 28 26 61 70  mutex_unlock(&ap
4870: 70 66 73 5f 70 61 74 68 5f 69 6e 66 6f 5f 63 61  pfs_path_info_ca
4880: 63 68 65 5f 6d 75 74 65 78 29 3b 0a 09 69 66 20  che_mutex);..if 
4890: 28 70 74 68 72 65 61 64 5f 72 65 74 20 21 3d 20  (pthread_ret != 
48a0: 30 29 20 7b 0a 09 09 41 50 50 46 53 5f 44 45 42  0) {...APPFS_DEB
48b0: 55 47 28 22 55 6e 61 62 6c 65 20 74 6f 20 75 6e  UG("Unable to un
48c0: 6c 6f 63 6b 20 70 61 74 68 5f 69 6e 66 6f 20 63  lock path_info c
48d0: 61 63 68 65 20 6d 75 74 65 78 20 21 22 29 3b 0a  ache mutex !");.
48e0: 0a 09 09 72 65 74 75 72 6e 3b 0a 09 7d 0a 0a 09  ...return;..}...
48f0: 72 65 74 75 72 6e 3b 0a 7d 0a 0a 73 74 61 74 69  return;.}..stati
4900: 63 20 76 6f 69 64 20 61 70 70 66 73 5f 67 65 74  c void appfs_get
4910: 5f 70 61 74 68 5f 69 6e 66 6f 5f 63 61 63 68 65  _path_info_cache
4920: 5f 66 6c 75 73 68 28 75 69 64 5f 74 20 75 69 64  _flush(uid_t uid
4930: 2c 20 69 6e 74 20 6e 65 77 5f 73 69 7a 65 29 20  , int new_size) 
4940: 7b 0a 09 75 6e 73 69 67 6e 65 64 20 69 6e 74 20  {..unsigned int 
4950: 69 64 78 3b 0a 09 69 6e 74 20 70 74 68 72 65 61  idx;..int pthrea
4960: 64 5f 72 65 74 3b 0a 0a 09 41 50 50 46 53 5f 44  d_ret;...APPFS_D
4970: 45 42 55 47 28 22 46 6c 75 73 68 69 6e 67 20 41  EBUG("Flushing A
4980: 70 70 46 53 20 63 61 63 68 65 20 28 75 69 64 20  ppFS cache (uid 
4990: 3d 20 25 6c 6c 69 2c 20 6e 65 77 5f 73 69 7a 65  = %lli, new_size
49a0: 20 3d 20 25 69 29 22 2c 20 28 6c 6f 6e 67 20 6c   = %i)", (long l
49b0: 6f 6e 67 29 20 75 69 64 2c 20 6e 65 77 5f 73 69  ong) uid, new_si
49c0: 7a 65 29 3b 0a 0a 09 70 74 68 72 65 61 64 5f 72  ze);...pthread_r
49d0: 65 74 20 3d 20 70 74 68 72 65 61 64 5f 6d 75 74  et = pthread_mut
49e0: 65 78 5f 6c 6f 63 6b 28 26 61 70 70 66 73 5f 70  ex_lock(&appfs_p
49f0: 61 74 68 5f 69 6e 66 6f 5f 63 61 63 68 65 5f 6d  ath_info_cache_m
4a00: 75 74 65 78 29 3b 0a 09 69 66 20 28 70 74 68 72  utex);..if (pthr
4a10: 65 61 64 5f 72 65 74 20 21 3d 20 30 29 20 7b 0a  ead_ret != 0) {.
4a20: 09 09 41 50 50 46 53 5f 44 45 42 55 47 28 22 55  ..APPFS_DEBUG("U
4a30: 6e 61 62 6c 65 20 74 6f 20 6c 6f 63 6b 20 70 61  nable to lock pa
4a40: 74 68 5f 69 6e 66 6f 20 63 61 63 68 65 20 6d 75  th_info cache mu
4a50: 74 65 78 20 21 22 29 3b 0a 0a 09 09 72 65 74 75  tex !");....retu
4a60: 72 6e 3b 0a 09 7d 0a 0a 09 69 66 20 28 61 70 70  rn;..}...if (app
4a70: 66 73 5f 70 61 74 68 5f 69 6e 66 6f 5f 63 61 63  fs_path_info_cac
4a80: 68 65 20 21 3d 20 4e 55 4c 4c 29 20 7b 0a 09 09  he != NULL) {...
4a90: 66 6f 72 20 28 69 64 78 20 3d 20 30 3b 20 69 64  for (idx = 0; id
4aa0: 78 20 3c 20 61 70 70 66 73 5f 70 61 74 68 5f 69  x < appfs_path_i
4ab0: 6e 66 6f 5f 63 61 63 68 65 5f 73 69 7a 65 3b 20  nfo_cache_size; 
4ac0: 69 64 78 2b 2b 29 20 7b 0a 09 09 09 69 66 20 28  idx++) {....if (
4ad0: 61 70 70 66 73 5f 70 61 74 68 5f 69 6e 66 6f 5f  appfs_path_info_
4ae0: 63 61 63 68 65 5b 69 64 78 5d 2e 5f 63 61 63 68  cache[idx]._cach
4af0: 65 5f 70 61 74 68 20 21 3d 20 4e 55 4c 4c 29 20  e_path != NULL) 
4b00: 7b 0a 09 09 09 09 69 66 20 28 75 69 64 20 21 3d  {.....if (uid !=
4b10: 20 28 28 75 69 64 5f 74 29 20 2d 31 29 29 20 7b   ((uid_t) -1)) {
4b20: 0a 09 09 09 09 09 69 66 20 28 61 70 70 66 73 5f  ......if (appfs_
4b30: 70 61 74 68 5f 69 6e 66 6f 5f 63 61 63 68 65 5b  path_info_cache[
4b40: 69 64 78 5d 2e 5f 63 61 63 68 65 5f 75 69 64 20  idx]._cache_uid 
4b50: 21 3d 20 75 69 64 29 20 7b 0a 09 09 09 09 09 09  != uid) {.......
4b60: 63 6f 6e 74 69 6e 75 65 3b 0a 09 09 09 09 09 7d  continue;......}
4b70: 0a 09 09 09 09 7d 0a 0a 09 09 09 09 66 72 65 65  .....}......free
4b80: 28 61 70 70 66 73 5f 70 61 74 68 5f 69 6e 66 6f  (appfs_path_info
4b90: 5f 63 61 63 68 65 5b 69 64 78 5d 2e 5f 63 61 63  _cache[idx]._cac
4ba0: 68 65 5f 70 61 74 68 29 3b 0a 0a 09 09 09 09 61  he_path);......a
4bb0: 70 70 66 73 5f 70 61 74 68 5f 69 6e 66 6f 5f 63  ppfs_path_info_c
4bc0: 61 63 68 65 5b 69 64 78 5d 2e 5f 63 61 63 68 65  ache[idx]._cache
4bd0: 5f 70 61 74 68 20 3d 20 4e 55 4c 4c 3b 0a 09 09  _path = NULL;...
4be0: 09 7d 0a 09 09 7d 0a 09 7d 0a 0a 09 69 66 20 28  .}...}..}...if (
4bf0: 75 69 64 20 3d 3d 20 28 28 75 69 64 5f 74 29 20  uid == ((uid_t) 
4c00: 2d 31 29 29 20 7b 0a 09 09 66 72 65 65 28 61 70  -1)) {...free(ap
4c10: 70 66 73 5f 70 61 74 68 5f 69 6e 66 6f 5f 63 61  pfs_path_info_ca
4c20: 63 68 65 29 3b 0a 0a 09 09 61 70 70 66 73 5f 70  che);....appfs_p
4c30: 61 74 68 5f 69 6e 66 6f 5f 63 61 63 68 65 20 3d  ath_info_cache =
4c40: 20 4e 55 4c 4c 3b 0a 0a 09 09 69 66 20 28 6e 65   NULL;....if (ne
4c50: 77 5f 73 69 7a 65 20 21 3d 20 2d 31 29 20 7b 0a  w_size != -1) {.
4c60: 09 09 09 61 70 70 66 73 5f 70 61 74 68 5f 69 6e  ...appfs_path_in
4c70: 66 6f 5f 63 61 63 68 65 5f 73 69 7a 65 20 3d 20  fo_cache_size = 
4c80: 6e 65 77 5f 73 69 7a 65 3b 0a 09 09 7d 0a 09 7d  new_size;...}..}
4c90: 0a 0a 09 70 74 68 72 65 61 64 5f 72 65 74 20 3d  ...pthread_ret =
4ca0: 20 70 74 68 72 65 61 64 5f 6d 75 74 65 78 5f 75   pthread_mutex_u
4cb0: 6e 6c 6f 63 6b 28 26 61 70 70 66 73 5f 70 61 74  nlock(&appfs_pat
4cc0: 68 5f 69 6e 66 6f 5f 63 61 63 68 65 5f 6d 75 74  h_info_cache_mut
4cd0: 65 78 29 3b 0a 09 69 66 20 28 70 74 68 72 65 61  ex);..if (pthrea
4ce0: 64 5f 72 65 74 20 21 3d 20 30 29 20 7b 0a 09 09  d_ret != 0) {...
4cf0: 41 50 50 46 53 5f 44 45 42 55 47 28 22 55 6e 61  APPFS_DEBUG("Una
4d00: 62 6c 65 20 74 6f 20 75 6e 6c 6f 63 6b 20 70 61  ble to unlock pa
4d10: 74 68 5f 69 6e 66 6f 20 63 61 63 68 65 20 6d 75  th_info cache mu
4d20: 74 65 78 20 21 22 29 3b 0a 0a 09 09 72 65 74 75  tex !");....retu
4d30: 72 6e 3b 0a 09 7d 0a 0a 09 72 65 74 75 72 6e 3b  rn;..}...return;
4d40: 0a 7d 0a 0a 2f 2a 20 47 65 74 20 69 6e 66 6f 72  .}../* Get infor
4d50: 6d 61 74 69 6f 6e 20 61 62 6f 75 74 20 61 20 70  mation about a p
4d60: 61 74 68 2c 20 61 6e 64 20 6f 70 74 69 6f 6e 61  ath, and optiona
4d70: 6c 6c 79 20 6c 69 73 74 20 63 68 69 6c 64 72 65  lly list childre
4d80: 6e 20 2a 2f 0a 73 74 61 74 69 63 20 69 6e 74 20  n */.static int 
4d90: 61 70 70 66 73 5f 67 65 74 5f 70 61 74 68 5f 69  appfs_get_path_i
4da0: 6e 66 6f 28 63 6f 6e 73 74 20 63 68 61 72 20 2a  nfo(const char *
4db0: 70 61 74 68 2c 20 73 74 72 75 63 74 20 61 70 70  path, struct app
4dc0: 66 73 5f 70 61 74 68 69 6e 66 6f 20 2a 70 61 74  fs_pathinfo *pat
4dd0: 68 69 6e 66 6f 29 20 7b 0a 09 54 63 6c 5f 49 6e  hinfo) {..Tcl_In
4de0: 74 65 72 70 20 2a 69 6e 74 65 72 70 3b 0a 09 54  terp *interp;..T
4df0: 63 6c 5f 4f 62 6a 20 2a 61 74 74 72 73 5f 64 69  cl_Obj *attrs_di
4e00: 63 74 2c 20 2a 61 74 74 72 5f 76 61 6c 75 65 3b  ct, *attr_value;
4e10: 0a 09 63 6f 6e 73 74 20 63 68 61 72 20 2a 61 74  ..const char *at
4e20: 74 72 5f 76 61 6c 75 65 5f 73 74 72 2c 20 2a 61  tr_value_str, *a
4e30: 74 74 72 5f 76 61 6c 75 65 5f 73 74 72 5f 69 3b  ttr_value_str_i;
4e40: 0a 09 54 63 6c 5f 57 69 64 65 49 6e 74 20 61 74  ..Tcl_WideInt at
4e50: 74 72 5f 76 61 6c 75 65 5f 77 69 64 65 3b 0a 09  tr_value_wide;..
4e60: 69 6e 74 20 61 74 74 72 5f 76 61 6c 75 65 5f 69  int attr_value_i
4e70: 6e 74 3b 0a 09 73 74 61 74 69 63 20 5f 5f 74 68  nt;..static __th
4e80: 72 65 61 64 20 54 63 6c 5f 4f 62 6a 20 2a 61 74  read Tcl_Obj *at
4e90: 74 72 5f 6b 65 79 5f 74 79 70 65 20 3d 20 4e 55  tr_key_type = NU
4ea0: 4c 4c 2c 20 2a 61 74 74 72 5f 6b 65 79 5f 70 65  LL, *attr_key_pe
4eb0: 72 6d 73 20 3d 20 4e 55 4c 4c 2c 20 2a 61 74 74  rms = NULL, *att
4ec0: 72 5f 6b 65 79 5f 73 69 7a 65 20 3d 20 4e 55 4c  r_key_size = NUL
4ed0: 4c 2c 20 2a 61 74 74 72 5f 6b 65 79 5f 74 69 6d  L, *attr_key_tim
4ee0: 65 20 3d 20 4e 55 4c 4c 2c 20 2a 61 74 74 72 5f  e = NULL, *attr_
4ef0: 6b 65 79 5f 73 6f 75 72 63 65 20 3d 20 4e 55 4c  key_source = NUL
4f00: 4c 2c 20 2a 61 74 74 72 5f 6b 65 79 5f 63 68 69  L, *attr_key_chi
4f10: 6c 64 63 6f 75 6e 74 20 3d 20 4e 55 4c 4c 2c 20  ldcount = NULL, 
4f20: 2a 61 74 74 72 5f 6b 65 79 5f 70 61 63 6b 61 67  *attr_key_packag
4f30: 65 64 20 3d 20 4e 55 4c 4c 3b 0a 09 69 6e 74 20  ed = NULL;..int 
4f40: 63 61 63 68 65 5f 72 65 74 3b 0a 09 69 6e 74 20  cache_ret;..int 
4f50: 74 63 6c 5f 72 65 74 3b 0a 09 69 6e 74 20 72 65  tcl_ret;..int re
4f60: 74 76 61 6c 3b 0a 09 75 69 64 5f 74 20 66 73 75  tval;..uid_t fsu
4f70: 69 64 3b 0a 0a 09 72 65 74 76 61 6c 20 3d 20 30  id;...retval = 0
4f80: 3b 0a 0a 09 66 73 75 69 64 20 3d 20 61 70 70 66  ;...fsuid = appf
4f90: 73 5f 67 65 74 5f 66 73 75 69 64 28 29 3b 0a 0a  s_get_fsuid();..
4fa0: 09 63 61 63 68 65 5f 72 65 74 20 3d 20 61 70 70  .cache_ret = app
4fb0: 66 73 5f 67 65 74 5f 70 61 74 68 5f 69 6e 66 6f  fs_get_path_info
4fc0: 5f 63 61 63 68 65 5f 67 65 74 28 70 61 74 68 2c  _cache_get(path,
4fd0: 20 66 73 75 69 64 2c 20 70 61 74 68 69 6e 66 6f   fsuid, pathinfo
4fe0: 29 3b 0a 09 69 66 20 28 63 61 63 68 65 5f 72 65  );..if (cache_re
4ff0: 74 20 3d 3d 20 30 29 20 7b 0a 09 09 69 66 20 28  t == 0) {...if (
5000: 70 61 74 68 69 6e 66 6f 2d 3e 74 79 70 65 20 3d  pathinfo->type =
5010: 3d 20 41 50 50 46 53 5f 50 41 54 48 54 59 50 45  = APPFS_PATHTYPE
5020: 5f 44 4f 45 53 5f 4e 4f 54 5f 45 58 49 53 54 29  _DOES_NOT_EXIST)
5030: 20 7b 0a 09 09 09 41 50 50 46 53 5f 44 45 42 55   {....APPFS_DEBU
5040: 47 28 22 52 65 74 75 72 6e 69 6e 67 20 66 72 6f  G("Returning fro
5050: 6d 20 63 61 63 68 65 3a 20 64 6f 65 73 20 6e 6f  m cache: does no
5060: 74 20 65 78 69 73 74 20 5c 22 25 73 5c 22 22 2c  t exist \"%s\"",
5070: 20 70 61 74 68 29 3b 0a 0a 09 09 09 72 65 74 75   path);.....retu
5080: 72 6e 28 2d 45 4e 4f 45 4e 54 29 3b 0a 09 09 7d  rn(-ENOENT);...}
5090: 0a 0a 09 09 69 66 20 28 70 61 74 68 69 6e 66 6f  ....if (pathinfo
50a0: 2d 3e 74 79 70 65 20 3d 3d 20 41 50 50 46 53 5f  ->type == APPFS_
50b0: 50 41 54 48 54 59 50 45 5f 49 4e 56 41 4c 49 44  PATHTYPE_INVALID
50c0: 29 20 7b 0a 09 09 09 41 50 50 46 53 5f 44 45 42  ) {....APPFS_DEB
50d0: 55 47 28 22 52 65 74 75 72 6e 69 6e 67 20 66 72  UG("Returning fr
50e0: 6f 6d 20 63 61 63 68 65 3a 20 69 6e 76 61 6c 69  om cache: invali
50f0: 64 20 6f 62 6a 65 63 74 20 5c 22 25 73 5c 22 22  d object \"%s\""
5100: 2c 20 70 61 74 68 29 3b 0a 0a 09 09 09 72 65 74  , path);.....ret
5110: 75 72 6e 28 2d 45 49 4f 29 3b 0a 09 09 7d 0a 0a  urn(-EIO);...}..
5120: 09 09 72 65 74 75 72 6e 28 30 29 3b 0a 09 7d 0a  ..return(0);..}.
5130: 0a 09 69 6e 74 65 72 70 20 3d 20 61 70 70 66 73  ..interp = appfs
5140: 5f 54 63 6c 49 6e 74 65 72 70 28 29 3b 0a 09 69  _TclInterp();..i
5150: 66 20 28 69 6e 74 65 72 70 20 3d 3d 20 4e 55 4c  f (interp == NUL
5160: 4c 29 20 7b 0a 09 09 41 50 50 46 53 5f 44 45 42  L) {...APPFS_DEB
5170: 55 47 28 22 65 72 72 6f 72 3a 20 55 6e 61 62 6c  UG("error: Unabl
5180: 65 20 74 6f 20 67 65 74 20 61 6e 20 69 6e 74 65  e to get an inte
5190: 72 70 72 65 74 65 72 22 29 3b 0a 0a 09 09 72 65  rpreter");....re
51a0: 74 75 72 6e 28 2d 45 49 4f 29 3b 0a 09 7d 0a 0a  turn(-EIO);..}..
51b0: 09 61 70 70 66 73 5f 63 61 6c 6c 5f 6c 69 62 74  .appfs_call_libt
51c0: 63 6c 28 54 63 6c 5f 50 72 65 73 65 72 76 65 28  cl(Tcl_Preserve(
51d0: 69 6e 74 65 72 70 29 3b 29 0a 0a 09 74 63 6c 5f  interp);)...tcl_
51e0: 72 65 74 20 3d 20 61 70 70 66 73 5f 54 63 6c 5f  ret = appfs_Tcl_
51f0: 45 76 61 6c 28 69 6e 74 65 72 70 2c 20 32 2c 20  Eval(interp, 2, 
5200: 22 3a 3a 61 70 70 66 73 3a 3a 67 65 74 61 74 74  "::appfs::getatt
5210: 72 22 2c 20 70 61 74 68 29 3b 0a 09 69 66 20 28  r", path);..if (
5220: 74 63 6c 5f 72 65 74 20 21 3d 20 54 43 4c 5f 4f  tcl_ret != TCL_O
5230: 4b 29 20 7b 0a 09 09 41 50 50 46 53 5f 44 45 42  K) {...APPFS_DEB
5240: 55 47 28 22 3a 3a 61 70 70 66 73 3a 3a 67 65 74  UG("::appfs::get
5250: 61 74 74 72 28 25 73 29 20 66 61 69 6c 65 64 2e  attr(%s) failed.
5260: 22 2c 20 70 61 74 68 29 3b 0a 09 09 61 70 70 66  ", path);...appf
5270: 73 5f 63 61 6c 6c 5f 6c 69 62 74 63 6c 28 0a 09  s_call_libtcl(..
5280: 09 09 41 50 50 46 53 5f 44 45 42 55 47 28 22 54  ..APPFS_DEBUG("T
5290: 63 6c 20 45 72 72 6f 72 20 69 73 3a 20 25 73 22  cl Error is: %s"
52a0: 2c 20 54 63 6c 5f 47 65 74 53 74 72 69 6e 67 52  , Tcl_GetStringR
52b0: 65 73 75 6c 74 28 69 6e 74 65 72 70 29 29 3b 0a  esult(interp));.
52c0: 09 09 29 0a 0a 09 09 70 61 74 68 69 6e 66 6f 2d  ..)....pathinfo-
52d0: 3e 74 79 70 65 20 3d 20 41 50 50 46 53 5f 50 41  >type = APPFS_PA
52e0: 54 48 54 59 50 45 5f 44 4f 45 53 5f 4e 4f 54 5f  THTYPE_DOES_NOT_
52f0: 45 58 49 53 54 3b 0a 0a 09 09 61 70 70 66 73 5f  EXIST;....appfs_
5300: 67 65 74 5f 70 61 74 68 5f 69 6e 66 6f 5f 63 61  get_path_info_ca
5310: 63 68 65 5f 61 64 64 28 70 61 74 68 2c 20 66 73  che_add(path, fs
5320: 75 69 64 2c 20 70 61 74 68 69 6e 66 6f 29 3b 0a  uid, pathinfo);.
5330: 0a 09 09 61 70 70 66 73 5f 63 61 6c 6c 5f 6c 69  ...appfs_call_li
5340: 62 74 63 6c 28 54 63 6c 5f 52 65 6c 65 61 73 65  btcl(Tcl_Release
5350: 28 69 6e 74 65 72 70 29 3b 29 0a 0a 09 09 72 65  (interp);)....re
5360: 74 75 72 6e 28 2d 45 4e 4f 45 4e 54 29 3b 0a 09  turn(-ENOENT);..
5370: 7d 0a 0a 09 69 66 20 28 61 74 74 72 5f 6b 65 79  }...if (attr_key
5380: 5f 74 79 70 65 20 3d 3d 20 4e 55 4c 4c 29 20 7b  _type == NULL) {
5390: 0a 09 09 61 70 70 66 73 5f 63 61 6c 6c 5f 6c 69  ...appfs_call_li
53a0: 62 74 63 6c 28 0a 09 09 09 61 74 74 72 5f 6b 65  btcl(....attr_ke
53b0: 79 5f 74 79 70 65 20 20 20 20 20 20 20 3d 20 54  y_type       = T
53c0: 63 6c 5f 4e 65 77 53 74 72 69 6e 67 4f 62 6a 28  cl_NewStringObj(
53d0: 22 74 79 70 65 22 2c 20 2d 31 29 3b 0a 09 09 09  "type", -1);....
53e0: 61 74 74 72 5f 6b 65 79 5f 70 65 72 6d 73 20 20  attr_key_perms  
53f0: 20 20 20 20 3d 20 54 63 6c 5f 4e 65 77 53 74 72      = Tcl_NewStr
5400: 69 6e 67 4f 62 6a 28 22 70 65 72 6d 73 22 2c 20  ingObj("perms", 
5410: 2d 31 29 3b 0a 09 09 09 61 74 74 72 5f 6b 65 79  -1);....attr_key
5420: 5f 73 69 7a 65 20 20 20 20 20 20 20 3d 20 54 63  _size       = Tc
5430: 6c 5f 4e 65 77 53 74 72 69 6e 67 4f 62 6a 28 22  l_NewStringObj("
5440: 73 69 7a 65 22 2c 20 2d 31 29 3b 0a 09 09 09 61  size", -1);....a
5450: 74 74 72 5f 6b 65 79 5f 74 69 6d 65 20 20 20 20  ttr_key_time    
5460: 20 20 20 3d 20 54 63 6c 5f 4e 65 77 53 74 72 69     = Tcl_NewStri
5470: 6e 67 4f 62 6a 28 22 74 69 6d 65 22 2c 20 2d 31  ngObj("time", -1
5480: 29 3b 0a 09 09 09 61 74 74 72 5f 6b 65 79 5f 73  );....attr_key_s
5490: 6f 75 72 63 65 20 20 20 20 20 3d 20 54 63 6c 5f  ource     = Tcl_
54a0: 4e 65 77 53 74 72 69 6e 67 4f 62 6a 28 22 73 6f  NewStringObj("so
54b0: 75 72 63 65 22 2c 20 2d 31 29 3b 0a 09 09 09 61  urce", -1);....a
54c0: 74 74 72 5f 6b 65 79 5f 63 68 69 6c 64 63 6f 75  ttr_key_childcou
54d0: 6e 74 20 3d 20 54 63 6c 5f 4e 65 77 53 74 72 69  nt = Tcl_NewStri
54e0: 6e 67 4f 62 6a 28 22 63 68 69 6c 64 63 6f 75 6e  ngObj("childcoun
54f0: 74 22 2c 20 2d 31 29 3b 0a 09 09 09 61 74 74 72  t", -1);....attr
5500: 5f 6b 65 79 5f 70 61 63 6b 61 67 65 64 20 20 20  _key_packaged   
5510: 3d 20 54 63 6c 5f 4e 65 77 53 74 72 69 6e 67 4f  = Tcl_NewStringO
5520: 62 6a 28 22 70 61 63 6b 61 67 65 64 22 2c 20 2d  bj("packaged", -
5530: 31 29 3b 0a 0a 09 09 09 54 63 6c 5f 49 6e 63 72  1);.....Tcl_Incr
5540: 52 65 66 43 6f 75 6e 74 28 61 74 74 72 5f 6b 65  RefCount(attr_ke
5550: 79 5f 74 79 70 65 29 3b 0a 09 09 09 54 63 6c 5f  y_type);....Tcl_
5560: 49 6e 63 72 52 65 66 43 6f 75 6e 74 28 61 74 74  IncrRefCount(att
5570: 72 5f 6b 65 79 5f 70 65 72 6d 73 29 3b 0a 09 09  r_key_perms);...
5580: 09 54 63 6c 5f 49 6e 63 72 52 65 66 43 6f 75 6e  .Tcl_IncrRefCoun
5590: 74 28 61 74 74 72 5f 6b 65 79 5f 73 69 7a 65 29  t(attr_key_size)
55a0: 3b 0a 09 09 09 54 63 6c 5f 49 6e 63 72 52 65 66  ;....Tcl_IncrRef
55b0: 43 6f 75 6e 74 28 61 74 74 72 5f 6b 65 79 5f 74  Count(attr_key_t
55c0: 69 6d 65 29 3b 0a 09 09 09 54 63 6c 5f 49 6e 63  ime);....Tcl_Inc
55d0: 72 52 65 66 43 6f 75 6e 74 28 61 74 74 72 5f 6b  rRefCount(attr_k
55e0: 65 79 5f 73 6f 75 72 63 65 29 3b 0a 09 09 09 54  ey_source);....T
55f0: 63 6c 5f 49 6e 63 72 52 65 66 43 6f 75 6e 74 28  cl_IncrRefCount(
5600: 61 74 74 72 5f 6b 65 79 5f 63 68 69 6c 64 63 6f  attr_key_childco
5610: 75 6e 74 29 3b 0a 09 09 09 54 63 6c 5f 49 6e 63  unt);....Tcl_Inc
5620: 72 52 65 66 43 6f 75 6e 74 28 61 74 74 72 5f 6b  rRefCount(attr_k
5630: 65 79 5f 70 61 63 6b 61 67 65 64 29 3b 0a 09 09  ey_packaged);...
5640: 29 0a 09 7d 0a 0a 09 61 70 70 66 73 5f 63 61 6c  )..}...appfs_cal
5650: 6c 5f 6c 69 62 74 63 6c 28 0a 09 09 61 74 74 72  l_libtcl(...attr
5660: 73 5f 64 69 63 74 20 3d 20 54 63 6c 5f 47 65 74  s_dict = Tcl_Get
5670: 4f 62 6a 52 65 73 75 6c 74 28 69 6e 74 65 72 70  ObjResult(interp
5680: 29 3b 0a 09 09 74 63 6c 5f 72 65 74 20 3d 20 54  );...tcl_ret = T
5690: 63 6c 5f 44 69 63 74 4f 62 6a 47 65 74 28 69 6e  cl_DictObjGet(in
56a0: 74 65 72 70 2c 20 61 74 74 72 73 5f 64 69 63 74  terp, attrs_dict
56b0: 2c 20 61 74 74 72 5f 6b 65 79 5f 74 79 70 65 2c  , attr_key_type,
56c0: 20 26 61 74 74 72 5f 76 61 6c 75 65 29 3b 0a 09   &attr_value);..
56d0: 29 0a 09 69 66 20 28 74 63 6c 5f 72 65 74 20 21  )..if (tcl_ret !
56e0: 3d 20 54 43 4c 5f 4f 4b 29 20 7b 0a 09 09 41 50  = TCL_OK) {...AP
56f0: 50 46 53 5f 44 45 42 55 47 28 22 5b 64 69 63 74  PFS_DEBUG("[dict
5700: 20 67 65 74 20 5c 22 74 79 70 65 5c 22 5d 20 66   get \"type\"] f
5710: 61 69 6c 65 64 22 29 3b 0a 09 09 61 70 70 66 73  ailed");...appfs
5720: 5f 63 61 6c 6c 5f 6c 69 62 74 63 6c 28 0a 09 09  _call_libtcl(...
5730: 09 41 50 50 46 53 5f 44 45 42 55 47 28 22 54 63  .APPFS_DEBUG("Tc
5740: 6c 20 45 72 72 6f 72 20 69 73 3a 20 25 73 22 2c  l Error is: %s",
5750: 20 54 63 6c 5f 47 65 74 53 74 72 69 6e 67 52 65   Tcl_GetStringRe
5760: 73 75 6c 74 28 69 6e 74 65 72 70 29 29 3b 0a 09  sult(interp));..
5770: 09 29 0a 0a 09 09 61 70 70 66 73 5f 63 61 6c 6c  .)....appfs_call
5780: 5f 6c 69 62 74 63 6c 28 54 63 6c 5f 52 65 6c 65  _libtcl(Tcl_Rele
5790: 61 73 65 28 69 6e 74 65 72 70 29 3b 29 0a 0a 09  ase(interp);)...
57a0: 09 72 65 74 75 72 6e 28 2d 45 49 4f 29 3b 0a 09  .return(-EIO);..
57b0: 7d 0a 0a 09 69 66 20 28 61 74 74 72 5f 76 61 6c  }...if (attr_val
57c0: 75 65 20 3d 3d 20 4e 55 4c 4c 29 20 7b 0a 09 09  ue == NULL) {...
57d0: 41 50 50 46 53 5f 44 45 42 55 47 28 22 65 72 72  APPFS_DEBUG("err
57e0: 6f 72 3a 20 55 6e 61 62 6c 65 20 74 6f 20 67 65  or: Unable to ge
57f0: 74 20 74 79 70 65 20 66 6f 72 20 5c 22 25 73 5c  t type for \"%s\
5800: 22 20 66 72 6f 6d 20 54 63 6c 22 2c 20 70 61 74  " from Tcl", pat
5810: 68 29 3b 0a 0a 09 09 61 70 70 66 73 5f 63 61 6c  h);....appfs_cal
5820: 6c 5f 6c 69 62 74 63 6c 28 54 63 6c 5f 52 65 6c  l_libtcl(Tcl_Rel
5830: 65 61 73 65 28 69 6e 74 65 72 70 29 3b 29 0a 0a  ease(interp);)..
5840: 09 09 72 65 74 75 72 6e 28 2d 45 49 4f 29 3b 0a  ..return(-EIO);.
5850: 09 7d 0a 0a 09 70 61 74 68 69 6e 66 6f 2d 3e 70  .}...pathinfo->p
5860: 61 63 6b 61 67 65 64 20 3d 20 30 3b 0a 0a 09 61  ackaged = 0;...a
5870: 70 70 66 73 5f 63 61 6c 6c 5f 6c 69 62 74 63 6c  ppfs_call_libtcl
5880: 28 0a 09 09 61 74 74 72 5f 76 61 6c 75 65 5f 73  (...attr_value_s
5890: 74 72 20 3d 20 54 63 6c 5f 47 65 74 53 74 72 69  tr = Tcl_GetStri
58a0: 6e 67 28 61 74 74 72 5f 76 61 6c 75 65 29 3b 0a  ng(attr_value);.
58b0: 0a 09 09 73 77 69 74 63 68 20 28 61 74 74 72 5f  ...switch (attr_
58c0: 76 61 6c 75 65 5f 73 74 72 5b 30 5d 29 20 7b 0a  value_str[0]) {.
58d0: 09 09 09 63 61 73 65 20 27 64 27 3a 20 2f 2a 20  ...case 'd': /* 
58e0: 64 69 72 65 63 74 6f 72 79 20 2a 2f 0a 09 09 09  directory */....
58f0: 09 70 61 74 68 69 6e 66 6f 2d 3e 74 79 70 65 20  .pathinfo->type 
5900: 3d 20 41 50 50 46 53 5f 50 41 54 48 54 59 50 45  = APPFS_PATHTYPE
5910: 5f 44 49 52 45 43 54 4f 52 59 3b 0a 09 09 09 09  _DIRECTORY;.....
5920: 70 61 74 68 69 6e 66 6f 2d 3e 74 79 70 65 69 6e  pathinfo->typein
5930: 66 6f 2e 64 69 72 2e 63 68 69 6c 64 63 6f 75 6e  fo.dir.childcoun
5940: 74 20 3d 20 30 3b 0a 0a 09 09 09 09 54 63 6c 5f  t = 0;......Tcl_
5950: 44 69 63 74 4f 62 6a 47 65 74 28 69 6e 74 65 72  DictObjGet(inter
5960: 70 2c 20 61 74 74 72 73 5f 64 69 63 74 2c 20 61  p, attrs_dict, a
5970: 74 74 72 5f 6b 65 79 5f 63 68 69 6c 64 63 6f 75  ttr_key_childcou
5980: 6e 74 2c 20 26 61 74 74 72 5f 76 61 6c 75 65 29  nt, &attr_value)
5990: 3b 0a 09 09 09 09 69 66 20 28 61 74 74 72 5f 76  ;.....if (attr_v
59a0: 61 6c 75 65 20 21 3d 20 4e 55 4c 4c 29 20 7b 0a  alue != NULL) {.
59b0: 09 09 09 09 09 74 63 6c 5f 72 65 74 20 3d 20 54  .....tcl_ret = T
59c0: 63 6c 5f 47 65 74 57 69 64 65 49 6e 74 46 72 6f  cl_GetWideIntFro
59d0: 6d 4f 62 6a 28 4e 55 4c 4c 2c 20 61 74 74 72 5f  mObj(NULL, attr_
59e0: 76 61 6c 75 65 2c 20 26 61 74 74 72 5f 76 61 6c  value, &attr_val
59f0: 75 65 5f 77 69 64 65 29 3b 0a 09 09 09 09 09 69  ue_wide);......i
5a00: 66 20 28 74 63 6c 5f 72 65 74 20 3d 3d 20 54 43  f (tcl_ret == TC
5a10: 4c 5f 4f 4b 29 20 7b 0a 09 09 09 09 09 09 70 61  L_OK) {.......pa
5a20: 74 68 69 6e 66 6f 2d 3e 74 79 70 65 69 6e 66 6f  thinfo->typeinfo
5a30: 2e 64 69 72 2e 63 68 69 6c 64 63 6f 75 6e 74 20  .dir.childcount 
5a40: 3d 20 61 74 74 72 5f 76 61 6c 75 65 5f 77 69 64  = attr_value_wid
5a50: 65 3b 0a 09 09 09 09 09 7d 0a 09 09 09 09 7d 0a  e;......}.....}.
5a60: 0a 09 09 09 09 62 72 65 61 6b 3b 0a 09 09 09 63  .....break;....c
5a70: 61 73 65 20 27 66 27 3a 20 2f 2a 20 66 69 6c 65  ase 'f': /* file
5a80: 20 2a 2f 0a 09 09 09 09 70 61 74 68 69 6e 66 6f   */.....pathinfo
5a90: 2d 3e 74 79 70 65 20 3d 20 41 50 50 46 53 5f 50  ->type = APPFS_P
5aa0: 41 54 48 54 59 50 45 5f 46 49 4c 45 3b 0a 09 09  ATHTYPE_FILE;...
5ab0: 09 09 70 61 74 68 69 6e 66 6f 2d 3e 74 79 70 65  ..pathinfo->type
5ac0: 69 6e 66 6f 2e 66 69 6c 65 2e 73 69 7a 65 20 3d  info.file.size =
5ad0: 20 30 3b 0a 09 09 09 09 70 61 74 68 69 6e 66 6f   0;.....pathinfo
5ae0: 2d 3e 74 79 70 65 69 6e 66 6f 2e 66 69 6c 65 2e  ->typeinfo.file.
5af0: 65 78 65 63 75 74 61 62 6c 65 20 3d 20 30 3b 0a  executable = 0;.
5b00: 09 09 09 09 70 61 74 68 69 6e 66 6f 2d 3e 74 79  ....pathinfo->ty
5b10: 70 65 69 6e 66 6f 2e 66 69 6c 65 2e 73 75 69 64  peinfo.file.suid
5b20: 52 6f 6f 74 20 3d 20 30 3b 0a 09 09 09 09 70 61  Root = 0;.....pa
5b30: 74 68 69 6e 66 6f 2d 3e 74 79 70 65 69 6e 66 6f  thinfo->typeinfo
5b40: 2e 66 69 6c 65 2e 77 6f 72 6c 64 61 63 63 65 73  .file.worldacces
5b50: 73 69 62 6c 65 20 3d 20 30 3b 0a 0a 09 09 09 09  sible = 0;......
5b60: 54 63 6c 5f 44 69 63 74 4f 62 6a 47 65 74 28 69  Tcl_DictObjGet(i
5b70: 6e 74 65 72 70 2c 20 61 74 74 72 73 5f 64 69 63  nterp, attrs_dic
5b80: 74 2c 20 61 74 74 72 5f 6b 65 79 5f 73 69 7a 65  t, attr_key_size
5b90: 2c 20 26 61 74 74 72 5f 76 61 6c 75 65 29 3b 0a  , &attr_value);.
5ba0: 09 09 09 09 69 66 20 28 61 74 74 72 5f 76 61 6c  ....if (attr_val
5bb0: 75 65 20 21 3d 20 4e 55 4c 4c 29 20 7b 0a 09 09  ue != NULL) {...
5bc0: 09 09 09 74 63 6c 5f 72 65 74 20 3d 20 54 63 6c  ...tcl_ret = Tcl
5bd0: 5f 47 65 74 57 69 64 65 49 6e 74 46 72 6f 6d 4f  _GetWideIntFromO
5be0: 62 6a 28 4e 55 4c 4c 2c 20 61 74 74 72 5f 76 61  bj(NULL, attr_va
5bf0: 6c 75 65 2c 20 26 61 74 74 72 5f 76 61 6c 75 65  lue, &attr_value
5c00: 5f 77 69 64 65 29 3b 0a 09 09 09 09 09 69 66 20  _wide);......if 
5c10: 28 74 63 6c 5f 72 65 74 20 3d 3d 20 54 43 4c 5f  (tcl_ret == TCL_
5c20: 4f 4b 29 20 7b 0a 09 09 09 09 09 09 70 61 74 68  OK) {.......path
5c30: 69 6e 66 6f 2d 3e 74 79 70 65 69 6e 66 6f 2e 66  info->typeinfo.f
5c40: 69 6c 65 2e 73 69 7a 65 20 3d 20 61 74 74 72 5f  ile.size = attr_
5c50: 76 61 6c 75 65 5f 77 69 64 65 3b 0a 09 09 09 09  value_wide;.....
5c60: 09 7d 0a 09 09 09 09 7d 0a 0a 09 09 09 09 54 63  .}.....}......Tc
5c70: 6c 5f 44 69 63 74 4f 62 6a 47 65 74 28 69 6e 74  l_DictObjGet(int
5c80: 65 72 70 2c 20 61 74 74 72 73 5f 64 69 63 74 2c  erp, attrs_dict,
5c90: 20 61 74 74 72 5f 6b 65 79 5f 70 65 72 6d 73 2c   attr_key_perms,
5ca0: 20 26 61 74 74 72 5f 76 61 6c 75 65 29 3b 0a 09   &attr_value);..
5cb0: 09 09 09 69 66 20 28 61 74 74 72 5f 76 61 6c 75  ...if (attr_valu
5cc0: 65 20 21 3d 20 4e 55 4c 4c 29 20 7b 0a 09 09 09  e != NULL) {....
5cd0: 09 09 61 74 74 72 5f 76 61 6c 75 65 5f 73 74 72  ..attr_value_str
5ce0: 20 3d 20 54 63 6c 5f 47 65 74 53 74 72 69 6e 67   = Tcl_GetString
5cf0: 28 61 74 74 72 5f 76 61 6c 75 65 29 3b 0a 09 09  (attr_value);...
5d00: 09 09 09 66 6f 72 20 28 61 74 74 72 5f 76 61 6c  ...for (attr_val
5d10: 75 65 5f 73 74 72 5f 69 20 3d 20 26 61 74 74 72  ue_str_i = &attr
5d20: 5f 76 61 6c 75 65 5f 73 74 72 5b 30 5d 3b 20 2a  _value_str[0]; *
5d30: 61 74 74 72 5f 76 61 6c 75 65 5f 73 74 72 5f 69  attr_value_str_i
5d40: 20 21 3d 20 27 5c 30 27 3b 20 61 74 74 72 5f 76   != '\0'; attr_v
5d50: 61 6c 75 65 5f 73 74 72 5f 69 2b 2b 29 20 7b 0a  alue_str_i++) {.
5d60: 09 09 09 09 09 09 73 77 69 74 63 68 20 28 2a 61  ......switch (*a
5d70: 74 74 72 5f 76 61 6c 75 65 5f 73 74 72 5f 69 29  ttr_value_str_i)
5d80: 20 7b 0a 09 09 09 09 09 09 09 63 61 73 65 20 27   {........case '
5d90: 78 27 3a 0a 09 09 09 09 09 09 09 09 70 61 74 68  x':.........path
5da0: 69 6e 66 6f 2d 3e 74 79 70 65 69 6e 66 6f 2e 66  info->typeinfo.f
5db0: 69 6c 65 2e 65 78 65 63 75 74 61 62 6c 65 20 3d  ile.executable =
5dc0: 20 31 3b 0a 0a 09 09 09 09 09 09 09 09 62 72 65   1;..........bre
5dd0: 61 6b 3b 0a 09 09 09 09 09 09 09 63 61 73 65 20  ak;........case 
5de0: 27 55 27 3a 0a 09 09 09 09 09 09 09 09 70 61 74  'U':.........pat
5df0: 68 69 6e 66 6f 2d 3e 74 79 70 65 69 6e 66 6f 2e  hinfo->typeinfo.
5e00: 66 69 6c 65 2e 73 75 69 64 52 6f 6f 74 20 3d 20  file.suidRoot = 
5e10: 31 3b 0a 0a 09 09 09 09 09 09 09 09 62 72 65 61  1;..........brea
5e20: 6b 3b 0a 09 09 09 09 09 09 09 63 61 73 65 20 27  k;........case '
5e30: 2d 27 3a 0a 09 09 09 09 09 09 09 09 70 61 74 68  -':.........path
5e40: 69 6e 66 6f 2d 3e 74 79 70 65 69 6e 66 6f 2e 66  info->typeinfo.f
5e50: 69 6c 65 2e 77 6f 72 6c 64 61 63 63 65 73 73 69  ile.worldaccessi
5e60: 62 6c 65 20 3d 20 31 3b 0a 0a 09 09 09 09 09 09  ble = 1;........
5e70: 09 09 62 72 65 61 6b 3b 0a 09 09 09 09 09 09 7d  ..break;.......}
5e80: 0a 09 09 09 09 09 7d 0a 09 09 09 09 7d 0a 09 09  ......}.....}...
5e90: 09 09 62 72 65 61 6b 3b 0a 09 09 09 63 61 73 65  ..break;....case
5ea0: 20 27 73 27 3a 20 2f 2a 20 73 79 6d 6c 69 6e 6b   's': /* symlink
5eb0: 20 2a 2f 0a 09 09 09 09 70 61 74 68 69 6e 66 6f   */.....pathinfo
5ec0: 2d 3e 74 79 70 65 20 3d 20 41 50 50 46 53 5f 50  ->type = APPFS_P
5ed0: 41 54 48 54 59 50 45 5f 53 59 4d 4c 49 4e 4b 3b  ATHTYPE_SYMLINK;
5ee0: 0a 09 09 09 09 70 61 74 68 69 6e 66 6f 2d 3e 74  .....pathinfo->t
5ef0: 79 70 65 69 6e 66 6f 2e 73 79 6d 6c 69 6e 6b 2e  ypeinfo.symlink.
5f00: 73 69 7a 65 20 3d 20 30 3b 0a 09 09 09 09 70 61  size = 0;.....pa
5f10: 74 68 69 6e 66 6f 2d 3e 74 79 70 65 69 6e 66 6f  thinfo->typeinfo
5f20: 2e 73 79 6d 6c 69 6e 6b 2e 73 6f 75 72 63 65 5b  .symlink.source[
5f30: 30 5d 20 3d 20 27 5c 30 27 3b 0a 0a 09 09 09 09  0] = '\0';......
5f40: 54 63 6c 5f 44 69 63 74 4f 62 6a 47 65 74 28 69  Tcl_DictObjGet(i
5f50: 6e 74 65 72 70 2c 20 61 74 74 72 73 5f 64 69 63  nterp, attrs_dic
5f60: 74 2c 20 61 74 74 72 5f 6b 65 79 5f 73 6f 75 72  t, attr_key_sour
5f70: 63 65 2c 20 26 61 74 74 72 5f 76 61 6c 75 65 29  ce, &attr_value)
5f80: 3b 0a 09 09 09 09 69 66 20 28 61 74 74 72 5f 76  ;.....if (attr_v
5f90: 61 6c 75 65 20 21 3d 20 4e 55 4c 4c 29 20 7b 0a  alue != NULL) {.
5fa0: 09 09 09 09 09 61 74 74 72 5f 76 61 6c 75 65 5f  .....attr_value_
5fb0: 73 74 72 20 3d 20 54 63 6c 5f 47 65 74 53 74 72  str = Tcl_GetStr
5fc0: 69 6e 67 46 72 6f 6d 4f 62 6a 28 61 74 74 72 5f  ingFromObj(attr_
5fd0: 76 61 6c 75 65 2c 20 26 61 74 74 72 5f 76 61 6c  value, &attr_val
5fe0: 75 65 5f 69 6e 74 29 3b 20 0a 0a 09 09 09 09 09  ue_int); .......
5ff0: 69 66 20 28 28 61 74 74 72 5f 76 61 6c 75 65 5f  if ((attr_value_
6000: 69 6e 74 20 2b 20 31 29 20 3c 3d 20 73 69 7a 65  int + 1) <= size
6010: 6f 66 28 70 61 74 68 69 6e 66 6f 2d 3e 74 79 70  of(pathinfo->typ
6020: 65 69 6e 66 6f 2e 73 79 6d 6c 69 6e 6b 2e 73 6f  einfo.symlink.so
6030: 75 72 63 65 29 29 20 7b 0a 09 09 09 09 09 09 70  urce)) {.......p
6040: 61 74 68 69 6e 66 6f 2d 3e 74 79 70 65 69 6e 66  athinfo->typeinf
6050: 6f 2e 73 79 6d 6c 69 6e 6b 2e 73 69 7a 65 20 3d  o.symlink.size =
6060: 20 61 74 74 72 5f 76 61 6c 75 65 5f 69 6e 74 3b   attr_value_int;
6070: 0a 09 09 09 09 09 09 70 61 74 68 69 6e 66 6f 2d  .......pathinfo-
6080: 3e 74 79 70 65 69 6e 66 6f 2e 73 79 6d 6c 69 6e  >typeinfo.symlin
6090: 6b 2e 73 6f 75 72 63 65 5b 61 74 74 72 5f 76 61  k.source[attr_va
60a0: 6c 75 65 5f 69 6e 74 5d 20 3d 20 27 5c 30 27 3b  lue_int] = '\0';
60b0: 0a 0a 09 09 09 09 09 09 6d 65 6d 63 70 79 28 70  ........memcpy(p
60c0: 61 74 68 69 6e 66 6f 2d 3e 74 79 70 65 69 6e 66  athinfo->typeinf
60d0: 6f 2e 73 79 6d 6c 69 6e 6b 2e 73 6f 75 72 63 65  o.symlink.source
60e0: 2c 20 61 74 74 72 5f 76 61 6c 75 65 5f 73 74 72  , attr_value_str
60f0: 2c 20 61 74 74 72 5f 76 61 6c 75 65 5f 69 6e 74  , attr_value_int
6100: 29 3b 0a 09 09 09 09 09 7d 0a 09 09 09 09 7d 0a  );......}.....}.
6110: 09 09 09 09 62 72 65 61 6b 3b 0a 09 09 09 63 61  ....break;....ca
6120: 73 65 20 27 46 27 3a 20 2f 2a 20 70 69 70 65 2f  se 'F': /* pipe/
6130: 66 69 66 6f 20 2a 2f 0a 09 09 09 09 70 61 74 68  fifo */.....path
6140: 69 6e 66 6f 2d 3e 74 79 70 65 20 3d 20 41 50 50  info->type = APP
6150: 46 53 5f 50 41 54 48 54 59 50 45 5f 46 49 46 4f  FS_PATHTYPE_FIFO
6160: 3b 0a 09 09 09 09 62 72 65 61 6b 3b 0a 09 09 09  ;.....break;....
6170: 63 61 73 65 20 27 53 27 3a 20 2f 2a 20 55 4e 49  case 'S': /* UNI
6180: 58 20 64 6f 6d 61 69 6e 20 73 6f 63 6b 65 74 20  X domain socket 
6190: 2a 2f 0a 09 09 09 09 70 61 74 68 69 6e 66 6f 2d  */.....pathinfo-
61a0: 3e 74 79 70 65 20 3d 20 41 50 50 46 53 5f 50 41  >type = APPFS_PA
61b0: 54 48 54 59 50 45 5f 53 4f 43 4b 45 54 3b 0a 09  THTYPE_SOCKET;..
61c0: 09 09 09 62 72 65 61 6b 3b 0a 09 09 09 64 65 66  ...break;....def
61d0: 61 75 6c 74 3a 0a 09 09 09 09 72 65 74 76 61 6c  ault:.....retval
61e0: 20 3d 20 2d 45 49 4f 3b 0a 09 09 7d 0a 0a 09 09   = -EIO;...}....
61f0: 54 63 6c 5f 44 69 63 74 4f 62 6a 47 65 74 28 69  Tcl_DictObjGet(i
6200: 6e 74 65 72 70 2c 20 61 74 74 72 73 5f 64 69 63  nterp, attrs_dic
6210: 74 2c 20 61 74 74 72 5f 6b 65 79 5f 70 61 63 6b  t, attr_key_pack
6220: 61 67 65 64 2c 20 26 61 74 74 72 5f 76 61 6c 75  aged, &attr_valu
6230: 65 29 3b 0a 09 09 69 66 20 28 61 74 74 72 5f 76  e);...if (attr_v
6240: 61 6c 75 65 20 21 3d 20 4e 55 4c 4c 29 20 7b 0a  alue != NULL) {.
6250: 09 09 09 70 61 74 68 69 6e 66 6f 2d 3e 70 61 63  ...pathinfo->pac
6260: 6b 61 67 65 64 20 3d 20 31 3b 0a 09 09 7d 0a 0a  kaged = 1;...}..
6270: 09 09 54 63 6c 5f 44 69 63 74 4f 62 6a 47 65 74  ..Tcl_DictObjGet
6280: 28 69 6e 74 65 72 70 2c 20 61 74 74 72 73 5f 64  (interp, attrs_d
6290: 69 63 74 2c 20 61 74 74 72 5f 6b 65 79 5f 74 69  ict, attr_key_ti
62a0: 6d 65 2c 20 26 61 74 74 72 5f 76 61 6c 75 65 29  me, &attr_value)
62b0: 3b 0a 09 09 69 66 20 28 61 74 74 72 5f 76 61 6c  ;...if (attr_val
62c0: 75 65 20 21 3d 20 4e 55 4c 4c 29 20 7b 0a 09 09  ue != NULL) {...
62d0: 09 74 63 6c 5f 72 65 74 20 3d 20 54 63 6c 5f 47  .tcl_ret = Tcl_G
62e0: 65 74 57 69 64 65 49 6e 74 46 72 6f 6d 4f 62 6a  etWideIntFromObj
62f0: 28 4e 55 4c 4c 2c 20 61 74 74 72 5f 76 61 6c 75  (NULL, attr_valu
6300: 65 2c 20 26 61 74 74 72 5f 76 61 6c 75 65 5f 77  e, &attr_value_w
6310: 69 64 65 29 3b 0a 09 09 09 69 66 20 28 74 63 6c  ide);....if (tcl
6320: 5f 72 65 74 20 3d 3d 20 54 43 4c 5f 4f 4b 29 20  _ret == TCL_OK) 
6330: 7b 0a 09 09 09 09 70 61 74 68 69 6e 66 6f 2d 3e  {.....pathinfo->
6340: 74 69 6d 65 20 3d 20 61 74 74 72 5f 76 61 6c 75  time = attr_valu
6350: 65 5f 77 69 64 65 3b 0a 09 09 09 7d 0a 09 09 7d  e_wide;....}...}
6360: 20 65 6c 73 65 20 7b 0a 09 09 09 70 61 74 68 69   else {....pathi
6370: 6e 66 6f 2d 3e 74 69 6d 65 20 3d 20 61 70 70 66  nfo->time = appf
6380: 73 5f 62 6f 6f 74 74 69 6d 65 3b 0a 09 09 7d 0a  s_boottime;...}.
6390: 0a 09 09 54 63 6c 5f 52 65 6c 65 61 73 65 28 69  ...Tcl_Release(i
63a0: 6e 74 65 72 70 29 3b 0a 09 29 0a 0a 09 69 66 20  nterp);..)...if 
63b0: 28 70 61 74 68 69 6e 66 6f 2d 3e 70 61 63 6b 61  (pathinfo->packa
63c0: 67 65 64 29 20 7b 0a 09 09 70 61 74 68 69 6e 66  ged) {...pathinf
63d0: 6f 2d 3e 69 6e 6f 64 65 20 3d 20 61 70 70 66 73  o->inode = appfs
63e0: 5f 67 65 74 5f 70 61 74 68 5f 69 6e 6f 64 65 28  _get_path_inode(
63f0: 70 61 74 68 2c 20 2d 31 29 3b 0a 09 7d 20 65 6c  path, -1);..} el
6400: 73 65 20 7b 0a 09 09 70 61 74 68 69 6e 66 6f 2d  se {...pathinfo-
6410: 3e 69 6e 6f 64 65 20 3d 20 61 70 70 66 73 5f 67  >inode = appfs_g
6420: 65 74 5f 70 61 74 68 5f 69 6e 6f 64 65 28 70 61  et_path_inode(pa
6430: 74 68 2c 20 66 73 75 69 64 29 3b 0a 09 7d 0a 0a  th, fsuid);..}..
6440: 09 41 50 50 46 53 5f 44 45 42 55 47 28 22 43 61  .APPFS_DEBUG("Ca
6450: 63 68 69 6e 67 20 69 6e 6f 64 65 20 66 6f 72 20  ching inode for 
6460: 70 61 74 68 3d 25 73 2c 75 69 64 3d 25 6c 6c 69  path=%s,uid=%lli
6470: 20 61 73 20 25 6c 6c 75 20 28 70 61 63 6b 61 67   as %llu (packag
6480: 65 64 20 3d 20 25 69 29 22 2c 20 70 61 74 68 2c  ed = %i)", path,
6490: 20 28 6c 6f 6e 67 20 6c 6f 6e 67 29 20 66 73 75   (long long) fsu
64a0: 69 64 2c 20 70 61 74 68 69 6e 66 6f 2d 3e 69 6e  id, pathinfo->in
64b0: 6f 64 65 2c 20 70 61 74 68 69 6e 66 6f 2d 3e 70  ode, pathinfo->p
64c0: 61 63 6b 61 67 65 64 29 3b 0a 0a 09 69 66 20 28  ackaged);...if (
64d0: 72 65 74 76 61 6c 20 3d 3d 20 30 29 20 7b 0a 09  retval == 0) {..
64e0: 09 61 70 70 66 73 5f 67 65 74 5f 70 61 74 68 5f  .appfs_get_path_
64f0: 69 6e 66 6f 5f 63 61 63 68 65 5f 61 64 64 28 70  info_cache_add(p
6500: 61 74 68 2c 20 66 73 75 69 64 2c 20 70 61 74 68  ath, fsuid, path
6510: 69 6e 66 6f 29 3b 0a 09 7d 20 65 6c 73 65 20 7b  info);..} else {
6520: 0a 09 09 41 50 50 46 53 5f 44 45 42 55 47 28 22  ...APPFS_DEBUG("
6530: 65 72 72 6f 72 3a 20 49 6e 76 61 6c 69 64 20 74  error: Invalid t
6540: 79 70 65 20 66 6f 72 20 5c 22 25 73 5c 22 20 66  ype for \"%s\" f
6550: 72 6f 6d 20 54 63 6c 22 2c 20 70 61 74 68 29 3b  rom Tcl", path);
6560: 0a 09 7d 0a 0a 09 72 65 74 75 72 6e 28 72 65 74  ..}...return(ret
6570: 76 61 6c 29 3b 0a 7d 0a 0a 73 74 61 74 69 63 20  val);.}..static 
6580: 63 68 61 72 20 2a 61 70 70 66 73 5f 70 72 65 70  char *appfs_prep
6590: 61 72 65 5f 74 6f 5f 63 72 65 61 74 65 28 63 6f  are_to_create(co
65a0: 6e 73 74 20 63 68 61 72 20 2a 70 61 74 68 29 20  nst char *path) 
65b0: 7b 0a 09 54 63 6c 5f 49 6e 74 65 72 70 20 2a 69  {..Tcl_Interp *i
65c0: 6e 74 65 72 70 3b 0a 09 63 6f 6e 73 74 20 63 68  nterp;..const ch
65d0: 61 72 20 2a 72 65 61 6c 5f 70 61 74 68 3b 0a 09  ar *real_path;..
65e0: 69 6e 74 20 74 63 6c 5f 72 65 74 3b 0a 0a 09 61  int tcl_ret;...a
65f0: 70 70 66 73 5f 67 65 74 5f 70 61 74 68 5f 69 6e  ppfs_get_path_in
6600: 66 6f 5f 63 61 63 68 65 5f 66 6c 75 73 68 28 61  fo_cache_flush(a
6610: 70 70 66 73 5f 67 65 74 5f 66 73 75 69 64 28 29  ppfs_get_fsuid()
6620: 2c 20 2d 31 29 3b 0a 0a 09 69 6e 74 65 72 70 20  , -1);...interp 
6630: 3d 20 61 70 70 66 73 5f 54 63 6c 49 6e 74 65 72  = appfs_TclInter
6640: 70 28 29 3b 0a 09 69 66 20 28 69 6e 74 65 72 70  p();..if (interp
6650: 20 3d 3d 20 4e 55 4c 4c 29 20 7b 0a 09 09 72 65   == NULL) {...re
6660: 74 75 72 6e 28 4e 55 4c 4c 29 3b 0a 09 7d 0a 0a  turn(NULL);..}..
6670: 09 61 70 70 66 73 5f 63 61 6c 6c 5f 6c 69 62 74  .appfs_call_libt
6680: 63 6c 28 54 63 6c 5f 50 72 65 73 65 72 76 65 28  cl(Tcl_Preserve(
6690: 69 6e 74 65 72 70 29 3b 29 0a 0a 09 61 70 70 66  interp);)...appf
66a0: 73 5f 63 61 6c 6c 5f 6c 69 62 74 63 6c 28 0a 09  s_call_libtcl(..
66b0: 09 74 63 6c 5f 72 65 74 20 3d 20 61 70 70 66 73  .tcl_ret = appfs
66c0: 5f 54 63 6c 5f 45 76 61 6c 28 69 6e 74 65 72 70  _Tcl_Eval(interp
66d0: 2c 20 32 2c 20 22 3a 3a 61 70 70 66 73 3a 3a 70  , 2, "::appfs::p
66e0: 72 65 70 61 72 65 5f 74 6f 5f 63 72 65 61 74 65  repare_to_create
66f0: 22 2c 20 70 61 74 68 29 3b 0a 09 29 0a 09 69 66  ", path);..)..if
6700: 20 28 74 63 6c 5f 72 65 74 20 21 3d 20 54 43 4c   (tcl_ret != TCL
6710: 5f 4f 4b 29 20 7b 0a 09 09 41 50 50 46 53 5f 44  _OK) {...APPFS_D
6720: 45 42 55 47 28 22 3a 3a 61 70 70 66 73 3a 3a 70  EBUG("::appfs::p
6730: 72 65 70 61 72 65 5f 74 6f 5f 63 72 65 61 74 65  repare_to_create
6740: 28 25 73 29 20 66 61 69 6c 65 64 2e 22 2c 20 70  (%s) failed.", p
6750: 61 74 68 29 3b 0a 09 09 61 70 70 66 73 5f 63 61  ath);...appfs_ca
6760: 6c 6c 5f 6c 69 62 74 63 6c 28 0a 09 09 09 41 50  ll_libtcl(....AP
6770: 50 46 53 5f 44 45 42 55 47 28 22 54 63 6c 20 45  PFS_DEBUG("Tcl E
6780: 72 72 6f 72 20 69 73 3a 20 25 73 22 2c 20 54 63  rror is: %s", Tc
6790: 6c 5f 47 65 74 53 74 72 69 6e 67 52 65 73 75 6c  l_GetStringResul
67a0: 74 28 69 6e 74 65 72 70 29 29 3b 0a 09 09 29 0a  t(interp));...).
67b0: 0a 09 09 61 70 70 66 73 5f 63 61 6c 6c 5f 6c 69  ...appfs_call_li
67c0: 62 74 63 6c 28 54 63 6c 5f 52 65 6c 65 61 73 65  btcl(Tcl_Release
67d0: 28 69 6e 74 65 72 70 29 3b 29 0a 0a 09 09 72 65  (interp);)....re
67e0: 74 75 72 6e 28 4e 55 4c 4c 29 3b 0a 09 7d 0a 0a  turn(NULL);..}..
67f0: 09 61 70 70 66 73 5f 63 61 6c 6c 5f 6c 69 62 74  .appfs_call_libt
6800: 63 6c 28 0a 09 09 72 65 61 6c 5f 70 61 74 68 20  cl(...real_path 
6810: 3d 20 54 63 6c 5f 47 65 74 53 74 72 69 6e 67 52  = Tcl_GetStringR
6820: 65 73 75 6c 74 28 69 6e 74 65 72 70 29 3b 0a 09  esult(interp);..
6830: 29 0a 0a 09 61 70 70 66 73 5f 63 61 6c 6c 5f 6c  )...appfs_call_l
6840: 69 62 74 63 6c 28 54 63 6c 5f 52 65 6c 65 61 73  ibtcl(Tcl_Releas
6850: 65 28 69 6e 74 65 72 70 29 3b 29 0a 0a 09 69 66  e(interp);)...if
6860: 20 28 72 65 61 6c 5f 70 61 74 68 20 3d 3d 20 4e   (real_path == N
6870: 55 4c 4c 29 20 7b 0a 09 09 72 65 74 75 72 6e 28  ULL) {...return(
6880: 4e 55 4c 4c 29 3b 0a 09 7d 0a 0a 09 72 65 74 75  NULL);..}...retu
6890: 72 6e 28 73 74 72 64 75 70 28 72 65 61 6c 5f 70  rn(strdup(real_p
68a0: 61 74 68 29 29 3b 0a 7d 0a 0a 73 74 61 74 69 63  ath));.}..static
68b0: 20 63 68 61 72 20 2a 61 70 70 66 73 5f 6c 6f 63   char *appfs_loc
68c0: 61 6c 70 61 74 68 28 63 6f 6e 73 74 20 63 68 61  alpath(const cha
68d0: 72 20 2a 70 61 74 68 29 20 7b 0a 09 54 63 6c 5f  r *path) {..Tcl_
68e0: 49 6e 74 65 72 70 20 2a 69 6e 74 65 72 70 3b 0a  Interp *interp;.
68f0: 09 63 6f 6e 73 74 20 63 68 61 72 20 2a 72 65 61  .const char *rea
6900: 6c 5f 70 61 74 68 3b 0a 09 69 6e 74 20 74 63 6c  l_path;..int tcl
6910: 5f 72 65 74 3b 0a 0a 09 69 6e 74 65 72 70 20 3d  _ret;...interp =
6920: 20 61 70 70 66 73 5f 54 63 6c 49 6e 74 65 72 70   appfs_TclInterp
6930: 28 29 3b 0a 09 69 66 20 28 69 6e 74 65 72 70 20  ();..if (interp 
6940: 3d 3d 20 4e 55 4c 4c 29 20 7b 0a 09 09 72 65 74  == NULL) {...ret
6950: 75 72 6e 28 4e 55 4c 4c 29 3b 0a 09 7d 0a 0a 09  urn(NULL);..}...
6960: 61 70 70 66 73 5f 63 61 6c 6c 5f 6c 69 62 74 63  appfs_call_libtc
6970: 6c 28 54 63 6c 5f 50 72 65 73 65 72 76 65 28 69  l(Tcl_Preserve(i
6980: 6e 74 65 72 70 29 3b 29 0a 0a 09 61 70 70 66 73  nterp);)...appfs
6990: 5f 63 61 6c 6c 5f 6c 69 62 74 63 6c 28 0a 09 09  _call_libtcl(...
69a0: 74 63 6c 5f 72 65 74 20 3d 20 61 70 70 66 73 5f  tcl_ret = appfs_
69b0: 54 63 6c 5f 45 76 61 6c 28 69 6e 74 65 72 70 2c  Tcl_Eval(interp,
69c0: 20 32 2c 20 22 3a 3a 61 70 70 66 73 3a 3a 6c 6f   2, "::appfs::lo
69d0: 63 61 6c 70 61 74 68 22 2c 20 70 61 74 68 29 3b  calpath", path);
69e0: 0a 09 29 0a 09 69 66 20 28 74 63 6c 5f 72 65 74  ..)..if (tcl_ret
69f0: 20 21 3d 20 54 43 4c 5f 4f 4b 29 20 7b 0a 09 09   != TCL_OK) {...
6a00: 41 50 50 46 53 5f 44 45 42 55 47 28 22 3a 3a 61  APPFS_DEBUG("::a
6a10: 70 70 66 73 3a 3a 6c 6f 63 61 6c 70 61 74 68 28  ppfs::localpath(
6a20: 25 73 29 20 66 61 69 6c 65 64 2e 22 2c 20 70 61  %s) failed.", pa
6a30: 74 68 29 3b 0a 09 09 61 70 70 66 73 5f 63 61 6c  th);...appfs_cal
6a40: 6c 5f 6c 69 62 74 63 6c 28 0a 09 09 09 41 50 50  l_libtcl(....APP
6a50: 46 53 5f 44 45 42 55 47 28 22 54 63 6c 20 45 72  FS_DEBUG("Tcl Er
6a60: 72 6f 72 20 69 73 3a 20 25 73 22 2c 20 54 63 6c  ror is: %s", Tcl
6a70: 5f 47 65 74 53 74 72 69 6e 67 52 65 73 75 6c 74  _GetStringResult
6a80: 28 69 6e 74 65 72 70 29 29 3b 0a 09 09 29 0a 0a  (interp));...)..
6a90: 09 09 72 65 74 75 72 6e 28 4e 55 4c 4c 29 3b 0a  ..return(NULL);.
6aa0: 09 7d 0a 0a 09 61 70 70 66 73 5f 63 61 6c 6c 5f  .}...appfs_call_
6ab0: 6c 69 62 74 63 6c 28 0a 09 09 72 65 61 6c 5f 70  libtcl(...real_p
6ac0: 61 74 68 20 3d 20 54 63 6c 5f 47 65 74 53 74 72  ath = Tcl_GetStr
6ad0: 69 6e 67 52 65 73 75 6c 74 28 69 6e 74 65 72 70  ingResult(interp
6ae0: 29 3b 0a 09 29 0a 0a 09 61 70 70 66 73 5f 63 61  );..)...appfs_ca
6af0: 6c 6c 5f 6c 69 62 74 63 6c 28 54 63 6c 5f 52 65  ll_libtcl(Tcl_Re
6b00: 6c 65 61 73 65 28 69 6e 74 65 72 70 29 3b 29 0a  lease(interp);).
6b10: 0a 09 69 66 20 28 72 65 61 6c 5f 70 61 74 68 20  ..if (real_path 
6b20: 3d 3d 20 4e 55 4c 4c 29 20 7b 0a 09 09 72 65 74  == NULL) {...ret
6b30: 75 72 6e 28 4e 55 4c 4c 29 3b 0a 09 7d 0a 0a 09  urn(NULL);..}...
6b40: 72 65 74 75 72 6e 28 73 74 72 64 75 70 28 72 65  return(strdup(re
6b50: 61 6c 5f 70 61 74 68 29 29 3b 0a 7d 0a 0a 23 69  al_path));.}..#i
6b60: 66 20 28 64 65 66 69 6e 65 64 28 44 45 42 55 47  f (defined(DEBUG
6b70: 29 20 26 26 20 64 65 66 69 6e 65 64 28 41 50 50  ) && defined(APP
6b80: 46 53 5f 45 58 49 54 5f 50 41 54 48 29 29 20 7c  FS_EXIT_PATH)) |
6b90: 7c 20 64 65 66 69 6e 65 64 28 41 50 50 46 53 5f  | defined(APPFS_
6ba0: 45 58 49 54 5f 50 41 54 48 5f 45 4e 41 42 4c 45  EXIT_PATH_ENABLE
6bb0: 5f 4d 41 4a 4f 52 5f 53 45 43 55 52 49 54 59 5f  _MAJOR_SECURITY_
6bc0: 48 4f 4c 45 29 0a 73 74 61 74 69 63 20 76 6f 69  HOLE).static voi
6bd0: 64 20 61 70 70 66 73 5f 65 78 69 74 28 76 6f 69  d appfs_exit(voi
6be0: 64 29 20 7b 0a 09 69 6e 74 20 67 6c 6f 62 61 6c  d) {..int global
6bf0: 5f 69 6e 74 65 72 70 5f 72 65 73 65 74 5f 6b 65  _interp_reset_ke
6c00: 79 3b 0a 0a 09 67 6c 6f 62 61 6c 5f 69 6e 74 65  y;...global_inte
6c10: 72 70 5f 72 65 73 65 74 5f 6b 65 79 20 3d 20 5f  rp_reset_key = _
6c20: 5f 73 79 6e 63 5f 66 65 74 63 68 5f 61 6e 64 5f  _sync_fetch_and_
6c30: 61 64 64 28 26 69 6e 74 65 72 70 5f 72 65 73 65  add(&interp_rese
6c40: 74 5f 6b 65 79 2c 20 30 29 3b 0a 09 5f 5f 73 79  t_key, 0);..__sy
6c50: 6e 63 5f 66 65 74 63 68 5f 61 6e 64 5f 73 75 62  nc_fetch_and_sub
6c60: 28 26 69 6e 74 65 72 70 5f 72 65 73 65 74 5f 6b  (&interp_reset_k
6c70: 65 79 2c 20 67 6c 6f 62 61 6c 5f 69 6e 74 65 72  ey, global_inter
6c80: 70 5f 72 65 73 65 74 5f 6b 65 79 29 3b 0a 0a 09  p_reset_key);...
6c90: 77 68 69 6c 65 20 28 5f 5f 73 79 6e 63 5f 73 75  while (__sync_su
6ca0: 62 5f 61 6e 64 5f 66 65 74 63 68 28 26 69 6e 74  b_and_fetch(&int
6cb0: 65 72 70 5f 72 65 73 65 74 5f 6b 65 79 2c 20 31  erp_reset_key, 1
6cc0: 29 20 3e 3d 20 30 29 20 7b 0a 09 09 2f 2a 20 42  ) >= 0) {.../* B
6cd0: 75 73 79 20 4c 6f 6f 70 20 2a 2f 0a 09 7d 0a 0a  usy Loop */..}..
6ce0: 09 67 6c 6f 62 61 6c 5f 69 6e 74 65 72 70 5f 72  .global_interp_r
6cf0: 65 73 65 74 5f 6b 65 79 20 3d 20 5f 5f 73 79 6e  eset_key = __syn
6d00: 63 5f 66 65 74 63 68 5f 61 6e 64 5f 61 64 64 28  c_fetch_and_add(
6d10: 26 69 6e 74 65 72 70 5f 72 65 73 65 74 5f 6b 65  &interp_reset_ke
6d20: 79 2c 20 30 29 3b 0a 09 69 66 20 28 67 6c 6f 62  y, 0);..if (glob
6d30: 61 6c 5f 69 6e 74 65 72 70 5f 72 65 73 65 74 5f  al_interp_reset_
6d40: 6b 65 79 20 21 3d 20 2d 31 29 20 7b 0a 09 09 41  key != -1) {...A
6d50: 50 50 46 53 5f 44 45 42 55 47 28 22 45 72 72 6f  PPFS_DEBUG("Erro
6d60: 72 20 73 65 6e 64 69 6e 67 20 6b 69 6c 6c 20 73  r sending kill s
6d70: 69 67 6e 61 6c 20 74 6f 20 61 6c 6c 20 74 68 72  ignal to all thr
6d80: 65 61 64 73 2c 20 61 62 6f 72 74 69 6e 67 20 61  eads, aborting a
6d90: 6e 79 77 61 79 2e 22 29 3b 0a 09 7d 0a 0a 09 61  nyway.");..}...a
6da0: 70 70 66 73 5f 67 65 74 5f 70 61 74 68 5f 69 6e  ppfs_get_path_in
6db0: 66 6f 5f 63 61 63 68 65 5f 66 6c 75 73 68 28 2d  fo_cache_flush(-
6dc0: 31 2c 20 2d 31 29 3b 0a 0a 09 66 75 73 65 5f 65  1, -1);...fuse_e
6dd0: 78 69 74 28 66 75 73 65 5f 67 65 74 5f 63 6f 6e  xit(fuse_get_con
6de0: 74 65 78 74 28 29 2d 3e 66 75 73 65 29 3b 0a 0a  text()->fuse);..
6df0: 09 72 65 74 75 72 6e 3b 0a 7d 0a 23 65 6e 64 69  .return;.}.#endi
6e00: 66 0a 0a 73 74 61 74 69 63 20 69 6e 74 20 61 70  f..static int ap
6e10: 70 66 73 5f 66 75 73 65 5f 72 65 61 64 6c 69 6e  pfs_fuse_readlin
6e20: 6b 28 63 6f 6e 73 74 20 63 68 61 72 20 2a 70 61  k(const char *pa
6e30: 74 68 2c 20 63 68 61 72 20 2a 62 75 66 2c 20 73  th, char *buf, s
6e40: 69 7a 65 5f 74 20 73 69 7a 65 29 20 7b 0a 09 73  ize_t size) {..s
6e50: 74 72 75 63 74 20 61 70 70 66 73 5f 70 61 74 68  truct appfs_path
6e60: 69 6e 66 6f 20 70 61 74 68 69 6e 66 6f 3b 0a 09  info pathinfo;..
6e70: 69 6e 74 20 72 65 74 76 61 6c 20 3d 20 30 3b 0a  int retval = 0;.
6e80: 0a 09 41 50 50 46 53 5f 44 45 42 55 47 28 22 45  ..APPFS_DEBUG("E
6e90: 6e 74 65 72 20 28 70 61 74 68 20 3d 20 25 73 2c  nter (path = %s,
6ea0: 20 2e 2e 2e 29 22 2c 20 70 61 74 68 29 3b 0a 0a   ...)", path);..
6eb0: 09 70 61 74 68 69 6e 66 6f 2e 74 79 70 65 20 3d  .pathinfo.type =
6ec0: 20 41 50 50 46 53 5f 50 41 54 48 54 59 50 45 5f   APPFS_PATHTYPE_
6ed0: 49 4e 56 41 4c 49 44 3b 0a 0a 09 72 65 74 76 61  INVALID;...retva
6ee0: 6c 20 3d 20 61 70 70 66 73 5f 67 65 74 5f 70 61  l = appfs_get_pa
6ef0: 74 68 5f 69 6e 66 6f 28 70 61 74 68 2c 20 26 70  th_info(path, &p
6f00: 61 74 68 69 6e 66 6f 29 3b 0a 09 69 66 20 28 72  athinfo);..if (r
6f10: 65 74 76 61 6c 20 21 3d 20 30 29 20 7b 0a 09 09  etval != 0) {...
6f20: 72 65 74 75 72 6e 28 72 65 74 76 61 6c 29 3b 0a  return(retval);.
6f30: 09 7d 0a 0a 09 69 66 20 28 70 61 74 68 69 6e 66  .}...if (pathinf
6f40: 6f 2e 74 79 70 65 20 21 3d 20 41 50 50 46 53 5f  o.type != APPFS_
6f50: 50 41 54 48 54 59 50 45 5f 53 59 4d 4c 49 4e 4b  PATHTYPE_SYMLINK
6f60: 29 20 7b 0a 09 09 72 65 74 75 72 6e 28 2d 45 49  ) {...return(-EI
6f70: 4e 56 41 4c 29 3b 0a 09 7d 0a 0a 09 69 66 20 28  NVAL);..}...if (
6f80: 28 73 74 72 6c 65 6e 28 70 61 74 68 69 6e 66 6f  (strlen(pathinfo
6f90: 2e 74 79 70 65 69 6e 66 6f 2e 73 79 6d 6c 69 6e  .typeinfo.symlin
6fa0: 6b 2e 73 6f 75 72 63 65 29 20 2b 20 31 29 20 3e  k.source) + 1) >
6fb0: 20 73 69 7a 65 29 20 7b 0a 09 09 72 65 74 75 72   size) {...retur
6fc0: 6e 28 2d 45 4e 41 4d 45 54 4f 4f 4c 4f 4e 47 29  n(-ENAMETOOLONG)
6fd0: 3b 0a 09 7d 0a 0a 09 6d 65 6d 63 70 79 28 62 75  ;..}...memcpy(bu
6fe0: 66 2c 20 70 61 74 68 69 6e 66 6f 2e 74 79 70 65  f, pathinfo.type
6ff0: 69 6e 66 6f 2e 73 79 6d 6c 69 6e 6b 2e 73 6f 75  info.symlink.sou
7000: 72 63 65 2c 20 73 74 72 6c 65 6e 28 70 61 74 68  rce, strlen(path
7010: 69 6e 66 6f 2e 74 79 70 65 69 6e 66 6f 2e 73 79  info.typeinfo.sy
7020: 6d 6c 69 6e 6b 2e 73 6f 75 72 63 65 29 20 2b 20  mlink.source) + 
7030: 31 29 3b 0a 0a 09 72 65 74 75 72 6e 28 30 29 3b  1);...return(0);
7040: 0a 7d 0a 0a 73 74 61 74 69 63 20 69 6e 74 20 61  .}..static int a
7050: 70 70 66 73 5f 66 75 73 65 5f 67 65 74 61 74 74  ppfs_fuse_getatt
7060: 72 28 63 6f 6e 73 74 20 63 68 61 72 20 2a 70 61  r(const char *pa
7070: 74 68 2c 20 73 74 72 75 63 74 20 73 74 61 74 20  th, struct stat 
7080: 2a 73 74 62 75 66 29 20 7b 0a 09 73 74 72 75 63  *stbuf) {..struc
7090: 74 20 61 70 70 66 73 5f 70 61 74 68 69 6e 66 6f  t appfs_pathinfo
70a0: 20 70 61 74 68 69 6e 66 6f 3b 0a 09 69 6e 74 20   pathinfo;..int 
70b0: 63 68 61 6e 67 65 4f 77 6e 65 72 54 6f 55 73 65  changeOwnerToUse
70c0: 72 49 66 50 61 63 6b 61 67 65 64 3b 0a 09 69 6e  rIfPackaged;..in
70d0: 74 20 72 65 74 76 61 6c 3b 0a 0a 09 72 65 74 76  t retval;...retv
70e0: 61 6c 20 3d 20 30 3b 0a 0a 09 41 50 50 46 53 5f  al = 0;...APPFS_
70f0: 44 45 42 55 47 28 22 45 6e 74 65 72 20 28 70 61  DEBUG("Enter (pa
7100: 74 68 20 3d 20 25 73 2c 20 2e 2e 2e 29 22 2c 20  th = %s, ...)", 
7110: 70 61 74 68 29 3b 0a 0a 23 69 66 20 28 64 65 66  path);..#if (def
7120: 69 6e 65 64 28 44 45 42 55 47 29 20 26 26 20 64  ined(DEBUG) && d
7130: 65 66 69 6e 65 64 28 41 50 50 46 53 5f 45 58 49  efined(APPFS_EXI
7140: 54 5f 50 41 54 48 29 29 20 7c 7c 20 64 65 66 69  T_PATH)) || defi
7150: 6e 65 64 28 41 50 50 46 53 5f 45 58 49 54 5f 50  ned(APPFS_EXIT_P
7160: 41 54 48 5f 45 4e 41 42 4c 45 5f 4d 41 4a 4f 52  ATH_ENABLE_MAJOR
7170: 5f 53 45 43 55 52 49 54 59 5f 48 4f 4c 45 29 0a  _SECURITY_HOLE).
7180: 09 2f 2a 0a 09 20 2a 20 54 68 69 73 20 69 73 20  ./*.. * This is 
7190: 61 20 6d 61 6a 6f 72 20 73 65 63 75 72 69 74 79  a major security
71a0: 20 69 73 73 75 65 20 73 6f 20 77 65 20 63 61 6e   issue so we can
71b0: 6e 6f 74 20 6c 65 74 20 69 74 20 62 65 20 63 6f  not let it be co
71c0: 6d 70 69 6c 65 64 20 69 6e 74 6f 0a 09 20 2a 20  mpiled into.. * 
71d0: 61 6e 79 20 72 65 6c 65 61 73 65 0a 09 20 2a 2f  any release.. */
71e0: 0a 0a 09 69 66 20 28 73 74 72 63 6d 70 28 70 61  ...if (strcmp(pa
71f0: 74 68 2c 20 22 2f 65 78 69 74 22 29 20 3d 3d 20  th, "/exit") == 
7200: 30 29 20 7b 0a 09 09 61 70 70 66 73 5f 65 78 69  0) {...appfs_exi
7210: 74 28 29 3b 0a 09 7d 0a 23 65 6e 64 69 66 0a 0a  t();..}.#endif..
7220: 09 70 61 74 68 69 6e 66 6f 2e 74 79 70 65 20 3d  .pathinfo.type =
7230: 20 41 50 50 46 53 5f 50 41 54 48 54 59 50 45 5f   APPFS_PATHTYPE_
7240: 49 4e 56 41 4c 49 44 3b 0a 0a 09 72 65 74 76 61  INVALID;...retva
7250: 6c 20 3d 20 61 70 70 66 73 5f 67 65 74 5f 70 61  l = appfs_get_pa
7260: 74 68 5f 69 6e 66 6f 28 70 61 74 68 2c 20 26 70  th_info(path, &p
7270: 61 74 68 69 6e 66 6f 29 3b 0a 09 69 66 20 28 72  athinfo);..if (r
7280: 65 74 76 61 6c 20 21 3d 20 30 29 20 7b 0a 09 09  etval != 0) {...
7290: 69 66 20 28 72 65 74 76 61 6c 20 3d 3d 20 2d 45  if (retval == -E
72a0: 4e 4f 45 4e 54 29 20 7b 0a 09 09 09 41 50 50 46  NOENT) {....APPF
72b0: 53 5f 44 45 42 55 47 28 22 67 65 74 5f 70 61 74  S_DEBUG("get_pat
72c0: 68 5f 69 6e 66 6f 20 72 65 74 75 72 6e 65 64 20  h_info returned 
72d0: 45 4e 4f 45 4e 54 2c 20 72 65 74 75 72 6e 69 6e  ENOENT, returnin
72e0: 67 20 69 74 20 61 73 20 77 65 6c 6c 2e 22 29 3b  g it as well.");
72f0: 0a 09 09 7d 20 65 6c 73 65 20 7b 0a 09 09 09 41  ...} else {....A
7300: 50 50 46 53 5f 44 45 42 55 47 28 22 65 72 72 6f  PPFS_DEBUG("erro
7310: 72 3a 20 67 65 74 5f 70 61 74 68 5f 69 6e 66 6f  r: get_path_info
7320: 20 66 61 69 6c 65 64 22 29 3b 0a 09 09 7d 0a 0a   failed");...}..
7330: 09 09 72 65 74 75 72 6e 28 72 65 74 76 61 6c 29  ..return(retval)
7340: 3b 0a 09 7d 0a 0a 09 6d 65 6d 73 65 74 28 73 74  ;..}...memset(st
7350: 62 75 66 2c 20 30 2c 20 73 69 7a 65 6f 66 28 73  buf, 0, sizeof(s
7360: 74 72 75 63 74 20 73 74 61 74 29 29 3b 0a 0a 09  truct stat));...
7370: 73 74 62 75 66 2d 3e 73 74 5f 6d 74 69 6d 65 20  stbuf->st_mtime 
7380: 3d 20 70 61 74 68 69 6e 66 6f 2e 74 69 6d 65 3b  = pathinfo.time;
7390: 0a 09 73 74 62 75 66 2d 3e 73 74 5f 63 74 69 6d  ..stbuf->st_ctim
73a0: 65 20 3d 20 70 61 74 68 69 6e 66 6f 2e 74 69 6d  e = pathinfo.tim
73b0: 65 3b 0a 09 73 74 62 75 66 2d 3e 73 74 5f 61 74  e;..stbuf->st_at
73c0: 69 6d 65 20 3d 20 70 61 74 68 69 6e 66 6f 2e 74  ime = pathinfo.t
73d0: 69 6d 65 3b 0a 09 73 74 62 75 66 2d 3e 73 74 5f  ime;..stbuf->st_
73e0: 69 6e 6f 20 20 20 3d 20 70 61 74 68 69 6e 66 6f  ino   = pathinfo
73f0: 2e 69 6e 6f 64 65 3b 0a 09 73 74 62 75 66 2d 3e  .inode;..stbuf->
7400: 73 74 5f 6d 6f 64 65 20 20 3d 20 30 3b 0a 0a 09  st_mode  = 0;...
7410: 63 68 61 6e 67 65 4f 77 6e 65 72 54 6f 55 73 65  changeOwnerToUse
7420: 72 49 66 50 61 63 6b 61 67 65 64 20 3d 20 31 3b  rIfPackaged = 1;
7430: 0a 0a 09 73 77 69 74 63 68 20 28 70 61 74 68 69  ...switch (pathi
7440: 6e 66 6f 2e 74 79 70 65 29 20 7b 0a 09 09 63 61  nfo.type) {...ca
7450: 73 65 20 41 50 50 46 53 5f 50 41 54 48 54 59 50  se APPFS_PATHTYP
7460: 45 5f 44 49 52 45 43 54 4f 52 59 3a 0a 09 09 09  E_DIRECTORY:....
7470: 73 74 62 75 66 2d 3e 73 74 5f 6d 6f 64 65 20 3d  stbuf->st_mode =
7480: 20 53 5f 49 46 44 49 52 20 7c 20 30 35 35 35 3b   S_IFDIR | 0555;
7490: 0a 09 09 09 73 74 62 75 66 2d 3e 73 74 5f 6e 6c  ....stbuf->st_nl
74a0: 69 6e 6b 20 3d 20 32 20 2b 20 70 61 74 68 69 6e  ink = 2 + pathin
74b0: 66 6f 2e 74 79 70 65 69 6e 66 6f 2e 64 69 72 2e  fo.typeinfo.dir.
74c0: 63 68 69 6c 64 63 6f 75 6e 74 3b 0a 09 09 09 62  childcount;....b
74d0: 72 65 61 6b 3b 0a 09 09 63 61 73 65 20 41 50 50  reak;...case APP
74e0: 46 53 5f 50 41 54 48 54 59 50 45 5f 46 49 4c 45  FS_PATHTYPE_FILE
74f0: 3a 0a 09 09 09 73 74 62 75 66 2d 3e 73 74 5f 6d  :....stbuf->st_m
7500: 6f 64 65 20 3d 20 53 5f 49 46 52 45 47 20 7c 20  ode = S_IFREG | 
7510: 30 34 34 34 3b 0a 0a 09 09 09 69 66 20 28 70 61  0444;.....if (pa
7520: 74 68 69 6e 66 6f 2e 74 79 70 65 69 6e 66 6f 2e  thinfo.typeinfo.
7530: 66 69 6c 65 2e 65 78 65 63 75 74 61 62 6c 65 29  file.executable)
7540: 20 7b 0a 09 09 09 09 73 74 62 75 66 2d 3e 73 74   {.....stbuf->st
7550: 5f 6d 6f 64 65 20 7c 3d 20 30 31 31 31 3b 0a 09  _mode |= 0111;..
7560: 09 09 7d 0a 0a 09 09 09 69 66 20 28 70 61 74 68  ..}.....if (path
7570: 69 6e 66 6f 2e 70 61 63 6b 61 67 65 64 29 20 7b  info.packaged) {
7580: 0a 09 09 09 09 69 66 20 28 70 61 74 68 69 6e 66  .....if (pathinf
7590: 6f 2e 74 79 70 65 69 6e 66 6f 2e 66 69 6c 65 2e  o.typeinfo.file.
75a0: 73 75 69 64 52 6f 6f 74 29 20 7b 0a 09 09 09 09  suidRoot) {.....
75b0: 09 63 68 61 6e 67 65 4f 77 6e 65 72 54 6f 55 73  .changeOwnerToUs
75c0: 65 72 49 66 50 61 63 6b 61 67 65 64 20 3d 20 30  erIfPackaged = 0
75d0: 3b 0a 0a 09 09 09 09 09 73 74 62 75 66 2d 3e 73  ;.......stbuf->s
75e0: 74 5f 6d 6f 64 65 20 7c 3d 20 30 34 30 30 30 3b  t_mode |= 04000;
75f0: 0a 09 09 09 09 7d 0a 09 09 09 7d 0a 0a 09 09 09  .....}....}.....
7600: 69 66 20 28 70 61 74 68 69 6e 66 6f 2e 74 79 70  if (pathinfo.typ
7610: 65 69 6e 66 6f 2e 66 69 6c 65 2e 77 6f 72 6c 64  einfo.file.world
7620: 61 63 63 65 73 73 69 62 6c 65 29 20 7b 0a 09 09  accessible) {...
7630: 09 09 73 74 62 75 66 2d 3e 73 74 5f 6d 6f 64 65  ..stbuf->st_mode
7640: 20 26 3d 20 7e 30 37 37 3b 0a 09 09 09 7d 0a 0a   &= ~077;....}..
7650: 09 09 09 73 74 62 75 66 2d 3e 73 74 5f 6e 6c 69  ...stbuf->st_nli
7660: 6e 6b 20 3d 20 31 3b 0a 09 09 09 73 74 62 75 66  nk = 1;....stbuf
7670: 2d 3e 73 74 5f 73 69 7a 65 20 3d 20 70 61 74 68  ->st_size = path
7680: 69 6e 66 6f 2e 74 79 70 65 69 6e 66 6f 2e 66 69  info.typeinfo.fi
7690: 6c 65 2e 73 69 7a 65 3b 0a 0a 09 09 09 62 72 65  le.size;.....bre
76a0: 61 6b 3b 0a 09 09 63 61 73 65 20 41 50 50 46 53  ak;...case APPFS
76b0: 5f 50 41 54 48 54 59 50 45 5f 53 59 4d 4c 49 4e  _PATHTYPE_SYMLIN
76c0: 4b 3a 0a 09 09 09 73 74 62 75 66 2d 3e 73 74 5f  K:....stbuf->st_
76d0: 6d 6f 64 65 20 3d 20 53 5f 49 46 4c 4e 4b 20 7c  mode = S_IFLNK |
76e0: 20 30 35 35 35 3b 0a 09 09 09 73 74 62 75 66 2d   0555;....stbuf-
76f0: 3e 73 74 5f 6e 6c 69 6e 6b 20 3d 20 31 3b 0a 09  >st_nlink = 1;..
7700: 09 09 73 74 62 75 66 2d 3e 73 74 5f 73 69 7a 65  ..stbuf->st_size
7710: 20 3d 20 70 61 74 68 69 6e 66 6f 2e 74 79 70 65   = pathinfo.type
7720: 69 6e 66 6f 2e 73 79 6d 6c 69 6e 6b 2e 73 69 7a  info.symlink.siz
7730: 65 3b 0a 09 09 09 62 72 65 61 6b 3b 0a 09 09 63  e;....break;...c
7740: 61 73 65 20 41 50 50 46 53 5f 50 41 54 48 54 59  ase APPFS_PATHTY
7750: 50 45 5f 53 4f 43 4b 45 54 3a 0a 09 09 09 73 74  PE_SOCKET:....st
7760: 62 75 66 2d 3e 73 74 5f 6d 6f 64 65 20 3d 20 53  buf->st_mode = S
7770: 5f 49 46 53 4f 43 4b 20 7c 20 30 35 35 35 3b 0a  _IFSOCK | 0555;.
7780: 09 09 09 73 74 62 75 66 2d 3e 73 74 5f 6e 6c 69  ...stbuf->st_nli
7790: 6e 6b 20 3d 20 31 3b 0a 09 09 09 73 74 62 75 66  nk = 1;....stbuf
77a0: 2d 3e 73 74 5f 73 69 7a 65 20 3d 20 30 3b 0a 09  ->st_size = 0;..
77b0: 09 09 62 72 65 61 6b 3b 0a 09 09 63 61 73 65 20  ..break;...case 
77c0: 41 50 50 46 53 5f 50 41 54 48 54 59 50 45 5f 46  APPFS_PATHTYPE_F
77d0: 49 46 4f 3a 0a 09 09 09 73 74 62 75 66 2d 3e 73  IFO:....stbuf->s
77e0: 74 5f 6d 6f 64 65 20 3d 20 53 5f 49 46 49 46 4f  t_mode = S_IFIFO
77f0: 20 7c 20 30 35 35 35 3b 0a 09 09 09 73 74 62 75   | 0555;....stbu
7800: 66 2d 3e 73 74 5f 6e 6c 69 6e 6b 20 3d 20 31 3b  f->st_nlink = 1;
7810: 0a 09 09 09 73 74 62 75 66 2d 3e 73 74 5f 73 69  ....stbuf->st_si
7820: 7a 65 20 3d 20 30 3b 0a 09 09 09 62 72 65 61 6b  ze = 0;....break
7830: 3b 0a 09 09 63 61 73 65 20 41 50 50 46 53 5f 50  ;...case APPFS_P
7840: 41 54 48 54 59 50 45 5f 44 4f 45 53 5f 4e 4f 54  ATHTYPE_DOES_NOT
7850: 5f 45 58 49 53 54 3a 0a 09 09 09 72 65 74 76 61  _EXIST:....retva
7860: 6c 20 3d 20 2d 45 4e 4f 45 4e 54 3b 0a 0a 09 09  l = -ENOENT;....
7870: 09 62 72 65 61 6b 3b 0a 09 09 63 61 73 65 20 41  .break;...case A
7880: 50 50 46 53 5f 50 41 54 48 54 59 50 45 5f 49 4e  PPFS_PATHTYPE_IN
7890: 56 41 4c 49 44 3a 0a 09 09 09 72 65 74 76 61 6c  VALID:....retval
78a0: 20 3d 20 2d 45 49 4f 3b 0a 0a 09 09 09 62 72 65   = -EIO;.....bre
78b0: 61 6b 3b 0a 09 7d 0a 0a 09 69 66 20 28 28 70 61  ak;..}...if ((pa
78c0: 74 68 69 6e 66 6f 2e 70 61 63 6b 61 67 65 64 20  thinfo.packaged 
78d0: 26 26 20 63 68 61 6e 67 65 4f 77 6e 65 72 54 6f  && changeOwnerTo
78e0: 55 73 65 72 49 66 50 61 63 6b 61 67 65 64 29 20  UserIfPackaged) 
78f0: 7c 7c 20 28 21 70 61 74 68 69 6e 66 6f 2e 70 61  || (!pathinfo.pa
7900: 63 6b 61 67 65 64 29 29 20 7b 0a 09 09 73 74 62  ckaged)) {...stb
7910: 75 66 2d 3e 73 74 5f 75 69 64 20 20 20 3d 20 61  uf->st_uid   = a
7920: 70 70 66 73 5f 67 65 74 5f 66 73 75 69 64 28 29  ppfs_get_fsuid()
7930: 3b 0a 09 09 73 74 62 75 66 2d 3e 73 74 5f 67 69  ;...stbuf->st_gi
7940: 64 20 20 20 3d 20 61 70 70 66 73 5f 67 65 74 5f  d   = appfs_get_
7950: 66 73 67 69 64 28 29 3b 0a 09 09 73 74 62 75 66  fsgid();...stbuf
7960: 2d 3e 73 74 5f 6d 6f 64 65 20 7c 3d 20 30 32 30  ->st_mode |= 020
7970: 30 3b 0a 09 7d 0a 0a 09 72 65 74 75 72 6e 28 72  0;..}...return(r
7980: 65 74 76 61 6c 29 3b 0a 7d 0a 0a 73 74 61 74 69  etval);.}..stati
7990: 63 20 69 6e 74 20 61 70 70 66 73 5f 66 75 73 65  c int appfs_fuse
79a0: 5f 72 65 61 64 64 69 72 28 63 6f 6e 73 74 20 63  _readdir(const c
79b0: 68 61 72 20 2a 70 61 74 68 2c 20 76 6f 69 64 20  har *path, void 
79c0: 2a 62 75 66 2c 20 66 75 73 65 5f 66 69 6c 6c 5f  *buf, fuse_fill_
79d0: 64 69 72 5f 74 20 66 69 6c 6c 65 72 2c 20 6f 66  dir_t filler, of
79e0: 66 5f 74 20 6f 66 66 73 65 74 2c 20 73 74 72 75  f_t offset, stru
79f0: 63 74 20 66 75 73 65 5f 66 69 6c 65 5f 69 6e 66  ct fuse_file_inf
7a00: 6f 20 2a 66 69 29 20 7b 0a 09 54 63 6c 5f 49 6e  o *fi) {..Tcl_In
7a10: 74 65 72 70 20 2a 69 6e 74 65 72 70 3b 0a 09 54  terp *interp;..T
7a20: 63 6c 5f 4f 62 6a 20 2a 2a 63 68 69 6c 64 72 65  cl_Obj **childre
7a30: 6e 3b 0a 09 69 6e 74 20 63 68 69 6c 64 72 65 6e  n;..int children
7a40: 5f 63 6f 75 6e 74 2c 20 69 64 78 3b 0a 09 69 6e  _count, idx;..in
7a50: 74 20 74 63 6c 5f 72 65 74 3b 0a 0a 09 41 50 50  t tcl_ret;...APP
7a60: 46 53 5f 44 45 42 55 47 28 22 45 6e 74 65 72 20  FS_DEBUG("Enter 
7a70: 28 70 61 74 68 20 3d 20 25 73 2c 20 2e 2e 2e 29  (path = %s, ...)
7a80: 22 2c 20 70 61 74 68 29 3b 0a 0a 09 69 6e 74 65  ", path);...inte
7a90: 72 70 20 3d 20 61 70 70 66 73 5f 54 63 6c 49 6e  rp = appfs_TclIn
7aa0: 74 65 72 70 28 29 3b 0a 09 69 66 20 28 69 6e 74  terp();..if (int
7ab0: 65 72 70 20 3d 3d 20 4e 55 4c 4c 29 20 7b 0a 09  erp == NULL) {..
7ac0: 09 41 50 50 46 53 5f 44 45 42 55 47 28 22 65 72  .APPFS_DEBUG("er
7ad0: 72 6f 72 3a 20 55 6e 61 62 6c 65 20 74 6f 20 67  ror: Unable to g
7ae0: 65 74 20 61 6e 20 69 6e 74 65 72 70 72 65 74 65  et an interprete
7af0: 72 22 29 3b 0a 0a 09 09 72 65 74 75 72 6e 28 30  r");....return(0
7b00: 29 3b 0a 09 7d 0a 0a 09 61 70 70 66 73 5f 63 61  );..}...appfs_ca
7b10: 6c 6c 5f 6c 69 62 74 63 6c 28 54 63 6c 5f 50 72  ll_libtcl(Tcl_Pr
7b20: 65 73 65 72 76 65 28 69 6e 74 65 72 70 29 3b 29  eserve(interp);)
7b30: 0a 0a 09 66 69 6c 6c 65 72 28 62 75 66 2c 20 22  ...filler(buf, "
7b40: 2e 22 2c 20 4e 55 4c 4c 2c 20 30 29 3b 0a 09 66  .", NULL, 0);..f
7b50: 69 6c 6c 65 72 28 62 75 66 2c 20 22 2e 2e 22 2c  iller(buf, "..",
7b60: 20 4e 55 4c 4c 2c 20 30 29 3b 0a 0a 09 74 63 6c   NULL, 0);...tcl
7b70: 5f 72 65 74 20 3d 20 61 70 70 66 73 5f 54 63 6c  _ret = appfs_Tcl
7b80: 5f 45 76 61 6c 28 69 6e 74 65 72 70 2c 20 32 2c  _Eval(interp, 2,
7b90: 20 22 3a 3a 61 70 70 66 73 3a 3a 67 65 74 63 68   "::appfs::getch
7ba0: 69 6c 64 72 65 6e 22 2c 20 70 61 74 68 29 3b 0a  ildren", path);.
7bb0: 09 69 66 20 28 74 63 6c 5f 72 65 74 20 21 3d 20  .if (tcl_ret != 
7bc0: 54 43 4c 5f 4f 4b 29 20 7b 0a 09 09 41 50 50 46  TCL_OK) {...APPF
7bd0: 53 5f 44 45 42 55 47 28 22 3a 3a 61 70 70 66 73  S_DEBUG("::appfs
7be0: 3a 3a 67 65 74 63 68 69 6c 64 72 65 6e 28 25 73  ::getchildren(%s
7bf0: 29 20 66 61 69 6c 65 64 2e 22 2c 20 70 61 74 68  ) failed.", path
7c00: 29 3b 0a 09 09 61 70 70 66 73 5f 63 61 6c 6c 5f  );...appfs_call_
7c10: 6c 69 62 74 63 6c 28 0a 09 09 09 41 50 50 46 53  libtcl(....APPFS
7c20: 5f 44 45 42 55 47 28 22 54 63 6c 20 45 72 72 6f  _DEBUG("Tcl Erro
7c30: 72 20 69 73 3a 20 25 73 22 2c 20 54 63 6c 5f 47  r is: %s", Tcl_G
7c40: 65 74 53 74 72 69 6e 67 52 65 73 75 6c 74 28 69  etStringResult(i
7c50: 6e 74 65 72 70 29 29 3b 0a 09 09 29 0a 0a 09 09  nterp));...)....
7c60: 61 70 70 66 73 5f 63 61 6c 6c 5f 6c 69 62 74 63  appfs_call_libtc
7c70: 6c 28 54 63 6c 5f 52 65 6c 65 61 73 65 28 69 6e  l(Tcl_Release(in
7c80: 74 65 72 70 29 3b 29 0a 0a 09 09 72 65 74 75 72  terp);)....retur
7c90: 6e 28 30 29 3b 0a 09 7d 0a 0a 09 61 70 70 66 73  n(0);..}...appfs
7ca0: 5f 63 61 6c 6c 5f 6c 69 62 74 63 6c 28 0a 09 09  _call_libtcl(...
7cb0: 74 63 6c 5f 72 65 74 20 3d 20 54 63 6c 5f 4c 69  tcl_ret = Tcl_Li
7cc0: 73 74 4f 62 6a 47 65 74 45 6c 65 6d 65 6e 74 73  stObjGetElements
7cd0: 28 69 6e 74 65 72 70 2c 20 54 63 6c 5f 47 65 74  (interp, Tcl_Get
7ce0: 4f 62 6a 52 65 73 75 6c 74 28 69 6e 74 65 72 70  ObjResult(interp
7cf0: 29 2c 20 26 63 68 69 6c 64 72 65 6e 5f 63 6f 75  ), &children_cou
7d00: 6e 74 2c 20 26 63 68 69 6c 64 72 65 6e 29 3b 0a  nt, &children);.
7d10: 09 29 0a 09 69 66 20 28 74 63 6c 5f 72 65 74 20  .)..if (tcl_ret 
7d20: 21 3d 20 54 43 4c 5f 4f 4b 29 20 7b 0a 09 09 41  != TCL_OK) {...A
7d30: 50 50 46 53 5f 44 45 42 55 47 28 22 50 61 72 73  PPFS_DEBUG("Pars
7d40: 69 6e 67 20 6c 69 73 74 20 6f 66 20 63 68 69 6c  ing list of chil
7d50: 64 72 65 6e 20 6f 6e 20 70 61 74 68 20 25 73 20  dren on path %s 
7d60: 66 61 69 6c 65 64 2e 22 2c 20 70 61 74 68 29 3b  failed.", path);
7d70: 0a 09 09 61 70 70 66 73 5f 63 61 6c 6c 5f 6c 69  ...appfs_call_li
7d80: 62 74 63 6c 28 0a 09 09 09 41 50 50 46 53 5f 44  btcl(....APPFS_D
7d90: 45 42 55 47 28 22 54 63 6c 20 45 72 72 6f 72 20  EBUG("Tcl Error 
7da0: 69 73 3a 20 25 73 22 2c 20 54 63 6c 5f 47 65 74  is: %s", Tcl_Get
7db0: 53 74 72 69 6e 67 52 65 73 75 6c 74 28 69 6e 74  StringResult(int
7dc0: 65 72 70 29 29 3b 0a 09 09 29 0a 0a 09 09 61 70  erp));...)....ap
7dd0: 70 66 73 5f 63 61 6c 6c 5f 6c 69 62 74 63 6c 28  pfs_call_libtcl(
7de0: 54 63 6c 5f 52 65 6c 65 61 73 65 28 69 6e 74 65  Tcl_Release(inte
7df0: 72 70 29 3b 29 0a 0a 09 09 72 65 74 75 72 6e 28  rp);)....return(
7e00: 30 29 3b 0a 09 7d 0a 0a 09 66 6f 72 20 28 69 64  0);..}...for (id
7e10: 78 20 3d 20 30 3b 20 69 64 78 20 3c 20 63 68 69  x = 0; idx < chi
7e20: 6c 64 72 65 6e 5f 63 6f 75 6e 74 3b 20 69 64 78  ldren_count; idx
7e30: 2b 2b 29 20 7b 0a 09 09 61 70 70 66 73 5f 63 61  ++) {...appfs_ca
7e40: 6c 6c 5f 6c 69 62 74 63 6c 28 0a 09 09 09 66 69  ll_libtcl(....fi
7e50: 6c 6c 65 72 28 62 75 66 2c 20 54 63 6c 5f 47 65  ller(buf, Tcl_Ge
7e60: 74 53 74 72 69 6e 67 28 63 68 69 6c 64 72 65 6e  tString(children
7e70: 5b 69 64 78 5d 29 2c 20 4e 55 4c 4c 2c 20 30 29  [idx]), NULL, 0)
7e80: 3b 0a 09 09 29 0a 09 7d 0a 0a 09 61 70 70 66 73  ;...)..}...appfs
7e90: 5f 63 61 6c 6c 5f 6c 69 62 74 63 6c 28 54 63 6c  _call_libtcl(Tcl
7ea0: 5f 52 65 6c 65 61 73 65 28 69 6e 74 65 72 70 29  _Release(interp)
7eb0: 3b 29 0a 0a 09 72 65 74 75 72 6e 28 30 29 3b 0a  ;)...return(0);.
7ec0: 7d 0a 0a 73 74 61 74 69 63 20 69 6e 74 20 61 70  }..static int ap
7ed0: 70 66 73 5f 66 75 73 65 5f 6f 70 65 6e 28 63 6f  pfs_fuse_open(co
7ee0: 6e 73 74 20 63 68 61 72 20 2a 70 61 74 68 2c 20  nst char *path, 
7ef0: 73 74 72 75 63 74 20 66 75 73 65 5f 66 69 6c 65  struct fuse_file
7f00: 5f 69 6e 66 6f 20 2a 66 69 29 20 7b 0a 09 54 63  _info *fi) {..Tc
7f10: 6c 5f 49 6e 74 65 72 70 20 2a 69 6e 74 65 72 70  l_Interp *interp
7f20: 3b 0a 09 73 74 72 75 63 74 20 61 70 70 66 73 5f  ;..struct appfs_
7f30: 70 61 74 68 69 6e 66 6f 20 70 61 74 68 69 6e 66  pathinfo pathinf
7f40: 6f 3b 0a 09 63 6f 6e 73 74 20 63 68 61 72 20 2a  o;..const char *
7f50: 72 65 61 6c 5f 70 61 74 68 2c 20 2a 6d 6f 64 65  real_path, *mode
7f60: 3b 0a 09 69 6e 74 20 67 70 69 5f 72 65 74 2c 20  ;..int gpi_ret, 
7f70: 74 63 6c 5f 72 65 74 3b 0a 09 69 6e 74 20 66 68  tcl_ret;..int fh
7f80: 3b 0a 0a 09 41 50 50 46 53 5f 44 45 42 55 47 28  ;...APPFS_DEBUG(
7f90: 22 45 6e 74 65 72 20 28 70 61 74 68 20 3d 20 25  "Enter (path = %
7fa0: 73 2c 20 2e 2e 2e 29 22 2c 20 70 61 74 68 29 3b  s, ...)", path);
7fb0: 0a 0a 09 67 70 69 5f 72 65 74 20 3d 20 61 70 70  ...gpi_ret = app
7fc0: 66 73 5f 67 65 74 5f 70 61 74 68 5f 69 6e 66 6f  fs_get_path_info
7fd0: 28 70 61 74 68 2c 20 26 70 61 74 68 69 6e 66 6f  (path, &pathinfo
7fe0: 29 3b 0a 0a 09 69 66 20 28 28 66 69 2d 3e 66 6c  );...if ((fi->fl
7ff0: 61 67 73 20 26 20 28 4f 5f 57 52 4f 4e 4c 59 7c  ags & (O_WRONLY|
8000: 4f 5f 43 52 45 41 54 29 29 20 3d 3d 20 28 4f 5f  O_CREAT)) == (O_
8010: 43 52 45 41 54 7c 4f 5f 57 52 4f 4e 4c 59 29 29  CREAT|O_WRONLY))
8020: 20 7b 0a 09 09 2f 2a 20 54 68 65 20 66 69 6c 65   {.../* The file
8030: 20 77 69 6c 6c 20 62 65 20 63 72 65 61 74 65 64   will be created
8040: 20 69 66 20 69 74 20 64 6f 65 73 20 6e 6f 74 20   if it does not 
8050: 65 78 69 73 74 20 2a 2f 0a 09 09 69 66 20 28 67  exist */...if (g
8060: 70 69 5f 72 65 74 20 21 3d 20 30 20 26 26 20 67  pi_ret != 0 && g
8070: 70 69 5f 72 65 74 20 21 3d 20 2d 45 4e 4f 45 4e  pi_ret != -ENOEN
8080: 54 29 20 7b 0a 09 09 09 41 50 50 46 53 5f 44 45  T) {....APPFS_DE
8090: 42 55 47 28 22 65 72 72 6f 72 3a 20 67 65 74 5f  BUG("error: get_
80a0: 70 61 74 68 5f 69 6e 66 6f 20 66 61 69 6c 65 64  path_info failed
80b0: 22 29 3b 0a 0a 09 09 09 72 65 74 75 72 6e 28 67  ");.....return(g
80c0: 70 69 5f 72 65 74 29 3b 0a 09 09 7d 0a 0a 09 09  pi_ret);...}....
80d0: 6d 6f 64 65 20 3d 20 22 63 72 65 61 74 65 22 3b  mode = "create";
80e0: 0a 0a 09 09 2f 2a 0a 09 09 20 2a 20 57 65 20 68  ..../*... * We h
80f0: 61 76 65 20 74 6f 20 63 6c 65 61 72 20 74 68 65  ave to clear the
8100: 20 63 61 63 68 65 20 68 65 72 65 20 73 6f 20 74   cache here so t
8110: 68 61 74 20 74 68 65 20 6e 75 6d 62 65 72 20 6f  hat the number o
8120: 66 0a 09 09 20 2a 20 6c 69 6e 6b 73 20 67 65 74  f... * links get
8130: 73 20 6d 61 69 6e 74 61 69 6e 65 64 20 6f 6e 20  s maintained on 
8140: 74 68 65 20 70 61 72 65 6e 74 20 64 69 72 65 63  the parent direc
8150: 74 6f 72 79 0a 09 09 20 2a 2f 0a 09 09 61 70 70  tory... */...app
8160: 66 73 5f 67 65 74 5f 70 61 74 68 5f 69 6e 66 6f  fs_get_path_info
8170: 5f 63 61 63 68 65 5f 66 6c 75 73 68 28 61 70 70  _cache_flush(app
8180: 66 73 5f 67 65 74 5f 66 73 75 69 64 28 29 2c 20  fs_get_fsuid(), 
8190: 2d 31 29 3b 0a 09 7d 20 65 6c 73 65 20 7b 0a 09  -1);..} else {..
81a0: 09 2f 2a 20 54 68 65 20 66 69 6c 65 20 6d 75 73  ./* The file mus
81b0: 74 20 61 6c 72 65 61 64 79 20 65 78 69 73 74 20  t already exist 
81c0: 2a 2f 0a 09 09 69 66 20 28 67 70 69 5f 72 65 74  */...if (gpi_ret
81d0: 20 21 3d 20 30 29 20 7b 0a 09 09 09 41 50 50 46   != 0) {....APPF
81e0: 53 5f 44 45 42 55 47 28 22 65 72 72 6f 72 3a 20  S_DEBUG("error: 
81f0: 67 65 74 5f 70 61 74 68 5f 69 6e 66 6f 20 66 61  get_path_info fa
8200: 69 6c 65 64 22 29 3b 0a 0a 09 09 09 72 65 74 75  iled");.....retu
8210: 72 6e 28 67 70 69 5f 72 65 74 29 3b 0a 09 09 7d  rn(gpi_ret);...}
8220: 0a 0a 09 09 6d 6f 64 65 20 3d 20 22 22 3b 0a 0a  ....mode = "";..
8230: 09 09 69 66 20 28 28 66 69 2d 3e 66 6c 61 67 73  ..if ((fi->flags
8240: 20 26 20 4f 5f 57 52 4f 4e 4c 59 29 20 3d 3d 20   & O_WRONLY) == 
8250: 4f 5f 57 52 4f 4e 4c 59 29 20 7b 0a 09 09 09 6d  O_WRONLY) {....m
8260: 6f 64 65 20 3d 20 22 77 72 69 74 65 22 3b 0a 09  ode = "write";..
8270: 09 7d 0a 09 7d 0a 0a 09 69 66 20 28 70 61 74 68  .}..}...if (path
8280: 69 6e 66 6f 2e 74 79 70 65 20 3d 3d 20 41 50 50  info.type == APP
8290: 46 53 5f 50 41 54 48 54 59 50 45 5f 44 49 52 45  FS_PATHTYPE_DIRE
82a0: 43 54 4f 52 59 29 20 7b 0a 09 09 41 50 50 46 53  CTORY) {...APPFS
82b0: 5f 44 45 42 55 47 28 22 65 72 72 6f 72 3a 20 41  _DEBUG("error: A
82c0: 73 6b 65 64 20 74 6f 20 6f 70 65 6e 20 61 20 64  sked to open a d
82d0: 69 72 65 63 74 6f 72 79 2e 22 29 3b 0a 0a 09 09  irectory.");....
82e0: 72 65 74 75 72 6e 28 2d 45 49 53 44 49 52 29 3b  return(-EISDIR);
82f0: 0a 09 7d 0a 0a 09 69 6e 74 65 72 70 20 3d 20 61  ..}...interp = a
8300: 70 70 66 73 5f 54 63 6c 49 6e 74 65 72 70 28 29  ppfs_TclInterp()
8310: 3b 0a 09 69 66 20 28 69 6e 74 65 72 70 20 3d 3d  ;..if (interp ==
8320: 20 4e 55 4c 4c 29 20 7b 0a 09 09 41 50 50 46 53   NULL) {...APPFS
8330: 5f 44 45 42 55 47 28 22 65 72 72 6f 72 3a 20 55  _DEBUG("error: U
8340: 6e 61 62 6c 65 20 74 6f 20 67 65 74 20 61 6e 20  nable to get an 
8350: 69 6e 74 65 72 70 72 65 74 65 72 22 29 3b 0a 0a  interpreter");..
8360: 09 09 72 65 74 75 72 6e 28 2d 45 49 4f 29 3b 0a  ..return(-EIO);.
8370: 09 7d 0a 0a 09 61 70 70 66 73 5f 63 61 6c 6c 5f  .}...appfs_call_
8380: 6c 69 62 74 63 6c 28 54 63 6c 5f 50 72 65 73 65  libtcl(Tcl_Prese
8390: 72 76 65 28 69 6e 74 65 72 70 29 3b 29 0a 0a 09  rve(interp);)...
83a0: 74 63 6c 5f 72 65 74 20 3d 20 61 70 70 66 73 5f  tcl_ret = appfs_
83b0: 54 63 6c 5f 45 76 61 6c 28 69 6e 74 65 72 70 2c  Tcl_Eval(interp,
83c0: 20 33 2c 20 22 3a 3a 61 70 70 66 73 3a 3a 6f 70   3, "::appfs::op
83d0: 65 6e 70 61 74 68 22 2c 20 70 61 74 68 2c 20 6d  enpath", path, m
83e0: 6f 64 65 29 3b 0a 09 69 66 20 28 74 63 6c 5f 72  ode);..if (tcl_r
83f0: 65 74 20 21 3d 20 54 43 4c 5f 4f 4b 29 20 7b 0a  et != TCL_OK) {.
8400: 09 09 41 50 50 46 53 5f 44 45 42 55 47 28 22 3a  ..APPFS_DEBUG(":
8410: 3a 61 70 70 66 73 3a 3a 6f 70 65 6e 70 61 74 68  :appfs::openpath
8420: 28 25 73 2c 20 25 73 29 20 66 61 69 6c 65 64 2e  (%s, %s) failed.
8430: 22 2c 20 70 61 74 68 2c 20 6d 6f 64 65 29 3b 0a  ", path, mode);.
8440: 09 09 61 70 70 66 73 5f 63 61 6c 6c 5f 6c 69 62  ..appfs_call_lib
8450: 74 63 6c 28 0a 09 09 09 41 50 50 46 53 5f 44 45  tcl(....APPFS_DE
8460: 42 55 47 28 22 54 63 6c 20 45 72 72 6f 72 20 69  BUG("Tcl Error i
8470: 73 3a 20 25 73 22 2c 20 54 63 6c 5f 47 65 74 53  s: %s", Tcl_GetS
8480: 74 72 69 6e 67 52 65 73 75 6c 74 28 69 6e 74 65  tringResult(inte
8490: 72 70 29 29 3b 0a 09 09 29 0a 0a 09 09 61 70 70  rp));...)....app
84a0: 66 73 5f 63 61 6c 6c 5f 6c 69 62 74 63 6c 28 54  fs_call_libtcl(T
84b0: 63 6c 5f 52 65 6c 65 61 73 65 28 69 6e 74 65 72  cl_Release(inter
84c0: 70 29 3b 29 0a 0a 09 09 72 65 74 75 72 6e 28 2d  p);)....return(-
84d0: 45 49 4f 29 3b 0a 09 7d 0a 0a 09 61 70 70 66 73  EIO);..}...appfs
84e0: 5f 63 61 6c 6c 5f 6c 69 62 74 63 6c 28 0a 09 09  _call_libtcl(...
84f0: 72 65 61 6c 5f 70 61 74 68 20 3d 20 54 63 6c 5f  real_path = Tcl_
8500: 47 65 74 53 74 72 69 6e 67 52 65 73 75 6c 74 28  GetStringResult(
8510: 69 6e 74 65 72 70 29 3b 0a 09 29 0a 0a 09 61 70  interp);..)...ap
8520: 70 66 73 5f 63 61 6c 6c 5f 6c 69 62 74 63 6c 28  pfs_call_libtcl(
8530: 54 63 6c 5f 52 65 6c 65 61 73 65 28 69 6e 74 65  Tcl_Release(inte
8540: 72 70 29 3b 29 0a 0a 09 69 66 20 28 72 65 61 6c  rp);)...if (real
8550: 5f 70 61 74 68 20 3d 3d 20 4e 55 4c 4c 29 20 7b  _path == NULL) {
8560: 0a 09 09 41 50 50 46 53 5f 44 45 42 55 47 28 22  ...APPFS_DEBUG("
8570: 65 72 72 6f 72 3a 20 72 65 61 6c 5f 70 61 74 68  error: real_path
8580: 20 77 61 73 20 4e 55 4c 4c 2e 22 29 0a 0a 09 09   was NULL.")....
8590: 72 65 74 75 72 6e 28 2d 45 49 4f 29 3b 0a 09 7d  return(-EIO);..}
85a0: 0a 0a 09 41 50 50 46 53 5f 44 45 42 55 47 28 22  ...APPFS_DEBUG("
85b0: 54 72 61 6e 73 6c 61 74 65 64 20 72 65 71 75 65  Translated reque
85c0: 73 74 20 74 6f 20 6f 70 65 6e 20 25 73 20 74 6f  st to open %s to
85d0: 20 6f 70 65 6e 69 6e 67 20 25 73 20 28 6d 6f 64   opening %s (mod
85e0: 65 20 3d 20 5c 22 25 73 5c 22 29 22 2c 20 70 61  e = \"%s\")", pa
85f0: 74 68 2c 20 72 65 61 6c 5f 70 61 74 68 2c 20 6d  th, real_path, m
8600: 6f 64 65 29 3b 0a 0a 09 66 68 20 3d 20 6f 70 65  ode);...fh = ope
8610: 6e 28 72 65 61 6c 5f 70 61 74 68 2c 20 66 69 2d  n(real_path, fi-
8620: 3e 66 6c 61 67 73 2c 20 30 36 30 30 29 3b 0a 0a  >flags, 0600);..
8630: 09 69 66 20 28 66 68 20 3c 20 30 29 20 7b 0a 09  .if (fh < 0) {..
8640: 09 41 50 50 46 53 5f 44 45 42 55 47 28 22 65 72  .APPFS_DEBUG("er
8650: 72 6f 72 3a 20 6f 70 65 6e 20 66 61 69 6c 65 64  ror: open failed
8660: 22 29 3b 0a 0a 09 09 72 65 74 75 72 6e 28 65 72  ");....return(er
8670: 72 6e 6f 20 2a 20 2d 31 29 3b 0a 09 7d 0a 0a 09  rno * -1);..}...
8680: 66 69 2d 3e 66 68 20 3d 20 66 68 3b 0a 0a 09 41  fi->fh = fh;...A
8690: 50 50 46 53 5f 44 45 42 55 47 28 22 4f 70 65 6e  PPFS_DEBUG("Open
86a0: 65 64 20 5c 22 25 73 5c 22 20 28 66 6f 72 20 5c  ed \"%s\" (for \
86b0: 22 25 73 5c 22 29 20 77 69 74 68 20 66 69 6c 65  "%s\") with file
86c0: 20 64 65 73 63 72 69 70 74 6f 72 20 25 69 22 2c   descriptor %i",
86d0: 20 72 65 61 6c 5f 70 61 74 68 2c 20 70 61 74 68   real_path, path
86e0: 2c 20 66 68 29 3b 0a 0a 09 72 65 74 75 72 6e 28  , fh);...return(
86f0: 30 29 3b 0a 7d 0a 0a 73 74 61 74 69 63 20 69 6e  0);.}..static in
8700: 74 20 61 70 70 66 73 5f 66 75 73 65 5f 63 6c 6f  t appfs_fuse_clo
8710: 73 65 28 63 6f 6e 73 74 20 63 68 61 72 20 2a 70  se(const char *p
8720: 61 74 68 2c 20 73 74 72 75 63 74 20 66 75 73 65  ath, struct fuse
8730: 5f 66 69 6c 65 5f 69 6e 66 6f 20 2a 66 69 29 20  _file_info *fi) 
8740: 7b 0a 09 69 6e 74 20 63 6c 6f 73 65 5f 72 65 74  {..int close_ret
8750: 3b 0a 0a 09 61 70 70 66 73 5f 67 65 74 5f 70 61  ;...appfs_get_pa
8760: 74 68 5f 69 6e 66 6f 5f 63 61 63 68 65 5f 72 6d  th_info_cache_rm
8770: 28 70 61 74 68 2c 20 61 70 70 66 73 5f 67 65 74  (path, appfs_get
8780: 5f 66 73 75 69 64 28 29 29 3b 0a 0a 09 63 6c 6f  _fsuid());...clo
8790: 73 65 5f 72 65 74 20 3d 20 63 6c 6f 73 65 28 66  se_ret = close(f
87a0: 69 2d 3e 66 68 29 3b 0a 09 69 66 20 28 63 6c 6f  i->fh);..if (clo
87b0: 73 65 5f 72 65 74 20 21 3d 20 30 29 20 7b 0a 09  se_ret != 0) {..
87c0: 09 41 50 50 46 53 5f 44 45 42 55 47 28 22 65 72  .APPFS_DEBUG("er
87d0: 72 6f 72 3a 20 63 6c 6f 73 65 20 66 61 69 6c 65  ror: close faile
87e0: 64 22 29 3b 0a 0a 09 09 72 65 74 75 72 6e 28 65  d");....return(e
87f0: 72 72 6e 6f 20 2a 20 2d 31 29 3b 0a 09 7d 0a 0a  rrno * -1);..}..
8800: 09 72 65 74 75 72 6e 28 30 29 3b 0a 7d 0a 0a 73  .return(0);.}..s
8810: 74 61 74 69 63 20 69 6e 74 20 61 70 70 66 73 5f  tatic int appfs_
8820: 66 75 73 65 5f 72 65 61 64 28 63 6f 6e 73 74 20  fuse_read(const 
8830: 63 68 61 72 20 2a 70 61 74 68 2c 20 63 68 61 72  char *path, char
8840: 20 2a 62 75 66 2c 20 73 69 7a 65 5f 74 20 73 69   *buf, size_t si
8850: 7a 65 2c 20 6f 66 66 5f 74 20 6f 66 66 73 65 74  ze, off_t offset
8860: 2c 20 73 74 72 75 63 74 20 66 75 73 65 5f 66 69  , struct fuse_fi
8870: 6c 65 5f 69 6e 66 6f 20 2a 66 69 29 20 7b 0a 09  le_info *fi) {..
8880: 73 73 69 7a 65 5f 74 20 72 65 61 64 5f 72 65 74  ssize_t read_ret
8890: 3b 0a 09 69 6e 74 20 72 65 74 76 61 6c 3b 0a 0a  ;..int retval;..
88a0: 09 41 50 50 46 53 5f 44 45 42 55 47 28 22 45 6e  .APPFS_DEBUG("En
88b0: 74 65 72 20 28 70 61 74 68 20 3d 20 25 73 2c 20  ter (path = %s, 
88c0: 62 75 66 2c 20 73 69 7a 65 20 3d 20 25 6c 6c 69  buf, size = %lli
88d0: 2c 20 6f 66 66 73 65 74 20 3d 20 25 6c 6c 69 2c  , offset = %lli,
88e0: 20 66 64 20 3d 20 25 6c 6c 69 29 22 2c 20 70 61   fd = %lli)", pa
88f0: 74 68 2c 20 28 6c 6f 6e 67 20 6c 6f 6e 67 29 20  th, (long long) 
8900: 73 69 7a 65 2c 20 28 6c 6f 6e 67 20 6c 6f 6e 67  size, (long long
8910: 29 20 6f 66 66 73 65 74 2c 20 28 6c 6f 6e 67 20  ) offset, (long 
8920: 6c 6f 6e 67 29 20 66 69 2d 3e 66 68 29 3b 0a 0a  long) fi->fh);..
8930: 09 72 65 74 76 61 6c 20 3d 20 30 3b 0a 0a 09 77  .retval = 0;...w
8940: 68 69 6c 65 20 28 73 69 7a 65 20 21 3d 20 30 29  hile (size != 0)
8950: 20 7b 0a 09 09 72 65 61 64 5f 72 65 74 20 3d 20   {...read_ret = 
8960: 70 72 65 61 64 28 66 69 2d 3e 66 68 2c 20 62 75  pread(fi->fh, bu
8970: 66 2c 20 73 69 7a 65 2c 20 6f 66 66 73 65 74 29  f, size, offset)
8980: 3b 0a 0a 09 09 69 66 20 28 72 65 61 64 5f 72 65  ;....if (read_re
8990: 74 20 3c 20 30 29 20 7b 0a 09 09 09 41 50 50 46  t < 0) {....APPF
89a0: 53 5f 44 45 42 55 47 28 22 65 72 72 6f 72 3a 20  S_DEBUG("error: 
89b0: 72 65 61 64 20 66 61 69 6c 65 64 22 29 3b 0a 0a  read failed");..
89c0: 09 09 09 72 65 74 75 72 6e 28 65 72 72 6e 6f 20  ...return(errno 
89d0: 2a 20 2d 31 29 3b 0a 09 09 7d 0a 0a 09 09 69 66  * -1);...}....if
89e0: 20 28 72 65 61 64 5f 72 65 74 20 3d 3d 20 30 29   (read_ret == 0)
89f0: 20 7b 0a 09 09 09 62 72 65 61 6b 3b 0a 09 09 7d   {....break;...}
8a00: 0a 0a 09 09 73 69 7a 65 20 2d 3d 20 72 65 61 64  ....size -= read
8a10: 5f 72 65 74 3b 0a 09 09 62 75 66 20 20 2b 3d 20  _ret;...buf  += 
8a20: 72 65 61 64 5f 72 65 74 3b 0a 09 09 6f 66 66 73  read_ret;...offs
8a30: 65 74 20 2b 3d 20 72 65 61 64 5f 72 65 74 3b 0a  et += read_ret;.
8a40: 09 09 72 65 74 76 61 6c 20 2b 3d 20 72 65 61 64  ..retval += read
8a50: 5f 72 65 74 3b 0a 09 7d 0a 0a 09 69 66 20 28 73  _ret;..}...if (s
8a60: 69 7a 65 20 21 3d 20 30 29 20 7b 0a 09 09 41 50  ize != 0) {...AP
8a70: 50 46 53 5f 44 45 42 55 47 28 22 65 72 72 6f 72  PFS_DEBUG("error
8a80: 3a 20 69 6e 63 6f 6d 70 6c 65 74 65 20 72 65 61  : incomplete rea
8a90: 64 20 28 74 68 69 73 20 6d 69 67 68 74 20 62 65  d (this might be
8aa0: 20 61 6e 20 65 72 72 6f 72 20 62 65 63 61 75 73   an error becaus
8ab0: 65 20 46 55 53 45 20 77 69 6c 6c 20 72 65 71 75  e FUSE will requ
8ac0: 65 73 74 20 74 68 65 20 65 78 61 63 74 20 6c 65  est the exact le
8ad0: 6e 67 74 68 20 6f 66 20 74 68 65 20 66 69 6c 65  ngth of the file
8ae0: 29 22 29 3b 0a 09 7d 0a 0a 09 41 50 50 46 53 5f  )");..}...APPFS_
8af0: 44 45 42 55 47 28 22 52 65 74 75 72 6e 69 6e 67  DEBUG("Returning
8b00: 3a 20 25 69 22 2c 20 72 65 74 76 61 6c 29 3b 0a  : %i", retval);.
8b10: 0a 09 72 65 74 75 72 6e 28 72 65 74 76 61 6c 29  ..return(retval)
8b20: 3b 0a 7d 0a 0a 73 74 61 74 69 63 20 69 6e 74 20  ;.}..static int 
8b30: 61 70 70 66 73 5f 66 75 73 65 5f 77 72 69 74 65  appfs_fuse_write
8b40: 28 63 6f 6e 73 74 20 63 68 61 72 20 2a 70 61 74  (const char *pat
8b50: 68 2c 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 62  h, const char *b
8b60: 75 66 2c 20 73 69 7a 65 5f 74 20 73 69 7a 65 2c  uf, size_t size,
8b70: 20 6f 66 66 5f 74 20 6f 66 66 73 65 74 2c 20 73   off_t offset, s
8b80: 74 72 75 63 74 20 66 75 73 65 5f 66 69 6c 65 5f  truct fuse_file_
8b90: 69 6e 66 6f 20 2a 66 69 29 20 7b 0a 09 73 73 69  info *fi) {..ssi
8ba0: 7a 65 5f 74 20 77 72 69 74 65 5f 72 65 74 3b 0a  ze_t write_ret;.
8bb0: 09 69 6e 74 20 72 65 74 76 61 6c 3b 0a 0a 09 41  .int retval;...A
8bc0: 50 50 46 53 5f 44 45 42 55 47 28 22 45 6e 74 65  PPFS_DEBUG("Ente
8bd0: 72 20 28 70 61 74 68 20 3d 20 25 73 2c 20 2e 2e  r (path = %s, ..
8be0: 2e 29 22 2c 20 70 61 74 68 29 3b 0a 0a 09 61 70  .)", path);...ap
8bf0: 70 66 73 5f 67 65 74 5f 70 61 74 68 5f 69 6e 66  pfs_get_path_inf
8c00: 6f 5f 63 61 63 68 65 5f 72 6d 28 70 61 74 68 2c  o_cache_rm(path,
8c10: 20 61 70 70 66 73 5f 67 65 74 5f 66 73 75 69 64   appfs_get_fsuid
8c20: 28 29 29 3b 0a 0a 09 72 65 74 76 61 6c 20 3d 20  ());...retval = 
8c30: 30 3b 0a 0a 09 77 68 69 6c 65 20 28 73 69 7a 65  0;...while (size
8c40: 20 21 3d 20 30 29 20 7b 0a 09 09 77 72 69 74 65   != 0) {...write
8c50: 5f 72 65 74 20 3d 20 70 77 72 69 74 65 28 66 69  _ret = pwrite(fi
8c60: 2d 3e 66 68 2c 20 62 75 66 2c 20 73 69 7a 65 2c  ->fh, buf, size,
8c70: 20 6f 66 66 73 65 74 29 3b 0a 0a 09 09 69 66 20   offset);....if 
8c80: 28 77 72 69 74 65 5f 72 65 74 20 3c 20 30 29 20  (write_ret < 0) 
8c90: 7b 0a 09 09 09 41 50 50 46 53 5f 44 45 42 55 47  {....APPFS_DEBUG
8ca0: 28 22 65 72 72 6f 72 3a 20 77 72 69 74 65 20 66  ("error: write f
8cb0: 61 69 6c 65 64 22 29 3b 0a 0a 09 09 09 72 65 74  ailed");.....ret
8cc0: 75 72 6e 28 65 72 72 6e 6f 20 2a 20 2d 31 29 3b  urn(errno * -1);
8cd0: 0a 09 09 7d 0a 0a 09 09 69 66 20 28 77 72 69 74  ...}....if (writ
8ce0: 65 5f 72 65 74 20 3d 3d 20 30 29 20 7b 0a 09 09  e_ret == 0) {...
8cf0: 09 62 72 65 61 6b 3b 0a 09 09 7d 0a 0a 09 09 73  .break;...}....s
8d00: 69 7a 65 20 2d 3d 20 77 72 69 74 65 5f 72 65 74  ize -= write_ret
8d10: 3b 0a 09 09 62 75 66 20 20 2b 3d 20 77 72 69 74  ;...buf  += writ
8d20: 65 5f 72 65 74 3b 0a 09 09 6f 66 66 73 65 74 20  e_ret;...offset 
8d30: 2b 3d 20 77 72 69 74 65 5f 72 65 74 3b 0a 09 09  += write_ret;...
8d40: 72 65 74 76 61 6c 20 2b 3d 20 77 72 69 74 65 5f  retval += write_
8d50: 72 65 74 3b 0a 09 7d 0a 0a 09 69 66 20 28 73 69  ret;..}...if (si
8d60: 7a 65 20 21 3d 20 30 29 20 7b 0a 09 09 41 50 50  ze != 0) {...APP
8d70: 46 53 5f 44 45 42 55 47 28 22 65 72 72 6f 72 3a  FS_DEBUG("error:
8d80: 20 69 6e 63 6f 6d 70 6c 65 74 65 20 77 72 69 74   incomplete writ
8d90: 65 22 29 3b 0a 09 7d 0a 0a 09 72 65 74 75 72 6e  e");..}...return
8da0: 28 72 65 74 76 61 6c 29 3b 0a 7d 0a 0a 73 74 61  (retval);.}..sta
8db0: 74 69 63 20 69 6e 74 20 61 70 70 66 73 5f 66 75  tic int appfs_fu
8dc0: 73 65 5f 6d 6b 6e 6f 64 28 63 6f 6e 73 74 20 63  se_mknod(const c
8dd0: 68 61 72 20 2a 70 61 74 68 2c 20 6d 6f 64 65 5f  har *path, mode_
8de0: 74 20 6d 6f 64 65 2c 20 64 65 76 5f 74 20 64 65  t mode, dev_t de
8df0: 76 69 63 65 29 20 7b 0a 09 63 68 61 72 20 2a 72  vice) {..char *r
8e00: 65 61 6c 5f 70 61 74 68 3b 0a 09 69 6e 74 20 6d  eal_path;..int m
8e10: 6b 6e 6f 64 5f 72 65 74 3b 0a 0a 09 41 50 50 46  knod_ret;...APPF
8e20: 53 5f 44 45 42 55 47 28 22 45 6e 74 65 72 20 28  S_DEBUG("Enter (
8e30: 70 61 74 68 20 3d 20 25 73 2c 20 2e 2e 2e 29 22  path = %s, ...)"
8e40: 2c 20 70 61 74 68 29 3b 0a 0a 09 69 66 20 28 28  , path);...if ((
8e50: 6d 6f 64 65 20 26 20 53 5f 49 46 43 48 52 29 20  mode & S_IFCHR) 
8e60: 3d 3d 20 53 5f 49 46 43 48 52 29 20 7b 0a 09 09  == S_IFCHR) {...
8e70: 72 65 74 75 72 6e 28 2d 45 50 45 52 4d 29 3b 0a  return(-EPERM);.
8e80: 09 7d 0a 0a 09 69 66 20 28 28 6d 6f 64 65 20 26  .}...if ((mode &
8e90: 20 53 5f 49 46 42 4c 4b 29 20 3d 3d 20 53 5f 49   S_IFBLK) == S_I
8ea0: 46 42 4c 4b 29 20 7b 0a 09 09 72 65 74 75 72 6e  FBLK) {...return
8eb0: 28 2d 45 50 45 52 4d 29 3b 0a 09 7d 0a 0a 09 72  (-EPERM);..}...r
8ec0: 65 61 6c 5f 70 61 74 68 20 3d 20 61 70 70 66 73  eal_path = appfs
8ed0: 5f 70 72 65 70 61 72 65 5f 74 6f 5f 63 72 65 61  _prepare_to_crea
8ee0: 74 65 28 70 61 74 68 29 3b 0a 09 69 66 20 28 72  te(path);..if (r
8ef0: 65 61 6c 5f 70 61 74 68 20 3d 3d 20 4e 55 4c 4c  eal_path == NULL
8f00: 29 20 7b 0a 09 09 72 65 74 75 72 6e 28 2d 45 49  ) {...return(-EI
8f10: 4f 29 3b 0a 09 7d 0a 0a 09 61 70 70 66 73 5f 73  O);..}...appfs_s
8f20: 69 6d 75 6c 61 74 65 5f 75 73 65 72 5f 66 73 5f  imulate_user_fs_
8f30: 65 6e 74 65 72 28 29 3b 0a 0a 09 6d 6b 6e 6f 64  enter();...mknod
8f40: 5f 72 65 74 20 3d 20 6d 6b 6e 6f 64 28 72 65 61  _ret = mknod(rea
8f50: 6c 5f 70 61 74 68 2c 20 6d 6f 64 65 2c 20 64 65  l_path, mode, de
8f60: 76 69 63 65 29 3b 0a 0a 09 61 70 70 66 73 5f 73  vice);...appfs_s
8f70: 69 6d 75 6c 61 74 65 5f 75 73 65 72 5f 66 73 5f  imulate_user_fs_
8f80: 6c 65 61 76 65 28 29 3b 0a 0a 09 66 72 65 65 28  leave();...free(
8f90: 72 65 61 6c 5f 70 61 74 68 29 3b 0a 0a 09 69 66  real_path);...if
8fa0: 20 28 6d 6b 6e 6f 64 5f 72 65 74 20 21 3d 20 30   (mknod_ret != 0
8fb0: 29 20 7b 0a 09 09 72 65 74 75 72 6e 28 65 72 72  ) {...return(err
8fc0: 6e 6f 20 2a 20 2d 31 29 3b 0a 09 7d 0a 0a 09 72  no * -1);..}...r
8fd0: 65 74 75 72 6e 28 30 29 3b 0a 7d 0a 0a 73 74 61  eturn(0);.}..sta
8fe0: 74 69 63 20 69 6e 74 20 61 70 70 66 73 5f 66 75  tic int appfs_fu
8ff0: 73 65 5f 63 72 65 61 74 65 28 63 6f 6e 73 74 20  se_create(const 
9000: 63 68 61 72 20 2a 70 61 74 68 2c 20 6d 6f 64 65  char *path, mode
9010: 5f 74 20 6d 6f 64 65 2c 20 73 74 72 75 63 74 20  _t mode, struct 
9020: 66 75 73 65 5f 66 69 6c 65 5f 69 6e 66 6f 20 2a  fuse_file_info *
9030: 66 69 29 20 7b 0a 09 63 68 61 72 20 2a 72 65 61  fi) {..char *rea
9040: 6c 5f 70 61 74 68 3b 0a 09 69 6e 74 20 66 64 3b  l_path;..int fd;
9050: 0a 0a 09 41 50 50 46 53 5f 44 45 42 55 47 28 22  ...APPFS_DEBUG("
9060: 45 6e 74 65 72 20 28 70 61 74 68 20 3d 20 25 73  Enter (path = %s
9070: 2c 20 2e 2e 2e 29 22 2c 20 70 61 74 68 29 3b 0a  , ...)", path);.
9080: 0a 09 69 66 20 28 28 6d 6f 64 65 20 26 20 53 5f  ..if ((mode & S_
9090: 49 46 43 48 52 29 20 3d 3d 20 53 5f 49 46 43 48  IFCHR) == S_IFCH
90a0: 52 29 20 7b 0a 09 09 72 65 74 75 72 6e 28 2d 45  R) {...return(-E
90b0: 50 45 52 4d 29 3b 0a 09 7d 0a 0a 09 69 66 20 28  PERM);..}...if (
90c0: 28 6d 6f 64 65 20 26 20 53 5f 49 46 42 4c 4b 29  (mode & S_IFBLK)
90d0: 20 3d 3d 20 53 5f 49 46 42 4c 4b 29 20 7b 0a 09   == S_IFBLK) {..
90e0: 09 72 65 74 75 72 6e 28 2d 45 50 45 52 4d 29 3b  .return(-EPERM);
90f0: 0a 09 7d 0a 0a 09 72 65 61 6c 5f 70 61 74 68 20  ..}...real_path 
9100: 3d 20 61 70 70 66 73 5f 70 72 65 70 61 72 65 5f  = appfs_prepare_
9110: 74 6f 5f 63 72 65 61 74 65 28 70 61 74 68 29 3b  to_create(path);
9120: 0a 09 69 66 20 28 72 65 61 6c 5f 70 61 74 68 20  ..if (real_path 
9130: 3d 3d 20 4e 55 4c 4c 29 20 7b 0a 09 09 72 65 74  == NULL) {...ret
9140: 75 72 6e 28 2d 45 49 4f 29 3b 0a 09 7d 0a 0a 09  urn(-EIO);..}...
9150: 61 70 70 66 73 5f 73 69 6d 75 6c 61 74 65 5f 75  appfs_simulate_u
9160: 73 65 72 5f 66 73 5f 65 6e 74 65 72 28 29 3b 0a  ser_fs_enter();.
9170: 0a 09 66 64 20 3d 20 63 72 65 61 74 28 72 65 61  ..fd = creat(rea
9180: 6c 5f 70 61 74 68 2c 20 6d 6f 64 65 29 3b 0a 0a  l_path, mode);..
9190: 09 61 70 70 66 73 5f 73 69 6d 75 6c 61 74 65 5f  .appfs_simulate_
91a0: 75 73 65 72 5f 66 73 5f 6c 65 61 76 65 28 29 3b  user_fs_leave();
91b0: 0a 0a 09 66 72 65 65 28 72 65 61 6c 5f 70 61 74  ...free(real_pat
91c0: 68 29 3b 0a 0a 09 69 66 20 28 66 64 20 3c 20 30  h);...if (fd < 0
91d0: 29 20 7b 0a 09 09 72 65 74 75 72 6e 28 65 72 72  ) {...return(err
91e0: 6e 6f 20 2a 20 2d 31 29 3b 0a 09 7d 0a 0a 09 66  no * -1);..}...f
91f0: 69 2d 3e 66 68 20 3d 20 66 64 3b 0a 0a 09 72 65  i->fh = fd;...re
9200: 74 75 72 6e 28 30 29 3b 0a 7d 0a 0a 73 74 61 74  turn(0);.}..stat
9210: 69 63 20 69 6e 74 20 61 70 70 66 73 5f 66 75 73  ic int appfs_fus
9220: 65 5f 74 72 75 6e 63 61 74 65 28 63 6f 6e 73 74  e_truncate(const
9230: 20 63 68 61 72 20 2a 70 61 74 68 2c 20 6f 66 66   char *path, off
9240: 5f 74 20 73 69 7a 65 29 20 7b 0a 09 63 68 61 72  _t size) {..char
9250: 20 2a 72 65 61 6c 5f 70 61 74 68 3b 0a 09 69 6e   *real_path;..in
9260: 74 20 74 72 75 6e 63 61 74 65 5f 72 65 74 3b 0a  t truncate_ret;.
9270: 0a 09 41 50 50 46 53 5f 44 45 42 55 47 28 22 45  ..APPFS_DEBUG("E
9280: 6e 74 65 72 20 28 70 61 74 68 20 3d 20 25 73 2c  nter (path = %s,
9290: 20 2e 2e 2e 29 22 2c 20 70 61 74 68 29 3b 0a 0a   ...)", path);..
92a0: 09 72 65 61 6c 5f 70 61 74 68 20 3d 20 61 70 70  .real_path = app
92b0: 66 73 5f 6c 6f 63 61 6c 70 61 74 68 28 70 61 74  fs_localpath(pat
92c0: 68 29 3b 0a 09 69 66 20 28 72 65 61 6c 5f 70 61  h);..if (real_pa
92d0: 74 68 20 3d 3d 20 4e 55 4c 4c 29 20 7b 0a 09 09  th == NULL) {...
92e0: 72 65 74 75 72 6e 28 2d 45 49 4f 29 3b 0a 09 7d  return(-EIO);..}
92f0: 0a 0a 09 61 70 70 66 73 5f 67 65 74 5f 70 61 74  ...appfs_get_pat
9300: 68 5f 69 6e 66 6f 5f 63 61 63 68 65 5f 72 6d 28  h_info_cache_rm(
9310: 70 61 74 68 2c 20 61 70 70 66 73 5f 67 65 74 5f  path, appfs_get_
9320: 66 73 75 69 64 28 29 29 3b 0a 0a 09 61 70 70 66  fsuid());...appf
9330: 73 5f 73 69 6d 75 6c 61 74 65 5f 75 73 65 72 5f  s_simulate_user_
9340: 66 73 5f 65 6e 74 65 72 28 29 3b 0a 0a 09 74 72  fs_enter();...tr
9350: 75 6e 63 61 74 65 5f 72 65 74 20 3d 20 74 72 75  uncate_ret = tru
9360: 6e 63 61 74 65 28 72 65 61 6c 5f 70 61 74 68 2c  ncate(real_path,
9370: 20 73 69 7a 65 29 3b 0a 0a 09 61 70 70 66 73 5f   size);...appfs_
9380: 73 69 6d 75 6c 61 74 65 5f 75 73 65 72 5f 66 73  simulate_user_fs
9390: 5f 6c 65 61 76 65 28 29 3b 0a 0a 09 66 72 65 65  _leave();...free
93a0: 28 72 65 61 6c 5f 70 61 74 68 29 3b 0a 0a 09 69  (real_path);...i
93b0: 66 20 28 74 72 75 6e 63 61 74 65 5f 72 65 74 20  f (truncate_ret 
93c0: 21 3d 20 30 29 20 7b 0a 09 09 72 65 74 75 72 6e  != 0) {...return
93d0: 28 65 72 72 6e 6f 20 2a 20 2d 31 29 3b 0a 09 7d  (errno * -1);..}
93e0: 0a 0a 09 72 65 74 75 72 6e 28 30 29 3b 0a 7d 0a  ...return(0);.}.
93f0: 0a 73 74 61 74 69 63 20 69 6e 74 20 61 70 70 66  .static int appf
9400: 73 5f 66 75 73 65 5f 75 6e 6c 69 6e 6b 5f 72 6d  s_fuse_unlink_rm
9410: 64 69 72 28 63 6f 6e 73 74 20 63 68 61 72 20 2a  dir(const char *
9420: 70 61 74 68 29 20 7b 0a 09 54 63 6c 5f 49 6e 74  path) {..Tcl_Int
9430: 65 72 70 20 2a 69 6e 74 65 72 70 3b 0a 09 69 6e  erp *interp;..in
9440: 74 20 74 63 6c 5f 72 65 74 3b 0a 0a 09 41 50 50  t tcl_ret;...APP
9450: 46 53 5f 44 45 42 55 47 28 22 45 6e 74 65 72 20  FS_DEBUG("Enter 
9460: 28 70 61 74 68 20 3d 20 25 73 2c 20 2e 2e 2e 29  (path = %s, ...)
9470: 22 2c 20 70 61 74 68 29 3b 0a 0a 09 61 70 70 66  ", path);...appf
9480: 73 5f 67 65 74 5f 70 61 74 68 5f 69 6e 66 6f 5f  s_get_path_info_
9490: 63 61 63 68 65 5f 66 6c 75 73 68 28 61 70 70 66  cache_flush(appf
94a0: 73 5f 67 65 74 5f 66 73 75 69 64 28 29 2c 20 2d  s_get_fsuid(), -
94b0: 31 29 3b 0a 0a 09 69 6e 74 65 72 70 20 3d 20 61  1);...interp = a
94c0: 70 70 66 73 5f 54 63 6c 49 6e 74 65 72 70 28 29  ppfs_TclInterp()
94d0: 3b 0a 09 69 66 20 28 69 6e 74 65 72 70 20 3d 3d  ;..if (interp ==
94e0: 20 4e 55 4c 4c 29 20 7b 0a 09 09 72 65 74 75 72   NULL) {...retur
94f0: 6e 28 2d 45 49 4f 29 3b 0a 09 7d 0a 0a 09 61 70  n(-EIO);..}...ap
9500: 70 66 73 5f 63 61 6c 6c 5f 6c 69 62 74 63 6c 28  pfs_call_libtcl(
9510: 54 63 6c 5f 50 72 65 73 65 72 76 65 28 69 6e 74  Tcl_Preserve(int
9520: 65 72 70 29 3b 29 0a 0a 09 74 63 6c 5f 72 65 74  erp);)...tcl_ret
9530: 20 3d 20 61 70 70 66 73 5f 54 63 6c 5f 45 76 61   = appfs_Tcl_Eva
9540: 6c 28 69 6e 74 65 72 70 2c 20 32 2c 20 22 3a 3a  l(interp, 2, "::
9550: 61 70 70 66 73 3a 3a 75 6e 6c 69 6e 6b 70 61 74  appfs::unlinkpat
9560: 68 22 2c 20 70 61 74 68 29 3b 0a 09 69 66 20 28  h", path);..if (
9570: 74 63 6c 5f 72 65 74 20 21 3d 20 54 43 4c 5f 4f  tcl_ret != TCL_O
9580: 4b 29 20 7b 0a 09 09 41 50 50 46 53 5f 44 45 42  K) {...APPFS_DEB
9590: 55 47 28 22 3a 3a 61 70 70 66 73 3a 3a 75 6e 6c  UG("::appfs::unl
95a0: 69 6e 6b 70 61 74 68 28 25 73 29 20 66 61 69 6c  inkpath(%s) fail
95b0: 65 64 2e 22 2c 20 70 61 74 68 29 3b 0a 09 09 61  ed.", path);...a
95c0: 70 70 66 73 5f 63 61 6c 6c 5f 6c 69 62 74 63 6c  ppfs_call_libtcl
95d0: 28 0a 09 09 09 41 50 50 46 53 5f 44 45 42 55 47  (....APPFS_DEBUG
95e0: 28 22 54 63 6c 20 45 72 72 6f 72 20 69 73 3a 20  ("Tcl Error is: 
95f0: 25 73 22 2c 20 54 63 6c 5f 47 65 74 53 74 72 69  %s", Tcl_GetStri
9600: 6e 67 52 65 73 75 6c 74 28 69 6e 74 65 72 70 29  ngResult(interp)
9610: 29 3b 0a 09 09 29 0a 0a 09 09 61 70 70 66 73 5f  );...)....appfs_
9620: 63 61 6c 6c 5f 6c 69 62 74 63 6c 28 54 63 6c 5f  call_libtcl(Tcl_
9630: 52 65 6c 65 61 73 65 28 69 6e 74 65 72 70 29 3b  Release(interp);
9640: 29 0a 0a 09 09 72 65 74 75 72 6e 28 2d 45 49 4f  )....return(-EIO
9650: 29 3b 0a 09 7d 0a 0a 09 61 70 70 66 73 5f 63 61  );..}...appfs_ca
9660: 6c 6c 5f 6c 69 62 74 63 6c 28 54 63 6c 5f 52 65  ll_libtcl(Tcl_Re
9670: 6c 65 61 73 65 28 69 6e 74 65 72 70 29 3b 29 0a  lease(interp);).
9680: 0a 09 72 65 74 75 72 6e 28 30 29 3b 0a 7d 0a 0a  ..return(0);.}..
9690: 73 74 61 74 69 63 20 69 6e 74 20 61 70 70 66 73  static int appfs
96a0: 5f 66 75 73 65 5f 6d 6b 64 69 72 28 63 6f 6e 73  _fuse_mkdir(cons
96b0: 74 20 63 68 61 72 20 2a 70 61 74 68 2c 20 6d 6f  t char *path, mo
96c0: 64 65 5f 74 20 6d 6f 64 65 29 20 7b 0a 09 63 68  de_t mode) {..ch
96d0: 61 72 20 2a 72 65 61 6c 5f 70 61 74 68 3b 0a 09  ar *real_path;..
96e0: 69 6e 74 20 6d 6b 64 69 72 5f 72 65 74 3b 0a 0a  int mkdir_ret;..
96f0: 09 41 50 50 46 53 5f 44 45 42 55 47 28 22 45 6e  .APPFS_DEBUG("En
9700: 74 65 72 20 28 70 61 74 68 20 3d 20 25 73 2c 20  ter (path = %s, 
9710: 2e 2e 2e 29 22 2c 20 70 61 74 68 29 3b 0a 0a 09  ...)", path);...
9720: 72 65 61 6c 5f 70 61 74 68 20 3d 20 61 70 70 66  real_path = appf
9730: 73 5f 70 72 65 70 61 72 65 5f 74 6f 5f 63 72 65  s_prepare_to_cre
9740: 61 74 65 28 70 61 74 68 29 3b 0a 09 69 66 20 28  ate(path);..if (
9750: 72 65 61 6c 5f 70 61 74 68 20 3d 3d 20 4e 55 4c  real_path == NUL
9760: 4c 29 20 7b 0a 09 09 72 65 74 75 72 6e 28 2d 45  L) {...return(-E
9770: 49 4f 29 3b 0a 09 7d 0a 0a 09 61 70 70 66 73 5f  IO);..}...appfs_
9780: 73 69 6d 75 6c 61 74 65 5f 75 73 65 72 5f 66 73  simulate_user_fs
9790: 5f 65 6e 74 65 72 28 29 3b 0a 0a 09 6d 6b 64 69  _enter();...mkdi
97a0: 72 5f 72 65 74 20 3d 20 6d 6b 64 69 72 28 72 65  r_ret = mkdir(re
97b0: 61 6c 5f 70 61 74 68 2c 20 6d 6f 64 65 29 3b 0a  al_path, mode);.
97c0: 0a 09 61 70 70 66 73 5f 73 69 6d 75 6c 61 74 65  ..appfs_simulate
97d0: 5f 75 73 65 72 5f 66 73 5f 6c 65 61 76 65 28 29  _user_fs_leave()
97e0: 3b 0a 0a 09 66 72 65 65 28 72 65 61 6c 5f 70 61  ;...free(real_pa
97f0: 74 68 29 3b 0a 0a 09 69 66 20 28 6d 6b 64 69 72  th);...if (mkdir
9800: 5f 72 65 74 20 21 3d 20 30 29 20 7b 0a 09 09 69  _ret != 0) {...i
9810: 66 20 28 65 72 72 6e 6f 20 21 3d 20 45 45 58 49  f (errno != EEXI
9820: 53 54 29 20 7b 0a 09 09 09 72 65 74 75 72 6e 28  ST) {....return(
9830: 65 72 72 6e 6f 20 2a 20 2d 31 29 3b 0a 09 09 7d  errno * -1);...}
9840: 0a 09 7d 0a 0a 09 72 65 74 75 72 6e 28 30 29 3b  ..}...return(0);
9850: 0a 7d 0a 0a 73 74 61 74 69 63 20 69 6e 74 20 61  .}..static int a
9860: 70 70 66 73 5f 66 75 73 65 5f 63 68 6d 6f 64 28  ppfs_fuse_chmod(
9870: 63 6f 6e 73 74 20 63 68 61 72 20 2a 70 61 74 68  const char *path
9880: 2c 20 6d 6f 64 65 5f 74 20 6d 6f 64 65 29 20 7b  , mode_t mode) {
9890: 0a 09 54 63 6c 5f 49 6e 74 65 72 70 20 2a 69 6e  ..Tcl_Interp *in
98a0: 74 65 72 70 3b 0a 09 63 6f 6e 73 74 20 63 68 61  terp;..const cha
98b0: 72 20 2a 72 65 61 6c 5f 70 61 74 68 3b 0a 09 69  r *real_path;..i
98c0: 6e 74 20 74 63 6c 5f 72 65 74 2c 20 63 68 6d 6f  nt tcl_ret, chmo
98d0: 64 5f 72 65 74 3b 0a 0a 09 41 50 50 46 53 5f 44  d_ret;...APPFS_D
98e0: 45 42 55 47 28 22 45 6e 74 65 72 20 28 70 61 74  EBUG("Enter (pat
98f0: 68 20 3d 20 25 73 2c 20 2e 2e 2e 29 22 2c 20 70  h = %s, ...)", p
9900: 61 74 68 29 3b 0a 0a 09 61 70 70 66 73 5f 67 65  ath);...appfs_ge
9910: 74 5f 70 61 74 68 5f 69 6e 66 6f 5f 63 61 63 68  t_path_info_cach
9920: 65 5f 72 6d 28 70 61 74 68 2c 20 61 70 70 66 73  e_rm(path, appfs
9930: 5f 67 65 74 5f 66 73 75 69 64 28 29 29 3b 0a 0a  _get_fsuid());..
9940: 09 69 6e 74 65 72 70 20 3d 20 61 70 70 66 73 5f  .interp = appfs_
9950: 54 63 6c 49 6e 74 65 72 70 28 29 3b 0a 09 69 66  TclInterp();..if
9960: 20 28 69 6e 74 65 72 70 20 3d 3d 20 4e 55 4c 4c   (interp == NULL
9970: 29 20 7b 0a 09 09 72 65 74 75 72 6e 28 2d 45 49  ) {...return(-EI
9980: 4f 29 3b 0a 09 7d 0a 0a 09 61 70 70 66 73 5f 63  O);..}...appfs_c
9990: 61 6c 6c 5f 6c 69 62 74 63 6c 28 54 63 6c 5f 50  all_libtcl(Tcl_P
99a0: 72 65 73 65 72 76 65 28 69 6e 74 65 72 70 29 3b  reserve(interp);
99b0: 29 0a 0a 09 74 63 6c 5f 72 65 74 20 3d 20 61 70  )...tcl_ret = ap
99c0: 70 66 73 5f 54 63 6c 5f 45 76 61 6c 28 69 6e 74  pfs_Tcl_Eval(int
99d0: 65 72 70 2c 20 33 2c 20 22 3a 3a 61 70 70 66 73  erp, 3, "::appfs
99e0: 3a 3a 6f 70 65 6e 70 61 74 68 22 2c 20 70 61 74  ::openpath", pat
99f0: 68 2c 20 22 77 72 69 74 65 22 29 3b 0a 09 69 66  h, "write");..if
9a00: 20 28 74 63 6c 5f 72 65 74 20 21 3d 20 54 43 4c   (tcl_ret != TCL
9a10: 5f 4f 4b 29 20 7b 0a 09 09 41 50 50 46 53 5f 44  _OK) {...APPFS_D
9a20: 45 42 55 47 28 22 3a 3a 61 70 70 66 73 3a 3a 6f  EBUG("::appfs::o
9a30: 70 65 6e 70 61 74 68 28 25 73 2c 20 25 73 29 20  penpath(%s, %s) 
9a40: 66 61 69 6c 65 64 2e 22 2c 20 70 61 74 68 2c 20  failed.", path, 
9a50: 22 77 72 69 74 65 22 29 3b 0a 09 09 61 70 70 66  "write");...appf
9a60: 73 5f 63 61 6c 6c 5f 6c 69 62 74 63 6c 28 0a 09  s_call_libtcl(..
9a70: 09 09 41 50 50 46 53 5f 44 45 42 55 47 28 22 54  ..APPFS_DEBUG("T
9a80: 63 6c 20 45 72 72 6f 72 20 69 73 3a 20 25 73 22  cl Error is: %s"
9a90: 2c 20 54 63 6c 5f 47 65 74 53 74 72 69 6e 67 52  , Tcl_GetStringR
9aa0: 65 73 75 6c 74 28 69 6e 74 65 72 70 29 29 3b 0a  esult(interp));.
9ab0: 09 09 29 0a 0a 09 09 61 70 70 66 73 5f 63 61 6c  ..)....appfs_cal
9ac0: 6c 5f 6c 69 62 74 63 6c 28 54 63 6c 5f 52 65 6c  l_libtcl(Tcl_Rel
9ad0: 65 61 73 65 28 69 6e 74 65 72 70 29 3b 29 0a 0a  ease(interp);)..
9ae0: 09 09 72 65 74 75 72 6e 28 2d 45 49 4f 29 3b 0a  ..return(-EIO);.
9af0: 09 7d 0a 0a 09 61 70 70 66 73 5f 63 61 6c 6c 5f  .}...appfs_call_
9b00: 6c 69 62 74 63 6c 28 0a 09 09 72 65 61 6c 5f 70  libtcl(...real_p
9b10: 61 74 68 20 3d 20 54 63 6c 5f 47 65 74 53 74 72  ath = Tcl_GetStr
9b20: 69 6e 67 52 65 73 75 6c 74 28 69 6e 74 65 72 70  ingResult(interp
9b30: 29 3b 0a 09 29 0a 0a 09 61 70 70 66 73 5f 63 61  );..)...appfs_ca
9b40: 6c 6c 5f 6c 69 62 74 63 6c 28 54 63 6c 5f 52 65  ll_libtcl(Tcl_Re
9b50: 6c 65 61 73 65 28 69 6e 74 65 72 70 29 3b 29 0a  lease(interp);).
9b60: 0a 09 69 66 20 28 72 65 61 6c 5f 70 61 74 68 20  ..if (real_path 
9b70: 3d 3d 20 4e 55 4c 4c 29 20 7b 0a 09 09 72 65 74  == NULL) {...ret
9b80: 75 72 6e 28 2d 45 49 4f 29 3b 0a 09 7d 0a 0a 09  urn(-EIO);..}...
9b90: 61 70 70 66 73 5f 73 69 6d 75 6c 61 74 65 5f 75  appfs_simulate_u
9ba0: 73 65 72 5f 66 73 5f 65 6e 74 65 72 28 29 3b 0a  ser_fs_enter();.
9bb0: 0a 09 63 68 6d 6f 64 5f 72 65 74 20 3d 20 63 68  ..chmod_ret = ch
9bc0: 6d 6f 64 28 72 65 61 6c 5f 70 61 74 68 2c 20 6d  mod(real_path, m
9bd0: 6f 64 65 29 3b 0a 0a 09 61 70 70 66 73 5f 73 69  ode);...appfs_si
9be0: 6d 75 6c 61 74 65 5f 75 73 65 72 5f 66 73 5f 6c  mulate_user_fs_l
9bf0: 65 61 76 65 28 29 3b 0a 0a 09 72 65 74 75 72 6e  eave();...return
9c00: 28 63 68 6d 6f 64 5f 72 65 74 29 3b 0a 7d 0a 0a  (chmod_ret);.}..
9c10: 73 74 61 74 69 63 20 69 6e 74 20 61 70 70 66 73  static int appfs
9c20: 5f 66 75 73 65 5f 73 79 6d 6c 69 6e 6b 28 63 6f  _fuse_symlink(co
9c30: 6e 73 74 20 63 68 61 72 20 2a 6f 6c 64 70 61 74  nst char *oldpat
9c40: 68 2c 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 6e  h, const char *n
9c50: 65 77 70 61 74 68 29 20 7b 0a 09 63 68 61 72 20  ewpath) {..char 
9c60: 2a 72 65 61 6c 5f 70 61 74 68 3b 0a 09 69 6e 74  *real_path;..int
9c70: 20 73 79 6d 6c 69 6e 6b 5f 72 65 74 3b 0a 0a 09   symlink_ret;...
9c80: 41 50 50 46 53 5f 44 45 42 55 47 28 22 45 6e 74  APPFS_DEBUG("Ent
9c90: 65 72 20 28 70 61 74 68 20 3d 20 25 73 2c 20 25  er (path = %s, %
9ca0: 73 29 22 2c 20 6f 6c 64 70 61 74 68 2c 20 6e 65  s)", oldpath, ne
9cb0: 77 70 61 74 68 29 3b 0a 0a 09 72 65 61 6c 5f 70  wpath);...real_p
9cc0: 61 74 68 20 3d 20 61 70 70 66 73 5f 70 72 65 70  ath = appfs_prep
9cd0: 61 72 65 5f 74 6f 5f 63 72 65 61 74 65 28 6e 65  are_to_create(ne
9ce0: 77 70 61 74 68 29 3b 0a 09 69 66 20 28 72 65 61  wpath);..if (rea
9cf0: 6c 5f 70 61 74 68 20 3d 3d 20 4e 55 4c 4c 29 20  l_path == NULL) 
9d00: 7b 0a 09 09 72 65 74 75 72 6e 28 2d 45 49 4f 29  {...return(-EIO)
9d10: 3b 0a 09 7d 0a 0a 09 61 70 70 66 73 5f 73 69 6d  ;..}...appfs_sim
9d20: 75 6c 61 74 65 5f 75 73 65 72 5f 66 73 5f 65 6e  ulate_user_fs_en
9d30: 74 65 72 28 29 3b 0a 0a 09 73 79 6d 6c 69 6e 6b  ter();...symlink
9d40: 5f 72 65 74 20 3d 20 73 79 6d 6c 69 6e 6b 28 6f  _ret = symlink(o
9d50: 6c 64 70 61 74 68 2c 20 72 65 61 6c 5f 70 61 74  ldpath, real_pat
9d60: 68 29 3b 0a 0a 09 61 70 70 66 73 5f 73 69 6d 75  h);...appfs_simu
9d70: 6c 61 74 65 5f 75 73 65 72 5f 66 73 5f 6c 65 61  late_user_fs_lea
9d80: 76 65 28 29 3b 0a 0a 09 66 72 65 65 28 72 65 61  ve();...free(rea
9d90: 6c 5f 70 61 74 68 29 3b 0a 0a 09 69 66 20 28 73  l_path);...if (s
9da0: 79 6d 6c 69 6e 6b 5f 72 65 74 20 21 3d 20 30 29  ymlink_ret != 0)
9db0: 20 7b 0a 09 09 72 65 74 75 72 6e 28 65 72 72 6e   {...return(errn
9dc0: 6f 20 2a 20 2d 31 29 3b 0a 09 7d 0a 0a 09 72 65  o * -1);..}...re
9dd0: 74 75 72 6e 28 30 29 3b 0a 7d 0a 0a 2f 2a 0a 20  turn(0);.}../*. 
9de0: 2a 20 53 51 4c 69 74 65 33 20 6d 6f 64 65 3a 20  * SQLite3 mode: 
9df0: 45 78 65 63 75 74 65 20 72 61 77 20 53 51 4c 20  Execute raw SQL 
9e00: 61 6e 64 20 72 65 74 75 72 6e 20 73 75 63 63 65  and return succe
9e10: 73 73 20 6f 72 20 66 61 69 6c 75 72 65 0a 20 2a  ss or failure. *
9e20: 2f 0a 73 74 61 74 69 63 20 69 6e 74 20 61 70 70  /.static int app
9e30: 66 73 5f 73 71 6c 69 74 65 33 28 63 6f 6e 73 74  fs_sqlite3(const
9e40: 20 63 68 61 72 20 2a 73 71 6c 29 20 7b 0a 09 54   char *sql) {..T
9e50: 63 6c 5f 49 6e 74 65 72 70 20 2a 69 6e 74 65 72  cl_Interp *inter
9e60: 70 3b 0a 09 63 6f 6e 73 74 20 63 68 61 72 20 2a  p;..const char *
9e70: 73 71 6c 5f 72 65 74 3b 0a 09 69 6e 74 20 74 63  sql_ret;..int tc
9e80: 6c 5f 72 65 74 3b 0a 0a 09 69 6e 74 65 72 70 20  l_ret;...interp 
9e90: 3d 20 61 70 70 66 73 5f 63 72 65 61 74 65 5f 54  = appfs_create_T
9ea0: 63 6c 49 6e 74 65 72 70 28 4e 55 4c 4c 29 3b 0a  clInterp(NULL);.
9eb0: 09 69 66 20 28 69 6e 74 65 72 70 20 3d 3d 20 4e  .if (interp == N
9ec0: 55 4c 4c 29 20 7b 0a 09 09 66 70 72 69 6e 74 66  ULL) {...fprintf
9ed0: 28 73 74 64 65 72 72 2c 20 22 55 6e 61 62 6c 65  (stderr, "Unable
9ee0: 20 74 6f 20 63 72 65 61 74 65 20 61 20 54 63 6c   to create a Tcl
9ef0: 20 69 6e 74 65 72 70 72 65 74 65 72 2e 20 20 41   interpreter.  A
9f00: 62 6f 72 74 69 6e 67 2e 5c 6e 22 29 3b 0a 0a 09  borting.\n");...
9f10: 09 72 65 74 75 72 6e 28 31 29 3b 0a 09 7d 0a 0a  .return(1);..}..
9f20: 09 74 63 6c 5f 72 65 74 20 3d 20 61 70 70 66 73  .tcl_ret = appfs
9f30: 5f 54 63 6c 5f 45 76 61 6c 28 69 6e 74 65 72 70  _Tcl_Eval(interp
9f40: 2c 20 35 2c 20 22 3a 3a 61 70 70 66 73 3a 3a 64  , 5, "::appfs::d
9f50: 62 22 2c 20 22 65 76 61 6c 22 2c 20 73 71 6c 2c  b", "eval", sql,
9f60: 20 22 72 6f 77 22 2c 20 22 75 6e 73 65 74 20 2d   "row", "unset -
9f70: 6e 6f 63 6f 6d 70 6c 61 69 6e 20 72 6f 77 28 2a  nocomplain row(*
9f80: 29 3b 20 70 61 72 72 61 79 20 72 6f 77 3b 20 70  ); parray row; p
9f90: 75 74 73 20 5c 22 2d 2d 2d 2d 5c 22 22 29 3b 0a  uts \"----\"");.
9fa0: 09 73 71 6c 5f 72 65 74 20 3d 20 54 63 6c 5f 47  .sql_ret = Tcl_G
9fb0: 65 74 53 74 72 69 6e 67 52 65 73 75 6c 74 28 69  etStringResult(i
9fc0: 6e 74 65 72 70 29 3b 0a 0a 09 69 66 20 28 74 63  nterp);...if (tc
9fd0: 6c 5f 72 65 74 20 21 3d 20 54 43 4c 5f 4f 4b 29  l_ret != TCL_OK)
9fe0: 20 7b 0a 09 09 66 70 72 69 6e 74 66 28 73 74 64   {...fprintf(std
9ff0: 65 72 72 2c 20 22 5b 65 72 72 6f 72 5d 20 25 73  err, "[error] %s
a000: 5c 6e 22 2c 20 73 71 6c 5f 72 65 74 29 3b 0a 0a  \n", sql_ret);..
a010: 09 09 72 65 74 75 72 6e 28 31 29 3b 0a 09 7d 0a  ..return(1);..}.
a020: 0a 09 69 66 20 28 73 71 6c 5f 72 65 74 20 26 26  ..if (sql_ret &&
a030: 20 73 71 6c 5f 72 65 74 5b 30 5d 20 21 3d 20 27   sql_ret[0] != '
a040: 5c 30 27 29 20 7b 0a 09 09 70 72 69 6e 74 66 28  \0') {...printf(
a050: 22 25 73 5c 6e 22 2c 20 73 71 6c 5f 72 65 74 29  "%s\n", sql_ret)
a060: 3b 0a 09 7d 0a 0a 09 72 65 74 75 72 6e 28 30 29  ;..}...return(0)
a070: 3b 0a 7d 0a 0a 2f 2a 0a 20 2a 20 54 63 6c 20 6d  ;.}../*. * Tcl m
a080: 6f 64 65 3a 20 45 78 65 63 75 74 65 20 72 61 77  ode: Execute raw
a090: 20 54 63 6c 20 61 6e 64 20 72 65 74 75 72 6e 20   Tcl and return 
a0a0: 73 75 63 63 65 73 73 20 6f 72 20 66 61 69 6c 75  success or failu
a0b0: 72 65 0a 20 2a 2f 0a 73 74 61 74 69 63 20 69 6e  re. */.static in
a0c0: 74 20 61 70 70 66 73 5f 74 63 6c 28 63 6f 6e 73  t appfs_tcl(cons
a0d0: 74 20 63 68 61 72 20 2a 74 63 6c 29 20 7b 0a 09  t char *tcl) {..
a0e0: 54 63 6c 5f 49 6e 74 65 72 70 20 2a 69 6e 74 65  Tcl_Interp *inte
a0f0: 72 70 3b 0a 09 63 6f 6e 73 74 20 63 68 61 72 20  rp;..const char 
a100: 2a 74 63 6c 5f 72 65 73 75 6c 74 3b 0a 09 69 6e  *tcl_result;..in
a110: 74 20 74 63 6c 5f 72 65 74 3b 0a 0a 09 69 6e 74  t tcl_ret;...int
a120: 65 72 70 20 3d 20 61 70 70 66 73 5f 63 72 65 61  erp = appfs_crea
a130: 74 65 5f 54 63 6c 49 6e 74 65 72 70 28 4e 55 4c  te_TclInterp(NUL
a140: 4c 29 3b 0a 09 69 66 20 28 69 6e 74 65 72 70 20  L);..if (interp 
a150: 3d 3d 20 4e 55 4c 4c 29 20 7b 0a 09 09 66 70 72  == NULL) {...fpr
a160: 69 6e 74 66 28 73 74 64 65 72 72 2c 20 22 55 6e  intf(stderr, "Un
a170: 61 62 6c 65 20 74 6f 20 63 72 65 61 74 65 20 61  able to create a
a180: 20 54 63 6c 20 69 6e 74 65 72 70 72 65 74 65 72   Tcl interpreter
a190: 2e 20 20 41 62 6f 72 74 69 6e 67 2e 5c 6e 22 29  .  Aborting.\n")
a1a0: 3b 0a 0a 09 09 72 65 74 75 72 6e 28 31 29 3b 0a  ;....return(1);.
a1b0: 09 7d 0a 0a 09 74 63 6c 5f 72 65 74 20 3d 20 54  .}...tcl_ret = T
a1c0: 63 6c 5f 45 76 61 6c 28 69 6e 74 65 72 70 2c 20  cl_Eval(interp, 
a1d0: 74 63 6c 29 3b 0a 09 74 63 6c 5f 72 65 73 75 6c  tcl);..tcl_resul
a1e0: 74 20 3d 20 54 63 6c 5f 47 65 74 53 74 72 69 6e  t = Tcl_GetStrin
a1f0: 67 52 65 73 75 6c 74 28 69 6e 74 65 72 70 29 3b  gResult(interp);
a200: 0a 0a 09 69 66 20 28 74 63 6c 5f 72 65 74 20 21  ...if (tcl_ret !
a210: 3d 20 54 43 4c 5f 4f 4b 29 20 7b 0a 09 09 66 70  = TCL_OK) {...fp
a220: 72 69 6e 74 66 28 73 74 64 65 72 72 2c 20 22 5b  rintf(stderr, "[
a230: 65 72 72 6f 72 5d 20 25 73 5c 6e 22 2c 20 54 63  error] %s\n", Tc
a240: 6c 5f 47 65 74 56 61 72 28 69 6e 74 65 72 70 2c  l_GetVar(interp,
a250: 20 22 65 72 72 6f 72 49 6e 66 6f 22 2c 20 54 43   "errorInfo", TC
a260: 4c 5f 47 4c 4f 42 41 4c 5f 4f 4e 4c 59 29 29 3b  L_GLOBAL_ONLY));
a270: 0a 0a 09 09 72 65 74 75 72 6e 28 31 29 3b 0a 09  ....return(1);..
a280: 7d 0a 0a 09 69 66 20 28 74 63 6c 5f 72 65 73 75  }...if (tcl_resu
a290: 6c 74 20 26 26 20 74 63 6c 5f 72 65 73 75 6c 74  lt && tcl_result
a2a0: 5b 30 5d 20 21 3d 20 27 5c 30 27 29 20 7b 0a 09  [0] != '\0') {..
a2b0: 09 70 72 69 6e 74 66 28 22 25 73 5c 6e 22 2c 20  .printf("%s\n", 
a2c0: 74 63 6c 5f 72 65 73 75 6c 74 29 3b 0a 09 7d 0a  tcl_result);..}.
a2d0: 0a 09 72 65 74 75 72 6e 28 30 29 3b 0a 7d 0a 0a  ..return(0);.}..
a2e0: 2f 2a 0a 20 2a 20 41 70 70 46 53 64 20 50 61 63  /*. * AppFSd Pac
a2f0: 6b 61 67 65 20 66 6f 72 20 54 63 6c 3a 0a 20 2a  kage for Tcl:. *
a300: 20 20 20 20 20 20 20 20 20 42 72 69 64 67 65 20           Bridge 
a310: 66 6f 72 20 49 2f 4f 20 6f 70 65 72 61 74 69 6f  for I/O operatio
a320: 6e 73 20 74 6f 20 72 65 71 75 65 73 74 20 69 6e  ns to request in
a330: 66 6f 72 6d 61 74 69 6f 6e 20 61 62 6f 75 74 20  formation about 
a340: 74 68 65 20 63 75 72 72 65 6e 74 0a 20 2a 20 20  the current. *  
a350: 20 20 20 20 20 20 20 74 72 61 6e 73 61 63 74 69         transacti
a360: 6f 6e 0a 20 2a 2f 0a 2f 2a 0a 20 2a 20 54 63 6c  on. */./*. * Tcl
a370: 20 69 6e 74 65 72 66 61 63 65 20 74 6f 20 67 65   interface to ge
a380: 74 20 74 68 65 20 68 6f 6d 65 20 64 69 72 65 63  t the home direc
a390: 74 6f 72 79 20 66 6f 72 20 74 68 65 20 75 73 65  tory for the use
a3a0: 72 20 6d 61 6b 69 6e 67 20 74 68 65 20 22 63 75  r making the "cu
a3b0: 72 72 65 6e 74 22 0a 20 2a 20 46 55 53 45 20 49  rrent". * FUSE I
a3c0: 2f 4f 20 72 65 71 75 65 73 74 0a 20 2a 2f 0a 73  /O request. */.s
a3d0: 74 61 74 69 63 20 69 6e 74 20 74 63 6c 5f 61 70  tatic int tcl_ap
a3e0: 70 66 73 5f 67 65 74 5f 68 6f 6d 65 64 69 72 28  pfs_get_homedir(
a3f0: 43 6c 69 65 6e 74 44 61 74 61 20 63 64 2c 20 54  ClientData cd, T
a400: 63 6c 5f 49 6e 74 65 72 70 20 2a 69 6e 74 65 72  cl_Interp *inter
a410: 70 2c 20 69 6e 74 20 6f 62 6a 63 2c 20 54 63 6c  p, int objc, Tcl
a420: 5f 4f 62 6a 20 2a 43 4f 4e 53 54 20 6f 62 6a 76  _Obj *CONST objv
a430: 5b 5d 29 20 7b 0a 09 63 68 61 72 20 2a 68 6f 6d  []) {..char *hom
a440: 65 64 69 72 3b 0a 09 54 63 6c 5f 4f 62 6a 20 2a  edir;..Tcl_Obj *
a450: 68 6f 6d 65 64 69 72 5f 6f 62 6a 3b 0a 09 75 69  homedir_obj;..ui
a460: 64 5f 74 20 66 73 75 69 64 3b 0a 09 73 74 61 74  d_t fsuid;..stat
a470: 69 63 20 5f 5f 74 68 72 65 61 64 20 54 63 6c 5f  ic __thread Tcl_
a480: 4f 62 6a 20 2a 6c 61 73 74 5f 68 6f 6d 65 64 69  Obj *last_homedi
a490: 72 5f 6f 62 6a 20 3d 20 4e 55 4c 4c 3b 0a 09 73  r_obj = NULL;..s
a4a0: 74 61 74 69 63 20 5f 5f 74 68 72 65 61 64 20 75  tatic __thread u
a4b0: 69 64 5f 74 20 6c 61 73 74 5f 66 73 75 69 64 20  id_t last_fsuid 
a4c0: 3d 20 2d 31 3b 0a 0a 20 20 20 20 20 20 20 20 69  = -1;..        i
a4d0: 66 20 28 6f 62 6a 63 20 21 3d 20 31 29 20 7b 0a  f (objc != 1) {.
a4e0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
a4f0: 54 63 6c 5f 57 72 6f 6e 67 4e 75 6d 41 72 67 73  Tcl_WrongNumArgs
a500: 28 69 6e 74 65 72 70 2c 20 31 2c 20 6f 62 6a 76  (interp, 1, objv
a510: 2c 20 4e 55 4c 4c 29 3b 0a 20 20 20 20 20 20 20  , NULL);.       
a520: 20 20 20 20 20 20 20 20 20 72 65 74 75 72 6e 28           return(
a530: 54 43 4c 5f 45 52 52 4f 52 29 3b 0a 20 20 20 20  TCL_ERROR);.    
a540: 20 20 20 20 7d 0a 0a 09 66 73 75 69 64 20 3d 20      }...fsuid = 
a550: 61 70 70 66 73 5f 67 65 74 5f 66 73 75 69 64 28  appfs_get_fsuid(
a560: 29 3b 0a 0a 09 69 66 20 28 66 73 75 69 64 20 3d  );...if (fsuid =
a570: 3d 20 6c 61 73 74 5f 66 73 75 69 64 20 26 26 20  = last_fsuid && 
a580: 6c 61 73 74 5f 68 6f 6d 65 64 69 72 5f 6f 62 6a  last_homedir_obj
a590: 20 21 3d 20 4e 55 4c 4c 29 20 7b 0a 09 09 68 6f   != NULL) {...ho
a5a0: 6d 65 64 69 72 5f 6f 62 6a 20 3d 20 6c 61 73 74  medir_obj = last
a5b0: 5f 68 6f 6d 65 64 69 72 5f 6f 62 6a 3b 0a 0a 09  _homedir_obj;...
a5c0: 09 54 63 6c 5f 49 6e 63 72 52 65 66 43 6f 75 6e  .Tcl_IncrRefCoun
a5d0: 74 28 68 6f 6d 65 64 69 72 5f 6f 62 6a 29 3b 0a  t(homedir_obj);.
a5e0: 09 7d 20 65 6c 73 65 20 7b 0a 09 09 68 6f 6d 65  .} else {...home
a5f0: 64 69 72 20 3d 20 61 70 70 66 73 5f 67 65 74 5f  dir = appfs_get_
a600: 68 6f 6d 65 64 69 72 28 61 70 70 66 73 5f 67 65  homedir(appfs_ge
a610: 74 5f 66 73 75 69 64 28 29 29 3b 0a 0a 09 09 69  t_fsuid());....i
a620: 66 20 28 68 6f 6d 65 64 69 72 20 3d 3d 20 4e 55  f (homedir == NU
a630: 4c 4c 29 20 7b 0a 09 09 09 72 65 74 75 72 6e 28  LL) {....return(
a640: 54 43 4c 5f 45 52 52 4f 52 29 3b 0a 09 09 7d 0a  TCL_ERROR);...}.
a650: 0a 09 09 68 6f 6d 65 64 69 72 5f 6f 62 6a 20 3d  ...homedir_obj =
a660: 20 54 63 6c 5f 4e 65 77 53 74 72 69 6e 67 4f 62   Tcl_NewStringOb
a670: 6a 28 68 6f 6d 65 64 69 72 2c 20 2d 31 29 3b 0a  j(homedir, -1);.
a680: 0a 09 09 66 72 65 65 28 68 6f 6d 65 64 69 72 29  ...free(homedir)
a690: 3b 0a 0a 09 09 54 63 6c 5f 49 6e 63 72 52 65 66  ;....Tcl_IncrRef
a6a0: 43 6f 75 6e 74 28 68 6f 6d 65 64 69 72 5f 6f 62  Count(homedir_ob
a6b0: 6a 29 3b 0a 0a 09 09 69 66 20 28 6c 61 73 74 5f  j);....if (last_
a6c0: 68 6f 6d 65 64 69 72 5f 6f 62 6a 20 21 3d 20 4e  homedir_obj != N
a6d0: 55 4c 4c 29 20 7b 0a 09 09 09 54 63 6c 5f 44 65  ULL) {....Tcl_De
a6e0: 63 72 52 65 66 43 6f 75 6e 74 28 6c 61 73 74 5f  crRefCount(last_
a6f0: 68 6f 6d 65 64 69 72 5f 6f 62 6a 29 3b 0a 09 09  homedir_obj);...
a700: 7d 0a 0a 09 09 6c 61 73 74 5f 68 6f 6d 65 64 69  }....last_homedi
a710: 72 5f 6f 62 6a 20 3d 20 68 6f 6d 65 64 69 72 5f  r_obj = homedir_
a720: 6f 62 6a 3b 0a 09 09 6c 61 73 74 5f 66 73 75 69  obj;...last_fsui
a730: 64 20 3d 20 66 73 75 69 64 3b 0a 0a 09 09 54 63  d = fsuid;....Tc
a740: 6c 5f 49 6e 63 72 52 65 66 43 6f 75 6e 74 28 68  l_IncrRefCount(h
a750: 6f 6d 65 64 69 72 5f 6f 62 6a 29 3b 0a 09 7d 0a  omedir_obj);..}.
a760: 0a 20 20 20 20 20 20 20 09 54 63 6c 5f 53 65 74  .       .Tcl_Set
a770: 4f 62 6a 52 65 73 75 6c 74 28 69 6e 74 65 72 70  ObjResult(interp
a780: 2c 20 68 6f 6d 65 64 69 72 5f 6f 62 6a 29 3b 0a  , homedir_obj);.
a790: 0a 09 54 63 6c 5f 44 65 63 72 52 65 66 43 6f 75  ..Tcl_DecrRefCou
a7a0: 6e 74 28 68 6f 6d 65 64 69 72 5f 6f 62 6a 29 3b  nt(homedir_obj);
a7b0: 0a 0a 20 20 20 20 20 20 20 20 72 65 74 75 72 6e  ..        return
a7c0: 28 54 43 4c 5f 4f 4b 29 3b 0a 7d 0a 0a 73 74 61  (TCL_OK);.}..sta
a7d0: 74 69 63 20 69 6e 74 20 74 63 6c 5f 61 70 70 66  tic int tcl_appf
a7e0: 73 5f 73 69 6d 75 6c 61 74 65 5f 75 73 65 72 5f  s_simulate_user_
a7f0: 66 73 5f 65 6e 74 65 72 28 43 6c 69 65 6e 74 44  fs_enter(ClientD
a800: 61 74 61 20 63 64 2c 20 54 63 6c 5f 49 6e 74 65  ata cd, Tcl_Inte
a810: 72 70 20 2a 69 6e 74 65 72 70 2c 20 69 6e 74 20  rp *interp, int 
a820: 6f 62 6a 63 2c 20 54 63 6c 5f 4f 62 6a 20 2a 43  objc, Tcl_Obj *C
a830: 4f 4e 53 54 20 6f 62 6a 76 5b 5d 29 20 7b 0a 09  ONST objv[]) {..
a840: 61 70 70 66 73 5f 73 69 6d 75 6c 61 74 65 5f 75  appfs_simulate_u
a850: 73 65 72 5f 66 73 5f 65 6e 74 65 72 28 29 3b 0a  ser_fs_enter();.
a860: 0a 09 72 65 74 75 72 6e 28 54 43 4c 5f 4f 4b 29  ..return(TCL_OK)
a870: 3b 0a 7d 0a 0a 73 74 61 74 69 63 20 69 6e 74 20  ;.}..static int 
a880: 74 63 6c 5f 61 70 70 66 73 5f 73 69 6d 75 6c 61  tcl_appfs_simula
a890: 74 65 5f 75 73 65 72 5f 66 73 5f 6c 65 61 76 65  te_user_fs_leave
a8a0: 28 43 6c 69 65 6e 74 44 61 74 61 20 63 64 2c 20  (ClientData cd, 
a8b0: 54 63 6c 5f 49 6e 74 65 72 70 20 2a 69 6e 74 65  Tcl_Interp *inte
a8c0: 72 70 2c 20 69 6e 74 20 6f 62 6a 63 2c 20 54 63  rp, int objc, Tc
a8d0: 6c 5f 4f 62 6a 20 2a 43 4f 4e 53 54 20 6f 62 6a  l_Obj *CONST obj
a8e0: 76 5b 5d 29 20 7b 0a 09 61 70 70 66 73 5f 73 69  v[]) {..appfs_si
a8f0: 6d 75 6c 61 74 65 5f 75 73 65 72 5f 66 73 5f 6c  mulate_user_fs_l
a900: 65 61 76 65 28 29 3b 0a 0a 09 72 65 74 75 72 6e  eave();...return
a910: 28 54 43 4c 5f 4f 4b 29 3b 0a 7d 0a 0a 73 74 61  (TCL_OK);.}..sta
a920: 74 69 63 20 69 6e 74 20 74 63 6c 5f 61 70 70 66  tic int tcl_appf
a930: 73 5f 67 65 74 5f 66 73 75 69 64 28 43 6c 69 65  s_get_fsuid(Clie
a940: 6e 74 44 61 74 61 20 63 64 2c 20 54 63 6c 5f 49  ntData cd, Tcl_I
a950: 6e 74 65 72 70 20 2a 69 6e 74 65 72 70 2c 20 69  nterp *interp, i
a960: 6e 74 20 6f 62 6a 63 2c 20 54 63 6c 5f 4f 62 6a  nt objc, Tcl_Obj
a970: 20 2a 43 4f 4e 53 54 20 6f 62 6a 76 5b 5d 29 20   *CONST objv[]) 
a980: 7b 0a 09 75 69 64 5f 74 20 66 73 75 69 64 3b 0a  {..uid_t fsuid;.
a990: 0a 09 66 73 75 69 64 20 3d 20 61 70 70 66 73 5f  ..fsuid = appfs_
a9a0: 67 65 74 5f 66 73 75 69 64 28 29 3b 0a 0a 20 20  get_fsuid();..  
a9b0: 20 20 20 20 20 09 54 63 6c 5f 53 65 74 4f 62 6a       .Tcl_SetObj
a9c0: 52 65 73 75 6c 74 28 69 6e 74 65 72 70 2c 20 54  Result(interp, T
a9d0: 63 6c 5f 4e 65 77 57 69 64 65 49 6e 74 4f 62 6a  cl_NewWideIntObj
a9e0: 28 66 73 75 69 64 29 29 3b 0a 0a 09 72 65 74 75  (fsuid));...retu
a9f0: 72 6e 28 54 43 4c 5f 4f 4b 29 3b 0a 7d 0a 0a 73  rn(TCL_OK);.}..s
aa00: 74 61 74 69 63 20 69 6e 74 20 74 63 6c 5f 61 70  tatic int tcl_ap
aa10: 70 66 73 5f 67 65 74 5f 66 73 67 69 64 28 43 6c  pfs_get_fsgid(Cl
aa20: 69 65 6e 74 44 61 74 61 20 63 64 2c 20 54 63 6c  ientData cd, Tcl
aa30: 5f 49 6e 74 65 72 70 20 2a 69 6e 74 65 72 70 2c  _Interp *interp,
aa40: 20 69 6e 74 20 6f 62 6a 63 2c 20 54 63 6c 5f 4f   int objc, Tcl_O
aa50: 62 6a 20 2a 43 4f 4e 53 54 20 6f 62 6a 76 5b 5d  bj *CONST objv[]
aa60: 29 20 7b 0a 09 67 69 64 5f 74 20 66 73 67 69 64  ) {..gid_t fsgid
aa70: 3b 0a 0a 09 66 73 67 69 64 20 3d 20 61 70 70 66  ;...fsgid = appf
aa80: 73 5f 67 65 74 5f 66 73 67 69 64 28 29 3b 0a 0a  s_get_fsgid();..
aa90: 20 20 20 20 20 20 20 09 54 63 6c 5f 53 65 74 4f         .Tcl_SetO
aaa0: 62 6a 52 65 73 75 6c 74 28 69 6e 74 65 72 70 2c  bjResult(interp,
aab0: 20 54 63 6c 5f 4e 65 77 57 69 64 65 49 6e 74 4f   Tcl_NewWideIntO
aac0: 62 6a 28 66 73 67 69 64 29 29 3b 0a 0a 09 72 65  bj(fsgid));...re
aad0: 74 75 72 6e 28 54 43 4c 5f 4f 4b 29 3b 0a 7d 0a  turn(TCL_OK);.}.
aae0: 0a 73 74 61 74 69 63 20 69 6e 74 20 74 63 6c 5f  .static int tcl_
aaf0: 61 70 70 66 73 5f 67 65 74 5f 70 61 74 68 5f 69  appfs_get_path_i
ab00: 6e 66 6f 5f 63 61 63 68 65 5f 66 6c 75 73 68 28  nfo_cache_flush(
ab10: 43 6c 69 65 6e 74 44 61 74 61 20 63 64 2c 20 54  ClientData cd, T
ab20: 63 6c 5f 49 6e 74 65 72 70 20 2a 69 6e 74 65 72  cl_Interp *inter
ab30: 70 2c 20 69 6e 74 20 6f 62 6a 63 2c 20 54 63 6c  p, int objc, Tcl
ab40: 5f 4f 62 6a 20 2a 43 4f 4e 53 54 20 6f 62 6a 76  _Obj *CONST objv
ab50: 5b 5d 29 20 7b 0a 09 69 6e 74 20 74 63 6c 5f 72  []) {..int tcl_r
ab60: 65 74 3b 0a 09 69 6e 74 20 6e 65 77 5f 73 69 7a  et;..int new_siz
ab70: 65 3b 0a 0a 09 6e 65 77 5f 73 69 7a 65 20 3d 20  e;...new_size = 
ab80: 2d 31 3b 0a 0a 09 69 66 20 28 6f 62 6a 63 20 3d  -1;...if (objc =
ab90: 3d 20 32 29 20 7b 0a 09 09 74 63 6c 5f 72 65 74  = 2) {...tcl_ret
aba0: 20 3d 20 54 63 6c 5f 47 65 74 49 6e 74 46 72 6f   = Tcl_GetIntFro
abb0: 6d 4f 62 6a 28 69 6e 74 65 72 70 2c 20 6f 62 6a  mObj(interp, obj
abc0: 76 5b 31 5d 2c 20 26 6e 65 77 5f 73 69 7a 65 29  v[1], &new_size)
abd0: 3b 0a 09 09 69 66 20 28 74 63 6c 5f 72 65 74 20  ;...if (tcl_ret 
abe0: 21 3d 20 54 43 4c 5f 4f 4b 29 20 7b 0a 09 09 09  != TCL_OK) {....
abf0: 72 65 74 75 72 6e 28 74 63 6c 5f 72 65 74 29 3b  return(tcl_ret);
ac00: 0a 09 09 7d 0a 09 7d 20 65 6c 73 65 20 69 66 20  ...}..} else if 
ac10: 28 6f 62 6a 63 20 3e 20 32 20 7c 7c 20 6f 62 6a  (objc > 2 || obj
ac20: 63 20 3c 20 31 29 20 7b 0a 20 20 20 20 20 20 20  c < 1) {.       
ac30: 20 20 20 20 20 20 20 20 20 54 63 6c 5f 57 72 6f           Tcl_Wro
ac40: 6e 67 4e 75 6d 41 72 67 73 28 69 6e 74 65 72 70  ngNumArgs(interp
ac50: 2c 20 31 2c 20 6f 62 6a 76 2c 20 22 3f 6e 65 77  , 1, objv, "?new
ac60: 5f 63 61 63 68 65 5f 73 69 7a 65 3f 22 29 3b 0a  _cache_size?");.
ac70: 09 09 72 65 74 75 72 6e 28 54 43 4c 5f 45 52 52  ..return(TCL_ERR
ac80: 4f 52 29 3b 0a 09 7d 0a 0a 09 61 70 70 66 73 5f  OR);..}...appfs_
ac90: 67 65 74 5f 70 61 74 68 5f 69 6e 66 6f 5f 63 61  get_path_info_ca
aca0: 63 68 65 5f 66 6c 75 73 68 28 2d 31 2c 20 6e 65  che_flush(-1, ne
acb0: 77 5f 73 69 7a 65 29 3b 0a 0a 09 72 65 74 75 72  w_size);...retur
acc0: 6e 28 54 43 4c 5f 4f 4b 29 3b 0a 7d 0a 0a 73 74  n(TCL_OK);.}..st
acd0: 61 74 69 63 20 69 6e 74 20 41 70 70 66 73 64 5f  atic int Appfsd_
ace0: 49 6e 69 74 28 54 63 6c 5f 49 6e 74 65 72 70 20  Init(Tcl_Interp 
acf0: 2a 69 6e 74 65 72 70 29 20 7b 0a 23 69 66 64 65  *interp) {.#ifde
ad00: 66 20 55 53 45 5f 54 43 4c 5f 53 54 55 42 53 0a  f USE_TCL_STUBS.
ad10: 09 69 66 20 28 54 63 6c 5f 49 6e 69 74 53 74 75  .if (Tcl_InitStu
ad20: 62 73 28 69 6e 74 65 72 70 2c 20 54 43 4c 5f 56  bs(interp, TCL_V
ad30: 45 52 53 49 4f 4e 2c 20 30 29 20 3d 3d 20 30 4c  ERSION, 0) == 0L
ad40: 29 20 7b 0a 09 09 72 65 74 75 72 6e 28 54 43 4c  ) {...return(TCL
ad50: 5f 45 52 52 4f 52 29 3b 0a 09 7d 0a 23 65 6e 64  _ERROR);..}.#end
ad60: 69 66 0a 0a 09 54 63 6c 5f 43 72 65 61 74 65 4f  if...Tcl_CreateO
ad70: 62 6a 43 6f 6d 6d 61 6e 64 28 69 6e 74 65 72 70  bjCommand(interp
ad80: 2c 20 22 61 70 70 66 73 64 3a 3a 67 65 74 5f 68  , "appfsd::get_h
ad90: 6f 6d 65 64 69 72 22 2c 20 74 63 6c 5f 61 70 70  omedir", tcl_app
ada0: 66 73 5f 67 65 74 5f 68 6f 6d 65 64 69 72 2c 20  fs_get_homedir, 
adb0: 4e 55 4c 4c 2c 20 4e 55 4c 4c 29 3b 0a 09 54 63  NULL, NULL);..Tc
adc0: 6c 5f 43 72 65 61 74 65 4f 62 6a 43 6f 6d 6d 61  l_CreateObjComma
add0: 6e 64 28 69 6e 74 65 72 70 2c 20 22 61 70 70 66  nd(interp, "appf
ade0: 73 64 3a 3a 67 65 74 5f 66 73 75 69 64 22 2c 20  sd::get_fsuid", 
adf0: 74 63 6c 5f 61 70 70 66 73 5f 67 65 74 5f 66 73  tcl_appfs_get_fs
ae00: 75 69 64 2c 20 4e 55 4c 4c 2c 20 4e 55 4c 4c 29  uid, NULL, NULL)
ae10: 3b 0a 09 54 63 6c 5f 43 72 65 61 74 65 4f 62 6a  ;..Tcl_CreateObj
ae20: 43 6f 6d 6d 61 6e 64 28 69 6e 74 65 72 70 2c 20  Command(interp, 
ae30: 22 61 70 70 66 73 64 3a 3a 67 65 74 5f 66 73 67  "appfsd::get_fsg
ae40: 69 64 22 2c 20 74 63 6c 5f 61 70 70 66 73 5f 67  id", tcl_appfs_g
ae50: 65 74 5f 66 73 67 69 64 2c 20 4e 55 4c 4c 2c 20  et_fsgid, NULL, 
ae60: 4e 55 4c 4c 29 3b 0a 09 54 63 6c 5f 43 72 65 61  NULL);..Tcl_Crea
ae70: 74 65 4f 62 6a 43 6f 6d 6d 61 6e 64 28 69 6e 74  teObjCommand(int
ae80: 65 72 70 2c 20 22 61 70 70 66 73 64 3a 3a 73 69  erp, "appfsd::si
ae90: 6d 75 6c 61 74 65 5f 75 73 65 72 5f 66 73 5f 65  mulate_user_fs_e
aea0: 6e 74 65 72 22 2c 20 74 63 6c 5f 61 70 70 66 73  nter", tcl_appfs
aeb0: 5f 73 69 6d 75 6c 61 74 65 5f 75 73 65 72 5f 66  _simulate_user_f
aec0: 73 5f 65 6e 74 65 72 2c 20 4e 55 4c 4c 2c 20 4e  s_enter, NULL, N
aed0: 55 4c 4c 29 3b 0a 09 54 63 6c 5f 43 72 65 61 74  ULL);..Tcl_Creat
aee0: 65 4f 62 6a 43 6f 6d 6d 61 6e 64 28 69 6e 74 65  eObjCommand(inte
aef0: 72 70 2c 20 22 61 70 70 66 73 64 3a 3a 73 69 6d  rp, "appfsd::sim
af00: 75 6c 61 74 65 5f 75 73 65 72 5f 66 73 5f 6c 65  ulate_user_fs_le
af10: 61 76 65 22 2c 20 74 63 6c 5f 61 70 70 66 73 5f  ave", tcl_appfs_
af20: 73 69 6d 75 6c 61 74 65 5f 75 73 65 72 5f 66 73  simulate_user_fs
af30: 5f 6c 65 61 76 65 2c 20 4e 55 4c 4c 2c 20 4e 55  _leave, NULL, NU
af40: 4c 4c 29 3b 0a 09 54 63 6c 5f 43 72 65 61 74 65  LL);..Tcl_Create
af50: 4f 62 6a 43 6f 6d 6d 61 6e 64 28 69 6e 74 65 72  ObjCommand(inter
af60: 70 2c 20 22 61 70 70 66 73 64 3a 3a 67 65 74 5f  p, "appfsd::get_
af70: 70 61 74 68 5f 69 6e 66 6f 5f 63 61 63 68 65 5f  path_info_cache_
af80: 66 6c 75 73 68 22 2c 20 74 63 6c 5f 61 70 70 66  flush", tcl_appf
af90: 73 5f 67 65 74 5f 70 61 74 68 5f 69 6e 66 6f 5f  s_get_path_info_
afa0: 63 61 63 68 65 5f 66 6c 75 73 68 2c 20 4e 55 4c  cache_flush, NUL
afb0: 4c 2c 20 4e 55 4c 4c 29 3b 0a 0a 09 54 63 6c 5f  L, NULL);...Tcl_
afc0: 50 6b 67 50 72 6f 76 69 64 65 28 69 6e 74 65 72  PkgProvide(inter
afd0: 70 2c 20 22 61 70 70 66 73 64 22 2c 20 22 31 2e  p, "appfsd", "1.
afe0: 30 22 29 3b 0a 0a 09 72 65 74 75 72 6e 28 54 43  0");...return(TC
aff0: 4c 5f 4f 4b 29 3b 0a 7d 0a 0a 2f 2a 0a 20 2a 20  L_OK);.}../*. * 
b000: 48 6f 74 2d 72 65 73 74 61 72 74 20 73 75 70 70  Hot-restart supp
b010: 6f 72 74 0a 20 2a 2f 0a 2f 2a 20 49 6e 69 74 69  ort. */./* Initi
b020: 61 74 65 20 61 20 68 6f 74 2d 72 65 73 74 61 72  ate a hot-restar
b030: 74 20 2a 2f 0a 73 74 61 74 69 63 20 76 6f 69 64  t */.static void
b040: 20 61 70 70 66 73 5f 68 6f 74 5f 72 65 73 74 61   appfs_hot_resta
b050: 72 74 28 76 6f 69 64 29 20 7b 0a 09 41 50 50 46  rt(void) {..APPF
b060: 53 5f 44 45 42 55 47 28 22 41 73 6b 65 64 20 74  S_DEBUG("Asked t
b070: 6f 20 69 6e 69 74 69 61 74 65 20 68 6f 74 20 72  o initiate hot r
b080: 65 73 74 61 72 74 22 29 3b 0a 0a 09 61 70 70 66  estart");...appf
b090: 73 5f 74 63 6c 5f 52 65 73 65 74 49 6e 74 65 72  s_tcl_ResetInter
b0a0: 70 73 28 29 3b 0a 0a 09 61 70 70 66 73 5f 67 65  ps();...appfs_ge
b0b0: 74 5f 70 61 74 68 5f 69 6e 66 6f 5f 63 61 63 68  t_path_info_cach
b0c0: 65 5f 66 6c 75 73 68 28 2d 31 2c 20 2d 31 29 3b  e_flush(-1, -1);
b0d0: 0a 0a 09 72 65 74 75 72 6e 3b 0a 7d 0a 0a 2f 2a  ...return;.}../*
b0e0: 0a 20 2a 20 53 69 67 6e 61 6c 20 68 61 6e 64 6c  . * Signal handl
b0f0: 65 72 0a 20 2a 20 20 20 20 20 20 20 20 20 53 49  er. *         SI
b100: 47 48 55 50 20 69 6e 69 74 69 61 74 65 73 20 61  GHUP initiates a
b110: 20 68 6f 74 20 72 65 73 74 61 72 74 0a 20 2a 2f   hot restart. */
b120: 0a 73 74 61 74 69 63 20 76 6f 69 64 20 61 70 70  .static void app
b130: 66 73 5f 73 69 67 6e 61 6c 5f 68 61 6e 64 6c 65  fs_signal_handle
b140: 72 28 69 6e 74 20 73 69 67 29 20 7b 0a 09 2f 2a  r(int sig) {../*
b150: 20 44 6f 20 6e 6f 74 20 68 61 6e 64 6c 65 20 73   Do not handle s
b160: 69 67 6e 61 6c 73 20 75 6e 74 69 6c 20 46 55 53  ignals until FUS
b170: 45 20 68 61 73 20 62 65 65 6e 20 73 74 61 72 74  E has been start
b180: 65 64 20 2a 2f 0a 09 69 66 20 28 21 61 70 70 66  ed */..if (!appf
b190: 73 5f 66 75 73 65 5f 73 74 61 72 74 65 64 29 20  s_fuse_started) 
b1a0: 7b 0a 09 09 72 65 74 75 72 6e 3b 0a 09 7d 0a 0a  {...return;..}..
b1b0: 09 2f 2a 20 52 65 71 75 65 73 74 20 74 6f 20 70  ./* Request to p
b1c0: 65 72 66 6f 72 6d 20 61 20 22 68 6f 74 22 20 72  erform a "hot" r
b1d0: 65 73 74 61 72 74 20 2a 2f 0a 09 69 66 20 28 73  estart */..if (s
b1e0: 69 67 20 3d 3d 20 53 49 47 48 55 50 29 20 7b 0a  ig == SIGHUP) {.
b1f0: 09 09 61 70 70 66 73 5f 68 6f 74 5f 72 65 73 74  ..appfs_hot_rest
b200: 61 72 74 28 29 3b 0a 09 7d 0a 0a 09 72 65 74 75  art();..}...retu
b210: 72 6e 3b 0a 7d 0a 0a 2f 2a 0a 20 2a 20 54 65 72  rn;.}../*. * Ter
b220: 6d 69 6e 61 74 65 20 61 20 74 68 72 65 61 64 0a  minate a thread.
b230: 20 2a 2f 0a 73 74 61 74 69 63 20 76 6f 69 64 20   */.static void 
b240: 61 70 70 66 73 5f 74 65 72 6d 69 6e 61 74 65 5f  appfs_terminate_
b250: 69 6e 74 65 72 70 5f 61 6e 64 5f 74 68 72 65 61  interp_and_threa
b260: 64 28 76 6f 69 64 20 2a 5f 69 6e 74 65 72 70 29  d(void *_interp)
b270: 20 7b 0a 09 54 63 6c 5f 49 6e 74 65 72 70 20 2a   {..Tcl_Interp *
b280: 69 6e 74 65 72 70 3b 0a 0a 09 41 50 50 46 53 5f  interp;...APPFS_
b290: 44 45 42 55 47 28 22 43 61 6c 6c 65 64 3a 20 5f  DEBUG("Called: _
b2a0: 69 6e 74 65 72 70 20 3d 20 25 70 22 2c 20 5f 69  interp = %p", _i
b2b0: 6e 74 65 72 70 29 3b 0a 0a 09 69 66 20 28 5f 69  nterp);...if (_i
b2c0: 6e 74 65 72 70 20 21 3d 20 4e 55 4c 4c 29 20 7b  nterp != NULL) {
b2d0: 0a 09 09 69 6e 74 65 72 70 20 3d 20 5f 69 6e 74  ...interp = _int
b2e0: 65 72 70 3b 0a 0a 09 09 41 50 50 46 53 5f 44 45  erp;....APPFS_DE
b2f0: 42 55 47 28 22 54 65 72 6d 69 6e 61 74 69 6e 67  BUG("Terminating
b300: 20 69 6e 74 65 72 70 72 65 74 65 72 20 64 75 65   interpreter due
b310: 20 74 6f 20 74 68 72 65 61 64 20 74 65 72 6d 69   to thread termi
b320: 6e 61 74 69 6f 6e 22 29 3b 0a 0a 09 09 61 70 70  nation");....app
b330: 66 73 5f 63 61 6c 6c 5f 6c 69 62 74 63 6c 28 0a  fs_call_libtcl(.
b340: 09 09 09 54 63 6c 5f 44 65 6c 65 74 65 49 6e 74  ...Tcl_DeleteInt
b350: 65 72 70 28 69 6e 74 65 72 70 29 3b 0a 09 09 29  erp(interp);...)
b360: 0a 09 7d 20 65 6c 73 65 20 7b 0a 09 09 41 50 50  ..} else {...APP
b370: 46 53 5f 44 45 42 55 47 28 22 54 65 72 6d 69 6e  FS_DEBUG("Termin
b380: 61 74 69 6e 67 20 74 68 72 65 61 64 20 77 69 74  ating thread wit
b390: 68 20 6e 6f 20 69 6e 74 65 72 70 72 65 74 65 72  h no interpreter
b3a0: 22 29 3b 0a 09 7d 0a 0a 09 61 70 70 66 73 5f 63  ");..}...appfs_c
b3b0: 61 6c 6c 5f 6c 69 62 74 63 6c 28 0a 09 09 54 63  all_libtcl(...Tc
b3c0: 6c 5f 46 69 6e 61 6c 69 7a 65 54 68 72 65 61 64  l_FinalizeThread
b3d0: 28 29 3b 0a 09 29 0a 0a 09 72 65 74 75 72 6e 3b  ();..)...return;
b3e0: 0a 7d 0a 0a 2f 2a 0a 20 2a 20 43 6f 6d 6d 61 6e  .}../*. * Comman
b3f0: 64 2d 6c 69 6e 65 20 70 61 72 73 69 6e 67 20 74  d-line parsing t
b400: 6f 6f 6c 73 0a 20 2a 2f 0a 73 74 61 74 69 63 20  ools. */.static 
b410: 76 6f 69 64 20 61 70 70 66 73 5f 70 72 69 6e 74  void appfs_print
b420: 5f 68 65 6c 70 28 46 49 4c 45 20 2a 63 68 61 6e  _help(FILE *chan
b430: 6e 65 6c 29 20 7b 0a 09 66 70 72 69 6e 74 66 28  nel) {..fprintf(
b440: 63 68 61 6e 6e 65 6c 2c 20 22 55 73 61 67 65 3a  channel, "Usage:
b450: 20 7b 61 70 70 66 73 64 7c 6d 6f 75 6e 74 2e 61   {appfsd|mount.a
b460: 70 70 66 73 7d 20 5b 2d 6f 20 3c 6f 70 74 69 6f  ppfs} [-o <optio
b470: 6e 3e 5d 20 5b 2d 64 66 73 68 5d 20 3c 63 61 63  n>] [-dfsh] <cac
b480: 68 65 64 69 72 3e 20 3c 6d 6f 75 6e 74 70 6f 69  hedir> <mountpoi
b490: 6e 74 3e 5c 6e 22 29 3b 0a 09 66 70 72 69 6e 74  nt>\n");..fprint
b4a0: 66 28 63 68 61 6e 6e 65 6c 2c 20 22 5c 6e 22 29  f(channel, "\n")
b4b0: 3b 0a 09 66 70 72 69 6e 74 66 28 63 68 61 6e 6e  ;..fprintf(chann
b4c0: 65 6c 2c 20 22 4f 70 74 69 6f 6e 73 3a 5c 6e 22  el, "Options:\n"
b4d0: 29 3b 0a 09 66 70 72 69 6e 74 66 28 63 68 61 6e  );..fprintf(chan
b4e0: 6e 65 6c 2c 20 22 20 20 2d 64 20 20 20 20 20 20  nel, "  -d      
b4f0: 20 20 20 20 20 20 20 20 45 6e 61 62 6c 65 20 46          Enable F
b500: 55 53 45 20 64 65 62 75 67 20 6d 6f 64 65 2e 5c  USE debug mode.\
b510: 6e 22 29 3b 0a 09 66 70 72 69 6e 74 66 28 63 68  n");..fprintf(ch
b520: 61 6e 6e 65 6c 2c 20 22 20 20 2d 66 20 20 20 20  annel, "  -f    
b530: 20 20 20 20 20 20 20 20 20 20 52 75 6e 20 69 6e            Run in
b540: 20 66 6f 72 65 67 72 6f 75 6e 64 2e 5c 6e 22 29   foreground.\n")
b550: 3b 0a 09 66 70 72 69 6e 74 66 28 63 68 61 6e 6e  ;..fprintf(chann
b560: 65 6c 2c 20 22 20 20 2d 73 20 20 20 20 20 20 20  el, "  -s       
b570: 20 20 20 20 20 20 20 45 6e 61 62 6c 65 20 73 69         Enable si
b580: 6e 67 6c 65 20 74 68 72 65 61 64 65 64 20 6d 6f  ngle threaded mo
b590: 64 65 2e 5c 6e 22 29 3b 0a 09 66 70 72 69 6e 74  de.\n");..fprint
b5a0: 66 28 63 68 61 6e 6e 65 6c 2c 20 22 20 20 2d 68  f(channel, "  -h
b5b0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 47 69                Gi
b5c0: 76 65 20 74 68 69 73 20 68 65 6c 70 2e 5c 6e 22  ve this help.\n"
b5d0: 29 3b 0a 09 66 70 72 69 6e 74 66 28 63 68 61 6e  );..fprintf(chan
b5e0: 6e 65 6c 2c 20 22 20 20 2d 6f 20 6e 6f 74 68 72  nel, "  -o nothr
b5f0: 65 61 64 73 20 20 20 20 45 6e 61 62 6c 65 20 73  eads    Enable s
b600: 69 6e 67 6c 65 20 74 68 72 65 61 64 65 64 20 6d  ingle threaded m
b610: 6f 64 65 2e 5c 6e 22 29 3b 0a 09 66 70 72 69 6e  ode.\n");..fprin
b620: 74 66 28 63 68 61 6e 6e 65 6c 2c 20 22 20 20 2d  tf(channel, "  -
b630: 6f 20 61 6c 6c 6f 77 5f 6f 74 68 65 72 20 20 41  o allow_other  A
b640: 6c 6c 6f 77 20 6f 74 68 65 72 20 75 73 65 72 73  llow other users
b650: 20 74 6f 20 61 63 63 65 73 73 20 74 68 69 73 20   to access this 
b660: 6d 6f 75 6e 74 70 6f 69 6e 74 20 28 64 65 66 61  mountpoint (defa
b670: 75 6c 74 5c 6e 22 29 3b 0a 09 66 70 72 69 6e 74  ult\n");..fprint
b680: 66 28 63 68 61 6e 6e 65 6c 2c 20 22 20 20 20 20  f(channel, "    
b690: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 69 66                if
b6a0: 20 72 6f 6f 74 29 2e 5c 6e 22 29 3b 0a 0a 09 72   root).\n");...r
b6b0: 65 74 75 72 6e 3b 0a 7d 0a 0a 73 74 61 74 69 63  eturn;.}..static
b6c0: 20 69 6e 74 20 61 70 70 66 73 5f 6f 70 74 5f 70   int appfs_opt_p
b6d0: 61 72 73 65 28 69 6e 74 20 61 72 67 63 2c 20 63  arse(int argc, c
b6e0: 68 61 72 20 2a 2a 61 72 67 76 2c 20 20 73 74 72  har **argv,  str
b6f0: 75 63 74 20 66 75 73 65 5f 61 72 67 73 20 2a 61  uct fuse_args *a
b700: 72 67 73 29 20 7b 0a 09 69 6e 74 20 63 68 3b 0a  rgs) {..int ch;.
b710: 09 63 68 61 72 20 2a 6f 70 74 73 74 72 2c 20 2a  .char *optstr, *
b720: 6f 70 74 73 74 72 5f 6e 65 78 74 2c 20 2a 6f 70  optstr_next, *op
b730: 74 73 74 72 5f 73 3b 0a 09 63 68 61 72 20 66 61  tstr_s;..char fa
b740: 6b 65 5f 61 72 67 5b 33 5d 20 3d 20 7b 27 2d 27  ke_arg[3] = {'-'
b750: 2c 20 30 2c 20 30 7d 3b 0a 0a 09 2f 2a 0a 09 20  , 0, 0};.../*.. 
b760: 2a 20 44 65 66 61 75 6c 74 20 76 61 6c 75 65 73  * Default values
b770: 0a 09 20 2a 2f 0a 23 69 66 64 65 66 20 54 43 4c  .. */.#ifdef TCL
b780: 5f 54 48 52 45 41 44 53 0a 09 61 70 70 66 73 5f  _THREADS..appfs_
b790: 74 68 72 65 61 64 65 64 5f 74 63 6c 20 3d 20 31  threaded_tcl = 1
b7a0: 3b 0a 23 65 6c 73 65 0a 09 61 70 70 66 73 5f 74  ;.#else..appfs_t
b7b0: 68 72 65 61 64 65 64 5f 74 63 6c 20 3d 20 30 3b  hreaded_tcl = 0;
b7c0: 0a 23 65 6e 64 69 66 0a 0a 09 2f 2a 2a 0a 09 20  .#endif.../**.. 
b7d0: 2a 2a 20 41 64 64 20 46 55 53 45 20 61 72 67 75  ** Add FUSE argu
b7e0: 6d 65 6e 74 73 20 77 68 69 63 68 20 77 65 20 61  ments which we a
b7f0: 6c 77 61 79 73 20 73 75 70 70 6c 79 0a 09 20 2a  lways supply.. *
b800: 2a 2f 0a 09 66 75 73 65 5f 6f 70 74 5f 61 64 64  */..fuse_opt_add
b810: 5f 61 72 67 28 61 72 67 73 2c 20 22 2d 6f 64 65  _arg(args, "-ode
b820: 66 61 75 6c 74 5f 70 65 72 6d 69 73 73 69 6f 6e  fault_permission
b830: 73 2c 66 73 6e 61 6d 65 3d 61 70 70 66 73 2c 73  s,fsname=appfs,s
b840: 75 62 74 79 70 65 3d 61 70 70 66 73 64 2c 75 73  ubtype=appfsd,us
b850: 65 5f 69 6e 6f 2c 65 6e 74 72 79 5f 74 69 6d 65  e_ino,entry_time
b860: 6f 75 74 3d 30 2c 61 74 74 72 5f 74 69 6d 65 6f  out=0,attr_timeo
b870: 75 74 3d 30 2c 62 69 67 5f 77 72 69 74 65 73 2c  ut=0,big_writes,
b880: 69 6e 74 72 2c 68 61 72 64 5f 72 65 6d 6f 76 65  intr,hard_remove
b890: 22 29 3b 0a 0a 09 69 66 20 28 67 65 74 75 69 64  ");...if (getuid
b8a0: 28 29 20 3d 3d 20 30 29 20 7b 0a 09 09 66 75 73  () == 0) {...fus
b8b0: 65 5f 6f 70 74 5f 70 61 72 73 65 28 61 72 67 73  e_opt_parse(args
b8c0: 2c 20 4e 55 4c 4c 2c 20 4e 55 4c 4c 2c 20 4e 55  , NULL, NULL, NU
b8d0: 4c 4c 29 3b 0a 09 09 66 75 73 65 5f 6f 70 74 5f  LL);...fuse_opt_
b8e0: 61 64 64 5f 61 72 67 28 61 72 67 73 2c 20 22 2d  add_arg(args, "-
b8f0: 6f 61 6c 6c 6f 77 5f 6f 74 68 65 72 22 29 3b 0a  oallow_other");.
b900: 0a 09 09 2f 2a 0a 09 09 20 2a 20 54 68 69 73 20  .../*... * This 
b910: 73 68 6f 75 6c 64 20 67 65 6e 65 72 61 6c 6c 79  should generally
b920: 20 62 65 20 61 76 6f 69 64 65 64 2c 20 62 75 74   be avoided, but
b930: 20 69 66 20 74 68 65 72 65 20 61 72 65 20 73 65   if there are se
b940: 63 75 72 69 74 79 0a 09 09 20 2a 20 63 6f 6e 63  curity... * conc
b950: 65 72 6e 73 20 73 75 69 64 20 63 61 6e 20 62 65  erns suid can be
b960: 20 64 69 73 61 62 6c 65 64 20 63 6f 6d 70 6c 65   disabled comple
b970: 74 65 6c 79 20 6f 6e 20 74 68 65 20 63 6f 6d 6d  tely on the comm
b980: 61 6e 64 6c 69 6e 65 0a 09 09 20 2a 2f 0a 09 09  andline... */...
b990: 66 75 73 65 5f 6f 70 74 5f 70 61 72 73 65 28 61  fuse_opt_parse(a
b9a0: 72 67 73 2c 20 4e 55 4c 4c 2c 20 4e 55 4c 4c 2c  rgs, NULL, NULL,
b9b0: 20 4e 55 4c 4c 29 3b 0a 09 09 66 75 73 65 5f 6f   NULL);...fuse_o
b9c0: 70 74 5f 61 64 64 5f 61 72 67 28 61 72 67 73 2c  pt_add_arg(args,
b9d0: 20 22 2d 6f 73 75 69 64 22 29 3b 0a 09 7d 0a 0a   "-osuid");..}..
b9e0: 09 77 68 69 6c 65 20 28 28 63 68 20 3d 20 67 65  .while ((ch = ge
b9f0: 74 6f 70 74 28 61 72 67 63 2c 20 61 72 67 76 2c  topt(argc, argv,
ba00: 20 22 64 66 73 68 76 6f 3a 22 29 29 20 21 3d 20   "dfshvo:")) != 
ba10: 2d 31 29 20 7b 0a 09 09 73 77 69 74 63 68 20 28  -1) {...switch (
ba20: 63 68 29 20 7b 0a 09 09 09 63 61 73 65 20 27 76  ch) {....case 'v
ba30: 27 3a 0a 09 09 09 09 2f 2a 20 49 67 6e 6f 72 65  ':...../* Ignore
ba40: 64 20 2a 2f 0a 09 09 09 09 62 72 65 61 6b 3b 0a  d */.....break;.
ba50: 09 09 09 63 61 73 65 20 27 6f 27 3a 0a 09 09 09  ...case 'o':....
ba60: 09 6f 70 74 73 74 72 5f 6e 65 78 74 20 3d 20 6f  .optstr_next = o
ba70: 70 74 73 74 72 20 3d 20 6f 70 74 73 74 72 5f 73  ptstr = optstr_s
ba80: 20 3d 20 73 74 72 64 75 70 28 6f 70 74 61 72 67   = strdup(optarg
ba90: 29 3b 0a 0a 09 09 09 09 77 68 69 6c 65 20 28 31  );......while (1
baa0: 29 20 7b 0a 09 09 09 09 09 6f 70 74 73 74 72 20  ) {......optstr 
bab0: 3d 20 6f 70 74 73 74 72 5f 6e 65 78 74 3b 0a 0a  = optstr_next;..
bac0: 09 09 09 09 09 69 66 20 28 21 6f 70 74 73 74 72  .....if (!optstr
bad0: 29 20 7b 0a 09 09 09 09 09 09 62 72 65 61 6b 3b  ) {.......break;
bae0: 0a 09 09 09 09 09 7d 0a 0a 09 09 09 09 09 6f 70  ......}.......op
baf0: 74 73 74 72 5f 6e 65 78 74 20 3d 20 73 74 72 63  tstr_next = strc
bb00: 68 72 28 6f 70 74 73 74 72 2c 20 27 2c 27 29 3b  hr(optstr, ',');
bb10: 0a 09 09 09 09 09 69 66 20 28 6f 70 74 73 74 72  ......if (optstr
bb20: 5f 6e 65 78 74 29 20 7b 0a 09 09 09 09 09 09 2a  _next) {.......*
bb30: 6f 70 74 73 74 72 5f 6e 65 78 74 20 3d 20 27 5c  optstr_next = '\
bb40: 30 27 3b 0a 09 09 09 09 09 09 6f 70 74 73 74 72  0';.......optstr
bb50: 5f 6e 65 78 74 2b 2b 3b 0a 09 09 09 09 09 7d 0a  _next++;......}.
bb60: 0a 09 09 09 09 09 69 66 20 28 73 74 72 63 6d 70  ......if (strcmp
bb70: 28 6f 70 74 73 74 72 2c 20 22 6e 6f 74 68 72 65  (optstr, "nothre
bb80: 61 64 73 22 29 20 3d 3d 20 30 29 20 7b 0a 09 09  ads") == 0) {...
bb90: 09 09 09 09 41 50 50 46 53 5f 44 45 42 55 47 28  ....APPFS_DEBUG(
bba0: 22 50 61 73 73 69 6e 67 20 6f 70 74 69 6f 6e 20  "Passing option 
bbb0: 74 6f 20 46 55 53 45 3a 20 2d 73 22 29 3b 0a 0a  to FUSE: -s");..
bbc0: 09 09 09 09 09 09 66 75 73 65 5f 6f 70 74 5f 70  ......fuse_opt_p
bbd0: 61 72 73 65 28 61 72 67 73 2c 20 4e 55 4c 4c 2c  arse(args, NULL,
bbe0: 20 4e 55 4c 4c 2c 20 4e 55 4c 4c 29 3b 0a 09 09   NULL, NULL);...
bbf0: 09 09 09 09 66 75 73 65 5f 6f 70 74 5f 61 64 64  ....fuse_opt_add
bc00: 5f 61 72 67 28 61 72 67 73 2c 20 22 2d 73 22 29  _arg(args, "-s")
bc10: 3b 0a 0a 09 09 09 09 09 09 61 70 70 66 73 5f 74  ;........appfs_t
bc20: 68 72 65 61 64 65 64 5f 74 63 6c 20 3d 20 30 3b  hreaded_tcl = 0;
bc30: 0a 09 09 09 09 09 7d 20 65 6c 73 65 20 69 66 20  ......} else if 
bc40: 28 73 74 72 63 6d 70 28 6f 70 74 73 74 72 2c 20  (strcmp(optstr, 
bc50: 22 61 6c 6c 6f 77 5f 6f 74 68 65 72 22 29 20 3d  "allow_other") =
bc60: 3d 20 30 29 20 7b 0a 09 09 09 09 09 09 41 50 50  = 0) {.......APP
bc70: 46 53 5f 44 45 42 55 47 28 22 50 61 73 73 69 6e  FS_DEBUG("Passin
bc80: 67 20 6f 70 74 69 6f 6e 20 74 6f 20 46 55 53 45  g option to FUSE
bc90: 3a 20 2d 6f 20 61 6c 6c 6f 77 5f 6f 74 68 65 72  : -o allow_other
bca0: 22 29 3b 0a 0a 09 09 09 09 09 09 66 75 73 65 5f  ");........fuse_
bcb0: 6f 70 74 5f 70 61 72 73 65 28 61 72 67 73 2c 20  opt_parse(args, 
bcc0: 4e 55 4c 4c 2c 20 4e 55 4c 4c 2c 20 4e 55 4c 4c  NULL, NULL, NULL
bcd0: 29 3b 0a 09 09 09 09 09 09 66 75 73 65 5f 6f 70  );.......fuse_op
bce0: 74 5f 61 64 64 5f 61 72 67 28 61 72 67 73 2c 20  t_add_arg(args, 
bcf0: 22 2d 6f 61 6c 6c 6f 77 5f 6f 74 68 65 72 22 29  "-oallow_other")
bd00: 3b 0a 09 09 09 09 09 7d 20 65 6c 73 65 20 69 66  ;......} else if
bd10: 20 28 73 74 72 63 6d 70 28 6f 70 74 73 74 72 2c   (strcmp(optstr,
bd20: 20 22 72 77 22 29 20 3d 3d 20 30 29 20 7b 0a 09   "rw") == 0) {..
bd30: 09 09 09 09 09 2f 2a 20 49 67 6e 6f 72 65 64 20  ...../* Ignored 
bd40: 2a 2f 0a 09 09 09 09 09 7d 20 65 6c 73 65 20 7b  */......} else {
bd50: 0a 09 09 09 09 09 09 66 70 72 69 6e 74 66 28 73  .......fprintf(s
bd60: 74 64 65 72 72 2c 20 22 61 70 70 66 73 64 3a 20  tderr, "appfsd: 
bd70: 69 6e 76 61 6c 69 64 20 6f 70 74 69 6f 6e 3a 20  invalid option: 
bd80: 5c 22 2d 6f 20 25 73 5c 22 5c 6e 22 2c 20 6f 70  \"-o %s\"\n", op
bd90: 74 73 74 72 29 3b 0a 0a 09 09 09 09 09 09 66 72  tstr);........fr
bda0: 65 65 28 6f 70 74 73 74 72 5f 73 29 3b 0a 0a 09  ee(optstr_s);...
bdb0: 09 09 09 09 09 72 65 74 75 72 6e 28 31 29 3b 0a  .....return(1);.
bdc0: 09 09 09 09 09 7d 0a 09 09 09 09 7d 0a 0a 09 09  .....}.....}....
bdd0: 09 09 66 72 65 65 28 6f 70 74 73 74 72 5f 73 29  ..free(optstr_s)
bde0: 3b 0a 0a 09 09 09 09 62 72 65 61 6b 3b 0a 09 09  ;......break;...
bdf0: 09 63 61 73 65 20 27 64 27 3a 0a 09 09 09 63 61  .case 'd':....ca
be00: 73 65 20 27 66 27 3a 0a 09 09 09 63 61 73 65 20  se 'f':....case 
be10: 27 73 27 3a 0a 09 09 09 09 69 66 20 28 63 68 20  's':.....if (ch 
be20: 3d 3d 20 27 73 27 29 20 7b 0a 09 09 09 09 09 61  == 's') {......a
be30: 70 70 66 73 5f 74 68 72 65 61 64 65 64 5f 74 63  ppfs_threaded_tc
be40: 6c 20 3d 20 30 3b 0a 09 09 09 09 7d 0a 0a 09 09  l = 0;.....}....
be50: 09 09 66 61 6b 65 5f 61 72 67 5b 31 5d 20 3d 20  ..fake_arg[1] = 
be60: 63 68 3b 0a 0a 09 09 09 09 41 50 50 46 53 5f 44  ch;......APPFS_D
be70: 45 42 55 47 28 22 50 61 73 73 69 6e 67 20 6f 70  EBUG("Passing op
be80: 74 69 6f 6e 20 74 6f 20 46 55 53 45 3a 20 25 73  tion to FUSE: %s
be90: 22 2c 20 66 61 6b 65 5f 61 72 67 29 3b 0a 0a 09  ", fake_arg);...
bea0: 09 09 09 66 75 73 65 5f 6f 70 74 5f 70 61 72 73  ...fuse_opt_pars
beb0: 65 28 61 72 67 73 2c 20 4e 55 4c 4c 2c 20 4e 55  e(args, NULL, NU
bec0: 4c 4c 2c 20 4e 55 4c 4c 29 3b 0a 09 09 09 09 66  LL, NULL);.....f
bed0: 75 73 65 5f 6f 70 74 5f 61 64 64 5f 61 72 67 28  use_opt_add_arg(
bee0: 61 72 67 73 2c 20 66 61 6b 65 5f 61 72 67 29 3b  args, fake_arg);
bef0: 0a 09 09 09 09 62 72 65 61 6b 3b 0a 09 09 09 63  .....break;....c
bf00: 61 73 65 20 27 68 27 3a 0a 09 09 09 09 61 70 70  ase 'h':.....app
bf10: 66 73 5f 70 72 69 6e 74 5f 68 65 6c 70 28 73 74  fs_print_help(st
bf20: 64 6f 75 74 29 3b 0a 0a 09 09 09 09 72 65 74 75  dout);......retu
bf30: 72 6e 28 2d 31 29 3b 0a 09 09 09 63 61 73 65 20  rn(-1);....case 
bf40: 27 3a 27 3a 0a 09 09 09 63 61 73 65 20 27 3f 27  ':':....case '?'
bf50: 3a 0a 09 09 09 64 65 66 61 75 6c 74 3a 0a 09 09  :....default:...
bf60: 09 09 61 70 70 66 73 5f 70 72 69 6e 74 5f 68 65  ..appfs_print_he
bf70: 6c 70 28 73 74 64 65 72 72 29 3b 0a 0a 09 09 09  lp(stderr);.....
bf80: 09 72 65 74 75 72 6e 28 31 29 3b 0a 09 09 7d 0a  .return(1);...}.
bf90: 09 7d 0a 0a 09 69 66 20 28 28 6f 70 74 69 6e 64  .}...if ((optind
bfa0: 20 2b 20 32 29 20 21 3d 20 61 72 67 63 29 20 7b   + 2) != argc) {
bfb0: 0a 09 09 69 66 20 28 28 6f 70 74 69 6e 64 20 2b  ...if ((optind +
bfc0: 20 32 29 20 3c 20 61 72 67 63 29 20 7b 0a 09 09   2) < argc) {...
bfd0: 09 66 70 72 69 6e 74 66 28 73 74 64 65 72 72 2c  .fprintf(stderr,
bfe0: 20 22 54 6f 6f 20 6d 61 6e 79 20 61 72 67 75 6d   "Too many argum
bff0: 65 6e 74 73 5c 6e 22 29 3b 0a 09 09 7d 20 65 6c  ents\n");...} el
c000: 73 65 20 7b 0a 09 09 09 66 70 72 69 6e 74 66 28  se {....fprintf(
c010: 73 74 64 65 72 72 2c 20 22 4d 69 73 73 69 6e 67  stderr, "Missing
c020: 20 63 61 63 68 65 64 69 72 20 6f 72 20 6d 6f 75   cachedir or mou
c030: 6e 74 70 6f 69 6e 74 5c 6e 22 29 3b 0a 09 09 7d  ntpoint\n");...}
c040: 0a 0a 09 09 61 70 70 66 73 5f 70 72 69 6e 74 5f  ....appfs_print_
c050: 68 65 6c 70 28 73 74 64 65 72 72 29 3b 0a 0a 09  help(stderr);...
c060: 09 72 65 74 75 72 6e 28 31 29 3b 0a 09 7d 0a 0a  .return(1);..}..
c070: 09 2f 2a 0a 09 20 2a 20 53 65 74 20 63 61 63 68  ./*.. * Set cach
c080: 65 20 64 69 72 20 61 73 20 66 69 72 73 74 20 61  e dir as first a
c090: 72 67 75 6d 65 6e 74 20 28 74 68 65 20 22 64 65  rgument (the "de
c0a0: 76 69 63 65 22 2c 20 65 73 73 65 6e 74 69 61 6c  vice", essential
c0b0: 6c 79 29 0a 09 20 2a 2f 0a 09 61 70 70 66 73 5f  ly).. */..appfs_
c0c0: 63 61 63 68 65 64 69 72 20 3d 20 61 72 67 76 5b  cachedir = argv[
c0d0: 6f 70 74 69 6e 64 5d 3b 0a 0a 09 2f 2a 0a 09 20  optind];.../*.. 
c0e0: 2a 20 50 61 73 73 20 74 68 65 20 72 65 6d 61 69  * Pass the remai
c0f0: 6e 69 6e 67 20 61 72 67 75 6d 65 6e 74 20 74 6f  ning argument to
c100: 20 46 55 53 45 20 61 73 20 74 68 65 20 64 69 72   FUSE as the dir
c110: 65 63 74 6f 72 79 0a 09 20 2a 2f 0a 09 66 75 73  ectory.. */..fus
c120: 65 5f 6f 70 74 5f 70 61 72 73 65 28 61 72 67 73  e_opt_parse(args
c130: 2c 20 4e 55 4c 4c 2c 20 4e 55 4c 4c 2c 20 4e 55  , NULL, NULL, NU
c140: 4c 4c 29 3b 0a 09 66 75 73 65 5f 6f 70 74 5f 61  LL);..fuse_opt_a
c150: 64 64 5f 61 72 67 28 61 72 67 73 2c 20 61 72 67  dd_arg(args, arg
c160: 76 5b 6f 70 74 69 6e 64 20 2b 20 31 5d 29 3b 0a  v[optind + 1]);.
c170: 0a 09 72 65 74 75 72 6e 28 30 29 3b 0a 7d 0a 0a  ..return(0);.}..
c180: 0a 2f 2a 0a 20 2a 20 46 55 53 45 20 6f 70 65 72  ./*. * FUSE oper
c190: 61 74 69 6f 6e 73 20 73 74 72 75 63 74 75 72 65  ations structure
c1a0: 0a 20 2a 2f 0a 73 74 61 74 69 63 20 73 74 72 75  . */.static stru
c1b0: 63 74 20 66 75 73 65 5f 6f 70 65 72 61 74 69 6f  ct fuse_operatio
c1c0: 6e 73 20 61 70 70 66 73 5f 6f 70 65 72 61 74 69  ns appfs_operati
c1d0: 6f 6e 73 20 3d 20 7b 0a 09 2e 67 65 74 61 74 74  ons = {...getatt
c1e0: 72 20 20 20 3d 20 61 70 70 66 73 5f 66 75 73 65  r   = appfs_fuse
c1f0: 5f 67 65 74 61 74 74 72 2c 0a 09 2e 72 65 61 64  _getattr,...read
c200: 64 69 72 20 20 20 3d 20 61 70 70 66 73 5f 66 75  dir   = appfs_fu
c210: 73 65 5f 72 65 61 64 64 69 72 2c 0a 09 2e 72 65  se_readdir,...re
c220: 61 64 6c 69 6e 6b 20 20 3d 20 61 70 70 66 73 5f  adlink  = appfs_
c230: 66 75 73 65 5f 72 65 61 64 6c 69 6e 6b 2c 0a 09  fuse_readlink,..
c240: 2e 6f 70 65 6e 20 20 20 20 20 20 3d 20 61 70 70  .open      = app
c250: 66 73 5f 66 75 73 65 5f 6f 70 65 6e 2c 0a 09 2e  fs_fuse_open,...
c260: 72 65 6c 65 61 73 65 20 20 20 3d 20 61 70 70 66  release   = appf
c270: 73 5f 66 75 73 65 5f 63 6c 6f 73 65 2c 0a 09 2e  s_fuse_close,...
c280: 72 65 61 64 20 20 20 20 20 20 3d 20 61 70 70 66  read      = appf
c290: 73 5f 66 75 73 65 5f 72 65 61 64 2c 0a 09 2e 77  s_fuse_read,...w
c2a0: 72 69 74 65 20 20 20 20 20 3d 20 61 70 70 66 73  rite     = appfs
c2b0: 5f 66 75 73 65 5f 77 72 69 74 65 2c 0a 09 2e 6d  _fuse_write,...m
c2c0: 6b 6e 6f 64 20 20 20 20 20 3d 20 61 70 70 66 73  knod     = appfs
c2d0: 5f 66 75 73 65 5f 6d 6b 6e 6f 64 2c 0a 09 2e 63  _fuse_mknod,...c
c2e0: 72 65 61 74 65 20 20 20 20 3d 20 61 70 70 66 73  reate    = appfs
c2f0: 5f 66 75 73 65 5f 63 72 65 61 74 65 2c 0a 09 2e  _fuse_create,...
c300: 74 72 75 6e 63 61 74 65 20 20 3d 20 61 70 70 66  truncate  = appf
c310: 73 5f 66 75 73 65 5f 74 72 75 6e 63 61 74 65 2c  s_fuse_truncate,
c320: 0a 09 2e 75 6e 6c 69 6e 6b 20 20 20 20 3d 20 61  ...unlink    = a
c330: 70 70 66 73 5f 66 75 73 65 5f 75 6e 6c 69 6e 6b  ppfs_fuse_unlink
c340: 5f 72 6d 64 69 72 2c 0a 09 2e 72 6d 64 69 72 20  _rmdir,...rmdir 
c350: 20 20 20 20 3d 20 61 70 70 66 73 5f 66 75 73 65      = appfs_fuse
c360: 5f 75 6e 6c 69 6e 6b 5f 72 6d 64 69 72 2c 0a 09  _unlink_rmdir,..
c370: 2e 6d 6b 64 69 72 20 20 20 20 20 3d 20 61 70 70  .mkdir     = app
c380: 66 73 5f 66 75 73 65 5f 6d 6b 64 69 72 2c 0a 09  fs_fuse_mkdir,..
c390: 2e 63 68 6d 6f 64 20 20 20 20 20 3d 20 61 70 70  .chmod     = app
c3a0: 66 73 5f 66 75 73 65 5f 63 68 6d 6f 64 2c 0a 09  fs_fuse_chmod,..
c3b0: 2e 73 79 6d 6c 69 6e 6b 20 20 20 3d 20 61 70 70  .symlink   = app
c3c0: 66 73 5f 66 75 73 65 5f 73 79 6d 6c 69 6e 6b 2c  fs_fuse_symlink,
c3d0: 0a 7d 3b 0a 0a 2f 2a 0a 20 2a 20 45 6e 74 72 79  .};../*. * Entry
c3e0: 20 70 6f 69 6e 74 20 69 6e 74 6f 20 74 68 69 73   point into this
c3f0: 20 70 72 6f 67 72 61 6d 2e 0a 20 2a 2f 0a 69 6e   program.. */.in
c400: 74 20 6d 61 69 6e 28 69 6e 74 20 61 72 67 63 2c  t main(int argc,
c410: 20 63 68 61 72 20 2a 2a 61 72 67 76 29 20 7b 0a   char **argv) {.
c420: 09 54 63 6c 5f 49 6e 74 65 72 70 20 2a 74 65 73  .Tcl_Interp *tes
c430: 74 5f 69 6e 74 65 72 70 3b 0a 09 63 68 61 72 20  t_interp;..char 
c440: 2a 74 65 73 74 5f 69 6e 74 65 72 70 5f 65 72 72  *test_interp_err
c450: 6f 72 3b 0a 09 73 74 72 75 63 74 20 66 75 73 65  or;..struct fuse
c460: 5f 61 72 67 73 20 61 72 67 73 20 3d 20 46 55 53  _args args = FUS
c470: 45 5f 41 52 47 53 5f 49 4e 49 54 28 30 2c 20 4e  E_ARGS_INIT(0, N
c480: 55 4c 4c 29 3b 0a 09 73 74 72 75 63 74 20 72 6c  ULL);..struct rl
c490: 69 6d 69 74 20 6e 75 6d 62 65 72 5f 6f 70 65 6e  imit number_open
c4a0: 5f 66 69 6c 65 73 3b 0a 09 69 6e 74 20 70 74 68  _files;..int pth
c4b0: 72 65 61 64 5f 72 65 74 2c 20 61 6f 70 5f 72 65  read_ret, aop_re
c4c0: 74 2c 20 72 6c 69 6d 69 74 5f 72 65 74 3b 0a 09  t, rlimit_ret;..
c4d0: 76 6f 69 64 20 2a 73 69 67 6e 61 6c 5f 72 65 74  void *signal_ret
c4e0: 3b 0a 09 63 68 61 72 20 2a 61 72 67 76 30 3b 0a  ;..char *argv0;.
c4f0: 09 72 6c 69 6d 5f 74 20 6e 75 6d 62 65 72 5f 6f  .rlim_t number_o
c500: 70 65 6e 5f 66 69 6c 65 73 5f 6d 61 78 3b 0a 0a  pen_files_max;..
c510: 09 2f 2a 0a 09 20 2a 20 53 6b 69 70 20 70 61 73  ./*.. * Skip pas
c520: 73 65 64 20 70 72 6f 67 72 61 6d 20 6e 61 6d 65  sed program name
c530: 0a 09 20 2a 2f 0a 09 69 66 20 28 61 72 67 63 20  .. */..if (argc 
c540: 3d 3d 20 30 20 7c 7c 20 61 72 67 76 20 3d 3d 20  == 0 || argv == 
c550: 4e 55 4c 4c 29 20 7b 0a 09 09 72 65 74 75 72 6e  NULL) {...return
c560: 28 31 29 3b 0a 09 7d 0a 0a 09 61 72 67 76 30 20  (1);..}...argv0 
c570: 3d 20 61 72 67 76 5b 30 5d 3b 0a 0a 09 61 72 67  = argv[0];...arg
c580: 63 2d 2d 3b 0a 09 61 72 67 76 2b 2b 3b 0a 0a 09  c--;..argv++;...
c590: 2f 2a 0a 09 20 2a 20 53 65 74 20 61 70 70 72 6f  /*.. * Set appro
c5a0: 70 72 69 61 74 65 20 75 6d 61 73 6b 0a 09 20 2a  priate umask.. *
c5b0: 2f 0a 09 75 6d 61 73 6b 28 30 32 32 29 3b 0a 0a  /..umask(022);..
c5c0: 09 2f 2a 0a 09 20 2a 20 53 65 74 20 67 6c 6f 62  ./*.. * Set glob
c5d0: 61 6c 20 76 61 72 69 61 62 6c 65 73 2c 20 74 68  al variables, th
c5e0: 65 73 65 20 73 68 6f 75 6c 64 20 62 65 20 63 6f  ese should be co
c5f0: 6e 66 69 67 75 72 61 74 69 6f 6e 20 6f 70 74 69  nfiguration opti
c600: 6f 6e 73 2e 0a 09 20 2a 2f 0a 09 61 70 70 66 73  ons... */..appfs
c610: 5f 63 61 63 68 65 64 69 72 20 3d 20 41 50 50 46  _cachedir = APPF
c620: 53 5f 43 41 43 48 45 44 49 52 3b 0a 0a 09 2f 2a  S_CACHEDIR;.../*
c630: 0a 09 20 2a 20 53 65 74 20 67 6c 6f 62 61 6c 20  .. * Set global 
c640: 76 61 72 69 61 62 6c 65 20 66 6f 72 20 22 62 6f  variable for "bo
c650: 6f 74 20 74 69 6d 65 22 20 74 6f 20 73 65 74 20  ot time" to set 
c660: 61 20 74 69 6d 65 20 6f 6e 20 64 69 72 65 63 74  a time on direct
c670: 6f 72 69 65 73 0a 09 20 2a 20 74 68 61 74 20 77  ories.. * that w
c680: 65 20 66 61 6b 65 2e 0a 09 20 2a 2f 0a 09 61 70  e fake... */..ap
c690: 70 66 73 5f 62 6f 6f 74 74 69 6d 65 20 3d 20 74  pfs_boottime = t
c6a0: 69 6d 65 28 4e 55 4c 4c 29 3b 0a 0a 09 2f 2a 0a  ime(NULL);.../*.
c6b0: 09 20 2a 20 52 65 67 69 73 74 65 72 20 22 73 68  . * Register "sh
c6c0: 61 31 22 20 61 6e 64 20 22 61 70 70 66 73 64 22  a1" and "appfsd"
c6d0: 20 70 61 63 6b 61 67 65 20 77 69 74 68 20 6c 69   package with li
c6e0: 62 74 63 6c 20 73 6f 20 74 68 61 74 20 61 6e 79  btcl so that any
c6f0: 20 6e 65 77 0a 09 20 2a 20 69 6e 74 65 72 70 72   new.. * interpr
c700: 65 74 65 72 73 20 63 72 65 61 74 65 64 20 28 77  eters created (w
c710: 68 69 63 68 20 61 72 65 20 64 6f 6e 65 20 64 79  hich are done dy
c720: 6e 61 6d 69 63 61 6c 6c 79 20 62 79 20 46 55 53  namically by FUS
c730: 45 29 20 63 61 6e 20 68 61 76 65 0a 09 20 2a 20  E) can have.. * 
c740: 74 68 65 20 61 70 70 72 6f 70 72 69 61 74 65 20  the appropriate 
c750: 63 6f 6e 66 69 67 75 72 61 74 69 6f 6e 20 64 6f  configuration do
c760: 6e 65 20 61 75 74 6f 6d 61 74 69 63 61 6c 6c 79  ne automatically
c770: 2e 0a 09 20 2a 2f 0a 09 54 63 6c 5f 53 74 61 74  ... */..Tcl_Stat
c780: 69 63 50 61 63 6b 61 67 65 28 4e 55 4c 4c 2c 20  icPackage(NULL, 
c790: 22 73 68 61 31 22 2c 20 53 68 61 31 5f 49 6e 69  "sha1", Sha1_Ini
c7a0: 74 2c 20 4e 55 4c 4c 29 3b 0a 09 54 63 6c 5f 53  t, NULL);..Tcl_S
c7b0: 74 61 74 69 63 50 61 63 6b 61 67 65 28 4e 55 4c  taticPackage(NUL
c7c0: 4c 2c 20 22 61 70 70 66 73 64 22 2c 20 41 70 70  L, "appfsd", App
c7d0: 66 73 64 5f 49 6e 69 74 2c 20 4e 55 4c 4c 29 3b  fsd_Init, NULL);
c7e0: 0a 0a 09 2f 2a 0a 09 20 2a 20 43 72 65 61 74 65  .../*.. * Create
c7f0: 20 61 20 74 68 72 65 61 64 2d 73 70 65 63 69 66   a thread-specif
c800: 69 63 2d 64 61 74 61 20 28 54 53 44 29 20 6b 65  ic-data (TSD) ke
c810: 79 20 66 6f 72 20 65 61 63 68 20 74 68 72 65 61  y for each threa
c820: 64 20 74 6f 20 72 65 66 65 72 0a 09 20 2a 20 74  d to refer.. * t
c830: 6f 20 69 74 73 20 6f 77 6e 20 54 63 6c 20 69 6e  o its own Tcl in
c840: 74 65 72 70 72 65 74 65 72 2e 20 20 54 63 6c 20  terpreter.  Tcl 
c850: 69 6e 74 65 72 70 72 65 74 65 72 73 20 6d 75 73  interpreters mus
c860: 74 20 62 65 20 75 6e 69 71 75 65 20 70 65 72 0a  t be unique per.
c870: 09 20 2a 20 74 68 72 65 61 64 20 61 6e 64 20 6e  . * thread and n
c880: 65 77 20 74 68 72 65 61 64 73 20 61 72 65 20 64  ew threads are d
c890: 79 6e 61 6d 69 63 61 6c 6c 79 20 63 72 65 61 74  ynamically creat
c8a0: 65 64 20 62 79 20 46 55 53 45 2e 0a 09 20 2a 2f  ed by FUSE... */
c8b0: 0a 09 70 74 68 72 65 61 64 5f 72 65 74 20 3d 20  ..pthread_ret = 
c8c0: 70 74 68 72 65 61 64 5f 6b 65 79 5f 63 72 65 61  pthread_key_crea
c8d0: 74 65 28 26 69 6e 74 65 72 70 4b 65 79 2c 20 61  te(&interpKey, a
c8e0: 70 70 66 73 5f 74 65 72 6d 69 6e 61 74 65 5f 69  ppfs_terminate_i
c8f0: 6e 74 65 72 70 5f 61 6e 64 5f 74 68 72 65 61 64  nterp_and_thread
c900: 29 3b 0a 09 69 66 20 28 70 74 68 72 65 61 64 5f  );..if (pthread_
c910: 72 65 74 20 21 3d 20 30 29 20 7b 0a 09 09 66 70  ret != 0) {...fp
c920: 72 69 6e 74 66 28 73 74 64 65 72 72 2c 20 22 55  rintf(stderr, "U
c930: 6e 61 62 6c 65 20 74 6f 20 63 72 65 61 74 65 20  nable to create 
c940: 54 53 44 20 6b 65 79 20 66 6f 72 20 54 63 6c 2e  TSD key for Tcl.
c950: 20 20 41 62 6f 72 74 69 6e 67 2e 5c 6e 22 29 3b    Aborting.\n");
c960: 0a 0a 09 09 72 65 74 75 72 6e 28 31 29 3b 0a 09  ....return(1);..
c970: 7d 0a 0a 09 2f 2a 0a 09 20 2a 20 4d 61 6e 75 61  }.../*.. * Manua
c980: 6c 6c 79 20 73 70 65 63 69 66 79 20 63 61 63 68  lly specify cach
c990: 65 20 64 69 72 65 63 74 6f 72 79 2c 20 77 69 74  e directory, wit
c9a0: 68 6f 75 74 20 46 55 53 45 20 63 61 6c 6c 62 61  hout FUSE callba
c9b0: 63 6b 0a 09 20 2a 20 54 68 69 73 20 6f 70 74 69  ck.. * This opti
c9c0: 6f 6e 20 6f 6e 6c 79 20 77 6f 72 6b 73 20 77 68  on only works wh
c9d0: 65 6e 20 6e 6f 74 20 75 73 69 6e 67 20 46 55 53  en not using FUS
c9e0: 45 2c 20 73 69 6e 63 65 20 77 65 0a 09 20 2a 20  E, since we.. * 
c9f0: 64 6f 20 6e 6f 74 20 70 72 6f 63 65 73 73 20 69  do not process i
ca00: 74 20 77 69 74 68 20 46 55 53 45 73 20 6f 70 74  t with FUSEs opt
ca10: 69 6f 6e 20 70 72 6f 63 65 73 73 69 6e 67 2e 0a  ion processing..
ca20: 09 20 2a 2f 0a 09 69 66 20 28 61 72 67 63 20 3e  . */..if (argc >
ca30: 3d 20 32 29 20 7b 0a 09 09 69 66 20 28 73 74 72  = 2) {...if (str
ca40: 63 6d 70 28 61 72 67 76 5b 30 5d 2c 20 22 2d 2d  cmp(argv[0], "--
ca50: 63 61 63 68 65 64 69 72 22 29 20 3d 3d 20 30 29  cachedir") == 0)
ca60: 20 7b 0a 09 09 09 61 70 70 66 73 5f 63 61 63 68   {....appfs_cach
ca70: 65 64 69 72 20 3d 20 73 74 72 64 75 70 28 61 72  edir = strdup(ar
ca80: 67 76 5b 31 5d 29 3b 0a 0a 09 09 09 61 72 67 63  gv[1]);.....argc
ca90: 20 2d 3d 20 32 3b 0a 09 09 09 61 72 67 76 20 2b   -= 2;....argv +
caa0: 3d 20 32 3b 0a 09 09 7d 0a 09 7d 0a 0a 09 2f 2a  = 2;...}..}.../*
cab0: 0a 09 20 2a 20 53 51 4c 69 74 65 33 20 6d 6f 64  .. * SQLite3 mod
cac0: 65 2c 20 66 6f 72 20 72 75 6e 6e 69 6e 67 20 72  e, for running r
cad0: 61 77 20 53 51 4c 20 61 67 61 69 6e 73 74 20 74  aw SQL against t
cae0: 68 65 20 63 61 63 68 65 20 64 61 74 61 62 61 73  he cache databas
caf0: 65 0a 09 20 2a 2f 0a 09 69 66 20 28 61 72 67 63  e.. */..if (argc
cb00: 20 3d 3d 20 32 20 26 26 20 73 74 72 63 6d 70 28   == 2 && strcmp(
cb10: 61 72 67 76 5b 30 5d 2c 20 22 2d 2d 73 71 6c 69  argv[0], "--sqli
cb20: 74 65 33 22 29 20 3d 3d 20 30 29 20 7b 0a 09 09  te3") == 0) {...
cb30: 72 65 74 75 72 6e 28 61 70 70 66 73 5f 73 71 6c  return(appfs_sql
cb40: 69 74 65 33 28 61 72 67 76 5b 31 5d 29 29 3b 0a  ite3(argv[1]));.
cb50: 09 7d 0a 0a 09 2f 2a 0a 09 20 2a 20 54 63 6c 20  .}.../*.. * Tcl 
cb60: 6d 6f 64 65 2c 20 66 6f 72 20 72 75 6e 6e 69 6e  mode, for runnin
cb70: 67 20 72 61 77 20 54 63 6c 20 69 6e 20 74 68 65  g raw Tcl in the
cb80: 20 73 61 6d 65 20 65 6e 76 69 72 6f 6e 6d 65 6e   same environmen
cb90: 74 20 41 70 70 46 53 64 20 77 6f 75 6c 64 0a 09  t AppFSd would..
cba0: 20 2a 20 72 75 6e 20 63 6f 64 65 2e 0a 09 20 2a   * run code... *
cbb0: 2f 0a 09 69 66 20 28 61 72 67 63 20 3d 3d 20 32  /..if (argc == 2
cbc0: 20 26 26 20 73 74 72 63 6d 70 28 61 72 67 76 5b   && strcmp(argv[
cbd0: 30 5d 2c 20 22 2d 2d 74 63 6c 22 29 20 3d 3d 20  0], "--tcl") == 
cbe0: 30 29 20 7b 0a 09 09 72 65 74 75 72 6e 28 61 70  0) {...return(ap
cbf0: 70 66 73 5f 74 63 6c 28 61 72 67 76 5b 31 5d 29  pfs_tcl(argv[1])
cc00: 29 3b 0a 09 7d 0a 0a 09 2f 2a 0a 09 20 2a 20 52  );..}.../*.. * R
cc10: 65 67 69 73 74 65 72 20 61 20 73 69 67 6e 61 6c  egister a signal
cc20: 20 68 61 6e 64 6c 65 72 20 66 6f 72 20 68 6f 74   handler for hot
cc30: 2d 72 65 73 74 61 72 74 20 72 65 71 75 65 73 74  -restart request
cc40: 73 0a 09 20 2a 2f 0a 09 73 69 67 6e 61 6c 5f 72  s.. */..signal_r
cc50: 65 74 20 3d 20 73 69 67 6e 61 6c 28 53 49 47 48  et = signal(SIGH
cc60: 55 50 2c 20 61 70 70 66 73 5f 73 69 67 6e 61 6c  UP, appfs_signal
cc70: 5f 68 61 6e 64 6c 65 72 29 3b 0a 09 69 66 20 28  _handler);..if (
cc80: 73 69 67 6e 61 6c 5f 72 65 74 20 3d 3d 20 53 49  signal_ret == SI
cc90: 47 5f 45 52 52 29 20 7b 0a 09 09 66 70 72 69 6e  G_ERR) {...fprin
cca0: 74 66 28 73 74 64 65 72 72 2c 20 22 55 6e 61 62  tf(stderr, "Unab
ccb0: 6c 65 20 74 6f 20 69 6e 73 74 61 6c 6c 20 73 69  le to install si
ccc0: 67 6e 61 6c 20 68 61 6e 64 6c 65 72 20 66 6f 72  gnal handler for
ccd0: 20 68 6f 74 2d 72 65 73 74 61 72 74 5c 6e 22 29   hot-restart\n")
cce0: 3b 0a 09 09 66 70 72 69 6e 74 66 28 73 74 64 65  ;...fprintf(stde
ccf0: 72 72 2c 20 22 48 6f 74 2d 72 65 73 74 61 72 74  rr, "Hot-restart
cd00: 20 77 69 6c 6c 20 6e 6f 74 20 62 65 20 61 76 61   will not be ava
cd10: 69 6c 61 62 6c 65 2e 5c 6e 22 29 3b 0a 09 7d 0a  ilable.\n");..}.
cd20: 0a 09 2f 2a 0a 09 20 2a 20 50 61 72 73 65 20 63  ../*.. * Parse c
cd30: 6f 6d 6d 61 6e 64 20 6c 69 6e 65 20 61 72 67 75  ommand line argu
cd40: 6d 65 6e 74 73 0a 09 20 2a 2f 0a 09 2f 2a 2a 0a  ments.. */../**.
cd50: 09 20 2a 2a 20 52 65 73 74 6f 72 65 20 61 72 67  . ** Restore arg
cd60: 63 2f 61 72 67 76 20 74 6f 20 6f 72 69 67 69 6e  c/argv to origin
cd70: 61 6c 20 76 61 6c 75 65 73 2c 20 72 65 70 6c 61  al values, repla
cd80: 63 69 6e 67 20 61 72 67 76 5b 30 5d 20 69 6e 20  cing argv[0] in 
cd90: 63 61 73 65 0a 09 20 2a 2a 20 69 74 20 77 61 73  case.. ** it was
cda0: 20 6d 6f 69 66 69 65 64 20 62 79 20 2d 2d 63 61   moified by --ca
cdb0: 63 68 65 64 69 72 20 6f 70 74 69 6f 6e 2e 0a 09  chedir option...
cdc0: 20 2a 2a 2f 0a 09 61 72 67 63 2b 2b 3b 0a 09 61   **/..argc++;..a
cdd0: 72 67 76 2d 2d 3b 0a 09 61 72 67 76 5b 30 5d 20  rgv--;..argv[0] 
cde0: 3d 20 61 72 67 76 30 3b 0a 0a 09 2f 2a 2a 0a 09  = argv0;.../**..
cdf0: 20 2a 2a 20 50 65 72 66 6f 72 6d 20 74 68 65 20   ** Perform the 
ce00: 61 72 67 75 6d 65 6e 74 20 70 61 72 73 69 6e 67  argument parsing
ce10: 0a 09 20 2a 2a 2f 0a 09 61 6f 70 5f 72 65 74 20  .. **/..aop_ret 
ce20: 3d 20 61 70 70 66 73 5f 6f 70 74 5f 70 61 72 73  = appfs_opt_pars
ce30: 65 28 61 72 67 63 2c 20 61 72 67 76 2c 20 26 61  e(argc, argv, &a
ce40: 72 67 73 29 3b 0a 09 69 66 20 28 61 6f 70 5f 72  rgs);..if (aop_r
ce50: 65 74 20 21 3d 20 30 29 20 7b 0a 09 09 69 66 20  et != 0) {...if 
ce60: 28 61 6f 70 5f 72 65 74 20 3c 20 30 29 20 7b 0a  (aop_ret < 0) {.
ce70: 09 09 09 72 65 74 75 72 6e 28 30 29 3b 0a 09 09  ...return(0);...
ce80: 7d 0a 0a 09 09 72 65 74 75 72 6e 28 61 6f 70 5f  }....return(aop_
ce90: 72 65 74 29 3b 0a 09 7d 0a 0a 09 2f 2a 0a 09 20  ret);..}.../*.. 
cea0: 2a 20 43 72 65 61 74 65 20 61 20 54 63 6c 20 69  * Create a Tcl i
ceb0: 6e 74 65 72 70 72 65 74 65 72 20 6a 75 73 74 20  nterpreter just 
cec0: 74 6f 20 76 65 72 69 66 79 20 74 68 61 74 20 74  to verify that t
ced0: 68 69 6e 67 73 20 61 72 65 20 69 6e 20 77 6f 72  hings are in wor
cee0: 6b 69 6e 67 20 0a 09 20 2a 20 6f 72 64 65 72 20  king .. * order 
cef0: 62 65 66 6f 72 65 20 77 65 20 62 65 63 6f 6d 65  before we become
cf00: 20 61 20 64 61 65 6d 6f 6e 2e 0a 09 20 2a 2f 0a   a daemon... */.
cf10: 09 74 65 73 74 5f 69 6e 74 65 72 70 20 3d 20 61  .test_interp = a
cf20: 70 70 66 73 5f 63 72 65 61 74 65 5f 54 63 6c 49  ppfs_create_TclI
cf30: 6e 74 65 72 70 28 26 74 65 73 74 5f 69 6e 74 65  nterp(&test_inte
cf40: 72 70 5f 65 72 72 6f 72 29 3b 0a 09 69 66 20 28  rp_error);..if (
cf50: 74 65 73 74 5f 69 6e 74 65 72 70 20 3d 3d 20 4e  test_interp == N
cf60: 55 4c 4c 29 20 7b 0a 09 09 69 66 20 28 74 65 73  ULL) {...if (tes
cf70: 74 5f 69 6e 74 65 72 70 5f 65 72 72 6f 72 20 3d  t_interp_error =
cf80: 3d 20 4e 55 4c 4c 29 20 7b 0a 09 09 09 74 65 73  = NULL) {....tes
cf90: 74 5f 69 6e 74 65 72 70 5f 65 72 72 6f 72 20 3d  t_interp_error =
cfa0: 20 22 55 6e 6b 6e 6f 77 6e 20 65 72 72 6f 72 22   "Unknown error"
cfb0: 3b 0a 09 09 7d 0a 0a 09 09 66 70 72 69 6e 74 66  ;...}....fprintf
cfc0: 28 73 74 64 65 72 72 2c 20 22 55 6e 61 62 6c 65  (stderr, "Unable
cfd0: 20 74 6f 20 69 6e 69 74 69 61 6c 69 7a 65 20 54   to initialize T
cfe0: 63 6c 20 69 6e 74 65 72 70 72 65 74 65 72 20 66  cl interpreter f
cff0: 6f 72 20 41 70 70 46 53 64 3a 5c 6e 22 29 3b 0a  or AppFSd:\n");.
d000: 09 09 66 70 72 69 6e 74 66 28 73 74 64 65 72 72  ..fprintf(stderr
d010: 2c 20 22 25 73 5c 6e 22 2c 20 74 65 73 74 5f 69  , "%s\n", test_i
d020: 6e 74 65 72 70 5f 65 72 72 6f 72 29 3b 0a 0a 09  nterp_error);...
d030: 09 72 65 74 75 72 6e 28 31 29 3b 0a 09 7d 0a 0a  .return(1);..}..
d040: 09 54 63 6c 5f 44 65 6c 65 74 65 49 6e 74 65 72  .Tcl_DeleteInter
d050: 70 28 74 65 73 74 5f 69 6e 74 65 72 70 29 3b 0a  p(test_interp);.
d060: 0a 09 69 66 20 28 61 70 70 66 73 5f 74 68 72 65  ..if (appfs_thre
d070: 61 64 65 64 5f 74 63 6c 29 20 7b 0a 09 09 54 63  aded_tcl) {...Tc
d080: 6c 5f 46 69 6e 61 6c 69 7a 65 4e 6f 74 69 66 69  l_FinalizeNotifi
d090: 65 72 28 4e 55 4c 4c 29 3b 0a 09 7d 0a 0a 09 2f  er(NULL);..}.../
d0a0: 2a 0a 09 20 2a 20 49 6e 63 72 65 61 73 65 20 72  *.. * Increase r
d0b0: 65 73 6f 75 72 63 65 20 6c 69 6d 69 74 73 20 66  esource limits f
d0c0: 6f 72 20 6e 75 6d 62 65 72 20 6f 66 20 6f 70 65  or number of ope
d0d0: 6e 20 66 69 6c 65 73 0a 09 20 2a 20 74 6f 20 74  n files.. * to t
d0e0: 68 65 20 6d 61 78 69 6d 75 6d 20 76 61 6c 75 65  he maximum value
d0f0: 73 2c 20 73 69 6e 63 65 20 77 65 20 6d 61 79 20  s, since we may 
d100: 62 65 20 61 73 6b 65 64 20 74 6f 0a 09 20 2a 20  be asked to.. * 
d110: 68 6f 6c 64 20 6f 70 65 6e 20 6d 61 6e 79 20 66  hold open many f
d120: 69 6c 65 73 20 6f 6e 20 62 65 68 61 6c 66 20 6f  iles on behalf o
d130: 66 20 6d 61 6e 79 20 6f 74 68 65 72 20 70 72 6f  f many other pro
d140: 63 65 73 73 65 73 0a 09 20 2a 2f 0a 09 6e 75 6d  cesses.. */..num
d150: 62 65 72 5f 6f 70 65 6e 5f 66 69 6c 65 73 2e 72  ber_open_files.r
d160: 6c 69 6d 5f 63 75 72 20 3d 20 6e 75 6d 62 65 72  lim_cur = number
d170: 5f 6f 70 65 6e 5f 66 69 6c 65 73 2e 72 6c 69 6d  _open_files.rlim
d180: 5f 6d 61 78 20 3d 20 52 4c 49 4d 5f 49 4e 46 49  _max = RLIM_INFI
d190: 4e 49 54 59 3b 0a 0a 09 72 6c 69 6d 69 74 5f 72  NITY;...rlimit_r
d1a0: 65 74 20 3d 20 73 65 74 72 6c 69 6d 69 74 28 52  et = setrlimit(R
d1b0: 4c 49 4d 49 54 5f 4e 4f 46 49 4c 45 2c 20 26 6e  LIMIT_NOFILE, &n
d1c0: 75 6d 62 65 72 5f 6f 70 65 6e 5f 66 69 6c 65 73  umber_open_files
d1d0: 29 3b 0a 0a 09 69 66 20 28 72 6c 69 6d 69 74 5f  );...if (rlimit_
d1e0: 72 65 74 20 21 3d 20 30 29 20 7b 0a 09 09 72 6c  ret != 0) {...rl
d1f0: 69 6d 69 74 5f 72 65 74 20 3d 20 67 65 74 72 6c  imit_ret = getrl
d200: 69 6d 69 74 28 52 4c 49 4d 49 54 5f 4e 4f 46 49  imit(RLIMIT_NOFI
d210: 4c 45 2c 20 26 6e 75 6d 62 65 72 5f 6f 70 65 6e  LE, &number_open
d220: 5f 66 69 6c 65 73 29 3b 0a 09 09 69 66 20 28 72  _files);...if (r
d230: 6c 69 6d 69 74 5f 72 65 74 20 3d 3d 20 30 29 20  limit_ret == 0) 
d240: 7b 0a 09 09 09 6e 75 6d 62 65 72 5f 6f 70 65 6e  {....number_open
d250: 5f 66 69 6c 65 73 5f 6d 61 78 20 3d 20 6e 75 6d  _files_max = num
d260: 62 65 72 5f 6f 70 65 6e 5f 66 69 6c 65 73 2e 72  ber_open_files.r
d270: 6c 69 6d 5f 6d 61 78 3b 0a 0a 09 09 09 69 66 20  lim_max;.....if 
d280: 28 6e 75 6d 62 65 72 5f 6f 70 65 6e 5f 66 69 6c  (number_open_fil
d290: 65 73 5f 6d 61 78 20 3c 20 28 31 30 32 34 20 2a  es_max < (1024 *
d2a0: 20 31 30 32 34 29 29 20 7b 0a 09 09 09 09 6e 75   1024)) {.....nu
d2b0: 6d 62 65 72 5f 6f 70 65 6e 5f 66 69 6c 65 73 2e  mber_open_files.
d2c0: 72 6c 69 6d 5f 63 75 72 20 3d 20 6e 75 6d 62 65  rlim_cur = numbe
d2d0: 72 5f 6f 70 65 6e 5f 66 69 6c 65 73 2e 72 6c 69  r_open_files.rli
d2e0: 6d 5f 6d 61 78 20 3d 20 31 30 32 34 20 2a 20 31  m_max = 1024 * 1
d2f0: 30 32 34 3b 0a 0a 09 09 09 09 72 6c 69 6d 69 74  024;......rlimit
d300: 5f 72 65 74 20 3d 20 73 65 74 72 6c 69 6d 69 74  _ret = setrlimit
d310: 28 52 4c 49 4d 49 54 5f 4e 4f 46 49 4c 45 2c 20  (RLIMIT_NOFILE, 
d320: 26 6e 75 6d 62 65 72 5f 6f 70 65 6e 5f 66 69 6c  &number_open_fil
d330: 65 73 29 3b 0a 09 09 09 7d 20 65 6c 73 65 20 7b  es);....} else {
d340: 0a 09 09 09 09 6e 75 6d 62 65 72 5f 6f 70 65 6e  .....number_open
d350: 5f 66 69 6c 65 73 2e 72 6c 69 6d 5f 63 75 72 20  _files.rlim_cur 
d360: 3d 20 6e 75 6d 62 65 72 5f 6f 70 65 6e 5f 66 69  = number_open_fi
d370: 6c 65 73 2e 72 6c 69 6d 5f 6d 61 78 3b 0a 09 09  les.rlim_max;...
d380: 09 7d 0a 0a 09 09 09 72 6c 69 6d 69 74 5f 72 65  .}.....rlimit_re
d390: 74 20 3d 20 73 65 74 72 6c 69 6d 69 74 28 52 4c  t = setrlimit(RL
d3a0: 49 4d 49 54 5f 4e 4f 46 49 4c 45 2c 20 26 6e 75  IMIT_NOFILE, &nu
d3b0: 6d 62 65 72 5f 6f 70 65 6e 5f 66 69 6c 65 73 29  mber_open_files)
d3c0: 3b 0a 0a 09 09 09 69 66 20 28 72 6c 69 6d 69 74  ;.....if (rlimit
d3d0: 5f 72 65 74 20 21 3d 20 30 20 26 26 20 6e 75 6d  _ret != 0 && num
d3e0: 62 65 72 5f 6f 70 65 6e 5f 66 69 6c 65 73 2e 72  ber_open_files.r
d3f0: 6c 69 6d 5f 63 75 72 20 21 3d 20 6e 75 6d 62 65  lim_cur != numbe
d400: 72 5f 6f 70 65 6e 5f 66 69 6c 65 73 5f 6d 61 78  r_open_files_max
d410: 29 20 7b 0a 09 09 09 09 6e 75 6d 62 65 72 5f 6f  ) {.....number_o
d420: 70 65 6e 5f 66 69 6c 65 73 2e 72 6c 69 6d 5f 63  pen_files.rlim_c
d430: 75 72 20 3d 20 6e 75 6d 62 65 72 5f 6f 70 65 6e  ur = number_open
d440: 5f 66 69 6c 65 73 2e 72 6c 69 6d 5f 6d 61 78 20  _files.rlim_max 
d450: 3d 20 6e 75 6d 62 65 72 5f 6f 70 65 6e 5f 66 69  = number_open_fi
d460: 6c 65 73 5f 6d 61 78 3b 0a 0a 09 09 09 09 73 65  les_max;......se
d470: 74 72 6c 69 6d 69 74 28 52 4c 49 4d 49 54 5f 4e  trlimit(RLIMIT_N
d480: 4f 46 49 4c 45 2c 20 26 6e 75 6d 62 65 72 5f 6f  OFILE, &number_o
d490: 70 65 6e 5f 66 69 6c 65 73 29 3b 0a 09 09 09 7d  pen_files);....}
d4a0: 0a 09 09 7d 0a 09 7d 0a 0a 0a 09 2f 2a 0a 09 20  ...}..}..../*.. 
d4b0: 2a 20 45 6e 74 65 72 20 74 68 65 20 46 55 53 45  * Enter the FUSE
d4c0: 20 6d 61 69 6e 20 6c 6f 6f 70 20 2d 2d 20 74 68   main loop -- th
d4d0: 69 73 20 77 69 6c 6c 20 70 72 6f 63 65 73 73 20  is will process 
d4e0: 61 6e 79 20 61 72 67 75 6d 65 6e 74 73 0a 09 20  any arguments.. 
d4f0: 2a 20 61 6e 64 20 73 74 61 72 74 20 73 65 72 76  * and start serv
d500: 69 63 69 6e 67 20 72 65 71 75 65 73 74 73 2e 0a  icing requests..
d510: 09 20 2a 2f 0a 09 61 70 70 66 73 5f 66 75 73 65  . */..appfs_fuse
d520: 5f 73 74 61 72 74 65 64 20 3d 20 31 3b 0a 09 72  _started = 1;..r
d530: 65 74 75 72 6e 28 66 75 73 65 5f 6d 61 69 6e 28  eturn(fuse_main(
d540: 61 72 67 73 2e 61 72 67 63 2c 20 61 72 67 73 2e  args.argc, args.
d550: 61 72 67 76 2c 20 26 61 70 70 66 73 5f 6f 70 65  argv, &appfs_ope
d560: 72 61 74 69 6f 6e 73 2c 20 4e 55 4c 4c 29 29 3b  rations, NULL));
d570: 0a 7d 0a                                         .}.