mirror of
https://github.com/libguestfs/libguestfs.git
synced 2026-03-21 22:53:37 +00:00
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.
This commit is contained in:
2
TODO
2
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
|
||||
|
||||
@@ -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 \
|
||||
|
||||
69
daemon/mknod.c
Normal file
69
daemon/mknod.c
Normal file
@@ -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 <config.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#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);
|
||||
}
|
||||
46
daemon/umask.c
Normal file
46
daemon/umask.c
Normal file
@@ -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 <config.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#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;
|
||||
}
|
||||
@@ -2676,6 +2676,76 @@ Create a swap partition on C<device> with label C<label>.");
|
||||
"\
|
||||
Create a swap partition on C<device> with UUID C<uuid>.");
|
||||
|
||||
("mknod", (RErr, [Int "mode"; Int "devmajor"; Int "devminor"; String "path"]), 133, [],
|
||||
[InitBasicFS, Always, TestOutputStruct (
|
||||
[["mknod"; "0o10777"; "0"; "0"; "/node"];
|
||||
(* NB: default umask 022 means 0777 -> 0755 in these tests *)
|
||||
["stat"; "/node"]], [CompareWithInt ("mode", 0o10755)]);
|
||||
InitBasicFS, Always, TestOutputStruct (
|
||||
[["mknod"; "0o60777"; "66"; "99"; "/node"];
|
||||
["stat"; "/node"]], [CompareWithInt ("mode", 0o60755)])],
|
||||
"make block, character or FIFO devices",
|
||||
"\
|
||||
This call creates block or character special devices, or
|
||||
named pipes (FIFOs).
|
||||
|
||||
The C<mode> parameter should be the mode, using the standard
|
||||
constants. C<devmajor> and C<devminor> are the
|
||||
device major and minor numbers, only used when creating block
|
||||
and character special devices.");
|
||||
|
||||
("mkfifo", (RErr, [Int "mode"; String "path"]), 134, [],
|
||||
[InitBasicFS, Always, TestOutputStruct (
|
||||
[["mkfifo"; "0o777"; "/node"];
|
||||
["stat"; "/node"]], [CompareWithInt ("mode", 0o10755)])],
|
||||
"make FIFO (named pipe)",
|
||||
"\
|
||||
This call creates a FIFO (named pipe) called C<path> with
|
||||
mode C<mode>. It is just a convenient wrapper around
|
||||
C<guestfs_mknod>.");
|
||||
|
||||
("mknod_b", (RErr, [Int "mode"; Int "devmajor"; Int "devminor"; String "path"]), 135, [],
|
||||
[InitBasicFS, Always, TestOutputStruct (
|
||||
[["mknod_b"; "0o777"; "99"; "66"; "/node"];
|
||||
["stat"; "/node"]], [CompareWithInt ("mode", 0o60755)])],
|
||||
"make block device node",
|
||||
"\
|
||||
This call creates a block device node called C<path> with
|
||||
mode C<mode> and device major/minor C<devmajor> and C<devminor>.
|
||||
It is just a convenient wrapper around C<guestfs_mknod>.");
|
||||
|
||||
("mknod_c", (RErr, [Int "mode"; Int "devmajor"; Int "devminor"; String "path"]), 136, [],
|
||||
[InitBasicFS, Always, TestOutputStruct (
|
||||
[["mknod_c"; "0o777"; "99"; "66"; "/node"];
|
||||
["stat"; "/node"]], [CompareWithInt ("mode", 0o20755)])],
|
||||
"make char device node",
|
||||
"\
|
||||
This call creates a char device node called C<path> with
|
||||
mode C<mode> and device major/minor C<devmajor> and C<devminor>.
|
||||
It is just a convenient wrapper around C<guestfs_mknod>.");
|
||||
|
||||
("umask", (RInt "oldmask", [Int "mask"]), 137, [],
|
||||
[], (* XXX umask is one of those stateful things that we should
|
||||
* reset between each test.
|
||||
*)
|
||||
"set file mode creation mask (umask)",
|
||||
"\
|
||||
This function sets the mask used for creating new files and
|
||||
device nodes to C<mask & 0777>.
|
||||
|
||||
Typical umask values would be C<022> which creates new files
|
||||
with permissions like \"-rw-r--r--\" or \"-rwxr-xr-x\", and
|
||||
C<002> which creates new files with permissions like
|
||||
\"-rw-rw-r--\" or \"-rwxrwxr-x\".
|
||||
|
||||
The default umask is C<022>. This is important because it
|
||||
means that directories and device nodes will be created with
|
||||
C<0644> or C<0755> mode even if you specify C<0777>.
|
||||
|
||||
See also L<umask(2)>, C<guestfs_mknod>, C<guestfs_mkdir>.
|
||||
|
||||
This call returns the previous umask.");
|
||||
|
||||
]
|
||||
|
||||
let all_functions = non_daemon_functions @ daemon_functions
|
||||
|
||||
Reference in New Issue
Block a user