<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>ものぐさ備忘録 &#187; tar</title>
	<atom:link href="http://www.ginriki.net/wd/category/tar/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.ginriki.net/wd</link>
	<description>ソフトウェア関係の話を中心とした備忘録的日記</description>
	<lastBuildDate>Sun, 16 Jan 2011 20:07:53 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.5</generator>
	<language>ja</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>色々なtarフォーマットの確認方法</title>
		<link>http://www.ginriki.net/wd/2010/06/14/136/</link>
		<comments>http://www.ginriki.net/wd/2010/06/14/136/#comments</comments>
		<pubDate>Sun, 13 Jun 2010 17:01:09 +0000</pubDate>
		<dc:creator>ginriki</dc:creator>
				<category><![CDATA[CentOS]]></category>
		<category><![CDATA[tar]]></category>

		<guid isPermaLink="false">http://www.ginriki.net/wd/?p=136</guid>
		<description><![CDATA[tarファイルには、いくつかのフォーマットがあるのだけど、何らかのコマンドで作成したtarファイルが
どのフォーマットで作られているか判断するやり方が見当たらないのでメモしとく。
なお、メジャーなフォーマットは以下]]></description>
			<content:encoded><![CDATA[<p>tarファイルには、いくつかのフォーマットがあるのだけど、何らかのコマンドで作成したtarファイルが<br />
どのフォーマットで作られているか判断するやり方が見当たらないのでメモしとく。</p>
<p>なお、メジャーなフォーマットは以下らしい<sup>1</sup>。</p>
<ul>
<li>POSIX.1-1988 ustar format</li>
<li>GNU tar format</li>
<li>POSIX.1-2001 pax format</li>
</ul>
<p>利用者から見たフォーマット間の大きな違いは、ustar形式のtarフォーマットの場合、tarでまとめる各ファイルのファイル名が256文字制限だったり、各ファイルのサイズ制限が8GBになってること。残りの２つのフォーマットは制限なし。その代わり、他と比べてustar形式は歴史がある形式なので、対応しているツールも多い。</p>
<p>ちなみに、普通のlinux上のtarプログラム(=GNU tar)がデフォルトで使うtarフォーマットは&#8211;helpを付ければわかる。<br />
以下のように、最近のtarプログラムならgnuフォーマットのはず。</p>
<pre>
# tar --help
[...略]
*This* tar defaults to:
--format=gnu -f- -b20 --quoting-style=escape --rmt-command=/sbin/rmt
</pre>
<p><br/></p>
<h1>・tarファイルのフォーマットの見分け方</h1>
<p>hexdumpコマンドでtarファイルを出力し、tarファイル内にアーカイブされた各ファイルのtarヘッダ（とpaxヘッダ)で見分けます。<sup>2</sup></p>
<p>hexdump -C <tar file>で出力された情報のなかで、<br />
それぞれのフォーマットごとに特徴的なヘッダ部分は以下。</p>
<ul>
<li>ustar format
<pre>
00000100  ...(省略)...  |.ustar.00root...|
</pre>
</li>
<li> GNU tar format
<pre>
00000100  ...(省略)...  |.ustar  .root...|
</pre>
</li>
<li>pax format
<pre>
00000000  ...(省略)...  |./PaxHeaders.108|
</pre>
</li>
</ul>
<p>以下、各フォーマットの確認例です。</p>
<pre>
# echo "hello" > foo.txt
# tar --format=gnu -cvf test.gnu.tar foo.txt
# tar --format=ustar -cvf test.ustar.tar foo.txt
# tar --format=pax -cvf test.pax.tar foo.txt

# hexdump -C test.ustar.tar
00000000  66 6f 6f 2e 74 78 74 00  00 00 00 00 00 00 00 00  |foo.txt.........|
00000010  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
00000060  00 00 00 00 30 30 30 30  36 34 34 00 30 30 30 30  |....0000644.0000|
00000070  30 30 30 00 30 30 30 30  30 30 30 00 30 30 30 30  |000.0000000.0000|
00000080  30 30 30 30 30 30 36 00  31 31 34 30 35 31 37 34  |0000006.11405174|
00000090  33 30 34 00 30 31 32 33  37 33 00 20 30 00 00 00  |304.012373. 0...|
000000a0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
00000100  00 75 73 74 61 72 00 30  30 72 6f 6f 74 00 00 00  |.ustar.00root...|
00000110  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000120  00 00 00 00 00 00 00 00  00 72 6f 6f 74 00 00 00  |.........root...|
00000130  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000140  00 00 00 00 00 00 00 00  00 30 30 30 30 30 30 30  |.........0000000|
00000150  00 30 30 30 30 30 30 30  00 00 00 00 00 00 00 00  |.0000000........|
00000160  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
00000200  68 65 6c 6c 6f 0a 00 00  00 00 00 00 00 00 00 00  |hello...........|
00000210  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
00002800

# hexdump -C test.gnu.tar
00000000  66 6f 6f 2e 74 78 74 00  00 00 00 00 00 00 00 00  |foo.txt.........|
00000010  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
00000060  00 00 00 00 30 30 30 30  36 34 34 00 30 30 30 30  |....0000644.0000|
00000070  30 30 30 00 30 30 30 30  30 30 30 00 30 30 30 30  |000.0000000.0000|
00000080  30 30 30 30 30 30 36 00  31 31 34 30 35 31 37 34  |0000006.11405174|
00000090  33 30 34 00 30 31 31 30  37 33 00 20 30 00 00 00  |304.011073. 0...|
000000a0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
00000100  00 75 73 74 61 72 20 20  00 72 6f 6f 74 00 00 00  |.ustar  .root...|
00000110  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000120  00 00 00 00 00 00 00 00  00 72 6f 6f 74 00 00 00  |.........root...|
00000130  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
00000200  68 65 6c 6c 6f 0a 00 00  00 00 00 00 00 00 00 00  |hello...........|
00000210  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
00002800

# hexdump -C test.pax.tar
00000000  2e 2f 50 61 78 48 65 61  64 65 72 73 2e 31 30 38  |./PaxHeaders.108|
00000010  31 2f 66 6f 6f 2e 74 78  74 00 00 00 00 00 00 00  |1/foo.txt.......|
00000020  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
00000060  00 00 00 00 30 30 30 30  36 34 34 00 30 30 30 30  |....0000644.0000|
00000070  30 30 30 00 30 30 30 30  30 30 30 00 30 30 30 30  |000.0000000.0000|
00000080  30 30 30 30 30 35 30 00  31 31 34 30 35 31 37 34  |0000050.11405174|
00000090  34 30 31 00 30 31 33 34  34 31 00 20 78 00 00 00  |401.013441. x...|
000000a0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
00000100  00 75 73 74 61 72 00 30  30 00 00 00 00 00 00 00  |.ustar.00.......|
00000110  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
00000140  00 00 00 00 00 00 00 00  00 30 30 30 30 30 30 30  |.........0000000|
00000150  00 30 30 30 30 30 30 30  00 00 00 00 00 00 00 00  |.0000000........|
00000160  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
00000200  32 30 20 61 74 69 6d 65  3d 31 32 37 36 34 34 32  |20 atime=1276442|
00000210  38 37 30 0a 32 30 20 63  74 69 6d 65 3d 31 32 37  |870.20 ctime=127|
00000220  36 34 34 32 38 32 30 0a  00 00 00 00 00 00 00 00  |6442820.........|
00000230  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
00000400  66 6f 6f 2e 74 78 74 00  00 00 00 00 00 00 00 00  |foo.txt.........|
00000410  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
00000460  00 00 00 00 30 30 30 30  36 34 34 00 30 30 30 30  |....0000644.0000|
00000470  30 30 30 00 30 30 30 30  30 30 30 00 30 30 30 30  |000.0000000.0000|
00000480  30 30 30 30 30 30 36 00  31 31 34 30 35 31 37 34  |0000006.11405174|
00000490  33 30 34 00 30 31 32 33  37 33 00 20 30 00 00 00  |304.012373. 0...|
000004a0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
00000500  00 75 73 74 61 72 00 30  30 72 6f 6f 74 00 00 00  |.ustar.00root...|
00000510  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000520  00 00 00 00 00 00 00 00  00 72 6f 6f 74 00 00 00  |.........root...|
00000530  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000540  00 00 00 00 00 00 00 00  00 30 30 30 30 30 30 30  |.........0000000|
00000550  00 30 30 30 30 30 30 30  00 00 00 00 00 00 00 00  |.0000000........|
00000560  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
00000600  68 65 6c 6c 6f 0a 00 00  00 00 00 00 00 00 00 00  |hello...........|
00000610  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
00002800
</pre>
<ol class="footnotes"><li id="footnote_0_136" class="footnote"><a href="http://pythonjp.sourceforge.jp/dev/library/tarfile.html">Pythonのtarfileライブラリのマニュアル</a>参照。</li><li id="footnote_1_136" class="footnote">ヘッダの概説は<a href=http://www.jp.freebsd.org/cgi/mroff.cgi?sect=5&#038;cmd=&#038;lc=1&#038;subdir=man&#038;dir=jpman-6.0.0/man&#038;subdir=man&#038;man=tar">FreeBSDのtarマニュアル</a>がわかりやすいです。もっと知りたい場合は各tar形式の仕様書を見た方が良いです。</li></ol>]]></content:encoded>
			<wfw:commentRss>http://www.ginriki.net/wd/2010/06/14/136/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

