Coverage Report

Created: 2025-08-26 06:11

/src/sleuthkit/tsk/fs/nofs_misc.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) 2006-2011 Brian Carrier, Basis Technology.  All Rights reserved
6
** Copyright (c) 2004-2005 Brian Carrier.  All rights reserved
7
**
8
**
9
** This software is distributed under the Common Public License 1.0
10
**
11
*/
12
13
#include "tsk_fs_i.h"
14
15
16
/**
17
 *\file nofs_misc.c
18
 * Contains internal functions that are common to the "non-file system" file systems, such as
19
 * raw and swap. Many of the functions in this file simply give an error that the functionality
20
 * is not supported for the given file system type.
21
 */
22
23
24
/** \internal
25
 * Print details about the file system to a file handle.
26
 *
27
 * @param a_fs File system to print details on
28
 * @param hFile File handle to print text to
29
 *
30
 * @returns 1 on error and 0 on success
31
 */
32
uint8_t
33
tsk_fs_nofs_fsstat(TSK_FS_INFO * a_fs, FILE * hFile)
34
0
{
35
0
    tsk_fprintf(hFile, "%s Data\n", tsk_fs_type_toname(a_fs->ftype));
36
0
    tsk_fprintf(hFile, "Block Size: %d\n", a_fs->block_size);
37
0
    tsk_fprintf(hFile, "Block Range: 0 - %" PRIuDADDR "\n",
38
0
        a_fs->last_block);
39
0
    return 0;
40
0
}
41
42
43
/** \internal
44
 */
45
TSK_FS_ATTR_TYPE_ENUM
46
tsk_fs_nofs_get_default_attr_type([[maybe_unused]] const TSK_FS_FILE * a_fs_file)
47
0
{
48
0
    return TSK_FS_ATTR_TYPE_DEFAULT;
49
0
}
50
51
52
/** \internal
53
 */
54
uint8_t
55
tsk_fs_nofs_make_data_run(TSK_FS_FILE * a_fs_file)
56
0
{
57
0
    tsk_error_reset();
58
0
    tsk_error_set_errno(TSK_ERR_FS_UNSUPFUNC);
59
0
    tsk_error_set_errstr("Illegal analysis method for %s data ",
60
0
        (a_fs_file->fs_info) ? tsk_fs_type_toname(a_fs_file->
61
0
            fs_info->ftype) : "");
62
0
    return 1;
63
0
}
64
65
66
67
/** \internal
68
 */
69
void
70
tsk_fs_nofs_close(TSK_FS_INFO * a_fs)
71
0
{
72
0
    a_fs->tag = 0;
73
0
    tsk_fs_free(a_fs);
74
0
}
75
76
/************* BLOCKS *************/
77
78
/** \internal
79
 */
80
TSK_FS_BLOCK_FLAG_ENUM
81
tsk_fs_nofs_block_getflags(
82
  [[maybe_unused]] TSK_FS_INFO * a_fs,
83
  [[maybe_unused]] TSK_DADDR_T a_addr)
84
0
{
85
0
    return (TSK_FS_BLOCK_FLAG_ENUM) (TSK_FS_BLOCK_FLAG_ALLOC | TSK_FS_BLOCK_FLAG_CONT);
86
0
}
87
88
89
/** \internal
90
 *
91
 * return 1 on error and 0 on success
92
 */
93
uint8_t
94
tsk_fs_nofs_block_walk(TSK_FS_INFO * fs, TSK_DADDR_T a_start_blk,
95
    TSK_DADDR_T a_end_blk, TSK_FS_BLOCK_WALK_FLAG_ENUM a_flags,
96
    TSK_FS_BLOCK_WALK_CB a_action, void *a_ptr)
