1*d5c9a868SElliott Hughes #ifdef OS_linux
2*d5c9a868SElliott Hughes
3*d5c9a868SElliott Hughes /* Copyright 1996-2002,2009 Alain Knaff.
4*d5c9a868SElliott Hughes * This file is part of mtools.
5*d5c9a868SElliott Hughes *
6*d5c9a868SElliott Hughes * Mtools is free software: you can redistribute it and/or modify
7*d5c9a868SElliott Hughes * it under the terms of the GNU General Public License as published by
8*d5c9a868SElliott Hughes * the Free Software Foundation, either version 3 of the License, or
9*d5c9a868SElliott Hughes * (at your option) any later version.
10*d5c9a868SElliott Hughes *
11*d5c9a868SElliott Hughes * Mtools is distributed in the hope that it will be useful,
12*d5c9a868SElliott Hughes * but WITHOUT ANY WARRANTY; without even the implied warranty of
13*d5c9a868SElliott Hughes * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14*d5c9a868SElliott Hughes * GNU General Public License for more details.
15*d5c9a868SElliott Hughes *
16*d5c9a868SElliott Hughes * You should have received a copy of the GNU General Public License
17*d5c9a868SElliott Hughes * along with Mtools. If not, see <http://www.gnu.org/licenses/>.
18*d5c9a868SElliott Hughes */
19*d5c9a868SElliott Hughes #include <sys/types.h>
20*d5c9a868SElliott Hughes
21*d5c9a868SElliott Hughes #ifdef HAVE_SYS_SYSMACROS_H
22*d5c9a868SElliott Hughes
23*d5c9a868SElliott Hughes #include <sys/sysmacros.h>
24*d5c9a868SElliott Hughes #ifndef MAJOR
25*d5c9a868SElliott Hughes #define MAJOR(dev) major(dev)
26*d5c9a868SElliott Hughes #endif /* MAJOR not defined */
27*d5c9a868SElliott Hughes #ifndef MINOR
28*d5c9a868SElliott Hughes #define MINOR(dev) minor(dev)
29*d5c9a868SElliott Hughes #endif /* MINOR not defined */
30*d5c9a868SElliott Hughes
31*d5c9a868SElliott Hughes #else
32*d5c9a868SElliott Hughes
33*d5c9a868SElliott Hughes #include <linux/fs.h> /* get MAJOR/MINOR from Linux kernel */
34*d5c9a868SElliott Hughes #ifndef major
35*d5c9a868SElliott Hughes #define major(x) MAJOR(x)
36*d5c9a868SElliott Hughes #endif
37*d5c9a868SElliott Hughes
38*d5c9a868SElliott Hughes #endif /* HAVE_SYS_SYSMACROS_H */
39*d5c9a868SElliott Hughes
40*d5c9a868SElliott Hughes #include <linux/fd.h>
41*d5c9a868SElliott Hughes #include <linux/fdreg.h>
42*d5c9a868SElliott Hughes #include <linux/major.h>
43*d5c9a868SElliott Hughes
44*d5c9a868SElliott Hughes
45*d5c9a868SElliott Hughes typedef struct floppy_raw_cmd RawRequest_t;
46*d5c9a868SElliott Hughes
UNUSED(static __inline__ void RR_INIT (struct floppy_raw_cmd * request))47*d5c9a868SElliott Hughes UNUSED(static __inline__ void RR_INIT(struct floppy_raw_cmd *request))
48*d5c9a868SElliott Hughes {
49*d5c9a868SElliott Hughes request->data = 0;
50*d5c9a868SElliott Hughes request->length = 0;
51*d5c9a868SElliott Hughes request->cmd_count = 9;
52*d5c9a868SElliott Hughes request->flags = FD_RAW_INTR | FD_RAW_NEED_SEEK | FD_RAW_NEED_DISK
53*d5c9a868SElliott Hughes #ifdef FD_RAW_SOFTFAILUE
54*d5c9a868SElliott Hughes | FD_RAW_SOFTFAILURE | FD_RAW_STOP_IF_FAILURE
55*d5c9a868SElliott Hughes #endif
56*d5c9a868SElliott Hughes ;
57*d5c9a868SElliott Hughes request->cmd[1] = 0;
58*d5c9a868SElliott Hughes request->cmd[6] = 0;
59*d5c9a868SElliott Hughes request->cmd[7] = 0x1b;
60*d5c9a868SElliott Hughes request->cmd[8] = 0xff;
61*d5c9a868SElliott Hughes request->reply_count = 0;
62*d5c9a868SElliott Hughes }
63*d5c9a868SElliott Hughes
UNUSED(static __inline__ void RR_SETRATE (struct floppy_raw_cmd * request,uint8_t rate))64*d5c9a868SElliott Hughes UNUSED(static __inline__ void RR_SETRATE(struct floppy_raw_cmd *request, uint8_t rate))
65*d5c9a868SElliott Hughes {
66*d5c9a868SElliott Hughes request->rate = rate;
67*d5c9a868SElliott Hughes }
68*d5c9a868SElliott Hughes
UNUSED(static __inline__ void RR_SETDRIVE (struct floppy_raw_cmd * request,int drive))69*d5c9a868SElliott Hughes UNUSED(static __inline__ void RR_SETDRIVE(struct floppy_raw_cmd *request,int drive))
70*d5c9a868SElliott Hughes {
71*d5c9a868SElliott Hughes request->cmd[1] = (request->cmd[1] & ~3) | (drive & 3);
72*d5c9a868SElliott Hughes }
73*d5c9a868SElliott Hughes
UNUSED(static __inline__ void RR_SETTRACK (struct floppy_raw_cmd * request,uint8_t track))74*d5c9a868SElliott Hughes UNUSED(static __inline__ void RR_SETTRACK(struct floppy_raw_cmd *request,uint8_t track))
75*d5c9a868SElliott Hughes {
76*d5c9a868SElliott Hughes request->cmd[2] = track;
77*d5c9a868SElliott Hughes }
78*d5c9a868SElliott Hughes
UNUSED(static __inline__ void RR_SETPTRACK (struct floppy_raw_cmd * request,int track))79*d5c9a868SElliott Hughes UNUSED(static __inline__ void RR_SETPTRACK(struct floppy_raw_cmd *request,
80*d5c9a868SElliott Hughes int track))
81*d5c9a868SElliott Hughes {
82*d5c9a868SElliott Hughes request->track = track;
83*d5c9a868SElliott Hughes }
84*d5c9a868SElliott Hughes
UNUSED(static __inline__ void RR_SETHEAD (struct floppy_raw_cmd * request,uint8_t head))85*d5c9a868SElliott Hughes UNUSED(static __inline__ void RR_SETHEAD(struct floppy_raw_cmd *request, uint8_t head))
86*d5c9a868SElliott Hughes {
87*d5c9a868SElliott Hughes if(head)
88*d5c9a868SElliott Hughes request->cmd[1] |= 4;
89*d5c9a868SElliott Hughes else
90*d5c9a868SElliott Hughes request->cmd[1] &= ~4;
91*d5c9a868SElliott Hughes request->cmd[3] = head;
92*d5c9a868SElliott Hughes }
93*d5c9a868SElliott Hughes
UNUSED(static __inline__ void RR_SETSECTOR (struct floppy_raw_cmd * request,uint8_t sector))94*d5c9a868SElliott Hughes UNUSED(static __inline__ void RR_SETSECTOR(struct floppy_raw_cmd *request,
95*d5c9a868SElliott Hughes uint8_t sector))
96*d5c9a868SElliott Hughes {
97*d5c9a868SElliott Hughes request->cmd[4] = sector;
98*d5c9a868SElliott Hughes request->cmd[6] = sector-1;
99*d5c9a868SElliott Hughes }
100*d5c9a868SElliott Hughes
UNUSED(static __inline__ void RR_SETSIZECODE (struct floppy_raw_cmd * request,uint8_t sizecode))101*d5c9a868SElliott Hughes UNUSED(static __inline__ void RR_SETSIZECODE(struct floppy_raw_cmd *request,
102*d5c9a868SElliott Hughes uint8_t sizecode))
103*d5c9a868SElliott Hughes {
104*d5c9a868SElliott Hughes request->cmd[5] = sizecode;
105*d5c9a868SElliott Hughes request->cmd[6]++;
106*d5c9a868SElliott Hughes request->length += 128 << sizecode;
107*d5c9a868SElliott Hughes }
108*d5c9a868SElliott Hughes
109*d5c9a868SElliott Hughes #if 0
110*d5c9a868SElliott Hughes static inline void RR_SETEND(struct floppy_raw_cmd *request, int end)
111*d5c9a868SElliott Hughes {
112*d5c9a868SElliott Hughes request->cmd[6] = end;
113*d5c9a868SElliott Hughes }
114*d5c9a868SElliott Hughes #endif
115*d5c9a868SElliott Hughes
UNUSED(static __inline__ void RR_SETDIRECTION (struct floppy_raw_cmd * request,int direction))116*d5c9a868SElliott Hughes UNUSED(static __inline__ void RR_SETDIRECTION(struct floppy_raw_cmd *request,
117*d5c9a868SElliott Hughes int direction))
118*d5c9a868SElliott Hughes {
119*d5c9a868SElliott Hughes if(direction == MT_READ) {
120*d5c9a868SElliott Hughes request->flags |= FD_RAW_READ;
121*d5c9a868SElliott Hughes request->cmd[0] = FD_READ & ~0x80;
122*d5c9a868SElliott Hughes } else {
123*d5c9a868SElliott Hughes request->flags |= FD_RAW_WRITE;
124*d5c9a868SElliott Hughes request->cmd[0] = FD_WRITE & ~0x80;
125*d5c9a868SElliott Hughes }
126*d5c9a868SElliott Hughes }
127*d5c9a868SElliott Hughes
128*d5c9a868SElliott Hughes
UNUSED(static __inline__ void RR_SETDATA (struct floppy_raw_cmd * request,caddr_t data))129*d5c9a868SElliott Hughes UNUSED(static __inline__ void RR_SETDATA(struct floppy_raw_cmd *request,
130*d5c9a868SElliott Hughes caddr_t data))
131*d5c9a868SElliott Hughes {
132*d5c9a868SElliott Hughes request->data = data;
133*d5c9a868SElliott Hughes }
134*d5c9a868SElliott Hughes
135*d5c9a868SElliott Hughes
136*d5c9a868SElliott Hughes #if 0
137*d5c9a868SElliott Hughes static inline void RR_SETLENGTH(struct floppy_raw_cmd *request, int length)
138*d5c9a868SElliott Hughes {
139*d5c9a868SElliott Hughes request->length += length;
140*d5c9a868SElliott Hughes }
141*d5c9a868SElliott Hughes #endif
142*d5c9a868SElliott Hughes
UNUSED(static __inline__ void RR_SETCONT (struct floppy_raw_cmd * request))143*d5c9a868SElliott Hughes UNUSED(static __inline__ void RR_SETCONT(struct floppy_raw_cmd *request))
144*d5c9a868SElliott Hughes {
145*d5c9a868SElliott Hughes #ifdef FD_RAW_MORE
146*d5c9a868SElliott Hughes request->flags |= FD_RAW_MORE;
147*d5c9a868SElliott Hughes #endif
148*d5c9a868SElliott Hughes }
149*d5c9a868SElliott Hughes
150*d5c9a868SElliott Hughes
UNUSED(static __inline__ int RR_SIZECODE (struct floppy_raw_cmd * request))151*d5c9a868SElliott Hughes UNUSED(static __inline__ int RR_SIZECODE(struct floppy_raw_cmd *request))
152*d5c9a868SElliott Hughes {
153*d5c9a868SElliott Hughes return request->cmd[5];
154*d5c9a868SElliott Hughes }
155*d5c9a868SElliott Hughes
156*d5c9a868SElliott Hughes
157*d5c9a868SElliott Hughes
UNUSED(static __inline__ int RR_TRACK (struct floppy_raw_cmd * request))158*d5c9a868SElliott Hughes UNUSED(static __inline__ int RR_TRACK(struct floppy_raw_cmd *request))
159*d5c9a868SElliott Hughes {
160*d5c9a868SElliott Hughes return request->cmd[2];
161*d5c9a868SElliott Hughes }
162*d5c9a868SElliott Hughes
163*d5c9a868SElliott Hughes
UNUSED(static __inline__ int GET_DRIVE (int fd))164*d5c9a868SElliott Hughes UNUSED(static __inline__ int GET_DRIVE(int fd))
165*d5c9a868SElliott Hughes {
166*d5c9a868SElliott Hughes struct MT_STAT statbuf;
167*d5c9a868SElliott Hughes
168*d5c9a868SElliott Hughes if (MT_FSTAT(fd, &statbuf) < 0 ){
169*d5c9a868SElliott Hughes perror("stat");
170*d5c9a868SElliott Hughes return -1;
171*d5c9a868SElliott Hughes }
172*d5c9a868SElliott Hughes
173*d5c9a868SElliott Hughes if (!S_ISBLK(statbuf.st_mode) ||
174*d5c9a868SElliott Hughes MAJOR(statbuf.st_rdev) != FLOPPY_MAJOR)
175*d5c9a868SElliott Hughes return -1;
176*d5c9a868SElliott Hughes
177*d5c9a868SElliott Hughes return (int) MINOR( statbuf.st_rdev );
178*d5c9a868SElliott Hughes }
179*d5c9a868SElliott Hughes
180*d5c9a868SElliott Hughes
181*d5c9a868SElliott Hughes
182*d5c9a868SElliott Hughes /* void print_message(RawRequest_t *raw_cmd,char *message);*/
183*d5c9a868SElliott Hughes int send_one_cmd(int fd, RawRequest_t *raw_cmd, const char *message);
184*d5c9a868SElliott Hughes int analyze_one_reply(RawRequest_t *raw_cmd, int *bytes, int do_print);
185*d5c9a868SElliott Hughes
186*d5c9a868SElliott Hughes #endif
187*d5c9a868SElliott Hughes
188*d5c9a868SElliott Hughes int init_geom(int fd, struct device *dev, struct device *orig_dev,
189*d5c9a868SElliott Hughes struct MT_STAT *statbuf);
190