From 12d5058b6fdcefbaef9d8d4a199d8bf5df3d5f30 Mon Sep 17 00:00:00 2001 From: Eric Biggers Date: Wed, 22 May 2013 18:44:44 -0500 Subject: [PATCH] wim_inode: Move file descriptors table into union --- include/wimlib/dentry.h | 18 +++++++++++------- src/dentry.c | 4 ---- src/mount_image.c | 9 +++++++-- 3 files changed, 18 insertions(+), 13 deletions(-) diff --git a/include/wimlib/dentry.h b/include/wimlib/dentry.h index a571e021..a6aa31d7 100644 --- a/include/wimlib/dentry.h +++ b/include/wimlib/dentry.h @@ -368,17 +368,21 @@ struct wim_inode { * Freed and set to NULL after the extraction is done (either * success or failure). */ tchar *i_extracted_file; + +#ifdef WITH_FUSE + /* Used only during image mount: Table of file descriptors that + * have been opened to this inode. The table is automatically + * freed when the last file descriptor is closed. */ + struct { + struct wimfs_fd **i_fds; + u16 i_num_opened_fds; + u16 i_num_allocated_fds; + }; +#endif }; /* Next alternate data stream ID to be assigned */ u32 i_next_stream_id; - -#ifdef WITH_FUSE - /* wimfs file descriptors table for the inode */ - u16 i_num_opened_fds; - u16 i_num_allocated_fds; - struct wimfs_fd **i_fds; -#endif }; #define inode_for_each_dentry(dentry, inode) \ diff --git a/src/dentry.c b/src/dentry.c index 70250a7f..fb430eca 100644 --- a/src/dentry.c +++ b/src/dentry.c @@ -1121,10 +1121,6 @@ free_inode(struct wim_inode *inode) destroy_ads_entry(&inode->i_ads_entries[i]); FREE(inode->i_ads_entries); } - #ifdef WITH_FUSE - wimlib_assert(inode->i_num_opened_fds == 0); - FREE(inode->i_fds); - #endif /* HACK: This may instead delete the inode from i_list, but the * hlist_del() behaves the same as list_del(). */ if (!hlist_unhashed(&inode->i_hlist)) diff --git a/src/mount_image.c b/src/mount_image.c index d9a03a99..ac914618 100644 --- a/src/mount_image.c +++ b/src/mount_image.c @@ -259,8 +259,13 @@ inode_put_fd(struct wim_inode *inode, struct wimfs_fd *fd) inode->i_fds[fd->idx] = NULL; FREE(fd); - if (--inode->i_num_opened_fds == 0 && inode->i_nlink == 0) - free_inode(inode); + if (--inode->i_num_opened_fds == 0) { + FREE(inode->i_fds); + inode->i_fds = NULL; + inode->i_num_allocated_fds = 0; + if (inode->i_nlink == 0) + free_inode(inode); + } } static int -- 2.43.0