Lines Matching refs:h

107 #define	PC_BPSEC(h)	ltohs((h)->bs.bps[0])  argument
108 #define PC_RESSEC(h) ltohs((h)->bs.res_sec[0]) argument
109 #define PC_NROOTENT(h) ltohs((h)->bs.rdirents[0]) argument
110 #define PC_NSEC(h) ltohs((h)->bs.numsect[0]) argument
111 #define PC_DRVNUM(h) (FSTYP_IS_32(h) ? (h)->bs32.f_drvnum : \ argument
112 (h)->bs16.f_drvnum)
113 #define PC_VOLID(a) (FSTYP_IS_32(h) ? ltohi((h)->bs32.f_volid[0]) : \
114 ltohi((h)->bs16.f_volid[0]))
115 #define PC_LABEL_ADDR(a) (FSTYP_IS_32(h) ? \
116 &((h)->bs32.f_label[0]) : &((h)->bs16.f_label[0]))
118 #define FSTYP_IS_32(h) ((h)->fattype == 32) argument
123 static int read_bootsec(fstyp_pcfs_t *h);
124 static int valid_media(fstyp_pcfs_t *h);
125 static int well_formed(fstyp_pcfs_t *h);
126 static void calculate_parameters(fstyp_pcfs_t *h);
127 static void determine_fattype(fstyp_pcfs_t *h);
128 static void get_label(fstyp_pcfs_t *h);
129 static void get_label_16(fstyp_pcfs_t *h);
130 static void get_label_32(fstyp_pcfs_t *h);
131 static int next_cluster_32(fstyp_pcfs_t *h, int n);
132 static boolean_t dir_find_label(fstyp_pcfs_t *h, struct pcdir *d, int nent);
133 static int is_pcfs(fstyp_pcfs_t *h);
134 static int dumpfs(fstyp_pcfs_t *h, FILE *fout, FILE *ferr);
135 static int get_attr(fstyp_pcfs_t *h);
146 struct fstyp_pcfs *h; in fstyp_mod_init() local
148 if ((h = calloc(1, sizeof (struct fstyp_pcfs))) == NULL) { in fstyp_mod_init()
151 h->fd = fd; in fstyp_mod_init()
152 h->offset = offset; in fstyp_mod_init()
154 *handle = (fstyp_mod_handle_t)h; in fstyp_mod_init()
161 struct fstyp_pcfs *h = (struct fstyp_pcfs *)handle; in fstyp_mod_fini() local
163 if (h->attr == NULL) { in fstyp_mod_fini()
164 nvlist_free(h->attr); in fstyp_mod_fini()
165 h->attr = NULL; in fstyp_mod_fini()
167 free(h); in fstyp_mod_fini()
173 struct fstyp_pcfs *h = (struct fstyp_pcfs *)handle; in fstyp_mod_ident() local
175 return (is_pcfs(h)); in fstyp_mod_ident()
181 struct fstyp_pcfs *h = (struct fstyp_pcfs *)handle; in fstyp_mod_get_attr() local
184 if (h->attr == NULL) { in fstyp_mod_get_attr()
185 if (nvlist_alloc(&h->attr, NV_UNIQUE_NAME_TYPE, 0)) { in fstyp_mod_get_attr()
188 if ((error = get_attr(h)) != 0) { in fstyp_mod_get_attr()
189 nvlist_free(h->attr); in fstyp_mod_get_attr()
190 h->attr = NULL; in fstyp_mod_get_attr()
195 *attrp = h->attr; in fstyp_mod_get_attr()
202 struct fstyp_pcfs *h = (struct fstyp_pcfs *)handle; in fstyp_mod_dump() local
204 return (dumpfs(h, fout, ferr)); in fstyp_mod_dump()
212 read_bootsec(fstyp_pcfs_t *h) in read_bootsec() argument
216 (void) lseek(h->fd, h->offset, SEEK_SET); in read_bootsec()
217 if (read(h->fd, buf, sizeof (buf)) != sizeof (buf)) { in read_bootsec()
221 bcopy(buf, &h->bs, sizeof (h->bs)); in read_bootsec()
222 bcopy(buf + sizeof (struct bootsec), &h->bs16, sizeof (h->bs16)); in read_bootsec()
223 bcopy(buf + sizeof (struct bootsec), &h->bs32, sizeof (h->bs32)); in read_bootsec()
225 h->bs.fatsec = ltohs(h->bs.fatsec); in read_bootsec()
226 h->bs.spt = ltohs(h->bs.spt); in read_bootsec()
227 h->bs.nhead = ltohs(h->bs.nhead); in read_bootsec()
228 h->bs.hiddensec = ltohi(h->bs.hiddensec); in read_bootsec()
229 h->bs.totalsec = ltohi(h->bs.totalsec); in read_bootsec()
231 h->bs32.f_fatlength = ltohi(h->bs32.f_fatlength); in read_bootsec()
232 h->bs32.f_flags = ltohs(h->bs32.f_flags); in read_bootsec()
233 h->bs32.f_rootcluster = ltohi(h->bs32.f_rootcluster); in read_bootsec()
234 h->bs32.f_infosector = ltohs(h->bs32.f_infosector); in read_bootsec()
235 h->bs32.f_backupboot = ltohs(h->bs32.f_backupboot); in read_bootsec()
237 h->bps = PC_BPSEC(h); in read_bootsec()
243 valid_media(fstyp_pcfs_t *h) in valid_media() argument
245 switch (h->bs.mediadesriptor) { in valid_media()
260 well_formed(fstyp_pcfs_t *h) in well_formed() argument
264 if (h->bs16.f_bootsig == 0x29) { in well_formed()
265 fatmatch = ((h->bs16.f_typestring[0] == 'F' && in well_formed()
266 h->bs16.f_typestring[1] == 'A' && in well_formed()
267 h->bs16.f_typestring[2] == 'T') && in well_formed()
268 (h->bs.fatsec > 0) && in well_formed()
269 ((PC_NSEC(h) == 0 && h->bs.totalsec > 0) || in well_formed()
270 PC_NSEC(h) > 0)); in well_formed()
271 } else if (h->bs32.f_bootsig == 0x29) { in well_formed()
272 fatmatch = ((h->bs32.f_typestring[0] == 'F' && in well_formed()
273 h->bs32.f_typestring[1] == 'A' && in well_formed()
274 h->bs32.f_typestring[2] == 'T') && in well_formed()
275 (h->bs.fatsec == 0 && h->bs32.f_fatlength > 0) && in well_formed()
276 ((PC_NSEC(h) == 0 && h->bs.totalsec > 0) || in well_formed()
277 PC_NSEC(h) > 0)); in well_formed()
279 fatmatch = (PC_NSEC(h) > 0 && h->bs.fatsec > 0); in well_formed()
282 return (fatmatch && h->bps > 0 && h->bps % 512 == 0 && in well_formed()
283 h->bs.spcl > 0 && PC_RESSEC(h) >= 1 && h->bs.nfat > 0); in well_formed()
287 calculate_parameters(fstyp_pcfs_t *h) in calculate_parameters() argument
289 if (PC_NSEC(h) != 0) { in calculate_parameters()
290 h->TotSec = PC_NSEC(h); in calculate_parameters()
292 h->TotSec = h->bs.totalsec; in calculate_parameters()
294 if (h->bs.fatsec != 0) { in calculate_parameters()
295 h->FATSz = h->bs.fatsec; in calculate_parameters()
297 h->FATSz = h->bs32.f_fatlength; in calculate_parameters()
299 if ((h->bps == 0) || (h->bs.spcl == 0)) { in calculate_parameters()
302 h->RootDirSectors = in calculate_parameters()
303 ((PC_NROOTENT(h) * 32) + (h->bps - 1)) / h->bps; in calculate_parameters()
304 h->FirstDataSector = in calculate_parameters()
305 PC_RESSEC(h) + h->bs.nfat * h->FATSz + h->RootDirSectors; in calculate_parameters()
306 h->DataSec = h->TotSec - h->FirstDataSector; in calculate_parameters()
307 h->CountOfClusters = h->DataSec / h->bs.spcl; in calculate_parameters()
311 determine_fattype(fstyp_pcfs_t *h) in determine_fattype() argument
313 if ((h->CountOfClusters >= 4085 && h->CountOfClusters <= 4095) || in determine_fattype()
314 (h->CountOfClusters >= 65525 && h->CountOfClusters <= 65535)) { in determine_fattype()
315 h->fattype = 0; in determine_fattype()
316 } else if (h->CountOfClusters < 4085) { in determine_fattype()
317 h->fattype = 12; in determine_fattype()
318 } else if (h->CountOfClusters < 65525) { in determine_fattype()
319 h->fattype = 16; in determine_fattype()
321 h->fattype = 32; in determine_fattype()
326 get_label(fstyp_pcfs_t *h) in get_label() argument
332 (void) memcpy(h->volume_label, PC_LABEL_ADDR(h), PC_LABEL_SIZE); in get_label()
333 h->volume_label[PC_LABEL_SIZE] = '\0'; in get_label()
335 if (h->fattype == 0) { in get_label()
337 } else if (FSTYP_IS_32(h)) { in get_label()
338 get_label_32(h); in get_label()
340 get_label_16(h); in get_label()
350 get_label_16(fstyp_pcfs_t *h) in get_label_16() argument
359 if ((secsize = h->bps) > sizeof (buf)) { in get_label_16()
363 FirstRootDirSecNum = PC_RESSEC(h) + h->bs.nfat * h->bs.fatsec; in get_label_16()
364 offset = h->offset + FirstRootDirSecNum * secsize; in get_label_16()
365 resid = PC_NROOTENT(h); in get_label_16()
367 for (i = 0; i < h->RootDirSectors; i++) { in get_label_16()
368 (void) lseek(h->fd, offset, SEEK_SET); in get_label_16()
369 if (read(h->fd, buf, secsize) != secsize) { in get_label_16()
377 if (dir_find_label(h, (struct pcdir *)buf, nent)) { in get_label_16()
392 get_label_32(fstyp_pcfs_t *h) in get_label_32() argument
402 clustersize = h->bs.spcl * h->bps; in get_label_32()
408 for (n = h->bs32.f_rootcluster; n != 0; n = next_cluster_32(h, n)) { in get_label_32()
410 (n - 2) * h->bs.spcl + h->FirstDataSector; in get_label_32()
411 offset = h->offset + FirstSectorofCluster * h->bps; in get_label_32()
412 (void) lseek(h->fd, offset, SEEK_SET); in get_label_32()
413 if (read(h->fd, buf, clustersize) != clustersize) { in get_label_32()
418 if (dir_find_label(h, (struct pcdir *)buf, nent)) { in get_label_32()
434 next_cluster_32(fstyp_pcfs_t *h, int n) in next_cluster_32() argument
443 ThisFATSecNum = PC_RESSEC(h) + (n * 4) / h->bps; in next_cluster_32()
444 ThisFATEntOffset = (n * 4) % h->bps; in next_cluster_32()
445 offset = h->offset + ThisFATSecNum * h->bps; in next_cluster_32()
447 (void) lseek(h->fd, offset, SEEK_SET); in next_cluster_32()
448 if (read(h->fd, buf, sizeof (buf)) == sizeof (buf)) { in next_cluster_32()
460 dir_find_label(fstyp_pcfs_t *h, struct pcdir *d, int nent) in dir_find_label() argument
472 (void) memcpy(h->volume_label, d->pcd_filename, in dir_find_label()
474 h->volume_label[PC_LABEL_SIZE] = '\0'; in dir_find_label()
482 is_pcfs(fstyp_pcfs_t *h) in is_pcfs() argument
486 if ((error = read_bootsec(h)) != 0) { in is_pcfs()
489 if (!valid_media(h)) { in is_pcfs()
492 if (!well_formed(h)) { in is_pcfs()
496 calculate_parameters(h); in is_pcfs()
497 determine_fattype(h); in is_pcfs()
498 get_label(h); in is_pcfs()
505 dumpfs(fstyp_pcfs_t *h, FILE *fout, FILE *ferr) in dumpfs() argument
509 h->bps, h->bs.spcl); in dumpfs()
512 (unsigned short)PC_RESSEC(h), h->bs.nfat); in dumpfs()
515 (unsigned short)PC_NROOTENT(h), (unsigned short)PC_NSEC(h)); in dumpfs()
518 h->bs.fatsec, h->bs.spt); in dumpfs()
521 h->bs.nhead, h->bs.hiddensec); in dumpfs()
522 (void) fprintf(fout, "Volume ID: 0x%x\n", PC_VOLID(h)); in dumpfs()
523 (void) fprintf(fout, "Volume Label: %s\n", h->volume_label); in dumpfs()
524 (void) fprintf(fout, "Drive Number: 0x%x\n", PC_DRVNUM(h)); in dumpfs()
525 (void) fprintf(fout, "Media Type: 0x%x ", h->bs.mediadesriptor); in dumpfs()
527 switch (h->bs.mediadesriptor) { in dumpfs()
556 #define ADD_STRING(h, name, value) \ argument
557 if (nvlist_add_string(h->attr, name, value) != 0) { \
561 #define ADD_UINT32(h, name, value) \ argument
562 if (nvlist_add_uint32(h->attr, name, value) != 0) { \
566 #define ADD_UINT64(h, name, value) \ argument
567 if (nvlist_add_uint64(h->attr, name, value) != 0) { \
571 #define ADD_BOOL(h, name, value) \ argument
572 if (nvlist_add_boolean_value(h->attr, name, value) != 0) { \
577 get_attr(fstyp_pcfs_t *h) in get_attr() argument
581 ADD_UINT32(h, "bytes_per_sector", h->bps); in get_attr()
582 ADD_UINT32(h, "sectors_per_cluster", h->bs.spcl); in get_attr()
583 ADD_UINT32(h, "reserved_sectors", PC_RESSEC(h)); in get_attr()
584 ADD_UINT32(h, "fats", h->bs.nfat); in get_attr()
585 ADD_UINT32(h, "root_entry_count", PC_NROOTENT(h)); in get_attr()
586 ADD_UINT32(h, "total_sectors_16", PC_NSEC(h)); in get_attr()
587 ADD_UINT32(h, "media", h->bs.mediadesriptor); in get_attr()
588 ADD_UINT32(h, "fat_size_16", h->bs.fatsec); in get_attr()
589 ADD_UINT32(h, "sectors_per_track", h->bs.spt); in get_attr()
590 ADD_UINT32(h, "heads", h->bs.nhead); in get_attr()
591 ADD_UINT32(h, "hidden_sectors", h->bs.hiddensec); in get_attr()
592 ADD_UINT32(h, "total_sectors_32", h->bs.totalsec); in get_attr()
593 ADD_UINT32(h, "drive_number", PC_DRVNUM(h)); in get_attr()
594 ADD_UINT32(h, "volume_id", PC_VOLID(h)); in get_attr()
595 ADD_STRING(h, "volume_label", h->volume_label); in get_attr()
596 if (FSTYP_IS_32(h)) { in get_attr()
597 ADD_UINT32(h, "fat_size_32", h->bs32.f_fatlength); in get_attr()
599 ADD_UINT32(h, "total_sectors", h->TotSec); in get_attr()
600 ADD_UINT32(h, "fat_size", h->FATSz); in get_attr()
601 ADD_UINT32(h, "count_of_clusters", h->CountOfClusters); in get_attr()
602 ADD_UINT32(h, "fat_entry_size", h->fattype); in get_attr()
604 ADD_BOOL(h, "gen_clean", B_TRUE); in get_attr()
607 ADD_STRING(h, "gen_guid", s); in get_attr()
609 (void) snprintf(s, sizeof (s), "%d", h->fattype); in get_attr()
610 ADD_STRING(h, "gen_version", s); in get_attr()
611 ADD_STRING(h, "gen_volume_label", h->volume_label); in get_attr()