Commit Graph

211 Commits

Author SHA1 Message Date
Rafał Harabień
f2863e8f46 fix: Rework FAT size calculation for volume formatting
New formula gives nearly perfect results (according to tests) and is
better than formula from specification.
Also all math transformations are provided in comments so it is no longer
a blindly copied formula from spec but a Math supported formula.
Old formula was not taking into account sector size (it resulted in too
big FATs for sector size different than 512) and had rounding issues for
FAT12 and FAT32.
2018-12-12 21:28:05 +01:00
Rafał Harabień
a88d751c47 refactor: apply most of rustfmt changes 2018-12-09 00:32:52 +01:00
Rafał Harabień
a3ab0098da refactor: fix some lints from Clippy tool 2018-12-09 00:22:21 +01:00
Rafał Harabień
96339ff7e6 fix: use write_all in serialize method for FS Info sector 2018-12-08 23:45:31 +01:00
Rafał Harabień
70b0a771b8 refactor: Convert between sectors, clusters and bytes in one place (BPB)
Change encapsulates method of calculating it so it can be optimized in
future in one place (e.g. using bit shifts).
2018-12-08 19:38:31 +01:00
Rafał Harabień
cf3256bfda fix: clear directory returned from create_dir method
Previous implementation did not zero allocated cluster so created directory
could have garbage contents.
Bug exists in code since version 0.2 and all code using create_dir is
affected.
This commit also improves tests of volume formatting so a dirty partition
is used allowing to detect bugs like this.
2018-12-08 19:34:47 +01:00
Rafał Harabień
647ca9252a fix: when formatting FAT32 volume properly clear root directory cluster 2018-12-08 19:29:44 +01:00
Rafał Harabień
4727b170df Add more logging on trace channel 2018-12-08 19:29:02 +01:00
Rafał Harabień
1768b0fe7e Move Boot Sector/BPB related code to boot_sector.rs 2018-12-08 17:17:08 +01:00
Rafał Harabień
15b45f2457 Add docs for formatting API 2018-12-08 16:59:10 +01:00
Rafał Harabień
41c3d31ba2 New syntax for FormatVolumeOptions 2018-12-05 22:31:59 +01:00
Rafał Harabień
fd89185461 Add more format_volume tests and simlify code 2018-12-05 22:31:59 +01:00
Rafał Harabień
e8a313ac4c Change total FAT entries calculation
Old way of doing it was wrong because 512 (standard sector size) is not
dividable by 12.
Also fix the build...
2018-12-05 22:31:59 +01:00
Rafał Harabień
253f816c40 Check if total clusters after formatting and fat type matches 2018-12-05 22:31:59 +01:00
Rafał Harabień
b9753248f7 Properly initialize file allocation table when formatting a volume 2018-12-05 22:31:59 +01:00
Rafał Harabień
447c9dda35 Improve formulas for volume formatting
* Fix bytes per cluster and sectors per fat calculations + add tests
* Fix boot code in FAT12/16
2018-12-05 22:31:59 +01:00
Rafał Harabień
df81d3b9fd Volume format API 2018-12-05 22:31:59 +01:00
Rafał Harabień
e45cfb5188 fix: do not use hard-coded sector size when dealing with FSInfo sector
Previous code is not working correctly if sector size is different than 512.
Creating test for this issue would require another binary blob in
repository so I am leaving it without test for now.
2018-12-05 01:38:51 +01:00
Rafał Harabień
77be6dd9d0 Fix build 2018-10-22 21:40:03 +02:00
Rafał
c4ffb2ccf5
Add more checks of BPB (#21) 2018-10-22 14:51:32 +02:00
Rafał Harabień
a1db3e82c7 Simplify FAT tests 2018-10-20 15:34:00 +02:00
Rafał Harabień
18c496d6f0 Change version to 0.3.1 2018-10-20 13:55:25 +02:00
Rafał Harabień
a8b31ea888 Update email address 2018-10-20 13:53:22 +02:00
Rafał Harabień
6271741d24 Add changelog 2018-10-20 13:52:30 +02:00
Rafał Harabień
534781963b Simplify file size related code 2018-10-10 22:03:00 +02:00
Rafał Harabień
1724a54536 Fix formatting
Immprovements by hand + rustfmt
2018-10-10 21:26:31 +02:00
Rafał
83b5971045
Enable warnings and backtrace in Travis CI build (#20) 2018-10-06 17:37:48 +02:00
Rafał
9acd6ed6df
Separate sanity checks into validate() methods (#19) 2018-10-06 17:27:52 +02:00
Rafał
3590f43013
Try to fix build without std and alloc (#18) 2018-10-06 17:16:15 +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
Rafał Harabień
829b9c5f3f Fix warnings for file entries without LFN entries
Fixes #12 and #14.
2018-09-29 15:19:46 +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ń
8c9d476c2f Fix build 2018-08-05 17:21:08 +02:00
Rafał Harabień
dce8b32577 Simplify code dealing with LFN entries generation 2018-08-05 17:12:03 +02:00
Rafał Harabień
a503cb4562 Fix build on Rust 1.24 2018-08-05 03:09:48 +02:00
Rafał Harabień
6f10042784 Support reading volume label from root directory 2018-08-05 00:14:49 +02:00
Rafał Harabień
5dea8b5f8a Test dirty flags on all FAT variants
Flags field offset is different is it makes sense.
2018-06-29 15:38:27 +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ń
881cf7709d Deprecate set_created. set_accessed, set_modified methods on File 2018-06-28 18:58:29 +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ń
98c0fa528c Fix no_std build 2018-06-25 23:56:46 +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ń
cd7e77e1b4 Rename directory entry flags and add some internal docs 2018-06-25 00:22:34 +02:00
Rafał Harabień
f9ca0f95ce Fix decoding 0xE5 character in first byte of short name 2018-06-25 00:16:14 +02:00
Rafał Harabień
be96ba8122 Properly handle short names with spaces in the middle 2018-06-25 00:07:11 +02:00
Rafał Harabień
f5bf959aa7 Update TODO list 2018-06-24 17:15:53 +02:00