source: rtems/cpukit/libcsupport/src/mknod.c @ 1c6926c1

5
Last change on this file since 1c6926c1 was c499856, checked in by Chris Johns <chrisj@…>, on 03/20/14 at 21:10:47

Change all references of rtems.com to rtems.org.

  • Property mode set to 100644
File size: 1.8 KB
Line 
1/**
2 *  @file
3 *
4 *  @brief Create a Special or Ordinary File
5 *  @ingroup libcsupport
6 */
7
8/*
9 *  COPYRIGHT (c) 1989-1999.
10 *  On-Line Applications Research Corporation (OAR).
11 *
12 *  The license and distribution terms for this file may be
13 *  found in the file LICENSE in this distribution or at
14 *  http://www.rtems.org/license/LICENSE.
15 */
16
17#if HAVE_CONFIG_H
18  #include "config.h"
19#endif
20
21#include <sys/stat.h>
22
23#include <rtems/libio_.h>
24
25int rtems_filesystem_mknod(
26  const rtems_filesystem_location_info_t *parentloc,
27  const char *name,
28  size_t namelen,
29  mode_t mode,
30  dev_t dev
31)
32{
33  int rv = 0;
34
35  mode &= ~rtems_filesystem_umask;
36
37  switch (mode & S_IFMT) {
38    case S_IFBLK:
39    case S_IFCHR:
40    case S_IFDIR:
41    case S_IFIFO:
42    case S_IFREG:
43      break;
44    default:
45      errno = EINVAL;
46      rv = -1;
47      break;
48  }
49 
50  if ( rv == 0 ) {
51    const rtems_filesystem_operations_table *ops = parentloc->mt_entry->ops;
52
53    rv = (*ops->mknod_h)( parentloc, name, namelen, mode, dev );
54  }
55
56  return rv;
57}
58
59/**
60 * This routine is not defined in the POSIX 1003.1b standard but is
61 *  commonly supported on most UNIX and POSIX systems.  It is the
62 *  foundation for creating file system objects.
63 */
64int mknod( const char *path, mode_t mode, dev_t dev )
65{
66  int rv = 0;
67  rtems_filesystem_eval_path_context_t ctx;
68  int eval_flags = RTEMS_FS_FOLLOW_LINK
69    | RTEMS_FS_MAKE
70    | RTEMS_FS_EXCLUSIVE
71    | (S_ISDIR(mode) ? RTEMS_FS_ACCEPT_RESIDUAL_DELIMITERS : 0);
72  const rtems_filesystem_location_info_t *currentloc =
73    rtems_filesystem_eval_path_start( &ctx, path, eval_flags );
74
75  rv = rtems_filesystem_mknod(
76    currentloc,
77    rtems_filesystem_eval_path_get_token( &ctx ),
78    rtems_filesystem_eval_path_get_tokenlen( &ctx ),
79    mode,
80    dev
81  );
82
83  rtems_filesystem_eval_path_cleanup( &ctx );
84
85  return rv;
86}
Note: See TracBrowser for help on using the repository browser.