2 * Copyright (c) 1992, 1993, 1994
3 * The Regents of the University of California. All rights reserved.
5 * This code is derived from software donated to Berkeley by
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement:
18 * This product includes software developed by the University of
19 * California, Berkeley and its contributors.
20 * 4. Neither the name of the University nor the names of its contributors
21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission.
24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38 #include <sys/types.h>
39 #include <sys/mount.h>
40 #include <sys/sysctl.h>
43 #include <afs/sysctl.h>
45 #include <CoreFoundation/CFString.h>
46 #include <Foundation/Foundation.h>
54 typedef struct oidsetting {
58 struct oidsetting *children;
62 mygetvfsbyname(const char *fsname, struct vfsconf *vfcp, Setting *s, int myoid[])
68 myoid[1] = VFS_GENERIC;
69 myoid[2] = VFS_MAXTYPENUM;
71 if (sysctl(myoid, 3, &maxtypenum, &buflen, (void *)0, (size_t)0) < 0)
76 buflen = sizeof * vfcp;
77 for (cnt = 0; cnt < maxtypenum; cnt++)
80 if (sysctl(myoid, 4, vfcp, &buflen, (void *)0, (size_t)0) < 0)
82 if (errno != EOPNOTSUPP && errno != ENOENT && errno != ENOTSUP)
88 if (!strcmp(fsname, vfcp->vfc_name))
90 s->selector = vfcp->vfc_typenum;
99 oiderror(int *oid, int oidlen, enum Type type, void *obj)
101 fprintf(stderr, "sysctl ");
103 fprintf(stderr, "%d", *oid++);
106 fprintf(stderr, "%c", '.');
108 fprintf(stderr, " => ");
110 fprintf(stderr, "%d\n", *(int *)obj);
112 fprintf(stderr, "%s\n", (char *)obj);
118 recurse(id obj, Setting *s, int level, int myoid[])
125 myoid[level] = s->selector;
128 for(child = s->children; child->key; child++) {
129 if(child->type == Node && !child->children)
131 newobj = [obj objectForKey: child->key];
133 recurse(newobj, child, level+1, myoid);
137 intval = [obj intValue];
138 if(sysctl(myoid, level+1, NULL, NULL, &intval, sizeof(intval)) < 0)
139 oiderror(myoid, level+1, s->type, &intval);
142 cp = [obj UTF8String];
143 if(sysctl(myoid, level+1, NULL, NULL, (void *)cp, strlen(cp)) < 0)
144 oiderror(myoid, level+1, s->type, &cp);
149 Setting sysctl_darwin_all[] = {
150 {@"RealModes", AFS_SC_DARWIN_ALL_REALMODES, LeafNum, NULL},
151 {@"FSEvents", AFS_SC_DARWIN_ALL_FSEVENTS, LeafNum, NULL},
152 {@"Bulkstat", AFS_SC_DARWIN_ALL_BULKSTAT, LeafNum, NULL},
155 Setting sysctl_darwin[] = {
156 {@"All", AFS_SC_DARWIN_ALL, Node, sysctl_darwin_all},
157 {@"Darwin60", AFS_SC_DARWIN_60, Node, NULL},
158 {@"Darwin70", AFS_SC_DARWIN_70, Node, NULL},
159 {@"Darwin80", AFS_SC_DARWIN_80, Node, NULL},
160 {@"Darwin90", AFS_SC_DARWIN_90, Node, NULL},
161 {@"Darwin100", AFS_SC_DARWIN_100, Node, NULL},
164 Setting sysctl_first[] = {
165 {@"All", AFS_SC_ALL, Node, NULL},
166 {@"Darwin", AFS_SC_DARWIN, Node, sysctl_darwin},
169 Setting sysctl_top = {NULL, -1, Node, sysctl_first};
172 main(int argc, char **argv)
178 NSAutoreleasePool * nspool = [[NSAutoreleasePool alloc] init];
179 NSString *plistpath = @"/var/db/openafs/etc/config/settings.plist";
180 int oid[CTL_MAXNAME] = {CTL_VFS};
182 if (mygetvfsbyname("afs", &vfcp, &sysctl_top, oid) != 0)
184 plistData = [NSData dataWithContentsOfFile: plistpath];
186 plist = [NSPropertyListSerialization propertyListFromData: plistData
187 mutabilityOption: NSPropertyListImmutable
189 errorDescription: &error
192 NSLog(@"Error reading plist from file '%s', error = '%s'", [plistpath UTF8String], [error UTF8String]);
197 recurse(plist, &sysctl_top, 1, oid);