Пример #1
0
void extractFile(struct Volume *vol, char* name, char* path, unsigned char *extbuf,
    BOOL pflag, BOOL qflag)
{
    struct File *file;
    FILE* out;
    long n;
    char *filename;

    filename = NULL;
    if (pflag)
        out = stdout;
    else {
        if (strlen(path)>0) {
            filename=(char*)malloc(sizeof(char)* (strlen(path)+1+strlen(name)+1) );
            if (!filename) return;
            sprintf(filename,"%s%c%s",path,DIRSEP,name);
            out = fopen(filename, "wb");
        }
        else
            out = fopen(name, "wb");
        if (!out) return;
    }

    file = adfOpenFile(vol, name, "r");
    if (!file) { fclose(out); return; }

    n = adfReadFile(file, EXTBUFL, extbuf);
    while(!adfEndOfFile(file)) {
        fwrite(extbuf, sizeof(unsigned char), n, out);
        n = adfReadFile(file, EXTBUFL, extbuf);
    }
    if (n>0)
        fwrite(extbuf, sizeof(unsigned char), n, out);

    if (!pflag)
        fclose(out);

    adfCloseFile(file);

    if (!qflag) {
        if (filename!=NULL)
            printf("x - %s\n", filename);
        else
            printf("x - %s\n", name);
    }
	
    if (filename!=NULL)
        free(filename);
}
Пример #2
0
int main(int argc, char *argv[])
{
    struct Device *hd;
    struct Volume *vol;
    struct File *file;
    unsigned char buf[600];
    long n;
    FILE *out;
    long len;
    struct List *list;
 
    adfEnvInitDefault();

//	adfSetEnvFct(0,0,MyVer,0);

    /* mount existing device : FFS */
    hd = adfMountDev( "hd.adf",FALSE );
    if (!hd) {
        fprintf(stderr, "can't mount device\n");
        adfEnvCleanUp(); exit(1);
    }
    adfDeviceInfo(hd);

    vol = adfMount(hd, 1, FALSE);
    if (!vol) {
        adfUnMountDev(hd);
        fprintf(stderr, "can't mount volume\n");
        adfEnvCleanUp(); exit(1);
    }

    adfVolumeInfo(vol);


    /* write one file */
    file = adfOpenFile(vol, "moon_gif","w");
    if (!file) return 1;
    out = fopen("Check/MOON.GIF","rb");
    if (!out) return 1;
    
	len = 600;
    n = fread(buf,sizeof(unsigned char),len,out);
    while(!feof(out)) {
        adfWriteFile(file, n, buf);
        n = fread(buf,sizeof(unsigned char),len,out);
    }
    if (n>0)
        adfWriteFile(file, n, buf);

    fclose(out);

    adfCloseFile(file);

    /* the directory */
/*    list = adfGetDirEnt(vol,vol->curDirPtr);
    while(list) {
        printEntry(list->content);
        adfFreeEntry(list->content);
        list = list->next;
    }
    freeList(list);
*/

    /* re read this file */
    file = adfOpenFile(vol, "moon_gif","r");
    if (!file) return 1;
    out = fopen("moon__gif","wb");
    if (!out) return 1;

    len = 300;
    n = adfReadFile(file, len, buf);
    while(!adfEndOfFile(file)) {
        fwrite(buf,sizeof(unsigned char),n,out);
        n = adfReadFile(file, len, buf);
    }
    if (n>0)
        fwrite(buf,sizeof(unsigned char),n,out);

    fclose(out);

    adfCloseFile(file);

    adfUnMount(vol);
    adfUnMountDev(hd);


    adfEnvCleanUp();

    return 0;
}