Home | History | Annotate | Download | only in msdosfs
History log of /src/sys/fs/msdosfs/msdosfs_fat.c
RevisionDateAuthorComments
 1.37  13-May-2024  msaitoh s/contigous/contiguous/ in comment.
 1.36  23-Oct-2021  thorpej Sanitize the symbol namespace. NFC.
 1.35  07-Sep-2020  mrg avoid an uninit warning with GCC 9.
 1.34  03-Sep-2018  riastradh Rename min/max -> uimin/uimax for better honesty.

These functions are defined on unsigned int. The generic name
min/max should not silently truncate to 32 bits on 64-bit systems.
This is purely a name change -- no functional change intended.

HOWEVER! Some subsystems have

#define min(a, b) ((a) < (b) ? (a) : (b))
#define max(a, b) ((a) > (b) ? (a) : (b))

even though our standard name for that is MIN/MAX. Although these
may invite multiple evaluation bugs, these do _not_ cause integer
truncation.

To avoid `fixing' these cases, I first changed the name in libkern,
and then compile-tested every file where min/max occurred in order to
confirm that it failed -- and thus confirm that nothing shadowed
min/max -- before changing it.

I have left a handful of bootloaders that are too annoying to
compile-test, and some dead code:

cobalt ews4800mips hp300 hppa ia64 luna68k vax
acorn32/if_ie.c (not included in any kernels)
macppc/if_gm.c (superseded by gem(4))

It should be easy to fix the fallout once identified -- this way of
doing things fails safe, and the goal here, after all, is to _avoid_
silent integer truncations, not introduce them.

Maybe one day we can reintroduce min/max as type-generic things that
never silently truncate. But we should avoid doing that for a while,
so that existing code has a chance to be detected by the compiler for
conversion to uimin/uimax without changing the semantics until we can
properly audit it all. (Who knows, maybe in some cases integer
truncation is actually intended!)
 1.33  25-Jul-2018  kamil Avoid undefined behavior semantics in msdosfs_fat.c

Do not change signedness bit with left shift.
While there avoid signed integer overflow.
Address both issues with using unsigned type.

msdosfs_fat.c:512:42, left shift of 1 by 31 places cannot be represented in type 'int'
msdosfs_fat.c:521:44, left shift of 1 by 31 places cannot be represented in type 'int'
msdosfs_fat.c:744:14, left shift of 1 by 31 places cannot be represented in type 'int'
msdosfs_fat.c:744:24, signed integer overflow: -2147483648 - 1 cannot be represented in type 'int [20]'
msdosfs_fat.c:840:13, left shift of 1 by 31 places cannot be represented in type 'int'
msdosfs_fat.c:840:36, signed integer overflow: -2147483648 - 1 cannot be represented in type 'int [20]'

Detected with micro-UBSan in the user mode.
 1.32  27-Jan-2018  sevan branches: 1.32.2; 1.32.4;
Need strings.h for ffs()
Resolves implict declaration warning of ffs() when building tools via build.sh
 1.31  07-May-2016  mlelstv branches: 1.31.10;
fix DEBUG build
 1.30  03-May-2016  mlelstv Validate FAT entries to avoid some panics caused by a corrupted FAT.

Also print FAT write errors when mount is synchronous (-o sync). This
reveals problems caused by a write protected disklabel on sector 1.
 1.29  28-Mar-2015  maxv Remove the 'cred' argument from bread(). Remove a now unused var in
ffs_snapshot.c. Update the man page accordingly.

ok hannken@
 1.28  28-Jan-2013  christos branches: 1.28.12; 1.28.14;
A little more debugging.
 1.27  27-Jan-2013  christos don't need sys/mount.h in userland.
 1.26  27-Jan-2013  christos tidy up debugging printfs; no functional change.
 1.25  26-Jan-2013  christos more cross-compile friendly.
 1.24  26-Jan-2013  christos expose more stuff if MAKEFS is defined for the headers, and arrange for
the source file to be compilable from userland.
 1.23  20-Dec-2012  hannken Revert rev. 1.20 now that bread() has been fixed.

PR kern/46282 (6.0_BETA crash: msdosfs_bmap -> pcbmap -> bread -> bio_doread)
 1.22  20-Dec-2012  hannken Change bread() and breadn() to never return a buffer on
error and modify all callers to not brelse() on error.

Welcome to 6.99.16

PR kern/46282 (6.0_BETA crash: msdosfs_bmap -> pcbmap -> bread -> bio_doread)
 1.21  04-Nov-2012  jakllsch Stylistic changes in comments/strings:
"FAT" and "fat" are different things, use the appropriate case.
"GEMDOS" is all caps.
 1.20  09-Apr-2012  hannken branches: 1.20.2;
pcbmap(): We cannot use bread() here as for the pagedaemon getblk()
may fail leading to a panic in bread().
Replace bread() with getblk() / VOP_STRATEGY() and return
an error if getblk() fails.

Fixes PR#46282: 6.0_BETA crash: msdosfs_bmap -> pcbmap -> bread -> bio_doread

This is an interim solution for easy pullup. The final solution
is be to change bread() to not return a buffer on error. As
we have to change all callers of bread() this will not qualify
for a pullup.
 1.19  26-Jan-2010  joerg branches: 1.19.12; 1.19.16; 1.19.18;
On broken filesystems the fillinmap inner loop may have never read a
block, so don't try to release it if bp==NULL.
 1.18  14-Mar-2009  dsl ANSIfy another 1261 function definitions.
The only ones left in sys are beyond by sed script!
(or in sys/dist or sys/external)
Mostly they have function pointer parameters.
 1.17  14-Mar-2009  dsl Change about 4500 of the K&R function definitions to ANSI ones.
There are still about 1600 left, but they have ',' or /* ... */
in the actual variable definitions - which my awk script doesn't handle.
There are also many that need () -> (void).
(The script does handle misordered arguments.)
 1.16  16-May-2008  hannken branches: 1.16.6; 1.16.12;
Make sure all cached buffers with valid, not yet written data have been
run through copy-on-write. Call fscow_run() with valid data where possible.

The LP_UFSCOW hack is no longer needed to protect ffs_copyonwrite() against
endless recursion.

- Add a flag B_MODIFY to bread(), breada() and breadn(). If set the caller
intends to modify the buffer returned.

- Always run copy-on-write on buffers returned from ffs_balloc().

- Add new function ffs_getblk() that gets a buffer, assigns a new blkno,
may clear the buffer and runs copy-on-write. Process possible errors
from getblk() or fscow_run(). Part of PR kern/38664.

Welcome to 4.99.63

Reviewed by: YAMAMOTO Takashi <yamt@netbsd.org>
 1.15  08-Oct-2007  ad branches: 1.15.18; 1.15.20; 1.15.22; 1.15.24;
Merge brelse() changes from the vmlocking branch.
 1.14  29-Apr-2007  msaitoh branches: 1.14.6; 1.14.8; 1.14.10;
fix typos
 1.13  04-Mar-2007  christos branches: 1.13.2; 1.13.4;
Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.12  25-Nov-2006  scw branches: 1.12.4;
Support FAT filesystems on non-DEV_BSIZE media.

Based on the patches provided in PR kern/17398 by Trevin Beattie.
 1.11  22-Sep-2006  xtraeme Apply patch from PR kern/34583 sent by Rhialto, quoting him:

"Add a 3rd entry in the cache, which keeps the end position
from just before extending a file.
This has the desired effect of keeping the write speed constant."

And yes, that helps a lot copying large files... always at full speed
now. This closes my PR kern/30868 "Poor performance copying large files
on msdosfs".

Also remove a 2 if-statements testing the same condition, combine them.

All that from Rhialto, thank you very much.
 1.10  14-May-2006  elad branches: 1.10.6; 1.10.8; 1.10.10;
integrate kauth.
 1.9  15-Apr-2006  christos Coverity CID 839: Add KASSERT before deref.
 1.8  15-Apr-2006  christos Coverity CID 838: Add KASSERT before deref.
 1.7  24-Dec-2005  perry branches: 1.7.4; 1.7.6; 1.7.8; 1.7.10; 1.7.12;
Remove leading __ from __(const|inline|signed|volatile) -- it is obsolete.
 1.6  11-Dec-2005  christos merge ktrace-lwp.
 1.5  29-Aug-2005  xtraeme Remove __P()
 1.4  26-Feb-2005  perry branches: 1.4.2; 1.4.4;
nuke trailing whitespace
 1.3  21-Apr-2004  christos branches: 1.3.4; 1.3.6;
Replace the statfs() family of system calls with statvfs().
Retain binary compatibility.
 1.2  22-Oct-2003  briggs Fix a panic that occurred when trying to traverse a corrupt msdosfs
filesystem. With this particular corruption, the code in pcbmap()
would compute an offset into an array that was way out of bounds,
so check the bounds before trying to access and return an error if
the offset would be out of bounds.
 1.1  26-Dec-2002  jdolecek branches: 1.1.2; 1.1.4;
move msdosfs code from sys/msdosfs to sys/fs/msdosfs
 1.1.4.5  10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.1.4.4  04-Mar-2005  skrll Sync with HEAD.

Hi Perry!
 1.1.4.3  21-Sep-2004  skrll Fix the sync with head I botched.
 1.1.4.2  18-Sep-2004  skrll Sync with HEAD.
 1.1.4.1  03-Aug-2004  skrll Sync with HEAD
 1.1.2.2  29-Dec-2002  thorpej With with HEAD.
 1.1.2.1  26-Dec-2002  thorpej file msdosfs_fat.c was added on branch nathanw_sa on 2002-12-29 19:56:02 +0000
 1.3.6.1  19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.3.4.1  29-Apr-2005  kent sync with -current
 1.4.4.4  27-Oct-2007  yamt sync with head.
 1.4.4.3  03-Sep-2007  yamt sync with head.
 1.4.4.2  30-Dec-2006  yamt sync with head.
 1.4.4.1  21-Jun-2006  yamt sync with head.
 1.4.2.1  06-Oct-2006  ghen Pull up following revision(s) (requested by xtraeme in ticket #1525):
sys/fs/msdosfs/denode.h: revision 1.14
sys/fs/msdosfs/msdosfs_vnops.c: revision 1.31
sys/fs/msdosfs/msdosfs_fat.c: revision 1.11
Apply patch from PR kern/34583 sent by Rhialto, quoting him:
"Add a 3rd entry in the cache, which keeps the end position
from just before extending a file.
This has the desired effect of keeping the write speed constant."
And yes, that helps a lot copying large files... always at full speed
now. This closes my PR kern/30868 "Poor performance copying large files
on msdosfs".
Also remove a 2 if-statements testing the same condition, combine them.
All that from Rhialto, thank you very much.
 1.7.12.1  24-May-2006  tron Merge 2006-05-24 NetBSD-current into the "peter-altq" branch.
 1.7.10.2  06-May-2006  christos - Move kauth_cred_t declaration to <sys/types.h>
- Cleanup struct ucred; forward declarations that are unused.
- Don't include <sys/kauth.h> in any header, but include it in the c files
that need it.

Approved by core.
 1.7.10.1  19-Apr-2006  elad sync with head.
 1.7.8.1  24-May-2006  yamt sync with head.
 1.7.6.2  01-Jun-2006  kardel Sync with head.
 1.7.6.1  22-Apr-2006  simonb Sync with head.
 1.7.4.1  09-Sep-2006  rpaulo sync with head
 1.10.10.2  10-Dec-2006  yamt sync with head.
 1.10.10.1  22-Oct-2006  yamt sync with head
 1.10.8.2  12-Jan-2007  ad Sync with head.
 1.10.8.1  18-Nov-2006  ad Sync with head.
 1.10.6.1  23-Sep-2006  ghen Pull up following revision(s) (requested by xtraeme in ticket #206):
sys/fs/msdosfs/denode.h: revision 1.14
sys/fs/msdosfs/msdosfs_vnops.c: revision 1.31
sys/fs/msdosfs/msdosfs_fat.c: revision 1.11
Apply patch from PR kern/34583 sent by Rhialto, quoting him:
"Add a 3rd entry in the cache, which keeps the end position
from just before extending a file.
This has the desired effect of keeping the write speed constant."
And yes, that helps a lot copying large files... always at full speed
now. This closes my PR kern/30868 "Poor performance copying large files
on msdosfs".
Also remove a 2 if-statements testing the same condition, combine them.
All that from Rhialto, thank you very much.
 1.12.4.2  07-May-2007  yamt sync with head.
 1.12.4.1  12-Mar-2007  rmind Sync with HEAD.
 1.13.4.1  11-Jul-2007  mjf Sync with head.
 1.13.2.2  08-Jun-2007  ad Sync with head.
 1.13.2.1  13-May-2007  ad - Pass the error number and residual count to biodone(), and let it handle
setting error indicators. Prepare to eliminate B_ERROR.
- Add a flag argument to brelse() to be set into the buf's flags, instead
of doing it directly. Typically used to set B_INVAL.
- Add a "struct cpu_info *" argument to kthread_create(), to be used to
create bound threads. Change "bool mpsafe" to "int flags".
- Allow exit of LWPs in the IDL state when (l != curlwp).
- More locking fixes & conversion to the new API.
 1.14.10.1  14-Oct-2007  yamt sync with head.
 1.14.8.1  06-Nov-2007  matt sync with HEAD
 1.14.6.1  26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.15.24.1  23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.15.22.2  11-Mar-2010  yamt sync with head
 1.15.22.1  04-May-2009  yamt sync with head.
 1.15.20.1  18-May-2008  yamt sync with head.
 1.15.18.1  02-Jun-2008  mjf Sync with HEAD.
 1.16.12.1  13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.16.6.1  28-Apr-2009  skrll Sync with HEAD.
 1.19.18.1  16-Apr-2012  riz Pull up following revision(s) (requested by hannken in ticket #183):
sys/fs/msdosfs/msdosfs_fat.c: revision 1.20
pcbmap(): We cannot use bread() here as for the pagedaemon getblk()
may fail leading to a panic in bread().
Replace bread() with getblk() / VOP_STRATEGY() and return
an error if getblk() fails.

Fixes PR#46282: 6.0_BETA crash: msdosfs_bmap -> pcbmap -> bread ->
bio_doread

This is an interim solution for easy pullup. The final solution
is be to change bread() to not return a buffer on error. As
we have to change all callers of bread() this will not qualify
for a pullup.
 1.19.16.1  29-Apr-2012  mrg sync to latest -current.
 1.19.12.4  22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.19.12.3  23-Jan-2013  yamt sync with head
 1.19.12.2  16-Jan-2013  yamt sync with (a bit old) head
 1.19.12.1  17-Apr-2012  yamt sync with head
 1.20.2.3  03-Dec-2017  jdolecek update from HEAD
 1.20.2.2  25-Feb-2013  tls resync with head
 1.20.2.1  20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.28.14.2  29-May-2016  skrll Sync with HEAD
 1.28.14.1  06-Apr-2015  skrll Sync with HEAD
 1.28.12.1  19-Feb-2018  snj Pull up following revision(s) (requested by sevan in ticket #1558):
sys/fs/msdosfs/msdosfs_fat.c: 1.32
usr.sbin/makefs/msdos/msdosfs_vfsops.c: 1.11
Need strings.h for ffs()
--
Need strings.h for ffs()
Resolves implict declaration warning of ffs() when building tools via
build.sh
 1.31.10.1  04-Feb-2018  martin Pull up following revision(s) (requested by sevan in ticket #518):
sys/fs/msdosfs/msdosfs_fat.c: revision 1.32
usr.sbin/makefs/msdos/msdosfs_vfsops.c: revision 1.11
Need strings.h for ffs()
Need strings.h for ffs()
Resolves implict declaration warning of ffs() when building tools via
build.sh
 1.32.4.1  10-Jun-2019  christos Sync with HEAD
 1.32.2.2  06-Sep-2018  pgoyette Sync with HEAD

Resolve a couple of conflicts (result of the uimin/uimax changes)
 1.32.2.1  28-Jul-2018  pgoyette Sync with HEAD

RSS XML Feed