]> wimlib.net Git - wimlib/blobdiff - src/mount_image.c
mount_image.c: Remove unnecessary gotos in alloc_wimfs_fd()
[wimlib] / src / mount_image.c
index 7c480ebc76c02c7af9808b87f151c5188a8506ae..7482ceb069106d8829fc83037b16740ae6115d59 100644 (file)
@@ -164,7 +164,8 @@ get_lookup_flags(const struct wimfs_context *ctx)
 static inline int
 flags_writable(int open_flags)
 {
-       return open_flags & (O_RDWR | O_WRONLY);
+       int accmode = (open_flags & O_ACCMODE);
+       return (accmode == O_RDWR || accmode == O_WRONLY);
 }
 
 /*
@@ -175,7 +176,7 @@ flags_writable(int open_flags)
  * @lte:       Lookup table entry for the stream (may be NULL)
  * @fd_ret:    Return the allocated file descriptor if successful.
  *
- * Return 0 iff successful or error code if unsuccessful.
+ * Return 0 iff successful or negative error code if unsuccessful.
  */
 static int
 alloc_wimfs_fd(struct wim_inode *inode,
@@ -196,20 +197,18 @@ alloc_wimfs_fd(struct wim_inode *inode,
                struct wimfs_fd **fds;
                u16 num_new_fds;
 
-               if (inode->i_num_allocated_fds == max_fds) {
-                       ret = -EMFILE;
-                       goto out;
-               }
+               if (inode->i_num_allocated_fds == max_fds)
+                       return -EMFILE;
+
                num_new_fds = min(fds_per_alloc,
                                  max_fds - inode->i_num_allocated_fds);
 
                fds = REALLOC(inode->i_fds,
                              (inode->i_num_allocated_fds + num_new_fds) *
                                sizeof(inode->i_fds[0]));
-               if (!fds) {
-                       ret = -ENOMEM;
-                       goto out;
-               }
+               if (!fds)
+                       return -ENOMEM;
+
                memset(&fds[inode->i_num_allocated_fds], 0,
                       num_new_fds * sizeof(fds[0]));
                inode->i_fds = fds;
@@ -218,10 +217,9 @@ alloc_wimfs_fd(struct wim_inode *inode,
        for (u16 i = 0; ; i++) {
                if (!inode->i_fds[i]) {
                        struct wimfs_fd *fd = CALLOC(1, sizeof(*fd));
-                       if (!fd) {
-                               ret = -ENOMEM;
-                               break;
-                       }
+                       if (!fd)
+                               return -ENOMEM;
+
                        fd->f_inode     = inode;
                        fd->f_lte       = lte;
                        filedes_invalidate(&fd->staging_fd);
@@ -233,12 +231,9 @@ alloc_wimfs_fd(struct wim_inode *inode,
                        if (lte)
                                lte->num_opened_fds++;
                        DEBUG("Allocated fd (idx = %u)", fd->idx);
-                       ret = 0;
-                       break;
+                       return 0;
                }
        }
-out:
-       return ret;
 }
 
 static void
@@ -667,6 +662,7 @@ extract_resource_to_staging_dir(struct wim_inode *inode,
                }
        }
 
+       lte_put_resource(new_lte);
        new_lte->refcnt              = inode->i_nlink;
        new_lte->resource_location   = RESOURCE_IN_STAGING_FILE;
        new_lte->staging_file_name   = staging_file_name;
@@ -2410,6 +2406,15 @@ wimlib_mount_image(WIMStruct *wim, int image, const char *dir,
        if (!wim || !dir)
                return WIMLIB_ERR_INVALID_PARAM;
 
+       if (mount_flags & ~(WIMLIB_MOUNT_FLAG_READWRITE |
+                           WIMLIB_MOUNT_FLAG_DEBUG |
+                           WIMLIB_MOUNT_FLAG_STREAM_INTERFACE_NONE |
+                           WIMLIB_MOUNT_FLAG_STREAM_INTERFACE_XATTR |
+                           WIMLIB_MOUNT_FLAG_STREAM_INTERFACE_WINDOWS |
+                           WIMLIB_MOUNT_FLAG_UNIX_DATA |
+                           WIMLIB_MOUNT_FLAG_ALLOW_OTHER))
+               return WIMLIB_ERR_INVALID_PARAM;
+
        if (mount_flags & WIMLIB_MOUNT_FLAG_READWRITE) {
                ret = can_delete_from_wim(wim);
                if (ret)
@@ -2465,8 +2470,10 @@ wimlib_mount_image(WIMStruct *wim, int image, const char *dir,
        DEBUG("Preparing arguments to fuse_main()");
 
        dir_copy = STRDUP(dir);
-       if (!dir_copy)
+       if (!dir_copy) {
+               ret = WIMLIB_ERR_NOMEM;
                goto out_free_message_queue_names;
+       }
 
        argc = 0;
        argv[argc++] = "wimlib";
@@ -2570,6 +2577,13 @@ wimlib_unmount_image(const char *dir, int unmount_flags,
        int ret;
        struct wimfs_context wimfs_ctx;
 
+       if (unmount_flags & ~(WIMLIB_UNMOUNT_FLAG_CHECK_INTEGRITY |
+                             WIMLIB_UNMOUNT_FLAG_COMMIT |
+                             WIMLIB_UNMOUNT_FLAG_REBUILD |
+                             WIMLIB_UNMOUNT_FLAG_RECOMPRESS |
+                             WIMLIB_UNMOUNT_FLAG_LAZY))
+               return WIMLIB_ERR_INVALID_PARAM;
+
        init_wimfs_context(&wimfs_ctx);
 
        ret = set_message_queue_names(&wimfs_ctx, dir);