mkfs: drop support for running on DOS
[minix.git] / servers / vfs / time.c
blobdffbded57c3e7224314ad47c35867f0be5bb7a4b
1 /* This file takes care of those system calls that deal with time.
3 * The entry points into this file are
4 * do_utime: perform the UTIME system call
5 */
7 #include "fs.h"
8 #include <minix/callnr.h>
9 #include <minix/com.h>
10 #include "file.h"
11 #include "fproc.h"
12 #include "path.h"
13 #include "param.h"
14 #include "vnode.h"
15 #include <minix/vfsif.h>
16 #include "vmnt.h"
18 /*===========================================================================*
19 * do_utime *
20 *===========================================================================*/
21 int do_utime()
23 /* Perform the utime(name, timep) system call. */
24 int r;
25 time_t actime, modtime, newactime, newmodtime;
26 struct vnode *vp;
27 struct vmnt *vmp;
28 char fullpath[PATH_MAX];
29 struct lookup resolve;
30 vir_bytes vname;
31 size_t vname_length, len;
33 vname = (vir_bytes) job_m_in.utime_file;
34 vname_length = (size_t) job_m_in.utime_length;
35 actime = job_m_in.utime_actime;
36 modtime = job_m_in.utime_modtime;
38 /* Adjust for case of 'timep' being NULL;
39 * utime_strlen then holds the actual size: strlen(name)+1 */
40 len = vname_length;
41 if (len == 0) len = (size_t) job_m_in.utime_strlen;
43 lookup_init(&resolve, fullpath, PATH_NOFLAGS, &vmp, &vp);
44 resolve.l_vmnt_lock = VMNT_WRITE;
45 resolve.l_vnode_lock = VNODE_READ;
47 /* Temporarily open the file */
48 if (fetch_name(vname, len, fullpath) != OK) return(err_code);
49 if ((vp = eat_path(&resolve, fp)) == NULL) return(err_code);
51 /* Only the owner of a file or the super user can change its name. */
52 r = OK;
53 if (vp->v_uid != fp->fp_effuid && fp->fp_effuid != SU_UID) r = EPERM;
54 if (vname_length == 0 && r != OK) r = forbidden(fp, vp, W_BIT);
55 if (read_only(vp) != OK) r = EROFS; /* Not even su can touch if R/O */
56 if (r == OK) {
57 /* Issue request */
58 if (vname_length == 0) {
59 newactime = newmodtime = clock_time();
60 } else {
61 newactime = actime;
62 newmodtime = modtime;
64 r = req_utime(vp->v_fs_e, vp->v_inode_nr, newactime, newmodtime);
67 unlock_vnode(vp);
68 unlock_vmnt(vmp);
70 put_vnode(vp);
71 return(r);