-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathntfs.h
More file actions
306 lines (261 loc) · 8.96 KB
/
ntfs.h
File metadata and controls
306 lines (261 loc) · 8.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
/* SPDX-License-Identifier: GPL-2.0-or-later */
/*
* Defines for NTFS Linux kernel driver.
*
* Copyright (c) 2001-2014 Anton Altaparmakov and Tuxera Inc.
* Copyright (C) 2002 Richard Russon
* Copyright (c) 2025 LG Electronics Co., Ltd.
*/
#ifndef _LINUX_NTFS_H
#define _LINUX_NTFS_H
#include <linux/stddef.h>
#include <linux/kernel.h>
#include <linux/version.h>
#if LINUX_VERSION_CODE >= KERNEL_VERSION(7, 0, 0)
#include <linux/hex.h>
#endif
#include <linux/module.h>
#include <linux/compiler.h>
#include <linux/fs.h>
#include <linux/nls.h>
#include <linux/smp.h>
#include <linux/pagemap.h>
#include <linux/uidgid.h>
#include "volume.h"
#include "layout.h"
#include "inode.h"
#ifdef pr_fmt
#undef pr_fmt
#endif
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
/*
* Default pre-allocation size is optimize runlist merge overhead
* with small chunk size.
*/
#define NTFS_DEF_PREALLOC_SIZE 65536
/*
* The log2 of the standard number of clusters per compression block.
* A value of 4 corresponds to 16 clusters (1 << 4), which is the
* default chunk size used by NTFS LZNT1 compression.
*/
#define STANDARD_COMPRESSION_UNIT 4
/*
* The maximum cluster size (4KB) allowed for compression to be enabled.
* By design, NTFS does not support compression on volumes where the
* cluster size exceeds 4096 bytes.
*/
#define MAX_COMPRESSION_CLUSTER_SIZE 4096
#define NTFS_B_TO_CLU(vol, b) ((b) >> (vol)->cluster_size_bits)
#define NTFS_CLU_TO_B(vol, clu) ((u64)(clu) << (vol)->cluster_size_bits)
#define NTFS_B_TO_CLU_OFS(vol, clu) ((u64)(clu) & (vol)->cluster_size_mask)
#define NTFS_MFT_NR_TO_CLU(vol, mft_no) (((u64)mft_no << (vol)->mft_record_size_bits) >> \
(vol)->cluster_size_bits)
#define NTFS_MFT_NR_TO_PIDX(vol, mft_no) (mft_no >> (PAGE_SHIFT - \
(vol)->mft_record_size_bits))
#define NTFS_MFT_NR_TO_POFS(vol, mft_no) (((u64)mft_no << (vol)->mft_record_size_bits) & \
~PAGE_MASK)
#define NTFS_PIDX_TO_BLK(vol, idx) (((u64)idx << PAGE_SHIFT) >> \
((vol)->sb)->s_blocksize_bits)
#define NTFS_PIDX_TO_CLU(vol, idx) (((u64)idx << PAGE_SHIFT) >> \
(vol)->cluster_size_bits)
#define NTFS_CLU_TO_PIDX(vol, clu) (((u64)(clu) << (vol)->cluster_size_bits) >> \
PAGE_SHIFT)
#define NTFS_CLU_TO_POFS(vol, clu) (((u64)(clu) << (vol)->cluster_size_bits) & \
~PAGE_MASK)
#define NTFS_B_TO_SECTOR(vol, b) ((b) >> ((vol)->sb)->s_blocksize_bits)
enum {
NTFS_BLOCK_SIZE = 512,
NTFS_BLOCK_SIZE_BITS = 9,
NTFS_SB_MAGIC = 0x5346544e, /* 'NTFS' */
NTFS_MAX_NAME_LEN = 255,
NTFS_MAX_LABEL_LEN = 128,
};
enum {
CASE_SENSITIVE = 0,
IGNORE_CASE = 1,
};
/*
* Conversion helpers for NTFS units.
*/
/* Convert bytes to cluster count */
static inline u64 ntfs_bytes_to_cluster(const struct ntfs_volume *vol,
s64 bytes)
{
return bytes >> vol->cluster_size_bits;
}
/* Convert cluster count to bytes */
static inline u64 ntfs_cluster_to_bytes(const struct ntfs_volume *vol,
u64 clusters)
{
return clusters << vol->cluster_size_bits;
}
/* Get the byte offset within a cluster from a linear byte address */
static inline u64 ntfs_bytes_to_cluster_off(const struct ntfs_volume *vol,
u64 bytes)
{
return bytes & vol->cluster_size_mask;
}
/* Calculate the physical cluster number containing a specific MFT record. */
static inline u64 ntfs_mft_no_to_cluster(const struct ntfs_volume *vol,
unsigned long mft_no)
{
return ((u64)mft_no << vol->mft_record_size_bits) >>
vol->cluster_size_bits;
}
/* Calculate the folio index where the MFT record resides. */
static inline pgoff_t ntfs_mft_no_to_pidx(const struct ntfs_volume *vol,
unsigned long mft_no)
{
return mft_no >> (PAGE_SHIFT - vol->mft_record_size_bits);
}
/* Calculate the byte offset within a folio for an MFT record. */
static inline u64 ntfs_mft_no_to_poff(const struct ntfs_volume *vol,
unsigned long mft_no)
{
return ((u64)mft_no << vol->mft_record_size_bits) & ~PAGE_MASK;
}
/* Convert folio index to cluster number. */
static inline u64 ntfs_pidx_to_cluster(const struct ntfs_volume *vol,
pgoff_t idx)
{
return ((u64)idx << PAGE_SHIFT) >> vol->cluster_size_bits;
}
/* Convert cluster number to folio index. */
static inline pgoff_t ntfs_cluster_to_pidx(const struct ntfs_volume *vol,
u64 clu)
{
return (clu << vol->cluster_size_bits) >> PAGE_SHIFT;
}
/* Get the byte offset within a folio from a cluster number */
static inline u64 ntfs_cluster_to_poff(const struct ntfs_volume *vol,
u64 clu)
{
return (clu << vol->cluster_size_bits) & ~PAGE_MASK;
}
/* Convert byte offset to sector (block) number. */
static inline sector_t ntfs_bytes_to_sector(const struct ntfs_volume *vol,
u64 bytes)
{
return bytes >> vol->sb->s_blocksize_bits;
}
/* Global variables. */
/* Slab caches (from super.c). */
extern struct kmem_cache *ntfs_name_cache;
extern struct kmem_cache *ntfs_inode_cache;
extern struct kmem_cache *ntfs_big_inode_cache;
extern struct kmem_cache *ntfs_attr_ctx_cache;
extern struct kmem_cache *ntfs_index_ctx_cache;
/* The various operations structs defined throughout the driver files. */
extern const struct address_space_operations ntfs_aops;
extern const struct address_space_operations ntfs_mft_aops;
extern const struct file_operations ntfs_file_ops;
extern const struct inode_operations ntfs_file_inode_ops;
extern const struct inode_operations ntfs_symlink_inode_operations;
extern const struct inode_operations ntfs_special_inode_operations;
extern const struct file_operations ntfs_dir_ops;
extern const struct inode_operations ntfs_dir_inode_ops;
extern const struct file_operations ntfs_empty_file_ops;
extern const struct inode_operations ntfs_empty_inode_ops;
extern const struct export_operations ntfs_export_ops;
/*
* NTFS_SB - return the ntfs volume given a vfs super block
* @sb: VFS super block
*
* NTFS_SB() returns the ntfs volume associated with the VFS super block @sb.
*/
static inline struct ntfs_volume *NTFS_SB(struct super_block *sb)
{
return sb->s_fs_info;
}
/* Declarations of functions and global variables. */
/* From fs/ntfs/compress.c */
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 6, 0)
int ntfs_read_compressed_block(struct folio *folio);
#else
int ntfs_read_compressed_block(struct page *page);
#endif
int allocate_compression_buffers(void);
void free_compression_buffers(void);
int ntfs_compress_write(struct ntfs_inode *ni, loff_t pos, size_t count,
struct iov_iter *from);
/* From fs/ntfs/super.c */
#define default_upcase_len 0x10000
extern struct mutex ntfs_lock;
struct option_t {
int val;
char *str;
};
extern const struct option_t on_errors_arr[];
int ntfs_set_volume_flags(struct ntfs_volume *vol, __le16 flags);
int ntfs_clear_volume_flags(struct ntfs_volume *vol, __le16 flags);
int ntfs_write_volume_label(struct ntfs_volume *vol, char *label);
/* From fs/ntfs/mst.c */
int post_read_mst_fixup(struct ntfs_record *b, const u32 size);
int pre_write_mst_fixup(struct ntfs_record *b, const u32 size);
void post_write_mst_fixup(struct ntfs_record *b);
/* From fs/ntfs/unistr.c */
bool ntfs_are_names_equal(const __le16 *s1, size_t s1_len,
const __le16 *s2, size_t s2_len,
const u32 ic,
const __le16 *upcase, const u32 upcase_size);
int ntfs_collate_names(const __le16 *name1, const u32 name1_len,
const __le16 *name2, const u32 name2_len,
const int err_val, const u32 ic,
const __le16 *upcase, const u32 upcase_len);
int ntfs_ucsncmp(const __le16 *s1, const __le16 *s2, size_t n);
int ntfs_ucsncasecmp(const __le16 *s1, const __le16 *s2, size_t n,
const __le16 *upcase, const u32 upcase_size);
int ntfs_file_compare_values(const struct file_name_attr *file_name_attr1,
const struct file_name_attr *file_name_attr2,
const int err_val, const u32 ic,
const __le16 *upcase, const u32 upcase_len);
int ntfs_nlstoucs(const struct ntfs_volume *vol, const char *ins,
const int ins_len, __le16 **outs, int max_name_len);
int ntfs_ucstonls(const struct ntfs_volume *vol, const __le16 *ins,
const int ins_len, unsigned char **outs, int outs_len);
__le16 *ntfs_ucsndup(const __le16 *s, u32 maxlen);
bool ntfs_names_are_equal(const __le16 *s1, size_t s1_len,
const __le16 *s2, size_t s2_len,
const u32 ic,
const __le16 *upcase, const u32 upcase_size);
int ntfs_force_shutdown(struct super_block *sb, u32 flags);
long ntfs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg);
#ifdef CONFIG_COMPAT
long ntfs_compat_ioctl(struct file *filp, unsigned int cmd,
unsigned long arg);
#endif
/* From fs/ntfs/upcase.c */
__le16 *generate_default_upcase(void);
static inline int ntfs_ffs(int x)
{
int r = 1;
if (!x)
return 0;
if (!(x & 0xffff)) {
x >>= 16;
r += 16;
}
if (!(x & 0xff)) {
x >>= 8;
r += 8;
}
if (!(x & 0xf)) {
x >>= 4;
r += 4;
}
if (!(x & 3)) {
x >>= 2;
r += 2;
}
if (!(x & 1))
r += 1;
return r;
}
/* From fs/ntfs/bdev-io.c */
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 16, 0)
int ntfs_bdev_read(struct block_device *bdev, char *data, loff_t start, size_t size);
#else
int ntfs_dev_read(struct super_block *sb, void *buf, loff_t start, size_t size);
#endif
int ntfs_bdev_write(struct super_block *sb, void *buf, loff_t start, size_t size);
#endif /* _LINUX_NTFS_H */