Back to index

glibc  2.9
xmknod.c
Go to the documentation of this file.
00001 /* xmknod call using old-style Unix mknod system call.
00002    Copyright (C) 1991, 1993, 1995, 1996, 1997, 1998, 2000, 2002, 2003
00003    Free Software Foundation, Inc.
00004    This file is part of the GNU C Library.
00005 
00006    The GNU C Library is free software; you can redistribute it and/or
00007    modify it under the terms of the GNU Lesser General Public
00008    License as published by the Free Software Foundation; either
00009    version 2.1 of the License, or (at your option) any later version.
00010 
00011    The GNU C Library is distributed in the hope that it will be useful,
00012    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014    Lesser General Public License for more details.
00015 
00016    You should have received a copy of the GNU Lesser General Public
00017    License along with the GNU C Library; if not, write to the Free
00018    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00019    02111-1307 USA.  */
00020 
00021 #include <errno.h>
00022 #include <sys/types.h>
00023 #include <sys/stat.h>
00024 #include <sys/sysmacros.h>
00025 
00026 #include <sysdep.h>
00027 #include <sys/syscall.h>
00028 #include <bp-checks.h>
00029 
00030 /* Create a device file named PATH, with permission and special bits MODE
00031    and device number DEV (which can be constructed from major and minor
00032    device numbers with the `makedev' macro above).  */
00033 int
00034 __xmknod (int vers, const char *path, mode_t mode, dev_t *dev)
00035 {
00036   unsigned long long int k_dev;
00037 
00038   if (vers != _MKNOD_VER)
00039     {
00040       __set_errno (EINVAL);
00041       return -1;
00042     }
00043 
00044   /* We must convert the value to dev_t type used by the kernel.  */
00045   k_dev =  (*dev) & ((1ULL << 32) - 1);
00046   if (k_dev != *dev)
00047     {
00048       __set_errno (EINVAL);
00049       return -1;
00050     }
00051 
00052   return INLINE_SYSCALL (mknod, 3, CHECK_STRING (path), mode,
00053                       (unsigned int) k_dev);
00054 }
00055 
00056 weak_alias (__xmknod, _xmknod)
00057 libc_hidden_def (__xmknod)