[PATCH] add discard option -d to swapon

Matt Whitlock busybox at mattwhitlock.name
Sun Mar 23 22:09:59 UTC 2014


On Sunday, 23 March 2014, at 8:29 pm, Tito wrote:
> On Sunday 23 March 2014 00:33:04 Matt Whitlock wrote:
> > Attached are a series of three patches affecting swaponoff.
> 
> Hi,
> attached you will find a alternative patch to your patches #1 and #2 that includes your fixes and
> improvements and reworks swap_on_off_main to allow you to implement patch #3 without
> creating a #ifdef hell.
> I hope that the code is also easier readable than the original
> unpatched version.

So are the main improvements here the use of the IF_FEATURE* macros and testing the ENABLE_FEATURE* macros at the C level rather than at the preprocessor level? This is still going to create a "hell" when adding the discard flag. Consider what will happen in the enum: if DISCARD is enabled but PRI is disabled, then OPT_d will be (1 << 1), but if both are enabled, then OPT_p will be (1 << 1) and OPT_d will be (1 << 2) (or vice versa). Imagine adding five more optional features. It leads to a combinatorial explosion. It's cleaner to downshift the bitmap after checking each bit within its appropriate #if section.

I do agree that I could clean up the construction of the options string using the IF_FEATURE* macros. See attached patch.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-improve-code-readability-using-IF_FEATURE-macros.patch
Type: text/x-patch
Size: 1429 bytes
Desc: not available
URL: <http://lists.busybox.net/pipermail/busybox/attachments/20140323/f624e8c1/attachment.bin>


More information about the busybox mailing list