![]() |
|
|||
0001 /* SPDX-License-Identifier: GPL-2.0-or-later */ 0002 /* 0003 * lcnalloc.h - Exports for NTFS kernel cluster (de)allocation. Part of the 0004 * Linux-NTFS project. 0005 * 0006 * Copyright (c) 2004-2005 Anton Altaparmakov 0007 */ 0008 0009 #ifndef _LINUX_NTFS_LCNALLOC_H 0010 #define _LINUX_NTFS_LCNALLOC_H 0011 0012 #ifdef NTFS_RW 0013 0014 #include <linux/fs.h> 0015 0016 #include "attrib.h" 0017 #include "types.h" 0018 #include "inode.h" 0019 #include "runlist.h" 0020 #include "volume.h" 0021 0022 typedef enum { 0023 FIRST_ZONE = 0, /* For sanity checking. */ 0024 MFT_ZONE = 0, /* Allocate from $MFT zone. */ 0025 DATA_ZONE = 1, /* Allocate from $DATA zone. */ 0026 LAST_ZONE = 1, /* For sanity checking. */ 0027 } NTFS_CLUSTER_ALLOCATION_ZONES; 0028 0029 extern runlist_element *ntfs_cluster_alloc(ntfs_volume *vol, 0030 const VCN start_vcn, const s64 count, const LCN start_lcn, 0031 const NTFS_CLUSTER_ALLOCATION_ZONES zone, 0032 const bool is_extension); 0033 0034 extern s64 __ntfs_cluster_free(ntfs_inode *ni, const VCN start_vcn, 0035 s64 count, ntfs_attr_search_ctx *ctx, const bool is_rollback); 0036 0037 /** 0038 * ntfs_cluster_free - free clusters on an ntfs volume 0039 * @ni: ntfs inode whose runlist describes the clusters to free 0040 * @start_vcn: vcn in the runlist of @ni at which to start freeing clusters 0041 * @count: number of clusters to free or -1 for all clusters 0042 * @ctx: active attribute search context if present or NULL if not 0043 * 0044 * Free @count clusters starting at the cluster @start_vcn in the runlist 0045 * described by the ntfs inode @ni. 0046 * 0047 * If @count is -1, all clusters from @start_vcn to the end of the runlist are 0048 * deallocated. Thus, to completely free all clusters in a runlist, use 0049 * @start_vcn = 0 and @count = -1. 0050 * 0051 * If @ctx is specified, it is an active search context of @ni and its base mft 0052 * record. This is needed when ntfs_cluster_free() encounters unmapped runlist 0053 * fragments and allows their mapping. If you do not have the mft record 0054 * mapped, you can specify @ctx as NULL and ntfs_cluster_free() will perform 0055 * the necessary mapping and unmapping. 0056 * 0057 * Note, ntfs_cluster_free() saves the state of @ctx on entry and restores it 0058 * before returning. Thus, @ctx will be left pointing to the same attribute on 0059 * return as on entry. However, the actual pointers in @ctx may point to 0060 * different memory locations on return, so you must remember to reset any 0061 * cached pointers from the @ctx, i.e. after the call to ntfs_cluster_free(), 0062 * you will probably want to do: 0063 * m = ctx->mrec; 0064 * a = ctx->attr; 0065 * Assuming you cache ctx->attr in a variable @a of type ATTR_RECORD * and that 0066 * you cache ctx->mrec in a variable @m of type MFT_RECORD *. 0067 * 0068 * Note, ntfs_cluster_free() does not modify the runlist, so you have to remove 0069 * from the runlist or mark sparse the freed runs later. 0070 * 0071 * Return the number of deallocated clusters (not counting sparse ones) on 0072 * success and -errno on error. 0073 * 0074 * WARNING: If @ctx is supplied, regardless of whether success or failure is 0075 * returned, you need to check IS_ERR(@ctx->mrec) and if 'true' the @ctx 0076 * is no longer valid, i.e. you need to either call 0077 * ntfs_attr_reinit_search_ctx() or ntfs_attr_put_search_ctx() on it. 0078 * In that case PTR_ERR(@ctx->mrec) will give you the error code for 0079 * why the mapping of the old inode failed. 0080 * 0081 * Locking: - The runlist described by @ni must be locked for writing on entry 0082 * and is locked on return. Note the runlist may be modified when 0083 * needed runlist fragments need to be mapped. 0084 * - The volume lcn bitmap must be unlocked on entry and is unlocked 0085 * on return. 0086 * - This function takes the volume lcn bitmap lock for writing and 0087 * modifies the bitmap contents. 0088 * - If @ctx is NULL, the base mft record of @ni must not be mapped on 0089 * entry and it will be left unmapped on return. 0090 * - If @ctx is not NULL, the base mft record must be mapped on entry 0091 * and it will be left mapped on return. 0092 */ 0093 static inline s64 ntfs_cluster_free(ntfs_inode *ni, const VCN start_vcn, 0094 s64 count, ntfs_attr_search_ctx *ctx) 0095 { 0096 return __ntfs_cluster_free(ni, start_vcn, count, ctx, false); 0097 } 0098 0099 extern int ntfs_cluster_free_from_rl_nolock(ntfs_volume *vol, 0100 const runlist_element *rl); 0101 0102 /** 0103 * ntfs_cluster_free_from_rl - free clusters from runlist 0104 * @vol: mounted ntfs volume on which to free the clusters 0105 * @rl: runlist describing the clusters to free 0106 * 0107 * Free all the clusters described by the runlist @rl on the volume @vol. In 0108 * the case of an error being returned, at least some of the clusters were not 0109 * freed. 0110 * 0111 * Return 0 on success and -errno on error. 0112 * 0113 * Locking: - This function takes the volume lcn bitmap lock for writing and 0114 * modifies the bitmap contents. 0115 * - The caller must have locked the runlist @rl for reading or 0116 * writing. 0117 */ 0118 static inline int ntfs_cluster_free_from_rl(ntfs_volume *vol, 0119 const runlist_element *rl) 0120 { 0121 int ret; 0122 0123 down_write(&vol->lcnbmp_lock); 0124 ret = ntfs_cluster_free_from_rl_nolock(vol, rl); 0125 up_write(&vol->lcnbmp_lock); 0126 return ret; 0127 } 0128 0129 #endif /* NTFS_RW */ 0130 0131 #endif /* defined _LINUX_NTFS_LCNALLOC_H */
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.1.0 LXR engine. The LXR team |
![]() ![]() |