-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtar.h
131 lines (115 loc) · 3.02 KB
/
tar.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#ifndef __TAR_H
#define __TAR_H
/*
* tar header block definition
*
* From IEEE Std 1003.1-1988, pp.156
*/
//POSIX magic
#define TMAGIC "ustar"
#define TMAGLEN 6
//GNU magic+version:
#define TOMAGIC "ustar "
#define TOMAGLEN 8
//POSIX version
#define TVERSION "00"
#define TVERSLEN 2
#define REGTYPE '0' /* Regular file */
#define AREGTYPE '\0' /* Regular file; old V7 format */
#define LNKTYPE '1' /* Link */
#define SYMTYPE '2' /* Symbolic link */
#define CHRTYPE '3' /* Character special */
#define BLKTYPE '4' /* Block special */
#define DIRTYPE '5' /* Directory */
#define FIFOTYPE '6' /* FIFO special */
#define CONTTYPE '7' /* Continguous file */
#define LONGLINK 'L' /* Long name Link by tantan*/
#define PAX_ENTRTY 'x' /* PAX header block for file entry : added by claybird 2011.11.29 */
#define PAX_GLOBAL 'g' /* PAX global extended header : added by claybird 2011.11.29 */
#define MULTYPE 'M' /* Added by GNUtar, not POSIX */
#define VOLTYPE 'V' /* Added by GNUtar, not POSIX */
#define TSUID 04000 /* Set UID on execution */
#define TSGID 02000 /* Set GID on execution */
#define TSVTX 01000 /* Reserved */
/* 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 */
#define TBLOCK 512
#define NAMSIZ 100
//added by claybird(2009.12.05)
#define TAR_FORMAT_GNU 0
#define TAR_FORMAT_POSIX 1
typedef union hblock {
char dummy[TBLOCK];
struct {
char name[NAMSIZ];
char mode[8];
char uid[8];
char gid[8];
char size[12];
char mtime[12];
char chksum[8];
char typeflag;
char linkname[NAMSIZ];
char magic[6];
char version[2];
char uname[32];
char gname[32];
char devmajor[8];
char devminor[8];
union _exthead{ //header extension
struct _POSIX{ //POSIX ustar format
char prefix[155];
char pad[12];
}posix;
struct _GNU{ //GNUtar format
/* Following fields were added by GNUtar */
char atime[12];
char ctime[12];
char offset[12];
}gnu;
}exthead;
} dbuf;
unsigned int compsum(){
unsigned int sum = 0;
int i;
for(i=0;i<TBLOCK;i++){
sum += (unsigned char)dummy[i];
}
/* calc without checksum field */
for(i=0;i<sizeof(dbuf.chksum);i++){
sum -= dbuf.chksum[i];
sum += ' ';
}
return sum;
}
//added by claybird(2011.01.13)
int compsum_oldtar(){
unsigned int sum = 0;
int i;
for(i=0;i<TBLOCK;i++){
sum += (signed char)dummy[i]; //different way to compute like old unix
}
/* calc without checksum field */
for(i=0;i<sizeof(dbuf.chksum);i++){
sum -= dbuf.chksum[i];
sum += ' ';
}
return sum;
}
int getFormat()const{
if(dbuf.magic[5]==TOMAGIC[5]){
return TAR_FORMAT_GNU;
}else{
return TAR_FORMAT_POSIX;
}
}
} TAR_HEADER;
#endif /* __TAR_H */