Advertisement
anhkiet2507

Program to display content of first 30 non-empty FAT cell

Oct 5th, 2022
1,384
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.12 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.  
  44.     int drive = 3; //A=0, B=1, C=2, D=3 ...
  45.  
  46.     //Reading boot sector from disk D
  47.     BOOT boot;
  48.     int res = absread(drive, 1, 0, &boot);
  49.     unsigned int *fat = (unsigned int *)malloc (boot.FAT_size * boot.bytes_per_sector);
  50.     //printing first 30 non-empty FAT cells
  51.     printf("Content of first 30 non-empty FAT cells:");
  52.     int i = 0, num = 0;
  53.     int total = 30;
  54.     while(num<total){
  55.         if(fat[i]!=0){
  56.             printf("%u ", fat[i]);
  57.             num++;
  58.         }
  59.         i++;
  60.    
  61.     getchar();
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement