18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * ntfs.h - Defines for NTFS Linux kernel driver.
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * Copyright (c) 2001-2014 Anton Altaparmakov and Tuxera Inc.
68c2ecf20Sopenharmony_ci * Copyright (C) 2002 Richard Russon
78c2ecf20Sopenharmony_ci */
88c2ecf20Sopenharmony_ci
98c2ecf20Sopenharmony_ci#ifndef _LINUX_NTFS_H
108c2ecf20Sopenharmony_ci#define _LINUX_NTFS_H
118c2ecf20Sopenharmony_ci
128c2ecf20Sopenharmony_ci#include <linux/stddef.h>
138c2ecf20Sopenharmony_ci#include <linux/kernel.h>
148c2ecf20Sopenharmony_ci#include <linux/module.h>
158c2ecf20Sopenharmony_ci#include <linux/compiler.h>
168c2ecf20Sopenharmony_ci#include <linux/fs.h>
178c2ecf20Sopenharmony_ci#include <linux/nls.h>
188c2ecf20Sopenharmony_ci#include <linux/smp.h>
198c2ecf20Sopenharmony_ci#include <linux/pagemap.h>
208c2ecf20Sopenharmony_ci
218c2ecf20Sopenharmony_ci#include "types.h"
228c2ecf20Sopenharmony_ci#include "volume.h"
238c2ecf20Sopenharmony_ci#include "layout.h"
248c2ecf20Sopenharmony_ci
258c2ecf20Sopenharmony_citypedef enum {
268c2ecf20Sopenharmony_ci	NTFS_BLOCK_SIZE		= 512,
278c2ecf20Sopenharmony_ci	NTFS_BLOCK_SIZE_BITS	= 9,
288c2ecf20Sopenharmony_ci	NTFS_SB_MAGIC		= 0x5346544e,	/* 'NTFS' */
298c2ecf20Sopenharmony_ci	NTFS_MAX_NAME_LEN	= 255,
308c2ecf20Sopenharmony_ci	NTFS_MAX_ATTR_NAME_LEN	= 255,
318c2ecf20Sopenharmony_ci	NTFS_MAX_CLUSTER_SIZE	= 64 * 1024,	/* 64kiB */
328c2ecf20Sopenharmony_ci	NTFS_MAX_PAGES_PER_CLUSTER = NTFS_MAX_CLUSTER_SIZE / PAGE_SIZE,
338c2ecf20Sopenharmony_ci} NTFS_CONSTANTS;
348c2ecf20Sopenharmony_ci
358c2ecf20Sopenharmony_ci/* Global variables. */
368c2ecf20Sopenharmony_ci
378c2ecf20Sopenharmony_ci/* Slab caches (from super.c). */
388c2ecf20Sopenharmony_ciextern struct kmem_cache *ntfs_name_cache;
398c2ecf20Sopenharmony_ciextern struct kmem_cache *ntfs_inode_cache;
408c2ecf20Sopenharmony_ciextern struct kmem_cache *ntfs_big_inode_cache;
418c2ecf20Sopenharmony_ciextern struct kmem_cache *ntfs_attr_ctx_cache;
428c2ecf20Sopenharmony_ciextern struct kmem_cache *ntfs_index_ctx_cache;
438c2ecf20Sopenharmony_ci
448c2ecf20Sopenharmony_ci/* The various operations structs defined throughout the driver files. */
458c2ecf20Sopenharmony_ciextern const struct address_space_operations ntfs_normal_aops;
468c2ecf20Sopenharmony_ciextern const struct address_space_operations ntfs_compressed_aops;
478c2ecf20Sopenharmony_ciextern const struct address_space_operations ntfs_mst_aops;
488c2ecf20Sopenharmony_ci
498c2ecf20Sopenharmony_ciextern const struct  file_operations ntfs_file_ops;
508c2ecf20Sopenharmony_ciextern const struct inode_operations ntfs_file_inode_ops;
518c2ecf20Sopenharmony_ci
528c2ecf20Sopenharmony_ciextern const struct  file_operations ntfs_dir_ops;
538c2ecf20Sopenharmony_ciextern const struct inode_operations ntfs_dir_inode_ops;
548c2ecf20Sopenharmony_ci
558c2ecf20Sopenharmony_ciextern const struct  file_operations ntfs_empty_file_ops;
568c2ecf20Sopenharmony_ciextern const struct inode_operations ntfs_empty_inode_ops;
578c2ecf20Sopenharmony_ci
588c2ecf20Sopenharmony_ciextern const struct export_operations ntfs_export_ops;
598c2ecf20Sopenharmony_ci
608c2ecf20Sopenharmony_ci/**
618c2ecf20Sopenharmony_ci * NTFS_SB - return the ntfs volume given a vfs super block
628c2ecf20Sopenharmony_ci * @sb:		VFS super block
638c2ecf20Sopenharmony_ci *
648c2ecf20Sopenharmony_ci * NTFS_SB() returns the ntfs volume associated with the VFS super block @sb.
658c2ecf20Sopenharmony_ci */
668c2ecf20Sopenharmony_cistatic inline ntfs_volume *NTFS_SB(struct super_block *sb)
678c2ecf20Sopenharmony_ci{
688c2ecf20Sopenharmony_ci	return sb->s_fs_info;
698c2ecf20Sopenharmony_ci}
708c2ecf20Sopenharmony_ci
718c2ecf20Sopenharmony_ci/* Declarations of functions and global variables. */
728c2ecf20Sopenharmony_ci
738c2ecf20Sopenharmony_ci/* From fs/ntfs/compress.c */
748c2ecf20Sopenharmony_ciextern int ntfs_read_compressed_block(struct page *page);
758c2ecf20Sopenharmony_ciextern int allocate_compression_buffers(void);
768c2ecf20Sopenharmony_ciextern void free_compression_buffers(void);
778c2ecf20Sopenharmony_ci
788c2ecf20Sopenharmony_ci/* From fs/ntfs/super.c */
798c2ecf20Sopenharmony_ci#define default_upcase_len 0x10000
808c2ecf20Sopenharmony_ciextern struct mutex ntfs_lock;
818c2ecf20Sopenharmony_ci
828c2ecf20Sopenharmony_citypedef struct {
838c2ecf20Sopenharmony_ci	int val;
848c2ecf20Sopenharmony_ci	char *str;
858c2ecf20Sopenharmony_ci} option_t;
868c2ecf20Sopenharmony_ciextern const option_t on_errors_arr[];
878c2ecf20Sopenharmony_ci
888c2ecf20Sopenharmony_ci/* From fs/ntfs/mst.c */
898c2ecf20Sopenharmony_ciextern int post_read_mst_fixup(NTFS_RECORD *b, const u32 size);
908c2ecf20Sopenharmony_ciextern int pre_write_mst_fixup(NTFS_RECORD *b, const u32 size);
918c2ecf20Sopenharmony_ciextern void post_write_mst_fixup(NTFS_RECORD *b);
928c2ecf20Sopenharmony_ci
938c2ecf20Sopenharmony_ci/* From fs/ntfs/unistr.c */
948c2ecf20Sopenharmony_ciextern bool ntfs_are_names_equal(const ntfschar *s1, size_t s1_len,
958c2ecf20Sopenharmony_ci		const ntfschar *s2, size_t s2_len,
968c2ecf20Sopenharmony_ci		const IGNORE_CASE_BOOL ic,
978c2ecf20Sopenharmony_ci		const ntfschar *upcase, const u32 upcase_size);
988c2ecf20Sopenharmony_ciextern int ntfs_collate_names(const ntfschar *name1, const u32 name1_len,
998c2ecf20Sopenharmony_ci		const ntfschar *name2, const u32 name2_len,
1008c2ecf20Sopenharmony_ci		const int err_val, const IGNORE_CASE_BOOL ic,
1018c2ecf20Sopenharmony_ci		const ntfschar *upcase, const u32 upcase_len);
1028c2ecf20Sopenharmony_ciextern int ntfs_ucsncmp(const ntfschar *s1, const ntfschar *s2, size_t n);
1038c2ecf20Sopenharmony_ciextern int ntfs_ucsncasecmp(const ntfschar *s1, const ntfschar *s2, size_t n,
1048c2ecf20Sopenharmony_ci		const ntfschar *upcase, const u32 upcase_size);
1058c2ecf20Sopenharmony_ciextern void ntfs_upcase_name(ntfschar *name, u32 name_len,
1068c2ecf20Sopenharmony_ci		const ntfschar *upcase, const u32 upcase_len);
1078c2ecf20Sopenharmony_ciextern void ntfs_file_upcase_value(FILE_NAME_ATTR *file_name_attr,
1088c2ecf20Sopenharmony_ci		const ntfschar *upcase, const u32 upcase_len);
1098c2ecf20Sopenharmony_ciextern int ntfs_file_compare_values(FILE_NAME_ATTR *file_name_attr1,
1108c2ecf20Sopenharmony_ci		FILE_NAME_ATTR *file_name_attr2,
1118c2ecf20Sopenharmony_ci		const int err_val, const IGNORE_CASE_BOOL ic,
1128c2ecf20Sopenharmony_ci		const ntfschar *upcase, const u32 upcase_len);
1138c2ecf20Sopenharmony_ciextern int ntfs_nlstoucs(const ntfs_volume *vol, const char *ins,
1148c2ecf20Sopenharmony_ci		const int ins_len, ntfschar **outs);
1158c2ecf20Sopenharmony_ciextern int ntfs_ucstonls(const ntfs_volume *vol, const ntfschar *ins,
1168c2ecf20Sopenharmony_ci		const int ins_len, unsigned char **outs, int outs_len);
1178c2ecf20Sopenharmony_ci
1188c2ecf20Sopenharmony_ci/* From fs/ntfs/upcase.c */
1198c2ecf20Sopenharmony_ciextern ntfschar *generate_default_upcase(void);
1208c2ecf20Sopenharmony_ci
1218c2ecf20Sopenharmony_cistatic inline int ntfs_ffs(int x)
1228c2ecf20Sopenharmony_ci{
1238c2ecf20Sopenharmony_ci	int r = 1;
1248c2ecf20Sopenharmony_ci
1258c2ecf20Sopenharmony_ci	if (!x)
1268c2ecf20Sopenharmony_ci		return 0;
1278c2ecf20Sopenharmony_ci	if (!(x & 0xffff)) {
1288c2ecf20Sopenharmony_ci		x >>= 16;
1298c2ecf20Sopenharmony_ci		r += 16;
1308c2ecf20Sopenharmony_ci	}
1318c2ecf20Sopenharmony_ci	if (!(x & 0xff)) {
1328c2ecf20Sopenharmony_ci		x >>= 8;
1338c2ecf20Sopenharmony_ci		r += 8;
1348c2ecf20Sopenharmony_ci	}
1358c2ecf20Sopenharmony_ci	if (!(x & 0xf)) {
1368c2ecf20Sopenharmony_ci		x >>= 4;
1378c2ecf20Sopenharmony_ci		r += 4;
1388c2ecf20Sopenharmony_ci	}
1398c2ecf20Sopenharmony_ci	if (!(x & 3)) {
1408c2ecf20Sopenharmony_ci		x >>= 2;
1418c2ecf20Sopenharmony_ci		r += 2;
1428c2ecf20Sopenharmony_ci	}
1438c2ecf20Sopenharmony_ci	if (!(x & 1)) {
1448c2ecf20Sopenharmony_ci		x >>= 1;
1458c2ecf20Sopenharmony_ci		r += 1;
1468c2ecf20Sopenharmony_ci	}
1478c2ecf20Sopenharmony_ci	return r;
1488c2ecf20Sopenharmony_ci}
1498c2ecf20Sopenharmony_ci
1508c2ecf20Sopenharmony_ci#endif /* _LINUX_NTFS_H */
151