Sleuth Kit Java Bindings (JNI)  4.10.0
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-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.ArrayList;
22 import java.util.List;
23 import java.util.logging.Level;
24 import java.util.logging.Logger;
31 
38 public abstract class FsContent extends AbstractFile {
39 
40  private static final Logger logger = Logger.getLogger(FsContent.class.getName());
41  private String uniquePath;
42  private List<String> metaDataText = null;
43  private volatile FileSystem parentFileSystem;
44 
48  // TODO: Make private.
49  @Deprecated
50  protected final long fsObjId;
51 
56  // TODO: Make private.
57  @Deprecated
58  protected volatile long fileHandle = 0;
59 
109  @SuppressWarnings("deprecation")
111  long objId,
112  long dataSourceObjectId,
113  long fsObjId,
115  String name,
117  long metaAddr, int metaSeq,
120  long size,
121  long ctime, long crtime, long atime, long mtime,
122  short modes, int uid, int gid,
123  String md5Hash, FileKnown knownState,
124  String parentPath,
125  String mimeType,
126  String extension) {
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, extension);
128  this.fsObjId = fsObjId;
129  }
130 
136  @SuppressWarnings("deprecation")
137  public long getFileSystemId() {
138  return fsObjId;
139  }
140 
146  void setFileSystem(FileSystem parent) {
147  parentFileSystem = parent;
148  }
149 
157  @SuppressWarnings("deprecation")
159  if (parentFileSystem == null) {
160  synchronized (this) {
161  if (parentFileSystem == null) {
162  parentFileSystem = getSleuthkitCase().getFileSystemById(fsObjId, AbstractContent.UNKNOWN_ID);
163  }
164  }
165  }
166  return parentFileSystem;
167  }
168 
174  @SuppressWarnings("deprecation")
175  void loadFileHandle() throws TskCoreException {
176  if (fileHandle == 0) {
177  synchronized (this) {
178  if (fileHandle == 0) {
179  fileHandle = SleuthkitJNI.openFile(getFileSystem().getFileSystemHandle(), metaAddr, attrType, attrId, getSleuthkitCase());
180  }
181  }
182  }
183  }
184 
191  @SuppressWarnings("deprecation")
192  long getFileHandle() {
193  return fileHandle;
194  }
195 
207  @Override
208  @SuppressWarnings("deprecation")
209  protected synchronized int readInt(byte[] buf, long offset, long len) throws TskCoreException {
210  if (offset == 0 && size == 0) {
211  //special case for 0-size file
212  return 0;
213  }
214  loadFileHandle();
215  return SleuthkitJNI.readFile(fileHandle, buf, offset, len);
216  }
217 
218  @Override
219  public boolean isRoot() {
220  try {
221  FileSystem fs = getFileSystem();
222  return fs.getRoot_inum() == this.getMetaAddr();
223  } catch (TskCoreException ex) {
224  logger.log(Level.SEVERE, "Exception while calling 'getFileSystem' on " + this, ex); //NON-NLS
225  return false;
226  }
227  }
228 
237  public AbstractFile getParentDirectory() throws TskCoreException {
238  return getSleuthkitCase().getParentDirectory(this);
239  }
240 
248  @Override
249  public Content getDataSource() throws TskCoreException {
250  return getFileSystem().getDataSource();
251  }
252 
261  @Override
262  public synchronized String getUniquePath() throws TskCoreException {
263  if (uniquePath == null) {
264  StringBuilder sb = new StringBuilder();
265  sb.append(getFileSystem().getUniquePath());
266  sb.append(getParentPath());
267  sb.append(getName());
268  uniquePath = sb.toString();
269  }
270  return uniquePath;
271  }
272 
282  public synchronized List<String> getMetaDataText() throws TskCoreException {
283  if (metaDataText != null) {
284  return metaDataText;
285  }
286 
287  // if there is no metadata for this file, return empty string
288  if (metaAddr == 0) {
289  metaDataText = new ArrayList<String>();
290  metaDataText.add("");
291  return metaDataText;
292  }
293 
294  loadFileHandle();
295  metaDataText = SleuthkitJNI.getFileMetaDataText(fileHandle);
296  return metaDataText;
297  }
298 
302  @Override
303  @SuppressWarnings("deprecation")
304  public synchronized void close() {
305  if (fileHandle != 0) {
306  SleuthkitJNI.closeFile(fileHandle);
307  fileHandle = 0;
308  }
309  }
310 
315  @Override
316  public void finalize() throws Throwable {
317  try {
318  close();
319  } finally {
320  super.finalize();
321  }
322  }
323 
330  @Override
331  @SuppressWarnings("deprecation")
332  public String toString(boolean preserveState) {
333  return super.toString(preserveState)
334  + "FsContent [\t" //NON-NLS
335  + "fsObjId " + fsObjId //NON-NLS
336  + "\t" + "uniquePath " + uniquePath //NON-NLS
337  + "\t" + "fileHandle " + fileHandle //NON-NLS
338  + "]\t";
339  }
340 
380  @Deprecated
381  @SuppressWarnings("deprecation")
382  FsContent(SleuthkitCase db, long objId, long fsObjId, TSK_FS_ATTR_TYPE_ENUM attrType, short attrId,
384  TSK_FS_NAME_FLAG_ENUM dirFlag, short metaFlags, long size, long ctime, long crtime, long atime, long mtime,
385  short modes, int uid, int gid, String md5Hash, FileKnown knownState, String parentPath) {
386  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, null);
387  }
388 
439  @Deprecated
440  @SuppressWarnings("deprecation")
441  FsContent(SleuthkitCase db, long objId, long dataSourceObjectId, long fsObjId, TSK_FS_ATTR_TYPE_ENUM attrType, short attrId,
442  String name, long metaAddr, int metaSeq, TSK_FS_NAME_TYPE_ENUM dirType, TSK_FS_META_TYPE_ENUM metaType,
443  TSK_FS_NAME_FLAG_ENUM dirFlag, short metaFlags, long size, long ctime, long crtime, long atime, long mtime,
444  short modes, int uid, int gid, String md5Hash, FileKnown knownState, String parentPath, String mimeType) {
445  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, null);
446  }
447 }
FS
File that can be found in file system tree.
Definition: TskData.java:676
final TSK_FS_NAME_TYPE_ENUM dirType
synchronized int readInt(byte[] buf, long offset, long len)
Definition: FsContent.java:209
final TSK_FS_NAME_FLAG_ENUM dirFlag
static long openFile(long fsHandle, long fileId, TSK_FS_ATTR_TYPE_ENUM attrType, int attrId, SleuthkitCase skCase)
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:282
final TskData.TSK_FS_ATTR_TYPE_ENUM attrType
final Set< TSK_FS_META_FLAG_ENUM > metaFlags
synchronized String getUniquePath()
Definition: FsContent.java:262
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-2020 Brian Carrier. (carrier -at- sleuthkit -dot- org)
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.