Skip to contentSkip to conversation

hostfs: fix setting the timestamps of files

PATCH In review Tobias Brunner 2 participants 2 messages Nov 10, 2009 – Dec 15, 2009 User-mode Linux (UML)

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 hostfs: fix setting the timestamps of files

When setting the timestamps of a file using e.g. futimens the flag HOSTFS_ATTR_(A|M)TIME_SET is set only if explicit timestamps were specified. If futimens is called without timestamps (i.e. parameter times is set to NULL), only HOSTFS_ATTR_(A|M)TIME is set. On the other hand, the latter flag is also set if the timestamps were explicitly specified.

---
 fs/hostfs/hostfs_user.c |   15 ++++-----------
 1 files changed, 4 insertions(+), 11 deletions(-)
fs/hostfs/hostfs_user.c +0 -0
index b79424f..3da7cdd 100644
@@ -277,7 +277,8 @@ int set_attr(const char *file, struct hostfs_iattr

*attrs, int fd)
* times according to the changes to perform, and then call futimes()
* or utimes() to apply them.
*/
- ma = (HOSTFS_ATTR_ATIME_SET | HOSTFS_ATTR_MTIME_SET);
+ /* Note: ctime is not handled */
+ ma = (HOSTFS_ATTR_ATIME | HOSTFS_ATTR_MTIME);
if (attrs->ia_valid & ma) {
err = stat_file(file, NULL, NULL, NULL, NULL, NULL, NULL,
&atime_ts, &mtime_ts, NULL, NULL, NULL, fd);
@@ -289,11 +290,11 @@ int set_attr(const char *file, struct hostfs_iattr *attrs, int fd)
times[1].tv_sec = mtime_ts.tv_sec; times[1].tv_usec = mtime_ts.tv_nsec / 1000;

- if (attrs->ia_valid & HOSTFS_ATTR_ATIME_SET) {
+ if (attrs->ia_valid & HOSTFS_ATTR_ATIME) {
times[0].tv_sec = attrs->ia_atime.tv_sec; times[0].tv_usec = attrs->ia_atime.tv_nsec / 1000;
}
- if (attrs->ia_valid & HOSTFS_ATTR_MTIME_SET) {
+ if (attrs->ia_valid & HOSTFS_ATTR_MTIME) {
times[1].tv_sec = attrs->ia_mtime.tv_sec; times[1].tv_usec = attrs->ia_mtime.tv_nsec / 1000;
}
@@ -306,14 +307,6 @@ int set_attr(const char *file, struct hostfs_iattr *attrs, int fd)
}
}

- /* Note: ctime is not handled */
- if (attrs->ia_valid & (HOSTFS_ATTR_ATIME | HOSTFS_ATTR_MTIME)) {
- err = stat_file(file, NULL, NULL, NULL, NULL, NULL, NULL,
- &attrs->ia_atime, &attrs->ia_mtime, NULL,
- NULL, NULL, fd);
- if (err != 0)
- return err;
- }
return 0;
}

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july
_______________________________________________
User-mode-linux-devel mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel

Acked-by on v1 1/1
#1 lore raw
Quoted 8 lines · On Tuesday 10 November 2009 07:50:21 Tobias Brunner wrote:

When setting the timestamps of a file using e.g. futimens the flag HOSTFS_ATTR_(A|M)TIME_SET is set only if explicit timestamps were specified. If futimens is called without timestamps (i.e. parameter times is set to NULL), only HOSTFS_ATTR_(A|M)TIME is set. On the other hand, the latter flag is also set if the timestamps were explicitly specified.

I hit this bug too, and this patch fixed it for me, so:

Speaking of which, here's a pending patch of my own reparented on top of this one:

From: Rob Landley <[email protected]>

Switch futimes() usage to Posix 2008 futimens(), and while I'm at migrate utimes() to utimensat() and eliminate use of timeval.

This is required to build UML against uClibc.

---

 fs/hostfs/hostfs_user.c |   32 +++++++++++++++++---------------
 1 file changed, 17 insertions(+), 15 deletions(-)
fs/hostfs/hostfs_user.c +17 -15
@@ -3,6 +3,12 @@
  * Licensed under the GPL
  */
 
+/* These two #defines are needed for futimens and utimensat until glibc
+   catches up with posix 2008. */
+
+#define __USE_ATFILE
+#define __USE_GNU
+
 #include <stdio.h>
 #include <stddef.h>
 #include <unistd.h>
@@ -235,8 +241,7 @@
 
 int set_attr(const char *file, struct hostfs_iattr *attrs, int fd)
 {
-	struct timeval times[2];
-	struct timespec atime_ts, mtime_ts;
+	struct timespec time_ts[2];
 	int err, ma;
 
 	if (attrs->ia_valid & HOSTFS_ATTR_MODE) {
@@ -280,29 +285,26 @@
 	ma = (HOSTFS_ATTR_ATIME | HOSTFS_ATTR_MTIME);
 	if (attrs->ia_valid & ma) {
 		err = stat_file(file, NULL, NULL, NULL, NULL, NULL, NULL,
-				&atime_ts, &mtime_ts, NULL, NULL, NULL, fd);
+				time_ts, time_ts+1, NULL, NULL, NULL, fd);
 		if (err != 0)
 			return err;
 
-		times[0].tv_sec = atime_ts.tv_sec;
-		times[0].tv_usec = atime_ts.tv_nsec / 1000;
-		times[1].tv_sec = mtime_ts.tv_sec;
-		times[1].tv_usec = mtime_ts.tv_nsec / 1000;
-
 		if (attrs->ia_valid & HOSTFS_ATTR_ATIME) {
-			times[0].tv_sec = attrs->ia_atime.tv_sec;
-			times[0].tv_usec = attrs->ia_atime.tv_nsec / 1000;
+			time_ts[0].tv_sec = attrs->ia_atime.tv_sec;
+			time_ts[0].tv_nsec = attrs->ia_atime.tv_nsec;
 		}
 		if (attrs->ia_valid & HOSTFS_ATTR_MTIME) {
-			times[1].tv_sec = attrs->ia_mtime.tv_sec;
-			times[1].tv_usec = attrs->ia_mtime.tv_nsec / 1000;
+			time_ts[1].tv_sec = attrs->ia_mtime.tv_sec;
+			time_ts[1].tv_nsec = attrs->ia_mtime.tv_nsec;
 		}
 
 		if (fd >= 0) {
-			if (futimes(fd, times) != 0)
+			if (futimens(fd, time_ts) != 0)
 				return -errno;
-		} else if (utimes(file, times) != 0) {
-			return -errno;
+		} else {
+			if (utimensat(AT_FDCWD, file, time_ts, 0) != 0) {
+				return -errno;
+			}
 		}
 	}
 
Signature · 11 lines
Latency is more important than throughput. It's that simple. - Linus Torvalds

------------------------------------------------------------------------------
Return on Information:
Google Enterprise Search pays you back
Get the facts.
http://p.sf.net/sfu/google-dev2dev
_______________________________________________
User-mode-linux-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel