Skip to content
Advertisement

How to generate a PAX Tar archive with an Global Extended Attributes (‘g’) initial entry?

In Linux, I am trying to generate an uncompressed PAX archive containing a Global Extended Attributes entry using either one of the following commands:

A) Specifying the pax options (implies --xattrs):

tar cvf file.tar folder/* --xattrs --pax-option=gname:=MyGroup,uname:=MyUser

B) Specifying xattrs support (implies --format=pax):

tar cvf file.tar folder/* --format=pax --pax-option=gname:=MyGroup,uname:=MyUser

Both commands generate a file successfully, but when I open the file with my hex editor, the first entry has the ‘x’ type, instead of the expected ‘g’ type.

What am I doing wrong?

Environment:

  • Ubuntu 20.04 ARM64
  • tar tool version: GNU tar 1.30

More info

The tar tool manual specifies that --pax-option and --xattrs are the arguments to manipulate extended attributes, but does not mention anything about creating a global extended attribute entry.

If I understood it correctly, the Tar spec states that the PAX format supports two special kinds of entries:

Typeflag ‘x’

Extended Attributes entry. This is an entry that precedes the actual filesystem entry it describes. It allows the user to specify any number of attributes in the data section, using UTF8 strings, in the format BYTES NAME=VALUEn.

Typeflag ‘g’

Global Extended Attributes entry. Identical features to the ‘x’ entry, but with the difference that there is only one of this kind: this entry is located at the 0th position of the archive and describes attributes that apply to all the rest of the entries.

Sources

Advertisement

Answer

The answer was in the gnu document. I need to use the the globexthdr prefix to indicate I want to create a global extended attribute header entry, like this:

tar cvf file.tar folder/* --format=pax --pax-option=globexthdr.gname:=MyGroup,globexthdr.uname:=MyUser

I opened the generated file with an hex editor and I can confirm there is a ‘g’ entry at the beginning.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement