^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /* SPDX-License-Identifier: GPL-2.0-or-later */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * ntfs.h - Defines for NTFS Linux kernel driver.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (c) 2001-2014 Anton Altaparmakov and Tuxera Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Copyright (C) 2002 Richard Russon
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #ifndef _LINUX_NTFS_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #define _LINUX_NTFS_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/stddef.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/compiler.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/nls.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/smp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/pagemap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include "types.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include "volume.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include "layout.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) typedef enum {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) NTFS_BLOCK_SIZE = 512,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) NTFS_BLOCK_SIZE_BITS = 9,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) NTFS_SB_MAGIC = 0x5346544e, /* 'NTFS' */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) NTFS_MAX_NAME_LEN = 255,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) NTFS_MAX_ATTR_NAME_LEN = 255,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) NTFS_MAX_CLUSTER_SIZE = 64 * 1024, /* 64kiB */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) NTFS_MAX_PAGES_PER_CLUSTER = NTFS_MAX_CLUSTER_SIZE / PAGE_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) } NTFS_CONSTANTS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) /* Global variables. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) /* Slab caches (from super.c). */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) extern struct kmem_cache *ntfs_name_cache;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) extern struct kmem_cache *ntfs_inode_cache;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) extern struct kmem_cache *ntfs_big_inode_cache;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) extern struct kmem_cache *ntfs_attr_ctx_cache;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) extern struct kmem_cache *ntfs_index_ctx_cache;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) /* The various operations structs defined throughout the driver files. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) extern const struct address_space_operations ntfs_normal_aops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) extern const struct address_space_operations ntfs_compressed_aops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) extern const struct address_space_operations ntfs_mst_aops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) extern const struct file_operations ntfs_file_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) extern const struct inode_operations ntfs_file_inode_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) extern const struct file_operations ntfs_dir_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) extern const struct inode_operations ntfs_dir_inode_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) extern const struct file_operations ntfs_empty_file_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) extern const struct inode_operations ntfs_empty_inode_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) extern const struct export_operations ntfs_export_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) * NTFS_SB - return the ntfs volume given a vfs super block
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) * @sb: VFS super block
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) * NTFS_SB() returns the ntfs volume associated with the VFS super block @sb.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) static inline ntfs_volume *NTFS_SB(struct super_block *sb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) return sb->s_fs_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) /* Declarations of functions and global variables. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) /* From fs/ntfs/compress.c */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) extern int ntfs_read_compressed_block(struct page *page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) extern int allocate_compression_buffers(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) extern void free_compression_buffers(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) /* From fs/ntfs/super.c */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) #define default_upcase_len 0x10000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) extern struct mutex ntfs_lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) typedef struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) int val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) char *str;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) } option_t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) extern const option_t on_errors_arr[];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) /* From fs/ntfs/mst.c */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) extern int post_read_mst_fixup(NTFS_RECORD *b, const u32 size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) extern int pre_write_mst_fixup(NTFS_RECORD *b, const u32 size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) extern void post_write_mst_fixup(NTFS_RECORD *b);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) /* From fs/ntfs/unistr.c */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) extern bool ntfs_are_names_equal(const ntfschar *s1, size_t s1_len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) const ntfschar *s2, size_t s2_len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) const IGNORE_CASE_BOOL ic,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) const ntfschar *upcase, const u32 upcase_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) extern int ntfs_collate_names(const ntfschar *name1, const u32 name1_len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) const ntfschar *name2, const u32 name2_len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) const int err_val, const IGNORE_CASE_BOOL ic,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) const ntfschar *upcase, const u32 upcase_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) extern int ntfs_ucsncmp(const ntfschar *s1, const ntfschar *s2, size_t n);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) extern int ntfs_ucsncasecmp(const ntfschar *s1, const ntfschar *s2, size_t n,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) const ntfschar *upcase, const u32 upcase_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) extern void ntfs_upcase_name(ntfschar *name, u32 name_len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) const ntfschar *upcase, const u32 upcase_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) extern void ntfs_file_upcase_value(FILE_NAME_ATTR *file_name_attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) const ntfschar *upcase, const u32 upcase_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) extern int ntfs_file_compare_values(FILE_NAME_ATTR *file_name_attr1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) FILE_NAME_ATTR *file_name_attr2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) const int err_val, const IGNORE_CASE_BOOL ic,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) const ntfschar *upcase, const u32 upcase_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) extern int ntfs_nlstoucs(const ntfs_volume *vol, const char *ins,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) const int ins_len, ntfschar **outs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) extern int ntfs_ucstonls(const ntfs_volume *vol, const ntfschar *ins,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) const int ins_len, unsigned char **outs, int outs_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) /* From fs/ntfs/upcase.c */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) extern ntfschar *generate_default_upcase(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) static inline int ntfs_ffs(int x)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) int r = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) if (!x)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) if (!(x & 0xffff)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) x >>= 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) r += 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) if (!(x & 0xff)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) x >>= 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) r += 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) if (!(x & 0xf)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) x >>= 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) r += 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) if (!(x & 3)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) x >>= 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) r += 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) if (!(x & 1)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) x >>= 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) r += 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) return r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) #endif /* _LINUX_NTFS_H */