1 /*
2
3 File: fatn.c
4
5 Copyright (C) 1998-2009 Christophe GRENIER <grenier@cgsecurity.org>
6
7 This software is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License along
18 with this program; if not, write the Free Software Foundation, Inc., 51
19 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20
21 */
22
23 #ifdef HAVE_CONFIG_H
24 #include <config.h>
25 #endif
26
27 #ifdef HAVE_NCURSES
28 #include <stdio.h>
29 #include "types.h"
30 #include "common.h"
31 #include "intrf.h"
32 #include "intrfn.h"
33 #include "fat.h"
34 #include "fatn.h"
35 #include "fat_common.h"
36
dump_fat_info_ncurses(const struct fat_boot_sector * fh1,const upart_type_t upart_type,const unsigned int sector_size)37 int dump_fat_info_ncurses(const struct fat_boot_sector*fh1, const upart_type_t upart_type, const unsigned int sector_size)
38 {
39 switch(upart_type)
40 {
41 case UP_FAT12:
42 wprintw(stdscr,"FAT : 12\n");
43 break;
44 case UP_FAT16:
45 wprintw(stdscr,"FAT : 16\n");
46 break;
47 case UP_FAT32:
48 wprintw(stdscr,"FAT : 32\n");
49 break;
50 default:
51 wprintw(stdscr,"Not a FAT\n");
52 return 0;
53 }
54 wprintw(stdscr,"cluster_size %u\n", fh1->sectors_per_cluster);
55 wprintw(stdscr,"reserved %u\n", le16(fh1->reserved));
56 if(fat_sectors(fh1)!=0)
57 wprintw(stdscr,"sectors %u\n", fat_sectors(fh1));
58 if(le32(fh1->total_sect)!=0)
59 wprintw(stdscr,"total_sect %u\n", (unsigned int)le32(fh1->total_sect));
60 if(upart_type==UP_FAT32)
61 {
62 wprintw(stdscr,"fat32_length %u\n", (unsigned int)le32(fh1->fat32_length));
63 wprintw(stdscr,"root_cluster %u\n", (unsigned int)le32(fh1->root_cluster));
64 wprintw(stdscr,"flags %04X\n", le16(fh1->flags));
65 wprintw(stdscr,"version %u.%u\n", fh1->version[0], fh1->version[1]);
66 wprintw(stdscr,"root_cluster %u\n", (unsigned int)le32(fh1->root_cluster));
67 wprintw(stdscr,"info_sector %u\n", le16(fh1->info_sector));
68 wprintw(stdscr,"backup_boot %u\n", le16(fh1->backup_boot));
69 if(fat32_get_free_count((const unsigned char*)fh1,sector_size)==0xFFFFFFFF)
70 wprintw(stdscr,"free_count uninitialised\n");
71 else
72 wprintw(stdscr,"free_count %lu\n",fat32_get_free_count((const unsigned char*)fh1,sector_size));
73 if(fat32_get_next_free((const unsigned char*)fh1,sector_size)==0xFFFFFFFF)
74 wprintw(stdscr,"next_free uninitialised\n");
75 else
76 wprintw(stdscr,"next_free %lu\n",fat32_get_next_free((const unsigned char*)fh1,sector_size));
77 } else {
78 wprintw(stdscr,"fat_length %u\n", le16(fh1->fat_length));
79 wprintw(stdscr,"dir_entries %u\n", get_dir_entries(fh1));
80 }
81 return 0;
82 }
83
dump_2fat_info_ncurses(const struct fat_boot_sector * fh1,const struct fat_boot_sector * fh2,const upart_type_t upart_type,const unsigned int sector_size)84 int dump_2fat_info_ncurses(const struct fat_boot_sector*fh1, const struct fat_boot_sector*fh2, const upart_type_t upart_type, const unsigned int sector_size)
85 {
86 switch(upart_type)
87 {
88 case UP_FAT12:
89 wprintw(stdscr,"FAT : 12\n");
90 break;
91 case UP_FAT16:
92 wprintw(stdscr,"FAT : 16\n");
93 break;
94 case UP_FAT32:
95 wprintw(stdscr,"FAT : 32\n");
96 break;
97 default:
98 wprintw(stdscr,"Not a FAT\n");
99 return 1;
100 }
101 wprintw(stdscr,"cluster_size %u %u\n", fh1->sectors_per_cluster, fh2->sectors_per_cluster);
102 wprintw(stdscr,"reserved %u %u\n", le16(fh1->reserved),le16(fh2->reserved));
103 if(fat_sectors(fh1)!=0 || fat_sectors(fh2)!=0)
104 wprintw(stdscr,"sectors %u %u\n", fat_sectors(fh1), fat_sectors(fh2));
105 if(le32(fh1->total_sect)!=0 || le32(fh2->total_sect)!=0)
106 wprintw(stdscr,"total_sect %u %u\n", (unsigned int)le32(fh1->total_sect), (unsigned int)le32(fh2->total_sect));
107 if(upart_type==UP_FAT32)
108 {
109 wprintw(stdscr,"fat32_length %u %u\n", (unsigned int)le32(fh1->fat32_length), (unsigned int)le32(fh2->fat32_length));
110 wprintw(stdscr,"root_cluster %u %u\n", (unsigned int)le32(fh1->root_cluster), (unsigned int)le32(fh2->root_cluster));
111 wprintw(stdscr,"free_count ");
112 if(fat32_get_free_count((const unsigned char*)fh1,sector_size)==0xFFFFFFFF)
113 wprintw(stdscr,"uninitialised ");
114 else
115 wprintw(stdscr,"%lu ",fat32_get_free_count((const unsigned char*)fh1,sector_size));
116 if(fat32_get_free_count((const unsigned char*)fh2,sector_size)==0xFFFFFFFF)
117 wprintw(stdscr,"uninitialised\n");
118 else
119 wprintw(stdscr,"%lu\n",fat32_get_free_count((const unsigned char*)fh2,sector_size));
120 wprintw(stdscr,"next_free ");
121 if(fat32_get_next_free((const unsigned char*)fh1,sector_size)==0xFFFFFFFF)
122 wprintw(stdscr,"uninitialised ");
123 else
124 wprintw(stdscr,"%lu ",fat32_get_next_free((const unsigned char*)fh1,sector_size));
125 if(fat32_get_next_free((const unsigned char*)fh2,sector_size)==0xFFFFFFFF)
126 wprintw(stdscr,"uninitialised\n");
127 else
128 wprintw(stdscr,"%lu\n",fat32_get_next_free((const unsigned char*)fh2,sector_size));
129 } else {
130 wprintw(stdscr,"fat_length %u %u\n", le16(fh1->fat_length), le16(fh2->fat_length));
131 wprintw(stdscr,"dir_entries %u %u\n", get_dir_entries(fh1), get_dir_entries(fh2));
132 }
133 return 0;
134 }
135 #endif
136