From 62fef8b3fc0c41f048133edbbdb2dec3b2d65c3c Mon Sep 17 00:00:00 2001 From: Ingo Weinhold Date: Thu, 16 Jun 2011 20:05:01 +0200 Subject: [PATCH] Added driver settings and find_directory() support. find_directory() is a very simplified implementation, only supporting what we currently need. --- src/build/libroot/Jamfile | 16 ++++- src/build/libroot/find_directory.cpp | 97 ++++++++++++++++++++++++++++ 2 files changed, 112 insertions(+), 1 deletion(-) create mode 100644 src/build/libroot/find_directory.cpp diff --git a/src/build/libroot/Jamfile b/src/build/libroot/Jamfile index 8f244ab532..767c6371f3 100644 --- a/src/build/libroot/Jamfile +++ b/src/build/libroot/Jamfile @@ -9,7 +9,7 @@ UseHeaders [ FDirName $(HAIKU_TOP) headers build os interface ] : true ; UseHeaders [ FDirName $(HAIKU_TOP) headers build os storage ] : true ; UseHeaders [ FDirName $(HAIKU_TOP) headers build os support ] : true ; -UsePrivateBuildHeaders kernel ; +UsePrivateBuildHeaders kernel libroot ; { local defines = [ FDefines @@ -17,8 +17,15 @@ UsePrivateBuildHeaders kernel ; ] ; SubDirCcFlags $(defines) ; SubDirC++Flags $(defines) ; + + local defines = [ FDefines + HAIKU_BUILD_GENERATED_DIRECTORY="\\\"$(HAIKU_OUTPUT_DIR)\\\"" + ] ; + SubDirC++Flags $(defines) ; + ObjectC++Flags find_directory.cpp : $(defines) ; } + DEFINES += KMESSAGE_CONTAINER_ONLY ; ObjectC++Flags KMessage.cpp : $(HOST_BE_API_C++FLAGS) ; @@ -44,6 +51,7 @@ local librootSources = atomic.cpp byteorder.cpp errors.cpp + find_directory.cpp fs.cpp fs_attr.cpp fs_descriptors.cpp @@ -53,12 +61,16 @@ local librootSources = $(hostPlatformSources) + driver_settings.cpp + $(strlSources) strnlen.c KMessage.cpp ; +USES_BE_API on [ FGristFiles $(librootSources:S=$(SUFOBJ)) ] = true ; + BuildPlatformSharedLibrary libroot_build.so : $(librootSources) : @@ -70,6 +82,8 @@ BuildPlatformStaticLibrary libroot_build.a : [ FGristFiles $(librootSources:S=$(SUFOBJ)) ] ; +SEARCH on [ FGristFiles driver_settings.cpp ] + = [ FDirName $(HAIKU_TOP) src system libroot os ] ; SEARCH on [ FGristFiles $(strlSources) strnlen.c ] = [ FDirName $(HAIKU_TOP) src system libroot posix string ] ; SEARCH on [ FGristFiles KMessage.cpp ] diff --git a/src/build/libroot/find_directory.cpp b/src/build/libroot/find_directory.cpp new file mode 100644 index 0000000000..061ecf7bc6 --- /dev/null +++ b/src/build/libroot/find_directory.cpp @@ -0,0 +1,97 @@ +/* + * Copyright 2004, François Revol. + * Copyright 2007-2010, Axel Dörfler, axeld@pinc-software.de. + * Copyright 2011, Oliver Tappe + * Copyright 2011, Ingo Weinhold, ingo_weinhold@gmx.de. + * Distributed under the terms of the MIT License. + */ + + +#include + +#include +#include +#include +#include +#include + +#include + + +#ifndef HAIKU_BUILD_GENERATED_DIRECTORY +# error HAIKU_BUILD_GENERATED_DIRECTORY not defined! +#endif + + +/*! make dir and its parents if needed */ +static int +create_path(const char *path, mode_t mode) +{ + char buffer[B_PATH_NAME_LENGTH + 1]; + int pathLength; + int i = 0; + + if (path == NULL || ((pathLength = strlen(path)) > B_PATH_NAME_LENGTH)) + return EINVAL; + + while (++i < pathLength) { + const char *slash = strchr(&path[i], '/'); + struct stat st; + + if (slash == NULL) + i = pathLength; + else if (i != slash - path) + i = slash - path; + else + continue; + + strlcpy(buffer, path, i + 1); + if (stat(buffer, &st) < 0) { + errno = 0; + if (mkdir(buffer, mode) < 0) + return errno; + } + } + + return 0; +} + + +status_t +find_directory(directory_which which, dev_t device, bool createIt, + char *returnedPath, int32 pathLength) +{ + // we support only the handful of paths we need + const char* path; + switch (which) { + case B_COMMON_TEMP_DIRECTORY: + path = HAIKU_BUILD_GENERATED_DIRECTORY "/tmp"; + break; + case B_COMMON_SETTINGS_DIRECTORY: + path = HAIKU_BUILD_GENERATED_DIRECTORY "/common/settings"; + break; + case B_COMMON_CACHE_DIRECTORY: + path = HAIKU_BUILD_GENERATED_DIRECTORY "/common/cache"; + break; + case B_USER_SETTINGS_DIRECTORY: + path = HAIKU_BUILD_GENERATED_DIRECTORY "/user/settings"; + break; + case B_USER_CACHE_DIRECTORY: + path = HAIKU_BUILD_GENERATED_DIRECTORY "/user/cache"; + break; + default: + return B_BAD_VALUE; + } + + // create, if necessary + status_t error = B_OK; + struct stat st; + if (createIt && stat(path, &st) < 0) + error = create_path(path, 0755); + + if (error == B_OK) + strlcpy(returnedPath, path, pathLength); + + return error; +} +