source: rtems/cpukit/libcsupport/src/mknod.c @ 5357e24

4.9
Last change on this file since 5357e24 was 5357e24, checked in by Joel Sherrill <joel.sherrill@…>, on Mar 3, 2011 at 1:38:52 PM

2011-03-03 Chris Johns <chrisj@…>

PR 1749/filesystem

  • libcsupport/src/mknod.c: Fix the incorrect handling of the file type in the mode value o reject invalid types as per the standard.
  • Property mode set to 100644
File size: 1.8 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 *  $Id$
16 */
17
18#if HAVE_CONFIG_H
19#include "config.h"
20#endif
21
22#include <sys/types.h>
23#include <sys/stat.h>
24#include <fcntl.h>
25#include <unistd.h>
26#include <errno.h>
27#include <stdlib.h>
28
29#include <rtems/libio_.h>
30#include <rtems/seterr.h>
31
32int mknod(
33  const char *pathname,
34  mode_t      mode,
35  dev_t       dev
36)
37{
38  rtems_filesystem_location_info_t    temp_loc;
39  int                                 i;
40  const char                         *name_start;
41  int                                 result;
42
43  /*
44   * The file type is field within the mode. Check we have a sane mode set.
45   */
46  switch (mode & S_IFMT) {
47    case S_IFDIR:
48    case S_IFCHR:
49    case S_IFBLK:
50    case S_IFREG:
51    case S_IFIFO:
52      break;
53    default:
54      rtems_set_errno_and_return_minus_one( EINVAL );
55  }
56
57  if ( S_ISFIFO(mode) )
58    rtems_set_errno_and_return_minus_one( ENOTSUP );
59
60  rtems_filesystem_get_start_loc( pathname, &i, &temp_loc );
61
62  if ( !temp_loc.ops->evalformake_h ) {
63    rtems_set_errno_and_return_minus_one( ENOTSUP );
64  }
65
66  result = (*temp_loc.ops->evalformake_h)(
67    &pathname[i],
68    &temp_loc,
69    &name_start
70  );
71  if ( result != 0 )
72    return -1;
73
74  if ( !temp_loc.ops->mknod_h ) {
75    rtems_filesystem_freenode( &temp_loc );
76    rtems_set_errno_and_return_minus_one( ENOTSUP );
77  }
78
79  result =  (*temp_loc.ops->mknod_h)( name_start, mode, dev, &temp_loc );
80
81  rtems_filesystem_freenode( &temp_loc );
82
83  return result;
84}
Note: See TracBrowser for help on using the repository browser.