■とりあえず安全なのから
/usr/include/linux/ps2/mcio.h を見ると、とっかかりに最高な PS2MC_IOCGETINFO
てのがあったのでたたいてみました。
#include <stdio.h>
#include <stdlib.h>
#include <asm/types.h>
#include <sys/types.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <linux/ps2/mcio.h>
#define TARGET "/dev/ps2mc00"
int main(void)
{
int rc;
int fd;
struct ps2mc_cardinfo info;
fd = open(TARGET, O_RDONLY);
if (fd < 0) {
perror(TARGET);
return EXIT_FAILURE;
}
rc = ioctl(fd, PS2MC_IOCGETINFO, &info);
close(fd);
printf("rc=%d\n", rc);
puts("\nstruct ps2mc_cardinfo:");
printf("type=%0x\n", info.type);
printf("blocksize=%0d\n", info.blocksize);
printf("totalblocks=%0d\n", info.totalblocks);
printf("freeblocks=%0d\n", info.freeblocks);
printf("formatted=%0d\n", info.formatted);
printf("generation=%0d\n", info.generation);
printf("busy=%0d\n", info.busy);
return EXIT_SUCCESS;
}
出力はこんな感じ。
rc=0 struct ps2mc_cardinfo: type=2 blocksize=1024 totalblocks=8192 freeblocks=5817 formatted=1 generation=1 busy=1ちゃんと動いたみたい。 こいつはマウントして df すると
/dev/ps2mc00 8192 2375 5817 29% /mnt/mc00てなってます。 ヘッダによると mode の2は ps2 のメモカという意味です。 0:カラ 1:PS1 2:PS2 3:ポケステ だそうです。
■つぎ、 PS2MC_IOCREAD
に挑戦。でも struct ps2mc_arg になにを渡せばいいのやら。
いろいろためした結果。
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <asm/types.h>
#include <sys/types.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <linux/ps2/mcio.h>
#define TARGET "/dev/ps2mc00"
#define READ_MODE 0
#define WRITE_MODE 1
#define USER_COPY 2
void dump(void *vp, int size)
{
unsigned char *ptr = (unsigned char *)vp;
int u, i;
FILE *fp = stdout;
int till;
for (u = 0 ; u < size ; u += 0x10) {
till = size - u < 0x10 ? size - u : 0x10;
fprintf(fp, "%04x:", u);
for (i = 0 ; i < till ; i ++) fprintf(fp, " %02x", ptr[u+i]);
fputs(" : ", fp);
for (i = 0 ; i < till ; i ++) {
fputc(isprint(ptr[u+i]) ? ptr[u+i] : '.', fp);
}
fputc('\n', fp);
}
}
int main(void)
{
int rc;
int fd;
struct ps2mc_arg arg;
char block[1024];
fd = open(TARGET, O_RDONLY);
if (fd < 0) {
perror(TARGET);
return EXIT_FAILURE;
}
//arg.path = "BWLINUX/icon.sys";
arg.path = "/p2lboot.cnf";
arg.pathlen = strlen(arg.path);
arg.mode = READ_MODE;
arg.pos = 0;
arg.data = block;
arg.count = sizeof (block);
memset(arg.reserved, 0, sizeof (arg.reserved));
rc = ioctl(fd, PS2MC_IOCREAD, &arg);
close(fd);
printf("rc=%d\n", rc);
dump(block, rc);
return EXIT_SUCCESS;
}
これで出力はこうなりました。 /p2lboot.cnf が読めました。
rc=63 0000: 22 4c 69 6e 75 78 20 6f 6e 20 4d 43 22 09 76 6d : "Linux on MC".vm 0010: 6c 69 6e 75 78 20 22 22 09 32 30 33 20 2f 64 65 : linux "".203 /de 0020: 76 2f 68 64 61 31 20 22 22 20 4c 69 6e 75 78 20 : v/hda1 "" Linux 0030: 6f 6e 20 4d 65 6d 6f 72 79 20 43 61 72 64 0a : on Memory Card.READ_MODE てマクロは mcfs のソースからひっぱってきたのですが、 あってるかどうかは試していません。 struct ps2mc_arg の pos の単位はバイトでした。
つぎ、ディレクトリを読む。。。。わかんね〜
マウントしたほうが早いぢゃん。。。つかえね〜(落胆
#format,unformat みたいなコマンドもありますが、怖いのでやってません。
あと、書きこみはメモリカードのROMが劣化するのでやりません(笑