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 {"ipldev", "IPLDEV ", "NSS ", 4096, 0, 0},
42 {"login", "LOGIN ", "NSS ", 4096, 0, 0},
43 {"", "" , "" , -1, -1, 0},
46 static void save_file(struct table
*te
, int filesize
, u8
*buf
)
53 ret
= find_file(te
->fn
, te
->ft
, &fst
);
57 wto("' already exists on the device.\n");
58 wto("The device has been left unmodified.\n");
62 ret
= create_file(te
->fn
, te
->ft
, te
->lrecl
, &fst
);
64 wto("Could not create file '");
71 ascii2ebcdic(buf
, filesize
);
74 if (filesize
> te
->lrecl
)
76 snprintf(pbuf
, 100, "special file, writing copy of data to LBA %d\n",
79 write_blk(buf
, te
->lba
);
82 for(rec
=0; rec
<(filesize
/te
->lrecl
); rec
++)
83 append_record(&fst
, buf
+ (rec
* te
->lrecl
));
85 if (filesize
% te
->lrecl
) {
88 memset(buf2
, 0, te
->lrecl
);
89 memcpy(buf2
, buf
+ (rec
* te
->lrecl
), filesize
% te
->lrecl
);
91 append_record(&fst
, buf2
);
95 static u32
getnumber(u8
*data
, int digits
)
99 for(;digits
; digits
--, data
++)
100 ret
= (ret
* 8) + (*data
- '0');
105 static void readcard(u8
*buf
)
117 ccw
.addr
= ADDR31(buf
);
119 ORB
.param
= 0x12345678,
122 ORB
.addr
= ADDR31(&ccw
);
124 ret
= __do_io(ipl_sch
);
127 return; // end of media
134 void unload_archive(void)
137 struct cpio_hdr
*hdr
;
146 dasd_buf
= malloc(2*1024*1024);
147 hdr
= (void*) dasd_buf
;
153 /* read a file header */
154 if (fill
< sizeof(struct cpio_hdr
)) {
155 readcard(dasd_buf
+ fill
);
159 namesize
= getnumber(hdr
->namesize
, 6);
160 filesize
= getnumber(hdr
->filesize
, 11);
162 while(namesize
+ sizeof(struct cpio_hdr
) > fill
) {
163 readcard(dasd_buf
+ fill
);
167 if ((namesize
== 11) &&
168 !strncmp("TRAILER!!!", (char*) hdr
->data
, 10))
172 for(i
=0; table
[i
].lrecl
!= -1; i
++) {
173 if (!strcmp((char*) hdr
->data
, table
[i
].arch
)) {
180 snprintf(printbuf
, 132, "processing '%.8s' '%.8s' => '%s'\n",
181 table
[i
].fn
, table
[i
].fn
+ 8, (char*) hdr
->data
);
184 snprintf(printbuf
, 132, "skipping '%s'\n",
189 fill
-= (sizeof(struct cpio_hdr
) + namesize
);
190 memmove(hdr
, hdr
->data
+ namesize
, fill
);
192 /* read the entire file into storage (assuming it's <= 1MB) */
193 while(fill
< filesize
) {
194 readcard(dasd_buf
+ fill
);
199 save_file(&table
[i
], filesize
, dasd_buf
);
202 memmove(dasd_buf
, dasd_buf
+ filesize
, fill
);