/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* bos720 src/bos/kernel/sys/mode.h 1.24.1.3                              */
/*                                                                        */
/* Licensed Materials - Property of IBM                                   */
/*                                                                        */
/* COPYRIGHT International Business Machines Corp. 1985,1995              */
/* All Rights Reserved                                                    */
/*                                                                        */
/* US Government Users Restricted Rights - Use, duplication or            */
/* disclosure restricted by GSA ADP Schedule Contract with IBM Corp.      */
/*                                                                        */
/* IBM_PROLOG_END_TAG                                                     */
/* @(#)86    1.24.1.3  src/bos/kernel/sys/mode.h, syssdac, bos720 1/20/10 08:17:26 */
/*
 * COMPONENT_NAME: SYSSEC - Security Component
 *
 * ORIGINS: 27
 *
 * (C) COPYRIGHT International Business Machines Corp. 1985, 1988, 1989, 1995
 * All Rights Reserved
 * Licensed Materials - Property of IBM
 *
 * US Government Users Restricted Rights - Use, duplication or
 * disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
 */

#ifndef _H_MODE
#define _H_MODE


/*
 * POSIX requires that certain values effectively be included in stat.h.
 * It also requires that when _POSIX_SOURCE is defined, only those standard
 * specific values are present.  Since mode.h defines values on behalf of
 * stat.h and since stat.h includes mode.h, this header adheres to the
 * POSIX requirements.
 */

#include <standards.h>
#ifdef _POSIX_SOURCE 

/*
 *	(stat) st_mode bit values
 */

#define _S_IFMT		0170000		/* type of file */
#define   _S_IFREG	0100000		/*   regular */
#define   _S_IFDIR	0040000		/*   directory */
#define   _S_IFBLK	0060000		/*   block special */
#define   _S_IFCHR	0020000		/*   character special */
#define   _S_IFIFO	0010000		/*   fifo */

#define S_ISUID		0004000		/* set user id on execution */
#define S_ISGID		0002000		/* set group id on execution */

					/* ->>> /usr/group definitions <<<- */
#define S_IRWXU		0000700		/* read,write,execute perm: owner */
#define S_IRUSR		0000400		/* read permission: owner */
#define S_IWUSR		0000200		/* write permission: owner */
#define S_IXUSR		0000100		/* execute/search permission: owner */
#define S_IRWXG		0000070		/* read,write,execute perm: group */
#define S_IRGRP		0000040		/* read permission: group */
#define S_IWGRP		0000020		/* write permission: group */
#define S_IXGRP		0000010		/* execute/search permission: group */
#define S_IRWXO		0000007		/* read,write,execute perm: other */
#define S_IROTH		0000004		/* read permission: other */
#define S_IWOTH		0000002		/* write permission: other */
#define S_IXOTH		0000001		/* execute/search permission: other */

/*
 *	File type macros
 */

#define S_ISFIFO(m)	(((m)&(_S_IFMT)) == (_S_IFIFO))
#define S_ISDIR(m)	(((m)&(_S_IFMT)) == (_S_IFDIR))
#define S_ISCHR(m)	(((m)&(_S_IFMT)) == (_S_IFCHR))
#define S_ISBLK(m)	(((m)&(_S_IFMT)) == (_S_IFBLK))
#define S_ISREG(m)	(((m)&(_S_IFMT)) == (_S_IFREG))

#endif /* _POSIX_SOURCE */


/*
 *	Additional mode bit values
 *	(Macros are separated because they're not strictly part of the standard)
 */

#ifdef _XOPEN_SOURCE

#define S_ISVTX		0001000		/* save text even after use */

/*
 *	(stat) st_mode bit values
 */
#define S_IFMT		_S_IFMT		/* type of file */
#define   S_IFREG	_S_IFREG	/*   regular */
#define   S_IFDIR	_S_IFDIR	/*   directory */
#define   S_IFBLK	_S_IFBLK	/*   block special */
#define   S_IFCHR	_S_IFCHR	/*   character special */
#define   S_IFIFO	_S_IFIFO	/*   fifo */

#endif /* _XOPEN_SOURCE */

#if _XOPEN_SOURCE_EXTENDED == 1

/*
 *	(stat) st_mode bit values
 */
#define S_IFLNK		0120000		/* symbolic link */
#define S_IFSOCK	0140000		/* socket */

#define S_ISLNK(m)	(((m)&(S_IFMT)) == (S_IFLNK))
#define S_ISSOCK(m)	(((m)&(S_IFMT)) == (S_IFSOCK))

#endif /* _XOPEN_SOURCE_EXTENDED == 1 */

#ifdef _ALL_SOURCE

/*
 *	(stat) st_mode bit values
 */

#define S_IREAD		0000400		/* read permission, owner */
#define S_IWRITE	0000200		/* write permission, owner */
#define S_IEXEC		0000100		/* execute/search permission, owner */

#define S_ENFMT		S_ISGID		/* record locking enforcement flag */

