1 #include <linux/compiler.h>
3 #include <linux/linkage.h>
4 #include <linux/namei.h>
5 #include <linux/sched.h>
6 #include <linux/utime.h>
7 #include <asm/uaccess.h>
8 #include <asm/unistd.h>
10 #ifdef __ARCH_WANT_SYS_UTIME
13 * sys_utime() can be implemented in user-level using sys_utimes().
14 * Is this for backwards compatibility? If so, why not move it
15 * into the appropriate arch directory (for those architectures that
19 /* If times==NULL, set access and modification to current time,
20 * must be owner or have write permission.
21 * Else, update from *times, must be owner or super user.
23 asmlinkage
long sys_utime(char __user
* filename
, struct utimbuf __user
* times
)
28 struct iattr newattrs
;
30 error
= user_path_walk(filename
, &nd
);
33 inode
= nd
.dentry
->d_inode
;
39 /* Don't worry, the checks are done in inode_change_ok() */
40 newattrs
.ia_valid
= ATTR_CTIME
| ATTR_MTIME
| ATTR_ATIME
;
43 if (IS_APPEND(inode
) || IS_IMMUTABLE(inode
))
46 error
= get_user(newattrs
.ia_atime
.tv_sec
, ×
->actime
);
47 newattrs
.ia_atime
.tv_nsec
= 0;
49 error
= get_user(newattrs
.ia_mtime
.tv_sec
, ×
->modtime
);
50 newattrs
.ia_mtime
.tv_nsec
= 0;
54 newattrs
.ia_valid
|= ATTR_ATIME_SET
| ATTR_MTIME_SET
;
57 if (IS_IMMUTABLE(inode
))
60 if (current
->fsuid
!= inode
->i_uid
&&
61 (error
= vfs_permission(&nd
, MAY_WRITE
)) != 0)
64 mutex_lock(&inode
->i_mutex
);
65 error
= notify_change(nd
.dentry
, &newattrs
);
66 mutex_unlock(&inode
->i_mutex
);
75 /* If times==NULL, set access and modification to current time,
76 * must be owner or have write permission.
77 * Else, update from *times, must be owner or super user.
79 long do_utimes(int dfd
, char __user
*filename
, struct timeval
*times
)
84 struct iattr newattrs
;
86 error
= __user_walk_fd(dfd
, filename
, LOOKUP_FOLLOW
, &nd
);
90 inode
= nd
.dentry
->d_inode
;
96 /* Don't worry, the checks are done in inode_change_ok() */
97 newattrs
.ia_valid
= ATTR_CTIME
| ATTR_MTIME
| ATTR_ATIME
;
100 if (IS_APPEND(inode
) || IS_IMMUTABLE(inode
))
103 newattrs
.ia_atime
.tv_sec
= times
[0].tv_sec
;
104 newattrs
.ia_atime
.tv_nsec
= times
[0].tv_usec
* 1000;
105 newattrs
.ia_mtime
.tv_sec
= times
[1].tv_sec
;
106 newattrs
.ia_mtime
.tv_nsec
= times
[1].tv_usec
* 1000;
107 newattrs
.ia_valid
|= ATTR_ATIME_SET
| ATTR_MTIME_SET
;
110 if (IS_IMMUTABLE(inode
))
113 if (current
->fsuid
!= inode
->i_uid
&&
114 (error
= vfs_permission(&nd
, MAY_WRITE
)) != 0)
117 mutex_lock(&inode
->i_mutex
);
118 error
= notify_change(nd
.dentry
, &newattrs
);
119 mutex_unlock(&inode
->i_mutex
);
126 asmlinkage
long sys_futimesat(int dfd
, char __user
*filename
, struct timeval __user
*utimes
)
128 struct timeval times
[2];
130 if (utimes
&& copy_from_user(×
, utimes
, sizeof(times
)))
132 return do_utimes(dfd
, filename
, utimes
? times
: NULL
);
135 asmlinkage
long sys_utimes(char __user
*filename
, struct timeval __user
*utimes
)
137 return sys_futimesat(AT_FDCWD
, filename
, utimes
);