From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:44726) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Qa1f2-00070q-Fq for qemu-devel@nongnu.org; Fri, 24 Jun 2011 04:22:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Qa1ey-0002TO-Ge for qemu-devel@nongnu.org; Fri, 24 Jun 2011 04:22:44 -0400 Received: from e28smtp04.in.ibm.com ([122.248.162.4]:43500) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Qa1ex-0002Qt-2S for qemu-devel@nongnu.org; Fri, 24 Jun 2011 04:22:40 -0400 Received: from d28relay05.in.ibm.com (d28relay05.in.ibm.com [9.184.220.62]) by e28smtp04.in.ibm.com (8.14.4/8.13.1) with ESMTP id p5O8MUHJ020276 for ; Fri, 24 Jun 2011 13:52:30 +0530 Received: from d28av01.in.ibm.com (d28av01.in.ibm.com [9.184.220.63]) by d28relay05.in.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id p5O8MTQr299042 for ; Fri, 24 Jun 2011 13:52:29 +0530 Received: from d28av01.in.ibm.com (loopback [127.0.0.1]) by d28av01.in.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id p5O8MTgd004295 for ; Fri, 24 Jun 2011 13:52:29 +0530 From: "M. Mohan Kumar" Date: Fri, 24 Jun 2011 13:52:24 +0530 Message-Id: <1308903744-2870-16-git-send-email-mohan@in.ibm.com> In-Reply-To: <1308903744-2870-1-git-send-email-mohan@in.ibm.com> References: <1308903744-2870-1-git-send-email-mohan@in.ibm.com> Subject: [Qemu-devel] [V11 15/15] virtio-9p: Chroot environment for other functions List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: "M. Mohan Kumar" From: "M. Mohan Kumar" 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 e865cc8..5847d43 100644 --- a/hw/9pfs/virtio-9p-local.c +++ b/hw/9pfs/virtio-9p-local.c @@ -608,7 +608,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, @@ -648,8 +666,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.5.4