From 5111a2a6e2ada88e3fbd23c6e575520837dd3d22 Mon Sep 17 00:00:00 2001 From: Brian Carrier <carrier@sleuthkit.org> Date: Sun, 12 Apr 2009 04:33:26 +0000 Subject: [PATCH] fixed issue 2662168 re: warning messages on macs when reading raw character device --- CHANGES.txt | 3 +++ tsk3/img/raw.c | 61 +++++++++++++++++++++++++++++--------------------- 2 files changed, 38 insertions(+), 26 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index 41909027b..77d1b2be6 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -68,6 +68,9 @@ of file system and not local system. Created new conversion function and changed a couple of other spots that had similar bug. Reported by Rob Joyce. +4/11/09: Bug Fix: Fixed issue 2662168 re: warning messages on macs +when reading the raw character device. patch by Rob Joyce. + ---------------- VERSION 3.0.0 -------------- 0/00/00: Update: Many, many, many API changes. diff --git a/tsk3/img/raw.c b/tsk3/img/raw.c index 3a362673b..515f1d005 100644 --- a/tsk3/img/raw.c +++ b/tsk3/img/raw.c @@ -210,30 +210,34 @@ raw_open(const TSK_TCHAR * image) "raw_open: Trying Windows device with share_write mode\n"); raw_info->fd = CreateFile(image, FILE_READ_DATA, - FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL); + FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, + OPEN_EXISTING, 0, NULL); } if (raw_info->fd == INVALID_HANDLE_VALUE) { tsk_error_reset(); tsk_errno = TSK_ERR_IMG_OPEN; // print string of commonly found errors - if (GetLastError() == ERROR_ACCESS_DENIED) { - snprintf(tsk_errstr, TSK_ERRSTR_L, - "raw_open file: %" PRIttocTSK " (Access Denied)", image); - } - else if (GetLastError() == ERROR_SHARING_VIOLATION) { - snprintf(tsk_errstr, TSK_ERRSTR_L, - "raw_open file: %" PRIttocTSK " (Sharing Violation)", image); - } + if (GetLastError() == ERROR_ACCESS_DENIED) { + snprintf(tsk_errstr, TSK_ERRSTR_L, + "raw_open file: %" PRIttocTSK " (Access Denied)", + image); + } + else if (GetLastError() == ERROR_SHARING_VIOLATION) { + snprintf(tsk_errstr, TSK_ERRSTR_L, + "raw_open file: %" PRIttocTSK + " (Sharing Violation)", image); + } else if (GetLastError() == ERROR_FILE_NOT_FOUND) { - snprintf(tsk_errstr, TSK_ERRSTR_L, - "raw_open file: %" PRIttocTSK " (File not found)", image); - } - else { - snprintf(tsk_errstr, TSK_ERRSTR_L, - "raw_open file: %" PRIttocTSK " (%d)", image, - (int)GetLastError()); - } + snprintf(tsk_errstr, TSK_ERRSTR_L, + "raw_open file: %" PRIttocTSK " (File not found)", + image); + } + else { + snprintf(tsk_errstr, TSK_ERRSTR_L, + "raw_open file: %" PRIttocTSK " (%d)", image, + (int) GetLastError()); + } return NULL; } } @@ -248,7 +252,7 @@ raw_open(const TSK_TCHAR * image) tsk_errno = TSK_ERR_IMG_OPEN; snprintf(tsk_errstr, TSK_ERRSTR_L, "raw_open file: %" PRIttocTSK " GetFileSize: %d", - image, (int)GetLastError()); + image, (int) GetLastError()); return NULL; } img_info->size = dwLo | ((TSK_OFF_T) dwHi << 32); @@ -265,7 +269,7 @@ raw_open(const TSK_TCHAR * image) tsk_errno = TSK_ERR_IMG_OPEN; snprintf(tsk_errstr, TSK_ERRSTR_L, "raw_open file: %" PRIttocTSK - " DeviceIoControl: %d", image, (int)GetLastError()); + " DeviceIoControl: %d", image, (int) GetLastError()); return NULL; } @@ -286,13 +290,13 @@ raw_open(const TSK_TCHAR * image) return NULL; } - /* We don't use the stat output because it doesn't work on raw - * devices and such */ - img_info->size = lseek(raw_info->fd, 0, SEEK_END); - lseek(raw_info->fd, 0, SEEK_SET); - #if defined(__APPLE__) - /* OS X doesn't support SEEK_END on devices */ + /* OS X doesn't support SEEK_END on char devices */ + if ((stat_buf.st_mode & S_IFMT) != S_IFCHR) { + img_info->size = lseek(raw_info->fd, 0, SEEK_END); + lseek(raw_info->fd, 0, SEEK_SET); + } + if (img_info->size == 0) { int blkSize; long long blkCnt; @@ -303,7 +307,12 @@ raw_open(const TSK_TCHAR * image) } } } -#endif // apple +#else + /* We don't use the stat output because it doesn't work on raw + * devices and such */ + img_info->size = lseek(raw_info->fd, 0, SEEK_END); + lseek(raw_info->fd, 0, SEEK_SET); +#endif #endif raw_info->seek_pos = 0; -- GitLab