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