Use typed attributes.
This commit is contained in:
parent
65936f8f27
commit
dd23854cd5
7
Cargo.lock
generated
7
Cargo.lock
generated
@ -2,10 +2,16 @@
|
|||||||
name = "rustfat"
|
name = "rustfat"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"bitflags 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"byteorder 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"byteorder 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"chrono 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"chrono 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "bitflags"
|
||||||
|
version = "1.0.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "byteorder"
|
name = "byteorder"
|
||||||
version = "1.1.0"
|
version = "1.1.0"
|
||||||
@ -93,6 +99,7 @@ version = "0.1.1"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
|
||||||
[metadata]
|
[metadata]
|
||||||
|
"checksum bitflags 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f5cde24d1b2e2216a726368b2363a273739c91f4e3eb4e0dd12d672d396ad989"
|
||||||
"checksum byteorder 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ff81738b726f5d099632ceaffe7fb65b90212e8dce59d518729e7e8634032d3d"
|
"checksum byteorder 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ff81738b726f5d099632ceaffe7fb65b90212e8dce59d518729e7e8634032d3d"
|
||||||
"checksum chrono 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7c20ebe0b2b08b0aeddba49c609fe7957ba2e33449882cb186a180bc60682fa9"
|
"checksum chrono 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7c20ebe0b2b08b0aeddba49c609fe7957ba2e33449882cb186a180bc60682fa9"
|
||||||
"checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d"
|
"checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d"
|
||||||
|
@ -5,4 +5,5 @@ authors = ["Rafał Harabień <rafalh1992@o2.pl>"]
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
byteorder = "1"
|
byteorder = "1"
|
||||||
|
bitflags = "1.0"
|
||||||
chrono = "0.4"
|
chrono = "0.4"
|
||||||
|
31
src/dir.rs
31
src/dir.rs
@ -8,22 +8,23 @@ use chrono::{DateTime, Date, TimeZone, Local};
|
|||||||
use fs::FatFileSystem;
|
use fs::FatFileSystem;
|
||||||
use file::FatFile;
|
use file::FatFile;
|
||||||
|
|
||||||
#[derive(Debug, PartialEq)]
|
bitflags! {
|
||||||
#[allow(dead_code)]
|
pub struct FatFileAttributes: u8 {
|
||||||
enum FatFileAttribute {
|
const READ_ONLY = 0x01;
|
||||||
READ_ONLY = 0x01,
|
const HIDDEN = 0x02;
|
||||||
HIDDEN = 0x02,
|
const SYSTEM = 0x04;
|
||||||
SYSTEM = 0x04,
|
const VOLUME_ID = 0x08;
|
||||||
VOLUME_ID = 0x08,
|
const DIRECTORY = 0x10;
|
||||||
DIRECTORY = 0x10,
|
const ARCHIVE = 0x20;
|
||||||
ARCHIVE = 0x20,
|
const LFN = Self::READ_ONLY.bits | Self::HIDDEN.bits
|
||||||
LFN = 0x0F,
|
| Self::SYSTEM.bits | Self::VOLUME_ID.bits;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
pub struct FatDirEntry {
|
pub struct FatDirEntry {
|
||||||
name: [u8; 11],
|
name: [u8; 11],
|
||||||
attrs: u8,
|
attrs: FatFileAttributes,
|
||||||
reserved_0: u8,
|
reserved_0: u8,
|
||||||
create_time_0: u8,
|
create_time_0: u8,
|
||||||
create_time_1: u16,
|
create_time_1: u16,
|
||||||
@ -49,7 +50,11 @@ fn convert_date_time(dos_date: u16, dos_time: u16) -> DateTime<Local> {
|
|||||||
impl FatDirEntry {
|
impl FatDirEntry {
|
||||||
|
|
||||||
pub fn get_name(&self) -> String {
|
pub fn get_name(&self) -> String {
|
||||||
return str::from_utf8(&self.name).unwrap().trim_right().to_string();
|
str::from_utf8(&self.name).unwrap().trim_right().to_string()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_attrs(&self) -> FatFileAttributes {
|
||||||
|
self.attrs
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_cluster(&self) -> u32 {
|
pub fn get_cluster(&self) -> u32 {
|
||||||
@ -103,7 +108,7 @@ fn read_dir_entry(rdr: &mut Read) -> io::Result<FatDirEntry> {
|
|||||||
rdr.read(&mut name)?;
|
rdr.read(&mut name)?;
|
||||||
Ok(FatDirEntry {
|
Ok(FatDirEntry {
|
||||||
name: name,
|
name: name,
|
||||||
attrs: rdr.read_u8()?,
|
attrs: FatFileAttributes::from_bits(rdr.read_u8()?).unwrap(),
|
||||||
reserved_0: rdr.read_u8()?,
|
reserved_0: rdr.read_u8()?,
|
||||||
create_time_0: rdr.read_u8()?,
|
create_time_0: rdr.read_u8()?,
|
||||||
create_time_1: rdr.read_u16::<LittleEndian>()?,
|
create_time_1: rdr.read_u16::<LittleEndian>()?,
|
||||||
|
@ -4,6 +4,9 @@
|
|||||||
extern crate byteorder;
|
extern crate byteorder;
|
||||||
extern crate chrono;
|
extern crate chrono;
|
||||||
|
|
||||||
|
#[macro_use]
|
||||||
|
extern crate bitflags;
|
||||||
|
|
||||||
pub mod fs;
|
pub mod fs;
|
||||||
pub mod dir;
|
pub mod dir;
|
||||||
pub mod file;
|
pub mod file;
|
||||||
|
Loading…
Reference in New Issue
Block a user