2 * This file and its contents are supplied under the terms of the
3 * Common Development and Distribution License ("CDDL"), version 1.0.
4 * You may only use this file in accordance with the terms of version
7 * A full copy of the text of the CDDL should have accompanied this
8 * source. A copy of the CDDL is also available via the Internet at
9 * http://www.illumos.org/license/CDDL.
13 * Copyright 2022 iXsystems, Inc.
17 * FreeBSD exposes additional file attributes via ls -o and chflags.
18 * Under Linux, we provide ZFS_IOC_[GS]ETDOSFLAGS ioctl()s.
20 * This application is equivalent to FreeBSD chflags.
28 #include <sys/types.h>
30 #include <sys/ioctl.h>
31 #include <sys/fs/zfs.h>
32 #include "dos_attributes.h"
35 main(int argc
, const char *const *argv
)
38 errx(EXIT_FAILURE
, "usage: %s flag file", argv
[0]);
42 const char *flag
= argv
[1];
43 if (strcmp(flag
, "0") == 0)
45 else if (strcmp(flag
, SU_NODUMP
) == 0)
47 else if (strcmp(flag
, UNSET_NODUMP
) == 0) {
51 if (strncmp(flag
, "no", 2) == 0) {
55 for (size_t i
= 0; i
< ARRAY_SIZE(all_dos_attribute_names
); ++i
)
56 for (const char *const *nm
= all_dos_attribute_names
[i
];
58 if (strcmp(flag
, *nm
) == 0) {
59 attr
= all_dos_attributes
[i
];
63 errx(EXIT_FAILURE
, "%s: unknown flag", argv
[1]);
67 int fd
= open(argv
[2], O_RDWR
| O_APPEND
| O_CLOEXEC
);
69 err(EXIT_FAILURE
, "%s", argv
[2]);
72 if (ioctl(fd
, ZFS_IOC_GETDOSFLAGS
, &flags
) == -1)
73 err(EXIT_FAILURE
, "ZFS_IOC_GETDOSFLAGS");
82 if (ioctl(fd
, ZFS_IOC_SETDOSFLAGS
, &flags
) == -1)
83 err(EXIT_FAILURE
, "ZFS_IOC_SETDOSFLAGS");
86 if (ioctl(fd
, ZFS_IOC_GETDOSFLAGS
, &newflags
) == -1)
87 err(EXIT_FAILURE
, "second ZFS_IOC_GETDOSFLAGS");
89 if (newflags
!= flags
)
90 errx(EXIT_FAILURE
, "expecting %#" PRIx64
", got %#" PRIx64
91 "; %ssetting %#" PRIx64
"",
92 flags
, newflags
, unset
? "un" : "", attr
);
94 (void) printf("%#" PRIx64
"\n", flags
);