diff --git a/updateServer/src/situpdateInputFilter.c b/updateServer/src/situpdateInputFilter.c index 41fb0ba..03d05d8 100644 --- a/updateServer/src/situpdateInputFilter.c +++ b/updateServer/src/situpdateInputFilter.c @@ -28,12 +28,16 @@ int main(int argc,char **argv) int fd_partition=-1; static struct data_chunck_t data_chunk; static char all_chunkslist[MAX_CHUNKS_COUNT/8] = {0}; - off64_t seekpos=0,lastseekpos=0; + off64_t seekpos=0,lastseekpos=0, max_pos=0; + int retcode=0; + /* This variable tell to exit if we are arriving at the end of the device*/ + int exit_after_this_read=0; + if (argc != 3) return -1; data_chunk.chunck_tag = SIGNATURE; -/* Get chunklist */ + /* Get chunklist */ fchunks=open(argv[2],O_RDONLY); if (fchunks < 0) { fprintf(stderr,"Cannot open chunck list file,error %s\n",strerror(errno)); @@ -45,39 +49,70 @@ int main(int argc,char **argv) return 2; } close(fchunks); -/* Open partition for reading */ + + /* Open partition for reading */ fd_partition=open(argv[1],O_RDONLY); if (fd_partition < 0) { fprintf(stderr,"Cannot open partition %s,error %s\n",argv[1],strerror(errno)); return 3; } - r=1; + /* Let's find how big is our disk */ + max_pos=lseek64(fd_partition,0,SEEK_END); + if (max_pos < 0) { + fprintf(stderr, "Could not seek to the end of the device %s\n",strerror(errno)); + retcode=7; goto exit; + } + + /* Let's get back to the begining */ + if (lseek64(fd_partition,0,SEEK_SET) < 0) { + fprintf(stderr, "Could not seek to the begin of the device %s\n",strerror(errno)); + retcode=7; goto exit; + } + for (i=0;(i/8)