Commit Graph

35 Commits

Author SHA1 Message Date
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
Fabian Groffen eb76ca98b0 build-sys: provide alternatives for err, errx, warn and warnx
Solaris lacks err, errx, warn and warnx.  This also means the err.h header
doesn't exist.  Removed err.h include from all files, and included err.h from
c.h instead if it exists, otherwise alternatives are provided.

Signed-off-by: Fabian Groffen <grobian@gentoo.org>
2011-02-14 17:45:24 +01:00
Karel Zak 042154d764 fallocate: fix typo
Signed-off-by: Karel Zak <kzak@redhat.com>
2010-11-24 23:16:01 +01:00
Davidlohr Bueso 8abcf29002 lib: [strutils] general purpose string handling functions
This patch replaces a few functions used throughout the source:
* Renames getnum (from schedutils) to strtol_or_err
* Moves strtosize (from lib/strtosize.c)
* Moves xstrncpy (from include/xstrncpy.h)
* Adds strnlen, strnchr and strndup if not available (remove it from libmount utils)

A few Makefile.am files were modified to compile accordingly along with trivial renaming
in schedutils source code.

Signed-off-by: Davidlohr Bueso <dave@gnu.org>
2010-11-23 21:06:49 +01:00
Mike Frysinger fac8b4bd78 fallocate: fix build failure with old linux headers
If linux/falloc.h does not exist, the build system still enables the
fallocate util, but ultimately fails when it tries to include the
header and use a define from it.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
2010-10-07 09:49:01 +02:00
Karel Zak fd1ee3b92e fallocate: check for number of arguments
Signed-off-by: Karel Zak <kzak@redhat.com>
2010-05-14 13:04:50 +02:00
Karel Zak 3b6b039ae8 fallocate: support suffixes for --offset and --lenght
Signed-off-by: Karel Zak <kzak@redhat.com>
2010-03-30 14:45:37 +02:00
Karel Zak 6264af59fd fallocate: check for ERANGE errors
Signed-off-by: Karel Zak <kzak@redhat.com>
2009-10-06 23:57:11 +02:00
Karel Zak d46a54994e fallocate: new command
The fallocate(1) utility is used to preallocate blocks to a file.

This can be useful for virtual images, database files, testing, etc.
Normally we'd hope that various tools will start using preallocation
internally, but until then such a utility may be useful, and could be
scripted as well.

The original Eric's version is available at:
http://thread.gmane.org/gmane.linux.utilities.util-linux-ng/2490

This version:
 - checks for fallocate glibc function and kernel syscall
 - does not provide a fallback and does not call posix_fallocate()
 - adds long options
 - uses err.h for errro messages
 - adds NLS support
 - cleanups man page

Co-Author: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2009-09-22 15:26:18 +02:00