1.1 --- a/server/src/main.cc Sat Feb 09 18:21:18 2019 +0100
1.2 +++ b/server/src/main.cc Sun Feb 10 21:54:06 2019 +0100
1.3 @@ -28,12 +28,14 @@
1.4 #include <l4/sys/err.h>
1.5 #include <l4/sys/types.h>
1.6
1.7 +#include <fcntl.h>
1.8 #include <stdlib.h>
1.9 #include <stdio.h>
1.10 #include <unistd.h>
1.11
1.12 #include <ext2fs/ext2fs.h>
1.13 #include <e2access/image.h>
1.14 +#include <e2access/path.h>
1.15
1.16 #include <fsclient/client.h>
1.17 #include <fsclient/fs_client.h>
1.18 @@ -181,8 +183,6 @@
1.19 _obj.position = ipc_message_get_word(msg, 0);
1.20 size_t length = ipc_message_get_word(msg, 1);
1.21
1.22 - printf("write at %d length %d\n", _obj.position, length);
1.23 -
1.24 if (ext2fs_file_lseek(_file, _obj.position, EXT2_SEEK_SET, 0))
1.25 {
1.26 error(msg, -L4_EIO);
1.27 @@ -234,6 +234,10 @@
1.28 ext2_filsys _fs;
1.29 const char *_devname;
1.30
1.31 + /* NOTE: To be configured by a user identity. */
1.32 +
1.33 + __u16 _mode = 0x644, _uid = 1000, _gid = 1000;
1.34 +
1.35 public:
1.36 explicit Fs_server(ext2_filsys fs, const char *devname)
1.37 : _fs(fs), _devname(devname)
1.38 @@ -260,10 +264,10 @@
1.39
1.40 void open(ipc_message_t *msg)
1.41 {
1.42 - int flags;
1.43 + int flags, ext2flags = 0;
1.44 fs_object_t fsobj;
1.45 ext2_file_t file;
1.46 - ext2_ino_t ino_file;
1.47 + ext2_ino_t ino_file, ino_parent;
1.48 struct ext2_inode inode;
1.49 long err;
1.50
1.51 @@ -284,17 +288,47 @@
1.52
1.53 const char *path = (const char *) fsobj.buffer;
1.54
1.55 - /* Find the object. If it cannot be located, return an error. */
1.56 + /* Find the object. If it cannot be located, return an error if it is not to
1.57 + be created. */
1.58
1.59 - if (image_find_path(_fs, &path, &ino_file))
1.60 + if (image_find_path(_fs, &path, &ino_parent))
1.61 {
1.62 - error(msg, -L4_EIO);
1.63 - return;
1.64 + if (flags & O_CREAT)
1.65 + {
1.66 + ext2flags |= EXT2_FILE_CREATE;
1.67 +
1.68 + /* Only create the file if it has a parent directory. */
1.69 +
1.70 + if (!_image_isdir(_fs, ino_parent) || !path_is_leafname(path))
1.71 + {
1.72 + error(msg, -L4_EIO);
1.73 + return;
1.74 + }
1.75 +
1.76 + errcode_t retval = image_create_file(_fs, ino_parent, path, _mode, _uid, _gid, &ino_file);
1.77 + if (retval)
1.78 + {
1.79 + error(msg, -L4_EIO);
1.80 + return;
1.81 + }
1.82 + }
1.83 + else
1.84 + {
1.85 + error(msg, -L4_EIO);
1.86 + return;
1.87 + }
1.88 }
1.89 + else
1.90 + ino_file = ino_parent;
1.91 +
1.92 + /* Set the appropriate ext2fs flags. */
1.93 +
1.94 + if ((flags & O_RDWR) || (flags & O_WRONLY))
1.95 + ext2flags |= EXT2_FILE_WRITE;
1.96
1.97 /* Obtain a file via the filesystem. */
1.98
1.99 - if (ext2fs_file_open(_fs, ino_file, flags, &file))
1.100 + if (ext2fs_file_open(_fs, ino_file, ext2flags, &file))
1.101 {
1.102 error(msg, -L4_EIO);
1.103 return;
1.104 @@ -363,7 +397,7 @@
1.105 {
1.106 l4_cap_idx_t server;
1.107 char *devname;
1.108 - long err;
1.109 + errcode_t retval;
1.110
1.111 if (argc < 2)
1.112 {
1.113 @@ -376,11 +410,17 @@
1.114 devname = argv[1];
1.115
1.116 ext2_filsys fs = NULL;
1.117 - int flags = EXT2_FLAG_RW; // | EXT2_FLAG_SOFTSUPP_FEATURES | EXT2_FLAG_64BITS;
1.118 + int ext2flags = EXT2_FLAG_RW; // | EXT2_FLAG_SOFTSUPP_FEATURES | EXT2_FLAG_64BITS;
1.119
1.120 - if ((err = ext2fs_open(devname, flags, 0, 0, blockserver_io_manager, &fs)))
1.121 + if ((retval = ext2fs_open(devname, ext2flags, 0, 0, blockserver_io_manager, &fs)))
1.122 {
1.123 - printf("Could not obtain filesystem: %ld.\n", err);
1.124 + printf("Could not obtain filesystem: %ld.\n", retval);
1.125 + return 1;
1.126 + }
1.127 +
1.128 + if ((retval = ext2fs_read_bitmaps(fs)))
1.129 + {
1.130 + printf("Could not obtain filesystem: %ld.\n", retval);
1.131 return 1;
1.132 }
1.133