mirror of
https://github.com/libguestfs/libguestfs.git
synced 2026-03-21 22:53:37 +00:00
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.
This commit is contained in:
@@ -52,6 +52,7 @@ guestfsd_SOURCES = \
|
||||
link.c \
|
||||
ls.c \
|
||||
lvm.c \
|
||||
mkfs.c \
|
||||
mknod.c \
|
||||
mount.c \
|
||||
names.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;
|
||||
}
|
||||
|
||||
149
daemon/ext2.c
149
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;
|
||||
}
|
||||
|
||||
68
daemon/mkfs.c
Normal file
68
daemon/mkfs.c
Normal file
@@ -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;
|
||||
}
|
||||
@@ -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
|
||||
|
||||
@@ -1 +1 @@
|
||||
186
|
||||
193
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user