2006-02-15 12:18:21 +01:00
|
|
|
/*
|
|
|
|
newroot.c
|
|
|
|
|
|
|
|
Replace the current root with a new one
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <errno.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2009-08-12 21:57:37 +02:00
|
|
|
#include <sys/mount.h>
|
2006-02-15 12:18:21 +01:00
|
|
|
|
2009-08-18 13:36:01 +02:00
|
|
|
void usage(void) {
|
|
|
|
fprintf(stderr, "Usage: newroot [-i] <block-special>\n");
|
|
|
|
fprintf(stderr, "-i: copy mfs binary from boot image to memory\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2006-02-15 12:18:21 +01:00
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
int r;
|
|
|
|
char *dev;
|
2009-08-18 13:36:01 +02:00
|
|
|
int mountflags;
|
2006-02-15 12:18:21 +01:00
|
|
|
|
2009-08-18 13:36:01 +02:00
|
|
|
r = 0;
|
|
|
|
mountflags = 0; /* !read-only */
|
|
|
|
|
|
|
|
if (argc != 2 && argc != 3) usage();
|
|
|
|
if(argc == 2) {
|
|
|
|
dev = argv[1];
|
|
|
|
} else if(argc == 3) {
|
|
|
|
/* -i flag was supposedly entered. Verify.*/
|
|
|
|
if(strcmp(argv[1], "-i") != 0) usage();
|
|
|
|
mountflags |= MS_REUSE;
|
|
|
|
dev = argv[2];
|
2006-02-15 12:18:21 +01:00
|
|
|
}
|
2009-08-18 13:36:01 +02:00
|
|
|
|
|
|
|
r = mount(dev, "/", mountflags, NULL, NULL);
|
|
|
|
if (r != 0) {
|
|
|
|
fprintf(stderr, "newroot: mount failed: %s\n",strerror(errno));
|
2006-02-15 12:18:21 +01:00
|
|
|
exit(1);
|
|
|
|
}
|
2009-08-18 13:36:01 +02:00
|
|
|
|
2006-02-15 12:18:21 +01:00
|
|
|
return 0;
|
|
|
|
}
|