Changeset 6634edb in rtems-libbsd


Ignore:
Timestamp:
Aug 16, 2016, 6:52:06 AM (3 years ago)
Author:
Christian Mauderer <Christian.Mauderer@…>
Branches:
5283630d2c9d40deb0183696d278e02644fe4326, freebsd-9.3, bc2ba9a9cdc7381c2a4f2ae6ee303be636f31368
Children:
69355c3
Parents:
ab7739a
git-author:
Christian Mauderer <Christian.Mauderer@…> (08/16/16 06:52:06)
git-committer:
Sebastian Huber <sebastian.huber@…> (08/16/16 07:16:43)
Message:

devfs: Create path.

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • rtemsbsd/sys/fs/devfs/devfs_devs.c

    rab7739a r6634edb  
    3737#include <string.h>
    3838#include <sys/file.h>
     39#include <sys/malloc.h>
    3940#include <unistd.h>
    4041
     
    229230        struct cdev *cdev;
    230231
    231         cdev = malloc(sizeof *cdev);
     232        cdev = malloc(sizeof *cdev, M_TEMP, 0);
    232233        if (cdev == NULL)
    233234                return (NULL);
     
    244245devfs_free(struct cdev *cdev)
    245246{
    246         free(cdev);
     247        free(cdev, M_TEMP);
     248}
     249
     250/*
     251 * Create the directory for a device.
     252 * Note: This don't uses dirname() because this function is not defined thread
     253 * save in POSIX.
     254 */
     255static void
     256devfs_create_directory(const char *devname)
     257{
     258        char *dir = NULL;
     259        char *lastsep = NULL;
     260        int rv;
     261        mode_t mode = S_IRWXU | S_IRWXG | S_IRWXO;
     262
     263        dir = strdup(devname, M_TEMP);
     264        BSD_ASSERT(dir != NULL);
     265
     266        lastsep = strrchr(dir, '/');
     267        if(lastsep != NULL) {
     268                *lastsep = 0;
     269                rv = rtems_mkdir(dir, mode);
     270                BSD_ASSERT(rv == 0);
     271        }
     272
     273        free(dir, M_TEMP);
    247274}
    248275
     
    259286        mode_t mode = S_IFCHR | S_IRWXU | S_IRWXG | S_IRWXO;
    260287
     288        devfs_create_directory(dev->si_path);
     289
    261290        rv = IMFS_make_generic_node(dev->si_path, mode, &devfs_imfs_control,
    262291            dev);
     
    271300        rv = unlink(dev->si_path);
    272301        BSD_ASSERT(rv == 0);
     302
     303        /* FIXME: Check if directory is empty and remove it. */
    273304}
    274305
  • testsuite/cdev01/test_main.c

    rab7739a r6634edb  
    4141#include <fcntl.h>
    4242#include <poll.h>
     43#include <stdio.h>
    4344#include <stdlib.h>
     45#include <string.h>
    4446#include <unistd.h>
    4547
     
    4850#define TEST_NAME "LIBBSD CDEV 1"
    4951
    50 static void test_cdev(void)
     52static void test_cdev(const char *path)
    5153{
    52         const char *name = "test";
    53         const char *path = "/dev/test";
    5454        const struct timespec *timeout = NULL;
     55        const char *name;
     56
     57        /* Remove leading "/dev/" and use the rest as a name. */
     58        name = path + sizeof("/dev/") - 1;
     59
     60        printf("Test creating a cdev named \"%s\" at \"%s\".\n", name, path);
    5561
    5662        test_state state = TEST_NEW;
     
    132138test_main(void)
    133139{
    134         test_cdev();
     140        test_cdev("/dev/test");
     141        test_cdev("/dev/some/sub/dir/somedev");
    135142
    136143        exit(0);
Note: See TracChangeset for help on using the changeset viewer.