1 /*
   2  * utils.h - Part of the Linux-NTFS project.
   3  *
   4  * Copyright (c) 2002-2005 Richard Russon
   5  * Copyright (c) 2004 Anton Altaparmakov
   6  *
   7  * A set of shared functions for ntfs utilities
   8  *
   9  * This program is free software; you can redistribute it and/or modify
  10  * it under the terms of the GNU General Public License as published by
  11  * the Free Software Foundation; either version 2 of the License, or
  12  * (at your option) any later version.
  13  *
  14  * This program is distributed in the hope that it will be useful,
  15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17  * GNU General Public License for more details.
  18  *
  19  * You should have received a copy of the GNU General Public License
  20  * along with this program (in the main directory of the Linux-NTFS
  21  * distribution in the file COPYING); if not, write to the Free Software
  22  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  23  */
  24 
  25 #ifndef _NTFS_UTILS_H_
  26 #define _NTFS_UTILS_H_
  27 
  28 #include "config.h"
  29 
  30 #include "types.h"
  31 #include "layout.h"
  32 #include "volume.h"
  33 
  34 #ifdef HAVE_ERRNO_H
  35 #include <errno.h>
  36 #endif
  37 #ifdef HAVE_STDARG_H
  38 #include <stdarg.h>
  39 #endif
  40 
  41 extern const char *ntfs_bugs;
  42 extern const char *ntfs_home;
  43 extern const char *ntfs_gpl;
  44 
  45 int utils_set_locale(void);
  46 int utils_parse_size(const char *value, s64 *size, BOOL scale);
  47 int utils_parse_range(const char *string, s64 *start, s64 *finish, BOOL scale);
  48 int utils_inode_get_name(ntfs_inode *inode, char *buffer, int bufsize);
  49 int utils_attr_get_name(ntfs_volume *vol, ATTR_RECORD *attr, char *buffer, int bufsize);
  50 int utils_cluster_in_use(ntfs_volume *vol, long long lcn);
  51 int utils_mftrec_in_use(ntfs_volume *vol, MFT_REF mref);
  52 int utils_is_metadata(ntfs_inode *inode);
  53 void utils_dump_mem(void *buf, int start, int length, int flags);
  54 
  55 ATTR_RECORD * find_attribute(const ATTR_TYPES type, ntfs_attr_search_ctx *ctx);
  56 ATTR_RECORD * find_first_attribute(const ATTR_TYPES type, MFT_RECORD *mft);
  57 
  58 int utils_valid_device(const char *name, int force);
  59 ntfs_volume * utils_mount_volume(const char *device, ntfs_mount_flags flags);
  60 
  61 /**
  62  * defines...
  63  * if *not in use* then the other flags are ignored?
  64  */
  65 #define FEMR_IN_USE             (1 << 0)
  66 #define FEMR_NOT_IN_USE         (1 << 1)
  67 #define FEMR_FILE               (1 << 2)          // $DATA
  68 #define FEMR_DIR                (1 << 3)          // $INDEX_ROOT, "$I30"
  69 #define FEMR_METADATA           (1 << 4)
  70 #define FEMR_NOT_METADATA       (1 << 5)
  71 #define FEMR_BASE_RECORD        (1 << 6)
  72 #define FEMR_NOT_BASE_RECORD    (1 << 7)
  73 #define FEMR_ALL_RECORDS        0xFF
  74 
  75 /**
  76  * struct mft_search_ctx
  77  */
  78 struct mft_search_ctx {
  79         int flags_search;
  80         int flags_match;
  81         ntfs_inode *inode;
  82         ntfs_volume *vol;
  83         u64 mft_num;
  84 };
  85 
  86 struct mft_search_ctx * mft_get_search_ctx(ntfs_volume *vol);
  87 void mft_put_search_ctx(struct mft_search_ctx *ctx);
  88 int mft_next_record(struct mft_search_ctx *ctx);
  89 
  90 // Flags for dump mem
  91 #define DM_DEFAULTS     0
  92 #define DM_NO_ASCII     (1 << 0)
  93 #define DM_NO_DIVIDER   (1 << 1)
  94 #define DM_INDENT       (1 << 2)
  95 #define DM_RED          (1 << 3)
  96 #define DM_GREEN        (1 << 4)
  97 #define DM_BLUE         (1 << 5)
  98 #define DM_BOLD         (1 << 6)
  99 
 100 #endif /* _NTFS_UTILS_H_ */