typedef u_int64_t cn_t;
typedef u_int16_t wchar;
#define BBSIZE 1024
#define BBOFF ((off_t)(0))
#define BBLOCK 0
#define NTFS_MFTINO 0
#define NTFS_VOLUMEINO 3
#define NTFS_ATTRDEFINO 4
#define NTFS_ROOTINO 5
#define NTFS_BITMAPINO 6
#define NTFS_BOOTINO 7
#define NTFS_BADCLUSINO 8
#define NTFS_UPCASEINO 10
#define NTFS_MAXFILENAME 255
typedef u_int32_t ntfsino_t;
struct fixuphdr {
u_int32_t fh_magic;
u_int16_t fh_foff;
u_int16_t fh_fnum;
} __packed;
#define NTFS_AF_INRUN 0x00000001
struct attrhdr {
u_int32_t a_type;
u_int32_t reclen;
u_int8_t a_flag;
u_int8_t a_namelen;
u_int8_t a_nameoff;
u_int8_t reserved1;
u_int8_t a_compression;
u_int8_t reserved2;
u_int16_t a_index;
} __packed;
#define NTFS_A_STD 0x10
#define NTFS_A_ATTRLIST 0x20
#define NTFS_A_NAME 0x30
#define NTFS_A_VOLUMENAME 0x60
#define NTFS_A_DATA 0x80
#define NTFS_A_INDXROOT 0x90
#define NTFS_A_INDX 0xA0
#define NTFS_A_INDXBITMAP 0xB0
#define NTFS_MAXATTRNAME 255
struct attr {
struct attrhdr a_hdr;
union {
struct {
u_int16_t a_datalen;
u_int16_t reserved1;
u_int16_t a_dataoff;
u_int16_t a_indexed;
} __packed a_S_r;
struct {
cn_t a_vcnstart;
cn_t a_vcnend;
u_int16_t a_dataoff;
u_int16_t a_compressalg;
u_int32_t reserved1;
u_int64_t a_allocated;
u_int64_t a_datalen;
u_int64_t a_initialized;
} __packed a_S_nr;
} a_S;
} __packed;
#define a_r a_S.a_S_r
#define a_nr a_S.a_S_nr
typedef struct {
u_int64_t t_create;
u_int64_t t_write;
u_int64_t t_mftwrite;
u_int64_t t_access;
} __packed ntfs_times_t;
#define NTFS_FFLAG_RDONLY 0x01LL
#define NTFS_FFLAG_HIDDEN 0x02LL
#define NTFS_FFLAG_SYSTEM 0x04LL
#define NTFS_FFLAG_ARCHIVE 0x20LL
#define NTFS_FFLAG_COMPRESSED 0x0800LL
#define NTFS_FFLAG_DIR 0x10000000LL
struct attr_name {
u_int32_t n_pnumber;
u_int32_t reserved;
ntfs_times_t n_times;
u_int64_t n_size;
u_int64_t n_attrsz;
u_int64_t n_flag;
u_int8_t n_namelen;
u_int8_t n_nametype;
u_int16_t n_name[1];
} __packed;
#define NTFS_IRFLAG_INDXALLOC 0x00000001
struct attr_indexroot {
u_int32_t ir_unkn1;
u_int32_t ir_unkn2;
u_int32_t ir_size;
u_int32_t ir_unkn3;
u_int32_t ir_unkn4;
u_int32_t ir_datalen;
u_int32_t ir_allocated;
u_int16_t ir_flag;
u_int16_t ir_unkn7;
} __packed;
struct attr_attrlist {
u_int32_t al_type;
u_int16_t reclen;
u_int8_t al_namelen;
u_int8_t al_nameoff;
u_int64_t al_vcnstart;
u_int32_t al_inumber;
u_int32_t reserved;
u_int16_t al_index;
u_int16_t al_name[1];
} __packed;
#define NTFS_INDXMAGIC (u_int32_t)(0x58444E49)
struct attr_indexalloc {
struct fixuphdr ia_fixup;
u_int64_t unknown1;
cn_t ia_bufcn;
u_int16_t ia_hdrsize;
u_int16_t unknown2;
u_int32_t ia_inuse;
u_int32_t ia_allocated;
} __packed;
#define NTFS_IEFLAG_SUBNODE 0x00000001
#define NTFS_IEFLAG_LAST 0x00000002
struct attr_indexentry {
u_int32_t ie_number;
u_int32_t unknown1;
u_int16_t reclen;
u_int16_t ie_size;
u_int32_t ie_flag;
u_int32_t ie_fpnumber;
u_int32_t unknown2;
ntfs_times_t ie_ftimes;
u_int64_t ie_fallocated;
u_int64_t ie_fsize;
u_int64_t ie_fflag;
u_int8_t ie_fnamelen;
u_int8_t ie_fnametype;
wchar ie_fname[NTFS_MAXFILENAME];
} __packed;
#define NTFS_FILEMAGIC (u_int32_t)(0x454C4946)
#define NTFS_FRFLAG_DIR 0x0002
struct filerec {
struct fixuphdr fr_fixup;
u_int8_t reserved[8];
u_int16_t fr_seqnum;
u_int16_t fr_nlink;
u_int16_t fr_attroff;
u_int16_t fr_flags;
u_int32_t fr_size;
u_int32_t fr_allocated;
u_int64_t fr_mainrec;
u_int16_t fr_attrnum;
} __packed;
#define NTFS_ATTRNAME_MAXLEN 0x40
#define NTFS_ADFLAG_NONRES 0x0080
#define NTFS_ADFLAG_INDEX 0x0002
struct attrdef {
wchar ad_name[NTFS_ATTRNAME_MAXLEN];
u_int32_t ad_type;
u_int32_t reserved1[2];
u_int32_t ad_flag;
u_int64_t ad_minlen;
u_int64_t ad_maxlen;
} __packed;
struct ntvattrdef {
char ad_name[0x40];
int ad_namelen;
u_int32_t ad_type;
} __packed;
#define NTFS_BBID "NTFS "
#define NTFS_BBIDLEN 8
struct bootfile {
u_int8_t reserved1[3];
u_int8_t bf_sysid[8];
u_int16_t bf_bps;
u_int8_t bf_spc;
u_int8_t reserved2[7];
u_int8_t bf_media;
u_int8_t reserved3[2];
u_int16_t bf_spt;
u_int16_t bf_heads;
u_int8_t reserver4[12];
u_int64_t bf_spv;
cn_t bf_mftcn;
cn_t bf_mftmirrcn;
u_int8_t bf_mftrecsz;
u_int32_t bf_ibsz;
u_int32_t bf_volsn;
} __packed;
typedef wchar (ntfs_wget_func_t)(const char **);
typedef int (ntfs_wput_func_t)(char *, size_t, wchar);
typedef int (ntfs_wcmp_func_t)(wchar, wchar);
#define LOADED_NTNODE_HI 16
struct ntnode;
TAILQ_HEAD(ntnodeq, ntnode);
#define NTFS_SYSNODESNUM 0x0B
struct ntfsmount {
struct mount *ntm_mountp;
struct bootfile ntm_bootfile;
dev_t ntm_dev;
struct vnode *ntm_devvp;
struct vnode *ntm_sysvn[NTFS_SYSNODESNUM];
u_int32_t ntm_bpmftrec;
uid_t ntm_uid;
gid_t ntm_gid;
mode_t ntm_mode;
u_long ntm_flag;
cn_t ntm_cfree;
struct ntvattrdef *ntm_ad;
int ntm_adnum;
struct netexport ntm_export;
ntfs_wget_func_t *ntm_wget;
ntfs_wput_func_t *ntm_wput;
ntfs_wcmp_func_t *ntm_wcmp;
int ntm_ntnodes;
struct ntnodeq ntm_ntnodeq;
};
#define ntm_mftcn ntm_bootfile.bf_mftcn
#define ntm_mftmirrcn ntm_bootfile.bf_mftmirrcn
#define ntm_mftrecsz ntm_bootfile.bf_mftrecsz
#define ntm_spc ntm_bootfile.bf_spc
#define ntm_bps ntm_bootfile.bf_bps
#define NTFS_NEXTREC(s, type) ((type)(((caddr_t) s) + (s)->reclen))
#define VFSTONTFS(mp) ((struct ntfsmount *)((mp)->mnt_data))
#define VTONT(v) FTONT(VTOF(v))
#define VTOF(v) ((struct fnode *)((v)->v_data))
#define FTOV(f) ((f)->f_vp)
#define FTONT(f) ((f)->f_ip)
#define ntfs_cntobn(cn) (daddr_t)((cn) * (ntmp->ntm_spc))
#define ntfs_cntob(cn) (off_t)((cn) * (ntmp)->ntm_spc * (ntmp)->ntm_bps)
#define ntfs_btocn(off) (cn_t)((off) / ((ntmp)->ntm_spc * (ntmp)->ntm_bps))
#define ntfs_btocl(off) (cn_t)((off + ntfs_cntob(1) - 1) / ((ntmp)->ntm_spc * (ntmp)->ntm_bps))
#define ntfs_btocnoff(off) (off_t)((off) % ((ntmp)->ntm_spc * (ntmp)->ntm_bps))
#define ntfs_bntob(bn) (int32_t)((bn) * (ntmp)->ntm_bps)
#ifdef _KERNEL
#if defined(NTFS_DEBUG)
extern int ntfs_debug;
#define DNPRINTF(n, x...) do { if(ntfs_debug >= (n)) printf(x); } while(0)
#define DPRINTF(x...) DNPRINTF(1, x)
#define DDPRINTF(x...) DNPRINTF(2, x)
#else
#define DNPRINTF(n, x...)
#define DPRINTF(x...)
#define DDPRINTF(x...)
#endif
extern const struct vops ntfs_vops;
#endif