From b796791788f6f793dbbaad8bb93e7b1b4d086d1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Fri, 12 Sep 2003 01:20:07 +0000 Subject: [PATCH] Now adds real devices - it scans the /dev/disk tree and adds all files with the name "raw" - note, this is directly accessing your precious data, but read-only of course. Also added the test-file-device as used by the DiskDeviceManagerTest. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@4636 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- .../kernel/boot/loader/platform_devices.cpp | 64 ++++++++++++++++++- 1 file changed, 63 insertions(+), 1 deletion(-) diff --git a/src/tests/kernel/boot/loader/platform_devices.cpp b/src/tests/kernel/boot/loader/platform_devices.cpp index 755cfa15b7..e88e1a02f5 100644 --- a/src/tests/kernel/boot/loader/platform_devices.cpp +++ b/src/tests/kernel/boot/loader/platform_devices.cpp @@ -4,13 +4,75 @@ */ +#include "Handle.h" + #include +#include + +#include +#include +#include +#include +#include +#include + + +static status_t +add_device(const char *path, struct list *list) +{ + Handle *device = new Handle(path); + if (device == NULL) + return B_NO_MEMORY; + + if (device->InitCheck() != B_OK) { + delete device; + return B_ERROR; + } + + printf("add \"%s\" to list of boot devices\n", path); + list_add_item(list, device); + + return B_OK; +} + + +static status_t +recursive_add_device(const char *path, struct list *list) +{ + DIR *dir = opendir(path); + if (dir == NULL) + return errno; + + struct dirent *dirent; + while ((dirent = readdir(dir)) != NULL) { + // we don't care about names with a leading dot (incl. "." and "..") + if (dirent->d_name[0] == '.') + continue; + + char nextPath[PATH_MAX]; + strcpy(nextPath, path); + strcat(nextPath, "/"); + strcat(nextPath, dirent->d_name); + + // Note, this doesn't care about if it's a directory or not! + if (!strcmp(dirent->d_name, "raw") + && add_device(nextPath, list) == B_OK) + continue; + + recursive_add_device(nextPath, list); + } + closedir(dir); + + return B_OK; +} status_t platform_get_boot_devices(struct stage2_args *args, struct list *list) { + add_device("/boot/home/test-file-device", list); + recursive_add_device("/dev/disk", list); + return B_OK; } -