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

📄 inode.c

📁 《嵌入式系统设计与实例开发实验教材二源码》Linux内核移植与编译实验
💻 C
📖 第 1 页 / 共 2 页
字号:
/* *  inode.c * *  Copyright (C) 1995, 1996 by Volker Lendecke *  Modified for big endian by J.F. Chadima and David S. Miller *  Modified 1997 Peter Waltenberg, Bill Hawes, David Woodhouse for 2.1 dcache *  Modified 1998 Wolfram Pienkoss for NLS * */#include <linux/config.h>#include <linux/module.h>#include <asm/system.h>#include <asm/uaccess.h>#include <asm/byteorder.h>#include <linux/sched.h>#include <linux/kernel.h>#include <linux/mm.h>#include <linux/string.h>#include <linux/stat.h>#include <linux/errno.h>#include <linux/locks.h>#include <linux/file.h>#include <linux/fcntl.h>#include <linux/slab.h>#include <linux/vmalloc.h>#include <linux/init.h>#include <linux/ncp_fs.h>#include "ncplib_kernel.h"static void ncp_delete_inode(struct inode *);static void ncp_put_super(struct super_block *);static int  ncp_statfs(struct super_block *, struct statfs *);static struct super_operations ncp_sops ={	put_inode:	force_delete,	delete_inode:	ncp_delete_inode,	put_super:	ncp_put_super,	statfs:		ncp_statfs,};extern struct dentry_operations ncp_dentry_operations;#ifdef CONFIG_NCPFS_EXTRASextern struct address_space_operations ncp_symlink_aops;extern int ncp_symlink(struct inode*, struct dentry*, const char*);#endif/* * Fill in the ncpfs-specific information in the inode. */void ncp_update_inode(struct inode *inode, struct ncp_entry_info *nwinfo){	NCP_FINFO(inode)->DosDirNum = nwinfo->i.DosDirNum;	NCP_FINFO(inode)->dirEntNum = nwinfo->i.dirEntNum;	NCP_FINFO(inode)->volNumber = nwinfo->i.volNumber;#ifdef CONFIG_NCPFS_STRONG	NCP_FINFO(inode)->nwattr = nwinfo->i.attributes;#endif	NCP_FINFO(inode)->access = nwinfo->access;	NCP_FINFO(inode)->server_file_handle = nwinfo->server_file_handle;	memcpy(NCP_FINFO(inode)->file_handle, nwinfo->file_handle,			sizeof(nwinfo->file_handle));	DPRINTK("ncp_update_inode: updated %s, volnum=%d, dirent=%u\n",		nwinfo->i.entryName, NCP_FINFO(inode)->volNumber,		NCP_FINFO(inode)->dirEntNum);}void ncp_update_inode2(struct inode* inode, struct ncp_entry_info *nwinfo){	struct nw_info_struct *nwi = &nwinfo->i;	struct ncp_server *server = NCP_SERVER(inode);	if (!atomic_read(&NCP_FINFO(inode)->opened)) {#ifdef CONFIG_NCPFS_STRONG		NCP_FINFO(inode)->nwattr = nwi->attributes;#endif		if (nwi->attributes & aDIR) {			inode->i_mode = server->m.dir_mode;			inode->i_size = NCP_BLOCK_SIZE;		} else {			inode->i_mode = server->m.file_mode;			inode->i_size = le32_to_cpu(nwi->dataStreamSize);#ifdef CONFIG_NCPFS_EXTRAS			if ((server->m.flags & (NCP_MOUNT_EXTRAS|NCP_MOUNT_SYMLINKS)) && (nwi->attributes & aSHARED)) {				switch (nwi->attributes & (aHIDDEN|aSYSTEM)) {					case aHIDDEN:						if (server->m.flags & NCP_MOUNT_SYMLINKS) {							if ( /* (inode->i_size >= NCP_MIN_SYMLINK_SIZE)							 && */ (inode->i_size <= NCP_MAX_SYMLINK_SIZE)) {								inode->i_mode = (inode->i_mode & ~S_IFMT) | S_IFLNK;								break;							}						}						/* FALLTHROUGH */					case 0:						if (server->m.flags & NCP_MOUNT_EXTRAS)							inode->i_mode |= 0444;						break;					case aSYSTEM:						if (server->m.flags & NCP_MOUNT_EXTRAS)							inode->i_mode |= (inode->i_mode >> 2) & 0111;						break;					/* case aSYSTEM|aHIDDEN: */					default:						/* reserved combination */						break;				}			}#endif		}		if (nwi->attributes & aRONLY) inode->i_mode &= ~0222;	}	inode->i_blocks = (inode->i_size + NCP_BLOCK_SIZE - 1) >> NCP_BLOCK_SHIFT;	inode->i_mtime = ncp_date_dos2unix(le16_to_cpu(nwi->modifyTime),					   le16_to_cpu(nwi->modifyDate));	inode->i_ctime = ncp_date_dos2unix(le16_to_cpu(nwi->creationTime),					   le16_to_cpu(nwi->creationDate));	inode->i_atime = ncp_date_dos2unix(0, le16_to_cpu(nwi->lastAccessDate));	NCP_FINFO(inode)->DosDirNum = nwi->DosDirNum;	NCP_FINFO(inode)->dirEntNum = nwi->dirEntNum;	NCP_FINFO(inode)->volNumber = nwi->volNumber;}/* * Fill in the inode based on the ncp_entry_info structure. */static void ncp_set_attr(struct inode *inode, struct ncp_entry_info *nwinfo){	struct nw_info_struct *nwi = &nwinfo->i;	struct ncp_server *server = NCP_SERVER(inode);	if (nwi->attributes & aDIR) {		inode->i_mode = server->m.dir_mode;		/* for directories dataStreamSize seems to be some		   Object ID ??? */		inode->i_size = NCP_BLOCK_SIZE;	} else {		inode->i_mode = server->m.file_mode;		inode->i_size = le32_to_cpu(nwi->dataStreamSize);#ifdef CONFIG_NCPFS_EXTRAS		if ((server->m.flags & (NCP_MOUNT_EXTRAS|NCP_MOUNT_SYMLINKS)) 		 && (nwi->attributes & aSHARED)) {			switch (nwi->attributes & (aHIDDEN|aSYSTEM)) {				case aHIDDEN:					if (server->m.flags & NCP_MOUNT_SYMLINKS) {						if (/* (inode->i_size >= NCP_MIN_SYMLINK_SIZE)						 && */ (inode->i_size <= NCP_MAX_SYMLINK_SIZE)) {							inode->i_mode = (inode->i_mode & ~S_IFMT) | S_IFLNK;							break;						}					}					/* FALLTHROUGH */				case 0:					if (server->m.flags & NCP_MOUNT_EXTRAS)						inode->i_mode |= 0444;					break;				case aSYSTEM:					if (server->m.flags & NCP_MOUNT_EXTRAS)						inode->i_mode |= (inode->i_mode >> 2) & 0111;					break;				/* case aSYSTEM|aHIDDEN: */				default:					/* reserved combination */					break;			}		}#endif	}	if (nwi->attributes & aRONLY) inode->i_mode &= ~0222;	DDPRINTK("ncp_read_inode: inode->i_mode = %u\n", inode->i_mode);	inode->i_nlink = 1;	inode->i_uid = server->m.uid;	inode->i_gid = server->m.gid;	inode->i_rdev = 0;	inode->i_blksize = NCP_BLOCK_SIZE;	inode->i_blocks = (inode->i_size + NCP_BLOCK_SIZE - 1) >> NCP_BLOCK_SHIFT;	inode->i_mtime = ncp_date_dos2unix(le16_to_cpu(nwi->modifyTime),			  		   le16_to_cpu(nwi->modifyDate));	inode->i_ctime = ncp_date_dos2unix(le16_to_cpu(nwi->creationTime),			    		   le16_to_cpu(nwi->creationDate));	inode->i_atime = ncp_date_dos2unix(0,					   le16_to_cpu(nwi->lastAccessDate));	ncp_update_inode(inode, nwinfo);}static struct inode_operations ncp_symlink_inode_operations = {	readlink:	page_readlink,	follow_link:	page_follow_link,	setattr:	ncp_notify_change,};/* * Get a new inode. */struct inode * ncp_iget(struct super_block *sb, struct ncp_entry_info *info){	struct inode *inode;	if (info == NULL) {		printk(KERN_ERR "ncp_iget: info is NULL\n");		return NULL;	}	inode = new_inode(sb);	if (inode) {		init_MUTEX(&NCP_FINFO(inode)->open_sem);		atomic_set(&NCP_FINFO(inode)->opened, info->opened);		inode->i_ino = info->ino;		ncp_set_attr(inode, info);		if (S_ISREG(inode->i_mode)) {			inode->i_op = &ncp_file_inode_operations;			inode->i_fop = &ncp_file_operations;		} else if (S_ISDIR(inode->i_mode)) {			inode->i_op = &ncp_dir_inode_operations;			inode->i_fop = &ncp_dir_operations;#ifdef CONFIG_NCPFS_EXTRAS		} else if (S_ISLNK(inode->i_mode)) {			inode->i_op = &ncp_symlink_inode_operations;			inode->i_data.a_ops = &ncp_symlink_aops;#endif		}		insert_inode_hash(inode);	} else		printk(KERN_ERR "ncp_iget: iget failed!\n");	return inode;}static voidncp_delete_inode(struct inode *inode){	if (S_ISDIR(inode->i_mode)) {		DDPRINTK("ncp_delete_inode: put directory %ld\n", inode->i_ino);	}	if (ncp_make_closed(inode) != 0) {		/* We can't do anything but complain. */		printk(KERN_ERR "ncp_delete_inode: could not close\n");	}	clear_inode(inode);}struct super_block *ncp_read_super(struct super_block *sb, void *raw_data, int silent){	struct ncp_mount_data_kernel data;	struct ncp_server *server;	struct file *ncp_filp;	struct inode *root_inode;	struct inode *sock_inode;	struct socket *sock;	int error;	int default_bufsize;#ifdef CONFIG_NCPFS_PACKET_SIGNING	int options;#endif	struct ncp_entry_info finfo;	if (raw_data == NULL)		goto out_no_data;	switch (*(int*)raw_data) {		case NCP_MOUNT_VERSION:			{				struct ncp_mount_data* md = (struct ncp_mount_data*)raw_data;				data.flags = md->flags;				data.int_flags = NCP_IMOUNT_LOGGEDIN_POSSIBLE;				data.mounted_uid = md->mounted_uid;				data.wdog_pid = md->wdog_pid;				data.ncp_fd = md->ncp_fd;				data.time_out = md->time_out;				data.retry_count = md->retry_count;				data.uid = md->uid;				data.gid = md->gid;				data.file_mode = md->file_mode;				data.dir_mode = md->dir_mode;				memcpy(data.mounted_vol, md->mounted_vol,					NCP_VOLNAME_LEN+1);			}			break;		case NCP_MOUNT_VERSION_V4:			{				struct ncp_mount_data_v4* md = (struct ncp_mount_data_v4*)raw_data;				data.flags = md->flags;				data.int_flags = 0;				data.mounted_uid = md->mounted_uid;				data.wdog_pid = md->wdog_pid;				data.ncp_fd = md->ncp_fd;				data.time_out = md->time_out;				data.retry_count = md->retry_count;				data.uid = md->uid;				data.gid = md->gid;				data.file_mode = md->file_mode;				data.dir_mode = md->dir_mode;				data.mounted_vol[0] = 0;			}			break;		default:			goto out_bad_mount;	}	ncp_filp = fget(data.ncp_fd);	if (!ncp_filp)		goto out_bad_file;	sock_inode = ncp_filp->f_dentry->d_inode;	if (!S_ISSOCK(sock_inode->i_mode))		goto out_bad_file2;	sock = &sock_inode->u.socket_i;	if (!sock)		goto out_bad_file2;			if (sock->type == SOCK_STREAM)		default_bufsize = 61440;	else		default_bufsize = 1024;	sb->s_blocksize = 1024;	/* Eh...  Is this correct? */	sb->s_blocksize_bits = 10;	sb->s_magic = NCP_SUPER_MAGIC;	sb->s_op = &ncp_sops;	server = NCP_SBP(sb);	memset(server, 0, sizeof(*server));	server->ncp_filp = ncp_filp;/*	server->lock = 0;	*/	init_MUTEX(&server->sem);	server->packet = NULL;/*	server->buffer_size = 0;	*//*	server->conn_status = 0;	*//*	server->root_dentry = NULL;	*//*	server->root_setuped = 0;	*/#ifdef CONFIG_NCPFS_PACKET_SIGNING/*	server->sign_wanted = 0;	*//*	server->sign_active = 0;	*/#endif	server->auth.auth_type = NCP_AUTH_NONE;/*	server->auth.object_name_len = 0;	*//*	server->auth.object_name = NULL;	*//*	server->auth.object_type = 0;		*//*	server->priv.len = 0;			*//*	server->priv.data = NULL;		*/	server->m = data;	/* Althought anything producing this is buggy, it happens	   now because of PATH_MAX changes.. */	if (server->m.time_out < 1) {		server->m.time_out = 10;		printk(KERN_INFO "You need to recompile your ncpfs utils..\n");	}	server->m.time_out = server->m.time_out * HZ / 100;	server->m.file_mode = (server->m.file_mode &			       (S_IRWXU | S_IRWXG | S_IRWXO)) | S_IFREG;	server->m.dir_mode = (server->m.dir_mode &

⌨️ 快捷键说明

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