Commit Graph

49 Commits

Author SHA1 Message Date
Karel Zak 18b3e5495b swapon: split swapon-common.c
swapon    - requires libmount and libblkid
 swapoff   - requires libmount
 swaplabel - requires libblkid

This patch add lib/swapprober.c with blkid stuff for swap. It allows
to use and link libblkid only when necessary.

Signed-off-by: Karel Zak <>
2014-09-22 13:16:25 +02:00
Sami Kerola 3077ff49f3 swapon: remove invalid error string print outs
To avoid messages like this:

$ swapon /dev/zram0
swapon: /dev/zram0: read swap header failed: Success

Signed-off-by: Sami Kerola <>
2014-08-11 14:51:56 +02:00
Karel Zak a3c74d88e1 swapon: don't print errors as data in smartcols table
Signed-off-by: Karel Zak <>
2014-07-22 12:29:38 +02:00
Karel Zak 7c1fa4691f swapon: don't use empty strings for smartcols output
The libsmartcols is smart enough to accept NULL for empty fields
rather than empty strings.

Signed-off-by: Karel Zak <>
2014-07-22 12:24:56 +02:00
Sami Kerola 5db57cfc46 swapon: share get_swap_prober() with swaplabel to print uuid and label
The swapon(8) listing was almost complete, apart from label and uuid.
This change moves the code from swaplabel(8) to shared scope to be used
for printouts in other swap commands, such as swapon.

Adding this feature to lsblk(8) was a consideration, but lsblk is not
interested of swapfiles, so the swapon seems like a better option to add
this information.

Signed-off-by: Sami Kerola <>
2014-07-22 12:17:20 +02:00
Karel Zak a560a3487b swapon: clean up columns[] usage
Signed-off-by: Karel Zak <>
2014-07-18 13:53:02 +02:00
Karel Zak a6c6662d7c swapon: mark --sumarry as deprecated
Signed-off-by: Karel Zak <>
2014-06-30 11:03:12 +02:00
Sami Kerola 7471244148 swapon: align --summary fields
This commit makes  partitions and files to have remaining three columns
aligned.  Below print out demonstrates earlier misalignment.

$ swapon -s
Filename                                Type            Size    Used    Priority
/dev/sda2                               partition       4194300 0       3
/home/src/util-linux/newswap            file    496     0       -1

Signed-off-by: Sami Kerola <>
2014-06-30 10:43:04 +02:00
Karel Zak 710ed55dcd libsmartcols: add debug messages
Signed-off-by: Karel Zak <>
2014-06-06 13:47:06 +02:00
Sami Kerola 24f83f7392 swapon, swapheader, mkswap: move swap signature to header
Both swapon and mkswap need to know what is valid device signature, so
share the value.

[ - use SWAP_SIGNATURE_SZ properly in write_signature()]

Signed-off-by: Sami Kerola <>
Signed-off-by: Karel Zak <>
2014-05-06 10:16:54 +02:00
Sami Kerola eb397d19e4 swapon: swaps with legacy version label are not supported
Reviewed-by: Benno Schulenberg <>
Signed-off-by: Sami Kerola <>
2014-05-06 10:12:14 +02:00
Sami Kerola 8a101b1447 mkswap, swaplabel: move version number to header
Corrently only the swap version 1 is supported, which is a magic value so
move it to header.

Signed-off-by: Sami Kerola <>
2014-05-04 11:42:03 +01:00
Karel Zak 0925a9dd6c libsmartcols: clean up flags usage
* rename flags functions to scols_table_enable_*
 * rename *_no_foo() functions to _nofoo()
 * output formats are mutually exclusive, so don't use flags there
 * don't assume symbols in scols_new_table(), use scols_table_set_symbols()

