summaryrefslogtreecommitdiffstats
path: root/sys-utils/fallocate.c
Commit message (Collapse)AuthorAgeFilesLines
* fallocate: make posix_fadvise() use more readable for analyzersKarel Zak2019-05-231-2/+5
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* misc: consolidate version printing and close_stdout()Karel Zak2019-04-161-6/+5Star
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* fallocate: add missing semicolonMatti Niemenmaa2018-09-101-1/+1
| | | | | | | | This broke compilation when HAVE_POSIX_FALLOCATE was undefined. The typo dates to the original posix_fallocate support added in commit 833f9a7aae713278eec5f85266597482f18c7370. Signed-off-by: Matti Niemenmaa <matti.niemenmaa+git@iki.fi>
* fallocate: remove unwanted debug messageKarel Zak2018-07-041-2/+0Star
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* fallocate: add man page note about --collapse-range granularityKarel Zak2018-07-031-0/+3
| | | | | Reported-by: Radka Skvarilova <rskvaril@redhat.com> Signed-off-by: Karel Zak <kzak@redhat.com>
* fallocate: remove typoKarel Zak2017-11-291-1/+1
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* fallocate: dig holes only in data extentsKarel Zak2017-11-291-64/+55Star
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* misc: consolidate macro style USAGE_HELP_OPTIONSRuediger Meier2017-06-291-2/+2
| | | | | | | | | 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>
* misc: introduce print_usage_help_options()Ruediger Meier2017-06-271-2/+1Star
| | | | | | | | | | | | 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>
* misc: cosmetics, remove argument from usage(FILE*)Ruediger Meier2017-06-261-3/+4
| | | | | | | | | | | | | | 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>
* misc: do not use plain 0 as NULL [smatch scan]Sami Kerola2017-02-201-13/+13
| | | | | | | | | | 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>
* docs: Fix word repetitionsYuri Chornoivan2017-02-131-1/+1
|
* fallocate: Added posix_fallocate() support.Denis Chaplygin2017-01-311-1/+27
| | | | | | | No all filesystems support Linux fallocate. The new option allow use posix implementation if necessary. Signed-off-by: Karel Zak <kzak@redhat.com>
* Use --help suggestion on invalid optionKarel Zak2016-12-191-2/+1Star
| | | | | | | | 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>
* fallocate: add insert range supportFabian Frederick2016-12-021-2/+12
| | | | | | | | | | | | Based on patch 83cc932d7412 ("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>
* fallocate: fix error messageKarel Zak2015-08-251-1/+1
| | | | | | | | 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>
* misc: fix indention [smatch scan]Karel Zak2015-08-051-1/+1
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* textual: grammarize and harmonize the stat error messageBenno Schulenberg2015-02-021-1/+1
| | | | | | | | | 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>
* fallocate: create mode 0666, that's what umask is forKarel Zak2015-01-071-1/+2
| | | | | | | 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>
* textual: add a docstring to most of the utilitiesBenno Schulenberg2015-01-061-1/+4
| | | | | | | | | 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>
* textual: remove some inconsistent periods from error messagesBenno Schulenberg2014-08-111-1/+1
| | | | | | While doing so, also improve translatability and some wordings. Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
* fallocate: avoid unnecessary computationSami Kerola2014-07-171-11/+10Star
| | | | | | | | | 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>
* fallocate: use O_CREAT only for the default behaviorKarel Zak2014-06-261-1/+3
| | | | | Reported-by: Bernhard Voelker <mail@bernhard-voelker.de> Signed-off-by: Karel Zak <kzak@redhat.com>
* fallocate: fix check of number of argumentsBernhard Voelker2014-06-261-9/+9
| | | | Signed-off-by: Bernhard Voelker <mail@bernhard-voelker.de>
* fallocate: clarify usage()Pádraig Brady2014-06-261-7/+9
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* fallocate: use err_exclusive_options(), cleanup getopt_long() stuffKarel Zak2014-06-261-20/+24
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* fallocate: fix FALLOC_FL_ZERO_RANGE flag checkKarel Zak2014-06-261-3/+7
| | | | | Reported-by: Bernhard Voelker <mail@bernhard-voelker.de> Signed-off-by: Karel Zak <kzak@redhat.com>
* fallocate: add FALLOC_FL_ZERO_RANGE supportLukas Czerner2014-04-181-6/+19
| | | | | | | | 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>
* fallocate: introduce an option -c to support COLLAPSE_RANGEDongsu Park2014-04-181-17/+28
| | | | | | | | | | | | 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>
* fallocate: fix missing sentinel for is_nul()Karel Zak2014-02-191-2/+7
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* fallocate: code optimalizationsKarel Zak2014-02-191-18/+29
| | | | | | | | | | | | 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>
* fallocate: use POSIX_FADV_DONTNEED to discard cached dataKarel Zak2014-02-181-3/+27
| | | | | | | | The patch discard cached data in 1MiB (or bigger) steps. Thanks to Pádraig Brady. Signed-off-by: Karel Zak <kzak@redhat.com>
* fallocate: use SEEK_DATA on already sparse filesKarel Zak2014-02-181-3/+35
| | | | | | | | | 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>
* fallocate: improve --dig-holesKarel Zak2014-02-171-55/+71
| | | | | | | | | * 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>
* fallocate: add --verbose, clean up usage()Karel Zak2014-02-141-12/+29
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* fallocate: Add "--dig-holes" optionRodrigo Campos2014-02-141-23/+76
| | | | | | | | | | 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>
* fallocate: Hide #ifdef tricks to call fallocate in a functionRodrigo Campos2014-02-141-15/+28
| | | | | | | | | | | | 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>
* fallocate: Clarify that space can also be deallocatedRodrigo Campos2014-02-141-2/+2
| | | | | | | 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>
* fallocate: prefer FALLOC_FL_* flags from libc headersKarel Zak2014-01-131-2/+3
| | | | | Reported-by: Sami Kerola <kerolasa@iki.fi> Signed-off-by: Karel Zak <kzak@redhat.com>
* fallocate: check writing to a file descriptor was successfulSami Kerola2013-04-261-1/+2
| | | | Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* translation: unify file open error messagesSami Kerola2012-07-161-1/+1
| | | | Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* sys-utils: verify writing to streams was successfulSami Kerola2012-04-041-1/+2
| | | | Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* fallocate: add --version and align with howto-usage-function.txtSami Kerola2012-03-301-9/+12
| | | | Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* docs: corrections to FSF license files, and postal addressSami Kerola2012-02-241-3/+3
| | | | | | | | | | | | | | 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>
* fallocate: clean up fallbacks for FALLOC_FL_* flagsKarel Zak2011-11-231-1/+6
| | | | | Reported-by: Voelker, Bernhard <bernhard.voelker@siemens-enterprise.com> Signed-off-by: Karel Zak <kzak@redhat.com>
* fallocate: add FALLOC_FL_PUNCH_HOLE supportCong Wang2011-11-231-1/+7
| | | | | | | | | | | | | 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>
* fallocate: cleanup usage()Karel Zak2011-08-161-5/+7
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* move struct option to .rodataKarel Zak2011-03-031-1/+1
| | | | | | | It does not make sense to have writable large arrays of "struct option" on the stack. Signed-off-by: Karel Zak <kzak@redhat.com>
* build-sys: provide alternatives for err, errx, warn and warnxFabian Groffen2011-02-141-1/+1
| | | | | | | | 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>
* fallocate: fix typoKarel Zak2010-11-241-1/+1
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>