Loading...
1/* SPDX-License-Identifier: GPL-2.0-or-later */
2/*
3 * ntfs.h - Defines for NTFS Linux kernel driver.
4 *
5 * Copyright (c) 2001-2014 Anton Altaparmakov and Tuxera Inc.
6 * Copyright (C) 2002 Richard Russon
7 */
8
9#ifndef _LINUX_NTFS_H
10#define _LINUX_NTFS_H
11
12#include <linux/stddef.h>
13#include <linux/kernel.h>
14#include <linux/module.h>
15#include <linux/compiler.h>
16#include <linux/fs.h>
17#include <linux/nls.h>
18#include <linux/smp.h>
19#include <linux/pagemap.h>
20
21#include "types.h"
22#include "volume.h"
23#include "layout.h"
24
25typedef enum {
26 NTFS_BLOCK_SIZE = 512,
27 NTFS_BLOCK_SIZE_BITS = 9,
28 NTFS_SB_MAGIC = 0x5346544e, /* 'NTFS' */
29 NTFS_MAX_NAME_LEN = 255,
30 NTFS_MAX_ATTR_NAME_LEN = 255,
31 NTFS_MAX_CLUSTER_SIZE = 64 * 1024, /* 64kiB */
32 NTFS_MAX_PAGES_PER_CLUSTER = NTFS_MAX_CLUSTER_SIZE / PAGE_SIZE,
33} NTFS_CONSTANTS;
34
35/* Global variables. */
36
37/* Slab caches (from super.c). */
38extern struct kmem_cache *ntfs_name_cache;
39extern struct kmem_cache *ntfs_inode_cache;
40extern struct kmem_cache *ntfs_big_inode_cache;
41extern struct kmem_cache *ntfs_attr_ctx_cache;
42extern struct kmem_cache *ntfs_index_ctx_cache;
43
44/* The various operations structs defined throughout the driver files. */
45extern const struct address_space_operations ntfs_normal_aops;
46extern const struct address_space_operations ntfs_compressed_aops;
47extern const struct address_space_operations ntfs_mst_aops;
48
49extern const struct file_operations ntfs_file_ops;
50extern const struct inode_operations ntfs_file_inode_ops;
51
52extern const struct file_operations ntfs_dir_ops;
53extern const struct inode_operations ntfs_dir_inode_ops;
54
55extern const struct file_operations ntfs_empty_file_ops;
56extern const struct inode_operations ntfs_empty_inode_ops;
57
58extern const struct export_operations ntfs_export_ops;
59
60/**
61 * NTFS_SB - return the ntfs volume given a vfs super block
62 * @sb: VFS super block
63 *
64 * NTFS_SB() returns the ntfs volume associated with the VFS super block @sb.
65 */
66static inline ntfs_volume *NTFS_SB(struct super_block *sb)
67{
68 return sb->s_fs_info;
69}
70
71/* Declarations of functions and global variables. */
72
73/* From fs/ntfs/compress.c */
74extern int ntfs_read_compressed_block(struct page *page);
75extern int allocate_compression_buffers(void);
76extern void free_compression_buffers(void);
77
78/* From fs/ntfs/super.c */
79#define default_upcase_len 0x10000
80extern struct mutex ntfs_lock;
81
82typedef struct {
83 int val;
84 char *str;
85} option_t;
86extern const option_t on_errors_arr[];
87
88/* From fs/ntfs/mst.c */
89extern int post_read_mst_fixup(NTFS_RECORD *b, const u32 size);
90extern int pre_write_mst_fixup(NTFS_RECORD *b, const u32 size);
91extern void post_write_mst_fixup(NTFS_RECORD *b);
92
93/* From fs/ntfs/unistr.c */
94extern bool ntfs_are_names_equal(const ntfschar *s1, size_t s1_len,
95 const ntfschar *s2, size_t s2_len,
96 const IGNORE_CASE_BOOL ic,
97 const ntfschar *upcase, const u32 upcase_size);
98extern int ntfs_collate_names(const ntfschar *name1, const u32 name1_len,
99 const ntfschar *name2, const u32 name2_len,
100 const int err_val, const IGNORE_CASE_BOOL ic,
101 const ntfschar *upcase, const u32 upcase_len);
102extern int ntfs_ucsncmp(const ntfschar *s1, const ntfschar *s2, size_t n);
103extern int ntfs_ucsncasecmp(const ntfschar *s1, const ntfschar *s2, size_t n,
104 const ntfschar *upcase, const u32 upcase_size);
105extern void ntfs_upcase_name(ntfschar *name, u32 name_len,
106 const ntfschar *upcase, const u32 upcase_len);
107extern void ntfs_file_upcase_value(FILE_NAME_ATTR *file_name_attr,
108 const ntfschar *upcase, const u32 upcase_len);
109extern int ntfs_file_compare_values(FILE_NAME_ATTR *file_name_attr1,
110 FILE_NAME_ATTR *file_name_attr2,
111 const int err_val, const IGNORE_CASE_BOOL ic,
112 const ntfschar *upcase, const u32 upcase_len);
113extern int ntfs_nlstoucs(const ntfs_volume *vol, const char *ins,
114 const int ins_len, ntfschar **outs);
115extern int ntfs_ucstonls(const ntfs_volume *vol, const ntfschar *ins,
116 const int ins_len, unsigned char **outs, int outs_len);
117
118/* From fs/ntfs/upcase.c */
119extern ntfschar *generate_default_upcase(void);
120
121static inline int ntfs_ffs(int x)
122{
123 int r = 1;
124
125 if (!x)
126 return 0;
127 if (!(x & 0xffff)) {
128 x >>= 16;
129 r += 16;
130 }
131 if (!(x & 0xff)) {
132 x >>= 8;
133 r += 8;
134 }
135 if (!(x & 0xf)) {
136 x >>= 4;
137 r += 4;
138 }
139 if (!(x & 3)) {
140 x >>= 2;
141 r += 2;
142 }
143 if (!(x & 1)) {
144 x >>= 1;
145 r += 1;
146 }
147 return r;
148}
149
150#endif /* _LINUX_NTFS_H */
1/*
2 * ntfs.h - Defines for NTFS Linux kernel driver. Part of the Linux-NTFS
3 * project.
4 *
5 * Copyright (c) 2001-2005 Anton Altaparmakov
6 * Copyright (C) 2002 Richard Russon
7 *
8 * This program/include file is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as published
10 * by the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program/include file is distributed in the hope that it will be
14 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty
15 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program (in the main directory of the Linux-NTFS
20 * distribution in the file COPYING); if not, write to the Free Software
21 * Foundation,Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 */
23
24#ifndef _LINUX_NTFS_H
25#define _LINUX_NTFS_H
26
27#include <linux/stddef.h>
28#include <linux/kernel.h>
29#include <linux/module.h>
30#include <linux/compiler.h>
31#include <linux/fs.h>
32#include <linux/nls.h>
33#include <linux/smp.h>
34#include <linux/pagemap.h>
35
36#include "types.h"
37#include "volume.h"
38#include "layout.h"
39
40typedef enum {
41 NTFS_BLOCK_SIZE = 512,
42 NTFS_BLOCK_SIZE_BITS = 9,
43 NTFS_SB_MAGIC = 0x5346544e, /* 'NTFS' */
44 NTFS_MAX_NAME_LEN = 255,
45 NTFS_MAX_ATTR_NAME_LEN = 255,
46 NTFS_MAX_CLUSTER_SIZE = 64 * 1024, /* 64kiB */
47 NTFS_MAX_PAGES_PER_CLUSTER = NTFS_MAX_CLUSTER_SIZE / PAGE_CACHE_SIZE,
48} NTFS_CONSTANTS;
49
50/* Global variables. */
51
52/* Slab caches (from super.c). */
53extern struct kmem_cache *ntfs_name_cache;
54extern struct kmem_cache *ntfs_inode_cache;
55extern struct kmem_cache *ntfs_big_inode_cache;
56extern struct kmem_cache *ntfs_attr_ctx_cache;
57extern struct kmem_cache *ntfs_index_ctx_cache;
58
59/* The various operations structs defined throughout the driver files. */
60extern const struct address_space_operations ntfs_aops;
61extern const struct address_space_operations ntfs_mst_aops;
62
63extern const struct file_operations ntfs_file_ops;
64extern const struct inode_operations ntfs_file_inode_ops;
65
66extern const struct file_operations ntfs_dir_ops;
67extern const struct inode_operations ntfs_dir_inode_ops;
68
69extern const struct file_operations ntfs_empty_file_ops;
70extern const struct inode_operations ntfs_empty_inode_ops;
71
72extern const struct export_operations ntfs_export_ops;
73
74/**
75 * NTFS_SB - return the ntfs volume given a vfs super block
76 * @sb: VFS super block
77 *
78 * NTFS_SB() returns the ntfs volume associated with the VFS super block @sb.
79 */
80static inline ntfs_volume *NTFS_SB(struct super_block *sb)
81{
82 return sb->s_fs_info;
83}
84
85/* Declarations of functions and global variables. */
86
87/* From fs/ntfs/compress.c */
88extern int ntfs_read_compressed_block(struct page *page);
89extern int allocate_compression_buffers(void);
90extern void free_compression_buffers(void);
91
92/* From fs/ntfs/super.c */
93#define default_upcase_len 0x10000
94extern struct mutex ntfs_lock;
95
96typedef struct {
97 int val;
98 char *str;
99} option_t;
100extern const option_t on_errors_arr[];
101
102/* From fs/ntfs/mst.c */
103extern int post_read_mst_fixup(NTFS_RECORD *b, const u32 size);
104extern int pre_write_mst_fixup(NTFS_RECORD *b, const u32 size);
105extern void post_write_mst_fixup(NTFS_RECORD *b);
106
107/* From fs/ntfs/unistr.c */
108extern bool ntfs_are_names_equal(const ntfschar *s1, size_t s1_len,
109 const ntfschar *s2, size_t s2_len,
110 const IGNORE_CASE_BOOL ic,
111 const ntfschar *upcase, const u32 upcase_size);
112extern int ntfs_collate_names(const ntfschar *name1, const u32 name1_len,
113 const ntfschar *name2, const u32 name2_len,
114 const int err_val, const IGNORE_CASE_BOOL ic,
115 const ntfschar *upcase, const u32 upcase_len);
116extern int ntfs_ucsncmp(const ntfschar *s1, const ntfschar *s2, size_t n);
117extern int ntfs_ucsncasecmp(const ntfschar *s1, const ntfschar *s2, size_t n,
118 const ntfschar *upcase, const u32 upcase_size);
119extern void ntfs_upcase_name(ntfschar *name, u32 name_len,
120 const ntfschar *upcase, const u32 upcase_len);
121extern void ntfs_file_upcase_value(FILE_NAME_ATTR *file_name_attr,
122 const ntfschar *upcase, const u32 upcase_len);
123extern int ntfs_file_compare_values(FILE_NAME_ATTR *file_name_attr1,
124 FILE_NAME_ATTR *file_name_attr2,
125 const int err_val, const IGNORE_CASE_BOOL ic,
126 const ntfschar *upcase, const u32 upcase_len);
127extern int ntfs_nlstoucs(const ntfs_volume *vol, const char *ins,
128 const int ins_len, ntfschar **outs);
129extern int ntfs_ucstonls(const ntfs_volume *vol, const ntfschar *ins,
130 const int ins_len, unsigned char **outs, int outs_len);
131
132/* From fs/ntfs/upcase.c */
133extern ntfschar *generate_default_upcase(void);
134
135static inline int ntfs_ffs(int x)
136{
137 int r = 1;
138
139 if (!x)
140 return 0;
141 if (!(x & 0xffff)) {
142 x >>= 16;
143 r += 16;
144 }
145 if (!(x & 0xff)) {
146 x >>= 8;
147 r += 8;
148 }
149 if (!(x & 0xf)) {
150 x >>= 4;
151 r += 4;
152 }
153 if (!(x & 3)) {
154 x >>= 2;
155 r += 2;
156 }
157 if (!(x & 1)) {
158 x >>= 1;
159 r += 1;
160 }
161 return r;
162}
163
164#endif /* _LINUX_NTFS_H */