source: trunk/minix/commands/i386/mtools-3.9.7/devices.h@ 11

Last change on this file since 11 was 9, checked in by Mattia Monga, 14 years ago

Minix 3.1.2a

File size: 3.3 KB
Line 
1#ifdef OS_linux
2
3#ifdef HAVE_SYS_SYSMACROS_H
4
5#include <sys/sysmacros.h>
6#ifndef MAJOR
7#define MAJOR(dev) major(dev)
8#endif /* MAJOR not defined */
9#ifndef MINOR
10#define MINOR(dev) minor(dev)
11#endif /* MINOR not defined */
12
13#else
14
15#include <linux/fs.h> /* get MAJOR/MINOR from Linux kernel */
16#ifndef major
17#define major(x) MAJOR(x)
18#endif
19
20#endif /* HAVE_SYS_SYSMACROS_H */
21
22#include <linux/fd.h>
23#include <linux/fdreg.h>
24#include <linux/major.h>
25
26
27typedef struct floppy_raw_cmd RawRequest_t;
28
29UNUSED(static inline void RR_INIT(struct floppy_raw_cmd *request))
30{
31 request->data = 0;
32 request->length = 0;
33 request->cmd_count = 9;
34 request->flags = FD_RAW_INTR | FD_RAW_NEED_SEEK | FD_RAW_NEED_DISK
35#ifdef FD_RAW_SOFTFAILUE
36 | FD_RAW_SOFTFAILURE | FD_RAW_STOP_IF_FAILURE
37#endif
38 ;
39 request->cmd[1] = 0;
40 request->cmd[6] = 0;
41 request->cmd[7] = 0x1b;
42 request->cmd[8] = 0xff;
43 request->reply_count = 0;
44}
45
46UNUSED(static inline void RR_SETRATE(struct floppy_raw_cmd *request, int rate))
47{
48 request->rate = rate;
49}
50
51UNUSED(static inline void RR_SETDRIVE(struct floppy_raw_cmd *request,int drive))
52{
53 request->cmd[1] = (request->cmd[1] & ~3) | (drive & 3);
54}
55
56UNUSED(static inline void RR_SETTRACK(struct floppy_raw_cmd *request,int track))
57{
58 request->cmd[2] = track;
59}
60
61UNUSED(static inline void RR_SETPTRACK(struct floppy_raw_cmd *request,
62 int track))
63{
64 request->track = track;
65}
66
67UNUSED(static inline void RR_SETHEAD(struct floppy_raw_cmd *request, int head))
68{
69 if(head)
70 request->cmd[1] |= 4;
71 else
72 request->cmd[1] &= ~4;
73 request->cmd[3] = head;
74}
75
76UNUSED(static inline void RR_SETSECTOR(struct floppy_raw_cmd *request,
77 int sector))
78{
79 request->cmd[4] = sector;
80 request->cmd[6] = sector-1;
81}
82
83UNUSED(static inline void RR_SETSIZECODE(struct floppy_raw_cmd *request,
84 int sizecode))
85{
86 request->cmd[5] = sizecode;
87 request->cmd[6]++;
88 request->length += 128 << sizecode;
89}
90
91#if 0
92static inline void RR_SETEND(struct floppy_raw_cmd *request, int end)
93{
94 request->cmd[6] = end;
95}
96#endif
97
98UNUSED(static inline void RR_SETDIRECTION(struct floppy_raw_cmd *request,
99 int direction))
100{
101 if(direction == MT_READ) {
102 request->flags |= FD_RAW_READ;
103 request->cmd[0] = FD_READ & ~0x80;
104 } else {
105 request->flags |= FD_RAW_WRITE;
106 request->cmd[0] = FD_WRITE & ~0x80;
107 }
108}
109
110
111UNUSED(static inline void RR_SETDATA(struct floppy_raw_cmd *request,
112 caddr_t data))
113{
114 request->data = data;
115}
116
117
118#if 0
119static inline void RR_SETLENGTH(struct floppy_raw_cmd *request, int length)
120{
121 request->length += length;
122}
123#endif
124
125UNUSED(static inline void RR_SETCONT(struct floppy_raw_cmd *request))
126{
127#ifdef FD_RAW_MORE
128 request->flags |= FD_RAW_MORE;
129#endif
130}
131
132
133UNUSED(static inline int RR_SIZECODE(struct floppy_raw_cmd *request))
134{
135 return request->cmd[5];
136}
137
138
139
140UNUSED(static inline int RR_TRACK(struct floppy_raw_cmd *request))
141{
142 return request->cmd[2];
143}
144
145
146UNUSED(static inline int GET_DRIVE(int fd))
147{
148 struct stat statbuf;
149
150 if (fstat(fd, &statbuf) < 0 ){
151 perror("stat");
152 return -1;
153 }
154
155 if (!S_ISBLK(statbuf.st_mode) ||
156 MAJOR(statbuf.st_rdev) != FLOPPY_MAJOR)
157 return -1;
158
159 return MINOR( statbuf.st_rdev );
160}
161
162
163
164/* void print_message(RawRequest_t *raw_cmd,char *message);*/
165int send_one_cmd(int fd, RawRequest_t *raw_cmd, const char *message);
166int analyze_one_reply(RawRequest_t *raw_cmd, int *bytes, int do_print);
167
168
169#endif
Note: See TracBrowser for help on using the repository browser.