aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--fs/Makefile2
-rw-r--r--fs/open.c134
-rw-r--r--fs/utimes.c137
-rw-r--r--include/linux/namei.h1
-rw-r--r--include/linux/utime.h2
5 files changed, 141 insertions, 135 deletions
diff --git a/fs/Makefile b/fs/Makefile
index a503e6ce0f32..819b2a93bebe 100644
--- a/fs/Makefile
+++ b/fs/Makefile
@@ -10,7 +10,7 @@ obj-y := open.o read_write.o file_table.o super.o \
10 ioctl.o readdir.o select.o fifo.o locks.o dcache.o inode.o \ 10 ioctl.o readdir.o select.o fifo.o locks.o dcache.o inode.o \
11 attr.o bad_inode.o file.o filesystems.o namespace.o aio.o \ 11 attr.o bad_inode.o file.o filesystems.o namespace.o aio.o \
12 seq_file.o xattr.o libfs.o fs-writeback.o \ 12 seq_file.o xattr.o libfs.o fs-writeback.o \
13 pnode.o drop_caches.o splice.o sync.o 13 pnode.o drop_caches.o splice.o sync.o utimes.o
14 14
15ifeq ($(CONFIG_BLOCK),y) 15ifeq ($(CONFIG_BLOCK),y)
16obj-y += buffer.o bio.o block_dev.o direct-io.o mpage.o ioprio.o 16obj-y += buffer.o bio.o block_dev.o direct-io.o mpage.o ioprio.o
diff --git a/fs/open.c b/fs/open.c
index 304c1c7814cb..35c3e454458e 100644
--- a/fs/open.c
+++ b/fs/open.c
@@ -6,7 +6,6 @@
6 6
7#include <linux/string.h> 7#include <linux/string.h>
8#include <linux/mm.h> 8#include <linux/mm.h>
9#include <linux/utime.h>
10#include <linux/file.h> 9#include <linux/file.h>
11#include <linux/smp_lock.h> 10#include <linux/smp_lock.h>
12#include <linux/quotaops.h> 11#include <linux/quotaops.h>
@@ -29,8 +28,6 @@
29#include <linux/rcupdate.h> 28#include <linux/rcupdate.h>
30#include <linux/audit.h> 29#include <linux/audit.h>
31 30
32#include <asm/unistd.h>
33
34int vfs_statfs(struct dentry *dentry, struct kstatfs *buf) 31int vfs_statfs(struct dentry *dentry, struct kstatfs *buf)
35{ 32{
36 int retval = -ENODEV; 33 int retval = -ENODEV;
@@ -353,137 +350,6 @@ asmlinkage long sys_ftruncate64(unsigned int fd, loff_t length)
353} 350}
354#endif 351#endif
355 352
356#ifdef __ARCH_WANT_SYS_UTIME
357
358/*
359 * sys_utime() can be implemented in user-level using sys_utimes().
360 * Is this for backwards compatibility? If so, why not move it
361 * into the appropriate arch directory (for those architectures that
362 * need it).
363 */
364
365/* If times==NULL, set access and modification to current time,
366 * must be owner or have write permission.
367 * Else, update from *times, must be owner or super user.
368 */
369asmlinkage long sys_utime(char __user * filename, struct utimbuf __user * times)
370{
371 int error;
372 struct nameidata nd;
373 struct inode * inode;
374 struct iattr newattrs;
375
376 error = user_path_walk(filename, &nd);
377 if (error)
378 goto out;
379 inode = nd.dentry->d_inode;
380
381 error = -EROFS;
382 if (IS_RDONLY(inode))
383 goto dput_and_out;
384
385 /* Don't worry, the checks are done in inode_change_ok() */
386 newattrs.ia_valid = ATTR_CTIME | ATTR_MTIME | ATTR_ATIME;
387 if (times) {
388 error = -EPERM;
389 if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
390 goto dput_and_out;
391
392 error = get_user(newattrs.ia_atime.tv_sec, &times->actime);
393 newattrs.ia_atime.tv_nsec = 0;
394 if (!error)
395 error = get_user(newattrs.ia_mtime.tv_sec, &times->modtime);
396 newattrs.ia_mtime.tv_nsec = 0;
397 if (error)
398 goto dput_and_out;
399
400 newattrs.ia_valid |= ATTR_ATIME_SET | ATTR_MTIME_SET;
401 } else {
402 error = -EACCES;
403 if (IS_IMMUTABLE(inode))
404 goto dput_and_out;
405
406 if (current->fsuid != inode->i_uid &&
407 (error = vfs_permission(&nd, MAY_WRITE)) != 0)
408 goto dput_and_out;
409 }
410 mutex_lock(&inode->i_mutex);
411 error = notify_change(nd.dentry, &newattrs);
412 mutex_unlock(&inode->i_mutex);
413dput_and_out:
414 path_release(&nd);
415out:
416 return error;
417}
418
419#endif
420
421/* If times==NULL, set access and modification to current time,
422 * must be owner or have write permission.
423 * Else, update from *times, must be owner or super user.
424 */
425long do_utimes(int dfd, char __user *filename, struct timeval *times)
426{
427 int error;
428 struct nameidata nd;
429 struct inode * inode;
430 struct iattr newattrs;
431
432 error = __user_walk_fd(dfd, filename, LOOKUP_FOLLOW, &nd);
433
434 if (error)
435 goto out;
436 inode = nd.dentry->d_inode;
437
438 error = -EROFS;
439 if (IS_RDONLY(inode))
440 goto dput_and_out;
441
442 /* Don't worry, the checks are done in inode_change_ok() */
443 newattrs.ia_valid = ATTR_CTIME | ATTR_MTIME | ATTR_ATIME;
444 if (times) {
445 error = -EPERM;
446 if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
447 goto dput_and_out;
448
449 newattrs.ia_atime.tv_sec = times[0].tv_sec;
450 newattrs.ia_atime.tv_nsec = times[0].tv_usec * 1000;
451 newattrs.ia_mtime.tv_sec = times[1].tv_sec;
452 newattrs.ia_mtime.tv_nsec = times[1].tv_usec * 1000;
453 newattrs.ia_valid |= ATTR_ATIME_SET | ATTR_MTIME_SET;
454 } else {
455 error = -EACCES;
456 if (IS_IMMUTABLE(inode))
457 goto dput_and_out;
458
459 if (current->fsuid != inode->i_uid &&
460 (error = vfs_permission(&nd, MAY_WRITE)) != 0)
461 goto dput_and_out;
462 }
463 mutex_lock(&inode->i_mutex);
464 error = notify_change(nd.dentry, &newattrs);
465 mutex_unlock(&inode->i_mutex);
466dput_and_out:
467 path_release(&nd);
468out:
469 return error;
470}
471
472asmlinkage long sys_futimesat(int dfd, char __user *filename, struct timeval __user *utimes)
473{
474 struct timeval times[2];
475
476 if (utimes && copy_from_user(&times, utimes, sizeof(times)))
477 return -EFAULT;
478 return do_utimes(dfd, filename, utimes ? times : NULL);
479}
480
481asmlinkage long sys_utimes(char __user *filename, struct timeval __user *utimes)
482{
483 return sys_futimesat(AT_FDCWD, filename, utimes);
484}
485
486
487/* 353/*
488 * access() needs to use the real uid/gid, not the effective uid/gid. 354 * access() needs to use the real uid/gid, not the effective uid/gid.
489 * We do this by temporarily clearing all FS-related capabilities and 355 * We do this by temporarily clearing all FS-related capabilities and
diff --git a/fs/utimes.c b/fs/utimes.c
new file mode 100644
index 000000000000..1bcd852fc4a9
--- /dev/null
+++ b/fs/utimes.c
@@ -0,0 +1,137 @@
1#include <linux/compiler.h>
2#include <linux/fs.h>
3#include <linux/linkage.h>
4#include <linux/namei.h>
5#include <linux/utime.h>
6#include <asm/uaccess.h>
7#include <asm/unistd.h>
8
9#ifdef __ARCH_WANT_SYS_UTIME
10
11/*
12 * sys_utime() can be implemented in user-level using sys_utimes().
13 * Is this for backwards compatibility? If so, why not move it
14 * into the appropriate arch directory (for those architectures that
15 * need it).
16 */
17
18/* If times==NULL, set access and modification to current time,
19 * must be owner or have write permission.
20 * Else, update from *times, must be owner or super user.
21 */
22asmlinkage long sys_utime(char __user * filename, struct utimbuf __user * times)
23{
24 int error;
25 struct nameidata nd;
26 struct inode * inode;
27 struct iattr newattrs;
28
29 error = user_path_walk(filename, &nd);
30 if (error)
31 goto out;
32 inode = nd.dentry->d_inode;
33
34 error = -EROFS;
35 if (IS_RDONLY(inode))
36 goto dput_and_out;
37
38 /* Don't worry, the checks are done in inode_change_ok() */
39 newattrs.ia_valid = ATTR_CTIME | ATTR_MTIME | ATTR_ATIME;
40 if (times) {
41 error = -EPERM;
42 if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
43 goto dput_and_out;
44
45 error = get_user(newattrs.ia_atime.tv_sec, &times->actime);
46 newattrs.ia_atime.tv_nsec = 0;
47 if (!error)
48 error = get_user(newattrs.ia_mtime.tv_sec, &times->modtime);
49 newattrs.ia_mtime.tv_nsec = 0;
50 if (error)
51 goto dput_and_out;
52
53 newattrs.ia_valid |= ATTR_ATIME_SET | ATTR_MTIME_SET;
54 } else {
55 error = -EACCES;
56 if (IS_IMMUTABLE(inode))
57 goto dput_and_out;
58
59 if (current->fsuid != inode->i_uid &&
60 (error = vfs_permission(&nd, MAY_WRITE)) != 0)
61 goto dput_and_out;
62 }
63 mutex_lock(&inode->i_mutex);
64 error = notify_change(nd.dentry, &newattrs);
65 mutex_unlock(&inode->i_mutex);
66dput_and_out:
67 path_release(&nd);
68out:
69 return error;
70}
71
72#endif
73
74/* If times==NULL, set access and modification to current time,
75 * must be owner or have write permission.
76 * Else, update from *times, must be owner or super user.
77 */
78long do_utimes(int dfd, char __user *filename, struct timeval *times)
79{
80 int error;
81 struct nameidata nd;
82 struct inode * inode;
83 struct iattr newattrs;
84
85 error = __user_walk_fd(dfd, filename, LOOKUP_FOLLOW, &nd);
86
87 if (error)
88 goto out;
89 inode = nd.dentry->d_inode;
90
91 error = -EROFS;
92 if (IS_RDONLY(inode))
93 goto dput_and_out;
94
95 /* Don't worry, the checks are done in inode_change_ok() */
96 newattrs.ia_valid = ATTR_CTIME | ATTR_MTIME | ATTR_ATIME;
97 if (times) {
98 error = -EPERM;
99 if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
100 goto dput_and_out;
101
102 newattrs.ia_atime.tv_sec = times[0].tv_sec;
103 newattrs.ia_atime.tv_nsec = times[0].tv_usec * 1000;
104 newattrs.ia_mtime.tv_sec = times[1].tv_sec;
105 newattrs.ia_mtime.tv_nsec = times[1].tv_usec * 1000;
106 newattrs.ia_valid |= ATTR_ATIME_SET | ATTR_MTIME_SET;
107 } else {
108 error = -EACCES;
109 if (IS_IMMUTABLE(inode))
110 goto dput_and_out;
111
112 if (current->fsuid != inode->i_uid &&
113 (error = vfs_permission(&nd, MAY_WRITE)) != 0)
114 goto dput_and_out;
115 }
116 mutex_lock(&inode->i_mutex);
117 error = notify_change(nd.dentry, &newattrs);
118 mutex_unlock(&inode->i_mutex);
119dput_and_out:
120 path_release(&nd);
121out:
122 return error;
123}
124
125asmlinkage long sys_futimesat(int dfd, char __user *filename, struct timeval __user *utimes)
126{
127 struct timeval times[2];
128
129 if (utimes && copy_from_user(&times, utimes, sizeof(times)))
130 return -EFAULT;
131 return do_utimes(dfd, filename, utimes ? times : NULL);
132}
133
134asmlinkage long sys_utimes(char __user *filename, struct timeval __user *utimes)
135{
136 return sys_futimesat(AT_FDCWD, filename, utimes);
137}
diff --git a/include/linux/namei.h b/include/linux/namei.h
index c6470ba00668..f5f19606effb 100644
--- a/include/linux/namei.h
+++ b/include/linux/namei.h
@@ -1,6 +1,7 @@
1#ifndef _LINUX_NAMEI_H 1#ifndef _LINUX_NAMEI_H
2#define _LINUX_NAMEI_H 2#define _LINUX_NAMEI_H
3 3
4#include <linux/dcache.h>
4#include <linux/linkage.h> 5#include <linux/linkage.h>
5 6
6struct vfsmount; 7struct vfsmount;
diff --git a/include/linux/utime.h b/include/linux/utime.h
index c6bf27b7897e..640be6a1959e 100644
--- a/include/linux/utime.h
+++ b/include/linux/utime.h
@@ -1,6 +1,8 @@
1#ifndef _LINUX_UTIME_H 1#ifndef _LINUX_UTIME_H
2#define _LINUX_UTIME_H 2#define _LINUX_UTIME_H
3 3
4#include <linux/types.h>
5
4struct utimbuf { 6struct utimbuf {
5 time_t actime; 7 time_t actime;
6 time_t modtime; 8 time_t modtime;