o Update extattrctl to take into account the updated EA interface with

explicit namespaces.  Modify it to use libutil for string/constant
  namespace conversions.  Update the documentation to take into account
  the new interface.

Obtained from:	TrustedBSD Project
This commit is contained in:
Robert Watson 2001-03-15 03:04:35 +00:00
parent 1bc2362e07
commit bf6afea751
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=74275
3 changed files with 61 additions and 25 deletions

View File

@ -1,7 +1,7 @@
# $FreeBSD$ # $FreeBSD$
PROG= extattrctl PROG= extattrctl
SRCS= extattrctl.c SRCS= extattrctl.c
LDADD= LDADD= ${LIBUTIL}
CFLAGS+= -g -Wall CFLAGS+= -g -Wall
MAN8+= extattrctl.8 MAN8+= extattrctl.8

View File

@ -1,5 +1,5 @@
.\"- .\"-
.\" Copyright (c) 2000 Robert N. M. Watson .\" Copyright (c) 2000, 2001 Robert N. M. Watson
.\" All rights reserved. .\" All rights reserved.
.\" .\"
.\" Redistribution and use in source and binary forms, with or without .\" Redistribution and use in source and binary forms, with or without
@ -47,11 +47,13 @@
.Nm .Nm
.Cm enable .Cm enable
.Ar path .Ar path
.Ar namespace
.Ar attrname .Ar attrname
.Ar attrfile .Ar attrfile
.Nm .Nm
.Cm disable .Cm disable
.Ar path .Ar path
.Ar namespace
.Ar attrname .Ar attrname
.Sh DESCRIPTION .Sh DESCRIPTION
.Nm .Nm
@ -102,23 +104,29 @@ from denying attribute service.
.Pp .Pp
This file should not exist before running This file should not exist before running
.Cm initattr . .Cm initattr .
.It Cm enable Ar path Ar attrname Ar attrfile .It Cm enable Ar path Ar namespace Ar attrname Ar attrfile
Enable an attribute named Enable an attribute named
.Ar attrname .Ar attrname
in the namespace
.Ar namespace
on the file system identified using on the file system identified using
.Ar path , .Ar path ,
and backed by initialized attribute file and backed by initialized attribute file
.Ar attrfile . .Ar attrfile .
Available namespaces are "user" and "system".
The backing file must have been initialized using The backing file must have been initialized using
.Cm initattr .Cm initattr
before its first use. before its first use.
Attributes must have been started on the file system prior to the Attributes must have been started on the file system prior to the
enabling of any attributes. enabling of any attributes.
.It Cm disable Ar path Ar attrname .It Cm disable Ar path Ar namespace Ar attrname
Disable the attributed named Disable the attributed named
.Ar attrname .Ar attrname
in namespace
.Ar namespace
on the file system identified by on the file system identified by
.Ar path . .Ar path .
Available namespaces are "user" and "system".
The file system must have attributes started on it, and the attribute The file system must have attributes started on it, and the attribute
most have been enabled using most have been enabled using
.Cm enable . .Cm enable .
@ -135,7 +143,7 @@ Create an attribute backing file in /.attribute/md5, and set the maximum
size of each attribute to 17 bytes, with a sparse file used for storing size of each attribute to 17 bytes, with a sparse file used for storing
the attributes. the attributes.
.Pp .Pp
.Dl extattrctl enable / md5 /.attribute/md5 .Dl extattrctl enable / system md5 /.attribute/md5
.Pp .Pp
Enable an attribute named md5 on the root file system, backed from the file Enable an attribute named md5 on the root file system, backed from the file
/.attribute/md5. /.attribute/md5.

View File

