3 /* Copyright 1996-2002,2009 Alain Knaff.
4 * This file is part of mtools.
6 * Mtools is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * Mtools is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with Mtools. If not, see <http://www.gnu.org/licenses/>.
19 #include <sys/types.h>
21 #ifdef HAVE_SYS_SYSMACROS_H
23 #include <sys/sysmacros.h>
25 #define MAJOR(dev) major(dev)
26 #endif /* MAJOR not defined */
28 #define MINOR(dev) minor(dev)
29 #endif /* MINOR not defined */
33 #include <linux/fs.h> /* get MAJOR/MINOR from Linux kernel */
35 #define major(x) MAJOR(x)
38 #endif /* HAVE_SYS_SYSMACROS_H */
41 #include <linux/fdreg.h>
42 #include <linux/major.h>
45 typedef struct floppy_raw_cmd RawRequest_t;
47 UNUSED(static __inline__ void RR_INIT(struct floppy_raw_cmd *request))
51 request->cmd_count = 9;
52 request->flags = FD_RAW_INTR | FD_RAW_NEED_SEEK | FD_RAW_NEED_DISK
53 #ifdef FD_RAW_SOFTFAILUE
54 | FD_RAW_SOFTFAILURE | FD_RAW_STOP_IF_FAILURE
59 request->cmd[7] = 0x1b;
60 request->cmd[8] = 0xff;
61 request->reply_count = 0;
64 UNUSED(static __inline__ void RR_SETRATE(struct floppy_raw_cmd *request, int rate))
69 UNUSED(static __inline__ void RR_SETDRIVE(struct floppy_raw_cmd *request,int drive))
71 request->cmd[1] = (request->cmd[1] & ~3) | (drive & 3);
74 UNUSED(static __inline__ void RR_SETTRACK(struct floppy_raw_cmd *request,int track))
76 request->cmd[2] = track;
79 UNUSED(static __inline__ void RR_SETPTRACK(struct floppy_raw_cmd *request,
82 request->track = track;
85 UNUSED(static __inline__ void RR_SETHEAD(struct floppy_raw_cmd *request, int head))
90 request->cmd[1] &= ~4;
91 request->cmd[3] = head;
94 UNUSED(static __inline__ void RR_SETSECTOR(struct floppy_raw_cmd *request,
97 request->cmd[4] = sector;
98 request->cmd[6] = sector-1;
101 UNUSED(static __inline__ void RR_SETSIZECODE(struct floppy_raw_cmd *request,
104 request->cmd[5] = sizecode;
106 request->length += 128 << sizecode;
110 static inline void RR_SETEND(struct floppy_raw_cmd *request, int end)
112 request->cmd[6] = end;
116 UNUSED(static __inline__ void RR_SETDIRECTION(struct floppy_raw_cmd *request,
119 if(direction == MT_READ) {
120 request->flags |= FD_RAW_READ;
121 request->cmd[0] = FD_READ & ~0x80;
123 request->flags |= FD_RAW_WRITE;
124 request->cmd[0] = FD_WRITE & ~0x80;
129 UNUSED(static __inline__ void RR_SETDATA(struct floppy_raw_cmd *request,
132 request->data = data;
137 static inline void RR_SETLENGTH(struct floppy_raw_cmd *request, int length)
139 request->length += length;
143 UNUSED(static __inline__ void RR_SETCONT(struct floppy_raw_cmd *request))
146 request->flags |= FD_RAW_MORE;
151 UNUSED(static __inline__ int RR_SIZECODE(struct floppy_raw_cmd *request))
153 return request->cmd[5];
158 UNUSED(static __inline__ int RR_TRACK(struct floppy_raw_cmd *request))
160 return request->cmd[2];
164 UNUSED(static __inline__ int GET_DRIVE(int fd))
166 struct MT_STAT statbuf;
168 if (MT_FSTAT(fd, &statbuf) < 0 ){
173 if (!S_ISBLK(statbuf.st_mode) ||
174 MAJOR(statbuf.st_rdev) != FLOPPY_MAJOR)
177 return MINOR( statbuf.st_rdev );
182 /* void print_message(RawRequest_t *raw_cmd,char *message);*/
183 int send_one_cmd(int fd, RawRequest_t *raw_cmd, const char *message);
184 int analyze_one_reply(RawRequest_t *raw_cmd, int *bytes, int do_print);