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.sun.com/software/products/lustre/docs/GPLv2.pdf
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
27 * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
31 * This file is part of Lustre, http://www.lustre.org/
32 * Lustre is a trademark of Sun Microsystems, Inc.
37 #include <sys/types.h>
45 void usage(const char *prog, int status)
47 fprintf(status == 0 ? stdout : stderr,
48 "Usage: %s [OPTION]... FILE\n"
49 " -d, --device=DEV use device number DEV\n"
50 " -h, --help dispaly help\n"
51 " -m, --mode=MODE use mode MODE\n"
52 " -M, --major=MAJOR use device major MAJOR\n"
53 " -N, --minor=MINOR use device minor MINOR\n",
59 int main(int argc, char ** argv)
61 struct option opts[] = {
62 { "device", 1, NULL, 'd' },
63 { "help", 0, NULL, 'h' },
64 { "mode", 1, NULL, 'm' },
65 { "major", 1, NULL, 'M' },
66 { "minor", 1, NULL, 'N' },
70 mode_t mode = S_IFREG | 0644;
75 while ((c = getopt_long(argc, argv, "d:hm:M:N:", opts, NULL)) != -1) {
78 dev = strtoul(optarg, NULL, 0);
83 mode = strtoul(optarg, NULL, 0);
86 dev = makedev(strtoul(optarg, NULL, 0), minor(dev));
89 dev = makedev(major(dev), strtoul(optarg, NULL, 0));
96 if (argc - optind != 1)
101 if ((mode & S_IFMT) == S_IFDIR)
102 rc = mkdir(path, mode & ~S_IFMT);
103 else if ((mode & S_IFMT) == S_IFLNK)
104 rc = symlink("oldpath", path);
106 rc = mknod(path, mode, dev);
109 fprintf(stderr, "%s: cannot create `%s' with mode %#o: %s\n",
110 argv[0], path, mode, strerror(errno));