@ -1,5 +1,5 @@
/*- /*-
* Copyright (c) 1999, 2000 Robert N. M. Watson * Copyright (c) 1999, 2000, 2001 Robert N. M. Watson
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -23,7 +23,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE. * SUCH DAMAGE.
* *
* $FreeBSD$ * $FreeBSD$
*/ */
/* /*
* TrustedBSD Project - extended attribute support for UFS-like file systems * TrustedBSD Project - extended attribute support for UFS-like file systems
@ -37,7 +37,9 @@
#include <ufs/ufs/extattr.h> #include <ufs/ufs/extattr.h>
#include <errno.h>
#include <fcntl.h> #include <fcntl.h>
#include <libutil.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
@ -55,8 +57,8 @@ usage(void)
" extattrctl start [path]\n" " extattrctl start [path]\n"
" extattrctl stop [path]\n" " extattrctl stop [path]\n"
" extattrctl initattr [-f] [-p path] [attrsize] [attrfile]\n" " extattrctl initattr [-f] [-p path] [attrsize] [attrfile]\n"
" extattrctl enable [path] [attrname] [attrfile]\n" " extattrctl enable [path] [namespace] [attrname] [attrfile]\n"
" extattrctl disable [path] [attrname]\n"); " extattrctl disable [path] [namespace] [attrname]\n");
exit(-1); exit(-1);
} }
@ -157,7 +159,7 @@ initattr(int argc, char *argv[])
int int
main(int argc, char *argv[]) main(int argc, char *argv[])
{ {
int error = 0; int error = 0, namespace;
if (argc < 2) if (argc < 2)
usage(); usage();
@ -165,34 +167,60 @@ main(int argc, char *argv[])
if (!strcmp(argv[1], "start")) { if (!strcmp(argv[1], "start")) {
if (argc != 3) if (argc != 3)
usage(); usage();
error = extattrctl(argv[2], UFS_EXTATTR_CMD_START, 0, 0); error = extattrctl(argv[2], UFS_EXTATTR_CMD_START, NULL, 0,
if (error) NULL);
if (error) {
perror("extattrctl start"); perror("extattrctl start");
return (-1);
}
return (0);
} else if (!strcmp(argv[1], "stop")) { } else if (!strcmp(argv[1], "stop")) {
if (argc != 3) if (argc != 3)
usage(); usage();
error = extattrctl(argv[2], UFS_EXTATTR_CMD_STOP, 0, 0); error = extattrctl(argv[2], UFS_EXTATTR_CMD_STOP, NULL, 0,
if (error) NULL);
if (error) {
perror("extattrctl stop"); perror("extattrctl stop");
return (-1);
}
return (0);
} else if (!strcmp(argv[1], "enable")) { } else if (!strcmp(argv[1], "enable")) {
if (argc != 6)
usage();
error = extattr_string_to_namespace(argv[3], &namespace);
if (error) {
perror("extattrctl enable");
return (-1);
}
error = extattrctl(argv[2], UFS_EXTATTR_CMD_ENABLE, argv[4],
namespace, argv[5]);
if (error) {
perror("extattrctl enable");
return (-1);
}
return (0);
} else if (!strcmp(argv[1], "disable")) {
if (argc != 5) if (argc != 5)
usage(); usage();
error = extattrctl(argv[2], UFS_EXTATTR_CMD_ENABLE, argv[3], error = extattr_string_to_namespace(argv[3], &namespace);
argv[4]); if (error) {
if (error)
perror("extattrctl enable");
} else if (!strcmp(argv[1], "disable")) {
if (argc != 4)
usage();
error = extattrctl(argv[2], UFS_EXTATTR_CMD_DISABLE, argv[3],
NULL);
if (error)
perror("extattrctl disable"); perror("extattrctl disable");
return (-1);
}
error = extattrctl(argv[2], UFS_EXTATTR_CMD_DISABLE, NULL,
namespace, argv[5]);
if (error) {
perror("extattrctl disable");
return (-1);
}
return (0);
} else if (!strcmp(argv[1], "initattr")) { } else if (!strcmp(argv[1], "initattr")) {
argc -= 2; argc -= 2;
argv += 2; argv += 2;
error = initattr(argc, argv); error = initattr(argc, argv);
if (error)
return (-1);
return (0);
} else } else
usage(); usage();
return(error);
} }