From f850e1f065fb04df7cc87a921ab3c658741cc393 Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" Date: Tue, 30 Jun 2009 13:08:34 +0100 Subject: [PATCH] New commands: mknod, mkfifo, mknod_b, mknod_c and umask. These commands are used to create block and char device nodes or FIFOs (named pipes) in the filesystem. The umask command is required also because the permissions used by mknod are masked by the umask. Also document and guarantee that the umask starts as 022. --- TODO | 2 -- daemon/Makefile.am | 2 ++ daemon/mknod.c | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++++ daemon/umask.c | 46 +++++++++++++++++++++++++++++++++++ src/generator.ml | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 187 insertions(+), 2 deletions(-) create mode 100644 daemon/mknod.c create mode 100644 daemon/umask.c diff --git a/TODO b/TODO index bc00946..72e8cd4 100644 --- a/TODO +++ b/TODO @@ -121,10 +121,8 @@ Extra commands / functionality: grep (do it locally using pipe?) dd (?) ln / ln -s - mknod readlink utime / utimes / futimes / futimens / l.. - mkfifo more mk*temp calls readdir / readdir-and-stat some sort of alloc/fallocate/posix_fallocate call to create empty space diff --git a/daemon/Makefile.am b/daemon/Makefile.am index d69f899..8884c6b 100644 --- a/daemon/Makefile.am +++ b/daemon/Makefile.am @@ -46,6 +46,7 @@ guestfsd_SOURCES = \ initrd.c \ ls.c \ lvm.c \ + mknod.c \ mount.c \ ntfs.c \ pingdaemon.c \ @@ -59,6 +60,7 @@ guestfsd_SOURCES = \ swap.c \ sync.c \ tar.c \ + umask.c \ upload.c \ wc.c \ zero.c \ diff --git a/daemon/mknod.c b/daemon/mknod.c new file mode 100644 index 0000000..5af791f --- /dev/null +++ b/daemon/mknod.c @@ -0,0 +1,69 @@ +/* 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 + +#include +#include +#include +#include +#include +#include +#include + +#include "../src/guestfs_protocol.h" +#include "daemon.h" +#include "actions.h" + +int +do_mknod (int mode, int devmajor, int devminor, char *path) +{ + int r; + + NEED_ROOT (-1); + ABS_PATH (path, -1); + + CHROOT_IN; + r = mknod (path, mode, makedev (devmajor, devminor)); + CHROOT_OUT; + + if (r == -1) { + reply_with_perror ("mknod: %s", path); + return -1; + } + + return 0; +} + +int +do_mkfifo (int mode, char *path) +{ + return do_mknod (mode | S_IFIFO, 0, 0, path); +} + +int +do_mknod_b (int mode, int devmajor, int devminor, char *path) +{ + return do_mknod (mode | S_IFBLK, devmajor, devminor, path); +} + +int +do_mknod_c (int mode, int devmajor, int devminor, char *path) +{ + return do_mknod (mode | S_IFCHR, devmajor, devminor, path); +} diff --git a/daemon/umask.c b/daemon/umask.c new file mode 100644 index 0000000..ad8573d --- /dev/null +++ b/daemon/umask.c @@ -0,0 +1,46 @@ +/* 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 + +#include +#include +#include +#include +#include +#include +#include + +#include "../src/guestfs_protocol.h" +#include "daemon.h" +#include "actions.h" + +int +do_umask (int mask) +{ + int r; + + r = umask (mask); + + if (r == -1) { + reply_with_perror ("umask"); + return -1; + } + + return r; +} diff --git a/src/generator.ml b/src/generator.ml index 1a844ee..960973d 100755 --- a/src/generator.ml +++ b/src/generator.ml @@ -2676,6 +2676,76 @@ Create a swap partition on C with label C