Added driver settings and find_directory() support.

find_directory() is a very simplified implementation, only supporting
what we currently need.
This commit is contained in:
Ingo Weinhold 2011-06-16 20:05:01 +02:00
parent b795c9ce72
commit 62fef8b3fc
2 changed files with 112 additions and 1 deletions

View File

@ -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 storage ] : true ;
UseHeaders [ FDirName $(HAIKU_TOP) headers build os support ] : true ; UseHeaders [ FDirName $(HAIKU_TOP) headers build os support ] : true ;
UsePrivateBuildHeaders kernel ; UsePrivateBuildHeaders kernel libroot ;
{ {
local defines = [ FDefines local defines = [ FDefines
@ -17,8 +17,15 @@ UsePrivateBuildHeaders kernel ;
] ; ] ;
SubDirCcFlags $(defines) ; SubDirCcFlags $(defines) ;
SubDirC++Flags $(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 ; DEFINES += KMESSAGE_CONTAINER_ONLY ;
ObjectC++Flags KMessage.cpp : $(HOST_BE_API_C++FLAGS) ; ObjectC++Flags KMessage.cpp : $(HOST_BE_API_C++FLAGS) ;
@ -44,6 +51,7 @@ local librootSources =
atomic.cpp atomic.cpp
byteorder.cpp byteorder.cpp
errors.cpp errors.cpp
find_directory.cpp
fs.cpp fs.cpp
fs_attr.cpp fs_attr.cpp
fs_descriptors.cpp fs_descriptors.cpp
@ -53,12 +61,16 @@ local librootSources =
$(hostPlatformSources) $(hostPlatformSources)
driver_settings.cpp
$(strlSources) $(strlSources)
strnlen.c strnlen.c
KMessage.cpp KMessage.cpp
; ;
USES_BE_API on [ FGristFiles $(librootSources:S=$(SUFOBJ)) ] = true ;
BuildPlatformSharedLibrary libroot_build.so : BuildPlatformSharedLibrary libroot_build.so :
$(librootSources) $(librootSources)
: :
@ -70,6 +82,8 @@ BuildPlatformStaticLibrary libroot_build.a :
[ FGristFiles $(librootSources:S=$(SUFOBJ)) ] [ FGristFiles $(librootSources:S=$(SUFOBJ)) ]
; ;
SEARCH on [ FGristFiles driver_settings.cpp ]
= [ FDirName $(HAIKU_TOP) src system libroot os ] ;
SEARCH on [ FGristFiles $(strlSources) strnlen.c ] SEARCH on [ FGristFiles $(strlSources) strnlen.c ]
= [ FDirName $(HAIKU_TOP) src system libroot posix string ] ; = [ FDirName $(HAIKU_TOP) src system libroot posix string ] ;
SEARCH on [ FGristFiles KMessage.cpp ] SEARCH on [ FGristFiles KMessage.cpp ]

View File

@ -0,0 +1,97 @@
/*
* Copyright 2004, François Revol.
* Copyright 2007-2010, Axel Dörfler, axeld@pinc-software.de.
* Copyright 2011, Oliver Tappe <zooey@hirschkaefer.de>
* Copyright 2011, Ingo Weinhold, ingo_weinhold@gmx.de.
* Distributed under the terms of the MIT License.
*/
#include <FindDirectory.h>
#include <errno.h>
#include <string.h>
#include <sys/stat.h>
#include <stdlib.h>
#include <unistd.h>
#include <StorageDefs.h>
#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;
}