/* RHEL5 blkid doesn't have the -p (low-level probing) option and the * -i(I/O limits) option so we must test for these options the first * time the function is called. * * Debian 6 has -p but not -i. */ static int test_blkid_p_i_opt (void) { int r; CLEANUP_FREE char *err = NULL, *err2 = NULL; r = commandr (NULL, &err, str_blkid, "-p", "/dev/null", NULL); if (r == -1) { /* This means we couldn't run the blkid command at all. */ command_failed: reply_with_error ("could not run 'blkid' command: %s", err); return -1; } if (strstr (err, "invalid option --")) { return 0; } r = commandr (NULL, &err2, str_blkid, "-i", NULL); if (r == -1) goto command_failed; if (strstr (err2, "invalid option --")) { return 0; } /* We have both options. */ return 1; }
int do_fsck (const char *fstype, const char *device) { char *err; int r; r = commandr (NULL, &err, "fsck", "-a", "-t", fstype, device, NULL); if (r == -1) { reply_with_error ("%s: %s", device, err); free (err); return -1; } free (err); return r; }
int do_ntfs_3g_probe (int rw, const char *device) { CLEANUP_FREE char *err = NULL; int r; const char *rw_flag; rw_flag = rw ? "-w" : "-r"; r = commandr (NULL, &err, str_ntfs3g_probe, rw_flag, device, NULL); if (r == -1) { reply_with_error ("%s: %s", device, err); return -1; } return r; }
/* Search for filesystem in /proc/filesystems, ignoring "nodev". */ static int test_proc_filesystems (const char *filesystem) { size_t len = strlen (filesystem) + 32; char regex[len]; CLEANUP_FREE char *err = NULL; int r; snprintf (regex, len, "^[[:space:]]*%s$", filesystem); r = commandr (NULL, &err, str_grep, regex, "/proc/filesystems", NULL); if (r == -1 || r >= 2) { fprintf (stderr, "grep /proc/filesystems: %s", err); return -1; } return r == 0; }
static void dump(Vga*, Ctlr* ctlr) { int i; uchar command; printitem(ctlr->name, "command"); command = commandr(); printreg(command); printitem(ctlr->name, "index08"); commandw(command|0x10); for(i = 0x08; i < 0x11; i++){ outportb(PaddrR, i); printreg(inportb(PaddrW)); } commandw(command); }
/* RHEL5 blkid doesn't have the -p(partition info) option and the * -i(I/O limits) option so we must test for these options the first * time the function is called. */ static int test_blkid_p_opt(void) { static int result; char *err = NULL; int r = commandr(NULL, &err, "blkid", "-p", "/dev/null", NULL); if (r == -1) { reply_with_error("could not run 'blkid' command: %s", err); free(err); return -1; } if (strstr(err, "invalid option --")) result = 0; else result = 1; free(err); return result; }
/* RHEL 5 parted doesn't have the -m (machine readable) option so we * must do a lot more work to parse the output in * print_partition_table below. Test for this option the first time * this function is called. */ static int test_parted_m_opt (void) { static int result = -1; if (result >= 0) return result; CLEANUP_FREE char *err = NULL; int r = commandr (NULL, &err, str_parted, "-s", "-m", "/dev/null", NULL); if (r == -1) { /* Test failed, eg. missing or completely unusable parted binary. */ reply_with_error ("could not run 'parted' command"); return -1; } if (err && strstr (err, "invalid option -- m")) result = 0; else result = 1; return result; }
static char * get_blkid_tag (const char *device, const char *tag) { char *out, *err; int r; r = commandr (&out, &err, "blkid", /* Adding -c option kills all caching, even on RHEL 5. */ "-c", "/dev/null", "-o", "value", "-s", tag, device, NULL); if (r != 0 && r != 2) { if (r >= 0) reply_with_error ("%s: %s (blkid returned %d)", device, err, r); else reply_with_error ("%s: %s", device, err); free (out); free (err); return NULL; } free (err); if (r == 2) { /* means UUID etc not found */ free (out); out = strdup (""); if (out == NULL) reply_with_perror ("strdup"); return out; } /* Trim trailing \n if present. */ size_t len = strlen (out); if (len > 0 && out[len-1] == '\n') out[len-1] = '\0'; return out; /* caller frees */ }