1.1 --- a/Makefile Tue Oct 22 21:32:44 2019 +0200
1.2 +++ b/Makefile Tue Oct 22 23:07:50 2019 +0200
1.3 @@ -1,11 +1,20 @@
1.4 PKGDIR ?= .
1.5 L4DIR ?= $(PKGDIR)/../..
1.6
1.7 -TARGET = test_newlib test_newlib_fstat test_newlib_malloc test_newlib_posix_memalign
1.8 +TARGET = \
1.9 + test_newlib \
1.10 + test_newlib_fstat \
1.11 + test_newlib_lseek \
1.12 + test_newlib_malloc \
1.13 + test_newlib_posix_memalign \
1.14 + test_newlib_stat \
1.15 +
1.16 SRC_C_test_newlib = crt0.c debug.c minimal.c
1.17 SRC_C_test_newlib_fstat = crt0.c debug.c fstat.c
1.18 +SRC_C_test_newlib_lseek = crt0.c debug.c lseek.c
1.19 SRC_C_test_newlib_malloc = crt0.c debug.c malloc.c
1.20 SRC_C_test_newlib_posix_memalign = crt0.c debug.c posix_memalign.c
1.21 +SRC_C_test_newlib_stat = crt0.c debug.c stat.c
1.22
1.23 MODE = static_newlib
1.24
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2.2 +++ b/conf/test_newlib_lseek.cfg Tue Oct 22 23:07:50 2019 +0200
2.3 @@ -0,0 +1,43 @@
2.4 +-- vim:set ft=lua:
2.5 +
2.6 +local L4 = require("L4");
2.7 +
2.8 +local l = L4.default_loader;
2.9 +
2.10 +local block_root = l:new_channel();
2.11 +
2.12 +l:startv({
2.13 + caps = {
2.14 + block = block_root:svr(),
2.15 + },
2.16 + log = { "block_root", "r" },
2.17 + },
2.18 + "rom/blockserver", "rom/e2test.fs", "4");
2.19 +
2.20 +-- Root filesystem.
2.21 +
2.22 +local fs_root = l:new_channel();
2.23 +
2.24 +l:startv({
2.25 + caps = {
2.26 + block = block_root,
2.27 + export = fs_root:svr(),
2.28 + },
2.29 + log = { "fs_root", "y" },
2.30 + },
2.31 + "rom/e2fsserver", "block", "4");
2.32 +
2.33 +-- Obtain user filesystems with umask 0022 (18).
2.34 +
2.35 +local getuserfs = 6;
2.36 +local fs_paulb = L4.cast(L4.Proto.Factory, fs_root):create(getuserfs, 1000, 1000, 18);
2.37 +
2.38 +-- Client programs.
2.39 +
2.40 +l:startv({
2.41 + caps = {
2.42 + fs = fs_paulb,
2.43 + },
2.44 + log = { "client", "g" },
2.45 + },
2.46 + "rom/test_newlib_lseek", "home/paulb/test.txt");
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
3.2 +++ b/conf/test_newlib_lseek.list Tue Oct 22 23:07:50 2019 +0200
3.3 @@ -0,0 +1,37 @@
3.4 +entry test_newlib_lseek
3.5 +roottask moe rom/test_newlib_lseek.cfg
3.6 +module test_newlib_lseek.cfg
3.7 +module e2test.fs
3.8 +module ned
3.9 +module l4re
3.10 +module test_newlib_lseek
3.11 +module e2fsserver
3.12 +module blockserver
3.13 +module lib4re-c.so
3.14 +module lib4re-c-util.so
3.15 +module lib4re.so
3.16 +module lib4re-util.so
3.17 +module libblkid.so
3.18 +module libc_be_l4refile.so
3.19 +module libc_be_l4re.so
3.20 +module libc_be_socket_noop.so
3.21 +module libc_support_misc.so
3.22 +module libdl.so
3.23 +module libe2access.so
3.24 +module libe2p.so
3.25 +module libet.so
3.26 +module libext2fs_blockserver.so
3.27 +module libext2fs.so
3.28 +module libfsclient.so
3.29 +module libfsserver.so
3.30 +module libipc.so
3.31 +module libl4sys-direct.so
3.32 +module libl4sys.so
3.33 +module libl4util.so
3.34 +module libld-l4.so
3.35 +module libpthread.so
3.36 +module libstdc++.so
3.37 +module libsupc++.so
3.38 +module libsupport.so
3.39 +module libuc_c.so
3.40 +module libuuid.so
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
4.2 +++ b/conf/test_newlib_stat.cfg Tue Oct 22 23:07:50 2019 +0200
4.3 @@ -0,0 +1,43 @@
4.4 +-- vim:set ft=lua:
4.5 +
4.6 +local L4 = require("L4");
4.7 +
4.8 +local l = L4.default_loader;
4.9 +
4.10 +local block_root = l:new_channel();
4.11 +
4.12 +l:startv({
4.13 + caps = {
4.14 + block = block_root:svr(),
4.15 + },
4.16 + log = { "block_root", "r" },
4.17 + },
4.18 + "rom/blockserver", "rom/e2test.fs", "4");
4.19 +
4.20 +-- Root filesystem.
4.21 +
4.22 +local fs_root = l:new_channel();
4.23 +
4.24 +l:startv({
4.25 + caps = {
4.26 + block = block_root,
4.27 + export = fs_root:svr(),
4.28 + },
4.29 + log = { "fs_root", "y" },
4.30 + },
4.31 + "rom/e2fsserver", "block", "4");
4.32 +
4.33 +-- Obtain user filesystems with umask 0022 (18).
4.34 +
4.35 +local getuserfs = 6;
4.36 +local fs_paulb = L4.cast(L4.Proto.Factory, fs_root):create(getuserfs, 1000, 1000, 18);
4.37 +
4.38 +-- Client programs.
4.39 +
4.40 +l:startv({
4.41 + caps = {
4.42 + fs = fs_paulb,
4.43 + },
4.44 + log = { "client", "g" },
4.45 + },
4.46 + "rom/test_newlib_stat", "home/paulb/LICENCE.txt");
5.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
5.2 +++ b/conf/test_newlib_stat.list Tue Oct 22 23:07:50 2019 +0200
5.3 @@ -0,0 +1,37 @@
5.4 +entry test_newlib_stat
5.5 +roottask moe rom/test_newlib_stat.cfg
5.6 +module test_newlib_stat.cfg
5.7 +module e2test.fs
5.8 +module ned
5.9 +module l4re
5.10 +module test_newlib_stat
5.11 +module e2fsserver
5.12 +module blockserver
5.13 +module lib4re-c.so
5.14 +module lib4re-c-util.so
5.15 +module lib4re.so
5.16 +module lib4re-util.so
5.17 +module libblkid.so
5.18 +module libc_be_l4refile.so
5.19 +module libc_be_l4re.so
5.20 +module libc_be_socket_noop.so
5.21 +module libc_support_misc.so
5.22 +module libdl.so
5.23 +module libe2access.so
5.24 +module libe2p.so
5.25 +module libet.so
5.26 +module libext2fs_blockserver.so
5.27 +module libext2fs.so
5.28 +module libfsclient.so
5.29 +module libfsserver.so
5.30 +module libipc.so
5.31 +module libl4sys-direct.so
5.32 +module libl4sys.so
5.33 +module libl4util.so
5.34 +module libld-l4.so
5.35 +module libpthread.so
5.36 +module libstdc++.so
5.37 +module libsupc++.so
5.38 +module libsupport.so
5.39 +module libuc_c.so
5.40 +module libuuid.so
6.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
6.2 +++ b/lseek.c Tue Oct 22 23:07:50 2019 +0200
6.3 @@ -0,0 +1,102 @@
6.4 +#include <fcntl.h>
6.5 +#include <string.h>
6.6 +#include <unistd.h>
6.7 +
6.8 +#include "debug.h"
6.9 +
6.10 +/* Messages. */
6.11 +
6.12 +char message[] = "Hello file!\n";
6.13 +char addition[] = " Goodbye from file!\n";
6.14 +
6.15 +/* Definitions from fcntl.h and fcntl-linux.h. */
6.16 +
6.17 +#define O_CREAT_LINUX 0x0100
6.18 +
6.19 +
6.20 +
6.21 +/* Read from the file. */
6.22 +
6.23 +static void read_file(int fd)
6.24 +{
6.25 + char buffer[100];
6.26 + int available = read(fd, buffer, 100);
6.27 +
6.28 + if (available == -1)
6.29 + debug("Failed to read file!\n");
6.30 + else if (!available)
6.31 + debug("Nothing read.\n");
6.32 + else
6.33 + debug_len(buffer, available);
6.34 +}
6.35 +
6.36 +/* Main program. */
6.37 +
6.38 +int main(int argc, char *argv[], char *envp[])
6.39 +{
6.40 + int fd;
6.41 + off_t pos;
6.42 +
6.43 + if (argc < 2)
6.44 + {
6.45 + debug("No filename specified!\n");
6.46 + return 1;
6.47 + }
6.48 +
6.49 + fd = open(argv[1], O_CREAT_LINUX | O_RDWR);
6.50 +
6.51 + if (fd == -1)
6.52 + {
6.53 + debug("Failed to open file!\n");
6.54 + return 1;
6.55 + }
6.56 +
6.57 + /* Write and then read back. */
6.58 +
6.59 + if (write(fd, message, strlen(message)) == -1)
6.60 + {
6.61 + debug("Failed to write to file!\n");
6.62 + return 1;
6.63 + }
6.64 +
6.65 + if (lseek(fd, 0, SEEK_SET) == -1)
6.66 + {
6.67 + debug("Failed to seek relative to start of file!\n");
6.68 + return 1;
6.69 + }
6.70 +
6.71 + read_file(fd);
6.72 +
6.73 + pos = lseek(fd, -1, SEEK_END);
6.74 + if (pos == -1)
6.75 + {
6.76 + debug("Failed to seek relative to end of file!\n");
6.77 + return 1;
6.78 + }
6.79 +
6.80 + if (write(fd, addition, strlen(addition)) == -1)
6.81 + {
6.82 + debug("Failed to write to file!\n");
6.83 + return 1;
6.84 + }
6.85 +
6.86 + if (lseek(fd, 0, SEEK_SET) == -1)
6.87 + {
6.88 + debug("Failed to seek relative to start of file!\n");
6.89 + return 1;
6.90 + }
6.91 +
6.92 + read_file(fd);
6.93 +
6.94 + if (close(fd) == -1)
6.95 + {
6.96 + debug("Failed to close file!\n");
6.97 + return 1;
6.98 + }
6.99 +
6.100 + /* Finish off. */
6.101 +
6.102 + debug("At end of program!\n");
6.103 +
6.104 + return 0;
6.105 +}
7.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
7.2 +++ b/stat.c Tue Oct 22 23:07:50 2019 +0200
7.3 @@ -0,0 +1,40 @@
7.4 +#include <stdio.h>
7.5 +#include <sys/stat.h>
7.6 +#include <unistd.h>
7.7 +
7.8 +#include "debug.h"
7.9 +
7.10 +#define logprintf(fmt, ...) sprintf(buffer, fmt, __VA_ARGS__); debug(buffer);
7.11 +
7.12 +
7.13 +
7.14 +/* Main program. */
7.15 +
7.16 +int main(int argc, char *argv[], char *envp[])
7.17 +{
7.18 + char buffer[32];
7.19 + struct stat st;
7.20 +
7.21 + if (argc < 2)
7.22 + {
7.23 + debug("No filename given.\n");
7.24 + return 1;
7.25 + }
7.26 +
7.27 + if (stat(argv[1], &st))
7.28 + {
7.29 + debug("Failed to get metadata.\n");
7.30 + return 1;
7.31 + }
7.32 +
7.33 + logprintf("mode: %o\n", st.st_mode);
7.34 + logprintf("uid: %d\n", st.st_uid);
7.35 + logprintf("gid: %d\n", st.st_gid);
7.36 + logprintf("size: %ld\n", st.st_size);
7.37 +
7.38 + /* Finish off. */
7.39 +
7.40 + debug("At end of program!\n");
7.41 +
7.42 + return 0;
7.43 +}