static pcre *re_rhel_old;
static pcre *re_rhel;
static pcre *re_rhel_no_minor;
-static pcre *re_debian;
+static pcre *re_major_minor;
static pcre *re_aug_seq;
static pcre *re_xdev;
static pcre *re_windows_version;
"(?:Red Hat Enterprise Linux|CentOS|Scientific Linux).*release (\\d+)\\.(\\d+)", 0);
COMPILE (re_rhel_no_minor,
"(?:Red Hat Enterprise Linux|CentOS|Scientific Linux).*release (\\d+)", 0);
- COMPILE (re_debian, "(\\d+)\\.(\\d+)", 0);
+ COMPILE (re_major_minor, "(\\d+)\\.(\\d+)", 0);
COMPILE (re_aug_seq, "/\\d+$", 0);
COMPILE (re_xdev, "^/dev/(?:h|s|v|xv)d([a-z]\\d*)$", 0);
COMPILE (re_windows_version, "^(\\d+)\\.(\\d+)", 0);
pcre_free (re_rhel_old);
pcre_free (re_rhel);
pcre_free (re_rhel_no_minor);
- pcre_free (re_debian);
+ pcre_free (re_major_minor);
pcre_free (re_aug_seq);
pcre_free (re_xdev);
pcre_free (re_windows_version);
return 0;
}
+/* Set fs->product_name to the first line of the release file. */
+static int
+parse_release_file (guestfs_h *g, struct inspect_fs *fs,
+ const char *release_filename)
+{
+ char **product_name = guestfs_head_n (g, 1, release_filename);
+ if (product_name == NULL)
+ return -1;
+ if (product_name[0] == NULL) {
+ error (g, "%s: file is empty", release_filename);
+ free_string_list (product_name);
+ return -1;
+ }
+
+ /* Note that this string becomes owned by the handle and will
+ * be freed by guestfs___free_inspect_info.
+ */
+ fs->product_name = product_name[0];
+ free (product_name);
+
+ return 0;
+}
+
+/* Parse generic MAJOR.MINOR from the fs->product_name string. */
+static int
+parse_major_minor (guestfs_h *g, struct inspect_fs *fs)
+{
+ char *major, *minor;
+
+ if (match2 (g, fs->product_name, re_major_minor, &major, &minor)) {
+ fs->major_version = parse_unsigned_int (g, major);
+ free (major);
+ if (fs->major_version == -1) {
+ free (minor);
+ return -1;
+ }
+ fs->minor_version = parse_unsigned_int (g, minor);
+ free (minor);
+ if (fs->minor_version == -1)
+ return -1;
+ }
+ return 0;
+}
+
/* The currently mounted device is known to be a Linux root. Try to
* determine from this the distro, version, etc. Also parse
* /etc/fstab to determine the arrangement of mountpoints and
if (guestfs_exists (g, "/etc/redhat-release") > 0) {
fs->distro = OS_DISTRO_REDHAT_BASED; /* Something generic Red Hat-like. */
- char **product_name = guestfs_head_n (g, 1, "/etc/redhat-release");
- if (product_name == NULL)
- return -1;
- if (product_name[0] == NULL) {
- error (g, "/etc/redhat-release file is empty");
- free_string_list (product_name);
+ if (parse_release_file (g, fs, "/etc/redhat-release") == -1)
return -1;
- }
-
- /* Note that this string becomes owned by the handle and will
- * be freed by guestfs___free_inspect_info.
- */
- fs->product_name = product_name[0];
- free (product_name);
char *major, *minor;
if ((major = match1 (g, fs->product_name, re_fedora)) != NULL) {
else if (guestfs_exists (g, "/etc/debian_version") > 0) {
fs->distro = OS_DISTRO_DEBIAN;
- char **product_name = guestfs_head_n (g, 1, "/etc/debian_version");
- if (product_name == NULL)
+ if (parse_release_file (g, fs, "/etc/debian_version") == -1)
return -1;
- if (product_name[0] == NULL) {
- error (g, "/etc/debian_version file is empty");
- free_string_list (product_name);
+
+ if (parse_major_minor (g, fs) == -1)
return -1;
- }
+ }
+ else if (guestfs_exists (g, "/etc/pardus-release") > 0) {
+ fs->distro = OS_DISTRO_PARDUS;
- /* Note that this string becomes owned by the handle and will
- * be freed by guestfs___free_inspect_info.
- */
- fs->product_name = product_name[0];
- free (product_name);
+ if (parse_release_file (g, fs, "/etc/pardus-release") == -1)
+ return -1;
- char *major, *minor;
- if (match2 (g, fs->product_name, re_debian, &major, &minor)) {
- fs->major_version = parse_unsigned_int (g, major);
- free (major);
- if (fs->major_version == -1) {
- free (minor);
- return -1;
- }
- fs->minor_version = parse_unsigned_int (g, minor);
- free (minor);
- if (fs->minor_version == -1)
- return -1;
- }
+ if (parse_major_minor (g, fs) == -1)
+ return -1;
}
/* Determine the architecture. */
device = guestfs_findfs_uuid (g, &spec[5]);
else if (STRPREFIX (spec, "LABEL="))
device = guestfs_findfs_label (g, &spec[6]);
- /* Resolve guest block device names. */
- else if (spec[0] == '/')
+ /* Ignore "/.swap" (Pardus) and pseudo-devices like "tmpfs". */
+ else if (STRPREFIX (spec, "/dev/"))
+ /* Resolve guest block device names. */
device = resolve_fstab_device (g, spec);
- /* Also ignore pseudo-devices completely, like spec == "tmpfs".
- * If we haven't resolved the device successfully by this point,
+
+ /* If we haven't resolved the device successfully by this point,
* we don't care, just ignore it.
*/
if (device == NULL)
switch (fs->distro) {
case OS_DISTRO_DEBIAN: ret = safe_strdup (g, "debian"); break;
case OS_DISTRO_FEDORA: ret = safe_strdup (g, "fedora"); break;
+ case OS_DISTRO_PARDUS: ret = safe_strdup (g, "pardus"); break;
case OS_DISTRO_REDHAT_BASED: ret = safe_strdup (g, "redhat-based"); break;
case OS_DISTRO_RHEL: ret = safe_strdup (g, "rhel"); break;
case OS_DISTRO_WINDOWS: ret = safe_strdup (g, "windows"); break;