From: Eric Biggers Date: Fri, 31 Aug 2012 02:56:22 +0000 (-0500) Subject: NTFS tests X-Git-Tag: v1.0.0~29 X-Git-Url: https://wimlib.net/git/?p=wimlib;a=commitdiff_plain;h=507c465ba8f26dc79e43d53b3d8df1dc07074e9f NTFS tests --- diff --git a/tests/ntfs-cmp.c b/tests/ntfs-cmp.c index 6c43a41d..338dce56 100644 --- a/tests/ntfs-cmp.c +++ b/tests/ntfs-cmp.c @@ -1,4 +1,6 @@ -/* Compares two mounted NTFS filesystems. */ +/* + * A program to compare two mounted NTFS filesystems. + */ #include #include @@ -56,6 +58,9 @@ static void error(const char *format, ...) exit(2); } +/* This is just a binary tree that maps inode numbers in one NTFS tree to inode + * numbers in the other NTFS tree. This is so we can tell if the hard link + * groups are the same between the two NTFS trees. */ struct node { u64 ino_from; u64 ino_to; @@ -116,6 +121,7 @@ static void insert_ino(u64 ino_from, u64 ino_to) } +/* Compares the "normal" contents of two files of size @size. */ static void cmp(const char *file1, const char *file2, size_t size) { int fd1, fd2; @@ -142,6 +148,7 @@ static void cmp(const char *file1, const char *file2, size_t size) close(fd2); } +/* Compares an extended attribute of the files. */ static void cmp_xattr(const char *file1, const char *file2, const char *xattr_name, ssize_t max_size, bool missingok) @@ -158,7 +165,7 @@ static void cmp_xattr(const char *file1, const char *file2, if (errno == ENOATTR) return; else - error("xattr `%s' exists on file `%s' " + difference("xattr `%s' exists on file `%s' " "but not on file `%s'", xattr_name, file1, file2); } else { @@ -199,6 +206,7 @@ static void cmp_xattr(const char *file1, const char *file2, free(buf2); } +/* Compares all alternate data streams of the files */ static void cmp_ads(const char *file1, const char *file2) { char _list1[256], _list2[sizeof(_list1)]; @@ -237,7 +245,7 @@ static void cmp_ads(const char *file1, const char *file2) pe = list1 + len1 - 1; while (p < pe) { cmp_xattr(file1, file2, p, 0, false); - p += strlen(p); + p += strlen(p) + 1; } if (list1 != _list1) { free(list1); @@ -245,6 +253,8 @@ static void cmp_ads(const char *file1, const char *file2) } } +/* Compares special NTFS data of the files, as accessed through extended + * attributes. */ static void special_cmp(const char *file1, const char *file2) { cmp_xattr(file1, file2, "system.ntfs_acl", 0, false); @@ -256,6 +266,7 @@ static void special_cmp(const char *file1, const char *file2) } +/* Compares file1 on one NTFS volume to file2 on another NTFS volume. */ static void ntfs_cmp(char file1[], int file1_len, char file2[], int file2_len) { struct stat st1, st2; diff --git a/tests/test-imagex-ntfs b/tests/test-imagex-ntfs index eb061b1a..a0c79fcc 100755 --- a/tests/test-imagex-ntfs +++ b/tests/test-imagex-ntfs @@ -81,9 +81,19 @@ do_test() { if ! imagex apply ntfs.wim 1 out.ntfs; then error "Failed to apply WIM to NTFS volume" fi - __do_mount in.ntfs in.mnt - __do_mount out.ntfs out.mnt - ./ntfs-cmp in.mnt out.mnt + __do_mount in.ntfs in.mnt noatime + __do_mount out.ntfs out.mnt noatime + if [ -x /usr/bin/tree ]; then + tree in.mnt --inodes -F -s --noreport + fi + if ! ./ntfs-cmp in.mnt out.mnt; then + if [ -x /usr/bin/tree ]; then + echo "Dumping tree of applied image" + tree out.mnt --inodes -F -s --noreport + error 'Information was lost or corrupted while capturing + and then applying a NTFS volume' + fi + fi rm -rf out.mnt/* in.mnt/* __do_unmount out.mnt } @@ -148,7 +158,7 @@ msg "NTFS volume containing identical files and symlinks in subdirectory" do_test 'mkdir dir; echo 888 > dir/file; echo 888 > dir/idfile2; - ln -s dir dir/circle; ln -s file dir/filelink' + ln -s ../dir dir/circle; ln -s file dir/filelink' msg "NTFS volume containing hard link group and identical files not hard linked" do_test 'echo 888 > file; @@ -161,5 +171,40 @@ msg "NTFS volume containing file with named data stream" do_test 'echo 1 > file; setfattr -n user.ads -v 2 file' +msg "NTFS volume containing file with multiple named data streams" +do_test 'echo 1 > file; + setfattr -n user.a -v 1 file; + setfattr -n user.aa -v 11 file; + setfattr -n user.aaa -v 111 file; + setfattr -n user.aaaa -v 1111 file' + +msg "NTFS volume containing file with multiple named data streams with same contents" +do_test 'echo 1 > file; + setfattr -n user.a -v 1111 file; + setfattr -n user.aa -v 1111 file; + setfattr -n user.aaa -v 1111 file; + setfattr -n user.aaaa -v 1111 file;' +msg "NTFS volume containing file with named data streams with same contents as other file" +do_test 'echo -n > file; + setfattr -n user.a -v 1111 file; + echo -n 1111 > otherfile;' +msg "NTFS volume containing file with empty named data stream and non-empty unnamed data stream" +do_test 'echo 1 > file; + setfattr -n user.ads -v "" file;' + +msg "NTFS volume containing file with empty named data stream and empty unnamed data stream" +do_test 'echo -n > file; + setfattr -n user.ads -v "" file;' + +msg "NTFS volume containing file with named data stream with hardlink" +do_test 'echo 999 > file; + setfattr -n user.ads -v "888" file; + ln file link;' + +msg "NTFS volume containing file with named data stream with hardlink and DOS name" +do_test 'echo 999 > file; + setfattr -n user.ads -v "888" file; + ln file link; + setfattr -v DOSNAME -n system.ntfs_dos_name file;'