[haiku-commits] r40224 - haiku/trunk/src/system/kernel/disk_device_manager

  • From: axeld@xxxxxxxxxxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Wed, 12 Jan 2011 19:42:48 +0100 (CET)

Author: axeld
Date: 2011-01-12 19:42:48 +0100 (Wed, 12 Jan 2011)
New Revision: 40224
Changeset: http://dev.haiku-os.org/changeset/40224

Modified:
   haiku/trunk/src/system/kernel/disk_device_manager/KDiskDevice.cpp
   haiku/trunk/src/system/kernel/disk_device_manager/KFileDiskDevice.cpp
Log:
* Replaced one occurence of sprintf() with snprintf().
* Minor cleanup.


Modified: haiku/trunk/src/system/kernel/disk_device_manager/KDiskDevice.cpp
===================================================================
--- haiku/trunk/src/system/kernel/disk_device_manager/KDiskDevice.cpp   
2011-01-12 18:42:30 UTC (rev 40223)
+++ haiku/trunk/src/system/kernel/disk_device_manager/KDiskDevice.cpp   
2011-01-12 18:42:48 UTC (rev 40224)
@@ -1,9 +1,12 @@
 /*
+ * Copyright 2006-2011, Axel Dörfler, axeld@xxxxxxxxxxxxxxxxx
  * Copyright 2003-2009, Ingo Weinhold, ingo_weinhold@xxxxxxx
  * 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
@@ -46,7 +49,7 @@
 
 
 status_t
-KDiskDevice::SetTo(const char *path)
+KDiskDevice::SetTo(const char* path)
 {
        // check initialization and parameter
        status_t error = InitCheck();
@@ -156,7 +159,7 @@
        return B_OK;
 }
 
-// UnpublishDevice
+
 status_t
 KDiskDevice::UnpublishDevice()
 {
@@ -165,7 +168,7 @@
        return B_OK;
 }
 
-// RepublishDevice
+
 status_t
 KDiskDevice::RepublishDevice()
 {
@@ -174,42 +177,42 @@
        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,15 +257,14 @@
 }
 
 
-// SetPath
 status_t
-KDiskDevice::SetPath(const char *path)
+KDiskDevice::SetPath(const char* path)
 {
        return set_string(fDeviceData.path, path);
 }
 
-// Path
-const char *
+
+const char*
 KDiskDevice::Path() const
 {
        return fDeviceData.path;
@@ -270,7 +272,7 @@
 
 
 status_t
-KDiskDevice::GetFileName(char *buffer, size_t size) const
+KDiskDevice::GetFileName(char* buffer, size_t size) const
 {
        if (strlcpy(buffer, "raw", size) >= size)
                return B_NAME_TOO_LONG;
@@ -278,9 +280,8 @@
 }
 
 
-// GetPath
 status_t
-KDiskDevice::GetPath(KPath *path) const
+KDiskDevice::GetPath(KPath* path) const
 {
        if (!path || path->InitCheck() != B_OK)
                return B_BAD_VALUE;
@@ -289,51 +290,50 @@
        return path->SetPath(fDeviceData.path);
 }
 
-// SetFD
+
 void
 KDiskDevice::SetFD(int fd)
 {
        fFD = fd;
 }
 
-// FD
+
 int
 KDiskDevice::FD() const
 {
        return fFD;
 }
 
-// DeviceData
-disk_device_data *
+
+disk_device_data*
 KDiskDevice::DeviceData()
 {
        return &fDeviceData;
 }
 
-// DeviceData
-const disk_device_data *
+
+const disk_device_data*
 KDiskDevice::DeviceData() const
 {
        return &fDeviceData;
 }
 
 
-// WriteUserData
 void
-KDiskDevice::WriteUserData(UserDataWriter &writer, user_partition_data *data)
+KDiskDevice::WriteUserData(UserDataWriter& writer, user_partition_data* data)
 {
        return KPartition::WriteUserData(writer, data);
 }
 
-// WriteUserData
+
 void
-KDiskDevice::WriteUserData(UserDataWriter &writer)
+KDiskDevice::WriteUserData(UserDataWriter& writer)
 {
-       KPartition *partition = this;
-       user_disk_device_data *data
+       KPartition* partition = this;
+       user_disk_device_data* data
                = writer.AllocateDeviceData(partition->CountChildren());
-       char *path = writer.PlaceString(Path());
-       if (data) {
+       char* path = writer.PlaceString(Path());
+       if (data != NULL) {
                data->device_flags = DeviceFlags();
                data->path = path;
                writer.AddRelocationEntry(&data->path);
@@ -342,7 +342,7 @@
                partition->WriteUserData(writer, NULL);
 }
 
-// Dump
+
 void
 KDiskDevice::Dump(bool deep, int32 level)
 {
@@ -353,9 +353,9 @@
                KPartition::Dump(deep, 0);
 }
 
-// GetMediaStatus
+
 status_t
-KDiskDevice::GetMediaStatus(status_t *mediaStatus)
+KDiskDevice::GetMediaStatus(status_t* mediaStatus)
 {
        status_t error = B_OK;
        if (ioctl(fFD, B_GET_MEDIA_STATUS, mediaStatus) != 0)
@@ -376,16 +376,16 @@
        return error;
 }
 
-// GetGeometry
+
 status_t
-KDiskDevice::GetGeometry(device_geometry *geometry)
+KDiskDevice::GetGeometry(device_geometry* geometry)
 {
        if (ioctl(fFD, B_GET_GEOMETRY, geometry) != 0)
                return errno;
        return B_OK;
 }
 
-// _InitPartitionData
+
 void
 KDiskDevice::_InitPartitionData()
 {
@@ -429,4 +429,3 @@
        if (fDeviceData.geometry.write_once)
                SetDeviceFlags(DeviceFlags() | B_DISK_DEVICE_WRITE_ONCE);
 }
-

Modified: haiku/trunk/src/system/kernel/disk_device_manager/KFileDiskDevice.cpp
===================================================================
--- haiku/trunk/src/system/kernel/disk_device_manager/KFileDiskDevice.cpp       
2011-01-12 18:42:30 UTC (rev 40223)
+++ haiku/trunk/src/system/kernel/disk_device_manager/KFileDiskDevice.cpp       
2011-01-12 18:42:48 UTC (rev 40224)
@@ -1,16 +1,21 @@
-// KFileDiskDevice.cpp
+/*
+ * Copyright 2003-2009, Ingo Weinhold, ingo_weinhold@xxxxxxx
+ * Distributed under the terms of the MIT License.
+ */
 
