Skip to content

Rewrite image cache so that all reads are block-aligned. #86

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Improved comments and platform independence of image cache.
  • Loading branch information
Judson Powers committed Aug 7, 2012
commit 13ab34e32105c1f593b2bf3087978526905eea72
2 changes: 2 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ AX_PTHREAD( [
CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
LDFLAGS="$LDFLAGS $PTHREAD_CFLAGS"
CC="$PTHREAD_CC"],[])
AC_CHECK_FUNCS(posix_memalign, [AC_DEFINE(HAVE_POSIX_MEMALIGN, 1, [Define to 1 if you have the posix_memalign() function.])])

# Not all compilers include /usr/local in the include and link path
if test -d /usr/local/include; then
CFLAGS="$CFLAGS -I/usr/local/include"
Expand Down
18 changes: 9 additions & 9 deletions tsk3/img/img_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@
#include "tsk_img_i.h"

/**
* \ingroup imglib
* \internal
* XXX
* @param a_img_info Disk image to read from
* @param ent XXX
* @returns XXX
*/
static int
cache_promote(TSK_IMG_INFO * a_img_info, int ent)
static inline int
tsk_cache_promote(TSK_IMG_INFO * a_img_info, int ent)
{
if (ent == 0)
return 0;
Expand All @@ -34,15 +34,15 @@ cache_promote(TSK_IMG_INFO * a_img_info, int ent)
}

/**
* \ingroup imglib
* \internal
* XXX
* @param a_img_info Disk image to read from
* @param a_off XXX
* @param a_entry XXX
* @returns 0 on error or 1 on success
*/
static int
get_cache_block(TSK_IMG_INFO * a_img_info,
static inline int
tsk_get_cache_block(TSK_IMG_INFO * a_img_info,
TSK_OFF_T a_off, struct TSK_IMG_INFO_CACHE_ENTRY ** a_entry)
{
// we require that we're called with a page-aligned offset
Expand All @@ -56,7 +56,7 @@ get_cache_block(TSK_IMG_INFO * a_img_info,
// find existing cache page
for (ent = 0; ent < a_img_info->cache_used; ent++) {
if (a_img_info->cache_info[ent].offset == a_off) {
ent = cache_promote(a_img_info, ent);
ent = tsk_cache_promote(a_img_info, ent);
*a_entry = &(a_img_info->cache_info[ent]);
return 1;
}
Expand Down Expand Up @@ -85,7 +85,7 @@ get_cache_block(TSK_IMG_INFO * a_img_info,
return 0;
}

ent = cache_promote(a_img_info, ent);
ent = tsk_cache_promote(a_img_info, ent);
*a_entry = &(a_img_info->cache_info[ent]);
return 1;
}
Expand Down Expand Up @@ -152,7 +152,7 @@ tsk_img_read(TSK_IMG_INFO * a_img_info, TSK_OFF_T a_off,

while (rlen > 0) {
// get the current block from cache (possibly reading from disk)
if (! get_cache_block(a_img_info, block_addr, & cache_entry)) {
if (! tsk_get_cache_block(a_img_info, block_addr, & cache_entry)) {
tsk_release_lock(&(a_img_info->cache_lock));
return len2 - rlen;
}
Expand Down
29 changes: 27 additions & 2 deletions tsk3/img/raw.c
Original file line number Diff line number Diff line change
Expand Up @@ -721,8 +721,33 @@ tsk_img_malloc(size_t a_len)
tsk_init_lock(&(imgInfo->cache_lock));
imgInfo->tag = TSK_IMG_INFO_TAG;

// alloc cache
imgInfo->cache = valloc(TSK_IMG_INFO_CACHE_NUM * TSK_IMG_INFO_CACHE_LEN);
long cachesz = TSK_IMG_INFO_CACHE_NUM * TSK_IMG_INFO_CACHE_LEN;

#ifdef TSK_WIN32
#else

// unistd.h

#ifdef _SC_PAGESIZE
long pagesz = sysconf(_SC_PAGESIZE);
#else
#ifdef _SC_PAGE_SIZE
long pagesz = sysconf(_SC_PAGE_SIZE);
#else
long pagesz = TSK_IMG_INFO_CACHE_LEN;
#endif
#endif // PAGESIZE

#ifdef HAVE_POSIX_MEMALIGN
int retval;
if ((retval = posix_memalign(&imgInfo->cache, pagesz, cachesz)) != 0) {
tsk_fprintf("tsk_img_malloc: unable to allocate cache (%d)\n", retval);
exit(-1); // XXX fix
}
#else // HAVE_POSIX_MEMALIGN
imgInfo->cache = malloc(TSK_IMG_INFO_CACHE_NUM * TSK_IMG_INFO_CACHE_LEN);
#endif // HAVE_POSIX_MEMALIGN
#endif

return (void *) imgInfo;
}
Expand Down
2 changes: 1 addition & 1 deletion tsk3/img/tsk_img.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ extern "C" {
TSK_IMG_TYPE_UNSUPP = 0xffff, ///< Unsupported disk image type
} TSK_IMG_TYPE_ENUM;

#define TSK_IMG_INFO_CACHE_NUM 256
#define TSK_IMG_INFO_CACHE_NUM 32
#define TSK_IMG_INFO_CACHE_LEN 32768

typedef struct TSK_IMG_INFO TSK_IMG_INFO;
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy