macos-move-afssettings-20060801
authorDerrick Brashear <shadow@dementia.org>
Tue, 1 Aug 2006 21:43:34 +0000 (21:43 +0000)
committerDerrick Brashear <shadow@dementia.org>
Tue, 1 Aug 2006 21:43:34 +0000 (21:43 +0000)
build this as part of the build

Makefile.in
configure.in
src/platform/DARWIN/Makefile.in [new file with mode: 0644]
src/platform/DARWIN/afssettings.m [new file with mode: 0644]
src/platform/Makefile.in [new file with mode: 0644]

index 30f7435..9d467c0 100644 (file)
@@ -347,6 +347,9 @@ aklog: comerr ptserver
                echo Skipping aklog for ${SYS_NAME} ; \
        fi
 
+platform: 
+       ${COMPILE_PART1} platform ${COMPILE_PART2}
+
 login: cmd comerr kauth rxkad pam sia tsm41 sgistuff aklog
        set -x; \
        if test "@BUILD_LOGIN@" = "yes"; then \
@@ -582,7 +585,8 @@ jafsadm: libjafsadm
 finale: project cmd comerr afsd butc tbutc @ENABLE_KERNEL_MODULE@ libuafs audit kauth log package \
        ptserver scout bu_utils ubik uss bozo vfsck volser tvolser tsalvaged \
        venus update xstat afsmonitor dauth rxdebug libafsrpc \
-       libafsauthent shlibafsrpc shlibafsauthent libadmin login man-pages
+       libafsauthent shlibafsrpc shlibafsauthent libadmin login man-pages \
+       platform
        ${COMPILE_PART1} finale ${COMPILE_PART2}
 
 finale_nolibafs: project cmd comerr afsd butc tbutc libuafs audit kauth log package \
index 5761960..a6288db 100644 (file)
@@ -79,6 +79,8 @@ src/mpp/Makefile \
 src/null/Makefile \
 src/package/Makefile \
 src/pam/Makefile \
+src/platform/Makefile \
+src/platform/${MKAFS_OSTYPE}/Makefile \
 src/procmgmt/Makefile \
 src/procmgmt/test/Makefile \
 src/ptserver/Makefile \
diff --git a/src/platform/DARWIN/Makefile.in b/src/platform/DARWIN/Makefile.in
new file mode 100644 (file)
index 0000000..22ea6be
--- /dev/null
@@ -0,0 +1,32 @@
+# Copyright 2000, International Business Machines Corporation and others.
+# All Rights Reserved.
+# 
+# This software has been released under the terms of the IBM Public
+# License.  For details, see the LICENSE file in the top-level source
+# directory or online at http://www.openafs.org/dl/license10.html
+
+srcdir=@srcdir@
+include @TOP_OBJDIR@/src/config/Makefile.config
+include ../config/Makefile.version
+
+all: afssettings
+
+afssettings: afssettings.m 
+        ${CC} ${CFLAGS} -o afssettings afssettings.m -framework Foundation
+
+install: \
+        ${DESTDIR}${bindir}/afssettings
+
+dest: \
+        ${DEST}/bin/afssettings
+
+
+${DESTDIR}${bindir}/afssettings: afssettings
+        ${INSTALL} -s $? $@
+
+
+${DEST}/bin/afssettings: afssettings
+       ${INSTALL} -s $? $@
+
+clean:
+       $(RM) -f *.o core afssettings AFS_component_version_number.c 
diff --git a/src/platform/DARWIN/afssettings.m b/src/platform/DARWIN/afssettings.m
new file mode 100644 (file)
index 0000000..f6f1088
--- /dev/null
@@ -0,0 +1,173 @@
+/*
+ * Copyright (c) 2003, 2006 Apple Computer, Inc. All rights reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ * 
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
+ * 
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ * 
+ * @APPLE_LICENSE_HEADER_END@
+ */
+#import <Foundation/Foundation.h>
+#import <stdio.h>
+#import <err.h>
+#import <sys/types.h>
+#import <sys/mount.h>
+#import <sys/sysctl.h>
+#import <afs/sysctl.h>
+
+enum Type {
+    TypeNode = 0,
+    TypeNum,
+    TypeStr
+};
+
+typedef struct _setting {
+    NSString *key;
+    int selector;
+    enum Type type;
+    struct _setting *children;
+} Setting;
+
+Setting s_darwin_all[] = {
+    {@"RealModes", AFS_SC_DARWIN_ALL_REALMODES, TypeNum, NULL},
+    {NULL, 0, 0, NULL}
+};
+Setting s_darwin[] = {
+    {@"All", AFS_SC_DARWIN_ALL, TypeNode, s_darwin_all},
+    {@"Darwin12", AFS_SC_DARWIN_12, TypeNode, NULL},
+    {@"Darwin13", AFS_SC_DARWIN_13, TypeNode, NULL},
+    {@"Darwin14", AFS_SC_DARWIN_14, TypeNode, NULL},
+    {@"Darwin60", AFS_SC_DARWIN_60, TypeNode, NULL},
+    {@"Darwin70", AFS_SC_DARWIN_70, TypeNode, NULL},
+    {@"Darwin80", AFS_SC_DARWIN_80, TypeNode, NULL},
+    {@"Darwin90", AFS_SC_DARWIN_90, TypeNode, NULL},
+    {NULL, 0, 0, NULL}
+};
+Setting s_first[] = {
+    {@"All", AFS_SC_ALL, TypeNode, NULL},
+    {@"Darwin", AFS_SC_DARWIN, TypeNode, s_darwin},
+    {NULL, 0, 0, NULL}
+};
+Setting s_top = {NULL, -1, TypeNode, s_first};
+
+int oid[CTL_MAXNAME] = {CTL_VFS};
+NSString *path = @"/var/db/openafs/etc/config/settings.plist";
+
+char *oidString(int *oid, int len);
+void init(void);
+void walk(id obj, Setting *s, int level);
+
+void
+init(void)
+{
+    int oidmax[] = {CTL_VFS, VFS_GENERIC, VFS_MAXTYPENUM};
+    int oidvfs[] = {CTL_VFS, VFS_GENERIC, VFS_CONF, 0};
+    int max;
+    struct vfsconf conf;
+    size_t len;
+    int i;
+
+    len = sizeof(max);
+    if(sysctl(oidmax, 3, &max, &len, NULL, 0) < 0)
+       err(1, "sysctl VFS_MAXTYPENUM");
+    for(i = max; --i >= 0; ) {
+       oidvfs[3] = i;
+       len = sizeof(conf);
+       if(sysctl(oidvfs, 4, &conf, &len, NULL, 0) < 0)
+           continue;
+       if(strcmp("afs", conf.vfc_name) == 0) {
+           s_top.selector = conf.vfc_typenum;
+           break;
+       }
+    }
+    if(s_top.selector < 0)
+       errx(1, "AFS is not loaded");
+}
+
+char *
+oidString(int *oid, int len)
+{
+    static char buf[256];
+    char *cp = buf;
+
+    for(;;) {
+       sprintf(cp, "%d", *oid++);
+       if(--len <= 0)
+           break;
+       cp += strlen(cp);
+       *cp++ = '.';
+    }
+    return buf;
+}
+
+void
+walk(id obj, Setting *s, int level)
+{
+    Setting *child;
+    id newobj;
+    int intval;
+    const char *cp;
+    int level1 = level + 1;
+
+    oid[level] = s->selector;
+    switch(s->type) {
+      case TypeNode:
+       for(child = s->children; child->key; child++) {
+           if(child->type == TypeNode && !child->children)
+               continue;
+           newobj = [obj objectForKey: child->key];
+           if(newobj)
+               walk(newobj, child, level1);
+       }
+       break;
+      case TypeNum:
+       intval = [obj intValue];
+       if(sysctl(oid, level1, NULL, NULL, &intval, sizeof(intval)) < 0)
+           err(1, "sysctl %s => %d", oidString(oid, level1), intval);
+       break;
+      case TypeStr:
+       cp = [obj UTF8String];
+       if(sysctl(oid, level1, NULL, NULL, (void *)cp, strlen(cp)) < 0)
+           err(1, "sysctl %s => %s", oidString(oid, level1), cp);
+       break;
+    }
+}
+
+main()
+{
+    NSData *plistData;
+    id plist;
+    NSString *error;
+    NSPropertyListFormat format;
+    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
+
+    init();
+    plistData = [NSData dataWithContentsOfFile: path];
+    if(plistData) {
+       plist = [NSPropertyListSerialization propertyListFromData: plistData
+         mutabilityOption: NSPropertyListImmutable
+         format: &format
+         errorDescription: &error
+       ];
+       if(plist)
+           walk(plist, &s_top, 1);
+       else
+           errx(1, "%s: %s", [path UTF8String], [error UTF8String]);
+    }
+
+    [pool release];
+    return 0;
+}
diff --git a/src/platform/Makefile.in b/src/platform/Makefile.in
new file mode 100644 (file)
index 0000000..f5f14bc
--- /dev/null
@@ -0,0 +1,26 @@
+# Copyright 2000, International Business Machines Corporation and others.
+# All Rights Reserved.
+# 
+# This software has been released under the terms of the IBM Public
+# License.  For details, see the LICENSE file in the top-level source
+# directory or online at http://www.openafs.org/dl/license10.html
+
+# Common elements for Makefiles for all system types.
+#
+SHELL=/bin/sh
+
+all:
+       cd $(MKAFS_OSTYPE) ; \
+       echo $(MAKE) all; \
+       $(MAKE) all
+dest:
+       cd $(MKAFS_OSTYPE) ; \
+       echo $(MAKE) DEST=${DEST} dest; \
+       $(MAKE) DEST=${DEST} dest
+install:
+       cd $(MKAFS_OSTYPE) ; \
+       echo $(MAKE) DESTDIR=${DESTDIR} install; \
+       $(MAKE) DESTDIR=${DESTDIR} install
+
+
+include ${TOP_OBJDIR}/src/config/Makefile.version