⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 stat.c

📁 早期linux0.95内核的源代码
💻 C
字号:
/* *  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 inode * inode, struct stat * statbuf){	struct stat tmp;	int i;	verify_area(statbuf,sizeof (struct stat));	tmp.st_dev = inode->i_dev;	tmp.st_ino = inode->i_ino;	tmp.st_mode = inode->i_mode;	tmp.st_nlink = inode->i_nlink;	tmp.st_uid = inode->i_uid;	tmp.st_gid = inode->i_gid;	tmp.st_rdev = inode->i_rdev;	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],i + (char *) statbuf);}int sys_stat(char * filename, struct stat * statbuf){	struct inode * inode;	if (!(inode=namei(filename)))		return -ENOENT;	cp_stat(inode,statbuf);	iput(inode);	return 0;}int sys_lstat(char * filename, struct stat * statbuf){	struct inode * inode;	if (!(inode = lnamei(filename)))		return -ENOENT;	cp_stat(inode,statbuf);	iput(inode);	return 0;}int sys_fstat(unsigned int fd, struct stat * statbuf){	struct file * f;	struct inode * inode;	if (fd >= NR_OPEN || !(f=current->filp[fd]) || !(inode=f->f_inode))		return -EBADF;	cp_stat(inode,statbuf);	return 0;}int sys_readlink(const char * path, char * buf, int bufsiz){	struct inode * inode;	if (bufsiz <= 0)		return -EINVAL;	verify_area(buf,bufsiz);	if (!(inode = lnamei(path)))		return -ENOENT;	if (!inode->i_op || !inode->i_op->readlink) {		iput(inode);		return -EINVAL;	}	return inode->i_op->readlink(inode,buf,bufsiz);}

⌨️ 快捷键说明

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