summaryrefslogtreecommitdiff
path: root/diskio-unix.cc
diff options
context:
space:
mode:
authorsrs5694 <srs5694@users.sourceforge.net>2010-03-07 22:16:07 -0500
committersrs5694 <srs5694@users.sourceforge.net>2010-03-07 22:16:07 -0500
commit55d926192adc984462509b2966e23bc0d1129bbd (patch)
treebff8bea805e3fb0e15f7f3a0cd26a20fa12c5f29 /diskio-unix.cc
parentea17cffd083c839b7af3560d55ba697667277901 (diff)
downloadsgdisk-55d926192adc984462509b2966e23bc0d1129bbd.tar.gz
Updated project files for 0.6.5 release version.
Diffstat (limited to 'diskio-unix.cc')
-rw-r--r--diskio-unix.cc14
1 files changed, 9 insertions, 5 deletions
diff --git a/diskio-unix.cc b/diskio-unix.cc
index e955739..7d24301 100644
--- a/diskio-unix.cc
+++ b/diskio-unix.cc
@@ -34,7 +34,9 @@ void DiskIO::MakeRealName(void) {
realFilename = userFilename;
} // DiskIO::MakeRealName()
-// Open the currently on-record file for reading
+// Open the currently on-record file for reading. Returns 1 if the file is
+// already open or is opened by this call, 0 if opening the file doesn't
+// work.
int DiskIO::OpenForRead(void) {
int shouldOpen = 1;
@@ -49,10 +51,11 @@ int DiskIO::OpenForRead(void) {
if (shouldOpen) {
fd = open(realFilename.c_str(), O_RDONLY);
if (fd == -1) {
- cerr << "Problem opening " << realFilename << " for reading! Error is " << errno << "\n";
- if (errno == EACCES) { // User is probably not running as root
+ cerr << "Problem opening " << realFilename << " for reading! Error is " << errno << ".\n";
+ if (errno == EACCES) // User is probably not running as root
cerr << "You must run this program as root or use sudo!\n";
- } // if
+ if (errno == ENOENT)
+ cerr << "The specified file does not exist!\n";
realFilename = "";
userFilename = "";
isOpen = 0;
@@ -105,7 +108,7 @@ void DiskIO::Close(void) {
// Returns block size of device pointed to by fd file descriptor. If the ioctl
// returns an error condition, print a warning but return a value of SECTOR_SIZE
-// (512)..
+// (512). If the disk can't be opened at all, return a value of 0.
int DiskIO::GetBlockSize(void) {
int err = -1, blockSize = 0;
@@ -134,6 +137,7 @@ int DiskIO::GetBlockSize(void) {
if ((errno != ENOTTY) && (errno != EINVAL)) {
cerr << "\aError " << errno << " when determining sector size! Setting sector size to "
<< SECTOR_SIZE << "\n";
+ cout << "Disk device is " << realFilename << "\n";
} // if
} // if (err == -1)
} // if (isOpen)