Commit Graph

224 Commits

Author SHA1 Message Date
Rafał Harabień
0a68d8f0d5 Fix the workaround for no_std build failure in travis 2019-06-20 02:41:08 +02:00
Rafał Harabień
44d01bb164 Work around no_std build failure in travis
Issue is caused by core_io crate requiring very old rustc which is not
compatible with byteorder create since version 1.3.
In crates depending on fatfs byteorder version can be overriden in
their Cargo.toml file.
2019-06-20 02:13:59 +02:00
Rafał Harabień
6ee7e3fc16 Fix example in README file 2019-05-21 00:48:26 +02:00
Rafał Harabień
8178908e06 Add changelog entries for v0.3.2 2018-12-29 20:57:16 +01:00
Rafał Harabień
3628ec9825 Add mkfatfs example 2018-12-29 20:42:49 +01:00
Rafał Harabień
a63458b150 Change version to 0.3.2 2018-12-29 20:22:10 +01:00
Rafał Harabień
812f61e393 Change rustfmt options and reformat code
Option 'use_small_heuristics' is too abstract for me.
Smaller lines and disabled heuristics should work better.
2018-12-29 20:21:24 +01:00
Rafał Harabień
8ddd1de5fc Add basic validation in FormatVolumeOptions setters 2018-12-29 19:43:42 +01:00
Rafał Harabień
dc128b7308 Refactor FAT type determination, rename and add option for format_volume
* FAT type should be properly selected even if custom cluster size is used.
* root_entries has been renamed to max_root_dir_entries in FormatVolumeOptions
* added option FormatVolumeOptions::fats
2018-12-29 19:37:46 +01:00
Rafał Harabień
131f047c91 Fix build on old Rustc 2018-12-20 02:43:04 +01:00
Rafał Harabień
8502edb7b8 feat: Make sector size and total sectors optional for format_volume
* moved bytes_per_sector and total_sectors from FormatVolumeOptions::new
to a dedicated methods (it is optional now)
* calculate total number of sectors using seek() to disk end if not provided
* added more doc comments
* added assertions about disk handle position being zero
2018-12-20 01:47:34 +01:00
Rafał Harabień
c372429951 feat: check more BPB fields when mounting fs
Fail mounting if:
* root_entries is zero (only on FAT12/FAT16)
* backup_boot_sector is outside of the reserved region (only on FAT32)
* fs_info_sector is outside of the reserved region (only on FAT32)
2018-12-12 22:21:12 +01:00
Rafał Harabień
b4455a86a8 fix: Make backup boot-sector part of reserved region when formatting volume
Change number of reserved sectors to 8.
Previously backup boot-sector was over-written by FAT formatting code soon
after it was initialized.
2018-12-12 22:10:10 +01:00
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