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/
28 * Lustre is a trademark of Sun Microsystems, Inc.
33 #include <sys/sysmacros.h>
41 void usage(const char *prog, int status)
43 fprintf(status == 0 ? stdout : stderr,
44 "Usage: %s [OPTION]... FILE\n"
45 " -d, --device=DEV use device number DEV\n"
46 " -h, --help dispaly help\n"
47 " -m, --mode=MODE use mode MODE\n"
48 " -M, --major=MAJOR use device major MAJOR\n"
49 " -N, --minor=MINOR use device minor MINOR\n",
55 int main(int argc, char **argv)
57 struct option opts[] = {
58 { .name = "device", .has_arg = required_argument, .val = 'd' },
59 { .name = "help", .has_arg = no_argument, .val = 'h' },
60 { .name = "mode", .has_arg = required_argument, .val = 'm' },
61 { .name = "major", .has_arg = required_argument, .val = 'M' },
62 { .name = "minor", .has_arg = required_argument, .val = 'N' },
66 mode_t mode = S_IFREG | 0644;
71 while ((c = getopt_long(argc, argv, "d:hm:M:N:", opts, NULL)) != -1) {
74 dev = strtoul(optarg, NULL, 0);
79 mode = strtoul(optarg, NULL, 0);
82 dev = makedev(strtoul(optarg, NULL, 0), minor(dev));
85 dev = makedev(major(dev), strtoul(optarg, NULL, 0));
92 if (argc - optind != 1)
97 if ((mode & S_IFMT) == S_IFDIR)
98 rc = mkdir(path, mode & ~S_IFMT);
99 else if ((mode & S_IFMT) == S_IFLNK)
100 rc = symlink("oldpath", path);
102 rc = mknod(path, mode, dev);
106 fprintf(stderr, "%s: cannot create `%s' with mode %#o: %s\n",
107 argv[0], path, mode, strerror(rc));