2003-01-09 09:42:21 +08:00
|
|
|
/*
|
2003-01-20 06:01:18 +08:00
|
|
|
* utils.h - Part of the Linux-NTFS project.
|
2003-01-09 09:42:21 +08:00
|
|
|
*
|
2005-10-17 07:33:03 +08:00
|
|
|
* Copyright (c) 2002-2005 Richard Russon
|
2004-02-20 22:44:16 +08:00
|
|
|
* Copyright (c) 2004 Anton Altaparmakov
|
2003-01-09 09:42:21 +08:00
|
|
|
*
|
2003-01-20 06:01:18 +08:00
|
|
|
* A set of shared functions for ntfs utilities
|
2003-01-09 09:42:21 +08:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program (in the main directory of the Linux-NTFS
|
|
|
|
* distribution in the file COPYING); if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _NTFS_UTILS_H_
|
|
|
|
#define _NTFS_UTILS_H_
|
|
|
|
|
2004-02-20 22:44:16 +08:00
|
|
|
#include "config.h"
|
|
|
|
|
2010-12-15 19:03:51 +08:00
|
|
|
#include "types.h"
|
|
|
|
#include "layout.h"
|
|
|
|
#include "volume.h"
|
2003-01-14 04:05:15 +08:00
|
|
|
|
2005-10-22 02:05:13 +08:00
|
|
|
#ifdef HAVE_ERRNO_H
|
2003-01-19 19:32:24 +08:00
|
|
|
#include <errno.h>
|
2005-10-22 02:05:13 +08:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_STDARG_H
|
2003-01-19 19:32:24 +08:00
|
|
|
#include <stdarg.h>
|
2005-10-22 02:05:13 +08:00
|
|
|
#endif
|
2003-01-19 19:32:24 +08:00
|
|
|
|
2003-01-19 19:48:06 +08:00
|
|
|
extern const char *ntfs_bugs;
|
|
|
|
extern const char *ntfs_gpl;
|
|
|
|
|
2005-10-27 04:48:00 +08:00
|
|
|
int utils_set_locale(void);
|
|
|
|
int utils_parse_size(const char *value, s64 *size, BOOL scale);
|
|
|
|
int utils_parse_range(const char *string, s64 *start, s64 *finish, BOOL scale);
|
|
|
|
int utils_inode_get_name(ntfs_inode *inode, char *buffer, int bufsize);
|
|
|
|
int utils_attr_get_name(ntfs_volume *vol, ATTR_RECORD *attr, char *buffer, int bufsize);
|
|
|
|
int utils_cluster_in_use(ntfs_volume *vol, long long lcn);
|
|
|
|
int utils_mftrec_in_use(ntfs_volume *vol, MFT_REF mref);
|
|
|
|
int utils_is_metadata(ntfs_inode *inode);
|
2005-10-28 20:47:49 +08:00
|
|
|
void utils_dump_mem(void *buf, int start, int length, int flags);
|
2003-01-09 09:42:21 +08:00
|
|
|
|
2005-10-27 04:48:00 +08:00
|
|
|
ATTR_RECORD * find_attribute(const ATTR_TYPES type, ntfs_attr_search_ctx *ctx);
|
|
|
|
ATTR_RECORD * find_first_attribute(const ATTR_TYPES type, MFT_RECORD *mft);
|
2005-10-17 07:33:03 +08:00
|
|
|
|
2005-10-27 04:48:00 +08:00
|
|
|
int utils_valid_device(const char *name, int force);
|
2011-01-10 18:19:54 +08:00
|
|
|
ntfs_volume * utils_mount_volume(const char *device, unsigned long flags);
|
2003-01-09 09:42:21 +08:00
|
|
|
|
2003-10-11 23:31:25 +08:00
|
|
|
/**
|
|
|
|
* defines...
|
|
|
|
* if *not in use* then the other flags are ignored?
|
|
|
|
*/
|
2005-10-28 21:00:48 +08:00
|
|
|
#define FEMR_IN_USE (1 << 0)
|
|
|
|
#define FEMR_NOT_IN_USE (1 << 1)
|
|
|
|
#define FEMR_FILE (1 << 2) // $DATA
|
|
|
|
#define FEMR_DIR (1 << 3) // $INDEX_ROOT, "$I30"
|
|
|
|
#define FEMR_METADATA (1 << 4)
|
|
|
|
#define FEMR_NOT_METADATA (1 << 5)
|
|
|
|
#define FEMR_BASE_RECORD (1 << 6)
|
|
|
|
#define FEMR_NOT_BASE_RECORD (1 << 7)
|
2003-10-11 23:31:25 +08:00
|
|
|
#define FEMR_ALL_RECORDS 0xFF
|
|
|
|
|
|
|
|
/**
|
|
|
|
* struct mft_search_ctx
|
|
|
|
*/
|
|
|
|
struct mft_search_ctx {
|
|
|
|
int flags_search;
|
|
|
|
int flags_match;
|
|
|
|
ntfs_inode *inode;
|
|
|
|
ntfs_volume *vol;
|
2004-08-20 20:01:17 +08:00
|
|
|
u64 mft_num;
|
2003-10-11 23:31:25 +08:00
|
|
|
};
|
|
|
|
|
2005-10-27 04:48:00 +08:00
|
|
|
struct mft_search_ctx * mft_get_search_ctx(ntfs_volume *vol);
|
|
|
|
void mft_put_search_ctx(struct mft_search_ctx *ctx);
|
|
|
|
int mft_next_record(struct mft_search_ctx *ctx);
|
2003-10-11 23:31:25 +08:00
|
|
|
|
2004-06-24 21:08:28 +08:00
|
|
|
// Flags for dump mem
|
|
|
|
#define DM_DEFAULTS 0
|
|
|
|
#define DM_NO_ASCII (1 << 0)
|
|
|
|
#define DM_NO_DIVIDER (1 << 1)
|
|
|
|
#define DM_INDENT (1 << 2)
|
|
|
|
#define DM_RED (1 << 3)
|
|
|
|
#define DM_GREEN (1 << 4)
|
|
|
|
#define DM_BLUE (1 << 5)
|
|
|
|
#define DM_BOLD (1 << 6)
|
|
|
|
|
2010-01-15 16:33:54 +08:00
|
|
|
/* MAX_PATH definition was missing in ntfs-3g's headers. */
|
|
|
|
#ifndef MAX_PATH
|
|
|
|
#define MAX_PATH 1024
|
|
|
|
#endif
|
|
|
|
|
2013-02-09 19:57:22 +08:00
|
|
|
#ifdef HAVE_WINDOWS_H
|
|
|
|
/*
|
|
|
|
* Macroes to hide the needs to translate formats on older Windows
|
|
|
|
*/
|
2013-04-23 00:31:16 +08:00
|
|
|
#define MAX_FMT 1536
|
2013-02-09 19:57:22 +08:00
|
|
|
char *ntfs_utils_reformat(char *out, int sz, const char *fmt);
|
2015-04-17 15:15:25 +08:00
|
|
|
char *ntfs_utils_unix_path(const char *in);
|
2013-02-09 19:57:22 +08:00
|
|
|
#define ntfs_log_redirect(fn,fi,li,le,d,fmt, args...) \
|
2015-09-30 15:08:35 +08:00
|
|
|
do { char _b[MAX_FMT]; ntfs_log_redirect(fn,fi,li,le,d, \
|
|
|
|
ntfs_utils_reformat(_b,MAX_FMT,fmt), args); } while (0)
|
2013-02-09 19:57:22 +08:00
|
|
|
#define printf(fmt, args...) \
|
2015-09-30 15:08:35 +08:00
|
|
|
do { char _b[MAX_FMT]; \
|
|
|
|
printf(ntfs_utils_reformat(_b,MAX_FMT,fmt), args); } while (0)
|
2013-02-09 19:57:22 +08:00
|
|
|
#define fprintf(str, fmt, args...) \
|
2015-09-30 15:08:35 +08:00
|
|
|
do { char _b[MAX_FMT]; \
|
|
|
|
fprintf(str, ntfs_utils_reformat(_b,MAX_FMT,fmt), args); } while (0)
|
2013-02-09 19:57:22 +08:00
|
|
|
#define vfprintf(file, fmt, args) \
|
2015-09-30 15:08:35 +08:00
|
|
|
do { char _b[MAX_FMT]; vfprintf(file, \
|
|
|
|
ntfs_utils_reformat(_b,MAX_FMT,fmt), args); } while (0)
|
2013-02-09 19:57:22 +08:00
|
|
|
#endif
|
|
|
|
|
2010-01-15 16:33:54 +08:00
|
|
|
/**
|
|
|
|
* linux-ntfs's ntfs_mbstoucs has different semantics, so we emulate it with
|
|
|
|
* ntfs-3g's.
|
|
|
|
*/
|
2010-12-21 22:51:07 +08:00
|
|
|
int ntfs_mbstoucs_libntfscompat(const char *ins,
|
|
|
|
ntfschar **outs, int outs_len);
|
2010-01-15 16:33:54 +08:00
|
|
|
|
2010-12-02 14:37:40 +08:00
|
|
|
/* This simple utility function was missing from libntfs-3g. */
|
|
|
|
static __inline__ ntfschar *ntfs_attr_get_name(ATTR_RECORD *attr)
|
|
|
|
{
|
|
|
|
return (ntfschar*)((u8*)attr + le16_to_cpu(attr->name_offset));
|
|
|
|
}
|
|
|
|
|
2003-01-09 09:42:21 +08:00
|
|
|
#endif /* _NTFS_UTILS_H_ */
|