xref: /titanic_50/usr/src/lib/libast/common/misc/fs3d.c (revision 174bc6499d233e329ecd3d98a880a7b07df16bfa)
1 /***********************************************************************
2 *                                                                      *
3 *               This software is part of the ast package               *
4 *          Copyright (c) 1985-2010 AT&T Intellectual Property          *
5 *                      and is licensed under the                       *
6 *                  Common Public License, Version 1.0                  *
7 *                    by AT&T Intellectual Property                     *
8 *                                                                      *
9 *                A copy of the License is available at                 *
10 *            http://www.opensource.org/licenses/cpl1.0.txt             *
11 *         (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9)         *
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
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
113 fs3d_mount(const char* source, char* target, int flags, void* data)
114 {
115 	return mount(source, target, flags, data);
116 }
117