blob: 8b6bfae5e8ba4a486e6004f67a8fc00797f435df
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_gpl; |
43 | |
44 | int utils_set_locale(void); |
45 | int utils_parse_size(const char *value, s64 *size, BOOL scale); |
46 | int utils_parse_range(const char *string, s64 *start, s64 *finish, BOOL scale); |
47 | int utils_inode_get_name(ntfs_inode *inode, char *buffer, int bufsize); |
48 | int utils_attr_get_name(ntfs_volume *vol, ATTR_RECORD *attr, char *buffer, int bufsize); |
49 | int utils_cluster_in_use(ntfs_volume *vol, long long lcn); |
50 | int utils_mftrec_in_use(ntfs_volume *vol, MFT_REF mref); |
51 | int utils_is_metadata(ntfs_inode *inode); |
52 | void utils_dump_mem(void *buf, int start, int length, int flags); |
53 | |
54 | ATTR_RECORD * find_attribute(const ATTR_TYPES type, ntfs_attr_search_ctx *ctx); |
55 | ATTR_RECORD * find_first_attribute(const ATTR_TYPES type, MFT_RECORD *mft); |
56 | |
57 | int utils_valid_device(const char *name, int force); |
58 | ntfs_volume * utils_mount_volume(const char *device, unsigned long flags); |
59 | |
60 | /** |
61 | * defines... |
62 | * if *not in use* then the other flags are ignored? |
63 | */ |
64 | #define FEMR_IN_USE (1 << 0) |
65 | #define FEMR_NOT_IN_USE (1 << 1) |
66 | #define FEMR_FILE (1 << 2) // $DATA |
67 | #define FEMR_DIR (1 << 3) // $INDEX_ROOT, "$I30" |
68 | #define FEMR_METADATA (1 << 4) |
69 | #define FEMR_NOT_METADATA (1 << 5) |
70 | #define FEMR_BASE_RECORD (1 << 6) |
71 | #define FEMR_NOT_BASE_RECORD (1 << 7) |
72 | #define FEMR_ALL_RECORDS 0xFF |
73 | |
74 | /** |
75 | * struct mft_search_ctx |
76 | */ |
77 | struct mft_search_ctx { |
78 | int flags_search; |
79 | int flags_match; |
80 | ntfs_inode *inode; |
81 | ntfs_volume *vol; |
82 | u64 mft_num; |
83 | }; |
84 | |
85 | struct mft_search_ctx * mft_get_search_ctx(ntfs_volume *vol); |
86 | void mft_put_search_ctx(struct mft_search_ctx *ctx); |
87 | int mft_next_record(struct mft_search_ctx *ctx); |
88 | |
89 | // Flags for dump mem |
90 | #define DM_DEFAULTS 0 |
91 | #define DM_NO_ASCII (1 << 0) |
92 | #define DM_NO_DIVIDER (1 << 1) |
93 | #define DM_INDENT (1 << 2) |
94 | #define DM_RED (1 << 3) |
95 | #define DM_GREEN (1 << 4) |
96 | #define DM_BLUE (1 << 5) |
97 | #define DM_BOLD (1 << 6) |
98 | |
99 | /* MAX_PATH definition was missing in ntfs-3g's headers. */ |
100 | #ifndef MAX_PATH |
101 | #define MAX_PATH 1024 |
102 | #endif |
103 | |
104 | #ifdef HAVE_WINDOWS_H |
105 | /* |
106 | * Macroes to hide the needs to translate formats on older Windows |
107 | */ |
108 | #define MAX_FMT 1536 |
109 | char *ntfs_utils_reformat(char *out, int sz, const char *fmt); |
110 | #define ntfs_log_redirect(fn,fi,li,le,d,fmt, args...) \ |
111 | do { char buf[MAX_FMT]; ntfs_log_redirect(fn,fi,li,le,d, \ |
112 | ntfs_utils_reformat(buf,MAX_FMT,fmt), args); } while (0) |
113 | #define printf(fmt, args...) \ |
114 | do { char buf[MAX_FMT]; \ |
115 | printf(ntfs_utils_reformat(buf,MAX_FMT,fmt), args); } while (0) |
116 | #define fprintf(str, fmt, args...) \ |
117 | do { char buf[MAX_FMT]; \ |
118 | fprintf(str, ntfs_utils_reformat(buf,MAX_FMT,fmt), args); } while (0) |
119 | #define vfprintf(file, fmt, args) \ |
120 | do { char buf[MAX_FMT]; vfprintf(file, \ |
121 | ntfs_utils_reformat(buf,MAX_FMT,fmt), args); } while (0) |
122 | #endif |
123 | |
124 | /** |
125 | * linux-ntfs's ntfs_mbstoucs has different semantics, so we emulate it with |
126 | * ntfs-3g's. |
127 | */ |
128 | int ntfs_mbstoucs_libntfscompat(const char *ins, |
129 | ntfschar **outs, int outs_len); |
130 | |
131 | /* This simple utility function was missing from libntfs-3g. */ |
132 | static __inline__ ntfschar *ntfs_attr_get_name(ATTR_RECORD *attr) |
133 | { |
134 | return (ntfschar*)((u8*)attr + le16_to_cpu(attr->name_offset)); |
135 | } |
136 | |
137 | #endif /* _NTFS_UTILS_H_ */ |
138 |