From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:54693) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1R0bsj-0005bZ-JA for qemu-devel@nongnu.org; Mon, 05 Sep 2011 12:18:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1R0bsi-0005E8-Eh for qemu-devel@nongnu.org; Mon, 05 Sep 2011 12:18:45 -0400 Received: from e28smtp05.in.ibm.com ([122.248.162.5]:38599) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1R0bsh-0005Df-R9 for qemu-devel@nongnu.org; Mon, 05 Sep 2011 12:18:44 -0400 Received: from d28relay05.in.ibm.com (d28relay05.in.ibm.com [9.184.220.62]) by e28smtp05.in.ibm.com (8.14.4/8.13.1) with ESMTP id p85GIf2U001961 for ; Mon, 5 Sep 2011 21:48:41 +0530 Received: from d28av05.in.ibm.com (d28av05.in.ibm.com [9.184.220.67]) by d28relay05.in.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id p85GIf0V3342358 for ; Mon, 5 Sep 2011 21:48:41 +0530 Received: from d28av05.in.ibm.com (loopback [127.0.0.1]) by d28av05.in.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id p85GIeab029257 for ; Tue, 6 Sep 2011 02:18:40 +1000 From: "M. Mohan Kumar" Date: Mon, 5 Sep 2011 21:48:36 +0530 Message-Id: <1315239516-4451-16-git-send-email-mohan@in.ibm.com> In-Reply-To: <1315239516-4451-1-git-send-email-mohan@in.ibm.com> References: <1315239516-4451-1-git-send-email-mohan@in.ibm.com> Subject: [Qemu-devel] [PATCH V12 15/15] hw/9pfs: Chroot environment for other functions List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org, Anthony Liguori , Stefan Hajnoczi Add chroot functionality for system calls that can operate on a file using relative directory file descriptor. Signed-off-by: M. Mohan Kumar --- hw/9pfs/virtio-9p-local.c | 41 +++++++++++++++++++++++++++++++++++++++-- 1 files changed, 39 insertions(+), 2 deletions(-) diff --git a/hw/9pfs/virtio-9p-local.c b/hw/9pfs/virtio-9p-local.c index ffef8a2..c7cceb5 100644 --- a/hw/9pfs/virtio-9p-local.c +++ b/hw/9pfs/virtio-9p-local.c @@ -628,7 +628,25 @@ static int local_truncate(FsContext *ctx, V9fsPath *fs_path, off_t size) char buffer[PATH_MAX]; char *path = fs_path->data; - return truncate(rpath(ctx, path, buffer), size); + if (ctx->fs_sm == SM_PASSTHROUGH) { + int fd, retval, serrno; + fd = passthrough_request(ctx, NULL, path, O_RDWR, NULL, T_OPEN); + if (fd < 0) { + errno = -fd; + return -1; + } + retval = ftruncate(fd, size); + if (retval < 0) { + serrno = errno; + } + close(fd); + if (retval < 0) { + errno = serrno; + } + return retval; + } else { + return truncate(rpath(ctx, path, buffer), size); + } } static int local_rename(FsContext *ctx, const char *oldpath, @@ -668,8 +686,27 @@ static int local_utimensat(FsContext *s, V9fsPath *fs_path, char buffer[PATH_MAX]; char *path = fs_path->data; - return qemu_utimensat(AT_FDCWD, rpath(s, path, buffer), buf, + if (s->fs_sm == SM_PASSTHROUGH) { + int fd, retval, serrno = 0; + fd = passthrough_request(s, NULL, path, + O_RDONLY | O_NONBLOCK | O_NOFOLLOW, NULL, T_OPEN); + if (fd < 0) { + errno = -fd; + return -1; + } + retval = futimens(fd, buf); + if (retval < 0) { + serrno = errno; + } + close(fd); + if (retval < 0) { + errno = serrno; + } + return retval; + } else { + return qemu_utimensat(AT_FDCWD, rpath(s, path, buffer), buf, AT_SYMLINK_NOFOLLOW); + } } static int local_remove(FsContext *ctx, const char *path) -- 1.7.6