* Added private header defining __gUmask which is now used everywhere where

needed.
* Some cleanup in Directory.cpp, and File.cpp.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@31086 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2009-06-17 14:09:40 +00:00
parent 0bb8521b68
commit 160f2d1081
8 changed files with 96 additions and 88 deletions
+14
View File
@@ -0,0 +1,14 @@
/*
* Copyright 2009, Axel Dörfler, [email protected].
* Distributed under the terms of the MIT License.
*/
#ifndef UMASK_H
#define UMASK_H
#include <sys/types.h>
extern mode_t __gUmask;
#endif /* UMASK_H */
+53 -48
View File
@@ -24,10 +24,7 @@
#include <SymLink.h> #include <SymLink.h>
#include <syscalls.h> #include <syscalls.h>
#include <umask.h>
extern mode_t __gUmask;
// declared in sys/umask.c
//! Creates an uninitialized BDirectory object. //! Creates an uninitialized BDirectory object.
@@ -41,7 +38,7 @@ BDirectory::BDirectory()
/*! \brief Creates a copy of the supplied BDirectory. /*! \brief Creates a copy of the supplied BDirectory.
\param dir the BDirectory object to be copied \param dir the BDirectory object to be copied
*/ */
BDirectory::BDirectory(const BDirectory &dir) BDirectory::BDirectory(const BDirectory& dir)
: :
fDirFd(-1) fDirFd(-1)
{ {
@@ -53,7 +50,7 @@ BDirectory::BDirectory(const BDirectory &dir)
to by the supplied entry_ref. to by the supplied entry_ref.
\param ref the entry_ref referring to the directory \param ref the entry_ref referring to the directory
*/ */
BDirectory::BDirectory(const entry_ref *ref) BDirectory::BDirectory(const entry_ref* ref)
: :
fDirFd(-1) fDirFd(-1)
{ {
@@ -65,7 +62,7 @@ BDirectory::BDirectory(const entry_ref *ref)
to by the supplied node_ref. to by the supplied node_ref.
\param nref the node_ref referring to the directory \param nref the node_ref referring to the directory
*/ */
BDirectory::BDirectory(const node_ref *nref) BDirectory::BDirectory(const node_ref* nref)
: :
fDirFd(-1) fDirFd(-1)
{ {
@@ -77,7 +74,7 @@ BDirectory::BDirectory(const node_ref *nref)
to by the supplied BEntry. to by the supplied BEntry.
\param entry the BEntry referring to the directory \param entry the BEntry referring to the directory
*/ */
BDirectory::BDirectory(const BEntry *entry) BDirectory::BDirectory(const BEntry* entry)
: :
fDirFd(-1) fDirFd(-1)
{ {
@@ -89,7 +86,7 @@ BDirectory::BDirectory(const BEntry *entry)
to by the supplied path name. to by the supplied path name.
\param path the directory's path name \param path the directory's path name
*/ */
BDirectory::BDirectory(const char *path) BDirectory::BDirectory(const char* path)
: :
fDirFd(-1) fDirFd(-1)
{ {
@@ -103,7 +100,7 @@ BDirectory::BDirectory(const char *path)
given given
\param path the directory's path name relative to \a dir \param path the directory's path name relative to \a dir
*/ */
BDirectory::BDirectory(const BDirectory *dir, const char *path) BDirectory::BDirectory(const BDirectory* dir, const char* path)
: :
fDirFd(-1) fDirFd(-1)
{ {
@@ -140,7 +137,7 @@ BDirectory::~BDirectory()
- \c B_NO_MORE_FDS: The application has run out of file descriptors. - \c B_NO_MORE_FDS: The application has run out of file descriptors.
*/ */
status_t status_t
BDirectory::SetTo(const entry_ref *ref) BDirectory::SetTo(const entry_ref* ref)
{ {
// open node // open node
status_t error = _SetTo(ref, true); status_t error = _SetTo(ref, true);
@@ -177,7 +174,7 @@ BDirectory::SetTo(const entry_ref *ref)
- \c B_NO_MORE_FDS: The application has run out of file descriptors. - \c B_NO_MORE_FDS: The application has run out of file descriptors.
*/ */
status_t status_t
BDirectory::SetTo(const node_ref *nref) BDirectory::SetTo(const node_ref* nref)
{ {
Unset(); Unset();
status_t error = (nref ? B_OK : B_BAD_VALUE); status_t error = (nref ? B_OK : B_BAD_VALUE);
@@ -205,7 +202,7 @@ BDirectory::SetTo(const node_ref *nref)
- \c B_NO_MORE_FDS: The application has run out of file descriptors. - \c B_NO_MORE_FDS: The application has run out of file descriptors.
*/ */
status_t status_t
BDirectory::SetTo(const BEntry *entry) BDirectory::SetTo(const BEntry* entry)
{ {
if (!entry) { if (!entry) {
Unset(); Unset();
@@ -249,7 +246,7 @@ BDirectory::SetTo(const BEntry *entry)
- \c B_NOT_A_DIRECTORY: \a path includes a non-directory. - \c B_NOT_A_DIRECTORY: \a path includes a non-directory.
*/ */
status_t status_t
BDirectory::SetTo(const char *path) BDirectory::SetTo(const char* path)
{ {
// open node // open node
status_t error = _SetTo(-1, path, true); status_t error = _SetTo(-1, path, true);
@@ -290,7 +287,7 @@ BDirectory::SetTo(const char *path)
- \c B_NOT_A_DIRECTORY: \a path includes a non-directory. - \c B_NOT_A_DIRECTORY: \a path includes a non-directory.
*/ */
status_t status_t
BDirectory::SetTo(const BDirectory *dir, const char *path) BDirectory::SetTo(const BDirectory* dir, const char* path)
{ {
if (!dir || !path || BPrivate::Storage::is_absolute_path(path)) { if (!dir || !path || BPrivate::Storage::is_absolute_path(path)) {
Unset(); Unset();
@@ -344,7 +341,7 @@ BDirectory::SetTo(const BDirectory *dir, const char *path)
- \c B_NO_MORE_FDS: The application has run out of file descriptors. - \c B_NO_MORE_FDS: The application has run out of file descriptors.
*/ */
status_t status_t
BDirectory::GetEntry(BEntry *entry) const BDirectory::GetEntry(BEntry* entry) const
{ {
if (!entry) if (!entry)
return B_BAD_VALUE; return B_BAD_VALUE;
@@ -402,24 +399,27 @@ BDirectory::IsRootDirectory() const
function does. function does.
*/ */
status_t status_t
BDirectory::FindEntry(const char *path, BEntry *entry, bool traverse) const BDirectory::FindEntry(const char* path, BEntry* entry, bool traverse) const
{ {
status_t error = (path && entry ? B_OK : B_BAD_VALUE); if (path == NULL || entry == NULL)
if (entry) return B_BAD_VALUE;
entry->Unset();
// init a potentially abstract entry
status_t status;
if (InitCheck() == B_OK)
status = entry->SetTo(this, path, traverse);
else
status = entry->SetTo(path, traverse);
// fail, if entry is abstract
if (status == B_OK && !entry->Exists()) {
status = B_ENTRY_NOT_FOUND;
entry->Unset(); entry->Unset();
if (error == B_OK) {
// init a potentially abstract entry
if (InitCheck() == B_OK)
error = entry->SetTo(this, path, traverse);
else
error = entry->SetTo(path, traverse);
// fail, if entry is abstract
if (error == B_OK && !entry->Exists()) {
error = B_ENTRY_NOT_FOUND;
entry->Unset();
}
} }
return error;
return status;
} }
@@ -449,7 +449,7 @@ BDirectory::FindEntry(const char *path, BEntry *entry, bool traverse) const
- \c false, otherwise - \c false, otherwise
*/ */
bool bool
BDirectory::Contains(const char *path, int32 nodeFlags) const BDirectory::Contains(const char* path, int32 nodeFlags) const
{ {
// check initialization and parameters // check initialization and parameters
if (InitCheck() != B_OK) if (InitCheck() != B_OK)
@@ -484,7 +484,7 @@ BDirectory::Contains(const char *path, int32 nodeFlags) const
- \c false, otherwise - \c false, otherwise
*/ */
bool bool
BDirectory::Contains(const BEntry *entry, int32 nodeFlags) const BDirectory::Contains(const BEntry* entry, int32 nodeFlags) const
{ {
// check, if the entry exists at all // check, if the entry exists at all
if (entry == NULL || !entry->Exists() || InitCheck() != B_OK) if (entry == NULL || !entry->Exists() || InitCheck() != B_OK)
@@ -522,7 +522,7 @@ BDirectory::Contains(const BEntry *entry, int32 nodeFlags) const
} }
/*! \fn status_t BDirectory::GetStatFor(const char *path, struct stat *st) const /*! \fn status_t BDirectory::GetStatFor(const char* path, struct stat* st) const
\brief Returns the stat structure of the entry referred to by the supplied \brief Returns the stat structure of the entry referred to by the supplied
path name. path name.
\param path the entry's path name. May be relative to this directory or \param path the entry's path name. May be relative to this directory or
@@ -563,7 +563,7 @@ BDirectory::Contains(const BEntry *entry, int32 nodeFlags) const
- \c B_NO_MORE_FDS: The application has run out of file descriptors. - \c B_NO_MORE_FDS: The application has run out of file descriptors.
*/ */
status_t status_t
BDirectory::GetNextEntry(BEntry *entry, bool traverse) BDirectory::GetNextEntry(BEntry* entry, bool traverse)
{ {
status_t error = (entry ? B_OK : B_BAD_VALUE); status_t error = (entry ? B_OK : B_BAD_VALUE);
if (error == B_OK) { if (error == B_OK) {
@@ -596,7 +596,7 @@ BDirectory::GetNextEntry(BEntry *entry, bool traverse)
- \c B_NO_MORE_FDS: The application has run out of file descriptors. - \c B_NO_MORE_FDS: The application has run out of file descriptors.
*/ */
status_t status_t
BDirectory::GetNextRef(entry_ref *ref) BDirectory::GetNextRef(entry_ref* ref)
{ {
status_t error = (ref ? B_OK : B_BAD_VALUE); status_t error = (ref ? B_OK : B_BAD_VALUE);
if (error == B_OK && InitCheck() != B_OK) if (error == B_OK && InitCheck() != B_OK)
@@ -643,7 +643,7 @@ BDirectory::GetNextRef(entry_ref *ref)
- \c B_NO_MORE_FDS: The application has run out of file descriptors. - \c B_NO_MORE_FDS: The application has run out of file descriptors.
*/ */
int32 int32
BDirectory::GetNextDirents(dirent *buf, size_t bufSize, int32 count) BDirectory::GetNextDirents(dirent* buf, size_t bufSize, int32 count)
{ {
if (!buf) if (!buf)
return B_BAD_VALUE; return B_BAD_VALUE;
@@ -725,7 +725,7 @@ BDirectory::CountEntries()
- \c B_NO_MORE_FDS: The application has run out of file descriptors. - \c B_NO_MORE_FDS: The application has run out of file descriptors.
*/ */
status_t status_t
BDirectory::CreateDirectory(const char *path, BDirectory *dir) BDirectory::CreateDirectory(const char* path, BDirectory* dir)
{ {
if (!path) if (!path)
return B_BAD_VALUE; return B_BAD_VALUE;
@@ -774,15 +774,16 @@ BDirectory::CreateDirectory(const char *path, BDirectory *dir)
- \c B_NO_MORE_FDS: The application has run out of file descriptors. - \c B_NO_MORE_FDS: The application has run out of file descriptors.
*/ */
status_t status_t
BDirectory::CreateFile(const char *path, BFile *file, bool failIfExists) BDirectory::CreateFile(const char* path, BFile* file, bool failIfExists)
{ {
if (!path) if (!path)
return B_BAD_VALUE; return B_BAD_VALUE;
// Let BFile do the dirty job. // Let BFile do the dirty job.
uint32 openMode = B_READ_WRITE | B_CREATE_FILE | B_ERASE_FILE uint32 openMode = B_READ_WRITE | B_CREATE_FILE | B_ERASE_FILE
| (failIfExists ? B_FAIL_IF_EXISTS : 0); | (failIfExists ? B_FAIL_IF_EXISTS : 0);
BFile tmpFile; BFile tmpFile;
BFile *realFile = file ? file : &tmpFile; BFile* realFile = file ? file : &tmpFile;
status_t error = B_OK; status_t error = B_OK;
if (InitCheck() == B_OK && !BPrivate::Storage::is_absolute_path(path)) if (InitCheck() == B_OK && !BPrivate::Storage::is_absolute_path(path))
error = realFile->SetTo(this, path, openMode); error = realFile->SetTo(this, path, openMode);
@@ -814,8 +815,8 @@ BDirectory::CreateFile(const char *path, BFile *file, bool failIfExists)
- \c B_NO_MORE_FDS: The application has run out of file descriptors. - \c B_NO_MORE_FDS: The application has run out of file descriptors.
*/ */
status_t status_t
BDirectory::CreateSymLink(const char *path, const char *linkToPath, BDirectory::CreateSymLink(const char* path, const char* linkToPath,
BSymLink *link) BSymLink* link)
{ {
if (!path || !linkToPath) if (!path || !linkToPath)
return B_BAD_VALUE; return B_BAD_VALUE;
@@ -843,8 +844,8 @@ BDirectory::CreateSymLink(const char *path, const char *linkToPath,
\param dir the original BDirectory \param dir the original BDirectory
\return a reference to this BDirectory \return a reference to this BDirectory
*/ */
BDirectory & BDirectory&
BDirectory::operator=(const BDirectory &dir) BDirectory::operator=(const BDirectory& dir)
{ {
if (&dir != this) { // no need to assign us to ourselves if (&dir != this) { // no need to assign us to ourselves
Unset(); Unset();
@@ -856,7 +857,7 @@ BDirectory::operator=(const BDirectory &dir)
status_t status_t
BDirectory::_GetStatFor(const char *path, struct stat *st) const BDirectory::_GetStatFor(const char* path, struct stat* st) const
{ {
if (!st) if (!st)
return B_BAD_VALUE; return B_BAD_VALUE;
@@ -873,7 +874,7 @@ BDirectory::_GetStatFor(const char *path, struct stat *st) const
status_t status_t
BDirectory::_GetStatFor(const char *path, struct stat_beos *st) const BDirectory::_GetStatFor(const char* path, struct stat_beos* st) const
{ {
struct stat newStat; struct stat newStat;
status_t error = _GetStatFor(path, &newStat); status_t error = _GetStatFor(path, &newStat);
@@ -940,10 +941,11 @@ BDirectory::get_fd() const
\todo Check for efficency. \todo Check for efficency.
*/ */
status_t status_t
create_directory(const char *path, mode_t mode) create_directory(const char* path, mode_t mode)
{ {
if (!path) if (!path)
return B_BAD_VALUE; return B_BAD_VALUE;
// That's the strategy: We start with the first component of the supplied // That's the strategy: We start with the first component of the supplied
// path, create a BPath object from it and successively add the following // path, create a BPath object from it and successively add the following
// components. Each time we get a new path, we check, if the entry it // components. Each time we get a new path, we check, if the entry it
@@ -951,7 +953,7 @@ create_directory(const char *path, mode_t mode)
// to create it. This goes on, until we're done with the input path or // to create it. This goes on, until we're done with the input path or
// an error occurs. // an error occurs.
BPath dirPath; BPath dirPath;
char *component; char* component;
int32 nextComponent; int32 nextComponent;
do { do {
// get the next path component // get the next path component
@@ -959,6 +961,7 @@ create_directory(const char *path, mode_t mode)
component, nextComponent); component, nextComponent);
if (error != B_OK) if (error != B_OK)
return error; return error;
// append it to the BPath // append it to the BPath
if (dirPath.InitCheck() == B_NO_INIT) // first component if (dirPath.InitCheck() == B_NO_INIT) // first component
error = dirPath.SetTo(component); error = dirPath.SetTo(component);
@@ -968,11 +971,13 @@ create_directory(const char *path, mode_t mode)
if (error != B_OK) if (error != B_OK)
return error; return error;
path += nextComponent; path += nextComponent;
// create a BEntry from the BPath // create a BEntry from the BPath
BEntry entry; BEntry entry;
error = entry.SetTo(dirPath.Path(), true); error = entry.SetTo(dirPath.Path(), true);
if (error != B_OK) if (error != B_OK)
return error; return error;
// check, if it exists // check, if it exists
if (entry.Exists()) { if (entry.Exists()) {
// yep, it exists // yep, it exists
+14 -23
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2008, Haiku Inc. * Copyright 2002-2009, Haiku Inc.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
@@ -19,17 +19,13 @@
#include "storage_support.h" #include "storage_support.h"
#include <syscalls.h> #include <syscalls.h>
#include <umask.h>
extern mode_t __gUmask;
// declared in sys/umask.c
//! Creates an uninitialized BFile. //! Creates an uninitialized BFile.
BFile::BFile() BFile::BFile()
: BNode(), :
BPositionIO(), fMode(0)
fMode(0)
{ {
} }
@@ -39,9 +35,8 @@ BFile::BFile()
\param file the BFile object to be copied \param file the BFile object to be copied
*/ */
BFile::BFile(const BFile &file) BFile::BFile(const BFile &file)
: BNode(), :
BPositionIO(), fMode(0)
fMode(0)
{ {
*this = file; *this = file;
} }
@@ -54,9 +49,8 @@ BFile::BFile(const BFile &file)
\see SetTo() for values for \a openMode \see SetTo() for values for \a openMode
*/ */
BFile::BFile(const entry_ref *ref, uint32 openMode) BFile::BFile(const entry_ref *ref, uint32 openMode)
: BNode(), :
BPositionIO(), fMode(0)
fMode(0)
{ {
SetTo(ref, openMode); SetTo(ref, openMode);
} }
@@ -69,9 +63,8 @@ BFile::BFile(const entry_ref *ref, uint32 openMode)
\see SetTo() for values for \a openMode \see SetTo() for values for \a openMode
*/ */
BFile::BFile(const BEntry *entry, uint32 openMode) BFile::BFile(const BEntry *entry, uint32 openMode)
: BNode(), :
BPositionIO(), fMode(0)
fMode(0)
{ {
SetTo(entry, openMode); SetTo(entry, openMode);
} }
@@ -84,9 +77,8 @@ BFile::BFile(const BEntry *entry, uint32 openMode)
\see SetTo() for values for \a openMode \see SetTo() for values for \a openMode
*/ */
BFile::BFile(const char *path, uint32 openMode) BFile::BFile(const char *path, uint32 openMode)
: BNode(), :
BPositionIO(), fMode(0)
fMode(0)
{ {
SetTo(path, openMode); SetTo(path, openMode);
} }
@@ -102,9 +94,8 @@ BFile::BFile(const char *path, uint32 openMode)
\see SetTo() for values for \a openMode \see SetTo() for values for \a openMode
*/ */
BFile::BFile(const BDirectory *dir, const char *path, uint32 openMode) BFile::BFile(const BDirectory *dir, const char *path, uint32 openMode)
: BNode(), :
BPositionIO(), fMode(0)
fMode(0)
{ {
SetTo(dir, path, openMode); SetTo(dir, path, openMode);
} }
+1 -1
View File
@@ -4,7 +4,7 @@ SetSubDirSupportedPlatforms haiku libbe_test ;
UseLibraryHeaders icon ; UseLibraryHeaders icon ;
UsePrivateHeaders shared app storage ; UsePrivateHeaders app libroot shared storage ;
UsePrivateSystemHeaders ; UsePrivateSystemHeaders ;
# for libbe_test # for libbe_test
+1 -1
View File
@@ -1,6 +1,6 @@
SubDir HAIKU_TOP src system libroot posix sys ; SubDir HAIKU_TOP src system libroot posix sys ;
UsePrivateHeaders shared ; UsePrivateHeaders libroot shared ;
UsePrivateSystemHeaders ; UsePrivateSystemHeaders ;
MergeObject posix_sys.o : MergeObject posix_sys.o :
+3 -5
View File
@@ -1,16 +1,14 @@
/* /*
* Copyright 2002-2008, Axel Dörfler, [email protected]. * Copyright 2002-2009, Axel Dörfler, [email protected].
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
*/ */
#include <sys/stat.h> #include <sys/stat.h>
#include <syscalls.h>
#include <errno.h> #include <errno.h>
#include <syscalls.h>
extern mode_t __gUmask; #include <umask.h>
// declared in sys/umask.c
#define RETURN_AND_SET_ERRNO(err) \ #define RETURN_AND_SET_ERRNO(err) \
+6 -4
View File
@@ -1,13 +1,15 @@
/* /*
** Copyright 2004, Axel Dörfler, [email protected]. All rights reserved. * Copyright 2004-2009, Axel Dörfler, [email protected].
** Distributed under the terms of the Haiku License. * Distributed under the terms of the MIT License.
*/ */
#include <sys/stat.h> #include <sys/stat.h>
#include <syscalls.h>
#include <errno.h> #include <errno.h>
#include <syscalls.h>
#include <umask.h>
mode_t __gUmask = 022; mode_t __gUmask = 022;
// this must be made available to open() and friends // this must be made available to open() and friends
+4 -6
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2005, Axel Dörfler, [email protected]. All rights reserved. * Copyright 2002-2009, Axel Dörfler, [email protected].
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Copyright 2001, Manuel J. Petit. All rights reserved. * Copyright 2001, Manuel J. Petit. All rights reserved.
@@ -13,16 +13,14 @@
#include <errno.h> #include <errno.h>
#include <syscalls.h> #include <syscalls.h>
#include <umask.h>
extern mode_t __gUmask;
// declared in sys/umask.c
int int
creat(const char *path, mode_t mode) creat(const char *path, mode_t mode)
{ {
int status = _kern_open(-1, path, O_CREAT | O_TRUNC | O_WRONLY, mode & ~__gUmask); int status = _kern_open(-1, path, O_CREAT | O_TRUNC | O_WRONLY,
mode & ~__gUmask);
// adapt the permissions as required by POSIX // adapt the permissions as required by POSIX
if (status < 0) { if (status < 0) {
errno = status; errno = status;