Add externs to avoid multiple definitions, and then add missing definitions.
[rrq/maintain_lilo.git] / src / geometry.h
1 /* geometry.h  -  Device and file geometry computation
2  * 
3  * Copyright 1992-1998 Werner Almesberger
4  * Copyright 1999-2005 John Coffman
5  * Copyright 2009-2015 Joachim Wiedorn
6  * All rights reserved.
7  * 
8  * Licensed under the terms contained in the file 'COPYING'
9  * in the source directory.
10  */
11
12 #ifndef GEOMETRY_H
13 #define GEOMETRY_H
14
15 #define LINUX 1
16
17 #if LINUX
18 #include <linux/fd.h>
19 #include <linux/hdreg.h>
20 #else
21 struct hd_geometry {
22       unsigned char heads;
23       unsigned char sectors;
24       unsigned short cylinders;
25       uint32_t start;
26 };
27
28 /* hd/ide ctl's that pass (arg) ptrs to user space are numbered 0x030n/0x031n */
29 #define HDIO_GETGEO             0x0301  /* get device geometry */
30 struct floppy_struct {
31         unsigned int    size,           /* nr of sectors total */
32                         sect,           /* sectors per track */
33                         head,           /* nr of heads */
34                         track,          /* nr of tracks */
35                         stretch;        /* !=0 means double track steps */
36 #define FD_STRETCH 1
37 #define FD_SWAPSIDES 2
38 #define FD_ZEROBASED 4
39
40         unsigned char   gap,            /* gap1 size */
41
42                         rate,           /* data rate. |= 0x40 for perpendicular */
43 #define FD_2M 0x4
44 #define FD_SIZECODEMASK 0x38
45 #define FD_SIZECODE(floppy) (((((floppy)->rate&FD_SIZECODEMASK)>> 3)+ 2) %8)
46 #define FD_SECTSIZE(floppy) ( (floppy)->rate & FD_2M ? \
47                              512 : 128 << FD_SIZECODE(floppy) )
48 #define FD_PERP 0x40
49
50                         spec1,          /* stepping rate, head unload time */
51                         fmt_gap;        /* gap2 size */
52         const char      * name; /* used only for predefined formats */
53 };
54 #define FDGETPRM _IOR(2, 0x04, struct floppy_struct)
55 #endif
56
57 #if 1
58 #define MAJOR(dev) (unsigned int)((((dev_t)(dev) >> 8) & 0xfff) | ((unsigned int) ((dev_t)(dev) >> 32) & ~0xfff))
59 #define MINOR(dev) (unsigned int)(((dev_t)(dev) & 0xff) | ((unsigned int) ((dev_t)(dev) >> 12) & ~0xff))
60 #define MKDEV(major,minor) (((minor & 0xff) | ((major & 0xfff) << 8) \
61           | (((uint64_t) (minor & ~0xff)) << 12) \
62           | (((uint64_t) (major & ~0xfff)) << 32)))
63 #else
64 #include <sys/sysmacros.h>
65 #ifdef major
66 #define MAJOR(dev) major(dev)
67 #define MINOR(dev) minor(dev)
68 #define MKDEV(maj,min) makedev(maj,min)
69 #else
70 /* from <linux/kdev_t.h>  */
71 /* These are for user-level "dev_t" */
72 #define MINORBITS       8
73 #define MINORMASK       ((1U << MINORBITS) - 1)
74 #error "Should not get here:  MAJOR/MINOR (geometry.h)"
75 #define MAJOR(dev)      ((unsigned int) ((dev) >> MINORBITS))
76 #define MINOR(dev)      ((unsigned int) ((dev) & MINORMASK))
77 #define MKDEV(ma,mi)    (((ma) << MINORBITS) | (mi))
78 #endif
79 #endif
80
81 /*  from <linux/fs.h> */
82 #define BMAP_IOCTL 1            /* obsolete - kept for compatibility */
83 #define FIBMAP     _IO(0x00,1)  /* bmap access */
84 #define FIGETBSZ   _IO(0x00,2)  /* get the block size used for bmap */
85
86
87
88 typedef struct {
89     int device,heads;
90     int cylinders,sectors;
91     int start; /* partition offset */
92     int spb; /* sectors per block */
93     int fd,file;
94     int boot; /* non-zero after geo_open_boot */
95     int raid; /* file references require raid1 relocation */
96     dev_t dev, base_dev; /* real device if remapping (LVM, etc) */
97 } GEOMETRY;
98
99 typedef struct _dt_entry {
100     unsigned int device;
101     int bios;
102     int sectors;
103     int heads; /* 0 if inaccessible */
104     int cylinders;
105     int start;
106     struct _dt_entry *next;
107 } DT_ENTRY;
108
109 extern DT_ENTRY *disktab;
110
111
112 /* unsigned char max_partno[256]; */
113 /* index by major device number; entries must be 2**n-1 (7,15, or 63) */
114
115
116 int has_partitions(dev_t dev);
117 /* indicates that the specified device is a block hard disk device */
118 /* returns the partition mask or 0 */
119
120
121 void geo_init(char *name);
122 /* Loads the disk geometry table. */
123
124 int is_first(int device);
125 /* Returns a non-zero integer if the specified device could be the first (i.e.
126    boot) disk, zero otherwise. */
127
128
129 void geo_get(GEOMETRY *geo,int device,int user_device,int all);
130 /* Obtains geometry information of the specified device. Sets the BIOS device
131    number to user_device unless -1. If ALL is zero, only the BIOS device number
132    is retrieved and the other geometry information is undefined. */
133
134
135 int geo_open(GEOMETRY *geo,const char *name,int flags);
136 /* Opens the specified file or block device, obtains the necessary geometry
137    information and returns the file descriptor. If the name contains a BIOS
138    device specification (xxx:yyy), it is removed and stored in the geometry
139    descriptor. Returns the file descriptor of the opened object. */
140
141
142 int geo_open_boot(GEOMETRY *geo,char *name);
143 /* Like get_open, but only the first sector of the device is accessed. This
144    way, no geometry information is needed. */
145
146
147 void geo_close(GEOMETRY *geo);
148 /* Closes a file or device that has previously been opened by geo_open. */
149
150
151 int geo_comp_addr(GEOMETRY *geo,int offset,SECTOR_ADDR *addr);
152 /* Determines the address of the disk sector that contains the offset'th
153    byte of the specified file or device. Returns a non-zero value if such
154    a sector exists, zero if it doesn't. */
155
156
157 int geo_find(GEOMETRY *geo,SECTOR_ADDR addr);
158 /* lseeks in the file associated with GEO for the sector at address ADDR.
159    Returns a non-zero integer on success, zero on failure. */
160
161
162 void geo_query_dev(GEOMETRY *geo,int device,int all);
163 /* opens the specified device and gets the geometry information.  That
164    information is then stored in *geo */
165
166
167 int is_dm_major(int major);
168 /* tell whether the specified major device number is one of the
169    device-mapper major devices */
170    
171
172 #if 0
173 int geo_devscan(int device);
174 /* called to fill in a disktab with arbitrary BIOS codes */
175 #endif
176
177
178 #endif