コード例 #1
0
ファイル: hardfile_host.cpp プロジェクト: adurdin/fs-uae
static void rdbdump (FILE *h, uae_u64 offset, uae_u8 *buf, int blocksize)
{
    static int cnt = 1;
    int i, blocks;
    char name[100];
    FILE *f;

    blocks = (buf[132] << 24) | (buf[133] << 16) | (buf[134] << 8) | (buf[135] << 0);
    if (blocks < 0 || blocks > 100000)
        return;
    _stprintf (name, "rdb_dump_%d.rdb", cnt);
    f = uae_tfopen (name, "wb");
    if (!f)
        return;
    for (i = 0; i <= blocks; i++) {
        if (uae_fseeko64 (h, offset, SEEK_SET) != 0)
            break;
        int outlen = fread (buf, 1, blocksize, h);
        if (outlen != blocksize) {
            write_log("rdbdump: warning: read %d bytes (not blocksize %d)\n",
                      outlen, blocksize);
        }
        fwrite (buf, 1, blocksize, f);
        offset += blocksize;
    }
    fclose (f);
    cnt++;
}
コード例 #2
0
FILE *moduleripper_fopen (const char *aname, const char *amode)
{
	TCHAR outname[MAX_DPATH];
	TCHAR *mode;
	FILE *f;

	moduleripper_filename(aname, outname, true);

	mode = au (amode);
	f = uae_tfopen (outname, mode);
	xfree (mode);
	return f;
}
コード例 #3
0
FILE *moduleripper_fopen (const char *aname, const char *amode)
{
	TCHAR tmp2[MAX_DPATH];
	TCHAR tmp[MAX_DPATH];
	TCHAR *name, *mode;
	FILE *f;

	fetch_ripperpath (tmp, sizeof tmp);
	name = au (aname);
	mode = au (amode);
	_stprintf (tmp2, _T("%s%s"), tmp, name);
	f = uae_tfopen (tmp2, mode);
	xfree (mode);
	xfree (name);
	return f;
}
コード例 #4
0
ファイル: hardfile_host.cpp プロジェクト: adurdin/fs-uae
int hdf_open_target (struct hardfiledata *hfd, const char *pname)
{
    FILE *h = INVALID_HANDLE_VALUE;
    int i;
    struct uae_driveinfo *udi;
    char *name = strdup (pname);

    if (getenv("FS_DEBUG_HDF")) {
        g_debug = 1;
    }
    if (g_debug) {
        write_log("\n\n-- hdf_open_target pname = %s\n", pname);
    }

    hfd->flags = 0;
    hfd->drive_empty = 0;
    hdf_close (hfd);
    hfd->cache = (uae_u8*)xmalloc (uae_u8, CACHE_SIZE);
    hfd->cache_valid = 0;
    hfd->virtual_size = 0;
    hfd->virtual_rdb = NULL;
    if (!hfd->cache) {
        write_log ("VirtualAlloc(%d) failed, error %d\n", CACHE_SIZE, errno);
        goto end;
    }
    hfd->handle = xcalloc (struct hardfilehandle, 1);
    hfd->handle->h = INVALID_HANDLE_VALUE;
    hfd_log ("hfd open: '%s'\n", name);
    if (_tcslen (name) > 4 && !_tcsncmp (name,"HD_", 3)) {
        hdf_init_target ();
        i = isharddrive (name);
        if (i >= 0) {
            udi = &uae_drives[i];
            hfd->flags = HFD_FLAGS_REALDRIVE;
            if (udi->nomedia)
                hfd->drive_empty = -1;
            if (udi->readonly)
                hfd->ci.readonly = 1;
            h = uae_tfopen (udi->device_path, hfd->ci.readonly ? "rb" : "r+b");
            hfd->handle->h = h;
            if (h == INVALID_HANDLE_VALUE)
                goto end;
            _tcsncpy (hfd->vendor_id, udi->vendor_id, 8);
            _tcsncpy (hfd->product_id, udi->product_id, 16);
            _tcsncpy (hfd->product_rev, udi->product_rev, 4);
            hfd->offset = udi->offset;
            hfd->physsize = hfd->virtsize = udi->size;
            hfd->ci.blocksize = udi->bytespersector;
            if (hfd->offset == 0 && !hfd->drive_empty) {
                int sf = safetycheck (hfd->handle->h, udi->device_path, 0, hfd->cache, hfd->ci.blocksize);
                if (sf > 0)
                    goto end;
                if (sf == 0 && !hfd->ci.readonly && harddrive_dangerous != 0x1234dead) {
                    write_log ("'%s' forced read-only, safetycheck enabled\n", udi->device_path);
                    hfd->dangerous = 1;
                    // clear GENERIC_WRITE
                    fclose (h);
                    h = uae_tfopen (udi->device_path, "r+b");
                    hfd->handle->h = h;
                    if (h == INVALID_HANDLE_VALUE)
                        goto end;
                }
            }
            hfd->handle_valid = HDF_HANDLE_LINUX;
            hfd->emptyname = strdup (name);
        } else {
            hfd->flags = HFD_FLAGS_REALDRIVE;
            hfd->drive_empty = -1;
            hfd->emptyname = strdup (name);
        }
    } else {
        int zmode = 0;
        char *ext = _tcsrchr (name, '.');
        if (ext != NULL) {
            ext++;
            for (i = 0; hdz[i]; i++) {
                if (!_tcsicmp (ext, hdz[i]))
                    zmode = 1;
            }
        }
        h = uae_tfopen (name, hfd->ci.readonly ? "rb" : "r+b");
        if (h == INVALID_HANDLE_VALUE)
            goto end;
        hfd->handle->h = h;
        i = _tcslen (name) - 1;
        while (i >= 0) {
            if ((i > 0 && (name[i - 1] == '/' || name[i - 1] == '\\')) || i == 0) {
                _tcscpy (hfd->vendor_id, "UAE");
                _tcsncpy (hfd->product_id, name + i, 15);
                _tcscpy (hfd->product_rev, "0.3");
                break;
            }
            i--;
        }
        if (h != INVALID_HANDLE_VALUE) {
            // determine size of hdf file
            int ret;
            off_t low = -1;

#if defined(MACOSX) || defined(OPENBSD)
            // check type of file
            struct stat st;
            ret = stat(name,&st);
            if (ret) {
                write_log("osx: can't stat '%s'\n", name);
                goto end;
            }
            // block devices need special handling on BSD and OSX
            if (S_ISBLK(st.st_mode) || S_ISCHR(st.st_mode)) {
                int fh = fileno(h);
#if defined(MACOSX)
                uint32_t block_size;
                uint64_t block_count;
                // get number of blocks
                ret = ioctl(fh, DKIOCGETBLOCKCOUNT, &block_count);
                if (ret) {
                    write_log("osx: can't get block count of '%s' (%d)\n",
                            name, fh);
                    goto end;
                }
                // get block size
                ret = ioctl(fh, DKIOCGETBLOCKSIZE, &block_size);
                if (ret) {
                    write_log("osx: can't get block size of '%s' (%d)\n",
                            name, fh);
                    goto end;
                }
                write_log("osx: found raw device: block_size=%u "
                        "block_count=%llu\n", block_size, block_count);
                low = block_size * block_count;
#elif defined(OPENBSD)
                struct disklabel label;
                if (ioctl(fh, DIOCGDINFO, &label) < 0) {
                    write_log("openbsd: can't get disklabel of '%s' (%d)\n", name, fh);
                    goto end;
                }
                write_log("openbsd: bytes per sector: %u\n", label.d_secsize);
                write_log("openbsd: sectors per unit: %u\n", label.d_secperunit);
                low = label.d_secsize * label.d_secperunit;
                write_log("openbsd: total bytes: %llu\n", low);
#endif
            }
#endif // OPENBSD || MACOSX

            if (low == -1) {
                // assuming regular file; seek to end and ftell
                ret = uae_fseeko64 (h, 0, SEEK_END);
                if (ret)
                    goto end;
                low = uae_ftello64 (h);
                if (low == -1)
                    goto end;
            }

            low &= ~(hfd->ci.blocksize - 1);
            hfd->physsize = hfd->virtsize = low;
            if (g_debug) {
                write_log("set physsize = virtsize = %lld (low)\n",
                        hfd->virtsize);
            }
            hfd->handle_valid = HDF_HANDLE_LINUX;
            if (hfd->physsize < 64 * 1024 * 1024 && zmode) {
                write_log ("HDF '%s' re-opened in zfile-mode\n", name);
                fclose (h);
                hfd->handle->h = INVALID_HANDLE_VALUE;
                hfd->handle->zf = zfile_fopen(name, hfd->ci.readonly ? "rb" : "r+b", ZFD_NORMAL);
                hfd->handle->zfile = 1;
                if (!h)
                    goto end;
                zfile_fseek (hfd->handle->zf, 0, SEEK_END);
                hfd->physsize = hfd->virtsize = zfile_ftell (hfd->handle->zf);
                if (g_debug) {
                    write_log("set physsize = virtsize = %lld\n",
                            hfd->virtsize);
                }
                zfile_fseek (hfd->handle->zf, 0, SEEK_SET);
                hfd->handle_valid = HDF_HANDLE_ZFILE;
            }
        } else {
            write_log ("HDF '%s' failed to open. error = %d\n", name, errno);
        }
    }
    if (hfd->handle_valid || hfd->drive_empty) {
        hfd_log ("HDF '%s' opened, size=%dK mode=%d empty=%d\n",
            name, (int) (hfd->physsize / 1024), hfd->handle_valid, hfd->drive_empty);
        return 1;
    }
end:
    hdf_close (hfd);
    xfree (name);
    return 0;
}