xref: /linux/fs/xfs/xfs_bmap_util.h (revision 825e587af2e90e9b953849f3347a01d8f383d577)
168988114SDave Chinner /*
268988114SDave Chinner  * Copyright (c) 2000-2006 Silicon Graphics, Inc.
368988114SDave Chinner  * All Rights Reserved.
468988114SDave Chinner  *
568988114SDave Chinner  * This program is free software; you can redistribute it and/or
668988114SDave Chinner  * modify it under the terms of the GNU General Public License as
768988114SDave Chinner  * published by the Free Software Foundation.
868988114SDave Chinner  *
968988114SDave Chinner  * This program is distributed in the hope that it would be useful,
1068988114SDave Chinner  * but WITHOUT ANY WARRANTY; without even the implied warranty of
1168988114SDave Chinner  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1268988114SDave Chinner  * GNU General Public License for more details.
1368988114SDave Chinner  *
1468988114SDave Chinner  * You should have received a copy of the GNU General Public License
1568988114SDave Chinner  * along with this program; if not, write the Free Software Foundation,
1668988114SDave Chinner  * Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
1768988114SDave Chinner  */
1868988114SDave Chinner #ifndef __XFS_BMAP_UTIL_H__
1968988114SDave Chinner #define	__XFS_BMAP_UTIL_H__
2068988114SDave Chinner 
2168988114SDave Chinner /* Kernel only BMAP related definitions and functions */
2268988114SDave Chinner 
2368988114SDave Chinner struct xfs_bmbt_irec;
24c24b5dfaSDave Chinner struct xfs_bmap_free_item;
2568988114SDave Chinner struct xfs_ifork;
2668988114SDave Chinner struct xfs_inode;
2768988114SDave Chinner struct xfs_mount;
2868988114SDave Chinner struct xfs_trans;
2968988114SDave Chinner 
3068988114SDave Chinner /*
3168988114SDave Chinner  * Argument structure for xfs_bmap_alloc.
3268988114SDave Chinner  */
3368988114SDave Chinner struct xfs_bmalloca {
3468988114SDave Chinner 	xfs_fsblock_t		*firstblock; /* i/o first block allocated */
3568988114SDave Chinner 	struct xfs_bmap_free	*flist;	/* bmap freelist */
3668988114SDave Chinner 	struct xfs_trans	*tp;	/* transaction pointer */
3768988114SDave Chinner 	struct xfs_inode	*ip;	/* incore inode pointer */
3868988114SDave Chinner 	struct xfs_bmbt_irec	prev;	/* extent before the new one */
3968988114SDave Chinner 	struct xfs_bmbt_irec	got;	/* extent after, or delayed */
4068988114SDave Chinner 
4168988114SDave Chinner 	xfs_fileoff_t		offset;	/* offset in file filling in */
4268988114SDave Chinner 	xfs_extlen_t		length;	/* i/o length asked/allocated */
4368988114SDave Chinner 	xfs_fsblock_t		blkno;	/* starting block of new extent */
4468988114SDave Chinner 
4568988114SDave Chinner 	struct xfs_btree_cur	*cur;	/* btree cursor */
4668988114SDave Chinner 	xfs_extnum_t		idx;	/* current extent index */
4768988114SDave Chinner 	int			nallocs;/* number of extents alloc'd */
4868988114SDave Chinner 	int			logflags;/* flags for transaction logging */
4968988114SDave Chinner 
5068988114SDave Chinner 	xfs_extlen_t		total;	/* total blocks needed for xaction */
5168988114SDave Chinner 	xfs_extlen_t		minlen;	/* minimum allocation size (blocks) */
5268988114SDave Chinner 	xfs_extlen_t		minleft; /* amount must be left after alloc */
5368988114SDave Chinner 	char			eof;	/* set if allocating past last extent */
5468988114SDave Chinner 	char			wasdel;	/* replacing a delayed allocation */
5568988114SDave Chinner 	char			userdata;/* set if is user data */
5668988114SDave Chinner 	char			aeof;	/* allocated space at eof */
5768988114SDave Chinner 	char			conv;	/* overwriting unwritten extents */
5868988114SDave Chinner 	char			stack_switch;
5968988114SDave Chinner 	int			flags;
6068988114SDave Chinner 	struct completion	*done;
6168988114SDave Chinner 	struct work_struct	work;
6268988114SDave Chinner 	int			result;
6368988114SDave Chinner };
6468988114SDave Chinner 
6568988114SDave Chinner int	xfs_bmap_finish(struct xfs_trans **tp, struct xfs_bmap_free *flist,
6668988114SDave Chinner 			int *committed);
6768988114SDave Chinner int	xfs_bmap_rtalloc(struct xfs_bmalloca *ap);
6868988114SDave Chinner int	xfs_bmapi_allocate(struct xfs_bmalloca *args);
6968988114SDave Chinner int	__xfs_bmapi_allocate(struct xfs_bmalloca *args);
7068988114SDave Chinner int	xfs_bmap_eof(struct xfs_inode *ip, xfs_fileoff_t endoff,
7168988114SDave Chinner 		     int whichfork, int *eof);
7268988114SDave Chinner int	xfs_bmap_count_blocks(struct xfs_trans *tp, struct xfs_inode *ip,
7368988114SDave Chinner 			      int whichfork, int *count);
7468988114SDave Chinner int	xfs_bmap_punch_delalloc_range(struct xfs_inode *ip,
7568988114SDave Chinner 		xfs_fileoff_t start_fsb, xfs_fileoff_t length);
7668988114SDave Chinner 
7768988114SDave Chinner /* bmap to userspace formatter - copy to user & advance pointer */
7868988114SDave Chinner typedef int (*xfs_bmap_format_t)(void **, struct getbmapx *, int *);
7968988114SDave Chinner int	xfs_getbmap(struct xfs_inode *ip, struct getbmapx *bmv,
8068988114SDave Chinner 		xfs_bmap_format_t formatter, void *arg);
8168988114SDave Chinner 
8268988114SDave Chinner /* functions in xfs_bmap.c that are only needed by xfs_bmap_util.c */
8368988114SDave Chinner void	xfs_bmap_del_free(struct xfs_bmap_free *flist,
8468988114SDave Chinner 			  struct xfs_bmap_free_item *prev,
8568988114SDave Chinner 			  struct xfs_bmap_free_item *free);
8668988114SDave Chinner int	xfs_bmap_extsize_align(struct xfs_mount *mp, struct xfs_bmbt_irec *gotp,
8768988114SDave Chinner 			       struct xfs_bmbt_irec *prevp, xfs_extlen_t extsz,
8868988114SDave Chinner 			       int rt, int eof, int delay, int convert,
8968988114SDave Chinner 			       xfs_fileoff_t *offp, xfs_extlen_t *lenp);
9068988114SDave Chinner void	xfs_bmap_adjacent(struct xfs_bmalloca *ap);
9168988114SDave Chinner int	xfs_bmap_last_extent(struct xfs_trans *tp, struct xfs_inode *ip,
9268988114SDave Chinner 			     int whichfork, struct xfs_bmbt_irec *rec,
9368988114SDave Chinner 			     int *is_empty);
9468988114SDave Chinner 
95c24b5dfaSDave Chinner /* preallocation and hole punch interface */
9683aee9e4SChristoph Hellwig int	xfs_alloc_file_space(struct xfs_inode *ip, xfs_off_t offset,
9783aee9e4SChristoph Hellwig 			     xfs_off_t len, int alloc_type);
9883aee9e4SChristoph Hellwig int	xfs_free_file_space(struct xfs_inode *ip, xfs_off_t offset,
9983aee9e4SChristoph Hellwig 			    xfs_off_t len);
100*865e9446SChristoph Hellwig int	xfs_zero_file_space(struct xfs_inode *ip, xfs_off_t offset,
101*865e9446SChristoph Hellwig 			    xfs_off_t len);
102c24b5dfaSDave Chinner 
103c24b5dfaSDave Chinner /* EOF block manipulation functions */
104c24b5dfaSDave Chinner bool	xfs_can_free_eofblocks(struct xfs_inode *ip, bool force);
105c24b5dfaSDave Chinner int	xfs_free_eofblocks(struct xfs_mount *mp, struct xfs_inode *ip,
106c24b5dfaSDave Chinner 			   bool need_iolock);
107c24b5dfaSDave Chinner 
108a133d952SDave Chinner int	xfs_swap_extents(struct xfs_inode *ip, struct xfs_inode *tip,
109a133d952SDave Chinner 			 struct xfs_swapext *sx);
110a133d952SDave Chinner 
11168988114SDave Chinner xfs_daddr_t xfs_fsb_to_db(struct xfs_inode *ip, xfs_fsblock_t fsb);
11268988114SDave Chinner 
11368988114SDave Chinner #endif	/* __XFS_BMAP_UTIL_H__ */
114