/***************************************************************************
 *             __________               __   ___.
 *   Open      \______   \ ____   ____ |  | _\_ |__   _______  ___
 *   Source     |       _//  _ \_/ ___\|  |/ /| __ \ /  _ \  \/  /
 *   Jukebox    |    |   (  <_> )  \___|    < | \_\ (  <_> > <  <
 *   Firmware   |____|_  /\____/ \___  >__|_ \|___  /\____/__/\_ \
 *                     \/            \/     \/    \/            \/
 * $Id: file.h,v 1.8 2002/07/05 11:28:20 linusnielsen Exp $
 *
 * Copyright (C) 2002 by Bill Napier
 *
 * All files in this archive are subject to the GNU General Public License.
 * See the file COPYING in the source tree root for full license agreement.
 *
 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
 * KIND, either express or implied.
 *
 ****************************************************************************/

#ifndef _STAT_H_
#define _STAT_H_

/* Maybe not the right place for these? */
typedef unsigned long dev_t;
typedef unsigned long ino_t;
typedef unsigned long mode_t;
typedef unsigned long nlink_t; 
typedef unsigned long gid_t; 
typedef unsigned long uid_t; 
typedef unsigned long off_t; 

typedef unsigned long time_t; 

#define S_IFMT     0170000   /* bitmask for the file type bitfields */
#define S_IFSOCK   0140000   /* socket */
#define S_IFLNK    0120000   /* symbolic link */
#define S_IFREG    0100000   /* regular file */
#define S_IFBLK    0060000   /* block device */
#define S_IFDIR    0040000   /* directory */
#define S_IFCHR    0020000   /* character device */
#define S_IFIFO    0010000   /* fifo */
#define S_ISUID    0004000   /* set UID bit */
#define S_ISGID    0002000   /* set GID bit (see below) */
#define S_ISVTX    0001000   /* sticky bit (see below) */
#define S_IRWXU    00700     /* mask for file owner permissions */
#define S_IRUSR    00400     /* owner has read permission */
#define S_IWUSR    00200     /* owner has write permission */
#define S_IXUSR    00100     /* owner has execute permission */
#define S_IRWXG    00070     /* mask for group permissions */
#define S_IRGRP    00040     /* group has read permission */
#define S_IWGRP    00020     /* group has write permission */
#define S_IXGRP    00010     /* group has execute permission */
#define S_IRWXO    00007     /* mask for permissions for others (not in group) */
#define S_IROTH    00004     /* others have read permission */
#define S_IWOTH    00002     /* others have write permisson */
#define S_IXOTH    00001     /* others have execute permission */

/* is it a regular file? */
#define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
/* directory? */
#define S_ISDIR(m)   (((m) & S_IFMT) == S_IFDIR)
/* character device? */
#define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
/* block device? */
#define S_ISBLK(m)   (((m) & S_IFMT) == S_IFBLK)
/* fifo? */
#define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
/* symbolic link? */
#define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK)
/* socket? */
#define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)

struct stat {
   dev_t         st_dev;      /* device */
   ino_t         st_ino;      /* inode */
   mode_t        st_mode;     /* protection */
   nlink_t       st_nlink;    /* number of hard links */
   uid_t         st_uid;      /* user ID of owner */
   gid_t         st_gid;      /* group ID of owner */
   dev_t         st_rdev;     /* device type (if inode device) */
   off_t         st_size;     /* total size, in bytes */
   unsigned long st_blksize;  /* blocksize for filesystem I/O */
   unsigned long st_blocks;   /* number of blocks allocated */
   time_t        st_atime;    /* time of last access */
   time_t        st_mtime;    /* time of last modification */
   time_t        st_ctime;    /* time of last change */
};

#ifndef SIMULATOR
extern int stat(char *file_name, struct stat *buf);
#endif // SIMULATOR

#endif

