]> git.saurik.com Git - apple/xnu.git/blobdiff - bsd/miscfs/devfs/devfsdefs.h
xnu-1228.tar.gz
[apple/xnu.git] / bsd / miscfs / devfs / devfsdefs.h
index 630795bb4650abc7138af84394e84b3296bd6e5d..701b8f43d668d4392b02f5ed812b64ca0c7d50e4 100644 (file)
@@ -1,23 +1,29 @@
 /*
- * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved.
  *
- * @APPLE_LICENSE_HEADER_START@
+ * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
  * 
- * The contents of this file constitute Original Code as defined in and
- * are subject to the Apple Public Source License Version 1.1 (the
- * "License").  You may not use this file except in compliance with the
- * License.  Please obtain a copy of the License at
- * http://www.apple.com/publicsource and read it before using this file.
+ * 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. The rights granted to you under the License
+ * may not be used to create, or enable the creation or redistribution of,
+ * unlawful or unlicensed copies of an Apple operating system, or to
+ * circumvent, violate, or enable the circumvention or violation of, any
+ * terms of an Apple operating system software license agreement.
  * 
- * This Original Code and all software distributed under the License are
- * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * 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 OR NON-INFRINGEMENT.  Please see the
- * License for the specific language governing rights and limitations
- * under the License.
+ * 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@
+ * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
  */
 /*
  * Copyright 1997,1998 Julian Elischer.  All rights reserved.
  * 
  * devfsdefs.h
  */
+/*
+ * NOTICE: This file was modified by McAfee Research in 2004 to introduce
+ * support for mandatory and extensible security protections.  This notice
+ * is included in support of clause 2.2 (b) of the Apple Public License,
+ * Version 2.0.
+ */
 
 /*
  * HISTORY
  *     Renamed structures/elements to clarify usage in code.
  */
 
+#ifndef __DEVFS_DEVFSDEFS_H__
+#define __DEVFS_DEVFSDEFS_H__
 
+#include  <sys/appleapiopts.h>
+
+#include <security/mac.h>
+
+#ifdef __APPLE_API_PRIVATE
 #define DEVMAXNAMESIZE         32              /* XXX */
 #define DEVMAXPATHSIZE         128             /* XXX */
 
@@ -63,7 +82,7 @@ typedef enum {
     DEV_DIR,
     DEV_BDEV,
     DEV_CDEV,
-    DEV_SLNK,
+    DEV_SLNK
 } devfstype_t;
 
 extern int (**devfs_vnodeop_p)(void *);        /* our own vector array for dirs */
@@ -96,19 +115,13 @@ union devnode_type {
     }Slnk;
 };
 
-#define        DN_ACCESS       0x0001          /* Access time update request. */
-#define        DN_CHANGE       0x0002          /* Inode change time update request. */
-#define        DN_UPDATE       0x0004          /* Modification time update request. */
-#define        DN_MODIFIED     0x0008          /* Inode has been modified. */
-#define        DN_RENAME       0x0010          /* Inode is being renamed. */
-
 struct devnode
 {
     devfstype_t                dn_type;
     int                        dn_flags;
     u_short            dn_mode;
-    u_short            dn_uid; 
-    u_short            dn_gid;
+    uid_t              dn_uid; 
+    gid_t              dn_gid;
     struct timespec    dn_atime;/* time of last access */
     struct timespec    dn_mtime;/* time of last modification */
     struct timespec    dn_ctime;/* time file changed */
@@ -118,13 +131,24 @@ struct devnode
     struct vnode *     dn_vn;  /* address of last vnode that represented us */
     int                        dn_len;   /* of any associated info (e.g. dir data) */
     devdirent_t *      dn_linklist;/* circular list of hardlinks to this node */
-    devdirent_t *      dn_last_lookup; /* name I was last looked up from */
     devnode_t *                dn_nextsibling; /* the list of equivalent nodes */
     devnode_t * *      dn_prevsiblingp;/* backpointer for the above */
     devnode_type_t     dn_typeinfo;
     int                        dn_delete;      /* mark for deletion */
+    int                        dn_change;
+    int                        dn_update;
+    int                        dn_access;
+  int                  dn_lflags;
+    int                        (*dn_clone)(dev_t dev, int action); /* get minor # */
+    struct label *     dn_label;       /* security label */
 };
 
+#define        DN_BUSY                 0x01
+#define        DN_DELETE               0x02
+#define        DN_CREATE               0x04
+#define        DN_CREATEWAIT   0x08
+
+
 struct devdirent
 {
     /*-----------------------directory entry fields-------------*/
@@ -138,8 +162,8 @@ struct devdirent
 };
 
 extern devdirent_t *           dev_root;
-extern struct lock__bsd__      devfs_lock;
 extern struct devfs_stats      devfs_stats;
+extern lck_mtx_t               devfs_mutex;
 
 /*
  * Rules for front nodes:
@@ -164,6 +188,7 @@ struct devfsmount
  */
 #include <sys/lock.h>
 #include <miscfs/devfs/devfs_proto.h>
+#include <libkern/OSAtomic.h>          /* required for OSAddAtomic() */
 
 //#define HIDDEN_MOUNTPOINT    1
 
@@ -172,104 +197,84 @@ struct devfsmount
 #define M_DEVFSNODE    M_DEVFS
 #define M_DEVFSMNT     M_DEVFS
 
