[Toybox] [PATCH] make partprobe use more toybox functions

Isaac Dunham ibid.ag at gmail.com
Sun Jun 1 13:59:39 PDT 2014


On Sat, May 31, 2014 at 11:52:03PM -0500, Rob Landley wrote:
> I cleaned it up myself earlier today. Let me know if I missed anything...
> 
Nope, got it all.
> I thought it was in the documentation.html stuff, but that's kinda large
> at this point.
> 
> I need some sort of "intro to programming for toybox", but the best I've
> come up with so far is the toys/examples/* stuff.

No matter how much documentation you have, someone will manage to skip
or forget it.
Pointing people at one of the simpler programs using loopfiles might
help, I think.
Also, the documentation guidelines seem to be entirely outside the
source tree; documenting the [] ARG ... conventions somewhere, along
with the "simple error messages" bit might be useful.
> >> The hard part of this sort of thing is coming up with decent tests for
> >> everything. I keep meaning to properly attack the test suite, but it's
> >> about as big a timesink as doing writeups for cleanups (and updating the
> >> cleanup.html page with full series and stats and such)...
> >>
> >> Rob
> > I've sent a test for cpio, and could try covering (at least) df and link
> > shortly.
> 
> The posix spec for df has horrible corner cases having to do with read
> and write granularity. This is why I've paused in my rewrite: the idea
> that they care about this is sort of horrifying. (People say on irc that
> bell labs guys have said df's command line options were created to mock
> IBM somehow. Dunno if they're joking or not...)
> 

I'm pretty sure that was "dd", not df (parody of JCL, which is used on
IBM mainframes). 
Easy mistake; I'd meant to say du instead of df.

Speaking of du, I've got a preliminary test, but there's one detail that
I'll need clarification on:
toybox and busybox du (I don't have any others built yet) count symlinks
as having a size of 0.
Between cpio and the limited specification in POSIX--"shall count the 
size of the symbolic link (rather than the file referenced by the link)"--
I'd gotten the impression that the contents of the symlink should be
used to compute the size of a symlink; if this is correct, a symlink
should ordinarily use 4k.
Is that correct?

(On the other hand, POSIX says "when du cannot stat() files..."; the
reading I referred to would mandate calling lstat(). But then, POSIX
mandates that the contents of a symlink are globally readable, per the
specification of symlink().)

Depending what the answer to this is, we eiher pass all tests for du 
or fail 3.

The tests for link and du are attached.
> > HTH,
> > Isaac Dunham
> 
> Rob

Thanks,
Isaac Dunham
-------------- next part --------------
#!/bin/bash

[ -f testing.sh ] && . testing.sh

#testing "name" "command" "result" "infile" "stdin"

# we only test with -k since getting POSIX version is variable
# POSIXLY_CORRECT is sometimes needed, sometimes -P is needed,
# while -k is the default on most Linux systems

mkdir -p du_test/test du_2/foo
testing "du (no options)" "du -k du_test" "4\tdu_test/test\n8\tdu_test\n" "" ""
testing "du -s" "du -k -s du_test" "8\tdu_test\n" "" ""
ln -s ../du_2 du_test/xyz
# "du shall count the size of the symbolic link"
# I assume this means the space used to store the link name
testing "du counts symlinks without following" "du -ks du_test" "12\tdu_test\n" "" ""
testing "du -L follows symlinks" "du -ksL du_test" "16\tdu_test\n" "" ""
# if -H and -L are specified, the last takes priority
testing "du -HL follows symlinks" "du -ksHL du_test" "16\tdu_test\n" "" ""
testing "du -H does not follow unspecified symlinks" "du -ksH du_test" "12\tdu_test\n" "" ""
testing "du -LH does not follow unspecified symlinks" "du -ksLH du_test" "12\tdu_test\n" "" ""
testing "du -H follows specified symlinks" "du -ksH du_test/xyz" "8\tdu_test/xyz\n" "" ""

rm -rf du_test du_2

-------------- next part --------------
#!/bin/bash

[ -e testing.sh ] && . testing.sh

echo "" >foo
testing "link has same inode" "link foo bar && stat -c '%DI%i bar'" "stat -c '%DI%i' foo" "" ""
testing "link fails on non-existent file" "link foo/foo baz || echo GOOD" "GOOD\n" "" ""
rm -f foo bar


More information about the Toybox mailing list