#include <vsidevice.h>
Public Member Functions | |
CvsiDevice () | |
~CvsiDevice () | |
int | Open (const char *deviceName) |
int | OpenDeviceAgain (const char *deviceName, u64 Size) |
int | Close () |
int | Read (u64 startingByte, int numberBytes, char *data) |
int | Write (u64 startingByte, int numberBytes, char *data) |
int | SectorSize () |
u64 | Size () |
Private Attributes | |
int | m_Handle |
int | m_SectorSize |
u64 | m_Size |
Definition at line 34 of file vsidevice.h.
CvsiDevice::CvsiDevice | ( | ) |
Definition at line 55 of file vsidevice.cpp.
00056 { 00057 m_Handle = -1; 00058 m_SectorSize = 0; 00059 m_Size = 0; 00060 }
CvsiDevice::~CvsiDevice | ( | ) |
Definition at line 63 of file vsidevice.cpp.
00064 { 00065 Close(); 00066 }
int CvsiDevice::Close | ( | void | ) |
Definition at line 69 of file vsidevice.cpp.
int CvsiDevice::Open | ( | const char * | deviceName | ) |
Definition at line 80 of file vsidevice.cpp.
00081 { 00082 // get a handle to the device 00083 m_Handle = open( deviceName, O_RDWR ); 00084 00085 if( m_Handle == -1) 00086 { 00087 RioErr << "CvsiDevice: Could not open device "<< deviceName << " with RDRW permissions, trying to open it with RDONLY permission" << endl 00088 << strerror(errno) << endl; 00089 m_Handle = open( deviceName, O_RDONLY); 00090 00091 if( m_Handle == -1) 00092 { 00093 RioErr << "CvsiDevice: Could not open device "<< deviceName << " with RDONLY permission" << endl 00094 << strerror(errno) << endl; 00095 return( VSI_ERROR_DEVICE_NOT_EXIST); 00096 } 00097 } 00098 00099 // get number of sectors (512 bytes each) on disk 00100 m_SectorSize = 512; 00101 00102 off_t disknosect; 00103 int rc; 00104 rc = ioctl(m_Handle, BLKGETSIZE, &disknosect); 00105 if(rc != 0) 00106 { 00107 if(errno == ENOTTY)/* perhaps is file, not disk */ 00108 { 00109 rc = lseek(m_Handle, 0, SEEK_END); 00110 if(rc == -1) 00111 { 00112 Close(); 00113 RioErr << "CvsiDevice: seek error." << endl; 00114 return(VSI_ERROR_DEVICE_SEEK); 00115 } 00116 m_Size = rc; // normal file 00117 } 00118 else 00119 { 00120 Close(); 00121 RioErr << "CvsiDevice: Could not get Device size." << endl; 00122 return(VSI_ERROR_DEVICE_GETSIZE); 00123 } 00124 } 00125 else 00126 { 00127 m_Size = ( (u64) disknosect) * m_SectorSize; 00128 } 00129 00130 return(0); 00131 }
int CvsiDevice::OpenDeviceAgain | ( | const char * | deviceName, | |
u64 | Size | |||
) |
Definition at line 135 of file vsidevice.cpp.
00136 { 00137 // get a handle to the device 00138 m_Handle = open( deviceName, O_RDWR ); 00139 00140 if( m_Handle == -1) 00141 { 00142 RioErr << "CvsiDevice: Could not open device "<< deviceName << " with RDRW permissions, trying to open it with RDONLY permission" << endl 00143 << strerror(errno) << endl; 00144 m_Handle = open( deviceName, O_RDONLY); 00145 00146 if( m_Handle == -1) 00147 { 00148 RioErr << "CvsiDevice: Could not open device "<< deviceName << " with RDONLY permission" << endl 00149 << strerror(errno) << endl; 00150 return( VSI_ERROR_DEVICE_NOT_EXIST); 00151 } 00152 } 00153 00154 m_SectorSize = 512; 00155 m_Size = Size; 00156 00157 return(0); 00158 }
int CvsiDevice::Read | ( | u64 | startingByte, | |
int | numberBytes, | |||
char * | data | |||
) |
Definition at line 203 of file vsidevice.cpp.
00204 { 00205 int numberBytesRead = 0; 00206 //u32 startingByteLow = 0; 00207 //u32 startingByteHigh = 0; 00208 s64 seekresult; 00209 00210 if( ( startingByte >= m_Size ) || 00211 ( startingByte >= m_Size + numberBytes ) || 00212 ( numberBytes < 0 )) 00213 { 00214 return ( VSI_ERROR_DEVICE_POSITION ); 00215 } 00216 00217 // extract high and low 32 bit values of startingByte 00218 //startingByteLow = (u32) ( startingByte & 0xFFFFFFFF ); 00219 //startingByteHigh = (u32) ( startingByte >> 32 ); 00220 00221 // set file pointer to beginning of block 00222 //int rc = syscall( __NR__llseek, m_Handle, 00223 // startingByteHigh, startingByteLow, 00224 // &seekresult, 00225 // SEEK_SET ); 00226 seekresult = lseek64( m_Handle, startingByte, SEEK_SET ); 00227 //if(rc != 0) 00228 if( seekresult < 0 ) 00229 { 00230 return(VSI_ERROR_DEVICE_SEEK); 00231 } 00232 00233 // read the data 00234 numberBytesRead = read(m_Handle, data, numberBytes); 00235 00236 if(numberBytesRead != numberBytes) 00237 { 00238 return( VSI_ERROR_DEVICE_READ); 00239 } 00240 00241 return(0); 00242 }
int CvsiDevice::SectorSize | ( | ) |
Definition at line 245 of file vsidevice.cpp.
00246 { 00247 return m_SectorSize; 00248 }
u64 CvsiDevice::Size | ( | ) |
Definition at line 251 of file vsidevice.cpp.
00252 { 00253 return m_Size; 00254 }
int CvsiDevice::Write | ( | u64 | startingByte, | |
int | numberBytes, | |||
char * | data | |||
) |
Definition at line 161 of file vsidevice.cpp.
00162 { 00163 int numberBytesWritten = 0; 00164 //u32 startingByteHigh = 0; 00165 //u32 startingByteLow = 0; 00166 s64 seekresult; 00167 00168 if( ( startingByte >= m_Size ) || 00169 ( startingByte >= m_Size + numberBytes ) || 00170 ( numberBytes < 0 )) 00171 { 00172 return (VSI_ERROR_DEVICE_POSITION); 00173 } 00174 00175 // extract high and low 32 bit values of startingByte 00176 //startingByteLow = (u32) ( startingByte & 0xFFFFFFFF ); 00177 //startingByteHigh = (u32) ( startingByte >> 32 ); 00178 00179 // set file pointer to beginning of block 00180 //int rc = syscall( __NR__llseek, m_Handle, 00181 // startingByteHigh, startingByteLow, 00182 // &seekresult, 00183 // SEEK_SET ); 00184 seekresult = lseek64( m_Handle, startingByte, SEEK_SET ); 00185 //if(rc != 0) 00186 if( seekresult < 0 ) 00187 { 00188 return(VSI_ERROR_DEVICE_SEEK); 00189 } 00190 00191 // write the data 00192 numberBytesWritten = write(m_Handle, data, numberBytes); 00193 00194 if(numberBytesWritten != numberBytes) 00195 { 00196 return( VSI_ERROR_DEVICE_WRITE ); 00197 } 00198 00199 return(0); 00200 }
int CvsiDevice::m_Handle [private] |
Definition at line 48 of file vsidevice.h.
int CvsiDevice::m_SectorSize [private] |
Definition at line 49 of file vsidevice.h.
u64 CvsiDevice::m_Size [private] |
Definition at line 50 of file vsidevice.h.