blockio.cc
1 /* 2 * blockio.cc 3 * 4 * 5 */ 6 7 #define _LARGEFILE_SOURCE 8 #define _FILE_OFFSET_BITS 64 9 10 #include "version.h" 11 #include "blockio.h" 12 #include "osutils.h" 13 #include <stdio.h> 14 #include <string.h> 15 #include <sys/types.h> 16 #include <sys/stat.h> 17 #include <fcntl.h> 18 #include <unistd.h> 19 #include <stdint.h> 20 21 __ID("@(#) $Id$"); 22 23 ssize_t readlogicalblocks(source & s, 24 void * buffer, 25 long long pos, long long count) 26 { 27 long long result = 0; 28 29 memset(buffer, 0, count*s.blocksize); 30 31 /* attempt to read past the end of the section */ 32 if((s.size>0) && ((pos+count)*s.blocksize>s.size)) return 0; 33 34 result = lseek(s.fd, s.offset + pos*s.blocksize, SEEK_SET); 35 36 if(result == -1) return 0; 37 38 result = read(s.fd, buffer, count*s.blocksize); 39 40 if(result!=count*s.blocksize) 41 return 0; 42 else 43 return count; 44 }