From owner-freebsd-bugs@FreeBSD.ORG Sat Dec 31 11:50:05 2005 Return-Path: X-Original-To: freebsd-bugs@hub.freebsd.org Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id F002016A41F for ; Sat, 31 Dec 2005 11:50:04 +0000 (GMT) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id 6FEC143D62 for ; Sat, 31 Dec 2005 11:50:03 +0000 (GMT) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.13.4/8.13.4) with ESMTP id jBVBo3DO074563 for ; Sat, 31 Dec 2005 11:50:03 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.13.4/8.13.4/Submit) id jBVBo3Tl074562; Sat, 31 Dec 2005 11:50:03 GMT (envelope-from gnats) Resent-Date: Sat, 31 Dec 2005 11:50:03 GMT Resent-Message-Id: <200512311150.jBVBo3Tl074562@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-bugs@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Gilbert Cao Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 5430316A41F for ; Sat, 31 Dec 2005 11:42:32 +0000 (GMT) (envelope-from hika@bsdmon.com) Received: from smtp.bsdmon.com (hosting-28.42.rev.fr.colt.net [213.41.42.28]) by mx1.FreeBSD.org (Postfix) with ESMTP id 4B25043D6E for ; Sat, 31 Dec 2005 11:42:28 +0000 (GMT) (envelope-from hika@bsdmon.com) Received: from localhost (localhost [127.0.0.1]) by smtp.bsdmon.com (Postfix) with ESMTP id 6E57E3760B4; Sat, 31 Dec 2005 12:42:27 +0100 (CET) Received: from smtp.bsdmon.com ([127.0.0.1]) by localhost (freefugu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 45043-01; Sat, 31 Dec 2005 12:41:58 +0100 (CET) Received: from mail.bsdmon.com (14.128.101-84.rev.gaoland.net [84.101.128.14]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.bsdmon.com (Postfix) with ESMTP id EBE3737606C; Sat, 31 Dec 2005 12:22:59 +0100 (CET) Received: by sdf1.bsdmon.com (Postfix, from userid 1001) id C4B72B853; Sat, 31 Dec 2005 12:22:58 +0100 (CET) Message-Id: <20051231112258.C4B72B853@sdf1.bsdmon.com> Date: Sat, 31 Dec 2005 12:22:58 +0100 (CET) From: Gilbert Cao To: FreeBSD-gnats-submit@FreeBSD.org X-Send-Pr-Version: 3.113 Cc: Gilbert Cao Subject: bin/91134: [PATCH] Preserve access and modification time when cp to a smbfs destination path X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: Gilbert Cao List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 31 Dec 2005 11:50:05 -0000 >Number: 91134 >Category: bin >Synopsis: [PATCH] Preserve access and modification time when cp to a smbfs destination path >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Sat Dec 31 11:50:02 GMT 2005 >Closed-Date: >Last-Modified: >Originator: Gilbert Cao >Release: FreeBSD 6.0-STABLE i386 >Organization: BSDMon >Environment: On the smb client machine, FreeBSD sdf1.bsdmon.com 6.0-STABLE FreeBSD 6.0-STABLE #0: Sun Nov 20 16:47:51 CET 2005 root@sdf1.bsdmon.com:/usr/obj/usr/src/sys/SDF1BSD i386 cp utility program ($FreeBSD: src/bin/cp/utils.c,v 1.45.2.1 2005/11/12 21:21:45 csjp Exp $) On the smb server machine, FreeBSD bigfugu 5.4-STABLE FreeBSD 5.4-STABLE #6: Sat Aug 20 16:03:24 CEST 2005 root@bigfugu:/usr/obj/usr/src/sys/BIGFUGU i386 Samba port version : samba-3.0.8,1 or above >Description: When I do a 'cp -p somefile /path/to/smbmountdir/anotherfolder', the access time and modification time are not preserved, even if I use the -p flag. The user doing the copy with cp is the owner of /path/to/smbmountdir. >How-To-Repeat: On the smb client side, simply $ mount_smbfs //user@machine/share /path/to/smbmountdir $ cp -p file /path/to/smbmountdir and then, compare the file's modification time on both smb client and server side. The modification time in the smb server side has been set to the current time, not the source file's modification time. >Fix: The following patch has fixed the problem as I have finally found the problem in the src/bin/cp source code, especially the utils.c file : I have found out that utimes() does nothing on the newly created file, if its file descriptor is not closed yet, and this is only the case in a SMB destination path. --- patch_cp_utils.diff begins here --- --- ./src/bin/cp/utils.c.orig Sat Nov 12 22:21:45 2005 +++ ./src/bin/cp/utils.c Fri Dec 30 19:23:04 2005 @@ -204,8 +204,6 @@ * to remove it if we created it and its length is 0. */ - if (pflag && setfile(fs, to_fd)) - rval = 1; if (pflag && preserve_fd_acls(from_fd, to_fd) != 0) rval = 1; (void)close(from_fd); @@ -213,6 +211,14 @@ warn("%s", to.p_path); rval = 1; } + /* + * To preserve times in SMB to.p_path, + * setfile() should be call *AFTER* we have closed the file + * descriptors. As we have closed the descriptors, we should + * pass -1 instead of the `to_fd` value + */ + if (pflag && setfile(fs, -1)) + rval = 1; return (rval); } --- patch_cp_utils.diff ends here --- >Release-Note: >Audit-Trail: >Unformatted: