diff options
author | Christian Mauderer <Christian.Mauderer@embedded-brains.de> | 2016-08-16 08:52:06 +0200 |
---|---|---|
committer | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2016-08-16 09:16:43 +0200 |
commit | 6634edbee85ed0b28c483d9fc6284f3ba6761f0f (patch) | |
tree | 0905d37bc5fe69c754b567765b84bd607397852e | |
parent | rc.conf/net: Let interface option appear on a DHCP ifconfig_ line. (diff) | |
download | rtems-libbsd-6634edbee85ed0b28c483d9fc6284f3ba6761f0f.tar.bz2 |
devfs: Create path.
-rw-r--r-- | rtemsbsd/sys/fs/devfs/devfs_devs.c | 35 | ||||
-rw-r--r-- | testsuite/cdev01/test_main.c | 15 |
2 files changed, 44 insertions, 6 deletions
diff --git a/rtemsbsd/sys/fs/devfs/devfs_devs.c b/rtemsbsd/sys/fs/devfs/devfs_devs.c index 027013b4..10735f9b 100644 --- a/rtemsbsd/sys/fs/devfs/devfs_devs.c +++ b/rtemsbsd/sys/fs/devfs/devfs_devs.c @@ -36,6 +36,7 @@ #include <stdlib.h> #include <string.h> #include <sys/file.h> +#include <sys/malloc.h> #include <unistd.h> #include <sys/conf.h> @@ -228,7 +229,7 @@ devfs_alloc(int flags) { struct cdev *cdev; - cdev = malloc(sizeof *cdev); + cdev = malloc(sizeof *cdev, M_TEMP, 0); if (cdev == NULL) return (NULL); @@ -243,7 +244,33 @@ devfs_alloc(int flags) void devfs_free(struct cdev *cdev) { - free(cdev); + free(cdev, M_TEMP); +} + +/* + * Create the directory for a device. + * Note: This don't uses dirname() because this function is not defined thread + * save in POSIX. + */ +static void +devfs_create_directory(const char *devname) +{ + char *dir = NULL; + char *lastsep = NULL; + int rv; + mode_t mode = S_IRWXU | S_IRWXG | S_IRWXO; + + dir = strdup(devname, M_TEMP); + BSD_ASSERT(dir != NULL); + + lastsep = strrchr(dir, '/'); + if(lastsep != NULL) { + *lastsep = 0; + rv = rtems_mkdir(dir, mode); + BSD_ASSERT(rv == 0); + } + + free(dir, M_TEMP); } /* @@ -258,6 +285,8 @@ devfs_create(struct cdev *dev) int rv; mode_t mode = S_IFCHR | S_IRWXU | S_IRWXG | S_IRWXO; + devfs_create_directory(dev->si_path); + rv = IMFS_make_generic_node(dev->si_path, mode, &devfs_imfs_control, dev); BSD_ASSERT(rv == 0); @@ -270,6 +299,8 @@ devfs_destroy(struct cdev *dev) rv = unlink(dev->si_path); BSD_ASSERT(rv == 0); + + /* FIXME: Check if directory is empty and remove it. */ } int diff --git a/testsuite/cdev01/test_main.c b/testsuite/cdev01/test_main.c index 898eb174..cbff9133 100644 --- a/testsuite/cdev01/test_main.c +++ b/testsuite/cdev01/test_main.c @@ -40,18 +40,24 @@ #include <errno.h> #include <fcntl.h> #include <poll.h> +#include <stdio.h> #include <stdlib.h> +#include <string.h> #include <unistd.h> #include "test_cdev01.h" #define TEST_NAME "LIBBSD CDEV 1" -static void test_cdev(void) +static void test_cdev(const char *path) { - const char *name = "test"; - const char *path = "/dev/test"; const struct timespec *timeout = NULL; + const char *name; + + /* Remove leading "/dev/" and use the rest as a name. */ + name = path + sizeof("/dev/") - 1; + + printf("Test creating a cdev named \"%s\" at \"%s\".\n", name, path); test_state state = TEST_NEW; int rv = 0; @@ -131,7 +137,8 @@ static void test_cdev(void) static void test_main(void) { - test_cdev(); + test_cdev("/dev/test"); + test_cdev("/dev/some/sub/dir/somedev"); exit(0); } |