📄 ioctl.c
字号:
break; case NCP_LOCK_LOG: rqdata.timeout = NCP_LOCK_DEFAULT_TIMEOUT; /* has no effect */ case NCP_LOCK_CLEAR: break; default: return -EINVAL; } /* locking needs both read and write access */ if ((result = ncp_make_open(inode, O_RDWR)) != 0) { return result; } result = -EIO; if (!ncp_conn_valid(server)) goto outrel; result = -EISDIR; if (!S_ISREG(inode->i_mode)) goto outrel; if (rqdata.cmd == NCP_LOCK_CLEAR) { result = ncp_ClearPhysicalRecord(NCP_SERVER(inode), NCP_FINFO(inode)->file_handle, rqdata.offset, rqdata.length); if (result > 0) result = 0; /* no such lock */ } else { int lockcmd; switch (rqdata.cmd) { case NCP_LOCK_EX: lockcmd=1; break; case NCP_LOCK_SH: lockcmd=3; break; default: lockcmd=0; break; } result = ncp_LogPhysicalRecord(NCP_SERVER(inode), NCP_FINFO(inode)->file_handle, lockcmd, rqdata.offset, rqdata.length, rqdata.timeout); if (result > 0) result = -EAGAIN; }outrel: ncp_inode_close(inode); return result; }#endif /* CONFIG_NCPFS_IOCTL_LOCKING */ case NCP_IOC_GETOBJECTNAME: if (current->uid != server->m.mounted_uid) { return -EACCES; } { struct ncp_objectname_ioctl user; size_t outl; if (copy_from_user(&user, (struct ncp_objectname_ioctl*)arg, sizeof(user))) return -EFAULT; user.auth_type = server->auth.auth_type; outl = user.object_name_len; user.object_name_len = server->auth.object_name_len; if (outl > user.object_name_len) outl = user.object_name_len; if (outl) { if (copy_to_user(user.object_name, server->auth.object_name, outl)) return -EFAULT; } if (copy_to_user((struct ncp_objectname_ioctl*)arg, &user, sizeof(user))) return -EFAULT; return 0; } case NCP_IOC_SETOBJECTNAME: if (current->uid != server->m.mounted_uid) { return -EACCES; } { struct ncp_objectname_ioctl user; void* newname; void* oldname; size_t oldnamelen; void* oldprivate; size_t oldprivatelen; if (copy_from_user(&user, (struct ncp_objectname_ioctl*)arg, sizeof(user))) return -EFAULT; if (user.object_name_len > NCP_OBJECT_NAME_MAX_LEN) return -ENOMEM; if (user.object_name_len) { newname = ncp_kmalloc(user.object_name_len, GFP_USER); if (!newname) return -ENOMEM; if (copy_from_user(newname, user.object_name, sizeof(user))) { ncp_kfree_s(newname, user.object_name_len); return -EFAULT; } } else { newname = NULL; } /* enter critical section */ /* maybe that kfree can sleep so do that this way */ /* it is at least more SMP friendly (in future...) */ oldname = server->auth.object_name; oldnamelen = server->auth.object_name_len; oldprivate = server->priv.data; oldprivatelen = server->priv.len; server->auth.auth_type = user.auth_type; server->auth.object_name_len = user.object_name_len; server->auth.object_name = user.object_name; server->priv.len = 0; server->priv.data = NULL; /* leave critical section */ if (oldprivate) ncp_kfree_s(oldprivate, oldprivatelen); if (oldname) ncp_kfree_s(oldname, oldnamelen); return 0; } case NCP_IOC_GETPRIVATEDATA: if (current->uid != server->m.mounted_uid) { return -EACCES; } { struct ncp_privatedata_ioctl user; size_t outl; if (copy_from_user(&user, (struct ncp_privatedata_ioctl*)arg, sizeof(user))) return -EFAULT; outl = user.len; user.len = server->priv.len; if (outl > user.len) outl = user.len; if (outl) { if (copy_to_user(user.data, server->priv.data, outl)) return -EFAULT; } if (copy_to_user((struct ncp_privatedata_ioctl*)arg, &user, sizeof(user))) return -EFAULT; return 0; } case NCP_IOC_SETPRIVATEDATA: if (current->uid != server->m.mounted_uid) { return -EACCES; } { struct ncp_privatedata_ioctl user; void* new; void* old; size_t oldlen; if (copy_from_user(&user, (struct ncp_privatedata_ioctl*)arg, sizeof(user))) return -EFAULT; if (user.len > NCP_PRIVATE_DATA_MAX_LEN) return -ENOMEM; if (user.len) { new = ncp_kmalloc(user.len, GFP_USER); if (!new) return -ENOMEM; if (copy_from_user(new, user.data, user.len)) { ncp_kfree_s(new, user.len); return -EFAULT; } } else { new = NULL; } /* enter critical section */ old = server->priv.data; oldlen = server->priv.len; server->priv.len = user.len; server->priv.data = new; /* leave critical section */ if (old) ncp_kfree_s(old, oldlen); return 0; }#ifdef CONFIG_NCPFS_NLS/* Here we are select the iocharset and the codepage for NLS. * Thanks Petr Vandrovec for idea and many hints. */ case NCP_IOC_SETCHARSETS: if (!capable(CAP_SYS_ADMIN)) return -EACCES; if (server->root_setuped) return -EBUSY; { struct ncp_nls_ioctl user; struct nls_table *codepage; struct nls_table *iocharset; struct nls_table *oldset_io; struct nls_table *oldset_cp; if (copy_from_user(&user, (struct ncp_nls_ioctl*)arg, sizeof(user))) return -EFAULT; codepage = NULL; user.codepage[NCP_IOCSNAME_LEN] = 0; if (!user.codepage[0] || !strcmp(user.codepage, "default")) codepage = load_nls_default(); else { codepage = load_nls(user.codepage); if (!codepage) { return -EBADRQC; } } iocharset = NULL; user.iocharset[NCP_IOCSNAME_LEN] = 0; if (!user.iocharset[0] || !strcmp(user.iocharset, "default")) { iocharset = load_nls_default(); NCP_CLR_FLAG(server, NCP_FLAG_UTF8); } else { if (!strcmp(user.iocharset, "utf8")) { iocharset = load_nls_default(); NCP_SET_FLAG(server, NCP_FLAG_UTF8); } else { iocharset = load_nls(user.iocharset); if (!iocharset) { unload_nls(codepage); return -EBADRQC; } NCP_CLR_FLAG(server, NCP_FLAG_UTF8); } } oldset_cp = server->nls_vol; server->nls_vol = codepage; oldset_io = server->nls_io; server->nls_io = iocharset; if (oldset_cp) unload_nls(oldset_cp); if (oldset_io) unload_nls(oldset_io); return 0; } case NCP_IOC_GETCHARSETS: /* not tested */ { struct ncp_nls_ioctl user; int len; memset(&user, 0, sizeof(user)); if (server->nls_vol && server->nls_vol->charset) { len = strlen(server->nls_vol->charset); if (len > NCP_IOCSNAME_LEN) len = NCP_IOCSNAME_LEN; strncpy(user.codepage, server->nls_vol->charset, len); user.codepage[len] = 0; } if (NCP_IS_FLAG(server, NCP_FLAG_UTF8)) strcpy(user.iocharset, "utf8"); else if (server->nls_io && server->nls_io->charset) { len = strlen(server->nls_io->charset); if (len > NCP_IOCSNAME_LEN) len = NCP_IOCSNAME_LEN; strncpy(user.iocharset, server->nls_io->charset, len); user.iocharset[len] = 0; } if (copy_to_user((struct ncp_nls_ioctl*)arg, &user, sizeof(user))) return -EFAULT; return 0; }#endif /* CONFIG_NCPFS_NLS */ case NCP_IOC_SETDENTRYTTL: if ((permission(inode, MAY_WRITE) != 0) && (current->uid != server->m.mounted_uid)) return -EACCES; { u_int32_t user; if (copy_from_user(&user, (u_int32_t*)arg, sizeof(user))) return -EFAULT; /* 20 secs at most... */ if (user > 20000) return -EINVAL; user = (user * HZ) / 1000; server->dentry_ttl = user; return 0; } case NCP_IOC_GETDENTRYTTL: { u_int32_t user = (server->dentry_ttl * 1000) / HZ; if (copy_to_user((u_int32_t*)arg, &user, sizeof(user))) return -EFAULT; return 0; } }/* #ifdef CONFIG_UID16 */ /* NCP_IOC_GETMOUNTUID may be same as NCP_IOC_GETMOUNTUID2, so we have this out of switch */ if (cmd == NCP_IOC_GETMOUNTUID) { if ((permission(inode, MAY_READ) != 0) && (current->uid != server->m.mounted_uid)) { return -EACCES; } if (put_user(NEW_TO_OLD_UID(server->m.mounted_uid), (__kernel_uid_t *) arg)) return -EFAULT; return 0; }/* #endif */ return -EINVAL;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -