From 5ebee1cf0a8ed0a2d58b33f6ececf3c759daf57e Mon Sep 17 00:00:00 2001 From: Tyler Dauwalder Date: Tue, 23 Jul 2002 21:39:49 +0000 Subject: [PATCH] BVolume and BVolumeRoster updates, courtesty of Vincent Dominguez git-svn-id: file:///srv/svn/repos/haiku/trunk/current@405 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- headers/os/storage/Volume.h | 2 - headers/os/storage/VolumeRoster.h | 64 +++++++ headers/private/storage/kernel_interface.h | 8 + src/kits/storage/Jamfile | 1 + src/kits/storage/Volume.cpp | 58 +++++-- src/kits/storage/VolumeRoster.cpp | 182 ++++++++++++++++++++ src/kits/storage/kernel_interface.POSIX.cpp | 13 ++ 7 files changed, 311 insertions(+), 17 deletions(-) create mode 100644 headers/os/storage/VolumeRoster.h create mode 100644 src/kits/storage/VolumeRoster.cpp diff --git a/headers/os/storage/Volume.h b/headers/os/storage/Volume.h index 56f125fe5c..d8c939ec86 100644 --- a/headers/os/storage/Volume.h +++ b/headers/os/storage/Volume.h @@ -17,11 +17,9 @@ #ifndef _FS_INFO_H #include -//#include "fs_info.h" #endif #ifndef _STORAGE_DEFS_H #include -//#include "StorageDefs.h" #endif #ifndef _MIME_H #include diff --git a/headers/os/storage/VolumeRoster.h b/headers/os/storage/VolumeRoster.h new file mode 100644 index 0000000000..7f7c77e318 --- /dev/null +++ b/headers/os/storage/VolumeRoster.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 +#endif +#include +#include +#include + +#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 diff --git a/headers/private/storage/kernel_interface.h b/headers/private/storage/kernel_interface.h index 662c5a56b6..45edf7c4e2 100644 --- a/headers/private/storage/kernel_interface.h +++ b/headers/private/storage/kernel_interface.h @@ -18,6 +18,7 @@ #include // For dirent #include // For struct stat #include // For flock +#include // 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 //------------------------------------------------------------------------------ diff --git a/src/kits/storage/Jamfile b/src/kits/storage/Jamfile index 5202af64ee..15523d6722 100644 --- a/src/kits/storage/Jamfile +++ b/src/kits/storage/Jamfile @@ -39,6 +39,7 @@ SharedLibrary storage : Statable.cpp SymLink.cpp Volume.cpp + VolumeRoster.cpp kernel_interface.POSIX.cpp storage_support.cpp ; diff --git a/src/kits/storage/Volume.cpp b/src/kits/storage/Volume.cpp index aeebadaa6b..f3dc28545c 100644 --- a/src/kits/storage/Volume.cpp +++ b/src/kits/storage/Volume.cpp @@ -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 -//#include "Volume.h" #include #include #include #include +#include +#include #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 - diff --git a/src/kits/storage/VolumeRoster.cpp b/src/kits/storage/VolumeRoster.cpp new file mode 100644 index 0000000000..08963fdad0 --- /dev/null +++ b/src/kits/storage/VolumeRoster.cpp @@ -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 + +#include +#include +#include +#include +#include +#include + + +#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 + diff --git a/src/kits/storage/kernel_interface.POSIX.cpp b/src/kits/storage/kernel_interface.POSIX.cpp index dd8bb4b650..2e464fc711 100644 --- a/src/kits/storage/kernel_interface.POSIX.cpp +++ b/src/kits/storage/kernel_interface.POSIX.cpp @@ -18,6 +18,7 @@ #include #include // errno #include +#include // File sytem information functions, structs, defines #include // BeOS's C-based attribute functions #include // BeOS's C-based query functions #include // 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 //------------------------------------------------------------------------------