/src/sleuthkit/tsk/vs/mm_io.c
Line | Count | Source |
1 | | /* |
2 | | * The Sleuth Kit |
3 | | * |
4 | | * Brian Carrier [carrier <at> sleuthkit [dot] org] |
5 | | * Copyright (c) 2006-2011 Brian Carrier, Basis Technology. All rights reserved |
6 | | * Copyright (c) 2003-2005 Brian Carrier. All rights reserved |
7 | | * |
8 | | * This software is distributed under the Common Public License 1.0 |
9 | | */ |
10 | | |
11 | | /** \file mm_io.c |
12 | | * Contains the wrapper code that allows one to read sectors from |
13 | | * a TSK_VS_INFO or TSK_VS_PART_INFO structure. These functions |
14 | | * call the underlying TSK_IMG_INFO functions. |
15 | | */ |
16 | | #include <errno.h> |
17 | | #include "tsk_vs_i.h" |
18 | | |
19 | | |
20 | | /** |
21 | | * \ingroup vslib |
22 | | * Reads one or more blocks of data with an address relative to the start of the volume system. |
23 | | * |
24 | | * @param a_vs Pointer to open volume system |
25 | | * @param a_addr Sector address to read from, relative to start of VOLUME SYSTEM. |
26 | | * @param a_buf Buffer to store data in |
27 | | * @param a_len Amount of data to read (in bytes - must be a multiple of block_size) |
28 | | * @returns Number of bytes read or -1 on error |
29 | | */ |
30 | | ssize_t |
31 | | tsk_vs_read_block(TSK_VS_INFO * a_vs, TSK_DADDR_T a_addr, char *a_buf, |
32 | | size_t a_len) |
33 | 528k | { |
34 | 528k | if (a_len % a_vs->block_size) { |
35 | 0 | tsk_error_reset(); |
36 | 0 | tsk_error_set_errno(TSK_ERR_VS_READ); |
37 | 0 | tsk_error_set_errstr("tsk_vs_read_block: length %" PRIuSIZE "" |
38 | 0 | " not a multiple of %d", a_len, a_vs->block_size); |
39 | 0 | return -1; |
40 | 0 | } |
41 | | |
42 | 528k | return tsk_img_read(a_vs->img_info, |
43 | 528k | a_vs->offset + (TSK_OFF_T) (a_addr * a_vs->block_size), |
44 | 528k | a_buf, a_len); |
45 | 528k | } |
46 | | |
47 | | |
48 | | /** |
49 | | * \ingroup vslib |
50 | | * Reads data starting at a byte address relative to the start of a VOLUME in a volume system. |
51 | | * |
52 | | * @param a_vs_part info Pointer to open volume in a volume system |
53 | | * @param a_off Byte offset to read from, relative to start of VOLUME in volume system. |
54 | | * @param a_buf Buffer to store data in |
55 | | * @param a_len Amount of data to read (in bytes) |
56 | | * @returns Number of bytes read or -1 on error |
57 | | */ |
58 | | ssize_t |
59 | | tsk_vs_part_read(const TSK_VS_PART_INFO * a_vs_part, TSK_OFF_T a_off, |
60 | | char *a_buf, size_t a_len) |
61 | 0 | { |
62 | 0 | TSK_VS_INFO *vs = a_vs_part->vs; |
63 | |
|
64 | 0 | return tsk_img_read(vs->img_info, |
65 | 0 | vs->offset + (TSK_OFF_T) a_vs_part->start * vs->block_size + |
66 | 0 | a_off, a_buf, a_len); |
67 | 0 | } |
68 | | |
69 | | /** |
70 | | * \ingroup vslib |
71 | | * Reads one or more blocks of data with an address relative to the start of a VOLUME in a volume system. |
72 | | * |
73 | | * @param a_vs_part info Pointer to open volume in a volume system |
74 | | * @param a_addr Block address to start reading from, relative to start of VOLUME in volume system. |
75 | | * @param a_buf Buffer to store data in |
76 | | * @param a_len Amount of data to read (in bytes - must be a multiple of block_size) |
77 | | * @returns Number of bytes read or -1 on error |
78 | | */ |
79 | | ssize_t |
80 | | tsk_vs_part_read_block(const TSK_VS_PART_INFO * a_vs_part, |
81 | | TSK_DADDR_T a_addr, char *a_buf, size_t a_len) |
82 | 0 | { |
83 | 0 | TSK_VS_INFO *vs = a_vs_part->vs; |
84 | |
|
85 | 0 | if (a_len % vs->block_size) { |
86 | 0 | tsk_error_reset(); |
87 | 0 | tsk_error_set_errno(TSK_ERR_VS_READ); |
88 | 0 | tsk_error_set_errstr("tsk_vs_part_read_block: length %" PRIuSIZE "" |
89 | 0 | " not a multiple of %d", a_len, vs->block_size); |
90 | 0 | return -1; |
91 | 0 | } |
92 | | |
93 | 0 | return tsk_img_read(vs->img_info, |
94 | 0 | vs->offset + (TSK_OFF_T) (a_vs_part->start + |
95 | 0 | a_addr) * vs->block_size, a_buf, a_len); |
96 | 0 | } |