Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <dos.h>
- #include <memory.h>
- #include <stdlib.h>
- #include <string.h>
- struct BOOT { //for FAT16
- char jmp[3];
- char OEM[8];
- int bytes_per_sector;
- char sectors_per_cluster;
- int reserved;
- char FAT_cnt;
- int ROOT_size;
- int total_sectors;
- char media;
- int FAT_size;
- int sectors_per_track;
- int head_cnt;
- long hidden_sectors;
- long total_sectors_long;
- char unknown[3];
- long serial;
- char volume[11];
- char FAT_type[8];
- char loader[448];
- char mark[2];
- };
- struct ROOT {
- char name[8];
- char ext[3];
- char attr;
- char reserved[10];
- char time[2];
- char date[2];
- int first_cluster;
- long size;
- };
- void main()
- {
- int i;
- int drive = 3;
- BOOT boot;
- int res = absread(drive, 1, 0, &boot);
- unsigned int *fat = (unsigned int *)malloc (boot.FAT_size * boot.bytes_per_sector);
- res = absread(drive, boot.FAT_size, boot.reserved, fat);
- unsigned int n = 5;
- unsigned int cur = n;
- int num_byte = boot.ROOT_size * 32;
- ROOT *root = (ROOT *)malloc(num_byte);
- if(root == NULL) return;
- int num_sector = num_byte / boot.bytes_per_sector;
- int root_begin = boot.reserved + boot.FAT_size * boot.FAT_cnt;
- res = absread(drive, num_sector, root_begin, (void *)root);
- //Printing first 3 items of root
- printf("1. In ten va do dai cac file trong thu muc goc\n");
- printf("Filename\t Size \n");
- for(i = 0; i < boot.ROOT_size; i++){
- if(root[i].name[0] == ' ') continue;
- for(int j = 0; j < 8 && root[i].name[j] != ' '; j++)
- printf("%c", root[i].name[j]);
- printf("\t");
- printf("%d \t %ld\n", root[i].first_cluster, root[i].size);
- if(root[i].size==0) break;
- }
- free(root);
- free(fat);
- getchar();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement