1 /* geometry.h - Device and file geometry computation
3 * Copyright 1992-1998 Werner Almesberger
4 * Copyright 1999-2005 John Coffman
5 * Copyright 2009-2011 Joachim Wiedorn
8 * Licensed under the terms contained in the file 'COPYING'
9 * in the source directory.
19 #include <linux/hdreg.h>
23 unsigned char sectors;
24 unsigned short cylinders;
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 */
37 #define FD_SWAPSIDES 2
38 #define FD_ZEROBASED 4
40 unsigned char gap, /* gap1 size */
42 rate, /* data rate. |= 0x40 for perpendicular */
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) )
50 spec1, /* stepping rate, head unload time */
51 fmt_gap; /* gap2 size */
52 const char * name; /* used only for predefined formats */
54 #define FDGETPRM _IOR(2, 0x04, struct floppy_struct)
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 | (((unsigned long long int) (minor & ~0xff)) << 12) \
62 | (((unsigned long long int) (major & ~0xfff)) << 32)))
64 #include <sys/sysmacros.h>
66 #define MAJOR(dev) major(dev)
67 #define MINOR(dev) minor(dev)
68 #define MKDEV(maj,min) makedev(maj,min)
70 /* from <linux/kdev_t.h> */
71 /* These are for user-level "dev_t" */
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))
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 */
90 int cylinders,sectors;
91 int start; /* partition offset */
92 int spb; /* sectors per block */
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) */
99 typedef struct _dt_entry {
103 int heads; /* 0 if inaccessible */
106 struct _dt_entry *next;
109 extern DT_ENTRY *disktab;
112 /* unsigned char max_partno[256]; */
113 /* index by major device number; entries must be 2**n-1 (7,15, or 63) */
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 */
121 void geo_init(char *name);
122 /* Loads the disk geometry table. */
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. */
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. */
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. */
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. */
147 void geo_close(GEOMETRY *geo);
148 /* Closes a file or device that has previously been opened by geo_open. */
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. */
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. */
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 */
167 int is_dm_major(int major);
168 /* tell whether the specified major device number is one of the
169 device-mapper major devices */
173 int geo_devscan(int device);
174 /* called to fill in a disktab with arbitrary BIOS codes */