MIPS: Yosemite, Emma: Fix off-by-two in arcs_cmdline buffer size check
[linux-2.6/linux-mips.git] / include / linux / fd.h
blob72202b1b9a6a0e4fdd1184ee644e4d30f342b94a
1 #ifndef _LINUX_FD_H
2 #define _LINUX_FD_H
4 #include <linux/ioctl.h>
5 #include <linux/compiler.h>
7 /* New file layout: Now the ioctl definitions immediately follow the
8 * definitions of the structures that they use */
11 * Geometry
13 struct floppy_struct {
14 unsigned int size, /* nr of sectors total */
15 sect, /* sectors per track */
16 head, /* nr of heads */
17 track, /* nr of tracks */
18 stretch; /* bit 0 !=0 means double track steps */
19 /* bit 1 != 0 means swap sides */
20 /* bits 2..9 give the first sector */
21 /* number (the LSB is flipped) */
22 #define FD_STRETCH 1
23 #define FD_SWAPSIDES 2
24 #define FD_ZEROBASED 4
25 #define FD_SECTBASEMASK 0x3FC
26 #define FD_MKSECTBASE(s) (((s) ^ 1) << 2)
27 #define FD_SECTBASE(floppy) ((((floppy)->stretch & FD_SECTBASEMASK) >> 2) ^ 1)
29 unsigned char gap, /* gap1 size */
31 rate, /* data rate. |= 0x40 for perpendicular */
32 #define FD_2M 0x4
33 #define FD_SIZECODEMASK 0x38
34 #define FD_SIZECODE(floppy) (((((floppy)->rate&FD_SIZECODEMASK)>> 3)+ 2) %8)
35 #define FD_SECTSIZE(floppy) ( (floppy)->rate & FD_2M ? \
36 512 : 128 << FD_SIZECODE(floppy) )
37 #define FD_PERP 0x40
39 spec1, /* stepping rate, head unload time */
40 fmt_gap; /* gap2 size */
41 const char * name; /* used only for predefined formats */
45 /* commands needing write access have 0x40 set */
46 /* commands needing super user access have 0x80 set */
48 #define FDCLRPRM _IO(2, 0x41)
49 /* clear user-defined parameters */
51 #define FDSETPRM _IOW(2, 0x42, struct floppy_struct)
52 #define FDSETMEDIAPRM FDSETPRM
53 /* set user-defined parameters for current media */
55 #define FDDEFPRM _IOW(2, 0x43, struct floppy_struct)
56 #define FDGETPRM _IOR(2, 0x04, struct floppy_struct)
57 #define FDDEFMEDIAPRM FDDEFPRM
58 #define FDGETMEDIAPRM FDGETPRM
59 /* set/get disk parameters */
62 #define FDMSGON _IO(2,0x45)
63 #define FDMSGOFF _IO(2,0x46)
64 /* issue/don't issue kernel messages on media type change */
67 /*
68 * Formatting (obsolete)
70 #define FD_FILL_BYTE 0xF6 /* format fill byte. */
72 struct format_descr {
73 unsigned int device,head,track;
76 #define FDFMTBEG _IO(2,0x47)
77 /* begin formatting a disk */
78 #define FDFMTTRK _IOW(2,0x48, struct format_descr)
79 /* format the specified track */
80 #define FDFMTEND _IO(2,0x49)
81 /* end formatting a disk */
85 * Error thresholds
87 struct floppy_max_errors {
88 unsigned int
89 abort, /* number of errors to be reached before aborting */
90 read_track, /* maximal number of errors permitted to read an
91 * entire track at once */
92 reset, /* maximal number of errors before a reset is tried */
93 recal, /* maximal number of errors before a recalibrate is
94 * tried */
97 * Threshold for reporting FDC errors to the console.
98 * Setting this to zero may flood your screen when using
99 * ultra cheap floppies ;-)
101 reporting;
105 #define FDSETEMSGTRESH _IO(2,0x4a)
106 /* set fdc error reporting threshold */
108 #define FDFLUSH _IO(2,0x4b)
109 /* flush buffers for media; either for verifying media, or for
110 * handling a media change without closing the file descriptor */
112 #define FDSETMAXERRS _IOW(2, 0x4c, struct floppy_max_errors)
113 #define FDGETMAXERRS _IOR(2, 0x0e, struct floppy_max_errors)
114 /* set/get abortion and read_track threshold. See also floppy_drive_params
115 * structure */
118 typedef char floppy_drive_name[16];
119 #define FDGETDRVTYP _IOR(2, 0x0f, floppy_drive_name)
120 /* get drive type: 5 1/4 or 3 1/2 */
124 * Drive parameters (user modifiable)
126 struct floppy_drive_params {
127 signed char cmos; /* CMOS type */
129 /* Spec2 is (HLD<<1 | ND), where HLD is head load time (1=2ms, 2=4 ms
130 * etc) and ND is set means no DMA. Hardcoded to 6 (HLD=6ms, use DMA).
132 unsigned long max_dtr; /* Step rate, usec */
133 unsigned long hlt; /* Head load/settle time, msec */
134 unsigned long hut; /* Head unload time (remnant of
135 * 8" drives) */
136 unsigned long srt; /* Step rate, usec */
138 unsigned long spinup; /* time needed for spinup (expressed
139 * in jiffies) */
140 unsigned long spindown; /* timeout needed for spindown */
141 unsigned char spindown_offset; /* decides in which position the disk
142 * will stop */
143 unsigned char select_delay; /* delay to wait after select */
144 unsigned char rps; /* rotations per second */
145 unsigned char tracks; /* maximum number of tracks */
146 unsigned long timeout; /* timeout for interrupt requests */
148 unsigned char interleave_sect; /* if there are more sectors, use
149 * interleave */
151 struct floppy_max_errors max_errors;
153 char flags; /* various flags, including ftd_msg */
155 * Announce successful media type detection and media information loss after
156 * disk changes.
157 * Also used to enable/disable printing of overrun warnings.
160 #define FTD_MSG 0x10
161 #define FD_BROKEN_DCL 0x20
162 #define FD_DEBUG 0x02
163 #define FD_SILENT_DCL_CLEAR 0x4
164 #define FD_INVERTED_DCL 0x80 /* must be 0x80, because of hardware
165 considerations */
167 char read_track; /* use readtrack during probing? */
170 * Auto-detection. Each drive type has eight formats which are
171 * used in succession to try to read the disk. If the FDC cannot lock onto
172 * the disk, the next format is tried. This uses the variable 'probing'.
174 short autodetect[8]; /* autodetected formats */
176 int checkfreq; /* how often should the drive be checked for disk
177 * changes */
178 int native_format; /* native format of this drive */
181 enum {
182 FD_NEED_TWADDLE_BIT, /* more magic */
183 FD_VERIFY_BIT, /* inquire for write protection */
184 FD_DISK_NEWCHANGE_BIT, /* change detected, and no action undertaken yet
185 * to clear media change status */
186 FD_UNUSED_BIT,
187 FD_DISK_CHANGED_BIT, /* disk has been changed since last i/o */
188 FD_DISK_WRITABLE_BIT /* disk is writable */
191 #define FDSETDRVPRM _IOW(2, 0x90, struct floppy_drive_params)
192 #define FDGETDRVPRM _IOR(2, 0x11, struct floppy_drive_params)
193 /* set/get drive parameters */
197 * Current drive state (not directly modifiable by user, readonly)
199 struct floppy_drive_struct {
200 unsigned long flags;
201 /* values for these flags */
202 #define FD_NEED_TWADDLE (1 << FD_NEED_TWADDLE_BIT)
203 #define FD_VERIFY (1 << FD_VERIFY_BIT)
204 #define FD_DISK_NEWCHANGE (1 << FD_DISK_NEWCHANGE_BIT)
205 #define FD_DISK_CHANGED (1 << FD_DISK_CHANGED_BIT)
206 #define FD_DISK_WRITABLE (1 << FD_DISK_WRITABLE_BIT)
208 unsigned long spinup_date;
209 unsigned long select_date;
210 unsigned long first_read_date;
211 short probed_format;
212 short track; /* current track */
213 short maxblock; /* id of highest block read */
214 short maxtrack; /* id of highest half track read */
215 int generation; /* how many diskchanges? */
218 * (User-provided) media information is _not_ discarded after a media change
219 * if the corresponding keep_data flag is non-zero. Positive values are
220 * decremented after each probe.
222 int keep_data;
224 /* Prevent "aliased" accesses. */
225 int fd_ref;
226 int fd_device;
227 unsigned long last_checked; /* when was the drive last checked for a disk
228 * change? */
230 char *dmabuf;
231 int bufblocks;
234 #define FDGETDRVSTAT _IOR(2, 0x12, struct floppy_drive_struct)
235 #define FDPOLLDRVSTAT _IOR(2, 0x13, struct floppy_drive_struct)
236 /* get drive state: GET returns the cached state, POLL polls for new state */
240 * reset FDC
242 enum reset_mode {
243 FD_RESET_IF_NEEDED, /* reset only if the reset flags is set */
244 FD_RESET_IF_RAWCMD, /* obsolete */
245 FD_RESET_ALWAYS /* reset always */
247 #define FDRESET _IO(2, 0x54)
251 * FDC state
253 struct floppy_fdc_state {
254 int spec1; /* spec1 value last used */
255 int spec2; /* spec2 value last used */
256 int dtr;
257 unsigned char version; /* FDC version code */
258 unsigned char dor;
259 unsigned long address; /* io address */
260 unsigned int rawcmd:2;
261 unsigned int reset:1;
262 unsigned int need_configure:1;
263 unsigned int perp_mode:2;
264 unsigned int has_fifo:1;
265 unsigned int driver_version; /* version code for floppy driver */
266 #define FD_DRIVER_VERSION 0x100
267 /* user programs using the floppy API should use floppy_fdc_state to
268 * get the version number of the floppy driver that they are running
269 * on. If this version number is bigger than the one compiled into the
270 * user program (the FD_DRIVER_VERSION define), it should be prepared
271 * to bigger structures
274 unsigned char track[4];
275 /* Position of the heads of the 4 units attached to this FDC,
276 * as stored on the FDC. In the future, the position as stored
277 * on the FDC might not agree with the actual physical
278 * position of these drive heads. By allowing such
279 * disagreement, it will be possible to reset the FDC without
280 * incurring the expensive cost of repositioning all heads.
281 * Right now, these positions are hard wired to 0. */
285 #define FDGETFDCSTAT _IOR(2, 0x15, struct floppy_fdc_state)
289 * Asynchronous Write error tracking
291 struct floppy_write_errors {
292 /* Write error logging.
294 * These fields can be cleared with the FDWERRORCLR ioctl.
295 * Only writes that were attempted but failed due to a physical media
296 * error are logged. write(2) calls that fail and return an error code
297 * to the user process are not counted.
300 unsigned int write_errors; /* number of physical write errors
301 * encountered */
303 /* position of first and last write errors */
304 unsigned long first_error_sector;
305 int first_error_generation;
306 unsigned long last_error_sector;
307 int last_error_generation;
309 unsigned int badness; /* highest retry count for a read or write
310 * operation */
313 #define FDWERRORCLR _IO(2, 0x56)
314 /* clear write error and badness information */
315 #define FDWERRORGET _IOR(2, 0x17, struct floppy_write_errors)
316 /* get write error and badness information */
320 * Raw commands
322 /* new interface flag: now we can do them in batches */
323 #define FDHAVEBATCHEDRAWCMD
325 struct floppy_raw_cmd {
326 unsigned int flags;
327 #define FD_RAW_READ 1
328 #define FD_RAW_WRITE 2
329 #define FD_RAW_NO_MOTOR 4
330 #define FD_RAW_DISK_CHANGE 4 /* out: disk change flag was set */
331 #define FD_RAW_INTR 8 /* wait for an interrupt */
332 #define FD_RAW_SPIN 0x10 /* spin up the disk for this command */
333 #define FD_RAW_NO_MOTOR_AFTER 0x20 /* switch the motor off after command
334 * completion */
335 #define FD_RAW_NEED_DISK 0x40 /* this command needs a disk to be present */
336 #define FD_RAW_NEED_SEEK 0x80 /* this command uses an implied seek (soft) */
338 /* more "in" flags */
339 #define FD_RAW_MORE 0x100 /* more records follow */
340 #define FD_RAW_STOP_IF_FAILURE 0x200 /* stop if we encounter a failure */
341 #define FD_RAW_STOP_IF_SUCCESS 0x400 /* stop if command successful */
342 #define FD_RAW_SOFTFAILURE 0x800 /* consider the return value for failure
343 * detection too */
345 /* more "out" flags */
346 #define FD_RAW_FAILURE 0x10000 /* command sent to fdc, fdc returned error */
347 #define FD_RAW_HARDFAILURE 0x20000 /* fdc had to be reset, or timed out */
349 void __user *data;
350 char *kernel_data; /* location of data buffer in the kernel */
351 struct floppy_raw_cmd *next; /* used for chaining of raw cmd's
352 * within the kernel */
353 long length; /* in: length of dma transfer. out: remaining bytes */
354 long phys_length; /* physical length, if different from dma length */
355 int buffer_length; /* length of allocated buffer */
357 unsigned char rate;
358 unsigned char cmd_count;
359 unsigned char cmd[16];
360 unsigned char reply_count;
361 unsigned char reply[16];
362 int track;
363 int resultcode;
365 int reserved1;
366 int reserved2;
369 #define FDRAWCMD _IO(2, 0x58)
370 /* send a raw command to the fdc. Structure size not included, because of
371 * batches */
373 #define FDTWADDLE _IO(2, 0x59)
374 /* flicker motor-on bit before reading a sector. Experimental */
377 #define FDEJECT _IO(2, 0x5a)
378 /* eject the disk */
381 #ifdef __KERNEL__
382 #ifdef CONFIG_COMPAT
383 #include <linux/compat.h>
385 struct compat_floppy_struct {
386 compat_uint_t size;
387 compat_uint_t sect;
388 compat_uint_t head;
389 compat_uint_t track;
390 compat_uint_t stretch;
391 unsigned char gap;
392 unsigned char rate;
393 unsigned char spec1;
394 unsigned char fmt_gap;
395 const compat_caddr_t name;
398 #define FDGETPRM32 _IOR(2, 0x04, struct compat_floppy_struct)
399 #endif
400 #endif
402 #endif