xref: /illumos-gate/usr/src/cmd/fs.d/pcfs/common/pcfs_common.h (revision fdc43e978a96b43e8b78e80d9bc6f39c99a8ca83)
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) 1999 by Sun Microsystems, Inc.
24   * All rights reserved.
25   * Copyright (c) 2011 Gary Mills
26   * Copyright 2024 MNX Cloud, Inc.
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 <stdbool.h>
41  #include <sys/isa_defs.h>
42  #include <sys/types.h>
43  #include <sys/stat.h>
44  #include <sys/sysmacros.h>
45  #include "pcfs_bpb.h"
46  
47  #define	IN_RANGE(n, x, y) (((n) >= (x)) && ((n) <= (y)))
48  
49  /*
50   *  A macro implementing a ceiling function for integer divides.
51   */
52  #define	idivceil(dvend, dvsor) \
53  	((dvend)/(dvsor) + (((dvend)%(dvsor) == 0) ? 0 : 1))
54  
55  /*
56   * These defines should move into a kernel header file eventually
57   * and pcfs_mount may want to refuse to mount FAT32's that aren't "clean"
58   *
59   *	If Windows shuts down properly it sets the fourth bit of the 8th
60   *	and final reserved byte at the start of the FAT.
61   */
62  #define	WIN_SHUTDOWN_STATUS_BYTE	7
63  #define	WIN_SHUTDOWN_BIT_MASK		0x8
64  
65  /*
66   *  Define some special logical drives we use.
67   */
68  #define	BOOT_PARTITION_DRIVE	99
69  #define	PRIMARY_DOS_DRIVE	1
70  
71  /*
72   * Function prototypes
73   */
74  extern off64_t findPartitionOffset(int fd, size_t bpsec, char *ldrive);
75  extern char *stat_actual_disk(const char *diskname, struct stat *info,
76  	char **suffix);
77  extern void header_for_dump(void);
78  extern void store_16_bits(uchar_t **bp, uint32_t v);
79  extern void store_32_bits(uchar_t **bp, uint32_t v);
80  extern void read_16_bits(uchar_t *bp, uint32_t *value);
81  extern void read_32_bits(uchar_t *bp, uint32_t *value);
82  extern void missing_arg(char *option);
83  extern void dump_bytes(uchar_t *b, int n);
84  extern void bad_arg(char *option);
85  extern void usage(void);
86  extern bool is_sector_size_valid(size_t size);
87  extern int  get_media_sector_size(int fd, size_t *sizep);
88  
89  /*
90   *	The assumption here is that _BIG_ENDIAN implies sparc, and
91   *	so in addition to swapping bytes we also have to construct
92   *	packed structures by hand to avoid bus errors due to improperly
93   *	aligned pointers.
94   */
95  #ifdef _BIG_ENDIAN
96  extern void swap_pack_grab32bpb(bpb_t *wbpb, struct _boot_sector *bsp);
97  extern void swap_pack_grabbpb(bpb_t *wbpb, struct _boot_sector *bsp);
98  #endif	/* _BIG_ENDIAN */
99  
100  #ifdef __cplusplus
101  }
102  #endif
103  
104  #endif /* _PCFS_COMMON_H */
105