From 99d1bfb5de8e2ca3ff2b245a050c09366cca5374 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Thu, 7 May 2009 21:38:56 +0000 Subject: [PATCH] * 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 --- .../kernel/file_systems/iso9660/iso9660.cpp | 89 ++++++++++--------- .../file_systems/iso9660/kernel_interface.cpp | 29 +++--- 2 files changed, 63 insertions(+), 55 deletions(-) diff --git a/src/add-ons/kernel/file_systems/iso9660/iso9660.cpp b/src/add-ons/kernel/file_systems/iso9660/iso9660.cpp index 6084ab01e7..d9f33044c9 100644 --- a/src/add-ons/kernel/file_systems/iso9660/iso9660.cpp +++ b/src/add-ons/kernel/file_systems/iso9660/iso9660.cpp @@ -694,37 +694,40 @@ status_t ISOReadDirEnt(iso9660_volume *volume, dircookie *cookie, struct dirent *dirent, 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; - size_t bytesRead = 0; + bool done = false; TRACE(("ISOReadDirEnt - ENTER\n")); - // If we're at the end of the data in a block, move to the next block. - 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; + while (!done) { + off_t totalRead = cookie->pos + (cookie->block - cookie->startBlock) + * volume->logicalBlkSize[FS_DATA_FORMAT]; - if (totalRead >= cookie->totalSize) - break; - } + // If we're at the end of the data in a block, move to the next block. + 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 (blockData != NULL && totalRead < cookie->totalSize) { - bool done = false; - while (!done) { + if (totalRead >= cookie->totalSize) + break; + } + + off_t cacheBlock = cookie->block; + + if (blockData != NULL && totalRead < cookie->totalSize) { iso9660_inode node; + size_t bytesRead = 0; result = InitNode(&node, blockData + cookie->pos, &bytesRead, volume->joliet_level); if (result != B_OK) @@ -741,14 +744,14 @@ ISOReadDirEnt(iso9660_volume *volume, dircookie *cookie, struct dirent *dirent, if (node.name_length <= nameBufferSize) { // need to do some size checking here. strlcpy(dirent->d_name, node.name, node.name_length + 1); - TRACE(("ISOReadDirEnt - success, name is %s, block %Ld, pos " - "%Ld, inode id %Ld\n", dirent->d_name, cookie->block, + TRACE(("ISOReadDirEnt - success, name is %s, block %Ld, " + "pos %Ld, inode id %Ld\n", dirent->d_name, cookie->block, cookie->pos, dirent->d_ino)); } else { // TODO: this can be just normal if we support reading more // than one entry. - TRACE(("ISOReadDirEnt - ERROR, name %s does not fit in buffer " - "of size %lu\n", node.name, nameBufferSize)); + TRACE(("ISOReadDirEnt - ERROR, name %s does not fit in " + "buffer of size %d\n", node.name, (int)nameBufferSize)); result = B_BAD_VALUE; } @@ -761,19 +764,21 @@ ISOReadDirEnt(iso9660_volume *volume, dircookie *cookie, struct dirent *dirent, cookie->pos = 0; 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) - block_cache_put(volume->fBlockCache, cacheBlock); + if (blockData != NULL) + block_cache_put(volume->fBlockCache, cacheBlock); + } TRACE(("ISOReadDirEnt - EXIT, result is %s, vnid is %Lu\n", strerror(result), dirent->d_ino)); + return result; } @@ -801,19 +806,21 @@ InitNode(iso9660_inode* node, char* buffer, size_t* _bytesRead, memset(node->attr.stat, 0, sizeof(node->attr.stat)); 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; buffer += 4; node->startLBN[MSB_DATA] = *(uint32*)buffer; 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; buffer += 4; node->dataLen[MSB_DATA] = *(uint32*)buffer; 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); buffer += 7; @@ -832,11 +839,11 @@ InitNode(iso9660_inode* node, char* buffer, size_t* _bytesRead, node->volSeqNum = *(uint32*)buffer; 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; 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. node->attr.stat[FS_DATA_FORMAT].st_mode |= (node->flags & ISO_IS_DIR) != 0 diff --git a/src/add-ons/kernel/file_systems/iso9660/kernel_interface.cpp b/src/add-ons/kernel/file_systems/iso9660/kernel_interface.cpp index d0b0492937..2c9915406e 100644 --- a/src/add-ons/kernel/file_systems/iso9660/kernel_interface.cpp +++ b/src/add-ons/kernel/file_systems/iso9660/kernel_interface.cpp @@ -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 *newNode = NULL; - TRACE(("fs_walk - looking for %s in dir file of length %ld\n", file, - baseNode->dataLen[FS_DATA_FORMAT])); + TRACE(("fs_walk - looking for %s in dir file of length %d\n", file, + (int)baseNode->dataLen[FS_DATA_FORMAT])); if (strcmp(file, ".") == 0) { // base directory @@ -266,12 +266,12 @@ fs_walk(fs_volume *_vol, fs_vnode *_base, const char *file, ino_t *_vnodeID) && !done) { initResult = InitNode(&node, blockData, &bytesRead, ns->joliet_level); - TRACE(("fs_walk - InitNode returned %s, filename %s, %lu bytes " - "read\n", strerror(initResult), node.name, - bytesRead)); + TRACE(("fs_walk - InitNode returned %s, filename %s, %u bytes " + "read\n", strerror(initResult), node.name, (unsigned)bytesRead)); 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 " "%Ld\n", block, blockBytesRead)); @@ -296,15 +296,15 @@ fs_walk(fs_volume *_vol, fs_vnode *_base, const char *file, ino_t *_vnodeID) blockData += bytesRead; blockBytesRead += bytesRead; - TRACE(("fs_walk - Adding %lu bytes to blockBytes read (total " - "%Ld/%lu).\n", bytesRead, blockBytesRead, - baseNode->dataLen[FS_DATA_FORMAT])); + TRACE(("fs_walk - Adding %u bytes to blockBytes read (total " + "%Ld/%u).\n", (unsigned)bytesRead, blockBytesRead, + (unsigned)baseNode->dataLen[FS_DATA_FORMAT])); } totalRead += ns->logicalBlkSize[FS_DATA_FORMAT]; block++; - TRACE(("fs_walk - moving to next block %Ld, total read %lu\n", - block, totalRead)); + TRACE(("fs_walk - moving to next block %Ld, total read %u\n", + block, (unsigned)totalRead)); 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 block = vnodeID >> 30; - TRACE(("fs_read_vnode - block = %ld, pos = %ld, raw = %Lu node %p\n", - block, pos, vnodeID, newNode)); + TRACE(("fs_read_vnode - block = %u, pos = %u, raw = %Lu node %p\n", + (unsigned)block, (unsigned) pos, vnodeID, newNode)); if (pos > ns->logicalBlkSize[FS_DATA_FORMAT]) { free(newNode); @@ -352,7 +352,8 @@ fs_read_vnode(fs_volume *_vol, ino_t vnodeID, fs_vnode *_node, newNode->id = vnodeID; _node->private_node = newNode; _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; if ((newNode->flags & ISO_IS_DIR) == 0) {