BVolume and BVolumeRoster updates, courtesty of Vincent Dominguez
git-svn-id: file:///srv/svn/repos/haiku/trunk/current@405 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -17,11 +17,9 @@
|
||||
|
||||
#ifndef _FS_INFO_H
|
||||
#include <fs_info.h>
|
||||
//#include "fs_info.h"
|
||||
#endif
|
||||
#ifndef _STORAGE_DEFS_H
|
||||
#include <StorageDefs.h>
|
||||
//#include "StorageDefs.h"
|
||||
#endif
|
||||
#ifndef _MIME_H
|
||||
#include <Mime.h>
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
// ----------------------------------------------------------------------
|
||||
// This software is part of the OpenBeOS distribution and is covered
|
||||
// by the OpenBeOS license.
|
||||
//
|
||||
// File Name: VolumeRoster.h
|
||||
//
|
||||
// Description: BVolumeRoster class
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
|
||||
#ifndef __sk_volumeroster_h__
|
||||
#define __sk_volumeroster_h__
|
||||
|
||||
#ifndef _BE_BUILD_H
|
||||
#include <BeBuild.h>
|
||||
#endif
|
||||
#include <SupportDefs.h>
|
||||
#include <Volume.h>
|
||||
#include <Application.h>
|
||||
|
||||
#ifdef USE_OPENBEOS_NAMESPACE
|
||||
namespace OpenBeOS {
|
||||
#endif
|
||||
|
||||
const char kBootVolumeName[B_DEV_NAME_LENGTH] = "/boot";
|
||||
|
||||
class BVolume;
|
||||
class BMessenger;
|
||||
|
||||
class BVolumeRoster {
|
||||
public:
|
||||
BVolumeRoster(void);
|
||||
virtual ~BVolumeRoster(void);
|
||||
|
||||
status_t GetNextVolume(BVolume* vol);
|
||||
void Rewind(void);
|
||||
|
||||
status_t GetBootVolume(BVolume* boot_vol);
|
||||
status_t StartWatching(BMessenger msngr=be_app_messenger);
|
||||
|
||||
void StopWatching(void);
|
||||
|
||||
BMessenger Messenger(void) const;
|
||||
|
||||
private:
|
||||
|
||||
virtual void _SeveredVRoster1(void);
|
||||
virtual void _SeveredVRoster2(void);
|
||||
|
||||
int32 fPos;
|
||||
BMessenger* fTarget;
|
||||
|
||||
#if !_PR3_COMPATIBLE_
|
||||
uint32 _reserved[3];
|
||||
#endif
|
||||
|
||||
};
|
||||
|
||||
|
||||
#ifdef USE_OPENBEOS_NAMESPACE
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -18,6 +18,7 @@
|
||||
#include <sys/dirent.h> // For dirent
|
||||
#include <sys/stat.h> // For struct stat
|
||||
#include <fcntl.h> // For flock
|
||||
#include <fs_info.h> // File sytem information functions, structs, defines
|
||||
|
||||
// Forward Declarations
|
||||
typedef struct attr_info;
|
||||
@@ -46,6 +47,13 @@ struct LongDirEntry : DirEntry { char _buffer[B_FILE_NAME_LENGTH]; };
|
||||
const FileDescriptor NullFd = -1;
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Device Functions
|
||||
//------------------------------------------------------------------------------
|
||||
/*! Returns information about the file system on the specified device. */
|
||||
status_t stat_dev(dev_t dev, fs_info* info);
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// File Functions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
@@ -39,6 +39,7 @@ SharedLibrary storage :
|
||||
Statable.cpp
|
||||
SymLink.cpp
|
||||
Volume.cpp
|
||||
VolumeRoster.cpp
|
||||
kernel_interface.POSIX.cpp
|
||||
storage_support.cpp
|
||||
;
|
||||
|
||||
+43
-15
@@ -2,18 +2,19 @@
|
||||
// This software is part of the OpenBeOS distribution and is covered
|
||||
// by the OpenBeOS license.
|
||||
//
|
||||
// File Name: Directory.cpp
|
||||
// File Name: Volume.cpp
|
||||
//
|
||||
// Description: BVolume class
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
#include <Volume.h>
|
||||
//#include "Volume.h"
|
||||
|
||||
#include <Directory.h>
|
||||
#include <Bitmap.h>
|
||||
#include <Node.h>
|
||||
#include <errno.h>
|
||||
#include <fs_info.h>
|
||||
#include <kernel_interface.h>
|
||||
|
||||
|
||||
#ifdef USE_OPENBEOS_NAMESPACE
|
||||
@@ -41,6 +42,20 @@ BVolume::BVolume(void)
|
||||
BVolume::BVolume(
|
||||
dev_t dev)
|
||||
{
|
||||
#if !_PR3_COMPATIBLE_
|
||||
// Initialize reserved class variables to "safe" values:
|
||||
_reserved[0] = 0L;
|
||||
_reserved[1] = 0L;
|
||||
_reserved[2] = 0L;
|
||||
_reserved[3] = 0L;
|
||||
_reserved[4] = 0L;
|
||||
_reserved[5] = 0L;
|
||||
_reserved[6] = 0L;
|
||||
_reserved[7] = 0L;
|
||||
// Place this in a separate initialization method at
|
||||
// a later time.
|
||||
#endif
|
||||
|
||||
SetTo(dev);
|
||||
}
|
||||
|
||||
@@ -54,6 +69,20 @@ BVolume::BVolume(
|
||||
BVolume::BVolume(
|
||||
const BVolume& vol)
|
||||
{
|
||||
#if !_PR3_COMPATIBLE_
|
||||
// Initialize reserved class variables to "safe" values:
|
||||
_reserved[0] = 0L;
|
||||
_reserved[1] = 0L;
|
||||
_reserved[2] = 0L;
|
||||
_reserved[3] = 0L;
|
||||
_reserved[4] = 0L;
|
||||
_reserved[5] = 0L;
|
||||
_reserved[6] = 0L;
|
||||
_reserved[7] = 0L;
|
||||
// Place this in a separate initialization method at
|
||||
// a later time.
|
||||
#endif
|
||||
|
||||
fDev = vol.Device();
|
||||
fCStatus = vol.InitCheck();
|
||||
}
|
||||
@@ -97,7 +126,7 @@ BVolume::SetTo(
|
||||
// Call the kernel function that gets device information
|
||||
// in order to determine the device status:
|
||||
fs_info fsInfo;
|
||||
int err = fs_stat_dev(dev, &fsInfo);
|
||||
int err = StorageKit::stat_dev(dev, &fsInfo);
|
||||
|
||||
if (err != 0) {
|
||||
fCStatus = errno;
|
||||
@@ -160,7 +189,7 @@ BVolume::GetRootDirectory(
|
||||
// the device and root node values.
|
||||
|
||||
fs_info fsInfo;
|
||||
int err = fs_stat_dev(fDev, &fsInfo);
|
||||
int err = StorageKit::stat_dev(fDev, &fsInfo);
|
||||
|
||||
if (err != 0) {
|
||||
currentStatus = errno;
|
||||
@@ -197,7 +226,7 @@ BVolume::Capacity(void) const
|
||||
// and calculate the total storage capacity.
|
||||
|
||||
fs_info fsInfo;
|
||||
int err = fs_stat_dev(fDev, &fsInfo);
|
||||
int err = StorageKit::stat_dev(fDev, &fsInfo);
|
||||
|
||||
if (err == 0) {
|
||||
totalBytes = fsInfo.block_size * fsInfo.total_blocks;
|
||||
@@ -226,7 +255,7 @@ BVolume::FreeBytes(void) const
|
||||
// and calculate the free storage available.
|
||||
|
||||
fs_info fsInfo;
|
||||
int err = fs_stat_dev(fDev, &fsInfo);
|
||||
int err = StorageKit::stat_dev(fDev, &fsInfo);
|
||||
|
||||
if (err == 0) {
|
||||
remainingBytes = fsInfo.block_size * fsInfo.free_blocks;
|
||||
@@ -255,7 +284,7 @@ BVolume::GetName(
|
||||
// and copies the device name into the buffer.
|
||||
|
||||
fs_info fsInfo;
|
||||
int err = fs_stat_dev(fDev, &fsInfo);
|
||||
int err = StorageKit::stat_dev(fDev, &fsInfo);
|
||||
|
||||
if (err != 0) {
|
||||
currentStatus = errno;
|
||||
@@ -336,7 +365,7 @@ BVolume::IsRemovable(void) const
|
||||
// and determines whether or not the device is removable.
|
||||
|
||||
fs_info fsInfo;
|
||||
int err = fs_stat_dev(fDev, &fsInfo);
|
||||
int err = StorageKit::stat_dev(fDev, &fsInfo);
|
||||
|
||||
if (err == 0) {
|
||||
volumeIsRemovable = (fsInfo.flags & B_FS_IS_REMOVABLE);
|
||||
@@ -360,7 +389,7 @@ BVolume::IsReadOnly(void) const
|
||||
// and determines whether or not the device is read-only.
|
||||
|
||||
fs_info fsInfo;
|
||||
int err = fs_stat_dev(fDev, &fsInfo);
|
||||
int err = StorageKit::stat_dev(fDev, &fsInfo);
|
||||
|
||||
if (err == 0) {
|
||||
volumeIsReadOnly = (fsInfo.flags & B_FS_IS_READONLY);
|
||||
@@ -385,7 +414,7 @@ BVolume::IsPersistent(void) const
|
||||
// is persistent.
|
||||
|
||||
fs_info fsInfo;
|
||||
int err = fs_stat_dev(fDev, &fsInfo);
|
||||
int err = StorageKit::stat_dev(fDev, &fsInfo);
|
||||
|
||||
if (err == 0) {
|
||||
volumeIsPersistent = (fsInfo.flags & B_FS_IS_PERSISTENT);
|
||||
@@ -410,7 +439,7 @@ BVolume::IsShared(void) const
|
||||
// over a network.
|
||||
|
||||
fs_info fsInfo;
|
||||
int err = fs_stat_dev(fDev, &fsInfo);
|
||||
int err = StorageKit::stat_dev(fDev, &fsInfo);
|
||||
|
||||
if (err == 0) {
|
||||
volumeIsShared = (fsInfo.flags & B_FS_IS_SHARED);
|
||||
@@ -435,7 +464,7 @@ BVolume::KnowsMime(void) const
|
||||
// MIME types.
|
||||
|
||||
fs_info fsInfo;
|
||||
int err = fs_stat_dev(fDev, &fsInfo);
|
||||
int err = StorageKit::stat_dev(fDev, &fsInfo);
|
||||
|
||||
if (err == 0) {
|
||||
volumeKnowsMime = (fsInfo.flags & B_FS_HAS_MIME);
|
||||
@@ -461,7 +490,7 @@ BVolume::KnowsAttr(void) const
|
||||
// volume accept attributes.
|
||||
|
||||
fs_info fsInfo;
|
||||
int err = fs_stat_dev(fDev, &fsInfo);
|
||||
int err = StorageKit::stat_dev(fDev, &fsInfo);
|
||||
|
||||
if (err == 0) {
|
||||
volumeKnowsAttr = (fsInfo.flags & B_FS_HAS_ATTR);
|
||||
@@ -487,7 +516,7 @@ BVolume::KnowsQuery(void) const
|
||||
// respond to queries.
|
||||
|
||||
fs_info fsInfo;
|
||||
int err = fs_stat_dev(fDev, &fsInfo);
|
||||
int err = StorageKit::stat_dev(fDev, &fsInfo);
|
||||
|
||||
if (err == 0) {
|
||||
volumeKnowsQuery = (fsInfo.flags & B_FS_HAS_QUERY);
|
||||
@@ -582,4 +611,3 @@ void BVolume::_TurnUpTheVolume8() {}
|
||||
#ifdef USE_OPENBEOS_NAMESPACE
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
@@ -0,0 +1,182 @@
|
||||
// ----------------------------------------------------------------------
|
||||
// This software is part of the OpenBeOS distribution and is covered
|
||||
// by the OpenBeOS license.
|
||||
//
|
||||
// File Name: VolumeRoster.cpp
|
||||
//
|
||||
// Description: BVolumeRoster class
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
#include <VolumeRoster.h>
|
||||
|
||||
#include <Directory.h>
|
||||
#include <Bitmap.h>
|
||||
#include <Node.h>
|
||||
#include <errno.h>
|
||||
#include <fs_info.h>
|
||||
#include <kernel_interface.h>
|
||||
|
||||
|
||||
#ifdef USE_OPENBEOS_NAMESPACE
|
||||
namespace OpenBeOS {
|
||||
#endif
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// BVolumeRoster (public)
|
||||
// ----------------------------------------------------------------------
|
||||
// Default constructor: creates a new BVolumeRoster object.
|
||||
// You don't have to "initialize" the object before using it (as you do
|
||||
// with most other Storage Kit classes). You can call GetNextVolume()
|
||||
// (or another method) immediately after constructing.
|
||||
|
||||
BVolumeRoster::BVolumeRoster(void)
|
||||
{
|
||||
#if !_PR3_COMPATIBLE_
|
||||
// Initialize reserved class variables to "safe" values:
|
||||
_reserved[0] = 0L;
|
||||
_reserved[1] = 0L;
|
||||
_reserved[2] = 0L;
|
||||
// Place this in a separate initialization method at
|
||||
// a later time.
|
||||
#endif
|
||||
|
||||
fPos = 0;
|
||||
fTarget = NULL;
|
||||
}
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// ~BVolumeRoster (public, virtual)
|
||||
// ----------------------------------------------------------------------
|
||||
// Destructor: Destroys the BVolumeRoster object.
|
||||
// If this BVolumeRoster object was watching volumes,
|
||||
// the watch is called off.
|
||||
|
||||
BVolumeRoster::~BVolumeRoster(void)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// GetNextVolume (public)
|
||||
// ----------------------------------------------------------------------
|
||||
// Retrieves the "next" volume from the volume list and uses it to
|
||||
// initialize the argument (which must be allocated). When the function
|
||||
// returns B_BAD_VALUE, you've reached the end of the list.
|
||||
|
||||
status_t
|
||||
BVolumeRoster::GetNextVolume(BVolume* vol)
|
||||
{
|
||||
status_t currentStatus = B_BAD_VALUE;
|
||||
dev_t deviceID = next_dev(&fPos);
|
||||
|
||||
if ((deviceID >= 0) && (vol != NULL))
|
||||
{
|
||||
currentStatus = vol->SetTo(deviceID);
|
||||
}
|
||||
|
||||
return currentStatus;
|
||||
}
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Rewind (public)
|
||||
// ----------------------------------------------------------------------
|
||||
// Rewinds the volume list such that the next call to GetNextVolume()
|
||||
// will return the first element in the list.
|
||||
|
||||
void
|
||||
BVolumeRoster::Rewind(void)
|
||||
{
|
||||
fPos = 0;
|
||||
}
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// GetBootVolume (public)
|
||||
// ----------------------------------------------------------------------
|
||||
// Initializes boot_vol to refer to the "boot volume." This is the
|
||||
// volume that was used to boot the computer. boot_vol must be
|
||||
// allocated before you pass it in. If the boot volume can't be found,
|
||||
// the argument is uninitialized.
|
||||
//
|
||||
// Currently, this function looks for the volume that is mounted at /boot.
|
||||
// The only way to fool the system into thinking that there is not a boot
|
||||
// volume is to rename /boot -- but, please refrain from doing so...(:o(
|
||||
|
||||
status_t
|
||||
BVolumeRoster::GetBootVolume(BVolume* boot_vol)
|
||||
{
|
||||
int32 pos = 0;
|
||||
dev_t deviceID = 0;
|
||||
status_t currentStatus = B_BAD_VALUE;
|
||||
|
||||
do {
|
||||
deviceID = next_dev(&pos);
|
||||
|
||||
if(deviceID >= 0) {
|
||||
fs_info fsInfo;
|
||||
int err = StorageKit::stat_dev(deviceID, &fsInfo);
|
||||
|
||||
if (err == 0) {
|
||||
if(std::strcmp(fsInfo.device_name, kBootVolumeName) == 0) {
|
||||
fPos = pos;
|
||||
currentStatus = boot_vol->SetTo(deviceID);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} while(deviceID >= 0);
|
||||
|
||||
return currentStatus;
|
||||
}
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// StartWatching (public)
|
||||
// ----------------------------------------------------------------------
|
||||
// Registers a request for notifications of volume mounts and unmounts.
|
||||
// The notifications are sent (as BMessages) to the BHandler/BLooper
|
||||
// pair specified by the argument. There are separate messages for
|
||||
// mounting and unmounting; their formats are described below.
|
||||
//
|
||||
// The caller retains possession of the BHandler/BLooper that the
|
||||
// BMessenger represents. The volume watching continues until this
|
||||
// BVolumeRoster object is destroyed, or until you call StopWatching().
|
||||
|
||||
status_t
|
||||
BVolumeRoster::StartWatching(BMessenger msngr)
|
||||
{
|
||||
return B_BAD_VALUE;
|
||||
}
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// StopWatching (public)
|
||||
// ----------------------------------------------------------------------
|
||||
// Tells the volume-watcher to stop watching. Notifications of volume
|
||||
// mounts and unmounts are no longer sent to the BVolumeRoster's target.
|
||||
|
||||
void
|
||||
BVolumeRoster::StopWatching(void)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Messenger (public)
|
||||
// ----------------------------------------------------------------------
|
||||
// Returns a copy of the BMessenger object that was set in the
|
||||
// previous StartWatching() call.
|
||||
|
||||
BMessenger
|
||||
BVolumeRoster::Messenger(void) const
|
||||
{
|
||||
return *fTarget;
|
||||
}
|
||||
|
||||
|
||||
#ifdef USE_OPENBEOS_NAMESPACE
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
#include <fsproto.h>
|
||||
#include <errno.h> // errno
|
||||
#include <new>
|
||||
#include <fs_info.h> // File sytem information functions, structs, defines
|
||||
#include <fs_attr.h> // BeOS's C-based attribute functions
|
||||
#include <fs_query.h> // BeOS's C-based query functions
|
||||
#include <Entry.h> // entry_ref
|
||||
@@ -33,6 +34,18 @@
|
||||
struct LongDIR : DIR { char _buffer[B_FILE_NAME_LENGTH]; };
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Device Functions
|
||||
//------------------------------------------------------------------------------
|
||||
/*! Returns information about the file system on the specified device. */
|
||||
|
||||
status_t
|
||||
StorageKit::stat_dev(dev_t dev, fs_info* info)
|
||||
{
|
||||
return fs_stat_dev(dev, info);
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// File Functions
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user