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

📄 inode.c

📁 elinux jffs初始版本 具体了解JFFS的文件系统!
💻 C
📖 第 1 页 / 共 2 页
字号:
		/* next entry */		offset = ntohl(ri.next) & ROMFH_MASK;	}	/* Hard link handling */	if ((ntohl(ri.next) & ROMFH_TYPE) == ROMFH_HRD)		offset = ntohl(ri.spec) & ROMFH_MASK;	res = 0;	if (!(*result = iget(dir->i_sb, offset)))		res = -EACCES;out:	iput(dir);	return res;}/* * Ok, we do readpage, to be able to execute programs.  Unfortunately, * we can't use bmap, since we have looser alignments. */static intromfs_readpage(struct inode * inode, struct page * page){	unsigned long buf;	unsigned long offset, avail, readlen;	int result = -EIO;	page->count++;	set_bit(PG_locked, &page->flags);	buf = page_address(page);	clear_bit(PG_uptodate, &page->flags);	clear_bit(PG_error, &page->flags);	offset = page->offset;	if (offset < inode->i_size) {		avail = inode->i_size-offset;		readlen = min(avail, PAGE_SIZE);		if (romfs_copyfrom(inode, (void *)buf, inode->u.romfs_i.i_dataoffset+offset, readlen) == readlen) {			if (readlen < PAGE_SIZE) {				memset((void *)(buf+readlen),0,PAGE_SIZE-readlen);			}			set_bit(PG_uptodate, &page->flags);			result = 0;		}	}	if (result) {		set_bit(PG_error, &page->flags);		memset((void *)buf, 0, PAGE_SIZE);	}	clear_bit(PG_locked, &page->flags);	wake_up(&page->wait);	free_page(buf);	return result;}#ifdef MAGIC_ROM_PTRstatic intromfs_romptr(struct inode * inode, struct file * filp, struct vm_area_struct * vma){	vma->vm_offset += inode->u.romfs_i.i_dataoffset;	if ((vma->vm_flags & VM_WRITE) || bromptr(inode->i_dev, vma))		return -ENOSYS;	return 0;}#endifstatic intromfs_readlink(struct inode *inode, char *buffer, int len){	int mylen;	char buf[ROMFS_MAXFN];		/* XXX dynamic */	if (!inode || !S_ISLNK(inode->i_mode)) {		mylen = -EBADF;		goto out;	}	mylen = min(sizeof(buf), inode->i_size);	if (romfs_copyfrom(inode, buf, inode->u.romfs_i.i_dataoffset, mylen) <= 0) {		mylen = -EIO;		goto out;	}	memcpy_tofs(buffer, buf, mylen);out:	iput(inode);	return mylen;}static intromfs_follow_link(struct inode *dir, struct inode *inode,	int flag, int mode, struct inode **res_inode){	int error, len;	char *buf;	*res_inode = NULL;	if (!dir) {		dir = current->fs->root;		dir->i_count++;	}	if (!inode) {		iput(dir);		return -ENOENT;	}	if (!S_ISLNK(inode->i_mode)) {		*res_inode = inode;		iput(dir);		return 0;	}	if (current->link_count > 5) {		iput(inode);		iput(dir);		return -ELOOP;	}	/* Eek. Short enough. */	len = inode->i_size;	if (!(buf = kmalloc(len+1, GFP_KERNEL))) {		iput(inode);		iput(dir);		/* correct?  spin? */		return -EAGAIN;	}	error = romfs_copyfrom(inode, buf, inode->u.romfs_i.i_dataoffset, len);	if (error != len) {		iput(inode);		iput(dir);		error = -EIO;	} else {		iput(inode);		buf[len] = 0;		current->link_count++;		error = open_namei(buf, flag, mode, res_inode, dir);		current->link_count--;	}	kfree(buf);	return error;}/* Mapping from our types to the kernel */static struct file_operations romfs_file_operations = {	NULL,			/* lseek - default */        generic_file_read,	/* read */	NULL,			/* write - bad */	NULL,			/* readdir */	NULL,			/* select - default */	NULL,			/* ioctl */	generic_file_mmap,	/* mmap */	NULL,			/* open */	NULL,			/* release */	NULL,			/* fsync */	NULL,			/* fasync */	NULL,			/* check_media_change */	NULL,			/* revalidate */#ifdef MAGIC_ROM_PTR	romfs_romptr,		/* romptr */#endif};static struct inode_operations romfs_file_inode_operations = {	&romfs_file_operations,	NULL,			/* create */	NULL,			/* lookup */	NULL,			/* link */	NULL,			/* unlink */	NULL,			/* symlink */	NULL,			/* mkdir */	NULL,			/* rmdir */	NULL,			/* mknod */	NULL,			/* rename */	NULL,			/* readlink */	NULL,			/* follow_link */	romfs_readpage,		/* readpage */	NULL,			/* writepage */	NULL,			/* bmap -- not really */	NULL,			/* truncate */	NULL,			/* permission */	NULL,			/* smap */};static struct file_operations romfs_dir_operations = {	NULL,			/* lseek - default */        NULL,			/* read */	NULL,			/* write - bad */	romfs_readdir,		/* readdir */	NULL,			/* select - default */	NULL,			/* ioctl */	NULL,			/* mmap */	NULL,			/* open */	NULL,			/* release */	NULL,			/* fsync */	NULL,			/* fasync */	NULL,			/* check_media_change */	NULL			/* revalidate */};/* Merged dir/symlink op table.  readdir/lookup/readlink/follow_link * will protect from type mismatch. */static struct inode_operations romfs_dirlink_inode_operations = {	&romfs_dir_operations,	NULL,			/* create */	romfs_lookup,		/* lookup */	NULL,			/* link */	NULL,			/* unlink */	NULL,			/* symlink */	NULL,			/* mkdir */	NULL,			/* rmdir */	NULL,			/* mknod */	NULL,			/* rename */	romfs_readlink,		/* readlink */	romfs_follow_link,	/* follow_link */	NULL,			/* readpage */	NULL,			/* writepage */	NULL,			/* bmap */	NULL,			/* truncate */	NULL,			/* permission */	NULL,			/* smap */};static mode_t romfs_modemap[] ={	0, S_IFDIR, S_IFREG, S_IFLNK+0777,	S_IFBLK, S_IFCHR, S_IFSOCK, S_IFIFO};static struct inode_operations *romfs_inoops[] ={	NULL,				/* hardlink, handled elsewhere */	&romfs_dirlink_inode_operations,	&romfs_file_inode_operations,	&romfs_dirlink_inode_operations,	&blkdev_inode_operations,	/* standard handlers */	&chrdev_inode_operations,	NULL,				/* socket */	NULL,				/* fifo */};static voidromfs_read_inode(struct inode *i){	int nextfh, ino;	struct romfs_inode ri;	ino = i->i_ino & ROMFH_MASK;	i->i_op = NULL;	i->i_mode = 0;	/* Loop for finding the real hard link */	for(;;) {		if (romfs_copyfrom(i, &ri, ino, ROMFH_SIZE) <= 0) {			printk("romfs: read error for inode 0x%x\n", ino);			return;		}		/* XXX: do romfs_checksum here too (with name) */		nextfh = ntohl(ri.next);		if ((nextfh & ROMFH_TYPE) != ROMFH_HRD)			break;		ino = ntohl(ri.spec) & ROMFH_MASK;	}	i->i_nlink = 1;		/* Hard to decide.. */	i->i_size = ntohl(ri.size);	i->i_mtime = i->i_atime = i->i_ctime = 0;	i->i_uid = i->i_gid = 0;	i->i_op = romfs_inoops[nextfh & ROMFH_TYPE];	/* Precalculate the data offset */	ino = romfs_strnlen(i, ino+ROMFH_SIZE, ROMFS_MAXFN);	if (ino >= 0)		ino = ((ROMFH_SIZE+ino+1+ROMFH_PAD)&ROMFH_MASK);	else		ino = 0;	i->u.romfs_i.i_metasize = ino;	i->u.romfs_i.i_dataoffset = ino+(i->i_ino&ROMFH_MASK);	/* Compute permissions */	ino = S_IRUGO|S_IWUSR;	ino |= romfs_modemap[nextfh & ROMFH_TYPE];	if (nextfh & ROMFH_EXEC) {		ino |= S_IXUGO;	}	i->i_mode = ino;	if (S_ISFIFO(ino))		init_fifo(i);	else if (S_ISDIR(ino))		i->i_size = i->u.romfs_i.i_metasize;	else if (S_ISBLK(ino) || S_ISCHR(ino)) {		i->i_mode |= S_IRWXG | S_IRWXO; /* permission to write for all */		/*i->i_mode &= ~(S_IRWXG|S_IRWXO);*/		ino = ntohl(ri.spec);		i->i_rdev = MKDEV(ino>>16,ino&0xffff);	}}static struct super_operations romfs_ops = {	romfs_read_inode,	/* read inode */	NULL,			/* notify change */	NULL,			/* write inode */	NULL,			/* put inode */	romfs_put_super,	/* put super */	NULL,			/* write super */	romfs_statfs,		/* statfs */	NULL			/* remount */};static struct file_system_type romfs_fs_type = {	romfs_read_super, "romfs", 1, NULL};intinit_romfs_fs(void){	return register_filesystem(&romfs_fs_type);}#ifdef MODULE/* Yes, works even as a module... :) */intinit_module(void){	int status;	if ((status = init_romfs_fs()) == 0)		register_symtab(0);	return status;}voidcleanup_module(void){	unregister_filesystem(&romfs_fs_type);}#endif

⌨️ 快捷键说明

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