]> wimlib.net Git - wimlib/commitdiff
Move wim_pathname_to_stream() to mount_image.c
authorEric Biggers <ebiggers3@gmail.com>
Mon, 26 May 2014 04:21:05 +0000 (23:21 -0500)
committerEric Biggers <ebiggers3@gmail.com>
Mon, 26 May 2014 04:21:05 +0000 (23:21 -0500)
include/wimlib/dentry.h
src/dentry.c
src/mount_image.c

index 5067cfcca83d6e39e67ba9fcd892d7011f8e50be..e687e9cb994ac9e73110b55f4f791c86c2d5fb2b 100644 (file)
@@ -220,20 +220,6 @@ extern struct wim_dentry *
 get_parent_dentry(struct WIMStruct *wim, const tchar *path,
                  CASE_SENSITIVITY_TYPE case_type);
 
-#ifdef WITH_FUSE
-
-#define LOOKUP_FLAG_ADS_OK             0x00000001
-#define LOOKUP_FLAG_DIRECTORY_OK       0x00000002
-
-extern int
-wim_pathname_to_stream(WIMStruct *wim,
-                      const tchar *path,
-                      int lookup_flags,
-                      struct wim_dentry **dentry_ret,
-                      struct wim_lookup_table_entry **lte_ret,
-                      u16 *stream_idx_ret);
-#endif
-
 extern int
 calculate_dentry_full_path(struct wim_dentry *dentry);
 
index 9c32bcb68130bc2459dbc0ad8bbab0d740e80f45..7d108a88e8e93c0e20f01b39b00aa238b104c571 100644 (file)
@@ -775,72 +775,6 @@ get_parent_dentry(WIMStruct *wim, const tchar *path,
        return get_dentry(wim, buf, case_type);
 }
 
-#ifdef WITH_FUSE
-/* Finds the dentry, lookup table entry, and stream index for a WIM file stream,
- * given a path name.
- *
- * Currently, lookups of this type are only needed if FUSE is enabled.  */
-int
-wim_pathname_to_stream(WIMStruct *wim,
-                      const tchar *path,
-                      int lookup_flags,
-                      struct wim_dentry **dentry_ret,
-                      struct wim_lookup_table_entry **lte_ret,
-                      u16 *stream_idx_ret)
-{
-       struct wim_dentry *dentry;
-       struct wim_lookup_table_entry *lte;
-       u16 stream_idx;
-       const tchar *stream_name = NULL;
-       struct wim_inode *inode;
-       tchar *p = NULL;
-
-       if (lookup_flags & LOOKUP_FLAG_ADS_OK) {
-               stream_name = path_stream_name(path);
-               if (stream_name) {
-                       p = (tchar*)stream_name - 1;
-                       *p = T('\0');
-               }
-       }
-
-       dentry = get_dentry(wim, path, WIMLIB_CASE_SENSITIVE);
-       if (p)
-               *p = T(':');
-       if (!dentry)
-               return -errno;
-
-       inode = dentry->d_inode;
-
-       if (!inode->i_resolved)
-               if (inode_resolve_streams(inode, wim->lookup_table, false))
-                       return -EIO;
-
-       if (!(lookup_flags & LOOKUP_FLAG_DIRECTORY_OK)
-             && inode_is_directory(inode))
-               return -EISDIR;
-
-       if (stream_name) {
-               struct wim_ads_entry *ads_entry;
-
-               ads_entry = inode_get_ads_entry(inode, stream_name);
-               if (!ads_entry)
-                       return -errno;
-
-               stream_idx = ads_entry - inode->i_ads_entries + 1;
-               lte = ads_entry->lte;
-       } else {
-               lte = inode_unnamed_stream_resolved(inode, &stream_idx);
-       }
-       if (dentry_ret)
-               *dentry_ret = dentry;
-       if (lte_ret)
-               *lte_ret = lte;
-       if (stream_idx_ret)
-               *stream_idx_ret = stream_idx;
-       return 0;
-}
-#endif /* WITH_FUSE  */
-
 /* Creates an unlinked directory entry. */
 int
 new_dentry(const tchar *name, struct wim_dentry **dentry_ret)
index 81796cbc9c6b6ace9467c8d857e556832ce4ef79..0e77169cea9b99abef19ab3dd9a36bd169ffac6d 100644 (file)
@@ -195,12 +195,6 @@ wimfs_get_WIMStruct(void)
        return wimfs_get_context()->wim;
 }
 
-static inline int
-get_lookup_flags(const struct wimfs_context *ctx)
-{
-       return ctx->default_lookup_flags;
-}
-
 /* Is write permission requested on the file?  */
 static inline bool
 flags_writable(int open_flags)
