Advertisement
anhkiet2507

Cau3De2

Oct 6th, 2022
1,274
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.48 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <dos.h>
  3. #include <memory.h>
  4. #include <stdlib.h>
  5. #include <string.h>
  6.  
  7. struct BOOT {  //for FAT16
  8.     char jmp[3];
  9.     char OEM[8];
  10.     int bytes_per_sector;
  11.     char sectors_per_cluster;
  12.     int reserved;
  13.     char FAT_cnt;
  14.     int ROOT_size;
  15.     int total_sectors;
  16.     char media;
  17.     int FAT_size;
  18.     int sectors_per_track;
  19.     int head_cnt;
  20.     long hidden_sectors;
  21.     long total_sectors_long;
  22.     char unknown[3];
  23.     long serial;
  24.     char volume[11];
  25.     char FAT_type[8];
  26.     char loader[448];
  27.     char mark[2];
  28. };
  29.  
  30. struct ROOT {
  31.     char name[8];
  32.     char ext[3];
  33.     char attr;
  34.     char reserved[10];
  35.     char time[2];
  36.     char date[2];
  37.     int first_cluster;
  38.     long size;
  39. };
  40.  
  41. void main()
  42. {
  43.     int i;
  44.     int drive = 3;
  45.     BOOT boot;
  46.  
  47.     int res = absread(drive, 1, 0, &boot);
  48.     unsigned int *fat = (unsigned int *)malloc (boot.FAT_size * boot.bytes_per_sector);
  49.  
  50.  
  51.     res = absread(drive, boot.FAT_size, boot.reserved, fat);
  52.  
  53.     unsigned int n = 5;
  54.     unsigned int cur = n;
  55.  
  56.     int num_byte = boot.ROOT_size * 32;
  57.  
  58.     ROOT *root = (ROOT *)malloc(num_byte);
  59.     if(root == NULL) return;
  60.  
  61.     int num_sector = num_byte / boot.bytes_per_sector;
  62.     int root_begin = boot.reserved + boot.FAT_size * boot.FAT_cnt;
  63.  
  64.     res = absread(drive, num_sector, root_begin, (void *)root);
  65.  
  66.  
  67.     printf("3. In ra bang bit cua 100 cluster dau tien\n");
  68.     for (i = 2; i < 100; i++){ //first 2 clusters are not used
  69.         if(fat[i] == 0) {
  70.             printf("%d ", 1);
  71.         }else{
  72.             printf("%d ", 0);
  73.         }
  74.     }
  75.    
  76.  
  77.  
  78.     free(root);
  79.     free(fat);
  80.  
  81.     getchar();
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement