* Replaced one occurence of sprintf() with snprintf().

* Minor cleanup.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@40224 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler 2011-01-12 18:42:48 +00:00
parent fd4998dce7
commit b16710b814
2 changed files with 70 additions and 65 deletions

View File

@ -1,9 +1,12 @@
/*
* Copyright 2006-2011, Axel Dörfler, axeld@pinc-software.de.
* Copyright 2003-2009, Ingo Weinhold, ingo_weinhold@gmx.de.
* Distributed under the terms of the MIT License.
*/
#include "KDiskDevice.h"
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
@ -13,11 +16,11 @@
#include <Drivers.h>
#include "ddm_userland_interface.h"
#include "KDiskDevice.h"
#include "KDiskDeviceUtils.h"
#include "KPath.h"
#include "UserDataWriter.h"
// debugging
//#define DBG(x)
#define DBG(x) x
@ -156,7 +159,7 @@ KDiskDevice::PublishDevice()
return B_OK;
}
// UnpublishDevice
status_t
KDiskDevice::UnpublishDevice()
{
@ -165,7 +168,7 @@ KDiskDevice::UnpublishDevice()
return B_OK;
}
// RepublishDevice
status_t
KDiskDevice::RepublishDevice()
{
@ -174,42 +177,42 @@ KDiskDevice::RepublishDevice()
return B_OK;
}
// SetDeviceFlags
void
KDiskDevice::SetDeviceFlags(uint32 flags)
{
fDeviceData.flags = flags;
}
// DeviceFlags
uint32
KDiskDevice::DeviceFlags() const
{
return fDeviceData.flags;
}
// IsReadOnlyMedia
bool
KDiskDevice::IsReadOnlyMedia() const
{
return fDeviceData.geometry.read_only;
}
// IsWriteOnce
bool
KDiskDevice::IsWriteOnce() const
{
return fDeviceData.geometry.write_once;
}
// IsRemovable
bool
KDiskDevice::IsRemovable() const
{
return fDeviceData.geometry.removable;
}
// HasMedia
bool
KDiskDevice::HasMedia() const
{
@ -254,14 +257,13 @@ KDiskDevice::UpdateGeometry()
}
// SetPath
status_t
KDiskDevice::SetPath(const char* path)
{
return set_string(fDeviceData.path, path);
}
// Path
const char*
KDiskDevice::Path() const
{
@ -278,7 +280,6 @@ KDiskDevice::GetFileName(char *buffer, size_t size) const
}
// GetPath
status_t
KDiskDevice::GetPath(KPath* path) const
{
@ -289,28 +290,28 @@ KDiskDevice::GetPath(KPath *path) const
return path->SetPath(fDeviceData.path);
}
// SetFD
void
KDiskDevice::SetFD(int fd)
{
fFD = fd;
}
// FD
int
KDiskDevice::FD() const
{
return fFD;
}
// DeviceData
disk_device_data*
KDiskDevice::DeviceData()
{
return &fDeviceData;
}
// DeviceData
const disk_device_data*
KDiskDevice::DeviceData() const
{
@ -318,14 +319,13 @@ KDiskDevice::DeviceData() const
}
// WriteUserData
void
KDiskDevice::WriteUserData(UserDataWriter& writer, user_partition_data* data)
{
return KPartition::WriteUserData(writer, data);
}
// WriteUserData
void
KDiskDevice::WriteUserData(UserDataWriter& writer)
{
@ -333,7 +333,7 @@ KDiskDevice::WriteUserData(UserDataWriter &writer)
user_disk_device_data* data
= writer.AllocateDeviceData(partition->CountChildren());
char* path = writer.PlaceString(Path());
if (data) {
if (data != NULL) {
data->device_flags = DeviceFlags();
data->path = path;
writer.AddRelocationEntry(&data->path);
@ -342,7 +342,7 @@ KDiskDevice::WriteUserData(UserDataWriter &writer)
partition->WriteUserData(writer, NULL);
}
// Dump
void
KDiskDevice::Dump(bool deep, int32 level)
{
@ -353,7 +353,7 @@ KDiskDevice::Dump(bool deep, int32 level)
KPartition::Dump(deep, 0);
}
// GetMediaStatus
status_t
KDiskDevice::GetMediaStatus(status_t* mediaStatus)
{
@ -376,7 +376,7 @@ KDiskDevice::GetMediaStatus(status_t *mediaStatus)
return error;
}
// GetGeometry
status_t
KDiskDevice::GetGeometry(device_geometry* geometry)
{
@ -385,7 +385,7 @@ KDiskDevice::GetGeometry(device_geometry *geometry)
return B_OK;
}
// _InitPartitionData
void
KDiskDevice::_InitPartitionData()
{
@ -429,4 +429,3 @@ KDiskDevice::_UpdateDeviceFlags()
if (fDeviceData.geometry.write_once)
SetDeviceFlags(DeviceFlags() | B_DISK_DEVICE_WRITE_ONCE);
}

View File

@ -1,16 +1,21 @@
// KFileDiskDevice.cpp
/*
* Copyright 2003-2009, Ingo Weinhold, ingo_weinhold@gmx.de.
* Distributed under the terms of the MIT License.
*/
#include <KFileDiskDevice.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <KernelExport.h>
#include <Drivers.h>
#include <devfs.h>
#include <Drivers.h>
#include <KernelExport.h>
#include <KDiskDeviceUtils.h>
#include <KFileDiskDevice.h>
#include <KPath.h>
@ -19,24 +24,25 @@
#define DBG(x) x
#define OUT dprintf
static const char* kFileDevicesDir = "/dev/disk/virtual/files";
// constructor
KFileDiskDevice::KFileDiskDevice(partition_id id)
: KDiskDevice(id),
:
KDiskDevice(id),
fFilePath(NULL)
{
SetDeviceFlags(DeviceFlags() | B_DISK_DEVICE_IS_FILE);
}
// destructor
KFileDiskDevice::~KFileDiskDevice()
{
Unset();
}
// SetTo
status_t
KFileDiskDevice::SetTo(const char* filePath, const char* devicePath)
{
@ -60,7 +66,7 @@ KFileDiskDevice::SetTo(const char *filePath, const char *devicePath)
return B_BAD_VALUE;
// create the device, if requested
KPath tmpDevicePath;
if (!devicePath) {
if (devicePath == NULL) {
// no device path: we shall create a new device entry
if (tmpDevicePath.InitCheck() != B_OK)
return tmpDevicePath.InitCheck();
@ -101,7 +107,7 @@ KFileDiskDevice::SetTo(const char *filePath, const char *devicePath)
return B_OK;
}
// Unset
void
KFileDiskDevice::Unset()
{
@ -118,21 +124,21 @@ KFileDiskDevice::Unset()
fFilePath = NULL;
}
// InitCheck
status_t
KFileDiskDevice::InitCheck() const
{
return KDiskDevice::InitCheck();
}
// FilePath
const char*
KFileDiskDevice::FilePath() const
{
return fFilePath;
}
// GetMediaStatus
status_t
KFileDiskDevice::GetMediaStatus(status_t* mediaStatus)
{
@ -145,7 +151,7 @@ KFileDiskDevice::GetMediaStatus(status_t *mediaStatus)
return B_OK;
}
// GetGeometry
status_t
KFileDiskDevice::GetGeometry(device_geometry* geometry)
{
@ -177,7 +183,7 @@ KFileDiskDevice::GetGeometry(device_geometry *geometry)
return B_OK;
}
// _RegisterDevice
status_t
KFileDiskDevice::_RegisterDevice(const char* file, const char* device)
{
@ -185,7 +191,7 @@ KFileDiskDevice::_RegisterDevice(const char *file, const char *device)
// we need to remove the "/dev/" part from the path
}
// _UnregisterDevice
status_t
KFileDiskDevice::_UnregisterDevice(const char* _device)
{
@ -193,7 +199,7 @@ KFileDiskDevice::_UnregisterDevice(const char *_device)
// we need to remove the "/dev/" part from the path
}
// _GetDirectoryPath
status_t
KFileDiskDevice::_GetDirectoryPath(partition_id id, KPath* path)
{
@ -206,7 +212,7 @@ KFileDiskDevice::_GetDirectoryPath(partition_id id, KPath *path)
status_t error = path->SetPath(kFileDevicesDir);
if (error == B_OK) {
char idBuffer[12];
sprintf(idBuffer, "%ld", id);
snprintf(idBuffer, sizeof(idBuffer), "%ld", id);
error = path->Append(idBuffer);
}
return error;