Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

c/c++ programmer to backup whole hard disk

$
0
0
hey guys,

was searching net for software to backup hardive and found many of them but i want to code one of my own. will it be similar to copying file?? n i want copy of whole hard drive inculding structure and data like any typical hardrive backup software like GHOST. thanks :helpsmilie:

this code ws ment to copy file but as every thing in linux is treated as file it should work to copy hard drive so i passed argument /dev/sda but didnt seems to work.

#include<stdio.h>
#include<stdlib.h>
int main(int argc, char *argv[])
{
 const int buffsize=200; 
 FILE *infile,*outfile;
 char buffer[buffsize],op='n';
 int size,check=0,i,d,m;
 //inf=argv[1];
 //of=argv[2]; 
 /*
 printf("enter source file name: ");
 scanf("%s",inf);
 printf("enter destination file name: ");
 scanf("%s",of);
 */ 
  
 infile=fopen(argv[1],"r");
 outfile=fopen(argv[2],"r"); 
  
 if(infile==NULL)
 { 
  printf("\nERROR :: input does not exist\n");   
  check=1;
  return 0;
 }//end if 
 
 if(outfile!=NULL)
 {    
  printf("\nERROR :: output file already exist\n do you want to overwrite?? (y/n)");
  fflush(stdin);
  scanf("%c",&op);
  scanf("%c",&op);
  if(op=='n')
   check=1; 
 } 

 if(check==1)
 {
  exit(0);
 }
 
 outfile=fopen(argv[2],"w");
 
 fseek(infile,0,SEEK_END);
 size=ftell(infile);
 printf("size : %d\n",size);   
 rewind(infile);
 
 if(size > buffsize)
 { 
  m=size/buffsize;
  if(m==0) m=1; 
 
  d=size-(m*buffsize);  
  printf("\n");
  for(i=0;i<m;i++)
  {  
   fseek(infile,i*buffsize,SEEK_SET);
   fseek(outfile,i*buffsize,SEEK_SET);
   fread(buffer,buffsize,1,infile);    
   fwrite(buffer,buffsize,1,outfile);    
  }//end for
  fseek(infile,m*buffsize,SEEK_SET);
  fseek(outfile,0,SEEK_END);
  fread(buffer,d,1,infile);    
  fwrite(buffer,d,1,outfile); 
 }//end if
 else
 { 
  fread(buffer,size,1,infile);    
  fwrite(buffer,size,1,outfile);
 }//end else
  
 fclose(infile);
 fclose(outfile); 
}//end main



Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>