protocol: use size_t for c api instead of ulong

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
Wolfgang Bumiller 2019-03-07 14:36:57 +01:00
parent b4844eb334
commit 181cb6401d
4 changed files with 17 additions and 11 deletions

View File

@ -14,4 +14,5 @@ crate-type = ['lib', 'cdylib']
chrono = "0.4" chrono = "0.4"
endian_trait = "0.6" endian_trait = "0.6"
failure = "0.1" failure = "0.1"
libc = "0.2"
openssl = "0.10" openssl = "0.10"

View File

@ -2,11 +2,13 @@
use std::os::raw::c_void; use std::os::raw::c_void;
use libc::size_t;
use crate::Chunker; use crate::Chunker;
/// Creates a new chunker instance. /// Creates a new chunker instance.
#[no_mangle] #[no_mangle]
pub extern "C" fn proxmox_chunker_new(chunk_size_avg: u64) -> *mut Chunker { pub extern "C" fn proxmox_chunker_new(chunk_size_avg: size_t) -> *mut Chunker {
Box::leak(Box::new(Chunker::new(chunk_size_avg as usize))) Box::leak(Box::new(Chunker::new(chunk_size_avg as usize)))
} }
@ -26,18 +28,20 @@ pub extern "C" fn proxmox_chunker_done(me: *mut Chunker) {
pub extern "C" fn proxmox_chunker_scan( pub extern "C" fn proxmox_chunker_scan(
me: *mut Chunker, me: *mut Chunker,
data: *const c_void, data: *const c_void,
size: u64, size: size_t,
) -> u64 { ) -> size_t {
let me = unsafe { &mut *me }; let me = unsafe { &mut *me };
me.scan(unsafe { me.scan(unsafe { std::slice::from_raw_parts(data as *const u8, size as usize) }) as size_t
std::slice::from_raw_parts(data as *const u8, size as usize)
}) as u64
} }
/// Compute a chunk digest. This is mostly a convenience method to avoid having to lookup the right /// Compute a chunk digest. This is mostly a convenience method to avoid having to lookup the right
/// digest method for your language of choice. /// digest method for your language of choice.
#[no_mangle] #[no_mangle]
pub extern "C" fn proxmox_chunk_digest(data: *const c_void, size: u64, out_digest: *mut [u8; 32]) { pub extern "C" fn proxmox_chunk_digest(
data: *const c_void,
size: size_t,
out_digest: *mut [u8; 32],
) {
let digest = crate::FixedChunk::from_data(unsafe { let digest = crate::FixedChunk::from_data(unsafe {
std::slice::from_raw_parts(data as *const u8, size as usize) std::slice::from_raw_parts(data as *const u8, size as usize)
}); });

View File

@ -4,9 +4,10 @@
use std::ffi::{CStr, CString}; use std::ffi::{CStr, CString};
use std::io; use std::io;
use std::os::raw::{c_char, c_int, c_ulong, c_void}; use std::os::raw::{c_char, c_int, c_void};
use failure::{bail, format_err, Error}; use failure::{bail, format_err, Error};
use libc::size_t;
/// Read callback. The first parameter is the `opaque` parameter passed to `proxmox_backup_new`, /// Read callback. The first parameter is the `opaque` parameter passed to `proxmox_backup_new`,
/// the rest are the usual read function parameters. This should return the number of bytes /// the rest are the usual read function parameters. This should return the number of bytes
@ -328,7 +329,7 @@ pub extern "C" fn proxmox_backup_create(
backup_id: *const c_char, backup_id: *const c_char,
time_epoch: i64, time_epoch: i64,
file_name: *const c_char, file_name: *const c_char,
chunk_size: c_ulong, chunk_size: size_t,
file_size: i64, file_size: i64,
is_new: bool, is_new: bool,
) -> c_int { ) -> c_int {
@ -391,7 +392,7 @@ pub extern "C" fn proxmox_backup_dynamic_data(
pub extern "C" fn proxmox_backup_fixed_data( pub extern "C" fn proxmox_backup_fixed_data(
me: *mut CClient, me: *mut CClient,
stream: c_int, stream: c_int,
index: c_ulong, index: size_t,
digest: *const [u8; 32], digest: *const [u8; 32],
) -> c_int { ) -> c_int {
let me = unsafe { &mut *me }; let me = unsafe { &mut *me };

View File

@ -16,5 +16,5 @@ pub use client::*;
mod types; mod types;
pub use types::*; pub use types::*;
pub mod c_client;
pub mod c_chunker; pub mod c_chunker;
pub mod c_client;