Sleuth Kit Java Bindings (JNI)  4.3
Java bindings for using The Sleuth Kit
FsContent.java
Go to the documentation of this file.
1 /*
2  * SleuthKit Java Bindings
3  *
4  * Copyright 2011-2016 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.ArrayList;
22 import java.util.List;
23 import java.util.ResourceBundle;
24 import java.util.logging.Level;
25 import java.util.logging.Logger;
32 
39 public abstract class FsContent extends AbstractFile {
40 
41  private static final Logger logger = Logger.getLogger(AbstractFile.class.getName());
42  private static final ResourceBundle bundle = ResourceBundle.getBundle("org.sleuthkit.datamodel.Bundle");
43  private String uniquePath;
44  private final SleuthkitCase tskCase;
45  private List<String> metaDataText = null;
46  private volatile FileSystem parentFileSystem;
47 
51  // TODO: Make private.
52  @Deprecated
53  protected final long fsObjId;
54 
59  // TODO: Make private.
60  @Deprecated
61  protected volatile long fileHandle = 0;
62 
110  @SuppressWarnings("deprecation")
112  long objId,
113  long dataSourceObjectId,
114  long fsObjId,
116  String name,
118  long metaAddr, int metaSeq,
121  long size,
122  long ctime, long crtime, long atime, long mtime,
123  short modes, int uid, int gid,
124  String md5Hash, FileKnown knownState,
125  String parentPath,
126  String mimeType) {
127  super(db, objId, dataSourceObjectId, attrType, attrId, name, fileType, metaAddr, metaSeq, dirType, metaType, dirFlag, metaFlags, size, ctime, crtime, atime, mtime, modes, uid, gid, md5Hash, knownState, parentPath, mimeType);
128  this.tskCase = db;
129  this.fsObjId = fsObjId;
130  }
131 
137  @SuppressWarnings("deprecation")
138  public long getFileSystemId() {
139  return fsObjId;
140  }
141 
147  void setFileSystem(FileSystem parent) {
148  parentFileSystem = parent;
149  }
150 
158  @SuppressWarnings("deprecation")
160  if (parentFileSystem == null) {
161  synchronized (this) {
162  if (parentFileSystem == null) {
163  parentFileSystem = getSleuthkitCase().getFileSystemById(fsObjId, AbstractContent.UNKNOWN_ID);
164  }
165  }
166  }
167  return parentFileSystem;
168  }
169 
175  @SuppressWarnings("deprecation")
176  void loadFileHandle() throws TskCoreException {
177  if (fileHandle == 0) {
178  synchronized (this) {
179  if (fileHandle == 0) {
180  fileHandle = SleuthkitJNI.openFile(getFileSystem().getFileSystemHandle(), metaAddr, attrType, attrId);
181  }
182  }
183  }
184  }
185 
192  @SuppressWarnings("deprecation")
193  long getFileHandle() {
194  return fileHandle;
195  }
196 
208  @Override
209  @SuppressWarnings("deprecation")
210  protected int readInt(byte[] buf, long offset, long len) throws TskCoreException {
211  if (offset == 0 && size == 0) {
212  //special case for 0-size file
213  return 0;
214  }
215  loadFileHandle();
216  return SleuthkitJNI.readFile(fileHandle, buf, offset, len);
217  }
218 
219  @Override
220  public boolean isRoot() {
221  try {
222  FileSystem fs = getFileSystem();
223  return fs.getRoot_inum() == this.getMetaAddr();
224  } catch (TskCoreException ex) {
225  logger.log(Level.SEVERE, "Exception while calling 'getFileSystem' on " + this, ex); //NON-NLS
226  return false;
227  }
228  }
229 
238  public AbstractFile getParentDirectory() throws TskCoreException {
239  return getSleuthkitCase().getParentDirectory(this);
240  }
241 
249  @Override
250  public Content getDataSource() throws TskCoreException {
251  return getFileSystem().getDataSource();
252  }
253 
260  @Override
261  public synchronized String getUniquePath() throws TskCoreException {
262  if (uniquePath == null) {
263  StringBuilder sb = new StringBuilder();
264  sb.append(getFileSystem().getUniquePath());
265  sb.append(getParentPath());
266  sb.append(getName());
267  uniquePath = sb.toString();
268  }
269  return uniquePath;
270  }
271 
281  public synchronized List<String> getMetaDataText() throws TskCoreException {
282  if (metaDataText != null) {
283  return metaDataText;
284  }
285 
286  // if there is no metadata for this file, return empty string
287  if (metaAddr == 0) {
288  metaDataText = new ArrayList<String>();
289  metaDataText.add("");
290  return metaDataText;
291  }
292 
293  loadFileHandle();
294  metaDataText = SleuthkitJNI.getFileMetaDataText(fileHandle);
295  return metaDataText;
296  }
297 
301  @Override
302  @SuppressWarnings("deprecation")
303  public void close() {
304  if (fileHandle != 0) {
305  synchronized (this) {
306  //need to recheck the handle after unlock
307  if (fileHandle != 0) {
308  SleuthkitJNI.closeFile(fileHandle);
309  fileHandle = 0;
310  }
311  }
312  }
313  }
314 
319  @Override
320  public void finalize() throws Throwable {
321  try {
322  close();
323  } finally {
324  super.finalize();
325  }
326  }
327 
337  @Override
338  @SuppressWarnings("deprecation")
339  public String toString(boolean preserveState) {
340  return super.toString(preserveState)
341  + "FsContent [\t" //NON-NLS
342  + "fsObjId " + fsObjId //NON-NLS
343  + "\t" + "uniquePath " + uniquePath //NON-NLS
344  + "\t" + "fileHandle " + fileHandle //NON-NLS
345  + "]\t";
346  }
347 
387  @Deprecated
388  @SuppressWarnings("deprecation")
391  TSK_FS_NAME_FLAG_ENUM dirFlag, short metaFlags, long size, long ctime, long crtime, long atime, long mtime,
392  short modes, int uid, int gid, String md5Hash, FileKnown knownState, String parentPath) {
393  this(db, objId, db.getDataSourceObjectId(objId), fsObjId, attrType, (int) attrId, name, TSK_DB_FILES_TYPE_ENUM.FS, metaAddr, metaSeq, dirType, metaType, dirFlag, metaFlags, size, ctime, crtime, atime, mtime, modes, uid, gid, md5Hash, knownState, parentPath, null);
394  }
395 
445  @Deprecated
446  @SuppressWarnings("deprecation")
447  FsContent(SleuthkitCase db, long objId, long dataSourceObjectId, long fsObjId, TSK_FS_ATTR_TYPE_ENUM attrType, short attrId,
448  String name, long metaAddr, int metaSeq, TSK_FS_NAME_TYPE_ENUM dirType, TSK_FS_META_TYPE_ENUM metaType,
449  TSK_FS_NAME_FLAG_ENUM dirFlag, short metaFlags, long size, long ctime, long crtime, long atime, long mtime,
450  short modes, int uid, int gid, String md5Hash, FileKnown knownState, String parentPath, String mimeType) {
451  this(db, objId, dataSourceObjectId, fsObjId, attrType, (int) attrId, name, TSK_DB_FILES_TYPE_ENUM.FS, metaAddr, metaSeq, dirType, metaType, dirFlag, metaFlags, size, ctime, crtime, atime, mtime, modes, uid, gid, md5Hash, knownState, parentPath, mimeType);
452  }
453 }
FS
File that can be found in file system tree.
Definition: TskData.java:656
final TSK_FS_NAME_TYPE_ENUM dirType
static final Logger logger
Definition: FsContent.java:41
static final ResourceBundle bundle
Definition: FsContent.java:42
int readInt(byte[] buf, long offset, long len)
Definition: FsContent.java:210
final SleuthkitCase tskCase
Definition: FsContent.java:44
final TSK_FS_NAME_FLAG_ENUM dirFlag
static long openFile(long fsHandle, long fileId, TSK_FS_ATTR_TYPE_ENUM attrType, int attrId)
static int readFile(long fileHandle, byte[] readBuffer, long offset, long len)
final TskData.TSK_DB_FILES_TYPE_ENUM fileType
synchronized List< String > getMetaDataText()
Definition: FsContent.java:281
final TskData.TSK_FS_ATTR_TYPE_ENUM attrType
volatile FileSystem parentFileSystem
Definition: FsContent.java:46
final Set< TSK_FS_META_FLAG_ENUM > metaFlags
synchronized String getUniquePath()
Definition: FsContent.java:261
final Set< TskData.TSK_FS_META_MODE_ENUM > modes
static List< String > getFileMetaDataText(long fileHandle)
static void closeFile(long fileHandle)
final TSK_FS_META_TYPE_ENUM metaType

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.