Merge commit 'b31320a79e2054c6739b5229259dbf98f3afc547' into merges
[unleashed.git] / share / man / man5 / fsattr.5
blob72bf95167ab34916b7a802b26c2991d6f2e31572
1 '\" te
2 .\" Copyright (c) 2007, Sun Microsystems, Inc. All Rights Reserved.
3 .\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License").  You may not use this file except in compliance with the License.
4 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing.  See the License for the specific language governing permissions and limitations under the License.
5 .\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE.  If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
6 .TH FSATTR 5 "Oct 10, 2007"
7 .SH NAME
8 fsattr \- extended file attributes
9 .SH DESCRIPTION
10 .sp
11 .LP
12 Attributes are logically supported as files within the file system.  The file
13 system is therefore augmented with an orthogonal name space of file attributes.
14 Any file (including attribute files) can have an arbitrarily deep attribute
15 tree associated with it. Attribute values are accessed by file descriptors
16 obtained through a special attribute interface.  This logical view of
17 "attributes as files" allows the leveraging of existing file system interface
18 functionality to support the construction, deletion, and manipulation of
19 attributes.
20 .sp
21 .LP
22 The special files "." and ".\|." retain their accustomed semantics within the
23 attribute hierarchy.  The "." attribute file refers to the current directory
24 and the ".\|." attribute file refers to the parent directory.  The unnamed
25 directory at the head of each attribute tree is considered the "child" of the
26 file it is associated with and the ".\|." file refers to the associated file.
27 For any non-directory file with attributes, the ".\|." entry in the unnamed
28 directory refers to a file that is not a directory.
29 .sp
30 .LP
31 Conceptually, the attribute model is fully general. Extended attributes can be
32 any type of file (doors, links, directories, and so forth) and can even have
33 their own attributes (fully recursive).  As a result, the attributes associated
34 with a file could be an arbitrarily deep directory hierarchy where each
35 attribute could have an equally complex attribute tree associated with it.  Not
36 all implementations are able to, or want to, support the full model.
37 Implementation are therefore permitted to reject operations that are not
38 supported.  For example, the implementation for the UFS file system allows only
39 regular files as attributes (for example, no sub-directories) and rejects
40 attempts to place attributes on attributes.
41 .sp
42 .LP
43 The following list details the operations that are rejected in the current
44 implementation:
45 .sp
46 .ne 2
47 .na
48 \fB\fBlink\fR\fR
49 .ad
50 .RS 25n
51 Any attempt to create links between attribute and non-attribute space is
52 rejected to prevent security-related or otherwise sensitive attributes from
53 being exposed, and therefore manipulable, as regular files.
54 .RE
56 .sp
57 .ne 2
58 .na
59 \fB\fBrename\fR\fR
60 .ad
61 .RS 25n
62 Any attempt to rename between attribute and non-attribute space is rejected to
63 prevent an already linked file from being renamed and thereby circumventing the
64 \fBlink\fR restriction above.
65 .RE
67 .sp
68 .ne 2
69 .na
70 \fB\fBmkdir\fR, \fBsymlink\fR, \fBmknod\fR\fR
71 .ad
72 .RS 25n
73 Any attempt to create a "non-regular" file in attribute space is rejected to
74 reduce the functionality, and therefore exposure and risk, of the initial
75 implementation.
76 .RE
78 .sp
79 .LP
80 The entire available name space has been allocated to "general use" to bring
81 the implementation in line with the NFSv4 draft standard [NFSv4]. That standard
82 defines "named attributes" (equivalent to Solaris Extended Attributes) with no
83 naming restrictions.  All Sun applications making use of opaque extended
84 attributes will use the prefix "SUNW".
85 .SS "Shell-level API"
86 .sp
87 .LP
88 The command interface for extended attributes is the set of applications
89 provided by Solaris for the manipulation of attributes from the command line.
90 This interface consists of a set of existing utilities that have been extended
91 to be "attribute-aware", plus the \fBrunat\fR utility designed to "expose" the
92 extended attribute space so that extended attributes can be manipulated as
93 regular files.
94 .sp
95 .LP
96 The \fB-@\fR option enable utilities to manipulate extended attributes. As a
97 rule, this option enables the utility to enter into attribute space when the
98 utility is performing a recursive traversal of file system space. This is a
99 fully recursive concept. If the underlying file system supports recursive
100 attributes and directory structures, the \fB-@\fR option opens these spaces to
101 the file tree-walking algorithms.
104 The following utilities accommodate extended attributes (see the individual
105 manual pages for details):
107 .ne 2
109 \fB\fBcp\fR\fR
111 .RS 8n
112 By default, \fBcp\fR ignores attributes and copies only file data.  This is
113 intended to maintain the semantics implied by \fBcp\fR currently, where
114 attributes (such as owner and mode) are not copied unless the \fB-p\fR option
115 is specified. With the \fB-@\fR (or \fB-p\fR) option, \fBcp\fR attempts to copy
116 all attributes along with the file data.
120 .ne 2
122 \fB\fBcpio\fR\fR
124 .RS 8n
125 The \fB-@\fR option informs \fBcpio\fR to archive attributes, but by default
126 \fBcpio\fR ignores extended attributes. See \fBExtended Archive Formats\fR
127 below for a description of the new archive records.
131 .ne 2
133 \fB\fBdu\fR\fR
135 .RS 8n
136 File sizes computed include the space allocated for any extended attributes
137 present.
141 .ne 2
143 \fB\fBfind\fR\fR
145 .RS 8n
146 By default, \fBfind\fR ignores attributes.  The \fB-xattr\fR expression
147 provides support for searches involving attribute space. It returns true if
148 extended attributes are present on the current file.
152 .ne 2
154 \fB\fBfsck\fR\fR
156 .RS 8n
157 The \fBfsck\fR utility manages extended attribute data on the disk. A file
158 system with extended attributes can be mounted on versions of Solaris that are
159 not attribute-aware (versions prior to Solaris 9), but the attributes will not
160 be accessible and \fBfsck\fR will strip them from the files and place them in
161 \fBlost+found\fR. Once the attributes have been stripped the file system is
162 completely stable on Solaris versions that are not attribute-aware, but would
163 now be considered corrupted on attribute-aware versions of Solaris. The
164 attribute-aware \fBfsck\fR utility should be run to stabilize the file system
165 before using it in an attribute-aware environment.
169 .ne 2
171 \fB\fBfsdb\fR\fR
173 .RS 8n
174 This \fBfsdb\fR utility is able to find the inode for the "hidden" extended
175 attribute directory.
179 .ne 2
181 \fB\fBls\fR\fR
183 .RS 8n
184 The \fBls\fR \fB-@\fR command displays an "@" following the mode information
185 when extended attributes are present.  More precisely, the output line for a
186 given file contains an "@" character following the mode characters if the
187 \fBpathconf\fR(2) variable \fBXATTR_EXISTS\fR is set to true. See the
188 \fBpathconf()\fR section below.  The \fB-@\fR option uses the same general
189 output format as the \fB-l\fR option.
193 .ne 2
195 \fB\fBmv\fR\fR
197 .RS 8n
198 When a file is moved, all attributes are carried along with the file rename.
199 When a file is moved across a file system boundary, the copy command invoked is
200 similar to the \fBcp\fR \fB-p\fR variant described above and extended
201 attributes are "moved". If the extended file attributes cannot be replicated,
202 the move operation fails and the source file is not removed.
206 .ne 2
208 \fB\fBpax\fR\fR
210 .RS 8n
211 The \fB-@\fR option informs \fBpax\fR to archive attributes, but by default
212 \fBpax\fR ignores extended attributes.  The \fBpax\fR(1) utility is a generic
213 replacement for both \fBtar\fR(1) and \fBcpio\fR(1) and is able to produce
214 either output format in its archive.  See \fBExtended Archive Formats\fR below
215 for a description of the new archive records.
219 .ne 2
221 \fB\fBtar\fR\fR
223 .RS 8n
224 In the default case, \fBtar\fR does not attempt to place attributes in the
225 archive.  If the \fB-@\fR option is specified, however, \fBtar\fR traverses
226 into the attribute space of all files being placed in the archive and attempts
227 to add the attributes to the archive. A new record type has been introduced for
228 extended attribute entries in \fBtar\fR archive files (the same is true for
229 \fBpax\fR and \fBcpio\fR archives) similar to the way ACLs records were
230 defined. See \fBExtended Archive Formats\fR below for a description of the new
231 archive records.
236 There is a class of utilities (\fBchmod\fR, \fBchown\fR, \fBchgrp\fR) that one
237 might expect to be modified in a manner similar to those listed above. For
238 example, one might expect that performing \fBchmod\fR on a file would not only
239 affect the file itself but would also affect at least the extended attribute
240 directory if not any existing extended attribute files.  This is not the case.
241 The model chosen for extended attributes implies that the attribute directory
242 and the attributes themselves are all file objects in their own right, and can
243 therefore have independent file status attributes associated with them  (a
244 given implementation cannot support this, for example, for intrinsic
245 attributes).  The relationship is left undefined and a fine-grained control
246 mechanism (\fBrunat\fR(1)) is provided to allow manipulation of extended
247 attribute status attributes as necessary.
250 The \fBrunat\fR utility has the following syntax:
252 .in +2
254 runat \fIfilename\fR [\fIcommand\fR]
256 .in -2
261 The \fBrunat\fR utility executes the supplied command in the context of the
262 "attribute space" associated with the indicated file.  If no command argument
263 is supplied, a shell is invoked. See \fBrunat\fR(1) for details.
264 .SS "Application-level API"
267 The primary interface required to access extended attributes at the
268 programmatic level is the \fBopenat\fR(2) function. Once a file descriptor has
269 been obtained for an attribute file by an \fBopenat()\fR call, all normal file
270 system semantics apply. There is no attempt to place special semantics on
271 \fBread\fR(2), \fBwrite\fR(2), \fBftruncate\fR(3C), or other functions when
272 applied to attribute file descriptors relative to "normal" file descriptors.
275 The set of existing attributes can be browsed by calling \fBopenat()\fR with
276 "." as the file name and the \fBO_XATTR\fR flag set, resulting in a file
277 descriptor for the attribute directory.  The list of attributes is obtained by
278 calls to \fBgetdents\fR(2) on the returned file descriptor.  If the target file
279 did not previously have any attributes associated with it, an empty top-level
280 attribute directory is created for the file and subsequent \fBgetdents()\fR
281 calls will return only "." and ".\|.".  While the owner of the parent file owns
282 the extended attribute directory, it is not charged against its quota if the
283 directory is empty.  Attribute files themselves, however, are charged against
284 the user quota as any other regular file.
287 Additional system calls have been provided as convenience functions. These
288 include the \fBfchownat\fR(2), \fBfstatat\fR(2), \fBfutimesat\fR(2),
289 \fBrenameat\fR(2), \fBunlinkat\fR(2). These new functions, along with
290 \fBopenat()\fR, provide a mechanism to access files relative to an arbitrary
291 point in the file system, rather than only the current working directory.  This
292 mechanism is particularly useful in situations when a file descriptor is
293 available with no path. The \fBopenat()\fR function, in particular, can be used
294 in many contexts where \fBchdir()\fR or \fBfchdir()\fR is currently required.
295 See \fBchdir\fR(2).
296 .SS "Open a file relative to a file descriptor"
298 .in +2
300 int openat (int \fIfd\fR, const char *\fIpath\fR, int \fIoflag\fR [, mode_t \fImode\fR])
302 .in -2
306 The \fBopenat\fR(2) function behaves exactly as \fBopen\fR(2) except when given
307 a relative path.  Where \fBopen()\fR resolves a relative path from the current
308 working directory, \fBopenat()\fR resolves the path based on the vnode
309 indicated by the supplied file descriptor. When \fIoflag\fR is \fBO_XATTR\fR,
310 \fBopenat()\fR interprets the \fIpath\fR argument as an extended attribute
311 reference. The following code fragment uses \fBopenat()\fR to examine the
312 attributes of some already opened file:
314 .in +2
316 dfd = openat(fd, ".", O_RDONLY|O_XATTR);
317 (void)getdents(dfd, buf, nbytes);
319 .in -2
323 If \fBopenat()\fR is passed the special value \fBAT_FDCWD\fR as its first
324 (\fIfd\fR) argument, its behavior is identical to \fBopen()\fR and the relative
325 path arguments are interpreted relative to the current working directory. If
326 the \fBO_XATTR\fR flag is provided to \fBopenat()\fR or to \fBopen()\fR, the
327 supplied path is interpreted as a reference to an extended attribute on the
328 current working directory.
329 .SS "Unlink a file relative to a directory file descriptor"
331 .in +2
333 int unlinkat (int \fIdirfd\fR, const char *path\fIflag\fR, int flag\fIflag\fR)
335 .in -2
339 The \fBunlinkat\fR(2) function deletes an entry from a directory.  The
340 \fIpath\fR argument indicates the name of the entry to remove. If \fIpath\fR an
341 absolute path, the \fIdirfd\fR argument is ignored. If it is a relative path,
342 it is interpreted relative to the directory indicated by the \fIdirfd\fR
343 argument. If \fIdirfd\fR does not refer to a valid directory, the function
344 returns \fBENOTDIR\fR.  If the special value \fBAT_FDCWD\fR is specified for
345 \fIdirfd\fR, a relative path argument is resolved relative to the current
346 working directory.  If the \fIflag\fR argument is 0, all other semantics of
347 this function are equivalent to \fBunlink\fR(2).  If \fIflag\fR is set to
348 \fBAT_REMOVEDIR\fR, all other semantics of this function are equivalent to
349 \fBrmdir\fR(2).
350 .SS "Rename a file relative to directories"
352 .in +2
354 int renameat (int \fIfromfd\fR, const char *\fIold\fR, int \fItofd\fR, const char *\fInew\fR)
356 .in -2
360 The \fBrenameat\fR(2) function renames an entry in a directory, possibly moving
361 the entry into a different directory.  The \fIold\fR argument indicates the
362 name of the entry to rename.  If this argument is a relative path, it is
363 interpreted relative to the directory indicated by the \fIfd\fR argument. If it
364 is an absolute path, the \fIfromfd\fR argument is ignored.  The \fInew\fR
365 argument indicates the new name for the entry.  If this argument is a relative
366 path, it is interpreted relative to the directory indicated by the \fItofd\fR
367 argument. If it is an absolute path, the \fItofd\fR argument is ignored.
370 In the relative path cases, if the directory file descriptor arguments do not
371 refer to a valid directory, the function returns \fBENOTDIR\fR.  All other
372 semantics of this function are equivalent to \fBrename\fR(2).
375 If a special value \fBAT_FDCWD\fR is specified for either the \fIfromfd\fR or
376 \fItofd\fR arguments, their associated path arguments (\fIold\fR and \fInew\fR)
377 are interpreted relative to the current working directory if they are not
378 specified as absolute paths. Any attempt to use \fBrenameat()\fR to move a file
379 that is not an extended attribute into an extended attribute directory (so that
380 it becomes an extended attribute) will fail. The same is true for an attempt to
381 move a file that is an extended attribute into a directory that is not an
382 extended attribute directory.
383 .SS "Obtain information about a file"
385 .in +2
387 int fstatat (int \fIfd\fR, const char *\fIpath\fR, struct stat* \fIbuf\fR, int \fIflag\fR)
389 .in -2
393 The \fBfstatat\fR(2) function obtains information about a file.  If the
394 \fIpath\fR argument is relative, it is resolved relative to the \fIfd\fR
395 argument file descriptor, otherwise the \fIfd\fR argument is ignored.  If the
396 \fIfd\fR argument is a special value \fBAT_FDCWD\fR the path is resolved
397 relative to the current working directory.  If the \fIpath\fR argument is a
398 null pointer, the function returns information about the file referenced by the
399 \fIfd\fR argument.  In all other relative path cases, if the \fIfd\fR argument
400 does not refer to a valid directory, the function returns \fBENOTDIR\fR. If
401 \fBAT_SYMLINK_NOFOLLOW\fR is set in the \fIflag\fR argument, the function will
402 not automatically traverse a symbolic link at the position of the path. If
403 \fB_AT_TRIGGER\fR is set in the \fIflag\fR argument and the vnode is a trigger
404 mount point, the mount is performed and the function returns the attributes of
405 the root of the mounted filesystem. The \fBfstatat()\fR function is a
406 multipurpose function that can be used in place of \fBstat()\fR, \fBlstat()\fR,
407 or \fBfstat()\fR. See \fBstat\fR(2)
410 The function call \fBstat(\fR\fIpath\fR\fB,\fR \fIbuf\fR\fB)\fR is identical to
411 \fBfstatat(AT_FDCWD\fR, \fIpath\fR\fB,\fR \fIbuf\fR\fB, 0)\fR.
414 The function call \fBlstat(\fR\fIpath\fR\fB,\fR \fIbuf\fR\fB)\fR is identical
415 to \fBfstatat(AT_FDCWD\fR, \fIpath\fR\fB,\fR \fIbuf\fR,
416 \fBAT_SYMLINK_NOFOLLOW)\fR
419 The function call \fBfstat(\fR\fIfildes\fR\fB,\fR \fIbuf\fR\fB)\fR is identical
420 to \fBfstatat(\fR\fIfildes\fR, \fBNULL\fR, \fIbuf\fR, \fB0)\fR.
421 .SS "Set owner and group ID"
423 .in +2
425 int fchownat (int \fIfd\fR, const char *\fIpath\fR, uid_t \fIowner\fR, gid_t \fIgroup\fR, \e
426           int \fIflag\fR)
428 .in -2
432 The \fBfchownat\fR(2) function sets the owner ID and group ID for a file. If
433 the \fIpath\fR argument is relative, it is resolved relative to the \fIfd\fR
434 argument file descriptor, otherwise the \fIfd\fR argument is ignored.  If the
435 \fIfd\fR argument is a special value \fBAT_FDCWD\fR the path is resolved
436 relative to the current working directory.  If the path argument is a null
437 pointer, the function sets the owner and group ID of the file referenced by the
438 \fIfd\fR argument.  In all other relative path cases, if the \fIfd\fR argument
439 does not refer to a valid directory, the function returns \fBENOTDIR\fR. If the
440 \fIflag\fR argument is set to \fBAT_SYMLINK_NOFOLLOW\fR, the function will not
441 automatically traverse a symbolic link at the position of the path. The
442 \fBfchownat()\fR function is a multi-purpose function that can be used in place
443 of \fBchown()\fR, \fBlchown()\fR, or \fBfchown()\fR. See \fBchown\fR(2).
446 The function call \fBchown(\fR\fIpath\fR\fB,\fR \fIowner\fR\fB,\fR
447 \fIgroup\fR\fB)\fR is equivalent to \fBfchownat(AT_FDCWD\fR, \fIpath\fR\fB,\fR
448 \fIowner\fR\fB,\fR \fIgroup\fR\fB, 0)\fR.
451 The function call \fBlchown(\fR\fIpath\fR\fB,\fR \fIowner\fR\fB,\fR
452 \fIgroup\fR\fB)\fR is equivalent to \fBfchownat(AT_FDCWD\fR, \fIpath\fR\fB,\fR
453 \fIowner\fR\fB,\fR \fIgroup\fR\fB, AT_SYMLINK_NOFOLLOW)\fR.
454 .SS "Set file access and modification times"
456 .in +2
458 int futimesat (int \fIfd\fR, const char *\fIpath\fR, const struct timeval \e
459               \fItimes\fR[2])
461 .in -2
465 The \fBfutimesat\fR(2) function sets the access and modification times for a
466 file.  If the \fIpath\fR argument is relative, it is resolved relative to the
467 \fIfd\fR argument file descriptor; otherwise the \fIfd\fR argument is ignored.
468 If the \fIfd\fR argument is the special value \fBAT_FDCWD\fR, the path is
469 resolved relative to the current working directory.  If the \fIpath\fR argument
470 is a null pointer, the function sets the access and modification times of the
471 file referenced by the \fIfd\fR argument. In all other relative path cases, if
472 the \fIfd\fR argument does not refer to a valid directory, the function returns
473 \fBENOTDIR\fR.  The \fBfutimesat()\fR function can be used in place of
474 \fButimes\fR(2).
477 The function call \fButimes(\fR\fIpath\fR\fB,\fR \fItimes\fR\fB)\fR is
478 equivalent to \fBfutimesat(AT_FDCWD\fR, \fIpath\fR\fB,\fR \fItimes\fR\fB)\fR.
479 .SS "New pathconf() functionality"
481 .in +2
483 long int pathconf(const char *\fIpath\fR, int \fIname\fR)
485 .in -2
489 Two variables have been added to \fBpathconf\fR(2) to provide enhanced support
490 for extended attribute manipulation. The \fBXATTR_ENABLED\fR variable allows an
491 application to determine if attribute support is currently enabled for the file
492 in question. The \fBXATTR_EXISTS\fR variable allows an application to determine
493 whether there are any extended attributes associated with the supplied path.
494 .SS "Open/Create an attribute file"
496 .in +2
498 int attropen (const char *\fIpath\fR, const char *\fIattrpath\fR, int \fIoflag\fR \e
499          [, mode_t \fImode\fR])
501 .in -2
505 The \fBattropen\fR(3C) function returns a file descriptor for the named
506 attribute, \fIattrpath\fR, of the file indicated by \fIpath\fR. The \fIoflag\fR
507 and \fImode\fR arguments are identical to the \fBopen\fR(2) arguments and are
508 applied to the open operation on the attribute file (for example, using the
509 \fBO_CREAT\fR flag creates a new attribute).  Once opened, all normal file
510 system operations can be used on the attribute file descriptor.  The
511 \fBattropen()\fR function is a convenience function and is equivalent to the
512 following sequence of operations:
514 .in +2
516 fd = open (path, O_RDONLY);
517 attrfd = openat(fd, attrpath, oflag|O_XATTR, mode);
518 close(fd);
520 .in -2
524 The set of existing attributes can be browsed by calling \fBattropen()\fR with
525 "." as the attribute name.  The list of attributes is obtained by calling
526 \fBgetdents\fR(2) (or \fBfdopendir\fR(3C) followed by \fBreaddir\fR(3C), see
527 below) on the returned file descriptor.
528 .SS "Convert an open file descriptor for a directory into a directory descriptor"
530 .in +2
532 DIR * fdopendir (const int \fIfd\fR)
534 .in -2
538 The \fBfdopendir\fR(3C) function promotes a file descriptor for a directory to
539 a directory pointer suitable for use with the \fBreaddir\fR(3C) function. The
540 originating file descriptor should not be used again following the call to
541 \fBfdopendir()\fR. The directory pointer should be closed with a call to
542 \fBclosedir\fR(3C). If the provided file descriptor does not reference a
543 directory, the function returns \fBENOTDIR\fR. This function is useful in
544 circumstances where the only available handle on a directory is a file
545 descriptor. See \fBattropen\fR(3C) and \fBopenat\fR(2).
546 .SS "Using the API"
549 The following examples demonstrate how the API might be used to perform basic
550 operations on extended attributes:
552 \fBExample 1 \fRList extended attributes on a file.
554 .in +2
556 attrdirfd = attropen("test", ".", O_RDONLY);
557 dirp = fdopendir(attrdirfd);
558 while (dp = readdir(dirp)) {
559 \&...
561 .in -2
564 \fBExample 2 \fROpen an extended attribute.
566 .in +2
568 attrfd = attropen("test", dp->d_name, O_RDONLY);
570 .in -2
577 .in +2
579 attrfd = openat(attrdirfd, dp->d_name, O_RDONLY);
581 .in -2
584 \fBExample 3 \fRRead from an extended attribute.
586 .in +2
588 while (read(attrfd, buf, 512) > 0) {
589 \&...
591 .in -2
594 \fBExample 4 \fRCreate an extended attribute.
596 .in +2
598 newfd = attropen("test", "attr", O_CREAT|O_RDWR);
600 .in -2
607 .in +2
609 newfd = openat(attrdirfd, "attr", O_CREAT|O_RDWR);
611 .in -2
614 \fBExample 5 \fRWrite to an extended attribute.
616 .in +2
618 count = write(newfd, buf, length);
620 .in -2
623 \fBExample 6 \fRDelete an extended attribute.
625 .in +2
627 error = unlinkat(attrdirfd, "attr");
629 .in -2
633 Applications intending to access the interfaces defined here as well as the
634 POSIX and X/Open specification-conforming interfaces should define the macro
635 \fB_ATFILE_SOURCE\fR to be 1 and set whichever feature test macros are
636 appropriate to obtain the desired environment. See \fBstandards\fR(5).
637 .SS "Extended Archive Formats"
640 As noted above in the description of command utilities modified to provide
641 support for extended attributes, the archive formats for \fBtar\fR(1) and
642 \fBcpio\fR(1) have been extended to provide support for archiving extended
643 attributes. This section describes the specifics of the archive format
644 extensions.
645 .SS "Extended tar format"
648 The \fBtar\fR archive is made up of a series of 512 byte blocks. Each archived
649 file is represented by a header block and zero or more data blocks containing
650 the file contents. The header block is structured as shown in the following
651 table.
656 c c c
657 l l l .
658 Field Name      Length (in Octets)      Description
659 Name    100     File name string
660 Mode    8       12 file mode bits
661 Uid     8       User ID of file owner
662 Gid     8       Group ID of file owner
663 Size    12      Size of file
664 Mtime   12      File modification time
665 Chksum  8       File contents checksum
666 Typeflag        1       File type flag
667 Linkname        100     Link target name if file linked
668 Magic   6       "ustar"
669 Version 2       "00"
670 Uname   32      User name of file owner
671 Gname   32      Group name of file owner
672 Devmajor        8       Major device ID if special file
673 Devminor        8       Minor device ID if special file
674 Prefix  155     Path prefix string for file
679 The extended attribute project extends the above header format by defining a
680 new header type (for the \fBTypeflag\fR field). The type 'E' is defined to be
681 used for all extended attribute files. Attribute files are stored in the
682 \fBtar\fR archive as a sequence of two \fB<header ,data>\fR pairs. The first
683 file contains the data necessary to locate and name the extended attribute in
684 the file system. The second file contains the actual attribute file data.  Both
685 files use an 'E' type header. The prefix and name fields in extended attribute
686 headers are ignored, though they should be set to meaningful values for the
687 benefit of archivers that do not process these headers. Solaris archivers set
688 the prefix field to "\fB/dev/null\fR" to prevent archivers that do not
689 understand the type 'E' header from trying to restore extended attribute files
690 in inappropriate places.
691 .SS "Extended cpio format"
694 The \fBcpio\fR archive format is octet-oriented rather than block-oriented.
695 Each file entry in the archive includes a header that describes the file,
696 followed by the file name, followed by the contents of the file.  These data
697 are arranged as described in the following table.
702 c c c
703 l l l .
704 \fBField Name\fR        Length (in Octets)      Description
705 \fBc_magic\fR   6       70707
706 \fBc_dev\fR     6       First half of unique file ID
707 \fBc_ino\fR     6       Second half of unique file ID
708 \fBc_mode\fR    6       File mode bits
709 \fBc_uid\fR     6       User ID of file owner
710 \fBc_gid\fR     6       Group ID of file owner
711 \fBc_nlink\fR   6       Number of links referencing file
712 \fBc_rdev\fR    6       Information for special files
713 \fBc_mtime\fR   11      Modification time of file
714 \fBc_namesize\fR        6       Length of file pathname
715 \fBc_filesize\fR        11      Length of file content
716 \fBc_name\fR    \fBc_namesize\fR        File pathname
717 \fBc_filedata\fR        \fBc_filesize\fR        File content
722 The basic archive file structure is not changed for extended attributes. The
723 file type bits stored in the \fBc_mode\fR field for an attribute file are set
724 to \fB0xB000\fR. As with the \fBtar\fR archive format, extended attributes are
725 stored in \fBcpio\fR archives as two consecutive file entries. The first file
726 describes the location/name for the extended attribute. The second file
727 contains the actual attribute file content. The \fBc_name\fR field in extended
728 attribute headers is ignored, though it should be set to a meaningful value for
729 the benefit of archivers that do not process these headers.  Solaris archivers
730 start the pathname with "\fB/dev/null/\fR"to prevent archivers that do not
731 understand the type 'E' header from trying to restore extended attribute files
732 in inappropriate places.
733 .SS "Attribute identification data format"
736 Both the \fBtar\fR and \fBcpio\fR archive formats can contain the special files
737 described above, always paired with the extended attribute data record, for
738 identifying the precise location of the extended attribute.  These special data
739 files are necessary because there is no simple naming mechanism for extended
740 attribute files. Extended attributes are not visible in the file system name
741 space. The extended attribute name space must be "tunneled into" using the
742 \fBopenat()\fR function. The attribute identification data must support not
743 only the flat naming structure for extended attributes, but also the
744 possibility of future extensions allowing for attribute directory hierarchies
745 and recursive attributes. The data file is therefore composed of a sequence of
746 records. It begins with a fixed length header describing  the content. The
747 following table describes the format of this data file.
752 c c c
753 l l l .
754 Field Name      Length (in Octets)      Description
755 \fBh_version\fR 7       Name file version
756 \fBh_size\fR    10      Length of data file
757 \fBh_component_len\fR   10      Total length of all path segments
758 \fBh_link_comp_len\fR   10      Total length of all link segments
759 \fBpath\fR      \fBh_component_len\fR   Complex path
760 \fBlink_path\fR \fBh_link_comp_len\fR   Complex link path
765 As demonstrated above, the header is followed by a record describing the "path"
766 to the attribute file. This path is composed of two or more path segments
767 separated by a null character. Each segment describes a path rooted at the
768 hidden extended attribute directory of the leaf file of the previous segment,
769 making it possible to name attributes on attributes.  The first segment is
770 always the path to the parent file that roots the entire sequence in the normal
771 name space. The following table describes the format of each segment.
776 c c c
777 l l l .
778 Field Name      Length (in Octets)      Description
780 \fBh_namesz\fR  7       Length of segment path
781 \fBh_typeflag\fR        1       Actual file type of attribute file
782 \fBh_names\fR   \fBh_namesz\fR  Parent path + segment path
787 If the attribute file is linked to another file, the path record is followed by
788 a second record describing the location of the referencing file.  The structure
789 of this record is identical to the record described above.
790 .SH SEE ALSO
793 \fBcp\fR(1), \fBcpio\fR(1), \fBfind\fR(1), \fBls\fR(1), \fBmv\fR(1),
794 \fBpax\fR(1), \fBrunat\fR(1), \fBtar\fR(1), \fBdu\fR(1), \fBfsck\fR(8),
795 \fBchown\fR(2), \fBlink\fR(2), \fBopen\fR(2), \fBpathconf\fR(2),
796 \fBrename\fR(2), \fBstat\fR(2), \fBunlink\fR(2), \fButimes\fR(2),
797 \fBattropen\fR(3C), \fBstandards\fR(5)