18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * runlist.h - Defines for runlist handling in NTFS Linux kernel driver.
48c2ecf20Sopenharmony_ci *	       Part of the Linux-NTFS project.
58c2ecf20Sopenharmony_ci *
68c2ecf20Sopenharmony_ci * Copyright (c) 2001-2005 Anton Altaparmakov
78c2ecf20Sopenharmony_ci * Copyright (c) 2002 Richard Russon
88c2ecf20Sopenharmony_ci */
98c2ecf20Sopenharmony_ci
108c2ecf20Sopenharmony_ci#ifndef _LINUX_NTFS_RUNLIST_H
118c2ecf20Sopenharmony_ci#define _LINUX_NTFS_RUNLIST_H
128c2ecf20Sopenharmony_ci
138c2ecf20Sopenharmony_ci#include "types.h"
148c2ecf20Sopenharmony_ci#include "layout.h"
158c2ecf20Sopenharmony_ci#include "volume.h"
168c2ecf20Sopenharmony_ci
178c2ecf20Sopenharmony_ci/**
188c2ecf20Sopenharmony_ci * runlist_element - in memory vcn to lcn mapping array element
198c2ecf20Sopenharmony_ci * @vcn:	starting vcn of the current array element
208c2ecf20Sopenharmony_ci * @lcn:	starting lcn of the current array element
218c2ecf20Sopenharmony_ci * @length:	length in clusters of the current array element
228c2ecf20Sopenharmony_ci *
238c2ecf20Sopenharmony_ci * The last vcn (in fact the last vcn + 1) is reached when length == 0.
248c2ecf20Sopenharmony_ci *
258c2ecf20Sopenharmony_ci * When lcn == -1 this means that the count vcns starting at vcn are not
268c2ecf20Sopenharmony_ci * physically allocated (i.e. this is a hole / data is sparse).
278c2ecf20Sopenharmony_ci */
288c2ecf20Sopenharmony_citypedef struct {	/* In memory vcn to lcn mapping structure element. */
298c2ecf20Sopenharmony_ci	VCN vcn;	/* vcn = Starting virtual cluster number. */
308c2ecf20Sopenharmony_ci	LCN lcn;	/* lcn = Starting logical cluster number. */
318c2ecf20Sopenharmony_ci	s64 length;	/* Run length in clusters. */
328c2ecf20Sopenharmony_ci} runlist_element;
338c2ecf20Sopenharmony_ci
348c2ecf20Sopenharmony_ci/**
358c2ecf20Sopenharmony_ci * runlist - in memory vcn to lcn mapping array including a read/write lock
368c2ecf20Sopenharmony_ci * @rl:		pointer to an array of runlist elements
378c2ecf20Sopenharmony_ci * @lock:	read/write spinlock for serializing access to @rl
388c2ecf20Sopenharmony_ci *
398c2ecf20Sopenharmony_ci */
408c2ecf20Sopenharmony_citypedef struct {
418c2ecf20Sopenharmony_ci	runlist_element *rl;
428c2ecf20Sopenharmony_ci	struct rw_semaphore lock;
438c2ecf20Sopenharmony_ci} runlist;
448c2ecf20Sopenharmony_ci
458c2ecf20Sopenharmony_cistatic inline void ntfs_init_runlist(runlist *rl)
468c2ecf20Sopenharmony_ci{
478c2ecf20Sopenharmony_ci	rl->rl = NULL;
488c2ecf20Sopenharmony_ci	init_rwsem(&rl->lock);
498c2ecf20Sopenharmony_ci}
508c2ecf20Sopenharmony_ci
518c2ecf20Sopenharmony_citypedef enum {
528c2ecf20Sopenharmony_ci	LCN_HOLE		= -1,	/* Keep this as highest value or die! */
538c2ecf20Sopenharmony_ci	LCN_RL_NOT_MAPPED	= -2,
548c2ecf20Sopenharmony_ci	LCN_ENOENT		= -3,
558c2ecf20Sopenharmony_ci	LCN_ENOMEM		= -4,
568c2ecf20Sopenharmony_ci	LCN_EIO			= -5,
578c2ecf20Sopenharmony_ci} LCN_SPECIAL_VALUES;
588c2ecf20Sopenharmony_ci
598c2ecf20Sopenharmony_ciextern runlist_element *ntfs_runlists_merge(runlist_element *drl,
608c2ecf20Sopenharmony_ci		runlist_element *srl);
618c2ecf20Sopenharmony_ci
628c2ecf20Sopenharmony_ciextern runlist_element *ntfs_mapping_pairs_decompress(const ntfs_volume *vol,
638c2ecf20Sopenharmony_ci		const ATTR_RECORD *attr, runlist_element *old_rl);
648c2ecf20Sopenharmony_ci
658c2ecf20Sopenharmony_ciextern LCN ntfs_rl_vcn_to_lcn(const runlist_element *rl, const VCN vcn);
668c2ecf20Sopenharmony_ci
678c2ecf20Sopenharmony_ci#ifdef NTFS_RW
688c2ecf20Sopenharmony_ci
698c2ecf20Sopenharmony_ciextern runlist_element *ntfs_rl_find_vcn_nolock(runlist_element *rl,
708c2ecf20Sopenharmony_ci		const VCN vcn);
718c2ecf20Sopenharmony_ci
728c2ecf20Sopenharmony_ciextern int ntfs_get_size_for_mapping_pairs(const ntfs_volume *vol,
738c2ecf20Sopenharmony_ci		const runlist_element *rl, const VCN first_vcn,
748c2ecf20Sopenharmony_ci		const VCN last_vcn);
758c2ecf20Sopenharmony_ci
768c2ecf20Sopenharmony_ciextern int ntfs_mapping_pairs_build(const ntfs_volume *vol, s8 *dst,
778c2ecf20Sopenharmony_ci		const int dst_len, const runlist_element *rl,
788c2ecf20Sopenharmony_ci		const VCN first_vcn, const VCN last_vcn, VCN *const stop_vcn);
798c2ecf20Sopenharmony_ci
808c2ecf20Sopenharmony_ciextern int ntfs_rl_truncate_nolock(const ntfs_volume *vol,
818c2ecf20Sopenharmony_ci		runlist *const runlist, const s64 new_length);
828c2ecf20Sopenharmony_ci
838c2ecf20Sopenharmony_ciint ntfs_rl_punch_nolock(const ntfs_volume *vol, runlist *const runlist,
848c2ecf20Sopenharmony_ci		const VCN start, const s64 length);
858c2ecf20Sopenharmony_ci
868c2ecf20Sopenharmony_ci#endif /* NTFS_RW */
878c2ecf20Sopenharmony_ci
888c2ecf20Sopenharmony_ci#endif /* _LINUX_NTFS_RUNLIST_H */
89