/*
 * Copyright (c) 1996-2003 MIPS Technologies, Inc.
 * 
 * All rights reserved.
 * 
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 
 *      * Redistributions of source code must retain the above copyright
 *        notice, this list of conditions and the following disclaimer.
 *      * Redistributions in binary form must reproduce the above
 *      copyright
 *        notice, this list of conditions and the following disclaimer
 *        in the documentation and/or other materials provided with
 *        the distribution.
 *      * Neither the name of MIPS Technologies Inc. nor the names of its
 *        contributors may be used to endorse or promote products derived
 *        from this software without specific prior written permission.
 * 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

/*
 * stat.h : SDE file system stat definitions
 */


#ifndef __SYS_STAT_H
#ifdef __cplusplus
extern "C" {
#endif
#define __SYS_STAT_H

/* --- Required  --- */
#include <sys/types.h>

/* --- Constants --- */
#ifndef _POSIX_SOURCE
#define S_IFMT  	0170000		/* type of file */
#define S_IFIFO 	0010000		/* named pipe (FIFO) */
#define S_IFCHR 	0020000		/* character special */
#define S_IFDIR 	0040000  	/* directory */
#define S_IFBLK 	0060000		/* block special */
#define S_IFREG 	0100000		/* regular */
#define S_IFLNK 	0120000		/* a BSD symbolic link */
#define S_IFSOCK 	0140000		/* a BSD socket */
#endif

#define S_ISUID	04000		/* set user id on execution */
#define S_ISGID	02000		/* set group id on execution */
#ifndef _POSIX_SOURCE
#define S_ISVTX 01000		/* save swapped text even after use */
#define S_ISTXT 01000		/* save swapped text even after use */
#endif

#define S_IRWXU	00700		/* owner rwx	*/
#define S_IRUSR	00400		/* owner r	*/
#define S_IWUSR	00200		/* owner  w	*/
#define S_IXUSR	00100		/* owner   x	*/

#define S_IRWXG	00070		/* group rwx	*/
#define S_IRGRP	00040		/* group r	*/
#define S_IWGRP	00020		/* group  w	*/
#define S_IXGRP	00010		/* group   x	*/

#define S_IRWXO	00007		/* other rwx	*/
#define S_IROTH	00004		/* other r	*/
#define S_IWOTH	00002		/* other  w	*/
#define S_IXOTH	00001		/* other   x	*/

#ifndef _POSIX_SOURCE
/* --- Compatibility --- */
#define S_IREAD   S_IRUSR	/* read permission, owner */
#define S_IWRITE  S_IWUSR	/* write permission, owner */
#define S_IEXEC   S_IXUSR	/* execute/search permission, owner */
#endif

/* --- Structures --- */
struct stat {
    dev_t 	st_dev;
    ino_t	st_ino;
    mode_t	st_mode;
    nlink_t 	st_nlink;
    uid_t 	st_uid;
    gid_t 	st_gid;
    dev_t 	st_rdev;
    off_t 	st_size;
    size_t	st_blksize;	/* for I/O optim */
    time_t	st_atime;
    time_t 	st_mtime;
    time_t 	st_ctime;
};

/* --- Macros --- */
#define S_ISDIR(m)	(((m) & 0170000) == 0040000)
#define S_ISCHR(m)	(((m) & 0170000) == 0020000)
#define S_ISBLK(m)	(((m) & 0170000) == 0060000)
#define S_ISREG(m)	(((m) & 0170000) == 0100000)
#define S_ISFIFO(m)	(((m) & 0170000) == 0010000 || ((m) & 0170000) == 0140000)
#ifndef _POSIX_SOURCE
#define S_ISLNK(m)	(((m) & 0170000) == 0120000)
#define S_ISSOCK(m)	(((m) & 0170000) == 0140000)
#endif


#ifndef _KERNEL
/* --- Prototypes --- */
int	chmod (const char *, mode_t);
int	fchmod (int, mode_t);
int	fstat (int, struct stat *);
int	mkdir (const char *, mode_t);
int	mkfifo (const char *, mode_t);
int	stat (const char *, struct stat *);
int	lstat (const char *, struct stat *);
mode_t	umask (mode_t);
#endif

#ifdef __cplusplus
}
#endif
#endif /* !__SYS_STAT_H */
