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

📄 inode.c

📁 讲述linux的初始化过程
💻 C
📖 第 1 页 / 共 2 页
字号:
		case 'i':			strncpy(mnt->codepage.local_name, optarg, 				SMB_NLS_MAXNAMELEN);			break;		case 'c':			strncpy(mnt->codepage.remote_name, optarg,				SMB_NLS_MAXNAMELEN);			break;		default:			printk ("smbfs: Unrecognized mount option %s\n",				optopt);			return -1;		}	}	mnt->flags = flags;	return c;}static voidsmb_put_super(struct super_block *sb){	struct smb_sb_info *server = &(sb->u.smbfs_sb);	if (server->sock_file) {		smb_proc_disconnect(server);		smb_dont_catch_keepalive(server);		fput(server->sock_file);	}	if (server->conn_pid)	       kill_proc(server->conn_pid, SIGTERM, 1);	kfree(server->mnt);	kfree(sb->u.smbfs_sb.temp_buf);	if (server->packet)		smb_vfree(server->packet);	if(sb->u.smbfs_sb.remote_nls) {		unload_nls(sb->u.smbfs_sb.remote_nls);		sb->u.smbfs_sb.remote_nls = NULL;	}	if(sb->u.smbfs_sb.local_nls) {		unload_nls(sb->u.smbfs_sb.local_nls);		sb->u.smbfs_sb.local_nls = NULL;	}}struct super_block *smb_read_super(struct super_block *sb, void *raw_data, int silent){	struct smb_mount_data_kernel *mnt;	struct smb_mount_data *oldmnt;	struct inode *root_inode;	struct smb_fattr root;	int ver;	if (!raw_data)		goto out_no_data;	oldmnt = (struct smb_mount_data *) raw_data;	ver = oldmnt->version;	if (ver != SMB_MOUNT_OLDVERSION && cpu_to_be32(ver) != SMB_MOUNT_ASCII)		goto out_wrong_data;	sb->s_blocksize = 1024;	/* Eh...  Is this correct? */	sb->s_blocksize_bits = 10;	sb->s_magic = SMB_SUPER_MAGIC;	sb->s_flags = 0;	sb->s_op = &smb_sops;	sb->u.smbfs_sb.mnt = NULL;	sb->u.smbfs_sb.sock_file = NULL;	init_MUTEX(&sb->u.smbfs_sb.sem);	init_waitqueue_head(&sb->u.smbfs_sb.wait);	sb->u.smbfs_sb.conn_pid = 0;	sb->u.smbfs_sb.state = CONN_INVALID; /* no connection yet */	sb->u.smbfs_sb.generation = 0;	sb->u.smbfs_sb.packet_size = smb_round_length(SMB_INITIAL_PACKET_SIZE);		sb->u.smbfs_sb.packet = smb_vmalloc(sb->u.smbfs_sb.packet_size);	if (!sb->u.smbfs_sb.packet)		goto out_no_mem;	/* Allocate the global temp buffer */	sb->u.smbfs_sb.temp_buf = kmalloc(2*SMB_MAXPATHLEN + 20, GFP_KERNEL);	if (!sb->u.smbfs_sb.temp_buf)		goto out_no_temp;	/* Setup NLS stuff */	sb->u.smbfs_sb.remote_nls = NULL;	sb->u.smbfs_sb.local_nls = NULL;	sb->u.smbfs_sb.name_buf = sb->u.smbfs_sb.temp_buf + SMB_MAXPATHLEN + 20;	/* Allocate the mount data structure */	/* FIXME: merge this with the other malloc and get a whole page? */	mnt = kmalloc(sizeof(struct smb_mount_data_kernel), GFP_KERNEL);	if (!mnt)		goto out_no_mount;	sb->u.smbfs_sb.mnt = mnt;	memset(mnt, 0, sizeof(struct smb_mount_data_kernel));	strncpy(mnt->codepage.local_name, CONFIG_NLS_DEFAULT,		SMB_NLS_MAXNAMELEN);	strncpy(mnt->codepage.remote_name, SMB_NLS_REMOTE,		SMB_NLS_MAXNAMELEN);	if (ver == SMB_MOUNT_OLDVERSION) {		mnt->version = oldmnt->version;		/* FIXME: is this enough to convert uid/gid's ? */		mnt->mounted_uid = oldmnt->mounted_uid;		mnt->uid = oldmnt->uid;		mnt->gid = oldmnt->gid;		mnt->file_mode =			oldmnt->file_mode & (S_IRWXU | S_IRWXG | S_IRWXO);		mnt->dir_mode =			oldmnt->dir_mode & (S_IRWXU | S_IRWXG | S_IRWXO);		mnt->file_mode |= S_IFREG;		mnt->dir_mode  |= S_IFDIR;		mnt->flags = (oldmnt->file_mode >> 9);	} else {		if (parse_options(mnt, raw_data))			goto out_bad_option;		mnt->mounted_uid = current->uid;	}	smb_setcodepage(&sb->u.smbfs_sb, &mnt->codepage);	if (!sb->u.smbfs_sb.convert)		PARANOIA("convert funcptr was NULL!\n");	/*	 * Display the enabled options	 * Note: smb_proc_getattr uses these in 2.4 (but was changed in 2.2)	 */	if (mnt->flags & SMB_MOUNT_OLDATTR)		printk("SMBFS: Using core getattr (Win 95 speedup)\n");	else if (mnt->flags & SMB_MOUNT_DIRATTR)		printk("SMBFS: Using dir ff getattr\n");	/*	 * Keep the super block locked while we get the root inode.	 */	smb_init_root_dirent(&(sb->u.smbfs_sb), &root);	root_inode = smb_iget(sb, &root);	if (!root_inode)		goto out_no_root;	sb->s_root = d_alloc_root(root_inode);	if (!sb->s_root)		goto out_no_root;	return sb;out_no_root:	iput(root_inode);out_bad_option:	kfree(sb->u.smbfs_sb.mnt);out_no_mount:	kfree(sb->u.smbfs_sb.temp_buf);out_no_temp:	smb_vfree(sb->u.smbfs_sb.packet);out_no_mem:	if (!sb->u.smbfs_sb.mnt)		printk(KERN_ERR "smb_read_super: allocation failure\n");	goto out_fail;out_wrong_data:	printk(KERN_ERR "smbfs: mount_data version %d is not supported\n", ver);	goto out_fail;out_no_data:	printk(KERN_ERR "smb_read_super: missing data argument\n");out_fail:	return NULL;}static intsmb_statfs(struct super_block *sb, struct statfs *buf){	smb_proc_dskattr(sb, buf);	buf->f_type = SMB_SUPER_MAGIC;	buf->f_namelen = SMB_MAXPATHLEN;	return 0;}intsmb_notify_change(struct dentry *dentry, struct iattr *attr){	struct inode *inode = dentry->d_inode;	struct smb_sb_info *server = server_from_dentry(dentry);	unsigned int mask = (S_IFREG | S_IFDIR | S_IRWXU | S_IRWXG | S_IRWXO);	int error, changed, refresh = 0;	struct smb_fattr fattr;	error = smb_revalidate_inode(dentry);	if (error)		goto out;	if ((error = inode_change_ok(inode, attr)) < 0)		goto out;	error = -EPERM;	if ((attr->ia_valid & ATTR_UID) && (attr->ia_uid != server->mnt->uid))		goto out;	if ((attr->ia_valid & ATTR_GID) && (attr->ia_uid != server->mnt->gid))		goto out;	if ((attr->ia_valid & ATTR_MODE) && (attr->ia_mode & ~mask))		goto out;	if ((attr->ia_valid & ATTR_SIZE) != 0)	{		VERBOSE("changing %s/%s, old size=%ld, new size=%ld\n",			DENTRY_PATH(dentry),			(long) inode->i_size, (long) attr->ia_size);		error = smb_open(dentry, O_WRONLY);		if (error)			goto out;		error = smb_proc_trunc(server, inode->u.smbfs_i.fileid,					 attr->ia_size);		if (error)			goto out;		vmtruncate(inode, attr->ia_size);		refresh = 1;	}	/*	 * Initialize the fattr and check for changed fields.	 * Note: CTIME under SMB is creation time rather than	 * change time, so we don't attempt to change it.	 */	smb_get_inode_attr(inode, &fattr);	changed = 0;	if ((attr->ia_valid & ATTR_MTIME) != 0)	{		fattr.f_mtime = attr->ia_mtime;		changed = 1;	}	if ((attr->ia_valid & ATTR_ATIME) != 0)	{		fattr.f_atime = attr->ia_atime;		/* Earlier protocols don't have an access time */		if (server->opt.protocol >= SMB_PROTOCOL_LANMAN2)			changed = 1;	}	if (changed)	{		error = smb_proc_settime(dentry, &fattr);		if (error)			goto out;		refresh = 1;	}	/*	 * Check for mode changes ... we're extremely limited in	 * what can be set for SMB servers: just the read-only bit.	 */	if ((attr->ia_valid & ATTR_MODE) != 0)	{		VERBOSE("%s/%s mode change, old=%x, new=%x\n",			DENTRY_PATH(dentry), fattr.f_mode, attr->ia_mode);		changed = 0;		if (attr->ia_mode & S_IWUSR)		{			if (fattr.attr & aRONLY)			{				fattr.attr &= ~aRONLY;				changed = 1;			}		} else {			if (!(fattr.attr & aRONLY))			{				fattr.attr |= aRONLY;				changed = 1;			}		}		if (changed)		{			error = smb_proc_setattr(dentry, &fattr);			if (error)				goto out;			refresh = 1;		}	}	error = 0;out:	if (refresh)		smb_refresh_inode(dentry);	return error;}#ifdef DEBUG_SMB_MALLOCint smb_malloced;int smb_current_kmalloced;int smb_current_vmalloced;#endifstatic DECLARE_FSTYPE( smb_fs_type, "smbfs", smb_read_super, 0);static int __init init_smb_fs(void){	DEBUG1("registering ...\n");#ifdef DEBUG_SMB_MALLOC	smb_malloced = 0;	smb_current_kmalloced = 0;	smb_current_vmalloced = 0;#endif	return register_filesystem(&smb_fs_type);}static void __exit exit_smb_fs(void){	DEBUG1("unregistering ...\n");	unregister_filesystem(&smb_fs_type);#ifdef DEBUG_SMB_MALLOC	printk(KERN_DEBUG "smb_malloced: %d\n", smb_malloced);	printk(KERN_DEBUG "smb_current_kmalloced: %d\n",smb_current_kmalloced);	printk(KERN_DEBUG "smb_current_vmalloced: %d\n",smb_current_vmalloced);#endif}EXPORT_NO_SYMBOLS;module_init(init_smb_fs)module_exit(exit_smb_fs)

⌨️ 快捷键说明

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