Signed-off-by: Karel Zak <>
2014-04-03 16:09:57 +02:00
Karel Zak e516634844 swapon: clean up scols usage
Signed-off-by: Karel Zak <>
2014-04-03 12:29:20 +02:00
Ondrej Oprala 248a7f70dd swapon: use libsmartcols
Signed-off-by: Ondrej Oprala <>
2014-04-03 12:29:19 +02:00
Karel Zak 3173ea8e7f swapon: use TT_FL_FREEDATA for tt table
Signed-off-by: Karel Zak <>
2013-09-16 16:46:59 +02:00
Rafael Aquini d6387c98cb swapon: allow a more flexible swap discard policy
Introduce the necessary changes to swapon(8) allowing a sysadmin to leverage
the new changes introduced to sys_swapon by "swap: discard while swapping
only if SWAP_FLAG_DISCARD_PAGES", therefore allowing a more flexible set of
choices when selection the discard policy for mounted swap areas.
This patch introduces the following optional arguments to the already
existent swapon(8) "--discard" option, in order to allow a discard type to
be selected at swapon time:
 * once    : only single-time area discards are issued. (swapon)
 * pages   : discard freed pages before they are reused.
If no policy is selected both discard types are enabled. (default)

[ - support <policy> argument for short -d option too,
                  - add errx() on unsupported policy name]

Signed-off-by: Rafael Aquini <>
Acked-by: KOSAKI Motohiro <>
Signed-off-by: Karel Zak <>
2013-08-23 12:50:39 +02:00
Karel Zak 6195f9e6fa misc: use libmnt_cache reference counting
Signed-off-by: Karel Zak <>
2013-08-21 14:38:38 +02:00
Karel Zak a2f17bb24e libmount: add mnt_table_is_empty(), improve table list usage
Currently you have to use mnt_table_remove_fs() + mnt_free_fs() to
destroy the list in the table. This is complicated in same situations.
This patch allows to use mnt_free_fs() only.

Signed-off-by: Karel Zak <>
2013-08-20 14:35:13 +02:00
Sami Kerola 1469971535 swapon: check writing to a file descriptor was successful
Signed-off-by: Sami Kerola <>
2013-04-26 13:26:07 +02:00
Sami Kerola 07ff972eb6 translation: unify exec error messages
Signed-off-by: Sami Kerola <>
2013-02-06 11:51:17 +01:00
Sami Kerola d96b743f3f swapon: default to --show if nothing is requested
Proposed-by: Karel Zak <>
Signed-off-by: Sami Kerola <>
2013-01-09 13:37:21 +01:00
Karel Zak cd04b26bf8 swapon: print warning about insecure owner/permissions
Let's make it more obvious if swap area is accessible for non-root
users. The old version prints the warning only if --verbose is

Signed-off-by: Karel Zak <>
2013-01-08 13:15:52 +01:00
Karel Zak 880f09c828 swapon: fix memmory leak [coverity scan]
Signed-off-by: Karel Zak <>
2012-12-12 12:40:48 +01:00
Karel Zak a0e35e3044 swapon: don't care about xasprintf() return code
Signed-off-by: Karel Zak <>
2012-12-12 12:18:20 +01:00
Sami Kerola e09bd8d0c5 swapon: remove loop declaration [smatch scan]
sys-utils/swapon.c:677:2: error: 'for' loop initial declarations are
only allowed in C99 mode

Signed-off-by: Sami Kerola <>
2012-10-15 16:53:59 +02:00
Sami Kerola 9db6a74905 swapon: check numeric user inputs
Signed-off-by: Sami Kerola <>
Signed-off-by: Karel Zak <>
2012-10-15 15:48:32 +02:00
Sami Kerola 289dcc9023 translation: unify file open error messages
Signed-off-by: Sami Kerola <>
2012-07-16 18:18:22 +02:00
Sami Kerola add1b8afd0 translation: unify stat error messages
Signed-off-by: Sami Kerola <>
2012-07-16 18:18:22 +02:00
Sami Kerola b9136477e6 swapon: remove unused variables
Signed-off-by: Sami Kerola <>
2012-07-16 18:18:21 +02:00
Sami Kerola 0aec470c2f swapon: fix --summary output regression
Commit 64b588814e changed --summary
header alignment, and usage of spaces vs tabs in output.

Signed-off-by: Sami Kerola <>
2012-07-10 13:45:31 +02:00
Sami Kerola 7ae8b469ad swapon: make --show size to be human readable by default
Cc: Bernhard Voelker <>
Signed-off-by: Sami Kerola <>

