Commit Graph

58 Commits

Author SHA1 Message Date
Gero Treuner 23fcac0457 fallocate: fix --dig-holes at end of files
I discovered that making a file sparse with "fallocate -d filename"
fails on the last block of a file, because - usually being partial -
the system call only zeroes that part instead of deallocating the
block. See man fallocate(2) - section "Deallocating file space".

The expected call is punching the whole block beyond eof, which
doesn't change the file length because of flag FALLOC_FL_KEEP_SIZE.

Signed-off-by: Karel Zak <kzak@redhat.com>
2020-09-14 12:03:50 +02:00
Karel Zak f1970cc557 docs: improve size arguments description in --help output
Let's add "Arguments:" section to the --help output and describe
{K,M,G...}iB suffixes there.

Addresses: https://github.com/karelzak/util-linux/pull/917
Co-Author: ed <ed@s5h.net>
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-02-05 11:01:36 +01:00
Karel Zak edf9c218c1 fallocate: make posix_fadvise() use more readable for analyzers
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-05-23 15:17:16 +02:00
Karel Zak 2c308875a7 misc: consolidate version printing and close_stdout()
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-04-16 15:14:13 +02:00
Matti Niemenmaa f1a7cfcb1d fallocate: add missing semicolon
This broke compilation when HAVE_POSIX_FALLOCATE was undefined. The typo
dates to the original posix_fallocate support added in commit
833f9a7aae.

Signed-off-by: Matti Niemenmaa <matti.niemenmaa+git@iki.fi>
2018-09-10 15:25:16 +03:00
Karel Zak 7a287e63b9 fallocate: remove unwanted debug message
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-07-04 13:37:06 +02:00
Karel Zak 562adaed91 fallocate: add man page note about --collapse-range granularity
Reported-by: Radka Skvarilova <rskvaril@redhat.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-07-03 13:51:51 +02:00
Karel Zak 09cb6b42c9 fallocate: remove typo
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-11-29 15:13:24 +01:00
Karel Zak 173ef88237 fallocate: dig holes only in data extents
Based on patch from Vaclav Dolezal <vdolezal@redhat.com>, this
implementation is less invasive.

The patch adds a new while() for pread() call (so diff is mostly code
indention). The pread() is called for a real data only (addressed by
'off' and 'end') and we use SEEK_{DATA,HOLE} before the pread() to
skip already existing holes. The variables 'file_off' and 'file_end'
addresses area in the file as specified on fallocate command line.

Test:

$ truncate -s 10G testfile
$ dd if=/dev/zero of=testfile count=10 bs=1M conv=notrunc

old version:

	$ time /usr/bin/fallocate --dig-holes --verbose testfile
	testfile: 10 GiB (10737418240 bytes) converted to sparse holes.

	real	0m3.013s
	user	0m0.700s
	sys	0m2.304s

new version:

	$ time ./fallocate --dig-holes --verbose testfile
	testfile: 10 MiB (10485760 bytes) converted to sparse holes.

	real	0m0.026s
	user	0m0.002s
	sys	0m0.004s

The old version scans all file.

The change has minimal overhead for files without holes.

Addresses: https://github.com/karelzak/util-linux/issues/421
Co-Author: Vaclav Dolezal <vdolezal@redhat.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-11-29 15:01:39 +01:00
Ruediger Meier f45f3ec34a misc: consolidate macro style USAGE_HELP_OPTIONS
changed in include/c.h and applied via sed:

  sed -i 's/fprintf.*\(USAGE_MAN_TAIL.*\)/printf(\1/' $(git ls-files -- "*.c")
  sed -i 's/print_usage_help_options\(.*\);/printf(USAGE_HELP_OPTIONS\1);/' $(git ls-files -- "*.c")

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2017-06-29 16:54:33 +02:00
Ruediger Meier b1a294c448 misc: introduce print_usage_help_options()
Consolidate --help and --version descriptions. We are
now able to align them to the other options.

We changed include/c.h. The rest of this patch was
generated by sed, plus manually setting the right
alignment numbers. We do not change anything but
white spaces in the --help output.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2017-06-27 12:26:19 +02:00
Ruediger Meier 86be6a32d3 misc: cosmetics, remove argument from usage(FILE*)
This patch is trivial and changes nothing, because
we were always using usage(stdout)

Now all our usage() functions look very similar. If wanted we
could auto-generate another big cosmetical patch to remove all
the useless "FILE *out" constants and use printf and puts
rather than their f* friends. Such patch could be automatically
synchronized with the translation project (newlines!) to not
make the translators sick.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2017-06-26 14:38:24 +02:00
Sami Kerola 8791804065 misc: do not use plain 0 as NULL [smatch scan]
text-utils/tailf.c:69:21: warning: Using plain integer as NULL pointer

Since many 'struct option' has used zero as NULL make them more readable in
same go by reindenting, and using named argument requirements.

