From owner-freebsd-bugs Tue Sep 5 23:38:08 1995 Return-Path: bugs-owner Received: (from majordom@localhost) by freefall.freebsd.org (8.6.11/8.6.6) id XAA02592 for bugs-outgoing; Tue, 5 Sep 1995 23:38:08 -0700 Received: from fgwmail.fujitsu.co.jp (fgwmail.fujitsu.co.jp [164.71.1.133]) by freefall.freebsd.org (8.6.11/8.6.6) with ESMTP id XAA02583 for ; Tue, 5 Sep 1995 23:38:02 -0700 Received: from fdmmail.fujitsu.co.jp by fgwmail.fujitsu.co.jp (8.6.12+2.5Wb4/3.3W5-MX950612-Fujitsu Mail Gateway) id PAA21420; Wed, 6 Sep 1995 15:37:53 +0900 Received: from fdm.fujitsu.co.jp by fdmmail.fujitsu.co.jp (8.6.12+2.5Wb4/3.3W5-MX950612-Fujitsu Domain Mail Master) id PAA22907; Wed, 6 Sep 1995 15:37:22 +0900 Received: from [133.160.49.9] by fdm.fujitsu.co.jp (5.65/6.4J.6) id AA15520; Wed, 6 Sep 95 15:37:21 +0900 Received: from localhost (yuhara@localhost) by cindy.avalon.flab.fujitsu.co.jp (8.6.9+2.4Wb/3.3Wb-ocsys-94092200) with SMTP id PAA04767 for ; Wed, 6 Sep 1995 15:37:20 +0900 Message-Id: <199509060637.PAA04767@cindy.avalon.flab.fujitsu.co.jp> To: freebsd-bugs@freebsd.org Subject: mv truncates files Reply-To: yuhara@flab.fujitsu.co.jp From: yuhara@flab.fujitsu.co.jp Date: Wed, 06 Sep 1995 15:37:20 +0900 Sender: bugs-owner@freebsd.org Precedence: bulk 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.