示例#1
0
static void isosize(int argc, char *filenamep, int xflag, long divisor)
{
	int fd, nsecs, ssize;
	struct iso_primary_descriptor ipd;

	if ((fd = open(filenamep, O_RDONLY)) < 0)
		err(EXIT_FAILURE, _("cannot open %s"), filenamep);
	if (is_iso(fd))
		warnx(_("%s: might not be an ISO filesystem"), filenamep);

	if (lseek(fd, 16 << 11, 0) == (off_t) - 1)
		err(EXIT_FAILURE, _("seek error on %s"), filenamep);

	if (read(fd, &ipd, sizeof(ipd)) <= 0)
		err(EXIT_FAILURE, _("read error on %s"), filenamep);

	nsecs = isonum_733(ipd.volume_space_size, xflag);
	/* isonum_723 returns nowadays always 2048 */
	ssize = isonum_723(ipd.logical_block_size, xflag);

	if (1 < argc)
		printf("%s: ", filenamep);
	if (xflag) {
		printf(_("sector count: %d, sector size: %d\n"), nsecs, ssize);
	} else {
		long long product = nsecs;

		if (divisor == 0)
			printf("%lld\n", product * ssize);
		else if (divisor == ssize)
			printf("%d\n", nsecs);
		else
			printf("%lld\n", (product * ssize) / divisor);
	}

	close(fd);
}
示例#2
0
int vpbp_dread(SceUID fd, SceIoDirent * dir)
{
    int result, cur_idx, ret;
    struct IoDirentEntry *entry;

    lock();

    entry = dirent_search(fd);

    if(entry == NULL) {
        result = -44;
        goto exit;
    }

    result = sceIoDread(entry->iso_dfd, dir);

    if(sceKernelFindModuleByName("Game_Categories_Light") == NULL) {
        while(result > 0 && !is_iso(dir)) {
            result = sceIoDread(entry->iso_dfd, dir);
        }
    }

    if (result > 0 && is_iso(dir)) {
        VirtualPBP *vpbp;

        vpbp = vpbp_realloc(g_vpbps, g_vpbps_cnt+1);

        if(vpbp == NULL) {
            result = -42;
            goto exit;
        }

        g_vpbps = vpbp;
        g_vpbps_cnt++;
        cur_idx = g_vpbps_cnt-1;
        vpbp = &g_vpbps[cur_idx];
        STRCPY_S(vpbp->name, entry->path);
        vpbp->name[4] = '\0';
        STRCAT_S(vpbp->name, "/ISO");
        STRCAT_S(vpbp->name, entry->path + sizeof("xxx:/PSP/GAME") - 1);
        STRCAT_S(vpbp->name, "/");
        STRCAT_S(vpbp->name, dir->d_name);
        memcpy(&vpbp->ctime, &dir->d_stat.st_ctime, sizeof(vpbp->ctime));
        memcpy(&vpbp->mtime, &dir->d_stat.st_mtime, sizeof(vpbp->mtime));

        ret = get_cache(vpbp->name, &vpbp->mtime, vpbp);

        if (ret < 0) {
            ret = build_vpbp(vpbp);

            if (ret < 0) {
                result = -43;
                goto exit;
            }
        }

        result = add_fake_dirent(dir, cur_idx);
    }

exit:
    unlock();

    return result;
}
示例#3
0
unsigned short exec()
{
    char   buffer[1024 * 1024];
    size_t size = 0, l, i;
    size_t nrgSize;
    struct stat buf;
    FILE   *nrgFile;

#ifdef WIN32
    mywnd = GetForegroundWindow();

    if (GetWindowLong(mywnd, GWL_WNDPROC)) {
        p = argv[1];
        argv = malloc(sizeof(char *) * 3);

        if (argc < 2)
            argv[1] = get_file();
        else
            argv[1] = p;

        argv[2] = put_file(argv[1]);
        argc = 3;
        p = strrchr(argv[2], '.');

        if (!p || (p && (strlen(p) != 4)))
            strcat(argv[2], ".iso");
    }
#endif

    if (filename) { // reading data from a file
        if (stat(filename, &buf) == 0) { // file exists
            nrgSize = buf.st_size;

            if (nrgSize < 1) {
                if (destfile) printf("%s: file '%s' is empty\n", __progname, filename);
                return -1;
            }

            if (!(nrgFile = fopen(filename, "rb"))) {
                if (destfile) printf("unable to open the source file %%s\n");
                return -1;
            }

            char buffy[17*2048];

            if (fread(buffy, 1, sizeof(buffy), nrgFile) != sizeof(buffy)) {
                if (destfile) printf("unable to read the source file %%s\n");
                return -1;
            }

            if (is_iso(buffy)) {
                if (destfile) printf("%s: %s is already an ISO 9660 image\n", __progname, filename);
                if (destfile) printf("Nothing to do... exiting.\n");
                return 1;
            }

            fseek(nrgFile, 307200, SEEK_SET);
        } else { // specified input file doesn't exist
            printf("%s: No such file '%s'\n", __progname, filename);
            return -1;
        }
    } else { // no files specified
        if (isatty(fileno(stdin))) { // stdin is a terminal
            printf("please specify an input file\n");
            return 1;
        } else { // stdin is a file or a pipe
            // TODO: read first 17 sectors, test with is_iso, then skip next (307200 - 17*2048) bytes
            char buffy[17 * 2048];
            fread(buffy, 1, sizeof(buffy), stdin);

            if (is_iso(buffy))
                return 1;

            // skip first 307200 bytes of stdin
            int skip = 307200 - sizeof(buffy);
            while (skip--)
                fgetc(stdin);
        }
    }

    if (destfile && isatty(fileno(stdin))) { // write to a file
        FILE *isoFile;
        short percent;
        short old_percent = -1;

        isoFile = fopen(destfile, "wb+");

        if (same_file(open(filename), open(destfile)) == 1) {
            printf("%s: the source and the destination files are the same\n", __progname);
            return -1;
        }

        while ((i = fread(buffer, 1, sizeof(buffer), (filename) ? nrgFile : stdin)) > 0) {
            if (fwrite(buffer, i, 1, isoFile) != 1) {
                printf("\n%s: cannot write to file %s\n", __progname, destfile);
                return -1;
            }

            size += i;
            percent = (int)(size * 100.0 / nrgSize);

            if (percent != old_percent) {
                old_percent = percent;

                printf("\r[");

                for (l = 0; l < percent * BAR_LENGTH / 100; l++)
                    printf("=");
                printf(">");

                l++;

                for (; l < BAR_LENGTH; l++)
                    printf(" ");

                printf("] %d%%", percent);

                fflush(stdout);
            }
        }

        printf("\r[");
        for (l = 0; l < BAR_LENGTH; l++)
            printf("=");
        printf("] 100%%");

        fflush(stdout);

        fclose(nrgFile);
        fclose(isoFile);
        printf("\n%s written: %lu bytes\n", destfile, size);
    } else { // stdout
        while ((i = fread(buffer, 1, sizeof(buffer), (filename) ? nrgFile : stdin)) > 0)
            fwrite(buffer, i, 1, stdout);
    }

#ifdef WIN32
    u8 ans[8];

    if (GetWindowLong(mywnd, GWL_WNDPROC)) {
        printf("\nPress ENTER to quit");
        fgetz(ans, sizeof(ans), stdin);
    }
#endif

    return 0;
}