"Fossies" - the Fresh Open Source Software Archive

Member "ntfsprogs-1.12.1/ntfsprogs/utils.h" (30 Sep 2005, 4209 Bytes) of package /linux/misc/old/ntfsprogs-1.12.1.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "utils.h" see the Fossies "Dox" file reference documentation.

    1 /*
    2  * utils.h - Part of the Linux-NTFS project.
    3  *
    4  * Copyright (c) 2002-2003 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 #include <errno.h>
   35 #include <stdarg.h>
   36 #include <regex.h>
   37 
   38 extern const char *ntfs_bugs;
   39 extern const char *ntfs_home;
   40 extern const char *ntfs_gpl;
   41 
   42 #if !defined(REG_NOERROR) || (REG_NOERROR != 0)
   43 #   define REG_NOERROR 0
   44 #endif
   45 
   46 #define DEC_PRINTF(NAME)                            \
   47     int NAME (const char *format, ...)                  \
   48     __attribute__ ((format (printf, 1, 2)));
   49 
   50 #define GEN_PRINTF(NAME, STREAM, CONTROL, TRIGGER)              \
   51     __attribute__ ((format (printf, 1, 2)))                 \
   52     int NAME (const char *format, ...)                  \
   53     {                                   \
   54         int ret, olderr = errno, *control = (CONTROL);          \
   55         va_list args;                           \
   56                                         \
   57         if (!(STREAM))                          \
   58             return -1;                      \
   59         if (control &&                          \
   60            ((*control && !(TRIGGER)) || (!*control && (TRIGGER))))  \
   61             return -1;                      \
   62                                         \
   63         va_start (args, format);                    \
   64         ret = vfprintf ((STREAM), format, args);            \
   65         va_end (args);                          \
   66         errno = olderr;                         \
   67         return ret;                         \
   68     }
   69 
   70 /* utils.c's utilities require the following functions implemented.
   71  * Example of implementation is:
   72  *  GEN_PRINTF (Eprintf, stderr, NULL,          FALSE)
   73  *  GEN_PRINTF (Vprintf, stderr, &opts.verbose, TRUE)
   74  *  GEN_PRINTF (Qprintf, stderr, &opts.quiet,   FALSE)
   75  */
   76 extern DEC_PRINTF(Eprintf)
   77 extern DEC_PRINTF(Vprintf)
   78 extern DEC_PRINTF(Qprintf)
   79 
   80 int utils_valid_device (const char *name, int force);
   81 int utils_set_locale (void);
   82 ntfs_volume * utils_mount_volume (const char *device, unsigned long flags, BOOL force);
   83 int utils_parse_size (const char *value, s64 *size, BOOL scale);
   84 int utils_parse_range (const char *string, s64 *start, s64 *finish, BOOL scale);
   85 int utils_inode_get_name (ntfs_inode *inode, char *buffer, int bufsize);
   86 int utils_attr_get_name (ntfs_volume *vol, ATTR_RECORD *attr, char *buffer, int bufsize);
   87 int utils_cluster_in_use (ntfs_volume *vol, long long lcn);
   88 int utils_mftrec_in_use (ntfs_volume *vol, MFT_REF mref);
   89 int utils_is_metadata (ntfs_inode *inode);
   90 void utils_dump_mem (void *buf, int start, int length, int ascii);
   91 
   92 ATTR_RECORD * find_attribute (const ATTR_TYPES type, ntfs_attr_search_ctx *ctx);
   93 ATTR_RECORD * find_first_attribute (const ATTR_TYPES type, MFT_RECORD *mft);
   94 
   95 /**
   96  * defines...
   97  * if *not in use* then the other flags are ignored?
   98  */
   99 #define FEMR_IN_USE     1 << 0
  100 #define FEMR_NOT_IN_USE     1 << 1
  101 #define FEMR_FILE       1 << 2      // $DATA
  102 #define FEMR_DIR        1 << 3      // $INDEX_ROOT, "$I30"
  103 #define FEMR_METADATA       1 << 4
  104 #define FEMR_NOT_METADATA   1 << 5
  105 #define FEMR_BASE_RECORD    1 << 6
  106 #define FEMR_NOT_BASE_RECORD    1 << 7
  107 #define FEMR_ALL_RECORDS    0xFF
  108 
  109 /**
  110  * struct mft_search_ctx
  111  */
  112 struct mft_search_ctx {
  113     int flags_search;
  114     int flags_match;
  115     ntfs_inode *inode;
  116     ntfs_volume *vol;
  117     u64 mft_num;
  118 };
  119 
  120 struct mft_search_ctx * mft_get_search_ctx (ntfs_volume *vol);
  121 void mft_put_search_ctx (struct mft_search_ctx *ctx);
  122 int mft_next_record (struct mft_search_ctx *ctx);
  123 
  124 // Flags for dump mem
  125 #define DM_DEFAULTS 0
  126 #define DM_NO_ASCII (1 << 0)
  127 #define DM_NO_DIVIDER   (1 << 1)
  128 #define DM_INDENT   (1 << 2)
  129 #define DM_RED      (1 << 3)
  130 #define DM_GREEN    (1 << 4)
  131 #define DM_BLUE     (1 << 5)
  132 #define DM_BOLD     (1 << 6)
  133 
  134 #endif /* _NTFS_UTILS_H_ */