Welcome to The Fiwix Project
A UNIX-like kernel for the i386 architecture
1 /* 2 * fiwix/kernel/syscalls/newlstat.c 3 * 4 * Copyright 2018, Jordi Sanfeliu. All rights reserved. 5 * Distributed under the terms of the Fiwix License. 6 */ 7 8 #include <fiwix/fs.h> 9 #include <fiwix/statbuf.h> 10 #include <fiwix/string.h> 11 12 #ifdef __DEBUG__ 13 #include <fiwix/stdio.h> 14 #include <fiwix/process.h> 15 #endif /*__DEBUG__ */ 16 17 int sys_newlstat(const char *filename, struct new_stat *statbuf) 18 { 19 struct inode *i; 20 char *tmp_name; 21 int errno; 22 23 #ifdef __DEBUG__ 24 printk("(pid %d) sys_newlstat('%s', 0x%08x) -> returning structure\n", current->pid, filename, (unsigned int )statbuf); 25 #endif /*__DEBUG__ */ 26 27 if((errno = check_user_area(VERIFY_WRITE, statbuf, sizeof(struct new_stat)))) { 28 return errno; 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 statbuf->st_dev = i->dev; 38 statbuf->__pad1 = 0; 39 statbuf->st_ino = i->inode; 40 statbuf->st_mode = i->i_mode; 41 statbuf->st_nlink = i->i_nlink; 42 statbuf->st_uid = i->i_uid; 43 statbuf->st_gid = i->i_gid; 44 statbuf->st_rdev = i->rdev; 45 statbuf->__pad2 = 0; 46 statbuf->st_size = i->i_size; 47 statbuf->st_blksize = i->sb->s_blocksize; 48 statbuf->st_blocks = i->i_blocks; 49 if(!i->i_blocks) { 50 statbuf->st_blocks = (i->i_size / i->sb->s_blocksize) * 2; 51 statbuf->st_blocks++; 52 } 53 statbuf->st_atime = i->i_atime; 54 statbuf->__unused1 = 0; 55 statbuf->st_mtime = i->i_mtime; 56 statbuf->__unused2 = 0; 57 statbuf->st_ctime = i->i_ctime; 58 statbuf->__unused3 = 0; 59 statbuf->__unused4 = 0; 60 statbuf->__unused5 = 0; 61 iput(i); 62 free_name(tmp_name); 63 return 0; 64 }