1 | /* LibSAP |
---|
2 | * Version 0.9.3 |
---|
3 | * Copyright (C) 2000-2003 Eric Botcazou |
---|
4 | * |
---|
5 | * This program is free software; you can redistribute it and/or modify |
---|
6 | * it under the terms of the GNU General Public License as published by |
---|
7 | * the Free Software Foundation; either version 2 of the License, or |
---|
8 | * (at your option) any later version. |
---|
9 | * |
---|
10 | * This program is distributed in the hope that it will be useful, |
---|
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
13 | * GNU General Public License for more details. |
---|
14 | * |
---|
15 | * You should have received a copy of the GNU General Public License |
---|
16 | * along with this program; if not, write to the Free Software |
---|
17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
---|
18 | */ |
---|
19 | |
---|
20 | |
---|
21 | #ifndef LIBSAP_H |
---|
22 | #define LIBSAP_H |
---|
23 | |
---|
24 | #include <stdio.h> |
---|
25 | #include <time.h> |
---|
26 | |
---|
27 | |
---|
28 | /* constants for the SAP physical file formats */ |
---|
29 | #define SAP_NSECTS 16 |
---|
30 | |
---|
31 | #define SAP_NTRACKS1 80 |
---|
32 | #define SAP_SECTSIZE1 256 |
---|
33 | #define SAP_TRACKSIZE1 (SAP_NSECTS*SAP_SECTSIZE1) |
---|
34 | |
---|
35 | #define SAP_NTRACKS2 40 |
---|
36 | #define SAP_SECTSIZE2 128 |
---|
37 | #define SAP_TRACKSIZE2 (SAP_NSECTS*SAP_SECTSIZE2) |
---|
38 | |
---|
39 | |
---|
40 | /* types used by the library */ |
---|
41 | typedef unsigned int sapID; |
---|
42 | |
---|
43 | typedef struct { |
---|
44 | unsigned char format; |
---|
45 | unsigned char protection; |
---|
46 | unsigned char track; |
---|
47 | unsigned char sector; |
---|
48 | unsigned char data[258]; |
---|
49 | } sapsector_t; /* type of a SAP sector */ |
---|
50 | |
---|
51 | typedef struct { |
---|
52 | int size; |
---|
53 | int file_type; |
---|
54 | int data_type; |
---|
55 | time_t date; |
---|
56 | char comment[9]; |
---|
57 | int nblocks; |
---|
58 | int *block; |
---|
59 | } sapfileinfo_t; |
---|
60 | |
---|
61 | typedef int (*sapfilecb_t)(sapID id, const char filename[], int n, unsigned char trk20_data[]); |
---|
62 | |
---|
63 | |
---|
64 | /* return values */ |
---|
65 | #define SAP_OK 0 |
---|
66 | #define SAP_NO_STD_FMT (1<<0) |
---|
67 | #define SAP_PROTECTED (1<<1) |
---|
68 | #define SAP_BAD_SECTOR (1<<2) |
---|
69 | #define SAP_CRC_ERROR (1<<3) |
---|
70 | #define SAP_ERROR (1<<7) |
---|
71 | |
---|
72 | |
---|
73 | /* errno values */ |
---|
74 | extern int sap_errno; |
---|
75 | |
---|
76 | #define SAP_EBADF 1 |
---|
77 | #define SAP_EBUSY 2 |
---|
78 | #define SAP_EEMPTY 3 |
---|
79 | #define SAP_EFBIG 4 |
---|
80 | #define SAP_EINVAL 5 |
---|
81 | #define SAP_ENFILE 6 |
---|
82 | #define SAP_ENOENT 7 |
---|
83 | #define SAP_ENOSPC 8 |
---|
84 | #define SAP_EPERM 9 |
---|
85 | #define SAP_ETOOMANY 10 |
---|
86 | |
---|
87 | |
---|
88 | /* low-level functions */ |
---|
89 | extern int _ExtractDir(char buffer[], int buffer_size, int drive, int density, const unsigned char trk20_data[]); |
---|
90 | extern int _ForEachFile(sapID id, const char pattern[], sapfilecb_t callback, int save_back); |
---|
91 | |
---|
92 | |
---|
93 | /* physical format API functions */ |
---|
94 | #define SAP_FORMAT1 1 |
---|
95 | #define SAP_FORMAT2 2 |
---|
96 | |
---|
97 | extern sapID sap_OpenArchive(const char filename[], int *format); |
---|
98 | extern sapID sap_CreateArchive(const char filename[], int format); |
---|
99 | extern int sap_CloseArchive(sapID id); |
---|
100 | extern int sap_FillArchive(sapID id, sapsector_t *sector); |
---|
101 | extern int sap_ReadSector(sapID id, int track, int sect, sapsector_t *sector); |
---|
102 | extern int sap_ReadSectorEx(sapID id, int track, int sect, int nsects, unsigned char data[]); |
---|
103 | extern int sap_WriteSector(sapID id, int track, int sect, sapsector_t *sector); |
---|
104 | extern int sap_WriteSectorEx(sapID id, int track, int sect, int nsects, const unsigned char data[]); |
---|
105 | |
---|
106 | |
---|
107 | /* logical format API functions */ |
---|
108 | #define SAP_TRK40 1 |
---|
109 | #define SAP_TRK80 2 |
---|
110 | |
---|
111 | extern int sap_FormatArchive(sapID id, int capacity); |
---|
112 | extern int sap_ListArchive(sapID id, char buffer[], int buffer_size); |
---|
113 | extern int sap_AddFile(sapID id, const char filename[]); |
---|
114 | extern int sap_DeleteFile(sapID id, const char pattern[]); |
---|
115 | extern int sap_ExtractFile(sapID id, const char pattern[]); |
---|
116 | extern int sap_GetFileInfo(sapID id, const char filename[], sapfileinfo_t *info); |
---|
117 | |
---|
118 | #endif |
---|
119 | |
---|