2011-08-17 15:23:45 +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"
|
|
|
|
#include "path.h"
|
|
|
|
#include "param.h"
|
|
|
|
#include "vnode.h"
|
|
|
|
#include <minix/vfsif.h>
|
|
|
|
#include "vmnt.h"
|
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* do_utime *
|
|
|
|
*===========================================================================*/
|
|
|
|
PUBLIC int do_utime()
|
|
|
|
{
|
|
|
|
/* Perform the utime(name, timep) system call. */
|
|
|
|
register int len;
|
|
|
|
int r;
|
|
|
|
time_t actime, modtime;
|
|
|
|
struct vnode *vp;
|
|
|
|
struct vmnt *vmp;
|
2011-09-12 11:00:24 +02:00
|
|
|
char fullpath[PATH_MAX];
|
2011-08-17 15:23:45 +02:00
|
|
|
struct lookup resolve;
|
|
|
|
|
|
|
|
lookup_init(&resolve, fullpath, PATH_NOFLAGS, &vmp, &vp);
|
|
|
|
resolve.l_vmnt_lock = VMNT_WRITE;
|
|
|
|
resolve.l_vnode_lock = VNODE_READ;
|
|
|
|
|
|
|
|
/* Adjust for case of 'timep' being NULL;
|
|
|
|
* utime_strlen then holds the actual size: strlen(name)+1 */
|
|
|
|
len = m_in.utime_length;
|
|
|
|
if (len == 0) len = m_in.utime_strlen;
|
|
|
|
|
|
|
|
/* Temporarily open the file */
|
|
|
|
if (fetch_name(m_in.utime_file, len, M1, fullpath) != OK) return(err_code);
|
|
|
|
if ((vp = eat_path(&resolve, fp)) == NULL) return(err_code);
|
|
|
|
|
|
|
|
/* 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;
|
2012-01-27 14:54:35 +01:00
|
|
|
if (m_in.utime_length == 0 && r != OK) r = forbidden(fp, vp, W_BIT);
|
2011-08-17 15:23:45 +02:00
|
|
|
if (read_only(vp) != OK) r = EROFS; /* Not even su can touch if R/O */
|
|
|
|
if (r == OK) {
|
|
|
|
/* Issue request */
|
|
|
|
if(m_in.utime_length == 0) {
|
|
|
|
actime = modtime = clock_time();
|
|
|
|
} else {
|
|
|
|
actime = m_in.utime_actime;
|
|
|
|
modtime = m_in.utime_modtime;
|
|
|
|
}
|
|
|
|
r = req_utime(vp->v_fs_e, vp->v_inode_nr, actime, modtime);
|
|
|
|
}
|
|
|
|
|
|
|
|
unlock_vnode(vp);
|
|
|
|
unlock_vmnt(vmp);
|
|
|
|
|
|
|
|
put_vnode(vp);
|
|
|
|
return(r);
|
|
|
|
}
|