source: rtems/cpukit/libfs/src/devfs/devfs_mknod.c @ c499856

4.115
Last change on this file since c499856 was c499856, checked in by Chris Johns <chrisj@…>, on Mar 20, 2014 at 9:10:47 PM

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

  • Property mode set to 100644
File size: 1.3 KB
Line 
1/**
2 * @file
3 *
4 * @brief Creates an item in the main device table.
5 * @ingroup DevFsDeviceTable Define Device Table Type
6 */
7
8/*
9 *  The license and distribution terms for this file may be
10 *  found in the file LICENSE in this distribution or at
11 *  http://www.rtems.org/license/LICENSE.
12 */
13
14#if HAVE_CONFIG_H
15  #include "config.h"
16#endif
17
18#include <sys/stat.h>
19#include <stdlib.h>
20#include <string.h>
21
22#include "devfs.h"
23
24int devFS_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  if (namelen != 3 || name [0] != 'd' || name [1] != 'e' || name [2] != 'v') {
35    if (S_ISBLK(mode) || S_ISCHR(mode)) {
36      char *dupname = malloc(namelen);
37
38      if (dupname != NULL) {
39        devFS_node *node = parentloc->node_access;
40
41        node->name = dupname;
42        node->namelen = namelen;
43        node->major = rtems_filesystem_dev_major_t(dev);
44        node->minor = rtems_filesystem_dev_minor_t(dev);
45        node->mode = mode;
46        memcpy(dupname, name, namelen);
47      } else {
48        errno = ENOMEM;
49        rv = -1;
50      }
51    } else {
52      errno = ENOTSUP;
53      rv = -1;
54    }
55  } else {
56    if (!S_ISDIR(mode)) {
57      errno = ENOTSUP;
58      rv = -1;
59    }
60  }
61
62  return rv;
63}
Note: See TracBrowser for help on using the repository browser.