summaryrefslogtreecommitdiff
path: root/devices.h
blob: 1d0e23660da347698dcb9e64df5f42ff01e8cdae (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
#ifdef OS_linux

/*  Copyright 1996-2002,2009 Alain Knaff.
 *  This file is part of mtools.
 *
 *  Mtools is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  Mtools is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with Mtools.  If not, see <http://www.gnu.org/licenses/>.
 */
#include <sys/types.h>

#ifdef HAVE_SYS_SYSMACROS_H

#include <sys/sysmacros.h>
#ifndef MAJOR
#define MAJOR(dev) major(dev)
#endif  /* MAJOR not defined */
#ifndef MINOR
#define MINOR(dev) minor(dev)
#endif  /* MINOR not defined */

#else
 
#include <linux/fs.h>        /* get MAJOR/MINOR from Linux kernel */
#ifndef major
#define major(x) MAJOR(x)
#endif

#endif /* HAVE_SYS_SYSMACROS_H */

#include <linux/fd.h>
#include <linux/fdreg.h>
#include <linux/major.h>


typedef struct floppy_raw_cmd RawRequest_t;

UNUSED(static __inline__ void RR_INIT(struct floppy_raw_cmd *request))
{
	request->data = 0;
	request->length = 0;
	request->cmd_count = 9;
	request->flags = FD_RAW_INTR | FD_RAW_NEED_SEEK | FD_RAW_NEED_DISK
#ifdef FD_RAW_SOFTFAILUE
		| FD_RAW_SOFTFAILURE | FD_RAW_STOP_IF_FAILURE
#endif
		;
	request->cmd[1] = 0;
	request->cmd[6] = 0;
	request->cmd[7] = 0x1b;
	request->cmd[8] = 0xff;
	request->reply_count = 0;
}

UNUSED(static __inline__ void RR_SETRATE(struct floppy_raw_cmd *request, int rate))
{
	request->rate = rate;
}

UNUSED(static __inline__ void RR_SETDRIVE(struct floppy_raw_cmd *request,int drive))
{
	request->cmd[1] = (request->cmd[1] & ~3) | (drive & 3);
}

UNUSED(static __inline__ void RR_SETTRACK(struct floppy_raw_cmd *request,int track))
{
	request->cmd[2] = track;
}

UNUSED(static __inline__ void RR_SETPTRACK(struct floppy_raw_cmd *request,
				       int track))
{
	request->track = track;
}

UNUSED(static __inline__ void RR_SETHEAD(struct floppy_raw_cmd *request, int head))
{
	if(head)
		request->cmd[1] |= 4;
	else
		request->cmd[1] &= ~4;
	request->cmd[3] = head;
}

UNUSED(static __inline__ void RR_SETSECTOR(struct floppy_raw_cmd *request, 
					   int sector))
{
	request->cmd[4] = sector;
	request->cmd[6] = sector-1;
}

UNUSED(static __inline__ void RR_SETSIZECODE(struct floppy_raw_cmd *request, 
					     int sizecode))
{
	request->cmd[5] = sizecode;
	request->cmd[6]++;
	request->length += 128 << sizecode;
}

#if 0
static inline void RR_SETEND(struct floppy_raw_cmd *request, int end)
{
	request->cmd[6] = end;
}
#endif

UNUSED(static __inline__ void RR_SETDIRECTION(struct floppy_raw_cmd *request, 
					      int direction))
{
	if(direction == MT_READ) {
		request->flags |= FD_RAW_READ;
		request->cmd[0] = FD_READ & ~0x80;
	} else {
		request->flags |= FD_RAW_WRITE;
		request->cmd[0] = FD_WRITE & ~0x80;
	}
}


UNUSED(static __inline__ void RR_SETDATA(struct floppy_raw_cmd *request, 
					 caddr_t data))
{
	request->data = data;
}


#if 0
static inline void RR_SETLENGTH(struct floppy_raw_cmd *request, int length)
{
	request->length += length;
}
#endif

UNUSED(static __inline__ void RR_SETCONT(struct floppy_raw_cmd *request))
{
#ifdef FD_RAW_MORE
	request->flags |= FD_RAW_MORE;
#endif
}


UNUSED(static __inline__ int RR_SIZECODE(struct floppy_raw_cmd *request))
{
	return request->cmd[5];
}



UNUSED(static __inline__ int RR_TRACK(struct floppy_raw_cmd *request))
{
	return request->cmd[2];
}


UNUSED(static __inline__ int GET_DRIVE(int fd))
{
	struct MT_STAT statbuf;

	if (MT_FSTAT(fd, &statbuf) < 0 ){
		perror("stat");
		return -1;
	}
	  
	if (!S_ISBLK(statbuf.st_mode) ||
	    MAJOR(statbuf.st_rdev) != FLOPPY_MAJOR)
		return -1;
	
	return MINOR( statbuf.st_rdev );
}



/* void print_message(RawRequest_t *raw_cmd,char *message);*/
int send_one_cmd(int fd, RawRequest_t *raw_cmd, const char *message);
int analyze_one_reply(RawRequest_t *raw_cmd, int *bytes, int do_print);


#endif