home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / utils / disk-man / mtools-3.000 / mtools-3 / mtools-3.0 / mbadblocks.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-05-08  |  1.5 KB  |  72 lines

  1. /*
  2.  * mbadblocks.c
  3.  * Mark bad blocks on disk
  4.  *
  5.  */
  6.  
  7. #include "sysincludes.h"
  8. #include "msdos.h"
  9. #include "mtools.h"
  10. #include "streamcache.h"
  11. #include "fsP.h"
  12.  
  13. void mbadblocks(int argc, char **argv, int type)
  14. {
  15.     int i;
  16.     char *in_buf;
  17.     int in_len;
  18.     long start;
  19.     struct StreamCache_t sc;
  20.     Fs_t *Fs;
  21.     Stream_t *Dir;
  22.     int ret;
  23.  
  24.     if (argc != 2) {
  25.         fprintf(stderr, "Mtools version %s, dated %s\n", 
  26.             mversion, mdate);
  27.         fprintf(stderr, "Usage: %s [-V] device\n", argv[0]);
  28.         cleanup_and_exit(1);
  29.     }
  30.  
  31.     init_sc(&sc);
  32.  
  33.     Dir = open_subdir(&sc, argv[1], O_RDWR, (Stream_t **) &Fs);
  34.  
  35.     if (!Fs) {
  36.         fprintf(stderr,"%s: Cannot initialize drive\n", argv[0]);
  37.         cleanup_and_exit(1);
  38.     }
  39.  
  40.     in_len = Fs->cluster_size * Fs->sector_size;
  41.     in_buf = safe_malloc(in_len);
  42.     for(i=0; i < Fs->dir_start + Fs->dir_len; i++ ){
  43.         ret = READS(Fs->Next, in_buf, i * Fs->sector_size, 
  44.                Fs->sector_size);
  45.         if( ret < 0 ){
  46.             perror("early error");
  47.             cleanup_and_exit(1);
  48.         }
  49.         if(ret < Fs->sector_size){
  50.             fprintf(stderr,"end of file in file_read\n");
  51.             cleanup_and_exit(1);
  52.         }
  53.     }
  54.         
  55.     in_len = Fs->cluster_size * Fs->sector_size;
  56.     for(i=2; i< Fs->num_clus + 2; i++){
  57.         if(Fs->fat_decode((Fs_t*)Fs,i))
  58.             continue;
  59.         start = (i - 2) * Fs->cluster_size + 
  60.             Fs->dir_start + Fs->dir_len;
  61.         ret = READS(Fs->Next, in_buf, start * Fs->sector_size, in_len);
  62.         if(ret < in_len ){
  63.             printf("Bad cluster %d found\n", i);
  64.             Fs->fat_encode((Fs_t*)Fs, i, 0xfff7);
  65.             continue;
  66.         }
  67.     }
  68.     FREE(&Dir);
  69.     finish_sc(&sc);
  70.     cleanup_and_exit(0);
  71. }
  72.