]> wimlib.net Git - wimlib/commitdiff
ntfs.c => ntfs-apply.c
authorEric Biggers <ebiggers3@gmail.com>
Tue, 21 Aug 2012 22:48:01 +0000 (17:48 -0500)
committerEric Biggers <ebiggers3@gmail.com>
Tue, 21 Aug 2012 22:48:01 +0000 (17:48 -0500)
Makefile.am
configure.ac
src/dentry.c
src/dentry.h
src/ntfs-apply.c [moved from src/ntfs.c with 75% similarity]

index 9b00f8b9cb27607cdf1017414b7be0c19e4cd5ae..5d2d00e892a96361035dc3a62fc184459416ecd8 100644 (file)
@@ -31,8 +31,7 @@ libwim_la_SOURCES =           \
        src/lzx.h               \
        src/modify.c            \
        src/mount.c             \
-       src/ntfs.c              \
-       src/ntfs-3g_security.c  \
+       src/ntfs-apply.c        \
        src/resource.c          \
        src/security.c          \
        src/security.h          \
@@ -53,6 +52,11 @@ libwim_la_SOURCES =          \
        src/xpress-decomp.c     \
        src/xpress.h
 
+if WITH_NTFS_3G
+libwim_la_SOURCES += src/ntfs-3g_security.c
+endif
+
+
 EXTRA_libwim_la_SOURCES = src/sha1-ssse3.asm
 libwim_la_DEPENDENCIES = $(SSSE3_SHA1_OBJ)
 STRIP_FPIC = sh $(top_srcdir)/build-aux/strip_fPIC.sh
index c67ca43e9b601c352953d0249e6ec28ba9d9fa93..af814b9d89ab5b32c7619777588c0ebed94c7c73 100644 (file)
@@ -158,6 +158,8 @@ else
        LIBNTFS_3G_LDADD=
        LIBNTFS_3G_CFLAGS=
 fi
+AM_CONDITIONAL([WITH_NTFS_3G], [test "x$WITH_NTFS_3G" = "xyes"])
+
 AC_SUBST([LIBNTFS_3G_LDADD], [$LIBNTFS_3G_LDADD])
 AC_SUBST([LIBNTFS_3G_CFLAGS], [$LIBNTFS_3G_CFLAGS])
 
index f5a3fe1476cabf07bae615680b07b2f22b001061..27937ab42a55a933e6833e34d5325bec7fdbd757 100644 (file)
@@ -1045,19 +1045,15 @@ int read_dentry(const u8 metadata_resource[], u64 metadata_resource_len,
         * aligned on the next 8-byte boundary.  Here's an example of the
         * aligned data:
         *
-        * 01000000400000006c786bbac58ede11b0bb00261870892ab6adb76fe63a3
-        * e468fca86530d2effa16c786bbac58ede11b0bb00261870892a0000000000
-        * 0000000000000000000000
+        * 01000000 40000000 6c786bba c58ede11 b0bb0026 1870892a b6adb76f
+        * e63a3e46 8fca8653 0d2effa1 6c786bba c58ede11 b0bb0026 1870892a
+        * 00000000 00000000 00000000 00000000
         *
         * Here's one interpretation of how the data is laid out.
         *
         * struct unknown {
         *      u32 field1; (always 0x00000001)
         *      u32 field2; (always 0x40000000)
-        *      u16 field3;
-        *      u32 field4;
-        *      u32 field5;
-        *      u32 field6;
         *      u8  data[48]; (???)
         *      u64 reserved1; (always 0)
         *      u64 reserved2; (always 0)
index db6481b14be04d242c24ffdb4095899fbe684781..613f6259e95c1b1884c81e6852a4e8e754b6534a 100644 (file)
@@ -100,7 +100,7 @@ static inline bool ads_entry_has_name(const struct ads_entry *entry,
 }
 
 
-/* In-memory structure for a directory entry.  There is a directory tree for
+/* In-memory structure for a WIM directory entry.  There is a directory tree for
  * each image in the WIM.  */
 struct dentry {
        /* The parent of this directory entry. */
similarity index 75%
rename from src/ntfs.c
rename to src/ntfs-apply.c
index 317f60d6904adf339323aedc727bc6a1703a2b63..300c30819af778f2fff1ec4543e7e2940c0ac833 100644 (file)
@@ -35,7 +35,7 @@
 #include <unistd.h>
 
 struct ntfs_apply_args {
-       struct SECURITY_API *scapi;
+       ntfs_volume *vol;
        int extract_flags;
        WIMStruct *w;
 };
@@ -44,80 +44,6 @@ extern int _ntfs_set_file_security(ntfs_volume *vol, ntfs_inode *ni,
                                   u32 selection, const char *attr);
 extern int _ntfs_set_file_attributes(ntfs_inode *ni, s32 attrib);
 
-/*
- *             Initializations before calling ntfs_get_file_security()
- *     ntfs_set_file_security() and ntfs_read_directory()
- *
- *     Returns an (obscured) struct SECURITY_API* needed for further calls
- *             NULL if device is mounted (EBUSY)
- */
-
-static struct SECURITY_API *_ntfs_initialize_file_security(const char *device,
-                                                          unsigned long flags)
-{
-       ntfs_volume *vol;
-       unsigned long mntflag;
-       int mnt;
-       struct SECURITY_API *scapi;
-       struct SECURITY_CONTEXT *scx;
-
-       scapi = (struct SECURITY_API*)NULL;
-       mnt = ntfs_check_if_mounted(device, &mntflag);
-       if (!mnt && !(mntflag & NTFS_MF_MOUNTED)) {
-               vol = ntfs_mount(device, flags);
-               if (vol) {
-                       scapi = (struct SECURITY_API*)
-                               ntfs_malloc(sizeof(struct SECURITY_API));
-                       if (!ntfs_volume_get_free_space(vol)
-                           && scapi) {
-                               scapi->magic = MAGIC_API;
-                               scapi->seccache = (struct PERMISSIONS_CACHE*)NULL;
-                               scx = &scapi->security;
-                               scx->vol = vol;
-                               scx->uid = 0;
-                               scx->gid = 0;
-                               scx->pseccache = &scapi->seccache;
-                               scx->vol->secure_flags = (1 << SECURITY_DEFAULT) |
-                                                       (1 << SECURITY_RAW);
-                               ntfs_open_secure(vol);
-                               ntfs_build_mapping(scx,(const char*)NULL,TRUE);
-                       } else {
-                               if (scapi)
-                                       free(scapi);
-                               else
-                                       errno = ENOMEM;
-                               mnt = ntfs_umount(vol,FALSE);
-                               scapi = (struct SECURITY_API*)NULL;
-                       }
-               }
-       } else
-               errno = EBUSY;
-       return (scapi);
-}
-
-/*
- *     JPA NTFS constants or structs
- *     should be moved to layout.h
- */
-
-#define ALIGN_SDS_BLOCK 0x40000 /* Alignment for a $SDS block */
-#define ALIGN_SDS_ENTRY 16 /* Alignment for a $SDS entry */
-#define STUFFSZ 0x4000 /* unitary stuffing size for $SDS */
-#define FIRST_SECURITY_ID 0x100 /* Lowest security id */
-       /* Mask for attributes which can be forced */
-#define FILE_ATTR_SETTABLE ( FILE_ATTR_READONLY                \
-                               | FILE_ATTR_HIDDEN      \
-                               | FILE_ATTR_SYSTEM      \
-                               | FILE_ATTR_ARCHIVE     \
-                               | FILE_ATTR_TEMPORARY   \
-                               | FILE_ATTR_OFFLINE     \
-                               | FILE_ATTR_NOT_CONTENT_INDEXED )
-
-
-
-#if 0
-#endif
-
 static int extract_resource_to_ntfs_attr(WIMStruct *w, const struct resource_entry *entry, 
                                         ntfs_attr *na)
 {
@@ -181,6 +107,15 @@ static int write_ntfs_data_streams(ntfs_inode *ni, const struct dentry *dentry,
        return 0;
 }
 
+/* 
+ * Applies a WIM dentry to a NTFS filesystem.
+ *
+ * @dentry:  The WIM dentry to apply
+ * @dir_ni:  The NTFS inode for the parent directory
+ * @w:      The WIMStruct for the WIM containing the image we are applying.
+ *
+ * @return:  0 on success; nonzero on failure.
+ */
 static int __ntfs_apply_dentry(struct dentry *dentry, ntfs_inode *dir_ni,
                               WIMStruct *w)
 {
@@ -272,8 +207,7 @@ out:
 static int ntfs_apply_dentry(struct dentry *dentry, void *arg)
 {
        struct ntfs_apply_args *args = arg;
-       struct SECURITY_API *scapi   = args->scapi;
-       ntfs_volume *vol             = scapi->security.vol;
+       ntfs_volume *vol             = args->vol;
        int extract_flags            = args->extract_flags;
        WIMStruct *w                 = args->w;
        ntfs_inode *dir_ni;
@@ -320,24 +254,25 @@ static int ntfs_apply_dentry(struct dentry *dentry, void *arg)
 
 static int do_ntfs_apply(WIMStruct *w, const char *device, int extract_flags)
 {
-       struct SECURITY_API *scapi;
+       ntfs_volume *vol;
        int ret;
        
-       scapi = _ntfs_initialize_file_security(device, 0);
-       if (!scapi) {
+       vol = ntfs_mount(device, 0);
+       if (!vol) {
                ERROR_WITH_ERRNO("Failed to mount NTFS volume `%s'", device);
                return WIMLIB_ERR_NTFS_3G;
        }
        struct ntfs_apply_args args = {
-               .scapi         = scapi,
+               .vol           = vol,
                .extract_flags = extract_flags,
                .w             = w,
        };
        ret = for_dentry_in_tree(wim_root_dentry(w), ntfs_apply_dentry,
                                 &args);
-       if (!ntfs_leave_file_security(scapi)) {
+       if (ntfs_umount(vol, FALSE) != 0) {
                ERROR_WITH_ERRNO("Failed to unmount NTFS volume");
-               ret = WIMLIB_ERR_NTFS_3G;
+               if (ret == 0)
+                       ret = WIMLIB_ERR_NTFS_3G;
        }
        return ret;
 }
@@ -363,14 +298,16 @@ WIMLIBAPI int wimlib_apply_image_to_ntfs_volume(WIMStruct *w, int image,
        if (ret != 0)
                return ret;
 
-       /*if (getuid() != 0) {*/
-               /*ERROR("We are not root, but NTFS-3g requires root privileges to set arbitrary");*/
-               /*ERROR("security data on the NTFS filesystem.  Please run this program as root");*/
-               /*ERROR("if you want to extract a WIM image while preserving NTFS-specific");*/
-               /*ERROR("information.");*/
+#if 0
+       if (getuid() != 0) {
+               ERROR("We are not root, but NTFS-3g requires root privileges to set arbitrary");
+               ERROR("security data on the NTFS filesystem.  Please run this program as root");
+               ERROR("if you want to extract a WIM image while preserving NTFS-specific");
+               ERROR("information.");
 
-               /*return WIMLIB_ERR_NOT_ROOT;*/
-       /*}*/
+               return WIMLIB_ERR_NOT_ROOT;
+       }
+#endif
        return do_ntfs_apply(w, device, flags);
 }