2 * Copyright (c) 2003, 2006 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
23 #import <Foundation/Foundation.h>
28 #import <sys/sysctl.h>
29 #import <afs/sysctl.h>
37 typedef struct _setting {
41 struct _setting *children;
44 Setting s_darwin_all[] = {
45 {@"RealModes", AFS_SC_DARWIN_ALL_REALMODES, TypeNum, NULL},
48 Setting s_darwin[] = {
49 {@"All", AFS_SC_DARWIN_ALL, TypeNode, s_darwin_all},
50 {@"Darwin12", AFS_SC_DARWIN_12, TypeNode, NULL},
51 {@"Darwin13", AFS_SC_DARWIN_13, TypeNode, NULL},
52 {@"Darwin14", AFS_SC_DARWIN_14, TypeNode, NULL},
53 {@"Darwin60", AFS_SC_DARWIN_60, TypeNode, NULL},
54 {@"Darwin70", AFS_SC_DARWIN_70, TypeNode, NULL},
55 {@"Darwin80", AFS_SC_DARWIN_80, TypeNode, NULL},
56 {@"Darwin90", AFS_SC_DARWIN_90, TypeNode, NULL},
60 {@"All", AFS_SC_ALL, TypeNode, NULL},
61 {@"Darwin", AFS_SC_DARWIN, TypeNode, s_darwin},
64 Setting s_top = {NULL, -1, TypeNode, s_first};
66 int oid[CTL_MAXNAME] = {CTL_VFS};
67 NSString *path = @"/var/db/openafs/etc/config/settings.plist";
69 char *oidString(int *oid, int len);
71 void walk(id obj, Setting *s, int level);
76 int oidmax[] = {CTL_VFS, VFS_GENERIC, VFS_MAXTYPENUM};
77 int oidvfs[] = {CTL_VFS, VFS_GENERIC, VFS_CONF, 0};
84 if(sysctl(oidmax, 3, &max, &len, NULL, 0) < 0)
85 err(1, "sysctl VFS_MAXTYPENUM");
86 for(i = max; --i >= 0; ) {
89 if(sysctl(oidvfs, 4, &conf, &len, NULL, 0) < 0)
91 if(strcmp("afs", conf.vfc_name) == 0) {
92 s_top.selector = conf.vfc_typenum;
96 if(s_top.selector < 0)
97 errx(1, "AFS is not loaded");
101 oidString(int *oid, int len)
103 static char buf[256];
107 sprintf(cp, "%d", *oid++);
117 walk(id obj, Setting *s, int level)
123 int level1 = level + 1;
125 oid[level] = s->selector;
128 for(child = s->children; child->key; child++) {
129 if(child->type == TypeNode && !child->children)
131 newobj = [obj objectForKey: child->key];
133 walk(newobj, child, level1);
137 intval = [obj intValue];
138 if(sysctl(oid, level1, NULL, NULL, &intval, sizeof(intval)) < 0)
139 err(1, "sysctl %s => %d", oidString(oid, level1), intval);
142 cp = [obj UTF8String];
143 if(sysctl(oid, level1, NULL, NULL, (void *)cp, strlen(cp)) < 0)
144 err(1, "sysctl %s => %s", oidString(oid, level1), cp);
154 NSPropertyListFormat format;
155 NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
158 plistData = [NSData dataWithContentsOfFile: path];
160 plist = [NSPropertyListSerialization propertyListFromData: plistData
161 mutabilityOption: NSPropertyListImmutable
163 errorDescription: &error
166 walk(plist, &s_top, 1);
168 errx(1, "%s: %s", [path UTF8String], [error UTF8String]);