1 // SPDX-License-Identifier: CDDL-1.0
2 /*
3 * This file and its contents are supplied under the terms of the
4 * Common Development and Distribution License ("CDDL"), version 1.0.
5 * You may only use this file in accordance with the terms of version
6 * 1.0 of the CDDL.
7 *
8 * A full copy of the text of the CDDL should have accompanied this
9 * source. A copy of the CDDL is also available via the Internet at
10 * http://www.illumos.org/license/CDDL.
11 */
12
13 /*
14 * Copyright 2022 iXsystems, Inc.
15 */
16
17 /*
18 * FreeBSD exposes additional file attributes via ls -o and chflags.
19 * Under Linux, we provide ZFS_IOC_[GS]ETDOSFLAGS ioctl()s.
20 *
21 * This application is the equivalent to FreeBSD ls -lo $1 | awk '{print $5}'.
22 */
23
24 #include <err.h>
25 #include <fcntl.h>
26 #include <stdio.h>
27 #include <stdlib.h>
28 #include <stdbool.h>
29 #include <sys/stat.h>
30 #include <sys/types.h>
31 #include <sys/ioctl.h>
32 #include <sys/fs/zfs.h>
33 #include "dos_attributes.h"
34
35 int
main(int argc,const char * const * argv)36 main(int argc, const char *const *argv)
37 {
38 if (argc != 2)
39 errx(EXIT_FAILURE, "usage: %s file", argv[0]);
40
41 int fd = open(argv[1], O_RDONLY | O_CLOEXEC);
42 if (fd == -1)
43 err(EXIT_FAILURE, "%s", argv[1]);
44
45 uint64_t flags;
46 if (ioctl(fd, ZFS_IOC_GETDOSFLAGS, &flags) == -1)
47 err(EXIT_FAILURE, "ZFS_IOC_GETDOSFLAGS");
48
49 bool any = false;
50 for (size_t i = 0; i < ARRAY_SIZE(all_dos_attributes); ++i)
51 if (flags & all_dos_attributes[i]) {
52 if (any)
53 putchar(',');
54 (void) fputs(*all_dos_attribute_names[i], stdout);
55 any = true;
56 }
57 if (any)
58 (void) putchar('\n');
59 else
60 (void) puts("-");
61 }
62