diff options
author | rwatson <rwatson@FreeBSD.org> | 2000-04-20 18:31:00 +0000 |
---|---|---|
committer | rwatson <rwatson@FreeBSD.org> | 2000-04-20 18:31:00 +0000 |
commit | bcd52d23a79386fd25fe196d96f8606bcf3c7063 (patch) | |
tree | 1a65edce4adfaec8384b0b5492bfd8e74090d1bf /usr.sbin | |
parent | 333168ead37b35c4cdc9ce15e85d80d393fa4fec (diff) | |
download | FreeBSD-src-bcd52d23a79386fd25fe196d96f8606bcf3c7063.zip FreeBSD-src-bcd52d23a79386fd25fe196d96f8606bcf3c7063.tar.gz |
o Allow the ``-p'' argument to be specified to initattr, which indicates
that space for extended attributes should be preallocated, instead of
using a sparse attribute file. NOTE: This can result in a really
large file full of zeros. However, it can prevent a low disk condition
from causing an attribute write to fail, which is good for security and
consistency attributes.
o Unlink the attribute file during initattr if an error occurs -- this is
alright, as we specify O_CREAT when opening the file.
Diffstat (limited to 'usr.sbin')
-rw-r--r-- | usr.sbin/extattrctl/extattrctl.c | 54 |
1 files changed, 46 insertions, 8 deletions
diff --git a/usr.sbin/extattrctl/extattrctl.c b/usr.sbin/extattrctl/extattrctl.c index 1617be1..96a8a18 100644 --- a/usr.sbin/extattrctl/extattrctl.c +++ b/usr.sbin/extattrctl/extattrctl.c @@ -32,7 +32,11 @@ #include <sys/types.h> #include <sys/uio.h> #include <sys/extattr.h> +#include <sys/param.h> +#include <sys/mount.h> + #include <ufs/ufs/extattr.h> + #include <fcntl.h> #include <stdio.h> #include <stdlib.h> @@ -50,8 +54,8 @@ usage(void) "usage:\n" " extattrctl start [path]\n" " extattrctl stop [path]\n" - " extattrctl initattr [-p] [-r [kroa]] [-w [kroa]] [attrsize] " - "[attrfile]\n" + " extattrctl initattr [-p path] [-r [kroa]] [-w [kroa]] " + "[attrsize] [attrfile]\n" " extattrctl enable [path] [attrname] [attrfile]\n" " extattrctl disable [path] [attrname]\n"); exit(-1); @@ -85,19 +89,37 @@ extattr_level_from_string(char *string) } } +long +num_inodes_by_path(char *path) +{ + struct statfs buf; + int error; + + error = statfs(path, &buf); + if (error) { + perror("statfs"); + return (-1); + } + + return (buf.f_files); +} + int initattr(int argc, char *argv[]) { struct ufs_extattr_fileheader uef; - int initattr_pflag = 0; + char *fs_path = NULL; + char *zero_buf = NULL; + long loop, num_inodes; int initattr_rlevel = UFS_EXTATTR_PERM_OWNER; int initattr_wlevel = UFS_EXTATTR_PERM_OWNER; int ch, i, error; - while ((ch = getopt(argc, argv, "prw")) != -1) + optind = 0; + while ((ch = getopt(argc, argv, "p:rw")) != -1) switch (ch) { case 'p': - initattr_pflag = 1; + fs_path = strdup(optarg); break; case 'r': initattr_rlevel = extattr_level_from_string(optarg); @@ -129,12 +151,28 @@ initattr(int argc, char *argv[]) uef.uef_size = atoi(argv[0]); if (write(i, &uef, sizeof(uef)) == -1) error = -1; - else if (initattr_pflag) { - + else if (fs_path) { + zero_buf = (char *) (malloc(uef.uef_size)); + if (zero_buf == NULL) { + perror("malloc"); + unlink(argv[1]); + return (-1); + } + memset(zero_buf, 0, uef.uef_size); + num_inodes = num_inodes_by_path(fs_path); + for (loop = 0; loop < num_inodes; loop++) { + error = write(i, zero_buf, uef.uef_size); + if (error != uef.uef_size) { + perror("write"); + unlink(argv[1]); + return (-1); + } + } } } if (i == -1 || error == -1) { - perror("argv[1]"); + perror(argv[1]); + unlink(argv[1]); return (-1); } |