X-Git-Url: https://wimlib.net/git/?p=wimlib;a=blobdiff_plain;f=src%2Fmount_image.c;h=2e50d6c3422c2e650727917caba50a38d8ae90e1;hp=734afe48073c21bdabcab74a89390e6fa43e3161;hb=f18b7fc3361c4daac0ddd104af65a8eff8466fec;hpb=3df040b57bf40f45a636fa4a012ba1eeb6157e92 diff --git a/src/mount_image.c b/src/mount_image.c index 734afe48..2e50d6c3 100644 --- a/src/mount_image.c +++ b/src/mount_image.c @@ -10,20 +10,18 @@ /* * Copyright (C) 2012, 2013, 2014 Eric Biggers * - * This file is part of wimlib, a library for working with WIM files. + * This file is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the Free + * Software Foundation; either version 3 of the License, or (at your option) any + * later version. * - * wimlib is free software; you can redistribute it and/or modify it under the - * terms of the GNU General Public License as published by the Free - * Software Foundation; either version 3 of the License, or (at your option) - * any later version. - * - * wimlib is distributed in the hope that it will be useful, but WITHOUT ANY - * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - * A PARTICULAR PURPOSE. See the GNU General Public License for more + * This file is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more * details. * - * You should have received a copy of the GNU General Public License - * along with wimlib; if not, see http://www.gnu.org/licenses/. + * You should have received a copy of the GNU Lesser General Public License + * along with this file; if not, see http://www.gnu.org/licenses/. */ #ifdef HAVE_CONFIG_H @@ -39,19 +37,12 @@ # error "FUSE mount not supported on Windows! Please configure --without-fuse" #endif -#include "wimlib/dentry.h" -#include "wimlib/encoding.h" -#include "wimlib/metadata.h" -#include "wimlib/paths.h" -#include "wimlib/progress.h" -#include "wimlib/reparse.h" -#include "wimlib/timestamp.h" -#include "wimlib/unix_data.h" -#include "wimlib/write.h" -#include "wimlib/xml.h" +#define FUSE_USE_VERSION 26 +#include #include #include +#include #include #include #include @@ -63,9 +54,17 @@ #include #include -#define FUSE_USE_VERSION 26 -#include -#include +#include "wimlib/dentry.h" +#include "wimlib/encoding.h" +#include "wimlib/lookup_table.h" +#include "wimlib/metadata.h" +#include "wimlib/paths.h" +#include "wimlib/progress.h" +#include "wimlib/reparse.h" +#include "wimlib/timestamp.h" +#include "wimlib/unix_data.h" +#include "wimlib/write.h" +#include "wimlib/xml.h" #ifndef O_NOFOLLOW # define O_NOFOLLOW 0 /* Security only... */ @@ -325,15 +324,7 @@ close_wimfs_fd(struct wimfs_fd *fd) if (fd->f_idx < inode->i_next_fd) inode->i_next_fd = fd->f_idx; FREE(fd); - if (--inode->i_num_opened_fds == 0) { - /* The last file descriptor to this inode was closed. */ - FREE(inode->i_fds); - inode->i_fds = NULL; - inode->i_num_allocated_fds = 0; - if (inode->i_nlink == 0) - /* No links to this inode remain. Get rid of it. */ - free_inode(inode); - } + inode_dec_num_opened_fds(inode); return ret; } @@ -373,12 +364,12 @@ wim_pathname_to_stream(const struct wimfs_context *ctx, const char *path, int lookup_flags, struct wim_dentry **dentry_ret, struct wim_lookup_table_entry **lte_ret, - u16 *stream_idx_ret) + unsigned *stream_idx_ret) { WIMStruct *wim = ctx->wim; struct wim_dentry *dentry; struct wim_lookup_table_entry *lte; - u16 stream_idx; + unsigned stream_idx; const char *stream_name = NULL; struct wim_inode *inode; char *p = NULL; @@ -592,11 +583,11 @@ inode_to_stbuf(const struct wim_inode *inode, stbuf->st_mtim = wim_timestamp_to_timespec(inode->i_last_write_time); stbuf->st_ctim = stbuf->st_mtim; #else - stbuf->st_atime = wim_timestamp_to_unix(inode->i_last_access_time); - stbuf->st_mtime = wim_timestamp_to_unix(inode->i_last_write_time); + stbuf->st_atime = wim_timestamp_to_time_t(inode->i_last_access_time); + stbuf->st_mtime = wim_timestamp_to_time_t(inode->i_last_write_time); stbuf->st_ctime = stbuf->st_mtime; #endif - stbuf->st_blocks = (stbuf->st_size + 511) / 512; + stbuf->st_blocks = DIV_ROUND_UP(stbuf->st_size, 512); return 0; } @@ -604,7 +595,7 @@ inode_to_stbuf(const struct wim_inode *inode, static void touch_inode(struct wim_inode *inode) { - u64 now = get_wim_timestamp(); + u64 now = now_as_wim_timestamp(); inode->i_last_access_time = now; inode->i_last_write_time = now; } @@ -681,7 +672,7 @@ retry: */ static int extract_resource_to_staging_dir(struct wim_inode *inode, - u16 stream_idx, + unsigned stream_idx, struct wim_lookup_table_entry **lte_ptr, off_t size, const struct wimfs_context *ctx) @@ -1146,7 +1137,7 @@ commit_image(struct wimfs_context *ctx, int unmount_flags, mqd_t mq) return wimlib_overwrite(ctx->wim, write_flags, 0); } -/* In the case of an allow_other mount, only the owner and root should be +/* In the case of an allow_other mount, only the mount owner and root are * allowed to unmount the filesystem. */ static bool may_unmount_wimfs(void) @@ -1440,12 +1431,10 @@ wimfs_link(const char *existing_path, const char *new_path) if (new_dentry(new_name, &new_alias)) return -ENOMEM; - new_alias->d_inode = inode; - inode_add_dentry(new_alias, inode); + inode_ref_streams(inode); + d_associate(new_alias, inode); dentry_add_child(dir, new_alias); touch_inode(dir->d_inode); - inode->i_nlink++; - inode_ref_streams(inode); return 0; } @@ -1586,7 +1575,7 @@ wimfs_open(const char *path, struct fuse_file_info *fi) struct wim_dentry *dentry; struct wim_inode *inode; struct wim_lookup_table_entry *lte; - u16 stream_idx; + unsigned stream_idx; struct wimfs_fd *fd; int ret; @@ -1914,7 +1903,7 @@ wimfs_truncate(const char *path, off_t size) const struct wimfs_context *ctx = wimfs_get_context(); struct wim_dentry *dentry; struct wim_lookup_table_entry *lte; - u16 stream_idx; + unsigned stream_idx; int ret; int fd; @@ -1948,7 +1937,7 @@ wimfs_unlink(const char *path) { const struct wimfs_context *ctx = wimfs_get_context(); struct wim_dentry *dentry; - u16 stream_idx; + unsigned stream_idx; int ret; ret = wim_pathname_to_stream(ctx, path, 0, &dentry, NULL, &stream_idx); @@ -1984,15 +1973,15 @@ wimfs_utimens(const char *path, const struct timespec tv[2]) if (tv[0].tv_nsec != UTIME_OMIT) { if (tv[0].tv_nsec == UTIME_NOW) - inode->i_last_access_time = get_wim_timestamp(); + inode->i_last_access_time = now_as_wim_timestamp(); else - inode->i_last_access_time = timespec_to_wim_timestamp(tv[0]); + inode->i_last_access_time = timespec_to_wim_timestamp(&tv[0]); } if (tv[1].tv_nsec != UTIME_OMIT) { if (tv[1].tv_nsec == UTIME_NOW) - inode->i_last_write_time = get_wim_timestamp(); + inode->i_last_write_time = now_as_wim_timestamp(); else - inode->i_last_write_time = timespec_to_wim_timestamp(tv[1]); + inode->i_last_write_time = timespec_to_wim_timestamp(&tv[1]); } return 0; } @@ -2007,8 +1996,8 @@ wimfs_utime(const char *path, struct utimbuf *times) if (!inode) return -errno; - inode->i_last_access_time = unix_timestamp_to_wim(times->actime); - inode->i_last_write_time = unix_timestamp_to_wim(times->modtime); + inode->i_last_access_time = time_t_to_wim_timestamp(times->actime); + inode->i_last_write_time = time_t_to_wim_timestamp(times->modtime); return 0; } #endif /* !HAVE_UTIMENSAT */ @@ -2102,7 +2091,7 @@ wimlib_mount_image(WIMStruct *wim, int image, const char *dir, if (mount_flags & WIMLIB_MOUNT_FLAG_READWRITE) { if (!wim->filename) return WIMLIB_ERR_NO_FILENAME; - ret = can_delete_from_wim(wim); + ret = can_modify_wim(wim); if (ret) return ret; } @@ -2437,7 +2426,7 @@ do_unmount_commit(const char *dir, int unmount_flags, ret = do_unmount(dir); if (progfunc) { /* Terminate the progress thread. */ - char empty[0]; + char empty[1]; mq_send(mq, empty, 0, 1); pthread_join(commit_progress_tid, NULL); }