2007-10-06 02:39:52 +04:00
|
|
|
/** \file ddm_userland_interface.cpp
|
2007-07-27 16:12:35 +04:00
|
|
|
*
|
|
|
|
* \brief Interface for userspace calls.
|
|
|
|
*/
|
2003-07-07 02:56:39 +04:00
|
|
|
|
2003-09-28 19:16:42 +04:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#include <AutoDeleter.h>
|
2003-07-30 21:48:08 +04:00
|
|
|
#include <ddm_userland_interface.h>
|
2003-07-07 02:56:39 +04:00
|
|
|
#include <KDiskDevice.h>
|
2003-07-30 21:48:08 +04:00
|
|
|
#include <KDiskDeviceJob.h>
|
|
|
|
#include <KDiskDeviceJobQueue.h>
|
2003-07-07 02:56:39 +04:00
|
|
|
#include <KDiskDeviceManager.h>
|
|
|
|
#include <KDiskDeviceUtils.h>
|
2003-07-09 03:23:27 +04:00
|
|
|
#include <KDiskSystem.h>
|
2003-07-25 02:58:06 +04:00
|
|
|
#include <KFileDiskDevice.h>
|
|
|
|
#include <KShadowPartition.h>
|
2003-09-28 19:16:42 +04:00
|
|
|
#include <syscall_args.h>
|
2003-07-07 02:56:39 +04:00
|
|
|
|
2003-09-30 01:40:36 +04:00
|
|
|
#include "ddm_operation_validation.h"
|
2003-08-02 04:01:37 +04:00
|
|
|
#include "KDiskDeviceJobGenerator.h"
|
2003-07-07 02:56:39 +04:00
|
|
|
#include "UserDataWriter.h"
|
|
|
|
|
2003-09-30 01:40:36 +04:00
|
|
|
using namespace BPrivate::DiskDevice;
|
|
|
|
|
2003-09-28 19:16:42 +04:00
|
|
|
// debugging
|
|
|
|
#define ERROR(x)
|
|
|
|
|
2007-10-07 19:39:35 +04:00
|
|
|
|
|
|
|
// TODO: Add user address checks and check return values of user_memcpy()!
|
|
|
|
|
|
|
|
|
2003-10-25 03:09:43 +04:00
|
|
|
// ddm_strlcpy
|
|
|
|
/*! \brief Wrapper around user_strlcpy() that returns a status_t
|
|
|
|
indicating appropriate success or failure.
|
2003-10-25 12:35:27 +04:00
|
|
|
|
|
|
|
\param allowTruncation If \c true, does not return an error if
|
|
|
|
\a from is longer than \to. If \c false, returns \c B_NAME_TOO_LONG
|
|
|
|
if \a from is longer than \to.
|
2003-10-25 03:09:43 +04:00
|
|
|
*/
|
2007-10-06 02:39:52 +04:00
|
|
|
static status_t
|
|
|
|
ddm_strlcpy(char *to, const char *from, size_t size,
|
|
|
|
bool allowTruncation = false)
|
|
|
|
{
|
|
|
|
ssize_t fromLen = user_strlcpy(to, from, size);
|
|
|
|
if (fromLen < 0)
|
|
|
|
return fromLen;
|
|
|
|
if ((size_t)fromLen >= size && !allowTruncation)
|
|
|
|
return B_NAME_TOO_LONG;
|
|
|
|
return B_OK;
|
2003-10-25 03:09:43 +04:00
|
|
|
}
|
|
|
|
|
2007-10-06 02:39:52 +04:00
|
|
|
|
2003-07-25 02:58:06 +04:00
|
|
|
// move_descendants
|
2007-10-06 02:39:52 +04:00
|
|
|
static void
|
2003-07-25 02:58:06 +04:00
|
|
|
move_descendants(KPartition *partition, off_t moveBy)
|
|
|
|
{
|
|
|
|
if (!partition)
|
|
|
|
return;
|
|
|
|
partition->SetOffset(partition->Offset() + moveBy);
|
|
|
|
// move children
|
|
|
|
for (int32 i = 0; KPartition *child = partition->ChildAt(i); i++)
|
|
|
|
move_descendants(child, moveBy);
|
|
|
|
}
|
|
|
|
|
2007-10-06 02:39:52 +04:00
|
|
|
|
2003-07-25 02:58:06 +04:00
|
|
|
// move_descendants_contents
|
2007-10-06 02:39:52 +04:00
|
|
|
static status_t
|
2003-07-25 02:58:06 +04:00
|
|
|
move_descendants_contents(KPartition *partition)
|
|
|
|
{
|
|
|
|
if (!partition)
|
|
|
|
return B_BAD_VALUE;
|
|
|
|
// implicit content disk system changes
|
|
|
|
KDiskSystem *diskSystem = partition->DiskSystem();
|
|
|
|
if (diskSystem || partition->AlgorithmData()) {
|
|
|
|
status_t error = diskSystem->ShadowPartitionChanged(partition,
|
2007-10-07 19:39:35 +04:00
|
|
|
NULL, B_PARTITION_MOVE);
|
2003-07-25 02:58:06 +04:00
|
|
|
if (error != B_OK)
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
// move children's contents
|
|
|
|
for (int32 i = 0; KPartition *child = partition->ChildAt(i); i++) {
|
|
|
|
status_t error = move_descendants_contents(child);
|
|
|
|
if (error != B_OK)
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
return B_OK;
|
|
|
|
}
|
|
|
|
|
2007-10-06 02:39:52 +04:00
|
|
|
|
2004-10-29 05:38:17 +04:00
|
|
|
// _user_get_next_disk_device_id
|
2003-07-07 02:56:39 +04:00
|
|
|
partition_id
|
2004-10-29 05:38:17 +04:00
|
|
|
_user_get_next_disk_device_id(int32 *_cookie, size_t *neededSize)
|
2003-07-07 02:56:39 +04:00
|
|
|
{
|
2003-09-27 09:19:37 +04:00
|
|
|
if (!_cookie)
|
2003-07-07 02:56:39 +04:00
|
|
|
return B_BAD_VALUE;
|
2003-10-24 13:37:20 +04:00
|
|
|
int32 cookie;
|
|
|
|
user_memcpy(&cookie, _cookie, sizeof(cookie));
|
2003-09-27 09:19:37 +04:00
|
|
|
|
2003-07-15 05:27:43 +04:00
|
|
|
partition_id id = B_ENTRY_NOT_FOUND;
|
2003-07-07 02:56:39 +04:00
|
|
|
KDiskDeviceManager *manager = KDiskDeviceManager::Default();
|
2003-07-15 05:27:43 +04:00
|
|
|
// get the next device
|
2003-09-27 09:19:37 +04:00
|
|
|
if (KDiskDevice *device = manager->RegisterNextDevice(&cookie)) {
|
2003-07-07 02:56:39 +04:00
|
|
|
PartitionRegistrar _(device, true);
|
|
|
|
id = device->ID();
|
|
|
|
if (neededSize) {
|
|
|
|
if (DeviceReadLocker locker = device) {
|
2003-07-15 05:27:43 +04:00
|
|
|
// get the needed size
|
|
|
|
UserDataWriter writer;
|
|
|
|
device->WriteUserData(writer, false);
|
|
|
|
*neededSize = writer.AllocatedSize();
|
2003-09-27 09:19:37 +04:00
|
|
|
} else {
|
|
|
|
id = B_ERROR;
|
|
|
|
}
|
2003-07-15 05:27:43 +04:00
|
|
|
}
|
|
|
|
}
|
2003-10-24 13:37:20 +04:00
|
|
|
user_memcpy(_cookie, &cookie, sizeof(cookie));
|
2003-07-15 05:27:43 +04:00
|
|
|
return id;
|
|
|
|
}
|
|
|
|
|
2007-10-06 02:39:52 +04:00
|
|
|
|
2004-10-29 05:38:17 +04:00
|
|
|
// _user_find_disk_device
|
2003-07-15 05:27:43 +04:00
|
|
|
partition_id
|
2004-10-29 05:38:17 +04:00
|
|
|
_user_find_disk_device(const char *_filename, size_t *neededSize)
|
2003-07-15 05:27:43 +04:00
|
|
|
{
|
2003-09-27 09:19:37 +04:00
|
|
|
if (!_filename)
|
2003-07-15 05:27:43 +04:00
|
|
|
return B_BAD_VALUE;
|
2003-09-27 09:19:37 +04:00
|
|
|
|
2003-10-25 03:09:43 +04:00
|
|
|
char filename[B_PATH_NAME_LENGTH];
|
|
|
|
status_t error = ddm_strlcpy(filename, _filename, B_PATH_NAME_LENGTH);
|
|
|
|
if (error)
|
|
|
|
return error;
|
|
|
|
|
2003-07-15 05:27:43 +04:00
|
|
|
partition_id id = B_ENTRY_NOT_FOUND;
|
|
|
|
KDiskDeviceManager *manager = KDiskDeviceManager::Default();
|
|
|
|
// find the device
|
|
|
|
if (KDiskDevice *device = manager->RegisterDevice(filename)) {
|
|
|
|
PartitionRegistrar _(device, true);
|
|
|
|
id = device->ID();
|
|
|
|
if (neededSize) {
|
|
|
|
if (DeviceReadLocker locker = device) {
|
|
|
|
// get the needed size
|
|
|
|
UserDataWriter writer;
|
|
|
|
device->WriteUserData(writer, false);
|
|
|
|
*neededSize = writer.AllocatedSize();
|
|
|
|
} else
|
|
|
|
return B_ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return id;
|
|
|
|
}
|
|
|
|
|
2007-10-06 02:39:52 +04:00
|
|
|
|
2004-10-29 05:38:17 +04:00
|
|
|
// _user_find_partition
|
2003-07-15 05:27:43 +04:00
|
|
|
partition_id
|
2004-10-29 05:38:17 +04:00
|
|
|
_user_find_partition(const char *_filename, size_t *neededSize)
|
2003-07-15 05:27:43 +04:00
|
|
|
{
|
2003-09-27 09:19:37 +04:00
|
|
|
if (!_filename)
|
2003-07-15 05:27:43 +04:00
|
|
|
return B_BAD_VALUE;
|
2003-09-27 09:19:37 +04:00
|
|
|
|
2003-10-25 03:09:43 +04:00
|
|
|
char filename[B_PATH_NAME_LENGTH];
|
|
|
|
status_t error = ddm_strlcpy(filename, _filename, B_PATH_NAME_LENGTH);
|
|
|
|
if (error)
|
|
|
|
return error;
|
2003-09-27 09:19:37 +04:00
|
|
|
|
2003-07-15 05:27:43 +04:00
|
|
|
partition_id id = B_ENTRY_NOT_FOUND;
|
|
|
|
KDiskDeviceManager *manager = KDiskDeviceManager::Default();
|
|
|
|
// find the partition
|
|
|
|
if (KPartition *partition = manager->RegisterPartition(filename)) {
|
|
|
|
PartitionRegistrar _(partition, true);
|
|
|
|
id = partition->ID();
|
|
|
|
if (neededSize) {
|
|
|
|
// get and lock the partition's device
|
|
|
|
KDiskDevice *device = manager->RegisterDevice(partition->ID());
|
|
|
|
if (!device)
|
|
|
|
return B_ENTRY_NOT_FOUND;
|
|
|
|
PartitionRegistrar _2(device, true);
|
|
|
|
if (DeviceReadLocker locker = device) {
|
|
|
|
// get the needed size
|
2003-07-07 02:56:39 +04:00
|
|
|
UserDataWriter writer;
|
|
|
|
device->WriteUserData(writer, false);
|
|
|
|
*neededSize = writer.AllocatedSize();
|
|
|
|
} else
|
|
|
|
return B_ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return id;
|
|
|
|
}
|
|
|
|
|
2007-10-06 02:39:52 +04:00
|
|
|
|
2004-10-29 05:38:17 +04:00
|
|
|
// _user_get_disk_device_data
|
2003-09-28 19:16:42 +04:00
|
|
|
/*! \brief Writes data describing the disk device identified by ID and all
|
|
|
|
its partitions into the supplied buffer.
|
|
|
|
|
|
|
|
The function passes the buffer size required to hold the data back
|
|
|
|
through the \a _neededSize parameter, if the device could be found at
|
|
|
|
least and no serious error occured. If fails with \c B_BUFFER_OVERFLOW,
|
|
|
|
if the supplied buffer is too small or a \c NULL buffer is supplied
|
|
|
|
(and \c bufferSize is 0).
|
|
|
|
|
|
|
|
The device is identified by \a id. If \a deviceOnly is \c true, then
|
|
|
|
it must be the ID of a disk device, otherwise the disk device is
|
|
|
|
chosen, on which the partition \a id refers to resides.
|
|
|
|
|
|
|
|
\param id The ID of an arbitrary partition on the disk device (including
|
|
|
|
the disk device itself), whose data shall be returned
|
|
|
|
(if \a deviceOnly is \c false), or the ID of the disk device
|
|
|
|
itself (if \a deviceOnly is true).
|
|
|
|
\param deviceOnly Specifies whether only IDs of disk devices (\c true),
|
|
|
|
or also IDs of partitions (\c false) are accepted for \a id.
|
|
|
|
\param shadow If \c true, the data of the shadow disk device is returned,
|
|
|
|
otherwise of the physical device. If there is no shadow device,
|
|
|
|
the parameter is ignored.
|
|
|
|
\param buffer The buffer into which the disk device data shall be written.
|
|
|
|
May be \c NULL.
|
|
|
|
\param bufferSize The size of \a buffer.
|
|
|
|
\param _neededSize Pointer to a variable into which the actually needed
|
|
|
|
buffer size is written. May be \c NULL.
|
|
|
|
\return
|
|
|
|
- \c B_OK: Everything went fine. The device was found and, if not \c NULL,
|
|
|
|
in \a _neededSize the actually needed buffer size is returned. And
|
|
|
|
\a buffer will contain the disk device data.
|
|
|
|
- \c B_BAD_VALUE: \c NULL \a buffer, but not 0 \a bufferSize.
|
|
|
|
- \c B_BUFFER_OVERFLOW: The supplied buffer was too small. \a _neededSize,
|
|
|
|
if not \c NULL, will contain the required buffer size.
|
|
|
|
- \c B_NO_MEMORY: Insufficient memory to complete the operation.
|
|
|
|
- \c B_ENTRY_NOT_FOUND: \a id is no valid disk device ID (if \a deviceOnly
|
|
|
|
is \c true) or not even a valid partition ID (if \a deviceOnly is
|
|
|
|
\c false).
|
|
|
|
- \c B_ERROR: An unexpected error occured.
|
|
|
|
- another error code...
|
|
|
|
*/
|
2003-07-07 02:56:39 +04:00
|
|
|
status_t
|
2004-10-29 05:38:17 +04:00
|
|
|
_user_get_disk_device_data(partition_id id, bool deviceOnly, bool shadow,
|
2007-10-06 02:39:52 +04:00
|
|
|
user_disk_device_data *buffer, size_t bufferSize, size_t *_neededSize)
|
2003-07-07 02:56:39 +04:00
|
|
|
{
|
2003-09-28 19:16:42 +04:00
|
|
|
if (!buffer && bufferSize > 0)
|
2003-07-07 02:56:39 +04:00
|
|
|
return B_BAD_VALUE;
|
|
|
|
KDiskDeviceManager *manager = KDiskDeviceManager::Default();
|
2003-07-15 05:27:43 +04:00
|
|
|
// get the device
|
|
|
|
if (KDiskDevice *device = manager->RegisterDevice(id, deviceOnly)) {
|
2003-07-07 02:56:39 +04:00
|
|
|
PartitionRegistrar _(device, true);
|
|
|
|
if (DeviceReadLocker locker = device) {
|
2003-09-28 19:16:42 +04:00
|
|
|
// do a dry run first to get the needed size
|
|
|
|
UserDataWriter writer;
|
|
|
|
device->WriteUserData(writer, shadow);
|
|
|
|
size_t neededSize = writer.AllocatedSize();
|
|
|
|
if (_neededSize) {
|
|
|
|
status_t error = copy_ref_var_to_user(neededSize, _neededSize);
|
|
|
|
if (error != B_OK)
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
// if no buffer has been supplied or the buffer is too small,
|
|
|
|
// then we're done
|
|
|
|
if (!buffer || bufferSize < neededSize)
|
|
|
|
return B_BUFFER_OVERFLOW;
|
|
|
|
// otherwise allocate a kernel buffer
|
|
|
|
user_disk_device_data *kernelBuffer
|
|
|
|
= static_cast<user_disk_device_data*>(malloc(neededSize));
|
|
|
|
if (!kernelBuffer)
|
|
|
|
return B_NO_MEMORY;
|
|
|
|
MemoryDeleter deleter(kernelBuffer);
|
2003-07-15 05:27:43 +04:00
|
|
|
// write the device data into the buffer
|
2003-09-28 19:16:42 +04:00
|
|
|
writer.SetTo(kernelBuffer, bufferSize);
|
2003-07-07 02:56:39 +04:00
|
|
|
device->WriteUserData(writer, shadow);
|
2003-09-28 19:16:42 +04:00
|
|
|
// sanity check
|
|
|
|
if (writer.AllocatedSize() != neededSize) {
|
|
|
|
ERROR(("Size of written disk device user data changed from "
|
|
|
|
"%lu to %lu while device was locked!\n"));
|
|
|
|
return B_ERROR;
|
|
|
|
}
|
|
|
|
// relocate
|
|
|
|
status_t error = writer.Relocate(buffer);
|
|
|
|
if (error != B_OK)
|
|
|
|
return error;
|
|
|
|
// copy out
|
|
|
|
if (buffer)
|
|
|
|
return user_memcpy(buffer, kernelBuffer, neededSize);
|
|
|
|
} else
|
|
|
|
return B_ERROR;
|
2003-07-07 02:56:39 +04:00
|
|
|
}
|
2003-09-28 19:16:42 +04:00
|
|
|
return B_ENTRY_NOT_FOUND;
|
2003-07-15 05:27:43 +04:00
|
|
|
}
|
|
|
|
|
2007-10-06 02:39:52 +04:00
|
|
|
|
2004-10-29 05:38:17 +04:00
|
|
|
// _user_get_partitionable_spaces
|
2003-07-20 21:18:48 +04:00
|
|
|
status_t
|
2004-10-29 05:38:17 +04:00
|
|
|
_user_get_partitionable_spaces(partition_id partitionID, int32 changeCounter,
|
2007-10-06 02:39:52 +04:00
|
|
|
partitionable_space_data *_buffer, int32 count, int32 *_actualCount)
|
2003-07-20 21:18:48 +04:00
|
|
|
{
|
2007-10-07 19:39:35 +04:00
|
|
|
if (count > 0 && !_buffer)
|
2003-09-27 09:19:37 +04:00
|
|
|
return B_BAD_VALUE;
|
2007-10-07 19:39:35 +04:00
|
|
|
|
|
|
|
if (count > 0 && !IS_USER_ADDRESS(_buffer)
|
|
|
|
|| _actualCount && !IS_USER_ADDRESS(_actualCount)) {
|
|
|
|
return B_BAD_ADDRESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
// allocate buffer
|
2003-09-27 09:19:37 +04:00
|
|
|
int32 bufferSize = count * sizeof(partitionable_space_data);
|
2007-10-07 19:39:35 +04:00
|
|
|
partitionable_space_data *buffer = NULL;
|
|
|
|
MemoryDeleter bufferDeleter;
|
|
|
|
if (count > 0) {
|
|
|
|
buffer = (partitionable_space_data*)malloc(bufferSize);
|
|
|
|
if (!buffer)
|
|
|
|
return B_NO_MEMORY;
|
|
|
|
bufferDeleter.SetTo(buffer);
|
|
|
|
}
|
|
|
|
|
2003-09-27 09:19:37 +04:00
|
|
|
status_t error = B_OK;
|
2007-10-07 19:39:35 +04:00
|
|
|
|
2003-07-20 21:18:48 +04:00
|
|
|
// get the partition
|
|
|
|
KDiskDeviceManager *manager = KDiskDeviceManager::Default();
|
|
|
|
KPartition *partition = manager->ReadLockPartition(partitionID);
|
2007-10-07 19:39:35 +04:00
|
|
|
if (!partition)
|
|
|
|
return B_ENTRY_NOT_FOUND;
|
|
|
|
|
|
|
|
PartitionRegistrar registrar1(partition, true);
|
|
|
|
PartitionRegistrar registrar2(partition->Device(), true);
|
|
|
|
DeviceReadLocker locker(partition->Device(), true);
|
|
|
|
|
|
|
|
if (!check_shadow_partition(partition, changeCounter))
|
|
|
|
return B_BAD_VALUE;
|
|
|
|
|
|
|
|
// get the disk system
|
|
|
|
KDiskSystem *diskSystem = partition->DiskSystem();
|
|
|
|
if (!diskSystem)
|
|
|
|
return B_ENTRY_NOT_FOUND;
|
|
|
|
|
|
|
|
// get the info
|
|
|
|
int32 actualCount;
|
|
|
|
error = diskSystem->GetPartitionableSpaces(partition, buffer, count,
|
|
|
|
&actualCount);
|
|
|
|
|
2003-09-27 09:19:37 +04:00
|
|
|
// copy out
|
2007-10-07 19:39:35 +04:00
|
|
|
if (_actualCount)
|
|
|
|
user_memcpy(_actualCount, &actualCount, sizeof(actualCount));
|
|
|
|
// copy even on error
|
|
|
|
|
|
|
|
if (error == B_OK && buffer)
|
2003-09-27 09:19:37 +04:00
|
|
|
user_memcpy(_buffer, buffer, bufferSize);
|
2007-10-07 19:39:35 +04:00
|
|
|
|
2003-09-27 09:19:37 +04:00
|
|
|
return error;
|
2003-07-20 21:18:48 +04:00
|
|
|
}
|
|
|
|
|
2007-10-06 02:39:52 +04:00
|
|
|
|
2004-10-29 05:38:17 +04:00
|
|
|
// _user_register_file_device
|
2003-07-15 05:27:43 +04:00
|
|
|
partition_id
|
2004-10-29 05:38:17 +04:00
|
|
|
_user_register_file_device(const char *_filename)
|
2003-07-15 05:27:43 +04:00
|
|
|
{
|
2003-09-27 09:19:37 +04:00
|
|
|
if (!_filename)
|
2003-07-15 05:27:43 +04:00
|
|
|
return B_BAD_VALUE;
|
2003-09-27 09:19:37 +04:00
|
|
|
char filename[B_PATH_NAME_LENGTH];
|
2003-10-25 03:09:43 +04:00
|
|
|
status_t error = ddm_strlcpy(filename, _filename, B_PATH_NAME_LENGTH);
|
|
|
|
if (error)
|
|
|
|
return error;
|
2003-07-15 05:27:43 +04:00
|
|
|
KDiskDeviceManager *manager = KDiskDeviceManager::Default();
|
|
|
|
if (ManagerLocker locker = manager) {
|
|
|
|
if (KFileDiskDevice *device = manager->FindFileDevice(filename))
|
|
|
|
return device->ID();
|
|
|
|
return manager->CreateFileDevice(filename);
|
|
|
|
}
|
2003-07-07 02:56:39 +04:00
|
|
|
return B_ERROR;
|
|
|
|
}
|
|
|
|
|
2007-10-06 02:39:52 +04:00
|
|
|
|
2004-10-29 05:38:17 +04:00
|
|
|
// _user_unregister_file_device
|
2003-07-15 05:27:43 +04:00
|
|
|
status_t
|
2004-10-29 05:38:17 +04:00
|
|
|
_user_unregister_file_device(partition_id deviceID, const char *_filename)
|
2003-07-15 05:27:43 +04:00
|
|
|
{
|
2003-09-27 09:19:37 +04:00
|
|
|
if (deviceID < 0 && !_filename)
|
|
|
|
return B_BAD_VALUE;
|
2003-07-15 05:27:43 +04:00
|
|
|
KDiskDeviceManager *manager = KDiskDeviceManager::Default();
|
2003-09-27 09:19:37 +04:00
|
|
|
if (deviceID >= 0) {
|
2003-07-15 05:27:43 +04:00
|
|
|
return manager->DeleteFileDevice(deviceID);
|
2003-09-27 09:19:37 +04:00
|
|
|
} else {
|
|
|
|
char filename[B_PATH_NAME_LENGTH];
|
2003-10-25 03:09:43 +04:00
|
|
|
status_t error = ddm_strlcpy(filename, _filename, B_PATH_NAME_LENGTH);
|
|
|
|
if (error)
|
|
|
|
return error;
|
2003-09-27 09:19:37 +04:00
|
|
|
return manager->DeleteFileDevice(filename);
|
|
|
|
}
|
2003-07-15 05:27:43 +04:00
|
|
|
}
|
|
|
|
|
2007-10-06 02:39:52 +04:00
|
|
|
|
2004-10-29 05:38:17 +04:00
|
|
|
// _user_get_disk_system_info
|
2003-07-09 03:23:27 +04:00
|
|
|
status_t
|
2004-10-29 05:38:17 +04:00
|
|
|
_user_get_disk_system_info(disk_system_id id, user_disk_system_info *_info)
|
2003-07-09 03:23:27 +04:00
|
|
|
{
|
2003-09-27 09:19:37 +04:00
|
|
|
if (!_info)
|
2003-07-09 03:23:27 +04:00
|
|
|
return B_BAD_VALUE;
|
|
|
|
KDiskDeviceManager *manager = KDiskDeviceManager::Default();
|
|
|
|
if (ManagerLocker locker = manager) {
|
|
|
|
if (KDiskSystem *diskSystem = manager->FindDiskSystem(id)) {
|
2003-09-27 09:19:37 +04:00
|
|
|
user_disk_system_info info;
|
|
|
|
diskSystem->GetInfo(&info);
|
|
|
|
user_memcpy(_info, &info, sizeof(info));
|
2003-07-09 03:23:27 +04:00
|
|
|
return B_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return B_ENTRY_NOT_FOUND;
|
|
|
|
}
|
|
|
|
|
2007-10-06 02:39:52 +04:00
|
|
|
|
2004-10-29 05:38:17 +04:00
|
|
|
// _user_get_next_disk_system_info
|
2003-07-09 03:23:27 +04:00
|
|
|
status_t
|
2004-10-29 05:38:17 +04:00
|
|
|
_user_get_next_disk_system_info(int32 *_cookie, user_disk_system_info *_info)
|
2003-07-09 03:23:27 +04:00
|
|
|
{
|
2003-09-27 09:19:37 +04:00
|
|
|
if (!_cookie || !_info)
|
2003-07-09 03:23:27 +04:00
|
|
|
return B_BAD_VALUE;
|
2003-10-24 13:37:20 +04:00
|
|
|
int32 cookie;
|
|
|
|
user_memcpy(&cookie, _cookie, sizeof(cookie));
|
2003-09-27 09:19:37 +04:00
|
|
|
status_t result = B_ENTRY_NOT_FOUND;
|
2003-07-09 03:23:27 +04:00
|
|
|
KDiskDeviceManager *manager = KDiskDeviceManager::Default();
|
|
|
|
if (ManagerLocker locker = manager) {
|
2003-09-27 09:19:37 +04:00
|
|
|
if (KDiskSystem *diskSystem = manager->NextDiskSystem(&cookie)) {
|
|
|
|
user_disk_system_info info;
|
|
|
|
diskSystem->GetInfo(&info);
|
|
|
|
user_memcpy(_info, &info, sizeof(info));
|
|
|
|
result = B_OK;
|
2003-07-09 03:23:27 +04:00
|
|
|
}
|
|
|
|
}
|
2003-10-24 13:37:20 +04:00
|
|
|
user_memcpy(_cookie, &cookie, sizeof(cookie));
|
2003-09-27 09:19:37 +04:00
|
|
|
return result;
|
2003-07-09 03:23:27 +04:00
|
|
|
}
|
|
|
|
|
2007-10-06 02:39:52 +04:00
|
|
|
|
2004-10-29 05:38:17 +04:00
|
|
|
// _user_find_disk_system
|
2003-07-09 03:23:27 +04:00
|
|
|
status_t
|
2004-10-29 05:38:17 +04:00
|
|
|
_user_find_disk_system(const char *_name, user_disk_system_info *_info)
|
2003-07-09 03:23:27 +04:00
|
|
|
{
|
2003-09-27 09:19:37 +04:00
|
|
|
if (!_name || !_info)
|
2003-07-09 03:23:27 +04:00
|
|
|
return B_BAD_VALUE;
|
2003-10-28 03:13:11 +03:00
|
|
|
char name[B_DISK_SYSTEM_NAME_LENGTH];
|
|
|
|
status_t error = ddm_strlcpy(name, _name, B_DISK_SYSTEM_NAME_LENGTH);
|
2003-10-25 03:09:43 +04:00
|
|
|
if (error)
|
|
|
|
return error;
|
2003-07-09 03:23:27 +04:00
|
|
|
KDiskDeviceManager *manager = KDiskDeviceManager::Default();
|
|
|
|
if (ManagerLocker locker = manager) {
|
|
|
|
if (KDiskSystem *diskSystem = manager->FindDiskSystem(name)) {
|
2003-09-27 09:19:37 +04:00
|
|
|
user_disk_system_info info;
|
|
|
|
diskSystem->GetInfo(&info);
|
|
|
|
user_memcpy(_info, &info, sizeof(info));
|
2003-07-09 03:23:27 +04:00
|
|
|
return B_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return B_ENTRY_NOT_FOUND;
|
|
|
|
}
|
|
|
|
|
2007-10-06 02:39:52 +04:00
|
|
|
|
2004-10-29 05:38:17 +04:00
|
|
|
// _user_supports_defragmenting_partition
|
2003-07-16 01:42:59 +04:00
|
|
|
bool
|
2004-10-29 05:38:17 +04:00
|
|
|
_user_supports_defragmenting_partition(partition_id partitionID,
|
2007-10-06 02:39:52 +04:00
|
|
|
int32 changeCounter, bool *_whileMounted)
|
2003-07-16 01:42:59 +04:00
|
|
|
{
|
|
|
|
KDiskDeviceManager *manager = KDiskDeviceManager::Default();
|
|
|
|
// get the partition
|
|
|
|
KPartition *partition = manager->ReadLockPartition(partitionID);
|
|
|
|
if (!partition)
|
|
|
|
return false;
|
|
|
|
PartitionRegistrar registrar1(partition, true);
|
|
|
|
PartitionRegistrar registrar2(partition->Device(), true);
|
|
|
|
DeviceReadLocker locker(partition->Device(), true);
|
2003-09-27 09:19:37 +04:00
|
|
|
bool whileMounted;
|
|
|
|
bool result = validate_defragment_partition(partition, changeCounter,
|
2007-10-06 02:39:52 +04:00
|
|
|
&whileMounted) == B_OK;
|
2003-09-27 09:19:37 +04:00
|
|
|
if (result && _whileMounted)
|
2003-10-24 13:37:20 +04:00
|
|
|
user_memcpy(_whileMounted, &whileMounted, sizeof(whileMounted));
|
2003-09-27 09:19:37 +04:00
|
|
|
return result;
|
2003-07-16 01:42:59 +04:00
|
|
|
}
|
|
|
|
|
2007-10-06 02:39:52 +04:00
|
|
|
|
2004-10-29 05:38:17 +04:00
|
|
|
// _user_supports_repairing_partition
|
2003-07-16 01:42:59 +04:00
|
|
|
bool
|
2004-10-29 05:38:17 +04:00
|
|
|
_user_supports_repairing_partition(partition_id partitionID,
|
2007-10-06 02:39:52 +04:00
|
|
|
int32 changeCounter, bool checkOnly, bool *_whileMounted)
|
2003-07-16 01:42:59 +04:00
|
|
|
{
|
|
|
|
KDiskDeviceManager *manager = KDiskDeviceManager::Default();
|
|
|
|
// get the partition
|
|
|
|
KPartition *partition = manager->ReadLockPartition(partitionID);
|
|
|
|
if (!partition)
|
|
|
|
return false;
|
|
|
|
PartitionRegistrar registrar1(partition, true);
|
|
|
|
PartitionRegistrar registrar2(partition->Device(), true);
|
|
|
|
DeviceReadLocker locker(partition->Device(), true);
|
2003-09-27 09:19:37 +04:00
|
|
|
bool whileMounted;
|
|
|
|
bool result = validate_repair_partition(partition, changeCounter, checkOnly,
|
2007-10-06 02:39:52 +04:00
|
|
|
&whileMounted) == B_OK;
|
2003-09-27 09:19:37 +04:00
|
|
|
if (result && _whileMounted)
|
2003-10-24 13:37:20 +04:00
|
|
|
user_memcpy(_whileMounted, &whileMounted, sizeof(whileMounted));
|
2003-09-27 09:19:37 +04:00
|
|
|
return result;
|
2003-07-16 01:42:59 +04:00
|
|
|
}
|
|
|
|
|
2007-10-06 02:39:52 +04:00
|
|
|
|
2004-10-29 05:38:17 +04:00
|
|
|
// _user_supports_resizing_partition
|
2003-07-16 01:42:59 +04:00
|
|
|
bool
|
2007-10-06 02:39:52 +04:00
|
|
|
_user_supports_resizing_partition(partition_id partitionID, int32 changeCounter,
|
|
|
|
bool *_canResizeContents, bool *_whileMounted)
|
2003-07-16 01:42:59 +04:00
|
|
|
{
|
|
|
|
KDiskDeviceManager *manager = KDiskDeviceManager::Default();
|
2007-08-23 01:21:30 +04:00
|
|
|
|
2003-07-16 01:42:59 +04:00
|
|
|
// get the partition
|
|
|
|
KPartition *partition = manager->ReadLockPartition(partitionID);
|
|
|
|
if (!partition)
|
|
|
|
return false;
|
|
|
|
PartitionRegistrar registrar1(partition, true);
|
|
|
|
PartitionRegistrar registrar2(partition->Device(), true);
|
|
|
|
DeviceReadLocker locker(partition->Device(), true);
|
2003-07-22 04:11:03 +04:00
|
|
|
if (!check_shadow_partition(partition, changeCounter)
|
|
|
|
|| !partition->Parent()) {
|
2003-07-16 01:42:59 +04:00
|
|
|
return false;
|
2003-07-22 04:11:03 +04:00
|
|
|
}
|
|
|
|
if (partition->Parent()->IsBusy()
|
|
|
|
|| partition->Parent()->IsDescendantBusy()) {
|
|
|
|
return false;
|
|
|
|
}
|
2007-08-23 01:21:30 +04:00
|
|
|
|
2003-07-20 00:37:00 +04:00
|
|
|
// get the parent disk system
|
|
|
|
KDiskSystem *parentDiskSystem = partition->Parent()->DiskSystem();
|
|
|
|
if (!parentDiskSystem)
|
2003-07-16 01:42:59 +04:00
|
|
|
return false;
|
2007-08-23 01:21:30 +04:00
|
|
|
bool result = parentDiskSystem->SupportsChildOperations(partition,
|
|
|
|
B_DISK_SYSTEM_SUPPORTS_RESIZING_CHILD);
|
2003-07-20 00:37:00 +04:00
|
|
|
if (!result)
|
2003-07-16 01:42:59 +04:00
|
|
|
return false;
|
2007-08-23 01:21:30 +04:00
|
|
|
|
2003-07-20 00:37:00 +04:00
|
|
|
// get the child disk system
|
|
|
|
KDiskSystem *childDiskSystem = partition->DiskSystem();
|
2003-10-24 13:37:20 +04:00
|
|
|
if (_canResizeContents) {
|
2007-08-23 01:21:30 +04:00
|
|
|
bool canResizeContents = false;
|
|
|
|
bool whileMounted = false;
|
|
|
|
if (childDiskSystem) {
|
|
|
|
uint32 operations = childDiskSystem->GetSupportedOperations(
|
|
|
|
partition, B_DISK_SYSTEM_SUPPORTS_RESIZING
|
|
|
|
| B_DISK_SYSTEM_SUPPORTS_RESIZING_WHILE_MOUNTED);
|
|
|
|
|
|
|
|
if (operations & B_DISK_SYSTEM_SUPPORTS_RESIZING) {
|
|
|
|
canResizeContents = true;
|
|
|
|
if (operations & B_DISK_SYSTEM_SUPPORTS_RESIZING_WHILE_MOUNTED)
|
|
|
|
whileMounted = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-10-24 13:37:20 +04:00
|
|
|
user_memcpy(_canResizeContents, &canResizeContents, sizeof(canResizeContents));
|
2003-09-27 09:19:37 +04:00
|
|
|
if (_whileMounted)
|
2003-10-24 13:37:20 +04:00
|
|
|
user_memcpy(_whileMounted, &whileMounted, sizeof(whileMounted));
|
2003-07-30 04:24:22 +04:00
|
|
|
}
|
2003-07-20 00:37:00 +04:00
|
|
|
// TODO: Currently we report that we cannot resize the contents, if the
|
|
|
|
// partition's disk system is unknown. I found this more logical. It doesn't
|
|
|
|
// really matter, though, since the API user can check for this situation.
|
|
|
|
return result;
|
2003-07-16 01:42:59 +04:00
|
|
|
}
|
|
|
|
|
2007-10-06 02:39:52 +04:00
|
|
|
|
2004-10-29 05:38:17 +04:00
|
|
|
// _user_supports_moving_partition
|
2003-07-16 01:42:59 +04:00
|
|
|
bool
|
2004-10-29 05:38:17 +04:00
|
|
|
_user_supports_moving_partition(partition_id partitionID, int32 changeCounter,
|
2007-10-06 02:39:52 +04:00
|
|
|
partition_id *_unmovable, partition_id *_needUnmounting, size_t bufferSize)
|
2003-07-16 01:42:59 +04:00
|
|
|
{
|
2003-10-27 10:28:55 +03:00
|
|
|
if ((!_unmovable || !_needUnmounting) && bufferSize > 0)
|
2003-07-16 01:42:59 +04:00
|
|
|
return false;
|
2003-10-27 10:28:55 +03:00
|
|
|
partition_id *unmovable = NULL;
|
|
|
|
partition_id *needUnmounting = NULL;
|
|
|
|
if (bufferSize > 0) {
|
|
|
|
unmovable = static_cast<partition_id*>(malloc(bufferSize));
|
|
|
|
needUnmounting = static_cast<partition_id*>(malloc(bufferSize));
|
|
|
|
if (unmovable && needUnmounting) {
|
|
|
|
user_memcpy(unmovable, _unmovable, bufferSize);
|
|
|
|
user_memcpy(needUnmounting, _needUnmounting, bufferSize);
|
|
|
|
} else {
|
|
|
|
free(unmovable);
|
|
|
|
free(needUnmounting);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2003-07-16 01:42:59 +04:00
|
|
|
KDiskDeviceManager *manager = KDiskDeviceManager::Default();
|
|
|
|
// get the partition
|
|
|
|
KPartition *partition = manager->ReadLockPartition(partitionID);
|
2003-10-27 10:28:55 +03:00
|
|
|
bool result = partition;
|
|
|
|
if (result) {
|
|
|
|
PartitionRegistrar registrar1(partition, true);
|
|
|
|
PartitionRegistrar registrar2(partition->Device(), true);
|
|
|
|
DeviceReadLocker locker(partition->Device(), true);
|
|
|
|
result = check_shadow_partition(partition, changeCounter)
|
2007-10-06 02:39:52 +04:00
|
|
|
&& partition->Parent();
|
2003-10-27 10:28:55 +03:00
|
|
|
if (result) {
|
|
|
|
result = !partition->Parent()->IsBusy()
|
2007-10-06 02:39:52 +04:00
|
|
|
&& !partition->Parent()->IsDescendantBusy();
|
2003-10-27 10:28:55 +03:00
|
|
|
}
|
|
|
|
if (result) {
|
|
|
|
// get the parent disk system
|
|
|
|
KDiskSystem *parentDiskSystem = partition->Parent()->DiskSystem();
|
|
|
|
result = parentDiskSystem;
|
2007-08-23 01:21:30 +04:00
|
|
|
if (result) {
|
|
|
|
result = parentDiskSystem->SupportsChildOperations(partition,
|
|
|
|
B_DISK_SYSTEM_SUPPORTS_MOVING_CHILD);
|
|
|
|
}
|
|
|
|
|
2003-10-27 10:28:55 +03:00
|
|
|
if (result) {
|
|
|
|
// check the movability of the descendants' contents
|
|
|
|
size_t unmovableSize = bufferSize;
|
|
|
|
size_t needUnmountingSize = bufferSize;
|
|
|
|
result = get_unmovable_descendants(partition, unmovable,
|
2007-10-06 02:39:52 +04:00
|
|
|
unmovableSize, needUnmounting, needUnmountingSize);
|
2003-10-27 10:28:55 +03:00
|
|
|
}
|
|
|
|
}
|
2003-07-22 04:11:03 +04:00
|
|
|
}
|
2003-10-27 10:28:55 +03:00
|
|
|
if (result && bufferSize > 0) {
|
|
|
|
user_memcpy(_unmovable, unmovable, bufferSize);
|
|
|
|
user_memcpy(_needUnmounting, needUnmounting, bufferSize);
|
2003-07-20 00:37:00 +04:00
|
|
|
}
|
2003-10-27 10:28:55 +03:00
|
|
|
free(unmovable);
|
|
|
|
free(needUnmounting);
|
2003-07-20 00:37:00 +04:00
|
|
|
return result;
|
2003-07-16 01:42:59 +04:00
|
|
|
}
|
|
|
|
|
2007-10-06 02:39:52 +04:00
|
|
|
|
2004-10-29 05:38:17 +04:00
|
|
|
// _user_supports_setting_partition_name
|
2003-07-16 01:42:59 +04:00
|
|
|
bool
|
2004-10-29 05:38:17 +04:00
|
|
|
_user_supports_setting_partition_name(partition_id partitionID,
|
2007-10-06 02:39:52 +04:00
|
|
|
int32 changeCounter)
|
2003-07-16 01:42:59 +04:00
|
|
|
{
|
|
|
|
KDiskDeviceManager *manager = KDiskDeviceManager::Default();
|
|
|
|
// get the partition
|
|
|
|
KPartition *partition = manager->ReadLockPartition(partitionID);
|
|
|
|
if (!partition)
|
|
|
|
return false;
|
|
|
|
PartitionRegistrar registrar1(partition, true);
|
|
|
|
PartitionRegistrar registrar2(partition->Device(), true);
|
|
|
|
DeviceReadLocker locker(partition->Device(), true);
|
2003-07-22 04:11:03 +04:00
|
|
|
if (!check_shadow_partition(partition, changeCounter)
|
|
|
|
|| !partition->Parent()) {
|
2003-07-16 01:42:59 +04:00
|
|
|
return false;
|
2003-07-22 04:11:03 +04:00
|
|
|
}
|
|
|
|
if (partition->Parent()->IsBusy()
|
|
|
|
|| partition->Parent()->IsDescendantBusy()) {
|
2003-07-16 01:42:59 +04:00
|
|
|
return false;
|
2003-07-22 04:11:03 +04:00
|
|
|
}
|
2007-08-23 01:21:30 +04:00
|
|
|
|
2003-07-22 04:11:03 +04:00
|
|
|
// get the disk system
|
2003-07-16 01:42:59 +04:00
|
|
|
KDiskSystem *diskSystem = partition->Parent()->DiskSystem();
|
2003-07-20 00:37:00 +04:00
|
|
|
if (!diskSystem)
|
2003-07-16 01:42:59 +04:00
|
|
|
return false;
|
2007-08-23 01:21:30 +04:00
|
|
|
|
2003-07-16 01:42:59 +04:00
|
|
|
// get the info
|
2007-08-23 01:21:30 +04:00
|
|
|
return diskSystem->SupportsChildOperations(partition,
|
|
|
|
B_DISK_SYSTEM_SUPPORTS_SETTING_NAME);
|
2003-07-16 01:42:59 +04:00
|
|
|
}
|
|
|
|
|
2004-10-29 05:38:17 +04:00
|
|
|
// _user_supports_setting_partition_content_name
|
2003-07-16 01:42:59 +04:00
|
|
|
bool
|
2004-10-29 05:38:17 +04:00
|
|
|
_user_supports_setting_partition_content_name(partition_id partitionID,
|
2007-10-06 02:39:52 +04:00
|
|
|
int32 changeCounter, bool *_whileMounted)
|
2003-07-16 01:42:59 +04:00
|
|
|
{
|
|
|
|
KDiskDeviceManager *manager = KDiskDeviceManager::Default();
|
|
|
|
// get the partition
|
|
|
|
KPartition *partition = manager->ReadLockPartition(partitionID);
|
|
|
|
if (!partition)
|
|
|
|
return false;
|
|
|
|
PartitionRegistrar registrar1(partition, true);
|
|
|
|
PartitionRegistrar registrar2(partition->Device(), true);
|
|
|
|
DeviceReadLocker locker(partition->Device(), true);
|
2003-07-22 04:11:03 +04:00
|
|
|
if (!check_shadow_partition(partition, changeCounter))
|
|
|
|
return false;
|
|
|
|
if (partition->IsBusy() || partition->IsDescendantBusy())
|
2003-07-16 01:42:59 +04:00
|
|
|
return false;
|
|
|
|
// get the disk system
|
|
|
|
KDiskSystem *diskSystem = partition->DiskSystem();
|
2003-07-20 00:37:00 +04:00
|
|
|
if (!diskSystem)
|
2003-07-16 01:42:59 +04:00
|
|
|
return false;
|
2007-08-23 01:21:30 +04:00
|
|
|
|
2003-07-16 01:42:59 +04:00
|
|
|
// get the info
|
2007-08-23 01:21:30 +04:00
|
|
|
uint32 operations = diskSystem->GetSupportedOperations(partition,
|
|
|
|
B_DISK_SYSTEM_SUPPORTS_SETTING_CONTENT_NAME
|
|
|
|
| B_DISK_SYSTEM_SUPPORTS_SETTING_CONTENT_NAME_WHILE_MOUNTED);
|
|
|
|
|
|
|
|
bool result = (operations & B_DISK_SYSTEM_SUPPORTS_SETTING_CONTENT_NAME);
|
|
|
|
if (result && _whileMounted) {
|
|
|
|
bool whileMounted = (operations
|
|
|
|
& B_DISK_SYSTEM_SUPPORTS_SETTING_CONTENT_NAME_WHILE_MOUNTED);
|
2003-10-24 13:37:20 +04:00
|
|
|
user_memcpy(_whileMounted, &whileMounted, sizeof(whileMounted));
|
2007-08-23 01:21:30 +04:00
|
|
|
}
|
|
|
|
|
2003-09-27 09:19:37 +04:00
|
|
|
return result;
|
2003-07-16 01:42:59 +04:00
|
|
|
}
|
|
|
|
|
2007-10-06 02:39:52 +04:00
|
|
|
|
2004-10-29 05:38:17 +04:00
|
|
|
// _user_supports_setting_partition_type
|
2003-07-16 01:42:59 +04:00
|
|
|
bool
|
2004-10-29 05:38:17 +04:00
|
|
|
_user_supports_setting_partition_type(partition_id partitionID,
|
2007-10-06 02:39:52 +04:00
|
|
|
int32 changeCounter)
|
2003-07-16 01:42:59 +04:00
|
|
|
{
|
|
|
|
KDiskDeviceManager *manager = KDiskDeviceManager::Default();
|
|
|
|
// get the partition
|
|
|
|
KPartition *partition = manager->ReadLockPartition(partitionID);
|
|
|
|
if (!partition)
|
|
|
|
return false;
|
|
|
|
PartitionRegistrar registrar1(partition, true);
|
|
|
|
PartitionRegistrar registrar2(partition->Device(), true);
|
|
|
|
DeviceReadLocker locker(partition->Device(), true);
|
2003-07-22 04:11:03 +04:00
|
|
|
if (!check_shadow_partition(partition, changeCounter)
|
|
|
|
|| !partition->Parent()) {
|
2003-07-16 01:42:59 +04:00
|
|
|
return false;
|
2003-07-22 04:11:03 +04:00
|
|
|
}
|
|
|
|
if (partition->Parent()->IsBusy()
|
|
|
|
|| partition->Parent()->IsDescendantBusy()) {
|
2003-07-16 01:42:59 +04:00
|
|
|
return false;
|
2003-07-22 04:11:03 +04:00
|
|
|
}
|
|
|
|
// get the disk system
|
2003-07-16 01:42:59 +04:00
|
|
|
KDiskSystem *diskSystem = partition->Parent()->DiskSystem();
|
2003-07-20 00:37:00 +04:00
|
|
|
if (!diskSystem)
|
2003-07-16 01:42:59 +04:00
|
|
|
return false;
|
|
|
|
// get the info
|
2007-08-23 01:21:30 +04:00
|
|
|
return diskSystem->SupportsChildOperations(partition,
|
|
|
|
B_DISK_SYSTEM_SUPPORTS_SETTING_TYPE);
|
2003-07-16 01:42:59 +04:00
|
|
|
}
|
|
|
|
|
2007-10-06 02:39:52 +04:00
|
|
|
|
2004-10-29 05:38:17 +04:00
|
|
|
// _user_supports_setting_partition_parameters
|
2003-07-16 01:42:59 +04:00
|
|
|
bool
|
2004-10-29 05:38:17 +04:00
|
|
|
_user_supports_setting_partition_parameters(partition_id partitionID,
|
2007-10-06 02:39:52 +04:00
|
|
|
int32 changeCounter)
|
2003-07-16 01:42:59 +04:00
|
|
|
{
|
|
|
|
KDiskDeviceManager *manager = KDiskDeviceManager::Default();
|
|
|
|
// get the partition
|
|
|
|
KPartition *partition = manager->ReadLockPartition(partitionID);
|
|
|
|
if (!partition)
|
|
|
|
return false;
|
|
|
|
PartitionRegistrar registrar1(partition, true);
|
|
|
|
PartitionRegistrar registrar2(partition->Device(), true);
|
|
|
|
DeviceReadLocker locker(partition->Device(), true);
|
2003-07-22 04:11:03 +04:00
|
|
|
if (!check_shadow_partition(partition, changeCounter)
|
|
|
|
|| !partition->Parent()) {
|
2003-07-16 01:42:59 +04:00
|
|
|
return false;
|
2003-07-22 04:11:03 +04:00
|
|
|
}
|
|
|
|
if (partition->Parent()->IsBusy()
|
|
|
|
|| partition->Parent()->IsDescendantBusy()) {
|
2003-07-20 00:37:00 +04:00
|
|
|
return false;
|
2003-07-22 04:11:03 +04:00
|
|
|
}
|
|
|
|
// get the disk system
|
2003-07-20 00:37:00 +04:00
|
|
|
KDiskSystem *diskSystem = partition->Parent()->DiskSystem();
|
|
|
|
if (!diskSystem)
|
2003-07-16 01:42:59 +04:00
|
|
|
return false;
|
|
|
|
// get the info
|
2007-08-23 01:21:30 +04:00
|
|
|
return diskSystem->SupportsChildOperations(partition,
|
|
|
|
B_DISK_SYSTEM_SUPPORTS_SETTING_PARAMETERS);
|
2003-07-16 01:42:59 +04:00
|
|
|
}
|
|
|
|
|
2007-10-06 02:39:52 +04:00
|
|
|
|
2004-10-29 05:38:17 +04:00
|
|
|
// _user_supports_setting_partition_content_parameters
|
2003-07-16 01:42:59 +04:00
|
|
|
bool
|
2004-10-29 05:38:17 +04:00
|
|
|
_user_supports_setting_partition_content_parameters(partition_id partitionID,
|
2007-10-06 02:39:52 +04:00
|
|
|
int32 changeCounter, bool *_whileMounted)
|
2003-07-16 01:42:59 +04:00
|
|
|
{
|
|
|
|
KDiskDeviceManager *manager = KDiskDeviceManager::Default();
|
|
|
|
// get the partition
|
|
|
|
KPartition *partition = manager->ReadLockPartition(partitionID);
|
|
|
|
if (!partition)
|
|
|
|
return false;
|
|
|
|
PartitionRegistrar registrar1(partition, true);
|
|
|
|
PartitionRegistrar registrar2(partition->Device(), true);
|
|
|
|
DeviceReadLocker locker(partition->Device(), true);
|
2003-07-22 04:11:03 +04:00
|
|
|
if (!check_shadow_partition(partition, changeCounter))
|
|
|
|
return false;
|
|
|
|
if (partition->IsBusy() || partition->IsDescendantBusy())
|
2003-07-16 01:42:59 +04:00
|
|
|
return false;
|
|
|
|
// get the disk system
|
2003-07-20 00:37:00 +04:00
|
|
|
KDiskSystem *diskSystem = partition->DiskSystem();
|
|
|
|
if (!diskSystem)
|
2003-07-16 01:42:59 +04:00
|
|
|
return false;
|
|
|
|
// get the info
|
2007-08-23 01:21:30 +04:00
|
|
|
uint32 operations = diskSystem->GetSupportedOperations(partition,
|
|
|
|
B_DISK_SYSTEM_SUPPORTS_SETTING_CONTENT_PARAMETERS
|
|
|
|
| B_DISK_SYSTEM_SUPPORTS_SETTING_CONTENT_PARAMETERS_WHILE_MOUNTED);
|
|
|
|
bool result = (operations
|
|
|
|
& B_DISK_SYSTEM_SUPPORTS_SETTING_CONTENT_PARAMETERS);
|
|
|
|
if (result && _whileMounted) {
|
|
|
|
bool whileMounted = (operations
|
|
|
|
& B_DISK_SYSTEM_SUPPORTS_SETTING_CONTENT_PARAMETERS_WHILE_MOUNTED);
|
2003-10-24 13:37:20 +04:00
|
|
|
user_memcpy(_whileMounted, &whileMounted, sizeof(whileMounted));
|
2007-08-23 01:21:30 +04:00
|
|
|
}
|
2003-09-28 04:41:19 +04:00
|
|
|
return result;
|
2003-07-16 01:42:59 +04:00
|
|
|
}
|
|
|
|
|
2007-10-06 02:39:52 +04:00
|
|
|
|
2004-10-29 05:38:17 +04:00
|
|
|
// _user_supports_initializing_partition
|
2003-07-16 01:42:59 +04:00
|
|
|
bool
|
2004-10-29 05:38:17 +04:00
|
|
|
_user_supports_initializing_partition(partition_id partitionID,
|
2007-10-06 02:39:52 +04:00
|
|
|
int32 changeCounter, const char *_diskSystemName)
|
2003-07-16 01:42:59 +04:00
|
|
|
{
|
2007-07-27 16:12:35 +04:00
|
|
|
if (!_diskSystemName)
|
2003-09-27 09:19:37 +04:00
|
|
|
return false;
|
2003-10-28 03:13:11 +03:00
|
|
|
char diskSystemName[B_DISK_SYSTEM_NAME_LENGTH];
|
|
|
|
status_t error = ddm_strlcpy(diskSystemName, _diskSystemName, B_DISK_SYSTEM_NAME_LENGTH);
|
2003-10-25 03:09:43 +04:00
|
|
|
if (error)
|
|
|
|
return error;
|
2003-07-16 01:42:59 +04:00
|
|
|
KDiskDeviceManager *manager = KDiskDeviceManager::Default();
|
2007-08-23 01:21:30 +04:00
|
|
|
|
2003-07-16 01:42:59 +04:00
|
|
|
// get the partition
|
|
|
|
KPartition *partition = manager->ReadLockPartition(partitionID);
|
|
|
|
if (!partition)
|
|
|
|
return false;
|
|
|
|
PartitionRegistrar registrar1(partition, true);
|
|
|
|
PartitionRegistrar registrar2(partition->Device(), true);
|
|
|
|
DeviceReadLocker locker(partition->Device(), true);
|
2003-07-22 04:11:03 +04:00
|
|
|
if (!check_shadow_partition(partition, changeCounter))
|
|
|
|
return false;
|
|
|
|
if (partition->IsBusy() || partition->IsDescendantBusy())
|
2003-07-16 01:42:59 +04:00
|
|
|
return false;
|
2007-08-23 01:21:30 +04:00
|
|
|
|
2003-07-16 01:42:59 +04:00
|
|
|
// get the disk system
|
2003-07-20 00:37:00 +04:00
|
|
|
KDiskSystem *diskSystem = manager->LoadDiskSystem(diskSystemName);
|
2003-07-16 01:42:59 +04:00
|
|
|
if (!diskSystem)
|
|
|
|
return false;
|
|
|
|
DiskSystemLoader loader(diskSystem, true);
|
2007-08-23 01:21:30 +04:00
|
|
|
|
2003-07-16 01:42:59 +04:00
|
|
|
// get the info
|
2007-08-23 01:21:30 +04:00
|
|
|
if (!diskSystem->SupportsOperations(partition,
|
|
|
|
B_DISK_SYSTEM_SUPPORTS_INITIALIZING)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// get the parent partition's disk system
|
|
|
|
KPartition* parentPartition = partition->Parent();
|
|
|
|
if (!parentPartition)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
KDiskSystem* parentDiskSystem = parentPartition->DiskSystem();
|
|
|
|
if (!parentDiskSystem)
|
|
|
|
return false; // something's fishy!
|
|
|
|
|
|
|
|
// ask the parent disk system
|
|
|
|
return parentDiskSystem->SupportsInitializingChild(partition,
|
|
|
|
diskSystemName);
|
2003-07-16 01:42:59 +04:00
|
|
|
}
|
|
|
|
|
2007-10-06 02:39:52 +04:00
|
|
|
|
2004-10-29 05:38:17 +04:00
|
|
|
// _user_supports_creating_child_partition
|
2003-07-16 01:42:59 +04:00
|
|
|
bool
|
2004-10-29 05:38:17 +04:00
|
|
|
_user_supports_creating_child_partition(partition_id partitionID,
|
2007-10-06 02:39:52 +04:00
|
|
|
int32 changeCounter)
|
2003-07-16 01:42:59 +04:00
|
|
|
{
|
|
|
|
KDiskDeviceManager *manager = KDiskDeviceManager::Default();
|
|
|
|
// get the partition
|
|
|
|
KPartition *partition = manager->ReadLockPartition(partitionID);
|
|
|
|
if (!partition)
|
|
|
|
return false;
|
|
|
|
PartitionRegistrar registrar1(partition, true);
|
|
|
|
PartitionRegistrar registrar2(partition->Device(), true);
|
|
|
|
DeviceReadLocker locker(partition->Device(), true);
|
2003-07-22 04:11:03 +04:00
|
|
|
if (!check_shadow_partition(partition, changeCounter))
|
|
|
|
return false;
|
|
|
|
if (partition->IsBusy() || partition->IsDescendantBusy())
|
2003-07-16 01:42:59 +04:00
|
|
|
return false;
|
|
|
|
// get the disk system
|
2003-07-20 00:37:00 +04:00
|
|
|
KDiskSystem *diskSystem = partition->DiskSystem();
|
|
|
|
if (!diskSystem)
|
2003-07-16 01:42:59 +04:00
|
|
|
return false;
|
|
|
|
// get the info
|
2007-08-23 01:21:30 +04:00
|
|
|
return diskSystem->SupportsOperations(partition,
|
|
|
|
B_DISK_SYSTEM_SUPPORTS_CREATING_CHILD);
|
2003-07-16 01:42:59 +04:00
|
|
|
}
|
|
|
|
|
2007-10-06 02:39:52 +04:00
|
|
|
|
2004-10-29 05:38:17 +04:00
|
|
|
// _user_supports_deleting_child_partition
|
2003-07-17 01:01:14 +04:00
|
|
|
bool
|
2004-10-29 05:38:17 +04:00
|
|
|
_user_supports_deleting_child_partition(partition_id partitionID,
|
2007-10-06 02:39:52 +04:00
|
|
|
int32 changeCounter)
|
2003-07-17 01:01:14 +04:00
|
|
|
{
|
|
|
|
KDiskDeviceManager *manager = KDiskDeviceManager::Default();
|
|
|
|
// get the partition
|
|
|
|
KPartition *partition = manager->ReadLockPartition(partitionID);
|
|
|
|
if (!partition)
|
|
|
|
return false;
|
|
|
|
PartitionRegistrar registrar1(partition, true);
|
|
|
|
PartitionRegistrar registrar2(partition->Device(), true);
|
|
|
|
DeviceReadLocker locker(partition->Device(), true);
|
2003-07-25 02:58:06 +04:00
|
|
|
return (validate_delete_child_partition(partition, changeCounter) == B_OK);
|
2003-07-17 01:01:14 +04:00
|
|
|
}
|
|
|
|
|
2007-10-06 02:39:52 +04:00
|
|
|
|
2004-10-29 05:38:17 +04:00
|
|
|
// _user_is_sub_disk_system_for
|
2003-07-20 00:37:00 +04:00
|
|
|
bool
|
2004-10-29 05:38:17 +04:00
|
|
|
_user_is_sub_disk_system_for(disk_system_id diskSystemID,
|
2007-10-06 02:39:52 +04:00
|
|
|
partition_id partitionID, int32 changeCounter)
|
2003-07-17 01:01:14 +04:00
|
|
|
{
|
|
|
|
KDiskDeviceManager *manager = KDiskDeviceManager::Default();
|
|
|
|
// get the partition
|
|
|
|
KPartition *partition = manager->ReadLockPartition(partitionID);
|
|
|
|
if (!partition)
|
2003-07-20 00:37:00 +04:00
|
|
|
return false;
|
2003-07-17 01:01:14 +04:00
|
|
|
PartitionRegistrar registrar1(partition, true);
|
|
|
|
PartitionRegistrar registrar2(partition->Device(), true);
|
|
|
|
DeviceReadLocker locker(partition->Device(), true);
|
2003-07-22 04:11:03 +04:00
|
|
|
if (!check_shadow_partition(partition, changeCounter))
|
2003-07-20 00:37:00 +04:00
|
|
|
return false;
|
2003-07-17 01:01:14 +04:00
|
|
|
// get the disk system
|
|
|
|
KDiskSystem *diskSystem = partition->DiskSystem();
|
|
|
|
if (!diskSystem || diskSystem->ID() != diskSystemID)
|
2003-07-20 00:37:00 +04:00
|
|
|
return false;
|
2003-07-17 01:01:14 +04:00
|
|
|
// get the info
|
2003-07-20 00:37:00 +04:00
|
|
|
return diskSystem->IsSubSystemFor(partition);
|
2003-07-17 01:01:14 +04:00
|
|
|
}
|
|
|
|
|
2007-10-06 02:39:52 +04:00
|
|
|
|
2004-10-29 05:38:17 +04:00
|
|
|
// _user_validate_resize_partition
|
2003-07-17 01:01:14 +04:00
|
|
|
status_t
|
2004-10-29 05:38:17 +04:00
|
|
|
_user_validate_resize_partition(partition_id partitionID, int32 changeCounter,
|
2007-10-06 02:39:52 +04:00
|
|
|
off_t *_size)
|
2003-07-17 01:01:14 +04:00
|
|
|
{
|
2003-09-27 09:19:37 +04:00
|
|
|
if (!_size)
|
2003-07-17 01:01:14 +04:00
|
|
|
return B_BAD_VALUE;
|
2003-10-24 13:37:20 +04:00
|
|
|
off_t size;
|
|
|
|
user_memcpy(&size, _size, sizeof(size));
|
2003-07-17 01:01:14 +04:00
|
|
|
KDiskDeviceManager *manager = KDiskDeviceManager::Default();
|
|
|
|
// get the partition
|
|
|
|
KPartition *partition = manager->ReadLockPartition(partitionID);
|
|
|
|
if (!partition)
|
|
|
|
return B_ENTRY_NOT_FOUND;
|
|
|
|
PartitionRegistrar registrar1(partition, true);
|
|
|
|
PartitionRegistrar registrar2(partition->Device(), true);
|
|
|
|
DeviceReadLocker locker(partition->Device(), true);
|
2003-09-30 01:40:36 +04:00
|
|
|
off_t contentSize = 0;
|
|
|
|
bool result = validate_resize_partition(partition, changeCounter, &size,
|
2007-10-06 02:39:52 +04:00
|
|
|
&contentSize);
|
2003-09-27 09:19:37 +04:00
|
|
|
if (result)
|
2003-10-24 13:37:20 +04:00
|
|
|
user_memcpy(_size, &size, sizeof(size));
|
2003-09-27 09:19:37 +04:00
|
|
|
return result;
|
2003-07-17 01:01:14 +04:00
|
|
|
}
|
|
|
|
|
2007-10-06 02:39:52 +04:00
|
|
|
|
2004-10-29 05:38:17 +04:00
|
|
|
// _user_validate_move_partition
|
2003-07-17 01:01:14 +04:00
|
|
|
status_t
|
2004-10-29 05:38:17 +04:00
|
|
|
_user_validate_move_partition(partition_id partitionID, int32 changeCounter,
|
2007-10-06 02:39:52 +04:00
|
|
|
off_t *_newOffset)
|
2003-07-17 01:01:14 +04:00
|
|
|
{
|
2003-10-24 13:37:20 +04:00
|
|
|
if (!_newOffset)
|
2003-07-17 01:01:14 +04:00
|
|
|
return B_BAD_VALUE;
|
2003-10-24 13:37:20 +04:00
|
|
|
off_t newOffset;
|
|
|
|
user_memcpy(&newOffset, _newOffset, sizeof(newOffset));
|
2003-07-17 01:01:14 +04:00
|
|
|
KDiskDeviceManager *manager = KDiskDeviceManager::Default();
|
|
|
|
// get the partition
|
|
|
|
KPartition *partition = manager->ReadLockPartition(partitionID);
|
|
|
|
if (!partition)
|
|
|
|
return B_ENTRY_NOT_FOUND;
|
|
|
|
PartitionRegistrar registrar1(partition, true);
|
|
|
|
PartitionRegistrar registrar2(partition->Device(), true);
|
|
|
|
DeviceReadLocker locker(partition->Device(), true);
|
2007-10-06 02:39:52 +04:00
|
|
|
status_t result = validate_move_partition(partition, changeCounter,
|
|
|
|
&newOffset);
|
2003-10-24 13:37:20 +04:00
|
|
|
if (result)
|
|
|
|
user_memcpy(_newOffset, &newOffset, sizeof(newOffset));
|
|
|
|
return result;
|
2003-07-17 01:01:14 +04:00
|
|
|
}
|
|
|
|
|
2007-10-06 02:39:52 +04:00
|
|
|
|
2004-10-29 05:38:17 +04:00
|
|
|
// _user_validate_set_partition_name
|
2003-07-17 01:01:14 +04:00
|
|
|
status_t
|
2004-10-29 05:38:17 +04:00
|
|
|
_user_validate_set_partition_name(partition_id partitionID,
|
2007-10-06 02:39:52 +04:00
|
|
|
int32 changeCounter, char *_name)
|
2003-07-17 01:01:14 +04:00
|
|
|
{
|
2003-10-24 13:37:20 +04:00
|
|
|
if (!_name)
|
2003-07-21 02:39:37 +04:00
|
|
|
return B_BAD_VALUE;
|
2003-10-28 03:13:11 +03:00
|
|
|
char name[B_DISK_DEVICE_NAME_LENGTH];
|
|
|
|
status_t error = ddm_strlcpy(name, _name, B_DISK_DEVICE_NAME_LENGTH, true);
|
2003-10-25 03:09:43 +04:00
|
|
|
if (error)
|
|
|
|
return error;
|
2003-07-17 01:01:14 +04:00
|
|
|
KDiskDeviceManager *manager = KDiskDeviceManager::Default();
|
|
|
|
// get the partition
|
|
|
|
KPartition *partition = manager->ReadLockPartition(partitionID);
|
|
|
|
if (!partition)
|
|
|
|
return B_ENTRY_NOT_FOUND;
|
|
|
|
PartitionRegistrar registrar1(partition, true);
|
|
|
|
PartitionRegistrar registrar2(partition->Device(), true);
|
|
|
|
DeviceReadLocker locker(partition->Device(), true);
|
2003-10-27 10:28:55 +03:00
|
|
|
error = validate_set_partition_name(partition, changeCounter, name);
|
|
|
|
if (!error)
|
2003-10-28 03:13:11 +03:00
|
|
|
error = ddm_strlcpy(_name, name, B_DISK_DEVICE_NAME_LENGTH);
|
2003-10-27 10:28:55 +03:00
|
|
|
return error;
|
2003-07-17 01:01:14 +04:00
|
|
|
}
|
|
|
|
|
2007-10-06 02:39:52 +04:00
|
|
|
|
2004-10-29 05:38:17 +04:00
|
|
|
// _user_validate_set_partition_content_name
|
2003-07-17 01:01:14 +04:00
|
|
|
status_t
|
2004-10-29 05:38:17 +04:00
|
|
|
_user_validate_set_partition_content_name(partition_id partitionID,
|
2003-10-24 13:37:20 +04:00
|
|
|
int32 changeCounter, char *_name)
|
2003-07-17 01:01:14 +04:00
|
|
|
{
|
2003-10-24 13:37:20 +04:00
|
|
|
if (!_name)
|
2003-07-21 02:39:37 +04:00
|
|
|
return B_BAD_VALUE;
|
2003-10-28 03:13:11 +03:00
|
|
|
char name[B_DISK_DEVICE_NAME_LENGTH];
|
|
|
|
status_t error = ddm_strlcpy(name, _name, B_DISK_DEVICE_NAME_LENGTH, true);
|
2003-10-25 03:09:43 +04:00
|
|
|
if (error)
|
|
|
|
return error;
|
2003-07-17 01:01:14 +04:00
|
|
|
KDiskDeviceManager *manager = KDiskDeviceManager::Default();
|
|
|
|
// get the partition
|
|
|
|
KPartition *partition = manager->ReadLockPartition(partitionID);
|
|
|
|
if (!partition)
|
|
|
|
return B_ENTRY_NOT_FOUND;
|
|
|
|
PartitionRegistrar registrar1(partition, true);
|
|
|
|
PartitionRegistrar registrar2(partition->Device(), true);
|
|
|
|
DeviceReadLocker locker(partition->Device(), true);
|
2003-10-27 10:28:55 +03:00
|
|
|
error = validate_set_partition_content_name(partition, changeCounter, name);
|
|
|
|
if (!error)
|
2003-10-28 03:13:11 +03:00
|
|
|
error = ddm_strlcpy(_name, name, B_DISK_DEVICE_NAME_LENGTH);
|
2003-10-27 10:28:55 +03:00
|
|
|
return error;
|
2003-07-17 01:01:14 +04:00
|
|
|
}
|
|
|
|
|
2007-10-06 02:39:52 +04:00
|
|
|
|
2004-10-29 05:38:17 +04:00
|
|
|
// _user_validate_set_partition_type
|
2003-07-17 01:01:14 +04:00
|
|
|
status_t
|
2004-10-29 05:38:17 +04:00
|
|
|
_user_validate_set_partition_type(partition_id partitionID,
|
2007-10-06 02:39:52 +04:00
|
|
|
int32 changeCounter, const char *_type)
|
2003-07-17 01:01:14 +04:00
|
|
|
{
|
2003-10-24 13:37:20 +04:00
|
|
|
if (!_type)
|
2003-07-17 01:01:14 +04:00
|
|
|
return B_BAD_VALUE;
|
2003-10-28 03:13:11 +03:00
|
|
|
char type[B_DISK_DEVICE_TYPE_LENGTH];
|
|
|
|
status_t error = ddm_strlcpy(type, _type, B_DISK_DEVICE_TYPE_LENGTH);
|
2003-10-25 03:09:43 +04:00
|
|
|
if (error)
|
|
|
|
return error;
|
2003-07-17 01:01:14 +04:00
|
|
|
KDiskDeviceManager *manager = KDiskDeviceManager::Default();
|
|
|
|
// get the partition
|
|
|
|
KPartition *partition = manager->ReadLockPartition(partitionID);
|
|
|
|
if (!partition)
|
|
|
|
return B_ENTRY_NOT_FOUND;
|
|
|
|
PartitionRegistrar registrar1(partition, true);
|
|
|
|
PartitionRegistrar registrar2(partition->Device(), true);
|
|
|
|
DeviceReadLocker locker(partition->Device(), true);
|
2003-07-25 02:58:06 +04:00
|
|
|
return validate_set_partition_type(partition, changeCounter, type);
|
2003-07-17 01:01:14 +04:00
|
|
|
}
|
|
|
|
|
2007-10-06 02:39:52 +04:00
|
|
|
|
2004-10-29 05:38:17 +04:00
|
|
|
// _user_validate_initialize_partition
|
2003-07-17 04:04:22 +04:00
|
|
|
status_t
|
2004-10-29 05:38:17 +04:00
|
|
|
_user_validate_initialize_partition(partition_id partitionID,
|
2007-10-06 02:39:52 +04:00
|
|
|
int32 changeCounter, const char *_diskSystemName, char *_name,
|
|
|
|
const char *_parameters, size_t parametersSize)
|
2003-07-17 04:04:22 +04:00
|
|
|
{
|
2007-10-06 03:25:58 +04:00
|
|
|
if (!_diskSystemName || parametersSize > B_DISK_DEVICE_MAX_PARAMETER_SIZE)
|
2003-07-20 00:37:00 +04:00
|
|
|
return B_BAD_VALUE;
|
2007-10-06 03:25:58 +04:00
|
|
|
|
|
|
|
// copy disk system name
|
2003-10-28 03:13:11 +03:00
|
|
|
char diskSystemName[B_DISK_SYSTEM_NAME_LENGTH];
|
2007-10-06 02:39:52 +04:00
|
|
|
status_t error = ddm_strlcpy(diskSystemName, _diskSystemName,
|
|
|
|
B_DISK_SYSTEM_NAME_LENGTH);
|
2007-10-06 03:25:58 +04:00
|
|
|
|
|
|
|
// copy name
|
|
|
|
char name[B_DISK_DEVICE_NAME_LENGTH];
|
|
|
|
if (!error && _name)
|
2003-10-28 03:13:11 +03:00
|
|
|
error = ddm_strlcpy(name, _name, B_DISK_DEVICE_NAME_LENGTH, true);
|
2007-10-06 03:25:58 +04:00
|
|
|
|
|
|
|
if (error != B_OK)
|
2003-10-25 03:09:43 +04:00
|
|
|
return error;
|
2007-10-06 03:25:58 +04:00
|
|
|
|
|
|
|
// copy parameters
|
|
|
|
char *parameters = NULL;
|
|
|
|
MemoryDeleter parameterDeleter;
|
2003-10-24 13:37:20 +04:00
|
|
|
if (_parameters) {
|
2003-10-25 12:35:27 +04:00
|
|
|
parameters = static_cast<char*>(malloc(parametersSize));
|
2007-10-06 03:25:58 +04:00
|
|
|
if (!parameters)
|
2003-10-24 13:37:20 +04:00
|
|
|
return B_NO_MEMORY;
|
2007-10-06 03:25:58 +04:00
|
|
|
parameterDeleter.SetTo(parameters);
|
|
|
|
|
|
|
|
if (user_memcpy(parameters, _parameters, parametersSize) != B_OK)
|
|
|
|
return B_BAD_ADDRESS;
|
2003-10-24 13:37:20 +04:00
|
|
|
}
|
2007-10-06 03:25:58 +04:00
|
|
|
|
2003-07-17 04:04:22 +04:00
|
|
|
// get the partition
|
2007-10-06 03:25:58 +04:00
|
|
|
KDiskDeviceManager *manager = KDiskDeviceManager::Default();
|
2003-07-17 04:04:22 +04:00
|
|
|
KPartition *partition = manager->ReadLockPartition(partitionID);
|
2007-10-06 03:25:58 +04:00
|
|
|
if (!partition)
|
|
|
|
return B_ENTRY_NOT_FOUND;
|
|
|
|
|
|
|
|
// validate
|
|
|
|
PartitionRegistrar registrar1(partition, true);
|
|
|
|
PartitionRegistrar registrar2(partition->Device(), true);
|
|
|
|
DeviceReadLocker locker(partition->Device(), true);
|
|
|
|
error = validate_initialize_partition(partition, changeCounter,
|
|
|
|
diskSystemName, _name ? name : NULL, parameters);
|
|
|
|
|
|
|
|
// copy back the modified name
|
|
|
|
if (!error && _name)
|
2007-07-27 20:32:47 +04:00
|
|
|
error = ddm_strlcpy(_name, name, B_DISK_DEVICE_NAME_LENGTH);
|
2007-10-06 03:25:58 +04:00
|
|
|
|
2007-07-27 16:12:35 +04:00
|
|
|
return error;
|
2003-07-17 04:04:22 +04:00
|
|
|
}
|
|
|
|
|
2007-10-06 02:39:52 +04:00
|
|
|
|
2004-10-29 05:38:17 +04:00
|
|
|
// _user_validate_create_child_partition
|
2003-07-17 01:01:14 +04:00
|
|
|
status_t
|
2004-10-29 05:38:17 +04:00
|
|
|
_user_validate_create_child_partition(partition_id partitionID,
|
2007-10-06 02:39:52 +04:00
|
|
|
int32 changeCounter, off_t *_offset, off_t *_size, const char *_type,
|
|
|
|
const char *_parameters, size_t parametersSize)
|
2003-07-17 01:01:14 +04:00
|
|
|
{
|
2003-10-27 11:10:52 +03:00
|
|
|
if (!_offset || !_size || !_type
|
2007-10-06 02:39:52 +04:00
|
|
|
|| parametersSize > B_DISK_DEVICE_MAX_PARAMETER_SIZE) {
|
2003-07-17 01:01:14 +04:00
|
|
|
return B_BAD_VALUE;
|
2003-10-27 11:10:52 +03:00
|
|
|
}
|
2003-10-24 13:37:20 +04:00
|
|
|
off_t offset;
|
|
|
|
off_t size;
|
2003-10-28 03:13:11 +03:00
|
|
|
char type[B_DISK_DEVICE_TYPE_LENGTH];
|
2003-10-24 13:37:20 +04:00
|
|
|
char *parameters = NULL;
|
|
|
|
user_memcpy(&offset, _offset, sizeof(offset));
|
|
|
|
user_memcpy(&size, _size, sizeof(size));
|
2003-10-28 03:13:11 +03:00
|
|
|
status_t error = ddm_strlcpy(type, _type, B_DISK_DEVICE_TYPE_LENGTH);
|
2003-10-25 03:09:43 +04:00
|
|
|
if (error)
|
|
|
|
return error;
|
2003-10-24 13:37:20 +04:00
|
|
|
if (_parameters) {
|
2003-10-25 12:35:27 +04:00
|
|
|
parameters = static_cast<char*>(malloc(parametersSize));
|
2003-10-24 13:37:20 +04:00
|
|
|
if (parameters)
|
2003-10-25 12:35:27 +04:00
|
|
|
user_memcpy(parameters, _parameters, parametersSize);
|
2003-10-24 13:37:20 +04:00
|
|
|
else
|
|
|
|
return B_NO_MEMORY;
|
|
|
|
}
|
2003-07-17 01:01:14 +04:00
|
|
|
KDiskDeviceManager *manager = KDiskDeviceManager::Default();
|
|
|
|
// get the partition
|
|
|
|
KPartition *partition = manager->ReadLockPartition(partitionID);
|
2007-10-06 02:39:52 +04:00
|
|
|
error = partition ? (status_t)B_OK : (status_t)B_ENTRY_NOT_FOUND;
|
2003-10-24 13:37:20 +04:00
|
|
|
if (!error) {
|
|
|
|
PartitionRegistrar registrar1(partition, true);
|
|
|
|
PartitionRegistrar registrar2(partition->Device(), true);
|
|
|
|
DeviceReadLocker locker(partition->Device(), true);
|
2007-10-06 02:39:52 +04:00
|
|
|
error = validate_create_child_partition(partition, changeCounter,
|
|
|
|
&offset, &size, type, parameters);
|
2003-10-24 13:37:20 +04:00
|
|
|
}
|
|
|
|
if (!error) {
|
|
|
|
user_memcpy(_offset, &offset, sizeof(offset));
|
|
|
|
user_memcpy(_size, &size, sizeof(size));
|
|
|
|
}
|
|
|
|
free(parameters);
|
|
|
|
return error;
|
2003-07-17 01:01:14 +04:00
|
|
|
}
|
|
|
|
|
2007-10-06 02:39:52 +04:00
|
|
|
|
2004-10-29 05:38:17 +04:00
|
|
|
// _user_get_next_supported_partition_type
|
2003-07-17 01:01:14 +04:00
|
|
|
status_t
|
2004-10-29 05:38:17 +04:00
|
|
|
_user_get_next_supported_partition_type(partition_id partitionID,
|
2007-10-06 02:39:52 +04:00
|
|
|
int32 changeCounter, int32 *_cookie, char *_type)
|
2003-07-17 01:01:14 +04:00
|
|
|
{
|
2003-10-24 13:37:20 +04:00
|
|
|
if (!_cookie || !_type)
|
2003-07-17 01:01:14 +04:00
|
|
|
return B_BAD_VALUE;
|
2003-10-24 13:37:20 +04:00
|
|
|
int32 cookie;
|
|
|
|
user_memcpy(&cookie, _cookie, sizeof(cookie));
|
2003-07-17 01:01:14 +04:00
|
|
|
KDiskDeviceManager *manager = KDiskDeviceManager::Default();
|
|
|
|
// get the partition
|
|
|
|
KPartition *partition = manager->ReadLockPartition(partitionID);
|
2007-10-06 02:39:52 +04:00
|
|
|
status_t error = partition ? (status_t)B_OK : (status_t)B_ENTRY_NOT_FOUND;
|
2003-10-24 13:37:20 +04:00
|
|
|
if (!error) {
|
|
|
|
PartitionRegistrar registrar1(partition, true);
|
|
|
|
PartitionRegistrar registrar2(partition->Device(), true);
|
|
|
|
DeviceReadLocker locker(partition->Device(), true);
|
2007-10-06 02:39:52 +04:00
|
|
|
error = check_shadow_partition(partition, changeCounter)
|
|
|
|
? B_OK : B_BAD_VALUE;
|
2003-10-24 13:37:20 +04:00
|
|
|
if (!error) {
|
|
|
|
// get the disk system
|
|
|
|
KDiskSystem *diskSystem = partition->DiskSystem();
|
2007-10-06 02:39:52 +04:00
|
|
|
error = diskSystem ? (status_t)B_OK : (status_t)B_ENTRY_NOT_FOUND;
|
2003-10-24 13:37:20 +04:00
|
|
|
if (!error) {
|
|
|
|
// get the info
|
2003-10-28 03:13:11 +03:00
|
|
|
char type[B_DISK_DEVICE_TYPE_LENGTH];
|
2007-10-06 02:39:52 +04:00
|
|
|
error = diskSystem->GetNextSupportedType(partition, &cookie,
|
|
|
|
type);
|
2007-10-07 19:39:35 +04:00
|
|
|
if (!error)
|
2003-10-28 03:13:11 +03:00
|
|
|
error = ddm_strlcpy(_type, type, B_DISK_DEVICE_TYPE_LENGTH);
|
2003-10-24 13:37:20 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!error)
|
|
|
|
user_memcpy(_cookie, &cookie, sizeof(cookie));
|
|
|
|
return error;
|
2003-07-17 01:01:14 +04:00
|
|
|
}
|
|
|
|
|
2007-10-06 02:39:52 +04:00
|
|
|
|
2004-10-29 05:38:17 +04:00
|
|
|
// _user_get_partition_type_for_content_type
|
2003-07-17 01:01:14 +04:00
|
|
|
status_t
|
2004-10-29 05:38:17 +04:00
|
|
|
_user_get_partition_type_for_content_type(disk_system_id diskSystemID,
|
2007-10-06 02:39:52 +04:00
|
|
|
const char *_contentType, char *_type)
|
2003-07-17 01:01:14 +04:00
|
|
|
{
|
2003-10-24 13:37:20 +04:00
|
|
|
if (!_contentType || !_type)
|
2003-07-17 01:01:14 +04:00
|
|
|
return B_BAD_VALUE;
|
2003-10-28 03:13:11 +03:00
|
|
|
char contentType[B_DISK_DEVICE_TYPE_LENGTH];
|
2007-10-06 02:39:52 +04:00
|
|
|
status_t error = ddm_strlcpy(contentType, _contentType,
|
|
|
|
B_DISK_DEVICE_TYPE_LENGTH);
|
2003-10-25 03:09:43 +04:00
|
|
|
if (error)
|
|
|
|
return error;
|
2003-07-17 01:01:14 +04:00
|
|
|
KDiskDeviceManager *manager = KDiskDeviceManager::Default();
|
|
|
|
// get the disk system
|
|
|
|
KDiskSystem *diskSystem = manager->LoadDiskSystem(diskSystemID);
|
|
|
|
if (!diskSystem)
|
|
|
|
return false;
|
|
|
|
DiskSystemLoader loader(diskSystem, true);
|
|
|
|
// get the info
|
2003-10-28 03:13:11 +03:00
|
|
|
char type[B_DISK_DEVICE_TYPE_LENGTH];
|
2007-10-06 02:39:52 +04:00
|
|
|
if (diskSystem->GetTypeForContentType(contentType, type))
|
2003-10-28 03:13:11 +03:00
|
|
|
return ddm_strlcpy(_type, type, B_DISK_DEVICE_TYPE_LENGTH);
|
2003-07-17 01:01:14 +04:00
|
|
|
return B_ERROR;
|
|
|
|
}
|
|
|
|
|
2007-10-06 02:39:52 +04:00
|
|
|
|
2004-10-29 05:38:17 +04:00
|
|
|
// _user_prepare_disk_device_modifications
|
2003-07-15 05:27:43 +04:00
|
|
|
status_t
|
2004-10-29 05:38:17 +04:00
|
|
|
_user_prepare_disk_device_modifications(partition_id deviceID)
|
2003-07-15 05:27:43 +04:00
|
|
|
{
|
|
|
|
KDiskDeviceManager *manager = KDiskDeviceManager::Default();
|
|
|
|
// get the device
|
|
|
|
if (KDiskDevice *device = manager->RegisterDevice(deviceID, true)) {
|
|
|
|
PartitionRegistrar _(device, true);
|
|
|
|
if (DeviceWriteLocker locker = device) {
|
|
|
|
if (device->ShadowOwner() >= 0)
|
|
|
|
return B_BUSY;
|
|
|
|
// create shadow device
|
|
|
|
return device->CreateShadowDevice(get_current_team());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return B_ENTRY_NOT_FOUND;
|
|
|
|
}
|
|
|
|
|
2004-10-29 05:38:17 +04:00
|
|
|
// _user_commit_disk_device_modifications
|
2003-07-15 05:27:43 +04:00
|
|
|
status_t
|
2004-10-29 05:38:17 +04:00
|
|
|
_user_commit_disk_device_modifications(partition_id deviceID, port_id port,
|
2007-10-06 02:39:52 +04:00
|
|
|
int32 token, bool completeProgress)
|
2003-07-15 05:27:43 +04:00
|
|
|
{
|
2003-08-02 04:01:37 +04:00
|
|
|
KDiskDeviceManager *manager = KDiskDeviceManager::Default();
|
|
|
|
// get the device
|
|
|
|
if (KDiskDevice *device = manager->RegisterDevice(deviceID, true)) {
|
|
|
|
PartitionRegistrar _(device, true);
|
|
|
|
if (DeviceWriteLocker locker = device) {
|
|
|
|
if (device->ShadowOwner() != get_current_team())
|
|
|
|
return B_BAD_VALUE;
|
|
|
|
// generate the jobs
|
|
|
|
KDiskDeviceJobGenerator generator(manager->JobFactory(), device);
|
|
|
|
status_t error = generator.GenerateJobs();
|
|
|
|
if (error != B_OK)
|
|
|
|
return error;
|
|
|
|
// add the jobs to the manager
|
|
|
|
if (ManagerLocker locker2 = manager) {
|
|
|
|
error = manager->AddJobQueue(generator.JobQueue());
|
2003-08-03 22:37:21 +04:00
|
|
|
if (error == B_OK)
|
|
|
|
generator.DetachJobQueue();
|
|
|
|
else
|
2003-08-02 04:01:37 +04:00
|
|
|
return error;
|
|
|
|
} else
|
|
|
|
return B_ERROR;
|
|
|
|
// TODO: notification stuff
|
|
|
|
return device->DeleteShadowDevice();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return B_ENTRY_NOT_FOUND;
|
2003-07-15 05:27:43 +04:00
|
|
|
}
|
|
|
|
|
2007-10-06 02:39:52 +04:00
|
|
|
|
2004-10-29 05:38:17 +04:00
|
|
|
// _user_cancel_disk_device_modifications
|
2003-07-15 05:27:43 +04:00
|
|
|
status_t
|
2004-10-29 05:38:17 +04:00
|
|
|
_user_cancel_disk_device_modifications(partition_id deviceID)
|
2003-07-15 05:27:43 +04:00
|
|
|
{
|
|
|
|
KDiskDeviceManager *manager = KDiskDeviceManager::Default();
|
|
|
|
// get the device
|
|
|
|
if (KDiskDevice *device = manager->RegisterDevice(deviceID, true)) {
|
|
|
|
PartitionRegistrar _(device, true);
|
|
|
|
if (DeviceWriteLocker locker = device) {
|
|
|
|
if (device->ShadowOwner() != get_current_team())
|
|
|
|
return B_BAD_VALUE;
|
|
|
|
// delete shadow device
|
|
|
|
return device->DeleteShadowDevice();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return B_ENTRY_NOT_FOUND;
|
|
|
|
}
|
|
|
|
|
2007-10-06 02:39:52 +04:00
|
|
|
|
2004-10-29 05:38:17 +04:00
|
|
|
// _user_is_disk_device_modified
|
2003-07-15 05:27:43 +04:00
|
|
|
bool
|
2004-10-29 05:38:17 +04:00
|
|
|
_user_is_disk_device_modified(partition_id deviceID)
|
2003-07-15 05:27:43 +04:00
|
|
|
{
|
2003-07-25 02:58:06 +04:00
|
|
|
KDiskDeviceManager *manager = KDiskDeviceManager::Default();
|
|
|
|
// get the device
|
|
|
|
if (KDiskDevice *device = manager->RegisterDevice(deviceID, true)) {
|
|
|
|
PartitionRegistrar _(device, true);
|
|
|
|
if (DeviceReadLocker locker = device) {
|
|
|
|
// check whether there's a shadow device and whether it's changed
|
|
|
|
return (device->ShadowOwner() == get_current_team()
|
2007-10-06 02:39:52 +04:00
|
|
|
&& device->ShadowPartition()
|
|
|
|
&& device->ShadowPartition()->ChangeFlags() != 0);
|
2003-07-25 02:58:06 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return B_ENTRY_NOT_FOUND;
|
2003-07-15 05:27:43 +04:00
|
|
|
}
|
|
|
|
|
2007-10-06 02:39:52 +04:00
|
|
|
|
2004-10-29 05:38:17 +04:00
|
|
|
// _user_defragment_partition
|
2003-07-21 02:39:37 +04:00
|
|
|
status_t
|
2004-10-29 05:38:17 +04:00
|
|
|
_user_defragment_partition(partition_id partitionID, int32 changeCounter)
|
2003-07-21 02:39:37 +04:00
|
|
|
{
|
2003-07-25 02:58:06 +04:00
|
|
|
KDiskDeviceManager *manager = KDiskDeviceManager::Default();
|
|
|
|
// get the partition
|
|
|
|
KPartition *partition = manager->WriteLockPartition(partitionID);
|
|
|
|
if (!partition)
|
|
|
|
return B_ENTRY_NOT_FOUND;
|
|
|
|
PartitionRegistrar registrar1(partition, true);
|
|
|
|
PartitionRegistrar registrar2(partition->Device(), true);
|
|
|
|
DeviceWriteLocker locker(partition->Device(), true);
|
|
|
|
// check whether the disk system supports defragmenting
|
|
|
|
status_t error = validate_defragment_partition(partition, changeCounter);
|
|
|
|
if (error != B_OK)
|
|
|
|
return error;
|
|
|
|
// set the defragmenting flag
|
|
|
|
partition->Changed(B_PARTITION_CHANGED_DEFRAGMENTATION);
|
|
|
|
return B_OK;
|
2003-07-21 02:39:37 +04:00
|
|
|
}
|
|
|
|
|
2007-10-06 02:39:52 +04:00
|
|
|
|
2004-10-29 05:38:17 +04:00
|
|
|
// _user_repair_partition
|
2003-07-21 02:39:37 +04:00
|
|
|
status_t
|
2004-10-29 05:38:17 +04:00
|
|
|
_user_repair_partition(partition_id partitionID, int32 changeCounter,
|
2007-10-06 02:39:52 +04:00
|
|
|
bool checkOnly)
|
2003-07-21 02:39:37 +04:00
|
|
|
{
|
2003-07-25 02:58:06 +04:00
|
|
|
KDiskDeviceManager *manager = KDiskDeviceManager::Default();
|
|
|
|
// get the partition
|
|
|
|
KPartition *partition = manager->WriteLockPartition(partitionID);
|
|
|
|
if (!partition)
|
|
|
|
return B_ENTRY_NOT_FOUND;
|
|
|
|
PartitionRegistrar registrar1(partition, true);
|
|
|
|
PartitionRegistrar registrar2(partition->Device(), true);
|
|
|
|
DeviceWriteLocker locker(partition->Device(), true);
|
|
|
|
// check whether the disk system supports defragmenting
|
|
|
|
status_t error = validate_repair_partition(partition, changeCounter,
|
2007-10-06 02:39:52 +04:00
|
|
|
checkOnly);
|
2003-07-25 02:58:06 +04:00
|
|
|
if (error != B_OK)
|
|
|
|
return error;
|
|
|
|
// set the respective flag
|
|
|
|
if (checkOnly)
|
|
|
|
partition->Changed(B_PARTITION_CHANGED_CHECK);
|
|
|
|
else
|
|
|
|
partition->Changed(B_PARTITION_CHANGED_REPAIR);
|
|
|
|
return B_OK;
|
2003-07-21 02:39:37 +04:00
|
|
|
}
|
|
|
|
|
2007-10-06 02:39:52 +04:00
|
|
|
|
2004-10-29 05:38:17 +04:00
|
|
|
// _user_resize_partition
|
2003-07-21 02:39:37 +04:00
|
|
|
status_t
|
2004-10-29 05:38:17 +04:00
|
|
|
_user_resize_partition(partition_id partitionID, int32 changeCounter,
|
2007-10-06 02:39:52 +04:00
|
|
|
off_t size)
|
2003-07-21 02:39:37 +04:00
|
|
|
{
|
2003-07-22 04:11:03 +04:00
|
|
|
KDiskDeviceManager *manager = KDiskDeviceManager::Default();
|
|
|
|
// get the partition
|
|
|
|
KPartition *partition = manager->WriteLockPartition(partitionID);
|
|
|
|
if (!partition)
|
|
|
|
return B_ENTRY_NOT_FOUND;
|
|
|
|
PartitionRegistrar registrar1(partition, true);
|
|
|
|
PartitionRegistrar registrar2(partition->Device(), true);
|
|
|
|
DeviceWriteLocker locker(partition->Device(), true);
|
|
|
|
// check the size
|
|
|
|
if (size == partition->Size())
|
|
|
|
return B_OK;
|
|
|
|
off_t proposedSize = size;
|
2003-09-30 01:40:36 +04:00
|
|
|
off_t contentSize = 0;
|
2003-07-22 04:11:03 +04:00
|
|
|
status_t error = validate_resize_partition(partition, changeCounter,
|
2007-10-06 02:39:52 +04:00
|
|
|
&proposedSize, &contentSize);
|
2003-07-22 04:11:03 +04:00
|
|
|
if (error != B_OK)
|
|
|
|
return error;
|
|
|
|
if (proposedSize != size)
|
|
|
|
return B_BAD_VALUE;
|
|
|
|
// new size is fine -- resize the thing
|
|
|
|
partition->SetSize(size);
|
|
|
|
partition->Changed(B_PARTITION_CHANGED_SIZE);
|
2003-07-25 02:58:06 +04:00
|
|
|
// implicit partitioning system changes
|
|
|
|
error = partition->Parent()->DiskSystem()->ShadowPartitionChanged(
|
2007-10-07 19:39:35 +04:00
|
|
|
partition->Parent(), partition, B_PARTITION_RESIZE_CHILD);
|
2003-07-25 02:58:06 +04:00
|
|
|
if (error != B_OK)
|
|
|
|
return error;
|
2003-09-22 01:26:12 +04:00
|
|
|
// implicit content disk system changes
|
|
|
|
if (partition->DiskSystem()) {
|
2003-07-25 02:58:06 +04:00
|
|
|
error = partition->DiskSystem()->ShadowPartitionChanged(
|
2007-10-07 19:39:35 +04:00
|
|
|
partition, NULL, B_PARTITION_RESIZE);
|
2003-07-22 04:11:03 +04:00
|
|
|
}
|
2003-07-25 02:58:06 +04:00
|
|
|
return error;
|
2003-07-21 02:39:37 +04:00
|
|
|
}
|
|
|
|
|
2007-10-06 02:39:52 +04:00
|
|
|
|
2004-10-29 05:38:17 +04:00
|
|
|
// _user_move_partition
|
2003-07-21 02:39:37 +04:00
|
|
|
status_t
|
2004-10-29 05:38:17 +04:00
|
|
|
_user_move_partition(partition_id partitionID, int32 changeCounter,
|
2007-10-06 02:39:52 +04:00
|
|
|
off_t newOffset)
|
2003-07-21 02:39:37 +04:00
|
|
|
{
|
2003-07-25 02:58:06 +04:00
|
|
|
KDiskDeviceManager *manager = KDiskDeviceManager::Default();
|
|
|
|
// get the partition
|
|
|
|
KPartition *partition = manager->WriteLockPartition(partitionID);
|
|
|
|
if (!partition)
|
|
|
|
return B_ENTRY_NOT_FOUND;
|
|
|
|
PartitionRegistrar registrar1(partition, true);
|
|
|
|
PartitionRegistrar registrar2(partition->Device(), true);
|
|
|
|
DeviceWriteLocker locker(partition->Device(), true);
|
|
|
|
// check the new offset
|
|
|
|
if (newOffset == partition->Offset())
|
|
|
|
return B_OK;
|
|
|
|
off_t proposedOffset = newOffset;
|
|
|
|
status_t error = validate_move_partition(partition, changeCounter,
|
2007-10-06 02:39:52 +04:00
|
|
|
&proposedOffset, true);
|
2003-07-25 02:58:06 +04:00
|
|
|
if (error != B_OK)
|
|
|
|
return error;
|
|
|
|
if (proposedOffset != newOffset)
|
|
|
|
return B_BAD_VALUE;
|
|
|
|
// new offset is fine -- move the thing
|
|
|
|
off_t moveBy = newOffset - partition->Offset();
|
|
|
|
move_descendants(partition, moveBy);
|
|
|
|
partition->Changed(B_PARTITION_CHANGED_OFFSET);
|
|
|
|
// implicit partitioning system changes
|
|
|
|
error = partition->Parent()->DiskSystem()->ShadowPartitionChanged(
|
2007-10-07 19:39:35 +04:00
|
|
|
partition->Parent(), partition, B_PARTITION_MOVE_CHILD);
|
2003-07-25 02:58:06 +04:00
|
|
|
if (error != B_OK)
|
|
|
|
return error;
|
|
|
|
// implicit descendants' content disk system changes
|
|
|
|
return move_descendants_contents(partition);
|
2003-07-21 02:39:37 +04:00
|
|
|
}
|
|
|
|
|
2007-10-06 02:39:52 +04:00
|
|
|
|
2004-10-29 05:38:17 +04:00
|
|
|
// _user_set_partition_name
|
2003-07-21 02:39:37 +04:00
|
|
|
status_t
|
2004-10-29 05:38:17 +04:00
|
|
|
_user_set_partition_name(partition_id partitionID, int32 changeCounter,
|
2007-10-06 02:39:52 +04:00
|
|
|
const char *_name)
|
2003-07-21 02:39:37 +04:00
|
|
|
{
|
2003-10-24 13:37:20 +04:00
|
|
|
if (!_name)
|
2003-07-25 02:58:06 +04:00
|
|
|
return B_BAD_VALUE;
|
2003-10-28 03:13:11 +03:00
|
|
|
char name[B_DISK_DEVICE_NAME_LENGTH];
|
|
|
|
status_t error = ddm_strlcpy(name, _name, B_DISK_DEVICE_NAME_LENGTH);
|
2003-10-25 03:09:43 +04:00
|
|
|
if (error)
|
|
|
|
return error;
|
2003-07-25 02:58:06 +04:00
|
|
|
KDiskDeviceManager *manager = KDiskDeviceManager::Default();
|
|
|
|
// get the partition
|
|
|
|
KPartition *partition = manager->WriteLockPartition(partitionID);
|
|
|
|
if (!partition)
|
|
|
|
return B_ENTRY_NOT_FOUND;
|
|
|
|
PartitionRegistrar registrar1(partition, true);
|
|
|
|
PartitionRegistrar registrar2(partition->Device(), true);
|
|
|
|
DeviceWriteLocker locker(partition->Device(), true);
|
|
|
|
// check name
|
2003-10-28 03:13:11 +03:00
|
|
|
char proposedName[B_DISK_DEVICE_NAME_LENGTH];
|
2003-07-25 02:58:06 +04:00
|
|
|
strcpy(proposedName, name);
|
2007-10-06 02:39:52 +04:00
|
|
|
error = validate_set_partition_name(partition, changeCounter, proposedName);
|
2003-07-25 02:58:06 +04:00
|
|
|
if (error != B_OK)
|
|
|
|
return error;
|
|
|
|
if (strcmp(name, proposedName))
|
|
|
|
return B_BAD_VALUE;
|
|
|
|
// set name
|
|
|
|
error = partition->SetName(name);
|
|
|
|
if (error != B_OK)
|
|
|
|
return error;
|
|
|
|
partition->Changed(B_PARTITION_CHANGED_NAME);
|
|
|
|
// implicit partitioning system changes
|
|
|
|
return partition->Parent()->DiskSystem()->ShadowPartitionChanged(
|
2007-10-07 19:39:35 +04:00
|
|
|
partition->Parent(), partition, B_PARTITION_SET_NAME);
|
2003-07-21 02:39:37 +04:00
|
|
|
}
|
|
|
|
|
2007-10-06 02:39:52 +04:00
|
|
|
|
2004-10-29 05:38:17 +04:00
|
|
|
// _user_set_partition_content_name
|
2003-07-21 02:39:37 +04:00
|
|
|
status_t
|
2004-10-29 05:38:17 +04:00
|
|
|
_user_set_partition_content_name(partition_id partitionID, int32 changeCounter,
|
2007-10-06 02:39:52 +04:00
|
|
|
const char *_name)
|
2003-07-21 02:39:37 +04:00
|
|
|
{
|
2003-10-24 13:37:20 +04:00
|
|
|
if (!_name)
|
2003-07-25 02:58:06 +04:00
|
|
|
return B_BAD_VALUE;
|
2003-10-28 03:13:11 +03:00
|
|
|
char name[B_DISK_DEVICE_NAME_LENGTH];
|
|
|
|
status_t error = ddm_strlcpy(name, _name, B_DISK_DEVICE_NAME_LENGTH);
|
2003-10-25 03:09:43 +04:00
|
|
|
if (error)
|
|
|
|
return error;
|
2003-07-25 02:58:06 +04:00
|
|
|
KDiskDeviceManager *manager = KDiskDeviceManager::Default();
|
|
|
|
// get the partition
|
|
|
|
KPartition *partition = manager->WriteLockPartition(partitionID);
|
|
|
|
if (!partition)
|
|
|
|
return B_ENTRY_NOT_FOUND;
|
|
|
|
PartitionRegistrar registrar1(partition, true);
|
|
|
|
PartitionRegistrar registrar2(partition->Device(), true);
|
|
|
|
DeviceWriteLocker locker(partition->Device(), true);
|
|
|
|
// check name
|
2003-10-28 03:13:11 +03:00
|
|
|
char proposedName[B_DISK_DEVICE_NAME_LENGTH];
|
2003-07-25 02:58:06 +04:00
|
|
|
strcpy(proposedName, name);
|
2003-10-25 03:09:43 +04:00
|
|
|
error = validate_set_partition_content_name(partition,
|
2003-07-25 02:58:06 +04:00
|
|
|
changeCounter, proposedName);
|
|
|
|
if (error != B_OK)
|
|
|
|
return error;
|
|
|
|
if (strcmp(name, proposedName))
|
|
|
|
return B_BAD_VALUE;
|
|
|
|
// set name
|
|
|
|
error = partition->SetContentName(name);
|
|
|
|
if (error != B_OK)
|
|
|
|
return error;
|
|
|
|
partition->Changed(B_PARTITION_CHANGED_CONTENT_NAME);
|
|
|
|
// implicit content disk system changes
|
|
|
|
return partition->DiskSystem()->ShadowPartitionChanged(
|
2007-10-07 19:39:35 +04:00
|
|
|
partition, NULL, B_PARTITION_SET_CONTENT_NAME);
|
2003-07-21 02:39:37 +04:00
|
|
|
}
|
|
|
|
|
2007-10-06 02:39:52 +04:00
|
|
|
|
2004-10-29 05:38:17 +04:00
|
|
|
// _user_set_partition_type
|
2003-07-21 02:39:37 +04:00
|
|
|
status_t
|
2004-10-29 05:38:17 +04:00
|
|
|
_user_set_partition_type(partition_id partitionID, int32 changeCounter,
|
2007-10-06 02:39:52 +04:00
|
|
|
const char *_type)
|
2003-07-21 02:39:37 +04:00
|
|
|
{
|
2003-10-24 13:37:20 +04:00
|
|
|
if (!_type)
|
2003-07-25 02:58:06 +04:00
|
|
|
return B_BAD_VALUE;
|
2003-10-28 03:13:11 +03:00
|
|
|
char type[B_DISK_DEVICE_TYPE_LENGTH];
|
|
|
|
status_t error = ddm_strlcpy(type, _type, B_DISK_DEVICE_TYPE_LENGTH);
|
2003-10-25 03:09:43 +04:00
|
|
|
if (error)
|
|
|
|
return error;
|
2003-07-25 02:58:06 +04:00
|
|
|
KDiskDeviceManager *manager = KDiskDeviceManager::Default();
|
|
|
|
// get the partition
|
|
|
|
KPartition *partition = manager->WriteLockPartition(partitionID);
|
|
|
|
if (!partition)
|
|
|
|
return B_ENTRY_NOT_FOUND;
|
|
|
|
PartitionRegistrar registrar1(partition, true);
|
|
|
|
PartitionRegistrar registrar2(partition->Device(), true);
|
|
|
|
DeviceWriteLocker locker(partition->Device(), true);
|
|
|
|
// check type
|
2007-10-06 02:39:52 +04:00
|
|
|
error = validate_set_partition_type(partition, changeCounter, type);
|
2003-07-25 02:58:06 +04:00
|
|
|
if (error != B_OK)
|
|
|
|
return error;
|
|
|
|
// set type
|
|
|
|
error = partition->SetType(type);
|
|
|
|
if (error != B_OK)
|
|
|
|
return error;
|
|
|
|
partition->Changed(B_PARTITION_CHANGED_TYPE);
|
|
|
|
// implicit partitioning system changes
|
|
|
|
return partition->Parent()->DiskSystem()->ShadowPartitionChanged(
|
2007-10-07 19:39:35 +04:00
|
|
|
partition->Parent(), partition, B_PARTITION_SET_TYPE);
|
2003-07-21 02:39:37 +04:00
|
|
|
}
|
|
|
|
|
2007-10-06 02:39:52 +04:00
|
|
|
|
2004-10-29 05:38:17 +04:00
|
|
|
// _user_set_partition_parameters
|
2003-07-21 02:39:37 +04:00
|
|
|
status_t
|
2004-10-29 05:38:17 +04:00
|
|
|
_user_set_partition_parameters(partition_id partitionID, int32 changeCounter,
|
2007-10-06 02:39:52 +04:00
|
|
|
const char *_parameters, size_t parametersSize)
|
2003-07-21 02:39:37 +04:00
|
|
|
{
|
2003-10-27 11:10:52 +03:00
|
|
|
if (!_parameters || parametersSize > B_DISK_DEVICE_MAX_PARAMETER_SIZE)
|
2003-07-25 02:58:06 +04:00
|
|
|
return B_BAD_VALUE;
|
2003-10-24 13:37:20 +04:00
|
|
|
char *parameters = NULL;
|
|
|
|
if (_parameters) {
|
2003-10-25 12:35:27 +04:00
|
|
|
parameters = static_cast<char*>(malloc(parametersSize));
|
2003-10-24 13:37:20 +04:00
|
|
|
if (parameters)
|
2003-10-25 12:35:27 +04:00
|
|
|
user_memcpy(parameters, _parameters, parametersSize);
|
2003-10-24 13:37:20 +04:00
|
|
|
else
|
|
|
|
return B_NO_MEMORY;
|
|
|
|
}
|
2003-07-25 02:58:06 +04:00
|
|
|
KDiskDeviceManager *manager = KDiskDeviceManager::Default();
|
|
|
|
// get the partition
|
|
|
|
KPartition *partition = manager->WriteLockPartition(partitionID);
|
2007-10-06 02:39:52 +04:00
|
|
|
status_t error = partition ? (status_t)B_OK : (status_t)B_ENTRY_NOT_FOUND;
|
2003-10-24 13:37:20 +04:00
|
|
|
if (!error) {
|
|
|
|
PartitionRegistrar registrar1(partition, true);
|
|
|
|
PartitionRegistrar registrar2(partition->Device(), true);
|
|
|
|
DeviceWriteLocker locker(partition->Device(), true);
|
|
|
|
// check parameters
|
|
|
|
error = validate_set_partition_parameters(partition,
|
|
|
|
changeCounter, parameters);
|
|
|
|
if (!error) {
|
|
|
|
// set type
|
|
|
|
error = partition->SetParameters(parameters);
|
|
|
|
if (!error) {
|
|
|
|
partition->Changed(B_PARTITION_CHANGED_PARAMETERS);
|
|
|
|
// implicit partitioning system changes
|
2007-10-06 02:39:52 +04:00
|
|
|
error = partition->Parent()->DiskSystem()
|
2007-10-07 19:39:35 +04:00
|
|
|
->ShadowPartitionChanged(partition->Parent(), partition,
|
2007-10-06 02:39:52 +04:00
|
|
|
B_PARTITION_SET_PARAMETERS);
|
2003-10-24 13:37:20 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
free(parameters);
|
|
|
|
return error;
|
2003-07-21 02:39:37 +04:00
|
|
|
}
|
|
|
|
|
2007-10-06 02:39:52 +04:00
|
|
|
|
2004-10-29 05:38:17 +04:00
|
|
|
// _user_set_partition_content_parameters
|
2003-07-21 02:39:37 +04:00
|
|
|
status_t
|
2004-10-29 05:38:17 +04:00
|
|
|
_user_set_partition_content_parameters(partition_id partitionID,
|
2007-10-06 02:39:52 +04:00
|
|
|
int32 changeCounter, const char *_parameters, size_t parametersSize)
|
2003-07-21 02:39:37 +04:00
|
|
|
{
|
2003-10-27 11:10:52 +03:00
|
|
|
if (!_parameters || parametersSize > B_DISK_DEVICE_MAX_PARAMETER_SIZE)
|
2003-10-24 13:37:20 +04:00
|
|
|
return B_BAD_VALUE;
|
|
|
|
char *parameters = NULL;
|
|
|
|
if (_parameters) {
|
2003-10-25 12:35:27 +04:00
|
|
|
parameters = static_cast<char*>(malloc(parametersSize));
|
2003-10-24 13:37:20 +04:00
|
|
|
if (parameters)
|
2003-10-25 12:35:27 +04:00
|
|
|
user_memcpy(parameters, _parameters, parametersSize);
|
2003-10-24 13:37:20 +04:00
|
|
|
else
|
|
|
|
return B_NO_MEMORY;
|
|
|
|
}
|
2003-07-25 02:58:06 +04:00
|
|
|
KDiskDeviceManager *manager = KDiskDeviceManager::Default();
|
|
|
|
// get the partition
|
|
|
|
KPartition *partition = manager->WriteLockPartition(partitionID);
|
2007-10-06 02:39:52 +04:00
|
|
|
status_t error = partition ? (status_t)B_OK : (status_t)B_ENTRY_NOT_FOUND;
|
2003-10-24 13:37:20 +04:00
|
|
|
if (!error) {
|
|
|
|
PartitionRegistrar registrar1(partition, true);
|
|
|
|
PartitionRegistrar registrar2(partition->Device(), true);
|
|
|
|
DeviceWriteLocker locker(partition->Device(), true);
|
|
|
|
// check parameters
|
|
|
|
error = validate_set_partition_content_parameters(partition,
|
|
|
|
changeCounter, parameters);
|
|
|
|
if (!error) {
|
|
|
|
// set name
|
|
|
|
error = partition->SetContentParameters(parameters);
|
|
|
|
if (!error) {
|
|
|
|
partition->Changed(B_PARTITION_CHANGED_CONTENT_PARAMETERS);
|
|
|
|
// implicit content disk system changes
|
|
|
|
error = partition->DiskSystem()->ShadowPartitionChanged(
|
2007-10-07 19:39:35 +04:00
|
|
|
partition, NULL, B_PARTITION_SET_CONTENT_PARAMETERS);
|
2003-10-24 13:37:20 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
free(partition);
|
|
|
|
return error;
|
2003-07-21 02:39:37 +04:00
|
|
|
}
|
|
|
|
|
2007-10-06 02:39:52 +04:00
|
|
|
|
2004-10-29 05:38:17 +04:00
|
|
|
// _user_initialize_partition
|
2003-07-21 02:39:37 +04:00
|
|
|
status_t
|
2004-10-29 05:38:17 +04:00
|
|
|
_user_initialize_partition(partition_id partitionID, int32 changeCounter,
|
2007-10-06 02:39:52 +04:00
|
|
|
const char *_diskSystemName, const char *_name, const char *_parameters,
|
|
|
|
size_t parametersSize)
|
2003-07-21 02:39:37 +04:00
|
|
|
{
|
2007-10-06 03:25:58 +04:00
|
|
|
if (!_diskSystemName || parametersSize > B_DISK_DEVICE_MAX_PARAMETER_SIZE)
|
2003-07-25 02:58:06 +04:00
|
|
|
return B_BAD_VALUE;
|
2007-10-06 03:25:58 +04:00
|
|
|
|
|
|
|
// copy disk system name
|
2003-10-28 03:13:11 +03:00
|
|
|
char diskSystemName[B_DISK_SYSTEM_NAME_LENGTH];
|
2007-10-06 02:39:52 +04:00
|
|
|
status_t error = ddm_strlcpy(diskSystemName, _diskSystemName,
|
|
|
|
B_DISK_SYSTEM_NAME_LENGTH);
|
2007-10-06 03:25:58 +04:00
|
|
|
|
|
|
|
// copy name
|
|
|
|
char name[B_DISK_DEVICE_NAME_LENGTH];
|
|
|
|
if (!error && _name)
|
2003-10-28 03:13:11 +03:00
|
|
|
error = ddm_strlcpy(name, _name, B_DISK_DEVICE_NAME_LENGTH);
|
2007-10-06 03:25:58 +04:00
|
|
|
|
2003-10-25 03:09:43 +04:00
|
|
|
if (error)
|
|
|
|
return error;
|
2007-10-06 03:25:58 +04:00
|
|
|
|
|
|
|
// copy parameters
|
|
|
|
MemoryDeleter parameterDeleter;
|
|
|
|
char *parameters = NULL;
|
2003-10-24 13:37:20 +04:00
|
|
|
if (_parameters) {
|
2003-10-25 12:35:27 +04:00
|
|
|
parameters = static_cast<char*>(malloc(parametersSize));
|
2007-10-06 03:25:58 +04:00
|
|
|
if (!parameters)
|
2003-10-24 13:37:20 +04:00
|
|
|
return B_NO_MEMORY;
|
2007-10-06 03:25:58 +04:00
|
|
|
parameterDeleter.SetTo(parameters);
|
|
|
|
|
|
|
|
if (user_memcpy(parameters, _parameters, parametersSize) != B_OK)
|
|
|
|
return B_BAD_ADDRESS;
|
2003-10-24 13:37:20 +04:00
|
|
|
}
|
2007-10-06 03:25:58 +04:00
|
|
|
|
2003-07-25 02:58:06 +04:00
|
|
|
// get the partition
|
2007-10-06 03:25:58 +04:00
|
|
|
KDiskDeviceManager *manager = KDiskDeviceManager::Default();
|
2003-07-25 02:58:06 +04:00
|
|
|
KPartition *partition = manager->WriteLockPartition(partitionID);
|
2007-10-06 03:25:58 +04:00
|
|
|
if (!partition)
|
|
|
|
return B_ENTRY_NOT_FOUND;
|
|
|
|
|
|
|
|
PartitionRegistrar registrar1(partition, true);
|
|
|
|
PartitionRegistrar registrar2(partition->Device(), true);
|
|
|
|
DeviceWriteLocker locker(partition->Device(), true);
|
|
|
|
|
|
|
|
// get the disk system
|
|
|
|
KDiskSystem *diskSystem = manager->LoadDiskSystem(diskSystemName);
|
|
|
|
if (!diskSystem)
|
|
|
|
return B_ENTRY_NOT_FOUND;
|
|
|
|
DiskSystemLoader loader(diskSystem, true);
|
|
|
|
|
|
|
|
// check parameters
|
|
|
|
char proposedName[B_DISK_DEVICE_NAME_LENGTH];
|
|
|
|
if (_name)
|
|
|
|
strcpy(proposedName, name);
|
|
|
|
|
|
|
|
error = validate_initialize_partition(partition, changeCounter,
|
|
|
|
diskSystemName, _name ? proposedName : NULL, parameters);
|
|
|
|
if (error != B_OK)
|
|
|
|
return error;
|
|
|
|
if (_name && strcmp(name, proposedName) != 0)
|
|
|
|
return B_BAD_VALUE;
|
|
|
|
|
|
|
|
// unitialize the partition's contents and set the new
|
|
|
|
// parameters
|
|
|
|
if ((error = partition->UninitializeContents(true)) != B_OK)
|
|
|
|
return error;
|
|
|
|
|
|
|
|
partition->SetDiskSystem(diskSystem);
|
|
|
|
|
|
|
|
if ((error = partition->SetContentName(_name ? name : NULL)) != B_OK)
|
|
|
|
return error;
|
|
|
|
partition->Changed(B_PARTITION_CHANGED_CONTENT_NAME);
|
|
|
|
|
|
|
|
if ((error = partition->SetContentParameters(parameters)) != B_OK)
|
|
|
|
return error;
|
|
|
|
partition->Changed(B_PARTITION_CHANGED_CONTENT_PARAMETERS);
|
|
|
|
|
|
|
|
partition->Changed(B_PARTITION_CHANGED_INITIALIZATION);
|
|
|
|
|
|
|
|
// implicit content disk system changes
|
|
|
|
return partition->DiskSystem()->ShadowPartitionChanged(
|
2007-10-07 19:39:35 +04:00
|
|
|
partition, NULL, B_PARTITION_INITIALIZE);
|
2003-07-21 02:39:37 +04:00
|
|
|
}
|
|
|
|
|
2007-10-06 02:39:52 +04:00
|
|
|
|
2004-10-29 05:38:17 +04:00
|
|
|
// _user_uninitialize_partition
|
2003-09-21 23:13:54 +04:00
|
|
|
status_t
|
2004-10-29 05:38:17 +04:00
|
|
|
_user_uninitialize_partition(partition_id partitionID, int32 changeCounter)
|
2003-09-21 23:13:54 +04:00
|
|
|
{
|
|
|
|
KDiskDeviceManager *manager = KDiskDeviceManager::Default();
|
|
|
|
// get the partition
|
|
|
|
KPartition *partition = manager->WriteLockPartition(partitionID);
|
|
|
|
if (!partition)
|
|
|
|
return B_ENTRY_NOT_FOUND;
|
|
|
|
PartitionRegistrar registrar1(partition, true);
|
|
|
|
PartitionRegistrar registrar2(partition->Device(), true);
|
|
|
|
DeviceWriteLocker locker(partition->Device(), true);
|
|
|
|
// unitialize the partition's contents and set the new parameters
|
2003-09-28 23:31:49 +04:00
|
|
|
return partition->UninitializeContents(true);
|
2003-09-21 23:13:54 +04:00
|
|
|
}
|
|
|
|
|
2007-10-06 02:39:52 +04:00
|
|
|
|
2004-10-29 05:38:17 +04:00
|
|
|
// _user_create_child_partition
|
2003-07-21 02:39:37 +04:00
|
|
|
status_t
|
2004-10-29 05:38:17 +04:00
|
|
|
_user_create_child_partition(partition_id partitionID, int32 changeCounter,
|
2007-10-06 02:39:52 +04:00
|
|
|
off_t offset, off_t size, const char *_type, const char *_parameters,
|
|
|
|
size_t parametersSize, partition_id *_childID)
|
2003-07-21 02:39:37 +04:00
|
|
|
{
|
2003-10-27 11:10:52 +03:00
|
|
|
if (!_type || parametersSize > B_DISK_DEVICE_MAX_PARAMETER_SIZE)
|
2003-07-25 02:58:06 +04:00
|
|
|
return B_BAD_VALUE;
|
2003-10-28 03:13:11 +03:00
|
|
|
char type[B_DISK_DEVICE_TYPE_LENGTH];
|
2003-10-24 13:37:20 +04:00
|
|
|
char *parameters = NULL;
|
2003-10-28 03:13:11 +03:00
|
|
|
status_t error = ddm_strlcpy(type, _type, B_DISK_DEVICE_TYPE_LENGTH);
|
2003-10-25 03:09:43 +04:00
|
|
|
if (error)
|
|
|
|
return error;
|
2003-10-24 13:37:20 +04:00
|
|
|
if (_parameters) {
|
2003-10-25 12:35:27 +04:00
|
|
|
parameters = static_cast<char*>(malloc(parametersSize));
|
2003-10-24 13:37:20 +04:00
|
|
|
if (parameters)
|
2003-10-25 12:35:27 +04:00
|
|
|
user_memcpy(parameters, _parameters, parametersSize);
|
2003-10-24 13:37:20 +04:00
|
|
|
else
|
|
|
|
return B_NO_MEMORY;
|
|
|
|
}
|
2003-07-25 02:58:06 +04:00
|
|
|
KDiskDeviceManager *manager = KDiskDeviceManager::Default();
|
|
|
|
// get the partition
|
|
|
|
KPartition *partition = manager->WriteLockPartition(partitionID);
|
2007-10-06 02:39:52 +04:00
|
|
|
error = partition ? (status_t)B_OK : (status_t)B_ENTRY_NOT_FOUND;
|
2003-10-24 13:37:20 +04:00
|
|
|
if (!error) {
|
|
|
|
PartitionRegistrar registrar1(partition, true);
|
|
|
|
PartitionRegistrar registrar2(partition->Device(), true);
|
|
|
|
DeviceWriteLocker locker(partition->Device(), true);
|
|
|
|
// check the parameters
|
|
|
|
off_t proposedOffset = offset;
|
|
|
|
off_t proposedSize = size;
|
|
|
|
int32 index = 0;
|
|
|
|
error = validate_create_child_partition(partition, changeCounter,
|
|
|
|
&proposedOffset, &proposedSize, type, parameters, &index);
|
|
|
|
if (!error) {
|
|
|
|
error = (proposedOffset == offset && proposedSize == size)
|
|
|
|
? B_OK : B_BAD_VALUE;
|
|
|
|
if (!error) {
|
|
|
|
// create the child
|
|
|
|
KPartition *child = NULL;
|
|
|
|
error = partition->CreateChild(-1, index, &child);
|
|
|
|
if (!error) {
|
|
|
|
partition->Changed(B_PARTITION_CHANGED_CHILDREN);
|
|
|
|
if (_childID) {
|
|
|
|
partition_id childID = child->ID();
|
|
|
|
user_memcpy(_childID, &childID, sizeof(childID));
|
|
|
|
}
|
|
|
|
// set the parameters
|
|
|
|
child->SetOffset(offset);
|
2007-10-07 19:39:35 +04:00
|
|
|
child->SetSize(size);
|
2003-10-24 13:37:20 +04:00
|
|
|
error = child->SetType(type);
|
|
|
|
}
|
|
|
|
if (!error) {
|
2007-10-07 19:39:35 +04:00
|
|
|
error = child->SetParameters(parameters);
|
2003-10-24 13:37:20 +04:00
|
|
|
}
|
|
|
|
if (!error) {
|
|
|
|
// implicit partitioning system changes
|
|
|
|
error = partition->DiskSystem()->ShadowPartitionChanged(
|
2007-10-07 19:39:35 +04:00
|
|
|
partition, child, B_PARTITION_CREATE_CHILD);
|
2003-10-24 13:37:20 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
free(parameters);
|
|
|
|
return error;
|
2003-07-21 02:39:37 +04:00
|
|
|
}
|
|
|
|
|
2007-10-06 02:39:52 +04:00
|
|
|
|
2004-10-29 05:38:17 +04:00
|
|
|
// _user_delete_partition
|
2003-07-21 02:39:37 +04:00
|
|
|
status_t
|
2004-10-29 05:38:17 +04:00
|
|
|
_user_delete_partition(partition_id partitionID, int32 changeCounter)
|
2003-07-21 02:39:37 +04:00
|
|
|
{
|
2003-07-25 02:58:06 +04:00
|
|
|
KDiskDeviceManager *manager = KDiskDeviceManager::Default();
|
|
|
|
// get the partition
|
|
|
|
KPartition *partition = manager->WriteLockPartition(partitionID);
|
|
|
|
if (!partition)
|
|
|
|
return B_ENTRY_NOT_FOUND;
|
|
|
|
PartitionRegistrar registrar1(partition, true);
|
|
|
|
PartitionRegistrar registrar2(partition->Device(), true);
|
|
|
|
DeviceWriteLocker locker(partition->Device(), true);
|
|
|
|
// check whether delete the child is OK
|
|
|
|
status_t error = validate_delete_child_partition(partition, changeCounter);
|
|
|
|
if (error != B_OK)
|
|
|
|
return error;
|
|
|
|
// delete the child
|
|
|
|
KPartition *parent = partition->Parent();
|
|
|
|
if (!parent->RemoveChild(partition))
|
|
|
|
return B_ERROR;
|
|
|
|
parent->Changed(B_PARTITION_CHANGED_CHILDREN);
|
|
|
|
return B_OK;
|
2003-07-21 02:39:37 +04:00
|
|
|
}
|
|
|
|
|
2007-10-06 02:39:52 +04:00
|
|
|
|
2004-10-29 05:38:17 +04:00
|
|
|
// _user_get_next_disk_device_job_info
|
2003-07-30 21:48:08 +04:00
|
|
|
status_t
|
2004-10-29 05:38:17 +04:00
|
|
|
_user_get_next_disk_device_job_info(int32 *_cookie,
|
2007-10-06 02:39:52 +04:00
|
|
|
user_disk_device_job_info *_info)
|
2003-07-30 21:48:08 +04:00
|
|
|
{
|
2003-10-24 13:37:20 +04:00
|
|
|
if (!_cookie || !_info)
|
2003-07-30 21:48:08 +04:00
|
|
|
return B_BAD_VALUE;
|
2003-10-24 13:37:20 +04:00
|
|
|
int32 cookie;
|
|
|
|
user_disk_device_job_info info;
|
|
|
|
user_memcpy(&cookie, _cookie, sizeof(cookie));
|
2003-07-30 21:48:08 +04:00
|
|
|
KDiskDeviceManager *manager = KDiskDeviceManager::Default();
|
2003-10-24 13:37:20 +04:00
|
|
|
status_t error = B_ENTRY_NOT_FOUND;
|
2003-07-30 21:48:08 +04:00
|
|
|
if (ManagerLocker locker = manager) {
|
|
|
|
// get the next job and an info
|
2003-10-24 13:37:20 +04:00
|
|
|
while (KDiskDeviceJob *job = manager->NextJob(&cookie)) {
|
2003-07-30 21:48:08 +04:00
|
|
|
// return info only on job scheduled or in progress
|
|
|
|
switch (job->Status()) {
|
|
|
|
case B_DISK_DEVICE_JOB_SCHEDULED:
|
|
|
|
case B_DISK_DEVICE_JOB_IN_PROGRESS:
|
2003-10-24 13:37:20 +04:00
|
|
|
error = job->GetInfo(&info);
|
|
|
|
break;
|
2003-07-30 21:48:08 +04:00
|
|
|
case B_DISK_DEVICE_JOB_UNINITIALIZED:
|
|
|
|
case B_DISK_DEVICE_JOB_SUCCEEDED:
|
|
|
|
case B_DISK_DEVICE_JOB_FAILED:
|
|
|
|
case B_DISK_DEVICE_JOB_CANCELED:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2003-10-24 13:37:20 +04:00
|
|
|
if (!error) {
|
|
|
|
user_memcpy(_cookie, &cookie, sizeof(cookie));
|
|
|
|
user_memcpy(_info, &info, sizeof(info));
|
|
|
|
}
|
|
|
|
return error;
|
2003-07-30 21:48:08 +04:00
|
|
|
}
|
|
|
|
|
2007-10-06 02:39:52 +04:00
|
|
|
|
2004-10-29 05:38:17 +04:00
|
|
|
// _user_get_disk_device_job_info
|
2003-07-30 21:48:08 +04:00
|
|
|
status_t
|
2004-10-29 05:38:17 +04:00
|
|
|
_user_get_disk_device_job_info(disk_job_id id, user_disk_device_job_info *_info)
|
2003-07-30 21:48:08 +04:00
|
|
|
{
|
2003-10-24 13:37:20 +04:00
|
|
|
if (!_info)
|
2003-07-30 21:48:08 +04:00
|
|
|
return B_BAD_VALUE;
|
2003-10-24 13:37:20 +04:00
|
|
|
user_disk_device_job_info info;
|
2003-07-30 21:48:08 +04:00
|
|
|
KDiskDeviceManager *manager = KDiskDeviceManager::Default();
|
2003-10-24 13:37:20 +04:00
|
|
|
status_t error = B_ENTRY_NOT_FOUND;
|
2003-07-30 21:48:08 +04:00
|
|
|
if (ManagerLocker locker = manager) {
|
|
|
|
// find the job and get the info
|
|
|
|
if (KDiskDeviceJob *job = manager->FindJob(id))
|
2003-10-24 13:37:20 +04:00
|
|
|
error = job->GetInfo(&info);
|
2003-07-30 21:48:08 +04:00
|
|
|
}
|
2003-10-24 13:37:20 +04:00
|
|
|
if (!error)
|
|
|
|
user_memcpy(_info, &info, sizeof(info));
|
|
|
|
return error;
|
2003-07-30 21:48:08 +04:00
|
|
|
}
|
|
|
|
|
2007-10-06 02:39:52 +04:00
|
|
|
|
2004-10-29 05:38:17 +04:00
|
|
|
// _user_get_disk_device_job_status
|
2003-07-30 21:48:08 +04:00
|
|
|
status_t
|
2004-10-29 05:38:17 +04:00
|
|
|
_user_get_disk_device_job_progress_info(disk_job_id id,
|
2007-10-06 02:39:52 +04:00
|
|
|
disk_device_job_progress_info *_info)
|
2003-07-30 21:48:08 +04:00
|
|
|
{
|
2003-10-24 13:37:20 +04:00
|
|
|
if (!_info)
|
2003-07-30 21:48:08 +04:00
|
|
|
return B_BAD_VALUE;
|
2003-10-24 13:37:20 +04:00
|
|
|
disk_device_job_progress_info info;
|
2003-07-30 21:48:08 +04:00
|
|
|
KDiskDeviceManager *manager = KDiskDeviceManager::Default();
|
2003-10-24 13:37:20 +04:00
|
|
|
status_t error = B_ENTRY_NOT_FOUND;
|
2003-07-30 21:48:08 +04:00
|
|
|
if (ManagerLocker locker = manager) {
|
|
|
|
// find the job and get the info
|
|
|
|
if (KDiskDeviceJob *job = manager->FindJob(id))
|
2003-10-24 13:37:20 +04:00
|
|
|
error = job->GetProgressInfo(&info);
|
2003-07-30 21:48:08 +04:00
|
|
|
}
|
2003-10-24 13:37:20 +04:00
|
|
|
if (!error)
|
|
|
|
user_memcpy(_info, &info, sizeof(info));
|
|
|
|
return error;
|
2003-07-30 21:48:08 +04:00
|
|
|
}
|
|
|
|
|
2007-10-06 02:39:52 +04:00
|
|
|
|
2004-10-29 05:38:17 +04:00
|
|
|
// _user_pause_disk_device_job
|
2003-07-30 21:48:08 +04:00
|
|
|
status_t
|
2004-10-29 05:38:17 +04:00
|
|
|
_user_pause_disk_device_job(disk_job_id id)
|
2003-07-30 21:48:08 +04:00
|
|
|
{
|
|
|
|
KDiskDeviceManager *manager = KDiskDeviceManager::Default();
|
|
|
|
if (ManagerLocker locker = manager) {
|
|
|
|
// get the job and the respective job queue
|
|
|
|
if (KDiskDeviceJob *job = manager->FindJob(id)) {
|
|
|
|
if (KDiskDeviceJobQueue *jobQueue = job->JobQueue()) {
|
|
|
|
// only the active job in progress can be paused
|
|
|
|
if (jobQueue->ActiveJob() != job)
|
|
|
|
return B_BAD_VALUE;
|
|
|
|
return jobQueue->Pause();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return B_ENTRY_NOT_FOUND;
|
|
|
|
}
|
|
|
|
|
2007-10-06 02:39:52 +04:00
|
|
|
|
2004-10-29 05:38:17 +04:00
|
|
|
// _user_cancel_disk_device_job
|
2003-07-30 21:48:08 +04:00
|
|
|
status_t
|
2004-10-29 05:38:17 +04:00
|
|
|
_user_cancel_disk_device_job(disk_job_id id, bool reverse)
|
2003-07-30 21:48:08 +04:00
|
|
|
{
|
|
|
|
KDiskDeviceManager *manager = KDiskDeviceManager::Default();
|
|
|
|
if (ManagerLocker locker = manager) {
|
|
|
|
// get the job and the respective job queue
|
|
|
|
if (KDiskDeviceJob *job = manager->FindJob(id)) {
|
|
|
|
if (KDiskDeviceJobQueue *jobQueue = job->JobQueue()) {
|
|
|
|
// only the active job in progress can be canceled
|
|
|
|
if (jobQueue->ActiveJob() != job)
|
|
|
|
return B_BAD_VALUE;
|
|
|
|
return jobQueue->Cancel(reverse);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return B_ENTRY_NOT_FOUND;
|
|
|
|
}
|
|
|
|
|