97
0
{
98
0
    TSK_FS_BLOCK *fs_block;
99
0
    TSK_DADDR_T addr;
100
101
    // clean up any error messages that are lying around
102
0
    tsk_error_reset();
103
104
    /*
105
     * Sanity checks.
106
     */
107
0
    if (a_start_blk < fs->first_block || a_start_blk > fs->last_block) {
108
0
        tsk_error_reset();
109
0
        tsk_error_set_errno(TSK_ERR_FS_WALK_RNG);
110
0
        tsk_error_set_errstr("nofs_block_walk: Start block number: %"
111
0
            PRIuDADDR, a_start_blk);
112
0
        return 1;
113
0
    }
114
115
0
    if (a_end_blk < fs->first_block || a_end_blk > fs->last_block
116
0
        || a_end_blk < a_start_blk) {
117
0
        tsk_error_reset();
118
0
        tsk_error_set_errno(TSK_ERR_FS_WALK_RNG);
119
0
        tsk_error_set_errstr("nofs_block_walk: Last block number: %"
120
0
            PRIuDADDR, a_end_blk);
121
0
        return 1;
122
0
    }
123
124
    /* Sanity check on a_flags -- make sure at least one ALLOC is set */
125
0
    if (((a_flags & TSK_FS_BLOCK_WALK_FLAG_ALLOC) == 0) &&
126
0
        ((a_flags & TSK_FS_BLOCK_WALK_FLAG_UNALLOC) == 0)) {
127
0
        a_flags = (TSK_FS_BLOCK_WALK_FLAG_ENUM)
128
0
            (a_flags | TSK_FS_BLOCK_WALK_FLAG_ALLOC |
129
0
            TSK_FS_BLOCK_WALK_FLAG_UNALLOC);
130
0
    }
131
132
    /* All swap has is allocated blocks... exit if not wanted */
133
0
    if (!(a_flags & TSK_FS_BLOCK_WALK_FLAG_ALLOC)) {
134
0
        return 0;
135
0
    }
136
137
0
    if ((fs_block = tsk_fs_block_alloc(fs)) == NULL) {
138
0
        return 1;
139
0
    }
140
141
0
    for (addr = a_start_blk; addr <= a_end_blk; addr++) {
142
0
        int retval;
143
144
0
        if (tsk_fs_block_get(fs, fs_block, addr) == NULL) {
145
0
            tsk_error_set_errstr2("nofs_block_walk: Block %" PRIuDADDR,
146
0
                addr);
147
0
            tsk_fs_block_free(fs_block);
148
0
            return 1;
149
0
        }
150
151
0
        retval = a_action(fs_block, a_ptr);
152
0
        if (retval == TSK_WALK_STOP) {
153
0
            break;
154
0
        }
155
0
        else if (retval == TSK_WALK_ERROR) {
156
0
            tsk_fs_block_free(fs_block);
157
0
            return 1;
158
0
        }
159
0
    }
160
161
    /*
162
     * Cleanup.
163
     */
164
0
    tsk_fs_block_free(fs_block);
165
0
    return 0;
166
0
}
167
168
169
/************ META / FILES ************/
170
171
172
/** \internal
173
 */
174
uint8_t
175
tsk_fs_nofs_inode_walk(
176
  TSK_FS_INFO * a_fs,
177
  [[maybe_unused]] TSK_INUM_T a_start_inum,
178
  [[maybe_unused]] TSK_INUM_T a_end_inum,
179
  [[maybe_unused]] TSK_FS_META_FLAG_ENUM a_flags,
180
  [[maybe_unused]] TSK_FS_META_WALK_CB a_action,
181
  [[maybe_unused]] void *a_ptr)
182
0
{
183
0
    tsk_error_reset();
184
0
    tsk_error_set_errno(TSK_ERR_FS_UNSUPFUNC);
185
0
    tsk_error_set_errstr("Illegal analysis method for %s data ",
186
0
        tsk_fs_type_toname(a_fs->ftype));
187
0
    return 1;
188
0
}
189
190
/** \internal
191
 */
192
uint8_t
193
tsk_fs_nofs_file_add_meta(
194
  TSK_FS_INFO * a_fs,
195
  [[maybe_unused]] TSK_FS_FILE * a_fs_file,
196
  [[maybe_unused]] TSK_INUM_T inum)
197
0
{
198
0
    tsk_error_reset();
199
0
    tsk_error_set_errno(TSK_ERR_FS_UNSUPFUNC);
200
0
    tsk_error_set_errstr("Illegal analysis method for %s data ",
201
0
        tsk_fs_type_toname(a_fs->ftype));
202
0
    return 1;
203
0
}
204
205
/** \internal
206
 */
