* _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:
Axel Dörfler
2008-07-22 14:05:47 +00:00
parent ebdb1a612b
commit 6cc43bfbb0
2 changed files with 50 additions and 40 deletions
@@ -233,9 +233,9 @@ KDiskDeviceManager::~KDiskDeviceManager()
// some sanity checks // some sanity checks
if (fPartitions->Count() > 0) { if (fPartitions->Count() > 0) {
DBG(OUT("WARNING: There are still %ld unremoved partitions!\n", DBG(OUT("WARNING: There are still %ld unremoved partitions!\n",
fPartitions->Count())); fPartitions->Count()));
for (PartitionMap::Iterator it = fPartitions->Begin(); for (PartitionMap::Iterator it = fPartitions->Begin();
it != fPartitions->End(); ++it) { it != fPartitions->End(); ++it) {
DBG(OUT(" partition: %ld\n", it->Value()->ID())); DBG(OUT(" partition: %ld\n", it->Value()->ID()));
} }
} }
@@ -243,17 +243,16 @@ KDiskDeviceManager::~KDiskDeviceManager()
DBG(OUT("WARNING: There are still %ld obsolete partitions!\n", DBG(OUT("WARNING: There are still %ld obsolete partitions!\n",
fObsoletePartitions->Count())); fObsoletePartitions->Count()));
for (PartitionSet::Iterator it = fObsoletePartitions->Begin(); for (PartitionSet::Iterator it = fObsoletePartitions->Begin();
it != fObsoletePartitions->End(); ++it) { it != fObsoletePartitions->End(); ++it) {
DBG(OUT(" partition: %ld\n", (*it)->ID())); DBG(OUT(" partition: %ld\n", (*it)->ID()));
} }
} }
// remove all disk systems // remove all disk systems
for (int32 cookie = 0; for (int32 cookie = 0; KDiskSystem *diskSystem = NextDiskSystem(&cookie);) {
KDiskSystem *diskSystem = NextDiskSystem(&cookie); ) {
fDiskSystems->Remove(diskSystem->ID()); fDiskSystems->Remove(diskSystem->ID());
if (diskSystem->IsLoaded()) { if (diskSystem->IsLoaded()) {
DBG(OUT("WARNING: Disk system `%s' (%ld) is still loaded!\n", DBG(OUT("WARNING: Disk system `%s' (%ld) is still loaded!\n",
diskSystem->Name(), diskSystem->ID())); diskSystem->Name(), diskSystem->ID()));
} else } else
delete diskSystem; delete diskSystem;
} }
@@ -361,8 +360,7 @@ KDiskDeviceManager::FindPartition(const char *path)
return NULL; return NULL;
for (PartitionMap::Iterator it = fPartitions->Begin(); for (PartitionMap::Iterator it = fPartitions->Begin();
it != fPartitions->End(); it != fPartitions->End(); ++it) {
++it) {
KPartition *partition = it->Value(); KPartition *partition = it->Value();
if (partition->GetPath(&partitionPath) == B_OK if (partition->GetPath(&partitionPath) == B_OK
&& partitionPath == path) { && partitionPath == path) {
@@ -807,8 +805,7 @@ KDiskDeviceManager::DeletePartition(KPartition *partition)
KDiskSystem * KDiskSystem *
KDiskDeviceManager::FindDiskSystem(const char *name, bool byPrettyName) KDiskDeviceManager::FindDiskSystem(const char *name, bool byPrettyName)
{ {
for (int32 cookie = 0; for (int32 cookie = 0; KDiskSystem *diskSystem = NextDiskSystem(&cookie);) {
KDiskSystem *diskSystem = NextDiskSystem(&cookie); ) {
if (byPrettyName) { if (byPrettyName) {
if (strcmp(name, diskSystem->PrettyName()) == 0) if (strcmp(name, diskSystem->PrettyName()) == 0)
return diskSystem; return diskSystem;
@@ -1053,15 +1050,16 @@ KDiskDeviceManager::_AddDiskSystem(KDiskSystem *diskSystem)
{ {
if (!diskSystem) if (!diskSystem)
return B_BAD_VALUE; 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(); status_t error = diskSystem->Init();
if (error != B_OK) DBG(if (error != B_OK)
DBG(OUT(" initialization failed: %s\n", strerror(error))); OUT(" initialization failed: %s\n", strerror(error)));
if (error == B_OK) if (error == B_OK)
error = fDiskSystems->Put(diskSystem->ID(), diskSystem); error = fDiskSystems->Put(diskSystem->ID(), diskSystem);
if (error != B_OK) if (error != B_OK)
delete diskSystem; delete diskSystem;
DBG(OUT("KDiskDeviceManager::_AddDiskSystem() done: %s\n", strerror(error))); DBG(OUT("KDiskDeviceManager::_AddDiskSystem() done: %s\n",
strerror(error)));
return error; return error;
} }
@@ -1155,7 +1153,7 @@ KDiskDeviceManager::_UpdateBusyPartitions(KDiskDevice *device)
status_t status_t
KDiskDeviceManager::_Scan(const char *path) 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; status_t error = B_ENTRY_NOT_FOUND;
struct stat st; struct stat st;
if (lstat(path, &st) < 0) { if (lstat(path, &st) < 0) {
@@ -1191,7 +1189,7 @@ DBG(OUT("KDiskDeviceManager::_Scan(%s)\n", path));
return B_OK; return B_OK;
} }
DBG(OUT(" found device: %s\n", path)); DBG(OUT(" found device: %s\n", path));
// create a KDiskDevice for it // create a KDiskDevice for it
KDiskDevice *device = new(nothrow) KDiskDevice; KDiskDevice *device = new(nothrow) KDiskDevice;
if (!device) if (!device)
@@ -129,6 +129,16 @@ struct UserStringParameter {
return B_OK; 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 // get the needed size
UserDataWriter writer; UserDataWriter writer;
device->WriteUserData(writer); device->WriteUserData(writer);
*neededSize = writer.AllocatedSize(); status_t status = copy_to_user_value(neededSize,
writer.AllocatedSize());
if (status != B_OK)
return status;
} else { } else {
id = B_ERROR; id = B_ERROR;
} }
@@ -251,12 +264,9 @@ _user_get_next_disk_device_id(int32 *_cookie, size_t *neededSize)
partition_id partition_id
_user_find_disk_device(const char *_filename, size_t *neededSize) _user_find_disk_device(const char *_filename, size_t *neededSize)
{ {
if (!_filename) UserStringParameter<false> filename;
return B_BAD_VALUE; status_t error = filename.Init(_filename, B_PATH_NAME_LENGTH);
if (error != B_OK)
char filename[B_PATH_NAME_LENGTH];
status_t error = ddm_strlcpy(filename, _filename, B_PATH_NAME_LENGTH);
if (error)
return error; return error;
partition_id id = B_ENTRY_NOT_FOUND; 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 // get the needed size
UserDataWriter writer; UserDataWriter writer;
device->WriteUserData(writer); device->WriteUserData(writer);
*neededSize = writer.AllocatedSize(); error = copy_to_user_value(neededSize, writer.AllocatedSize());
if (error != B_OK)
return error;
} else } else
return B_ERROR; return B_ERROR;
} }
@@ -283,12 +295,9 @@ _user_find_disk_device(const char *_filename, size_t *neededSize)
partition_id partition_id
_user_find_partition(const char *_filename, size_t *neededSize) _user_find_partition(const char *_filename, size_t *neededSize)
{ {
if (!_filename) UserStringParameter<false> filename;
return B_BAD_VALUE; status_t error = filename.Init(_filename, B_PATH_NAME_LENGTH);
if (error != B_OK)
char filename[B_PATH_NAME_LENGTH];
status_t error = ddm_strlcpy(filename, _filename, B_PATH_NAME_LENGTH);
if (error)
return error; return error;
partition_id id = B_ENTRY_NOT_FOUND; partition_id id = B_ENTRY_NOT_FOUND;
@@ -299,7 +308,8 @@ _user_find_partition(const char *_filename, size_t *neededSize)
id = partition->ID(); id = partition->ID();
if (neededSize) { if (neededSize) {
// get and lock the partition's device // get and lock the partition's device
KDiskDevice *device = manager->RegisterDevice(partition->ID()); KDiskDevice *device = manager->RegisterDevice(partition->ID(),
false);
if (!device) if (!device)
return B_ENTRY_NOT_FOUND; return B_ENTRY_NOT_FOUND;
PartitionRegistrar _2(device, true); PartitionRegistrar _2(device, true);
@@ -307,7 +317,9 @@ _user_find_partition(const char *_filename, size_t *neededSize)
// get the needed size // get the needed size
UserDataWriter writer; UserDataWriter writer;
device->WriteUserData(writer); device->WriteUserData(writer);
*neededSize = writer.AllocatedSize(); error = copy_to_user_value(neededSize, writer.AllocatedSize());
if (error != B_OK)
return error;
} else } else
return B_ERROR; return B_ERROR;
} }
@@ -412,12 +424,11 @@ _user_get_disk_device_data(partition_id id, bool deviceOnly,
partition_id partition_id
_user_register_file_device(const char *_filename) _user_register_file_device(const char *_filename)
{ {
if (!_filename) UserStringParameter<false> filename;
return B_BAD_VALUE; status_t error = filename.Init(_filename, B_PATH_NAME_LENGTH);
char filename[B_PATH_NAME_LENGTH]; if (error != B_OK)
status_t error = ddm_strlcpy(filename, _filename, B_PATH_NAME_LENGTH);
if (error)
return error; return error;
KDiskDeviceManager *manager = KDiskDeviceManager::Default(); KDiskDeviceManager *manager = KDiskDeviceManager::Default();
if (ManagerLocker locker = manager) { if (ManagerLocker locker = manager) {
if (KFileDiskDevice *device = manager->FindFileDevice(filename)) if (KFileDiskDevice *device = manager->FindFileDevice(filename))
@@ -438,10 +449,11 @@ _user_unregister_file_device(partition_id deviceID, const char *_filename)
if (deviceID >= 0) { if (deviceID >= 0) {
return manager->DeleteFileDevice(deviceID); return manager->DeleteFileDevice(deviceID);
} else { } else {
char filename[B_PATH_NAME_LENGTH]; UserStringParameter<false> filename;
status_t error = ddm_strlcpy(filename, _filename, B_PATH_NAME_LENGTH); status_t error = filename.Init(_filename, B_PATH_NAME_LENGTH);
if (error) if (error != B_OK)
return error; return error;
return manager->DeleteFileDevice(filename); return manager->DeleteFileDevice(filename);
} }
} }