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