Fix our NTFS readdir function.

To check a directory's in-use bitmap bit by bit, we use
a pointer to an 8 bit wide unsigned value.

The index used to dereference this pointer is calculated
by shifting the bit index right 3 bits.  Then we do a
logical AND with the bit# represented by the lower 3
bits of the bit index.

This is an idiomatic way of iterating through a bit map
with simple bitwise operations.

This commit fixes the bug that we only checked bits
3:0 of each 8 bit chunk, because we only used bits 1:0
of the bit index for the bit# in the current 8 bit value.
This resulted in files not being returned by getdirentries(2).

Change the type of the bit map pointer from `char *' to
`u_int8_t *'.
This commit is contained in:
Robert Drehmel 2005-05-06 00:06:06 +00:00
parent c4c9b52b87
commit e7aabf96a4

View File

@ -1125,7 +1125,7 @@ ntfs_ntreaddir(
struct ntvattr *bmvap = NULL; /* BitMap attribute */
struct ntvattr *iavap = NULL; /* IndexAllocation attribute */
caddr_t rdbuf; /* Buffer to read directory's blocks */
u_char *bmp = NULL; /* Bitmap */
u_int8_t *bmp = NULL; /* Bitmap */
u_int32_t blsize; /* Index allocation size (2048) */
u_int32_t rdsize; /* Length of data to read */
u_int32_t attrnum; /* Current attribute type */
@ -1162,7 +1162,7 @@ ntfs_ntreaddir(
error = ENOTDIR;
goto fail;
}
MALLOC(bmp, u_char *, bmvap->va_datalen, M_TEMP, M_WAITOK);
MALLOC(bmp, u_int8_t *, bmvap->va_datalen, M_TEMP, M_WAITOK);
error = ntfs_readattr(ntmp, ip, NTFS_A_INDXBITMAP, "$I30", 0,
bmvap->va_datalen, bmp, NULL);
if (error)
@ -1244,7 +1244,7 @@ ntfs_ntreaddir(
blnum++;
while (ntfs_cntob(blnum * cpbl) < iavap->va_datalen) {
if (bmp[blnum >> 3] & (1 << (blnum & 3)))
if (bmp[blnum >> 3] & (1 << (blnum & 7)))
break;
blnum++;
}