Signed-off-by: Karel Zak <>
2012-07-10 13:45:04 +02:00
Sami Kerola e076b5526f swapon: add --show option
The --show uses lib/tt.c, which allows user to specify columns he is
interested of, and avoids using hard coded field sizes which may be
problematic when system has large enough swap.

[ - improve usage(), remove unused code]

Cc: Bernhard Voelker <>
Signed-off-by: Sami Kerola <>
Signed-off-by: Karel Zak <>
2012-07-10 13:41:59 +02:00
Karel Zak 59114ba325 swapon: fix typo
Reported-by: Manan Tuli <>
Signed-off-by: Karel Zak <>
2012-06-27 14:04:03 +02:00
Karel Zak 9f9d0f21c4 swapon: add support for PARTUUID= and PARTLABEL=
Signed-off-by: Karel Zak <>
2012-04-19 14:40:22 +02:00
Karel Zak d335c9bd54 swapon: minor coding style changes
Signed-off-by: Karel Zak <>
2012-04-18 12:58:15 +02:00
Karel Zak 8b0d534155 swapon: cleanup usage()
Signed-off-by: Karel Zak <>
2012-04-18 12:52:13 +02:00
Karel Zak d9f07b100d swapon: cleanup main()
Signed-off-by: Karel Zak <>
2012-04-18 12:44:14 +02:00
Karel Zak 6cf8d46cee swapoff: move code from swapon.c to swapoff.c
* multipurpose binaries (symlinks) suck when used with autotools
 * swapoff shares small subset of the code with swapon
 * usage() and 'struct option' is unnecessary complex when shared
 * shorter and simple code is easer to maintain...

Signed-off-by: Karel Zak <>
2012-04-18 11:43:42 +02:00
Karel Zak 0b0c231f64 swapon: move generic code to swapon-common.c
This will allow to use separate binary for swapon and swapoff.

Signed-off-by: Karel Zak <>
2012-04-18 11:21:12 +02:00
Karel Zak 5072b90a65 swapon: use libmount for fstab parsing (for swapon --all)
Signed-off-by: Karel Zak <>
2012-04-18 10:14:44 +02:00
Karel Zak e5157fc9f0 swapon: use only libmount for paths/tags evealuation
libmount provides very simple API for paths and tags canonicalizations,
let's use it, rather directly link to libblkid and lib/canonicalize.c.

Signed-off-by: Karel Zak <>
2012-04-17 13:05:04 +02:00
Karel Zak 64b588814e swapon: use libmount for /proc/swaps parsing
Signed-off-by: Karel Zak <>
2012-04-17 12:49:11 +02:00
Sami Kerola efb8854f4c sys-utils: verify writing to streams was successful
Signed-off-by: Sami Kerola <>
2012-04-04 19:49:40 +02:00
Karel Zak b5b2c388dc swapon: use directly blkid rather than fsprobe wrapper
* remove dependence on lib/fsprobe.c

 * reuse already read swap header for --fixpgsz (don't re-read the
   header by libblkid)

Signed-off-by: Karel Zak <>
2012-03-27 12:13:24 +02:00
Dave Reisner 99d618c0eb checkxalloc: nudge regex, fix newfound instances
Using the -w flag with grep actually fought against us here, and hid
some instances where xalloc functions weren't used. Discard it in
favor of an explicit word boundary as a prefix to the function name,
and extend our requirements on the trailing side of the pattern.

This also fixes the few new instances that were overlooked because of
the regex's deficiency.

[ - fix also newfound in findmnt
                  - remove unnecessary checks after xallocs]

Signed-off-by: Dave Reisner <>
Signed-off-by: Karel Zak <>
2012-03-20 09:44:40 +01:00
Davidlohr Bueso f9bd085879 sys-utils: fix typos
Signed-off-by: Davidlohr Bueso <>
2012-02-24 14:15:40 +01:00
Karel Zak f8ff4ebb15 swapon: add break to keep static analysers happy 2012-01-31 20:59:54 +01:00
Karel Zak 143635c91f build-sys: move swapon from mount/ to sys-utils/
... to make it independent on mount stuff.

Signed-off-by: Karel Zak <>
2012-01-11 12:14:29 +01:00