[PATCH 1/5] Remove extra space in inspect-fs-unix.c
by Nikos Skalkotos
Signed-off-by: Nikos Skalkotos <skalkoto(a)grnet.gr>
---
src/inspect-fs-unix.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/inspect-fs-unix.c b/src/inspect-fs-unix.c
index 01a59f1..f55e53b 100644
--- a/src/inspect-fs-unix.c
+++ b/src/inspect-fs-unix.c
@@ -58,8 +58,8 @@ COMPILE_REGEXP (re_scientific_linux,
"Scientific Linux.*release (\\d+)\\.(\\d+)", 0)
COMPILE_REGEXP (re_scientific_linux_no_minor,
"Scientific Linux.*release (\\d+)", 0)
- COMPILE_REGEXP (re_oracle_linux_old,
- "Oracle Linux.*release (\\d+).*Update (\\d+)", 0)
+COMPILE_REGEXP (re_oracle_linux_old,
+ "Oracle Linux.*release (\\d+).*Update (\\d+)", 0)
COMPILE_REGEXP (re_oracle_linux,
"Oracle Linux.*release (\\d+)\\.(\\d+)", 0)
COMPILE_REGEXP (re_oracle_linux_no_minor, "Oracle Linux.*release (\\d+)", 0)
--
2.1.3
10 years, 1 month
Virt-rescue problem
by Suvajit Sarkar
Hello,
I am trying to run this command
virt-rescue --suggest -d XYZ
virt-rescue --network -d XYZ
the prompt is looking like this:
I have no name!@(none):
now I mounted the root partition suggested by virt-rescue to /sysroot
then chroot /sysroot
after that I tried to rebuild an initrd.img with the following command
update-initramfs -c -k 3.2.0-58-generic
But it failed with following error:
update-initramfs: failed for /boot/initrd.img-3.2.0-58-generic with 1.
Also when running apt-get update , it fails saying "no address associated
with hostname.
host configuration:ubuntu 14.04
guest:ubuntu 12.04
--
Thanks and regards,
Suvajit Sarkar
10 years, 1 month
[PATCH 5/5] Add freebsd and netbsd distros
by Nikos Skalkotos
Prior to this commit the distro for a FreeBSD or a NetBSD system, in
conjuction to what happened for OpenBSD, was shown as 'unknown'.
*BSDs are complete OSes, not a kernel like Linux, but theoritically you
could have FreeBSD as ostype and PC-BSD as distro.
Signed-off-by: Nikos Skalkotos <skalkoto(a)grnet.gr>
---
generator/actions.ml | 8 ++++++++
src/guestfs-internal.h | 2 ++
src/inspect-fs-unix.c | 2 ++
src/inspect-fs.c | 4 ++++
src/inspect-icon.c | 2 ++
src/inspect.c | 2 ++
src/osinfo.c | 4 ++++
7 files changed, 24 insertions(+)
diff --git a/generator/actions.ml b/generator/actions.ml
index 385b620..d4ec0b1 100644
--- a/generator/actions.ml
+++ b/generator/actions.ml
@@ -1065,6 +1065,10 @@ Debian.
Fedora.
+=item \"freebsd\"
+
+FreeBSD.
+
=item \"freedos\"
FreeDOS.
@@ -1089,6 +1093,10 @@ Mandriva.
MeeGo.
+=item \"netbsd\"
+
+NetBSD.
+
=item \"openbsd\"
OpenBSD.
diff --git a/src/guestfs-internal.h b/src/guestfs-internal.h
index c8dd084..0a4a6f2 100644
--- a/src/guestfs-internal.h
+++ b/src/guestfs-internal.h
@@ -543,6 +543,8 @@ enum inspect_os_distro {
OS_DISTRO_SLES,
OS_DISTRO_OPENBSD,
OS_DISTRO_ORACLE_LINUX,
+ OS_DISTRO_FREEBSD,
+ OS_DISTRO_NETBSD,
};
enum inspect_os_package_format {
diff --git a/src/inspect-fs-unix.c b/src/inspect-fs-unix.c
index b1a2f8f..ff6a156 100644
--- a/src/inspect-fs-unix.c
+++ b/src/inspect-fs-unix.c
@@ -591,6 +591,7 @@ int
guestfs___check_freebsd_root (guestfs_h *g, struct inspect_fs *fs)
{
fs->type = OS_TYPE_FREEBSD;
+ fs->distro = OS_DISTRO_FREEBSD;
/* FreeBSD has no authoritative version file. The version number is
* in /etc/motd, which the system administrator might edit, but
@@ -634,6 +635,7 @@ guestfs___check_netbsd_root (guestfs_h *g, struct inspect_fs *fs)
if (match2 (g, fs->product_name, re_netbsd, &major, &minor)) {
fs->type = OS_TYPE_NETBSD;
+ fs->distro = OS_DISTRO_NETBSD;
fs->major_version = guestfs___parse_unsigned_int (g, major);
free (major);
if (fs->major_version == -1) {
diff --git a/src/inspect-fs.c b/src/inspect-fs.c
index aaddb49..e9cc2e9 100644
--- a/src/inspect-fs.c
+++ b/src/inspect-fs.c
@@ -448,6 +448,8 @@ guestfs___check_package_format (guestfs_h *g, struct inspect_fs *fs)
case OS_DISTRO_BUILDROOT:
case OS_DISTRO_CIRROS:
case OS_DISTRO_FREEDOS:
+ case OS_DISTRO_FREEBSD:
+ case OS_DISTRO_NETBSD:
case OS_DISTRO_OPENBSD:
case OS_DISTRO_UNKNOWN:
fs->package_format = OS_PACKAGE_FORMAT_UNKNOWN;
@@ -507,6 +509,8 @@ guestfs___check_package_management (guestfs_h *g, struct inspect_fs *fs)
case OS_DISTRO_BUILDROOT:
case OS_DISTRO_CIRROS:
case OS_DISTRO_FREEDOS:
+ case OS_DISTRO_FREEBSD:
+ case OS_DISTRO_NETBSD:
case OS_DISTRO_OPENBSD:
case OS_DISTRO_UNKNOWN:
fs->package_management = OS_PACKAGE_MANAGEMENT_UNKNOWN;
diff --git a/src/inspect-icon.c b/src/inspect-icon.c
index b1b3adf..a7318c6 100644
--- a/src/inspect-icon.c
+++ b/src/inspect-icon.c
@@ -178,6 +178,8 @@ guestfs__inspect_get_icon (guestfs_h *g, const char *root, size_t *size_r,
case OS_DISTRO_SLACKWARE:
case OS_DISTRO_TTYLINUX:
case OS_DISTRO_WINDOWS:
+ case OS_DISTRO_FREEBSD:
+ case OS_DISTRO_NETBSD:
case OS_DISTRO_OPENBSD:
case OS_DISTRO_UNKNOWN:
; /* nothing */
diff --git a/src/inspect.c b/src/inspect.c
index c3b88e1..bdb45c3 100644
--- a/src/inspect.c
+++ b/src/inspect.c
@@ -203,12 +203,14 @@ guestfs__inspect_get_distro (guestfs_h *g, const char *root)
case OS_DISTRO_CIRROS: ret = safe_strdup (g, "cirros"); break;
case OS_DISTRO_DEBIAN: ret = safe_strdup (g, "debian"); break;
case OS_DISTRO_FEDORA: ret = safe_strdup (g, "fedora"); break;
+ case OS_DISTRO_FREEBSD: ret = safe_strdup (g, "freebsd"); break;
case OS_DISTRO_FREEDOS: ret = safe_strdup (g, "freedos"); break;
case OS_DISTRO_GENTOO: ret = safe_strdup (g, "gentoo"); break;
case OS_DISTRO_LINUX_MINT: ret = safe_strdup (g, "linuxmint"); break;
case OS_DISTRO_MAGEIA: ret = safe_strdup (g, "mageia"); break;
case OS_DISTRO_MANDRIVA: ret = safe_strdup (g, "mandriva"); break;
case OS_DISTRO_MEEGO: ret = safe_strdup (g, "meego"); break;
+ case OS_DISTRO_NETBSD: ret = safe_strdup (g, "netbsd"); break;
case OS_DISTRO_OPENBSD: ret = safe_strdup (g, "openbsd"); break;
case OS_DISTRO_OPENSUSE: ret = safe_strdup (g, "opensuse"); break;
case OS_DISTRO_ORACLE_LINUX: ret = safe_strdup (g, "oraclelinux"); break;
diff --git a/src/osinfo.c b/src/osinfo.c
index 3a6d342..aee3b8f 100644
--- a/src/osinfo.c
+++ b/src/osinfo.c
@@ -498,8 +498,12 @@ parse_distro (guestfs_h *g, xmlNodePtr node, struct osinfo *osinfo)
osinfo->distro = OS_DISTRO_DEBIAN;
else if (STREQ (content, "fedora"))
osinfo->distro = OS_DISTRO_FEDORA;
+ else if (STREQ (content, "freebsd"))
+ osinfo->distro = OS_DISTRO_FREEBSD;
else if (STREQ (content, "mandriva"))
osinfo->distro = OS_DISTRO_MANDRIVA;
+ else if (STREQ (content, "netbsd"))
+ osinfo->distro = OS_DISTRO_NETBSD;
else if (STREQ (content, "openbsd"))
osinfo->distro = OS_DISTRO_OPENBSD;
else if (STREQ (content, "opensuse"))
--
2.1.3
10 years, 1 month
[PATCH 4/5] Fix fstab block device resolution for FreeBSD
by Nikos Skalkotos
Take into granted that partition 'c' has a special purpose. It has
always the same size as the enclosing slice and is not mapped under
Linux.
This is a best effort try. The mapping will be incorrect if there is a
gap in the disklabel partitions sequence, e.g. 'b' (swap) partition is
missing but 'd' partition is defined.
Signed-off-by: Nikos Skalkotos <skalkoto(a)grnet.gr>
---
src/inspect-fs-unix.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/src/inspect-fs-unix.c b/src/inspect-fs-unix.c
index 3a2f81a..b1a2f8f 100644
--- a/src/inspect-fs-unix.c
+++ b/src/inspect-fs-unix.c
@@ -1620,9 +1620,13 @@ resolve_fstab_device (guestfs_h *g, const char *spec, Hash_table *md_map,
free (slice);
free (part);
+ if (part_i > 2)
+ /* Partition 'c' has the size of the enclosing slice. Not mapped under Linux. */
+ part_i -= 1;
+
if (disk_i != -1 && disk_i <= 26 &&
slice_i > 0 && slice_i <= 1 /* > 4 .. see comment above */ &&
- part_i >= 0 && part_i < 26) {
+ part_i >= 0 && part_i < 25) {
device = safe_asprintf (g, "/dev/sd%c%d", disk_i + 'a', part_i + 5);
}
}
--
2.1.3
10 years, 1 month
[PATCH 3/5] Support fstab block device resolution for NetBSD
by Nikos Skalkotos
Make a best effort try to map NetBSD disklabel partitions to Linux
partitions. The mapping will be incorrect if there is a gap in the
disklabel partitions sequence, e.g. 'b' (swap) partition is missing but
'e' partition is defined.
Signed-off-by: Nikos Skalkotos <skalkoto(a)grnet.gr>
---
src/inspect-fs-unix.c | 31 ++++++++++++++++++++++++++-----
1 file changed, 26 insertions(+), 5 deletions(-)
diff --git a/src/inspect-fs-unix.c b/src/inspect-fs-unix.c
index c6fa23e..3a2f81a 100644
--- a/src/inspect-fs-unix.c
+++ b/src/inspect-fs-unix.c
@@ -83,6 +83,7 @@ COMPILE_REGEXP (re_hurd_dev, "^/dev/(h)d(\\d+)s(\\d+)$", 0)
COMPILE_REGEXP (re_openbsd, "^OpenBSD (\\d+|\\?)\\.(\\d+|\\?)", 0)
COMPILE_REGEXP (re_openbsd_duid, "^[0-9a-f]{16}\\.[a-z]", 0)
COMPILE_REGEXP (re_openbsd_dev, "^/dev/(s|w)d([0-9])([a-z])$", 0)
+COMPILE_REGEXP (re_netbsd_dev, "^/dev/(l|s)d([0-9])([a-z])$", 0)
static void check_architecture (guestfs_h *g, struct inspect_fs *fs);
static int check_hostname_unix (guestfs_h *g, struct inspect_fs *fs);
@@ -92,7 +93,8 @@ static int check_fstab (guestfs_h *g, struct inspect_fs *fs);
static int add_fstab_entry (guestfs_h *g, struct inspect_fs *fs,
const char *mountable, const char *mp);
static char *resolve_fstab_device (guestfs_h *g, const char *spec,
- Hash_table *md_map);
+ Hash_table *md_map,
+ enum inspect_os_type os_type);
static int inspect_with_augeas (guestfs_h *g, struct inspect_fs *fs, const char **configfiles, int (*f) (guestfs_h *, struct inspect_fs *));
static int is_partition (guestfs_h *g, const char *partition);
@@ -1045,7 +1047,7 @@ check_fstab (guestfs_h *g, struct inspect_fs *fs)
/* Ignore "/.swap" (Pardus) and pseudo-devices like "tmpfs". */
else if (STRPREFIX (spec, "/dev/"))
/* Resolve guest block device names. */
- mountable = resolve_fstab_device (g, spec, md_map);
+ mountable = resolve_fstab_device (g, spec, md_map, fs->type);
else if (match (g, spec, re_openbsd_duid)) {
/* In OpenBSD's fstab you can specify partitions on a disk by appending a
* period and a partition letter to a Disklable Unique Identifier. The
@@ -1060,7 +1062,7 @@ check_fstab (guestfs_h *g, struct inspect_fs *fs)
* first disk.
*/
snprintf(device, 10, "%s%c", "/dev/sd0", part);
- mountable = resolve_fstab_device (g, device, md_map);
+ mountable = resolve_fstab_device (g, device, md_map, fs->type);
}
/* If we haven't resolved the device successfully by this point,
@@ -1544,7 +1546,8 @@ resolve_fstab_device_diskbyid (guestfs_h *g, const char *part,
* anything we don't recognize unchanged.
*/
static char *
-resolve_fstab_device (guestfs_h *g, const char *spec, Hash_table *md_map)
+resolve_fstab_device (guestfs_h *g, const char *spec, Hash_table *md_map,
+ enum inspect_os_type os_type)
{
char *device = NULL;
char *type, *slice, *disk, *part;
@@ -1623,7 +1626,25 @@ resolve_fstab_device (guestfs_h *g, const char *spec, Hash_table *md_map)
device = safe_asprintf (g, "/dev/sd%c%d", disk_i + 'a', part_i + 5);
}
}
- else if (match3 (g, spec, re_openbsd_dev, &type, &disk, &part)) {
+ else if ((os_type == OS_TYPE_NETBSD) &&
+ match3 (g, spec, re_netbsd_dev, &type, &disk, &part)) {
+ int disk_i = guestfs___parse_unsigned_int (g, disk);
+ int part_i = part[0] - 'a'; /* counting from 0 */
+ free (type);
+ free (disk);
+ free (part);
+
+ if (part_i > 3)
+ /* Partition 'c' is the disklabel partition and 'd' the hard disk itself.
+ * Not mapped under Linux.
+ */
+ part_i -= 2;
+
+ if (disk_i != -1 && part_i >= 0 && part_i < 24)
+ device = safe_asprintf (g, "/dev/sd%c%d", disk_i + 'a', part_i + 5);
+ }
+ else if ((os_type == OS_TYPE_OPENBSD) &&
+ match3 (g, spec, re_openbsd_dev, &type, &disk, &part)) {
int disk_i = guestfs___parse_unsigned_int (g, disk);
int part_i = part[0] - 'a'; /* counting from 0 */
free (type);
--
2.1.3
10 years, 1 month
[PATCH 2/5] inspect_os: Add support for detecting OpenBSD
by Nikos Skalkotos
Signed-off-by: Nikos Skalkotos <skalkoto(a)grnet.gr>
---
src/guestfs-internal.h | 1 +
src/inspect-fs-unix.c | 110 +++++++++++++++++++++++++++++++++++++++++++++----
src/inspect-fs.c | 12 ++++++
3 files changed, 116 insertions(+), 7 deletions(-)
diff --git a/src/guestfs-internal.h b/src/guestfs-internal.h
index 33d28f5..c8dd084 100644
--- a/src/guestfs-internal.h
+++ b/src/guestfs-internal.h
@@ -782,6 +782,7 @@ extern void guestfs___check_package_management (guestfs_h *g, struct inspect_fs
extern int guestfs___check_linux_root (guestfs_h *g, struct inspect_fs *fs);
extern int guestfs___check_freebsd_root (guestfs_h *g, struct inspect_fs *fs);
extern int guestfs___check_netbsd_root (guestfs_h *g, struct inspect_fs *fs);
+extern int guestfs___check_openbsd_root (guestfs_h *g, struct inspect_fs *fs);
extern int guestfs___check_hurd_root (guestfs_h *g, struct inspect_fs *fs);
extern int guestfs___check_minix_root (guestfs_h *g, struct inspect_fs *fs);
diff --git a/src/inspect-fs-unix.c b/src/inspect-fs-unix.c
index f55e53b..c6fa23e 100644
--- a/src/inspect-fs-unix.c
+++ b/src/inspect-fs-unix.c
@@ -80,6 +80,9 @@ COMPILE_REGEXP (re_sles_version, "^VERSION = (\\d+)", 0)
COMPILE_REGEXP (re_sles_patchlevel, "^PATCHLEVEL = (\\d+)", 0)
COMPILE_REGEXP (re_minix, "^(\\d+)\\.(\\d+)(\\.(\\d+))?", 0)
COMPILE_REGEXP (re_hurd_dev, "^/dev/(h)d(\\d+)s(\\d+)$", 0)
+COMPILE_REGEXP (re_openbsd, "^OpenBSD (\\d+|\\?)\\.(\\d+|\\?)", 0)
+COMPILE_REGEXP (re_openbsd_duid, "^[0-9a-f]{16}\\.[a-z]", 0)
+COMPILE_REGEXP (re_openbsd_dev, "^/dev/(s|w)d([0-9])([a-z])$", 0)
static void check_architecture (guestfs_h *g, struct inspect_fs *fs);
static int check_hostname_unix (guestfs_h *g, struct inspect_fs *fs);
@@ -659,6 +662,55 @@ guestfs___check_netbsd_root (guestfs_h *g, struct inspect_fs *fs)
return 0;
}
+/* The currently mounted device may be an OpenBSD root. */
+int
+guestfs___check_openbsd_root (guestfs_h *g, struct inspect_fs *fs)
+{
+ if (guestfs_is_file_opts (g, "/etc/motd",
+ GUESTFS_IS_FILE_OPTS_FOLLOWSYMLINKS, 1, -1) > 0) {
+ CLEANUP_FREE char *major = NULL, *minor = NULL;
+
+ /* The first line of this file gets automatically updated at boot. */
+ if (parse_release_file (g, fs, "/etc/motd") == -1)
+ return -1;
+
+ if (match2 (g, fs->product_name, re_openbsd, &major, &minor)) {
+ fs->type = OS_TYPE_OPENBSD;
+ fs->distro = OS_DISTRO_OPENBSD;
+
+ /* Before the first boot, the first line will look like this:
+ *
+ * OpenBSD ?.? (UNKNOWN)
+ */
+ if ((fs->product_name[8] != '?') && (fs->product_name[10] != '?')) {
+ fs->major_version = guestfs___parse_unsigned_int (g, major);
+ if (fs->major_version == -1)
+ return -1;
+
+ fs->minor_version = guestfs___parse_unsigned_int (g, minor);
+ if (fs->minor_version == -1)
+ return -1;
+ }
+ }
+ } else {
+ return -1;
+ }
+
+ /* Determine the architecture. */
+ check_architecture (g, fs);
+
+ /* We already know /etc/fstab exists because it's part of the test above. */
+ const char *configfiles[] = { "/etc/fstab", NULL };
+ if (inspect_with_augeas (g, fs, configfiles, check_fstab) == -1)
+ return -1;
+
+ /* Determine hostname. */
+ if (check_hostname_unix (g, fs) == -1)
+ return -1;
+
+ return 0;
+}
+
/* The currently mounted device may be a Hurd root. Hurd has distros
* just like Linux.
*/
@@ -821,6 +873,18 @@ check_hostname_unix (guestfs_h *g, struct inspect_fs *fs)
}
break;
+ case OS_TYPE_OPENBSD:
+ if (guestfs_is_file (g, "/etc/myname")) {
+ fs->hostname = guestfs___first_line_of_file (g, "/etc/myname");
+ if (fs->hostname == NULL)
+ return -1;
+ if (STREQ (fs->hostname, "")) {
+ free (fs->hostname);
+ fs->hostname = NULL;
+ }
+ }
+ break;
+
case OS_TYPE_MINIX:
if (guestfs_is_file (g, "/etc/hostname.file")) {
fs->hostname = guestfs___first_line_of_file (g, "/etc/hostname.file");
@@ -835,7 +899,6 @@ check_hostname_unix (guestfs_h *g, struct inspect_fs *fs)
case OS_TYPE_WINDOWS: /* not here, see check_windows_system_registry */
case OS_TYPE_DOS:
- case OS_TYPE_OPENBSD:
case OS_TYPE_UNKNOWN:
/* nothing */;
}
@@ -969,18 +1032,36 @@ check_fstab (guestfs_h *g, struct inspect_fs *fs)
STREQ (mp, "/sys"))
continue;
- /* Resolve UUID= and LABEL= to the actual device. */
- if (STRPREFIX (spec, "UUID="))
+ if (STREQ (mp, "/") || STREQ (spec, "/dev/root"))
+ /* The device translation is not straight forward for all OSes.
+ Make sure this is correctly resolved at least for /.
+ */
+ mountable = safe_strdup (g, fs->mountable);
+ else if (STRPREFIX (spec, "UUID="))
+ /* Resolve UUID= and LABEL= to the actual device. */
mountable = guestfs_findfs_uuid (g, &spec[5]);
else if (STRPREFIX (spec, "LABEL="))
mountable = guestfs_findfs_label (g, &spec[6]);
- /* Ignore "/.swap" (Pardus) and pseudo-devices like "tmpfs". */
- else if (STREQ (spec, "/dev/root"))
- /* Resolve /dev/root to the current device. */
- mountable = safe_strdup (g, fs->mountable);
+ /* Ignore "/.swap" (Pardus) and pseudo-devices like "tmpfs". */
else if (STRPREFIX (spec, "/dev/"))
/* Resolve guest block device names. */
mountable = resolve_fstab_device (g, spec, md_map);
+ else if (match (g, spec, re_openbsd_duid)) {
+ /* In OpenBSD's fstab you can specify partitions on a disk by appending a
+ * period and a partition letter to a Disklable Unique Identifier. The
+ * DUID is a 16 hex digit field found in the OpenBSD's altered BSD
+ * disklabel. For more info see here:
+ * http://www.openbsd.org/faq/faq14.html#intro
+ */
+ char device[10]; /* /dev/sd[0-9][a-z] */
+ char part = spec[17];
+
+ /* We cannot peep into disklables, we can only assume that this is the
+ * first disk.
+ */
+ snprintf(device, 10, "%s%c", "/dev/sd0", part);
+ mountable = resolve_fstab_device (g, device, md_map);
+ }
/* If we haven't resolved the device successfully by this point,
* we don't care, just ignore it.
@@ -1542,6 +1623,21 @@ resolve_fstab_device (guestfs_h *g, const char *spec, Hash_table *md_map)
device = safe_asprintf (g, "/dev/sd%c%d", disk_i + 'a', part_i + 5);
}
}
+ else if (match3 (g, spec, re_openbsd_dev, &type, &disk, &part)) {
+ int disk_i = guestfs___parse_unsigned_int (g, disk);
+ int part_i = part[0] - 'a'; /* counting from 0 */
+ free (type);
+ free (disk);
+ free (part);
+
+ if (part_i > 2)
+ /* Partition 'c' is the hard disk itself. Not mapped under Linux */
+ part_i -= 1;
+
+ /* In OpenBSD MAXPARTITIONS is defined to 16 for all architectures */
+ if (disk_i != -1 && part_i >= 0 && part_i < 15)
+ device = safe_asprintf (g, "/dev/sd%c%d", disk_i + 'a', part_i + 5);
+ }
else if ((part = match1 (g, spec, re_diskbyid)) != NULL) {
r = resolve_fstab_device_diskbyid (g, part, &device);
free (part);
diff --git a/src/inspect-fs.c b/src/inspect-fs.c
index fe82132..aaddb49 100644
--- a/src/inspect-fs.c
+++ b/src/inspect-fs.c
@@ -177,6 +177,7 @@ check_filesystem (guestfs_h *g, const char *mountable,
if (guestfs___check_freebsd_root (g, fs) == -1)
return -1;
}
+ /* NetBSD root? */
else if (is_dir_etc &&
is_dir_bin &&
guestfs_is_file (g, "/netbsd") > 0 &&
@@ -187,6 +188,17 @@ check_filesystem (guestfs_h *g, const char *mountable,
if (guestfs___check_netbsd_root (g, fs) == -1)
return -1;
}
+ /* OpenBSD root? */
+ else if (is_dir_etc &&
+ is_dir_bin &&
+ guestfs_is_file (g, "/bsd") > 0 &&
+ guestfs_is_file (g, "/etc/fstab") > 0 &&
+ guestfs_is_file (g, "/etc/motd") > 0) {
+ fs->is_root = 1;
+ fs->format = OS_FORMAT_INSTALLED;
+ if (guestfs___check_openbsd_root (g, fs) == -1)
+ return -1;
+ }
/* Hurd root? */
else if (guestfs_is_file (g, "/hurd/console") > 0 &&
guestfs_is_file (g, "/hurd/hello") > 0 &&
--
2.1.3
10 years, 1 month
[PATCH v2] fish: show synopsis if command syntax is wrong
by Hu Tao
This patch lets guestfish show command synopsis if the syntax of command issued
by user is wrong, rather than telling user that the number of parameters is wrong.
Signed-off-by: Hu Tao <hutao(a)cn.fujitsu.com>
---
changes in v2:
- fix the error of ' error: control reaches end of non-void function [-Werror=return-type]'
- change the return value from -2 to -1
fish/cmds-gperf.h | 1 +
generator/fish.ml | 38 +++++++++++++++-----------------------
2 files changed, 16 insertions(+), 23 deletions(-)
diff --git a/fish/cmds-gperf.h b/fish/cmds-gperf.h
index 74db69d..bcb3b5d 100644
--- a/fish/cmds-gperf.h
+++ b/fish/cmds-gperf.h
@@ -25,6 +25,7 @@
struct command_entry {
const char *name; /* Short name. */
const char *help; /* Online help. */
+ const char *synopsis; /* Synopsis. */
/* The run_* function. */
int (*run) (const char *cmd, size_t argc, char *argv[]);
diff --git a/generator/fish.ml b/generator/fish.ml
index 3f53ffa..52cdfd5 100644
--- a/generator/fish.ml
+++ b/generator/fish.ml
@@ -181,7 +181,7 @@ Guestfish will prompt for these separately."
else "" in
let pod =
- sprintf "%s - %s\n\n=head1 SYNOPSIS\n\n %s\n\n=head1 DESCRIPTION\n\n%s%s%s"
+ sprintf "%s - %s\n\n=head1 SYNOPSIS\n\n%s\n\n=head1 DESCRIPTION\n\n%s%s%s"
name2 shortdesc synopsis longdesc warnings describe_alias in
let text =
String.concat "\n" (pod2text ~trim:false ~discard:false "NAME" pod)
@@ -190,6 +190,7 @@ Guestfish will prompt for these separately."
pr "struct command_entry %s_cmd_entry = {\n" name;
pr " .name = \"%s\",\n" name2;
pr " .help = \"%s\",\n" (c_quote text);
+ pr " .synopsis = \"%s\",\n" (c_quote synopsis);
pr " .run = run_%s\n" name;
pr "};\n";
pr "\n";
@@ -393,30 +394,14 @@ Guestfish will prompt for these separately."
if argc_minimum = argc_maximum then (
pr " if (argc != %d) {\n" argc_minimum;
- if argc_minimum = 0 then (
- pr " fprintf (stderr, _(\"%%s should have no parameters\\n\"), cmd);\n";
- ) else (
- pr " fprintf (stderr, ngettext(\"%%s should have %%d parameter\\n\",\n";
- pr " \"%%s should have %%d parameters\\n\",\n";
- pr " %d),\n"
- argc_minimum;
- pr " cmd, %d);\n"
- argc_minimum;
- )
+ pr " ret = -2;\n";
) else if argc_minimum = 0 then (
pr " if (argc > %d) {\n" argc_maximum;
- pr " fprintf (stderr, ngettext(\"%%s should have at most %%d parameter\\n\",\n";
- pr " \"%%s should have at most %%d parameters\\n\",\n";
- pr " %d),\n"
- argc_maximum;
- pr " cmd, %d);\n"
- argc_maximum;
+ pr " ret = -2;\n";
) else (
pr " if (argc < %d || argc > %d) {\n" argc_minimum argc_maximum;
- pr " fprintf (stderr, _(\"%%s should have %%d-%%d parameter(s)\\n\"), cmd, %d, %d);\n"
- argc_minimum argc_maximum;
+ pr " ret = -2;\n";
);
- pr " fprintf (stderr, _(\"type 'help %%s' for help on %%s\\n\"), cmd, cmd);\n";
pr " goto out_noargs;\n";
pr " }\n";
@@ -694,16 +679,23 @@ Guestfish will prompt for these separately."
pr "run_action (const char *cmd, size_t argc, char *argv[])\n";
pr "{\n";
pr " const struct command_table *ct;\n";
+ pr " int ret = -1;\n";
pr "\n";
pr " ct = lookup_fish_command (cmd, strlen (cmd));\n";
- pr " if (ct)\n";
- pr " return ct->entry->run (cmd, argc, argv);\n";
+ pr " if (ct) {\n";
+ pr " ret = ct->entry->run (cmd, argc, argv);\n";
+ pr " if (ret == -2) {\n";
+ pr " fprintf (stderr, _(\"usage: %%s\\n\"), ct->entry->synopsis);\n";
+ pr " fprintf (stderr, _(\"type 'help %%s' for more help on %%s\\n\"), cmd, cmd);\n";
+ pr " ret = -1;\n";
+ pr " }\n";
+ pr " }\n";
pr " else {\n";
pr " fprintf (stderr, _(\"%%s: unknown command\\n\"), cmd);\n";
pr " if (command_num == 1)\n";
pr " extended_help_message ();\n";
- pr " return -1;\n";
pr " }\n";
+ pr " return ret;\n";
pr "}\n"
and generate_fish_cmds_h () =
--
1.9.3
10 years, 1 month
[PATCH] fish: show synopsis if command syntax is wrong
by Hu Tao
This patch lets guestfish show command synopsis if the syntax of command issued
by user is wrong, rather than telling user that the number of parameters is wrong.
Signed-off-by: Hu Tao <hutao(a)cn.fujitsu.com>
---
fish/cmds-gperf.h | 1 +
generator/fish.ml | 33 ++++++++++++---------------------
2 files changed, 13 insertions(+), 21 deletions(-)
diff --git a/fish/cmds-gperf.h b/fish/cmds-gperf.h
index 74db69d..bcb3b5d 100644
--- a/fish/cmds-gperf.h
+++ b/fish/cmds-gperf.h
@@ -25,6 +25,7 @@
struct command_entry {
const char *name; /* Short name. */
const char *help; /* Online help. */
+ const char *synopsis; /* Synopsis. */
/* The run_* function. */
int (*run) (const char *cmd, size_t argc, char *argv[]);
diff --git a/generator/fish.ml b/generator/fish.ml
index 3f53ffa..951b376 100644
--- a/generator/fish.ml
+++ b/generator/fish.ml
@@ -190,6 +190,7 @@ Guestfish will prompt for these separately."
pr "struct command_entry %s_cmd_entry = {\n" name;
pr " .name = \"%s\",\n" name2;
pr " .help = \"%s\",\n" (c_quote text);
+ pr " .synopsis = \"%s\",\n" (c_quote synopsis);
pr " .run = run_%s\n" name;
pr "};\n";
pr "\n";
@@ -393,30 +394,14 @@ Guestfish will prompt for these separately."
if argc_minimum = argc_maximum then (
pr " if (argc != %d) {\n" argc_minimum;
- if argc_minimum = 0 then (
- pr " fprintf (stderr, _(\"%%s should have no parameters\\n\"), cmd);\n";
- ) else (
- pr " fprintf (stderr, ngettext(\"%%s should have %%d parameter\\n\",\n";
- pr " \"%%s should have %%d parameters\\n\",\n";
- pr " %d),\n"
- argc_minimum;
- pr " cmd, %d);\n"
- argc_minimum;
- )
+ pr " ret = -2;\n";
) else if argc_minimum = 0 then (
pr " if (argc > %d) {\n" argc_maximum;
- pr " fprintf (stderr, ngettext(\"%%s should have at most %%d parameter\\n\",\n";
- pr " \"%%s should have at most %%d parameters\\n\",\n";
- pr " %d),\n"
- argc_maximum;
- pr " cmd, %d);\n"
- argc_maximum;
+ pr " ret = -2;\n";
) else (
pr " if (argc < %d || argc > %d) {\n" argc_minimum argc_maximum;
- pr " fprintf (stderr, _(\"%%s should have %%d-%%d parameter(s)\\n\"), cmd, %d, %d);\n"
- argc_minimum argc_maximum;
+ pr " ret = -2;\n";
);
- pr " fprintf (stderr, _(\"type 'help %%s' for help on %%s\\n\"), cmd, cmd);\n";
pr " goto out_noargs;\n";
pr " }\n";
@@ -694,10 +679,16 @@ Guestfish will prompt for these separately."
pr "run_action (const char *cmd, size_t argc, char *argv[])\n";
pr "{\n";
pr " const struct command_table *ct;\n";
+ pr " int ret = -1;\n";
pr "\n";
pr " ct = lookup_fish_command (cmd, strlen (cmd));\n";
- pr " if (ct)\n";
- pr " return ct->entry->run (cmd, argc, argv);\n";
+ pr " if (ct) {\n";
+ pr " ret = ct->entry->run (cmd, argc, argv);\n";
+ pr " if (ret == -2) {\n";
+ pr " fprintf (stderr, _(\"usage: %%s\\n\"), ct->entry->synopsis);\n";
+ pr " fprintf (stderr, _(\"type 'help %%s' for more help on %%s\\n\"), cmd, cmd);\n";
+ pr " }\n";
+ pr " }\n";
pr " else {\n";
pr " fprintf (stderr, _(\"%%s: unknown command\\n\"), cmd);\n";
pr " if (command_num == 1)\n";
--
1.9.3
10 years, 1 month