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