1N/A/*
1N/A * inode.h - Defines for NTFS inode handling. Part of the Linux-NTFS project.
1N/A *
1N/A * Copyright (c) 2001,2002 Anton Altaparmakov
1N/A * Copyright (c) 2004-2007 Yura Pakhuchiy
1N/A * Copyright (c) 2004-2005 Richard Russon
1N/A *
1N/A * This program/include file is free software; you can redistribute it and/or
1N/A * modify it under the terms of the GNU General Public License as published
1N/A * by the Free Software Foundation; either version 2 of the License, or
1N/A * (at your option) any later version.
1N/A *
1N/A * This program/include file is distributed in the hope that it will be
1N/A * useful, but WITHOUT ANY WARRANTY; without even the implied warranty
1N/A * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1N/A * GNU General Public License for more details.
1N/A *
1N/A * You should have received a copy of the GNU General Public License
1N/A * along with this program (in the main directory of the Linux-NTFS
1N/A * distribution in the file COPYING); if not, write to the Free Software
1N/A * Foundation,Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
1N/A */
1N/A
1N/A#ifndef _NTFS_INODE_H
1N/A#define _NTFS_INODE_H
1N/A
1N/A/* Forward declaration */
1N/Atypedef struct _ntfs_inode ntfs_inode;
1N/A
1N/A#include "list.h"
1N/A#include "types.h"
1N/A#include "layout.h"
1N/A#include "support.h"
1N/A#include "volume.h"
1N/A
1N/A/**
1N/A * enum ntfs_inode_state_bits -
1N/A *
1N/A * Defined bits for the state field in the ntfs_inode structure.
1N/A * (f) = files only, (d) = directories only
1N/A */
1N/Atypedef enum {
1N/A NI_Dirty, /* 1: Mft record needs to be written to disk. */
1N/A
1N/A /* Below fields only make sense for base inodes. */
1N/A NI_AttrList, /* 1: Mft record contains an attribute list. */
1N/A NI_AttrListDirty, /* 1: Attribute list needs to be written to the
1N/A mft record and then to disk. */
1N/A NI_FileNameDirty, /* 1: FILE_NAME attributes need to be updated
1N/A in the index. */
1N/A} ntfs_inode_state_bits;
1N/A
1N/A#define test_nino_flag(ni, flag) test_bit(NI_##flag, (ni)->state)
1N/A#define set_nino_flag(ni, flag) set_bit(NI_##flag, (ni)->state)
1N/A#define clear_nino_flag(ni, flag) clear_bit(NI_##flag, (ni)->state)
1N/A
1N/A#define test_and_set_nino_flag(ni, flag) \
1N/A test_and_set_bit(NI_##flag, (ni)->state)
1N/A#define test_and_clear_nino_flag(ni, flag) \
1N/A test_and_clear_bit(NI_##flag, (ni)->state)
1N/A
1N/A#define NInoDirty(ni) test_nino_flag(ni, Dirty)
1N/A#define NInoSetDirty(ni) set_nino_flag(ni, Dirty)
1N/A#define NInoClearDirty(ni) clear_nino_flag(ni, Dirty)
1N/A#define NInoTestAndSetDirty(ni) test_and_set_nino_flag(ni, Dirty)
1N/A#define NInoTestAndClearDirty(ni) test_and_clear_nino_flag(ni, Dirty)
1N/A
1N/A#define NInoAttrList(ni) test_nino_flag(ni, AttrList)
1N/A#define NInoSetAttrList(ni) set_nino_flag(ni, AttrList)
1N/A#define NInoClearAttrList(ni) clear_nino_flag(ni, AttrList)
1N/A
1N/A
1N/A#define test_nino_al_flag(ni, flag) test_nino_flag(ni, AttrList##flag)
1N/A#define set_nino_al_flag(ni, flag) set_nino_flag(ni, AttrList##flag)
1N/A#define clear_nino_al_flag(ni, flag) clear_nino_flag(ni, AttrList##flag)
1N/A
1N/A#define test_and_set_nino_al_flag(ni, flag) \
1N/A test_and_set_nino_flag(ni, AttrList##flag)
1N/A#define test_and_clear_nino_al_flag(ni, flag) \
1N/A test_and_clear_nino_flag(ni, AttrList##flag)
1N/A
1N/A#define NInoAttrListDirty(ni) test_nino_al_flag(ni, Dirty)
1N/A#define NInoAttrListSetDirty(ni) set_nino_al_flag(ni, Dirty)
1N/A#define NInoAttrListClearDirty(ni) clear_nino_al_flag(ni, Dirty)
1N/A#define NInoAttrListTestAndSetDirty(ni) test_and_set_nino_al_flag(ni, Dirty)
1N/A#define NInoAttrListTestAndClearDirty(ni) test_and_clear_nino_al_flag(ni, Dirty)
1N/A
1N/A#define NInoFileNameDirty(ni) \
1N/A test_nino_flag(ni, FileNameDirty)
1N/A#define NInoFileNameSetDirty(ni) \
1N/A set_nino_flag(ni, FileNameDirty)
1N/A#define NInoFileNameClearDirty(ni) \
1N/A clear_nino_flag(ni, FileNameDirty)
1N/A#define NInoFileNameTestAndSetDirty(ni) \
1N/A test_and_set_nino_flag(ni, FileNameDirty)
1N/A#define NInoFileNameTestAndClearDirty(ni) \
1N/A test_and_clear_nino_flag(ni, FileNameDirty)
1N/A
1N/A/**
1N/A * struct _ntfs_inode - The NTFS in-memory inode structure.
1N/A *
1N/A * It is just used as an extension to the fields already provided in the VFS
1N/A * inode.
1N/A */
1N/Astruct _ntfs_inode {
1N/A u64 mft_no; /* Inode / mft record number. */
1N/A MFT_RECORD *mrec; /* The actual mft record of the inode. */
1N/A ntfs_volume *vol; /* Pointer to the ntfs volume of this inode. */
1N/A unsigned long state; /* NTFS specific flags describing this inode.
1N/A See ntfs_inode_state_bits above. */
1N/A FILE_ATTR_FLAGS flags; /* Flags describing the file.
1N/A (Copy from STANDARD_INFORMATION) */
1N/A /*
1N/A * Attribute list support (for use by the attribute lookup functions).
1N/A * Setup during ntfs_open_inode() for all inodes with attribute lists.
1N/A * Only valid if NI_AttrList is set in state.
1N/A */
1N/A u32 attr_list_size; /* Length of attribute list value in bytes. */
1N/A u8 *attr_list; /* Attribute list value itself. */
1N/A /* Below fields are always valid. */
1N/A s32 nr_extents; /* For a base mft record, the number of
1N/A attached extent inodes (0 if none), for
1N/A extent records this is -1. */
1N/A union { /* This union is only used if nr_extents != 0. */
1N/A ntfs_inode **extent_nis;/* For nr_extents > 0, array of the
1N/A ntfs inodes of the extent mft
1N/A records belonging to this base
1N/A inode which have been loaded. */
1N/A ntfs_inode *base_ni; /* For nr_extents == -1, the ntfs
1N/A inode of the base mft record. */
1N/A } u;
1N/A
1N/A /* Below fields are valid only for base inode. */
1N/A
1N/A /*
1N/A * These two fields are used to sync filename index and guaranteed to be
1N/A * correct, however value in index itself maybe wrong (windows itself
1N/A * do not update them properly).
1N/A */
1N/A s64 data_size; /* Data size of unnamed DATA attribute. */
1N/A s64 allocated_size; /* Allocated size stored in the filename
1N/A index. (NOTE: Equal to allocated size of
1N/A the unnamed data attribute for normal or
1N/A encrypted files and to compressed size
1N/A of the unnamed data attribute for sparse or
1N/A compressed files.) */
1N/A
1N/A /*
1N/A * These four fields are copy of relevant fields from
1N/A * STANDARD_INFORMATION attribute and used to sync it and FILE_NAME
1N/A * attribute in the index.
1N/A */
1N/A time_t creation_time;
1N/A time_t last_data_change_time;
1N/A time_t last_mft_change_time;
1N/A time_t last_access_time;
1N/A
1N/A /* These 2 fields are used to keep track of opened inodes. */
1N/A struct list_head list_entry; /* Keep pointers to the next/prev list
1N/A entry. */
1N/A int nr_references; /* How many times this inode was
1N/A opened. We really close inode only
1N/A when this reaches zero. */
1N/A
1N/A struct list_head attr_cache; /* List of opened attributes. */
1N/A};
1N/A
1N/Aextern void __ntfs_inode_add_to_cache(ntfs_inode *ni);
1N/A
1N/Aextern ntfs_inode *ntfs_inode_allocate(ntfs_volume *vol);
1N/A
1N/Aextern ntfs_inode *ntfs_inode_open(ntfs_volume *vol, const MFT_REF mref);
1N/A
1N/Aextern int ntfs_inode_close(ntfs_inode *ni);
1N/A
1N/Aextern ntfs_inode *ntfs_extent_inode_open(ntfs_inode *base_ni,
1N/A const leMFT_REF mref);
1N/A
1N/Aextern int ntfs_inode_attach_all_extents(ntfs_inode *ni);
1N/A
1N/A/**
1N/A * ntfs_inode_mark_dirty - set the inode (and its base inode if it exists) dirty
1N/A * @ni: ntfs inode to set dirty
1N/A *
1N/A * Set the inode @ni dirty so it is written out later (at the latest at
1N/A * ntfs_inode_close() time). If @ni is an extent inode, set the base inode
1N/A * dirty, too.
1N/A *
1N/A * This function cannot fail.
1N/A */
1N/Astatic __inline__ void ntfs_inode_mark_dirty(ntfs_inode *ni)
1N/A{
1N/A NInoSetDirty(ni);
1N/A if (ni->nr_extents == -1)
1N/A NInoSetDirty(ni->u.base_ni);
1N/A}
1N/A
1N/Atypedef enum {
1N/A NTFS_UPDATE_ATIME = 1 << 0,
1N/A NTFS_UPDATE_MTIME = 1 << 1,
1N/A NTFS_UPDATE_CTIME = 1 << 2,
1N/A} ntfs_time_update_flags;
1N/A
1N/Aextern void ntfs_inode_update_times(ntfs_inode *ni,
1N/A ntfs_time_update_flags mask);
1N/A
1N/Aextern int ntfs_inode_sync(ntfs_inode *ni);
1N/A
1N/Aextern int ntfs_inode_add_attrlist(ntfs_inode *ni);
1N/A
1N/Aextern int ntfs_inode_free_space(ntfs_inode *ni, int size);
1N/A
1N/Aextern int ntfs_inode_badclus_bad(u64 mft_no, ATTR_RECORD *a);
1N/A
1N/A#endif /* defined _NTFS_INODE_H */