xref: /titanic_51/usr/src/lib/libast/common/misc/fs3d.c (revision 95c2d3023b88b9097d9822eb47ace5466e6d1cf4)
1 /***********************************************************************
2 *                                                                      *
3 *               This software is part of the ast package               *
4 *          Copyright (c) 1985-2008 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 #include <ast.h>
32 #include <fs3d.h>
33 
34 int
35 fs3d(register int op)
36 {
37 	register int	cur;
38 	register char*	v;
39 	char		val[sizeof(FS3D_off) + 8];
40 
41 	static int	fsview;
42 	static char	on[] = FS3D_on;
43 	static char	off[] = FS3D_off;
44 
45 	if (fsview < 0)
46 		return 0;
47 
48 	/*
49 	 * get the current setting
50 	 */
51 
52 	if (!fsview && (!getenv("LD_PRELOAD") || mount("", "", 0, NiL)))
53 		goto nope;
54 	if (FS3D_op(op) == FS3D_OP_INIT && mount(FS3D_init, NiL, FS3D_VIEW, NiL))
55 		goto nope;
56 	if (mount(on, val, FS3D_VIEW|FS3D_GET|FS3D_SIZE(sizeof(val)), NiL))
57 		goto nope;
58 	if (v = strchr(val, ' '))
59 		v++;
60 	else
61 		v = val;
62 	if (!strcmp(v, on))
63 		cur = FS3D_ON;
64 	else if (!strncmp(v, off, sizeof(off) - 1) && v[sizeof(off)] == '=')
65 		cur = FS3D_LIMIT((int)strtol(v + sizeof(off) + 1, NiL, 0));
66 	else
67 		cur = FS3D_OFF;
68 	if (cur != op)
69 	{
70 		switch (FS3D_op(op))
71 		{
72 		case FS3D_OP_OFF:
73 			v = off;
74 			break;
75 		case FS3D_OP_ON:
76 			v = on;
77 			break;
78 		case FS3D_OP_LIMIT:
79 			sfsprintf(val, sizeof(val), "%s=%d", off, FS3D_arg(op));
80 			v = val;
81 			break;
82 		default:
83 			v = 0;
84 			break;
85 		}
86 		if (v && mount(v, NiL, FS3D_VIEW, NiL))
87 			goto nope;
88 	}
89 	fsview = 1;
90 	return cur;
91  nope:
92 	fsview = -1;
93 	return 0;
94 }
95