source: rtems/cpukit/libcsupport/src/mknod.c @ da154e14

4.11
Last change on this file since da154e14 was da154e14, checked in by Sebastian Huber <sebastian.huber@…>, on May 14, 2012 at 2:55:41 PM

Filesystem: Move operations to mount table entry

The scope of the file system operations is the file system instance.
The scope of the file system node handlers is the file location. The
benefit of moving the operations to the mount table entry is a size
reduction of the file location (rtems_filesystem_location_info_t). The
code size is slightly increased due to additional load instructions.

Restructure rtems_filesystem_mount_table_entry_t to improve cache
efficiency.

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