Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-or-later */
0002 /*
0003  * runlist.h - Defines for runlist handling in NTFS Linux kernel driver.
0004  *         Part of the Linux-NTFS project.
0005  *
0006  * Copyright (c) 2001-2005 Anton Altaparmakov
0007  * Copyright (c) 2002 Richard Russon
0008  */
0009 
0010 #ifndef _LINUX_NTFS_RUNLIST_H
0011 #define _LINUX_NTFS_RUNLIST_H
0012 
0013 #include "types.h"
0014 #include "layout.h"
0015 #include "volume.h"
0016 
0017 /**
0018  * runlist_element - in memory vcn to lcn mapping array element
0019  * @vcn:    starting vcn of the current array element
0020  * @lcn:    starting lcn of the current array element
0021  * @length: length in clusters of the current array element
0022  *
0023  * The last vcn (in fact the last vcn + 1) is reached when length == 0.
0024  *
0025  * When lcn == -1 this means that the count vcns starting at vcn are not
0026  * physically allocated (i.e. this is a hole / data is sparse).
0027  */
0028 typedef struct {    /* In memory vcn to lcn mapping structure element. */
0029     VCN vcn;    /* vcn = Starting virtual cluster number. */
0030     LCN lcn;    /* lcn = Starting logical cluster number. */
0031     s64 length; /* Run length in clusters. */
0032 } runlist_element;
0033 
0034 /**
0035  * runlist - in memory vcn to lcn mapping array including a read/write lock
0036  * @rl:     pointer to an array of runlist elements
0037  * @lock:   read/write spinlock for serializing access to @rl
0038  *
0039  */
0040 typedef struct {
0041     runlist_element *rl;
0042     struct rw_semaphore lock;
0043 } runlist;
0044 
0045 static inline void ntfs_init_runlist(runlist *rl)
0046 {
0047     rl->rl = NULL;
0048     init_rwsem(&rl->lock);
0049 }
0050 
0051 typedef enum {
0052     LCN_HOLE        = -1,   /* Keep this as highest value or die! */
0053     LCN_RL_NOT_MAPPED   = -2,
0054     LCN_ENOENT      = -3,
0055     LCN_ENOMEM      = -4,
0056     LCN_EIO         = -5,
0057 } LCN_SPECIAL_VALUES;
0058 
0059 extern runlist_element *ntfs_runlists_merge(runlist_element *drl,
0060         runlist_element *srl);
0061 
0062 extern runlist_element *ntfs_mapping_pairs_decompress(const ntfs_volume *vol,
0063         const ATTR_RECORD *attr, runlist_element *old_rl);
0064 
0065 extern LCN ntfs_rl_vcn_to_lcn(const runlist_element *rl, const VCN vcn);
0066 
0067 #ifdef NTFS_RW
0068 
0069 extern runlist_element *ntfs_rl_find_vcn_nolock(runlist_element *rl,
0070         const VCN vcn);
0071 
0072 extern int ntfs_get_size_for_mapping_pairs(const ntfs_volume *vol,
0073         const runlist_element *rl, const VCN first_vcn,
0074         const VCN last_vcn);
0075 
0076 extern int ntfs_mapping_pairs_build(const ntfs_volume *vol, s8 *dst,
0077         const int dst_len, const runlist_element *rl,
0078         const VCN first_vcn, const VCN last_vcn, VCN *const stop_vcn);
0079 
0080 extern int ntfs_rl_truncate_nolock(const ntfs_volume *vol,
0081         runlist *const runlist, const s64 new_length);
0082 
0083 int ntfs_rl_punch_nolock(const ntfs_volume *vol, runlist *const runlist,
0084         const VCN start, const s64 length);
0085 
0086 #endif /* NTFS_RW */
0087 
0088 #endif /* _LINUX_NTFS_RUNLIST_H */