* _user_find_partition() did not work for partitions (only for devices), as it
did not set the "devicesOnly" flag to false when calling RegisterDevice(). * ddm_userland_interface.cpp incorrectly wrote to userland memory when it assigned "neededSize" in several places. * Replaced on-stack path with the UserStringParameter class where appropriate. * Made the UserStringParameter class castable to char*. * Minor cleanup in KDiskDeviceManager.cpp. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@26563 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
ebdb1a612b
commit
6cc43bfbb0
@ -233,9 +233,9 @@ KDiskDeviceManager::~KDiskDeviceManager()
|
||||
// some sanity checks
|
||||
if (fPartitions->Count() > 0) {
|
||||
DBG(OUT("WARNING: There are still %ld unremoved partitions!\n",
|
||||
fPartitions->Count()));
|
||||
fPartitions->Count()));
|
||||
for (PartitionMap::Iterator it = fPartitions->Begin();
|
||||
it != fPartitions->End(); ++it) {
|
||||
it != fPartitions->End(); ++it) {
|
||||
DBG(OUT(" partition: %ld\n", it->Value()->ID()));
|
||||
}
|
||||
}
|
||||
@ -243,17 +243,16 @@ KDiskDeviceManager::~KDiskDeviceManager()
|
||||
DBG(OUT("WARNING: There are still %ld obsolete partitions!\n",
|
||||
fObsoletePartitions->Count()));
|
||||
for (PartitionSet::Iterator it = fObsoletePartitions->Begin();
|
||||
it != fObsoletePartitions->End(); ++it) {
|
||||
it != fObsoletePartitions->End(); ++it) {
|
||||
DBG(OUT(" partition: %ld\n", (*it)->ID()));
|
||||
}
|
||||
}
|
||||
// remove all disk systems
|
||||
for (int32 cookie = 0;
|
||||
KDiskSystem *diskSystem = NextDiskSystem(&cookie); ) {
|
||||
for (int32 cookie = 0; KDiskSystem *diskSystem = NextDiskSystem(&cookie);) {
|
||||
fDiskSystems->Remove(diskSystem->ID());
|
||||
if (diskSystem->IsLoaded()) {
|
||||
DBG(OUT("WARNING: Disk system `%s' (%ld) is still loaded!\n",
|
||||
diskSystem->Name(), diskSystem->ID()));
|
||||
diskSystem->Name(), diskSystem->ID()));
|
||||
} else
|
||||
delete diskSystem;
|
||||
}
|
||||
@ -361,8 +360,7 @@ KDiskDeviceManager::FindPartition(const char *path)
|
||||
return NULL;
|
||||
|
||||
for (PartitionMap::Iterator it = fPartitions->Begin();
|
||||
it != fPartitions->End();
|
||||
++it) {
|
||||
it != fPartitions->End(); ++it) {
|
||||
KPartition *partition = it->Value();
|
||||
if (partition->GetPath(&partitionPath) == B_OK
|
||||
&& partitionPath == path) {
|
||||
@ -807,8 +805,7 @@ KDiskDeviceManager::DeletePartition(KPartition *partition)
|
||||
KDiskSystem *
|
||||
KDiskDeviceManager::FindDiskSystem(const char *name, bool byPrettyName)
|
||||
{
|
||||
for (int32 cookie = 0;
|
||||
KDiskSystem *diskSystem = NextDiskSystem(&cookie); ) {
|
||||
for (int32 cookie = 0; KDiskSystem *diskSystem = NextDiskSystem(&cookie);) {
|
||||
if (byPrettyName) {
|
||||
if (strcmp(name, diskSystem->PrettyName()) == 0)
|
||||
return diskSystem;
|
||||
@ -1053,15 +1050,16 @@ KDiskDeviceManager::_AddDiskSystem(KDiskSystem *diskSystem)
|
||||
{
|
||||
if (!diskSystem)
|
||||
return B_BAD_VALUE;
|
||||
DBG(OUT("KDiskDeviceManager::_AddDiskSystem(%s)\n", diskSystem->Name()));
|
||||
DBG(OUT("KDiskDeviceManager::_AddDiskSystem(%s)\n", diskSystem->Name()));
|
||||
status_t error = diskSystem->Init();
|
||||
if (error != B_OK)
|
||||
DBG(OUT(" initialization failed: %s\n", strerror(error)));
|
||||
DBG(if (error != B_OK)
|
||||
OUT(" initialization failed: %s\n", strerror(error)));
|
||||
if (error == B_OK)
|
||||
error = fDiskSystems->Put(diskSystem->ID(), diskSystem);
|
||||
if (error != B_OK)
|
||||
delete diskSystem;
|
||||
DBG(OUT("KDiskDeviceManager::_AddDiskSystem() done: %s\n", strerror(error)));
|
||||
DBG(OUT("KDiskDeviceManager::_AddDiskSystem() done: %s\n",
|
||||
strerror(error)));
|
||||
return error;
|
||||
}
|
||||
|
||||
@ -1155,7 +1153,7 @@ KDiskDeviceManager::_UpdateBusyPartitions(KDiskDevice *device)
|
||||
status_t
|
||||
KDiskDeviceManager::_Scan(const char *path)
|
||||
{
|
||||
DBG(OUT("KDiskDeviceManager::_Scan(%s)\n", path));
|
||||
DBG(OUT("KDiskDeviceManager::_Scan(%s)\n", path));
|
||||
status_t error = B_ENTRY_NOT_FOUND;
|
||||
struct stat st;
|
||||
if (lstat(path, &st) < 0) {
|
||||
@ -1191,7 +1189,7 @@ DBG(OUT("KDiskDeviceManager::_Scan(%s)\n", path));
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
DBG(OUT(" found device: %s\n", path));
|
||||
DBG(OUT(" found device: %s\n", path));
|
||||
// create a KDiskDevice for it
|
||||
KDiskDevice *device = new(nothrow) KDiskDevice;
|
||||
if (!device)
|
||||
|
@ -129,6 +129,16 @@ struct UserStringParameter {
|
||||
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
inline operator const char*()
|
||||
{
|
||||
return value;
|
||||
}
|
||||
|
||||
inline operator char*()
|
||||
{
|
||||
return value;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@ -236,7 +246,10 @@ _user_get_next_disk_device_id(int32 *_cookie, size_t *neededSize)
|
||||
// get the needed size
|
||||
UserDataWriter writer;
|
||||
device->WriteUserData(writer);
|
||||
*neededSize = writer.AllocatedSize();
|
||||
status_t status = copy_to_user_value(neededSize,
|
||||
writer.AllocatedSize());
|
||||
if (status != B_OK)
|
||||
return status;
|
||||
} else {
|
||||
id = B_ERROR;
|
||||
}
|
||||
@ -251,12 +264,9 @@ _user_get_next_disk_device_id(int32 *_cookie, size_t *neededSize)
|
||||
partition_id
|
||||
_user_find_disk_device(const char *_filename, size_t *neededSize)
|
||||
{
|
||||
if (!_filename)
|
||||
return B_BAD_VALUE;
|
||||
|
||||
char filename[B_PATH_NAME_LENGTH];
|
||||
status_t error = ddm_strlcpy(filename, _filename, B_PATH_NAME_LENGTH);
|
||||
if (error)
|
||||
UserStringParameter<false> filename;
|
||||
status_t error = filename.Init(_filename, B_PATH_NAME_LENGTH);
|
||||
if (error != B_OK)
|
||||
return error;
|
||||
|
||||
partition_id id = B_ENTRY_NOT_FOUND;
|
||||
@ -270,7 +280,9 @@ _user_find_disk_device(const char *_filename, size_t *neededSize)
|
||||
// get the needed size
|
||||
UserDataWriter writer;
|
||||
device->WriteUserData(writer);
|
||||
*neededSize = writer.AllocatedSize();
|
||||
error = copy_to_user_value(neededSize, writer.AllocatedSize());
|
||||
if (error != B_OK)
|
||||
return error;
|
||||
} else
|
||||
return B_ERROR;
|
||||
}
|
||||
@ -283,12 +295,9 @@ _user_find_disk_device(const char *_filename, size_t *neededSize)
|
||||
partition_id
|
||||
_user_find_partition(const char *_filename, size_t *neededSize)
|
||||
{
|
||||
if (!_filename)
|
||||
return B_BAD_VALUE;
|
||||
|
||||
char filename[B_PATH_NAME_LENGTH];
|
||||
status_t error = ddm_strlcpy(filename, _filename, B_PATH_NAME_LENGTH);
|
||||
if (error)
|
||||
UserStringParameter<false> filename;
|
||||
status_t error = filename.Init(_filename, B_PATH_NAME_LENGTH);
|
||||
if (error != B_OK)
|
||||
return error;
|
||||
|
||||
partition_id id = B_ENTRY_NOT_FOUND;
|
||||
@ -299,7 +308,8 @@ _user_find_partition(const char *_filename, size_t *neededSize)
|
||||
id = partition->ID();
|
||||
if (neededSize) {
|
||||
// get and lock the partition's device
|
||||
KDiskDevice *device = manager->RegisterDevice(partition->ID());
|
||||
KDiskDevice *device = manager->RegisterDevice(partition->ID(),
|
||||
false);
|
||||
if (!device)
|
||||
return B_ENTRY_NOT_FOUND;
|
||||
PartitionRegistrar _2(device, true);
|
||||
@ -307,7 +317,9 @@ _user_find_partition(const char *_filename, size_t *neededSize)
|
||||
// get the needed size
|
||||
UserDataWriter writer;
|
||||
device->WriteUserData(writer);
|
||||
*neededSize = writer.AllocatedSize();
|
||||
error = copy_to_user_value(neededSize, writer.AllocatedSize());
|
||||
if (error != B_OK)
|
||||
return error;
|
||||
} else
|
||||
return B_ERROR;
|
||||
}
|
||||
@ -412,12 +424,11 @@ _user_get_disk_device_data(partition_id id, bool deviceOnly,
|
||||
partition_id
|
||||
_user_register_file_device(const char *_filename)
|
||||
{
|
||||
if (!_filename)
|
||||
return B_BAD_VALUE;
|
||||
char filename[B_PATH_NAME_LENGTH];
|
||||
status_t error = ddm_strlcpy(filename, _filename, B_PATH_NAME_LENGTH);
|
||||
if (error)
|
||||
UserStringParameter<false> filename;
|
||||
status_t error = filename.Init(_filename, B_PATH_NAME_LENGTH);
|
||||
if (error != B_OK)
|
||||
return error;
|
||||
|
||||
KDiskDeviceManager *manager = KDiskDeviceManager::Default();
|
||||
if (ManagerLocker locker = manager) {
|
||||
if (KFileDiskDevice *device = manager->FindFileDevice(filename))
|
||||
@ -438,10 +449,11 @@ _user_unregister_file_device(partition_id deviceID, const char *_filename)
|
||||
if (deviceID >= 0) {
|
||||
return manager->DeleteFileDevice(deviceID);
|
||||
} else {
|
||||
char filename[B_PATH_NAME_LENGTH];
|
||||
status_t error = ddm_strlcpy(filename, _filename, B_PATH_NAME_LENGTH);
|
||||
if (error)
|
||||
UserStringParameter<false> filename;
|
||||
status_t error = filename.Init(_filename, B_PATH_NAME_LENGTH);
|
||||
if (error != B_OK)
|
||||
return error;
|
||||
|
||||
return manager->DeleteFileDevice(filename);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user