История изменений
Исправление rtxtxtrx, (текущая версия) :
Почему-то растоманская версия ненамного быстрее питона…
// rustc findfs.rs -o findfs
// sudo ./findfs /dev/nvme0n1
use std::env;
use std::fs::File;
use std::io::{self, Write, Read};
// Размер сектора в байтах (обычно 512 байт)
const DEFAULT_SECTOR_SIZE: usize = 512;
// Сигнатуры файловых систем
const FILE_SYSTEM_SIGNATURES: [(&[u8], &str); 6] = [
(b"\x53\xEF", "EXT 2/3/4"),
(b"\x58\x46\x53\x42", "Btrfs"),
(b"\xfd\x37\x7a\x58\x5a\x00", "ZFS"),
(b"\xeb\x3c\x90\x28", "FAT"),
(b"\xeb\x52\x90\x4e", "NTFS"),
(b"LUKS", "LUKS"), // LUKS signature
];
fn find_filesystems(device_path: &str, sector_size: usize) -> io::Result<()> {
let mut file = File::open(device_path)?;
let mut buffer = vec![0; sector_size];
let mut sector_offset = 0;
loop {
let bytes_read = file.read(&mut buffer)?;
if bytes_read == 0 {
break;
}
for (signature, fs_name) in FILE_SYSTEM_SIGNATURES.iter() {
if buffer.starts_with(signature) {
println!("Found {} filesystem at sector offset {}.", fs_name, sector_offset);
io::stdout().flush()?;
}
}
sector_offset += 1;
}
Ok(())
}
fn main() -> io::Result<()> {
let args: Vec<String> = env::args().collect();
if args.len() < 2 {
eprintln!("Usage: {} <device_path> [--sector-size <size>]", args[0]);
return Ok(());
}
let device_path = &args[1];
let sector_size = if args.len() > 3 && args[2] == "--sector-size" {
args[3].parse::<usize>().unwrap_or(DEFAULT_SECTOR_SIZE)
} else {
DEFAULT_SECTOR_SIZE
};
find_filesystems(device_path, sector_size)?;
Ok(())
}
$ sudo ./findfs /dev/nvme0n1
Found LUKS filesystem at sector offset 2048.
Found NTFS filesystem at sector offset 943720448.
Found NTFS filesystem at sector offset 948023712.
Found NTFS filesystem at sector offset 948029904.
Found NTFS filesystem at sector offset 948036104.
Found NTFS filesystem at sector offset 948042304.
Found NTFS filesystem at sector offset 978215088.
Found NTFS filesystem at sector offset 1015698472.
Found ZFS filesystem at sector offset 1040022745.
Found ZFS filesystem at sector offset 1040203195.
Found ZFS filesystem at sector offset 1040234634.
Found ZFS filesystem at sector offset 1040300985.
Found ZFS filesystem at sector offset 1040346482.
Found ZFS filesystem at sector offset 1040442619.
Found ZFS filesystem at sector offset 1040500302.
...
Выводы: Rust говно и нужно каким-то более продвинутым способом все искать. Анализируя байтики после сигнатур. Там какая-то же структура, которая позволит все точно найти
Исправление rtxtxtrx, :
Почему-то растоманская версия ненамного быстрее питона…
// rustc findfs.rs -o findfs
// sudo ./findfs /dev/nvme0n1
use std::env;
use std::fs::File;
use std::io::{self, Write, Read};
// Размер сектора в байтах (обычно 512 байт)
const DEFAULT_SECTOR_SIZE: usize = 512;
// Сигнатуры файловых систем
const FILE_SYSTEM_SIGNATURES: [(&[u8], &str); 6] = [
(b"\x53\xEF\xEF\x53", "EXT 2/3/4"), // Extended signature for EXT2, EXT3, and EXT4
(b"\x58\x46\x53\x42", "Btrfs"),
(b"\xfd\x37\x7a\x58\x5a\x00", "ZFS"),
(b"\xeb\x3c\x90\x28", "FAT"),
(b"\xeb\x52\x90\x4e", "NTFS"),
(b"LUKS", "LUKS"), // LUKS signature
];
fn find_filesystems(device_path: &str, sector_size: usize) -> io::Result<()> {
let mut file = File::open(device_path)?;
let mut buffer = vec![0; sector_size];
let mut sector_offset = 0;
loop {
let bytes_read = file.read(&mut buffer)?;
if bytes_read == 0 {
break;
}
for (signature, fs_name) in FILE_SYSTEM_SIGNATURES.iter() {
if buffer.starts_with(signature) {
println!("Found {} filesystem at sector offset {}.", fs_name, sector_offset);
io::stdout().flush()?;
}
}
sector_offset += 1;
}
Ok(())
}
fn main() -> io::Result<()> {
let args: Vec<String> = env::args().collect();
if args.len() < 2 {
eprintln!("Usage: {} <device_path> [--sector-size <size>]", args[0]);
return Ok(());
}
let device_path = &args[1];
let sector_size = if args.len() > 3 && args[2] == "--sector-size" {
args[3].parse::<usize>().unwrap_or(DEFAULT_SECTOR_SIZE)
} else {
DEFAULT_SECTOR_SIZE
};
find_filesystems(device_path, sector_size)?;
Ok(())
}
$ sudo ./findfs /dev/nvme0n1
Found LUKS filesystem at sector offset 2048.
Found NTFS filesystem at sector offset 943720448.
Found NTFS filesystem at sector offset 948023712.
Found NTFS filesystem at sector offset 948029904.
Found NTFS filesystem at sector offset 948036104.
Found NTFS filesystem at sector offset 948042304.
Found NTFS filesystem at sector offset 978215088.
Found NTFS filesystem at sector offset 1015698472.
Found ZFS filesystem at sector offset 1040022745.
Found ZFS filesystem at sector offset 1040203195.
Found ZFS filesystem at sector offset 1040234634.
Found ZFS filesystem at sector offset 1040300985.
Found ZFS filesystem at sector offset 1040346482.
Found ZFS filesystem at sector offset 1040442619.
Found ZFS filesystem at sector offset 1040500302.
...
Выводы: Rust говно и нужно каким-то более продвинутым способом все искать. Анализируя байтики после сигнатур. Там какая-то же структура, которая позволит все точно найти
Исправление rtxtxtrx, :
Почему-то растоманская версия ненамного быстрее питона…
// rustc findfs.rs -o findfs
// sudo ./findfs /dev/nvme0n1
use std::env;
use std::fs::File;
use std::io::{self, Write, Read};
// Размер сектора в байтах (обычно 512 байт)
const DEFAULT_SECTOR_SIZE: usize = 512;
// Сигнатуры файловых систем
const FILE_SYSTEM_SIGNATURES: [(&[u8], &str); 6] = [
(b"\x53\xEF\xEF\x53", "EXT 2/3/4"), // Extended signature for EXT2, EXT3, and EXT4
(b"\x58\x46\x53\x42", "Btrfs"),
(b"\xfd\x37\x7a\x58\x5a\x00", "ZFS"),
(b"\xeb\x3c\x90\x28", "FAT"),
(b"\xeb\x52\x90\x4e", "NTFS"),
(b"LUKS", "LUKS"), // LUKS signature
];
fn find_filesystems(device_path: &str, sector_size: usize) -> io::Result<()> {
let mut file = File::open(device_path)?;
let mut buffer = vec![0; sector_size];
let mut sector_offset = 0;
loop {
let bytes_read = file.read(&mut buffer)?;
if bytes_read == 0 {
break;
}
for (signature, fs_name) in FILE_SYSTEM_SIGNATURES.iter() {
if buffer.starts_with(signature) {
println!("Found {} filesystem at sector offset {}.", fs_name, sector_offset);
io::stdout().flush()?;
}
}
sector_offset += 1;
}
Ok(())
}
fn main() -> io::Result<()> {
let args: Vec<String> = env::args().collect();
if args.len() < 2 {
eprintln!("Usage: {} <device_path> [--sector-size <size>]", args[0]);
return Ok(());
}
let device_path = &args[1];
let sector_size = if args.len() > 3 && args[2] == "--sector-size" {
args[3].parse::<usize>().unwrap_or(DEFAULT_SECTOR_SIZE)
} else {
DEFAULT_SECTOR_SIZE
};
find_filesystems(device_path, sector_size)?;
Ok(())
}
$ sudo ./findfs /dev/nvme0n1
Found LUKS filesystem at sector offset 2048.
Found NTFS filesystem at sector offset 943720448.
Found NTFS filesystem at sector offset 948023712.
Found NTFS filesystem at sector offset 948029904.
Found NTFS filesystem at sector offset 948036104.
Found NTFS filesystem at sector offset 948042304.
Found NTFS filesystem at sector offset 978215088.
Found NTFS filesystem at sector offset 1015698472.
Found ZFS filesystem at sector offset 1040022745.
Found ZFS filesystem at sector offset 1040203195.
Found ZFS filesystem at sector offset 1040234634.
Found ZFS filesystem at sector offset 1040300985.
Found ZFS filesystem at sector offset 1040346482.
Found ZFS filesystem at sector offset 1040442619.
Found ZFS filesystem at sector offset 1040500302.
...
Исправление rtxtxtrx, :
Почему-то растоманская версия ненамного быстрее питона…
// rustc findfs.rs -o findfs
// sudo ./findfs /dev/nvme0n1
use std::env;
use std::fs::File;
use std::io::{self, Write, Read};
// Размер сектора в байтах (обычно 512 байт)
const DEFAULT_SECTOR_SIZE: usize = 512;
// Сигнатуры файловых систем
const FILE_SYSTEM_SIGNATURES: [(&[u8], &str); 6] = [
(b"\x53\xEF\xEF\x53", "EXT 2/3/4"), // Extended signature for EXT2, EXT3, and EXT4
(b"\x58\x46\x53\x42", "Btrfs"),
(b"\xfd\x37\x7a\x58\x5a\x00", "ZFS"),
(b"\xeb\x3c\x90\x28", "FAT"),
(b"\xeb\x52\x90\x4e", "NTFS"),
(b"LUKS", "LUKS"), // LUKS signature
];
fn find_filesystems(device_path: &str, sector_size: usize) -> io::Result<()> {
let mut file = File::open(device_path)?;
let mut buffer = vec![0; sector_size];
let mut sector_offset = 0;
loop {
let bytes_read = file.read(&mut buffer)?;
if bytes_read == 0 {
break;
}
for (signature, fs_name) in FILE_SYSTEM_SIGNATURES.iter() {
if buffer.starts_with(signature) {
println!("Found {} filesystem at sector offset {}.", fs_name, sector_offset);
io::stdout().flush()?;
}
}
sector_offset += 1;
}
Ok(())
}
fn main() -> io::Result<()> {
let args: Vec<String> = env::args().collect();
if args.len() < 2 {
eprintln!("Usage: {} <device_path> [--sector-size <size>]", args[0]);
return Ok(());
}
let device_path = &args[1];
let sector_size = if args.len() > 3 && args[2] == "--sector-size" {
args[3].parse::<usize>().unwrap_or(DEFAULT_SECTOR_SIZE)
} else {
DEFAULT_SECTOR_SIZE
};
find_filesystems(device_path, sector_size)?;
Ok(())
}
Исходная версия rtxtxtrx, :
Почему-то растоманская версия ненамного быстрее питона…
// rustc find_filesystems.rs -o findfs
// sudo ./findfs /dev/nvme0n1
use std::env;
use std::fs::File;
use std::io::{self, Read};
// Размер сектора в байтах (обычно 512 байт)
const DEFAULT_SECTOR_SIZE: usize = 512;
// Сигнатуры файловых систем
const FILE_SYSTEM_SIGNATURES: [(&[u8], &str); 6] = [
(b"\x53\xEF\xEF\x53", "EXT 2/3/4"), // Extended signature for EXT2, EXT3, and EXT4
(b"\x58\x46\x53\x42", "Btrfs"),
(b"\xfd\x37\x7a\x58\x5a\x00", "ZFS"),
(b"\xeb\x3c\x90\x28", "FAT"),
(b"\xeb\x52\x90\x4e", "NTFS"),
(b"LUKS", "LUKS"), // LUKS signature
];
fn find_filesystems(device_path: &str, sector_size: usize) -> io::Result<()> {
let mut file = File::open(device_path)?;
let mut buffer = vec![0; sector_size];
let mut sector_offset = 0;
loop {
let bytes_read = file.read(&mut buffer)?;
if bytes_read == 0 {
break;
}
for (signature, fs_name) in FILE_SYSTEM_SIGNATURES.iter() {
if buffer.starts_with(signature) {
println!("Found {} filesystem at sector offset {}.", fs_name, sector_offset);
}
}
sector_offset += 1;
}
Ok(())
}
fn main() -> io::Result<()> {
let args: Vec<String> = env::args().collect();
if args.len() < 2 {
eprintln!("Usage: {} <device_path> [--sector-size <size>]", args[0]);
return Ok(());
}
let device_path = &args[1];
let sector_size = if args.len() > 3 && args[2] == "--sector-size" {
args[3].parse::<usize>().unwrap_or(DEFAULT_SECTOR_SIZE)
} else {
DEFAULT_SECTOR_SIZE
};
find_filesystems(device_path, sector_size)?;
Ok(())
}