minix/servers/vfs/time.c

73 lines
2 KiB
C
Raw Normal View History

2005-04-21 16:53:53 +02:00
/* This file takes care of those system calls that deal with time.
*
* The entry points into this file are
* do_utime: perform the UTIME system call
*/
#include "fs.h"
#include <minix/callnr.h>
#include <minix/com.h>
#include "file.h"
#include "fproc.h"
2012-02-13 16:28:04 +01:00
#include "path.h"
2005-04-21 16:53:53 +02:00
#include "param.h"
2007-08-07 14:52:47 +02:00
#include "vnode.h"
#include <minix/vfsif.h>
#include "vmnt.h"
2005-04-21 16:53:53 +02:00
/*===========================================================================*
* do_utime *
*===========================================================================*/
2012-03-25 20:25:53 +02:00
int do_utime()
2005-04-21 16:53:53 +02:00
{
/* Perform the utime(name, timep) system call. */
int r;
time_t actime, modtime, newactime, newmodtime;
2007-08-07 14:52:47 +02:00
struct vnode *vp;
2012-02-13 16:28:04 +01:00
struct vmnt *vmp;
char fullpath[PATH_MAX];
struct lookup resolve;
vir_bytes vname;
size_t vname_length, len;
2012-02-13 16:28:04 +01:00
vname = (vir_bytes) job_m_in.utime_file;
vname_length = (size_t) job_m_in.utime_length;
actime = job_m_in.utime_actime;
modtime = job_m_in.utime_modtime;
2012-02-13 16:28:04 +01:00
2005-04-21 16:53:53 +02:00
/* Adjust for case of 'timep' being NULL;
* utime_strlen then holds the actual size: strlen(name)+1 */
len = vname_length;
if (len == 0) len = (size_t) job_m_in.utime_strlen;
lookup_init(&resolve, fullpath, PATH_NOFLAGS, &vmp, &vp);
resolve.l_vmnt_lock = VMNT_WRITE;
resolve.l_vnode_lock = VNODE_READ;
2005-04-21 16:53:53 +02:00
/* Temporarily open the file */
if (fetch_name(vname, len, fullpath) != OK) return(err_code);
2012-02-13 16:28:04 +01:00
if ((vp = eat_path(&resolve, fp)) == NULL) return(err_code);
2012-02-13 16:28:04 +01:00
/* Only the owner of a file or the super user can change its name. */
r = OK;
if (vp->v_uid != fp->fp_effuid && fp->fp_effuid != SU_UID) r = EPERM;
if (vname_length == 0 && r != OK) r = forbidden(fp, vp, W_BIT);
2012-02-13 16:28:04 +01:00
if (read_only(vp) != OK) r = EROFS; /* Not even su can touch if R/O */
if (r == OK) {
/* Issue request */
if (vname_length == 0) {
newactime = newmodtime = clock_time();
} else {
newactime = actime;
newmodtime = modtime;
}
r = req_utime(vp->v_fs_e, vp->v_inode_nr, newactime, newmodtime);
2005-04-21 16:53:53 +02:00
}
2012-02-13 16:28:04 +01:00
unlock_vnode(vp);
unlock_vmnt(vmp);
2007-08-07 14:52:47 +02:00
put_vnode(vp);
return(r);
2005-04-21 16:53:53 +02:00
}