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);
- printf("2. Tim 1 file co ten cho truoc va so thu tu cluster dau tien cua file do\n");
- int k;
- char str[9];
- int first_cluster = -1;
- for(i = 0; i < boot.ROOT_size; i++){
- for(k = 0; k < 8 && root[i].name[k] != ' '; k++)
- str[k] = root[i].name[k];
- str[k] = 0;
- char filename[8];
- printf("\n Enter a file name:");
- scanf("%s",filename);
- if(strcmp(str, filename) == 0){
- first_cluster = root[i].first_cluster;
- break;
- }
- }
- printf("So thu tu cluster dau tien %d", first_cluster);
- free(root);
- free(fat);
- getchar();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement