162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci * extent_map.h
462306a36Sopenharmony_ci *
562306a36Sopenharmony_ci * In-memory file extent mappings for OCFS2.
662306a36Sopenharmony_ci *
762306a36Sopenharmony_ci * Copyright (C) 2004 Oracle.  All rights reserved.
862306a36Sopenharmony_ci */
962306a36Sopenharmony_ci
1062306a36Sopenharmony_ci#ifndef _EXTENT_MAP_H
1162306a36Sopenharmony_ci#define _EXTENT_MAP_H
1262306a36Sopenharmony_ci
1362306a36Sopenharmony_cistruct ocfs2_extent_map_item {
1462306a36Sopenharmony_ci	unsigned int			ei_cpos;
1562306a36Sopenharmony_ci	unsigned int			ei_phys;
1662306a36Sopenharmony_ci	unsigned int			ei_clusters;
1762306a36Sopenharmony_ci	unsigned int			ei_flags;
1862306a36Sopenharmony_ci
1962306a36Sopenharmony_ci	struct list_head		ei_list;
2062306a36Sopenharmony_ci};
2162306a36Sopenharmony_ci
2262306a36Sopenharmony_ci#define OCFS2_MAX_EXTENT_MAP_ITEMS			3
2362306a36Sopenharmony_cistruct ocfs2_extent_map {
2462306a36Sopenharmony_ci	unsigned int			em_num_items;
2562306a36Sopenharmony_ci	struct list_head		em_list;
2662306a36Sopenharmony_ci};
2762306a36Sopenharmony_ci
2862306a36Sopenharmony_civoid ocfs2_extent_map_init(struct inode *inode);
2962306a36Sopenharmony_civoid ocfs2_extent_map_trunc(struct inode *inode, unsigned int cluster);
3062306a36Sopenharmony_civoid ocfs2_extent_map_insert_rec(struct inode *inode,
3162306a36Sopenharmony_ci				 struct ocfs2_extent_rec *rec);
3262306a36Sopenharmony_ci
3362306a36Sopenharmony_ciint ocfs2_get_clusters(struct inode *inode, u32 v_cluster, u32 *p_cluster,
3462306a36Sopenharmony_ci		       u32 *num_clusters, unsigned int *extent_flags);
3562306a36Sopenharmony_ciint ocfs2_extent_map_get_blocks(struct inode *inode, u64 v_blkno, u64 *p_blkno,
3662306a36Sopenharmony_ci				u64 *ret_count, unsigned int *extent_flags);
3762306a36Sopenharmony_ci
3862306a36Sopenharmony_ciint ocfs2_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
3962306a36Sopenharmony_ci		 u64 map_start, u64 map_len);
4062306a36Sopenharmony_ci
4162306a36Sopenharmony_ciint ocfs2_overwrite_io(struct inode *inode, struct buffer_head *di_bh,
4262306a36Sopenharmony_ci		       u64 map_start, u64 map_len);
4362306a36Sopenharmony_ci
4462306a36Sopenharmony_ciint ocfs2_seek_data_hole_offset(struct file *file, loff_t *offset, int origin);
4562306a36Sopenharmony_ci
4662306a36Sopenharmony_ciint ocfs2_xattr_get_clusters(struct inode *inode, u32 v_cluster,
4762306a36Sopenharmony_ci			     u32 *p_cluster, u32 *num_clusters,
4862306a36Sopenharmony_ci			     struct ocfs2_extent_list *el,
4962306a36Sopenharmony_ci			     unsigned int *extent_flags);
5062306a36Sopenharmony_ci
5162306a36Sopenharmony_ciint ocfs2_read_virt_blocks(struct inode *inode, u64 v_block, int nr,
5262306a36Sopenharmony_ci			   struct buffer_head *bhs[], int flags,
5362306a36Sopenharmony_ci			   int (*validate)(struct super_block *sb,
5462306a36Sopenharmony_ci					   struct buffer_head *bh));
5562306a36Sopenharmony_ciint ocfs2_figure_hole_clusters(struct ocfs2_caching_info *ci,
5662306a36Sopenharmony_ci			       struct ocfs2_extent_list *el,
5762306a36Sopenharmony_ci			       struct buffer_head *eb_bh,
5862306a36Sopenharmony_ci			       u32 v_cluster,
5962306a36Sopenharmony_ci			       u32 *num_clusters);
6062306a36Sopenharmony_cistatic inline int ocfs2_read_virt_block(struct inode *inode, u64 v_block,
6162306a36Sopenharmony_ci					struct buffer_head **bh,
6262306a36Sopenharmony_ci					int (*validate)(struct super_block *sb,
6362306a36Sopenharmony_ci							struct buffer_head *bh))
6462306a36Sopenharmony_ci{
6562306a36Sopenharmony_ci	int status = 0;
6662306a36Sopenharmony_ci
6762306a36Sopenharmony_ci	if (bh == NULL) {
6862306a36Sopenharmony_ci		printk("ocfs2: bh == NULL\n");
6962306a36Sopenharmony_ci		status = -EINVAL;
7062306a36Sopenharmony_ci		goto bail;
7162306a36Sopenharmony_ci	}
7262306a36Sopenharmony_ci
7362306a36Sopenharmony_ci	status = ocfs2_read_virt_blocks(inode, v_block, 1, bh, 0, validate);
7462306a36Sopenharmony_ci
7562306a36Sopenharmony_cibail:
7662306a36Sopenharmony_ci	return status;
7762306a36Sopenharmony_ci}
7862306a36Sopenharmony_ci
7962306a36Sopenharmony_ci
8062306a36Sopenharmony_ci#endif  /* _EXTENT_MAP_H */
81