xref: /aosp_15_r20/external/mtools/floppyd_io.h (revision d5c9a868b113e0ec0db2f27bc2ce8a253e77c4b0)
1*d5c9a868SElliott Hughes #ifndef MTOOLS_FLOPPYDIO_H
2*d5c9a868SElliott Hughes #define MTOOLS_FLOPPYDIO_H
3*d5c9a868SElliott Hughes 
4*d5c9a868SElliott Hughes /*  Copyright 1999 Peter Schlaile.
5*d5c9a868SElliott Hughes  *  Copyright 1998,2000-2002,2009 Alain Knaff.
6*d5c9a868SElliott Hughes  *  This file is part of mtools.
7*d5c9a868SElliott Hughes  *
8*d5c9a868SElliott Hughes  *  Mtools is free software: you can redistribute it and/or modify
9*d5c9a868SElliott Hughes  *  it under the terms of the GNU General Public License as published by
10*d5c9a868SElliott Hughes  *  the Free Software Foundation, either version 3 of the License, or
11*d5c9a868SElliott Hughes  *  (at your option) any later version.
12*d5c9a868SElliott Hughes  *
13*d5c9a868SElliott Hughes  *  Mtools is distributed in the hope that it will be useful,
14*d5c9a868SElliott Hughes  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
15*d5c9a868SElliott Hughes  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16*d5c9a868SElliott Hughes  *  GNU General Public License for more details.
17*d5c9a868SElliott Hughes  *
18*d5c9a868SElliott Hughes  *  You should have received a copy of the GNU General Public License
19*d5c9a868SElliott Hughes  *  along with Mtools.  If not, see <http://www.gnu.org/licenses/>.
20*d5c9a868SElliott Hughes  */
21*d5c9a868SElliott Hughes 
22*d5c9a868SElliott Hughes #ifdef USE_FLOPPYD
23*d5c9a868SElliott Hughes 
24*d5c9a868SElliott Hughes #include "stream.h"
25*d5c9a868SElliott Hughes 
26*d5c9a868SElliott Hughes typedef uint8_t Byte;
27*d5c9a868SElliott Hughes typedef uint32_t Dword;
28*d5c9a868SElliott Hughes typedef uint64_t Qword;
29*d5c9a868SElliott Hughes 
30*d5c9a868SElliott Hughes #define DWORD_ERR ((Dword) -1)
31*d5c9a868SElliott Hughes 
32*d5c9a868SElliott Hughes /*extern int ConnectToFloppyd(const char* name, Class_t** ioclass);*/
33*d5c9a868SElliott Hughes Stream_t *FloppydOpen(struct device *dev,
34*d5c9a868SElliott Hughes 		      const char *name, int mode, char *errmsg,
35*d5c9a868SElliott Hughes 		      mt_off_t *maxSize);
36*d5c9a868SElliott Hughes 
37*d5c9a868SElliott Hughes #define FLOPPYD_DEFAULT_PORT 5703
38*d5c9a868SElliott Hughes 
39*d5c9a868SElliott Hughes #define FLOPPYD_PROTOCOL_VERSION_OLD 10
40*d5c9a868SElliott Hughes #define FLOPPYD_PROTOCOL_VERSION 11
41*d5c9a868SElliott Hughes 
42*d5c9a868SElliott Hughes #define FLOPPYD_CAP_EXPLICIT_OPEN 1 /* explicit open. Useful for
43*d5c9a868SElliott Hughes 				     * clean signalling of readonly disks */
44*d5c9a868SElliott Hughes #define FLOPPYD_CAP_LARGE_SEEK 2    /* large seeks */
45*d5c9a868SElliott Hughes 
46*d5c9a868SElliott Hughes enum FloppydOpcodes {
47*d5c9a868SElliott Hughes 	OP_READ,
48*d5c9a868SElliott Hughes 	OP_WRITE,
49*d5c9a868SElliott Hughes 	OP_SEEK,
50*d5c9a868SElliott Hughes 	OP_FLUSH,
51*d5c9a868SElliott Hughes 	OP_CLOSE,
52*d5c9a868SElliott Hughes 	OP_IOCTL,
53*d5c9a868SElliott Hughes 	OP_OPRO,
54*d5c9a868SElliott Hughes 	OP_OPRW,
55*d5c9a868SElliott Hughes 	OP_SEEK64
56*d5c9a868SElliott Hughes };
57*d5c9a868SElliott Hughes 
58*d5c9a868SElliott Hughes enum AuthErrorsEnum {
59*d5c9a868SElliott Hughes 	AUTH_SUCCESS,
60*d5c9a868SElliott Hughes 	AUTH_PACKETOVERSIZE,
61*d5c9a868SElliott Hughes 	AUTH_AUTHFAILED,
62*d5c9a868SElliott Hughes 	AUTH_WRONGVERSION,
63*d5c9a868SElliott Hughes 	AUTH_DEVLOCKED,
64*d5c9a868SElliott Hughes 	AUTH_BADPACKET,
65*d5c9a868SElliott Hughes 	AUTH_IO_ERROR
66*d5c9a868SElliott Hughes };
67*d5c9a868SElliott Hughes 
68*d5c9a868SElliott Hughes 
UNUSED(static inline void cork (int sockhandle,int on))69*d5c9a868SElliott Hughes UNUSED(static inline void cork(int sockhandle, int on))
70*d5c9a868SElliott Hughes {
71*d5c9a868SElliott Hughes #ifdef TCP_CORK
72*d5c9a868SElliott Hughes 	if(setsockopt(sockhandle, IPPROTO_TCP,
73*d5c9a868SElliott Hughes 		      TCP_CORK, (char *)&on, sizeof(on)) < 0) {
74*d5c9a868SElliott Hughes 		perror("setsockopt cork");
75*d5c9a868SElliott Hughes 	}
76*d5c9a868SElliott Hughes #else
77*d5c9a868SElliott Hughes 	on = 1 ^ on;
78*d5c9a868SElliott Hughes 	if(setsockopt(sockhandle, IPPROTO_TCP,
79*d5c9a868SElliott Hughes 		      TCP_NODELAY, (char *)&on, sizeof(on)) < 0) {
80*d5c9a868SElliott Hughes 		perror("setsockopt nodelay");
81*d5c9a868SElliott Hughes 	}
82*d5c9a868SElliott Hughes #endif
83*d5c9a868SElliott Hughes }
84*d5c9a868SElliott Hughes 
85*d5c9a868SElliott Hughes 
86*d5c9a868SElliott Hughes #endif
87*d5c9a868SElliott Hughes #endif
88