fix struct stat to match Linux ABI

master
WangRunji 6 years ago
parent bed1fa274b
commit cb1bd5b835

@ -229,30 +229,63 @@ struct sockaddr_storage {
struct stat { struct stat {
dev_t st_dev; dev_t st_dev;
ino_t st_ino; ino_t st_ino;
ulong st_nlink;
mode_t st_mode; mode_t st_mode;
off_t st_size;
dev_t st_rdev;
uid_t st_uid; uid_t st_uid;
gid_t st_gid;
uint32_t _pad0;
dev_t st_rdev;
off_t st_size;
ulong st_blksize;
blkcnt_t st_blocks; blkcnt_t st_blocks;
time_t st_atime;
ulong st_atimensec;
time_t st_mtime; time_t st_mtime;
ulong st_mtimensec; ulong st_mtimensec;
time_t st_ctime;
ulong st_ctimensec;
}; };
#define S_IFMT (0xffff0000ul) #define S_IFMT 00170000
#define S_IFREG (1ul << 16) #define S_IFSOCK 0140000
#define S_IFDIR (2ul << 16) #define S_IFLNK 0120000
#define S_IFIFO (3ul << 16) #define S_IFREG 0100000
#define S_IFLNK (4ul << 16) #define S_IFBLK 0060000
#define S_IFBLK (5ul << 16) #define S_IFDIR 0040000
#define S_IFCHR 0020000
// XXX cleanup modes/dev majors #define S_IFIFO 0010000
#define S_ISDIR(mode) ((mode & S_IFMT) == S_IFDIR)
#define S_ISDEV(mode) (MAJOR(mode) != 0) #define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK)
#define S_ISFIFO(mode) ((mode & S_IFMT) == S_IFIFO) #define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
#define S_ISREG(mode) ((mode & S_IFMT) == S_IFREG) #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
#define S_ISSOCK(mode) (MAJOR(mode) == 2) #define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
#define S_ISLNK(mode) ((mode & S_IFMT) == S_IFLNK) #define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
#define S_ISBLK(mode) (MAJOR(mode) == S_IFBLK) #define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
#define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
// wrj: S_ISDEV is non-standard. just guess:
#define S_ISDEV(m) (((m) & S_IFMT) == S_IFBLK \
|| ((m) & S_IFMT) == S_IFCHR \
|| ((m) & S_IFMT) == S_IFSOCK)
//#define S_IFMT (0xffff0000ul)
//#define S_IFREG (1ul << 16)
//#define S_IFDIR (2ul << 16)
//#define S_IFIFO (3ul << 16)
//#define S_IFLNK (4ul << 16)
//#define S_IFBLK (5ul << 16)
//
//// XXX cleanup modes/dev majors
//#define S_ISDIR(mode) ((mode & S_IFMT) == S_IFDIR)
//#define S_ISDEV(mode) (MAJOR(mode) != 0)
//#define S_ISFIFO(mode) ((mode & S_IFMT) == S_IFIFO)
//#define S_ISREG(mode) ((mode & S_IFMT) == S_IFREG)
//#define S_ISSOCK(mode) (MAJOR(mode) == 2)
//#define S_ISLNK(mode) ((mode & S_IFMT) == S_IFLNK)
//#define S_ISBLK(mode) (MAJOR(mode) == S_IFBLK)
// please never use these // please never use these
#define S_ISUID (04000) #define S_ISUID (04000)

@ -52,13 +52,13 @@ typedef unsigned char u8;
typedef long time_t; typedef long time_t;
typedef unsigned long nfds_t; typedef unsigned long nfds_t;
typedef unsigned long mode_t; typedef unsigned int mode_t;
typedef long dev_t; typedef long dev_t;
typedef ulong ino_t; typedef ulong ino_t;
typedef long off_t; typedef long off_t;
typedef long pid_t; typedef long pid_t;
typedef long uid_t; typedef int uid_t;
typedef long gid_t; typedef int gid_t;
typedef unsigned long socklen_t; typedef unsigned long socklen_t;
typedef unsigned long rlim_t; typedef unsigned long rlim_t;
typedef unsigned long sigset_t; typedef unsigned long sigset_t;

@ -44,7 +44,7 @@ void rm(char *fn)
dirrm(fn); dirrm(fn);
return; return;
} }
errx(-1, "weird file type %ld", st.st_mode & S_IFMT); errx(-1, "weird file type %d", st.st_mode & S_IFMT);
} }
int main(int argc, char **argv) int main(int argc, char **argv)

@ -4,24 +4,44 @@
#include <defs.h> #include <defs.h>
struct stat { struct stat {
uint64_t st_dev;
uint64_t st_ino;
uint64_t st_nlinks; // number of hard links
uint32_t st_mode; // protection mode and file type uint32_t st_mode; // protection mode and file type
uint32_t st_nlinks; // number of hard links uint32_t st_uid;
uint32_t st_blocks; // number of blocks file is using uint32_t st_gid;
uint32_t st_size; // file size (bytes) uint32_t _pad0;
uint64_t st_rdev;
uint64_t st_size; // file size (bytes)
uint64_t st_blksize;
uint64_t st_blocks; // number of blocks file is using
uint64_t st_atime;
uint64_t st_atimensec;
uint64_t st_mtime;
uint64_t st_mtimensec;
uint64_t st_ctime;
uint64_t st_ctimensec;
}; };
#define S_IFMT 070000 // mask for type of file #define S_IFMT 00170000
#define S_IFREG 010000 // ordinary regular file #define S_IFSOCK 0140000
#define S_IFDIR 020000 // directory #define S_IFLNK 0120000
#define S_IFLNK 030000 // symbolic link #define S_IFREG 0100000
#define S_IFCHR 040000 // character device #define S_IFBLK 0060000
#define S_IFBLK 050000 // block device #define S_IFDIR 0040000
#define S_IFCHR 0020000
#define S_ISREG(mode) (((mode) & S_IFMT) == S_IFREG) // regular file #define S_IFIFO 0010000
#define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR) // directory
#define S_ISLNK(mode) (((mode) & S_IFMT) == S_IFLNK) // symlink #define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK)
#define S_ISCHR(mode) (((mode) & S_IFMT) == S_IFCHR) // char device #define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
#define S_ISBLK(mode) (((mode) & S_IFMT) == S_IFBLK) // block device #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_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
#define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
#endif /* !__LIBS_STAT_H__ */ #endif /* !__LIBS_STAT_H__ */

Loading…
Cancel
Save