1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright (c) 2011 Gary Mills
24  *
25  * Copyright (c) 1999 by Sun Microsystems, Inc.
26  * All rights reserved.
27  */
28 
29 #ifndef _PCFS_COMMON_H
30 #define	_PCFS_COMMON_H
31 
32 /*
33  * Common routines for the pcfs user-level utilities
34  */
35 
36 #ifdef __cplusplus
37 extern "C" {
38 #endif
39 
40 #include <sys/isa_defs.h>
41 #include <sys/types.h>
42 #include <sys/stat.h>
43 #include <sys/sysmacros.h>
44 #include "pcfs_bpb.h"
45 
46 #define	IN_RANGE(n, x, y) (((n) >= (x)) && ((n) <= (y)))
47 
48 /*
49  *  A macro implementing a ceiling function for integer divides.
50  */
51 #define	idivceil(dvend, dvsor) \
52 	((dvend)/(dvsor) + (((dvend)%(dvsor) == 0) ? 0 : 1))
53 
54 /*
55  * These defines should move into a kernel header file eventually
56  * and pcfs_mount may want to refuse to mount FAT32's that aren't "clean"
57  *
58  *	If Windows shuts down properly it sets the fourth bit of the 8th
59  *	and final reserved byte at the start of the FAT.
60  */
61 #define	WIN_SHUTDOWN_STATUS_BYTE	7
62 #define	WIN_SHUTDOWN_BIT_MASK		0x8
63 
64 /*
65  *  Define some special logical drives we use.
66  */
67 #define	BOOT_PARTITION_DRIVE	99
68 #define	PRIMARY_DOS_DRIVE	1
69 
70 /*
71  * Function prototypes
72  */
73 extern off64_t findPartitionOffset(int fd, char *ldrive);
74 extern char *stat_actual_disk(char *diskname, struct stat *info, char **suffix);
75 extern void header_for_dump(void);
76 extern void store_16_bits(uchar_t **bp, uint32_t v);
77 extern void store_32_bits(uchar_t **bp, uint32_t v);
78 extern void read_16_bits(uchar_t *bp, uint32_t *value);
79 extern void read_32_bits(uchar_t *bp, uint32_t *value);
80 extern void missing_arg(char *option);
81 extern void dump_bytes(uchar_t *b, int n);
82 extern void bad_arg(char *option);
83 extern void usage(void);
84 extern int  yes(void);
85 
86 /*
87  *	The assumption here is that _BIG_ENDIAN implies sparc, and
88  *	so in addition to swapping bytes we also have to construct
89  *	packed structures by hand to avoid bus errors due to improperly
90  *	aligned pointers.
91  */
92 #ifdef _BIG_ENDIAN
93 extern void swap_pack_grab32bpb(bpb_t *wbpb, struct _boot_sector *bsp);
94 extern void swap_pack_grabbpb(bpb_t *wbpb, struct _boot_sector *bsp);
95 #endif	/* _BIG_ENDIAN */
96 
97 #ifdef __cplusplus
98 }
99 #endif
100 
101 #endif /* _PCFS_COMMON_H */
102