From ec12abe0f04eb329b3f32e857a34f768fc93f3a1 Mon Sep 17 00:00:00 2001 From: Matthew Dillon Date: Wed, 27 Aug 2003 02:03:23 +0000 Subject: [PATCH] A significant number of applications need access to kernel data structures. Traditionally they have done a #define _KERNEL and then #include'd the files. Unfortunately this can create huge conflicts between libc declarations and kernel declarations. Also, every time we create a new dependancy between kernel includes we might windup causing another unexpected header file to be included into such a user program, causing its build to fail due to a conflict. This commit introduces _KERNEL_STRUCTURES. A user program which needs access to kernel data structures sets this instead of _KERNEL. This define will cause the kernel data structure but not the inlines or extern's to be brought in. Only those header files which directly impact buildworld have been modified so far, but the intent is for all significant kernel header files to use this feature. --- sys/i386/include/globaldata.h | 11 ++++++++-- sys/net/if_arp.h | 8 +++++-- sys/platform/pc32/include/globaldata.h | 11 ++++++++-- sys/sys/errno.h | 4 ++-- sys/sys/file.h | 12 ++++++++--- sys/sys/ipc.h | 10 +++++++-- sys/sys/mount.h | 27 +++++++++++++++++++---- sys/sys/msg.h | 7 ++++-- sys/sys/proc.h | 4 +++- sys/sys/sem.h | 13 +++++++---- sys/sys/shm.h | 10 +++++++-- sys/vfs/msdosfs/msdosfsmount.h | 12 ++++++++--- sys/vfs/ufs/inode.h | 7 +++--- sys/vfs/union/union.h | 30 ++++++++++++++++---------- 14 files changed, 123 insertions(+), 43 deletions(-) diff --git a/sys/i386/include/globaldata.h b/sys/i386/include/globaldata.h index 271475ff2c..422c0ede40 100644 --- a/sys/i386/include/globaldata.h +++ b/sys/i386/include/globaldata.h @@ -28,12 +28,14 @@ * should not include this file. * * $FreeBSD: src/sys/i386/include/globaldata.h,v 1.11.2.1 2000/05/16 06:58:10 dillon Exp $ - * $DragonFly: src/sys/i386/include/Attic/globaldata.h,v 1.19 2003/08/07 21:17:22 dillon Exp $ + * $DragonFly: src/sys/i386/include/Attic/globaldata.h,v 1.20 2003/08/27 02:03:17 dillon Exp $ */ #ifndef _MACHINE_GLOBALDATA_H_ #define _MACHINE_GLOBALDATA_H_ +#if defined(_KERNEL) || defined(_KERNEL_STRUCTURES) + #ifndef _SYS_GLOBALDATA_H_ #include /* struct globaldata */ #endif @@ -105,9 +107,14 @@ struct privatespace { /* page 5..4+UPAGES - idle stack (UPAGES pages) */ char idlestack[UPAGES * PAGE_SIZE]; /* SMPpt[5..] */ }; +#define mdcpu ((struct mdglobaldata *)_get_mycpu()) + +#endif + +#ifdef _KERNEL extern struct privatespace CPU_prvspace[]; -#define mdcpu ((struct mdglobaldata *)_get_mycpu()) +#endif #endif diff --git a/sys/net/if_arp.h b/sys/net/if_arp.h index dc802e88f4..23bb902b31 100644 --- a/sys/net/if_arp.h +++ b/sys/net/if_arp.h @@ -32,7 +32,7 @@ * * @(#)if_arp.h 8.1 (Berkeley) 6/10/93 * $FreeBSD: src/sys/net/if_arp.h,v 1.14.2.3 2002/02/20 23:34:09 fjoe Exp $ - * $DragonFly: src/sys/net/if_arp.h,v 1.2 2003/06/17 04:28:47 dillon Exp $ + * $DragonFly: src/sys/net/if_arp.h,v 1.3 2003/08/27 02:03:19 dillon Exp $ */ #ifndef _NET_IF_ARP_H_ @@ -100,7 +100,8 @@ struct arpreq { #define ATF_PUBL 0x08 /* publish entry (respond for other host) */ #define ATF_USETRAILERS 0x10 /* has requested trailers */ -#ifdef _KERNEL +#if defined(_KERNEL) || defined(_KERNEL_STRUCTURES) + /* * Structure shared between the ethernet driver modules and * the address resolution code. For example, each ec_softc or il_softc @@ -116,6 +117,9 @@ struct arpcom { void *ac_netgraph; /* ng_ether(4) netgraph node info */ }; +#endif + +#ifdef _KERNEL extern u_char etherbroadcastaddr[6]; extern u_char arcbroadcastaddr; #endif diff --git a/sys/platform/pc32/include/globaldata.h b/sys/platform/pc32/include/globaldata.h index 0ca63f0c3b..033ab144a3 100644 --- a/sys/platform/pc32/include/globaldata.h +++ b/sys/platform/pc32/include/globaldata.h @@ -28,12 +28,14 @@ * should not include this file. * * $FreeBSD: src/sys/i386/include/globaldata.h,v 1.11.2.1 2000/05/16 06:58:10 dillon Exp $ - * $DragonFly: src/sys/platform/pc32/include/globaldata.h,v 1.19 2003/08/07 21:17:22 dillon Exp $ + * $DragonFly: src/sys/platform/pc32/include/globaldata.h,v 1.20 2003/08/27 02:03:17 dillon Exp $ */ #ifndef _MACHINE_GLOBALDATA_H_ #define _MACHINE_GLOBALDATA_H_ +#if defined(_KERNEL) || defined(_KERNEL_STRUCTURES) + #ifndef _SYS_GLOBALDATA_H_ #include /* struct globaldata */ #endif @@ -105,9 +107,14 @@ struct privatespace { /* page 5..4+UPAGES - idle stack (UPAGES pages) */ char idlestack[UPAGES * PAGE_SIZE]; /* SMPpt[5..] */ }; +#define mdcpu ((struct mdglobaldata *)_get_mycpu()) + +#endif + +#ifdef _KERNEL extern struct privatespace CPU_prvspace[]; -#define mdcpu ((struct mdglobaldata *)_get_mycpu()) +#endif #endif diff --git a/sys/sys/errno.h b/sys/sys/errno.h index 964890ed59..64f3c5b5b1 100644 --- a/sys/sys/errno.h +++ b/sys/sys/errno.h @@ -37,7 +37,7 @@ * * @(#)errno.h 8.5 (Berkeley) 1/21/94 * $FreeBSD: src/sys/sys/errno.h,v 1.14.2.2 2002/01/22 10:46:56 keramida Exp $ - * $DragonFly: src/sys/sys/errno.h,v 1.4 2003/08/20 07:31:21 rob Exp $ + * $DragonFly: src/sys/sys/errno.h,v 1.5 2003/08/27 02:03:22 dillon Exp $ */ #ifndef _SYS_ERRNO_H_ @@ -185,7 +185,7 @@ __END_DECLS #endif /* _POSIX_SOURCE */ -#ifdef _KERNEL +#if defined(_KERNEL) || defined(_KERNEL_STRUCTURES) /* pseudo-errors returned inside kernel to modify return to process */ #define ERESTART (-1) /* restart syscall */ #define EJUSTRETURN (-2) /* don't modify regs, just return */ diff --git a/sys/sys/file.h b/sys/sys/file.h index d2e10b2c5a..a59dfb02c7 100644 --- a/sys/sys/file.h +++ b/sys/sys/file.h @@ -32,7 +32,7 @@ * * @(#)file.h 8.3 (Berkeley) 1/9/95 * $FreeBSD: src/sys/sys/file.h,v 1.22.2.7 2002/11/21 23:39:24 sam Exp $ - * $DragonFly: src/sys/sys/file.h,v 1.4 2003/07/29 20:03:08 dillon Exp $ + * $DragonFly: src/sys/sys/file.h,v 1.5 2003/08/27 02:03:22 dillon Exp $ */ #ifndef _SYS_FILE_H_ @@ -43,7 +43,8 @@ #include #endif -#ifdef _KERNEL +#if defined(_KERNEL) || defined(_KERNEL_STRUCTURES) + #include struct stat; @@ -108,13 +109,18 @@ struct file { int f_msgcount; /* reference count from message queue */ }; +LIST_HEAD(filelist, file); + +#endif + +#ifdef _KERNEL + #ifdef MALLOC_DECLARE MALLOC_DECLARE(M_FILE); #endif extern int fdrop (struct file *fp, struct thread *td); -LIST_HEAD(filelist, file); extern struct filelist filehead; /* head of list of open files */ extern struct fileops vnops; extern struct fileops badfileops; diff --git a/sys/sys/ipc.h b/sys/sys/ipc.h index e6656c548b..25e7336e10 100644 --- a/sys/sys/ipc.h +++ b/sys/sys/ipc.h @@ -42,7 +42,7 @@ * * @(#)ipc.h 8.4 (Berkeley) 2/19/95 * $FreeBSD: src/sys/sys/ipc.h,v 1.15 1999/12/29 04:24:43 peter Exp $ - * $DragonFly: src/sys/sys/ipc.h,v 1.3 2003/08/20 07:31:21 rob Exp $ + * $DragonFly: src/sys/sys/ipc.h,v 1.4 2003/08/27 02:03:22 dillon Exp $ */ /* @@ -77,7 +77,8 @@ struct ipc_perm { #define IPC_SET 1 /* set options */ #define IPC_STAT 2 /* get options */ -#ifdef _KERNEL +#if defined(_KERNEL) || defined(_KERNEL_STRUCTURES) + /* Macros to convert between ipc ids and array indices or sequence ids */ #define IPCID_TO_IX(id) ((id) & 0xffff) #define IPCID_TO_SEQ(id) (((id) >> 16) & 0xffff) @@ -85,7 +86,12 @@ struct ipc_perm { struct proc; +#endif + +#ifdef _KERNEL + int ipcperm (struct proc *, struct ipc_perm *, int); + #else /* ! _KERNEL */ /* XXX doesn't really belong here, but has been historical practice in SysV. */ diff --git a/sys/sys/mount.h b/sys/sys/mount.h index fc18e8180b..d4eab3a733 100644 --- a/sys/sys/mount.h +++ b/sys/sys/mount.h @@ -32,7 +32,7 @@ * * @(#)mount.h 8.21 (Berkeley) 5/20/95 * $FreeBSD: src/sys/sys/mount.h,v 1.89.2.7 2003/04/04 20:35:57 tegge Exp $ - * $DragonFly: src/sys/sys/mount.h,v 1.6 2003/08/20 07:31:21 rob Exp $ + * $DragonFly: src/sys/sys/mount.h,v 1.7 2003/08/27 02:03:22 dillon Exp $ */ #ifndef _SYS_MOUNT_H_ @@ -104,7 +104,7 @@ struct statfs { long f_spare[2]; /* unused spare */ }; -#ifdef _KERNEL +#if defined(_KERNEL) || defined(_KERNEL_STRUCTURES) /* * Structure per mounted file system. Each mounted file system has an * array of operations and an instance record. The file systems are @@ -137,7 +137,7 @@ struct mount { struct vnodelst mnt_reservedvnlist; /* (future) dirty vnode list */ int mnt_nvnodelistsize; /* # of vnodes on this mount */ }; -#endif /* _KERNEL */ +#endif /* _KERNEL || _KERNEL_STRUCTURES */ /* * User specifiable flags. @@ -320,6 +320,12 @@ extern int maxvfsconf; /* highest defined filesystem type */ extern int nfs_mount_type; /* vfc_typenum for nfs, or -1 */ extern struct vfsconf *vfsconf; /* head of list of filesystem types */ +#endif + +#if defined(_KERNEL) || defined(_KERNEL_STRUCTURES) + +TAILQ_HEAD(mntlist, mount); /* struct mntlist */ + /* * Operations supported on mounted file system. */ @@ -373,6 +379,10 @@ struct vfsops { #define VFS_EXTATTRCTL(MP, C, N, A, P) \ (*(MP)->mnt_op->vfs_extattrctl)(MP, C, N, A, P) +#endif + +#ifdef _KERNEL + #include #define VFS_SET(vfsops, fsname, flags) \ @@ -390,6 +400,10 @@ struct vfsops { }; \ DECLARE_MODULE(fsname, fsname ## _mod, SI_SUB_VFS, SI_ORDER_MIDDLE) +#endif + +#if defined(_KERNEL) || defined(_KERNEL_STRUCTURES) + #include #define AF_MAX 33 /* XXX */ @@ -411,6 +425,10 @@ struct netexport { struct radix_node_head *ne_rtable[AF_MAX+1]; /* Individual exports */ }; +#endif + +#ifdef _KERNEL + extern char *mountrootfsname; /* @@ -438,7 +456,7 @@ void vfs_unbusy (struct mount *, struct thread *); void vfs_unmountall (void); int vfs_register (struct vfsconf *); int vfs_unregister (struct vfsconf *); -extern TAILQ_HEAD(mntlist, mount) mountlist; /* mounted filesystem list */ +extern struct mntlist mountlist; /* mounted filesystem list */ extern struct lwkt_token mountlist_token; extern struct nfs_public nfs_pub; @@ -497,3 +515,4 @@ __END_DECLS #endif /* _KERNEL */ #endif /* !_SYS_MOUNT_H_ */ + diff --git a/sys/sys/msg.h b/sys/sys/msg.h index 84d30f4308..73cb24431a 100644 --- a/sys/sys/msg.h +++ b/sys/sys/msg.h @@ -1,5 +1,5 @@ /* $FreeBSD: src/sys/sys/msg.h,v 1.10.2.1 2000/08/04 22:31:10 peter Exp $ */ -/* $DragonFly: src/sys/sys/msg.h,v 1.3 2003/08/20 07:31:21 rob Exp $ */ +/* $DragonFly: src/sys/sys/msg.h,v 1.4 2003/08/27 02:03:22 dillon Exp $ */ /* $NetBSD: msg.h,v 1.4 1994/06/29 06:44:43 cgd Exp $ */ /* @@ -68,7 +68,7 @@ struct mymsg { char mtext[1]; /* message body */ }; -#ifdef _KERNEL +#if defined(_KERNEL) || defined(_KERNEL_STRUCTURES) /* * Based on the configuration parameters described in an SVR2 (yes, two) @@ -88,6 +88,9 @@ struct msginfo { msgssz, /* size of a message segment (see notes above) */ msgseg; /* number of message segments */ }; +#endif + +#ifdef _KERNEL extern struct msginfo msginfo; #endif diff --git a/sys/sys/proc.h b/sys/sys/proc.h index 4b60bfab92..ba6ed6871c 100644 --- a/sys/sys/proc.h +++ b/sys/sys/proc.h @@ -37,7 +37,7 @@ * * @(#)proc.h 8.15 (Berkeley) 5/19/95 * $FreeBSD: src/sys/sys/proc.h,v 1.99.2.9 2003/06/06 20:21:32 tegge Exp $ - * $DragonFly: src/sys/sys/proc.h,v 1.29 2003/08/20 07:31:21 rob Exp $ + * $DragonFly: src/sys/sys/proc.h,v 1.30 2003/08/27 02:03:22 dillon Exp $ */ #ifndef _SYS_PROC_H_ @@ -54,7 +54,9 @@ #include #include /* For struct klist */ #include +#ifdef _KERNEL #include +#endif #include /* Machine-dependent proc substruct. */ /* diff --git a/sys/sys/sem.h b/sys/sys/sem.h index 900a48601a..398c7487ec 100644 --- a/sys/sys/sem.h +++ b/sys/sys/sem.h @@ -1,5 +1,5 @@ /* $FreeBSD: src/sys/sys/sem.h,v 1.20.2.2 2000/08/04 22:31:10 peter Exp $ */ -/* $DragonFly: src/sys/sys/sem.h,v 1.3 2003/08/20 07:31:21 rob Exp $ */ +/* $DragonFly: src/sys/sys/sem.h,v 1.4 2003/08/27 02:03:22 dillon Exp $ */ /* $NetBSD: sem.h,v 1.5 1994/06/29 06:45:15 cgd Exp $ */ /* @@ -66,7 +66,7 @@ union semun { #define SEM_A 0200 /* alter permission */ #define SEM_R 0400 /* read permission */ -#ifdef _KERNEL +#if defined(_KERNEL) || defined(_KERNEL_STRUCTURES) /* * semaphore info struct @@ -83,17 +83,22 @@ struct seminfo { semvmx, /* semaphore maximum value */ semaem; /* adjust on exit max value */ }; -extern struct seminfo seminfo; /* internal "mode" bits */ #define SEM_ALLOC 01000 /* semaphore is allocated */ #define SEM_DEST 02000 /* semaphore will be destroyed on last detach */ +#endif /* _KERNEL || _KERNEL_STRUCTURES */ + +#ifdef _KERNEL + /* * Process sem_undo vectors at proc exit. */ void semexit (struct proc *p); -#endif /* _KERNEL */ +extern struct seminfo seminfo; + +#endif #ifndef _KERNEL #include diff --git a/sys/sys/shm.h b/sys/sys/shm.h index 8f52e2c07c..dbc3a26cca 100644 --- a/sys/sys/shm.h +++ b/sys/sys/shm.h @@ -1,5 +1,5 @@ /* $FreeBSD: src/sys/sys/shm.h,v 1.14 1999/12/29 04:24:46 peter Exp $ */ -/* $DragonFly: src/sys/sys/shm.h,v 1.4 2003/08/20 07:31:21 rob Exp $ */ +/* $DragonFly: src/sys/sys/shm.h,v 1.5 2003/08/27 02:03:22 dillon Exp $ */ /* $NetBSD: shm.h,v 1.15 1994/06/29 06:45:17 cgd Exp $ */ /* @@ -64,7 +64,7 @@ struct shmid_ds { void *shm_internal; /* sysv stupidity */ }; -#ifdef _KERNEL +#if defined(_KERNEL) || defined(_KERNEL_STRUCTURES) /* * System 5 style catch-all structure for shared memory constants that @@ -77,6 +77,11 @@ struct shminfo { shmseg, /* max shared memory segments per process */ shmall; /* max amount of shared memory (pages) */ }; + +#endif + +#ifdef _KERNEL + extern struct shminfo shminfo; extern struct shmid_ds *shmsegs; @@ -85,6 +90,7 @@ struct vmspace; void shmexit (struct vmspace *); void shmfork (struct proc *, struct proc *); + #else /* !_KERNEL */ #include diff --git a/sys/vfs/msdosfs/msdosfsmount.h b/sys/vfs/msdosfs/msdosfsmount.h index 4b2b1334e5..12611ebbfc 100644 --- a/sys/vfs/msdosfs/msdosfsmount.h +++ b/sys/vfs/msdosfs/msdosfsmount.h @@ -1,5 +1,5 @@ /* $FreeBSD: src/sys/msdosfs/msdosfsmount.h,v 1.20.2.2 2000/10/27 09:45:07 bde Exp $ */ -/* $DragonFly: src/sys/vfs/msdosfs/msdosfsmount.h,v 1.3 2003/08/20 09:56:32 rob Exp $ */ +/* $DragonFly: src/sys/vfs/msdosfs/msdosfsmount.h,v 1.4 2003/08/27 02:03:23 dillon Exp $ */ /* $NetBSD: msdosfsmount.h,v 1.17 1997/11/17 15:37:07 ws Exp $ */ /*- @@ -53,10 +53,12 @@ #define _MSDOSFS_MSDOSFSMOUNT_H_ #ifdef _KERNEL - #ifdef MALLOC_DECLARE MALLOC_DECLARE(M_MSDOSFSMNT); #endif +#endif + +#if defined(_KERNEL) || defined(_KERNEL_STRUCTURES) /* * Layout of the mount control block for a msdos file system. @@ -198,11 +200,15 @@ struct msdosfsmount { #define fsi_size(pmp) \ (1024 << ((pmp)->pm_BlkPerSec >> 2)) +#endif /* _KERNEL || _KERNEL_STRUCTURES */ + +#ifdef _KERNEL + int msdosfs_init (struct vfsconf *vfsp); int msdosfs_uninit (struct vfsconf *vfsp); int msdosfs_mountroot (void); -#endif /* _KERNEL */ +#endif /* * Arguments to mount MSDOS filesystems. diff --git a/sys/vfs/ufs/inode.h b/sys/vfs/ufs/inode.h index 77b3f2880e..4fc00ebc62 100644 --- a/sys/vfs/ufs/inode.h +++ b/sys/vfs/ufs/inode.h @@ -37,7 +37,7 @@ * * @(#)inode.h 8.9 (Berkeley) 5/14/95 * $FreeBSD: src/sys/ufs/ufs/inode.h,v 1.28.2.2 2001/09/29 12:52:52 iedowse Exp $ - * $DragonFly: src/sys/vfs/ufs/inode.h,v 1.3 2003/08/07 21:17:44 dillon Exp $ + * $DragonFly: src/sys/vfs/ufs/inode.h,v 1.4 2003/08/27 02:03:23 dillon Exp $ */ #ifndef _UFS_UFS_INODE_H_ @@ -133,7 +133,8 @@ struct inode { #define IN_HASHED 0x0080 /* Inode is on hash list */ #define IN_LAZYMOD 0x0100 /* Modified, but don't write yet. */ -#ifdef _KERNEL +#if defined(_KERNEL) || defined(_KERNEL_STRUCTURES) + /* * Structure used to pass around logical block paths generated by * ufs_getlbns and used by truncate and bmap code. @@ -159,6 +160,6 @@ struct ufid { ino_t ufid_ino; /* File number (ino). */ int32_t ufid_gen; /* Generation number. */ }; -#endif /* _KERNEL */ +#endif /* _KERNEL || _KERNEL_STRUCTURES */ #endif /* !_UFS_UFS_INODE_H_ */ diff --git a/sys/vfs/union/union.h b/sys/vfs/union/union.h index c2e9240ca0..19740f7340 100644 --- a/sys/vfs/union/union.h +++ b/sys/vfs/union/union.h @@ -36,7 +36,7 @@ * * @(#)union.h 8.9 (Berkeley) 12/10/94 * $FreeBSD: src/sys/miscfs/union/union.h,v 1.17 1999/12/29 04:54:48 peter Exp $ - * $DragonFly: src/sys/vfs/union/union.h,v 1.4 2003/08/20 09:56:34 rob Exp $ + * $DragonFly: src/sys/vfs/union/union.h,v 1.5 2003/08/27 02:03:23 dillon Exp $ */ struct union_args { @@ -63,6 +63,10 @@ struct union_mount { #define DIAGNOSTIC #endif +#endif + +#if defined(_KERNEL) || defined(_KERNEL_STRUCTURES) + /* * DEFDIRMODE is the mode bits used to create a shadow directory. */ @@ -114,6 +118,20 @@ struct union_node { #define UNVP_WANT 0x01 #define UNVP_LOCKED 0x02 +#define MOUNTTOUNIONMOUNT(mp) ((struct union_mount *)((mp)->mnt_data)) +#define VTOUNION(vp) ((struct union_node *)(vp)->v_data) +#define UNIONTOV(un) ((un)->un_vnode) +#define LOWERVP(vp) (VTOUNION(vp)->un_lowervp) +#define UPPERVP(vp) (VTOUNION(vp)->un_uppervp) +#define OTHERVP(vp) (UPPERVP(vp) ? UPPERVP(vp) : LOWERVP(vp)) + +#define UDEBUG(x) if (uniondebug) printf x +#define UDEBUG_ENABLED 1 + +#endif + +#ifdef _KERNEL + extern int union_allocvp (struct vnode **, struct mount *, struct vnode *, struct vnode *, @@ -139,16 +157,6 @@ extern void union_vm_coherency (struct vnode *, struct uio *, int); extern int (*union_dircheckp) (struct thread *, struct vnode **, struct file *); -#define MOUNTTOUNIONMOUNT(mp) ((struct union_mount *)((mp)->mnt_data)) -#define VTOUNION(vp) ((struct union_node *)(vp)->v_data) -#define UNIONTOV(un) ((un)->un_vnode) -#define LOWERVP(vp) (VTOUNION(vp)->un_lowervp) -#define UPPERVP(vp) (VTOUNION(vp)->un_uppervp) -#define OTHERVP(vp) (UPPERVP(vp) ? UPPERVP(vp) : LOWERVP(vp)) - -#define UDEBUG(x) if (uniondebug) printf x -#define UDEBUG_ENABLED 1 - extern vop_t **union_vnodeop_p; extern struct vfsops union_vfsops; extern int uniondebug; -- 2.41.0