Skip to content

Commit

Permalink
xnu-201.42.3
Browse files Browse the repository at this point in the history
  • Loading branch information
Darwin authored and das committed Jun 4, 2017
1 parent 2359fe3 commit e82021f
Show file tree
Hide file tree
Showing 59 changed files with 1,318 additions and 675 deletions.
2 changes: 1 addition & 1 deletion bsd/conf/version.minor
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4
5
1 change: 1 addition & 0 deletions bsd/conf/version.variant
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

220 changes: 0 additions & 220 deletions bsd/hfs/MacOSStubs.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@
#include <sys/types.h>
#include <sys/ubc.h>
#include <sys/vm.h>
#include <dev/disk.h>
#include "hfs.h"
#include "hfs_dbg.h"

Expand All @@ -75,225 +74,6 @@ extern int (**hfs_vnodeop_p)(void *);
struct timezone gTimeZone = {8*60,1};


/*************************************************************************************/

/*************************************************************************************/
/*
* The following two routines work in tandem: StoreBufferMapping stores
* successive buffer address -> buffer pointer mappings in a circular
* match list, advancing the list index forward each time, while LookupBufferMapping
* looks backwards through the list to look up a particular mapping (which is
* typically the entry currently pointed to by gBufferAddress).
*
*/
static void StoreBufferMapping(caddr_t bufferAddress, struct buf *bp)
{
int i;

DBG_ASSERT(gBufferListIndex >= 0);
DBG_ASSERT(gBufferListIndex < BUFFERPTRLISTSIZE);

simple_lock(&gBufferPtrListLock);

/* We've got at most BUFFERPTRLISTSIZE tries at this... */
for (i = BUFFERPTRLISTSIZE; i > 0; --i) {
if (gBufferAddress[gBufferListIndex] == NULL) {
gBufferAddress[gBufferListIndex] = bufferAddress;
gBufferHeaderPtr[gBufferListIndex] = bp;
break;
}
gBufferListIndex = (gBufferListIndex + 1) % BUFFERPTRLISTSIZE;
};

if (i == 0) {
panic("StoreBufferMapping: couldn't find an empty slot in buffer list.");
};

DBG_ASSERT(gBufferListIndex >= 0);
DBG_ASSERT(gBufferListIndex < BUFFERPTRLISTSIZE);

simple_unlock(&gBufferPtrListLock);
}


/*static*/ OSErr LookupBufferMapping(caddr_t bufferAddress, struct buf **bpp, int *mappingIndexPtr)
{
OSErr err = E_NONE;
int i;
int listIndex = gBufferListIndex;
struct buf *bp = NULL;

DBG_ASSERT(gBufferListIndex >= 0);
DBG_ASSERT(gBufferListIndex < BUFFERPTRLISTSIZE);

simple_lock(&gBufferPtrListLock);

/* We've got at most BUFFERPTRLISTSIZE tries at this... */
for (i = BUFFERPTRLISTSIZE; i > 0; --i) {
if (gBufferAddress[listIndex] == bufferAddress) {
*mappingIndexPtr = listIndex;
bp = gBufferHeaderPtr[listIndex];
break;
};

listIndex = (listIndex - 1);
if (listIndex < 0) {
listIndex = BUFFERPTRLISTSIZE - 1;
};
};

if (bp == NULL) {
DEBUG_BREAK_MSG(("LookupBufferMapping: couldn't find buffer header for buffer in list.\n"));
err = -1;
};

DBG_ASSERT(gBufferListIndex >= 0);
DBG_ASSERT(gBufferListIndex < BUFFERPTRLISTSIZE);

simple_unlock(&gBufferPtrListLock);

*bpp = bp;
return err;
}


static void ReleaseMappingEntry(int entryIndex) {

DBG_ASSERT(gBufferListIndex >= 0);
DBG_ASSERT(gBufferListIndex < BUFFERPTRLISTSIZE);

simple_lock(&gBufferPtrListLock);
gBufferAddress[entryIndex] = NULL;
simple_unlock(&gBufferPtrListLock);
};
#if HFS_DIAGNOSTIC
#define DBG_GETBLOCK 0
#else
#define DBG_GETBLOCK 0
#endif

