--- ./arch/alpha/kernel/osf_sys.c.firstwave	2010-01-25 14:52:25.000000000 +0300
+++ ./arch/alpha/kernel/osf_sys.c	2010-01-25 18:48:59.000000000 +0300
@@ -976,7 +976,7 @@ osf_utimes(char __user *filename, struct
 			return -EFAULT;
 	}
 
-	return do_utimes(filename, tvs ? ktvs : NULL);
+	return do_utimes(AT_FDCWD, filename, tvs ? ktvs : NULL);
 }
 
 #define MAX_SELECT_SECONDS \
--- ./arch/ppc64/kernel/sys_ppc32.c.firstwave	2010-01-25 14:52:25.000000000 +0300
+++ ./arch/ppc64/kernel/sys_ppc32.c	2010-01-25 18:48:59.000000000 +0300
@@ -1210,7 +1210,7 @@ asmlinkage long sys32_utimes(char __user
 		ptr = ktvs;
 	}
 
-	return do_utimes(filename, ptr);
+	return do_utimes(AT_FDCWD, filename, ptr);
 }
 
 long sys32_tgkill(u32 tgid, u32 pid, int sig)
--- ./arch/sparc64/kernel/sys_sparc32.c.firstwave	2010-01-25 14:52:25.000000000 +0300
+++ ./arch/sparc64/kernel/sys_sparc32.c	2010-01-25 18:48:59.000000000 +0300
@@ -1290,7 +1290,7 @@ asmlinkage long sys32_utimes(char __user
 			return -EFAULT;
 	}
 
-	return do_utimes(filename, (tvs ? &ktvs[0] : NULL));
+	return do_utimes(AT_FDCWD, filename, (tvs ? &ktvs[0] : NULL));
 }
 
 /* These are here just in case some old sparc32 binary calls it. */
--- ./fs/Makefile.firstwave	2010-01-25 14:52:25.000000000 +0300
+++ ./fs/Makefile	2010-01-25 18:53:55.000000000 +0300
@@ -10,7 +10,7 @@ obj-y :=	open.o read_write.o file_table.
 		namei.o fcntl.o ioctl.o readdir.o select.o fifo.o locks.o \
 		dcache.o inode.o attr.o bad_inode.o file.o dnotify.o \
 		filesystems.o namespace.o seq_file.o xattr.o libfs.o \
-		fs-writeback.o mpage.o direct-io.o aio.o
+		fs-writeback.o mpage.o direct-io.o aio.o utimes.o
 
 obj-$(CONFIG_EPOLL)		+= eventpoll.o
 obj-$(CONFIG_COMPAT)		+= compat.o
--- ./fs/compat.c.firstwave	2010-01-25 14:52:25.000000000 +0300
+++ ./fs/compat.c	2010-01-25 20:03:33.000000000 +0300
@@ -65,10 +65,10 @@ asmlinkage long compat_sys_utime(char __
 		tv[0].tv_usec = 0;
 		tv[1].tv_usec = 0;
 	}
-	return do_utimes(filename, t ? tv : NULL);
+	return do_utimes(AT_FDCWD, filename, t ? tv : NULL);
 }
 
-asmlinkage long compat_sys_utimes(char __user *filename, struct compat_timeval __user *t)
+asmlinkage long compat_sys_futimesat(int dfd, char __user *filename, struct compat_timeval __user *t)
 {
 	struct timeval tv[2];
 
@@ -79,7 +79,12 @@ asmlinkage long compat_sys_utimes(char _
 		    get_user(tv[1].tv_usec, &t[1].tv_usec))
 			return -EFAULT; 
 	} 