-static __inline__ void
-getnanotime(struct timespec * t_p)
-{
-    struct timeval tv;
-
-    microtime(&tv);
-    t_p->tv_sec = tv.tv_sec;
-    t_p->tv_nsec = tv.tv_usec * 1000;
-    return;
-}
-
 #define VTODN(vp)      ((devnode_t *)(vp)->v_data)
-extern void cache_purge(struct vnode *vp); /* vfs_cache.c */
 
-static __inline__ int
-DEVFS_LOCK(struct proc * p)
-{
-    return (lockmgr(&devfs_lock, LK_EXCLUSIVE, NULL, p));
-}
+#define DEVFS_LOCK()   lck_mtx_lock(&devfs_mutex)
 
-static __inline__ int
-DEVFS_UNLOCK(struct proc * p)
-{
-    return (lockmgr(&devfs_lock, LK_RELEASE, NULL, p));
-}
+#define DEVFS_UNLOCK() lck_mtx_unlock(&devfs_mutex)
 
+
+/*
+ * XXX all the (SInt32 *) casts below assume sizeof(int) == sizeof(long)
+ */
 static __inline__ void
-DEVFS_INCR_ENTRIES()
+DEVFS_INCR_ENTRIES(void)
 {
-    devfs_stats.entries++;
+    OSAddAtomic(1, (SInt32 *)&devfs_stats.entries);
 }
 
 static __inline__ void
-DEVFS_DECR_ENTRIES()
+DEVFS_DECR_ENTRIES(void)
 {
-    devfs_stats.entries--;
+    OSAddAtomic(-1, (SInt32 *)&devfs_stats.entries);
 }
 
 static __inline__ void
-DEVFS_INCR_NODES()
+DEVFS_INCR_NODES(void)
 {
-    devfs_stats.nodes++;
+    OSAddAtomic(1, (SInt32 *)&devfs_stats.nodes);
 }
 
 static __inline__ void
-DEVFS_DECR_NODES()
+DEVFS_DECR_NODES(void)
 {
-    devfs_stats.nodes--;
+    OSAddAtomic(-1, (SInt32 *)&devfs_stats.nodes);
 }
 
 static __inline__ void
-DEVFS_INCR_MOUNTS()
+DEVFS_INCR_MOUNTS(void)
 {
-    devfs_stats.mounts++;
+    OSAddAtomic(1, (SInt32 *)&devfs_stats.mounts);
 }
 
 static __inline__ void
-DEVFS_DECR_MOUNTS()
+DEVFS_DECR_MOUNTS(void)
 {
-    devfs_stats.mounts--;
+    OSAddAtomic(-1, (SInt32 *)&devfs_stats.mounts);
 }
 
 static __inline__ void
 DEVFS_INCR_STRINGSPACE(int space)
 {
-    devfs_stats.stringspace += space;
+    OSAddAtomic(space, (SInt32 *)&devfs_stats.stringspace);
 }
 
 static __inline__ void
 DEVFS_DECR_STRINGSPACE(int space)
 {
-    devfs_stats.stringspace -= space;
-    if (devfs_stats.stringspace < 0) {
-       printf("DEVFS_DECR_STRINGSPACE: (%d - %d < 0)\n",
-              devfs_stats.stringspace + space, space);
-       devfs_stats.stringspace = 0;
-    }
+    OSAddAtomic(-space, (SInt32 *)&devfs_stats.stringspace);
 }
 
 static __inline__ void
-dn_times(devnode_t * dnp, struct timeval t1, struct timeval t2
+dn_times(devnode_t * dnp, struct timeval *t1, struct timeval *t2, struct timeval *t3
 {
-    if (dnp->dn_flags & (DN_ACCESS | DN_CHANGE | DN_UPDATE)) {
-       if (dnp->dn_flags & DN_ACCESS) {
-           dnp->dn_atime.tv_sec = t1.tv_sec;
-           dnp->dn_atime.tv_nsec = t1.tv_usec * 1000;
+       if (dnp->dn_access) {
+           dnp->dn_atime.tv_sec = t1->tv_sec;
+           dnp->dn_atime.tv_nsec = t1->tv_usec * 1000;
+           dnp->dn_access = 0;
        }
-       if (dnp->dn_flags & DN_UPDATE) {
-           dnp->dn_mtime.tv_sec = t2.tv_sec;
-           dnp->dn_mtime.tv_nsec = t2.tv_usec * 1000;
+       if (dnp->dn_update) {
+           dnp->dn_mtime.tv_sec = t2->tv_sec;
+           dnp->dn_mtime.tv_nsec = t2->tv_usec * 1000;
+           dnp->dn_update = 0;
        }
-       if (dnp->dn_flags & DN_CHANGE) {
-           dnp->dn_ctime.tv_sec = time.tv_sec;
-           dnp->dn_ctime.tv_nsec = time.tv_usec * 1000;
+       if (dnp->dn_change) {
+           dnp->dn_ctime.tv_sec = t3->tv_sec;
+           dnp->dn_ctime.tv_nsec = t3->tv_usec * 1000;
+           dnp->dn_change = 0;
        }
-       dnp->dn_flags &= ~(DN_ACCESS | DN_CHANGE | DN_UPDATE);
-    }
-    return;
+
+       return;
 }
 
 static __inline__ void
@@ -280,3 +285,5 @@ dn_copy_times(devnode_t * target, devnode_t * source)
     target->dn_ctime = source->dn_ctime;
     return;
 }
+#endif /* __APPLE_API_PRIVATE */
+#endif /* __DEVFS_DEVFSDEFS_H__ */