Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
att
GitHub Repository: att/ast
Path: blob/master/src/cmd/3d/3d.h
1808 views
1
/***********************************************************************
2
* *
3
* This software is part of the ast package *
4
* Copyright (c) 1989-2011 AT&T Intellectual Property *
5
* and is licensed under the *
6
* Eclipse Public License, Version 1.0 *
7
* by AT&T Intellectual Property *
8
* *
9
* A copy of the License is available at *
10
* http://www.eclipse.org/org/documents/epl-v10.html *
11
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
12
* *
13
* Information and Software Systems Research *
14
* AT&T Research *
15
* Florham Park NJ *
16
* *
17
* Glenn Fowler <[email protected]> *
18
* David Korn <[email protected]> *
19
* Eduardo Krell <[email protected]> *
20
* *
21
***********************************************************************/
22
#pragma prototyped
23
24
/*
25
* Glenn Fowler
26
* David Korn
27
* Eduardo Krell
28
*
29
* AT&T Research
30
*
31
* 3d file system implementation interface
32
*/
33
34
#ifndef _3D_H
35
#define _3D_H
36
37
#undef _BLD_DEBUG
38
39
#define _def_map_ast 1
40
#define _std_strtol 1
41
42
#if defined(__STDPP__directive) && defined(__STDPP__hide)
43
__STDPP__directive pragma pp:hide fchown ftruncate mount readlink sbrk strmode truncate utimes __utimes
44
#else
45
#undef fchown
46
#define fchown ______fchown
47
#undef ftruncate
48
#define ftruncate ______ftruncate
49
#undef mount
50
#define mount ______mount
51
#undef readlink
52
#define readlink ______readlink
53
#undef sbrk
54
#define sbrk ______sbrk
55
#undef strmode
56
#define strmode ______strmode
57
#undef truncate
58
#define truncate ______truncate
59
#undef utimes
60
#define utimes ______utimes
61
#undef __utimes
62
#define __utimes ________utimes
63
#endif
64
65
#if defined(__STDPP__directive) && defined(__STDPP__note)
66
__STDPP__directive pragma pp:note off64_t
67
#endif
68
69
#include <ast_std.h>
70
71
#if defined(__STDPP__directive) && defined(__STDPP__hide)
72
__STDPP__directive pragma pp:nohide strmode
73
#else
74
#undef strmode
75
#endif
76
77
#include "lib_3d.h"
78
79
#include <ls.h>
80
#include <sig.h>
81
#include <times.h>
82
#include <error.h>
83
#include <debug.h>
84
#include <hashkey.h>
85
#include <dlldefs.h>
86
87
#if _lib_strerror && defined(strerror)
88
#undef strerror
89
extern char* strerror();
90
#endif
91
92
#undef mount
93
#define mount ______mount
94
#include <fs3d.h>
95
#undef mount
96
97
#include "msg.h"
98
99
#if defined(__STDPP__directive) && defined(__STDPP__hide)
100
__STDPP__directive pragma pp:nohide fchown ftruncate mount readlink sbrk strmode truncate utimes __utimes
101
#else
102
#undef fchown
103
#undef ftruncate
104
#undef mount
105
#undef readlink
106
#undef sbrk
107
#undef strmode
108
#undef truncate
109
#undef utimes
110
#undef __utimes
111
#endif
112
113
#if FS && defined(MIX)
114
#define LICENSED 1
115
#endif
116
117
#if defined(__STDPP__directive) && defined(__STDPP__note)
118
#if !_typ_off64_t && !noticed(off64_t)
119
#undef off64_t
120
#if _typ_int64_t
121
#define off64_t int64_t
122
#else
123
#define off64_t long
124
#endif
125
#endif
126
#endif
127
128
struct stat64;
129
130
#undef fcntl
131
#undef open
132
#undef stat
133
#undef strtol
134
#undef strtoul
135
#undef strtoll
136
#undef strtoull
137
138
#define MSG_read3d (MSG_read|MSG_EXT(MSG_ARG_number,4))
139
#define MSG_write3d (MSG_write|MSG_EXT(MSG_ARG_number,4))
140
141
struct Fs;
142
143
typedef long (*Sysfunc_t)();
144
145
typedef int (*Fs_get_t)(struct Fs*, char*, const char*, int);
146
147
typedef int (*Fs_set_t)(struct Fs*, const char*, int, const char*, int);
148
149
#define _3D_LINK_MAX 999 /* for nice ls -l */
150
151
#ifndef _3D_LINK_MAX
152
#ifdef LINK_MAX
153
#define _3D_LINK_MAX LINK_MAX
154
#else
155
#define _3D_LINK_MAX 30000
156
#endif
157
#endif
158
159
#define ATTR_MAX 121
160
161
#include "FEATURE/peek"
162
#include "FEATURE/syscall"
163
#include "FEATURE/syslib"
164
165
typedef struct Fs
166
{
167
long flags;
168
short fd;
169
short retry;
170
short specialsize;
171
Fs_get_t get;
172
Fs_set_t set;
173
unsigned long key;
174
unsigned long ack;
175
unsigned long call;
176
unsigned long terse;
177
char special[10];
178
char attr[ATTR_MAX];
179
struct stat st;
180
char* match;
181
char* service;
182
short matchsize;
183
short servicesize;
184
} Fs_t;
185
186
#if FS
187
188
typedef struct Mount
189
{
190
long channel;
191
Fs_t* fs;
192
struct Mount* global;
193
char* logical;
194
char* physical;
195
char attr[ATTR_MAX];
196
short logicalsize;
197
short physicalsize;
198
short flags;
199
} Mount_t;
200
201
typedef struct
202
{
203
dev_t dev;
204
ino_t ino;
205
char path[1];
206
} Dir_t;
207
208
#endif
209
210
typedef struct
211
{
212
#if FS
213
Mount_t* mount;
214
Dir_t* dir;
215
#endif
216
short* reserved;
217
Msg_file_t id;
218
unsigned long open;
219
unsigned char flags;
220
unsigned char oflag;
221
} File_t;
222
223
#if VCS
224
#include "vcs_3d.h"
225
#endif
226
227
#define NOSYS nosys
228
229
#define TABLE_FD (OPEN_MAX>22?22:(OPEN_MAX-1)) /* 0 for env */
230
#define TABLE_MAX (1<<(TABBITS+7))/* max 3d table image size */
231
#define TABLE_PREFIX "vpath " /* for external consistency */
232
#define TABLE_VERSION 1 /* to verify TABLE_FD */
233
234
#define TABBITS 5 /* max vpath,vmap table index bits (<6) */
235
#define TABSIZE (1<<TABBITS) /* v* tab size */
236
#define VERMODE (S_IRWXU|S_IRWXG|S_IRWXO) /* ver dir mode */
237
#define INSTANCE TABSIZE /* under ver */
238
239
#define INTERCEPT_MAX 8 /* max # call intercept layers */
240
241
#define LICENSE_ALL '+' /* everything licensed */
242
#define LICENSE_NONE '-' /* nothing licensed */
243
#define LICENSE_SEP ',' /* feature separator */
244
245
/*
246
* File_t flags
247
*/
248
249
#define RESERVED_FD 10 /* reserved fds >= this */
250
251
#define FILE_CLOEXEC (1<<0)
252
#define FILE_ERROR (1<<1)
253
#define FILE_LOCK (1<<2)
254
#define FILE_OPEN (1<<3)
255
#define FILE_REGULAR (1<<4)
256
#define FILE_WRITE (1<<5)
257
#define FILE_VIRTUAL (1<<6)
258
259
#define FILE_LOCAL (1<<8)
260
261
/*
262
* map flags
263
*/
264
265
#define MAP_EXEC (1<<0) /* get info for exec */
266
#define MAP_INIT (1<<1) /* get info for init */
267
268
/*
269
* Mount_t flags
270
*/
271
272
#define MOUNT_PRIMARY (1<<0)
273
274
/*
275
* pathreal() flags
276
*/
277
278
#define P_ABSOLUTE (1<<0) /* no relative conversion */
279
#define P_DOTDOT (1<<1) /* add /.. to end of path */
280
#define P_LSTAT (1<<2) /* lstat() calling */
281
#define P_NOOPAQUE (1<<3) /* remove if opaque object */
282
#define P_NOSLASH (1<<4) /* remove trailing /'s */
283
#define P_PATHONLY (1<<5) /* just canonicalize path */
284
#define P_READLINK (1<<6) /* readlink() calling */
285
#define P_SAFE (1<<7) /* must be in safe tree */
286
#define P_SLASH (1<<8) /* add trailing / */
287
#define P_TOP (1<<9) /* copy to top level */
288
289
#ifndef ENOTEMPTY
290
#define ENOTEMPTY EEXIST
291
#endif
292
293
#define T_ALLOCATE (1<<15)
294
#define T_PREFIX (1<<14)
295
#define T_DELETE (T_ALLOCATE|T_PREFIX)
296
#define T_SIZE (T_PREFIX-1)
297
298
#define T_VALSIZE(p) (((p)->valsize&T_SIZE)?((p)->valsize&T_SIZE):strlen((p)->val))
299
300
#define T_MOUNT (T_SIZE-0)
301
302
#define FS_null 0
303
#define FS_option 1
304
#define FS_view 2
305
#define FS_pwd 3
306
#define FS_fs 4
307
#define FS_map 5
308
#define FS_safe 6
309
#define FS_fd 7
310
#define FS_intercept 8
311
312
#define FS_ACTIVE (1<<0)
313
#define FS_BOUND (1<<1)
314
#define FS_CLOSE (1<<2)
315
#define FS_ERROR (1<<3)
316
#define FS_FLUSH (1<<4)
317
#define FS_FORK (1<<5)
318
#define FS_FS (1<<6)
319
#define FS_GLOBAL (1<<7)
320
#define FS_INIT (1<<8)
321
#define FS_INTERACTIVE (1<<9)
322
#define FS_INTERNAL (1<<10)
323
#define FS_LICENSED (1<<11)
324
#define FS_LOAD (1<<12)
325
#define FS_LOCK (1<<13)
326
#define FS_MAGIC (1<<14)
327
#define FS_MONITOR (1L<<15)
328
#define FS_NAME (1L<<16)
329
#define FS_ON (1L<<17)
330
#define FS_OPEN (1L<<18)
331
#define FS_RAW (1L<<19)
332
#define FS_RECEIVE (1L<<20)
333
#define FS_REFERENCED (1L<<21)
334
#define FS_REGULAR (1L<<22)
335
#define FS_UNIQUE (1L<<23)
336
#define FS_VALIDATED (1L<<24)
337
#define FS_WRITE (1L<<25)
338
339
#define FS_LOCAL (1L<<26)
340
341
#define cancel(p) (*(p)>=RESERVED_FD?(state.file[*(p)].reserved=0,CLOSE(*(p)),*(p)=0):(-1))
342
#define fsfd(p) ((((p)->flags&(FS_ERROR|FS_ON|FS_OPEN))==(FS_ON|FS_OPEN))?(p)->fd:((((p)->flags&(FS_BOUND|FS_ERROR|FS_INIT|FS_ON))==(FS_BOUND|FS_ON))?fsinit(p,-1):-1))
343
#define fson(p) (((p)->flags&(FS_BOUND|FS_ERROR|FS_ON))==(FS_BOUND|FS_ON))
344
#define initialize() do { if (!state.pid) init(0,0,0); else if (state.control.note) control(); } while(0)
345
#define monitored() ((state.path.monitor&&!state.path.mount)?state.path.monitor:(Mount_t*)0)
346
#define mounted() ((state.path.monitor&&state.path.mount)?state.path.monitor:(Mount_t*)0)
347
#if _hdr_alloca
348
#define reclaim()
349
#else
350
#define reclaim() do { if (state.brk.beg) fix(); } while (0)
351
#endif
352
#define reserve(p) ((state.file[*(p)].flags|=FILE_LOCK,*(state.file[*(p)].reserved=(p)))<RESERVED_FD?close(*(p)):0)
353
354
#if FS
355
#define fgetmount(f) ((f)>=0&&(f)<=state.cache?state.file[f].mount:(Mount_t*)0)
356
#define fsmonitored(p) ((state.path.monitor=getmount((p),NiL))&&(state.path.monitor->fs->flags&(FS_ERROR|FS_MONITOR|FS_ON))==(FS_MONITOR|FS_ON))
357
#define fsmount(p) (((p)->channel&&(p)->fs->fd)?((p)->channel==-1?-1:(p)->fs->fd):fschannel(p))
358
#define fssys(p,c) (fson((p)->fs)&&(((p)->fs->call&MSG_MASK(c))||((p)->fs->flags&FS_GLOBAL)&&(fsmount(p),0)))
359
#endif
360
361
#define var_3d "__="
362
#define var_pwd "PWD="
363
#define var_shell "SHELL="
364
#define var_view "VPATH="
365
366
typedef struct
367
{
368
char* key;
369
char* val;
370
unsigned short keysize;
371
unsigned short valsize;
372
} Map_t;
373
374
typedef struct
375
{
376
unsigned int size;
377
Map_t table[TABSIZE];
378
} Table_t;
379
380
typedef struct
381
{
382
int level;
383
int open_level;
384
int synthesize;
385
int nlinks;
386
char* linkname;
387
int linksize;
388
#if FS
389
Mount_t* monitor;
390
#endif
391
char* mount;
392
Table_t* table;
393
#if VCS && defined(VCS_PATH_STATE)
394
VCS_PATH_STATE;
395
#endif
396
struct stat st;
397
char name[4 * PATH_MAX];
398
} Path_t;
399
400
typedef struct
401
{
402
Fs_t* fs;
403
char* prefix;
404
int prelen;
405
} Visit_t;
406
407
struct Intercept_s; typedef struct Intercept_s Intercept_t;
408
409
typedef long (*Intercept_f)(Intercept_t*, int, int, void*, void*, void*, void*, void*, void*);
410
411
struct Intercept_s
412
{
413
Intercept_f call;
414
unsigned long mask;
415
};
416
417
#if _no_exit_exit
418
typedef void (*Exitfunc_t)(int);
419
#endif
420
421
typedef struct
422
{
423
/* the first elements are explicitly initialized */
424
425
const char* id;
426
char* cmd;
427
char dot[2];
428
char null[1];
429
char one[2];
430
char* binsh;
431
char env3d[sizeof(var_3d)];
432
char envpwd[sizeof(var_pwd) + 4 * PATH_MAX];
433
char envshell[sizeof(var_shell) + PATH_MAX];
434
char envview[sizeof(var_view)];
435
Fs_t fs[TABSIZE];
436
char vdefault[8];
437
char opaque[8];
438
int limit;
439
440
/* the rest are implicitly initialized */
441
442
struct
443
{
444
short monitor;
445
short name;
446
} call;
447
struct
448
{
449
short fd;
450
unsigned long internal;
451
} channel;
452
struct
453
{
454
int note;
455
int pathsize;
456
char* path;
457
} control;
458
#if VCS && defined(VCS_STATE)
459
VCS_STATE;
460
#endif
461
int boundary;
462
struct
463
{
464
char* beg;
465
char* end;
466
} brk;
467
int cache;
468
char** env;
469
char* envpath;
470
void* freedirp;
471
int in_2d;
472
gid_t gid;
473
int kernel;
474
int level;
475
char license[64];
476
int open;
477
pid_t pid;
478
char* pwd;
479
int pwdsize;
480
char pwdbuf[4 * PATH_MAX + 1];
481
long ret;
482
Fs_t* safe;
483
char* shell;
484
uid_t uid;
485
struct
486
{
487
char* value;
488
char* invert;
489
char* next;
490
int valsize;
491
int invertsize;
492
} key;
493
struct
494
{
495
short fd;
496
short version;
497
int size;
498
char buf[TABLE_MAX];
499
} table;
500
unsigned long test;
501
struct
502
{
503
unsigned long call;
504
short count;
505
pid_t pid;
506
} trace;
507
Table_t vmap;
508
Table_t vmount;
509
Table_t vpath;
510
Table_t vsafe;
511
Table_t vintercept;
512
File_t file[OPEN_MAX];
513
Visit_t visit;
514
Path_t path;
515
int real;
516
struct
517
{
518
int size;
519
Intercept_t intercept[INTERCEPT_MAX];
520
} trap;
521
#if _no_exit_exit
522
Exitfunc_t libexit;
523
#endif
524
#if FS
525
Mount_t* global;
526
Mount_t mount[2 * TABSIZE];
527
#endif
528
} State_t;
529
530
#include "std_3d.h"
531
532
extern State_t state;
533
534
extern int bprintf(char**, char*, const char*, ...);
535
extern ssize_t bvprintf(char**, char*, const char*, va_list);
536
extern void calldump(char**, char*);
537
extern void callinit(void);
538
extern int checklink(const char*, struct stat*, int);
539
extern void control(void);
540
extern int fs3d_copy(int, int, struct stat*);
541
extern int fs3d_dup(int, int);
542
extern int fs3d_mkdir(const char*, mode_t);
543
extern int fs3d_open(const char*, int, mode_t);
544
extern void fsdrop(Fs_t*, int);
545
extern int fsinit(Fs_t*, int);
546
extern unsigned long getkey(const char*, const char*, int);
547
extern int init(int, const char*, int);
548
extern int instance(char*, char*, struct stat*, int);
549
extern int iterate(Table_t*, int(*)(Map_t*, char*, int), char*, int);
550
extern int keep(const char*, size_t, int);
551
extern int mapdump(Table_t*, char*, int);
552
extern int mapget(Map_t*, char*, int);
553
extern int mapinit(const char*, int);
554
extern int mapset(Table_t*, const char*, int, const char*, int);
555
extern int nosys(void);
556
extern char* pathcanon(char*, size_t, int);
557
extern char* pathcat(const char*, int, const char*, const char*, char*, size_t);
558
extern char* pathreal(const char*, int, struct stat*);
559
extern ssize_t peek(int, void*, size_t);
560
extern Map_t* search(Table_t*, const char*, int, const char*, int);
561
extern Sysfunc_t sysfunc(int);
562
extern int intercept(Intercept_f, unsigned long);
563
564
#if FS
565
extern int fileinit(int, struct stat*, Mount_t*, int);
566
extern int fscall(Mount_t*, long, int, ...);
567
extern int fschannel(Mount_t*);
568
extern char* fsreal(Mount_t*, long, const char*);
569
extern int getattr(const char*, char*);
570
extern Mount_t* getmount(const char*, const char**);
571
extern const char* setattr(char*, const char*, const char*);
572
#endif
573
574
/*
575
* non-standard standards
576
*/
577
578
#if ! _UWIN
579
extern void* sbrk(ssize_t);
580
#endif
581
582
/*
583
* backwards compatibility fixups
584
* these should go away in 94 (ha!)
585
*/
586
587
#if _int_st_spare1
588
#define NIVIEW(p,v) ((p)->st_spare1=(v))
589
#else
590
#if _ary_st_spare4
591
#define NIVIEW(p,v) ((p)->st_spare4[0]=(v))
592
#else
593
#if _ary_st_pad4
594
#define NIVIEW(p,v) ((p)->st_pad4[0]=(v))
595
#else
596
#define NIVIEW(p,v)
597
#endif
598
#endif
599
#endif
600
601
#undef IVIEW
602
603
#if _mem_st_rdev_stat
604
#define IVIEW(p,v) do{NIVIEW(p,(v)&(INSTANCE-1));if(!S_ISBLK((p)->st_mode)&&!S_ISCHR((p)->st_mode))(p)->st_rdev=(v)&(INSTANCE-1);}while(0)
605
#else
606
#define IVIEW(p,v) NIVIEW(p,(v)&(INSTANCE-1))
607
#endif
608
609
#endif
610
611