/*1* Copyright (C) 2007 Oracle. All rights reserved.2*3* This program is free software; you can redistribute it and/or4* modify it under the terms of the GNU General Public5* License v2 as published by the Free Software Foundation.6*7* This program is distributed in the hope that it will be useful,8* but WITHOUT ANY WARRANTY; without even the implied warranty of9* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU10* General Public License for more details.11*12* You should have received a copy of the GNU General Public13* License along with this program; if not, write to the14* Free Software Foundation, Inc., 59 Temple Place - Suite 330,15* Boston, MA 021110-1307, USA.16*/1718#ifndef __BTRFS_I__19#define __BTRFS_I__2021#include "extent_map.h"22#include "extent_io.h"23#include "ordered-data.h"24#include "delayed-inode.h"2526/* in memory btrfs inode */27struct btrfs_inode {28/* which subvolume this inode belongs to */29struct btrfs_root *root;3031/* key used to find this inode on disk. This is used by the code32* to read in roots of subvolumes33*/34struct btrfs_key location;3536/* the extent_tree has caches of all the extent mappings to disk */37struct extent_map_tree extent_tree;3839/* the io_tree does range state (DIRTY, LOCKED etc) */40struct extent_io_tree io_tree;4142/* special utility tree used to record which mirrors have already been43* tried when checksums fail for a given block44*/45struct extent_io_tree io_failure_tree;4647/* held while logging the inode in tree-log.c */48struct mutex log_mutex;4950/* used to order data wrt metadata */51struct btrfs_ordered_inode_tree ordered_tree;5253/* for keeping track of orphaned inodes */54struct list_head i_orphan;5556/* list of all the delalloc inodes in the FS. There are times we need57* to write all the delalloc pages to disk, and this list is used58* to walk them all.59*/60struct list_head delalloc_inodes;6162/*63* list for tracking inodes that must be sent to disk before a64* rename or truncate commit65*/66struct list_head ordered_operations;6768/* node for the red-black tree that links inodes in subvolume root */69struct rb_node rb_node;7071/* the space_info for where this inode's data allocations are done */72struct btrfs_space_info *space_info;7374/* full 64 bit generation number, struct vfs_inode doesn't have a big75* enough field for this.76*/77u64 generation;7879/* sequence number for NFS changes */80u64 sequence;8182/*83* transid of the trans_handle that last modified this inode84*/85u64 last_trans;8687/*88* log transid when this inode was last modified89*/90u64 last_sub_trans;9192/*93* transid that last logged this inode94*/95u64 logged_trans;9697/* total number of bytes pending delalloc, used by stat to calc the98* real block usage of the file99*/100u64 delalloc_bytes;101102/* total number of bytes that may be used for this inode for103* delalloc104*/105u64 reserved_bytes;106107/*108* the size of the file stored in the metadata on disk. data=ordered109* means the in-memory i_size might be larger than the size on disk110* because not all the blocks are written yet.111*/112u64 disk_i_size;113114/* flags field from the on disk inode */115u32 flags;116117/*118* if this is a directory then index_cnt is the counter for the index119* number for new files that are created120*/121u64 index_cnt;122123/* the fsync log has some corner cases that mean we have to check124* directories to see if any unlinks have been done before125* the directory was logged. See tree-log.c for all the126* details127*/128u64 last_unlink_trans;129130/*131* Counters to keep track of the number of extent item's we may use due132* to delalloc and such. outstanding_extents is the number of extent133* items we think we'll end up using, and reserved_extents is the number134* of extent items we've reserved metadata for.135*/136atomic_t outstanding_extents;137atomic_t reserved_extents;138139/*140* ordered_data_close is set by truncate when a file that used141* to have good data has been truncated to zero. When it is set142* the btrfs file release call will add this inode to the143* ordered operations list so that we make sure to flush out any144* new data the application may have written before commit.145*146* yes, its silly to have a single bitflag, but we might grow more147* of these.148*/149unsigned ordered_data_close:1;150unsigned orphan_meta_reserved:1;151unsigned dummy_inode:1;152unsigned in_defrag:1;153154/*155* always compress this one file156*/157unsigned force_compress:4;158159struct btrfs_delayed_node *delayed_node;160161struct inode vfs_inode;162};163164extern unsigned char btrfs_filetype_table[];165166static inline struct btrfs_inode *BTRFS_I(struct inode *inode)167{168return container_of(inode, struct btrfs_inode, vfs_inode);169}170171static inline u64 btrfs_ino(struct inode *inode)172{173u64 ino = BTRFS_I(inode)->location.objectid;174175if (ino <= BTRFS_FIRST_FREE_OBJECTID)176ino = inode->i_ino;177return ino;178}179180static inline void btrfs_i_size_write(struct inode *inode, u64 size)181{182i_size_write(inode, size);183BTRFS_I(inode)->disk_i_size = size;184}185186#endif187188189