Post by Glenn FowlerPost by Lionel ConsGlenn, how hard is it to add the tar extensions described in the
Solaris fsattr(5)
[http://docs.oracle.com/cd/E19253-01/816-5175/6mbba7f02/index.html]
creation and restores them on archive unpacking?
a few pax questions
(1) when writing to the archive, what is output for a file that only
has the default xattr? just the file or the file and default xattr
(2) when reading from an archive what happens when a file being extracted
already exists and the archive xattr differs from the existing xattr?
(a) archive xattr added to existing
(b) existing file deleted then archive file+xattr added
Erm... first one seperation:
1. There are user and system extended attributes, both can be accessed
via |O_XATTR|. System attributes are usually for filesystem-internal
stuff but this API provides a way to backup them easily.
As result we need both the -@ and -/ option in AST pax
The Solaris pax(1) manual page says this about both options:
-- snip --
-@ Includes extended attributes in the archive.
pax does not place extended attributes in
the archive by default.
When traversing the file hierarchy specified
by a path name, pax descends into the
attribute directory for any file with
extended attributes. Extended attributes go
into the archive as special files.
When this flag is used during file extrac-
tion, any extended attributes associated
with a file being extracted are also
extracted. Extended attribute files can only
be extracted from an archive as part of a
normal file extract. Attempts to explicitly
extract attribute records are ignored.
-/ Includes extended system attributes in the
archive. pax does not place extended system
attributes in the archive by default.
When traversing the file hierarchy specified
by a path name, pax descends into the attri-
bute directory for any file with extended
attributes. Extended attributes go into the
archive as special files. When this flag is
used during file extraction, any extended
attributes associated with a file being
extracted are also extracted. Extended
attribute files can only be extracted from
an archive as part of a normal file extract.
Attempts to explicitly extract attribute
records are ignored.
-- snip --
If you look at http://src.illumos.org/source/xref/illumos-gate/usr/src/cmd/tar/tar.c
you see the following code which explains how the code becomes
available (or not) per platform CPP flags at built time:
-- snip --
813#if defined(O_XATTR)
814 case '@':
815 atflag++;
816 break;
817#endif /* O_XATTR */
818#if defined(_PC_SATTR_ENABLED)
819 case '/':
820 saflag++;
821 break;
822#endif /* _PC_SATTR_ENABLED */
-- snip --
And then Solaris tar.c has this comment:
-- snip --
1640#if defined(O_XATTR)
1641static int
1642is_sysattr(char *name)
1643{
1644 return ((strcmp(name, VIEW_READONLY) == 0) ||
1645 (strcmp(name, VIEW_READWRITE) == 0));
1646}
1647#endif
1648
1649#if defined(O_XATTR)
1650/*
1651 * Verify the attribute, attrname, is an attribute we want to restore.
1652 * Never restore read-only system attribute files. Only restore read-write
1653 * system attributes files when -/ was specified, and only traverse into
1654 * the 2nd level attribute directory containing only system attributes if
1655 * -@ was specified. This keeps us from archiving
1656 * <attribute name>/<read-write system attribute file>
1657 * when -/ was specified without - at .
1658 *
1659 * attrname - attribute file name
1660 * attrparent - attribute's parent name within the base file's attribute
1661 * directory hierarchy
1662 */
1663static attr_status_t
1664verify_attr(char *attrname, char *attrparent, int arc_rwsysattr,
1665 int *rw_sysattr)
1666{
1667#if defined(_PC_SATTR_ENABLED)
1668 int attr_supported;
1669
1670 /* Never restore read-only system attribute files */
1671 if ((attr_supported = sysattr_type(attrname)) == _RO_SATTR) {
1672 *rw_sysattr = 0;
1673 return (ATTR_SKIP);
1674 } else {
1675 *rw_sysattr = (attr_supported == _RW_SATTR);
1676 }
1677#else
1678 /*
1679 * Only need to check if this attribute is an extended system
1680 * attribute.
1681 */
1682 if (*rw_sysattr = is_sysattr(attrname)) {
1683 return (ATTR_SKIP);
1684 } else {
1685 return (ATTR_OK);
1686 }
1687#endif /* _PC_SATTR_ENABLED */
-- snip --
Finally... the only semi-official API to test whether an attribute is
a system attribute or not seems to be in libcmdutil - see
http://src.illumos.org/source/xref/illumos-gate/usr/src/lib/libcmdutils/common/sysattrs.c
-- snip --
65/*
66 * Returns the type of the specified in file. If the file name matches
67 * the name of either a read-only or read-write extended system attribute
68 * file then sysattr_type() returns the type of file:
69 * return value file type
70 * ------------ ---------
71 * _RO_SATTR read-only extended system attribute file
72 * _RW_SATTR read-write extended system attribute file
73 * _NOT_SATTR neither a read-only or read-write extended system
74 * attribute file.
75 */
76int
77sysattr_type(char *file)
78{
79 if (file == NULL) {
80 errno = ENOENT;
81 return (_NOT_SATTR);
82 }
83
84 if (strcmp(basename(file), file) != 0) {
85 errno = EINVAL;
86 return (_NOT_SATTR);
87 }
88
89 errno = 0;
90 if (strcmp(file, VIEW_READONLY) == 0) {
91 return (_RO_SATTR);
92 } else if (strcmp(file, VIEW_READWRITE) == 0) {
93 return (_RW_SATTR);
94 } else {
95 return (_NOT_SATTR);
96 }
97}
-- snip --
----
Bye,
Roland
----
Bye,
Roland
--
__ . . __
(o.\ \/ /.o) roland.mainz at nrubsig.org
\__\/\/__/ MPEG specialist, C&&JAVA&&Sun&&Unix programmer
/O /==\ O\ TEL +49 641 3992797
(;O/ \/ \O;)