2010-08-02 13:44:45 +02:00
|
|
|
/* Created (MFS based):
|
|
|
|
* February 2010 (Evgeniy Ivanov)
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "fs.h"
|
|
|
|
#include <minix/callnr.h>
|
|
|
|
#include <minix/com.h>
|
|
|
|
#include "inode.h"
|
2011-12-21 23:29:29 +01:00
|
|
|
#include <sys/stat.h>
|
2010-08-02 13:44:45 +02:00
|
|
|
#include <minix/vfsif.h>
|
|
|
|
|
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* fs_utime *
|
|
|
|
*===========================================================================*/
|
2012-03-25 20:25:53 +02:00
|
|
|
int fs_utime()
|
2010-08-02 13:44:45 +02:00
|
|
|
{
|
|
|
|
register struct inode *rip;
|
|
|
|
register int r;
|
|
|
|
|
|
|
|
/* Temporarily open the file. */
|
2014-04-29 20:08:54 +02:00
|
|
|
if( (rip = get_inode(fs_dev, fs_m_in.m_vfs_fs_utime.inode)) == NULL)
|
2010-08-02 13:44:45 +02:00
|
|
|
return(EINVAL);
|
|
|
|
|
2011-12-21 23:29:29 +01:00
|
|
|
/*
|
|
|
|
* Only the owner of a file or the super_user can change the timestamps.
|
|
|
|
* Here we assume VFS did that check before.
|
|
|
|
*/
|
|
|
|
|
2010-08-02 13:44:45 +02:00
|
|
|
r = OK;
|
|
|
|
if(read_only(rip) != OK) r = EROFS; /* not even su can touch if R/O */
|
|
|
|
if(r == OK) {
|
2011-12-21 23:29:29 +01:00
|
|
|
rip->i_update = CTIME; /* discard any stale ATIME and MTIME flags */
|
2014-04-29 20:08:54 +02:00
|
|
|
switch(fs_m_in.m_vfs_fs_utime.acnsec) {
|
2011-12-21 23:29:29 +01:00
|
|
|
case UTIME_NOW:
|
|
|
|
rip->i_update |= ATIME;
|
|
|
|
break;
|
|
|
|
case UTIME_OMIT: /* do not touch */
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/*
|
2014-04-29 20:08:54 +02:00
|
|
|
* cases fs_m_in.m_vfs_fs_utime.acnsec < 0 || fs_m_in.m_vfs_fs_utime.acnsec >= 1E9
|
2011-12-21 23:29:29 +01:00
|
|
|
* are caught by VFS to cooperate with old instances of EXT2
|
|
|
|
*/
|
2014-04-29 20:08:54 +02:00
|
|
|
rip->i_atime = fs_m_in.m_vfs_fs_utime.actime;
|
2011-12-21 23:29:29 +01:00
|
|
|
/*
|
|
|
|
* Ext2FS does not support better than second resolution,
|
2014-04-29 20:08:54 +02:00
|
|
|
* so we discard ACNSEC to round down
|
2011-12-21 23:29:29 +01:00
|
|
|
*/
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2014-04-29 20:08:54 +02:00
|
|
|
switch(fs_m_in.m_vfs_fs_utime.modnsec) {
|
2011-12-21 23:29:29 +01:00
|
|
|
case UTIME_NOW:
|
|
|
|
rip->i_update |= MTIME;
|
|
|
|
break;
|
|
|
|
case UTIME_OMIT: /* do not touch */
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/*
|
2014-04-29 20:08:54 +02:00
|
|
|
* cases fs_m_in.m_vfs_fs_utime.modnsec < 0 || fs_m_in.m_vfs_fs_utime.modnsec >= 1E9
|
2011-12-21 23:29:29 +01:00
|
|
|
* are caught by VFS to cooperate with old instances of EXT2
|
|
|
|
*/
|
2014-04-29 20:08:54 +02:00
|
|
|
rip->i_mtime = fs_m_in.m_vfs_fs_utime.modtime;
|
2011-12-21 23:29:29 +01:00
|
|
|
/*
|
|
|
|
* Ext2FS does not support better than second resolution,
|
2014-04-29 20:08:54 +02:00
|
|
|
* so we discard MODNSEC to round down
|
2011-12-21 23:29:29 +01:00
|
|
|
*/
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
rip->i_dirt = IN_DIRTY;
|
2010-08-02 13:44:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
put_inode(rip);
|
|
|
|
return(r);
|
|
|
|
}
|