OSErr GetBlock_glue (UInt16 options, UInt32 blockNum, Ptr *baddress, FileReference fileRefNum, ExtendedVCB * vcb)
{
int status;
struct buf *bp = NULL;
int readcount = 0;

#if DBG_GETBLOCK
DBG_IO(("Getting block %ld with options %d and a refnum of %x\n", blockNum, options, fileRefNum ));
#endif

if ((options & ~(gbReadMask | gbNoReadMask)) != 0) {
DEBUG_BREAK_MSG(("GetBlock_glue: options = 0x%04X.\n", options));
};

*baddress = NULL;

if (options & gbNoReadMask) {
if (fileRefNum == NULL) {
bp = getblk (VCBTOHFS(vcb)->hfs_devvp,
IOBLKNOFORBLK(blockNum, VCBTOHFS(vcb)->hfs_phys_block_size),
IOBYTECCNTFORBLK(blockNum, kHFSBlockSize, VCBTOHFS(vcb)->hfs_phys_block_size),
0,
0,
BLK_META);
} else {
bp = getblk (fileRefNum,
IOBLKNOFORBLK(blockNum, VCBTOHFS(vcb)->hfs_phys_block_size),
IOBYTECCNTFORBLK(blockNum, kHFSBlockSize, VCBTOHFS(vcb)->hfs_phys_block_size),
0,
0,
BLK_META);
};
status = E_NONE;
} else {
do {
if (fileRefNum == NULL) {
status = meta_bread (VCBTOHFS(vcb)->hfs_devvp,
IOBLKNOFORBLK(blockNum, VCBTOHFS(vcb)->hfs_phys_block_size),
IOBYTECCNTFORBLK(blockNum, kHFSBlockSize, VCBTOHFS(vcb)->hfs_phys_block_size),
NOCRED,
&bp);
} else {
status = meta_bread (fileRefNum,
IOBLKNOFORBLK(blockNum, VCBTOHFS(vcb)->hfs_phys_block_size),
IOBYTECCNTFORBLK(blockNum, kHFSBlockSize, VCBTOHFS(vcb)->hfs_phys_block_size),
NOCRED,
&bp);
};
if (status != E_NONE) {
if (bp) brelse(bp);
goto Error_Exit;
};

if (bp == NULL) {
status = -1;
goto Error_Exit;
};

++readcount;

if ((options & gbReadMask) && (bp->b_flags & B_CACHE)) {
/* Rats! The block was found in the cache just when we really wanted a
fresh copy off disk...
*/
if (bp->b_flags & B_DIRTY) {
DEBUG_BREAK_MSG(("GetBlock_glue: forced read for dirty block!\n"))
};
bp->b_flags |= B_INVAL;
brelse(bp);

/* Fall through and try again until we get a fresh copy from the disk... */
};
} while (((options & gbReadMask) != 0) && (readcount <= 1));
};

*baddress = bp->b_data + IOBYTEOFFSETFORBLK(bp->b_blkno, VCBTOHFS(vcb)->hfs_phys_block_size);
StoreBufferMapping(*baddress, bp);

Error_Exit: ;
return status;
}


OSErr RelBlock_glue (Ptr address, UInt16 options )
{
int err;
struct buf *bp;
int mappingEntry;

if (options & ~(rbTrashMask | rbDirtyMask | rbWriteMask) == 0) {
DEBUG_BREAK_MSG(("RelBlock_glue: options = 0x%04X.\n", options));
};

if ((err = LookupBufferMapping(address, &bp, &mappingEntry))) {
DEBUG_BREAK_MSG(("Failed to find buffer pointer for buffer in RelBlock_glue.\n"));
} else {
if (bp->b_flags & B_DIRTY) {
/* The buffer was previously marked dirty (using MarkBlock_glue):
now's the time to write it. */
options |= rbDirtyMask;
};
ReleaseMappingEntry(mappingEntry);
if (options & rbTrashMask) {
bp->b_flags |= B_INVAL;
brelse(bp);
} else {
if (options & (rbDirtyMask | rbWriteMask)) {
bp->b_flags |= B_DIRTY;
if (options & rbWriteMask) {
bwrite(bp);
} else {
bdwrite(bp);
}
} else {
brelse(bp);
};
};
err = E_NONE;
};
return err;
}