Reference: https://lwn.net/Articles/93577/
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-02-20 12:58:49 +01:00
Yuri Chornoivan a7349ee315 docs: Fix word repetitions 2017-02-13 14:10:12 +01:00
Denis Chaplygin 833f9a7aae fallocate: Added posix_fallocate() support.
No all filesystems support Linux fallocate. The new option allow use
posix implementation if necessary.

Signed-off-by: Karel Zak <kzak@redhat.com>
2017-01-31 12:51:28 +01:00
Karel Zak 677ec86cef Use --help suggestion on invalid option
The current default is to print all usage() output. This is overkill
in many case.

Addresses: https://github.com/karelzak/util-linux/issues/338
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-12-19 13:13:34 +01:00
Fabian Frederick b439065634 fallocate: add insert range support
Based on patch 83cc932d74
("fallocate: introduce an option -c to support COLLAPSE_RANGE")

This patch includes FALLOC_FL_INSERT_RANGE flag
added to Linux kernel v4.1

Thanks to Pádraig Brady for insert range definition

Signed-off-by: Fabian Frederick <fabf@skynet.be>
2016-12-02 13:56:32 +01:00
Karel Zak 049bfa066c fallocate: fix error message
FALLOC_FL_KEEP_SIZE flag is generic and used in many situations,
"-n" in the error message does not make sense.

Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1146152
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-08-25 15:34:09 +02:00
Karel Zak 7ff635bff4 misc: fix indention [smatch scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-08-05 13:22:05 +02:00
Benno Schulenberg fc14ceba5e textual: grammarize and harmonize the stat error message
The message "stat failed %s" seems to say that stat() failed to
do something, or failed to pass a test, but of course it means
that the statting of something failed.  So say so.  Also make
two very similar messages equal to this one.

Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
2015-02-02 11:27:10 +01:00
Karel Zak 185aa9e5b8 fallocate: create mode 0666, that's what umask is for
User's umask will typically mask the mode down to 0664 or 0644.

Reported-by: Peter Cordes <peter@cordes.ca>
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-01-07 09:57:55 +01:00
Benno Schulenberg 451dbcfae1 textual: add a docstring to most of the utilities
This adds a concise description of a tool to its usage text.

A first form of this patch was proposed by Steven Honeyman
(see http://www.spinics.net/lists/util-linux-ng/msg09994.html).

Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
2015-01-06 11:27:38 +01:00
Benno Schulenberg 1d23119072 textual: remove some inconsistent periods from error messages
While doing so, also improve translatability and some wordings.

Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
2014-08-11 14:51:54 +02:00
Sami Kerola 0407c1bef9 fallocate: avoid unnecessary computation
Where POSIX_FADV_SEQUENTIAL and HAVE_POSIX_FADVISE are not available it
is waste of resources to have variables that are meaningful only for
posix_fadvise().  Also initialize the variables immediately to correct
values, and since cachesz is never changed mark it read only.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2014-07-17 14:01:00 +02:00
Karel Zak 575718a04a fallocate: use O_CREAT only for the default behavior
Reported-by: Bernhard Voelker <mail@bernhard-voelker.de>
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-06-26 14:45:02 +02:00
Bernhard Voelker 38a5440c95 fallocate: fix check of number of arguments
Signed-off-by: Bernhard Voelker <mail@bernhard-voelker.de>
2014-06-26 14:27:08 +02:00
Pádraig Brady 14c9b68096 fallocate: clarify usage()
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-06-26 13:05:16 +02:00
Karel Zak b7f3f147f2 fallocate: use err_exclusive_options(), cleanup getopt_long() stuff
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-06-26 12:38:04 +02:00
Karel Zak dac1cb536b fallocate: fix FALLOC_FL_ZERO_RANGE flag check
Reported-by: Bernhard Voelker <mail@bernhard-voelker.de>
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-06-26 12:01:13 +02:00
Lukas Czerner 1fd4f609ee fallocate: add FALLOC_FL_ZERO_RANGE support
Recent Linux kernel supports FALLOC_FL_ZERO_RANGE in fallocate(2).
This patch adds FALLOC_FL_ZERO_RANGE support to fallocate utility,
by introducing a new option -z|--zero-range.

Signed-off-by: Lukas Czerner <lczerner@redhat.com>
2014-04-18 12:49:42 +02:00
Dongsu Park 83cc932d74 fallocate: introduce an option -c to support COLLAPSE_RANGE
Introduce a new option -c (or --collapse-range) to support a new flag
FALLOC_FL_COLLAPSE_RANGE for fallocate(2). It will nullify a particular
range [offset, offset+len] by shifting extents beyond the range to the
beginning of the hole.

Cc: Lukas Czerner <lczerner@redhat.com>
Cc: Namjae Jeon <namjae.jeon@samsung.com>
Cc: Ashish Sangwan <a.sangwan@samsung.com>
Signed-off-by: Dongsu Park <dongsu.park@profitbricks.com>
2014-04-18 12:49:39 +02:00
Karel Zak 4b01c5a142 fallocate: fix missing sentinel for is_nul()
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-02-19 14:26:52 +01:00
Karel Zak c4172cc3bb fallocate: code optimalizations
Based on Pádraig Brady review:

 * use is_nul() from coreutils rather then memcmp()

 * always call skip_hole() (SEEK_DATA)

 * fix possible overflows

Signed-off-by: Karel Zak <kzak@redhat.com>
2014-02-19 10:48:16 +01:00
Karel Zak c12eff4ce0 fallocate: use POSIX_FADV_DONTNEED to discard cached data
The patch discard cached data in 1MiB (or bigger) steps.

Thanks to Pádraig Brady.

Signed-off-by: Karel Zak <kzak@redhat.com>
2014-02-18 13:01:52 +01:00
Karel Zak db5f00bc88 fallocate: use SEEK_DATA on already sparse files
It's more efficient to skip already known holes by SEEK_DATA (seek to
the next area with data).

Thanks to Pádraig Brady.

Signed-off-by: Karel Zak <kzak@redhat.com>
2014-02-18 11:38:47 +01:00
Karel Zak d6cecc3fba fallocate: improve --dig-holes
* don't use --length to specify hole size, always use stat.st_blksize

 * use --offset and --length to specify offset within the file (like
   another fallocate operations)

Signed-off-by: Karel Zak <kzak@redhat.com>
2014-02-17 11:13:54 +01:00
Karel Zak 782c290c5c fallocate: add --verbose, clean up usage()
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-02-14 14:37:51 +01:00
Rodrigo Campos 24b2a479fd fallocate: Add "--dig-holes" option
This option tries to detect chunk of '\0's and punch a hole, making the file
sparse in-place.

[kzak@redhat.com: - fix coding style, use xalloc.h and err.h]

Signed-off-by: Rodrigo Campos <rodrigo@sdfg.com.ar>
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-02-14 11:31:12 +01:00
Rodrigo Campos bcd9315d4b fallocate: Hide #ifdef tricks to call fallocate in a function
Future patches will add more calls to fallocate(), so it will be useful to have
all these tricks inside a function.

The error message when fallocate is not supported is slightly changed: the file
name is not printed as a prefix because is not available in the context of the
function. Also, to only print one of the two possible errors (as happens when
using directly exit()), an else clause was added.

Signed-off-by: Rodrigo Campos <rodrigo@sdfg.com.ar>
2014-02-14 11:00:41 +01:00
Rodrigo Campos a8d10d1c9d fallocate: Clarify that space can also be deallocated
The functionality is already there, with --punch-hole, but the text was for the
preallocation case only.

Signed-off-by: Rodrigo Campos <rodrigo@sdfg.com.ar>
2014-02-14 11:00:38 +01:00
Karel Zak bc5ddf0c00 fallocate: prefer FALLOC_FL_* flags from libc headers
Reported-by: Sami Kerola <kerolasa@iki.fi>
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-01-13 14:53:18 +01:00
Sami Kerola 5f52af507b fallocate: check writing to a file descriptor was successful
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2013-04-26 13:26:07 +02:00
Sami Kerola 289dcc9023 translation: unify file open error messages
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2012-07-16 18:18:22 +02:00
Sami Kerola efb8854f4c sys-utils: verify writing to streams was successful
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2012-04-04 19:49:40 +02:00
Sami Kerola 584aed6b02 fallocate: add --version and align with howto-usage-function.txt
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2012-03-30 16:48:12 +02:00
Sami Kerola 7cebf0bb4f docs: corrections to FSF license files, and postal address
The COPYING and Documentation/licenses/COPYING* files are being
replaced by files from GNU web site.

http://www.gnu.org/licenses/gpl-2.0.txt
http://www.gnu.org/licenses/lgpl-2.1.txt

Postal addresses to FSF in other files are updated to match with the
address in license files.

Reference: http://lists.gnu.org/archive/html/freefont-announce/2005-04/msg00001.html
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2012-02-24 14:13:35 +01:00
Karel Zak f75b8e5cdf fallocate: clean up fallbacks for FALLOC_FL_* flags
Reported-by: Voelker, Bernhard <bernhard.voelker@siemens-enterprise.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2011-11-23 15:19:20 +01:00
Cong Wang 411fd3c27a fallocate: add FALLOC_FL_PUNCH_HOLE support
Recent Linux kernel supports FALLOC_FL_PUNCH_HOLE in fallocate(2).
This patch adds FALLOC_FL_PUNCH_HOLE support to fallocate utility,
by introducing a new option -p|--punch-hole.

[kzak@redhat.com: - fix merge conflict in fallocate.1]

Cc: Karel Zak <kzak@redhat.com>
Cc: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2011-11-23 13:12:48 +01:00
Karel Zak 130bf041ba fallocate: cleanup usage()
Signed-off-by: Karel Zak <kzak@redhat.com>
2011-08-16 13:04:08 +02:00
Karel Zak 6c7d5ae9a2 move struct option to .rodata
It does not make sense to have writable large arrays of "struct
option" on the stack.

Signed-off-by: Karel Zak <kzak@redhat.com>
2011-03-03 15:00:30 +01:00