1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 only,
10 * as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License version 2 for more details (a copy is included
16 * in the LICENSE file that accompanied this code).
18 * You should have received a copy of the GNU General Public License
19 * version 2 along with this program; If not, see
20 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
22 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23 * CA 95054 USA or visit www.sun.com if you need additional information or
29 * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
30 * Use is subject to license terms.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
39 #include <sys/types.h>
47 void usage(const char *prog, int status)
49 fprintf(status == 0 ? stdout : stderr,
50 "Usage: %s [OPTION]... FILE\n"
51 " -d, --device=DEV use device number DEV\n"
52 " -h, --help dispaly help\n"
53 " -m, --mode=MODE use mode MODE\n"
54 " -M, --major=MAJOR use device major MAJOR\n"
55 " -N, --minor=MINOR use device minor MINOR\n",
61 int main(int argc, char ** argv)
63 struct option opts[] = {
64 { "device", 1, NULL, 'd' },
65 { "help", 0, NULL, 'h' },
66 { "mode", 1, NULL, 'm' },
67 { "major", 1, NULL, 'M' },
68 { "minor", 1, NULL, 'N' },
72 mode_t mode = S_IFREG | 0644;
77 while ((c = getopt_long(argc, argv, "d:hm:M:N:", opts, NULL)) != -1) {
80 dev = strtoul(optarg, NULL, 0);
85 mode = strtoul(optarg, NULL, 0);
88 dev = makedev(strtoul(optarg, NULL, 0), minor(dev));
91 dev = makedev(major(dev), strtoul(optarg, NULL, 0));
98 if (argc - optind != 1)
103 if ((mode & S_IFMT) == S_IFDIR)
104 rc = mkdir(path, mode & ~S_IFMT);
105 else if ((mode & S_IFMT) == S_IFLNK)
106 rc = symlink("oldpath", path);
108 rc = mknod(path, mode, dev);
111 fprintf(stderr, "%s: cannot create `%s' with mode %#o: %s\n",
112 argv[0], path, mode, strerror(errno));