Commit Graph

81 Commits

Author SHA1 Message Date
Rafał
c4ffb2ccf5
Add more checks of BPB (#21) 2018-10-22 14:51:32 +02:00
Rafał Harabień
1724a54536 Fix formatting
Immprovements by hand + rustfmt
2018-10-10 21:26:31 +02:00
Rafał
9acd6ed6df
Separate sanity checks into validate() methods (#19) 2018-10-06 17:27:52 +02:00
Henry Gabryjelski
2a4c01082a Preserve 4 MSB in FAT32 entries and add more sanity checks (#13)
* Update compatibility maximum cluster size when sector size is larger than 512 bytes.

* Additional validation of values in FsInfo sector.
* next_free_cluster cannot be 0 or 1, as these are reserved clusters
* next_free_cluster must be a valid cluster (using BPB to validate)
* free_cluster_count must be possible value (using BPB to validate)

* Avoid data-loss edge-case on volumes over 138GB in size.

Specifically, if the volume has more
than 0x0FFF_FFF4 clusters, then the FAT
will include an entry for clusters that
are reserved values.  Specifically, cluster
number 0x0FFF_FFF7 is defined to mean
BAD_SECTOR, while numbers 0x0FFF_FFF8 ..
0x0FFF_FFFF are defined to mean end-of-chain.

This prevents these clusters from being part
of any valid cluster chain.  Therefore:
1. prevent setting these clusters to point to
   a valid next cluster
2. prevent reading these clusters as pointing
   to a valid next cluster

Instead, always read/write these FAT entries
to have next cluster value of BAD_SECTOR.

* Reduce noisy warnings on FAT32.

* The reserved bits in FAT entry must be preserved on update.

* Change the set() implementation for FAT32 entries to return an actual Err(),
when attempting to set values for cluster numbers that have special meaning.
2018-10-06 16:42:31 +02:00
Henry Gabryjelski
2d689a668d Add more sanity checks and fix size formatting in ls example (#11)
* Fix copy/paste errors in ls example so file sizes are correctly output.
* BPB updates.

Fix bug in bpb.active_fat(), because active_fat is
only valid when mirroring is disabled.

Add additional santiy checks to BPB deserialization:
1. bytes per sector must be a power of 2
2. 512 <= bytes per sector <= 4096
3. sectors per cluster must be a power of 2
4. 1 <= sectors per cluster <= 128

Also added some comments relating to conditions that
may be useful to WARN about for BPB deserialization:
Z. bpb.reserved_sectors should be 1
Y. bpb.fats should be either 1 or 2
X. bpb.fs_version should be validated as zero

Add syntactic sugar for:
A. bpb.is_fat32()
B. bpb.sectors_per_fat()
C. bpb.total_sectors()
2018-09-24 20:58:02 +02:00
Rafał Harabień
6f10042784 Support reading volume label from root directory 2018-08-05 00:14:49 +02:00
Rafał Harabień
dc1ad7d2f7 Mark volume dirty on first write and not-dirty on unmount 2018-06-29 15:35:37 +02:00
Rafał Harabień
1f2427d371 Implement the same traits for FsOptions as in current stable release 2018-06-28 19:16:04 +02:00
Rafał Harabień
759758c1f2 Improve OemCpConverter and TimeProvider docs 2018-06-28 19:01:07 +02:00
Rafał Harabień
ecef2627a7 Move time related code to 'time' module 2018-06-28 18:53:51 +02:00
Rafał Harabień
1f8f8365d6 Add TimeProvider trait and time_provider option
This functionality is very useful for embedded usage where chrono feature
cannot be enabled.
2018-06-28 18:43:02 +02:00
Rafał Harabień
30f3f96537 Improve code style using rustfmt 2018-06-28 18:13:07 +02:00
Rafał Harabień
4528aedc6e Add oem_cp_converter option allowing to provide custom short name decoder
Encoder is not yet used but will be in future.
This is implemented as static reference for now to avoid adding additional
type parameters to all main types. It should be enough for most of cases
where encoder/decoder does not have any state and can be implemented as
static variable.
2018-06-25 23:51:09 +02:00
Rafał Harabień
fda4b5ca5b Add docs for FatType variants 2018-06-20 19:56:16 +02:00
Rafał Harabień
04887faaea Improve docs 2018-06-20 19:08:50 +02:00
Rafał Harabień
8be8c68eab Remove update_fs_info option
FSInfo sector should always be saved if it has changed.
2018-06-20 18:03:12 +02:00
Rafał Harabień
c4a1bc70ec Rename methods: bytes -> as_bytes 2018-06-20 17:38:04 +02:00
Rafał Harabień
69b7675940 Fix no_std build 2018-06-20 17:28:46 +02:00
Rafał Harabień
7a53215a57 No longer return &str for short names in no_std mode
Instead methods returning &[u8] were added.
It is API preparation for proper OEM codepage decoding.
Previous behavior would require to store duplicated short names
(one lossy and one real).
2018-06-20 17:17:01 +02:00
Rafał Harabień
a6b66f9434 Make errors more consistent with std::fs 2018-06-17 23:11:53 +02:00
Rafał Harabień
4f08acf4ab Do not mount volume if fs_version field in BPB is not zero 2018-06-17 16:34:08 +02:00
Rafał Harabień
8a5491a919 Doc improvements 2018-06-17 16:27:59 +02:00
Rafał Harabień
11a39fdaae Improve/fix API docs 2018-06-16 18:35:56 +02:00
Rafał Harabień
217b6046f1 Make disk object type generic (breaking change)
This change allows for moving an object ownership to FileSystem object
instead of borrowing it. It makes usage of library easier in some cases.
Unfortunately it is a breaking change.
2018-06-13 23:24:08 +02:00
Rafał Harabień
ccb205c906 Ignore free_cluster_count in FSInfo sector if volume has dirty flag 2018-06-07 22:54:35 +02:00
Rafał Harabień
1656540eac Simplify code by using Self in return type 2018-06-06 17:16:32 +02:00
Rafał Harabień
75a6c32360 Add derived traits for FsStatusFlags and add Eq for some structs 2018-06-06 14:29:38 +02:00
Rafał Harabień
85c48d6aec Make FsStatusFlags struct fields non-public and add getters
This way new fields can be added later without losing backward compatibility.
2018-06-06 14:17:05 +02:00
Rafał Harabień
0b5b04aca6 Make FileSystemStats struct fields non-public and add getters
This way new fields can be added later without losing backward compatibility.
2018-06-06 14:01:19 +02:00
Rafał Harabień
242e650626 Reduce number of pub(crate) attributes 2018-06-03 16:44:12 +02:00
Rafał Harabień
a83115dd45 Update FSInfo sector by default (if it is dirty) 2018-05-31 21:39:17 +02:00
Rafał Harabień
b4be13823c Cache free clusters count 2018-05-28 00:03:42 +02:00
Rafał Harabień
945612f042 Do not write FSInfo sector if nothing changed. 2018-05-27 23:56:38 +02:00
Rafał Harabień
147b31fdcd Update FSInfo sector on unmount/drop 2018-05-27 23:48:38 +02:00
Rafał Harabień
908ab61ee5 Update number of free clusters when allocating and freeing 2018-05-27 23:31:40 +02:00
Rafał Harabień
7709f5e6f6 Add FileSystem::stats method
It allows to get number of total and free clusters on FAT volume.
2018-05-26 17:09:13 +02:00
Rafał Harabień
9129816893 Speed up allocation by tracking last allocated cluster 2018-05-26 14:36:38 +02:00
Rafał Harabień
d094fd5d1d Support checking entire FAT table when hint points in the middle of it 2018-05-12 23:38:56 +02:00
Rafał Harabień
4793d20977 Read FSInfo sector on mount and use it during cluster allocation 2018-05-12 23:17:45 +02:00
Rafał Harabień
35d03daae9 Support no_std without alloc 2018-05-10 15:00:59 +02:00
Rafał Harabień
11b2a3b956 Basic no_std support 2018-05-10 01:00:24 +02:00
Rafał Harabień
429864a69f Clarify that seeked filesystem is not handled by library 2018-05-09 15:34:41 +02:00
Rafał Harabień
e9dec65318 Fix warnings in Rust 1.25 2018-05-09 15:34:00 +02:00
Rafał Harabień
8bb24994e0 Add read_status_flags API for getting dirty and IO error volume flags. 2017-12-01 17:24:02 +01:00
Rafał Harabień
d5c37f2af5 Introduce FsOptions struct for providing options for library.
Old read_only flag in FileSystem::new was misleading.
2017-11-08 20:26:50 +01:00
Rafał Harabień
8a8ee3c51a Ignore volume ID and label if signature is not valid. 2017-11-08 20:03:21 +01:00
Rafał Harabień
5c0ad0ce18 More code refactoring. 2017-11-08 19:59:03 +01:00
Rafał Harabień
681ee56cb3 Keep only BPB in FileSystem struct instead of entire BootRecord. 2017-11-08 19:41:05 +01:00
Rafał Harabień
b38ea78f3e Add automatic update of timestamps (created, accessed, modified).
Works only if chrono feature is enabled (default).
2017-11-08 00:18:31 +01:00
Rafał
529d717e30 Add .editorconfig file and fix whitespaces in existing files. (#4) 2017-10-25 17:20:27 +02:00