From owner-freebsd-hackers@FreeBSD.ORG Fri Dec 30 22:14:08 2005 Return-Path: X-Original-To: freebsd-hackers@freebsd.org Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id E121C16A420 for ; Fri, 30 Dec 2005 22:14:07 +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 EEFC243D67 for ; Fri, 30 Dec 2005 22:13:59 +0000 (GMT) (envelope-from hika@bsdmon.com) Received: from localhost (localhost [127.0.0.1]) by smtp.bsdmon.com (Postfix) with ESMTP id 06445376038 for ; Fri, 30 Dec 2005 23:13:56 +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 26966-01 for ; Fri, 30 Dec 2005 23:13:28 +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 8D166375F2E for ; Fri, 30 Dec 2005 23:13:28 +0100 (CET) Received: by sdf1.bsdmon.com (Postfix, from userid 1001) id 040ADB853; Fri, 30 Dec 2005 23:13:16 +0100 (CET) Date: Fri, 30 Dec 2005 23:13:16 +0100 From: Gilbert Cao To: freebsd-hackers@freebsd.org Message-ID: <20051230221316.GA14549@bsdmon.com> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="qlTNgmc+xy1dBmNv" Content-Disposition: inline X-Operating-System: FreeBSD 6.0-STABLE i386 Organization: BSDMon X-GPG-Key: http://www.bsdmon.com/public_key.gpg User-Agent: Mutt/1.5.11 X-Virus-Scanned: amavisd-new at bsdmon.com Subject: Preserve date when cp over smbfs X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 30 Dec 2005 22:14:08 -0000 --qlTNgmc+xy1dBmNv Content-Type: multipart/mixed; boundary="0F1p//8PRICkK4MW" Content-Disposition: inline --0F1p//8PRICkK4MW Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Hi, the list. I have recently notice a problem when I copy a file to a SMB mount directory : My SMB client is a FreeBSD 6.0-STABLE. My SMB server is a FreeBSD 5.4-STABLE (with port samba-3.0.8,1). 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. Few days later, 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. Here is a small patch I have made. So pleeaaase, committers, I hope(pray) that the correction to the cp utility can be applied (with or without the patch), for the next time ;) I will be very grateful for that, as it is very important for me to preserve the modification time when I copy some photos to my file server over smbfs :) --=20 -------------------------------- (hika) Gilbert Cao http://www.miaouirc.com - MiaouIRC Project 2002-2003 http://www.bsdmon.com - The BSD DMON Power to serve IRC : #miaule at IRCNET Network -------------------------------- --0F1p//8PRICkK4MW Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="patch_cp_utils.diff" Content-Transfer-Encoding: quoted-printable --- ./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. */ =20 - if (pflag && setfile(fs, to_fd)) - rval =3D 1; if (pflag && preserve_fd_acls(from_fd, to_fd) !=3D 0) rval =3D 1; (void)close(from_fd); @@ -213,6 +211,14 @@ warn("%s", to.p_path); rval =3D 1; } + /* + * To preserve times in SMB to.p_path,=20 + * 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 =3D 1; return (rval); } =20 --0F1p//8PRICkK4MW-- --qlTNgmc+xy1dBmNv Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.2 (FreeBSD) iD8DBQFDtbD8SyQfFTqAEpcRAhioAKCfOmVDiey7z3yYYpbrCbIAvYSDeQCeI3ve x/GBVGZfJR0CXUShEKuClcc= =ob3q -----END PGP SIGNATURE----- --qlTNgmc+xy1dBmNv--