1 /* geometry.h - Device and file geometry computation */
3 Copyright 1992-1998 Werner Almesberger.
4 Copyright 1999-2005 John Coffman.
7 Licensed under the terms contained in the file 'COPYING' in the
18 #include <linux/hdreg.h>
22 unsigned char sectors;
23 unsigned short cylinders;
27 /* hd/ide ctl's that pass (arg) ptrs to user space are numbered 0x030n/0x031n */
28 #define HDIO_GETGEO 0x0301 /* get device geometry */
29 struct floppy_struct {
30 unsigned int size, /* nr of sectors total */
31 sect, /* sectors per track */
32 head, /* nr of heads */
33 track, /* nr of tracks */
34 stretch; /* !=0 means double track steps */
36 #define FD_SWAPSIDES 2
37 #define FD_ZEROBASED 4
39 unsigned char gap, /* gap1 size */
41 rate, /* data rate. |= 0x40 for perpendicular */
43 #define FD_SIZECODEMASK 0x38
44 #define FD_SIZECODE(floppy) (((((floppy)->rate&FD_SIZECODEMASK)>> 3)+ 2) %8)
45 #define FD_SECTSIZE(floppy) ( (floppy)->rate & FD_2M ? \
46 512 : 128 << FD_SIZECODE(floppy) )
49 spec1, /* stepping rate, head unload time */
50 fmt_gap; /* gap2 size */
51 const char * name; /* used only for predefined formats */
53 #define FDGETPRM _IOR(2, 0x04, struct floppy_struct)
57 #define MAJOR(dev) (unsigned int)((((dev_t)(dev) >> 8) & 0xfff) | ((unsigned int) ((dev_t)(dev) >> 32) & ~0xfff))
58 #define MINOR(dev) (unsigned int)(((dev_t)(dev) & 0xff) | ((unsigned int) ((dev_t)(dev) >> 12) & ~0xff))
59 #define MKDEV(major,minor) (((minor & 0xff) | ((major & 0xfff) << 8) \
60 | (((unsigned long long int) (minor & ~0xff)) << 12) \
61 | (((unsigned long long int) (major & ~0xfff)) << 32)))
63 #include <sys/sysmacros.h>
65 #define MAJOR(dev) major(dev)
66 #define MINOR(dev) minor(dev)
67 #define MKDEV(maj,min) makedev(maj,min)
69 /* from <linux/kdev_t.h> */
70 /* These are for user-level "dev_t" */
72 #define MINORMASK ((1U << MINORBITS) - 1)
73 #error "Should not get here: MAJOR/MINOR (geometry.h)"
74 #define MAJOR(dev) ((unsigned int) ((dev) >> MINORBITS))
75 #define MINOR(dev) ((unsigned int) ((dev) & MINORMASK))
76 #define MKDEV(ma,mi) (((ma) << MINORBITS) | (mi))
80 /* from <linux/fs.h> */
81 #define BMAP_IOCTL 1 /* obsolete - kept for compatibility */
82 #define FIBMAP _IO(0x00,1) /* bmap access */
83 #define FIGETBSZ _IO(0x00,2) /* get the block size used for bmap */
89 int cylinders,sectors;
90 int start; /* partition offset */
91 int spb; /* sectors per block */
93 int boot; /* non-zero after geo_open_boot */
94 int raid; /* file references require raid1 relocation */
95 dev_t dev, base_dev; /* real device if remapping (LVM, etc) */
98 typedef struct _dt_entry {
102 int heads; /* 0 if inaccessible */
105 struct _dt_entry *next;
108 extern DT_ENTRY *disktab;
111 /* unsigned char max_partno[256]; */
112 /* index by major device number; entries must be 2**n-1 (7,15, or 63) */
115 int has_partitions(dev_t dev);
116 /* indicates that the specified device is a block hard disk device */
117 /* returns the partition mask or 0 */
120 void geo_init(char *name);
121 /* Loads the disk geometry table. */
123 int is_first(int device);
124 /* Returns a non-zero integer if the specified device could be the first (i.e.
125 boot) disk, zero otherwise. */
128 void geo_get(GEOMETRY *geo,int device,int user_device,int all);
129 /* Obtains geometry information of the specified device. Sets the BIOS device
130 number to user_device unless -1. If ALL is zero, only the BIOS device number
131 is retrieved and the other geometry information is undefined. */
134 int geo_open(GEOMETRY *geo,char *name,int flags);
135 /* Opens the specified file or block device, obtains the necessary geometry
136 information and returns the file descriptor. If the name contains a BIOS
137 device specification (xxx:yyy), it is removed and stored in the geometry
138 descriptor. Returns the file descriptor of the opened object. */
141 int geo_open_boot(GEOMETRY *geo,char *name);
142 /* Like get_open, but only the first sector of the device is accessed. This
143 way, no geometry information is needed. */
146 void geo_close(GEOMETRY *geo);
147 /* Closes a file or device that has previously been opened by geo_open. */
150 int geo_comp_addr(GEOMETRY *geo,int offset,SECTOR_ADDR *addr);
151 /* Determines the address of the disk sector that contains the offset'th
152 byte of the specified file or device. Returns a non-zero value if such
153 a sector exists, zero if it doesn't. */
156 int geo_find(GEOMETRY *geo,SECTOR_ADDR addr);
157 /* lseeks in the file associated with GEO for the sector at address ADDR.
158 Returns a non-zero integer on success, zero on failure. */
161 void geo_query_dev(GEOMETRY *geo,int device,int all);
162 /* opens the specified device and gets the geometry information. That
163 information is then stored in *geo */
166 int is_dm_major(int major);
167 /* tell whether the specified major device number is one of the
168 device-mapper major devices */
172 int geo_devscan(int device);
173 /* called to fill in a disktab with arbitrary BIOS codes */