2 * Copyright (c) 2000-2003,2005 Silicon Graphics, Inc.
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation.
9 * This program is distributed in the hope that it would be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write the Free Software Foundation,
16 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 #ifndef __XFS_INODE_FORK_H__
19 #define __XFS_INODE_FORK_H__
21 struct xfs_inode_log_item
;
25 * The following xfs_ext_irec_t struct introduces a second (top) level
26 * to the in-core extent allocation scheme. These structs are allocated
27 * in a contiguous block, creating an indirection array where each entry
28 * (irec) contains a pointer to a buffer of in-core extent records which
29 * it manages. Each extent buffer is 4k in size, since 4k is the system
30 * page size on Linux i386 and systems with larger page sizes don't seem
31 * to gain much, if anything, by using their native page size as the
32 * extent buffer size. Also, using 4k extent buffers everywhere provides
33 * a consistent interface for CXFS across different platforms.
35 * There is currently no limit on the number of irec's (extent lists)
36 * allowed, so heavily fragmented files may require an indirection array
37 * which spans multiple system pages of memory. The number of extents
38 * which would require this amount of contiguous memory is very large
39 * and should not cause problems in the foreseeable future. However,
40 * if the memory needed for the contiguous array ever becomes a problem,
41 * it is possible that a third level of indirection may be required.
43 typedef struct xfs_ext_irec
{
44 xfs_bmbt_rec_host_t
*er_extbuf
; /* block of extent records */
45 xfs_extnum_t er_extoff
; /* extent offset in file */
46 xfs_extnum_t er_extcount
; /* number of extents in page/block */
50 * File incore extent information, present for each of data & attr forks.
52 #define XFS_IEXT_BUFSZ 4096
53 #define XFS_LINEAR_EXTS (XFS_IEXT_BUFSZ / (uint)sizeof(xfs_bmbt_rec_t))
54 #define XFS_INLINE_EXTS 2
55 #define XFS_INLINE_DATA 32
56 typedef struct xfs_ifork
{
57 int if_bytes
; /* bytes in if_u1 */
58 int if_real_bytes
; /* bytes allocated in if_u1 */
59 struct xfs_btree_block
*if_broot
; /* file's incore btree root */
60 short if_broot_bytes
; /* bytes allocated for root */
61 unsigned char if_flags
; /* per-fork flags */
63 xfs_bmbt_rec_host_t
*if_extents
;/* linear map file exts */
64 xfs_ext_irec_t
*if_ext_irec
; /* irec map file exts */
65 char *if_data
; /* inline file data */
68 xfs_bmbt_rec_host_t if_inline_ext
[XFS_INLINE_EXTS
];
69 /* very small file extents */
70 char if_inline_data
[XFS_INLINE_DATA
];
71 /* very small file data */
72 xfs_dev_t if_rdev
; /* dev number if special */
73 uuid_t if_uuid
; /* mount point value */
78 * Per-fork incore inode flags.
80 #define XFS_IFINLINE 0x01 /* Inline data is read in */
81 #define XFS_IFEXTENTS 0x02 /* All extent pointers are read in */
82 #define XFS_IFBROOT 0x04 /* i_broot points to the bmap b-tree root */
83 #define XFS_IFEXTIREC 0x08 /* Indirection array of extent blocks */
89 #define XFS_IFORK_Q(ip) ((ip)->i_d.di_forkoff != 0)
90 #define XFS_IFORK_BOFF(ip) ((int)((ip)->i_d.di_forkoff << 3))
92 #define XFS_IFORK_PTR(ip,w) \
93 ((w) == XFS_DATA_FORK ? \
95 ((w) == XFS_ATTR_FORK ? \
98 #define XFS_IFORK_DSIZE(ip) \
100 XFS_IFORK_BOFF(ip) : \
101 XFS_LITINO((ip)->i_mount, (ip)->i_d.di_version))
102 #define XFS_IFORK_ASIZE(ip) \
104 XFS_LITINO((ip)->i_mount, (ip)->i_d.di_version) - \
105 XFS_IFORK_BOFF(ip) : \
107 #define XFS_IFORK_SIZE(ip,w) \
108 ((w) == XFS_DATA_FORK ? \
109 XFS_IFORK_DSIZE(ip) : \
110 ((w) == XFS_ATTR_FORK ? \
111 XFS_IFORK_ASIZE(ip) : \
113 #define XFS_IFORK_FORMAT(ip,w) \
114 ((w) == XFS_DATA_FORK ? \
115 (ip)->i_d.di_format : \
116 ((w) == XFS_ATTR_FORK ? \
117 (ip)->i_d.di_aformat : \
119 #define XFS_IFORK_FMT_SET(ip,w,n) \
120 ((w) == XFS_DATA_FORK ? \
121 ((ip)->i_d.di_format = (n)) : \
122 ((w) == XFS_ATTR_FORK ? \
123 ((ip)->i_d.di_aformat = (n)) : \
124 ((ip)->i_cformat = (n))))
125 #define XFS_IFORK_NEXTENTS(ip,w) \
126 ((w) == XFS_DATA_FORK ? \
127 (ip)->i_d.di_nextents : \
128 ((w) == XFS_ATTR_FORK ? \
129 (ip)->i_d.di_anextents : \
131 #define XFS_IFORK_NEXT_SET(ip,w,n) \
132 ((w) == XFS_DATA_FORK ? \
133 ((ip)->i_d.di_nextents = (n)) : \
134 ((w) == XFS_ATTR_FORK ? \
135 ((ip)->i_d.di_anextents = (n)) : \
136 ((ip)->i_cnextents = (n))))
137 #define XFS_IFORK_MAXEXT(ip, w) \
138 (XFS_IFORK_SIZE(ip, w) / sizeof(xfs_bmbt_rec_t))
140 struct xfs_ifork
*xfs_iext_state_to_fork(struct xfs_inode
*ip
, int state
);
142 int xfs_iformat_fork(struct xfs_inode
*, struct xfs_dinode
*);
143 void xfs_iflush_fork(struct xfs_inode
*, struct xfs_dinode
*,
144 struct xfs_inode_log_item
*, int);
145 void xfs_idestroy_fork(struct xfs_inode
*, int);
146 void xfs_idata_realloc(struct xfs_inode
*, int, int);
147 void xfs_iroot_realloc(struct xfs_inode
*, int, int);
148 int xfs_iread_extents(struct xfs_trans
*, struct xfs_inode
*, int);
149 int xfs_iextents_copy(struct xfs_inode
*, struct xfs_bmbt_rec
*,
151 void xfs_init_local_fork(struct xfs_inode
*, int, const void *, int);
153 struct xfs_bmbt_rec_host
*
154 xfs_iext_get_ext(struct xfs_ifork
*, xfs_extnum_t
);
155 xfs_extnum_t
xfs_iext_count(struct xfs_ifork
*);
156 void xfs_iext_insert(struct xfs_inode
*, xfs_extnum_t
, xfs_extnum_t
,
157 struct xfs_bmbt_irec
*, int);
158 void xfs_iext_add(struct xfs_ifork
*, xfs_extnum_t
, int);
159 void xfs_iext_add_indirect_multi(struct xfs_ifork
*, int,
161 void xfs_iext_remove(struct xfs_inode
*, xfs_extnum_t
, int, int);
162 void xfs_iext_remove_inline(struct xfs_ifork
*, xfs_extnum_t
, int);
163 void xfs_iext_remove_direct(struct xfs_ifork
*, xfs_extnum_t
, int);
164 void xfs_iext_remove_indirect(struct xfs_ifork
*, xfs_extnum_t
, int);
165 void xfs_iext_realloc_direct(struct xfs_ifork
*, int);
166 void xfs_iext_direct_to_inline(struct xfs_ifork
*, xfs_extnum_t
);
167 void xfs_iext_inline_to_direct(struct xfs_ifork
*, int);
168 void xfs_iext_destroy(struct xfs_ifork
*);
169 struct xfs_bmbt_rec_host
*
170 xfs_iext_bno_to_ext(struct xfs_ifork
*, xfs_fileoff_t
, int *);
171 struct xfs_ext_irec
*
172 xfs_iext_bno_to_irec(struct xfs_ifork
*, xfs_fileoff_t
, int *);
173 struct xfs_ext_irec
*
174 xfs_iext_idx_to_irec(struct xfs_ifork
*, xfs_extnum_t
*, int *,
176 void xfs_iext_irec_init(struct xfs_ifork
*);
177 struct xfs_ext_irec
*
178 xfs_iext_irec_new(struct xfs_ifork
*, int);
179 void xfs_iext_irec_remove(struct xfs_ifork
*, int);
180 void xfs_iext_irec_compact(struct xfs_ifork
*);
181 void xfs_iext_irec_compact_pages(struct xfs_ifork
*);
182 void xfs_iext_irec_compact_full(struct xfs_ifork
*);
183 void xfs_iext_irec_update_extoffs(struct xfs_ifork
*, int, int);
185 bool xfs_iext_lookup_extent(struct xfs_inode
*ip
,
186 struct xfs_ifork
*ifp
, xfs_fileoff_t bno
,
187 xfs_extnum_t
*idxp
, struct xfs_bmbt_irec
*gotp
);
188 bool xfs_iext_get_extent(struct xfs_ifork
*ifp
, xfs_extnum_t idx
,
189 struct xfs_bmbt_irec
*gotp
);
190 void xfs_iext_update_extent(struct xfs_ifork
*ifp
, xfs_extnum_t idx
,
191 struct xfs_bmbt_irec
*gotp
);
193 extern struct kmem_zone
*xfs_ifork_zone
;
195 extern void xfs_ifork_init_cow(struct xfs_inode
*ip
);
197 #endif /* __XFS_INODE_FORK_H__ */