2 * pivot_root.c - Change the root file system
4 * Copyright (C) 2000 Werner Almesberger
6 * This file is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This file is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
21 #include <sys/syscall.h>
26 #include "closestream.h"
28 #define pivot_root(new_root,put_old) syscall(SYS_pivot_root,new_root,put_old)
30 static void __attribute__((__noreturn__
)) usage(void)
33 fputs(USAGE_HEADER
, out
);
34 fprintf(out
, _(" %s [options] new_root put_old\n"),
35 program_invocation_short_name
);
37 fputs(USAGE_SEPARATOR
, out
);
38 fputs(_("Change the root filesystem.\n"), out
);
40 fputs(USAGE_OPTIONS
, out
);
41 fprintf(out
, USAGE_HELP_OPTIONS(16));
42 fprintf(out
, USAGE_MAN_TAIL("pivot_root(8)"));
46 int main(int argc
, char **argv
)
49 static const struct option longopts
[] = {
50 {"version", no_argument
, NULL
, 'V'},
51 {"help", no_argument
, NULL
, 'h'},
55 setlocale(LC_ALL
, "");
56 bindtextdomain(PACKAGE
, LOCALEDIR
);
58 close_stdout_atexit();
60 while ((ch
= getopt_long(argc
, argv
, "Vh", longopts
, NULL
)) != -1)
63 print_version(EXIT_SUCCESS
);
67 errtryhelp(EXIT_FAILURE
);
71 warnx(_("bad usage"));
72 errtryhelp(EXIT_FAILURE
);
74 if (pivot_root(argv
[1], argv
[2]) < 0)
75 err(EXIT_FAILURE
, _("failed to change root from `%s' to `%s'"),