-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 retieve 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. Signed-off-by: Umer Saleem <[email protected]>
- Loading branch information
1 parent
7901b62
commit db4c190
Showing
19 changed files
with
492 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/read_dos_attributes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
50 changes: 50 additions & 0 deletions
50
tests/zfs-tests/cmd/read_dos_attributes/read_dos_attributes.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
#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> | ||
|
||
int | ||
main(int argc, const char * const argv[]) | ||
{ | ||
if (argc != 2) | ||
errx(EXIT_FAILURE, "Usage: %s filename", argv[0]); | ||
|
||
int fd = open(argv[1], O_RDONLY); | ||
if (fd < 0) | ||
err(EXIT_FAILURE, "Failed to open %s", argv[1]); | ||
|
||
uint64_t dosflags = -1; | ||
if (ioctl(fd, ZFS_IOC_GETDOSFLAGS, &dosflags) == -1) | ||
err(EXIT_FAILURE, "ZFS_IOC_GETDOSFLAGS failed"); | ||
|
||
(void) close(fd); | ||
|
||
(void) printf("Dos Flags: %#" PRIx64 "\n", dosflags); | ||
|
||
return (EXIT_SUCCESS); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/write_dos_attributes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
55 changes: 55 additions & 0 deletions
55
tests/zfs-tests/cmd/write_dos_attributes/write_dos_attributes.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
#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> | ||
|
||
int | ||
main(int argc, const char * const argv[]) | ||
{ | ||
if (argc != 2) | ||
errx(EXIT_FAILURE, "Usage: %s filename", argv[0]); | ||
|
||
int fd = open(argv[1], O_RDWR); | ||
if (fd < 0) | ||
err(EXIT_FAILURE, "Failed to open %s", argv[1]); | ||
|
||
uint64_t dosflags = ZFS_OFFLINE; | ||
if (ioctl(fd, ZFS_IOC_SETDOSFLAGS, &dosflags) == -1) | ||
err(EXIT_FAILURE, "ZFS_IOC_SETDOSFLAGS failed"); | ||
|
||
dosflags = -1; | ||
if (ioctl(fd, ZFS_IOC_GETDOSFLAGS, &dosflags) == -1) | ||
err(EXIT_FAILURE, "ZFS_IOC_GETDOSFLAGS failed"); | ||
|
||
(void) close(fd); | ||
|
||
if (!(dosflags & ZFS_OFFLINE)) | ||
errx(EXIT_FAILURE, "Could not set ZFS_OFFLINE attribute"); | ||
|
||
return (EXIT_SUCCESS); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,7 @@ SUBDIRS = \ | |
deadman \ | ||
delegate \ | ||
devices \ | ||
dos_attributes \ | ||
events \ | ||
exec \ | ||
fallocate \ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
Oops, something went wrong.