[Toybox] [PATCH] Implement file(1).
Isaac Dunham
ibid.ag at gmail.com
Sat Feb 13 13:57:12 PST 2016
On Sat, Feb 13, 2016 at 09:56:29AM -0800, enh wrote:
> Unlike the POSIX file(1), there's no magic file here, just hard-coded
> common (non-obsolete) file formats. Personally most of my use of file(1)
> is as a one-line readelf(1) summarizer, so although I assume a full POSIX
> file(1) is out of scope (because just the database would likely be larger
> than all the rest of toybox), a subset that only supports in-use file types
> actually covers most of the use cases I encounter personally.
FYI:
binary cpio (almost never seen) starts with a short having the octal value
070707; there are big- and little-endian variants, so 0143561 is
'byte-swapped cpio archive'
text-based cpio magic is a 6-byte string starting with "0707"
"ASCII cpio archive"
070707 is 'odc' - "(pre-SVR4 orr odc)"
070701 is 'newc' - "(SVR4 with no CRC)",
070702 is 'newc' - "(SVR4 with CRC)"
One of my own main uses for file is to check the interpreter for a script.
Standard output format is something like
"<interpreter> script, ASCII text executable"
"#!/bin/sh" becomes 'POSIX shell', while "#!/usr/bin/perl -w" becomes
'a /usr/bin/perl -w'
Tar magic is at offset 257:
'ustar\0' - "POSIX tar archive"
'ustar\040\040\0' - "GNU tar archive"
AFAICT, zip usually starts with 'PK\003\004', 'PK\005\006' (empty), or
'PK\007\008' (spanned archive).
HTH,
Isaac Dunham
1455400632.0
More information about the Toybox
mailing list