xref: /openbmc/linux/fs/ocfs2/extent_map.h (revision 1061f9c1)
1ccd979bdSMark Fasheh /* -*- mode: c; c-basic-offset: 8; -*-
2ccd979bdSMark Fasheh  * vim: noexpandtab sw=8 ts=8 sts=0:
3ccd979bdSMark Fasheh  *
4ccd979bdSMark Fasheh  * extent_map.h
5ccd979bdSMark Fasheh  *
6ccd979bdSMark Fasheh  * In-memory file extent mappings for OCFS2.
7ccd979bdSMark Fasheh  *
8ccd979bdSMark Fasheh  * Copyright (C) 2004 Oracle.  All rights reserved.
9ccd979bdSMark Fasheh  *
10ccd979bdSMark Fasheh  * This program is free software; you can redistribute it and/or
11ccd979bdSMark Fasheh  * modify it under the terms of the GNU General Public
12ccd979bdSMark Fasheh  * License, version 2,  as published by the Free Software Foundation.
13ccd979bdSMark Fasheh  *
14ccd979bdSMark Fasheh  * This program is distributed in the hope that it will be useful,
15ccd979bdSMark Fasheh  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16ccd979bdSMark Fasheh  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17ccd979bdSMark Fasheh  * General Public License for more details.
18ccd979bdSMark Fasheh  *
19ccd979bdSMark Fasheh  * You should have received a copy of the GNU General Public
20ccd979bdSMark Fasheh  * License along with this program; if not, write to the
21ccd979bdSMark Fasheh  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22ccd979bdSMark Fasheh  * Boston, MA 021110-1307, USA.
23ccd979bdSMark Fasheh  */
24ccd979bdSMark Fasheh 
25ccd979bdSMark Fasheh #ifndef _EXTENT_MAP_H
26ccd979bdSMark Fasheh #define _EXTENT_MAP_H
27ccd979bdSMark Fasheh 
2883418978SMark Fasheh struct ocfs2_extent_map_item {
2983418978SMark Fasheh 	unsigned int			ei_cpos;
3083418978SMark Fasheh 	unsigned int			ei_phys;
3183418978SMark Fasheh 	unsigned int			ei_clusters;
3283418978SMark Fasheh 	unsigned int			ei_flags;
3383418978SMark Fasheh 
3483418978SMark Fasheh 	struct list_head		ei_list;
3583418978SMark Fasheh };
3683418978SMark Fasheh 
3783418978SMark Fasheh #define OCFS2_MAX_EXTENT_MAP_ITEMS			3
3883418978SMark Fasheh struct ocfs2_extent_map {
3983418978SMark Fasheh 	unsigned int			em_num_items;
4083418978SMark Fasheh 	struct list_head		em_list;
4183418978SMark Fasheh };
4283418978SMark Fasheh 
4383418978SMark Fasheh void ocfs2_extent_map_init(struct inode *inode);
4483418978SMark Fasheh void ocfs2_extent_map_trunc(struct inode *inode, unsigned int cluster);
4583418978SMark Fasheh void ocfs2_extent_map_insert_rec(struct inode *inode,
4683418978SMark Fasheh 				 struct ocfs2_extent_rec *rec);
4783418978SMark Fasheh 
489517bac6SMark Fasheh int ocfs2_get_clusters(struct inode *inode, u32 v_cluster, u32 *p_cluster,
4949cb8d2dSMark Fasheh 		       u32 *num_clusters, unsigned int *extent_flags);
50363041a5SMark Fasheh int ocfs2_extent_map_get_blocks(struct inode *inode, u64 v_blkno, u64 *p_blkno,
514f902c37SMark Fasheh 				u64 *ret_count, unsigned int *extent_flags);
52ccd979bdSMark Fasheh 
5300dc417fSMark Fasheh int ocfs2_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
5400dc417fSMark Fasheh 		 u64 map_start, u64 map_len);
5500dc417fSMark Fasheh 
56f56654c4STao Ma int ocfs2_xattr_get_clusters(struct inode *inode, u32 v_cluster,
57f56654c4STao Ma 			     u32 *p_cluster, u32 *num_clusters,
581061f9c1STao Ma 			     struct ocfs2_extent_list *el,
591061f9c1STao Ma 			     unsigned int *extent_flags);
60f56654c4STao Ma 
61a8549fb5SJoel Becker int ocfs2_read_virt_blocks(struct inode *inode, u64 v_block, int nr,
62a8549fb5SJoel Becker 			   struct buffer_head *bhs[], int flags,
63a8549fb5SJoel Becker 			   int (*validate)(struct super_block *sb,
64a8549fb5SJoel Becker 					   struct buffer_head *bh));
65e73a819dSTao Ma int ocfs2_figure_hole_clusters(struct ocfs2_caching_info *ci,
66e73a819dSTao Ma 			       struct ocfs2_extent_list *el,
67e73a819dSTao Ma 			       struct buffer_head *eb_bh,
68e73a819dSTao Ma 			       u32 v_cluster,
69e73a819dSTao Ma 			       u32 *num_clusters);
70a8549fb5SJoel Becker static inline int ocfs2_read_virt_block(struct inode *inode, u64 v_block,
71a8549fb5SJoel Becker 					struct buffer_head **bh,
72a8549fb5SJoel Becker 					int (*validate)(struct super_block *sb,
73a8549fb5SJoel Becker 							struct buffer_head *bh))
74a8549fb5SJoel Becker {
75a8549fb5SJoel Becker 	int status = 0;
76a8549fb5SJoel Becker 
77a8549fb5SJoel Becker 	if (bh == NULL) {
78a8549fb5SJoel Becker 		printk("ocfs2: bh == NULL\n");
79a8549fb5SJoel Becker 		status = -EINVAL;
80a8549fb5SJoel Becker 		goto bail;
81a8549fb5SJoel Becker 	}
82a8549fb5SJoel Becker 
83a8549fb5SJoel Becker 	status = ocfs2_read_virt_blocks(inode, v_block, 1, bh, 0, validate);
84a8549fb5SJoel Becker 
85a8549fb5SJoel Becker bail:
86a8549fb5SJoel Becker 	return status;
87a8549fb5SJoel Becker }
88a8549fb5SJoel Becker 
89a8549fb5SJoel Becker 
90ccd979bdSMark Fasheh #endif  /* _EXTENT_MAP_H */
91