Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions disk/src/superblock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ fn parse_label(raw_label: &[std::os::raw::c_char; 256]) -> String {
let bytes: Vec<u8> = raw_label
.iter()
.take_while(|&&c| c != 0)
.map(|&c| c.cast_unsigned())
.map(|&c| c as u8)
.collect();
String::from_utf8_lossy(&bytes).into_owned()
}
Expand Down Expand Up @@ -679,7 +679,7 @@ pub fn write_superblock_all_mirrors(
#[cfg(test)]
mod tests {
use super::*;
use std::{io::Cursor, mem};
use std::{io::Cursor, mem, os::raw::c_char};

// --- super_mirror_offset ---

Expand Down Expand Up @@ -755,24 +755,24 @@ mod tests {

#[test]
fn parse_label_normal() {
let mut raw_label = [0i8; 256];
let mut raw_label = [c_char::default(); 256];
for (i, &b) in b"my-volume".iter().enumerate() {
raw_label[i] = b as i8;
raw_label[i] = b as c_char;
}
assert_eq!(parse_label(&raw_label), "my-volume");
}

#[test]
fn parse_label_empty() {
let raw_label = [0i8; 256];
let raw_label = [c_char::default(); 256];
assert_eq!(parse_label(&raw_label), "");
}

#[test]
fn parse_label_stops_at_nul() {
let mut raw_label = [0i8; 256];
let mut raw_label = [c_char::default(); 256];
for (i, &b) in b"hello\0world".iter().enumerate() {
raw_label[i] = b as i8;
raw_label[i] = b as c_char;
}
assert_eq!(parse_label(&raw_label), "hello");
}
Expand Down
4 changes: 2 additions & 2 deletions uapi/src/filesystem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ pub fn wait_sync(fd: BorrowedFd, transid: u64) -> nix::Result<()> {
///
/// Returns `Err` if the ioctl fails.
pub fn label_get(fd: BorrowedFd) -> nix::Result<CString> {
let mut buf = [0i8; BTRFS_LABEL_SIZE as usize];
let mut buf = [c_char::default(); BTRFS_LABEL_SIZE as usize];
unsafe { btrfs_ioc_get_fslabel(fd.as_raw_fd(), &raw mut buf) }?;
let cstr = unsafe { CStr::from_ptr(buf.as_ptr()) };
// CStr::to_owned() copies the bytes into a freshly allocated CString,
Expand All @@ -129,7 +129,7 @@ pub fn label_set(fd: BorrowedFd, label: &CStr) -> nix::Result<()> {
if bytes.len() >= BTRFS_LABEL_SIZE as usize {
return Err(nix::errno::Errno::EINVAL);
}
let mut buf = [0i8; BTRFS_LABEL_SIZE as usize];
let mut buf = [c_char::default(); BTRFS_LABEL_SIZE as usize];
for (i, &b) in bytes.iter().enumerate() {
buf[i] = b as c_char;
}
Expand Down
7 changes: 5 additions & 2 deletions uapi/src/inode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ use crate::{
},
tree_search::{SearchFilter, tree_search},
};
use std::os::fd::{AsRawFd, BorrowedFd};
use std::os::{
fd::{AsRawFd, BorrowedFd},
raw::c_char,
};

/// Look up the tree ID (root ID) of the subvolume containing the given file or directory.
///
Expand Down Expand Up @@ -104,7 +107,7 @@ pub fn ino_paths(fd: BorrowedFd<'_>, inum: u64) -> nix::Result<Vec<String>> {

// The path string starts at the base of val array plus the offset
let val_base = container.val.as_ptr() as usize;
let path_ptr = (val_base + val_offset) as *const i8;
let path_ptr = (val_base + val_offset) as *const c_char;

// Convert C string to Rust String
let c_str = unsafe { std::ffi::CStr::from_ptr(path_ptr) };
Expand Down