3 #ifndef _K_DISK_DEVICE_UTILS_H
4 #define _K_DISK_DEVICE_UTILS_H
9 #include <SupportDefs.h>
11 #include <util/AutoLock.h>
14 #include <KDiskDevice.h>
15 #include <KDiskDeviceManager.h>
16 #include <KDiskSystem.h>
17 #include <KPartition.h>
20 namespace DiskDevice
{
28 min(const T
&a
, const T
&b
)
39 max(const T
&a
, const T
&b
)
49 set_string(char *&location
, const char *newValue
)
57 status_t error
= B_OK
;
59 location
= strdup(newValue
);
67 /*! \brief \c NULL aware strcmp().
69 \c NULL is considered the least of all strings. \c NULL equals \c NULL.
71 \param str1 First string.
72 \param str2 Second string.
73 \return A value less than 0, if \a str1 is less than \a str2,
74 0, if they are equal, or a value greater than 0, if
75 \a str1 is greater \a str2.
79 compare_string(const char *str1
, const char *str2
)
85 } else if (str2
== NULL
)
87 return strcmp(str1
, str2
);
95 class KDiskDeviceManager
;
98 //typedef struct disk_device_data disk_device_data;
100 typedef AutoLocker
<KDiskDevice
, AutoLockerReadLocking
<KDiskDevice
> >
102 typedef AutoLocker
<KDiskDevice
, AutoLockerWriteLocking
<KDiskDevice
> >
104 typedef AutoLocker
<KDiskDeviceManager
> ManagerLocker
;
106 // AutoLockerPartitionRegistration
107 template<const int dummy
= 0>
108 class AutoLockerPartitionRegistration
{
110 inline bool Lock(KPartition
*partition
)
112 if (partition
== NULL
)
114 partition
->Register();
118 inline void Unlock(KPartition
*partition
)
120 if (partition
!= NULL
)
121 partition
->Unregister();
125 typedef AutoLocker
<KPartition
, AutoLockerPartitionRegistration
<> >
128 // AutoLockerDiskSystemLoading
129 template<const int dummy
= 0>
130 class AutoLockerDiskSystemLoading
{
132 inline bool Lock(KDiskSystem
*diskSystem
)
134 return (diskSystem
->Load() == B_OK
);
137 inline void Unlock(KDiskSystem
*diskSystem
)
139 diskSystem
->Unload();
143 typedef AutoLocker
<KDiskSystem
, AutoLockerDiskSystemLoading
<> >
147 // AutoLockerDeviceStructReadLocker
148 template<const int dummy = 0>
149 class AutoLockerDeviceStructReadLocker {
151 inline bool Lock(disk_device_data *device)
153 return read_lock_disk_device(device->id);
156 inline void Unlock(disk_device_data *device)
158 read_unlock_disk_device(device->id);
162 typedef AutoLocker<disk_device_data, AutoLockerDeviceStructReadLocker<> >
163 DeviceStructReadLocker;
165 // AutoLockerDeviceStructWriteLocker
166 template<const int dummy = 0>
167 class AutoLockerDeviceStructWriteLocker {
169 inline bool Lock(disk_device_data *device)
171 return write_lock_disk_device(device->id);
174 inline void Unlock(disk_device_data *device)
176 write_unlock_disk_device(device->id);
180 typedef AutoLocker<disk_device_data, AutoLockerDeviceStructWriteLocker<> >
181 DeviceStructWriteLocker;
184 } // namespace DiskDevice
185 } // namespace BPrivate
187 using BPrivate::DiskDevice::set_string
;
188 using BPrivate::DiskDevice::DeviceReadLocker
;
189 using BPrivate::DiskDevice::DeviceWriteLocker
;
190 using BPrivate::DiskDevice::ManagerLocker
;
191 using BPrivate::DiskDevice::PartitionRegistrar
;
192 using BPrivate::DiskDevice::DiskSystemLoader
;
193 //using BPrivate::DiskDevice::DeviceStructReadLocker;
194 //using BPrivate::DiskDevice::DeviceStructReadLocker;
196 #endif // _K_DISK_DEVICE_H