From e3811a93235976fc85a11846ea8363a86329ee5f Mon Sep 17 00:00:00 2001 From: hinus Date: Wed, 11 Aug 2021 17:03:51 +0800 Subject: [PATCH] Title: System call 'stat' Issue: https://gitee.com/hinus/linux_kernel_011/issues/I44ZQJ Description: System call 'stat' --- fs/stat.c | 9 +++++++++ include/linux/sys.h | 4 ++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/fs/stat.c b/fs/stat.c index 6508e45..8e8dda7 100644 --- a/fs/stat.c +++ b/fs/stat.c @@ -29,6 +29,15 @@ static void cp_stat(struct m_inode * inode, struct stat * statbuf) { } } +int sys_stat(char * filename, struct stat * statbuf) { + struct m_inode * inode; + if (!(inode=namei(filename))) + return -ENOENT; + cp_stat(inode,statbuf); + iput(inode); + return 0; +} + int sys_fstat(unsigned int fd, struct stat * statbuf) { struct file * f; struct m_inode * inode; diff --git a/include/linux/sys.h b/include/linux/sys.h index e37c652..8c92ab3 100644 --- a/include/linux/sys.h +++ b/include/linux/sys.h @@ -16,7 +16,7 @@ extern int sys_time(); extern int sys_chmod(); extern int sys_chown(); extern int sys_break(); -//extern int sys_stat(); +extern int sys_stat(); extern int sys_lseek(); extern int sys_getpid(); //extern int sys_mount(); @@ -107,7 +107,7 @@ fn_ptr sys_call_table[] = { sys_chown, sys_break, - 0, //sys_stat, + sys_stat, sys_lseek, sys_getpid, 0, //sys_mount, -- Gitee