1 /**
2  * @file header.h Tar header
3  *
4  * $Id: header.h,v 1.4 2003/01/01 06:22:33 chipx86 Exp $
5  *
6  * @Copyright (C) 1999-2003 The GNUpdate Project.
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Library General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Library General Public License for more details.
17  *
18  * You should have received a copy of the GNU Library General Public
19  * License along with this library; if not, write to the
20  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21  * Boston, MA  02111-1307, USA.
22  */
23 #ifndef _TAR_HEADER_H_
24 #define _TAR_HEADER_H_
25 
26 #include "gnuext.h"
27 
28 /** Tar files are made in basic blocks of this size. */
29 #define TAR_BLOCK_SIZE 512
30 
31 /* Static values. */
32 #define TAR_MAGIC       "ustar"  /**< Tar magic (with a trailing null)     */
33 #define TAR_MAGIC_LEN   6        /**< Length of magic.                     */
34 #define TAR_VERSION     "00"     /**< Tar version (witout a trailing null) */
35 #define TAR_VERSION_LEN 2        /**< Length of version.                   */
36 
37 /* Bits used in the mode field. */
38 #define TAR_SUID         04000  /**< Set UID on execution. */
39 #define TAR_SGID         02000  /**< Set GID on execution. */
40 #define TAR_VRX          01000  /**< Reserved.             */
41 
42 /* File permissions */
43 #define TAR_USER_READ    00400  /**< Read by owner.            */
44 #define TAR_USER_WRITE   00200  /**< Write by owner.           */
45 #define TAR_USER_EXEC    00100  /**< Execute/search by owner.  */
46 #define TAR_GROUP_READ   00040  /**< Read by group.            */
47 #define TAR_GROUP_WRITE  00020  /**< Write by group.           */
48 #define TAR_GROUP_EXEC   00010  /**< Execute/search by group.  */
49 #define TAR_OTHER_READ   00004  /**< Read by other.            */
50 #define TAR_OTHER_WRITE  00002  /**< Write by other.           */
51 #define TAR_OTHER_EXEC   00001  /**< Execute/search by other.  */
52 
53 typedef enum
54 {
55 	BLOCK_STILL_UNREAD,  /**< For when tarReadHeader has not been called */
56 	BLOCK_SUCCESS,       /**< Header successfully read and checksummed.  */
57 	BLOCK_ZERO_BLOCK,    /**< Zero block where header expected.          */
58 	BLOCK_END_OF_FILE,   /**< True end of file while header expected.    */
59 	BLOCK_FAILED         /**< Ill-formed header, or bad checksum.        */
60 
61 } TarReadStatus;
62 
63 typedef enum
64 {
65 	NORMAL_FILE_0 = '\0',  /**< For compatibility with decades-old bug. */
66 	NORMAL_FILE_1 = '0',   /**< Regular file.                           */
67 	HARDLINK      = '1',   /**< Hard link.                              */
68 	SYMLINK       = '2',   /**< Symbolic link (hard if not supported).  */
69 	CHAR_DEVICE   = '3',   /**< Character device.                       */
70 	BLOCK_DEVICE  = '4',   /**< Block device.                           */
71 	DIRECTORY     = '5',   /**< Directory.                              */
72 	FIFO          = '6',   /**< Named pipe.                             */
73 	CONTIGUOUS    = '7',   /**< Contiguous file.                        */
74 	GNU_LONGLINK  = 'K',   /**< GNU long link extension.                */
75 	GNU_LONGNAME  = 'L'    /**< GNU long name extension.                */
76 
77 } TarFileType;
78 
79 typedef struct
80 {
81 	char name[100];      /**< File name.                          */
82 	char mode[8];        /**< File mode.                          */
83 	char uid[8];         /**< User ID (UID).                      */
84 	char gid[8];         /**< Group ID (GID).                     */
85 	char size[12];       /**< File size.                          */
86 	char mtime[12];      /**< Last modified timestamp.            */
87 	char checksum[8];    /**< MD5 checksum.                       */
88 	char typeFlag;       /**< Flag for the symbolic or hard link. */
89 	char linkName[100];  /**< Name for symbolic or hard link.     */
90 	char magic[6];       /**< Tar magic number.                   */
91 	char version[2];     /**< Tar version.                        */
92 	char userName[32];   /**< User name.                          */
93 	char groupName[32];  /**< Group name.                         */
94 	char majorDevice[8]; /**< Major device number.                */
95 	char minorDevice[8]; /**< Minor device number.                */
96 	char prefix[155];    /**< Prefix.                             */
97 	char padding[12];    /**< Extra padding.                      */
98 
99 	char *gnu_longname;
100 	char *gnu_longlink;
101 
102 } UstarHeader;
103 
104 typedef union
105 {
106 	char         buffer[TAR_BLOCK_SIZE];
107 	UstarHeader  header;
108 	GnuHeader    extraHeader;
109 	GnuOldHeader oldGnuHeader;
110 	SparseHeader sparseHeader;
111 
112 } TarBlock;
113 
114 TarReadStatus tarReadBlock(FILE *fp, TarBlock *block);
115 
116 #endif /* _TAR_HEADER_H_ */
117 
118