* The code in fs_walk() duplicates the one in ISOReadDir() mostly, and suffered

from the same "associated file" problem as the latter. This now finally fixes
  bug #3861. This badly needs some cleanup.
* Fixed a possible problem I introduced in ISOReadDir() (did not read the next
  block even if it should have).
* Fixed warnings with debug output turned on.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@30663 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2009-05-07 21:38:56 +00:00
parent c6278c8f49
commit 99d1bfb5de
2 changed files with 63 additions and 55 deletions
@@ -694,37 +694,40 @@ status_t
ISOReadDirEnt(iso9660_volume *volume, dircookie *cookie, struct dirent *dirent, ISOReadDirEnt(iso9660_volume *volume, dircookie *cookie, struct dirent *dirent,
size_t bufferSize) size_t bufferSize)
{ {
off_t totalRead = cookie->pos + (cookie->block - cookie->startBlock)
* volume->logicalBlkSize[FS_DATA_FORMAT];
off_t cacheBlock;
char *blockData;
int result = B_NO_ERROR; int result = B_NO_ERROR;
size_t bytesRead = 0; bool done = false;
TRACE(("ISOReadDirEnt - ENTER\n")); TRACE(("ISOReadDirEnt - ENTER\n"));
// If we're at the end of the data in a block, move to the next block. while (!done) {
while (true) { off_t totalRead = cookie->pos + (cookie->block - cookie->startBlock)
blockData = (char*)block_cache_get(volume->fBlockCache, cookie->block); * volume->logicalBlkSize[FS_DATA_FORMAT];
if (blockData != NULL && *(blockData + cookie->pos) == 0) {
// NULL data, move to next block.
block_cache_put(volume->fBlockCache, cookie->block);
blockData = NULL;
totalRead += volume->logicalBlkSize[FS_DATA_FORMAT] - cookie->pos;
cookie->pos = 0;
cookie->block++;
} else
break;
if (totalRead >= cookie->totalSize) // If we're at the end of the data in a block, move to the next block.
break; char *blockData;
} while (true) {
blockData
= (char*)block_cache_get(volume->fBlockCache, cookie->block);
if (blockData != NULL && *(blockData + cookie->pos) == 0) {
// NULL data, move to next block.
block_cache_put(volume->fBlockCache, cookie->block);
blockData = NULL;
totalRead
+= volume->logicalBlkSize[FS_DATA_FORMAT] - cookie->pos;
cookie->pos = 0;
cookie->block++;
} else
break;
cacheBlock = cookie->block; if (totalRead >= cookie->totalSize)
if (blockData != NULL && totalRead < cookie->totalSize) { break;
bool done = false; }
while (!done) {
off_t cacheBlock = cookie->block;
if (blockData != NULL && totalRead < cookie->totalSize) {
iso9660_inode node; iso9660_inode node;
size_t bytesRead = 0;
result = InitNode(&node, blockData + cookie->pos, &bytesRead, result = InitNode(&node, blockData + cookie->pos, &bytesRead,
volume->joliet_level); volume->joliet_level);
if (result != B_OK) if (result != B_OK)
@@ -741,14 +744,14 @@ ISOReadDirEnt(iso9660_volume *volume, dircookie *cookie, struct dirent *dirent,
if (node.name_length <= nameBufferSize) { if (node.name_length <= nameBufferSize) {
// need to do some size checking here. // need to do some size checking here.
strlcpy(dirent->d_name, node.name, node.name_length + 1); strlcpy(dirent->d_name, node.name, node.name_length + 1);
TRACE(("ISOReadDirEnt - success, name is %s, block %Ld, pos " TRACE(("ISOReadDirEnt - success, name is %s, block %Ld, "
"%Ld, inode id %Ld\n", dirent->d_name, cookie->block, "pos %Ld, inode id %Ld\n", dirent->d_name, cookie->block,
cookie->pos, dirent->d_ino)); cookie->pos, dirent->d_ino));
} else { } else {
// TODO: this can be just normal if we support reading more // TODO: this can be just normal if we support reading more
// than one entry. // than one entry.
TRACE(("ISOReadDirEnt - ERROR, name %s does not fit in buffer " TRACE(("ISOReadDirEnt - ERROR, name %s does not fit in "
"of size %lu\n", node.name, nameBufferSize)); "buffer of size %d\n", node.name, (int)nameBufferSize));
result = B_BAD_VALUE; result = B_BAD_VALUE;
} }
@@ -761,19 +764,21 @@ ISOReadDirEnt(iso9660_volume *volume, dircookie *cookie, struct dirent *dirent,
cookie->pos = 0; cookie->pos = 0;
cookie->block++; cookie->block++;
} }
} else {
if (totalRead >= cookie->totalSize)
result = B_ENTRY_NOT_FOUND;
else
result = B_NO_MEMORY;
done = true;
} }
} else {
if (totalRead >= cookie->totalSize)
result = B_ENTRY_NOT_FOUND;
else
result = B_NO_MEMORY;
}
if (blockData != NULL) if (blockData != NULL)
block_cache_put(volume->fBlockCache, cacheBlock); block_cache_put(volume->fBlockCache, cacheBlock);
}
TRACE(("ISOReadDirEnt - EXIT, result is %s, vnid is %Lu\n", TRACE(("ISOReadDirEnt - EXIT, result is %s, vnid is %Lu\n",
strerror(result), dirent->d_ino)); strerror(result), dirent->d_ino));
return result; return result;
} }
@@ -801,19 +806,21 @@ InitNode(iso9660_inode* node, char* buffer, size_t* _bytesRead,
memset(node->attr.stat, 0, sizeof(node->attr.stat)); memset(node->attr.stat, 0, sizeof(node->attr.stat));
node->extAttrRecLen = *(uint8*)buffer++; node->extAttrRecLen = *(uint8*)buffer++;
TRACE(("InitNode - ext attr length is %ld\n", node->extAttrRecLen)); TRACE(("InitNode - ext attr length is %d\n", (int)node->extAttrRecLen));
node->startLBN[LSB_DATA] = *(uint32*)buffer; node->startLBN[LSB_DATA] = *(uint32*)buffer;
buffer += 4; buffer += 4;
node->startLBN[MSB_DATA] = *(uint32*)buffer; node->startLBN[MSB_DATA] = *(uint32*)buffer;
buffer += 4; buffer += 4;
TRACE(("InitNode - data start LBN is %ld\n", node->startLBN[FS_DATA_FORMAT])); TRACE(("InitNode - data start LBN is %d\n",
(int)node->startLBN[FS_DATA_FORMAT]));
node->dataLen[LSB_DATA] = *(uint32*)buffer; node->dataLen[LSB_DATA] = *(uint32*)buffer;
buffer += 4; buffer += 4;
node->dataLen[MSB_DATA] = *(uint32*)buffer; node->dataLen[MSB_DATA] = *(uint32*)buffer;
buffer += 4; buffer += 4;
TRACE(("InitNode - data length is %ld\n", node->dataLen[FS_DATA_FORMAT])); TRACE(("InitNode - data length is %d\n",
(int)node->dataLen[FS_DATA_FORMAT]));
init_node_date(&node->recordDate, buffer); init_node_date(&node->recordDate, buffer);
buffer += 7; buffer += 7;
@@ -832,11 +839,11 @@ InitNode(iso9660_inode* node, char* buffer, size_t* _bytesRead,
node->volSeqNum = *(uint32*)buffer; node->volSeqNum = *(uint32*)buffer;
buffer += 4; buffer += 4;
TRACE(("InitNode - volume seq num is %ld\n", node->volSeqNum)); TRACE(("InitNode - volume seq num is %d\n", (int)node->volSeqNum));
node->name_length = *(uint8*)buffer; node->name_length = *(uint8*)buffer;
buffer++; buffer++;
TRACE(("InitNode - file id length is %lu\n", node->name_length)); TRACE(("InitNode - file id length is %u\n", node->name_length));
// Set defaults, in case there is no RockRidge stuff. // Set defaults, in case there is no RockRidge stuff.
node->attr.stat[FS_DATA_FORMAT].st_mode |= (node->flags & ISO_IS_DIR) != 0 node->attr.stat[FS_DATA_FORMAT].st_mode |= (node->flags & ISO_IS_DIR) != 0
@@ -221,8 +221,8 @@ fs_walk(fs_volume *_vol, fs_vnode *_base, const char *file, ino_t *_vnodeID)
iso9660_inode *baseNode = (iso9660_inode*)_base->private_node; iso9660_inode *baseNode = (iso9660_inode*)_base->private_node;
iso9660_inode *newNode = NULL; iso9660_inode *newNode = NULL;
TRACE(("fs_walk - looking for %s in dir file of length %ld\n", file, TRACE(("fs_walk - looking for %s in dir file of length %d\n", file,
baseNode->dataLen[FS_DATA_FORMAT])); (int)baseNode->dataLen[FS_DATA_FORMAT]));
if (strcmp(file, ".") == 0) { if (strcmp(file, ".") == 0) {
// base directory // base directory
@@ -266,12 +266,12 @@ fs_walk(fs_volume *_vol, fs_vnode *_base, const char *file, ino_t *_vnodeID)
&& !done) { && !done) {
initResult = InitNode(&node, blockData, &bytesRead, initResult = InitNode(&node, blockData, &bytesRead,
ns->joliet_level); ns->joliet_level);
TRACE(("fs_walk - InitNode returned %s, filename %s, %lu bytes " TRACE(("fs_walk - InitNode returned %s, filename %s, %u bytes "
"read\n", strerror(initResult), node.name, "read\n", strerror(initResult), node.name, (unsigned)bytesRead));
bytesRead));
if (initResult == B_OK) { if (initResult == B_OK) {
if (!strcmp(node.name, file)) { if ((node.flags & ISO_IS_ASSOCIATED_FILE) == 0
&& !strcmp(node.name, file)) {
TRACE(("fs_walk - success, found vnode at block %Ld, pos " TRACE(("fs_walk - success, found vnode at block %Ld, pos "
"%Ld\n", block, blockBytesRead)); "%Ld\n", block, blockBytesRead));
@@ -296,15 +296,15 @@ fs_walk(fs_volume *_vol, fs_vnode *_base, const char *file, ino_t *_vnodeID)
blockData += bytesRead; blockData += bytesRead;
blockBytesRead += bytesRead; blockBytesRead += bytesRead;
TRACE(("fs_walk - Adding %lu bytes to blockBytes read (total " TRACE(("fs_walk - Adding %u bytes to blockBytes read (total "
"%Ld/%lu).\n", bytesRead, blockBytesRead, "%Ld/%u).\n", (unsigned)bytesRead, blockBytesRead,
baseNode->dataLen[FS_DATA_FORMAT])); (unsigned)baseNode->dataLen[FS_DATA_FORMAT]));
} }
totalRead += ns->logicalBlkSize[FS_DATA_FORMAT]; totalRead += ns->logicalBlkSize[FS_DATA_FORMAT];
block++; block++;
TRACE(("fs_walk - moving to next block %Ld, total read %lu\n", TRACE(("fs_walk - moving to next block %Ld, total read %u\n",
block, totalRead)); block, (unsigned)totalRead));
block_cache_put(ns->fBlockCache, cachedBlock); block_cache_put(ns->fBlockCache, cachedBlock);
} }
@@ -327,8 +327,8 @@ fs_read_vnode(fs_volume *_vol, ino_t vnodeID, fs_vnode *_node,
uint32 pos = vnodeID & 0x3fffffff; uint32 pos = vnodeID & 0x3fffffff;
uint32 block = vnodeID >> 30; uint32 block = vnodeID >> 30;
TRACE(("fs_read_vnode - block = %ld, pos = %ld, raw = %Lu node %p\n", TRACE(("fs_read_vnode - block = %u, pos = %u, raw = %Lu node %p\n",
block, pos, vnodeID, newNode)); (unsigned)block, (unsigned) pos, vnodeID, newNode));
if (pos > ns->logicalBlkSize[FS_DATA_FORMAT]) { if (pos > ns->logicalBlkSize[FS_DATA_FORMAT]) {
free(newNode); free(newNode);
@@ -352,7 +352,8 @@ fs_read_vnode(fs_volume *_vol, ino_t vnodeID, fs_vnode *_node,
newNode->id = vnodeID; newNode->id = vnodeID;
_node->private_node = newNode; _node->private_node = newNode;
_node->ops = &gISO9660VnodeOps; _node->ops = &gISO9660VnodeOps;
*_type = newNode->attr.stat[FS_DATA_FORMAT].st_mode & ~(S_IWUSR | S_IWGRP | S_IWOTH); *_type = newNode->attr.stat[FS_DATA_FORMAT].st_mode
& ~(S_IWUSR | S_IWGRP | S_IWOTH);
*_flags = 0; *_flags = 0;
if ((newNode->flags & ISO_IS_DIR) == 0) { if ((newNode->flags & ISO_IS_DIR) == 0) {