@@ -356,6 +350,81 @@ wim_pathname_to_inode(WIMStruct *wim, const char *path)
        return dentry->d_inode;
 }
 
+/* Can look up named data stream with colon syntax  */
+#define LOOKUP_FLAG_ADS_OK             0x01
+
+/* Can look up directory (otherwise get -ENOTDIR)  */
+#define LOOKUP_FLAG_DIRECTORY_OK       0x02
+
+/*
+ * Translate a path into the corresponding dentry, lookup table entry, and
+ * stream index in the mounted WIM image.
+ *
+ * Returns 0 or a -errno code.  All of @dentry_ret, @lte_ret, and
+ * @stream_idx_ret are optional.
+ */
+static int
+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)
+{
+       WIMStruct *wim = ctx->wim;
+       struct wim_dentry *dentry;
+       struct wim_lookup_table_entry *lte;
+       u16 stream_idx;
+       const tchar *stream_name = NULL;
+       struct wim_inode *inode;
+       tchar *p = NULL;
+
+       lookup_flags |= ctx->default_lookup_flags;
+
+       if (lookup_flags & LOOKUP_FLAG_ADS_OK) {
+               stream_name = path_stream_name(path);
+               if (stream_name) {
+                       p = (tchar*)stream_name - 1;
+                       *p = T('\0');
+               }
+       }
+
+       dentry = get_dentry(wim, path, WIMLIB_CASE_SENSITIVE);
+       if (p)
+               *p = T(':');
+       if (!dentry)
+               return -errno;
+
+       inode = dentry->d_inode;
+
+       if (!inode->i_resolved)
+               if (inode_resolve_streams(inode, wim->lookup_table, false))
+                       return -EIO;
+
+       if (!(lookup_flags & LOOKUP_FLAG_DIRECTORY_OK)
+             && inode_is_directory(inode))
+               return -EISDIR;
+
+       if (stream_name) {
+               struct wim_ads_entry *ads_entry;
+
+               ads_entry = inode_get_ads_entry(inode, stream_name);
+               if (!ads_entry)
+                       return -errno;
+
+               stream_idx = ads_entry - inode->i_ads_entries + 1;
+               lte = ads_entry->lte;
+       } else {
+               lte = inode_unnamed_stream_resolved(inode, &stream_idx);
+       }
+       if (dentry_ret)
+               *dentry_ret = dentry;
+       if (lte_ret)
+               *lte_ret = lte;
+       if (stream_idx_ret)
+               *stream_idx_ret = stream_idx;
+       return 0;
+}
+
 /*
  * Create a new file in the mounted WIM image.
  *
@@ -1199,9 +1268,7 @@ wimfs_getattr(const char *path, struct stat *stbuf)
        struct wim_lookup_table_entry *lte;
        int ret;
 
-       ret = wim_pathname_to_stream(ctx->wim, path,
-                                    get_lookup_flags(ctx) |
-                                       LOOKUP_FLAG_DIRECTORY_OK,
+       ret = wim_pathname_to_stream(ctx, path, LOOKUP_FLAG_DIRECTORY_OK,
                                     &dentry, &lte, NULL);
        if (ret)
                return ret;
@@ -1477,8 +1544,7 @@ wimfs_open(const char *path, struct fuse_file_info *fi)
        struct wimfs_fd *fd;
        int ret;
 
-       ret = wim_pathname_to_stream(ctx->wim, path, get_lookup_flags(ctx),
-                                    &dentry, &lte, &stream_idx);
+       ret = wim_pathname_to_stream(ctx, path, 0, &dentry, &lte, &stream_idx);
        if (ret)
                return ret;
 
@@ -1801,9 +1867,7 @@ wimfs_truncate(const char *path, off_t size)
        int ret;
        int fd;
 
-       ret = wim_pathname_to_stream(ctx->wim, path, get_lookup_flags(ctx),
-                                    &dentry, &lte, &stream_idx);
-
+       ret = wim_pathname_to_stream(ctx, path, 0, &dentry, &lte, &stream_idx);
        if (ret)
                return ret;
 
@@ -1836,9 +1900,7 @@ wimfs_unlink(const char *path)
        u16 stream_idx;
        int ret;
 
-       ret = wim_pathname_to_stream(ctx->wim, path, get_lookup_flags(ctx),
-                                    &dentry, NULL, &stream_idx);
-
+       ret = wim_pathname_to_stream(ctx, path, 0, &dentry, NULL, &stream_idx);
        if (ret)
                return ret;