コード例 #1
0
ファイル: path.c プロジェクト: Dazdin9o/DECAF
APosixStatus
path_copy_file( const char*  dest, const char*  source )
{
    int  fd, fs, result = -1;

    /* if the destination doesn't exist, create it */
    if ( access(source, F_OK)  < 0 ||
         path_empty_file(dest) < 0) {
        return -1;
    }

    if ( access(source, R_OK) < 0 ) {
        D("%s: source file is un-readable: %s\n",
          __FUNCTION__, source);
        return -1;
    }

#ifdef _WIN32
    fd = _open(dest, _O_RDWR | _O_BINARY);
    fs = _open(source, _O_RDONLY |  _O_BINARY);
#else
    fd = creat(dest, S_IRUSR | S_IWUSR);
    fs = open(source, S_IREAD);
#endif
    if (fs >= 0 && fd >= 0) {
        char buf[4096];
        ssize_t total = 0;
        ssize_t n;
        result = 0; /* success */
        while ((n = read(fs, buf, 4096)) > 0) {
            if (write(fd, buf, n) != n) {
                /* write failed. Make it return -1 so that an
                 * empty file be created. */
                D("Failed to copy '%s' to '%s': %s (%d)",
                       source, dest, strerror(errno), errno);
                result = -1;
                break;
            }
            total += n;
        }
    }

    if (fs >= 0) {
        close(fs);
    }
    if (fd >= 0) {
        close(fd);
    }
    return result;
}
コード例 #2
0
int androidPartitionType_makeEmptyFile(AndroidPartitionType part_type,
                                       uint64_t part_size,
                                       const char* part_file) {
    switch (part_type) {
        case ANDROID_PARTITION_TYPE_YAFFS2:
            // Any empty file is a valid YAFFS2 partition, |part_size|
            // can be ignored here.
            if (path_empty_file(part_file) < 0) {
                return -errno;
            }
            return 0;

        case ANDROID_PARTITION_TYPE_EXT4:
            return android_createEmptyExt4Image(part_file, part_size, NULL);

        default:
            return -EINVAL;
    }
}
コード例 #3
0
ファイル: goldfish_nand.c プロジェクト: KurSh/panda
static int goldfish_nand_init(GoldfishDevice *dev)
{
    GoldfishNandDevice *s = (GoldfishNandDevice *)dev;
    /* Initialize system partition image */
    {
        char        tmp[PATH_MAX+32];
        const char* sysImage = s->system_path;
        const char* initImage = s->system_init_path;
        uint64_t    sysBytes = s->system_size;

        if (sysBytes == 0) {
            PANIC("Invalid system partition size: %jd", sysBytes);
        }

        snprintf(tmp,sizeof(tmp),"system");

        if (sysImage && *sysImage) {
            if (filelock_create(sysImage) == NULL) {
                fprintf(stderr,"WARNING: System image already in use, changes will not persist!\n");
                /* If there is no file= parameters, nand_add_dev will create
                 * a temporary file to back the partition image. */
            } else {
                pstrcat(tmp,sizeof(tmp),",file=");
                pstrcat(tmp,sizeof(tmp),sysImage);
            }
        }
        if (initImage && *initImage) {
            if (!path_exists(initImage)) {
                PANIC("Invalid initial system image path: %s", initImage);
            }
            pstrcat(tmp,sizeof(tmp),",initfile=");
            pstrcat(tmp,sizeof(tmp),initImage);
        } /*else {
            PANIC("Missing initial system image path!");
        }*/
        nand_add_dev(tmp);
    }

    /* Initialize data partition image */
    {
        char        tmp[PATH_MAX+32];
        const char* dataImage = s->user_data_path;
        const char* initImage = s->user_data_init_path;
        uint64_t    dataBytes = s->user_data_size;

        if (dataBytes == 0) {
            PANIC("Invalid data partition size: %jd", dataBytes);
        }

        snprintf(tmp,sizeof(tmp),"userdata,size=0x%jx", dataBytes);

        if (dataImage && *dataImage) {
            if (filelock_create(dataImage) == NULL) {
                fprintf(stderr, "WARNING: Data partition already in use. Changes will not persist!\n");
                /* Note: if there is no file= parameters, nand_add_dev() will
                 *       create a temporary file to back the partition image. */
            } else {
                /* Create the file if needed */
                if (!path_exists(dataImage)) {
                    if (path_empty_file(dataImage) < 0) {
                        PANIC("Could not create data image file %s: %s", dataImage, strerror(errno));
                    }
                }
                pstrcat(tmp, sizeof(tmp), ",file=");
                pstrcat(tmp, sizeof(tmp), dataImage);
            }
        }
        if (initImage && *initImage) {
            pstrcat(tmp, sizeof(tmp), ",initfile=");
            pstrcat(tmp, sizeof(tmp), initImage);
        }
        nand_add_dev(tmp);
    }

    /* Initialize cache partition */
    {
        char        tmp[PATH_MAX+32];
        const char* partPath = s->cache_path;
        uint64_t    partSize = s->cache_size;

        snprintf(tmp,sizeof(tmp),"cache,size=0x%jx", partSize);

        if (partPath && *partPath && strcmp(partPath, "<temp>") != 0) {
            if (filelock_create(partPath) == NULL) {
                fprintf(stderr, "WARNING: Cache partition already in use. Changes will not persist!\n");
                /* Note: if there is no file= parameters, nand_add_dev() will
                 *       create a temporary file to back the partition image. */
            } else {
                /* Create the file if needed */
                if (!path_exists(partPath)) {
                    if (path_empty_file(partPath) < 0) {
                        PANIC("Could not create cache image file %s: %s", partPath, strerror(errno));
                    }
                }
                pstrcat(tmp, sizeof(tmp), ",file=");
                pstrcat(tmp, sizeof(tmp), partPath);
            }
        }
        nand_add_dev(tmp);
    }
    return 0;
}