Changes in 4.9.185 tracing: Silence GCC 9 array bounds warning gcc-9: silence 'address-of-packed-member' warning scsi: ufs: Avoid runtime suspend possibly being blocked forever usb: chipidea: udc: workaround for endpoint conflict issue IB/hfi1: Silence txreq allocation warnings Input: uinput - add compat ioctl number translation for UI_*_FF_UPLOAD apparmor: enforce nullbyte at end of tag string ARC: fix build warnings with !CONFIG_KPROBES parport: Fix mem leak in parport_register_dev_model parisc: Fix compiler warnings in float emulation code IB/rdmavt: Fix alloc_qpn() WARN_ON() IB/hfi1: Insure freeze_work work_struct is canceled on shutdown IB/{qib, hfi1, rdmavt}: Correct ibv_devinfo max_mr value MIPS: uprobes: remove set but not used variable 'epc' net: dsa: mv88e6xxx: avoid error message on remove from VLAN 0 net: hns: Fix loopback test failed at copper ports sparc: perf: fix updated event period in response to PERF_EVENT_IOC_PERIOD net: ethernet: mediatek: Use hw_feature to judge if HWLRO is supported net: ethernet: mediatek: Use NET_IP_ALIGN to judge if HW RX_2BYTE_OFFSET is enabled drm/arm/hdlcd: Allow a bit of clock tolerance scripts/checkstack.pl: Fix arm64 wrong or unknown architecture scsi: ufs: Check that space was properly alloced in copy_query_response s390/qeth: fix VLAN attribute in bridge_hostnotify udev event hwmon: (pmbus/core) Treat parameters as paged if on multiple pages nvme: Fix u32 overflow in the number of namespace list calculation btrfs: start readahead also in seed devices can: flexcan: fix timeout when set small bitrate can: purge socket error queue on sock destruct powerpc/bpf: use unsigned division instruction for 64-bit operations ARM: imx: cpuidle-imx6sx: Restrict the SW2ISO increase to i.MX6SX Bluetooth: Align minimum encryption key size for LE and BR/EDR connections Bluetooth: Fix regression with minimum encryption key size alignment cfg80211: fix memory leak of wiphy device name mac80211: drop robust management frames from unknown TA mac80211: Do not use stack memory with scatterlist for GMAC IB/hfi1: Avoid hardlockup with flushlist_lock perf ui helpline: Use strlcpy() as a shorter form of strncpy() + explicit set nul perf help: Remove needless use of strncpy() perf header: Fix unchecked usage of strncpy() 9p/rdma: do not disconnect on down_interruptible EAGAIN 9p: acl: fix uninitialized iattr access 9p/rdma: remove useless check in cm_event_handler 9p: p9dirent_read: check network-provided name length net/9p: include trans_common.h to fix missing prototype warning. fs/proc/array.c: allow reporting eip/esp for all coredumping threads fs/binfmt_flat.c: make load_flat_shared_library() work mm/page_idle.c: fix oops because end_pfn is larger than max_pfn scsi: vmw_pscsi: Fix use-after-free in pvscsi_queue_lck() x86/speculation: Allow guests to use SSBD even if host does not NFS/flexfiles: Use the correct TCP timeout for flexfiles I/O cpu/speculation: Warn on unsupported mitigations= parameter af_packet: Block execution of tasks waiting for transmit to complete in AF_PACKET net: stmmac: fixed new system time seconds value calculation sctp: change to hold sk after auth shkey is created successfully tipc: change to use register_pernet_device tipc: check msg->req data len in tipc_nl_compat_bearer_disable tun: wake up waitqueues after IFF_UP is set team: Always enable vlan tx offload bonding: Always enable vlan tx offload ipv4: Use return value of inet_iif() for __raw_v4_lookup in the while loop bpf: udp: Avoid calling reuseport's bpf_prog from udp_gro bpf: udp: ipv6: Avoid running reuseport's bpf_prog from __udp6_lib_err tipc: pass tunnel dev as NULL to udp_tunnel(6)_xmit_skb Bluetooth: Fix faulty expression for minimum encryption key size check ASoC : cs4265 : readable register too low ASoC: soc-pcm: BE dai needs prepare when pause release after resume spi: bitbang: Fix NULL pointer dereference in spi_unregister_master drm/mediatek: fix unbind functions ASoC: max98090: remove 24-bit format support if RJ is 0 usb: gadget: fusb300_udc: Fix memory leak of fusb300->ep[i] usb: gadget: udc: lpc32xx: allocate descriptor with GFP_ATOMIC scsi: hpsa: correct ioaccel2 chaining scripts/decode_stacktrace.sh: prefix addr2line with $CROSS_COMPILE mm/mlock.c: change count_mm_mlocked_page_nr return type MIPS: math-emu: do not use bools for arithmetic MIPS: netlogic: xlr: Remove erroneous check in nlm_fmn_send() mfd: omap-usb-tll: Fix register offsets ARC: fix allnoconfig build warning bug.h: work around GCC PR82365 in BUG() ARC: handle gcc generated __builtin_trap for older compiler clk: sunxi: fix uninitialized access KVM: x86: degrade WARN to pr_warn_ratelimited drm/i915/dmc: protect against reading random memory MIPS: Workaround GCC __builtin_unreachable reordering bug ptrace: Fix ->ptracer_cred handling for PTRACE_TRACEME crypto: user - prevent operating on larval algorithms ALSA: seq: fix incorrect order of dest_client/dest_ports arguments ALSA: firewire-lib/fireworks: fix miss detection of received MIDI messages ALSA: line6: Fix write on zero-sized buffer ALSA: usb-audio: fix sign unintended sign extension on left shifts lib/mpi: Fix karactx leak in mpi_powm drm/imx: notify drm core before sending event during crtc disable drm/imx: only send event on crtc disable if kept disabled btrfs: Ensure replaced device doesn't have pending chunk allocation tty: rocket: fix incorrect forward declaration of 'rp_init()' arm64, vdso: Define vdso_{start,end} as array KVM: LAPIC: Fix pending interrupt in IRR blocked by software disable LAPIC IB/hfi1: Close PSM sdma_progress sleep window MIPS: Add missing EHB in mtc0 -> mfc0 sequence. dmaengine: imx-sdma: remove BD_INTR for channel0 arm64: kaslr: keep modules inside module region when KASAN is enabled Linux 4.9.185 Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
641 lines
14 KiB
C
641 lines
14 KiB
C
/*
|
|
* net/9p/protocol.c
|
|
*
|
|
* 9P Protocol Support Code
|
|
*
|
|
* Copyright (C) 2008 by Eric Van Hensbergen <ericvh@gmail.com>
|
|
*
|
|
* Base on code from Anthony Liguori <aliguori@us.ibm.com>
|
|
* Copyright (C) 2008 by IBM, Corp.
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License version 2
|
|
* as published by the Free Software Foundation.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program; if not, write to:
|
|
* Free Software Foundation
|
|
* 51 Franklin Street, Fifth Floor
|
|
* Boston, MA 02111-1301 USA
|
|
*
|
|
*/
|
|
|
|
#include <linux/module.h>
|
|
#include <linux/errno.h>
|
|
#include <linux/kernel.h>
|
|
#include <linux/uaccess.h>
|
|
#include <linux/slab.h>
|
|
#include <linux/sched.h>
|
|
#include <linux/stddef.h>
|
|
#include <linux/types.h>
|
|
#include <linux/uio.h>
|
|
#include <net/9p/9p.h>
|
|
#include <net/9p/client.h>
|
|
#include "protocol.h"
|
|
|
|
#include <trace/events/9p.h>
|
|
|
|
static int
|
|
p9pdu_writef(struct p9_fcall *pdu, int proto_version, const char *fmt, ...);
|
|
|
|
void p9stat_free(struct p9_wstat *stbuf)
|
|
{
|
|
kfree(stbuf->name);
|
|
stbuf->name = NULL;
|
|
kfree(stbuf->uid);
|
|
stbuf->uid = NULL;
|
|
kfree(stbuf->gid);
|
|
stbuf->gid = NULL;
|
|
kfree(stbuf->muid);
|
|
stbuf->muid = NULL;
|
|
kfree(stbuf->extension);
|
|
stbuf->extension = NULL;
|
|
}
|
|
EXPORT_SYMBOL(p9stat_free);
|
|
|
|
size_t pdu_read(struct p9_fcall *pdu, void *data, size_t size)
|
|
{
|
|
size_t len = min(pdu->size - pdu->offset, size);
|
|
memcpy(data, &pdu->sdata[pdu->offset], len);
|
|
pdu->offset += len;
|
|
return size - len;
|
|
}
|
|
|
|
static size_t pdu_write(struct p9_fcall *pdu, const void *data, size_t size)
|
|
{
|
|
size_t len = min(pdu->capacity - pdu->size, size);
|
|
memcpy(&pdu->sdata[pdu->size], data, len);
|
|
pdu->size += len;
|
|
return size - len;
|
|
}
|
|
|
|
static size_t
|
|
pdu_write_u(struct p9_fcall *pdu, struct iov_iter *from, size_t size)
|
|
{
|
|
size_t len = min(pdu->capacity - pdu->size, size);
|
|
struct iov_iter i = *from;
|
|
if (copy_from_iter(&pdu->sdata[pdu->size], len, &i) != len)
|
|
len = 0;
|
|
|
|
pdu->size += len;
|
|
return size - len;
|
|
}
|
|
|
|
/*
|
|
b - int8_t
|
|
w - int16_t
|
|
d - int32_t
|
|
q - int64_t
|
|
s - string
|
|
u - numeric uid
|
|
g - numeric gid
|
|
S - stat
|
|
Q - qid
|
|
D - data blob (int32_t size followed by void *, results are not freed)
|
|
T - array of strings (int16_t count, followed by strings)
|
|
R - array of qids (int16_t count, followed by qids)
|
|
A - stat for 9p2000.L (p9_stat_dotl)
|
|
? - if optional = 1, continue parsing
|
|
*/
|
|
|
|
static int
|
|
p9pdu_vreadf(struct p9_fcall *pdu, int proto_version, const char *fmt,
|
|
va_list ap)
|
|
{
|
|
const char *ptr;
|
|
int errcode = 0;
|
|
|
|
for (ptr = fmt; *ptr; ptr++) {
|
|
switch (*ptr) {
|
|
case 'b':{
|
|
int8_t *val = va_arg(ap, int8_t *);
|
|
if (pdu_read(pdu, val, sizeof(*val))) {
|
|
errcode = -EFAULT;
|
|
break;
|
|
}
|
|
}
|
|
break;
|
|
case 'w':{
|
|
int16_t *val = va_arg(ap, int16_t *);
|
|
__le16 le_val;
|
|
if (pdu_read(pdu, &le_val, sizeof(le_val))) {
|
|
errcode = -EFAULT;
|
|
break;
|
|
}
|
|
*val = le16_to_cpu(le_val);
|
|
}
|
|
break;
|
|
case 'd':{
|
|
int32_t *val = va_arg(ap, int32_t *);
|
|
__le32 le_val;
|
|
if (pdu_read(pdu, &le_val, sizeof(le_val))) {
|
|
errcode = -EFAULT;
|
|
break;
|
|
}
|
|
*val = le32_to_cpu(le_val);
|
|
}
|
|
break;
|
|
case 'q':{
|
|
int64_t *val = va_arg(ap, int64_t *);
|
|
__le64 le_val;
|
|
if (pdu_read(pdu, &le_val, sizeof(le_val))) {
|
|
errcode = -EFAULT;
|
|
break;
|
|
}
|
|
*val = le64_to_cpu(le_val);
|
|
}
|
|
break;
|
|
case 's':{
|
|
char **sptr = va_arg(ap, char **);
|
|
uint16_t len;
|
|
|
|
errcode = p9pdu_readf(pdu, proto_version,
|
|
"w", &len);
|
|
if (errcode)
|
|
break;
|
|
|
|
*sptr = kmalloc(len + 1, GFP_NOFS);
|
|
if (*sptr == NULL) {
|
|
errcode = -EFAULT;
|
|
break;
|
|
}
|
|
if (pdu_read(pdu, *sptr, len)) {
|
|
errcode = -EFAULT;
|
|
kfree(*sptr);
|
|
*sptr = NULL;
|
|
} else
|
|
(*sptr)[len] = 0;
|
|
}
|
|
break;
|
|
case 'u': {
|
|
kuid_t *uid = va_arg(ap, kuid_t *);
|
|
__le32 le_val;
|
|
if (pdu_read(pdu, &le_val, sizeof(le_val))) {
|
|
errcode = -EFAULT;
|
|
break;
|
|
}
|
|
*uid = make_kuid(&init_user_ns,
|
|
le32_to_cpu(le_val));
|
|
} break;
|
|
case 'g': {
|
|
kgid_t *gid = va_arg(ap, kgid_t *);
|
|
__le32 le_val;
|
|
if (pdu_read(pdu, &le_val, sizeof(le_val))) {
|
|
errcode = -EFAULT;
|
|
break;
|
|
}
|
|
*gid = make_kgid(&init_user_ns,
|
|
le32_to_cpu(le_val));
|
|
} break;
|
|
case 'Q':{
|
|
struct p9_qid *qid =
|
|
va_arg(ap, struct p9_qid *);
|
|
|
|
errcode = p9pdu_readf(pdu, proto_version, "bdq",
|
|
&qid->type, &qid->version,
|
|
&qid->path);
|
|
}
|
|
break;
|
|
case 'S':{
|
|
struct p9_wstat *stbuf =
|
|
va_arg(ap, struct p9_wstat *);
|
|
|
|
memset(stbuf, 0, sizeof(struct p9_wstat));
|
|
stbuf->n_uid = stbuf->n_muid = INVALID_UID;
|
|
stbuf->n_gid = INVALID_GID;
|
|
|
|
errcode =
|
|
p9pdu_readf(pdu, proto_version,
|
|
"wwdQdddqssss?sugu",
|
|
&stbuf->size, &stbuf->type,
|
|
&stbuf->dev, &stbuf->qid,
|
|
&stbuf->mode, &stbuf->atime,
|
|
&stbuf->mtime, &stbuf->length,
|
|
&stbuf->name, &stbuf->uid,
|
|
&stbuf->gid, &stbuf->muid,
|
|
&stbuf->extension,
|
|
&stbuf->n_uid, &stbuf->n_gid,
|
|
&stbuf->n_muid);
|
|
if (errcode)
|
|
p9stat_free(stbuf);
|
|
}
|
|
break;
|
|
case 'D':{
|
|
uint32_t *count = va_arg(ap, uint32_t *);
|
|
void **data = va_arg(ap, void **);
|
|
|
|
errcode =
|
|
p9pdu_readf(pdu, proto_version, "d", count);
|
|
if (!errcode) {
|
|
*count =
|
|
min_t(uint32_t, *count,
|
|
pdu->size - pdu->offset);
|
|
*data = &pdu->sdata[pdu->offset];
|
|
}
|
|
}
|
|
break;
|
|
case 'T':{
|
|
uint16_t *nwname = va_arg(ap, uint16_t *);
|
|
char ***wnames = va_arg(ap, char ***);
|
|
|
|
errcode = p9pdu_readf(pdu, proto_version,
|
|
"w", nwname);
|
|
if (!errcode) {
|
|
*wnames =
|
|
kmalloc(sizeof(char *) * *nwname,
|
|
GFP_NOFS);
|
|
if (!*wnames)
|
|
errcode = -ENOMEM;
|
|
}
|
|
|
|
if (!errcode) {
|
|
int i;
|
|
|
|
for (i = 0; i < *nwname; i++) {
|
|
errcode =
|
|
p9pdu_readf(pdu,
|
|
proto_version,
|
|
"s",
|
|
&(*wnames)[i]);
|
|
if (errcode)
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (errcode) {
|
|
if (*wnames) {
|
|
int i;
|
|
|
|
for (i = 0; i < *nwname; i++)
|
|
kfree((*wnames)[i]);
|
|
}
|
|
kfree(*wnames);
|
|
*wnames = NULL;
|
|
}
|
|
}
|
|
break;
|
|
case 'R':{
|
|
uint16_t *nwqid = va_arg(ap, uint16_t *);
|
|
struct p9_qid **wqids =
|
|
va_arg(ap, struct p9_qid **);
|
|
|
|
*wqids = NULL;
|
|
|
|
errcode =
|
|
p9pdu_readf(pdu, proto_version, "w", nwqid);
|
|
if (!errcode) {
|
|
*wqids =
|
|
kmalloc(*nwqid *
|
|
sizeof(struct p9_qid),
|
|
GFP_NOFS);
|
|
if (*wqids == NULL)
|
|
errcode = -ENOMEM;
|
|
}
|
|
|
|
if (!errcode) {
|
|
int i;
|
|
|
|
for (i = 0; i < *nwqid; i++) {
|
|
errcode =
|
|
p9pdu_readf(pdu,
|
|
proto_version,
|
|
"Q",
|
|
&(*wqids)[i]);
|
|
if (errcode)
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (errcode) {
|
|
kfree(*wqids);
|
|
*wqids = NULL;
|
|
}
|
|
}
|
|
break;
|
|
case 'A': {
|
|
struct p9_stat_dotl *stbuf =
|
|
va_arg(ap, struct p9_stat_dotl *);
|
|
|
|
memset(stbuf, 0, sizeof(struct p9_stat_dotl));
|
|
errcode =
|
|
p9pdu_readf(pdu, proto_version,
|
|
"qQdugqqqqqqqqqqqqqqq",
|
|
&stbuf->st_result_mask,
|
|
&stbuf->qid,
|
|
&stbuf->st_mode,
|
|
&stbuf->st_uid, &stbuf->st_gid,
|
|
&stbuf->st_nlink,
|
|
&stbuf->st_rdev, &stbuf->st_size,
|
|
&stbuf->st_blksize, &stbuf->st_blocks,
|
|
&stbuf->st_atime_sec,
|
|
&stbuf->st_atime_nsec,
|
|
&stbuf->st_mtime_sec,
|
|
&stbuf->st_mtime_nsec,
|
|
&stbuf->st_ctime_sec,
|
|
&stbuf->st_ctime_nsec,
|
|
&stbuf->st_btime_sec,
|
|
&stbuf->st_btime_nsec,
|
|
&stbuf->st_gen,
|
|
&stbuf->st_data_version);
|
|
}
|
|
break;
|
|
case '?':
|
|
if ((proto_version != p9_proto_2000u) &&
|
|
(proto_version != p9_proto_2000L))
|
|
return 0;
|
|
break;
|
|
default:
|
|
BUG();
|
|
break;
|
|
}
|
|
|
|
if (errcode)
|
|
break;
|
|
}
|
|
|
|
return errcode;
|
|
}
|
|
|
|
int
|
|
p9pdu_vwritef(struct p9_fcall *pdu, int proto_version, const char *fmt,
|
|
va_list ap)
|
|
{
|
|
const char *ptr;
|
|
int errcode = 0;
|
|
|
|
for (ptr = fmt; *ptr; ptr++) {
|
|
switch (*ptr) {
|
|
case 'b':{
|
|
int8_t val = va_arg(ap, int);
|
|
if (pdu_write(pdu, &val, sizeof(val)))
|
|
errcode = -EFAULT;
|
|
}
|
|
break;
|
|
case 'w':{
|
|
__le16 val = cpu_to_le16(va_arg(ap, int));
|
|
if (pdu_write(pdu, &val, sizeof(val)))
|
|
errcode = -EFAULT;
|
|
}
|
|
break;
|
|
case 'd':{
|
|
__le32 val = cpu_to_le32(va_arg(ap, int32_t));
|
|
if (pdu_write(pdu, &val, sizeof(val)))
|
|
errcode = -EFAULT;
|
|
}
|
|
break;
|
|
case 'q':{
|
|
__le64 val = cpu_to_le64(va_arg(ap, int64_t));
|
|
if (pdu_write(pdu, &val, sizeof(val)))
|
|
errcode = -EFAULT;
|
|
}
|
|
break;
|
|
case 's':{
|
|
const char *sptr = va_arg(ap, const char *);
|
|
uint16_t len = 0;
|
|
if (sptr)
|
|
len = min_t(size_t, strlen(sptr),
|
|
USHRT_MAX);
|
|
|
|
errcode = p9pdu_writef(pdu, proto_version,
|
|
"w", len);
|
|
if (!errcode && pdu_write(pdu, sptr, len))
|
|
errcode = -EFAULT;
|
|
}
|
|
break;
|
|
case 'u': {
|
|
kuid_t uid = va_arg(ap, kuid_t);
|
|
__le32 val = cpu_to_le32(
|
|
from_kuid(&init_user_ns, uid));
|
|
if (pdu_write(pdu, &val, sizeof(val)))
|
|
errcode = -EFAULT;
|
|
} break;
|
|
case 'g': {
|
|
kgid_t gid = va_arg(ap, kgid_t);
|
|
__le32 val = cpu_to_le32(
|
|
from_kgid(&init_user_ns, gid));
|
|
if (pdu_write(pdu, &val, sizeof(val)))
|
|
errcode = -EFAULT;
|
|
} break;
|
|
case 'Q':{
|
|
const struct p9_qid *qid =
|
|
va_arg(ap, const struct p9_qid *);
|
|
errcode =
|
|
p9pdu_writef(pdu, proto_version, "bdq",
|
|
qid->type, qid->version,
|
|
qid->path);
|
|
} break;
|
|
case 'S':{
|
|
const struct p9_wstat *stbuf =
|
|
va_arg(ap, const struct p9_wstat *);
|
|
errcode =
|
|
p9pdu_writef(pdu, proto_version,
|
|
"wwdQdddqssss?sugu",
|
|
stbuf->size, stbuf->type,
|
|
stbuf->dev, &stbuf->qid,
|
|
stbuf->mode, stbuf->atime,
|
|
stbuf->mtime, stbuf->length,
|
|
stbuf->name, stbuf->uid,
|
|
stbuf->gid, stbuf->muid,
|
|
stbuf->extension, stbuf->n_uid,
|
|
stbuf->n_gid, stbuf->n_muid);
|
|
} break;
|
|
case 'V':{
|
|
uint32_t count = va_arg(ap, uint32_t);
|
|
struct iov_iter *from =
|
|
va_arg(ap, struct iov_iter *);
|
|
errcode = p9pdu_writef(pdu, proto_version, "d",
|
|
count);
|
|
if (!errcode && pdu_write_u(pdu, from, count))
|
|
errcode = -EFAULT;
|
|
}
|
|
break;
|
|
case 'T':{
|
|
uint16_t nwname = va_arg(ap, int);
|
|
const char **wnames = va_arg(ap, const char **);
|
|
|
|
errcode = p9pdu_writef(pdu, proto_version, "w",
|
|
nwname);
|
|
if (!errcode) {
|
|
int i;
|
|
|
|
for (i = 0; i < nwname; i++) {
|
|
errcode =
|
|
p9pdu_writef(pdu,
|
|
proto_version,
|
|
"s",
|
|
wnames[i]);
|
|
if (errcode)
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
break;
|
|
case 'R':{
|
|
uint16_t nwqid = va_arg(ap, int);
|
|
struct p9_qid *wqids =
|
|
va_arg(ap, struct p9_qid *);
|
|
|
|
errcode = p9pdu_writef(pdu, proto_version, "w",
|
|
nwqid);
|
|
if (!errcode) {
|
|
int i;
|
|
|
|
for (i = 0; i < nwqid; i++) {
|
|
errcode =
|
|
p9pdu_writef(pdu,
|
|
proto_version,
|
|
"Q",
|
|
&wqids[i]);
|
|
if (errcode)
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
break;
|
|
case 'I':{
|
|
struct p9_iattr_dotl *p9attr = va_arg(ap,
|
|
struct p9_iattr_dotl *);
|
|
|
|
errcode = p9pdu_writef(pdu, proto_version,
|
|
"ddugqqqqq",
|
|
p9attr->valid,
|
|
p9attr->mode,
|
|
p9attr->uid,
|
|
p9attr->gid,
|
|
p9attr->size,
|
|
p9attr->atime_sec,
|
|
p9attr->atime_nsec,
|
|
p9attr->mtime_sec,
|
|
p9attr->mtime_nsec);
|
|
}
|
|
break;
|
|
case '?':
|
|
if ((proto_version != p9_proto_2000u) &&
|
|
(proto_version != p9_proto_2000L))
|
|
return 0;
|
|
break;
|
|
default:
|
|
BUG();
|
|
break;
|
|
}
|
|
|
|
if (errcode)
|
|
break;
|
|
}
|
|
|
|
return errcode;
|
|
}
|
|
|
|
int p9pdu_readf(struct p9_fcall *pdu, int proto_version, const char *fmt, ...)
|
|
{
|
|
va_list ap;
|
|
int ret;
|
|
|
|
va_start(ap, fmt);
|
|
ret = p9pdu_vreadf(pdu, proto_version, fmt, ap);
|
|
va_end(ap);
|
|
|
|
return ret;
|
|
}
|
|
|
|
static int
|
|
p9pdu_writef(struct p9_fcall *pdu, int proto_version, const char *fmt, ...)
|
|
{
|
|
va_list ap;
|
|
int ret;
|
|
|
|
va_start(ap, fmt);
|
|
ret = p9pdu_vwritef(pdu, proto_version, fmt, ap);
|
|
va_end(ap);
|
|
|
|
return ret;
|
|
}
|
|
|
|
int p9stat_read(struct p9_client *clnt, char *buf, int len, struct p9_wstat *st)
|
|
{
|
|
struct p9_fcall fake_pdu;
|
|
int ret;
|
|
|
|
fake_pdu.size = len;
|
|
fake_pdu.capacity = len;
|
|
fake_pdu.sdata = buf;
|
|
fake_pdu.offset = 0;
|
|
|
|
ret = p9pdu_readf(&fake_pdu, clnt->proto_version, "S", st);
|
|
if (ret) {
|
|
p9_debug(P9_DEBUG_9P, "<<< p9stat_read failed: %d\n", ret);
|
|
trace_9p_protocol_dump(clnt, &fake_pdu);
|
|
return ret;
|
|
}
|
|
|
|
return fake_pdu.offset;
|
|
}
|
|
EXPORT_SYMBOL(p9stat_read);
|
|
|
|
int p9pdu_prepare(struct p9_fcall *pdu, int16_t tag, int8_t type)
|
|
{
|
|
pdu->id = type;
|
|
return p9pdu_writef(pdu, 0, "dbw", 0, type, tag);
|
|
}
|
|
|
|
int p9pdu_finalize(struct p9_client *clnt, struct p9_fcall *pdu)
|
|
{
|
|
int size = pdu->size;
|
|
int err;
|
|
|
|
pdu->size = 0;
|
|
err = p9pdu_writef(pdu, 0, "d", size);
|
|
pdu->size = size;
|
|
|
|
trace_9p_protocol_dump(clnt, pdu);
|
|
p9_debug(P9_DEBUG_9P, ">>> size=%d type: %d tag: %d\n",
|
|
pdu->size, pdu->id, pdu->tag);
|
|
|
|
return err;
|
|
}
|
|
|
|
void p9pdu_reset(struct p9_fcall *pdu)
|
|
{
|
|
pdu->offset = 0;
|
|
pdu->size = 0;
|
|
}
|
|
|
|
int p9dirent_read(struct p9_client *clnt, char *buf, int len,
|
|
struct p9_dirent *dirent)
|
|
{
|
|
struct p9_fcall fake_pdu;
|
|
int ret;
|
|
char *nameptr;
|
|
|
|
fake_pdu.size = len;
|
|
fake_pdu.capacity = len;
|
|
fake_pdu.sdata = buf;
|
|
fake_pdu.offset = 0;
|
|
|
|
ret = p9pdu_readf(&fake_pdu, clnt->proto_version, "Qqbs", &dirent->qid,
|
|
&dirent->d_off, &dirent->d_type, &nameptr);
|
|
if (ret) {
|
|
p9_debug(P9_DEBUG_9P, "<<< p9dirent_read failed: %d\n", ret);
|
|
trace_9p_protocol_dump(clnt, &fake_pdu);
|
|
return ret;
|
|
}
|
|
|
|
ret = strscpy(dirent->d_name, nameptr, sizeof(dirent->d_name));
|
|
if (ret < 0) {
|
|
p9_debug(P9_DEBUG_ERROR,
|
|
"On the wire dirent name too long: %s\n",
|
|
nameptr);
|
|
kfree(nameptr);
|
|
return ret;
|
|
}
|
|
kfree(nameptr);
|
|
|
|
return fake_pdu.offset;
|
|
}
|
|
EXPORT_SYMBOL(p9dirent_read);
|