1 /***********************************************************************
2 * *
3 * This software is part of the ast package *
4 * Copyright (c) 1985-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 <gsf@research.att.com> *
18 * David Korn <dgk@research.att.com> *
19 * Phong Vo <kpv@research.att.com> *
20 * *
21 ***********************************************************************/
22 #pragma prototyped
23 /*
24 * Glenn Fowler
25 * AT&T Bell Laboratories
26 *
27 * 3d fs operations
28 * only active for non-shared 3d library
29 */
30
31 #define mount ______mount
32
33 #include <ast.h>
34
35 #undef mount
36
37 #include <fs3d.h>
38
39 int
fs3d(register int op)40 fs3d(register int op)
41 {
42 register int cur;
43 register char* v;
44 char val[sizeof(FS3D_off) + 8];
45
46 static int fsview;
47 static char on[] = FS3D_on;
48 static char off[] = FS3D_off;
49
50 if (fsview < 0)
51 return 0;
52
53 /*
54 * get the current setting
55 */
56
57 if (!fsview && (!getenv("LD_PRELOAD") || mount("", "", 0, NiL)))
58 goto nope;
59 if (FS3D_op(op) == FS3D_OP_INIT && mount(FS3D_init, NiL, FS3D_VIEW, NiL))
60 goto nope;
61 if (mount(on, val, FS3D_VIEW|FS3D_GET|FS3D_SIZE(sizeof(val)), NiL))
62 goto nope;
63 if (v = strchr(val, ' '))
64 v++;
65 else
66 v = val;
67 if (!strcmp(v, on))
68 cur = FS3D_ON;
69 else if (!strncmp(v, off, sizeof(off) - 1) && v[sizeof(off)] == '=')
70 cur = FS3D_LIMIT((int)strtol(v + sizeof(off) + 1, NiL, 0));
71 else
72 cur = FS3D_OFF;
73 if (cur != op)
74 {
75 switch (FS3D_op(op))
76 {
77 case FS3D_OP_OFF:
78 v = off;
79 break;
80 case FS3D_OP_ON:
81 v = on;
82 break;
83 case FS3D_OP_LIMIT:
84 sfsprintf(val, sizeof(val), "%s=%d", off, FS3D_arg(op));
85 v = val;
86 break;
87 default:
88 v = 0;
89 break;
90 }
91 if (v && mount(v, NiL, FS3D_VIEW, NiL))
92 goto nope;
93 }
94 fsview = 1;
95 return cur;
96 nope:
97 fsview = -1;
98 return 0;
99 }
100
101 /*
102 * user code that includes <fs3d.h> will have mount() mapped to fs3d_mount()
103 * this restricts the various "standard" mount prototype conflicts to this spot
104 * this means that code that includes <fs3d.h> cannot access the real mount
105 * (at least without some additional macro hackery
106 */
107
108 #undef mount
109
110 extern int mount(const char*, char*, int, void*);
111
112 int
fs3d_mount(const char * source,char * target,int flags,void * data)113 fs3d_mount(const char* source, char* target, int flags, void* data)
114 {
115 return mount(source, target, flags, data);
116 }
117