-	return do_utimes(filename, t ? tv : NULL);
+	return do_utimes(dfd, filename, t ? tv : NULL);
+}
+
+asmlinkage long compat_sys_utimes(char __user *filename, struct compat_timeval __user *t)
+{
+	return compat_sys_futimesat(AT_FDCWD, filename, t);
 }
 
 asmlinkage long compat_sys_newstat(char __user * filename,
--- ./fs/open.c.firstwave	2010-01-25 16:21:29.000000000 +0300
+++ ./fs/open.c	2010-01-25 20:18:51.000000000 +0300
@@ -437,14 +437,14 @@ out:
  * must be owner or have write permission.
  * Else, update from *times, must be owner or super user.
  */
-long do_utimes(char __user * filename, struct timeval * times)
+long do_utimes(int dfd, char __user * filename, struct timeval * times)
 {
 	int error;
 	struct nameidata nd;
 	struct inode * inode;
 	struct iattr newattrs;
 
-	error = user_path_walk(filename, &nd);
+	error = __user_walk_fd(dfd, filename, LOOKUP_FOLLOW, &nd);
 
 	if (error)
 		goto out;
@@ -484,13 +484,18 @@ out:
 	return error;
 }
 
-asmlinkage long sys_utimes(char __user * filename, struct timeval __user * utimes)
+asmlinkage long sys_futimesat(int dfd, char __user * filename, struct timeval __user * utimes)
 {
 	struct timeval times[2];
 
 	if (utimes && copy_from_user(&times, utimes, sizeof(times)))
 		return -EFAULT;
-	return do_utimes(filename, utimes ? times : NULL);
+	return do_utimes(dfd, filename, utimes ? times : NULL);
+}
+
+asmlinkage long sys_utimes(char __user * filename, struct timeval __user * utimes)
+{
+	return sys_futimesat(AT_FDCWD, filename, utimes);
 }
 
 
--- ./fs/utimes.c.firstwave	2010-01-25 18:53:07.000000000 +0300
+++ ./fs/utimes.c	2010-01-25 18:57:23.000000000 +0300
@@ -0,0 +1,185 @@
+#include <linux/file.h>
+#include <linux/fs.h>
+#include <linux/namei.h>
+#include <linux/stat.h>
+#include <linux/utime.h>
+#include <linux/compat.h>
+#include <linux/sched.h>
+#include <asm/uaccess.h>
+
+static int nsec_valid(long nsec)
+{
+	if (nsec == UTIME_OMIT || nsec == UTIME_NOW)
+		return 1;
+
+	return nsec >= 0 && nsec <= 999999999;
+}
+
+static int utimes_common(struct dentry *dentry, struct timespec *times)
+{
+	int error;
+	struct iattr newattrs;
+	struct inode *inode = dentry->d_inode;
+
+	error = -EROFS;
+	if (IS_RDONLY(inode))
+		goto out;
+
+	if (times && times[0].tv_nsec == UTIME_NOW &&
+		     times[1].tv_nsec == UTIME_NOW)
+		times = NULL;
+
+	newattrs.ia_valid = ATTR_CTIME | ATTR_MTIME | ATTR_ATIME;
+	if (times) {
+		if (times[0].tv_nsec == UTIME_OMIT)
+			newattrs.ia_valid &= ~ATTR_ATIME;
+		else if (times[0].tv_nsec != UTIME_NOW) {
+			newattrs.ia_atime.tv_sec = times[0].tv_sec;
+			newattrs.ia_atime.tv_nsec = times[0].tv_nsec;
+			newattrs.ia_valid |= ATTR_ATIME_SET;
+		}
+
+		if (times[1].tv_nsec == UTIME_OMIT)
+			newattrs.ia_valid &= ~ATTR_MTIME;
+		else if (times[1].tv_nsec != UTIME_NOW) {
+			newattrs.ia_mtime.tv_sec = times[1].tv_sec;
+			newattrs.ia_mtime.tv_nsec = times[1].tv_nsec;
+			newattrs.ia_valid |= ATTR_MTIME_SET;
+		}
+		/*
+		 * if neither ATTR_ATIME_SET nor ATTR_MTIME_SET were used
+		 * we need to check permissions, because
+		 * inode_change_ok() won't do it.
+		 */
+		if (!(newattrs.ia_valid & (ATTR_ATIME_SET | ATTR_MTIME_SET))) {
+			error = -EPERM;
+			if (current->fsuid != inode->i_uid && !capable(CAP_FOWNER))
+				goto out;
+		}
+	} else {
+		/*
+		 * If times is NULL (or both times are UTIME_NOW),
+		 * then we need to check permissions, because
+		 * inode_change_ok() won't do it.
+		 */
+		error = -EACCES;
+		if (IS_IMMUTABLE(inode))
+			goto out;
+
+		if (current->fsuid != inode->i_uid && !capable(CAP_FOWNER)) {
+			error = permission(inode, MAY_WRITE, NULL, NULL);
+			if (error)
+				goto out;
+		}
+	}
+	down(&inode->i_sem);
+	error = notify_change(dentry, &newattrs);
+	up(&inode->i_sem);
+
+out:
+	return error;
+}
+
+/*
+ * do_utimes - change times on filename or file descriptor
+ * @dfd: open file descriptor, -1 or AT_FDCWD
+ * @filename: path name or NULL
+ * @times: new times or NULL
+ * @flags: zero or more flags (only AT_SYMLINK_NOFOLLOW for the moment)
+ *
+ * If filename is NULL and dfd refers to an open file, then operate on
+ * the file.  Otherwise look up filename, possibly using dfd as a
+ * starting point.
+ *
+ * If times==NULL, set access and modification to current time,
+ * must be owner or have write permission.
+ * Else, update from *times, must be owner or super user.
+ */
+static long __do_utimes(int dfd, char __user *filename, struct timespec *times, int flags)
+{
+	int error = -EINVAL;
+
+	if (times && (!nsec_valid(times[0].tv_nsec) ||
+		      !nsec_valid(times[1].tv_nsec))) {
+		goto out;
+	}
+
+	if (flags & ~AT_SYMLINK_NOFOLLOW)
+		goto out;
+
+	if (filename == NULL && dfd != AT_FDCWD) {
+		struct file *file;
+
+		if (flags & AT_SYMLINK_NOFOLLOW)
+			goto out;
+
+		file = fget(dfd);
+		error = -EBADF;
+		if (!file)
+			goto out;
+
+		error = utimes_common(file->f_dentry, times);
+		fput(file);
+	} else {
+		struct nameidata nd;
+		int lookup_flags = 0;
+
+		if (!(flags & AT_SYMLINK_NOFOLLOW))
+			lookup_flags |= LOOKUP_FOLLOW;
+
+		error = __user_walk_fd(dfd, filename, lookup_flags, &nd);
+		if (error)
+			goto out;
+
+		error = utimes_common(nd.dentry, times);
+		path_release(&nd);
+	}
+
+out:
+	return error;
+}
+
+asmlinkage long sys_utimensat(int dfd, char __user *filename,
+		struct timespec __user *utimes, int flags)
+{
+	struct timespec tstimes[2];
+
+	if (utimes) {
+		if (copy_from_user(&tstimes, utimes, sizeof(tstimes)))
+			return -EFAULT;
+
+		/* Nothing to do, we must not even check the path.  */
+		if (tstimes[0].tv_nsec == UTIME_OMIT &&
+		    tstimes[1].tv_nsec == UTIME_OMIT)
+			return 0;
+	}
+
+	return __do_utimes(dfd, filename,  utimes ? tstimes : NULL, flags);
+}
+
+#ifdef CONFIG_COMPAT
+
+asmlinkage long compat_sys_utimensat(unsigned int dfd, char __user *filename,
+		struct compat_timespec __user *t, int flags)
+{
+	struct timespec tv[2];
+
+	if  (t) {
+		if (get_compat_timespec(&tv[0], &t[0]) ||
+		    get_compat_timespec(&tv[1], &t[1]))
+			return -EFAULT;
+
+		if ((tv[0].tv_nsec == UTIME_OMIT || tv[0].tv_nsec == UTIME_NOW)
+		    && tv[0].tv_sec != 0)
+			return -EINVAL;
+		if ((tv[1].tv_nsec == UTIME_OMIT || tv[1].tv_nsec == UTIME_NOW)
+		    && tv[1].tv_sec != 0)
+			return -EINVAL;
+
+		if (tv[0].tv_nsec == UTIME_OMIT && tv[1].tv_nsec == UTIME_OMIT)
+			return 0;
+	}
+	return __do_utimes(dfd, filename, t ? tv : NULL, flags);
+}
+
+#endif
--- ./include/linux/stat.h.firstwave	2010-01-25 14:52:26.000000000 +0300
+++ ./include/linux/stat.h	2010-01-25 18:56:37.000000000 +0300
@@ -53,6 +53,9 @@
 #define S_IWUGO		(S_IWUSR|S_IWGRP|S_IWOTH)
 #define S_IXUGO		(S_IXUSR|S_IXGRP|S_IXOTH)
 
+#define UTIME_NOW       ((1l << 30) - 1l) 
+#define UTIME_OMIT      ((1l << 30) - 2l)
+
 #include <linux/types.h>
 #include <linux/time.h>
 
--- ./include/linux/time.h.firstwave	2010-01-25 14:52:26.000000000 +0300
+++ ./include/linux/time.h	2010-01-25 18:48:59.000000000 +0300
@@ -359,7 +359,7 @@ extern int do_sys_settimeofday(struct ti
 extern void clock_was_set(void); // call when ever the clock is set
 extern int do_posix_clock_monotonic_gettime(struct timespec *tp);
 extern long do_nanosleep(struct timespec *t);
-extern long do_utimes(char __user * filename, struct timeval * times);
+extern long do_utimes(int dfd, char __user * filename, struct timeval * times);
 struct itimerval;
 extern int do_setitimer(int which, struct itimerval *value, struct itimerval *ovalue);
 extern int do_getitimer(int which, struct itimerval *value);

