Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 30 Dec 2005 23:13:16 +0100
From:      Gilbert Cao <hika@bsdmon.com>
To:        freebsd-hackers@freebsd.org
Subject:   Preserve date when cp over smbfs
Message-ID:  <20051230221316.GA14549@bsdmon.com>

next in thread | raw e-mail | index | archive | help

--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--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20051230221316.GA14549>