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

📄 inode.c

📁 《嵌入式系统设计与实例开发实验教材二源码》Linux内核移植与编译实验
💻 C
📖 第 1 页 / 共 2 页
字号:
			      (S_IRWXU | S_IRWXG | S_IRWXO)) | S_IFDIR;#ifdef CONFIG_NCPFS_NLS	/* load the default NLS charsets */	server->nls_vol = load_nls_default();	server->nls_io = load_nls_default();#endif /* CONFIG_NCPFS_NLS */	server->dentry_ttl = 0;	/* no caching */#undef NCP_PACKET_SIZE#define NCP_PACKET_SIZE 65536	server->packet_size = NCP_PACKET_SIZE;	server->packet = vmalloc(NCP_PACKET_SIZE);	if (server->packet == NULL)		goto out_no_packet;	ncp_lock_server(server);	error = ncp_connect(server);	ncp_unlock_server(server);	if (error < 0)		goto out_no_connect;	DPRINTK("ncp_read_super: NCP_SBP(sb) = %x\n", (int) NCP_SBP(sb));#ifdef CONFIG_NCPFS_PACKET_SIGNING	if (ncp_negotiate_size_and_options(server, default_bufsize,		NCP_DEFAULT_OPTIONS, &(server->buffer_size), &options) == 0)	{		if (options != NCP_DEFAULT_OPTIONS)		{			if (ncp_negotiate_size_and_options(server, 				default_bufsize,				options & 2, 				&(server->buffer_size), &options) != 0)							{				goto out_no_bufsize;			}		}		if (options & 2)			server->sign_wanted = 1;	}	else #endif	/* CONFIG_NCPFS_PACKET_SIGNING */	if (ncp_negotiate_buffersize(server, default_bufsize,  				     &(server->buffer_size)) != 0)		goto out_no_bufsize;	DPRINTK("ncpfs: bufsize = %d\n", server->buffer_size);	memset(&finfo, 0, sizeof(finfo));	finfo.i.attributes	= aDIR;	finfo.i.dataStreamSize	= NCP_BLOCK_SIZE;	finfo.i.dirEntNum	= 0;	finfo.i.DosDirNum	= 0;#ifdef CONFIG_NCPFS_SMALLDOS	finfo.i.NSCreator	= NW_NS_DOS;#endif	finfo.i.volNumber	= NCP_NUMBER_OF_VOLUMES + 1;	/* illegal volnum */	/* set dates of mountpoint to Jan 1, 1986; 00:00 */	finfo.i.creationTime	= finfo.i.modifyTime				= cpu_to_le16(0x0000);	finfo.i.creationDate	= finfo.i.modifyDate				= finfo.i.lastAccessDate				= cpu_to_le16(0x0C21);	finfo.i.nameLen		= 0;	finfo.i.entryName[0]	= '\0';	finfo.opened		= 0;	finfo.ino		= 2;	/* tradition */	server->name_space[finfo.i.volNumber] = NW_NS_DOS;        root_inode = ncp_iget(sb, &finfo);        if (!root_inode)		goto out_no_root;	DPRINTK("ncp_read_super: root vol=%d\n", NCP_FINFO(root_inode)->volNumber);	sb->s_root = d_alloc_root(root_inode);        if (!sb->s_root)		goto out_no_root;	sb->s_root->d_op = &ncp_dentry_operations;	return sb;out_no_root:	printk(KERN_ERR "ncp_read_super: get root inode failed\n");	iput(root_inode);	goto out_disconnect;out_no_bufsize:	printk(KERN_ERR "ncp_read_super: could not get bufsize\n");out_disconnect:	ncp_lock_server(server);	ncp_disconnect(server);	ncp_unlock_server(server);	goto out_free_packet;out_no_connect:	printk(KERN_ERR "ncp_read_super: Failed connection, error=%d\n", error);out_free_packet:	vfree(server->packet);	goto out_free_server;out_no_packet:	printk(KERN_ERR "ncp_read_super: could not alloc packet\n");out_free_server:#ifdef CONFIG_NCPFS_NLS	unload_nls(server->nls_io);	unload_nls(server->nls_vol);#endif	/* 23/12/1998 Marcin Dalecki <dalecki@cs.net.pl>:	 * 	 * The previously used put_filp(ncp_filp); was bogous, since	 * it doesn't proper unlocking.	 */	fput(ncp_filp);	goto out;out_bad_file2:	fput(ncp_filp);out_bad_file:	printk(KERN_ERR "ncp_read_super: invalid ncp socket\n");	goto out;out_bad_mount:	printk(KERN_INFO "ncp_read_super: kernel requires mount version %d\n",		NCP_MOUNT_VERSION);	goto out;out_no_data:	printk(KERN_ERR "ncp_read_super: missing data argument\n");out:	return NULL;}static void ncp_put_super(struct super_block *sb){	struct ncp_server *server = NCP_SBP(sb);	ncp_lock_server(server);	ncp_disconnect(server);	ncp_unlock_server(server);#ifdef CONFIG_NCPFS_NLS	/* unload the NLS charsets */	if (server->nls_vol)	{		unload_nls(server->nls_vol);		server->nls_vol = NULL;	}	if (server->nls_io)	{		unload_nls(server->nls_io);		server->nls_io = NULL;	}#endif /* CONFIG_NCPFS_NLS */	fput(server->ncp_filp);	kill_proc(server->m.wdog_pid, SIGTERM, 1);	if (server->priv.data) 		ncp_kfree_s(server->priv.data, server->priv.len);	if (server->auth.object_name)		ncp_kfree_s(server->auth.object_name, server->auth.object_name_len);	vfree(server->packet);}static int ncp_statfs(struct super_block *sb, struct statfs *buf){	/* We cannot say how much disk space is left on a mounted	   NetWare Server, because free space is distributed over	   volumes, and the current user might have disk quotas. So	   free space is not that simple to determine. Our decision	   here is to err conservatively. */	buf->f_type = NCP_SUPER_MAGIC;	buf->f_bsize = NCP_BLOCK_SIZE;	buf->f_blocks = 0;	buf->f_bfree = 0;	buf->f_bavail = 0;	buf->f_namelen = 12;	return 0;}int ncp_notify_change(struct dentry *dentry, struct iattr *attr){	struct inode *inode = dentry->d_inode;	int result = 0;	int info_mask;	struct nw_modify_dos_info info;	struct ncp_server *server;	result = -EIO;	server = NCP_SERVER(inode);	if ((!server) || !ncp_conn_valid(server))		goto out;	/* ageing the dentry to force validation */	ncp_age_dentry(server, dentry);	result = inode_change_ok(inode, attr);	if (result < 0)		goto out;	result = -EPERM;	if (((attr->ia_valid & ATTR_UID) &&	     (attr->ia_uid != server->m.uid)))		goto out;	if (((attr->ia_valid & ATTR_GID) &&	     (attr->ia_gid != server->m.gid)))		goto out;	if (((attr->ia_valid & ATTR_MODE) &&	     (attr->ia_mode &	      ~(S_IFREG | S_IFDIR | S_IRWXU | S_IRWXG | S_IRWXO))))		goto out;	info_mask = 0;	memset(&info, 0, sizeof(info));#if 1         if ((attr->ia_valid & ATTR_MODE) != 0)        {                if (S_ISDIR(inode->i_mode)) {                	umode_t newmode;                	info_mask |= DM_ATTRIBUTES;                	newmode = attr->ia_mode;                	newmode &= NCP_SERVER(inode)->m.dir_mode;                	if (newmode & 0222)                		info.attributes &= ~(aRONLY|aRENAMEINHIBIT|aDELETEINHIBIT);                	else				info.attributes |=  (aRONLY|aRENAMEINHIBIT|aDELETEINHIBIT);                } else if (!S_ISREG(inode->i_mode))                {                        return -EPERM;                }                else                {			umode_t newmode;#ifdef CONFIG_NCPFS_EXTRAS						int extras;						extras = server->m.flags & NCP_MOUNT_EXTRAS;#endif                        info_mask |= DM_ATTRIBUTES;                        newmode=attr->ia_mode;#ifdef CONFIG_NCPFS_EXTRAS			if (!extras)#endif	                        newmode &= server->m.file_mode;                        if (newmode & 0222) /* any write bit set */                        {                                info.attributes &= ~(aRONLY|aRENAMEINHIBIT|aDELETEINHIBIT);                        }                        else                        {                                info.attributes |=  (aRONLY|aRENAMEINHIBIT|aDELETEINHIBIT);                        }#ifdef CONFIG_NCPFS_EXTRAS			if (extras) {				if (newmode & 0111) /* any execute bit set */					info.attributes |= aSHARED | aSYSTEM;				/* read for group/world and not in default file_mode */				else if (newmode & ~server->m.file_mode & 0444)					info.attributes |= aSHARED;			}#endif                }        }#endif	if ((attr->ia_valid & ATTR_CTIME) != 0) {		info_mask |= (DM_CREATE_TIME | DM_CREATE_DATE);		ncp_date_unix2dos(attr->ia_ctime,			     &(info.creationTime), &(info.creationDate));		info.creationTime = le16_to_cpu(info.creationTime);		info.creationDate = le16_to_cpu(info.creationDate);	}	if ((attr->ia_valid & ATTR_MTIME) != 0) {		info_mask |= (DM_MODIFY_TIME | DM_MODIFY_DATE);		ncp_date_unix2dos(attr->ia_mtime,				  &(info.modifyTime), &(info.modifyDate));		info.modifyTime = le16_to_cpu(info.modifyTime);		info.modifyDate = le16_to_cpu(info.modifyDate);	}	if ((attr->ia_valid & ATTR_ATIME) != 0) {		__u16 dummy;		info_mask |= (DM_LAST_ACCESS_DATE);		ncp_date_unix2dos(attr->ia_ctime,				  &(dummy), &(info.lastAccessDate));		info.lastAccessDate = le16_to_cpu(info.lastAccessDate);	}	if (info_mask != 0) {		result = ncp_modify_file_or_subdir_dos_info(NCP_SERVER(inode),				      inode, info_mask, &info);		if (result != 0) {			result = -EACCES;			if (info_mask == (DM_CREATE_TIME | DM_CREATE_DATE)) {				/* NetWare seems not to allow this. I				   do not know why. So, just tell the				   user everything went fine. This is				   a terrible hack, but I do not know				   how to do this correctly. */				result = 0;			}		}#ifdef CONFIG_NCPFS_STRONG				if ((!result) && (info_mask & DM_ATTRIBUTES))			NCP_FINFO(inode)->nwattr = info.attributes;#endif	}	if ((attr->ia_valid & ATTR_SIZE) != 0) {		int written;		DPRINTK("ncpfs: trying to change size to %ld\n",			attr->ia_size);		if ((result = ncp_make_open(inode, O_WRONLY)) < 0) {			return -EACCES;		}		ncp_write_kernel(NCP_SERVER(inode), NCP_FINFO(inode)->file_handle,			  attr->ia_size, 0, "", &written);		/* According to ndir, the changes only take effect after		   closing the file */		ncp_inode_close(inode);		result = ncp_make_closed(inode);		if (!result)			result = vmtruncate(inode, attr->ia_size);	}out:	return result;}#ifdef DEBUG_NCP_MALLOCint ncp_malloced;int ncp_current_malloced;#endifstatic DECLARE_FSTYPE(ncp_fs_type, "ncpfs", ncp_read_super, 0);static int __init init_ncp_fs(void){	DPRINTK("ncpfs: init_module called\n");#ifdef DEBUG_NCP_MALLOC	ncp_malloced = 0;	ncp_current_malloced = 0;#endif	return register_filesystem(&ncp_fs_type);}static void __exit exit_ncp_fs(void){	DPRINTK("ncpfs: cleanup_module called\n");	unregister_filesystem(&ncp_fs_type);#ifdef DEBUG_NCP_MALLOC	PRINTK("ncp_malloced: %d\n", ncp_malloced);	PRINTK("ncp_current_malloced: %d\n", ncp_current_malloced);#endif}EXPORT_NO_SYMBOLS;module_init(init_ncp_fs)module_exit(exit_ncp_fs)MODULE_LICENSE("GPL");

⌨️ 快捷键说明

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