Re: cp with verify?



2007-01-12, 10:39(-08), RolandRB:
[...]
cp "$file" "$dest" || echo "failed".

I am wondering if it is possible for "cp" to return a zero return code
but the copy not to be a perfect copy.
[...]

cp will return an error if any of the open, write or close
fails.

For instance

cp file /dev/null

will succeed.

even though cmp file /dev/null will fail (unless file is empty).

write or open may fail if the virtual filesystem interface of
the system fails. For NFS or other network filesystem, it will
check for the acknowledgement of the server that the write was
successful on the other end (I beleive).

For other filesystems (like for the write on the NFS server
side), errors are most likely to be due to filesystem space,
quotas or permissions. Then the data will be lying in kernel
pages in memory with flags saying that those pages need to be
flushed to whatever devices lays underneath (which may be a disk
partition, a mtd device, loop device... potentially other layers
before it is stored to a physical storage (possibly encrypted or
duplicated...)) at some point.

You can mount filesystems with a sync option or use the O_SYNC
flag for open(2) (I don't think cp has an option to enable
that). This will make sure all the data has been flushed to
hardware when the writes and the close are done (not sure about
NFS). That won't give you a lot more guarantee, just that you
may pull the plug now or remove the USB key.

--
Stéphane
.



Relevant Pages

  • Re: NFS file truncating
    ... Goodyear Tire and Rubber Company ... > We have a P655 running as a NFS server. ... > Strange thing is, many times when it fails, the ... > is copying to a filesystem that is the NFS mounted ...
    (AIX-L)
  • Re: NFS file truncating
    ... indirection to double indirection and if you don't ... > We have a P655 running as a NFS server. ... > Strange thing is, many times when it fails, the ... > is copying to a filesystem that is the NFS mounted ...
    (AIX-L)
  • Re: Dangers of using a non-base shell
    ... fails or is updated significantly, it could break, and prevent login. ... The suggested solution was to use a base shell and append ... I've only ever heard this advice applied to the root account. ... filesystem on which bash lives fails to mount, ...
    (freebsd-questions)
  • Re: sem_open fails because /dev/shm is wrong filesystem
    ... sem_open to create a named semaphore, but this fails with an ENOSYS ... filesystem type of /dev/shm. ... Even if I explicitly mount tmpfs on /dev/shm (with mount -t tmpfs ... It's a kernel build time option located under ...
    (comp.unix.programmer)
  • Re: ubuntu - filesystem check fails on boot
    ... On Tuesday 06 Jun 2006 17:40, andy baxter ... problem where it fails the filesystem check during bootup, ...
    (comp.os.linux.misc)