Click here to Skip to main content
16,003,404 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
void wipe_status(char * drive_path,long file_num, long gap)
{
    clear_console_screen();
   int p;
   p=a/20;
   printf("\n Total files :%d\n",p);
  // printf("\n Diffence Time:%dmin",file_num);
    fprintf(stdout, "%s - %s\n\nStatus: Wiping free space in progress [Press ENTER to stop]", PROGRAM_NAME, PROGRAM_VER);
    fprintf(stdout, "\nNote: Don't stop with CTRL+C otherwise the temporary files will not be deleted");
    fprintf(stdout, "\nInfo: %ld Mb written in %5.2f min\n", (long) ((long)file_num)*((long)DEFAULT_FILE_SIZE), (float)gap/60);
    fprintf(stdout, "\nTotal Mb:............%ld   Total Times:----------%5.2f min\n",a,a*(.00225) ); 
 
   // fprintf(stdout, "\nRemaining Time:----------%5.2f min ",((float)a*(.0005166))-(float)gap/60);
  //  fprintf(stdout, "\nRemaining Time:----------%5.2f min ",((float)a*(5.1*(10^(-3))))-(float)gap/60);
 //   if((a%20)==0)
//    {
      if(file_num<=p)
      {
                   
        fprintf(stdout, "\nProgress ............%ld Percent ",  ((100*file_num)/p));
        fprintf(stdout, "\nRemaining ...........%ld Percent ",  (100-((100*file_num)/p)));
      }
      else
      {
          p=p+1;
          fprintf(stdout, "\nProgress ............%ld Percent ",  ((100*file_num)/p));
          fprintf(stdout, "\nRemaining ...........%ld Percent ",  (100-((100*file_num)/p)));
      }
    fflush(stdout);
}
int wipe(char * drive_path, long file_size)
{
    
    FILE * f;
    int i;
    int const buf_size = 4096;
    long written;
    long file_num = 0;
    unsigned char buf[buf_size];
    unsigned int iseed;
    unsigned char filepath[256];
    int write_failed;
    time_t now_t, start_t;
    
    file_size = file_size * 1024000L;
    time(&start_t);
    wipe_status(drive_path,0L, 0L);
    
    while(1)
    {
       //sleep(1); //useless in this context
             
       written = 0;
       iseed = (unsigned int) time(NULL);
       srand (iseed);
       
       for (i=0; i<buf_size;>       {
           buf[i] = (unsigned char)( 255.0 * rand() / ( RAND_MAX + 0.0 ) );
       }  
       
       file_num++;
       write_failed = 0;  
       sprintf(filepath, "%s/%s%ld", drive_path, FILE_PREFIX, file_num);
       
       f = fopen(filepath, "wb");

       while(1){
          if (f == NULL){
             fprintf(stdout, "\nError: Unable to create file \"%s\"", filepath);
             write_failed = 1;
             break;
          }   
          
          if (stop_wiping == 1 || fwrite(buf, 1, buf_size, f) < buf_size){
             #if (DEBUG == 1)
             fprintf(stdout, "\nError: Unable to write to file \"%s\"", filepath);
             #endif
             write_failed = 1;
             break;
          }
          
          written += buf_size;
          
          if (written >= file_size){
             break;            
          }
       }
       
       if (f != NULL){
          fclose(f);
       }
       
       if (write_failed == 1){
          break;            
       }
      // wipe_status(drive_path,file_num, difftime(now_t, start_t));
      // if (file_num % 5 == 0){
          time(&now_t);
          wipe_status(drive_path,file_num, difftime(now_t, start_t));
          printf("\n Diffence Time:%5.2fmin",difftime);
     //  }
    } 
   
    delete_tmp_files(drive_path, file_num);
          
    return 0;
}


Please help me.
Posted
Updated 24-Oct-11 23:58pm
v2
Comments
CPallini 25-Oct-11 6:04am    
Uh? Please elaborate.
Richard MacCutchan 25-Oct-11 6:55am    
If you have a question then please edit the above and explain exactly what your problem is.
Albert Holguin 25-Oct-11 9:38am    
There's no question...

1 solution

printf("\n Diffence Time:%5.2fmin",difftime);
there is no variable difftime defined. Should this be a call to the function?
If it is a global variable, and there is a function by the same name this could get confusing for you and the compiler

I am going to assume that "exct" is a misspelling of "exact"
The following is portions of code I am using for benchmarking my thesis. It makes use of the High Precision Event Timer (HPET) which is part of modern computers. This is typically accurate to around 50-100 nanoseconds.

This code is a linux solution:
C++
#include <time.h>
#include <stdio.h>
#include <unistd.h> //for usleep()

void TimerStart(struct timespec *pSpec) {
   clock_gettime(CLOCK_REALTIME, pSpec);
}

double TimerStop(struct timespec *pSpec) {
   struct timespec t;
   clock_gettime(CLOCK_REALTIME, &t);
   return (t.tv_sec - pSpec->tv_sec) + (t.tv_nsec - pSpec->tv_nsec) * 1.0e-9;
}

//sample usage
int main() {
   struct timespec ts;
   TimerStart(&ts);
   usleep(1000000);
   printf("Time taken: %2.3f microseconds\n", TimerStop(&ts) * 1000000);
   return 0;
}


And this is the windows equivalent:
C++
#include <stdio.h>
#include <Windows.h>

void TimerStart(LARGE_INTEGER *pSpec) {
	QueryPerformanceCounter(pSpec);
}

double TimerStop(LARGE_INTEGER *pSpec) {
	LARGE_INTEGER li, liFreq;
	QueryPerformanceCounter(&li);
	QueryPerformanceFrequency(&liFreq); //If you want to optimise, do this once and save the result
	return (li.QuadPart - pSpec->QuadPart) / (double)liFreq.QuadPart;
}

//sample usage
int main() {
	LARGE_INTEGER ts;
	TimerStart(&ts);
	Sleep(1000);
	printf("Time taken: %2.3f microseconds\n", TimerStop(&ts) * 1000000);
	return 0;
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900