diff options
-rw-r--r-- | daemon/Makefile.am | 1 | ||||
-rw-r--r-- | daemon/devsparts.c | 17 | ||||
-rw-r--r-- | daemon/ext2.c | 149 | ||||
-rw-r--r-- | daemon/mkfs.c | 68 | ||||
-rw-r--r-- | po/POTFILES.in | 1 | ||||
-rw-r--r-- | src/MAX_PROC_NR | 2 | ||||
-rwxr-xr-x | src/generator.ml | 84 |
7 files changed, 304 insertions, 18 deletions
diff --git a/daemon/Makefile.am b/daemon/Makefile.am index 94069440..e6af0feb 100644 --- a/daemon/Makefile.am +++ b/daemon/Makefile.am @@ -52,6 +52,7 @@ guestfsd_SOURCES = \ link.c \ ls.c \ lvm.c \ + mkfs.c \ mknod.c \ mount.c \ names.c \ diff --git a/daemon/devsparts.c b/daemon/devsparts.c index b4ea5788..76852cca 100644 --- a/daemon/devsparts.c +++ b/daemon/devsparts.c @@ -186,20 +186,3 @@ do_list_partitions (void) { return foreach_block_device(add_partitions); } - -int -do_mkfs (const char *fstype, const char *device) -{ - char *err; - int r; - - r = command (NULL, &err, "/sbin/mkfs", "-t", fstype, device, NULL); - if (r == -1) { - reply_with_error ("mkfs: %s", err); - free (err); - return -1; - } - - free (err); - return 0; -} diff --git a/daemon/ext2.c b/daemon/ext2.c index f181b8d7..2603ed06 100644 --- a/daemon/ext2.c +++ b/daemon/ext2.c @@ -266,3 +266,152 @@ do_e2fsck_f (const char *device) free (err); return 0; } + +int +do_mke2journal (int blocksize, const char *device) +{ + char *err; + int r; + + char blocksize_s[32]; + snprintf (blocksize_s, sizeof blocksize_s, "%d", blocksize); + + r = command (NULL, &err, + "/sbin/mke2fs", "-O", "journal_dev", "-b", blocksize_s, + device, NULL); + if (r == -1) { + reply_with_error ("mke2journal: %s", err); + free (err); + return -1; + } + + free (err); + return 0; +} + +int +do_mke2journal_L (int blocksize, const char *label, const char *device) +{ + char *err; + int r; + + char blocksize_s[32]; + snprintf (blocksize_s, sizeof blocksize_s, "%d", blocksize); + + r = command (NULL, &err, + "/sbin/mke2fs", "-O", "journal_dev", "-b", blocksize_s, + "-L", label, + device, NULL); + if (r == -1) { + reply_with_error ("mke2journal_L: %s", err); + free (err); + return -1; + } + + free (err); + return 0; +} + +int +do_mke2journal_U (int blocksize, const char *uuid, const char *device) +{ + char *err; + int r; + + char blocksize_s[32]; + snprintf (blocksize_s, sizeof blocksize_s, "%d", blocksize); + + r = command (NULL, &err, + "/sbin/mke2fs", "-O", "journal_dev", "-b", blocksize_s, + "-U", uuid, + device, NULL); + if (r == -1) { + reply_with_error ("mke2journal_U: %s", err); + free (err); + return -1; + } + + free (err); + return 0; +} + +int +do_mke2fs_J (const char *fstype, int blocksize, const char *device, + const char *journal) +{ + char *err; + int r; + + char blocksize_s[32]; + snprintf (blocksize_s, sizeof blocksize_s, "%d", blocksize); + + int len = strlen (journal); + char jdev[len+32]; + snprintf (jdev, len+32, "device=%s", journal); + + r = command (NULL, &err, + "/sbin/mke2fs", "-t", fstype, "-J", jdev, "-b", blocksize_s, + device, NULL); + if (r == -1) { + reply_with_error ("mke2fs_J: %s", err); + free (err); + return -1; + } + + free (err); + return 0; +} + +int +do_mke2fs_JL (const char *fstype, int blocksize, const char *device, + const char *label) +{ + char *err; + int r; + + char blocksize_s[32]; + snprintf (blocksize_s, sizeof blocksize_s, "%d", blocksize); + + int len = strlen (label); + char jdev[len+32]; + snprintf (jdev, len+32, "device=LABEL=%s", label); + + r = command (NULL, &err, + "/sbin/mke2fs", "-t", fstype, "-J", jdev, "-b", blocksize_s, + device, NULL); + if (r == -1) { + reply_with_error ("mke2fs_JL: %s", err); + free (err); + return -1; + } + + free (err); + return 0; +} + +int +do_mke2fs_JU (const char *fstype, int blocksize, const char *device, + const char *uuid) +{ + char *err; + int r; + + char blocksize_s[32]; + snprintf (blocksize_s, sizeof blocksize_s, "%d", blocksize); + + int len = strlen (uuid); + char jdev[len+32]; + snprintf (jdev, len+32, "device=UUID=%s", uuid); + + r = command (NULL, &err, + "/sbin/mke2fs", "-t", fstype, "-J", jdev, "-b", blocksize_s, + device, NULL); + if (r == -1) { + reply_with_error ("mke2fs_JU: %s", err); + free (err); + return -1; + } + + free (err); + return 0; +} diff --git a/daemon/mkfs.c b/daemon/mkfs.c new file mode 100644 index 00000000..73fd860e --- /dev/null +++ b/daemon/mkfs.c @@ -0,0 +1,68 @@ +/* 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 <dirent.h> +#include <sys/stat.h> + +#include "daemon.h" +#include "actions.h" + +int +do_mkfs (const char *fstype, const char *device) +{ + char *err; + int r; + + r = command (NULL, &err, "/sbin/mkfs", "-t", fstype, device, NULL); + if (r == -1) { + reply_with_error ("mkfs: %s", err); + free (err); + return -1; + } + + free (err); + return 0; +} + +int +do_mkfs_b (const char *fstype, int blocksize, const char *device) +{ + char *err; + int r; + + char blocksize_s[32]; + snprintf (blocksize_s, sizeof blocksize_s, "%d", blocksize); + + r = command (NULL, &err, + "/sbin/mkfs", "-t", fstype, "-b", blocksize_s, device, NULL); + if (r == -1) { + reply_with_error ("mkfs_b: %s", err); + free (err); + return -1; + } + + free (err); + return 0; +} diff --git a/po/POTFILES.in b/po/POTFILES.in index 79a2856d..33bf6e67 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -28,6 +28,7 @@ daemon/inotify.c daemon/link.c daemon/ls.c daemon/lvm.c +daemon/mkfs.c daemon/mknod.c daemon/mount.c daemon/names.c diff --git a/src/MAX_PROC_NR b/src/MAX_PROC_NR index bc3d5444..2455a46a 100644 --- a/src/MAX_PROC_NR +++ b/src/MAX_PROC_NR @@ -1 +1 @@ -186 +193 diff --git a/src/generator.ml b/src/generator.ml index 51c6704b..ef7d3d5f 100755 --- a/src/generator.ml +++ b/src/generator.ml @@ -3475,6 +3475,90 @@ This gets the SELinux security context of the daemon. See the documentation about SELINUX in L<guestfs(3)>, and C<guestfs_setcon>"); + ("mkfs_b", (RErr, [String "fstype"; Int "blocksize"; Device "device"]), 187, [], + [InitEmpty, Always, TestOutput ( + [["sfdiskM"; "/dev/sda"; ","]; + ["mkfs_b"; "ext2"; "4096"; "/dev/sda1"]; + ["mount"; "/dev/sda1"; "/"]; + ["write_file"; "/new"; "new file contents"; "0"]; + ["cat"; "/new"]], "new file contents")], + "make a filesystem with block size", + "\ +This call is similar to C<guestfs_mkfs>, but it allows you to +control the block size of the resulting filesystem. Supported +block sizes depend on the filesystem type, but typically they +are C<1024>, C<2048> or C<4096> only."); + + ("mke2journal", (RErr, [Int "blocksize"; Device "device"]), 188, [], + [InitEmpty, Always, TestOutput ( + [["sfdiskM"; "/dev/sda"; ",100 ,"]; + ["mke2journal"; "4096"; "/dev/sda1"]; + ["mke2fs_J"; "ext2"; "4096"; "/dev/sda2"; "/dev/sda1"]; + ["mount"; "/dev/sda2"; "/"]; + ["write_file"; "/new"; "new file contents"; "0"]; + ["cat"; "/new"]], "new file contents")], + "make ext2/3/4 external journal", + "\ +This creates an ext2 external journal on C<device>. It is equivalent +to the command: + + mke2fs -O journal_dev -b blocksize device"); + + ("mke2journal_L", (RErr, [Int "blocksize"; String "label"; Device "device"]), 189, [], + [InitEmpty, Always, TestOutput ( + [["sfdiskM"; "/dev/sda"; ",100 ,"]; + ["mke2journal_L"; "4096"; "JOURNAL"; "/dev/sda1"]; + ["mke2fs_JL"; "ext2"; "4096"; "/dev/sda2"; "JOURNAL"]; + ["mount"; "/dev/sda2"; "/"]; + ["write_file"; "/new"; "new file contents"; "0"]; + ["cat"; "/new"]], "new file contents")], + "make ext2/3/4 external journal with label", + "\ +This creates an ext2 external journal on C<device> with label C<label>."); + + ("mke2journal_U", (RErr, [Int "blocksize"; String "uuid"; Device "device"]), 190, [], + (let uuid = uuidgen () in + [InitEmpty, Always, TestOutput ( + [["sfdiskM"; "/dev/sda"; ",100 ,"]; + ["mke2journal_U"; "4096"; uuid; "/dev/sda1"]; + ["mke2fs_JU"; "ext2"; "4096"; "/dev/sda2"; uuid]; + ["mount"; "/dev/sda2"; "/"]; + ["write_file"; "/new"; "new file contents"; "0"]; + ["cat"; "/new"]], "new file contents")]), + "make ext2/3/4 external journal with UUID", + "\ +This creates an ext2 external journal on C<device> with UUID C<uuid>."); + + ("mke2fs_J", (RErr, [String "fstype"; Int "blocksize"; Device "device"; Device "journal"]), 191, [], + [], + "make ext2/3/4 filesystem with external journal", + "\ +This creates an ext2/3/4 filesystem on C<device> with +an external journal on C<journal>. It is equivalent +to the command: + + mke2fs -t fstype -b blocksize -J device=<journal> <device> + +See also C<guestfs_mke2journal>."); + + ("mke2fs_JL", (RErr, [String "fstype"; Int "blocksize"; Device "device"; String "label"]), 192, [], + [], + "make ext2/3/4 filesystem with external journal", + "\ +This creates an ext2/3/4 filesystem on C<device> with +an external journal on the journal labeled C<label>. + +See also C<guestfs_mke2journal_L>."); + + ("mke2fs_JU", (RErr, [String "fstype"; Int "blocksize"; Device "device"; String "uuid"]), 193, [], + [], + "make ext2/3/4 filesystem with external journal", + "\ +This creates an ext2/3/4 filesystem on C<device> with +an external journal on the journal with UUID C<uuid>. + +See also C<guestfs_mke2journal_U>."); + ] let all_functions = non_daemon_functions @ daemon_functions |