git://scm.lunaixsky.com
/
lunaix-os.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Framework for exporting system header to user space (#59)
[lunaix-os.git]
/
lunaix-os
/
usr
/
stat.c
diff --git
a/lunaix-os/usr/stat.c
b/lunaix-os/usr/stat.c
index 108f462b887ad42882698e1b5d0e885938a4286a..3e782e96a428dd658304efaf6418c3c23f32661e 100644
(file)
--- a/
lunaix-os/usr/stat.c
+++ b/
lunaix-os/usr/stat.c
@@
-2,6
+2,7
@@
#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>
+#include <sys/types.h>
static char buf[256];
static char buf[256];
@@
-15,7
+16,7
@@
main(int argc, char* argv[])
int fd = open(argv[1], FO_RDONLY | FO_NOFOLLOW);
if (fd < 0) {
int fd = open(argv[1], FO_RDONLY | FO_NOFOLLOW);
if (fd < 0) {
- printf("fail to open %d\n",
fd
);
+ printf("fail to open %d\n",
errno
);
return 1;
}
return 1;
}
@@
-28,23
+29,22
@@
main(int argc, char* argv[])
printf("File: %s ", argv[1]);
char* ftype = "directory";
printf("File: %s ", argv[1]);
char* ftype = "directory";
- int mode = stat.
mode
;
- if ((mode & F_
M
DEV)) {
- if (!((mode & F_SEQDEV) ^ F_SEQDEV)) {
- ftype = "sequential device";
-
} else if (!((mode & F_VOLDEV) ^ F_VOL
DEV)) {
+ int mode = stat.
st_mode >> 16
;
+ if ((mode & F_DEV)) {
+ ftype = "mappable (sequential) device";
+
+
if (!((mode & F_SVDEV) ^ F_SV
DEV)) {
ftype = "volumetric device";
ftype = "volumetric device";
- } else {
- ftype = "regular device";
}
}
- } else if ((mode & F_MSLNK)) {
+
+ } else if ((mode & F_SYMLINK)) {
if (readlinkat(fd, NULL, buf, 256) < 0) {
printf("fail to readlink %d\n", errno);
} else {
printf("-> %s", buf);
}
ftype = "symbolic link";
if (readlinkat(fd, NULL, buf, 256) < 0) {
printf("fail to readlink %d\n", errno);
} else {
printf("-> %s", buf);
}
ftype = "symbolic link";
- } else if (
(mode & F_MFILE)
) {
+ } else if (
mode == F_FILE
) {
ftype = "regular file";
}
ftype = "regular file";
}
@@
-54,16
+54,25
@@
main(int argc, char* argv[])
stat.st_blocks,
stat.st_blksize,
stat.st_ioblksize);
stat.st_blocks,
stat.st_blksize,
stat.st_ioblksize);
- printf("Inode: %d; ", stat.st_ino);
dev_t* dev;
dev_t* dev;
- if (!(
stat.mode & F_M
DEV)) {
+ if (!(
mode & F_
DEV)) {
dev = &stat.st_dev;
} else {
dev = &stat.st_rdev;
}
dev = &stat.st_dev;
} else {
dev = &stat.st_rdev;
}
+ printf("Device: %xh:%xh@%d; Inode: %d; Links: %d\n",
+ dev->meta, dev->unique, dev->index,
+ stat.st_ino, stat.st_nlink);
+
+ printf("Access: 0%o; Uid: %d; Gid: %d\n",
+ stat.st_mode & 0xffff,
+ stat.st_uid,
+ stat.st_gid);
- printf("Device: %xh:%xh@%d;\n", dev->meta, dev->unique, dev->index);
+ printf("Access: %lu\n", stat.st_atim);
+ printf("Modify: %lu\n", stat.st_mtim);
+ printf("Create: %lu\n", stat.st_ctim);
close(fd);
return 0;
close(fd);
return 0;