Sleuth Kit Java Bindings (JNI)  4.12.1
Java bindings for using The Sleuth Kit
FileSystem.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 org.apache.commons.lang3.ArrayUtils;
23 
31 public class FileSystem extends AbstractContent {
32 
33  private long imgOffset, blockSize, blockCount, rootInum,
34  firstInum, lastInum;
35  private TskData.TSK_FS_TYPE_ENUM fsType;
36  private Content parent;
37  private volatile long filesystemHandle = 0;
38 
53  protected FileSystem(SleuthkitCase db, long obj_id, String name, long img_offset,
54  TskData.TSK_FS_TYPE_ENUM fs_type, long block_size, long block_count, long root_inum,
55  long first_inum, long last_inum) {
56  super(db, obj_id, name);
57  this.imgOffset = img_offset;
58  this.fsType = fs_type;
59  this.blockSize = block_size;
60  this.blockCount = block_count;
61  this.rootInum = root_inum;
62  this.firstInum = first_inum;
63  this.lastInum = last_inum;
64  }
65 
66  @Override
67  public void close() {
68  //does nothing currently, we are caching the fs handles
69  }
70 
71  @Override
72  public int read(byte[] buf, long offset, long len) throws TskCoreException {
73  Content dataSource = getDataSource();
74  if (dataSource instanceof Image && ArrayUtils.isEmpty(((Image) dataSource).getPaths())) {
75  return 0;
76  }
77  return SleuthkitJNI.readFs(getFileSystemHandle(), buf, offset, len);
78  }
79 
80  @Override
81  public long getSize() {
82  return blockSize * blockCount;
83  }
84 
94  long getFileSystemHandle() throws TskCoreException {
95  if (filesystemHandle == 0) {
96  synchronized (this) {
97  if (filesystemHandle == 0) {
98  Content dataSource = getDataSource();
99  if ((dataSource == null) || ( !(dataSource instanceof Image))) {
100  throw new TskCoreException("Data Source of File System is not an image");
101  }
102 
103  Image image = (Image) dataSource;
104 
105  // Check if this file system is in a pool
106  if (isPoolContent()) {
107  Pool pool = getPool();
108  if (pool == null) {
109  throw new TskCoreException("Error finding pool for file system");
110  }
111 
112  Volume poolVolume = getPoolVolume();
113  if (poolVolume == null) {
114  throw new TskCoreException("File system is in a pool but has no volume");
115  }
116  filesystemHandle = SleuthkitJNI.openFsPool(image.getImageHandle(), imgOffset, pool.getPoolHandle(), poolVolume.getStart(), getSleuthkitCase());
117  } else {
118  filesystemHandle = SleuthkitJNI.openFs(image.getImageHandle(), imgOffset, getSleuthkitCase());
119  }
120  }
121  }
122  }
123  return this.filesystemHandle;
124  }
125 
126  public Directory getRootDirectory() throws TskCoreException {
127 
128  List<Content> children = getChildren();
129  if (children.size() != 1) {
130  throw new TskCoreException("FileSystem must have only one child.");
131  }
132 
133  if (!(children.get(0) instanceof Directory)) {
134  throw new TskCoreException("Child of FileSystem must be a Directory.");
135  }
136 
137  return (Directory) children.get(0);
138  }
139 
145  public long getImageOffset() {
146  return imgOffset;
147  }
148 
155  return fsType;
156  }
157 
163  public long getBlock_size() {
164  return blockSize;
165  }
166 
172  public long getBlock_count() {
173  return blockCount;
174  }
175 
181  public long getRoot_inum() {
182  return rootInum;
183  }
184 
190  public long getFirst_inum() {
191  return firstInum;
192  }
193 
199  public long getLastInum() {
200  return lastInum;
201  }
202 
203  @SuppressWarnings("deprecation")
204  @Override
205  public void finalize() throws Throwable {
206  try {
207  if (filesystemHandle != 0) {
208  // SleuthkitJNI.closeFs(filesystemHandle); // closeFs is currently a no-op
209  filesystemHandle = 0;
210  }
211  } finally {
212  super.finalize();
213  }
214  }
215 
216  @Override
217  public <T> T accept(SleuthkitItemVisitor<T> v) {
218  return v.visit(this);
219  }
220 
221  @Override
222  public <T> T accept(ContentVisitor<T> v) {
223  return v.visit(this);
224  }
225 
226  @Override
227  public String toString(boolean preserveState) {
228  return super.toString(preserveState) + "FileSystem [\t" + " blockCount " + blockCount + "\t" + "blockSize " + blockSize + "\t" + "firstInum " + firstInum + "\t" + "fsType " + fsType + "\t" + "imgOffset " + imgOffset + "\t" + "lastInum " + lastInum + "\t" + "rootInum " + rootInum + "\t" + "]"; //NON-NLS
229  }
230 }
String toString(boolean preserveState)
int read(byte[] buf, long offset, long len)
Definition: FileSystem.java:72
FileSystem(SleuthkitCase db, long obj_id, String name, long img_offset, TskData.TSK_FS_TYPE_ENUM fs_type, long block_size, long block_count, long root_inum, long first_inum, long last_inum)
Definition: FileSystem.java:53
TskData.TSK_FS_TYPE_ENUM getFsType()
static int readFs(long fsHandle, byte[] readBuffer, long offset, long len)

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