Changeset View
Changeset View
Standalone View
Standalone View
sys/fs/msdosfs/msdosfs_fat.c
Show First 20 Lines • Show All 385 Lines • ▼ Show 20 Lines | usemap_alloc(struct msdosfsmount *pmp, u_long cn) | ||||
KASSERT(cn <= pmp->pm_maxcluster, ("cn too large %lu %lu", cn, | KASSERT(cn <= pmp->pm_maxcluster, ("cn too large %lu %lu", cn, | ||||
pmp->pm_maxcluster)); | pmp->pm_maxcluster)); | ||||
KASSERT((pmp->pm_flags & MSDOSFSMNT_RONLY) == 0, | KASSERT((pmp->pm_flags & MSDOSFSMNT_RONLY) == 0, | ||||
("usemap_alloc on ro msdosfs mount")); | ("usemap_alloc on ro msdosfs mount")); | ||||
KASSERT((pmp->pm_inusemap[cn / N_INUSEBITS] & (1 << (cn % N_INUSEBITS))) | KASSERT((pmp->pm_inusemap[cn / N_INUSEBITS] & (1 << (cn % N_INUSEBITS))) | ||||
== 0, ("Allocating used sector %ld %ld %x", cn, cn % N_INUSEBITS, | == 0, ("Allocating used sector %ld %ld %x", cn, cn % N_INUSEBITS, | ||||
(unsigned)pmp->pm_inusemap[cn / N_INUSEBITS])); | (unsigned)pmp->pm_inusemap[cn / N_INUSEBITS])); | ||||
pmp->pm_inusemap[cn / N_INUSEBITS] |= 1 << (cn % N_INUSEBITS); | pmp->pm_inusemap[cn / N_INUSEBITS] |= 1U << (cn % N_INUSEBITS); | ||||
KASSERT(pmp->pm_freeclustercount > 0, ("usemap_alloc: too little")); | KASSERT(pmp->pm_freeclustercount > 0, ("usemap_alloc: too little")); | ||||
pmp->pm_freeclustercount--; | pmp->pm_freeclustercount--; | ||||
pmp->pm_flags |= MSDOSFS_FSIMOD; | pmp->pm_flags |= MSDOSFS_FSIMOD; | ||||
} | } | ||||
static __inline void | static __inline void | ||||
usemap_free(struct msdosfsmount *pmp, u_long cn) | usemap_free(struct msdosfsmount *pmp, u_long cn) | ||||
{ | { | ||||
MSDOSFS_ASSERT_MP_LOCKED(pmp); | MSDOSFS_ASSERT_MP_LOCKED(pmp); | ||||
KASSERT(cn <= pmp->pm_maxcluster, ("cn too large %lu %lu", cn, | KASSERT(cn <= pmp->pm_maxcluster, ("cn too large %lu %lu", cn, | ||||
pmp->pm_maxcluster)); | pmp->pm_maxcluster)); | ||||
KASSERT((pmp->pm_flags & MSDOSFSMNT_RONLY) == 0, | KASSERT((pmp->pm_flags & MSDOSFSMNT_RONLY) == 0, | ||||
("usemap_free on ro msdosfs mount")); | ("usemap_free on ro msdosfs mount")); | ||||
pmp->pm_freeclustercount++; | pmp->pm_freeclustercount++; | ||||
pmp->pm_flags |= MSDOSFS_FSIMOD; | pmp->pm_flags |= MSDOSFS_FSIMOD; | ||||
KASSERT((pmp->pm_inusemap[cn / N_INUSEBITS] & (1 << (cn % N_INUSEBITS))) | KASSERT((pmp->pm_inusemap[cn / N_INUSEBITS] & (1 << (cn % N_INUSEBITS))) | ||||
!= 0, ("Freeing unused sector %ld %ld %x", cn, cn % N_INUSEBITS, | != 0, ("Freeing unused sector %ld %ld %x", cn, cn % N_INUSEBITS, | ||||
(unsigned)pmp->pm_inusemap[cn / N_INUSEBITS])); | (unsigned)pmp->pm_inusemap[cn / N_INUSEBITS])); | ||||
pmp->pm_inusemap[cn / N_INUSEBITS] &= ~(1 << (cn % N_INUSEBITS)); | pmp->pm_inusemap[cn / N_INUSEBITS] &= ~(1U << (cn % N_INUSEBITS)); | ||||
} | } | ||||
int | int | ||||
clusterfree(struct msdosfsmount *pmp, u_long cluster, u_long *oldcnp) | clusterfree(struct msdosfsmount *pmp, u_long cluster, u_long *oldcnp) | ||||
{ | { | ||||
int error; | int error; | ||||
u_long oldcn; | u_long oldcn; | ||||
▲ Show 20 Lines • Show All 346 Lines • ▼ Show 20 Lines | if (start) { | ||||
len = 0; | len = 0; | ||||
newst = pmp->pm_nxtfree; | newst = pmp->pm_nxtfree; | ||||
foundl = 0; | foundl = 0; | ||||
for (cn = newst; cn <= pmp->pm_maxcluster;) { | for (cn = newst; cn <= pmp->pm_maxcluster;) { | ||||
idx = cn / N_INUSEBITS; | idx = cn / N_INUSEBITS; | ||||
map = pmp->pm_inusemap[idx]; | map = pmp->pm_inusemap[idx]; | ||||
map |= (1 << (cn % N_INUSEBITS)) - 1; | map |= (1U << (cn % N_INUSEBITS)) - 1; | ||||
if (map != FULL_RUN) { | if (map != FULL_RUN) { | ||||
cn = idx * N_INUSEBITS + ffs(map ^ FULL_RUN) - 1; | cn = idx * N_INUSEBITS + ffs(map ^ FULL_RUN) - 1; | ||||
if ((l = chainlength(pmp, cn, count)) >= count) | if ((l = chainlength(pmp, cn, count)) >= count) | ||||
return (chainalloc(pmp, cn, count, fillwith, retcluster, got)); | return (chainalloc(pmp, cn, count, fillwith, retcluster, got)); | ||||
if (l > foundl) { | if (l > foundl) { | ||||
foundcn = cn; | foundcn = cn; | ||||
foundl = l; | foundl = l; | ||||
} | } | ||||
cn += l + 1; | cn += l + 1; | ||||
continue; | continue; | ||||
} | } | ||||
cn += N_INUSEBITS - cn % N_INUSEBITS; | cn += N_INUSEBITS - cn % N_INUSEBITS; | ||||
} | } | ||||
for (cn = 0; cn < newst;) { | for (cn = 0; cn < newst;) { | ||||
idx = cn / N_INUSEBITS; | idx = cn / N_INUSEBITS; | ||||
map = pmp->pm_inusemap[idx]; | map = pmp->pm_inusemap[idx]; | ||||
map |= (1 << (cn % N_INUSEBITS)) - 1; | map |= (1U << (cn % N_INUSEBITS)) - 1; | ||||
if (map != FULL_RUN) { | if (map != FULL_RUN) { | ||||
cn = idx * N_INUSEBITS + ffs(map ^ FULL_RUN) - 1; | cn = idx * N_INUSEBITS + ffs(map ^ FULL_RUN) - 1; | ||||
if ((l = chainlength(pmp, cn, count)) >= count) | if ((l = chainlength(pmp, cn, count)) >= count) | ||||
return (chainalloc(pmp, cn, count, fillwith, retcluster, got)); | return (chainalloc(pmp, cn, count, fillwith, retcluster, got)); | ||||
if (l > foundl) { | if (l > foundl) { | ||||
foundcn = cn; | foundcn = cn; | ||||
foundl = l; | foundl = l; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 141 Lines • ▼ Show 20 Lines | #endif | ||||
} else if (readcn == CLUST_FREE) | } else if (readcn == CLUST_FREE) | ||||
usemap_free(pmp, cn); | usemap_free(pmp, cn); | ||||
} | } | ||||
if (bp != NULL) | if (bp != NULL) | ||||
brelse(bp); | brelse(bp); | ||||
for (cn = pmp->pm_maxcluster + 1; cn < (pmp->pm_maxcluster + | for (cn = pmp->pm_maxcluster + 1; cn < (pmp->pm_maxcluster + | ||||
N_INUSEBITS) / N_INUSEBITS; cn++) | N_INUSEBITS) / N_INUSEBITS; cn++) | ||||
pmp->pm_inusemap[cn / N_INUSEBITS] |= 1 << (cn % N_INUSEBITS); | pmp->pm_inusemap[cn / N_INUSEBITS] |= 1U << (cn % N_INUSEBITS); | ||||
return (0); | return (0); | ||||
} | } | ||||
/* | /* | ||||
* Allocate a new cluster and chain it onto the end of the file. | * Allocate a new cluster and chain it onto the end of the file. | ||||
* | * | ||||
* dep - the file to extend | * dep - the file to extend | ||||
▲ Show 20 Lines • Show All 212 Lines • Show Last 20 Lines |