+
+#include <KFileDiskDevice.h>
+
 #include <errno.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
 
+#include <devfs.h>
+#include <Drivers.h>
 #include <KernelExport.h>
-#include <Drivers.h>
-#include <devfs.h>
 
 #include <KDiskDeviceUtils.h>
-#include <KFileDiskDevice.h>
 #include <KPath.h>
 
 
@@ -19,26 +24,27 @@
 #define DBG(x) x
 #define OUT dprintf
 
-static const char *kFileDevicesDir = "/dev/disk/virtual/files";
 
+static const char* kFileDevicesDir = "/dev/disk/virtual/files";
 
-// constructor
+
 KFileDiskDevice::KFileDiskDevice(partition_id id)
-       : KDiskDevice(id),
-         fFilePath(NULL)
+       :
+       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)
+KFileDiskDevice::SetTo(const char* filePath, const char* devicePath)
 {
        // check params
        if (!filePath || strlen(filePath) > B_PATH_NAME_LENGTH
@@ -60,7 +66,7 @@
                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 @@
        return B_OK;
 }
 
-// Unset
+
 void
 KFileDiskDevice::Unset()
 {
@@ -118,23 +124,23 @@
        fFilePath = NULL;
 }
 
-// InitCheck
+
 status_t
 KFileDiskDevice::InitCheck() const
 {
        return KDiskDevice::InitCheck();
 }
 
-// FilePath
-const char *
+
+const char*
 KFileDiskDevice::FilePath() const
 {
        return fFilePath;
 }
 
-// GetMediaStatus
+
 status_t
-KFileDiskDevice::GetMediaStatus(status_t *mediaStatus)
+KFileDiskDevice::GetMediaStatus(status_t* mediaStatus)
 {
        // check the file
        struct stat st;
@@ -145,9 +151,9 @@
        return B_OK;
 }
 
-// GetGeometry
+
 status_t
-KFileDiskDevice::GetGeometry(device_geometry *geometry)
+KFileDiskDevice::GetGeometry(device_geometry* geometry)
 {
        // check the file
        struct stat st;
@@ -177,25 +183,25 @@
        return B_OK;
 }
 
-// _RegisterDevice
+
 status_t
-KFileDiskDevice::_RegisterDevice(const char *file, const char *device)
+KFileDiskDevice::_RegisterDevice(const char* file, const char* device)
 {
        return devfs_publish_file_device(device + 5, file);
                // we need to remove the "/dev/" part from the path
 }
 
-// _UnregisterDevice
+
 status_t
-KFileDiskDevice::_UnregisterDevice(const char *_device)
+KFileDiskDevice::_UnregisterDevice(const char* _device)
 {
        return devfs_unpublish_file_device(_device + 5);
                // we need to remove the "/dev/" part from the path
 }
 
-// _GetDirectoryPath
+
 status_t
-KFileDiskDevice::_GetDirectoryPath(partition_id id, KPath *path)
+KFileDiskDevice::_GetDirectoryPath(partition_id id, KPath* path)
 {
        if (path == NULL)
                return B_BAD_VALUE;
@@ -206,7 +212,7 @@
        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;


Other related posts: