Commit graph

85 commits

Author SHA1 Message Date
Hermès Bélusca-Maïto 23b7c7b823
[FASTFAT] And now use the MS-open-sourced fastfat_new as our official FAT12/16/32 FS driver. 2022-10-01 01:28:19 +02:00
Hervé Poussineau 14c3936251 [VFATFS] Add it back to build on XBOX, with the name vfatfs.sys
Adapt some comments to new name.

CORE-16373
2022-09-24 12:12:33 +02:00
Hervé Poussineau b6d7571ebb [CMAKE] Set KDBG define only where required (fastfat, win32k, ntoskrnl) 2022-09-10 23:16:27 +02:00
Hermès Bélusca-Maïto 9393fc320e
[FORMATTING] Remove trailing whitespace. Addendum to 34593d93.
Excluded: 3rd-party code (incl. wine) and most of the win32ss.
2021-09-13 03:52:22 +02:00
Victor Perevertkin 34593d933b
[FORMATTING][NTOS][HAL][DRIVERS][SDK] Fix trailing spaces 2021-06-11 15:33:08 +03:00
Jérôme Gardou 3adf450867 [REACTOS] Addendum to 5c7ce4475e - Fix MSVC 2015 build
Put data into PAGEDATA or INITDATA sections
Keep section declaration for prototypes

