]> wimlib.net Git - wimlib/blobdiff - src/mount.c
Store dentry children in red-black trees
[wimlib] / src / mount.c
index ac56415ecd5906607e69f3e68987df7443a2bfcc..ed428fca58907d1b943fb51b7590cbd934c92ace 100644 (file)
@@ -956,7 +956,7 @@ static int wimfs_ftruncate(const char *path, off_t size,
        struct wimlib_fd *fd = (struct wimlib_fd*)(uintptr_t)fi->fh;
        int ret = ftruncate(fd->staging_fd, size);
        if (ret != 0)
-               return ret;
+               return -errno;
        if (fd->f_lte && size < fd->f_lte->resource_entry.original_size)
                fd->f_lte->resource_entry.original_size = size;
        return 0;
@@ -1249,9 +1249,9 @@ static int wimfs_opendir(const char *path, struct fuse_file_info *fi)
        struct inode *inode;
        int ret;
        struct wimlib_fd *fd = NULL;
-       struct wimfs_context *ctx = wimfs_get_context();
+       WIMStruct *w = wimfs_get_WIMStruct();
 
-       inode = wim_pathname_to_inode(ctx->wim, path);
+       inode = wim_pathname_to_inode(w, path);
        if (!inode)
                return -ENOENT;
        if (!inode_is_directory(inode))
@@ -1308,6 +1308,18 @@ static int wimfs_read(const char *path, char *buf, size_t size,
        }
 }
 
+struct fill_params {
+       void *buf;
+       fuse_fill_dir_t filler;
+};
+
+static int dentry_fuse_fill(struct dentry *dentry, void *arg)
+{
+       struct fill_params *fill_params = arg;
+       return fill_params->filler(fill_params->buf, dentry->file_name_utf8,
+                                  NULL, 0);
+}
+
 /* Fills in the entries of the directory specified by @path using the
  * FUSE-provided function @filler.  */
 static int wimfs_readdir(const char *path, void *buf, fuse_fill_dir_t filler,
@@ -1315,27 +1327,22 @@ static int wimfs_readdir(const char *path, void *buf, fuse_fill_dir_t filler,
 {
        struct wimlib_fd *fd = (struct wimlib_fd*)(uintptr_t)fi->fh;
        struct inode *inode;
-       struct dentry *child;
 
        if (!fd)
                return -EBADF;
 
        inode = fd->f_inode;
 
+       struct fill_params fill_params = {
+               .buf = buf,
+               .filler = filler,
+       };
+
        filler(buf, ".", NULL, 0);
        filler(buf, "..", NULL, 0);
 
-       child = inode->children;
-
-       if (!child)
-               return 0;
-
-       do {
-               if (filler(buf, child->file_name_utf8, NULL, 0))
-                       return 0;
-               child = child->next;
-       } while (child != inode->children);
-       return 0;
+       return for_dentry_in_rbtree(inode->children.rb_node,
+                                   dentry_fuse_fill, &fill_params);
 }
 
 
@@ -1439,7 +1446,7 @@ static int wimfs_rename(const char *from, const char *to)
                         * directory */
                        if (!dentry_is_directory(dst))
                                return -ENOTDIR;
-                       if (dst->d_inode->children != NULL)
+                       if (inode_has_children(dst->d_inode))
                                return -ENOTEMPTY;
                }
                parent_of_dst = dst->parent;
@@ -1692,6 +1699,8 @@ static int wimfs_utime(const char *path, struct utimbuf *times)
 {
        struct dentry *dentry;
        struct inode *inode;
+       WIMStruct *w = wimfs_get_WIMStruct();
+
        dentry = get_dentry(w, path);
        if (!dentry)
                return -ENOENT;