xref: /minix3/minix/fs/ext2/time.c (revision 970d95ecd592b97088f82dd45b0c93a10fc1d1c4)
1433d6423SLionel Sambuc /* Created (MFS based):
2433d6423SLionel Sambuc  *   February 2010 (Evgeniy Ivanov)
3433d6423SLionel Sambuc  */
4433d6423SLionel Sambuc 
5433d6423SLionel Sambuc #include "fs.h"
6433d6423SLionel Sambuc #include "inode.h"
7*970d95ecSDavid van Moolenbroek #include <sys/time.h>
8433d6423SLionel Sambuc #include <sys/stat.h>
9433d6423SLionel Sambuc 
10433d6423SLionel Sambuc 
11433d6423SLionel Sambuc /*===========================================================================*
12433d6423SLionel Sambuc  *				fs_utime				     *
13433d6423SLionel Sambuc  *===========================================================================*/
fs_utime(ino_t ino_nr,struct timespec * atime,struct timespec * mtime)14*970d95ecSDavid van Moolenbroek int fs_utime(ino_t ino_nr, struct timespec *atime, struct timespec *mtime)
15433d6423SLionel Sambuc {
16433d6423SLionel Sambuc   register struct inode *rip;
17433d6423SLionel Sambuc 
18433d6423SLionel Sambuc   /* Temporarily open the file. */
19*970d95ecSDavid van Moolenbroek   if( (rip = get_inode(fs_dev, ino_nr)) == NULL)
20433d6423SLionel Sambuc         return(EINVAL);
21433d6423SLionel Sambuc 
22433d6423SLionel Sambuc   rip->i_update = CTIME;	/* discard any stale ATIME and MTIME flags */
23*970d95ecSDavid van Moolenbroek 
24*970d95ecSDavid van Moolenbroek   switch (atime->tv_nsec) {
25433d6423SLionel Sambuc   case UTIME_NOW:
26433d6423SLionel Sambuc 	rip->i_update |= ATIME;
27433d6423SLionel Sambuc 	break;
28433d6423SLionel Sambuc   case UTIME_OMIT: /* do not touch */
29433d6423SLionel Sambuc 	break;
30433d6423SLionel Sambuc   default:
31*970d95ecSDavid van Moolenbroek 	/* Ext2FS does not support subsecond resolution, so we round down. */
32*970d95ecSDavid van Moolenbroek 	rip->i_atime = atime->tv_sec;
33433d6423SLionel Sambuc 	break;
34433d6423SLionel Sambuc   }
35433d6423SLionel Sambuc 
36*970d95ecSDavid van Moolenbroek   switch (mtime->tv_nsec) {
37433d6423SLionel Sambuc   case UTIME_NOW:
38433d6423SLionel Sambuc 	rip->i_update |= MTIME;
39433d6423SLionel Sambuc 	break;
40433d6423SLionel Sambuc   case UTIME_OMIT: /* do not touch */
41433d6423SLionel Sambuc 	break;
42433d6423SLionel Sambuc   default:
43*970d95ecSDavid van Moolenbroek 	/* Ext2FS does not support subsecond resolution, so we round down. */
44*970d95ecSDavid van Moolenbroek 	rip->i_mtime = mtime->tv_sec;
45433d6423SLionel Sambuc 	break;
46433d6423SLionel Sambuc   }
47433d6423SLionel Sambuc 
48433d6423SLionel Sambuc   rip->i_dirt = IN_DIRTY;
49433d6423SLionel Sambuc 
50433d6423SLionel Sambuc   put_inode(rip);
51*970d95ecSDavid van Moolenbroek   return(OK);
52433d6423SLionel Sambuc }
53