CORE-17540
2021-05-12 11:04:29 +02:00
Timo Kreuzer ca74467904
[NTOS:CC] Raise status, when CcMapData fails (#3348)
Also add a check in fastfat, that asserts, when CcMapData returns FALSE.
2021-02-09 09:29:48 +01:00
Victor Perevertkin 5c7ce4475e
[REACTOS] Cleanup INIT and some PAGE section allocations
- Change INIT_FUNCTION and INIT_SECTION to CODE_SEG("INIT") and DATA_SEG("INIT") respectively
- Remove INIT_FUNCTION from function prototypes
- Remove alloc_text pragma calls as they are not needed anymore
2020-11-02 21:45:31 +03:00
Thomas Faber 303f17f884
[FASTFAT] Implement the overflow queue. CORE-17344 CORE-17328
This avoids blocking all Ex worker threads in fastfat, thereby making Cc
unable to issue the lazy writes that would unblock those workers.
This is more or less directly taken from fastfat_new.
2020-10-24 19:53:36 +02:00
Thomas Faber 320abafdc3
[FASTFAT] Ensure that deferred write IRP contexts are not touched. CORE-17328
Cc may decide to process deferred writes any time, so the context might
already be freed by the time we return from CcDeferWrite.
Also mark the IRP as pending, since we're going to return STATUS_PENDING.
2020-10-16 16:18:56 +02:00
Doug Lyons 79794b524c
[FASTFAT] Fix create for DOT and DOT-DOT leaving bad directory entry (#3241) 2020-10-12 18:54:06 +03:00
Nguyen Trung Khanh 166f815e7b
[FILESYSTEMS] Fix pool memory disclosure in filesystem drivers supporting FS_INFORMATION_CLASS.FileFsVolumeInformation (#2975)
* FileFsVolumeInformation-memory-disclosure

* remove unnecessary assignment to 0

* fix
2020-09-11 15:51:35 +03:00
Nguyen Trung Khanh ede7a20a17
[FILESYSTEMS] Fix pool memory disclosure in NtQueryAttributesFile handlers (#2926)
Fix pool memory disclosure caused by alignment bytes at the end of the _FILE_BASIC_INFORMATION structure
2020-09-11 15:47:43 +03:00
Stanislav Motylkov 06d5ed7ece
[FASTFAT] Support 64 KiB cluster sizes
FAT16 filesystem was not recognized on some 4GB USB flash drives.
This change makes them just work.

References:
- https://chat.reactos.org/reactos/pl/h83pm5ngkffk7qiyrmqnaaopxh
- https://support.microsoft.com/en-us/help/140365/default-cluster-size-for-ntfs-fat-and-exfat

CORE-16511
2020-07-22 19:50:24 +03:00
Timo Kreuzer 791b1ad7bd [FASTFAT] Copy an entire field, instead of half-copying it with RtlCopyMemory
Fixes GCC 8 warning:
sdk/include/crt/mingw32/intrin_x86.h:76:12: error: 'memmove' offset [21, 40] from the object at 'DirContext' is out of the bounds of referenced subobject 'Attrib' with type 'unsigned char' at offset 19 [-Werror=array-bounds]
     return memmove(dest, source, num);
            ^~~~~~~~~~~~~~~~~~~~~~~~~~
2019-07-20 13:56:18 +02:00
Timo Kreuzer 9590cd15f4 [FASTFAT] Fix use after free when volume is unmounted 2019-06-30 13:57:14 +02:00
Bișoc George 42ce8519b6 [FASTFAT][FLTMGR][NTOS] Do not explicitly call ObfDereferenceObject() (#1636)
"Most code should not directly call the platform-specific ObfDereferenceObject() function but use the ObDereferenceObject() macro instead."

CORE-16081
2019-06-22 16:20:58 +02:00
Hermès Bélusca-Maïto 6fb3dcd312
[FASTFAT] Adjust the 'UnCleanCount', followng commit 9c3c0d12. 2019-06-09 19:05:24 +02:00
Hermès Bélusca-Maïto 4b6abeb352
[FASTFAT] Minor cleanup of the main header file. 2019-06-09 17:56:06 +02:00
Jérôme Gardou 23373acbb9 [CMAKE] Use modules instead of shared libraries
There is no need to compile our DLLs as shared libraries since we are
managing symbols exports and imports through spec files.

On my system, this reduces the configure-time by a factor of two.
2019-04-06 17:43:38 +02:00
Pierre Schweitzer f36cbf75e3
[FASTFAT] On volume open, update share access if volume was already open
It was never updated afterwards, leading to a totally loss of share
access information amongst callers.
2019-02-14 10:48:32 +01:00
Thomas Faber bc002f1708
[FASTFAT] Avoid a use after free in VfatCloseFile. 2019-01-12 16:27:37 +01:00
Thomas Faber bc8307205b
[FASTFAT] Avoid a use after free in VfatCheckForDismount. 2019-01-12 16:27:30 +01:00
Timo Kreuzer 71fefa32db
[NDK][NTOS] Add global definition of INIT_FUNCTION/INIT_SECTION (#779)
* Add an NDK header to define INIT_FUNCTION/INIT_SECTION globally
* Use _declspec(allocate(x)) and _declspec(code_seg(x)) on MSVC versions that support it
* Use INIT_FUNCTION on functions only and INIT_SECTION on data only (required by MSVC)
* Place INIT_FUNCTION before the return type (required by MSVC)
* Make sure declarations and implementations share the same modifiers (required by MSVC)
* Add a global linker option to suppress warnings about defined but unused INIT section
* Merge INIT section into .text in freeldr
2018-12-30 12:19:11 +01:00
Hermès Bélusca-Maïto b77824a375 [FASTFAT] Improvements for volume dismount + minor bugfixing.
- Cache the RootFcb so that its cleanup can be handled separately
  during dismounting.

- Force volume dismount at cleanup if the VCB_DISMOUNT_PENDING flag
  is set.

- Actually dismount a volume if its VCB has been flagged as not good,
  or if we force dismounting.

NOTE: In their *CheckForDismount() function, our 3rd-party FS drivers
as well as MS' fastfat, perform a comparison check of the current VCB's
VPB ReferenceCount with some sort of "dangling"/"residual" open count.
It seems to be related to the fact that the volume root directory as
well as auxiliary data stream(s) are still opened, and only these are
allowed to be opened at that moment. After analysis it appears that for
the ReactOS' fastfat, this number is equal to "3".

- On dismounting, cleanup and destroy the RootFcb, VolumeFcb and the
  FATFileObject. Then cleanup the SpareVPB or the IoVPB members, and
  finish by removing the dismounted volume from the VolumeListEntry
  and cleaning up the notify synchronization object and the resources.

- During dismounting, and on shutdown, flush the volume before
  resetting its dirty bit.

- On shutdown, after volume flushing, try to unmount it without forcing.

- Release the VCB resources only when we actually dismount the volume
  in VfatCheckForDismount().

- Initialize first the notify list and the synchronization object,
  before sending the FSRTL_VOLUME_MOUNT notification.

- If we failed at mounting a volume but its VCB's FATFileObject was
  already initialized, first call CcUninitializeCacheMap() on it
  before dereferencing it.

- Send FSRTL_VOLUME_LOCK, FSRTL_VOLUME_LOCK_FAILED and
  FSRTL_VOLUME_UNLOCK notifications during volume locking (and failure)
  and volume unlocking.

- Flush the volume before locking it, and clean its dirty bit if needed.

NOTE: In addition to checking for VCB_CLEAR_DIRTY, we also check for the
presence of the VCB_IS_DIRTY flag before cleaning up the dirty bit: this
allows us to not re-clean the bit if it has been previously cleaned.
This is needed for instance in this scenario:
- The volume is locked (it gets flushed and the dirty bit is possibly cleared);
- The volume then gets formatted with a completely different FS, that
  possibly clears up the first sector (e.g. BTRFS ignores 1st sector);
- The volume is then dismounted: if we didn't check whether VCB_IS_DIRTY
  was set prior to resetting it, we could attempt clearing it again! But
  now that the volume's filesystem has been completely changed, we would
  then try to modify the dirty bit on an erroneous position on disk!
  That's why it should not be touched in this case during dismounting.
- The volume is unlocked (same comment as above), and later can be
  detected as being BTRFS.
2018-11-25 09:00:40 +01:00
Pierre Schweitzer 4b4c0aabcd
[FASTFAT] Properly return failure in vfatFindDirSpace()
CID 1441394
2018-11-16 22:07:07 +01:00
Hermès Bélusca-Maïto 8c0c90112e
[FASTFAT] Don't mess my debug log when partition SysType is printed! (when invalid chars are printed) 2018-10-13 19:57:24 +02:00
Pierre Schweitzer b5aa79a66d
[FASTFAT] Drop an useless #ifdef, we have this cast in all other FSDs 2018-08-21 08:50:29 +02:00
Pierre Schweitzer 4bb1baa860
[FASTFAT] Finally drop the TAG_VFAT allocation tag 2018-08-21 08:36:51 +02:00
Pierre Schweitzer 53985bf64d
[FASTFAT] Disable delayed close
It brings too many regressions for too little gain.

CORE-14938
CORE-14917
CORE-14826
2018-08-20 19:43:43 +02:00
Pierre Schweitzer 901c47ed14
[FASTFAT] Don't delay any other close once shutdown has started 2018-08-19 09:56:12 +02:00
Pierre Schweitzer 4fe7aafe10
[FASTFAT] Magic values-- 2018-08-19 09:56:12 +02:00
Pierre Schweitzer 047479e0a2
[FASTFAT] Don't leak statistics on dismount 2018-08-18 19:03:30 +02:00
Pierre Schweitzer 639e6d635f
[FASTFAT] Reduce the usage of the generic allocation tag
And use tag compatible with MS FastFAT, to use debug with WinDBG
2018-08-18 19:03:30 +02:00
Pierre Schweitzer 50b00f0fcc
[FASTFAT] Implement delayed close
When we're about to close a file (ie, forget everything about it
and release any associated structure), actually delay it.
This allows keep data fresh in memory for faster reuse in case
it would be required. The effective closing will only happen after some time.

For specific operations, this will produce a real speed up in ReactOS.
For instance, with that patch, Winamp starts within seconds, instead of dozen
of minutes.
In most cases, it will bring ReactOS to performances it had before fixing
the huge leak in FastFAT (commit 94ead99) without leaking the whole FS.

For now, due to regressions, this is only activated for files and not
for directories. Once it gets fixed, it will be enabled for both.

CORE-14826
CORE-14917
2018-08-18 19:03:30 +02:00
Pierre Schweitzer 52f0f80a83
[FASTFAT] Don't add an extra \, when renaming a file at root.
This fixes failures to rename a file where destination is
the root of a FAT volume.

CORE-10503
2018-06-09 22:17:17 +02:00
Pierre Schweitzer 6aa4beeefb
[FASTFAT] Use the FastFAT mechanism for counting clusters already implemented
This allows us having more accurate statistics regarding available clusters
count. Even though FastFAT and chkdsk still don't agree!

CORE-3877
2018-06-09 18:23:07 +02:00
Pierre Schweitzer 704baed2df
[FASTFAT] Start implementing FAT32 statistics support
Not fully perfect yet, chkdsk still complains.

CORE-3877
2018-06-09 12:36:43 +02:00
Pierre Schweitzer 04640f9264
[FASTFAT] Save the FSINFO sector location 2018-06-09 12:11:43 +02:00
Pierre Schweitzer 01e2877161
[FASTFAT] Properly check for buffer size on dir enumeration.
This avoids improper returns when multiple entries are requested
and, in rare circumstances, entries not being seen by umode.

CORE-14699
2018-06-07 19:34:47 +02:00
Pierre Schweitzer 9f3169b295
[FASTFAT] Lock DirResource on flush in case we're updating entry
CORE-14660
2018-05-28 19:37:56 +02:00
Pierre Schweitzer fc788cf2fd
[FASTFAT] Lock DirResource when modifying an entry on disk.
Likely not optimal, but fixes some races conditions where
the directory is uninit in the middle of the write.
2018-05-26 17:13:08 +02:00
Pierre Schweitzer 47b9db9d02
[FASTFAT] Initialize cache if neded for changing volume label.
CORE-14654
2018-05-26 10:12:55 +02:00
Pierre Schweitzer b4363068d1
[FASTFAT] Properly handle IRPs that can wait and these that cannot.
CORE-14634
2018-05-22 21:30:08 +02:00
Pierre Schweitzer e9e14be661
[FASTFAT] Properly queue pending write IRPs.
Addendum to 30b836b
2018-05-21 10:41:59 +02:00
Pierre Schweitzer 30b836bf3f
[FASTFAT] When extending a file, also lock the DirResource.
This avoids race conditions under high IOs and thus corruption on
the FS, or assertions failures in the kernel.
Easily triggered by building ReactOS on ReactOS ;-).
2018-05-21 10:30:14 +02:00
Pierre Schweitzer a10f6c7a0c
[FASTFAT] Fail if allocating the stream FO fails. 2018-05-20 13:53:43 +02:00
Pierre Schweitzer 7283f3cfd9
[FASTFAT] Addendum to d69f318 2018-05-19 13:46:34 +02:00
Pierre Schweitzer d69f31848e
[FASTFAT] Misc. fixes spotted by Thomas. 2018-05-19 10:07:14 +02:00
Pierre Schweitzer 7c01587680
[FASTFAT] Completely rewrite support for dirty volumes.
Until now, our support for dirty volumes was totally broken
to a point where, on FAT32 volume, the dirty couldn't even
be written nor read from the disk.

This commit totally rewrites its handling, for both FAT16 and FAT32
so that it's now fully functionnal. Furthermore, it also gets
totally compatible with our vfatlib, and thus, autochk.
Now, on mount, FastFAT will check if the volume is dirty or not, and
autochk will be able to ask for a repair if dirty. vfatlib will
repair the volume and remove the dirty bit. So that, on next
reboot, the volume will be mounted clean.

As a reminder, the dirty bit is set immediately after mounting
the volume, so that, if you crash or have a powercut, autochk
will always attempt to repair your volume (with more or less,
that's FAT!).

If you want to experience without breaking your FAT volume,
just boot, open a cmd prompt and type: fsutil dirty set c:
and reboot!

CORE-13758
CORE-13760
CORE-13759
2018-05-18 23:05:05 +02:00