Sleuth Kit Java Bindings (JNI) 4.14.0
Java bindings for using The Sleuth Kit
Loading...
Searching...
No Matches
Pool.java
Go to the documentation of this file.
1/*
2 * Sleuth Kit Data Model
3 *
4 * Copyright 2011-2017 Basis Technology Corp.
5 * Contact: carrier <at> sleuthkit <dot> org
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 */
19package org.sleuthkit.datamodel;
20
21import java.util.List;
22import java.util.logging.Level;
23import java.util.logging.Logger;
24import org.sleuthkit.datamodel.TskData.TSK_POOL_TYPE_ENUM;
25
29public class Pool extends AbstractContent {
30
31 private static final Logger logger = Logger.getLogger(Pool.class.getName());
32 private volatile long poolHandle = 0;
33 private final long type;
34
43 protected Pool(SleuthkitCase db, long obj_id, String name, long type) {
44 super(db, obj_id, name);
45 this.type = type;
46 }
47
48 @Override
49 public int read(byte[] readBuffer, long offset, long len) throws TskCoreException {
50 synchronized (this) {
51 if (poolHandle == 0) {
52 getPoolHandle();
53 }
54 }
55 return SleuthkitJNI.readPool(poolHandle, readBuffer, offset, len);
56 }
57
58 @Override
59 public long getSize() {
60 try {
61 return getParent().getSize();
62 } catch (TskCoreException ex) {
63 logger.log(Level.SEVERE, "Error getting parent of pool with obj ID {0}", getId());
64 return 0;
65 }
66 }
67
76
86 long getPoolHandle() throws TskCoreException {
87 // Note that once poolHandle is set, it will never be changed or reset to zero
88 if (poolHandle == 0) {
89 synchronized (this) {
90 if (poolHandle == 0) {
91 Content dataSource = getDataSource();
92 if ((dataSource != null) && (dataSource instanceof Image)) {
93 Image image = (Image) dataSource;
94 poolHandle = SleuthkitJNI.openPool(image.getImageHandle(), getPoolOffset(image), getSleuthkitCase());
95 } else {
96 throw new TskCoreException("Data Source of pool is not an image");
97 }
98 }
99 }
100 }
101 return this.poolHandle;
102 }
103
110 private long getPoolOffset(Image image) throws TskCoreException {
111 if (this.getParent() instanceof Image) {
112 // If the parent is an image, then the pool starts at offset zero
113 return 0;
114 } else if (this.getParent() instanceof Volume) {
115 // If the parent is a volume, then the pool starts at the volume offset
116 Volume parent = (Volume)this.getParent();
117 if (parent.getParent() instanceof VolumeSystem) {
118 // uses block size from parent volume system
119 return parent.getStart() * ((VolumeSystem) parent.getParent()).getBlockSize(); // Offset needs to be in bytes
120 } else {
121 // uses sector size from parent image (old behavior fallback)
122 return parent.getStart() * image.getSsize(); // Offset needs to be in bytes
123 }
124 }
125 throw new TskCoreException("Pool with object ID " + this.getId() + " does not have Image or Volume parent");
126 }
127
128 @Override
129 public void close() {
130 // Pools will be closed during case closing by the JNI code.
131 }
132
133 @SuppressWarnings("deprecation")
134 @Override
135 protected void finalize() throws Throwable {
136 try {
137 close();
138 } finally {
139 super.finalize();
140 }
141 }
142
143 @Override
144 public <T> T accept(SleuthkitItemVisitor<T> v) {
145 return v.visit(this);
146 }
147
148 @Override
149 public <T> T accept(ContentVisitor<T> v) {
150 return v.visit(this);
151 }
152
153 @Override
154 public List<Content> getChildren() throws TskCoreException {
155 return getSleuthkitCase().getPoolChildren(this);
156 }
157
158 @Override
159 public List<Long> getChildrenIds() throws TskCoreException {
160 return getSleuthkitCase().getPoolChildrenIds(this);
161 }
162
163
164 @Override
165 public String toString(boolean preserveState) {
166 return super.toString(preserveState) + "Pool [\t" + "type " + type + "]\t"; //NON-NLS
167 }
168}
AbstractContent(SleuthkitCase db, long obj_id, String name)
synchronized long getImageHandle()
Definition Image.java:122
TSK_POOL_TYPE_ENUM getType()
Definition Pool.java:73
List< Long > getChildrenIds()
Definition Pool.java:159
List< Content > getChildren()
Definition Pool.java:154
String toString(boolean preserveState)
Definition Pool.java:165
int read(byte[] readBuffer, long offset, long len)
Definition Pool.java:49
Pool(SleuthkitCase db, long obj_id, String name, long type)
Definition Pool.java:43
static TSK_POOL_TYPE_ENUM valueOf(long poolType)
Definition TskData.java:772

Copyright © 2011-2024 Brian Carrier. (carrier -at- sleuthkit -dot- org)
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.