#define S_IFMPX		(S_IFCHR|S_ISVTX) /* multiplex character special file */
#define S_ISMPX(m)	(((m)&(S_IFMT|S_ISVTX)) == (S_IFMPX))


/*
 *	Equivalent mode macros (from sys/inode.h)
 */

#define	IFMT	S_IFMT		/* type of file */
#define	IFDIR	S_IFDIR		/* directory */
#define	IFCHR	S_IFCHR		/* character special */
#define	IFBLK	S_IFBLK		/* block special */
#define	IFREG	S_IFREG		/* regular */
#define	IFIFO	S_IFIFO		/* fifo */
#define	IFSOCK	S_IFSOCK	/* socket */
#define	IFLNK	S_IFLNK		/* symbolic link */
#define	ISUID	S_ISUID		/* set user id on execution */
#define	ISGID	S_ISGID		/* set group id on execution */
#define	ISVTX	S_ISVTX		/* save swapped text even after use */
#define	IREAD	S_IREAD		/* read permission, owner */
#define	IWRITE	S_IWRITE	/* write permission, owner */
#define	IEXEC	S_IEXEC		/* execute/search permission, owner */


/*
 *	High order mode bit definitions (for security)
 */

/* version information */

#define S_IFJOURNAL		0x00010000 	/* Defined by filesystems */
#define	S_RESERVED1		0x00020000	/* Future extension: deprecated
						 * ISPARSE; Only reuse with new
						 * version and check for it.
						 */
#define S_IXATTR		0x00040000	/* I am EA */
#define S_ICRYPTO		0x00080000	/* EFS activated */

#define S_IXINTERFACE		0x00100000	/* Dataset Management Object */
#define S_RESERVED2		0x00200000	/* Future extension */
#define S_RESERVED3		0x00400000	/* Future extension */
#define S_ITP			0x00800000	/* Trusted Process */

#define S_ITCB			0x01000000	/* Trusted Computing Base */
#define S_IXACL			0x02000000	/* primaryObject: extended 
						   ACL/I have ACL, eaObject: I am ACL */
#define	S_EMODFMT		0x3C000000	/* Bits reserved for flags
						 * Do not mask these bits.
						 * Define here the values and a
						 * S_IS* macro for checking the
						 * value below
						 */
#define S_IXMOD			0x40000000	/* extended mode/I have EA */
#define S_RESERVED4		0x80000000	/* Future extension */

/*
 * Valid mode bits used in raschk_mode.  These should be updated
 * anytime new bits are added/removed from the valid set.
 */
#define VALID_MODE_BITS	       (S_IFJOURNAL	| \
				S_IXMOD 	| \
				S_IXATTR 	| \
				S_IXACL  	| \
				S_ITCB		| \
				S_ITP		| \
				S_ICRYPTO	| \
				S_IXINTERFACE)

/*
 * S_IFPDIR, S_IFPSDIR, S_IFPSSDIR:
 * These bits used only for MLS partitioned directory.  These bits are
 * passed into mkdir() so that the partition directory type can be 
 * set accordingly.  These bits are not set in regular mode_t.  
 */
#define S_IFPDIR		0x04000000	/* Partitioned dir */
#define S_IFPSDIR		0x08000000	/* Partitioned sub dir */
#define S_IFPSSDIR		0x0C000000	/* Partitioned sub sub dir */
#define	S_RESFMT1		0x10000000	/* Future extension */
#define	S_RESFMT2		0x14000000	/* Future extension */
#define	S_RESFMT3		0x18000000	/* Future extension */
#define	S_RESFMT4		0x1C000000	/* Future extension */
#define	S_RESFMT5		0x20000000	/* Future extension */
#define	S_RESFMT6		0x24000000	/* Future extension */
#define	S_RESFMT7		0x28000000	/* Future extension */
#define	S_RESFMT8		0x2C000000	/* Future extension */
#define S_IFSYSEA               0x30000000
#define	S_RESFMT10		0x34000000	/* Future extension */
#define	S_RESFMT11		0x38000000	/* Future extension */
#define	S_RESFMT12		0x3C000000	/* Future extension */


#define	S_ISPDIR(m)		(((m)&(S_EMODFMT)) == (S_IFPDIR))
#define	S_ISPSDIR(m)		(((m)&(S_EMODFMT)) == (S_IFPSDIR))
#define	S_ISPSSDIR(m)		(((m)&(S_EMODFMT)) == (S_IFPSSDIR))
#define S_ISSYSEA(m)  		(((m)&(S_EMODFMT)) == (S_IFSYSEA))

#define S_HAS_PFS_EA(m)		S_ISSYSEA(m)  

/*
 *	extended attribute
 */
#define IXMOD		S_IXMOD
#define	IXATTR		S_IXATTR
#define	IXACL		S_IXACL	
#define IXINTERFACE	S_IXINTERFACE

#endif /* _ALL_SOURCE */
#endif /* _H_MODE */