Changeset View
Changeset View
Standalone View
Standalone View
sys/fs/msdosfs/msdosfs_fat.c
Show First 20 Lines • Show All 43 Lines • ▼ Show 20 Lines | |||||
* understanding that the author is not responsible for the correct | * understanding that the author is not responsible for the correct | ||||
* functioning of this software in any circumstances and is not liable for | * functioning of this software in any circumstances and is not liable for | ||||
* any damages caused by this software. | * any damages caused by this software. | ||||
* | * | ||||
* October 1992 | * October 1992 | ||||
*/ | */ | ||||
#include <sys/param.h> | #include <sys/param.h> | ||||
#include <sys/errno.h> | |||||
#ifndef MAKEFS | |||||
#include <sys/systm.h> | #include <sys/systm.h> | ||||
#include <sys/buf.h> | #include <sys/buf.h> | ||||
#include <sys/mount.h> | #include <sys/mount.h> | ||||
#include <sys/vnode.h> | #include <sys/vnode.h> | ||||
#else | |||||
#include <stdio.h> | |||||
#include <strings.h> | |||||
#include <string.h> | |||||
#include "ffs/buf.h" | |||||
#include "msdos/msdosfs_extern.h" | |||||
#endif | |||||
#include <fs/msdosfs/bpb.h> | #include <fs/msdosfs/bpb.h> | ||||
#include <fs/msdosfs/direntry.h> | #include <fs/msdosfs/direntry.h> | ||||
#include <fs/msdosfs/denode.h> | #include <fs/msdosfs/denode.h> | ||||
#include <fs/msdosfs/fat.h> | #include <fs/msdosfs/fat.h> | ||||
#include <fs/msdosfs/msdosfsmount.h> | #include <fs/msdosfs/msdosfsmount.h> | ||||
#define FULL_RUN ((u_int)0xffffffff) | #define FULL_RUN ((u_int)0xffffffff) | ||||
#ifndef MAKEFS | |||||
#define SYNCHRONOUS_WRITES(pmp) (pmp->pm_mountp->mnt_flag & MNT_SYNCHRONOUS) | |||||
#else | |||||
#define SYNCHRONOUS_WRITES(pmp) 1 | |||||
#endif | |||||
static int chainalloc(struct msdosfsmount *pmp, u_long start, | static int chainalloc(struct msdosfsmount *pmp, u_long start, | ||||
u_long count, u_long fillwith, u_long *retcluster, | u_long count, u_long fillwith, u_long *retcluster, | ||||
u_long *got); | u_long *got); | ||||
static int chainlength(struct msdosfsmount *pmp, u_long start, | static int chainlength(struct msdosfsmount *pmp, u_long start, | ||||
u_long count); | u_long count); | ||||
static void fatblock(struct msdosfsmount *pmp, u_long ofs, u_long *bnp, | static void fatblock(struct msdosfsmount *pmp, u_long ofs, u_long *bnp, | ||||
u_long *sizep, u_long *bop); | u_long *sizep, u_long *bop); | ||||
▲ Show 20 Lines • Show All 264 Lines • ▼ Show 20 Lines | for (i = 1; i < pmp->pm_FATs; i++) { | ||||
bpn = getblk(pmp->pm_devvp, fatbn, bp->b_bcount, | bpn = getblk(pmp->pm_devvp, fatbn, bp->b_bcount, | ||||
0, 0, 0); | 0, 0, 0); | ||||
memcpy(bpn->b_data, bp->b_data, bp->b_bcount); | memcpy(bpn->b_data, bp->b_data, bp->b_bcount); | ||||
/* Force the clean bit on in the other copies. */ | /* Force the clean bit on in the other copies. */ | ||||
if (cleanfat == 16) | if (cleanfat == 16) | ||||
((uint8_t *)bpn->b_data)[3] |= 0x80; | ((uint8_t *)bpn->b_data)[3] |= 0x80; | ||||
else if (cleanfat == 32) | else if (cleanfat == 32) | ||||
((uint8_t *)bpn->b_data)[7] |= 0x08; | ((uint8_t *)bpn->b_data)[7] |= 0x08; | ||||
if (pmp->pm_mountp->mnt_flag & MNT_SYNCHRONOUS) | if (SYNCHRONOUS_WRITES(pmp)) | ||||
bwrite(bpn); | bwrite(bpn); | ||||
else | else | ||||
bdwrite(bpn); | bdwrite(bpn); | ||||
} | } | ||||
} | } | ||||
/* | /* | ||||
* Write out the first (or current) FAT last. | * Write out the first (or current) FAT last. | ||||
*/ | */ | ||||
if (pmp->pm_mountp->mnt_flag & MNT_SYNCHRONOUS) | if (SYNCHRONOUS_WRITES(pmp)) | ||||
bwrite(bp); | bwrite(bp); | ||||
else | else | ||||
bdwrite(bp); | bdwrite(bp); | ||||
} | } | ||||
/* | /* | ||||
* Updating entries in 12 bit FATs is a pain in the butt. | * Updating entries in 12 bit FATs is a pain in the butt. | ||||
* | * | ||||
▲ Show 20 Lines • Show All 599 Lines • ▼ Show 20 Lines | |||||
extendfile(struct denode *dep, u_long count, struct buf **bpp, u_long *ncp, | extendfile(struct denode *dep, u_long count, struct buf **bpp, u_long *ncp, | ||||
int flags) | int flags) | ||||
{ | { | ||||
int error; | int error; | ||||
u_long frcn; | u_long frcn; | ||||
u_long cn, got; | u_long cn, got; | ||||
struct msdosfsmount *pmp = dep->de_pmp; | struct msdosfsmount *pmp = dep->de_pmp; | ||||
struct buf *bp; | struct buf *bp; | ||||
daddr_t blkno; | |||||
/* | /* | ||||
* Don't try to extend the root directory | * Don't try to extend the root directory | ||||
*/ | */ | ||||
if (dep->de_StartCluster == MSDOSFSROOT | if (dep->de_StartCluster == MSDOSFSROOT | ||||
&& (dep->de_Attributes & ATTR_DIRECTORY)) { | && (dep->de_Attributes & ATTR_DIRECTORY)) { | ||||
#ifdef MSDOSFS_DEBUG | #ifdef MSDOSFS_DEBUG | ||||
printf("extendfile(): attempt to extend root directory\n"); | printf("extendfile(): attempt to extend root directory\n"); | ||||
▲ Show 20 Lines • Show All 63 Lines • ▼ Show 20 Lines | while (count > 0) { | ||||
} | } | ||||
/* | /* | ||||
* Update the "last cluster of the file" entry in the | * Update the "last cluster of the file" entry in the | ||||
* denode's FAT cache. | * denode's FAT cache. | ||||
*/ | */ | ||||
fc_setcache(dep, FC_LASTFC, frcn + got - 1, cn + got - 1); | fc_setcache(dep, FC_LASTFC, frcn + got - 1, cn + got - 1); | ||||
#ifndef MAKEFS | |||||
daddr_t blkno; | |||||
if (flags & DE_CLEAR) { | if (flags & DE_CLEAR) { | ||||
while (got-- > 0) { | while (got-- > 0) { | ||||
/* | /* | ||||
* Get the buf header for the new block of the file. | * Get the buf header for the new block of the file. | ||||
*/ | */ | ||||
if (dep->de_Attributes & ATTR_DIRECTORY) | if (dep->de_Attributes & ATTR_DIRECTORY) | ||||
bp = getblk(pmp->pm_devvp, | bp = getblk(pmp->pm_devvp, | ||||
cntobn(pmp, cn++), | cntobn(pmp, cn++), | ||||
Show All 17 Lines | if (flags & DE_CLEAR) { | ||||
vfs_bio_clrbuf(bp); | vfs_bio_clrbuf(bp); | ||||
if (bpp) { | if (bpp) { | ||||
*bpp = bp; | *bpp = bp; | ||||
bpp = NULL; | bpp = NULL; | ||||
} else | } else | ||||
bdwrite(bp); | bdwrite(bp); | ||||
} | } | ||||
} | } | ||||
#else | |||||
if ((flags & DE_CLEAR) && | |||||
(dep->de_Attributes & ATTR_DIRECTORY)) { | |||||
while (got-- > 0) { | |||||
bp = getblk(pmp->pm_devvp, | |||||
cntobn(pmp, cn++), | |||||
pmp->pm_bpcluster, 0, 0, 0); | |||||
clrbuf(bp); | |||||
if (bpp) { | |||||
*bpp = bp; | |||||
bpp = NULL; | |||||
} else { | |||||
bdwrite(bp); | |||||
} | |||||
} | |||||
} | |||||
#endif | |||||
emaste: What's the explanation for this one? AFAICT OpenBSD's kernel msdosfs_fat.c matches our existing… | |||||
Not Done Inline ActionsOpenBSD actually created usr.sbin/makefs/msdos/msdosfs_fat.c to override the functionality of their kernel implementation. This new file uses the same code as the newly added #else ... #endif code from the snippet above. The reason I made this change is in the following: bp = getblk(DETOV(dep), frcn++, pmp->pm_bpcluster, 0, 0, 0); DETOV(dep) will always be NULL in makefs. However, I'm not sure if the way to go is to create a new msdosfs_fat.c in makefs like OpenBSD did or to keep it the way it is now. What do you think? smahadevan_freebsdfoundation.org: OpenBSD actually created `usr.sbin/makefs/msdos/msdosfs_fat.c` to override the functionality of… | |||||
} | } | ||||
return (0); | return (0); | ||||
} | } | ||||
/*- | /*- | ||||
* Routine to mark a FAT16 or FAT32 volume as "clean" or "dirty" by | * Routine to mark a FAT16 or FAT32 volume as "clean" or "dirty" by | ||||
* manipulating the upper bit of the FAT entry for cluster 1. Note that | * manipulating the upper bit of the FAT entry for cluster 1. Note that | ||||
▲ Show 20 Lines • Show All 73 Lines • Show Last 20 Lines |
What's the explanation for this one? AFAICT OpenBSD's kernel msdosfs_fat.c matches our existing (!MAKEFS) case, while the newly added #else here matches NetBSD's current kernel implementation.