Welcome to The Fiwix Project
A UNIX-like kernel for the i386 architecture
1 /* 2 * fiwix/kernel/syscalls/utime.c 3 * 4 * Copyright 2018, Jordi Sanfeliu. All rights reserved. 5 * Distributed under the terms of the Fiwix License. 6 */ 7 8 #include <fiwix/kernel.h> 9 #include <fiwix/fs.h> 10 #include <fiwix/utime.h> 11 #include <fiwix/stat.h> 12 #include <fiwix/errno.h> 13 #include <fiwix/string.h> 14 15 #ifdef __DEBUG__ 16 #include <fiwix/stdio.h> 17 #include <fiwix/process.h> 18 #endif /*__DEBUG__ */ 19 20 int sys_utime(const char *filename, struct utimbuf *times) 21 { 22 struct inode *i; 23 char *tmp_name; 24 int errno; 25 26 #ifdef __DEBUG__ 27 printk("(pid %d) sys_utime('%s', 0x%08x)\n", current->pid, filename, (int)times); 28 #endif /*__DEBUG__ */ 29 30 if((errno = malloc_name(filename, &tmp_name)) < 0) { 31 return errno; 32 } 33 if((errno = namei(tmp_name, &i, NULL, FOLLOW_LINKS))) { 34 free_name(tmp_name); 35 return errno; 36 } 37 38 if(IS_RDONLY_FS(i)) { 39 iput(i); 40 free_name(tmp_name); 41 return -EROFS; 42 } 43 44 if(!times) { 45 if(check_user_permission(i) || check_permission(TO_WRITE, i)) { 46 iput(i); 47 free_name(tmp_name); 48 return -EACCES; 49 } 50 i->i_atime = CURRENT_TIME; 51 i->i_mtime = CURRENT_TIME; 52 } else { 53 if((errno = check_user_area(VERIFY_READ, times, sizeof(struct utimbuf)))) { 54 iput(i); 55 free_name(tmp_name); 56 return errno; 57 } 58 if(check_user_permission(i)) { 59 iput(i); 60 free_name(tmp_name); 61 return -EPERM; 62 } 63 i->i_atime = times->actime; 64 i->i_mtime = times->modtime; 65 } 66 67 i->i_ctime = CURRENT_TIME; 68 i->dirty = 1; 69 iput(i); 70 free_name(tmp_name); 71 return 0; 72 }