#include "group-member.h"
#include "lchown.h"
#include "quote.h"
+#include "root-dev-ino.h"
#include "xstrtol.h"
/* The official name of this program (e.g., no `g' prefix). */
enum
{
DEREFERENCE_OPTION = CHAR_MAX + 1,
+ NO_PRESERVE_ROOT,
+ PRESERVE_ROOT,
REFERENCE_FILE_OPTION
};
{"changes", no_argument, NULL, 'c'},
{"dereference", no_argument, NULL, DEREFERENCE_OPTION},
{"no-dereference", no_argument, NULL, 'h'},
+ {"no-preserve-root", no_argument, NULL, NO_PRESERVE_ROOT},
+ {"preserve-root", no_argument, NULL, PRESERVE_ROOT},
{"quiet", no_argument, NULL, 'f'},
{"silent", no_argument, NULL, 'f'},
{"reference", required_argument, NULL, REFERENCE_FILE_OPTION},
int
main (int argc, char **argv)
{
+ bool preserve_root = false;
gid_t gid;
/* Bit flags that control how fts works. */
dereference = 1;
break;
+ case NO_PRESERVE_ROOT:
+ preserve_root = false;
+ break;
+
+ case PRESERVE_ROOT:
+ preserve_root = true;
+ break;
+
case REFERENCE_FILE_OPTION:
reference_file = optarg;
break;
gid = parse_group (group_name);
}
+ if (chopt.recurse & preserve_root)
+ {
+ static struct dev_ino dev_ino_buf;
+ chopt.root_dev_ino = get_root_dev_ino (&dev_ino_buf);
+ if (chopt.root_dev_ino == NULL)
+ error (EXIT_FAILURE, errno, _("failed to get attributes of %s"),
+ quote ("/"));
+ }
+
ok = chown_files (argv + optind, bit_flags,
(uid_t) -1, gid,
(uid_t) -1, (gid_t) -1, &chopt);