-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathroserv.c
More file actions
229 lines (201 loc) · 6.5 KB
/
Copy pathroserv.c
File metadata and controls
229 lines (201 loc) · 6.5 KB
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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
/* $Id: roserv.c,v 1.13 2006/07/11 22:22:31 chris Exp $
*
* Olivetti M20 PCOS diskette access utility: image readonly services
* Copyright (C) 2000,2001,2006 by Christian Groessler
*
* This program 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 2
* of the License, or (at your option) any later version.
*
* This program 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 this program; see the file COPYING. If not, write
* to the Free Software Foundation, 51 Franklin Street - Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include "cpgdefs.h"
#include "cpgtypes.h"
#include "roprotos.h"
#include "blockop.h"
#include "pcosdir.h"
#include "util.h"
static const char spaces[]=" "; /* 16 space characters */
struct m20dir *diskdir;
/* show directory */
void do_ls(FILE **file,int argc,char **argv,int lsl)
{
int i;
char nambuf[18]; /* lenght of a dir. entry: name + 2 bytes pointing where the file is - asb */
char scbuf[256];
struct disk_header *dskhdr = (struct disk_header *)scbuf;
if (read_phys_block(*file,0x200,(void *)dskhdr)) { /* 0x200 start of DIRECTORY. 0x20200 in the dump. Control
block begin at 0x20000 and start with disk name. -asb */
fprintf(stderr,"do_ls: cannot read main disk block\n");
return;
}
if (get_dir(*file,&diskdir)) {
fprintf(stderr,"do_ls: get_dir error!\n");
return;
}
if (lsl) printf("\n");
if (lsl && dskhdr->volname[0]) { /* disk has a volume name */
printf("Volume name: %s\n",dskhdr->volname);
}
if (lsl)
printf("# of files: %d\t\tfree blocks: %d\n",
diskdir->entries,
get_free_blocks(dskhdr,NULL,NULL));
if (lsl && diskdir->entries) {
printf("\nNAME \tSIZE\tBLOCKS\tALLBL\tEXTENTS\n");
printf("-------------- \t----\t------\t-----\t-------\n");
}
for (i=0; i<diskdir->entries; i++) {
if (lsl) {
strcpy(nambuf,diskdir->files[i].name);
strncpy(nambuf + strlen(nambuf),spaces,16-strlen(nambuf));
nambuf[16] = 0;
printf("%s\t%lu\t%lu\t%lu\t%lu\n",
nambuf,(unsigned long)diskdir->files[i].size,
(unsigned long)((diskdir->files[i].size + 0xff) >> 8),
(unsigned long)((diskdir->files[i].alloc_size) >> 8),
(unsigned long)diskdir->files[i].extents);
}
else {
puts(diskdir->files[i].name);
}
}
if (lsl) printf("\n");
}
/* cat a file */
void do_cat(FILE **file,int argc,char **argv)
{
int i,found = -1;
char *srcfile;
if (argc != 2) {
fprintf(stderr,"need srcname argument\n");
return;
}
srcfile = *(argv+1);
/* get contents of diskette */
if (get_dir(*file,&diskdir)) {
fprintf(stderr,"do_cat: get_dir error!\n");
return;
}
/* search requested file */
for (i=0; i<diskdir->entries; i++) {
if (!strcmp(diskdir->files[i].name,srcfile)) {
found = i;
break;
}
}
if (found == -1) {
fprintf(stderr,"%s not found on diskette\n",srcfile);
return;
}
get_file(*file,&diskdir->files[i],stdout); /* copy file out */
}
/* copy a file to host */
void do_get(FILE **file,int argc,char **argv)
{
int i,found = -1;
char *srcfile,*destfile;
FILE *dest;
if (argc != 2 && argc != 3) {
fprintf(stderr,"need srcname [destname] argument\n");
return;
}
srcfile = *(argv+1);
if (argc == 2) destfile = srcfile;
else destfile = *(argv+2);
#ifdef DEBUG
printf("srcfile: %s, destfile: %s\n",srcfile,destfile);
#endif
/* get contents of diskette */
if (get_dir(*file,&diskdir)) {
fprintf(stderr,"do_get: get_dir error!\n");
return;
}
/* search requested file */
for (i=0; i<diskdir->entries; i++) {
if (!strcmp(diskdir->files[i].name,srcfile)) {
found = i;
break;
}
}
if (found == -1) {
fprintf(stderr,"%s not found on diskette\n",srcfile);
return;
}
/* open/create destination file */
dest = fopen(destfile,"wb");
if (! dest) {
fprintf(stderr,"cannot open destination file %s: %s\n",destfile,strerror(errno));
return;
}
/* copy file out */
get_file(*file,&diskdir->files[i],dest);
/* close the destination file */
if (fclose(dest)) {
fprintf(stderr,"cannot close destination file %s: %s\n",destfile,strerror(errno));
}
}
/* copy many files to host */
void do_mget(FILE **file,int argc,char **argv)
{
int i,f,found = -1;
char *filename;
FILE *dest;
if (argc < 2) {
fprintf(stderr,"no files to get\n");
return;
}
argc--; /* skip command argument */
f = 0; /* files start at argv[1] (start with f=1: see f++ in while() loop) */
/* get contents of diskette */
if (get_dir(*file,&diskdir)) {
fprintf(stderr,"do_get: get_dir error!\n");
return;
}
while (f++,argc--) {
filename = *(argv+f);
#ifdef DEBUG
printf("mgetting %s\n",filename);
#endif
/* search requested file */
for (i=0,found=-1; i<diskdir->entries; i++) {
if (!strcmp(diskdir->files[i].name,filename)) {
found = i;
break;
}
}
if (found == -1) {
fprintf(stderr,"%s not found on diskette -- ignoring\n",filename);
continue;
}
/* open/create destination file */
dest = fopen(filename,"wb");
if (! dest) {
fprintf(stderr,"cannot open destination file %s: %s\n",filename,strerror(errno));
return;
}
/* copy file out */
get_file(*file,&diskdir->files[i],dest);
/* close the destination file */
if (fclose(dest)) {
fprintf(stderr,"cannot close destination file %s: %s (ignored)\n",filename,strerror(errno));
}
}
return;
}
/* Local Variables: */
/* c-file-style: "cpg" */
/* c-basic-offset: 4 */
/* End: */