📄 inode.c
字号:
/* * smb_show_options() is for displaying mount options in /proc/mounts. * It tries to avoid showing settings that were not changed from their * defaults. */static intsmb_show_options(struct seq_file *s, struct vfsmount *m){ struct smb_mount_data_kernel *mnt = SMB_SB(m->mnt_sb)->mnt; int i; for (i = 0; opts[i].name != NULL; i++) if (mnt->flags & opts[i].flag) seq_printf(s, ",%s", opts[i].name); if (mnt->flags & SMB_MOUNT_UID) seq_printf(s, ",uid=%d", mnt->uid); if (mnt->flags & SMB_MOUNT_GID) seq_printf(s, ",gid=%d", mnt->gid); if (mnt->mounted_uid != 0) seq_printf(s, ",mounted_uid=%d", mnt->mounted_uid); /* * Defaults for file_mode and dir_mode are unknown to us; they * depend on the current umask of the user doing the mount. */ if (mnt->flags & SMB_MOUNT_FMODE) seq_printf(s, ",file_mode=%04o", mnt->file_mode & S_IRWXUGO); if (mnt->flags & SMB_MOUNT_DMODE) seq_printf(s, ",dir_mode=%04o", mnt->dir_mode & S_IRWXUGO); if (strcmp(mnt->codepage.local_name, CONFIG_NLS_DEFAULT)) seq_printf(s, ",iocharset=%s", mnt->codepage.local_name); if (strcmp(mnt->codepage.remote_name, SMB_NLS_REMOTE)) seq_printf(s, ",codepage=%s", mnt->codepage.remote_name); if (mnt->ttl != SMB_TTL_DEFAULT) seq_printf(s, ",ttl=%d", mnt->ttl); return 0;}static voidsmb_unload_nls(struct smb_sb_info *server){ if (server->remote_nls) { unload_nls(server->remote_nls); server->remote_nls = NULL; } if (server->local_nls) { unload_nls(server->local_nls); server->local_nls = NULL; }}static voidsmb_put_super(struct super_block *sb){ struct smb_sb_info *server = SMB_SB(sb); smb_lock_server(server); server->state = CONN_INVALID; smbiod_unregister_server(server); smb_close_socket(server); if (server->conn_pid) kill_pid(server->conn_pid, SIGTERM, 1); kfree(server->ops); smb_unload_nls(server); sb->s_fs_info = NULL; smb_unlock_server(server); put_pid(server->conn_pid); kfree(server);}static int smb_fill_super(struct super_block *sb, void *raw_data, int silent){ struct smb_sb_info *server; struct smb_mount_data_kernel *mnt; struct smb_mount_data *oldmnt; struct inode *root_inode; struct smb_fattr root; int ver; void *mem; 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_flags |= MS_NODIRATIME; sb->s_blocksize = 1024; /* Eh... Is this correct? */ sb->s_blocksize_bits = 10; sb->s_magic = SMB_SUPER_MAGIC; sb->s_op = &smb_sops; sb->s_time_gran = 100; server = kzalloc(sizeof(struct smb_sb_info), GFP_KERNEL); if (!server) goto out_no_server; sb->s_fs_info = server; server->super_block = sb; server->mnt = NULL; server->sock_file = NULL; init_waitqueue_head(&server->conn_wq); init_MUTEX(&server->sem); INIT_LIST_HEAD(&server->entry); INIT_LIST_HEAD(&server->xmitq); INIT_LIST_HEAD(&server->recvq); server->conn_error = 0; server->conn_pid = NULL; server->state = CONN_INVALID; /* no connection yet */ server->generation = 0; /* Allocate the global temp buffer and some superblock helper structs */ /* FIXME: move these to the smb_sb_info struct */ VERBOSE("alloc chunk = %lu\n", sizeof(struct smb_ops) + sizeof(struct smb_mount_data_kernel)); mem = kmalloc(sizeof(struct smb_ops) + sizeof(struct smb_mount_data_kernel), GFP_KERNEL); if (!mem) goto out_no_mem; server->ops = mem; smb_install_null_ops(server->ops); server->mnt = mem + sizeof(struct smb_ops); /* Setup NLS stuff */ server->remote_nls = NULL; server->local_nls = NULL; mnt = server->mnt; memset(mnt, 0, sizeof(struct smb_mount_data_kernel)); strlcpy(mnt->codepage.local_name, CONFIG_NLS_DEFAULT, SMB_NLS_MAXNAMELEN); strlcpy(mnt->codepage.remote_name, SMB_NLS_REMOTE, SMB_NLS_MAXNAMELEN); mnt->ttl = SMB_TTL_DEFAULT; if (ver == SMB_MOUNT_OLDVERSION) { mnt->version = oldmnt->version; SET_UID(mnt->uid, oldmnt->uid); SET_GID(mnt->gid, oldmnt->gid); mnt->file_mode = (oldmnt->file_mode & S_IRWXUGO) | S_IFREG; mnt->dir_mode = (oldmnt->dir_mode & S_IRWXUGO) | S_IFDIR; mnt->flags = (oldmnt->file_mode >> 9) | SMB_MOUNT_UID | SMB_MOUNT_GID | SMB_MOUNT_FMODE | SMB_MOUNT_DMODE; } else { mnt->file_mode = S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH | S_IFREG; mnt->dir_mode = S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH | S_IFDIR; if (parse_options(mnt, raw_data)) goto out_bad_option; } mnt->mounted_uid = current->uid; smb_setcodepage(server, &mnt->codepage); /* * 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"); if (smbiod_register_server(server) < 0) { printk(KERN_ERR "smbfs: failed to start smbiod\n"); goto out_no_smbiod; } /* * Keep the super block locked while we get the root inode. */ smb_init_root_dirent(server, &root, sb); 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; smb_new_dentry(sb->s_root); return 0;out_no_root: iput(root_inode);out_no_smbiod: smb_unload_nls(server);out_bad_option: kfree(mem);out_no_mem: if (!server->mnt) printk(KERN_ERR "smb_fill_super: allocation failure\n"); sb->s_fs_info = NULL; kfree(server); 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_fill_super: missing data argument\n");out_fail: return -EINVAL;out_no_server: printk(KERN_ERR "smb_fill_super: cannot allocate struct smb_sb_info\n"); return -ENOMEM;}static intsmb_statfs(struct dentry *dentry, struct kstatfs *buf){ int result; lock_kernel(); result = smb_proc_dskattr(dentry, buf); unlock_kernel(); buf->f_type = SMB_SUPER_MAGIC; buf->f_namelen = SMB_MAXPATHLEN; return result;}int smb_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat){ int err = smb_revalidate_inode(dentry); if (!err) generic_fillattr(dentry->d_inode, stat); return err;}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_IRWXUGO); int error, changed, refresh = 0; struct smb_fattr fattr; lock_kernel(); 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); filemap_write_and_wait(inode->i_mapping); error = smb_open(dentry, O_WRONLY); if (error) goto out; error = server->ops->truncate(inode, attr->ia_size); if (error) goto out; error = vmtruncate(inode, attr->ia_size); if (error) goto out; refresh = 1; } if (server->opt.capabilities & SMB_CAP_UNIX) { /* For now we don't want to set the size with setattr_unix */ attr->ia_valid &= ~ATTR_SIZE; /* FIXME: only call if we actually want to set something? */ error = smb_proc_setattr_unix(dentry, attr, 0, 0); if (!error) refresh = 1; goto out; } /* * 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); unlock_kernel(); return error;}static int smb_get_sb(struct file_system_type *fs_type, int flags, const char *dev_name, void *data, struct vfsmount *mnt){ return get_sb_nodev(fs_type, flags, data, smb_fill_super, mnt);}static struct file_system_type smb_fs_type = { .owner = THIS_MODULE, .name = "smbfs", .get_sb = smb_get_sb, .kill_sb = kill_anon_super, .fs_flags = FS_BINARY_MOUNTDATA,};static int __init init_smb_fs(void){ int err; DEBUG1("registering ...\n"); err = init_inodecache(); if (err) goto out_inode; err = smb_init_request_cache(); if (err) goto out_request; err = register_filesystem(&smb_fs_type); if (err) goto out; return 0;out: smb_destroy_request_cache();out_request: destroy_inodecache();out_inode: return err;}static void __exit exit_smb_fs(void){ DEBUG1("unregistering ...\n"); unregister_filesystem(&smb_fs_type); smb_destroy_request_cache(); destroy_inodecache();}module_init(init_smb_fs)module_exit(exit_smb_fs)MODULE_LICENSE("GPL");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -