Bug 91134 - [smbfs] [patch] Preserve access and modification time when cp to a smbfs destination path
Summary: [smbfs] [patch] Preserve access and modification time when cp to a smbfs dest...
Status: Open
Alias: None
Product: Base System
Classification: Unclassified
Component: kern (show other bugs)
Version: 6.0-STABLE
Hardware: Any Any
: Normal Affects Only Me
Assignee: freebsd-bugs mailing list
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-12-31 11:50 UTC by Gilbert Cao
Modified: 2018-01-03 05:13 UTC (History)
1 user (show)

See Also:


Attachments
patch_cp_utils.diff (676 bytes, patch)
2005-12-31 11:50 UTC, Gilbert Cao
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Gilbert Cao 2005-12-31 11:50:02 UTC
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.

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.
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.
Comment 1 Emanuel Haupt freebsd_committer 2005-12-31 14:56:25 UTC
Responsible Changed
From-To: freebsd-bugs->ehaupt

Take.
Comment 2 Emanuel Haupt freebsd_committer 2005-12-31 15:05:37 UTC
Responsible Changed
From-To: ehaupt->freebsd-bugs

Back to freebsd-bugs, wrongly taken PR.
Comment 3 Bruce Evans 2006-01-01 00:06:48 UTC
On Sat, 31 Dec 2005, Gilbert Cao wrote:

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

This is a bug in smbfs.  cp only works on POSIX file systems.

> --- 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);
> }

It can't be right to always close the file.  This leaves the fd >= 0 case
in setfile() unused and bogotifies all the code that handles this case,
even for POSIX file systems where this code just works.  However, I can't
see any reason to have the fd >= 0 case except to avoid minor races for
regular files only.

Bruce
Comment 4 Gilbert Cao 2006-01-02 19:27:19 UTC
On Sun, Jan 01, 2006 at 11:06:48AM +1100, Bruce Evans wrote:
> On Sat, 31 Dec 2005, Gilbert Cao wrote:
> 
> >>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.
> 
> This is a bug in smbfs.  cp only works on POSIX file systems.


OK.

> 
> It can't be right to always close the file.  This leaves the fd >= 0 case
> in setfile() unused and bogotifies all the code that handles this case,
> even for POSIX file systems where this code just works.  However, I can't
> see any reason to have the fd >= 0 case except to avoid minor races for
> regular files only.


I guess I will maintain my own version of cp, until the bug in smbfs will
be correct, right ?
I don't know if I will be qualified enough to debug smbfs ;)

> 
> Bruce


-- 
--------------------------------
 (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
--------------------------------
Comment 5 Mark Linimon freebsd_committer freebsd_triage 2009-05-18 05:21:44 UTC
Responsible Changed
From-To: freebsd-bugs->freebsd-fs

Over to maintainer(s).
Comment 6 Eitan Adler freebsd_committer freebsd_triage 2017-12-31 07:59:50 UTC
For bugs matching the following criteria:

Status: In Progress Changed: (is less than) 2014-06-01

Reset to default assignee and clear in-progress tags.

Mail being skipped