From a61bccecfba1c9501910d28de24bac945e95001f Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" Date: Sat, 15 Aug 2009 18:03:21 +0100 Subject: [PATCH] New commands: mkfs-b, mke2journal*, mke2fs-J* mkfs-b: Pass the -b (blocksize) parameter to mkfs. mke2journal and friends: Lets you create external ext2 journals on devices. mke2fs-J and friends: Lets you create ext2/3/4 filesystems with external journals. --- daemon/Makefile.am | 1 + daemon/devsparts.c | 17 ------ daemon/ext2.c | 149 +++++++++++++++++++++++++++++++++++++++++++++++++++++ daemon/mkfs.c | 68 ++++++++++++++++++++++++ po/POTFILES.in | 1 + src/MAX_PROC_NR | 2 +- src/generator.ml | 84 ++++++++++++++++++++++++++++++ 7 files changed, 304 insertions(+), 18 deletions(-) create mode 100644 daemon/mkfs.c diff --git a/daemon/Makefile.am b/daemon/Makefile.am index 9406944..e6af0fe 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 b4ea578..76852cc 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 f181b8d..2603ed0 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 0000000..73fd860 --- /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 + +#include +#include +#include +#include +#include +#include +#include + +#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 79a2856..33bf6e6 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 bc3d544..2455a46 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 51c6704..ef7d3d5 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, and C"); + ("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, 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. 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 with label C