[Toybox] cpio cleanups.
Rob Landley
rob at landley.net
Sat Mar 15 13:54:35 PDT 2014
I've done three cpio cleanup commits so far:
http://landley.net/hg/toybox/rev/1221
http://landley.net/hg/toybox/rev/1222
http://landley.net/hg/toybox/rev/1223
The first two are smallish and have commit comments saying what I did.
Here's my notes from doing the third:
- Tweak arguments: add exclusion groups, make one of -iot required.
- Redo help text: tabs instead of spaces after -x
loopfiles_stdin()
- is only ever called from one place, with one function pointer
- just inline it
- why stdin? Why not arbitrary file so it could handle tar -T?
- no error message if listed file not opened?
- who said you have read access?
- perror_msg() prepends command name, lower level verror_msg() does not
write_cpio_member()
- you have a char array, and then you typecast it to a struct you never
dereference the fields of. Just use the char array. (This way we don't
have to worry about struct padding inserted by insane compiler.)
- in fact, just use toybuf instead of hdr, sprintf returns correct size
- Simplify if() to !IS_REG() && !IS_LNK()
- snprintf... we control the string, every field length controlled.
No need to specify length. Collate the format string.
- Make the last 00000000 another %08 and feed in a 0 arg, for consistency
- Add some (int) typecasting to shut up compiler warnings
- replace write() with xwrite() (catches write errors, retries short writes).
- use TT.outfd instead of hardwired 1 (for -F support).
- if readlink() fails, perror_msg() about it.
- we readlink() llen bytes and then write buf.st_size bytes, yet don't
compare them for equality?
- Remove strange lseek behavior in writing files, instead accumulate
length of reads to figure out current position in file.
- size_t out can't ever be negative so read error is lost, make it ssize_t
instead.
- what is this (nlen+2)&3 business? Padding? What's the 2 for?
Ah, the 2 is the header size (110) and 3. That was non-obvious. So
we're rounding the header size up to a multiple of 4 bytes.
main():
- Don't need else "must use -iot" if argument parsing | handled it.
Query: how to deal with files > 2gb?
- Which is worse: dying noisily or silently truncating them?
todo:
accept kernel directory format (ala get_init_cpio.c)
output kernel listing format (ala gen_initramfs_list.sh)
code sharing with tar and zip...?
Test:
archive file with permission 000 (can't open it, but for /dev node...)
1394916875.0
More information about the Toybox
mailing list