1 /*- 2 * SPDX-License-Identifier: BSD-2-Clause 3 * 4 * Copyright (c) 2017 Martin Matuska 5 * All rights reserved. 6 */ 7 #include "test.h" 8 9 #if defined(_WIN32) && !defined(__CYGWIN__) && !defined(__BORLANDC__) 10 #define chmod _chmod 11 #endif 12 13 static void 14 clear_fflags(const char *pathname) 15 { 16 #if defined(HAVE_STRUCT_STAT_ST_FLAGS) 17 chflags(pathname, 0); 18 #elif (defined(FS_IOC_GETFLAGS) && defined(HAVE_WORKING_FS_IOC_GETFLAGS)) || \ 19 (defined(EXT2_IOC_GETFLAGS) && defined(HAVE_WORKING_EXT2_IOC_GETFLAGS)) 20 int fd; 21 22 fd = open(pathname, O_RDONLY | O_NONBLOCK); 23 if (fd < 0) 24 return; 25 ioctl(fd, 26 #ifdef FS_IOC_GETFLAGS 27 FS_IOC_GETFLAGS, 28 #else 29 EXT2_IOC_GETFLAGS, 30 #endif 31 0); 32 #else 33 (void)pathname; /* UNUSED */ 34 #endif 35 return; 36 } 37 38 DEFINE_TEST(test_option_fflags) 39 { 40 int r; 41 42 if (!canNodump()) { 43 skipping("Can't test nodump flag on this filesystem"); 44 return; 45 } 46 47 /* Create a file. */ 48 assertMakeFile("f", 0644, "a"); 49 50 /* Set nodump flag on the file */ 51 assertSetNodump("f"); 52 53 /* FreeBSD ZFS workaround: ZFS sets uarch on all touched files and dirs */ 54 chmod("f", 0644); 55 56 /* Archive it with fflags */ 57 r = systemf("%s -c --fflags -f fflags.tar f >fflags.out 2>fflags.err", testprog); 58 assertEqualInt(r, 0); 59 60 /* Archive it without fflags */ 61 r = systemf("%s -c --no-fflags -f nofflags.tar f >nofflags.out 2>nofflags.err", testprog); 62 assertEqualInt(r, 0); 63 64 /* Extract fflags with fflags */ 65 assertMakeDir("fflags_fflags", 0755); 66 clear_fflags("fflags_fflags"); 67 r = systemf("%s -x -C fflags_fflags --no-same-permissions --fflags -f fflags.tar >fflags_fflags.out 2>fflags_fflags.err", testprog); 68 assertEqualInt(r, 0); 69 assertEqualFflags("f", "fflags_fflags/f"); 70 71 /* Extract fflags without fflags */ 72 assertMakeDir("fflags_nofflags", 0755); 73 clear_fflags("fflags_nofflags"); 74 r = systemf("%s -x -C fflags_nofflags -p --no-fflags -f fflags.tar >fflags_nofflags.out 2>fflags_nofflags.err", testprog); 75 assertEqualInt(r, 0); 76 assertUnequalFflags("f", "fflags_nofflags/f"); 77 78 /* Extract nofflags with fflags */ 79 assertMakeDir("nofflags_fflags", 0755); 80 clear_fflags("nofflags_fflags"); 81 r = systemf("%s -x -C nofflags_fflags --no-same-permissions --fflags -f nofflags.tar >nofflags_fflags.out 2>nofflags_fflags.err", testprog); 82 assertEqualInt(r, 0); 83 assertUnequalFflags("f", "nofflags_fflags/f"); 84 85 /* Extract nofflags with nofflags */ 86 assertMakeDir("nofflags_nofflags", 0755); 87 clear_fflags("nofflags_nofflags"); 88 r = systemf("%s -x -C nofflags_nofflags -p --no-fflags -f nofflags.tar >nofflags_nofflags.out 2>nofflags_nofflags.err", testprog); 89 assertEqualInt(r, 0); 90 assertUnequalFflags("f", "nofflags_nofflags/f"); 91 } 92