Sleuth Kit Java Bindings (JNI)  4.11.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 
30 public class FileSystem extends AbstractContent {
31 
32  private long imgOffset, blockSize, blockCount, rootInum,
33  firstInum, lastInum;
34  private TskData.TSK_FS_TYPE_ENUM fsType;
35  private Content parent;
36  private volatile long filesystemHandle = 0;
37 
52  protected FileSystem(SleuthkitCase db, long obj_id, String name, long img_offset,
53  TskData.TSK_FS_TYPE_ENUM fs_type, long block_size, long block_count, long root_inum,
54  long first_inum, long last_inum) {
55  super(db, obj_id, name);
56  this.imgOffset = img_offset;
57  this.fsType = fs_type;
58  this.blockSize = block_size;
59  this.blockCount = block_count;
60  this.rootInum = root_inum;
61  this.firstInum = first_inum;
62  this.lastInum = last_inum;
63  }
64 
65  @Override
66  public void close() {
67  //does nothing currently, we are caching the fs handles
68  }
69 
70  @Override
71  public int read(byte[] buf, long offset, long len) throws TskCoreException {
72  return SleuthkitJNI.readFs(getFileSystemHandle(), buf, offset, len);
73  }
74 
75  @Override
76  public long getSize() {
77  return blockSize * blockCount;
78  }
79 
89  long getFileSystemHandle() throws TskCoreException {
90  if (filesystemHandle == 0) {
91  synchronized (this) {
92  if (filesystemHandle == 0) {
93  Content dataSource = getDataSource();
94  if ((dataSource == null) || ( !(dataSource instanceof Image))) {
95  throw new TskCoreException("Data Source of File System is not an image");
96  }
97 
98  Image image = (Image) dataSource;
99 
100  // Check if this file system is in a pool
101  if (isPoolContent()) {
102  Pool pool = getPool();
103  if (pool == null) {
104  throw new TskCoreException("Error finding pool for file system");
105  }
106 
107  Volume poolVolume = getPoolVolume();
108  if (poolVolume == null) {
109  throw new TskCoreException("File system is in a pool but has no volume");
110  }
111  filesystemHandle = SleuthkitJNI.openFsPool(image.getImageHandle(), imgOffset, pool.getPoolHandle(), poolVolume.getStart(), getSleuthkitCase());
112  } else {
113  filesystemHandle = SleuthkitJNI.openFs(image.getImageHandle(), imgOffset, getSleuthkitCase());
114  }
115  }
116  }
117  }
118  return this.filesystemHandle;
119  }
120 
121  public Directory getRootDirectory() throws TskCoreException {
122 
123  List<Content> children = getChildren();
124  if (children.size() != 1) {
125  throw new TskCoreException("FileSystem must have only one child.");
126  }
127 
128  if (!(children.get(0) instanceof Directory)) {
129  throw new TskCoreException("Child of FileSystem must be a Directory.");
130  }
131 
132  return (Directory) children.get(0);
133  }
134 
140  public long getImageOffset() {
141  return imgOffset;
142  }
143 
150  return fsType;
151  }
152 
158  public long getBlock_size() {
159  return blockSize;
160  }
161 
167  public long getBlock_count() {
168  return blockCount;
169  }
170 
176  public long getRoot_inum() {
177  return rootInum;
178  }
179 
185  public long getFirst_inum() {
186  return firstInum;
187  }
188 
194  public long getLastInum() {
195  return lastInum;
196  }
197 
198  @SuppressWarnings("deprecation")
199  @Override
200  public void finalize() throws Throwable {
201  try {
202  if (filesystemHandle != 0) {
203  // SleuthkitJNI.closeFs(filesystemHandle); // closeFs is currently a no-op
204  filesystemHandle = 0;
205  }
206  } finally {
207  super.finalize();
208  }
209  }
210 
211  @Override
212  public <T> T accept(SleuthkitItemVisitor<T> v) {
213  return v.visit(this);
214  }
215 
216  @Override
217  public <T> T accept(ContentVisitor<T> v) {
218  return v.visit(this);
219  }
220 
221  @Override
222  public String toString(boolean preserveState) {
223  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
224  }
225 }
String toString(boolean preserveState)
int read(byte[] buf, long offset, long len)
Definition: FileSystem.java:71
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:52
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.