source: trunk/minix/commands/i386/mtools-3.9.7/minfo.c@ 10

Last change on this file since 10 was 9, checked in by Mattia Monga, 14 years ago

Minix 3.1.2a

File size: 4.3 KB
RevLine 
[9]1/*
2 * mlabel.c
3 * Make an MSDOS volume label
4 */
5
6#include "sysincludes.h"
7#include "msdos.h"
8#include "mainloop.h"
9#include "vfat.h"
10#include "mtools.h"
11#include "nameclash.h"
12
13static void usage(void)
14{
15 fprintf(stderr,
16 "Mtools version %s, dated %s\n", mversion, mdate);
17 fprintf(stderr,
18 "Usage: %s [-v] drive\n\t-v Verbose\n", progname);
19 exit(1);
20}
21
22
23static void displayInfosector(Stream_t *Stream, struct bootsector *boot)
24{
25 InfoSector_t *infosec;
26
27 if(WORD(ext.fat32.infoSector) == MAX32)
28 return;
29
30 infosec = (InfoSector_t *) safe_malloc(WORD(secsiz));
31 force_read(Stream, (char *) infosec,
32 (mt_off_t) WORD(secsiz) * WORD(ext.fat32.infoSector),
33 WORD(secsiz));
34 printf("\nInfosector:\n");
35 printf("signature=0x%08x\n", _DWORD(infosec->signature1));
36 if(_DWORD(infosec->count) != MAX32)
37 printf("free clusters=%u\n", _DWORD(infosec->count));
38 if(_DWORD(infosec->pos) != MAX32)
39 printf("last allocated cluster=%u\n", _DWORD(infosec->pos));
40}
41
42
43void minfo(int argc, char **argv, int type)
44{
45 struct bootsector boot0;
46#define boot (&boot0)
47 char name[EXPAND_BUF];
48 int media;
49 int tot_sectors;
50 struct device dev;
51 char *drive;
52 int verbose=0;
53 int c;
54 Stream_t *Stream;
55 struct label_blk_t *labelBlock;
56
57 while ((c = getopt(argc, argv, "v")) != EOF) {
58 switch (c) {
59 case 'v':
60 verbose = 1;
61 break;
62 default:
63 usage();
64 }
65 }
66
67 if(argc == optind)
68 usage();
69
70 for(;optind < argc; optind++) {
71 if(skip_drive(argv[optind]) == argv[optind])
72 usage();
73 drive = get_drive(argv[optind], NULL);
74
75 if(! (Stream = find_device(drive, O_RDONLY, &dev, boot,
76 name, &media, 0)))
77 exit(1);
78
79 tot_sectors = DWORD(bigsect);
80 SET_INT(tot_sectors, WORD(psect));
81 printf("device information:\n");
82 printf("===================\n");
83 printf("filename=\"%s\"\n", name);
84 printf("sectors per track: %d\n", dev.sectors);
85 printf("heads: %d\n", dev.heads);
86 printf("cylinders: %d\n\n", dev.tracks);
87 printf("mformat command line: mformat -t %d -h %d -s %d ",
88 dev.tracks, dev.heads, dev.sectors);
89 if(DWORD(nhs))
90 printf("-H %d ", DWORD(nhs));
91 printf("%s:\n", drive);
92 printf("\n");
93
94 printf("bootsector information\n");
95 printf("======================\n");
96 printf("banner:\"%8s\"\n", boot->banner);
97 printf("sector size: %d bytes\n", WORD(secsiz));
98 printf("cluster size: %d sectors\n", boot->clsiz);
99 printf("reserved (boot) sectors: %d\n", WORD(nrsvsect));
100 printf("fats: %d\n", boot->nfat);
101 printf("max available root directory slots: %d\n",
102 WORD(dirents));
103 printf("small size: %d sectors\n", WORD(psect));
104 printf("media descriptor byte: 0x%x\n", boot->descr);
105 printf("sectors per fat: %d\n", WORD(fatlen));
106 printf("sectors per track: %d\n", WORD(nsect));
107 printf("heads: %d\n", WORD(nheads));
108 printf("hidden sectors: %d\n", DWORD(nhs));
109 printf("big size: %d sectors\n", DWORD(bigsect));
110
111 if(WORD(fatlen)) {
112 labelBlock = &boot->ext.old.labelBlock;
113 } else {
114 labelBlock = &boot->ext.fat32.labelBlock;
115 }
116
117 printf("physical drive id: 0x%x\n",
118 labelBlock->physdrive);
119 printf("reserved=0x%x\n",
120 labelBlock->reserved);
121 printf("dos4=0x%x\n",
122 labelBlock->dos4);
123 printf("serial number: %08X\n",
124 _DWORD(labelBlock->serial));
125 printf("disk label=\"%11.11s\"\n",
126 labelBlock->label);
127 printf("disk type=\"%8.8s\"\n",
128 labelBlock->fat_type);
129
130 if(!WORD(fatlen)){
131 printf("Big fatlen=%u\n",
132 DWORD(ext.fat32.bigFat));
133 printf("Extended flags=0x%04x\n",
134 WORD(ext.fat32.extFlags));
135 printf("FS version=0x%04x\n",
136 WORD(ext.fat32.fsVersion));
137 printf("rootCluster=%u\n",
138 DWORD(ext.fat32.rootCluster));
139 if(WORD(ext.fat32.infoSector) != MAX32)
140 printf("infoSector location=%d\n",
141 WORD(ext.fat32.infoSector));
142 if(WORD(ext.fat32.backupBoot) != MAX32)
143 printf("backup boot sector=%d\n",
144 WORD(ext.fat32.backupBoot));
145 displayInfosector(Stream,boot);
146 }
147
148 if(verbose) {
149 int size;
150 unsigned char *buf;
151
152 printf("\n");
153 size = WORD(secsiz);
154
155 buf = (unsigned char *) malloc(size);
156 if(!buf) {
157 fprintf(stderr, "Out of memory error\n");
158 exit(1);
159 }
160
161 size = READS(Stream, buf, (mt_off_t) 0, size);
162 if(size < 0) {
163 perror("read boot sector");
164 exit(1);
165 }
166
167 print_sector("Boot sector hexdump", buf, size);
168 }
169 }
170
171 exit(0);
172}
Note: See TracBrowser for help on using the repository browser.