Whamcloud - gitweb
Ignore generated files.
[fs/lustre-release.git] / libsysio / src / mknod.c
1 /*
2  *    This Cplant(TM) source code is the property of Sandia National
3  *    Laboratories.
4  *
5  *    This Cplant(TM) source code is copyrighted by Sandia National
6  *    Laboratories.
7  *
8  *    The redistribution of this Cplant(TM) source code is subject to the
9  *    terms of the GNU Lesser General Public License
10  *    (see cit/LGPL or http://www.gnu.org/licenses/lgpl.html)
11  *
12  *    Cplant(TM) Copyright 1998-2003 Sandia Corporation. 
13  *    Under the terms of Contract DE-AC04-94AL85000, there is a non-exclusive
14  *    license for use of this work by or on behalf of the US Government.
15  *    Export of this program may require a license from the United States
16  *    Government.
17  */
18
19 /*
20  * This library is free software; you can redistribute it and/or
21  * modify it under the terms of the GNU Lesser General Public
22  * License as published by the Free Software Foundation; either
23  * version 2.1 of the License, or (at your option) any later version.
24  * 
25  * This library is distributed in the hope that it will be useful,
26  * but WITHOUT ANY WARRANTY; without even the implied warranty of
27  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
28  * Lesser General Public License for more details.
29  * 
30  * You should have received a copy of the GNU Lesser General Public
31  * License along with this library; if not, write to the Free Software
32  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
33  *
34  * Questions or comments about this library should be sent to:
35  *
36  * Lee Ward
37  * Sandia National Laboratories, New Mexico
38  * P.O. Box 5800
39  * Albuquerque, NM 87185-1110
40  *
41  * lee@sandia.gov
42  */
43
44 #if defined(__linux__)
45 #define _BSD_SOURCE
46 #endif
47
48 #include <unistd.h>
49 #include <errno.h>
50 #include <assert.h>
51 #include <sys/types.h>
52 #include <sys/stat.h>
53 #include <sys/queue.h>
54
55 #include "sysio.h"
56 #include "inode.h"
57 #include "fs.h"
58 #include "mount.h"
59
60 #include "sysio-symbols.h"
61
62 #undef mknod
63 #undef __xmknod
64
65 #if defined(BSD) || defined(REDSTORM)
66 #define _MKNOD_VER      0
67 #endif
68
69 int
70 PREPEND(__, SYSIO_INTERFACE_NAME(xmknod))(int __ver, 
71                                           const char *path, 
72                                           mode_t mode, 
73                                           dev_t *dev)
74 {
75         int     err;
76         struct intent intent;
77         struct pnode *pno;
78         SYSIO_INTERFACE_DISPLAY_BLOCK;
79
80         SYSIO_INTERFACE_ENTER;
81         if (__ver != _MKNOD_VER) {
82                 err = -ENOSYS;
83                 goto out;
84         }
85
86         /*
87          * Support only character-special and fifos right now.
88          */
89         if (!(S_ISCHR(mode) || S_ISFIFO(mode))) {
90                 err = -EINVAL;
91                 goto out;
92         }
93
94         INTENT_INIT(&intent, INT_CREAT, &mode, NULL);
95         err = _sysio_namei(_sysio_cwd, path, ND_NEGOK, &intent, &pno);
96         if (err)
97                 goto out;
98         if (pno->p_base->pb_ino) {
99                 err = -EEXIST;
100                 goto error;
101         }
102
103         if (IS_RDONLY(pno, pno->p_base->pb_ino)) {
104                 err = -EROFS;
105                 goto error;
106         }
107         err =
108             (*pno->p_parent->p_base->pb_ino->i_ops.inop_mknod)(pno, mode, *dev);
109 error:
110         P_RELE(pno);
111 out:
112         SYSIO_INTERFACE_RETURN(err ? -1 : 0, err);
113 }
114
115 #ifdef REDSTORM
116 #undef _xmknod
117 sysio_sym_weak_alias(PREPEND(__, SYSIO_INTERFACE_NAME(xmknod)), 
118                      PREPEND(_, SYSIO_INTERFACE_NAME(xmknod)))
119 #endif
120
121 static int
122 PREPEND(__, SYSIO_INTERFACE_NAME(mknod))(const char *path, 
123                                          mode_t mode, 
124                                          dev_t dev)
125 {
126
127         return PREPEND(__, SYSIO_INTERFACE_NAME(xmknod))(_MKNOD_VER, 
128                                                          path, 
129                                                          mode, 
130                                                          &dev);
131 }
132
133 sysio_sym_weak_alias(PREPEND(__, SYSIO_INTERFACE_NAME(mknod)),
134                      SYSIO_INTERFACE_NAME(mknod))