stat.c

来自「是学习LINUX必读的一个源码包和2.6内核相比可读性更强更容于理解」· C语言 代码 · 共 57 行

C
57
字号
/* *  linux/fs/stat.c * *  (C) 1991  Linus Torvalds */#include <errno.h>#include <sys/stat.h>#include <linux/fs.h>#include <linux/sched.h>#include <linux/kernel.h>#include <asm/segment.h>static void cp_stat(struct m_inode * inode, struct stat * statbuf){	struct stat tmp;	int i;	verify_area(statbuf,sizeof (* statbuf));	tmp.st_dev = inode->i_dev;	tmp.st_ino = inode->i_num;	tmp.st_mode = inode->i_mode;	tmp.st_nlink = inode->i_nlinks;	tmp.st_uid = inode->i_uid;	tmp.st_gid = inode->i_gid;	tmp.st_rdev = inode->i_zone[0];	tmp.st_size = inode->i_size;	tmp.st_atime = inode->i_atime;	tmp.st_mtime = inode->i_mtime;	tmp.st_ctime = inode->i_ctime;	for (i=0 ; i<sizeof (tmp) ; i++)		put_fs_byte(((char *) &tmp)[i],&((char *) statbuf)[i]);}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;	if (fd >= NR_OPEN || !(f=current->filp[fd]) || !(inode=f->f_inode))		return -EBADF;	cp_stat(inode,statbuf);	return 0;}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?