xref: /minix/minix/fs/mfs/time.c (revision 7f5f010b)
1 #include "fs.h"
2 #include "inode.h"
3 #include <sys/stat.h>
4 #include <minix/vfsif.h>
5 
6 
7 /*===========================================================================*
8  *				fs_utime				     *
9  *===========================================================================*/
10 int fs_utime()
11 {
12   register struct inode *rip;
13   register int r;
14 
15   /* Temporarily open the file. */
16   if( (rip = get_inode(fs_dev, fs_m_in.m_vfs_fs_utime.inode)) == NULL)
17         return(EINVAL);
18 
19   /*
20    * Only the owner of a file or the super_user can change the timestamps.
21    * Here we assume VFS did that check before.
22    */
23 
24   r = OK;
25   if(read_only(rip) != OK) r = EROFS;	/* not even su can touch if R/O */
26   if(r == OK) {
27 	rip->i_update = CTIME; /* discard any stale ATIME and MTIME flags */
28 	switch(fs_m_in.m_vfs_fs_utime.acnsec) {
29 	case UTIME_NOW:
30 		rip->i_update |= ATIME;
31 		break;
32 	case UTIME_OMIT: /* do not touch */
33 		break;
34 	default:
35 		/*
36 		 * cases fs_m_in.m_vfs_fs_utime.acnsec < 0 || fs_m_in.m_vfs_fs_utime.acnsec >= 1E9
37 		 * are caught by VFS to cooperate with old instances of MFS
38 		 */
39 		rip->i_atime = fs_m_in.m_vfs_fs_utime.actime;
40 		/*
41 		 * MFS does not support better than second resolution,
42 		 * so we discard ACNSEC to round down
43 		 */
44 		break;
45 	}
46 
47 	switch(fs_m_in.m_vfs_fs_utime.modnsec) {
48 	case UTIME_NOW:
49 		rip->i_update |= MTIME;
50 		break;
51 	case UTIME_OMIT: /* do not touch */
52 		break;
53 	default:
54 		/*
55 		 * cases fs_m_in.m_vfs_fs_utime.modnsec < 0 || fs_m_in.m_vfs_fs_utime.modnsec >= 1E9
56 		 * are caught by VFS to cooperate with old instances of MFS
57 		 */
58 		rip->i_mtime = fs_m_in.m_vfs_fs_utime.modtime;
59 		/*
60 		 * MFS does not support better than second resolution,
61 		 * so we discard MODNSEC to round down
62 		 */
63 		break;
64 	}
65 
66 	IN_MARKDIRTY(rip);
67   }
68 
69   put_inode(rip);
70   return(r);
71 }
72 
73