]>
Commit | Line | Data |
---|---|---|
dee56309 CV |
1 | /* mtinfo.h: Defininitions for the Cygwin tape driver class. |
2 | ||
61522196 | 3 | Copyright 2004, 2005, 2006, 2008, 2012 Red Hat, Inc. |
dee56309 CV |
4 | |
5 | This file is part of Cygwin. | |
6 | ||
7 | This software is a copyrighted work licensed under the terms of the | |
8 | Cygwin license. Please consult the file "CYGWIN_LICENSE" for | |
9 | details. */ | |
10 | ||
dee56309 CV |
11 | /* Maximum number of supported partitions per drive. */ |
12 | #define MAX_PARTITION_NUM 64 | |
13 | /* Maximum number of supported drives. */ | |
14 | #define MAX_DRIVE_NUM 8 | |
15 | ||
16 | /* Values for bookkeeping of the tape position relative to filemarks | |
17 | and eod/eom. */ | |
18 | enum eom_val | |
19 | { | |
20 | no_eof, | |
21 | eof_hit, | |
22 | eof, | |
23 | eod_hit, | |
24 | eod, | |
25 | eom_hit, | |
26 | eom | |
27 | }; | |
28 | ||
29 | enum dirty_state | |
30 | { | |
31 | clean, | |
32 | has_read, | |
0c8731b8 CV |
33 | has_written, |
34 | async_write_pending | |
dee56309 CV |
35 | }; |
36 | ||
37 | enum lock_state | |
38 | { | |
39 | unlocked, | |
40 | lock_error, | |
41 | auto_locked, | |
42 | locked | |
43 | }; | |
44 | ||
45 | /* Partition specific information */ | |
46 | class mtinfo_part | |
47 | { | |
48 | public: | |
61522196 CV |
49 | int32_t block; /* logical block no */ |
50 | int32_t file; /* current file no */ | |
51 | int32_t fblock; /* relative block no */ | |
dee56309 CV |
52 | bool smark; /* At setmark? */ |
53 | eom_val emark; /* "end-of"-mark */ | |
54 | ||
61522196 | 55 | void initialize (int32_t nblock = -1); |
dee56309 CV |
56 | }; |
57 | ||
58 | class mtinfo_drive | |
59 | { | |
60 | int drive; | |
61 | int lasterr; | |
61522196 CV |
62 | int32_t partition; |
63 | int32_t block; | |
dee56309 CV |
64 | dirty_state dirty; |
65 | lock_state lock; | |
66 | TAPE_GET_DRIVE_PARAMETERS _dp; | |
67 | TAPE_GET_MEDIA_PARAMETERS _mp; | |
61522196 CV |
68 | /* sizeof(OVERLAPPED) == 20 on 32 bit, 32 on 64 bit. A drive is always |
69 | opened exclusively by a single process, though, so instead of the | |
70 | OVERLAPPED structure, we just keep track of the pointer to the | |
71 | OVERLAPPED structure in the application's fhandler. */ | |
72 | LPOVERLAPPED ov; | |
ff084343 CV |
73 | struct status_flags |
74 | { | |
75 | unsigned buffer_writes : 1; | |
0c8731b8 | 76 | unsigned async_writes : 1; |
ff084343 CV |
77 | unsigned two_fm : 1; |
78 | unsigned fast_eom : 1; | |
79 | unsigned auto_lock : 1; | |
80 | unsigned sysv : 1; | |
81 | unsigned nowait : 1; | |
82 | } status; | |
dee56309 CV |
83 | mtinfo_part _part[MAX_PARTITION_NUM]; |
84 | ||
85 | inline int error (const char *str) | |
86 | { | |
87 | if (lasterr) | |
b575e059 | 88 | debug_printf ("%s: Win32 error %d", str, lasterr); |
dee56309 CV |
89 | return lasterr; |
90 | } | |
91 | inline bool get_feature (DWORD parm) | |
92 | { | |
93 | return ((parm & TAPE_DRIVE_HIGH_FEATURES) | |
94 | ? ((_dp.FeaturesHigh & parm) != 0) | |
95 | : ((_dp.FeaturesLow & parm) != 0)); | |
96 | } | |
61522196 CV |
97 | int get_pos (HANDLE mt, int32_t *ppartition = NULL, int32_t *pblock = NULL); |
98 | int _set_pos (HANDLE mt, int mode, int32_t count, int partition, BOOL dont_wait); | |
99 | int create_partitions (HANDLE mt, int32_t count); | |
100 | int set_partition (HANDLE mt, int32_t count); | |
dee56309 CV |
101 | int write_marks (HANDLE mt, int marktype, DWORD count); |
102 | int erase (HANDLE mt, int mode); | |
103 | int prepare (HANDLE mt, int action, bool is_auto = false); | |
61522196 CV |
104 | int set_compression (HANDLE mt, int32_t count); |
105 | int set_blocksize (HANDLE mt, DWORD count); | |
ff084343 | 106 | int get_status (HANDLE mt, struct mtget *get); |
61522196 | 107 | int set_options (HANDLE mt, int32_t options); |
0c8731b8 | 108 | int async_wait (HANDLE mt, DWORD *bytes_written); |
dee56309 CV |
109 | |
110 | public: | |
111 | void initialize (int num, bool first_time); | |
112 | int get_dp (HANDLE mt); | |
113 | int get_mp (HANDLE mt); | |
114 | int open (HANDLE mt); | |
115 | int close (HANDLE mt, bool rewind); | |
61522196 CV |
116 | int read (HANDLE mt, LPOVERLAPPED pov, void *ptr, size_t &ulen); |
117 | int write (HANDLE mt, LPOVERLAPPED pov, const void *ptr, size_t &len); | |
dee56309 | 118 | int ioctl (HANDLE mt, unsigned int cmd, void *buf); |
61522196 | 119 | int set_pos (HANDLE mt, int mode, int32_t count, bool sfm_func); |
dee56309 | 120 | |
825b3882 | 121 | IMPLEMENT_STATUS_FLAG (bool, buffer_writes) |
0c8731b8 | 122 | IMPLEMENT_STATUS_FLAG (bool, async_writes) |
825b3882 CV |
123 | IMPLEMENT_STATUS_FLAG (bool, two_fm) |
124 | IMPLEMENT_STATUS_FLAG (bool, fast_eom) | |
125 | IMPLEMENT_STATUS_FLAG (bool, auto_lock) | |
126 | IMPLEMENT_STATUS_FLAG (bool, sysv) | |
127 | IMPLEMENT_STATUS_FLAG (bool, nowait) | |
128 | ||
2f9ae2ed CF |
129 | PTAPE_GET_DRIVE_PARAMETERS dp () { return &_dp; } |
130 | PTAPE_GET_MEDIA_PARAMETERS mp () { return &_mp; } | |
dee56309 CV |
131 | mtinfo_part *part (int num) { return &_part[num]; } |
132 | }; | |
133 | ||
134 | class mtinfo | |
135 | { | |
dee56309 CV |
136 | mtinfo_drive _drive[MAX_DRIVE_NUM]; |
137 | ||
138 | public: | |
2f9ae2ed | 139 | void initialize (); |
dee56309 CV |
140 | mtinfo_drive *drive (int num) { return &_drive[num]; } |
141 | }; |