From 99bd425a0a8fb02c27e0c22b32dafa804773a7b1 Mon Sep 17 00:00:00 2001 From: Richard Jones Date: Fri, 3 Apr 2009 22:25:34 +0100 Subject: Implemented 'mount' and 'touch' commands. --- daemon/file.c | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 daemon/file.c (limited to 'daemon/file.c') diff --git a/daemon/file.c b/daemon/file.c new file mode 100644 index 00000000..1e633d85 --- /dev/null +++ b/daemon/file.c @@ -0,0 +1,63 @@ +/* libguestfs - the guestfsd daemon + * Copyright (C) 2009 Red Hat Inc. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * 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 the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +#include + +#define _GNU_SOURCE /* for futimens(2) */ + +#include +#include +#include +#include +#include +#include + +#include "daemon.h" +#include "actions.h" + +int +do_touch (const char *path) +{ + int fd; + + NEED_ROOT; + + if (path[0] != '/') { + reply_with_error ("touch: path must start with a / character"); + return -1; + } + + CHROOT_IN; + fd = open (path, O_WRONLY | O_CREAT | O_NOCTTY | O_NONBLOCK, 0666); + CHROOT_OUT; + + if (fd == -1) { + reply_with_perror ("open: %s", path); + close (fd); + return -1; + } + + if (futimens (fd, NULL) == -1) { + reply_with_perror ("futimens: %s", path); + close (fd); + return -1; + } + + close (fd); + return 0; +} -- cgit