Back to index

lshw  02.16
blockio.cc
Go to the documentation of this file.
00001 /*
00002  * blockio.cc
00003  *
00004  *
00005  */
00006 
00007 #define _LARGEFILE_SOURCE
00008 #define _FILE_OFFSET_BITS 64
00009 
00010 #include "version.h"
00011 #include "blockio.h"
00012 #include "osutils.h"
00013 #include <stdio.h>
00014 #include <string.h>
00015 #include <sys/types.h>
00016 #include <sys/stat.h>
00017 #include <fcntl.h>
00018 #include <unistd.h>
00019 #include <stdint.h>
00020 
00021 __ID("@(#) $Id: blockio.cc 2433 2012-01-10 22:01:30Z lyonel $");
00022 
00023 ssize_t readlogicalblocks(source & s,
00024 void * buffer,
00025 long long pos, long long count)
00026 {
00027   long long result = 0;
00028 
00029   memset(buffer, 0, count*s.blocksize);
00030 
00031                                                   /* attempt to read past the end of the section */
00032   if((s.size>0) && ((pos+count)*s.blocksize>s.size)) return 0;
00033 
00034   result = lseek(s.fd, s.offset + pos*s.blocksize, SEEK_SET);
00035 
00036   if(result == -1) return 0;
00037 
00038   result = read(s.fd, buffer, count*s.blocksize);
00039 
00040   if(result!=count*s.blocksize)
00041     return 0;
00042   else
00043     return count;
00044 }