示例#1
0
static void check_afc(gpointer data)
{
    //prepare a buffer
    unsigned int buffersize = BUFFER_SIZE * sizeof(unsigned int);
    int *buf = (int *) malloc(buffersize);
    int *buf2 = (int *) malloc(buffersize);
    unsigned int bytes = 0;
    uint64_t position = 0;

    //fill buffer
    int i = 0;
    for (i = 0; i < BUFFER_SIZE; i++) {
        buf[i] = ((param *) data)->id * i;
    }

    //now  writes buffer on device
    uint64_t file = 0;
    char path[50];
    sprintf(path, "/Buf%i", ((param *) data)->id);
    afc_file_open(((param *) data)->afc, path, AFC_FOPEN_RW, &file);
    afc_file_write(((param *) data)->afc, file, (char *) buf, buffersize, &bytes);
    afc_file_close(((param *) data)->afc, file);
    file = 0;
    if (bytes != buffersize)
        printf("Write operation failed\n");

    //now read it
    bytes = 0;
    afc_file_open(((param *) data)->afc, path, AFC_FOPEN_RDONLY, &file);
    afc_file_read(((param *) data)->afc, file, (char *) buf2, buffersize/2, &bytes);
    afc_file_read(((param *) data)->afc, file, (char *) buf2 + (buffersize/2), buffersize/2, &bytes);
    if(AFC_E_SUCCESS != afc_file_tell(((param *) data)->afc, file, &position))
        printf("Tell operation failed\n");
    afc_file_close(((param *) data)->afc, file);
    if (position != buffersize)
        printf("Read operation failed\n");

    //compare buffers
    for (i = 0; i < BUFFER_SIZE; i++) {
        if (buf[i] != buf2[i]) {
            printf("Buffers are differents, stream corrupted\n");
            break;
        }
    }

    //cleanup
    afc_remove_path(((param *) data)->afc, path);
    g_thread_exit(0);
}
示例#2
0
uint64_t Device::getFileLengthWithAfc(string path, afc_client_t afc) {
    uint64_t handle = 0;
    if (afc_file_open(afc, path.c_str(), afc_file_mode_t::AFC_FOPEN_RDONLY, &handle) != AFC_E_SUCCESS) {
        return 0;
    }
    if (afc_file_seek(afc, handle, 0, SEEK_END) != AFC_E_SUCCESS) {
        afc_file_close(afc, handle);
        return 0;
    }
    uint64_t length = 0;
    if (afc_file_tell(afc, handle, &length) != AFC_E_SUCCESS) {
        afc_file_close(afc, handle);
        return 0;
    }
    afc_file_close(afc, handle);
    return length;
}