Sleuth Kit Java Bindings (JNI)  4.6
Java bindings for using The Sleuth Kit
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  */
19 package org.sleuthkit.datamodel;
20 
21 import java.util.List;
22 import java.util.logging.Level;
23 import java.util.logging.Logger;
25 
29 public 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 
74  return TskData.TSK_POOL_TYPE_ENUM.valueOf(type);
75  }
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  return parent.getStart() * image.getSsize(); // Offset needs to be in bytes
118  }
119  throw new TskCoreException("Pool with object ID " + this.getId() + " does not have Image or Volume parent");
120  }
121 
122  @Override
123  public void close() {
124  // Pools will be closed during case closing by the JNI code.
125  }
126 
127  @Override
128  protected void finalize() throws Throwable {
129  try {
130  close();
131  } finally {
132  super.finalize();
133  }
134  }
135 
136  @Override
137  public <T> T accept(SleuthkitItemVisitor<T> v) {
138  return v.visit(this);
139  }
140 
141  @Override
142  public <T> T accept(ContentVisitor<T> v) {
143  return v.visit(this);
144  }
145 
146  @Override
147  public List<Content> getChildren() throws TskCoreException {
148  return getSleuthkitCase().getPoolChildren(this);
149  }
150 
151  @Override
152  public List<Long> getChildrenIds() throws TskCoreException {
153  return getSleuthkitCase().getPoolChildrenIds(this);
154  }
155 
156 
157  @Override
158  public String toString(boolean preserveState) {
159  return super.toString(preserveState) + "Pool [\t" + "type " + type + "]\t"; //NON-NLS
160  }
161 }
int read(byte[] readBuffer, long offset, long len)
Definition: Pool.java:49
String toString(boolean preserveState)
Definition: Pool.java:158
static TSK_POOL_TYPE_ENUM valueOf(long poolType)
Definition: TskData.java:752
List< Content > getChildren()
Definition: Pool.java:147
TSK_POOL_TYPE_ENUM getType()
Definition: Pool.java:73
List< Long > getChildrenIds()
Definition: Pool.java:152
Pool(SleuthkitCase db, long obj_id, String name, long type)
Definition: Pool.java:43
synchronized long getImageHandle()
Definition: Image.java:121

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