4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.gnu.org/licenses/gpl-2.0.html
23 * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Use is subject to license terms.
27 * This file is part of Lustre, http://www.lustre.org/
32 #include <sys/sysmacros.h>
40 void usage(const char *prog, int status)
42 fprintf(status == 0 ? stdout : stderr,
43 "Usage: %s [OPTION]... FILE\n"
44 " -d, --device=DEV use device number DEV\n"
45 " -h, --help dispaly help\n"
46 " -m, --mode=MODE use mode MODE\n"
47 " -M, --major=MAJOR use device major MAJOR\n"
48 " -N, --minor=MINOR use device minor MINOR\n",
54 int main(int argc, char **argv)
56 struct option opts[] = {
57 { .name = "device", .has_arg = required_argument, .val = 'd' },
58 { .name = "help", .has_arg = no_argument, .val = 'h' },
59 { .name = "mode", .has_arg = required_argument, .val = 'm' },
60 { .name = "major", .has_arg = required_argument, .val = 'M' },
61 { .name = "minor", .has_arg = required_argument, .val = 'N' },
65 mode_t mode = S_IFREG | 0644;
70 while ((c = getopt_long(argc, argv, "d:hm:M:N:", opts, NULL)) != -1) {
73 dev = strtoul(optarg, NULL, 0);
78 mode = strtoul(optarg, NULL, 0);
81 dev = makedev(strtoul(optarg, NULL, 0), minor(dev));
84 dev = makedev(major(dev), strtoul(optarg, NULL, 0));
91 if (argc - optind != 1)
96 if ((mode & S_IFMT) == S_IFDIR)
97 rc = mkdir(path, mode & ~S_IFMT);
98 else if ((mode & S_IFMT) == S_IFLNK)
99 rc = symlink("oldpath", path);
101 rc = mknod(path, mode, dev);
105 fprintf(stderr, "%s: cannot create `%s' with mode %#o: %s\n",
106 argv[0], path, mode, strerror(rc));