* 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

View File

@ -62,6 +62,7 @@ enum {
B_DISK_DEVICE_HAS_MEDIA = 0x02,
B_DISK_DEVICE_READ_ONLY = 0x04,
B_DISK_DEVICE_WRITE_ONCE = 0x08,
B_DISK_DEVICE_IS_FILE = 0x10,
};
// disk system flags

View File

@ -26,21 +26,25 @@ extern "C" {
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_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,
user_disk_device_data *buffer, size_t bufferSize,
size_t *neededSize);
partition_id _user_register_file_device(const char *filename);
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
// 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
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,
user_disk_system_info *info);
user_disk_system_info *info);
status_t _user_find_disk_system(const char *name, user_disk_system_info *info);
// disk device modification

View File

@ -37,6 +37,9 @@ public:
bool receiveCompleteProgressUpdates = true);
status_t CancelModifications();
bool IsFile() const;
status_t GetFilePath(BPath* path) const;
private:
friend class BDiskDeviceList;
friend class BDiskDeviceRoster;

View File

@ -28,7 +28,7 @@ enum {
// Basic masks
B_DEVICE_REQUEST_MOUNT_POINT = 0x0001, // mount point changes
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_LIST = 0x0010, // device additions/removals
B_DEVICE_REQUEST_JOB_LIST = 0x0020, // job addition/initiation/cancellation/completion
@ -125,6 +125,8 @@ public:
BDiskDevice* device);
status_t GetPartitionForPath(const char* filename,
BDiskDevice* device, BPartition** _partition);
status_t GetFileDeviceForPath(const char* filename,
BDiskDevice* device);
status_t StartWatching(BMessenger target,
uint32 eventMask = B_DEVICE_REQUEST_ALL);

View File

@ -441,9 +441,14 @@ extern status_t _kern_get_cpuid(cpuid_info *info, uint32 eax, uint32 cpu);
/* Disk Device Manager syscalls */
// iterating, retrieving device/partition data
extern partition_id _kern_get_next_disk_device_id(int32 *cookie, 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_get_next_disk_device_id(int32 *cookie,
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,
bool deviceOnly, struct user_disk_device_data *buffer,
size_t bufferSize, size_t *neededSize);
@ -452,6 +457,8 @@ extern status_t _kern_unregister_file_device(partition_id deviceID,
const char *filename);
// Only a valid deviceID or filename need to be passed. The other one
// 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
extern status_t _kern_get_disk_system_info(disk_system_id id,

View File

@ -59,8 +59,8 @@ BDiskDevice::~BDiskDevice()
bool
BDiskDevice::HasMedia() const
{
return (fDeviceData
&& fDeviceData->device_flags & B_DISK_DEVICE_HAS_MEDIA);
return fDeviceData
&& (fDeviceData->device_flags & B_DISK_DEVICE_HAS_MEDIA) != 0;
}
@ -71,8 +71,8 @@ BDiskDevice::HasMedia() const
bool
BDiskDevice::IsRemovableMedia() const
{
return (fDeviceData
&& fDeviceData->device_flags & B_DISK_DEVICE_REMOVABLE);
return fDeviceData
&& (fDeviceData->device_flags & B_DISK_DEVICE_REMOVABLE) != 0;
}
@ -80,8 +80,8 @@ BDiskDevice::IsRemovableMedia() const
bool
BDiskDevice::IsReadOnlyMedia() const
{
return (fDeviceData
&& fDeviceData->device_flags & B_DISK_DEVICE_READ_ONLY);
return fDeviceData
&& (fDeviceData->device_flags & B_DISK_DEVICE_READ_ONLY) != 0;
}
@ -89,8 +89,8 @@ BDiskDevice::IsReadOnlyMedia() const
bool
BDiskDevice::IsWriteOnceMedia() const
{
return (fDeviceData
&& fDeviceData->device_flags & B_DISK_DEVICE_WRITE_ONCE);
return fDeviceData
&& (fDeviceData->device_flags & B_DISK_DEVICE_WRITE_ONCE) != 0;
}
@ -190,7 +190,7 @@ BDiskDevice::Unset()
status_t
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);
}
virtual bool Visit(BPartition *partition, int32 level)
{
return partition->_IsModified();
@ -229,7 +229,7 @@ BDiskDevice::IsModified() const
// PrepareModifications
/*! \brief Initializes the partition hierarchy for modifications.
*
*
* Subsequent modifications are performed on so-called \a shadow structure
* 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
/*! \brief Privatized copy constructor to avoid usage.
*/

View File

@ -377,7 +377,7 @@ BDiskDeviceRoster::GetPartitionWithID(int32 id, BDiskDevice *device,
return B_OK;
}
// GetDeviceForPath
status_t
BDiskDeviceRoster::GetDeviceForPath(const char *filename, BDiskDevice *device)
{
@ -392,11 +392,10 @@ BDiskDeviceRoster::GetDeviceForPath(const char *filename, BDiskDevice *device)
return device->_SetTo(id, true, neededSize);
}
// GetPartitionForPath
status_t
BDiskDeviceRoster::GetPartitionForPath(const char *filename,
BDiskDevice *device,
BPartition **partition)
BDiskDevice *device, BPartition **partition)
{
if (!filename || !device || !partition)
return B_BAD_VALUE;
@ -416,6 +415,25 @@ BDiskDeviceRoster::GetPartitionForPath(const char *filename,
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
/*! \brief Adds a target to the list of targets to be notified on disk device
events.

View File

@ -27,6 +27,7 @@ KFileDiskDevice::KFileDiskDevice(partition_id id)
: KDiskDevice(id),
fFilePath(NULL)
{
SetDeviceFlags(DeviceFlags() | B_DISK_DEVICE_IS_FILE);
}
// destructor

View File

@ -4,6 +4,7 @@
*
* Authors:
* Ingo Weinhold, bonefish@cs.tu-berlin.de
* Axel Dörfler, axeld@pinc-software.de
*/
/*! \file ddm_userland_interface.cpp
@ -15,6 +16,7 @@
#include <AutoDeleter.h>
#include <ddm_userland_interface.h>
#include <fs/KPath.h>
#include <KDiskDevice.h>
#include <KDiskDeviceManager.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
/*! \brief Writes data describing the disk device identified by ID and all
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
status_t
_user_get_disk_system_info(disk_system_id id, user_disk_system_info *_info)