summaryrefslogtreecommitdiff
path: root/src/copy.c
AgeCommit message (Collapse)Author
2011-04-06copy: fix an unlikely memory leak when a fiemap copy failsPádraig Brady
* src/copy.c (extent_copy): Free the extents array when sparse_copy() fails.
2011-04-02cp: always detect copy-into-self: avoid infloop w/large PATH_MAXJim Meyering
When running the erroneous command, cp -rl A D D, and depending on the structure of directories A and D and the file system type (because that changes order of dir. entry traversal), cp would sometimes fail to detect that D was being copied into D, and would create D/D/D/D/D/... until it hit PATH_MAX or exhausted some resource. I noticed this via the occasional failure of the cp/into-self test when run using a ZFS file system. It is occasional because the bug is dependent on the order in which directory entries are traversed, and that is apparently indeterminate with ZFS. Technically, with the current recursive implementation, there is no risk of an infinite loop, due to stack limitations, but with an eventual fts-based implementation, it might have iterated until disk space or inodes are exhausted. * src/copy.c (copy_dir): Avoid copy-into-self interminable loop on systems with large PATH_MAX. On other systems, diagnose the copy-into- self error consistently. Handle the parameter, first_dir_created_per_command_line_arg, correctly when there are two or more sub-directories.
2011-04-01copy: process empty extents more efficientlyPádraig Brady
* src/copy.c (extent_copy): Treat an allocated but empty extent much like a hole. I.E. don't read data we know is going to be NUL. Also we convert the empty extent to a hole only when SPARSE_ALWAYS so that the source and dest have the same allocation. This will be improved soon, when we use fallocate() to do the allocation. * tests/cp/fiemap-empty: A new test for efficiency and correctness of copying empty extents. * tests/Makefile.am: Reference the new test. * NEWS: Mention the change in behavior.
2011-04-01copy: link rather than copy symlinks, when --link usedPádraig Brady
This bug was introduced in commit ca9e212c, 2009-09-24, "cp, mv: use linkat to guarantee semantics", which inadvertently disabled the creation of hardlinks to symlinks. However rather than implementing the intention of that commit and relying on gnulib linkat emulation, we'll revert to the previous emulation as that maintains ownership and timestamps. * src/copy.c (copy_internal): Use our existing hardlink to symlink emulation when link() might dereference the symlink. Also ensure that we copy the timestamps of the original symlink when we use the emulation. * tests/cp/link-symlink: Add a test to ensure timestamps copied. * tests/Makefile.am: Reference the new test. * NEWS: Mention the fix. Reported by Ruediger Meier
2011-02-11copy: adjust fiemap handling of sparse filesPádraig Brady
Don't depend on heuristics to detect sparse files if fiemap is available. Also don't scan for new holes unless --sparse=always has been specified. * src/copy.c (extent_copy): Pass the user specified sparse mode, and handle as described above.
2011-02-11copy: suppress redundant lseeks when using fiemapPádraig Brady
* src/copy.c (extent_copy): Suppress redundant lseek()s in both the source and dest files, when there is no hole between extents.
2011-02-05copy: don't let a failed lseek go undiagnosedJim Meyering
Upon failed lseek, sparse_copy_finalize would mistakenly return true. Admittedly, that is very unlikely, since that particular lseek is attempted only if the preceding call to sparse_copy induced a hole at EOF (via lseek on the destination FD). However, now that sparse_copy has an output parameter, N_READ, there is no longer any reason to call lseek (fd, 0, SEEK_CUR), so... * src/copy.c (sparse_copy_finalize): Remove the function. (copy_reg): Call ftruncate with n_read, rather than sparse_copy_finalize with its now-unnecessary lseek. Lasse Collin spotted the bug in sparse_copy_finalize.
2011-01-31cp: fix the buffer size used when writing zerosPádraig Brady
* src/copy.c (write_zeros): This bug caused 4 or 8 bytes to be written at a time which is very inefficient. One could trigger the issue with `cp --sparse=never sparse non-sparse` on a file system that supports fiemap.
2011-01-31cp: always initialize extent_copy's output parameterJim Meyering
* src/copy.c (extent_copy): Otherwise it would be used uninitialized.
2011-01-31cp: fix copying a sparse file to a pipeJim Meyering
The recent FIEMAP-related changes made it so the unusual case of copying a sparse file to a non-regular destination (e.g., a pipe) would erroneously write one byte too many to that destination. That happened because extent_copy assumed that it could use lseek to obtain the number of bytes written to the output file descriptor. That was valid only for regular files. * src/copy.c (sparse_copy): Add a parameter, to be used by extent_copy, but not by reg_copy. Adjust callers. (extent_copy): Maintain new local, dest_pos, using new arg, n_read. Don't call lseek on dest_fd; use new var, dest_pos, instead. (copy_reg): Add unused arg.
2011-01-31maint: remove unused inclusion of "fiemap.h"Jim Meyering
* src/copy.c: Don't include "fiemap.h".
2011-01-30copy, tee: assume EINTR is always defined: remove #ifdefsJim Meyering
Don't use "#ifdef EINTR". dd.c has been doing that since 2004. * src/copy.c (sparse_copy): Remove #ifdef...#endif around EINTR use. * src/tee.c (tee_files): Remove #ifdef...#endif around EINTR use. If we need it, add something like this in system.h: /* When EINTR is not defined, define it to an improbable value so that each use does not have to be #ifdef'd. */ #ifndef EINTR # define EINTR 999988 #endif
2011-01-30copy: make extent_copy use sparse_copy, rather than its own codeJim Meyering
* src/copy.c (extent_copy): Before this change, extent_copy would fail to create holes, thus breaking --sparse=auto and --sparse=always. I.e., copying a large enough file of all zeros, cp --sparse=always should introduce a hole, but with extent_copy, it would not.
2011-01-30copy: remove obsolete commentJim Meyering
* src/copy.c (sparse_copy): Remove now-obsolete comment about how we used to work around lack of ftruncate. Combine nested if conditions into one.
2011-01-30copy: factor sparse-copying code into its own function, becauseJim Meyering
we're going to have to use it from within extent_copy, too. * src/copy.c (sparse_copy): New function, factored out of... (copy_reg): ...here. Remove now-unused locals.
2011-01-30fiemap copy: avoid leak-on-errorJim Meyering
* src/copy.c (extent_copy): Don't leak an extent_scan buffer on failed lseek, read, or write.
2011-01-30fiemap copy: avoid a performance hit due to very small bufferJim Meyering
* src/copy.c (extent_copy): Don't let what should have been a temporary reduction of buf_size (to handle a short ext_len) become permanent and thus impact the performance of all further iterations.
2011-01-30fiemap copy: simplify post-loop logic; improve commentsJim Meyering
* src/copy.c (extent_copy): Avoid duplication in post-loop extend-to-desired-length code.
2011-01-30fiemap copy: rename some localsJim Meyering
(extent_copy): Rename locals: s/*ext_logical/*ext_start/
2011-01-30copy: don't allocate a separate buffer just for extent-based copyJim Meyering
* src/copy.c (copy_reg): Move use of extent_scan to just *after* we allocate the main copying buffer, so we can... (extent_scan): Take a new parameter, BUF, and use that rather than allocating a private buffer. Update caller.
2011-01-30copy: tweak variable name; improve a commentJim Meyering
* src/copy.c (copy_reg): Rename a variable to make more sense from caller's perspective: s/require_normal_copy/normal_copy_required/. This is an output-only variable, and the original name could make it look like an input (or i&o) variable.
2011-01-30copy: call extent_copy also when make_holes is false, ...Jim Meyering
so that we benefit from using extents also when reading a sparse input file with --sparse=never. * src/copy.c (copy_reg): Remove erroneous test of "make_holes" so that we call extent_copy also when make_holes is false. Otherwise, what's the point of that parameter?
2011-01-30copy: remove else-after-goto and adjust indentationJim Meyering
* src/copy.c (copy_reg): Remove useless else-after-goto.
2011-01-30extent-scan: adjust naming and formattingJim Meyering
* src/extent-scan.h [struct extent_scan]: Rename member: s/hit_last_extent/hit_final_extent/. "final" is clearer, since "last" can be interpreted as "preceding". Rename extent-scan functions to start with extent_scan_. * src/Makefile.am (copy_sources): Also distribute extent-scan.h. * src/extent-scan.c: Don't include error.h or quote.h. Neither is used. * src/copy.c: shorten a comment to fit in 80 columns * src/extent-scan.c, src/extent-scan.h: Correct formatting.
2011-01-30fiemap copy: don't let write failure go unreported; adjust style, etc.Jim Meyering
* src/copy.c (write_zeros): Add comments. (extent_copy): Move decls of "ok" and "i" down to scope where used. Adjust comments. Rename local: s/holes_len/hole_size/ Print a diagnostic upon failure to write zeros.
2011-01-30fiemap copy: add extent-scan.[ch], avoid a double-free and reorganizejeff.liu
Changes: ======== 1. fix write_zeros() per Jim's comments. 2. remove char const *fname from struct extent_scan. 3. change the signature of open_extent_scan() from "void open_extent_scan(struct extent_scan **scan)" to "void open_extent_scan(struct extent_scan *scan)" to avoid having to malloc the extent_scan variable; instead save it on the stack. 4. move close_extent_scan() from a function defined in extent-scan.c to extent-scan.h as a macro definition, but it does nothing for now, since initial extent scan defined at stack. 5. add a macro "free_extents_info()" defined at extent-scan.h to release the memory allocated to extent info which should be called combine with get_extents_info(), it just one line, so IMHO, define it as macro should be ok. * src/extent-scan.c: New file; functions to read "extents". * src/extent-scan.h: Header file of extent-scan.c. * src/Makefile.am: Reference it and link it to copy_source. * src/copy.c: Use the new functions and avoid double-free.
2011-01-30copy.c: add FIEMAP_FLAG_SYNC to fiemap ioctlJie Liu
* src/copy.c (fiemap_copy): Force kernel to sync the source file before mapping.
2011-01-30copy.c: ensure proper alignment of fiemap bufferPaul Eggert
* src/copy.c (fiemap_copy): Ensure that our fiemap buffer is large enough and well-aligned. Replace "0LL" with equivalent "0" as 3rd argument to lseek.
2011-01-30copy.c: adjust comments, tweak semanticsJim Meyering
* src/copy.c (fiemap_copy): Rename from fiemap_copy_ok. Add/improve comments. Remove local, "fail". (fiemap_copy): Do not require caller to set "normal_copy_required" before calling fiemap_copy. Report ioctl failure if it's the 2nd or subsequent call.
2011-01-30cp: copy sparse files efficiently using the FIEMAP ioctlJie Liu
* src/fiemap.h: Add fiemap.h for fiemap ioctl(2) support. Copied from linux's include/linux/fiemap.h, with minor formatting changes. * src/copy.c (copy_reg): Now, when `cp' is invoked with --sparse=[WHEN], we will try to do FIEMAP-copy if the underlying file system supports it, and fall back to a normal copy if it fails.
2011-01-13maint: trivial system header file cleanupsPádraig Brady
* src/system.h: Note where it should be included, and make ordering check portable to GLIBC > 2 * src/copy.c: Move <sys/ioctl.h> along with other system headers as is done elsewhere. * src/install.c: Move <sys/wait.h> along with other system headers as is done elsewhere. * src/ptx.c: Include <regex.h> rather than "regex.h" as is done elsewhere. Note <regex.h> is kept after "system.h" as per commit dba300a0.
2011-01-01maint: update all copyright year number rangesJim Meyering
Run "make update-copyright".
2010-12-28coreutils: keep lines within 80-column limitsPaul Eggert
* cfg.mk (LINE_LEN_MAX, FILTER_LONG_LINES): New macros. (sc_long_lines): New rule. * HACKING: Use shorter URLs to the same material. * doc/Makefile.am, doc/coreutils.texi, m4/boottime.m4: * man/help2man, man/stdbuf.x, src/Makefile.am, src/cat.c, src/copy.c: * src/cp.c, src/dd.c, src/df.c, src/du.c, src/groups.c, src/install.c: * src/ls.c, src/md5sum.c, src/mv.c, src/od.c, src/pinky.c, src/ptx.c: * src/readlink.c, src/remove.c, src/rmdir.c, src/setuidgid.c: * src/sort.c, src/tail.c, src/touch.c, tests/Coreutils.pm: * tests/cp/existing-perm-race, tests/cp/perm, tests/cp/preserve-gid: * tests/du/2g, tests/du/long-from-unreadable, tests/init.sh: * tests/install/basic-1, tests/ls/nameless-uid: * tests/ls/readdir-mountpoint-inode, tests/misc/chroot-credentials: * tests/misc/cut, tests/misc/date, tests/misc/join, tests/misc/md5sum: * tests/misc/sha1sum, tests/misc/sha224sum, tests/misc/sort: * tests/misc/sort-continue, tests/misc/sort-files0-from: * tests/misc/sort-rand, tests/misc/stdbuf, tests/misc/tr: * tests/misc/uniq, tests/mv/atomic, tests/mv/part-fail: * tests/mv/part-symlink, tests/mv/sticky-to-xpart, tests/pr/pr-tests: * tests/rm/fail-2eperm, tests/rm/interactive-always: Reformat to fit within 80 columns. * doc/Makefile.am (BAD_POSIX_PERL): New macro. * doc/coreutils.texi: Reword slightly, to make menus and index lines shorter. * src/md5sum.c: Redo --help output so that it fits within 79 columns, since that's a bit more portable and all the other --help strings fit in 79 columns.
2010-11-22cp: give a better diagnostic for nonexistent dest/Paul Eggert
This patch was written by Jim Meyering and myself. * src/copy.c (copy_reg): Turn EISDIR to ENOTDIR to improve the quality of diagnostics for commands like "cp a nosuch/". Reported by Марк Коренберг and Alan Curry in the thread starting at: http://lists.gnu.org/archive/html/bug-coreutils/2010-11/msg00178.html * THANKS: Update. * tests/mv/trailing-slash: Add a test.
2010-10-27cp: make --attributes-only override --reflink completelyPádraig Brady
* doc/coreutils.texi (cp invocation): Change the description slightly so as users might not immediately discount using this option. Mention that --reflink is overridden by the other linking options and --attributes-only, and give an example where this might be useful. * src/copy.c (copy_internal): Bypass the reflink if --attributes-only is specifed. * tests/cp/reflink-perm: Ensure both --reflink modes are overridden by --attributes-only. * NEWS: Mention the change in behavior. Reported by Jim Meyering.
2010-09-17maint: update to latest gnulibEric Blake
* gnulib: Update to latest. * src/copy.c (copy_reg): Use fdutimens instead of gl_futimens. * src/touch.c (touch): Adjust parameter order. * tests/init.sh: Resync from upstream.
2010-07-01cp: add an option to only copy the file attributesPádraig Brady
* src/copy.c (copy_attr): A new function which merges copy_attr_by_fd and copy_attr_by_name. Also display all errors when --attributes-only * src/copy.c (copy_reg): Skip copying the file contents if specified. Refactor the SELinux error handling code a little and display all SELinux errors when only copying attributes. * src/copy.h (struct cp_options): Add a data_copy_required boolean * src/cp.c (main): Default to copying data but don't if specified * src/install.c: Default to copying data * src/mv.c: Likewise tests/cp/reflink-perm: Add a test to check that --attributes-only does not copy data * tests/cp/acl: Likewise. Also refactor to remove redundant acl manipulation * doc/coreutils.texi (cp invocation): Describe the new option * NEWS: Mention the new feature
2010-05-31maint: make spacing around "=" consistent, even in IF_LINTJim Meyering
E.g., - size_t desired_width IF_LINT (= 0); + size_t desired_width IF_LINT ( = 0); Use this command: g grep -l IF_LINT | grep '\.[ch]$' \ | xargs perl -pi -e 's/(IF_LINT \()= /$1 = /'
2010-05-31maint: replace each "for (;;)" with "while (true)"Jim Meyering
Run this command: git ls-files | grep '\.[ch]$' \ | xargs perl -pi -e 's/for \(;;\)/while (true)/g' ...except for randint.c, which does not include stdbool.h. In that case, use "while (1)". * gl/lib/randint.c (randint_genmax): Use "while (1)" for infloops. * src/cat.c (simple_cat, cat): Use "while (true)" for infloops. * gl/lib/randread.c (readsource, readisaac): Likewise. * src/copy.c (copy_reg): Likewise. * src/csplit.c (record_line_starts, process_regexp): Likewise. * src/cut.c (set_fields): Likewise. * src/dd.c (iread, parse_symbols): Likewise. * src/df.c (find_mount_point, main): Likewise. * src/du.c (main): Likewise. * src/expand.c (expand): Likewise. * src/factor.c (factor_using_division, do_stdin): Likewise. * src/fmt.c (get_space): Likewise. * src/ls.c (decode_switches): Likewise. * src/od.c (main): Likewise. * src/pr.c (main, read_line): Likewise. * src/shred.c (dopass, genpattern): Likewise. * src/sort.c (initbuf, fillbuf, getmonth, keycompare): Likewise. * src/split.c (bytes_split, lines_split): Likewise. * src/tac.c (tac_seekable): Likewise. * src/test.c (and, or): Likewise. * src/tr.c (squeeze_filter, main): Likewise. * src/tsort.c (search_item): Likewise. * src/unexpand.c (unexpand): Likewise. * src/uniq.c (main): Likewise. * src/yes.c (main): Likewise.
2010-04-24maint: remove now-unnecessary #if HAVE_header_H tests.Jim Meyering
* .x-sc_prohibit_always_true_header_tests: New file. * Makefile.am (syntax_check_exceptions): Add it. * src/cat.c: Remove #if HAVE_SYS_IOCTL_H test. * src/copy.c: Likewise. * src/ls.c: Likewise. * src/stty.c: Likewise. * src/install.c: Remove #if HAVE_SYS_WAIT_H test. * src/kill.c: Likewise. * src/operand2sig.c: Likewise. * src/timeout.c: Likewise. * src/pathchk.c: Remove #if HAVE_WCHAR_H test. * src/stat.c: Remove #if HAVE_NETINET_IN_H test.
2010-04-16cp: preserve "capabilities" when also preserving file ownershipPádraig Brady
* src/copy.c (copy_reg): Copy xattrs _after_ setting file ownership so that capabilities are not cleared when setting ownership. * tests/cp/capability: A new root test. * tests/Makefile.am (root_tests): Reference the new test. * NEWS: Mention the fix.
2010-04-13cp: treat selinux warnings consistentlyPádraig Brady
* src/copy.c (copy_reg): Suppress SELinux ENOTSUP warnings consistently between the destination being present or not. Previously we did not suppress ENOTSUP messages when the destination was present. (copy_internal): Use the same ENOTSUP supression method as copy_reg() even though the issue was not seen in this case. * tests/cp/cp-a-selinux: Add a test case for the issue and group the other test cases in the file more coherently. * tests/cp/cp-mv-enotsup-xattr: Do the same check for xattr warnings, even though they did not have the issue.
2010-04-09maint: ftruncate is always available, even without gnulibJim Meyering
Now that even MinGW provides ftruncate, we know that all reasonable portability targets provide this function. Remove the workaround code. We nearly removed the gnulib module three years ago: http://thread.gmane.org/gmane.comp.lib.gnulib.bugs/9203 and it is now officially "obsolete". * bootstrap.conf (gnulib_modules): Remove ftruncate. * src/copy.c (copy_reg): Remove use of HAVE_FTRUNCATE and its no-longer-used workaround code. * src/truncate.c: Remove a comment about handling missing ftruncate.
2010-03-17maint: add a space before open-paren, where lackingJim Meyering
* src/copy.c (copy_reg): Likewise. * src/cut.c (main): Likewise. * src/dd.c (main): Likewise. * src/getlimits.c (print_int): Likewise. * src/join.c (join): Likewise. * src/pwd.c (logical_getcwd): Likewise. * src/sort.c (specify_nmerge, mergefps, avoid_trashing_input): Likewise. (merge): Likewise. * src/uptime.c (usage): Likewise.
2010-02-07copy.c: improve a commentJim Meyering
* src/copy.c (copy_reg): The comment about POSIXLY_CORRECT refers only to cp, not to any other application that uses copy.c.
2010-01-01maint: update all FSF copyright year lists to include 2010Jim Meyering
Use this command: git ls-files | grep -v COPYING \ | xargs env UPDATE_COPYRIGHT_USE_INTERVALS=1 \ build-aux/update-copyright
2009-10-10copy: allow symlink timestamp preservation on more systemsEric Blake
* src/copy.c (utimens_symlink): Simplify by using lutimens. * m4/jm-macros.m4 (coreutils_MACROS): Drop utimensat; gnulib does this for us. * tests/cp/preserve-slink-time: Recognize lutimes support.
2009-09-25cp, mv: use linkat to guarantee semanticsEric Blake
* src/copy.c (copy_internal): Use linkat, not link.
2009-09-23maint: Use logical rather than bitwise operators on boolsPádraig Brady
This is because bitwise operators are: - confusing and inconsistent in a boolean context - non short circuiting - brittle in C89 where bool can be an int (so > 1)
2009-09-21build: avoid compiler warnings on cygwin 1.5Eric Blake
* src/copy.c (utimens_symlink): Avoid unused variables. * src/su.c (getusershell): Rely on gnulib for prototype.