Date: Wed, 06 Sep 1995 15:37:20 +0900 From: yuhara@flab.fujitsu.co.jp To: freebsd-bugs@freebsd.org Subject: mv truncates files Message-ID: <199509060637.PAA04767@cindy.avalon.flab.fujitsu.co.jp>
next in thread | raw e-mail | index | archive | help
Bug Report: cross device "mv" corrupts files FreeBSD version: 2.1.0-SNAP-950726 File: /usr/src/bin/mv/mv.c Symptom: If a owner of a file is not a member of the group ID of the source file, cross device "mv" by the owner sometimes TRUNCATES the file, especially when the destination is in a NFS mounted directory. The source file is deleted so there is no way to retrieve the lost data!! Detail: For cross device "mv", "mv" opens the source and the destination, copies data, closes the source, changes uid/gid/mode of the destination (fchown(), fchmod()), and then closes the destination. Problem occurs when fchown() fails. My guess: When an error occurs during fchown(), the written data that is in the buffer cache but not yet transferred to a disk is regarded as erronous and is abandoned in the kernel. Either the filesystem or "mv" is wrong. Since I don't know the intended semantics of the filesystem of FreeBSD, I can't say which is wrong. If "mv" is the culprit, the fix seems to be simple. Close the destination just after the copy. Use chown(), chmod() instead of fchown(), fchmod(). (I'm not on the mailing lists. Please include my address in your reply.) ------ Masanobu Yuhara yuhara@flab.fujitsu.co.jp Fujitsu Laboratories Ltd.
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199509060637.PAA04767>