X-Git-Url: https://wimlib.net/git/?p=wimlib;a=blobdiff_plain;f=src%2Fmount.c;h=e10287a6f58aa918aaa06852ba31b9a3ab1d5e25;hp=e07a11c3fbcfdfbd761d846c255302da75a811dd;hb=45c3ad86e44a05a169bfb1fa8ff318861bbf9fbf;hpb=29a09c1a5c20e1b04cc11ef24f5863bf8db7796c diff --git a/src/mount.c b/src/mount.c index e07a11c3..e10287a6 100644 --- a/src/mount.c +++ b/src/mount.c @@ -185,7 +185,7 @@ static int alloc_wimlib_fd(struct inode *inode, inode->num_opened_fds++; if (lte) lte->num_opened_fds++; - DEBUG("Allocated fd"); + DEBUG("Allocated fd (idx = %u)", fd->idx); return 0; } } @@ -193,11 +193,11 @@ static int alloc_wimlib_fd(struct inode *inode, static void inode_put_fd(struct inode *inode, struct wimlib_fd *fd) { - wimlib_assert(fd); - wimlib_assert(inode); + wimlib_assert(fd != NULL); + wimlib_assert(inode != NULL); wimlib_assert(fd->f_inode == inode); - wimlib_assert(inode->num_opened_fds); - wimlib_assert(fd->idx < inode->num_opened_fds); + wimlib_assert(inode->num_opened_fds != 0); + wimlib_assert(fd->idx < inode->num_allocated_fds); wimlib_assert(inode->fds[fd->idx] == fd); inode->fds[fd->idx] = NULL; @@ -746,6 +746,28 @@ static int wimfs_access(const char *path, int mask) return 0; } +static int wimfs_chmod(const char *path, mode_t mask) +{ + struct dentry *dentry; + struct wimfs_context *ctx = wimfs_get_context(); + struct inode *inode; + struct stat stbuf; + int ret; + + ret = lookup_resource(ctx->wim, path, + get_lookup_flags(ctx) | LOOKUP_FLAG_DIRECTORY_OK, + &dentry, NULL, NULL); + if (ret != 0) + return ret; + inode = dentry->d_inode; + inode_to_stbuf(inode, NULL, &stbuf); + if (mask == stbuf.st_mode) + return 0; + else + return -EPERM; + +} + static void inode_update_lte_ptr(struct inode *inode, struct lookup_table_entry *old_lte, struct lookup_table_entry *new_lte) @@ -1064,7 +1086,7 @@ static int wimfs_link(const char *to, const char *from) lte->refcnt++; } - link_dentry(from_dentry, from_dentry_parent); + dentry_add_child(from_dentry_parent, from_dentry); return 0; } @@ -1130,7 +1152,7 @@ static int wimfs_mkdir(const char *path, mode_t mode) newdir->d_inode->attributes |= FILE_ATTRIBUTE_DIRECTORY; newdir->d_inode->resolved = true; newdir->d_inode->ino = ctx->next_ino++; - link_dentry(newdir, parent); + dentry_add_child(parent, newdir); return 0; } @@ -1182,7 +1204,7 @@ static int wimfs_mknod(const char *path, mode_t mode, dev_t rdev) return -ENOMEM; dentry->d_inode->resolved = true; dentry->d_inode->ino = ctx->next_ino++; - link_dentry(dentry, parent); + dentry_add_child(parent, dentry); } return 0; } @@ -1308,6 +1330,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 +1349,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 +1468,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; @@ -1462,7 +1491,7 @@ static int wimfs_rename(const char *from, const char *to) src->file_name_utf8_len = file_name_utf8_len; unlink_dentry(src); - link_dentry(src, parent_of_dst); + dentry_add_child(parent_of_dst, src); return 0; } @@ -1582,7 +1611,7 @@ static int wimfs_symlink(const char *to, const char *from) if (inode_set_symlink(inode, to, ctx->wim->lookup_table, NULL) != 0) goto out_free_dentry; - link_dentry(dentry, dentry_parent); + dentry_add_child(dentry_parent, dentry); return 0; out_free_dentry: free_dentry(dentry); @@ -1692,6 +1721,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; @@ -1738,6 +1769,7 @@ static int wimfs_write(const char *path, const char *buf, size_t size, static struct fuse_operations wimfs_operations = { .access = wimfs_access, + .chmod = wimfs_chmod, .destroy = wimfs_destroy, #if 0 .fallocate = wimfs_fallocate,