summaryrefslogtreecommitdiff
path: root/diskio-unix.cc
diff options
context:
space:
mode:
authorsrs5694 <srs5694@users.sourceforge.net>2013-01-09 12:55:40 -0500
committersrs5694 <srs5694@users.sourceforge.net>2013-01-09 12:55:40 -0500
commit0741fa21ac6cb477891ef15f269c8c8f36cac7c6 (patch)
treeb37926ea88396302141f9feeb1806c6bf3ac2455 /diskio-unix.cc
parentd8eed4629449a325999808a0170dbda53bd4a6df (diff)
downloadsgdisk-0741fa21ac6cb477891ef15f269c8c8f36cac7c6.tar.gz
0.8.6 release.
Diffstat (limited to 'diskio-unix.cc')
-rw-r--r--diskio-unix.cc23
1 files changed, 22 insertions, 1 deletions
diff --git a/diskio-unix.cc b/diskio-unix.cc
index 0bfceef..fcd10e5 100644
--- a/diskio-unix.cc
+++ b/diskio-unix.cc
@@ -132,6 +132,9 @@ void DiskIO::Close(void) {
// (512). If the disk can't be opened at all, return a value of 0.
int DiskIO::GetBlockSize(void) {
int err = -1, blockSize = 0;
+#ifdef __sun__
+ struct dk_minfo minfo;
+#endif
// If disk isn't open, try to open it....
if (!isOpen) {
@@ -142,6 +145,11 @@ int DiskIO::GetBlockSize(void) {
#ifdef __APPLE__
err = ioctl(fd, DKIOCGETBLOCKSIZE, &blockSize);
#endif
+#ifdef __sun__
+ err = ioctl(fd, DKIOCGMEDIAINFO, &minfo);
+ if (err == 0)
+ blockSize = minfo.dki_lbsize;
+#endif
#if defined (__FreeBSD__) || defined (__FreeBSD_kernel__)
err = ioctl(fd, DIOCGSECTORSIZE, &blockSize);
#endif
@@ -217,13 +225,17 @@ int DiskIO::DiskSync(void) {
if (isOpen) {
sync();
-#ifdef __APPLE__
+#if defined(__APPLE__) || defined(__sun__)
cout << "Warning: The kernel may continue to use old or deleted partitions.\n"
<< "You should reboot or remove the drive.\n";
/* don't know if this helps
* it definitely will get things on disk though:
* http://topiks.org/mac-os-x/0321278542/ch12lev1sec8.html */
+#ifdef __sun__
+ i = ioctl(fd, DKIOCFLUSHWRITECACHE);
+#else
i = ioctl(fd, DKIOCSYNCHRONIZECACHE);
+#endif
platformFound++;
#endif
#if defined (__FreeBSD__) || defined (__FreeBSD_kernel__)
@@ -377,6 +389,9 @@ uint64_t DiskIO::DiskSize(int *err) {
off_t bytes = 0; // size in bytes
struct stat64 st;
int platformFound = 0;
+#ifdef __sun__
+ struct dk_minfo minfo;
+#endif
// If disk isn't open, try to open it....
if (!isOpen) {
@@ -393,6 +408,12 @@ uint64_t DiskIO::DiskSize(int *err) {
*err = ioctl(fd, DKIOCGETBLOCKCOUNT, &sectors);
platformFound++;
#endif
+#ifdef __sun__
+ *err = ioctl(fd, DKIOCGMEDIAINFO, &minfo);
+ if (*err == 0)
+ sectors = minfo.dki_capacity;
+ platformFound++;
+#endif
#if defined (__FreeBSD__) || defined (__FreeBSD_kernel__)
*err = ioctl(fd, DIOCGMEDIASIZE, &bytes);
long long b = GetBlockSize();