Advertisement
anhkiet2507

Cau1De2

Oct 6th, 2022 (edited)
1,299
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.68 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.     //Printing first 3 items of root
  68.     printf("1. In ten va do dai cac file trong thu muc goc\n");
  69.     printf("Filename\t Size \n");
  70.     for(i = 0; i < boot.ROOT_size; i++){
  71.         if(root[i].name[0] == ' ') continue;
  72.         for(int j = 0; j < 8 && root[i].name[j] != ' '; j++)
  73.             printf("%c", root[i].name[j]);
  74.         printf("\t");
  75.         printf("%d \t %ld\n", root[i].first_cluster, root[i].size);
  76.         if(root[i].size==0) break;
  77.     }
  78.  
  79.  
  80.     free(root);
  81.     free(fat);
  82.  
  83.     getchar();
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement