Sleuth Kit Java Bindings (JNI)  4.11.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.Collections;
23 import java.util.List;
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(FsContent.class.getName());
42  private volatile String uniquePath;
43  private List<String> metaDataText = null;
44  private volatile FileSystem parentFileSystem;
45 
49  // TODO: Make private.
50  @Deprecated
51  protected final long fsObjId;
52 
57  // TODO: Make private.
58  @Deprecated
59  protected volatile long fileHandle = 0;
60 
113  @SuppressWarnings("deprecation")
115  long objId,
116  long dataSourceObjectId,
117  long fsObjId,
119  String name,
121  long metaAddr, int metaSeq,
124  long size,
125  long ctime, long crtime, long atime, long mtime,
126  short modes, int uid, int gid,
127  String md5Hash, String sha256Hash, FileKnown knownState,
128  String parentPath,
129  String mimeType,
130  String extension,
131  String ownerUid,
132  Long osAccountObjId,
133  List<Attribute> fileAttributes) {
134  super(db, objId, dataSourceObjectId, attrType, attrId, name, fileType, metaAddr, metaSeq, dirType, metaType, dirFlag, metaFlags, size, ctime, crtime, atime, mtime, modes, uid, gid, md5Hash, sha256Hash, knownState, parentPath, mimeType, extension, ownerUid, osAccountObjId, fileAttributes);
135  this.fsObjId = fsObjId;
136  }
137 
143  @SuppressWarnings("deprecation")
144  public long getFileSystemId() {
145  return fsObjId;
146  }
147 
153  void setFileSystem(FileSystem parent) {
154  parentFileSystem = parent;
155  }
156 
164  @SuppressWarnings("deprecation")
166  if (parentFileSystem == null) {
167  synchronized (this) {
168  if (parentFileSystem == null) {
169  parentFileSystem = getSleuthkitCase().getFileSystemById(fsObjId, AbstractContent.UNKNOWN_ID);
170  }
171  }
172  }
173  return parentFileSystem;
174  }
175 
181  @SuppressWarnings("deprecation")
182  void loadFileHandle() throws TskCoreException {
183  if (fileHandle == 0) {
184  synchronized (this) {
185  if (fileHandle == 0) {
186  fileHandle = SleuthkitJNI.openFile(getFileSystem().getFileSystemHandle(), metaAddr, attrType, attrId, getSleuthkitCase());
187  }
188  }
189  }
190  }
191 
198  @SuppressWarnings("deprecation")
199  long getFileHandle() {
200  return fileHandle;
201  }
202 
214  @Override
215  @SuppressWarnings("deprecation")
216  protected synchronized int readInt(byte[] buf, long offset, long len) throws TskCoreException {
217  if (offset == 0 && size == 0) {
218  //special case for 0-size file
219  return 0;
220  }
221  loadFileHandle();
222  return SleuthkitJNI.readFile(fileHandle, buf, offset, len);
223  }
224 
225  @Override
226  public boolean isRoot() {
227  try {
228  FileSystem fs = getFileSystem();
229  return fs.getRoot_inum() == this.getMetaAddr();
230  } catch (TskCoreException ex) {
231  logger.log(Level.SEVERE, "Exception while calling 'getFileSystem' on " + this, ex); //NON-NLS
232  return false;
233  }
234  }
235 
244  public AbstractFile getParentDirectory() throws TskCoreException {
245  return getSleuthkitCase().getParentDirectory(this);
246  }
247 
255  @Override
256  public Content getDataSource() throws TskCoreException {
257  return getFileSystem().getDataSource();
258  }
259 
268  @Override
269  public String getUniquePath() throws TskCoreException {
270  // It is possible that multiple threads could be doing this calculation
271  // simultaneously, but it's worth the potential extra processing to prevent deadlocks.
272  if (uniquePath == null) {
273  StringBuilder sb = new StringBuilder();
274  sb.append(getFileSystem().getUniquePath());
275  sb.append(getParentPath());
276  sb.append(getName());
277  uniquePath = sb.toString();
278  }
279  return uniquePath;
280  }
281 
291  public synchronized List<String> getMetaDataText() throws TskCoreException {
292  if (metaDataText != null) {
293  return metaDataText;
294  }
295 
296  // if there is no metadata for this file, return empty string
297  if (metaAddr == 0) {
298  metaDataText = new ArrayList<String>();
299  metaDataText.add("");
300  return metaDataText;
301  }
302 
303  loadFileHandle();
304  metaDataText = SleuthkitJNI.getFileMetaDataText(fileHandle);
305  return metaDataText;
306  }
307 
311  @Override
312  @SuppressWarnings("deprecation")
313  public synchronized void close() {
314  if (fileHandle != 0) {
315  SleuthkitJNI.closeFile(fileHandle);
316  fileHandle = 0;
317  }
318  }
319 
324  @Override
325  public void finalize() throws Throwable {
326  try {
327  close();
328  } finally {
329  super.finalize();
330  }
331  }
332 
339  @Override
340  @SuppressWarnings("deprecation")
341  public String toString(boolean preserveState) {
342  return super.toString(preserveState)
343  + "FsContent [\t" //NON-NLS
344  + "fsObjId " + fsObjId //NON-NLS
345  + "\t" + "uniquePath " + uniquePath //NON-NLS
346  + "\t" + "fileHandle " + fileHandle //NON-NLS
347  + "]\t";
348  }
349 
389  @Deprecated
390  @SuppressWarnings("deprecation")
391  FsContent(SleuthkitCase db, long objId, long fsObjId, TSK_FS_ATTR_TYPE_ENUM attrType, short attrId,
393  TSK_FS_NAME_FLAG_ENUM dirFlag, short metaFlags, long size, long ctime, long crtime, long atime, long mtime,
394  short modes, int uid, int gid, String md5Hash, FileKnown knownState, String parentPath) {
395  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, null, knownState, parentPath, null, null, OsAccount.NO_OWNER_ID, OsAccount.NO_ACCOUNT, Collections.emptyList() );
396  }
397 
448  @Deprecated
449  @SuppressWarnings("deprecation")
450  FsContent(SleuthkitCase db, long objId, long dataSourceObjectId, long fsObjId, TSK_FS_ATTR_TYPE_ENUM attrType, short attrId,
451  String name, long metaAddr, int metaSeq, TSK_FS_NAME_TYPE_ENUM dirType, TSK_FS_META_TYPE_ENUM metaType,
452  TSK_FS_NAME_FLAG_ENUM dirFlag, short metaFlags, long size, long ctime, long crtime, long atime, long mtime,
453  short modes, int uid, int gid, String md5Hash, FileKnown knownState, String parentPath, String mimeType) {
454  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, null, knownState, parentPath, mimeType, null, OsAccount.NO_OWNER_ID, OsAccount.NO_ACCOUNT, Collections.emptyList());
455  }
456 }
FS
File that can be found in file system tree.
Definition: TskData.java:685
final TSK_FS_NAME_TYPE_ENUM dirType
synchronized int readInt(byte[] buf, long offset, long len)
Definition: FsContent.java:216
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:291
final TskData.TSK_FS_ATTR_TYPE_ENUM attrType
Set< TSK_FS_META_FLAG_ENUM > metaFlags
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-2021 Brian Carrier. (carrier -at- sleuthkit -dot- org)
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.