aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorUmer Saleem <[email protected]>2022-03-08 06:52:03 +0500
committerGitHub <[email protected]>2022-03-07 17:52:03 -0800
commit39a4daf742a4bd34b34f85e004895385e4c46c1a (patch)
treeeed72bcbb589ca6a3d0288cc723ae9fa8da3e73e /tests
parent9955b9ba2efafeeb88ccb4c4ab5707ef2974fb47 (diff)
Expose additional file level attributes
ZFS allows to update and retrieve additional file level attributes for FreeBSD. This commit allows additional file level attributes to be updated and retrieved for Linux. These include the flags stored in the upper half of z_pflags only. Two new IOCTLs have been added for this purpose. ZFS_IOC_GETDOSFLAGS can be used to retrieve the attributes, while ZFS_IOC_SETDOSFLAGS can be used to update the attributes. Attributes that are allowed to be updated include ZFS_IMMUTABLE, ZFS_APPENDONLY, ZFS_NOUNLINK, ZFS_ARCHIVE, ZFS_NODUMP, ZFS_SYSTEM, ZFS_HIDDEN, ZFS_READONLY, ZFS_REPARSE, ZFS_OFFLINE and ZFS_SPARSE. Flags can be or'd together while calling ZFS_IOC_SETDOSFLAGS. Reviewed-by: Alexander Motin <[email protected]> Reviewed-by: Brian Behlendorf <[email protected]> Reviewed-by: Ryan Moeller <[email protected]> Signed-off-by: Umer Saleem <[email protected]> Closes #13118
Diffstat (limited to 'tests')
-rw-r--r--tests/runfiles/common.run2
-rw-r--r--tests/runfiles/freebsd.run4
-rw-r--r--tests/runfiles/linux.run4
-rw-r--r--tests/zfs-tests/cmd/Makefile.am2
-rw-r--r--tests/zfs-tests/cmd/read_dos_attributes/.gitignore1
-rw-r--r--tests/zfs-tests/cmd/read_dos_attributes/Makefile.am6
-rw-r--r--tests/zfs-tests/cmd/read_dos_attributes/read_dos_attributes.c167
-rw-r--r--tests/zfs-tests/cmd/write_dos_attributes/.gitignore1
-rw-r--r--tests/zfs-tests/cmd/write_dos_attributes/Makefile.am6
-rw-r--r--tests/zfs-tests/cmd/write_dos_attributes/write_dos_attributes.c201
-rw-r--r--tests/zfs-tests/include/commands.cfg2
-rw-r--r--tests/zfs-tests/tests/functional/Makefile.am1
-rw-r--r--tests/zfs-tests/tests/functional/acl/off/Makefile.am2
-rwxr-xr-xtests/zfs-tests/tests/functional/acl/off/dosmode.ksh97
-rw-r--r--tests/zfs-tests/tests/functional/acl/off/dosmode_readonly_write.c11
-rw-r--r--tests/zfs-tests/tests/functional/dos_attributes/Makefile.am8
-rwxr-xr-xtests/zfs-tests/tests/functional/dos_attributes/cleanup.ksh34
-rwxr-xr-xtests/zfs-tests/tests/functional/dos_attributes/read_dos_attrs_001.ksh60
-rwxr-xr-xtests/zfs-tests/tests/functional/dos_attributes/setup.ksh35
-rwxr-xr-xtests/zfs-tests/tests/functional/dos_attributes/write_dos_attrs_001.ksh61
20 files changed, 657 insertions, 48 deletions
diff --git a/tests/runfiles/common.run b/tests/runfiles/common.run
index 9f11284ad..eb0d45135 100644
--- a/tests/runfiles/common.run
+++ b/tests/runfiles/common.run
@@ -29,7 +29,7 @@ outputdir = /var/tmp/test_results
tags = ['functional']
[tests/functional/acl/off]
-tests = ['posixmode']
+tests = ['dosmode', 'posixmode']
tags = ['functional', 'acl']
[tests/functional/alloc_class]
diff --git a/tests/runfiles/freebsd.run b/tests/runfiles/freebsd.run
index 153b204b4..c7ca1d769 100644
--- a/tests/runfiles/freebsd.run
+++ b/tests/runfiles/freebsd.run
@@ -22,10 +22,6 @@ failsafe = callbacks/zfs_failsafe
outputdir = /var/tmp/test_results
tags = ['functional']
-[tests/functional/acl/off:FreeBSD]
-tests = ['dosmode']
-tags = ['functional', 'acl']
-
[tests/functional/cli_root/zfs_jail:FreeBSD]
tests = ['zfs_jail_001_pos']
tags = ['functional', 'cli_root', 'zfs_jail']
diff --git a/tests/runfiles/linux.run b/tests/runfiles/linux.run
index 7186d5d67..8412a7ea5 100644
--- a/tests/runfiles/linux.run
+++ b/tests/runfiles/linux.run
@@ -149,6 +149,10 @@ tests = ['projectid_001_pos', 'projectid_002_pos', 'projectid_003_pos',
'projecttree_001_pos', 'projecttree_002_pos', 'projecttree_003_neg']
tags = ['functional', 'projectquota']
+[tests/functional/dos_attributes:Linux]
+tests = ['read_dos_attrs_001', 'write_dos_attrs_001']
+tags = ['functional', 'dos_attributes']
+
[tests/functional/rsend:Linux]
tests = ['send_realloc_dnode_size', 'send_encrypted_files']
tags = ['functional', 'rsend']
diff --git a/tests/zfs-tests/cmd/Makefile.am b/tests/zfs-tests/cmd/Makefile.am
index 2470397a9..88d8c8cf0 100644
--- a/tests/zfs-tests/cmd/Makefile.am
+++ b/tests/zfs-tests/cmd/Makefile.am
@@ -34,6 +34,8 @@ if BUILD_LINUX
SUBDIRS += \
getversion \
randfree_file \
+ read_dos_attributes \
user_ns_exec \
+ write_dos_attributes \
xattrtest
endif
diff --git a/tests/zfs-tests/cmd/read_dos_attributes/.gitignore b/tests/zfs-tests/cmd/read_dos_attributes/.gitignore
new file mode 100644
index 000000000..52584e4a7
--- /dev/null
+++ b/tests/zfs-tests/cmd/read_dos_attributes/.gitignore
@@ -0,0 +1 @@
+/read_dos_attributes
diff --git a/tests/zfs-tests/cmd/read_dos_attributes/Makefile.am b/tests/zfs-tests/cmd/read_dos_attributes/Makefile.am
new file mode 100644
index 000000000..69412f05f
--- /dev/null
+++ b/tests/zfs-tests/cmd/read_dos_attributes/Makefile.am
@@ -0,0 +1,6 @@
+include $(top_srcdir)/config/Rules.am
+
+pkgexecdir = $(datadir)/@PACKAGE@/zfs-tests/bin
+
+pkgexec_PROGRAMS = read_dos_attributes
+read_dos_attributes_SOURCES = read_dos_attributes.c
diff --git a/tests/zfs-tests/cmd/read_dos_attributes/read_dos_attributes.c b/tests/zfs-tests/cmd/read_dos_attributes/read_dos_attributes.c
new file mode 100644
index 000000000..ed0906c36
--- /dev/null
+++ b/tests/zfs-tests/cmd/read_dos_attributes/read_dos_attributes.c
@@ -0,0 +1,167 @@
+/*
+ * This file and its contents are supplied under the terms of the
+ * Common Development and Distribution License ("CDDL"), version 1.0.
+ * You may only use this file in accordance with the terms of version
+ * 1.0 of the CDDL.
+ *
+ * A full copy of the text of the CDDL should have accompanied this
+ * source. A copy of the CDDL is also available via the Internet at
+ * http://www.illumos.org/license/CDDL.
+ */
+
+/*
+ * Copyright 2022 iXsystems, Inc.
+ */
+
+/*
+ * FreeBSD allows to update and retreive additional file level attributes.
+ * For Linux, two IOCTLs have been added to update and retrieve additional
+ * level attributes.
+ *
+ * This application reads additional file level attributes on a given
+ * file and prints FreeBSD keywords that map to respective attributes.
+ *
+ * Usage: 'read_dos_attributes filepath'
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <sys/ioctl.h>
+#include <err.h>
+#include <sys/fs/zfs.h>
+#include <string.h>
+
+#define SU_ARCH_SHORT "arch"
+#define SU_ARCH_FULL "archived"
+#define SU_NODUMP "nodump"
+#define SU_APPEND_SHORT "sappnd"
+#define SU_APPEND_FULL "sappend"
+#define SU_IMMUTABLE "schg"
+#define SU_IMMUTABLE_SHORT "schange"
+#define SU_IMMUTABLE_FULL "simmutable"
+#define SU_UNLINK_SHORT "sunlnk"
+#define SU_UNLINK_FULL "sunlink"
+#define U_APPEND_SHORT "uappnd"
+#define U_APPEND_FULL "uappend"
+#define U_ARCH_SHORT "uarch"
+#define U_ARCH_FULL "uarchive"
+#define U_IMMUTABLE "uchg"
+#define U_IMMUTABLE_SHORT "uchange"
+#define U_IMMUTABLE_FULL "uimmutable"
+#define U_HIDDEN_SHORT "hidden"
+#define U_HIDDEN_FULL "uhidden"
+#define U_OFFLINE_SHORT "offline"
+#define U_OFFLINE_FULL "uoffline"
+#define U_RDONLY "rdonly"
+#define U_RDONLY_SHORT "urdonly"
+#define U_RDONLY_FULL "readonly"
+#define U_SPARSE_SHORT "sparse"
+#define U_SPARSE_FULL "usparse"
+#define U_SYSTEM_SHORT "system"
+#define U_SYSTEM_FULL "usystem"
+#define U_REPARSE_SHORT "reparse"
+#define U_REPARSE_FULL "ureparse"
+#define U_UNLINK_SHORT "uunlnk"
+#define U_UNLINK_FULL "uunlink"
+#define UNSET_NODUMP "dump"
+
+#define NO_ATTRIBUTE "-"
+
+#define SEPARATOR ","
+
+#define BUFFER_SIZE 0x200
+
+void attribute_to_str(uint64_t attributes, char *buff);
+
+void
+attribute_to_str(uint64_t attributes, char *buff)
+{
+ if (attributes & ZFS_ARCHIVE) {
+ strcat(buff, U_ARCH_SHORT);
+ strcat(buff, SEPARATOR);
+ }
+
+ if (attributes & ZFS_APPENDONLY) {
+ strcat(buff, U_APPEND_SHORT);
+ strcat(buff, SEPARATOR);
+ }
+
+ if (attributes & ZFS_IMMUTABLE) {
+ strcat(buff, U_IMMUTABLE_FULL);
+ strcat(buff, SEPARATOR);
+ }
+
+ if (attributes & ZFS_NOUNLINK) {
+ strcat(buff, U_UNLINK_SHORT);
+ strcat(buff, SEPARATOR);
+ }
+
+ if (attributes & ZFS_NODUMP) {
+ strcat(buff, SU_NODUMP);
+ strcat(buff, SEPARATOR);
+ }
+
+ if (attributes & ZFS_HIDDEN) {
+ strcat(buff, U_HIDDEN_SHORT);
+ strcat(buff, SEPARATOR);
+ }
+
+ if (attributes & ZFS_OFFLINE) {
+ strcat(buff, U_OFFLINE_SHORT);
+ strcat(buff, SEPARATOR);
+ }
+
+ if (attributes & ZFS_READONLY) {
+ strcat(buff, U_RDONLY);
+ strcat(buff, SEPARATOR);
+ }
+
+ if (attributes & ZFS_SPARSE) {
+ strcat(buff, U_SPARSE_SHORT);
+ strcat(buff, SEPARATOR);
+ }
+
+ if (attributes & ZFS_SYSTEM) {
+ strcat(buff, U_SYSTEM_SHORT);
+ strcat(buff, SEPARATOR);
+ }
+
+ if (attributes & ZFS_REPARSE) {
+ strcat(buff, U_REPARSE_SHORT);
+ strcat(buff, SEPARATOR);
+ }
+
+ if (buff[0] == '\0')
+ strcat(buff, NO_ATTRIBUTE);
+ else
+ buff[strlen(buff) - 1] = '\0';
+}
+
+int
+main(int argc, const char * const argv[])
+{
+ if (argc != 2)
+ errx(EXIT_FAILURE, "Usage: %s filepath", argv[0]);
+
+ int fd = open(argv[1], O_RDWR | O_APPEND);
+ if (fd < 0)
+ err(EXIT_FAILURE, "Failed to open %s", argv[1]);
+
+ uint64_t dosflags = 0;
+ if (ioctl(fd, ZFS_IOC_GETDOSFLAGS, &dosflags) == -1)
+ err(EXIT_FAILURE, "ZFS_IOC_GETDOSFLAGS failed");
+
+ (void) close(fd);
+
+ char buffer[BUFFER_SIZE];
+ memset(buffer, 0, BUFFER_SIZE);
+
+ (void) attribute_to_str(dosflags, buffer);
+
+ (void) printf("%s\n", buffer);
+
+ return (EXIT_SUCCESS);
+}
diff --git a/tests/zfs-tests/cmd/write_dos_attributes/.gitignore b/tests/zfs-tests/cmd/write_dos_attributes/.gitignore
new file mode 100644
index 000000000..f3949ac82
--- /dev/null
+++ b/tests/zfs-tests/cmd/write_dos_attributes/.gitignore
@@ -0,0 +1 @@
+/write_dos_attributes
diff --git a/tests/zfs-tests/cmd/write_dos_attributes/Makefile.am b/tests/zfs-tests/cmd/write_dos_attributes/Makefile.am
new file mode 100644
index 000000000..c297fd49e
--- /dev/null
+++ b/tests/zfs-tests/cmd/write_dos_attributes/Makefile.am
@@ -0,0 +1,6 @@
+include $(top_srcdir)/config/Rules.am
+
+pkgexecdir = $(datadir)/@PACKAGE@/zfs-tests/bin
+
+pkgexec_PROGRAMS = write_dos_attributes
+write_dos_attributes_SOURCES = write_dos_attributes.c
diff --git a/tests/zfs-tests/cmd/write_dos_attributes/write_dos_attributes.c b/tests/zfs-tests/cmd/write_dos_attributes/write_dos_attributes.c
new file mode 100644
index 000000000..c373d3b15
--- /dev/null
+++ b/tests/zfs-tests/cmd/write_dos_attributes/write_dos_attributes.c
@@ -0,0 +1,201 @@
+/*
+ * This file and its contents are supplied under the terms of the
+ * Common Development and Distribution License ("CDDL"), version 1.0.
+ * You may only use this file in accordance with the terms of version
+ * 1.0 of the CDDL.
+ *
+ * A full copy of the text of the CDDL should have accompanied this
+ * source. A copy of the CDDL is also available via the Internet at
+ * http://www.illumos.org/license/CDDL.
+ */
+
+/*
+ * Copyright 2022 iXsystems, Inc.
+ */
+
+/*
+ * FreeBSD allows to update and retreive additional file level attributes.
+ * For Linux, two IOCTLs have been added to update and retrieve additional
+ * level attributes.
+ *
+ * This application updates additional file level attributes on a given
+ * file. FreeBSD keywords can be used to specify the flag.
+ *
+ * Usage: 'write_dos_attributes flag filepath'
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <sys/ioctl.h>
+#include <err.h>
+#include <sys/fs/zfs.h>
+#include <string.h>
+#include <ctype.h>
+
+#define SU_ARCH_SHORT "arch"
+#define SU_ARCH_FULL "archived"
+#define SU_NODUMP "nodump"
+#define SU_APPEND_SHORT "sappnd"
+#define SU_APPEND_FULL "sappend"
+#define SU_IMMUTABLE "schg"
+#define SU_IMMUTABLE_SHORT "schange"
+#define SU_IMMUTABLE_FULL "simmutable"
+#define SU_UNLINK_SHORT "sunlnk"
+#define SU_UNLINK_FULL "sunlink"
+#define U_APPEND_SHORT "uappnd"
+#define U_APPEND_FULL "uappend"
+#define U_ARCH_SHORT "uarch"
+#define U_ARCH_FULL "uarchive"
+#define U_IMMUTABLE "uchg"
+#define U_IMMUTABLE_SHORT "uchange"
+#define U_IMMUTABLE_FULL "uimmutable"
+#define U_HIDDEN_SHORT "hidden"
+#define U_HIDDEN_FULL "uhidden"
+#define U_OFFLINE_SHORT "offline"
+#define U_OFFLINE_FULL "uoffline"
+#define U_RDONLY "rdonly"
+#define U_RDONLY_SHORT "urdonly"
+#define U_RDONLY_FULL "readonly"
+#define U_SPARSE_SHORT "sparse"
+#define U_SPARSE_FULL "usparse"
+#define U_SYSTEM_SHORT "system"
+#define U_SYSTEM_FULL "usystem"
+#define U_REPARSE_SHORT "reparse"
+#define U_REPARSE_FULL "ureparse"
+#define U_UNLINK_SHORT "uunlnk"
+#define U_UNLINK_FULL "uunlink"
+#define UNSET_NODUMP "dump"
+
+#define IS_NO(s) (s[0] == 'n' && s[1] == 'o')
+
+uint64_t str_to_attribute(char *str);
+
+uint64_t
+str_to_attribute(char *str)
+{
+ if ((strcmp(str, SU_ARCH_SHORT) == 0) ||
+ (strcmp(str, SU_ARCH_FULL) == 0) ||
+ (strcmp(str, U_ARCH_SHORT) == 0) ||
+ (strcmp(str, U_ARCH_FULL) == 0))
+ return (ZFS_ARCHIVE);
+
+ else if ((strcmp(str, SU_APPEND_SHORT) == 0) ||
+ (strcmp(str, SU_APPEND_FULL) == 0) ||
+ (strcmp(str, U_APPEND_SHORT) == 0) ||
+ (strcmp(str, U_APPEND_FULL) == 0))
+ return (ZFS_APPENDONLY);
+
+ else if ((strcmp(str, SU_IMMUTABLE) == 0) ||
+ (strcmp(str, SU_IMMUTABLE_SHORT) == 0) ||
+ (strcmp(str, SU_IMMUTABLE_FULL) == 0))
+ return (ZFS_IMMUTABLE);
+
+ else if ((strcmp(str, SU_UNLINK_SHORT) == 0) ||
+ (strcmp(str, SU_UNLINK_FULL) == 0) ||
+ (strcmp(str, U_UNLINK_SHORT) == 0) ||
+ (strcmp(str, SU_UNLINK_FULL) == 0))
+ return (ZFS_NOUNLINK);
+
+ else if ((strcmp(str, U_HIDDEN_SHORT) == 0) ||
+ (strcmp(str, U_HIDDEN_FULL) == 0))
+ return (ZFS_HIDDEN);
+
+ else if ((strcmp(str, U_OFFLINE_SHORT) == 0) ||
+ (strcmp(str, U_OFFLINE_FULL) == 0))
+ return (ZFS_OFFLINE);
+
+ else if ((strcmp(str, U_RDONLY) == 0) ||
+ (strcmp(str, U_RDONLY_SHORT) == 0) ||
+ (strcmp(str, U_RDONLY_FULL) == 0))
+ return (ZFS_READONLY);
+
+ else if ((strcmp(str, U_SPARSE_SHORT) == 0) ||
+ (strcmp(str, U_SPARSE_FULL) == 0))
+ return (ZFS_SPARSE);
+
+ else if ((strcmp(str, U_SYSTEM_SHORT) == 0) ||
+ (strcmp(str, U_SYSTEM_FULL) == 0))
+ return (ZFS_SYSTEM);
+
+ else if ((strcmp(str, U_REPARSE_SHORT) == 0) ||
+ (strcmp(str, U_REPARSE_FULL) == 0))
+ return (ZFS_REPARSE);
+
+ return (-1);
+}
+
+int
+main(int argc, const char * const argv[])
+{
+ if (argc != 3)
+ errx(EXIT_FAILURE, "Usage: %s flag filepath", argv[0]);
+
+ uint8_t unset, unset_all;
+ uint64_t attribute, dosflags;
+ char *flag = strdup(argv[1]);
+ unset = unset_all = 0;
+ attribute = dosflags = 0;
+
+ // convert the flag to lower case
+ for (int i = 0; i < strlen(argv[1]); ++i)
+ flag[i] = tolower((unsigned char) flag[i]);
+
+ // check if flag starts with 'no'
+ if (IS_NO(flag)) {
+ if (strcmp(flag, SU_NODUMP) == 0) {
+ attribute = ZFS_NODUMP;
+ } else {
+ attribute = str_to_attribute(flag + 2);
+ unset = 1;
+ }
+ }
+ // check if '0' was passed
+ else if (strcmp(flag, "0") == 0) {
+ unset_all = 1;
+ }
+ // check if the flag is 'dump'
+ else if (strcmp(flag, UNSET_NODUMP) == 0) {
+ attribute = ZFS_NODUMP;
+ unset = 1;
+ } else {
+ attribute = str_to_attribute(flag);
+ }
+
+ if (attribute == -1)
+ errx(EXIT_FAILURE, "Invalid Flag %s", argv[1]);
+
+ int fd = open(argv[2], O_RDWR | O_APPEND);
+ if (fd < 0)
+ err(EXIT_FAILURE, "Failed to open %s", argv[2]);
+
+ if (ioctl(fd, ZFS_IOC_GETDOSFLAGS, &dosflags) == -1)
+ err(EXIT_FAILURE, "ZFS_IOC_GETDOSFLAGS failed");
+
+ if (unset == 0 && attribute != 0)
+ attribute |= dosflags;
+ else if (unset == 1 && attribute != 0)
+ attribute = dosflags & (~attribute);
+ else if (unset_all == 1)
+ attribute = 0;
+
+ // set the attribute/s
+ if (ioctl(fd, ZFS_IOC_SETDOSFLAGS, &attribute) == -1)
+ err(EXIT_FAILURE, "ZFS_IOC_SETDOSFLAGS failed");
+
+ // get the attributes to confirm
+ dosflags = -1;
+ if (ioctl(fd, ZFS_IOC_GETDOSFLAGS, &dosflags) == -1)
+ err(EXIT_FAILURE, "ZFS_IOC_GETDOSFLAGS failed");
+
+ (void) close(fd);
+
+ if (dosflags != attribute)
+ errx(EXIT_FAILURE, "Could not set %s attribute", argv[1]);
+
+ (void) printf("New Dos Flags: 0x%llx\n", (u_longlong_t)dosflags);
+
+ return (EXIT_SUCCESS);
+}
diff --git a/tests/zfs-tests/include/commands.cfg b/tests/zfs-tests/include/commands.cfg
index fa3d12d66..b247a67ff 100644
--- a/tests/zfs-tests/include/commands.cfg
+++ b/tests/zfs-tests/include/commands.cfg
@@ -215,10 +215,12 @@ export ZFSTEST_FILES='badsend
randfree_file
randwritecomp
readmmap
+ read_dos_attributes
rename_dir
rm_lnkcnt_zero_file
send_doall
threadsappend
user_ns_exec
+ write_dos_attributes
xattrtest
stride_dd'
diff --git a/tests/zfs-tests/tests/functional/Makefile.am b/tests/zfs-tests/tests/functional/Makefile.am
index e71172b8e..9164650e3 100644
--- a/tests/zfs-tests/tests/functional/Makefile.am
+++ b/tests/zfs-tests/tests/functional/Makefile.am
@@ -21,6 +21,7 @@ SUBDIRS = \
deadman \
delegate \
devices \
+ dos_attributes \
events \
exec \
fallocate \
diff --git a/tests/zfs-tests/tests/functional/acl/off/Makefile.am b/tests/zfs-tests/tests/functional/acl/off/Makefile.am
index 36aa13dd0..ae6a9c69d 100644
--- a/tests/zfs-tests/tests/functional/acl/off/Makefile.am
+++ b/tests/zfs-tests/tests/functional/acl/off/Makefile.am
@@ -10,7 +10,5 @@ dist_pkgdata_SCRIPTS = \
pkgexecdir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/acl/off
-if BUILD_FREEBSD
pkgexec_PROGRAMS = dosmode_readonly_write
dosmode_readonly_write_SOURCES = dosmode_readonly_write.c
-endif
diff --git a/tests/zfs-tests/tests/functional/acl/off/dosmode.ksh b/tests/zfs-tests/tests/functional/acl/off/dosmode.ksh
index e232dfd52..585aa0253 100755
--- a/tests/zfs-tests/tests/functional/acl/off/dosmode.ksh
+++ b/tests/zfs-tests/tests/functional/acl/off/dosmode.ksh
@@ -31,8 +31,6 @@
# DESCRIPTION:
# Verify that DOS mode flags function correctly.
#
-# These flags are not currently exposed on Linux, so the test is
-# only useful on FreeBSD.
#
# STRATEGY:
# 1. ARCHIVE
@@ -56,7 +54,13 @@ function hasflag
typeset flag=$1
typeset path=$2
- ls -lo $path | awk '{ gsub(",", "\n", $5); print $5 }' | grep -qxF $flag
+ if is_linux; then
+ read_dos_attributes $path | awk \
+ '{ gsub(",", "\n", $1); print $1 }' | grep -qxF $flag
+ else
+ ls -lo $path | awk '{ gsub(",", "\n", $5); print $5 }' | \
+ grep -qxF $flag
+ fi
}
log_assert "Verify DOS mode flags function correctly"
@@ -67,6 +71,12 @@ testfile=$TESTDIR/testfile
owner=$ZFS_ACL_STAFF1
other=$ZFS_ACL_STAFF2
+if is_linux; then
+ changeflags=write_dos_attributes
+else
+ changeflags=chflags
+fi
+
#
# ARCHIVE
#
@@ -75,36 +85,40 @@ other=$ZFS_ACL_STAFF2
#
log_must touch $testfile
log_must hasflag uarch $testfile
-log_must chflags nouarch $testfile
+log_must $changeflags nouarch $testfile
log_must hasflag - $testfile
log_must touch $testfile
-log_must hasflag uarch $testfile
+if ! is_linux; then
+ log_must hasflag uarch $testfile
+fi
log_must rm $testfile
log_must user_run $owner touch $testfile
log_must hasflag uarch $testfile
-log_must user_run $owner chflags nouarch $testfile
-log_mustnot user_run $other chflags uarch $testfile
+log_must user_run $owner $changeflags nouarch $testfile
+log_mustnot user_run $other $changeflags uarch $testfile
log_must hasflag - $testfile
log_must user_run $owner touch $testfile
-log_mustnot user_run $other chflags nouarch $testfile
-log_must hasflag uarch $testfile
+log_mustnot user_run $other $changeflags nouarch $testfile
+if ! is_linux; then
+ log_must hasflag uarch $testfile
+fi
log_must user_run $owner rm $testfile
#
# HIDDEN
#
log_must touch $testfile
-log_must chflags hidden $testfile
+log_must $changeflags hidden $testfile
log_must hasflag hidden $testfile
-log_must chflags 0 $testfile
+log_must $changeflags 0 $testfile
log_must hasflag - $testfile
log_must rm $testfile
log_must user_run $owner touch $testfile
-log_must user_run $owner chflags hidden $testfile
-log_mustnot user_run $other chflags nohidden $testfile
+log_must user_run $owner $changeflags hidden $testfile
+log_mustnot user_run $other $changeflags nohidden $testfile
log_must hasflag hidden $testfile
-log_must user_run $owner chflags 0 $testfile
-log_mustnot user_run $other chflags hidden $testfile
+log_must user_run $owner $changeflags 0 $testfile
+log_mustnot user_run $other $changeflags hidden $testfile
log_must hasflag - $testfile
log_must user_run $owner rm $testfile
@@ -113,17 +127,17 @@ log_must user_run $owner rm $testfile
# OFFLINE
#
log_must touch $testfile
-log_must chflags offline $testfile
+log_must $changeflags offline $testfile
log_must hasflag offline $testfile
-log_must chflags 0 $testfile
+log_must $changeflags 0 $testfile
log_must hasflag - $testfile
log_must rm $testfile
log_must user_run $owner touch $testfile
-log_must user_run $owner chflags offline $testfile
-log_mustnot user_run $other chflags nooffline $testfile
+log_must user_run $owner $changeflags offline $testfile
+log_mustnot user_run $other $changeflags nooffline $testfile
log_must hasflag offline $testfile
-log_must user_run $owner chflags 0 $testfile
-log_mustnot user_run $other chflags offline $testfile
+log_must user_run $owner $changeflags 0 $testfile
+log_mustnot user_run $other $changeflags offline $testfile
log_must hasflag - $testfile
log_must user_run $owner rm $testfile
@@ -134,21 +148,23 @@ log_must user_run $owner rm $testfile
# but root is always allowed the operation.
#
log_must touch $testfile
-log_must chflags rdonly $testfile
+log_must $changeflags rdonly $testfile
log_must hasflag rdonly $testfile
log_must eval "echo 'root write allowed' >> $testfile"
log_must cat $testfile
-log_must chflags 0 $testfile
-log_must hasflag - $tesfile
+log_must $changeflags 0 $testfile
+log_must hasflag - $testfile
log_must rm $testfile
# It is required to still be able to write to an fd that was opened RW before
# READONLY is set. We have a special test program for that.
log_must user_run $owner touch $testfile
-log_mustnot user_run $other chflags rdonly $testfile
+log_mustnot user_run $other $changeflags rdonly $testfile
log_must user_run $owner $tests_base/dosmode_readonly_write $testfile
-log_mustnot user_run $other chflags nordonly $testfile
+log_mustnot user_run $other $changeflags nordonly $testfile
log_must hasflag rdonly $testfile
-log_mustnot user_run $owner "echo 'user write forbidden' >> $testfile"
+if ! is_linux; then
+ log_mustnot user_run $owner "echo 'user write forbidden' >> $testfile"
+fi
log_must eval "echo 'root write allowed' >> $testfile"
# We are still allowed to read and remove the file when READONLY is set.
log_must user_run $owner cat $testfile
@@ -157,24 +173,23 @@ log_must user_run $owner rm $testfile
#
# REPARSE
#
-# FIXME: does not work, not sure if broken or testing wrong
-#
+# not allowed to be changed
#
# SPARSE
#
log_must truncate -s 1m $testfile
-log_must chflags sparse $testfile
+log_must $changeflags sparse $testfile
log_must hasflag sparse $testfile
-log_must chflags 0 $testfile
+log_must $changeflags 0 $testfile
log_must hasflag - $testfile
log_must rm $testfile
log_must user_run $owner truncate -s 1m $testfile
-log_must user_run $owner chflags sparse $testfile
-log_mustnot user_run $other chflags nosparse $testfile
+log_must user_run $owner $changeflags sparse $testfile
+log_mustnot user_run $other $changeflags nosparse $testfile
log_must hasflag sparse $testfile
-log_must user_run $owner chflags 0 $testfile
-log_mustnot user_run $other chflags sparse $testfile
+log_must user_run $owner $changeflags 0 $testfile
+log_mustnot user_run $other $changeflags sparse $testfile
log_must hasflag - $testfile
log_must user_run $owner rm $testfile
@@ -182,17 +197,17 @@ log_must user_run $owner rm $testfile
# SYSTEM
#
log_must touch $testfile
-log_must chflags system $testfile
+log_must $changeflags system $testfile
log_must hasflag system $testfile
-log_must chflags 0 $testfile
+log_must $changeflags 0 $testfile
log_must hasflag - $testfile
log_must rm $testfile
log_must user_run $owner touch $testfile
-log_must user_run $owner chflags system $testfile
-log_mustnot user_run $other chflags nosystem $testfile
+log_must user_run $owner $changeflags system $testfile
+log_mustnot user_run $other $changeflags nosystem $testfile
log_must hasflag system $testfile
-log_must user_run $owner chflags 0 $testfile
-log_mustnot user_run $other chflags system $testfile
+log_must user_run $owner $changeflags 0 $testfile
+log_mustnot user_run $other $changeflags system $testfile
log_must hasflag - $testfile
log_must user_run $owner rm $testfile
diff --git a/tests/zfs-tests/tests/functional/acl/off/dosmode_readonly_write.c b/tests/zfs-tests/tests/functional/acl/off/dosmode_readonly_write.c
index 372c3f7f6..0441d1c7b 100644
--- a/tests/zfs-tests/tests/functional/acl/off/dosmode_readonly_write.c
+++ b/tests/zfs-tests/tests/functional/acl/off/dosmode_readonly_write.c
@@ -36,6 +36,11 @@
#include <string.h>
#include <unistd.h>
+#ifdef __linux__
+#include <stdint.h>
+#include <sys/fs/zfs.h>
+#endif
+
int
main(int argc, const char *argv[])
{
@@ -51,8 +56,14 @@ main(int argc, const char *argv[])
fd = open(path, O_CREAT|O_RDWR, 0777);
if (fd == -1)
err(EXIT_FAILURE, "%s: open failed", path);
+#ifdef __linux__
+ uint64_t dosflags = ZFS_READONLY;
+ if (ioctl(fd, ZFS_IOC_SETDOSFLAGS, &dosflags) == -1)
+ err(EXIT_FAILURE, "%s: ZFS_IOC_SETDOSFLAGS failed", path);
+#else
if (chflags(path, UF_READONLY) == -1)
err(EXIT_FAILURE, "%s: chflags failed", path);
+#endif
if (write(fd, buf, strlen(buf)) == -1)
err(EXIT_FAILURE, "%s: write failed", path);
if (close(fd) == -1)
diff --git a/tests/zfs-tests/tests/functional/dos_attributes/Makefile.am b/tests/zfs-tests/tests/functional/dos_attributes/Makefile.am
new file mode 100644
index 000000000..436bcdb1f
--- /dev/null
+++ b/tests/zfs-tests/tests/functional/dos_attributes/Makefile.am
@@ -0,0 +1,8 @@
+include $(top_srcdir)/config/Rules.am
+
+pkgdatadir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/dos_attributes
+dist_pkgdata_SCRIPTS = \
+ cleanup.ksh \
+ read_dos_attrs_001.ksh \
+ write_dos_attrs_001.ksh \
+ setup.ksh
diff --git a/tests/zfs-tests/tests/functional/dos_attributes/cleanup.ksh b/tests/zfs-tests/tests/functional/dos_attributes/cleanup.ksh
new file mode 100755
index 000000000..3166bd6ec
--- /dev/null
+++ b/tests/zfs-tests/tests/functional/dos_attributes/cleanup.ksh
@@ -0,0 +1,34 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc. All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+default_cleanup
diff --git a/tests/zfs-tests/tests/functional/dos_attributes/read_dos_attrs_001.ksh b/tests/zfs-tests/tests/functional/dos_attributes/read_dos_attrs_001.ksh
new file mode 100755
index 000000000..c36c01833
--- /dev/null
+++ b/tests/zfs-tests/tests/functional/dos_attributes/read_dos_attrs_001.ksh
@@ -0,0 +1,60 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2009 Sun Microsystems, Inc. All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013, 2016 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#
+# Read additional file level attributes stored in upper half of z_pflags
+#
+# STARTEGY:
+# 1) Create a file
+# 2) Execute read_dos_attributes on the file we created
+# 3) Verify that read_dos_attributes exited successfully
+#
+
+verify_runnable "global"
+
+FILETOTEST="$TESTDIR/test_read_dos_attrs.txt"
+
+function cleanup
+{
+ rm -f $FILETOTEST
+}
+
+log_onexit cleanup
+
+log_must chmod 777 $TESTDIR
+log_must eval "echo 'This is a test file.' > $FILETOTEST"
+log_must read_dos_attributes $FILETOTEST
+
+log_pass "reading DOS attributes succeeded."
diff --git a/tests/zfs-tests/tests/functional/dos_attributes/setup.ksh b/tests/zfs-tests/tests/functional/dos_attributes/setup.ksh
new file mode 100755
index 000000000..fc5cec306
--- /dev/null
+++ b/tests/zfs-tests/tests/functional/dos_attributes/setup.ksh
@@ -0,0 +1,35 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc. All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+DISK=${DISKS%% *}
+default_setup $DISK
diff --git a/tests/zfs-tests/tests/functional/dos_attributes/write_dos_attrs_001.ksh b/tests/zfs-tests/tests/functional/dos_attributes/write_dos_attrs_001.ksh
new file mode 100755
index 000000000..9d66cd357
--- /dev/null
+++ b/tests/zfs-tests/tests/functional/dos_attributes/write_dos_attrs_001.ksh
@@ -0,0 +1,61 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2009 Sun Microsystems, Inc. All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013, 2016 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+#
+# Write additional file level attributes stored in upper half of z_pflags
+#
+# STARTEGY:
+# 1) Create a file
+# 2) Execute write_dos_attributes on the file we created
+# 3) Verify that write_dos_attributes exited successfully
+#
+
+verify_runnable "global"
+
+FILETOTEST="$TESTDIR/test_write_dos_attrs.txt"
+
+function cleanup
+{
+ rm -f $FILETOTEST
+}
+
+log_onexit cleanup
+
+log_must chmod 777 $TESTDIR
+log_must eval "echo 'This is a test file.' > $FILETOTEST"
+log_must write_dos_attributes offline $FILETOTEST
+log_must write_dos_attributes nooffline $FILETOTEST
+
+log_pass "writing DOS attributes succeeded."