/src/sleuthkit/tsk/fs/fs_load.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * The Sleuth Kit |
3 | | * |
4 | | * Brian Carrier [carrier <at> sleuthkit [dot] org] |
5 | | * Copyright (c) 2005-2011 Brian Carrier. All rights reserved |
6 | | * |
7 | | * This software is distributed under the Common Public License 1.0 |
8 | | * |
9 | | */ |
10 | | |
11 | | /** \file fs_load.c |
12 | | * Contains a general file walk callback that can be |
13 | | * used to load file content into a buffer. |
14 | | */ |
15 | | #include "tsk_fs_i.h" |
16 | | |
17 | | #include <string.h> |
18 | | |
19 | | |
20 | | /* File Walk Action to load the journal |
21 | | * TSK_FS_LOAD_FILE is defined in fs_tools.h |
22 | | */ |
23 | | |
24 | | TSK_WALK_RET_ENUM |
25 | | tsk_fs_load_file_action( |
26 | | [[maybe_unused]] TSK_FS_FILE * fs_file, |
27 | | [[maybe_unused]] TSK_OFF_T a_off, |
28 | | [[maybe_unused]] TSK_DADDR_T addr, |
29 | | char *buf, |
30 | | size_t size, |
31 | | [[maybe_unused]] TSK_FS_BLOCK_FLAG_ENUM flags, |
32 | | void *ptr) |
33 | 39.0M | { |
34 | 39.0M | TSK_FS_LOAD_FILE *buf1 = (TSK_FS_LOAD_FILE *) ptr; |
35 | | |
36 | 39.0M | if (buf1->cur == NULL) { |
37 | 1 | return TSK_WALK_ERROR; |
38 | 1 | } |
39 | 39.0M | size_t cp_size = size; |
40 | 39.0M | if (cp_size > buf1->left) cp_size = buf1->left; |
41 | | |
42 | 39.0M | size_t cp_offset = (size_t) (buf1->cur - buf1->base); |
43 | 39.0M | if ((cp_size > buf1->total) || (cp_offset > (buf1->total - cp_size))) { |
44 | 0 | return TSK_WALK_ERROR; |
45 | 0 | } |
46 | 39.0M | memcpy(buf1->cur, buf, cp_size); |
47 | | |
48 | 39.0M | buf1->left -= cp_size; |
49 | 39.0M | buf1->cur = (char *) ((uintptr_t) buf1->cur + cp_size); |
50 | | |
51 | 39.0M | if (buf1->left > 0) |
52 | 39.0M | return TSK_WALK_CONT; |
53 | 47.4k | else |
54 | 47.4k | return TSK_WALK_STOP; |
55 | 39.0M | } |