/* */
/* Creates a new vnode to hold a psuedo file like an extents tree file */
/* */
Expand Down
12 changes: 9 additions & 3 deletions bsd/hfs/hfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -656,7 +656,6 @@ struct hfsfid {

#define E_NONE 0
#define kHFSBlockSize 512
#define kHFSBlockShift 9 /* 2^9 = 512 */

#define IOBLKNOFORBLK(STARTINGBLOCK, BLOCKSIZEINBYTES) ((daddr_t)((STARTINGBLOCK) / ((BLOCKSIZEINBYTES) >> 9)))
#define IOBLKCNTFORBLK(STARTINGBLOCK, BYTESTOTRANSFER, BLOCKSIZEINBYTES) \
Expand All @@ -676,6 +675,13 @@ struct hfsfid {
(IOBLKCNTFORBYTE((STARTINGBYTE),(BYTESTOTRANSFER),(BLOCKSIZEINBYTES)) * (BLOCKSIZEINBYTES))
#define IOBYTEOFFSETFORBYTE(STARTINGBYTE, BLOCKSIZEINBYTES) ((STARTINGBYTE) - (IOBLKNOFORBYTE((STARTINGBYTE), (BLOCKSIZEINBYTES)) * (BLOCKSIZEINBYTES)))


#define HFS_PRI_SECTOR(blksize) (1024 / (blksize))
#define HFS_PRI_OFFSET(blksize) ((blksize) > 1024 ? 1024 : 0)

#define HFS_ALT_SECTOR(blksize, blkcnt) (((blkcnt) - 1) - (512 / (blksize)))
#define HFS_ALT_OFFSET(blksize) ((blksize) > 1024 ? (blksize) - 1024 : 0)

#define MAKE_VREFNUM(x) ((int32_t)((x) & 0xffff))
/*
* This is the straight GMT conversion constant:
Expand Down Expand Up @@ -766,9 +772,9 @@ unsigned long BestBlockSizeFit(unsigned long allocationBlockSize,
unsigned long baseMultiple);

OSErr hfs_MountHFSVolume(struct hfsmount *hfsmp, HFSMasterDirectoryBlock *mdb,
u_long sectors, struct proc *p);
struct proc *p);
OSErr hfs_MountHFSPlusVolume(struct hfsmount *hfsmp, HFSPlusVolumeHeader *vhp,
u_long embBlkOffset, u_long sectors, struct proc *p);
off_t embeddedOffset, off_t disksize, struct proc *p);
OSStatus GetInitializedVNode(struct hfsmount *hfsmp, struct vnode **tmpvnode);

int hfs_getconverter(u_int32_t encoding, hfs_to_unicode_func_t *get_unicode,
Expand Down
60 changes: 33 additions & 27 deletions bsd/hfs/hfs_btreeio.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,18 +84,9 @@ OSStatus GetBTreeBlock(FileReference vp, UInt32 blockNum, GetBlockOptions option
struct buf *bp = NULL;

if (options & kGetEmptyBlock)
bp = getblk (vp,
IOBLKNOFORBLK(blockNum, VTOHFS(vp)->hfs_phys_block_size),
IOBYTECCNTFORBLK(blockNum, block->blockSize, VTOHFS(vp)->hfs_phys_block_size),
0,
0,
BLK_META);
bp = getblk(vp, blockNum, block->blockSize, 0, 0, BLK_META);
else
retval = meta_bread(vp,
IOBLKNOFORBLK(blockNum, VTOHFS(vp)->hfs_phys_block_size),
IOBYTECCNTFORBLK(blockNum, block->blockSize, VTOHFS(vp)->hfs_phys_block_size),
NOCRED,
&bp);
retval = meta_bread(vp, blockNum, block->blockSize, NOCRED, &bp);

DBG_ASSERT(bp != NULL);
DBG_ASSERT(bp->b_data != NULL);
Expand All @@ -107,7 +98,7 @@ OSStatus GetBTreeBlock(FileReference vp, UInt32 blockNum, GetBlockOptions option

if (retval == E_NONE) {
block->blockHeader = bp;
block->buffer = bp->b_data + IOBYTEOFFSETFORBLK(bp->b_blkno, VTOHFS(vp)->hfs_phys_block_size);
block->buffer = bp->b_data;
block->blockReadFromDisk = (bp->b_flags & B_CACHE) == 0; /* not found in cache ==> came from disk */

#if BYTE_ORDER == LITTLE_ENDIAN
Expand Down Expand Up @@ -298,27 +289,42 @@ OSStatus ExtendBTreeFile(FileReference vp, FSSize minEOF, FSSize maxEOF)
static OSStatus
FlushAlternate( ExtendedVCB *vcb )
{
void *maindata;
void *altdata;
struct hfsmount *hfsmp = VCBTOHFS(vcb);
struct vnode *dev_vp = hfsmp->hfs_devvp;
struct buf *pri_bp = NULL;
struct buf *alt_bp = NULL;
int sectorsize;
u_long priIDSector;
u_long altIDSector;
int result;

sectorsize = hfsmp->hfs_phys_block_size;
priIDSector = (vcb->hfsPlusIOPosOffset / sectorsize) +
HFS_PRI_SECTOR(sectorsize);

altIDSector = (vcb->hfsPlusIOPosOffset / sectorsize) +
HFS_ALT_SECTOR(sectorsize, hfsmp->hfs_phys_block_count);

/* Get the main MDB/VolumeHeader block */
result = GetBlock_glue(gbDefault,
(vcb->hfsPlusIOPosOffset / kHFSBlockSize) + kMasterDirectoryBlock,
(Ptr *)&maindata, kNoFileReference, vcb);
if (result) return (result);

/* Get the alternate MDB/VolumeHeader block */
result = GetBlock_glue( gbDefault, vcb->altIDSector,
(Ptr *)&altdata, kNoFileReference, vcb );
result = meta_bread(dev_vp, priIDSector, sectorsize, NOCRED, &pri_bp);
if (result)
goto exit;

if (result == 0) {
bcopy(maindata, altdata, kMDBSize);
/* Get the alternate MDB/VolumeHeader block */
result = meta_bread(dev_vp, altIDSector, sectorsize, NOCRED, &alt_bp);
if (result)
goto exit;

result = RelBlock_glue( (Ptr)altdata, rbWriteMask );
}
bcopy(pri_bp->b_data + HFS_PRI_OFFSET(sectorsize),
alt_bp->b_data + HFS_ALT_OFFSET(sectorsize), kMDBSize);

(void) RelBlock_glue( (Ptr)maindata, rbFreeMask );
result = VOP_BWRITE(alt_bp);
alt_bp = NULL;
exit:
if (alt_bp)
brelse(alt_bp);
if (pri_bp)
brelse(pri_bp);

return (result);
}
Expand Down
2 changes: 1 addition & 1 deletion bsd/hfs/hfs_readwrite.c
Original file line number Diff line number Diff line change
Expand Up @@ -2019,7 +2019,7 @@ struct vop_bwrite_args /* {
if (((UInt16 *)((char *)bp->b_data + bp->b_bcount - 2))[0] == 0x000e) {
/* Prepare the block pointer */
block.blockHeader = bp;
block.buffer = bp->b_data + IOBYTEOFFSETFORBLK(bp->b_blkno, VTOHFS(vp)->hfs_phys_block_size);
block.buffer = bp->b_data;
block.blockReadFromDisk = (bp->b_flags & B_CACHE) == 0; /* not found in cache ==> came from disk */
block.blockSize = bp->b_bcount;

Expand Down
Loading

0 comments on commit e82021f

Please sign in to comment.