Sleuth Kit Java Bindings (JNI)  4.2
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 
88  long getFileSystemHandle() throws TskCoreException {
89  if (filesystemHandle == 0) {
90  synchronized (this) {
91  if (filesystemHandle == 0) {
92  Content dataSource = getDataSource();
93  if ((dataSource != null) && (dataSource instanceof Image)) {
94  Image image = (Image) dataSource;
95  filesystemHandle = SleuthkitJNI.openFs(image.getImageHandle(), imgOffset);
96  } else {
97  throw new TskCoreException("Data Source of File System is not an image");
98  }
99  }
100  }
101  }
102  return this.filesystemHandle;
103  }
104 
105  public Directory getRootDirectory() throws TskCoreException {
106 
107  List<Content> children = getChildren();
108  if (children.size() != 1) {
109  throw new TskCoreException("FileSystem must have only one child.");
110  }
111 
112  if (!(children.get(0) instanceof Directory)) {
113  throw new TskCoreException("Child of FileSystem must be a Directory.");
114  }
115 
116  return (Directory) children.get(0);
117  }
118 
124  public long getImageOffset() {
125  return imgOffset;
126  }
127 
134  return fsType;
135  }
136 
142  public long getBlock_size() {
143  return blockSize;
144  }
145 
151  public long getBlock_count() {
152  return blockCount;
153  }
154 
160  public long getRoot_inum() {
161  return rootInum;
162  }
163 
169  public long getFirst_inum() {
170  return firstInum;
171  }
172 
178  public long getLastInum() {
179  return lastInum;
180  }
181 
182  @Override
183  public void finalize() throws Throwable {
184  try {
185  if (filesystemHandle != 0) {
186  SleuthkitJNI.closeFs(filesystemHandle);
187  filesystemHandle = 0;
188  }
189  } finally {
190  super.finalize();
191  }
192  }
193 
194  @Override
195  public <T> T accept(SleuthkitItemVisitor<T> v) {
196  return v.visit(this);
197  }
198 
199  @Override
200  public <T> T accept(ContentVisitor<T> v) {
201  return v.visit(this);
202  }
203 
204  @Override
205  public List<Content> getChildren() throws TskCoreException {
206  return getSleuthkitCase().getAbstractFileChildren(this);
207  }
208 
209  @Override
210  public List<Long> getChildrenIds() throws TskCoreException {
211  return getSleuthkitCase().getAbstractFileChildrenIds(this);
212  }
213 
214  @Override
215  public String toString(boolean preserveState) {
216  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
217  }
218 }
String toString(boolean preserveState)
TskData.TSK_FS_TYPE_ENUM fsType
Definition: FileSystem.java:34
static void closeFs(long fsHandle)
static synchronized long openFs(long imgHandle, long fsOffset)
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)
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.