* Made the use of file devices more convenient and complete by adding

the methods IsFile() and GetFilePath() to BDiskDevice, and
  BDiskDeviceRoster::GetFileDeviceForPath().
* Added new syscalls to implement this functionality.
* Added new flag B_DISK_DEVICE_IS_FILE.
* Fixed wrong operator precedence assumption in the BDiskDevice class at
  several places.
* Minor cleanup.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@28052 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2008-10-13 21:51:43 +00:00
parent 42d02ade26
commit 38bbc95758
9 changed files with 147 additions and 22 deletions
+1
View File
@@ -62,6 +62,7 @@ enum {
B_DISK_DEVICE_HAS_MEDIA = 0x02, B_DISK_DEVICE_HAS_MEDIA = 0x02,
B_DISK_DEVICE_READ_ONLY = 0x04, B_DISK_DEVICE_READ_ONLY = 0x04,
B_DISK_DEVICE_WRITE_ONCE = 0x08, B_DISK_DEVICE_WRITE_ONCE = 0x08,
B_DISK_DEVICE_IS_FILE = 0x10,
}; };
// disk system flags // disk system flags
@@ -26,21 +26,25 @@ extern "C" {
partition_id _user_get_next_disk_device_id(int32 *cookie, size_t *neededSize); partition_id _user_get_next_disk_device_id(int32 *cookie, size_t *neededSize);
partition_id _user_find_disk_device(const char *filename, size_t *neededSize); partition_id _user_find_disk_device(const char *filename, size_t *neededSize);
partition_id _user_find_partition(const char *filename, size_t *neededSize); partition_id _user_find_partition(const char *filename, size_t *neededSize);
partition_id _user_find_file_disk_device(const char *filename,
size_t *neededSize);
status_t _user_get_disk_device_data(partition_id deviceID, bool deviceOnly, status_t _user_get_disk_device_data(partition_id deviceID, bool deviceOnly,
user_disk_device_data *buffer, size_t bufferSize, user_disk_device_data *buffer, size_t bufferSize,
size_t *neededSize); size_t *neededSize);
partition_id _user_register_file_device(const char *filename); partition_id _user_register_file_device(const char *filename);
status_t _user_unregister_file_device(partition_id deviceID, status_t _user_unregister_file_device(partition_id deviceID,
const char *filename); const char *filename);
// Only a valid deviceID or filename need to be passed. The other one // Only a valid deviceID or filename need to be passed. The other one
// is -1/NULL. If both is given only filename is ignored. // is -1/NULL. If both is given only filename is ignored.
status_t _user_get_file_disk_device_path(partition_id id, char* buffer,
size_t bufferSize);
// disk systems // disk systems
status_t _user_get_disk_system_info(disk_system_id id, status_t _user_get_disk_system_info(disk_system_id id,
user_disk_system_info *info); user_disk_system_info *info);
status_t _user_get_next_disk_system_info(int32 *cookie, status_t _user_get_next_disk_system_info(int32 *cookie,
user_disk_system_info *info); user_disk_system_info *info);
status_t _user_find_disk_system(const char *name, user_disk_system_info *info); status_t _user_find_disk_system(const char *name, user_disk_system_info *info);
// disk device modification // disk device modification
+3
View File
@@ -37,6 +37,9 @@ public:
bool receiveCompleteProgressUpdates = true); bool receiveCompleteProgressUpdates = true);
status_t CancelModifications(); status_t CancelModifications();
bool IsFile() const;
status_t GetFilePath(BPath* path) const;
private: private:
friend class BDiskDeviceList; friend class BDiskDeviceList;
friend class BDiskDeviceRoster; friend class BDiskDeviceRoster;
+3 -1
View File
@@ -28,7 +28,7 @@ enum {
// Basic masks // Basic masks
B_DEVICE_REQUEST_MOUNT_POINT = 0x0001, // mount point changes B_DEVICE_REQUEST_MOUNT_POINT = 0x0001, // mount point changes
B_DEVICE_REQUEST_MOUNTING = 0x0002, // mounting/unmounting B_DEVICE_REQUEST_MOUNTING = 0x0002, // mounting/unmounting
B_DEVICE_REQUEST_PARTITION = 0x0004, // partition changes B_DEVICE_REQUEST_PARTITION = 0x0004, // partition changes
B_DEVICE_REQUEST_DEVICE = 0x0008, // device changes (media changes) B_DEVICE_REQUEST_DEVICE = 0x0008, // device changes (media changes)
B_DEVICE_REQUEST_DEVICE_LIST = 0x0010, // device additions/removals B_DEVICE_REQUEST_DEVICE_LIST = 0x0010, // device additions/removals
B_DEVICE_REQUEST_JOB_LIST = 0x0020, // job addition/initiation/cancellation/completion B_DEVICE_REQUEST_JOB_LIST = 0x0020, // job addition/initiation/cancellation/completion
@@ -125,6 +125,8 @@ public:
BDiskDevice* device); BDiskDevice* device);
status_t GetPartitionForPath(const char* filename, status_t GetPartitionForPath(const char* filename,
BDiskDevice* device, BPartition** _partition); BDiskDevice* device, BPartition** _partition);
status_t GetFileDeviceForPath(const char* filename,
BDiskDevice* device);
status_t StartWatching(BMessenger target, status_t StartWatching(BMessenger target,
uint32 eventMask = B_DEVICE_REQUEST_ALL); uint32 eventMask = B_DEVICE_REQUEST_ALL);
+10 -3
View File
@@ -441,9 +441,14 @@ extern status_t _kern_get_cpuid(cpuid_info *info, uint32 eax, uint32 cpu);
/* Disk Device Manager syscalls */ /* Disk Device Manager syscalls */
// iterating, retrieving device/partition data // iterating, retrieving device/partition data
extern partition_id _kern_get_next_disk_device_id(int32 *cookie, size_t *neededSize); extern partition_id _kern_get_next_disk_device_id(int32 *cookie,
extern partition_id _kern_find_disk_device(const char *filename, size_t *neededSize); size_t *neededSize);
extern partition_id _kern_find_partition(const char *filename, size_t *neededSize); extern partition_id _kern_find_disk_device(const char *filename,
size_t *neededSize);
extern partition_id _kern_find_partition(const char *filename,
size_t *neededSize);
extern partition_id _kern_find_file_disk_device(const char *filename,
size_t *neededSize);
extern status_t _kern_get_disk_device_data(partition_id deviceID, extern status_t _kern_get_disk_device_data(partition_id deviceID,
bool deviceOnly, struct user_disk_device_data *buffer, bool deviceOnly, struct user_disk_device_data *buffer,
size_t bufferSize, size_t *neededSize); size_t bufferSize, size_t *neededSize);
@@ -452,6 +457,8 @@ extern status_t _kern_unregister_file_device(partition_id deviceID,
const char *filename); const char *filename);
// Only a valid deviceID or filename need to be passed. The other one // Only a valid deviceID or filename need to be passed. The other one
// is -1/NULL. If both is given only filename is ignored. // is -1/NULL. If both is given only filename is ignored.
extern status_t _kern_get_file_disk_device_path(partition_id id,
char* buffer, size_t bufferSize);
// disk systems // disk systems
extern status_t _kern_get_disk_system_info(disk_system_id id, extern status_t _kern_get_disk_system_info(disk_system_id id,
+41 -11
View File
@@ -59,8 +59,8 @@ BDiskDevice::~BDiskDevice()
bool bool
BDiskDevice::HasMedia() const BDiskDevice::HasMedia() const
{ {
return (fDeviceData return fDeviceData
&& fDeviceData->device_flags & B_DISK_DEVICE_HAS_MEDIA); && (fDeviceData->device_flags & B_DISK_DEVICE_HAS_MEDIA) != 0;
} }
@@ -71,8 +71,8 @@ BDiskDevice::HasMedia() const
bool bool
BDiskDevice::IsRemovableMedia() const BDiskDevice::IsRemovableMedia() const
{ {
return (fDeviceData return fDeviceData
&& fDeviceData->device_flags & B_DISK_DEVICE_REMOVABLE); && (fDeviceData->device_flags & B_DISK_DEVICE_REMOVABLE) != 0;
} }
@@ -80,8 +80,8 @@ BDiskDevice::IsRemovableMedia() const
bool bool
BDiskDevice::IsReadOnlyMedia() const BDiskDevice::IsReadOnlyMedia() const
{ {
return (fDeviceData return fDeviceData
&& fDeviceData->device_flags & B_DISK_DEVICE_READ_ONLY); && (fDeviceData->device_flags & B_DISK_DEVICE_READ_ONLY) != 0;
} }
@@ -89,8 +89,8 @@ BDiskDevice::IsReadOnlyMedia() const
bool bool
BDiskDevice::IsWriteOnceMedia() const BDiskDevice::IsWriteOnceMedia() const
{ {
return (fDeviceData return fDeviceData
&& fDeviceData->device_flags & B_DISK_DEVICE_WRITE_ONCE); && (fDeviceData->device_flags & B_DISK_DEVICE_WRITE_ONCE) != 0;
} }
@@ -190,7 +190,7 @@ BDiskDevice::Unset()
status_t status_t
BDiskDevice::InitCheck() const BDiskDevice::InitCheck() const
{ {
return (fDeviceData ? B_OK : B_NO_INIT); return fDeviceData ? B_OK : B_NO_INIT;
} }
@@ -216,7 +216,7 @@ BDiskDevice::IsModified() const
{ {
return Visit(device, 0); return Visit(device, 0);
} }
virtual bool Visit(BPartition *partition, int32 level) virtual bool Visit(BPartition *partition, int32 level)
{ {
return partition->_IsModified(); return partition->_IsModified();
@@ -229,7 +229,7 @@ BDiskDevice::IsModified() const
// PrepareModifications // PrepareModifications
/*! \brief Initializes the partition hierarchy for modifications. /*! \brief Initializes the partition hierarchy for modifications.
* *
* Subsequent modifications are performed on so-called \a shadow structure * Subsequent modifications are performed on so-called \a shadow structure
* and not written to device until \ref CommitModifications is called. * and not written to device until \ref CommitModifications is called.
* *
@@ -333,6 +333,36 @@ BDiskDevice::CancelModifications()
} }
/*! \brief Returns whether or not this device is a virtual device backed
up by a file.
*/
bool
BDiskDevice::IsFile() const
{
return fDeviceData
&& (fDeviceData->device_flags & B_DISK_DEVICE_IS_FILE) != 0;
}
/*! \brief Retrieves the path of the file backing up the disk device.*/
status_t
BDiskDevice::GetFilePath(BPath* path) const
{
if (path == NULL)
return B_BAD_VALUE;
if (!IsFile())
return B_BAD_TYPE;
char pathBuffer[B_PATH_NAME_LENGTH];
status_t status = _kern_get_file_disk_device_path(
fDeviceData->device_partition_data.id, pathBuffer, sizeof(pathBuffer));
if (status != B_OK)
return status;
return path->SetTo(pathBuffer);
}
// copy constructor // copy constructor
/*! \brief Privatized copy constructor to avoid usage. /*! \brief Privatized copy constructor to avoid usage.
*/ */
@@ -377,7 +377,7 @@ BDiskDeviceRoster::GetPartitionWithID(int32 id, BDiskDevice *device,
return B_OK; return B_OK;
} }
// GetDeviceForPath
status_t status_t
BDiskDeviceRoster::GetDeviceForPath(const char *filename, BDiskDevice *device) BDiskDeviceRoster::GetDeviceForPath(const char *filename, BDiskDevice *device)
{ {
@@ -392,11 +392,10 @@ BDiskDeviceRoster::GetDeviceForPath(const char *filename, BDiskDevice *device)
return device->_SetTo(id, true, neededSize); return device->_SetTo(id, true, neededSize);
} }
// GetPartitionForPath
status_t status_t
BDiskDeviceRoster::GetPartitionForPath(const char *filename, BDiskDeviceRoster::GetPartitionForPath(const char *filename,
BDiskDevice *device, BDiskDevice *device, BPartition **partition)
BPartition **partition)
{ {
if (!filename || !device || !partition) if (!filename || !device || !partition)
return B_BAD_VALUE; return B_BAD_VALUE;
@@ -416,6 +415,25 @@ BDiskDeviceRoster::GetPartitionForPath(const char *filename,
return B_OK; return B_OK;
} }
status_t
BDiskDeviceRoster::GetFileDeviceForPath(const char *filename,
BDiskDevice *device)
{
if (!filename || !device)
return B_BAD_VALUE;
// get the device ID
size_t neededSize = 0;
partition_id id = _kern_find_file_disk_device(filename, &neededSize);
if (id < 0)
return id;
// download the device data
return device->_SetTo(id, true, neededSize);
}
// StartWatching // StartWatching
/*! \brief Adds a target to the list of targets to be notified on disk device /*! \brief Adds a target to the list of targets to be notified on disk device
events. events.
@@ -27,6 +27,7 @@ KFileDiskDevice::KFileDiskDevice(partition_id id)
: KDiskDevice(id), : KDiskDevice(id),
fFilePath(NULL) fFilePath(NULL)
{ {
SetDeviceFlags(DeviceFlags() | B_DISK_DEVICE_IS_FILE);
} }
// destructor // destructor
@@ -4,6 +4,7 @@
* *
* Authors: * Authors:
* Ingo Weinhold, bonefish@cs.tu-berlin.de * Ingo Weinhold, bonefish@cs.tu-berlin.de
* Axel Dörfler, axeld@pinc-software.de
*/ */
/*! \file ddm_userland_interface.cpp /*! \file ddm_userland_interface.cpp
@@ -15,6 +16,7 @@
#include <AutoDeleter.h> #include <AutoDeleter.h>
#include <ddm_userland_interface.h> #include <ddm_userland_interface.h>
#include <fs/KPath.h>
#include <KDiskDevice.h> #include <KDiskDevice.h>
#include <KDiskDeviceManager.h> #include <KDiskDeviceManager.h>
#include <KDiskDeviceUtils.h> #include <KDiskDeviceUtils.h>
@@ -328,6 +330,38 @@ _user_find_partition(const char *_filename, size_t *neededSize)
} }
partition_id
_user_find_file_disk_device(const char *_filename, size_t *neededSize)
{
UserStringParameter<false> filename;
status_t error = filename.Init(_filename, B_PATH_NAME_LENGTH);
if (error != B_OK)
return error;
KPath path(filename, true);
partition_id id = B_ENTRY_NOT_FOUND;
KDiskDeviceManager *manager = KDiskDeviceManager::Default();
// find the device
if (KFileDiskDevice* device = manager->RegisterFileDevice(path.Path())) {
PartitionRegistrar _(device, true);
id = device->ID();
if (neededSize) {
if (DeviceReadLocker locker = device) {
// get the needed size
UserDataWriter writer;
device->WriteUserData(writer);
error = copy_to_user_value(neededSize, writer.AllocatedSize());
if (error != B_OK)
return error;
} else
return B_ERROR;
}
}
return id;
}
// _user_get_disk_device_data // _user_get_disk_device_data
/*! \brief Writes data describing the disk device identified by ID and all /*! \brief Writes data describing the disk device identified by ID and all
its partitions into the supplied buffer. its partitions into the supplied buffer.
@@ -459,6 +493,31 @@ _user_unregister_file_device(partition_id deviceID, const char *_filename)
} }
status_t
_user_get_file_disk_device_path(partition_id id, char* buffer,
size_t bufferSize)
{
if (id < 0 || buffer == NULL || bufferSize == 0)
return B_BAD_VALUE;
KDiskDeviceManager *manager = KDiskDeviceManager::Default();
if (KDiskDevice *device = manager->RegisterDevice(id, true)) {
PartitionRegistrar _(device, true);
if (DeviceReadLocker locker = device) {
KFileDiskDevice* fileDevice
= dynamic_cast<KFileDiskDevice*>(device);
if (fileDevice == NULL)
return B_BAD_VALUE;
return user_strlcpy(buffer, fileDevice->FilePath(), bufferSize);
}
}
return B_ERROR;
}
// _user_get_disk_system_info // _user_get_disk_system_info
status_t status_t
_user_get_disk_system_info(disk_system_id id, user_disk_system_info *_info) _user_get_disk_system_info(disk_system_id id, user_disk_system_info *_info)