Sleuth Kit Java Bindings (JNI)  4.3
Java bindings for using The Sleuth Kit
FileSystem.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2011 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;
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  Image image = (Image) dataSource;
96  filesystemHandle = SleuthkitJNI.openFs(image.getImageHandle(), imgOffset);
97  } else {
98  throw new TskCoreException("Data Source of File System is not an image");
99  }
100  }
101  }
102  }
103  return this.filesystemHandle;
104  }
105 
106  public Directory getRootDirectory() throws TskCoreException {
107 
108  List<Content> children = getChildren();
109  if (children.size() != 1) {
110  throw new TskCoreException("FileSystem must have only one child.");
111  }
112 
113  if (!(children.get(0) instanceof Directory)) {
114  throw new TskCoreException("Child of FileSystem must be a Directory.");
115  }
116 
117  return (Directory) children.get(0);
118  }
119 
125  public long getImageOffset() {
126  return imgOffset;
127  }
128 
135  return fsType;
136  }
137 
143  public long getBlock_size() {
144  return blockSize;
145  }
146 
152  public long getBlock_count() {
153  return blockCount;
154  }
155 
161  public long getRoot_inum() {
162  return rootInum;
163  }
164 
170  public long getFirst_inum() {
171  return firstInum;
172  }
173 
179  public long getLastInum() {
180  return lastInum;
181  }
182 
183  @Override
184  public void finalize() throws Throwable {
185  try {
186  if (filesystemHandle != 0) {
187  SleuthkitJNI.closeFs(filesystemHandle);
188  filesystemHandle = 0;
189  }
190  } finally {
191  super.finalize();
192  }
193  }
194 
195  @Override
196  public <T> T accept(SleuthkitItemVisitor<T> v) {
197  return v.visit(this);
198  }
199 
200  @Override
201  public <T> T accept(ContentVisitor<T> v) {
202  return v.visit(this);
203  }
204 
205  @Override
206  public List<Content> getChildren() throws TskCoreException {
207  return getSleuthkitCase().getAbstractFileChildren(this);
208  }
209 
210  @Override
211  public List<Long> getChildrenIds() throws TskCoreException {
212  return getSleuthkitCase().getAbstractFileChildrenIds(this);
213  }
214 
215  @Override
216  public String toString(boolean preserveState) {
217  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
218  }
219 }
String toString(boolean preserveState)
TskData.TSK_FS_TYPE_ENUM fsType
Definition: FileSystem.java:34
static void closeFs(long fsHandle)
int read(byte[] buf, long offset, long len)
Definition: FileSystem.java:71
static long openFs(long imgHandle, long fsOffset)
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)
synchronized long getImageHandle()
Definition: Image.java:72

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