📄 tar.texinfo
字号:
char magic[8]; char uname[TUNMLEN]; char gname[TGNMLEN]; char devmajor[8]; char devminor[8]; /* these following fields were added by JF for gnu */ /* and are NOT standard */ char atime[12]; char ctime[12]; char offset[12]; char longnames[4]; /* the next three fields were added by JK to deal with shrinking down sparse files */ struct sparse sp[SPARSE_IN_HDR]; char isextended; char ending_blanks[12]; /* number of nulls at the end of the file, if any */ @} header; struct extended_header @{ struct sparse sp[21]; char isextended; @} ext_hdr;@};/* The checksum field is filled with this while the checksum is computed. */#define CHKBLANKS " " /* 8 blanks, no null *//* The magic field is filled with this if uname and gname are valid. */#define TMAGIC "ustar " /* 7 chars and a null *//* The magic field is filled with this if this is a GNU format dump entry */#define GNUMAGIC "GNUtar " /* 7 chars and a null *//* The linkflag defines the type of file */#define LF_OLDNORMAL '\0' /* Normal disk file, Unix compatible */#define LF_NORMAL '0' /* Normal disk file */#define LF_LINK '1' /* Link to previously dumped file */#define LF_SYMLINK '2' /* Symbolic link */#define LF_CHR '3' /* Character special file */#define LF_BLK '4' /* Block special file */#define LF_DIR '5' /* Directory */#define LF_FIFO '6' /* FIFO special file */#define LF_CONTIG '7' /* Contiguous file *//* Further link types which were defined later. */#define LF_DUMPDIR 'D' /* This is a dir entry that contains the names of files that were in the dir at the time the dump was made */#define LF_MULTIVOL 'M' /* This is the continuation of a file that began on another volume */#define LF_SPARSE 'S' /* This is for sparse files */#define LF_VOLHDR 'V' /* This file is a tape/volume header */ /* Ignore it on extraction *//* Bits used in the mode field - values in octal */#define TSUID 04000 /* Set UID on execution */#define TSGID 02000 /* Set GID on execution */#define TSVTX 01000 /* Save text (sticky bit) *//* File permissions */#define TUREAD 00400 /* read by owner */#define TUWRITE 00200 /* write by owner */#define TUEXEC 00100 /* execute/search by owner */#define TGREAD 00040 /* read by group */#define TGWRITE 00020 /* write by group */#define TGEXEC 00010 /* execute/search by group */#define TOREAD 00004 /* read by other */#define TOWRITE 00002 /* write by other */#define TOEXEC 00001 /* execute/search by other */@end exampleAll characters in header records are represented by using 8-bitcharacters in the local variant of ASCII. Each field within thestructure is contiguous; that is, there is no padding used withinthe structure. Each character on the archive medium is storedcontiguously.Bytes representing the contents of files (after the header record ofeach file) are not translated in any way and are not constrained torepresent characters in any character set. The @code{tar} formatdoes not distinguish text files from binary files, and notranslation of file contents is performed.The @code{name}, @code{linkname}, @code{magic}, @code{uname}, and@code{gname} are null-terminated character strings. All otherfileds are zero-filled octal numbers in ASCII. Each numeric fieldof width @var{w} contains @var{w} minus 2 digits, a space, and a null,except @code{size}, and @code{mtime}, which do not contain thetrailing null.The @code{name} field is the pathname of the file, with directorynames (if any) preceding the file name, separated by slashes.The @code{mode} field provides nine bits specifying file permissionsand three bits to specify the Set UID, Set GID, and Save Text(``stick'') modes. Values for these bits are defined above. Whenspecial permissions are required to create a file with a given mode,and the user restoring files from the archive does not hold suchpermissions, the mode bit(s) specifying those special permissionsare ignored. Modes which are not supported by the operating systemrestoring files from the archive will be ignored. Unsupported modesshould be faked up when creating or updating an archive; e.g. thegroup permission could be copied from the @code{other} permission.The @code{uid} and @code{gid} fields are the numeric user and groupID of the file owners, respectively. If the operating system doesnot support numeric user or group IDs, these fields should beignored.The @code{size} field is the size of the file in bytes; linked filesare archived with this field specified as zero.@xref{Extraction Options}; in particular the @samp{-G} option.@refillThe @code{mtime} field is the modification time of the file at thetime it was archived. It is the ASCII representation of the octalvalue of the last time the file was modified, represented as aninteger number of seconds since January 1, 1970, 00:00 CoordinatedUniversal Time.The @code{chksum} field is the ASCII representation of the octalvalue of the simple sum of all bytes in the header record. Each8-bit byte in the header is added to an unsigned integer,initialized to zero, the precision of which shall be no less thanseventeen bits. When calculating the checksum, the @code{chksum}field is treated as if it were all blanks.The @code{typeflag} field specifies the type of file archived. If aparticular implementation does not recognize or permit the specifiedtype, the file will be extracted as if it were a regular file. Asthis action occurs, @code{tar} issues a warning to the standarderror.The @code{atime} and @code{ctime} fields are used in making incrementalbackups; they store, respectively, the particular file's access time andlast inode-change time.The @code{offset} is used by the -M option, when making a multi-volumearchive. The offset is number of bytes into the file that we need torestart at to continue the file on the next tape, i.e., where we storethe location that a continued file is continued at.The @code{longnames} field of the header belongs with something that isnot yet implemented in tar, and is therefore empty.The following fields were added to deal with sparse files. A file is@dfn{sparse} if it takes in unallocated blocks which end up beingrepresented as zeros, i.e., no useful data. A test to see if a file issparse is to look at the number blocks allocated for it versus the number ofcharacters in the file; if there are fewer blocks allocated for the filethan would normally be allocated for a file of that size, then the file issparse. This is the method tar uses to detect a sparse file, and once sucha file is detected, it is treated differently from non-sparse files.Sparse files are often dbm files, or other database-type files which havedata at some points and emptiness in the greater part of the file. Suchfiles can appear to be very large when an @code{ls -l} is done on them,when in truth, there may be a very small amount of important datacontained in the file. It is thus undesirable to have tar think that itmust back up this entire file, as great quantities of room are wasted onempty blocks, which can lead to running out of room on a tape farearlier than is necessary. Thus, sparse files are dealt with so thatthese empty blocks are not written to the tape. Instead, what iswritten to the tape is a description, of sorts, of the sparse file: wherethe holes are, how big the holes are, and how much data is found at theend of the hole. This way, the file takes up potentially far less roomon the tape, and when the file is extracted later on, it will lookexactly the way it looked beforehand. The following is a description ofthe fields used to handle a sparse file:The @code{sp} is an array of @code{struct sparse}. Each @code{structsparse} contains two 12-character strings which represent an offset intothe file and a number of bytes to be written at that offset. The offsetis absolute, and not relative to the offset in preceding array element.The header can hold four of these @code{struct sparse} at the moment; ifmore are needed, they are not stored in the header.The @code{isextended} flag is set when an @code{extended_header} isneeded to deal with a file. Note that this means that this flag can onlybe set when dealing with a sparse file, and it is only set in the eventthat the description of the file will not fit in the alloted room forsparse structures in the header. In other words, an extended_header isneeded.The @code{extended_header} structure is used for sparse files which needmore sparse structures than can fit in the header. The header can fit4 such structures; if more are needed, the flag @code{isextended} gets setand the next record is an @code{extended_header}.Each @code{extended_header} structure contains an array of 21 sparsestructures, along with a similar @code{isextended} flag that the headerhad. There can be an indeterminate number of such @code{extended_header}sto describe a sparse file.@table @code@item LF_NORMAL@itemx LF_OLDNORMALThese flags represent a regular file. In order to be compatible witholder versions of @code{tar}, a @code{typeflag} value of@code{LF_OLDNORMAL} should be silently recognized as a regularfile. New archives should be created using @code{LF_NORMAL}. Also,for backward compatibility, @code{tar} treats a regular file whosename ends with a slash as a directory.@item LF_LINKThis flag represents a file linked to another file, of any type,previously archived. Such files are identified in Unix by each filehaving the same device and inode number. The linked-toname is specified in the @code{linkname} field with a trailing null.@item LF_SYMLINKThis represents a symbolic link to another file. The linked-toname is specified in the @code{linkname} field with a trailing null.@item LF_CHR@itemx LF_BLKThese represent character special files and block special filesrespectively. In this case the @code{devmajor} and @code{devminor}fields will contain the major and minor device numbersrespectively. Operating systems may map the device specificationsto their own local specification, or may ignore the entry.@item LF_DIRThis flag specifies a directory or sub-directory. The directory name inthe @code{name} field should end with a slash. On systems wheredisk allocation is performed on a directory basis, the @code{size}field will contain the maximum number of bytes (which may be roundedto the nearest disk block allocation unit) which the directory mayhold. A @code{size} field of zero indicates no such limiting.Systems which do not support limiting in this manner should ignorethe @code{size} field.@item LF_FIFOThis specifies a FIFO special file. Note that the archiving of aFIFO file archives the existence of this file and not its contents.@item LF_CONTIGThis specifies a contiguous file, which is the same as a normalfile except that, in operating systems which support it,all its space is allocated contiguously on the disk. Operatingsystems which do not allow contiguous allocation should silently treatthis type as a normal file.@item 'A' @dots{}@itemx 'Z'These are reserved for custom implementations. Some of these areused in the GNU modified format, as described below.@end tableOther values are reserved for specification in future revisions ofthe P1003 standard, and should not be used by any @code{tar} program.The @code{magic} field indicates that this archive was output in theP1003 archive format. If this field contains @code{TMAGIC}, the@code{uname} and @code{gname} fields will contain the ASCIIrepresentation of the owner and group of the file respectively. Iffound, the user and group ID represented by these names will be usedrather than the values within the @code{uid} and @code{gid} fields.@section GNU Extensions to the Archive FormatThe GNU format uses additional file types to describe new types offiles in an archive. These are listed below.@table @code@item LF_DUMPDIR@itemx 'D'This represents a directory and a list of files created by the@samp{-G} option. The @code{size} field gives the total size of theassociated list of files. Each filename is preceded by either a @code{'Y'}(the file should be in this archive) or an @code{'N'} (The file is adirectory, or is not stored in the archive). Each filename isterminated by a null. There is an additional null after the lastfilename.@item LF_MULTIVOL@itemx 'M'This represents a file continued from another volume of amulti-volume archive created with the @samp{-M} option. The originaltype of the file is not given here. The @code{size} field gives themaximum size of this piece of the file (assuming the volume does notend before the file is written out). The @code{offset} field givesthe offset from the beginning of the file where this part of thefile begins. Thus @code{size} plus @code{offset} should equal theoriginal size of the file.@item LF_SPARSE@itemx 'S' This flag indicates that we are dealing with a sparse file. Note thatarchiving a sparse file requires special operations to find holes in thefile, which mark the positions of these holes, along with the number ofbytes of data to be found after the hole.@item LF_VOLHDR@itemx 'V'This file type is used to mark the volume header that was given withthe @samp{-V} option when the archive was created. The @code{name}field contains the @code{name} given after the @samp{-V} option.The @code{size} field is zero. Only the first file in each volumeof an archive should have this type.@end tableYou may have trouble reading a GNU format archive on a non-GNU system ifthe options @samp{-G}, @samp{-M}, @samp{-S}, or @samp{-V} were used whenwriting the archive. In general, if tar does not use the GNU-addedfields of the header, other versions of tar should be able to read thearchive. Otherwise, the tar program will give an error, the most likelyone being a checksum error.@unnumbered Concept Index@printindex cp@setchapternewpage odd@contents@bye
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -