* BEntry::GetStat() and BNode::GetStat() used sizeof(struct stat) for the kernel

syscall, but they could not know if R5 code called them (in which case the stat
  size has a different size). We now always only return the R5 stat structure here.
  This fixes bug #420. We might want to find a different solution to this problem,
  though.
* Be got SYMLINK_MAX wrong - it's not the maximum number of links (that's SYMLOOP_MAX),
  but the maximum size of a symlink buffer. Added missing SYMLOOP_MAX and SYMLINK_MAX
  constants to limits.h.
* Fixes MAXSYMLINKS to use SYMLOOP_MAX, instead of SYMLINKS_MAX (which doesn't exist
  in POSIX specs, but we (intentionally) break source compatibility here).
* Reenabled the Haiku versions of stat(), fstat(), and lstat() when build for Haiku.
* Removed OpenBeOS namespace stuff from the files I touched.
* Removed superfluous StorageDefs.Private.h, whyever that ended up in a public header
  is beyond me.
* Cleanup.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@17894 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2006-06-21 13:49:16 +00:00
parent dbd51bbab9
commit 7b3d36e5aa
12 changed files with 227 additions and 336 deletions
+6 -36
View File
@@ -1,37 +1,18 @@
//---------------------------------------------------------------------- /*
// This software is part of the OpenBeOS distribution and is covered * Copyright 2002-2006, Haiku, Inc. All Rights Reserved.
// by the OpenBeOS license. * Distributed under the terms of the MIT License.
//---------------------------------------------------------------------
/*!
\file Directory.h
BDirectory interface declaration.
*/ */
#ifndef _DIRECTORY_H #ifndef _DIRECTORY_H
#define _DIRECTORY_H #define _DIRECTORY_H
#include <Node.h> #include <Node.h>
#include <EntryList.h> #include <EntryList.h>
#include <StorageDefs.h> #include <StorageDefs.h>
#include <StorageDefs.Private.h>
#ifdef USE_OPENBEOS_NAMESPACE
namespace OpenBeOS {
#endif
class BSymLink; class BSymLink;
/*!
\class BDirectory
\brief A directory in the filesystem
Provides an interface for manipulating directories and their contents.
\author <a href='mailto:[email protected]'>Ingo Weinhold</a>
\author <a href="mailto:[email protected]">Tyler Dauwalder</a>
\version 0.0.0
*/
class BDirectory : public BNode, public BEntryList { class BDirectory : public BNode, public BEntryList {
public: public:
BDirectory(); BDirectory();
@@ -79,6 +60,8 @@ public:
private: private:
friend class BNode; friend class BNode;
friend class BEntry;
friend class BFile;
virtual void _ErectorDirectory1(); virtual void _ErectorDirectory1();
virtual void _ErectorDirectory2(); virtual void _ErectorDirectory2();
@@ -94,21 +77,8 @@ private:
private: private:
uint32 _reservedData[7]; uint32 _reservedData[7];
int fDirFd; int fDirFd;
friend class BEntry;
friend class BFile;
}; };
// C functions
status_t create_directory(const char *path, mode_t mode); status_t create_directory(const char *path, mode_t mode);
#ifdef USE_OPENBEOS_NAMESPACE
}; // namespace OpenBeOS
#endif
#endif // _DIRECTORY_H #endif // _DIRECTORY_H
+4 -30
View File
@@ -1,35 +1,15 @@
//---------------------------------------------------------------------- /*
// This software is part of the OpenBeOS distribution and is covered * Copyright 2002-2006, Haiku, Inc. All Rights Reserved.
// by the OpenBeOS license. * Distributed under the terms of the MIT License.
//---------------------------------------------------------------------
/*!
\file File.h
BFile interface declaration.
*/ */
#ifndef _FILE_H #ifndef _FILE_H
#define _FILE_H #define _FILE_H
#include <DataIO.h> #include <DataIO.h>
#include <Node.h> #include <Node.h>
#include <StorageDefs.Private.h>
#ifdef USE_OPENBEOS_NAMESPACE
namespace OpenBeOS {
#endif
/*!
\class BFile
\brief BFile is a wrapper class for common operations on files providing
access to the file's content data and its attributes.
A BFile represents a file in some file system. It implements the
BPositionIO interface and thus the methods to read from and write to the
file, and is derived of BNode to provide access to the file's attributes.
\author <a href='mailto:[email protected]'>Ingo Weinhold</a>
\version 0.0.0
*/
class BFile : public BNode, public BPositionIO { class BFile : public BNode, public BPositionIO {
public: public:
BFile(); BFile();
@@ -80,10 +60,4 @@ private:
uint32 fMode; uint32 fMode;
}; };
#ifdef USE_OPENBEOS_NAMESPACE
}; // namespace OpenBeOS
#endif
#endif // _FILE_H #endif // _FILE_H
+10 -33
View File
@@ -1,36 +1,20 @@
//---------------------------------------------------------------------- /*
// This software is part of the OpenBeOS distribution and is covered * Copyright 2002-2006, Haiku, Inc. All Rights Reserved.
// by the OpenBeOS license. * Distributed under the terms of the MIT License.
//---------------------------------------------------------------------
/*!
\file Statable.h
BStatable interface declaration.
*/ */
#ifndef _STATABLE_H #ifndef _STATABLE_H
#define _STATABLE_H #define _STATABLE_H
#include <sys/types.h>
#include <sys/stat.h>
#include <SupportDefs.h> #include <SupportDefs.h>
#ifdef USE_OPENBEOS_NAMESPACE #include <sys/types.h>
namespace OpenBeOS { #include <sys/stat.h>
#endif // USE_OPENBEOS_NAMESPACE
struct node_ref; struct node_ref;
class BVolume; class BVolume;
//! BStatable - A nice C++ wrapper to <code>stat()</code>
/*! A purly abstract class which provieds an expenive, but convenet
* C++ wrapper to the posix <code>\sa stat()</code> command.
*
* @see <a href="http://www.opensource.org/licenses/mit-license.html">MIT</a>
* @author <a href="mailto:[email protected]"> Michael Lloyd Lee </a>
* @author Be Inc
* @version 0
*/
class BStatable { class BStatable {
public: public:
virtual status_t GetStat(struct stat *st) const = 0; virtual status_t GetStat(struct stat *st) const = 0;
@@ -64,22 +48,15 @@ public:
status_t GetVolume(BVolume *vol) const; status_t GetVolume(BVolume *vol) const;
private: private:
friend class BEntry; friend class BEntry;
friend class BNode; friend class BNode;
virtual void _OhSoStatable1(); //< FBC virtual void _OhSoStatable1();
virtual void _OhSoStatable2(); //< FBC virtual void _OhSoStatable2();
virtual void _OhSoStatable3(); //< FBC virtual void _OhSoStatable3();
uint32 _ohSoData[4]; //< FBC uint32 _reserved[4];
virtual status_t set_stat(struct stat &st, uint32 what) = 0; virtual status_t set_stat(struct stat &st, uint32 what) = 0;
}; };
#ifdef USE_OPENBEOS_NAMESPACE
}
#endif // USE_OPENBEOS_NAMESPACE
#endif // _STATABLE_H #endif // _STATABLE_H
-21
View File
@@ -1,21 +0,0 @@
//----------------------------------------------------------------------
// This software is part of the OpenBeOS distribution and is covered
// by the OpenBeOS license.
//---------------------------------------------------------------------
/*!
\file StorageDefs.Private.h
Private Storage Kit declarations needed in public headers.
*/
#ifndef _DEF_STORAGE_PRIVATE_H
#define _DEF_STORAGE_PRIVATE_H
namespace BPrivate {
namespace Storage {
typedef int FileDescriptor;
};
};
#endif // _DEF_STORAGE_PRIVATE_H
+5 -23
View File
@@ -1,22 +1,15 @@
//---------------------------------------------------------------------- /*
// This software is part of the OpenBeOS distribution and is covered * Copyright 2002-2006, Haiku, Inc. All Rights Reserved.
// by the OpenBeOS license. * Distributed under the terms of the MIT License.
//---------------------------------------------------------------------
/*!
\file StorageDefs.h
Miscellaneous Storage Kit definitions and includes.
*/ */
#ifndef _DEF_STORAGE_H #ifndef _DEF_STORAGE_H
#define _DEF_STORAGE_H #define _DEF_STORAGE_H
#include <fcntl.h> #include <fcntl.h>
#include <sys/param.h> #include <sys/param.h>
#include <limits.h> #include <limits.h>
#ifdef USE_OPENBEOS_NAMESPACE
namespace OpenBeOS {
#endif // USE_OPENBEOS_NAMESPACE
// Limits // Limits
#define B_DEV_NAME_LENGTH 128 #define B_DEV_NAME_LENGTH 128
@@ -24,8 +17,7 @@ namespace OpenBeOS {
#define B_PATH_NAME_LENGTH MAXPATHLEN #define B_PATH_NAME_LENGTH MAXPATHLEN
#define B_ATTR_NAME_LENGTH (B_FILE_NAME_LENGTH-1) #define B_ATTR_NAME_LENGTH (B_FILE_NAME_LENGTH-1)
#define B_MIME_TYPE_LENGTH (B_ATTR_NAME_LENGTH - 15) #define B_MIME_TYPE_LENGTH (B_ATTR_NAME_LENGTH - 15)
#define B_MAX_SYMLINKS SYMLINK_MAX #define B_MAX_SYMLINKS SYMLOOP_MAX
// Open Modes // Open Modes
#define B_READ_ONLY O_RDONLY // read only #define B_READ_ONLY O_RDONLY // read only
@@ -37,7 +29,6 @@ namespace OpenBeOS {
#define B_ERASE_FILE O_TRUNC // erase the file's data #define B_ERASE_FILE O_TRUNC // erase the file's data
#define B_OPEN_AT_END O_APPEND // point to the end of the data #define B_OPEN_AT_END O_APPEND // point to the end of the data
// Node Flavors // Node Flavors
enum node_flavor { enum node_flavor {
B_FILE_NODE = 0x01, B_FILE_NODE = 0x01,
@@ -46,13 +37,4 @@ enum node_flavor {
B_ANY_NODE = 0x07 B_ANY_NODE = 0x07
}; };
#ifdef USE_OPENBEOS_NAMESPACE
}; // namespace OpenBeOS
#endif // USE_OPENBEOS_NAMESPACE
#endif // _DEF_STORAGE_H #endif // _DEF_STORAGE_H
+2 -1
View File
@@ -41,7 +41,8 @@
#define SSIZE_MAX (2147483647L) #define SSIZE_MAX (2147483647L)
#define TTY_NAME_MAX (256) #define TTY_NAME_MAX (256)
#define TZNAME_MAX (32) #define TZNAME_MAX (32)
#define SYMLINKS_MAX (16) #define SYMLINK_MAX (1024)
#define SYMLOOP_MAX (16)
#define _POSIX_ARG_MAX (32768) #define _POSIX_ARG_MAX (32768)
#define _POSIX_CHILD_MAX (1024) #define _POSIX_CHILD_MAX (1024)
+1 -1
View File
@@ -7,7 +7,7 @@
#include <limits.h> #include <limits.h>
#define MAXPATHLEN PATH_MAX #define MAXPATHLEN PATH_MAX
#define MAXSYMLINKS SYMLINKS_MAX #define MAXSYMLINKS SYMLOOP_MAX
#define NOFILE OPEN_MAX #define NOFILE OPEN_MAX
+18 -16
View File
@@ -1,11 +1,13 @@
/*
* Copyright 2002-2006, Haiku Inc. All Rights Reserved.
* Distributed under the terms of the MIT License.
*/
#ifndef _SYS_STAT_H_ #ifndef _SYS_STAT_H_
#define _SYS_STAT_H_ #define _SYS_STAT_H_
#include <sys/types.h> #include <sys/types.h>
/*
* stat structure
*/
struct stat { struct stat {
dev_t st_dev; /* "device" that this file resides on */ dev_t st_dev; /* "device" that this file resides on */
@@ -22,8 +24,10 @@ struct stat {
time_t st_ctime; /* last change time, not creation time */ time_t st_ctime; /* last change time, not creation time */
time_t st_crtime; /* creation time */ time_t st_crtime; /* creation time */
// OpenBeOS extensions: // Haiku extensions:
// ToDo: we might also define special types for files and TTYs // TODO: we might also define special types for files and TTYs
// TODO: we should find another solution for this, as BStatable::GetStat()
// can only retrieve the R5 stat structure
unsigned int st_type; /* attribute/index type */ unsigned int st_type; /* attribute/index type */
}; };
@@ -53,13 +57,13 @@ struct stat {
#define S_IFCHR 00000020000 /* character special */ #define S_IFCHR 00000020000 /* character special */
#define S_IFIFO 00000010000 /* fifo */ #define S_IFIFO 00000010000 /* fifo */
#define S_ISREG(m) (((m) & S_IFMT) == S_IFREG) #define S_ISREG(mode) (((mode) & S_IFMT) == S_IFREG)
#define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK) #define S_ISLNK(mode) (((mode) & S_IFMT) == S_IFLNK)
#define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK) #define S_ISBLK(mode) (((mode) & S_IFMT) == S_IFBLK)
#define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR) #define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR)
#define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR) #define S_ISCHR(mode) (((mode) & S_IFMT) == S_IFCHR)
#define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO) #define S_ISFIFO(mode) (((mode) & S_IFMT) == S_IFIFO)
#define S_ISINDEX(m) (((m) & S_INDEX_DIR) == S_INDEX_DIR) #define S_ISINDEX(mode) (((mode) & S_INDEX_DIR) == S_INDEX_DIR)
#define S_IUMSK 07777 /* user settable bits */ #define S_IUMSK 07777 /* user settable bits */
@@ -81,12 +85,10 @@ struct stat {
#define S_IWOTH 00002 /* write permission: other */ #define S_IWOTH 00002 /* write permission: other */
#define S_IXOTH 00001 /* execute permission: other */ #define S_IXOTH 00001 /* execute permission: other */
/** @def ACCESSPERMS 00777 */
#define ACCESSPERMS (S_IRWXU | S_IRWXG | S_IRWXO) #define ACCESSPERMS (S_IRWXU | S_IRWXG | S_IRWXO)
/** @def ALLPERMS 07777 */
#define ALLPERMS (S_ISUID | S_ISGID | S_ISTXT | S_IRWXU | S_IRWXG | S_IRWXO) #define ALLPERMS (S_ISUID | S_ISGID | S_ISTXT | S_IRWXU | S_IRWXG | S_IRWXO)
/** @def DEFFILEMODE 00666 default file mode, everyone can read/write*/
#define DEFFILEMODE (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH) #define DEFFILEMODE (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH)
/* default file mode, everyone can read/write */
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
@@ -102,7 +104,7 @@ extern int mkfifo(const char *path, mode_t mode);
extern mode_t umask(mode_t cmask); extern mode_t umask(mode_t cmask);
// This achieves backwards compatibility with R5 // This achieves backwards compatibility with R5
#if 0 #ifdef HAIKU_TARGET_PLATFORM_HAIKU
#define stat(fd, st) _stat(fd, st, sizeof(struct stat)) #define stat(fd, st) _stat(fd, st, sizeof(struct stat))
#define fstat(fd, st) _fstat(fd, st, sizeof(struct stat)) #define fstat(fd, st) _fstat(fd, st, sizeof(struct stat))
#define lstat(fd, st) _lstat(fd, st, sizeof(struct stat)) #define lstat(fd, st) _lstat(fd, st, sizeof(struct stat))
+4 -2
View File
@@ -21,6 +21,10 @@
#include <string> #include <string>
// R5 compatibility
#define R5_STAT_SIZE 60
namespace BPrivate { namespace BPrivate {
namespace Storage { namespace Storage {
@@ -149,5 +153,3 @@ private:
using BPrivate::Storage::FDCloser; using BPrivate::Storage::FDCloser;
#endif // _STORAGE_SUPPORT_H #endif // _STORAGE_SUPPORT_H
+26 -27
View File
@@ -1,18 +1,18 @@
//---------------------------------------------------------------------- /*
// This software is part of the Haiku distribution and is covered * Copyright 2002-2006, Haiku Inc.
// by the MIT license. * Distributed under the terms of the MIT License.
//--------------------------------------------------------------------- *
* Authors:
* Tyler Dauwalder
* Ingo Weinhold, [email protected]
*/
/*! /*!
\file Entry.cpp \file Entry.cpp
BEntry and entry_ref implementations. BEntry and entry_ref implementations.
*/ */
#include <fcntl.h>
#include <new>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <Directory.h> #include <Directory.h>
#include <Entry.h> #include <Entry.h>
#include <Path.h> #include <Path.h>
@@ -21,21 +21,17 @@
#include <syscalls.h> #include <syscalls.h>
#ifdef USE_OPENBEOS_NAMESPACE #include <fcntl.h>
using namespace OpenBeOS; #include <new>
#endif #include <stdio.h>
#include <string.h>
#include <unistd.h>
using namespace std; using namespace std;
// SYMLINK_MAX is needed by B_SYMLINK_MAX
// I don't know, why it isn't defined.
#ifndef SYMLINK_MAX
#define SYMLINK_MAX (16)
#endif
//---------------------------------------------------------------------------- // #pragma mark - struct entry_ref
// struct entry_ref
//----------------------------------------------------------------------------
/*! \struct entry_ref /*! \struct entry_ref
\brief A filesystem entry represented as a name in a concrete directory. \brief A filesystem entry represented as a name in a concrete directory.
@@ -184,9 +180,8 @@ entry_ref::operator=(const entry_ref &ref)
*/ */
//---------------------------------------------------------------------------- // #pragma mark - BEntry
// BEntry
//----------------------------------------------------------------------------
/*! /*!
\class BEntry \class BEntry
@@ -219,7 +214,8 @@ entry_ref::operator=(const entry_ref &ref)
- operator=(const BEntry&) - operator=(const BEntry&)
*/ */
BEntry::BEntry() BEntry::BEntry()
: fDirFd(-1), :
fDirFd(-1),
fName(NULL), fName(NULL),
fCStatus(B_NO_INIT) fCStatus(B_NO_INIT)
{ {
@@ -322,9 +318,10 @@ BEntry::Exists() const
{ {
// just stat the beast // just stat the beast
struct stat st; struct stat st;
return (GetStat(&st) == B_OK); return GetStat(&st) == B_OK;
} }
/*! \brief Fills in a stat structure for the entry. The information is copied into /*! \brief Fills in a stat structure for the entry. The information is copied into
the \c stat structure pointed to by \a result. the \c stat structure pointed to by \a result.
@@ -341,9 +338,11 @@ BEntry::GetStat(struct stat *result) const
{ {
if (fCStatus != B_OK) if (fCStatus != B_OK)
return B_NO_INIT; return B_NO_INIT;
return _kern_read_stat(fDirFd, fName, false, result, sizeof(struct stat));
return _kern_read_stat(fDirFd, fName, false, result, R5_STAT_SIZE);
} }
/*! \brief Reinitializes the BEntry to the path or directory path combination, /*! \brief Reinitializes the BEntry to the path or directory path combination,
resolving symlinks if traverse is true resolving symlinks if traverse is true
+22 -17
View File
@@ -1,34 +1,39 @@
//---------------------------------------------------------------------- /*
// This software is part of the Haiku distribution and is covered * Copyright 2002-2006, Haiku Inc.
// by the MIT license. * Distributed under the terms of the MIT License.
//---------------------------------------------------------------------- *
* Authors:
* Tyler Dauwalder
* Ingo Weinhold, [email protected]
*/
/*! /*!
\file Node.cpp \file Node.cpp
BNode implementation. BNode implementation.
*/ */
#include <errno.h> #include "storage_support.h"
#include <fcntl.h>
#include <fs_attr.h> // for struct attr_info
#include <new>
#include <string.h>
#include <unistd.h>
#include <Directory.h> #include <Directory.h>
#include <Entry.h> #include <Entry.h>
#include <fs_attr.h>
#include <Node.h> #include <Node.h>
#include <String.h> #include <String.h>
#include <TypeConstants.h> #include <TypeConstants.h>
#include <syscalls.h> #include <syscalls.h>
#include "storage_support.h" #include <errno.h>
#include <fcntl.h>
#include <new>
#include <string.h>
#include <unistd.h>
// #pragma mark - node_ref
//----------------------------------------------------------------------
// node_ref
//----------------------------------------------------------------------
// constructor
/*! \brief Creates an uninitialized node_ref object. /*! \brief Creates an uninitialized node_ref object.
*/ */
node_ref::node_ref() node_ref::node_ref()
@@ -84,7 +89,7 @@ node_ref::operator=(const node_ref &ref)
} }
// #pragma mark - // #pragma mark - BNode
/*! \brief Creates an uninitialized BNode object /*! \brief Creates an uninitialized BNode object
@@ -196,7 +201,7 @@ BNode::GetStat(struct stat *st) const
{ {
return fCStatus != B_OK return fCStatus != B_OK
? fCStatus ? fCStatus
: _kern_read_stat(fFd, NULL, false, st, sizeof(struct stat)); : _kern_read_stat(fFd, NULL, false, st, R5_STAT_SIZE);
} }
+4 -4
View File
@@ -1,11 +1,12 @@
/* /*
** Copyright 2002-2004, Axel Dörfler, [email protected]. All rights reserved. * Copyright 2002-2006, Axel Dörfler, [email protected]. All rights reserved.
** Distributed under the terms of the OpenBeOS License. * Distributed under the terms of the MIT License.
*/ */
#include <sys/stat.h>
#include <syscalls.h> #include <syscalls.h>
#include <sys/stat.h>
#include <errno.h> #include <errno.h>
@@ -18,7 +19,6 @@
// R5 compatibility // R5 compatibility
#define R5_STAT_SIZE 60 #define R5_STAT_SIZE 60
#undef stat #undef stat
#undef fstat #undef fstat