summaryrefslogtreecommitdiff
path: root/util/nvmutil
diff options
context:
space:
mode:
Diffstat (limited to 'util/nvmutil')
-rw-r--r--util/nvmutil/nvmutil.c876
-rw-r--r--util/nvmutil/nvmutil.h37
2 files changed, 498 insertions, 415 deletions
diff --git a/util/nvmutil/nvmutil.c b/util/nvmutil/nvmutil.c
index 13e9113a..ecc003ac 100644
--- a/util/nvmutil/nvmutil.c
+++ b/util/nvmutil/nvmutil.c
@@ -42,9 +42,26 @@
* is passed. The rest of the program
* will manipulate this data.
*/
+/*
+TODO:
+eventually, i will not have this return
+a pointer at all. instead, a similar key
+mechanism will be used for other access
+functions e.g. word/set_word, err(needs
+to clean up), and so on. then those
+would return values if already initialised,
+but would not permit additional init - will
+decide exactly how to implement this at a
+later state.
+
+this is part of an ongoing effort to introduce
+extreme memory safety into this program.
+ */
struct xstate *
-new_xstate(void)
+xstatus(void)
{
+ static int first_run = 1;
+
static struct xstate us = {
/* .cmd (update cmd[] in the struct if adding to it)
DO NOT FORGET. or C will init zeroes/NULLs */
@@ -114,52 +131,41 @@ new_xstate(void)
};
- struct xstate *xs_new;
+ if (first_run) {
+ us.xsize = sizeof(us);
- us.xsize = sizeof(us);
+ us.f.buf = us.f.real_buf;
- xs_new = malloc(us.xsize);
- if (xs_new == NULL)
- err(ECANCELED, "Could not initialise new state");
+ us.f.gbe_fd = -1;
+ us.f.tmp_fd = -1;
- memcpy(xs_new, &us, us.xsize);
-
- /*
- * Some pointers should be set
- * in the copy, not the template,
- * if they point to other items
- * in the struct, because if they
- * were set before copy, then copied,
- * the copied pointer would be invalid,
- * referring to the reference struct
- *
- * e.g. ->f.buf (gbe tmp file work memory):
- */
-
- xs_new->f.buf = xs_new->f.real_buf;
-
- xs_new->f.gbe_fd = -1;
- xs_new->f.tmp_fd = -1;
+ us.f.tname = NULL;
+ us.f.fname = NULL;
+ }
- xs_new->f.tname = NULL;
- xs_new->f.fname = NULL;
+ first_run = 0;
- return xs_new;
+ return &us;
}
-static struct xstate *x = NULL;
-
int
main(int argc, char *argv[])
{
+ struct xstate *x;
struct commands *cmd;
struct xfile *f;
- int fd;
+ unsigned long i;
+
+ char *tmp_path;
+
struct stat st;
+ int fd;
- char *tmp_path = NULL;
+ tmp_path = NULL;
- unsigned long *i;
+#ifndef S_ISREG
+ err(ECANCELED, "Can't determine file types (S_ISREG undefined)");
+#endif
#ifndef CHAR_BIT
err(ECANCELED, "Unknown char size");
@@ -189,17 +195,15 @@ main(int argc, char *argv[])
#ifdef NVMUTIL_UNVEIL
if (pledge("stdio flock rpath wpath cpath unveil", NULL) == -1)
err(errno, "pledge, unveil");
- if (unveil("/dev/urandom", "r") == -1)
- err(errno, "unveil: /dev/urandom");
- if (unveil("/dev/random", "r") == -1)
- err(errno, "unveil: /dev/random");
+ if (unveil("/dev/null", "r") == -1)
+ err(errno, "unveil: /dev/null");
#else
if (pledge("stdio flock rpath wpath cpath", NULL) == -1)
err(errno, "pledge");
#endif
#endif
- x = new_xstate();
+ x = xstatus();
if (x == NULL)
err(errno, NULL);
@@ -224,8 +228,8 @@ main(int argc, char *argv[])
set_cmd(argc, argv);
set_cmd_args(argc, argv);
- i = &x->i;
- cmd = &x->cmd[*i];
+ i = x->i;
+ cmd = &x->cmd[i];
#ifdef NVMUTIL_UNVEIL
if ((cmd->flags & O_ACCMODE) == O_RDONLY) {
@@ -236,8 +240,8 @@ main(int argc, char *argv[])
err(errno, "%s: unveil rw", f->tname);
}
- if (unveil(tname, "rwc") == -1)
- err(errno, "%s: unveil rwc", tname);
+ if (unveil(f->tname, "rwc") == -1)
+ err(errno, "%s: unveil rwc", f->tname);
if (unveil(NULL, NULL) == -1)
err(errno, "unveil block (rw)");
@@ -246,8 +250,6 @@ main(int argc, char *argv[])
err(errno, "pledge (kill unveil)");
#endif
- srand((unsigned int)(time(NULL) ^ getpid()));
-
open_gbe_file();
memset(f->buf, 0, GBE_BUF_SIZE);
@@ -280,8 +282,12 @@ main(int argc, char *argv[])
void
sanitize_command_list(void)
{
+ struct xstate *x = xstatus();
+
unsigned long c;
- unsigned long num_commands = items(x->cmd);
+ unsigned long num_commands;
+
+ num_commands = items(x->cmd);
for (c = 0; c < num_commands; c++)
sanitize_command_index(c);
@@ -293,11 +299,13 @@ sanitize_command_list(void)
void
sanitize_command_index(unsigned long c)
{
- unsigned long gbe_rw_size;
-
- struct commands *cmd = &x->cmd[c];
+ struct xstate *x = xstatus();
+ struct commands *cmd;
int _flag;
+ unsigned long gbe_rw_size;
+
+ cmd = &x->cmd[c];
check_command_num(c);
@@ -352,22 +360,23 @@ sanitize_command_index(unsigned long c)
void
set_cmd(int argc, char *argv[])
{
+ struct xstate *x = xstatus();
const char *cmd;
- unsigned long i = 0;
+ unsigned long c;
- for (i = 0; i < items(x->cmd); i++) {
+ for (c = 0; c < items(x->cmd); c++) {
- cmd = x->cmd[i].str;
+ cmd = x->cmd[c].str;
/* not the right command */
if (xstrxcmp(argv[2], cmd, MAX_CMD_LEN) != 0)
continue;
/* valid command found */
- if (argc >= x->cmd[i].argc) {
+ if (argc >= x->cmd[c].argc) {
x->no_cmd = 0;
- x->i = i; /* set command */
+ x->i = c; /* set command */
return;
}
@@ -382,31 +391,27 @@ set_cmd(int argc, char *argv[])
void
set_cmd_args(int argc, char *argv[])
{
- unsigned char arg_part;
+ struct xstate *x = xstatus();
+ struct commands *cmd;
+ struct xfile *f;
unsigned long i;
- struct xfile *f;
- struct commands *cmd;
+ i = x->i;
+ cmd = &x->cmd[i];
+ f = &x->f;
- if (!valid_command(x->i) || argc < 3)
+ if (!valid_command(i) || argc < 3)
usage();
if (x->no_cmd)
usage();
- i = x->i;
- f = &x->f;
-
- cmd = &x->cmd[i];
-
- arg_part = cmd->arg_part;
-
/* Maintainer bugs */
- if (arg_part && argc < 4)
+ if (cmd->arg_part && argc < 4)
err(EINVAL,
"arg_part set for command that needs argc4");
- if (arg_part && i == CMD_SETMAC)
+ if (cmd->arg_part && i == CMD_SETMAC)
err(EINVAL,
"arg_part set on CMD_SETMAC");
@@ -417,7 +422,7 @@ set_cmd_args(int argc, char *argv[])
else
x->mac.str = x->mac.rmac;
- } else if (arg_part) {
+ } else if (cmd->arg_part) {
f->part = conv_argv_part_num(argv[3]);
}
@@ -455,6 +460,7 @@ xstrxcmp(const char *a, const char *b, unsigned long maxlen)
err(EINVAL, "Empty string in xstrxcmp");
for (i = 0; i < maxlen; i++) {
+
unsigned char ac = (unsigned char)a[i];
unsigned char bc = (unsigned char)b[i];
@@ -483,14 +489,15 @@ xstrxcmp(const char *a, const char *b, unsigned long maxlen)
void
open_gbe_file(void)
{
+ struct xstate *x = xstatus();
+ struct commands *cmd;
+ struct xfile *f;
+
struct stat _st;
int _flags;
- unsigned long *i = &x->i;
-
- struct commands *cmd = &x->cmd[*i];
-
- struct xfile *f = &x->f;
+ cmd = &x->cmd[x->i];
+ f = &x->f;
xopen(&f->gbe_fd, f->fname,
cmd->flags | O_BINARY |
@@ -601,7 +608,10 @@ xopen(int *fd_ptr, const char *path, int flags, struct stat *st)
void
copy_gbe(void)
{
- struct xfile *f = &x->f;
+ struct xstate *x = xstatus();
+ struct xfile *f;
+
+ f = &x->f;
read_file();
@@ -626,10 +636,13 @@ copy_gbe(void)
void
read_file(void)
{
- long _r;
+ struct xstate *x = xstatus();
+ struct xfile *f;
+
struct stat _st;
+ long _r;
- struct xfile *f = &x->f;
+ f = &x->f;
/* read main file */
_r = rw_file_exact(f->gbe_fd, f->buf, f->gbe_file_size,
@@ -684,13 +697,18 @@ read_file(void)
void
read_checksums(void)
{
+ struct xstate *x = xstatus();
+ struct commands *cmd;
+ struct xfile *f;
+
unsigned long _p;
unsigned long _skip_part;
+
unsigned char _num_invalid;
unsigned char _max_invalid;
- struct xfile *f = &x->f;
- struct commands *cmd = &x->cmd[x->i];
+ cmd = &x->cmd[x->i];
+ f = &x->f;
f->part_valid[0] = 0;
f->part_valid[1] = 0;
@@ -734,30 +752,41 @@ read_checksums(void)
int
good_checksum(unsigned long partnum)
{
- unsigned short expected_checksum =
+ unsigned short expected_checksum;
+ unsigned short actual_checksum;
+
+ expected_checksum =
calculated_checksum(partnum);
- unsigned short current_checksum =
+ actual_checksum =
nvm_word(NVM_CHECKSUM_WORD, partnum);
- return current_checksum == expected_checksum;
+ if (expected_checksum == actual_checksum) {
+ return 1;
+ } else {
+ return 0;
+ }
}
void
run_cmd(void)
{
- unsigned long cmd_num;
- struct commands *cmd;
+ struct xstate *x = xstatus();
+ unsigned long i;
+ void (*run)(void);
- cmd_num = x->i;
- cmd = &x->cmd[cmd_num];
+ i = x->i;
+ run = x->cmd[i].run;
- check_command_num(cmd_num);
+ check_command_num(i);
- if (cmd->run == NULL)
- err(EINVAL, "Command %lu: null ptr", cmd_num);
+ if (run == NULL)
+ err(EINVAL, "Command %lu: null ptr", i);
- cmd->run();
+ run();
+
+ for (i = 0; i < items(x->cmd); i++)
+ x->cmd[i].run = cmd_helper_err;
}
void
@@ -771,6 +800,7 @@ check_command_num(unsigned long c)
unsigned char
valid_command(unsigned long c)
{
+ struct xstate *x = xstatus();
struct commands *cmd;
if (c >= items(x->cmd))
@@ -789,8 +819,11 @@ valid_command(unsigned long c)
void
cmd_helper_setmac(void)
{
+ struct xstate *x = xstatus();
unsigned long partnum;
- struct macaddr *mac = &x->mac;
+ struct macaddr *mac;
+
+ mac = &x->mac;
check_cmd(cmd_helper_setmac, "setmac");
@@ -804,9 +837,12 @@ cmd_helper_setmac(void)
void
parse_mac_string(void)
{
+ struct xstate *x = xstatus();
+ struct macaddr *mac;
+
unsigned long mac_byte;
- struct macaddr *mac = &x->mac;
+ mac = &x->mac;
if (xstrxlen(x->mac.str, 18) != 17)
err(EINVAL, "MAC address is the wrong length");
@@ -853,11 +889,17 @@ xstrxlen(const char *scmp, unsigned long maxlen)
void
set_mac_byte(unsigned long mac_byte_pos)
{
- unsigned long mac_str_pos = mac_byte_pos * 3;
- unsigned long mac_nib_pos;
+ struct xstate *x = xstatus();
+ struct macaddr *mac;
+
char separator;
- struct macaddr *mac = &x->mac;
+ unsigned long mac_str_pos;
+ unsigned long mac_nib_pos;
+
+ mac = &x->mac;
+
+ mac_str_pos = mac_byte_pos * 3;
if (mac_str_pos < 15) {
if ((separator = mac->str[mac_str_pos + 2]) != ':')
@@ -873,10 +915,13 @@ void
set_mac_nib(unsigned long mac_str_pos,
unsigned long mac_byte_pos, unsigned long mac_nib_pos)
{
+ struct xstate *x = xstatus();
+ struct macaddr *mac;
+
char mac_ch;
unsigned short hex_num;
- struct macaddr *mac = &x->mac;
+ mac = &x->mac;
mac_ch = mac->str[mac_str_pos + mac_nib_pos];
@@ -904,7 +949,9 @@ set_mac_nib(unsigned long mac_str_pos,
unsigned short
hextonum(char ch_s)
{
- unsigned char ch = (unsigned char)ch_s;
+ unsigned char ch;
+
+ ch = (unsigned char)ch_s;
if ((unsigned int)(ch - '0') <= 9)
return ch - '0';
@@ -923,125 +970,59 @@ hextonum(char ch_s)
unsigned long
rlong(void)
{
- struct x_st_timeval tv;
- static unsigned long mix = 0;
- static unsigned long counter = 0;
-
- static int fd = -1;
- unsigned long rval = 0;
- long nr = -1;
+#if (defined(__OpenBSD__) && (OpenBSD) >= 201) || \
+ defined(__FreeBSD__) || \
+ defined(__NetBSD__) || defined(__APPLE__)
- x_i_gettimeofday(&tv, NULL);
+ unsigned long rval;
+ arc4random_buf(&rval, sizeof(unsigned long));
- mix ^= (unsigned long)tv.tv_sec
- ^ (unsigned long)tv.tv_usec
- ^ (unsigned long)getpid()
- ^ (unsigned long)&mix
- ^ counter++
- ^ entropy_jitter();
+ return rval;
+#else
+ int fd;
- /*
- * Stack addresses can vary between
- * calls, thus increasing entropy.
- */
- mix ^= (unsigned long)&mix;
- mix ^= (unsigned long)&tv;
- mix ^= (unsigned long)&counter;
+ long nr;
- /*
- * Now, we won't use this mix
- * immediately. We'll try to
- * read urandom first, which is
- * likely safer, and pass that,
- * falling back to the mixture
- * if urandom fails.
- *
- * Since urandom is likely
- * reliable, the number of
- * times it will fail is
- * likely extremely random,
- * thus, building more than
- * sufficient entropy by the
- * time we do eventually use
- * the fallback code
- */
+ unsigned long rval;
- if (fd < 0)
- fd = open("/dev/urandom", O_RDONLY | O_BINARY | O_NONBLOCK);
+ fd = open("/dev/urandom", O_RDONLY | O_BINARY);
-#if !(defined(__OpenBSD__) && defined(OpenBSD)) || \
- (defined(__OpenBSD__) && defined(OpenBSD) && \
- OpenBSD < 604)
+#ifdef __OpenBSD__
if (fd < 0) /* old openbsd */
- fd = open("/dev/arandom", O_RDONLY | O_BINARY | O_NONBLOCK);
+ fd = open("/dev/arandom", O_RDONLY | O_BINARY);
#endif
if (fd < 0)
- fd = open("/dev/random", O_RDONLY | O_BINARY | O_NONBLOCK);
+ fd = open("/dev/random", O_RDONLY | O_BINARY);
+
+ if (fd < 0)
+ err(errno, "can't open random device");
nr = rw_file_exact(fd, (unsigned char *)&rval,
sizeof(unsigned long), 0, IO_READ, LOOP_EAGAIN,
LOOP_EINTR, MAX_ZERO_RW_RETRY, OFF_ERR);
- if (nr == sizeof(unsigned long))
- return rval;
-
- return mix;
-}
-
-unsigned long
-entropy_jitter(void)
-{
- struct x_st_timeval a, b;
- unsigned long mix = 0;
- long mix_diff;
- int i;
-
- x_i_gettimeofday(&a, NULL);
-
- for (i = 0; i < 32; i++) {
- getpid();
- x_i_gettimeofday(&b, NULL);
-
- /*
- * prevent negative numbers to prevent overflow,
- * which would bias rand to large numbers
- */
- mix_diff = (long)(b.tv_usec - a.tv_usec);
- if (mix_diff < 0)
- mix_diff = -mix_diff;
-
- mix ^= (unsigned long)(mix_diff);
- mix ^= (unsigned long)&mix;
- }
-
- return mix;
-}
-
-
-
-int
-x_i_gettimeofday(struct x_st_timeval *tv, void *tz)
-{
- time_t t;
-
- (void)tz;
+ if (x_i_close(fd) < 0)
+ err(errno, "Can't close randomness fd");
- t = time(NULL);
+ if (nr != sizeof(unsigned long))
+ err(errno, "Incomplete read from random device");
- tv->tv_sec = t;
- tv->tv_usec = (long)((unsigned long)clock() % 1000000UL);
-
- return 0;
+ return rval;
+#endif
}
void
write_mac_part(unsigned long partnum)
{
+ struct xstate *x = xstatus();
+ struct xfile *f;
+ struct macaddr *mac;
+
unsigned long w;
- struct xfile *f = &x->f;
- struct macaddr *mac = &x->mac;
+ f = &x->f;
+ mac = &x->mac;
check_bin(partnum, "part number");
if (!f->part_valid[partnum])
@@ -1058,27 +1039,35 @@ write_mac_part(unsigned long partnum)
void
cmd_helper_dump(void)
{
- unsigned long partnum;
+ struct xstate *x = xstatus();
+ struct xfile *f;
- struct xfile *f = &x->f;
+ unsigned long p;
+
+ f = &x->f;
check_cmd(cmd_helper_dump, "dump");
f->part_valid[0] = good_checksum(0);
f->part_valid[1] = good_checksum(1);
- for (partnum = 0; partnum < 2; partnum++) {
- if (!f->part_valid[partnum])
+ for (p = 0; p < 2; p++) {
+
+ if (!f->part_valid[p]) {
+
fprintf(stderr,
"BAD checksum %04x in part %lu (expected %04x)\n",
- nvm_word(NVM_CHECKSUM_WORD, partnum),
- (unsigned long)partnum,
- calculated_checksum(partnum));
+ nvm_word(NVM_CHECKSUM_WORD, p),
+ (unsigned long)p,
+ calculated_checksum(p));
+ }
printf("MAC (part %lu): ",
- (unsigned long)partnum);
- print_mac_from_nvm(partnum);
- hexdump(partnum);
+ (unsigned long)p);
+
+ print_mac_from_nvm(p);
+
+ hexdump(p);
}
}
@@ -1108,15 +1097,23 @@ hexdump(unsigned long partnum)
unsigned short val16;
for (row = 0; row < 8; row++) {
- printf("%08lx ", (unsigned long)((unsigned long)row << 4));
+
+ printf("%08lx ",
+ (unsigned long)((unsigned long)row << 4));
+
for (c = 0; c < 8; c++) {
+
val16 = nvm_word((row << 3) + c, partnum);
+
if (c == 4)
printf(" ");
+
printf(" %02x %02x",
(unsigned int)(val16 & 0xff),
(unsigned int)(val16 >> 8));
+
}
+
printf("\n");
}
}
@@ -1124,10 +1121,13 @@ hexdump(unsigned long partnum)
void
cmd_helper_swap(void)
{
- struct xfile *f = &x->f;
+ struct xstate *x = xstatus();
+ struct xfile *f;
check_cmd(cmd_helper_swap, "swap");
+ f = &x->f;
+
x_v_memcpy(
f->buf + (unsigned long)GBE_WORK_SIZE,
f->buf,
@@ -1150,10 +1150,13 @@ cmd_helper_swap(void)
void
cmd_helper_copy(void)
{
- struct xfile *f = &x->f;
+ struct xstate *x = xstatus();
+ struct xfile *f;
check_cmd(cmd_helper_copy, "copy");
+ f = &x->f;
+
x_v_memcpy(
f->buf + (unsigned long)((f->part ^ 1) * GBE_PART_SIZE),
f->buf + (unsigned long)(f->part * GBE_PART_SIZE),
@@ -1163,7 +1166,9 @@ cmd_helper_copy(void)
}
void
-cmd_helper_cat(void) {
+cmd_helper_cat(void)
+{
+ struct xstate *x = xstatus();
check_cmd(cmd_helper_cat, "cat");
x->cat = 0;
@@ -1171,7 +1176,9 @@ cmd_helper_cat(void) {
}
void
-cmd_helper_cat16(void) {
+cmd_helper_cat16(void)
+{
+ struct xstate *x = xstatus();
check_cmd(cmd_helper_cat16, "cat16");
x->cat = 1;
@@ -1179,7 +1186,9 @@ cmd_helper_cat16(void) {
}
void
-cmd_helper_cat128(void) {
+cmd_helper_cat128(void)
+{
+ struct xstate *x = xstatus();
check_cmd(cmd_helper_cat128, "cat128");
x->cat = 15;
@@ -1187,50 +1196,76 @@ cmd_helper_cat128(void) {
}
void
-check_cmd(void (*fn)(void), const char *name)
+check_cmd(void (*fn)(void),
+ const char *name)
{
+ struct xstate *x = xstatus();
+ unsigned long i;
+
if (x->cmd[x->i].run != fn)
err(ECANCELED, "Running %s, but cmd %s is set",
name, x->cmd[x->i].str);
+
+ /*
+ * In addition to making sure we ran
+ * the right command, we now disable
+ * all commands from running again
+ *
+ * the _nop function will just call
+ * err() immediately
+ */
+
+ for (i = 0; i < items(x->cmd); i++)
+ x->cmd[i].run = cmd_helper_err;
+}
+
+void
+cmd_helper_err(void)
+{
+ err(ECANCELED,
+ "Erroneously running command twice");
}
void
cat(unsigned long nff)
{
- struct xfile *f = &x->f;
- struct commands *cmd = &x->cmd[x->i];
+ struct xstate *x = xstatus();
+ struct xfile *f;
+
+ unsigned long p;
+ unsigned long ff;
+
+ f = &x->f;
+
+ p = 0;
+ ff = 0;
- unsigned long p = 0;
- unsigned long ff = 0;
+ if ((unsigned long)x->cat != nff) {
- if ((unsigned long)x->cat != nff ||
- !((cmd->run == cmd_helper_cat && nff == 0) ||
- (cmd->run == cmd_helper_cat16 && nff == 1) ||
- (cmd->run == cmd_helper_cat128 && nff == 15)))
err(ECANCELED, "erroneous call to cat");
+ }
fflush(NULL);
memset(f->pad, 0xff, GBE_PART_SIZE);
for (p = 0; p < 2; p++) {
+
cat_buf(f->bufcmp +
(unsigned long)(p * (f->gbe_file_size >> 1)));
- for (ff = 0; ff < nff; ff++)
+ for (ff = 0; ff < nff; ff++) {
+
cat_buf(f->pad);
+ }
}
}
void
cat_buf(unsigned char *b)
{
- struct commands *cmd = &x->cmd[x->i];
-
- if (!((cmd->run == cmd_helper_cat && x->cat == 0) ||
- (cmd->run == cmd_helper_cat16 && x->cat == 1) ||
- (cmd->run == cmd_helper_cat128 && x->cat == 15)))
- err(ECANCELED, "erroneous call to cat");
+ if (b == NULL)
+ err(errno, "null pointer in cat command");
if (rw_file_exact(STDOUT_FILENO, b,
GBE_PART_SIZE, 0, IO_WRITE, LOOP_EAGAIN, LOOP_EINTR,
@@ -1241,14 +1276,18 @@ cat_buf(unsigned char *b)
void
write_gbe_file(void)
{
+ struct xstate *x = xstatus();
+ struct commands *cmd;
+ struct xfile *f;
+
struct stat _gbe_st;
struct stat _tmp_st;
unsigned long p;
unsigned char update_checksum;
- struct commands *cmd = &x->cmd[x->i];
- struct xfile *f = &x->f;
+ cmd = &x->cmd[x->i];
+ f = &x->f;
if ((cmd->flags & O_ACCMODE) == O_RDONLY)
return;
@@ -1295,7 +1334,9 @@ unsigned short
calculated_checksum(unsigned long p)
{
unsigned long c;
- unsigned int val16 = 0;
+ unsigned int val16;
+
+ val16 = 0;
for (c = 0; c < NVM_CHECKSUM_WORD; c++)
val16 += (unsigned int)nvm_word(c, p);
@@ -1314,10 +1355,13 @@ calculated_checksum(unsigned long p)
unsigned short
nvm_word(unsigned long pos16, unsigned long p)
{
- struct xfile *f = &x->f;
+ struct xstate *x = xstatus();
+ struct xfile *f;
unsigned long pos;
+ f = &x->f;
+
check_nvm_bound(pos16, p);
pos = (pos16 << 1) + (p * GBE_PART_SIZE);
@@ -1328,9 +1372,13 @@ nvm_word(unsigned long pos16, unsigned long p)
void
set_nvm_word(unsigned long pos16, unsigned long p, unsigned short val16)
{
- struct xfile *f = &x->f;
+ struct xstate *x = xstatus();
+ struct xfile *f;
+
unsigned long pos;
+ f = &x->f;
+
check_nvm_bound(pos16, p);
pos = (pos16 << 1) + (p * GBE_PART_SIZE);
@@ -1343,7 +1391,10 @@ set_nvm_word(unsigned long pos16, unsigned long p, unsigned short val16)
void
set_part_modified(unsigned long p)
{
- struct xfile *f = &x->f;
+ struct xstate *x = xstatus();
+ struct xfile *f;
+
+ f = &x->f;
check_bin(p, "part number");
f->part_modified[p] = 1;
@@ -1377,15 +1428,19 @@ void
rw_gbe_file_part(unsigned long p, int rw_type,
const char *rw_type_str)
{
- struct xfile *f = &x->f;
- struct commands *cmd = &x->cmd[x->i];
+ struct xstate *x = xstatus();
+ struct commands *cmd;
+ struct xfile *f;
- long r;
- unsigned long gbe_rw_size;
+ long rval;
+
+ off_t file_offset;
+ unsigned long gbe_rw_size;
unsigned char *mem_offset;
- off_t file_offset;
+ cmd = &x->cmd[x->i];
+ f = &x->f;
gbe_rw_size = cmd->rw_size;
@@ -1396,14 +1451,14 @@ rw_gbe_file_part(unsigned long p, int rw_type,
mem_offset = gbe_mem_offset(p, rw_type_str);
file_offset = (off_t)gbe_file_offset(p, rw_type_str);
- r = rw_gbe_file_exact(f->tmp_fd, mem_offset,
+ rval = rw_gbe_file_exact(f->tmp_fd, mem_offset,
gbe_rw_size, file_offset, rw_type);
- if (r == -1)
+ if (rval == -1)
err(errno, "%s: %s: part %lu",
f->fname, rw_type_str, (unsigned long)p);
- if ((unsigned long)r != gbe_rw_size)
+ if ((unsigned long)rval != gbe_rw_size)
err(EIO, "%s: partial %s: part %lu",
f->fname, rw_type_str, (unsigned long)p);
}
@@ -1411,12 +1466,15 @@ rw_gbe_file_part(unsigned long p, int rw_type,
void
write_to_gbe_bin(void)
{
- struct xfile *f = &x->f;
+ struct xstate *x = xstatus();
+ struct commands *cmd;
+ struct xfile *f;
int saved_errno;
int mv;
- struct commands *cmd = &x->cmd[x->i];
+ cmd = &x->cmd[x->i];
+ f = &x->f;
if ((cmd->flags & O_ACCMODE) != O_RDWR)
return;
@@ -1503,16 +1561,22 @@ write_to_gbe_bin(void)
void
check_written_part(unsigned long p)
{
- struct commands *cmd = &x->cmd[x->i];
- struct xfile *f = &x->f;
+ struct xstate *x = xstatus();
+ struct commands *cmd;
+ struct xfile *f;
+
+ long rval;
unsigned long gbe_rw_size;
- unsigned char *mem_offset;
+
off_t file_offset;
- unsigned char *buf_restore;
+ unsigned char *mem_offset;
+
struct stat st;
+ unsigned char *buf_restore;
- long r;
+ cmd = &x->cmd[x->i];
+ f = &x->f;
if (!f->part_modified[p])
return;
@@ -1534,12 +1598,12 @@ check_written_part(unsigned long p)
if (st.st_dev != f->tmp_dev || st.st_ino != f->tmp_ino)
err(EIO, "%s: file changed during write", f->tname);
- r = rw_gbe_file_exact(f->tmp_fd, f->pad,
+ rval = rw_gbe_file_exact(f->tmp_fd, f->pad,
gbe_rw_size, file_offset, IO_PREAD);
- if (r == -1)
+ if (rval == -1)
f->rw_check_err_read[p] = f->io_err_gbe = 1;
- else if ((unsigned long)r != gbe_rw_size)
+ else if ((unsigned long)rval != gbe_rw_size)
f->rw_check_partial_read[p] = f->io_err_gbe = 1;
else if (x_i_memcmp(mem_offset, f->pad, gbe_rw_size) != 0)
f->rw_check_bad_part[p] = f->io_err_gbe = 1;
@@ -1554,18 +1618,29 @@ check_written_part(unsigned long p)
* That's why we hardcode good_checksum(0).
*/
buf_restore = f->buf;
+
+ /*
+ * good_checksum works on f->buf
+ * so let's change f->buf for now
+ */
f->buf = f->pad;
- f->post_rw_checksum[p] = good_checksum(0);
+
+ if (good_checksum(0))
+ f->post_rw_checksum[p] = 1;
+
f->buf = buf_restore;
}
void
report_io_err_rw(void)
{
- struct xfile *f = &x->f;
+ struct xstate *x = xstatus();
+ struct xfile *f;
unsigned long p;
+ f = &x->f;
+
if (!f->io_err_gbe)
return;
@@ -1617,20 +1692,30 @@ report_io_err_rw(void)
int
gbe_mv(void)
{
- struct xfile *f = &x->f;
+ struct xstate *x = xstatus();
+ struct xfile *f;
+
+ int rval;
- int r;
int saved_errno;
- int tmp_gbe_bin_exists = 1;
+ int tmp_gbe_bin_exists;
+
+ char *dest_tmp;
+ int dest_fd;
- char *dest_tmp = NULL;
- int dest_fd = -1;
+ f = &x->f;
+
+ /* will be set 0 if it doesn't */
+ tmp_gbe_bin_exists = 1;
+
+ dest_tmp = NULL;
+ dest_fd = -1;
saved_errno = errno;
- r = rename(f->tname, f->fname);
+ rval = rename(f->tname, f->fname);
- if (r > -1) {
+ if (rval > -1) {
/*
* same filesystem
*/
@@ -1639,7 +1724,7 @@ gbe_mv(void)
if (fsync_dir(f->fname) < 0) {
f->io_err_gbe_bin = 1;
- r = -1;
+ rval = -1;
}
goto ret_gbe_mv;
@@ -1650,7 +1735,7 @@ gbe_mv(void)
/* cross-filesystem rename */
- if ((r = f->tmp_fd = open(f->tname,
+ if ((rval = f->tmp_fd = open(f->tname,
O_RDONLY | O_BINARY)) == -1)
goto ret_gbe_mv;
@@ -1661,20 +1746,20 @@ gbe_mv(void)
/* copy data */
- r = rw_file_exact(f->tmp_fd, f->bufcmp,
+ rval = rw_file_exact(f->tmp_fd, f->bufcmp,
f->gbe_file_size, 0, IO_PREAD,
NO_LOOP_EAGAIN, LOOP_EINTR,
MAX_ZERO_RW_RETRY, OFF_ERR);
- if (r < 0)
+ if (rval < 0)
goto ret_gbe_mv;
- r = rw_file_exact(dest_fd, f->bufcmp,
+ rval = rw_file_exact(dest_fd, f->bufcmp,
f->gbe_file_size, 0, IO_PWRITE,
NO_LOOP_EAGAIN, LOOP_EINTR,
MAX_ZERO_RW_RETRY, OFF_ERR);
- if (r < 0)
+ if (rval < 0)
goto ret_gbe_mv;
if (x_i_fsync(dest_fd) == -1)
@@ -1698,17 +1783,17 @@ ret_gbe_mv:
if (f->gbe_fd > -1) {
if (x_i_close(f->gbe_fd) < 0)
- r = -1;
+ rval = -1;
if (fsync_dir(f->fname) < 0) {
f->io_err_gbe_bin = 1;
- r = -1;
+ rval = -1;
}
f->gbe_fd = -1;
}
if (f->tmp_fd > -1) {
if (x_i_close(f->tmp_fd) < 0)
- r = -1;
+ rval = -1;
f->tmp_fd = -1;
}
@@ -1719,12 +1804,12 @@ ret_gbe_mv:
*/
if (tmp_gbe_bin_exists) {
if (unlink(f->tname) < 0)
- r = -1;
+ rval = -1;
else
tmp_gbe_bin_exists = 0;
}
- if (r < 0) {
+ if (rval < 0) {
/*
* if nothing set errno,
* we assume EIO, or we
@@ -1736,7 +1821,7 @@ ret_gbe_mv:
errno = saved_errno;
}
- return r;
+ return rval;
}
/*
@@ -1746,21 +1831,27 @@ ret_gbe_mv:
int
fsync_dir(const char *path)
{
-#if defined(PATH_LEN) && \
- (PATH_LEN) >= 256
- unsigned long maxlen = PATH_LEN;
-#else
- unsigned long maxlen = 1024;
-#endif
+ int saved_errno = errno;
+
unsigned long pathlen;
-/* char dirbuf[maxlen]; */
- char *dirbuf = NULL;
+ unsigned long maxlen;
+
+ char *dirbuf;
+ int dirfd;
+
char *slash;
- int dfd = -1;
struct stat st;
- int saved_errno = errno;
+#if defined(PATH_LEN) && \
+ (PATH_LEN) >= 256
+ maxlen = PATH_LEN;
+#else
+ maxlen = 1024;
+#endif
+
+ dirbuf = NULL;
+ dirfd = -1;
pathlen = xstrxlen(path, maxlen);
@@ -1793,7 +1884,7 @@ fsync_dir(const char *path)
dirbuf[1] = '\0';
}
- dfd = open(dirbuf, O_RDONLY
+ dirfd = open(dirbuf, O_RDONLY
#ifdef O_DIRECTORY
| O_DIRECTORY
#endif
@@ -1801,10 +1892,10 @@ fsync_dir(const char *path)
| O_NOFOLLOW
#endif
);
- if (dfd == -1)
+ if (dirfd == -1)
goto err_fsync_dir;
- if (fstat(dfd, &st) < 0)
+ if (fstat(dirfd, &st) < 0)
goto err_fsync_dir;
if (!S_ISDIR(st.st_mode)) {
@@ -1813,10 +1904,10 @@ fsync_dir(const char *path)
}
/* sync file on disk */
- if (x_i_fsync(dfd) == -1)
+ if (x_i_fsync(dirfd) == -1)
goto err_fsync_dir;
- if (x_i_close(dfd) == -1)
+ if (x_i_close(dirfd) == -1)
goto err_fsync_dir;
if (dirbuf != NULL)
@@ -1835,8 +1926,8 @@ err_fsync_dir:
if (dirbuf != NULL)
free(dirbuf);
- if (dfd > -1)
- x_i_close(dfd);
+ if (dirfd > -1)
+ x_i_close(dirfd);
errno = saved_errno;
@@ -1851,12 +1942,18 @@ err_fsync_dir:
unsigned char *
gbe_mem_offset(unsigned long p, const char *f_op)
{
- struct xfile *f = &x->f;
+ struct xstate *x = xstatus();
+ struct xfile *f;
+
+ off_t gbe_off;
- off_t gbe_off = gbe_x_offset(p, f_op, "mem",
+ f = &x->f;
+
+ gbe_off = gbe_x_offset(p, f_op, "mem",
GBE_PART_SIZE, GBE_WORK_SIZE);
- return (unsigned char *)(f->buf + (unsigned long)gbe_off);
+ return (unsigned char *)
+ (f->buf + (unsigned long)gbe_off);
}
/*
@@ -1869,9 +1966,14 @@ gbe_mem_offset(unsigned long p, const char *f_op)
off_t
gbe_file_offset(unsigned long p, const char *f_op)
{
- struct xfile *f = &x->f;
+ struct xstate *x = xstatus();
+ struct xfile *f;
+
+ off_t gbe_file_half_size;
+
+ f = &x->f;
- off_t gbe_file_half_size = f->gbe_file_size >> 1;
+ gbe_file_half_size = f->gbe_file_size >> 1;
return gbe_x_offset(p, f_op, "file",
gbe_file_half_size, f->gbe_file_size);
@@ -1881,12 +1983,15 @@ off_t
gbe_x_offset(unsigned long p, const char *f_op, const char *d_type,
off_t nsize, off_t ncmp)
{
- struct xfile *f = &x->f;
+ struct xstate *x = xstatus();
+ struct xfile *f;
off_t off;
check_bin(p, "part number");
+ f = &x->f;
+
off = ((off_t)p) * (off_t)nsize;
if (off > ncmp - GBE_PART_SIZE)
@@ -1904,10 +2009,13 @@ long
rw_gbe_file_exact(int fd, unsigned char *mem, unsigned long nrw,
off_t off, int rw_type)
{
- struct xfile *f = &x->f;
+ struct xstate *x = xstatus();
+ struct xfile *f;
long r;
+ f = &x->f;
+
if (io_args(fd, mem, nrw, off, rw_type) == -1)
return -1;
@@ -1975,23 +2083,31 @@ rw_file_exact(int fd, unsigned char *mem, unsigned long nrw,
int loop_eintr, unsigned long max_retries,
int off_reset)
{
- long rv = 0;
- long rc = 0;
- unsigned long retries_on_zero = 0;
- off_t off_cur;
+ long rval;
+ long rc;
+
unsigned long nrw_cur;
+
+ off_t off_cur;
void *mem_cur;
+ unsigned long retries_on_zero;
+
+ rval = 0;
+
+ rc = 0;
+ retries_on_zero = 0;
+
if (io_args(fd, mem, nrw, off, rw_type) == -1)
return -1;
while (1) {
/* Prevent theoretical overflow */
- if (rv >= 0 && (unsigned long)rv > (nrw - rc))
+ if (rval >= 0 && (unsigned long)rval > (nrw - rc))
goto err_rw_file_exact;
- rc += rv;
+ rc += rval;
if ((unsigned long)rc >= nrw)
break;
@@ -2001,14 +2117,14 @@ rw_file_exact(int fd, unsigned char *mem, unsigned long nrw,
goto err_rw_file_exact;
off_cur = off + (off_t)rc;
- rv = prw(fd, mem_cur, nrw_cur, off_cur,
+ rval = prw(fd, mem_cur, nrw_cur, off_cur,
rw_type, loop_eagain, loop_eintr,
off_reset);
- if (rv < 0)
+ if (rval < 0)
return -1;
- if (rv == 0) {
+ if (rval == 0) {
if (retries_on_zero++ < max_retries)
continue;
goto err_rw_file_exact;
@@ -2075,6 +2191,12 @@ prw(int fd, void *mem, unsigned long nrw,
int loop_eagain, int loop_eintr,
int off_reset)
{
+#ifndef MAX_EAGAIN_RETRIES
+ unsigned long retries = 100000;
+#else
+ unsigned long retries = MAX_EAGAIN_RETRIES;
+#endif
+
long r;
int positional_rw;
struct stat st;
@@ -2086,8 +2208,10 @@ prw(int fd, void *mem, unsigned long nrw,
off_t off_last;
#endif
- if (io_args(fd, mem, nrw, off, rw_type) == -1)
+ if (io_args(fd, mem, nrw, off, rw_type)
+ == -1) {
return -1;
+ }
r = -1;
@@ -2200,8 +2324,9 @@ real_pread_pwrite:
}
} while (r == -1 &&
- (errno == try_err(loop_eintr, EINTR)
- || errno == try_err(loop_eagain, EAGAIN)));
+ (errno == try_err(loop_eintr, EINTR) ||
+ errno == try_err(loop_eagain, EAGAIN)) &&
+ retries++ < MAX_EAGAIN_RETRIES);
}
saved_errno = errno;
@@ -2298,7 +2423,9 @@ rw_over_nrw(long r, unsigned long nrw)
if (r == -1)
return r;
- if ((unsigned long)r > X_LONG_MAX) {
+ if ((unsigned long)
+ r > X_LONG_MAX) {
+
/*
* Theoretical buggy libc
* check. Extremely academic.
@@ -2341,7 +2468,9 @@ off_t
lseek_loop(int fd, off_t off, int whence,
int loop_eagain, int loop_eintr)
{
- off_t old = -1;
+ off_t old;
+
+ old = -1;
do {
old = lseek(fd, off, whence);
@@ -2374,7 +2503,9 @@ try_err(int loop_err, int errval)
void
usage(void)
{
- const char *util = getnvmprogname();
+ const char *util;
+
+ util = getnvmprogname();
fprintf(stderr,
"Modify Intel GbE NVM images e.g. set MAC\n"
@@ -2395,6 +2526,8 @@ usage(void)
void
err(int nvm_errval, const char *msg, ...)
{
+ struct xstate *x = xstatus();
+
va_list args;
if (errno == 0)
@@ -2404,7 +2537,8 @@ err(int nvm_errval, const char *msg, ...)
(void)exit_cleanup();
- fprintf(stderr, "%s: ", getnvmprogname());
+ if (x != NULL)
+ fprintf(stderr, "%s: ", getnvmprogname());
va_start(args, msg);
vfprintf(stderr, msg, args);
@@ -2418,10 +2552,14 @@ err(int nvm_errval, const char *msg, ...)
int
exit_cleanup(void)
{
+ struct xstate *x = xstatus();
struct xfile *f;
- int close_err = 0;
- int saved_errno = errno;
+ int close_err;
+ int saved_errno;
+
+ close_err = 0;
+ saved_errno = errno;
if (x != NULL) {
f = &x->f;
@@ -2457,17 +2595,25 @@ exit_cleanup(void)
const char *
getnvmprogname(void)
{
+ struct xstate *x = xstatus();
const char *p;
+ static char fallback[] = "nvmutil";
+
+ char *rval = fallback;
- if (x->argv0 == NULL || *x->argv0 == '\0')
- return "";
+ if (x != NULL) {
+ if (x->argv0 == NULL || *x->argv0 == '\0')
+ return "";
+
+ rval = x->argv0;
+ }
- p = x_c_strrchr(x->argv0, '/');
+ p = x_c_strrchr(rval, '/');
if (p)
return p + 1;
else
- return x->argv0;
+ return rval;
}
/*
@@ -2558,7 +2704,7 @@ new_tmpfile(int *fd, int local, const char *path)
/*
* appended to filename for tmp:
*/
- tmpdir_len = sizeof(default_tmpname);
+ tmpdir_len = xstrxlen(default_tmpname, maxlen);
} else {
base = x_c_tmpdir();
@@ -2610,7 +2756,7 @@ new_tmpfile(int *fd, int local, const char *path)
if (fd_tmp == -1)
goto err_new_tmpfile;
- if (x_i_fchmod(fd_tmp, 0600) == -1)
+ if (fchmod(fd_tmp, 0600) == -1)
goto err_new_tmpfile;
flags = fcntl(fd_tmp, F_GETFL);
@@ -2696,7 +2842,7 @@ x_i_mkstemp(char *template)
for (j = 0; j < 6; j++) {
r = rlong();
- p[j] = ch[r % (sizeof(ch) - 1)];
+ p[j] = ch[(unsigned long)(r >> 1) % (sizeof(ch) - 1)];
}
fd = open(template, O_RDWR | O_CREAT | O_EXCL, 0600);
@@ -2740,7 +2886,7 @@ x_c_strrchr(const char *s, int c)
int
x_i_rename(const char *src, const char *dst)
{
- int sfd, dfd;
+ int sfd, dirfd;
ssize_t r;
char buf[8192];
@@ -2748,31 +2894,31 @@ x_i_rename(const char *src, const char *dst)
if (sfd < 0)
return -1;
- dfd = open(dst, O_WRONLY | O_CREAT | O_TRUNC, 0600);
- if (dfd < 0) {
+ dirfd = open(dst, O_WRONLY | O_CREAT | O_TRUNC, 0600);
+ if (dirfd < 0) {
x_i_close(sfd);
return -1;
}
while ((r = read(sfd, buf, sizeof(buf))) > 0) {
- ssize_t w = write(dfd, buf, r);
+ ssize_t w = write(dirfd, buf, r);
if (w != r) {
x_i_close(sfd);
- x_i_close(dfd);
+ x_i_close(dirfd);
return -1;
}
}
if (r < 0) {
x_i_close(sfd);
- x_i_close(dfd);
+ x_i_close(dirfd);
return -1;
}
- x_i_fsync(dfd);
+ x_i_fsync(dirfd);
x_i_close(sfd);
- x_i_close(dfd);
+ x_i_close(dirfd);
if (unlink(src) < 0)
return -1;
@@ -2788,9 +2934,13 @@ x_c_tmpdir(void)
struct stat st;
t = getenv("TMPDIR");
+ t = getenv("TMPDIR");
if (t && *t) {
- if (stat(t, &st) == 0 && S_ISDIR(st.st_mode))
+ if (stat(t, &st) == 0 && S_ISDIR(st.st_mode)) {
+ if ((st.st_mode & S_IWOTH) && !(st.st_mode & S_ISVTX))
+ return NULL;
return t;
+ }
}
if (stat("/tmp", &st) == 0 && S_ISDIR(st.st_mode))
@@ -2806,11 +2956,15 @@ int
x_i_close(int fd)
{
int r;
+ int saved_errno = errno;
do {
r = close(fd);
} while (r == -1 && errno == EINTR);
+ if (r > -1)
+ errno = saved_errno;
+
return r;
}
@@ -2839,80 +2993,6 @@ x_i_memcmp(const void *a, const void *b, unsigned long n)
return 0;
}
-/*
- * emulate fchmod() using file descriptor
- * paths, for old unix portability. should
- * work on e.g. BSD/MacOS (/dev/fd/N),
- * Linux (/proc/self/fd/N) and others
- */
-int
-x_i_fchmod(int fd, mode_t mode)
-{
- if (x_try_fdpath("/dev/fd/", fd, mode) == 0)
- return 0;
-
- if (x_try_fdpath("/proc/self/fd/", fd, mode) == 0)
- return 0;
-
- errno = ENOSYS;
- return -1;
-}
-
-int
-x_try_fdpath(const char *prefix, int fd, mode_t mode)
-{
- char path[PATH_LEN];
-
- unsigned long i = 0;
- unsigned long j;
-
- struct stat st;
-
- while (prefix[i]) {
- if (i >= PATH_LEN - 1)
- return -1;
- path[i] = prefix[i];
- i++;
- }
-
- j = x_conv_fd(path + i, (unsigned long)fd);
-
- if (i + j >= PATH_LEN)
- return -1;
-
- i += j;
- path[i] = '\0';
-
- if (stat(path, &st) < 0)
- return -1;
-
- return chmod(path, mode);
-}
-
-unsigned long
-x_conv_fd(char *buf, unsigned long n)
-{
- char tmp[256];
-
- unsigned long i = 0;
- unsigned long j = 0;
-
- if (n == 0) {
- buf[0] = '0';
- return 1;
- }
-
- while (n > 0) {
- tmp[i++] = (char)('0' + (n % 10));
- n /= 10;
- }
-
- while (i > 0)
- buf[j++] = tmp[--i];
-
- return j;
-}
-
int
x_i_fsync(int fd)
{
diff --git a/util/nvmutil/nvmutil.h b/util/nvmutil/nvmutil.h
index d02d2d7f..a5d5e98f 100644
--- a/util/nvmutil/nvmutil.h
+++ b/util/nvmutil/nvmutil.h
@@ -9,6 +9,11 @@
check_cmd(cmd_helper_cat);
*/
+/*
+ * system prototypes
+ */
+int fchmod(int fd, mode_t mode);
+
#ifndef NVMUTIL_H
#define NVMUTIL_H
@@ -23,6 +28,14 @@
#define OFF_RESET 1
#endif
+#ifndef S_ISVTX
+#define S_ISVTX 01000
+#endif
+
+#if defined(S_IFMT) && ((S_ISVTX & S_IFMT) != 0)
+#error "Unexpected bit layout"
+#endif
+
#ifndef MAX_ZERO_RW_RETRY
#define MAX_ZERO_RW_RETRY 5
#endif
@@ -31,6 +44,10 @@
#define HAVE_REAL_PREAD_PWRITE 0
#endif
+#ifndef MAX_EAGAIN_RETRIES
+#define MAX_EAGAIN_RETRIES 100000
+#endif
+
#ifndef LOOP_EAGAIN
#define LOOP_EAGAIN 1
#endif
@@ -215,14 +232,6 @@
#define SKIP_CHECKSUM_WRITE 0
#define CHECKSUM_WRITE 1
-/*
- * portable timeval
- */
-struct x_st_timeval {
- long tv_sec;
- long tv_usec;
-};
-
struct commands {
unsigned long chk;
char *str;
@@ -280,7 +289,7 @@ struct xfile {
/*
* BE CAREFUL when editing this
* to ensure that you also update
- * the tables in new_xstate()
+ * the tables in xstatus()
*/
struct xstate {
struct commands cmd[7];
@@ -304,7 +313,7 @@ struct xstate {
-static struct xstate *new_xstate(void);
+static struct xstate *xstatus(void);
/*
* Sanitize command tables.
@@ -357,8 +366,6 @@ void set_mac_nib(unsigned long mac_str_pos,
unsigned long mac_byte_pos, unsigned long mac_nib_pos);
unsigned short hextonum(char ch_s);
unsigned long rlong(void);
-unsigned long entropy_jitter(void);
-int x_i_gettimeofday(struct x_st_timeval *tv, void *tz);
void write_mac_part(unsigned long partnum);
/*
@@ -389,6 +396,7 @@ void cat(unsigned long nff);
void cat_buf(unsigned char *b);
void check_cmd(void (*fn)(void), const char *name);
+void cmd_helper_err(void);
/*
* After command processing, write
@@ -473,11 +481,6 @@ void *x_v_memcpy(void *dst,
const void *src, unsigned long n);
int x_i_memcmp(const void *a,
const void *b, unsigned long n);
-int x_i_fchmod(int fd, mode_t mode);
-int x_try_fdpath(const char *prefix,
- int fd, mode_t mode);
-unsigned long x_conv_fd(char *buf,
- unsigned long n);
int x_i_fsync(int fd);