123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
#ifndef _LINUX_NTFS_VOLUME_H
#define _LINUX_NTFS_VOLUME_H
#include <linux/rwsem.h>
#include <linux/sched.h>
#include <linux/wait.h>
#include <linux/uidgid.h>
#include <linux/workqueue.h>
#include <linux/errseq.h>
#include "layout.h"
#define NTFS_VOL_UID BIT(1)
#define NTFS_VOL_GID BIT(2)
struct ntfs_volume {
struct super_block *sb;
s64 nr_blocks;
unsigned long flags;
kuid_t uid;
kgid_t gid;
umode_t fmask;
umode_t dmask;
u8 mft_zone_multiplier;
u8 on_errors;
errseq_t wb_err;
u16 sector_size;
u8 sector_size_bits;
u32 cluster_size;
u32 cluster_size_mask;
u8 cluster_size_bits;
u32 mft_record_size;
u32 mft_record_size_mask;
u8 mft_record_size_bits;
bool mft_write_supported;
u32 mft_io_unit_size;
u32 index_record_size;
u32 index_record_size_mask;
u8 index_record_size_bits;
s64 nr_clusters;
s64 bad_clusters;
s64 mft_lcn;
s64 mftmirr_lcn;
u64 serial_no;
u32 upcase_len;
__le16 *upcase;
s32 attrdef_size;
struct attr_def *attrdef;
s64 mft_data_pos;
s64 mft_record_reserve_pos;
s64 mft_record_reserve_end;
s64 mft_zone_start;
s64 mft_zone_end;
s64 mft_zone_pos;
s64 data1_zone_pos;
s64 data2_zone_pos;
struct inode *mft_ino;
struct inode *mftbmp_ino;
struct rw_semaphore mftbmp_lock;
struct inode *mftmirr_ino;
int mftmirr_size;
struct inode *logfile_ino;
struct inode *lcnbmp_ino;
struct rw_semaphore lcnbmp_lock;
struct mutex volume_label_lock;
struct inode *vol_ino;
__le16 vol_flags;
u8 major_ver;
u8 minor_ver;
unsigned char *volume_label;
struct inode *root_ino;
struct inode *secure_ino;
struct inode *extend_ino;
struct nls_table *nls_map;
bool nls_utf8;
wait_queue_head_t free_waitq;
atomic64_t free_clusters;
atomic64_t free_mft_records;
atomic64_t dirty_clusters;
u8 sparse_compression_unit;
unsigned int *lcn_empty_bits_per_page;
struct work_struct precalc_work;
loff_t preallocated_size;
};
enum {
NV_Errors,
NV_ShowSystemFiles,
NV_CaseSensitive,
NV_LogFileEmpty,
NV_UsnJrnlStamped,
NV_ReadOnly,
NV_Compression,
NV_FreeClusterKnown,
NV_Shutdown,
NV_SysImmutable,
NV_ShowHiddenFiles,
NV_HideDotFiles,
NV_CheckWindowsNames,
NV_Hibernated,
NV_Discard,
NV_DisableSparse,
NV_NativeSymlinkRel,
NV_SymlinkNative,
NV_MftBootstrap,
NV_StreamsWindows,
};
#define DEFINE_NVOL_BIT_OPS(flag) \
static inline int NVol##flag(struct ntfs_volume *vol) \
{ \
return test_bit(NV_##flag, &(vol)->flags); \
} \
static inline void NVolSet##flag(struct ntfs_volume *vol) \
{ \
set_bit(NV_##flag, &(vol)->flags); \
} \
static inline void NVolClear##flag(struct ntfs_volume *vol) \
{ \
clear_bit(NV_##flag, &(vol)->flags); \
}
DEFINE_NVOL_BIT_OPS(Errors)
DEFINE_NVOL_BIT_OPS(ShowSystemFiles)
DEFINE_NVOL_BIT_OPS(CaseSensitive)
DEFINE_NVOL_BIT_OPS(LogFileEmpty)
DEFINE_NVOL_BIT_OPS(UsnJrnlStamped)
DEFINE_NVOL_BIT_OPS(ReadOnly)
DEFINE_NVOL_BIT_OPS(Compression)
DEFINE_NVOL_BIT_OPS(FreeClusterKnown)
DEFINE_NVOL_BIT_OPS(Shutdown)
DEFINE_NVOL_BIT_OPS(SysImmutable)
DEFINE_NVOL_BIT_OPS(ShowHiddenFiles)
DEFINE_NVOL_BIT_OPS(HideDotFiles)
DEFINE_NVOL_BIT_OPS(CheckWindowsNames)
DEFINE_NVOL_BIT_OPS(Hibernated)
DEFINE_NVOL_BIT_OPS(Discard)
DEFINE_NVOL_BIT_OPS(DisableSparse)
DEFINE_NVOL_BIT_OPS(NativeSymlinkRel)
DEFINE_NVOL_BIT_OPS(SymlinkNative)
DEFINE_NVOL_BIT_OPS(MftBootstrap)
DEFINE_NVOL_BIT_OPS(StreamsWindows)
static inline void ntfs_inc_free_clusters(struct ntfs_volume *vol, s64 nr)
{
if (!NVolFreeClusterKnown(vol))
wait_event(vol->free_waitq, NVolFreeClusterKnown(vol));
atomic64_add(nr, &vol->free_clusters);
}
static inline void ntfs_dec_free_clusters(struct ntfs_volume *vol, s64 nr)
{
if (!NVolFreeClusterKnown(vol))
wait_event(vol->free_waitq, NVolFreeClusterKnown(vol));
atomic64_sub(nr, &vol->free_clusters);
}
static inline void ntfs_inc_free_mft_records(struct ntfs_volume *vol, s64 nr)
{
atomic64_add(nr, &vol->free_mft_records);
}
static inline void ntfs_dec_free_mft_records(struct ntfs_volume *vol, s64 nr)
{
atomic64_sub(nr, &vol->free_mft_records);
}
static inline void ntfs_set_lcn_empty_bits(struct ntfs_volume *vol, unsigned long index,
u8 val, unsigned int count)
{
if (!NVolFreeClusterKnown(vol))
wait_event(vol->free_waitq, NVolFreeClusterKnown(vol));
if (val)
vol->lcn_empty_bits_per_page[index] -= count;
else
vol->lcn_empty_bits_per_page[index] += count;
}
static __always_inline void ntfs_hold_dirty_clusters(struct ntfs_volume *vol, s64 nr_clusters)
{
atomic64_add(nr_clusters, &vol->dirty_clusters);
}
static __always_inline void ntfs_release_dirty_clusters(struct ntfs_volume *vol, s64 nr_clusters)
{
if (atomic64_read(&vol->dirty_clusters) < nr_clusters)
atomic64_set(&vol->dirty_clusters, 0);
else
atomic64_sub(nr_clusters, &vol->dirty_clusters);
}
s64 ntfs_available_clusters_count(struct ntfs_volume *vol, s64 nr_clusters);
s64 get_nr_free_clusters(struct ntfs_volume *vol);
#endif /* _LINUX_NTFS_VOLUME_H */