20 $ThisFileInfo[
'fileformat'] =
'tar';
21 $ThisFileInfo[
'tar'][
'files'] = array();
23 $unpack_header =
'a100fname/a8mode/a8uid/a8gid/a12size/a12mtime/a8chksum/a1typflag/a100lnkname/a6magic/a2ver/a32uname/a32gname/a8devmaj/a8devmin/a155/prefix';
24 $null_512k = str_repeat(
"\0", 512);
28 $buffer = fread($fd, 512);
32 for ($i = 0; $i < 148; $i++) {
33 $checksum += ord($buffer{$i});
35 for ($i = 148; $i < 156; $i++) {
36 $checksum += ord(
' ');
38 for ($i = 156; $i < 512; $i++) {
39 $checksum += ord($buffer{$i});
41 $attr = unpack($unpack_header, $buffer);
42 $name = trim(@$attr[
'fname']);
43 $mode = octdec(trim(@$attr[
'mode']));
44 $uid = octdec(trim(@$attr[
'uid']));
45 $gid = octdec(trim(@$attr[
'gid']));
46 $size = octdec(trim(@$attr[
'size']));
47 $mtime = octdec(trim(@$attr[
'mtime']));
48 $chksum = octdec(trim(@$attr[
'chksum']));
49 $typflag = trim(@$attr[
'typflag']);
50 $lnkname = trim(@$attr[
'lnkname']);
51 $magic = trim(@$attr[
'magic']);
52 $ver = trim(@$attr[
'ver']);
53 $uname = trim(@$attr[
'uname']);
54 $gname = trim(@$attr[
'gname']);
55 $devmaj = octdec(trim(@$attr[
'devmaj']));
56 $devmin = octdec(trim(@$attr[
'devmin']));
57 $prefix = trim(@$attr[
'prefix']);
58 if (($checksum == 256) && ($chksum == 0)) {
63 $name = $prefix.
'/'.$name;
65 if ((preg_match(
'#/$#', $name)) && !$name) {
68 if ($buffer == $null_512k) {
74 fseek($fd,
$size, SEEK_CUR);
79 fseek($fd, (512 - $diff), SEEK_CUR);
85 $ThisFileInfo[
'tar'][
'file_details'][$name] = array (
95 'linkname' => $lnkname,
100 'devmajor' => $devmaj,
101 'devminor' => $devmin
111 if ($mode & 0x1000) $type=
'p';
112 elseif ($mode & 0x2000) $type=
'c';
113 elseif ($mode & 0x4000) $type=
'd';
114 elseif ($mode & 0x6000) $type=
'b';
115 elseif ($mode & 0x8000) $type=
'-';
116 elseif ($mode & 0xA000) $type=
'l';
117 elseif ($mode & 0xC000) $type=
's';
121 $owner[
'read'] = (($mode & 00400) ?
'r' :
'-');
122 $owner[
'write'] = (($mode & 00200) ?
'w' :
'-');
123 $owner[
'execute'] = (($mode & 00100) ?
'x' :
'-');
124 $group[
'read'] = (($mode & 00040) ?
'r' :
'-');
125 $group[
'write'] = (($mode & 00020) ?
'w' :
'-');
126 $group[
'execute'] = (($mode & 00010) ?
'x' :
'-');
127 $world[
'read'] = (($mode & 00004) ?
'r' :
'-');
128 $world[
'write'] = (($mode & 00002) ?
'w' :
'-');
129 $world[
'execute'] = (($mode & 00001) ?
'x' :
'-');
132 if ($mode & 0x800) $owner[
'execute'] = ($owner[
'execute'] ==
'x') ?
's' :
'S';
133 if ($mode & 0x400) $group[
'execute'] = ($group[
'execute'] ==
'x') ?
's' :
'S';
134 if ($mode & 0x200) $world[
'execute'] = ($world[
'execute'] ==
'x') ?
't' :
'T';
136 $s = sprintf(
'%1s', $type);
137 $s .= sprintf(
'%1s%1s%1s', $owner[
'read'], $owner[
'write'], $owner[
'execute']);
138 $s .= sprintf(
'%1s%1s%1s', $group[
'read'], $group[
'write'], $group[
'execute']);
139 $s .= sprintf(
'%1s%1s%1s'.
"\n", $world[
'read'], $world[
'write'], $world[
'execute']);
145 static $flag_types = array(
155 'K' =>
'LF_LONGLINK',
156 'L' =>
'LF_LONGNAME',
157 'M' =>
'LF_MULTIVOL',
162 return @$flag_types[$typflag];