1.1 --- a/include/e2access/image.h Sun Mar 24 21:02:47 2019 +0100
1.2 +++ b/include/e2access/image.h Mon Mar 25 00:04:18 2019 +0100
1.3 @@ -45,10 +45,15 @@
1.4 struct ext2_inode *inode);
1.5
1.6 errcode_t image_make_next_dir(ext2_filsys fs, ext2_ino_t ino_dir,
1.7 - const char **basename, ext2_ino_t *ino);
1.8 + const char **basename, __u16 mode, __u16 uid,
1.9 + __u16 gid, ext2_ino_t *ino);
1.10
1.11 errcode_t image_make_dirs(ext2_filsys fs, const char **pathname,
1.12 - ext2_ino_t ino_dir);
1.13 + ext2_ino_t ino_dir, __u16 mode, __u16 uid,
1.14 + __u16 gid);
1.15 +
1.16 +void image_set_metadata(struct ext2_inode *inode, int clean, __u16 mode,
1.17 + __u16 uid, __u16 gid);
1.18
1.19 int _image_isdir(ext2_filsys fs, ext2_ino_t ino);
1.20
2.1 --- a/lib/src/image.c Sun Mar 24 21:02:47 2019 +0100
2.2 +++ b/lib/src/image.c Mon Mar 25 00:04:18 2019 +0100
2.3 @@ -69,15 +69,24 @@
2.4
2.5 /* Populate the inode details. */
2.6
2.7 - memset(&inode_file, 0, sizeof(inode_file));
2.8 -
2.9 - inode_file.i_mode = LINUX_S_IFREG | mode;
2.10 - inode_file.i_uid = uid;
2.11 - inode_file.i_gid = gid;
2.12 + image_set_metadata(&inode_file, 1, LINUX_S_IFREG | mode, uid, gid);
2.13
2.14 return ext2fs_write_new_inode(fs, *ino_file, &inode_file);
2.15 }
2.16
2.17 +/* Set the mode, user and group metadata for a file. */
2.18 +
2.19 +void image_set_metadata(struct ext2_inode *inode, int clean, __u16 mode,
2.20 + __u16 uid, __u16 gid)
2.21 +{
2.22 + if (clean)
2.23 + memset(inode, 0, sizeof(*inode));
2.24 +
2.25 + inode->i_mode = mode;
2.26 + inode->i_uid = uid;
2.27 + inode->i_gid = gid;
2.28 +}
2.29 +
2.30 /* Find an object in the given directory with the given name in the filesystem
2.31 image, updating the name reference to refer to the next component. */
2.32
2.33 @@ -180,8 +189,10 @@
2.34 the name reference to refer to the next component. */
2.35
2.36 errcode_t image_make_next_dir(ext2_filsys fs, ext2_ino_t ino_dir,
2.37 - const char **basename, ext2_ino_t *ino)
2.38 + const char **basename, __u16 mode, __u16 uid,
2.39 + __u16 gid, ext2_ino_t *ino)
2.40 {
2.41 + struct ext2_inode inode_dir;
2.42 char *end = (char *) path_component_end(*basename);
2.43 char endchar = *end;
2.44 errcode_t retval = 0;
2.45 @@ -197,11 +208,23 @@
2.46 {
2.47 /* Create an inode in the directory. */
2.48
2.49 - retval = ext2fs_new_inode(fs, ino_dir, LINUX_S_IFDIR | 0755, 0, ino);
2.50 + retval = ext2fs_new_inode(fs, ino_dir, LINUX_S_IFDIR | mode, 0, ino);
2.51 if (retval)
2.52 return retval;
2.53
2.54 + /* Make the directory and update the metadata (due to ext2fs_mkdir
2.55 + limitation). */
2.56 +
2.57 retval = ext2fs_mkdir(fs, ino_dir, *ino, *basename);
2.58 + if (!retval)
2.59 + {
2.60 + retval = ext2fs_read_inode(fs, *ino, &inode_dir);
2.61 + if (!retval)
2.62 + {
2.63 + image_set_metadata(&inode_dir, 0, LINUX_S_IFDIR | mode, uid, gid);
2.64 + retval = ext2fs_write_inode(fs, *ino, &inode_dir);
2.65 + }
2.66 + }
2.67 }
2.68
2.69 /* Restore the path separator and update the current component. */
2.70 @@ -218,14 +241,14 @@
2.71 /* Make directories descending to the given path in the filesystem image. */
2.72
2.73 errcode_t image_make_dirs(ext2_filsys fs, const char **pathname,
2.74 - ext2_ino_t ino_dir)
2.75 + ext2_ino_t ino_dir, __u16 mode, __u16 uid, __u16 gid)
2.76 {
2.77 ext2_ino_t ino;
2.78 errcode_t retval;
2.79
2.80 while (**pathname)
2.81 {
2.82 - retval = image_make_next_dir(fs, ino_dir, pathname, &ino);
2.83 + retval = image_make_next_dir(fs, ino_dir, pathname, mode, uid, gid, &ino);
2.84 if (retval)
2.85 return retval;
2.86