mknod.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /* vi: set sw=4 ts=4: */
  2. /*
  3. * mknod syscall for uClibc
  4. *
  5. * Copyright (C) 2002 by Erik Andersen <andersen@codpoet.org>
  6. *
  7. * This program is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU Library General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or (at your
  10. * option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful, but WITHOUT
  13. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  14. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License
  15. * for more details.
  16. *
  17. * You should have received a copy of the GNU Library General Public License
  18. * along with this program; if not, write to the Free Software Foundation,
  19. * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  20. *
  21. */
  22. #define _GNU_SOURCE
  23. #define __FORCE_GLIBC
  24. #include <features.h>
  25. #include <errno.h>
  26. #include <sys/types.h>
  27. #include <sys/syscall.h>
  28. #include <asm/posix_types.h>
  29. #ifndef _MKNOD_VER
  30. # define _MKNOD_VER 0
  31. #endif
  32. #ifndef INLINE_SYSCALL
  33. #define INLINE_SYSCALL(name, nr, args...) __syscall_mknod (args)
  34. #define __NR___syscall_mknod __NR_mknod
  35. static inline _syscall3(int, __syscall_mknod, const char *, path,
  36. unsigned short int, mode, unsigned short int, dev);
  37. #endif
  38. int __xmknod (int version, const char * path, __mode_t mode, __dev_t *dev)
  39. {
  40. unsigned short int k_dev;
  41. /* We must convert the value to dev_t type used by the kernel. */
  42. k_dev = ((major (*dev) & 0xff) << 8) | (minor (*dev) & 0xff);
  43. switch(version)
  44. {
  45. case 1:
  46. return INLINE_SYSCALL (mknod, 3, path, mode, k_dev);
  47. default:
  48. __set_errno(EINVAL);
  49. return -1;
  50. }
  51. }
  52. int mknod(const char *path, __mode_t mode, __dev_t dev)
  53. {
  54. return __xmknod(_MKNOD_VER, path, mode, &dev);
  55. }