2 * Copyright (c) 2011 Josef 'Jeff' Sipek
29 u32 lba
; /* 0 means undef */
32 static struct table table
[] = {
33 {"hvf.directory", "HVF ", "DIRECT ", 80, 1, 0},
34 {"system.config", "SYSTEM ", "CONFIG ", 80, 1, 0},
35 {"local-3215.txt", "HVF ", "LOGO ", 80, 1, 0},
36 {"hvf", "HVF ", "ELF ", 4096, 0, 0},
37 {"eckd.rto", "ECKDLOAD", "BIN ", 4096, 0, 1},
38 {"loader.rto", "DASDLOAD", "BIN ", 4096, 0, 2},
39 {"installed_files.txt", "HVF ", "TEXT ", 80, 1, 0},
40 {"8ball", "8BALL ", "NSS ", 4096, 0, 0},
41 {"", "" , "" , -1, -1, 0},
44 static void save_file(struct table
*te
, int filesize
, u8
*buf
)
51 ret
= find_file(te
->fn
, te
->ft
, &fst
);
55 wto("' already exists on the device.\n");
56 wto("The device has been left unmodified.\n");
60 ret
= create_file(te
->fn
, te
->ft
, te
->lrecl
, &fst
);
62 wto("Could not create file '");
69 ascii2ebcdic(buf
, filesize
);
72 if (filesize
> te
->lrecl
)
74 snprintf(pbuf
, 100, "special file, writing copy of data to LBA %d\n",
77 write_blk(buf
, te
->lba
);
80 for(rec
=0; rec
<(filesize
/te
->lrecl
); rec
++) {
81 snprintf(pbuf
, 100, "rec %03x at %p\n", rec
,
82 buf
+ (rec
* te
->lrecl
));
84 append_record(&fst
, buf
+ (rec
* te
->lrecl
));
87 if (filesize
% te
->lrecl
) {
90 memset(buf2
, 0, te
->lrecl
);
91 memcpy(buf2
, buf
+ (rec
* te
->lrecl
), filesize
% te
->lrecl
);
93 snprintf(pbuf
, 100, "rec %03x at %p\n", rec
,
94 buf
+ (rec
* te
->lrecl
));
96 append_record(&fst
, buf2
);
100 static u32
getnumber(u8
*data
, int digits
)
104 for(;digits
; digits
--, data
++)
105 ret
= (ret
* 8) + (*data
- '0');
110 static void readcard(u8
*buf
)
122 ccw
.addr
= ADDR31(buf
);
124 ORB
.param
= 0x12345678,
127 ORB
.addr
= ADDR31(&ccw
);
129 ret
= __do_io(ipl_sch
);
132 return; // end of media
139 void unload_archive(void)
142 struct cpio_hdr
*hdr
;
151 dasd_buf
= malloc(2*1024*1024);
152 hdr
= (void*) dasd_buf
;
158 /* read a file header */
159 if (fill
< sizeof(struct cpio_hdr
)) {
160 readcard(dasd_buf
+ fill
);
164 namesize
= getnumber(hdr
->namesize
, 6);
165 filesize
= getnumber(hdr
->filesize
, 11);
167 while(namesize
+ sizeof(struct cpio_hdr
) > fill
) {
168 readcard(dasd_buf
+ fill
);
172 if ((namesize
== 11) &&
173 !strncmp("TRAILER!!!", (char*) hdr
->data
, 10))
177 for(i
=0; table
[i
].lrecl
!= -1; i
++) {
178 if (!strcmp((char*) hdr
->data
, table
[i
].arch
)) {
185 snprintf(printbuf
, 132, "processing '%.8s' '%.8s' => '%s'\n",
186 table
[i
].fn
, table
[i
].fn
+ 8, (char*) hdr
->data
);
189 snprintf(printbuf
, 132, "skipping '%s'\n",
194 fill
-= (sizeof(struct cpio_hdr
) + namesize
);
195 memmove(hdr
, hdr
->data
+ namesize
, fill
);
197 /* read the entire file into storage (assuming it's <= 1MB) */
198 while(fill
< filesize
) {
199 readcard(dasd_buf
+ fill
);
204 save_file(&table
[i
], filesize
, dasd_buf
);
207 memmove(dasd_buf
, dasd_buf
+ filesize
, fill
);