207
uint8_t
208
tsk_fs_nofs_istat(
209
  TSK_FS_INFO * a_fs,
210
  [[maybe_unused]] TSK_FS_ISTAT_FLAG_ENUM istat_flags,
211
  [[maybe_unused]] FILE * hFile,
212
  [[maybe_unused]] TSK_INUM_T inum,
213
  [[maybe_unused]] TSK_DADDR_T numblock,
214
  [[maybe_unused]] int32_t sec_skew)
215
0
{
216
0
    tsk_error_reset();
217
0
    tsk_error_set_errno(TSK_ERR_FS_UNSUPFUNC);
218
0
    tsk_error_set_errstr("Illegal analysis method for %s data ",
219
0
        tsk_fs_type_toname(a_fs->ftype));
220
0
    return 1;
221
0
}
222
223
224
225
/************ DIR **************/
226
227
/** \internal
228
 */
229
TSK_RETVAL_ENUM
230
tsk_fs_nofs_dir_open_meta(
231
  TSK_FS_INFO * a_fs,
232
  [[maybe_unused]] TSK_FS_DIR ** a_fs_dir,
233
  [[maybe_unused]] TSK_INUM_T a_addr,
234
  [[maybe_unused]] int recursion_depth)
235
0
{
236
0
    tsk_error_reset();
237
0
    tsk_error_set_errno(TSK_ERR_FS_UNSUPFUNC);
238
0
    tsk_error_set_errstr("Illegal analysis method for %s data ",
239
0
        tsk_fs_type_toname(a_fs->ftype));
240
0
    return TSK_ERR;
241
0
}
242
243
/******** JOURNAL **********/
244
245
/** \internal
246
 */
247
uint8_t
248
tsk_fs_nofs_jopen(
249
  TSK_FS_INFO * a_fs,
250
  [[maybe_unused]] TSK_INUM_T inum)
251
0
{
252
0
    tsk_error_reset();
253
0
    tsk_error_set_errno(TSK_ERR_FS_UNSUPFUNC);
254
0
    tsk_error_set_errstr("Illegal analysis method for %s data ",
255
0
        tsk_fs_type_toname(a_fs->ftype));
256
0
    return 1;
257
0
}
258
259
/** \internal
260
 */
261
uint8_t
262
tsk_fs_nofs_jentry_walk(
263
  TSK_FS_INFO * a_fs,
264
  [[maybe_unused]] int a_flags,
265
  [[maybe_unused]] TSK_FS_JENTRY_WALK_CB a_action,
266
  [[maybe_unused]] void *a_ptr)
267
0
{
268
0
    tsk_error_reset();
269
0
    tsk_error_set_errno(TSK_ERR_FS_UNSUPFUNC);
270
0
    tsk_error_set_errstr("Illegal analysis method for %s data ",
271
0
        tsk_fs_type_toname(a_fs->ftype));
272
0
    return 1;
273
0
}
274
275
276
/** \internal
277
 */
278
uint8_t
279
tsk_fs_nofs_jblk_walk(
280
  TSK_FS_INFO * a_fs,
281
  [[maybe_unused]] TSK_INUM_T start,
282
  [[maybe_unused]] TSK_INUM_T end,
283
  [[maybe_unused]] int a_flags,
284
  [[maybe_unused]] TSK_FS_JBLK_WALK_CB a_action,
285
  [[maybe_unused]] void *a_ptr)
286
0
{
287
0
    tsk_error_reset();
288
0
    tsk_error_set_errno(TSK_ERR_FS_UNSUPFUNC);
289
0
    tsk_error_set_errstr("Illegal analysis method for %s data ",
290
0
        tsk_fs_type_toname(a_fs->ftype));
291
0
    return 1;
292
0
}
293
294
int
295
tsk_fs_nofs_name_cmp(
296
  [[maybe_unused]] TSK_FS_INFO * a_fs_info,
297
  [[maybe_unused]] const char *s1,
298
    const char *s2)
299
0
{
300
0
    return strcmp(s1, s2);
301
0
}