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(FILE * out
)
32 fprintf(out
, USAGE_HEADER
);
33 fprintf(out
, _(" %s [options] new_root put_old\n"),
34 program_invocation_short_name
);
36 fputs(USAGE_SEPARATOR
, out
);
37 fputs(_("Change the root filesystem.\n"), out
);
39 fprintf(out
, USAGE_OPTIONS
);
40 fprintf(out
, USAGE_HELP
);
41 fprintf(out
, USAGE_VERSION
);
42 fprintf(out
, USAGE_MAN_TAIL("pivot_root(8)"));
43 exit(out
== stderr
? EXIT_FAILURE
: EXIT_SUCCESS
);
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
);
60 while ((ch
= getopt_long(argc
, argv
, "Vh", longopts
, NULL
)) != -1)
63 printf(UTIL_LINUX_VERSION
);
68 errtryhelp(EXIT_FAILURE
);
74 if (pivot_root(argv
[1], argv
[2]) < 0)
75 err(EXIT_FAILURE
, _("failed to change root from `%s' to `%s'"),