From 6a1c3734e644abab6f3f57917ab9d51b9188d197 Mon Sep 17 00:00:00 2001 From: Louis Solofrizzo Date: Thu, 25 Apr 2019 11:30:39 +0200 Subject: [PATCH] fs: Add stat example Signed-off-by: Louis Solofrizzo --- unikernel-demo/fs1/stat/Makefile | 3 +++ unikernel-demo/fs1/stat/main.c | 20 ++++++++++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 unikernel-demo/fs1/stat/Makefile create mode 100644 unikernel-demo/fs1/stat/main.c diff --git a/unikernel-demo/fs1/stat/Makefile b/unikernel-demo/fs1/stat/Makefile new file mode 100644 index 00000000..ecd636b7 --- /dev/null +++ b/unikernel-demo/fs1/stat/Makefile @@ -0,0 +1,3 @@ +export ukl-obj-m := main.o + +include ../../Makefile diff --git a/unikernel-demo/fs1/stat/main.c b/unikernel-demo/fs1/stat/main.c new file mode 100644 index 00000000..abb3da10 --- /dev/null +++ b/unikernel-demo/fs1/stat/main.c @@ -0,0 +1,20 @@ +#include +#include + +#ifndef USERSPACE +#define main ukl_main +#endif + +int main(void) +{ + struct stat st = { 0 }; + + if (stat("/etc/passwd", &st) != 0) + { + fprintf(stderr, "Cannot stat() /etc/passwd\n"); + return 1; + } + + printf("Size of /etc/passwd: %zu bytes\n", st.st_size); + return 0; +}