Revision c1568af5 hw/virtio-9p.c
b/hw/virtio-9p.c | ||
---|---|---|
187 | 187 |
return s->ops->fstat(&s->ctx, fd, stbuf); |
188 | 188 |
} |
189 | 189 |
|
190 |
static int v9fs_do_open2(V9fsState *s, V9fsCreateState *vs) |
|
190 |
static int v9fs_do_open2(V9fsState *s, char *fullname, uid_t uid, gid_t gid, |
|
191 |
int flags, int mode) |
|
191 | 192 |
{ |
192 | 193 |
FsCred cred; |
193 |
int flags; |
|
194 | 194 |
|
195 | 195 |
cred_init(&cred); |
196 |
cred.fc_uid = vs->fidp->uid; |
|
197 |
cred.fc_mode = vs->perm & 0777; |
|
198 |
flags = omode_to_uflags(vs->mode) | O_CREAT; |
|
196 |
cred.fc_uid = uid; |
|
197 |
cred.fc_gid = gid; |
|
198 |
cred.fc_mode = mode & 07777; |
|
199 |
flags = flags; |
|
199 | 200 |
|
200 |
return s->ops->open2(&s->ctx, vs->fullname.data, flags, &cred);
|
|
201 |
return s->ops->open2(&s->ctx, fullname, flags, &cred);
|
|
201 | 202 |
} |
202 | 203 |
|
203 | 204 |
static int v9fs_do_symlink(V9fsState *s, V9fsFidState *fidp, |
... | ... | |
1671 | 1672 |
qemu_free(vs); |
1672 | 1673 |
} |
1673 | 1674 |
|
1675 |
static void v9fs_post_lcreate(V9fsState *s, V9fsLcreateState *vs, int err) |
|
1676 |
{ |
|
1677 |
if (err == 0) { |
|
1678 |
v9fs_string_copy(&vs->fidp->path, &vs->fullname); |
|
1679 |
stat_to_qid(&vs->stbuf, &vs->qid); |
|
1680 |
vs->offset += pdu_marshal(vs->pdu, vs->offset, "Qd", &vs->qid, |
|
1681 |
&vs->iounit); |
|
1682 |
err = vs->offset; |
|
1683 |
} else { |
|
1684 |
err = -errno; |
|
1685 |
} |
|
1686 |
|
|
1687 |
complete_pdu(s, vs->pdu, err); |
|
1688 |
v9fs_string_free(&vs->name); |
|
1689 |
v9fs_string_free(&vs->fullname); |
|
1690 |
qemu_free(vs); |
|
1691 |
} |
|
1692 |
|
|
1693 |
static void v9fs_lcreate_post_get_iounit(V9fsState *s, V9fsLcreateState *vs, |
|
1694 |
int err) |
|
1695 |
{ |
|
1696 |
if (err) { |
|
1697 |
err = -errno; |
|
1698 |
goto out; |
|
1699 |
} |
|
1700 |
err = v9fs_do_lstat(s, &vs->fullname, &vs->stbuf); |
|
1701 |
|
|
1702 |
out: |
|
1703 |
v9fs_post_lcreate(s, vs, err); |
|
1704 |
} |
|
1705 |
|
|
1706 |
static void v9fs_lcreate_post_do_open2(V9fsState *s, V9fsLcreateState *vs, |
|
1707 |
int err) |
|
1708 |
{ |
|
1709 |
if (vs->fidp->fd == -1) { |
|
1710 |
err = -errno; |
|
1711 |
goto out; |
|
1712 |
} |
|
1713 |
vs->iounit = get_iounit(s, &vs->fullname); |
|
1714 |
v9fs_lcreate_post_get_iounit(s, vs, err); |
|
1715 |
return; |
|
1716 |
|
|
1717 |
out: |
|
1718 |
v9fs_post_lcreate(s, vs, err); |
|
1719 |
} |
|
1720 |
|
|
1721 |
static void v9fs_lcreate(V9fsState *s, V9fsPDU *pdu) |
|
1722 |
{ |
|
1723 |
int32_t dfid, flags, mode; |
|
1724 |
gid_t gid; |
|
1725 |
V9fsLcreateState *vs; |
|
1726 |
ssize_t err = 0; |
|
1727 |
|
|
1728 |
vs = qemu_malloc(sizeof(*vs)); |
|
1729 |
vs->pdu = pdu; |
|
1730 |
vs->offset = 7; |
|
1731 |
|
|
1732 |
v9fs_string_init(&vs->fullname); |
|
1733 |
|
|
1734 |
pdu_unmarshal(vs->pdu, vs->offset, "dsddd", &dfid, &vs->name, &flags, |
|
1735 |
&mode, &gid); |
|
1736 |
|
|
1737 |
vs->fidp = lookup_fid(s, dfid); |
|
1738 |
if (vs->fidp == NULL) { |
|
1739 |
err = -ENOENT; |
|
1740 |
goto out; |
|
1741 |
} |
|
1742 |
|
|
1743 |
v9fs_string_sprintf(&vs->fullname, "%s/%s", vs->fidp->path.data, |
|
1744 |
vs->name.data); |
|
1745 |
|
|
1746 |
vs->fidp->fd = v9fs_do_open2(s, vs->fullname.data, vs->fidp->uid, |
|
1747 |
gid, flags, mode); |
|
1748 |
v9fs_lcreate_post_do_open2(s, vs, err); |
|
1749 |
return; |
|
1750 |
|
|
1751 |
out: |
|
1752 |
complete_pdu(s, vs->pdu, err); |
|
1753 |
v9fs_string_free(&vs->name); |
|
1754 |
qemu_free(vs); |
|
1755 |
} |
|
1756 |
|
|
1674 | 1757 |
static void v9fs_clunk(V9fsState *s, V9fsPDU *pdu) |
1675 | 1758 |
{ |
1676 | 1759 |
int32_t fid; |
... | ... | |
2258 | 2341 |
err = v9fs_do_mknod(s, vs, S_IFSOCK | (vs->perm & 0777), 0); |
2259 | 2342 |
v9fs_post_create(s, vs, err); |
2260 | 2343 |
} else { |
2261 |
vs->fidp->fd = v9fs_do_open2(s, vs); |
|
2344 |
vs->fidp->fd = v9fs_do_open2(s, vs->fullname.data, vs->fidp->uid, |
|
2345 |
-1, omode_to_uflags(vs->mode)|O_CREAT, vs->perm); |
|
2346 |
|
|
2262 | 2347 |
v9fs_create_post_open2(s, vs, err); |
2263 | 2348 |
} |
2264 | 2349 |
|
... | ... | |
2785 | 2870 |
[P9_TLINK] = v9fs_link, |
2786 | 2871 |
[P9_TSYMLINK] = v9fs_symlink, |
2787 | 2872 |
[P9_TCREATE] = v9fs_create, |
2873 |
[P9_TLCREATE] = v9fs_lcreate, |
|
2788 | 2874 |
[P9_TWRITE] = v9fs_write, |
2789 | 2875 |
[P9_TWSTAT] = v9fs_wstat, |
2790 | 2876 |
[P9_TREMOVE] = v9fs_remove, |
Also available in: Unified diff