162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci * bitmap.h - Defines for NTFS kernel bitmap handling.  Part of the Linux-NTFS
462306a36Sopenharmony_ci *	      project.
562306a36Sopenharmony_ci *
662306a36Sopenharmony_ci * Copyright (c) 2004 Anton Altaparmakov
762306a36Sopenharmony_ci */
862306a36Sopenharmony_ci
962306a36Sopenharmony_ci#ifndef _LINUX_NTFS_BITMAP_H
1062306a36Sopenharmony_ci#define _LINUX_NTFS_BITMAP_H
1162306a36Sopenharmony_ci
1262306a36Sopenharmony_ci#ifdef NTFS_RW
1362306a36Sopenharmony_ci
1462306a36Sopenharmony_ci#include <linux/fs.h>
1562306a36Sopenharmony_ci
1662306a36Sopenharmony_ci#include "types.h"
1762306a36Sopenharmony_ci
1862306a36Sopenharmony_ciextern int __ntfs_bitmap_set_bits_in_run(struct inode *vi, const s64 start_bit,
1962306a36Sopenharmony_ci		const s64 count, const u8 value, const bool is_rollback);
2062306a36Sopenharmony_ci
2162306a36Sopenharmony_ci/**
2262306a36Sopenharmony_ci * ntfs_bitmap_set_bits_in_run - set a run of bits in a bitmap to a value
2362306a36Sopenharmony_ci * @vi:			vfs inode describing the bitmap
2462306a36Sopenharmony_ci * @start_bit:		first bit to set
2562306a36Sopenharmony_ci * @count:		number of bits to set
2662306a36Sopenharmony_ci * @value:		value to set the bits to (i.e. 0 or 1)
2762306a36Sopenharmony_ci *
2862306a36Sopenharmony_ci * Set @count bits starting at bit @start_bit in the bitmap described by the
2962306a36Sopenharmony_ci * vfs inode @vi to @value, where @value is either 0 or 1.
3062306a36Sopenharmony_ci *
3162306a36Sopenharmony_ci * Return 0 on success and -errno on error.
3262306a36Sopenharmony_ci */
3362306a36Sopenharmony_cistatic inline int ntfs_bitmap_set_bits_in_run(struct inode *vi,
3462306a36Sopenharmony_ci		const s64 start_bit, const s64 count, const u8 value)
3562306a36Sopenharmony_ci{
3662306a36Sopenharmony_ci	return __ntfs_bitmap_set_bits_in_run(vi, start_bit, count, value,
3762306a36Sopenharmony_ci			false);
3862306a36Sopenharmony_ci}
3962306a36Sopenharmony_ci
4062306a36Sopenharmony_ci/**
4162306a36Sopenharmony_ci * ntfs_bitmap_set_run - set a run of bits in a bitmap
4262306a36Sopenharmony_ci * @vi:		vfs inode describing the bitmap
4362306a36Sopenharmony_ci * @start_bit:	first bit to set
4462306a36Sopenharmony_ci * @count:	number of bits to set
4562306a36Sopenharmony_ci *
4662306a36Sopenharmony_ci * Set @count bits starting at bit @start_bit in the bitmap described by the
4762306a36Sopenharmony_ci * vfs inode @vi.
4862306a36Sopenharmony_ci *
4962306a36Sopenharmony_ci * Return 0 on success and -errno on error.
5062306a36Sopenharmony_ci */
5162306a36Sopenharmony_cistatic inline int ntfs_bitmap_set_run(struct inode *vi, const s64 start_bit,
5262306a36Sopenharmony_ci		const s64 count)
5362306a36Sopenharmony_ci{
5462306a36Sopenharmony_ci	return ntfs_bitmap_set_bits_in_run(vi, start_bit, count, 1);
5562306a36Sopenharmony_ci}
5662306a36Sopenharmony_ci
5762306a36Sopenharmony_ci/**
5862306a36Sopenharmony_ci * ntfs_bitmap_clear_run - clear a run of bits in a bitmap
5962306a36Sopenharmony_ci * @vi:		vfs inode describing the bitmap
6062306a36Sopenharmony_ci * @start_bit:	first bit to clear
6162306a36Sopenharmony_ci * @count:	number of bits to clear
6262306a36Sopenharmony_ci *
6362306a36Sopenharmony_ci * Clear @count bits starting at bit @start_bit in the bitmap described by the
6462306a36Sopenharmony_ci * vfs inode @vi.
6562306a36Sopenharmony_ci *
6662306a36Sopenharmony_ci * Return 0 on success and -errno on error.
6762306a36Sopenharmony_ci */
6862306a36Sopenharmony_cistatic inline int ntfs_bitmap_clear_run(struct inode *vi, const s64 start_bit,
6962306a36Sopenharmony_ci		const s64 count)
7062306a36Sopenharmony_ci{
7162306a36Sopenharmony_ci	return ntfs_bitmap_set_bits_in_run(vi, start_bit, count, 0);
7262306a36Sopenharmony_ci}
7362306a36Sopenharmony_ci
7462306a36Sopenharmony_ci/**
7562306a36Sopenharmony_ci * ntfs_bitmap_set_bit - set a bit in a bitmap
7662306a36Sopenharmony_ci * @vi:		vfs inode describing the bitmap
7762306a36Sopenharmony_ci * @bit:	bit to set
7862306a36Sopenharmony_ci *
7962306a36Sopenharmony_ci * Set bit @bit in the bitmap described by the vfs inode @vi.
8062306a36Sopenharmony_ci *
8162306a36Sopenharmony_ci * Return 0 on success and -errno on error.
8262306a36Sopenharmony_ci */
8362306a36Sopenharmony_cistatic inline int ntfs_bitmap_set_bit(struct inode *vi, const s64 bit)
8462306a36Sopenharmony_ci{
8562306a36Sopenharmony_ci	return ntfs_bitmap_set_run(vi, bit, 1);
8662306a36Sopenharmony_ci}
8762306a36Sopenharmony_ci
8862306a36Sopenharmony_ci/**
8962306a36Sopenharmony_ci * ntfs_bitmap_clear_bit - clear a bit in a bitmap
9062306a36Sopenharmony_ci * @vi:		vfs inode describing the bitmap
9162306a36Sopenharmony_ci * @bit:	bit to clear
9262306a36Sopenharmony_ci *
9362306a36Sopenharmony_ci * Clear bit @bit in the bitmap described by the vfs inode @vi.
9462306a36Sopenharmony_ci *
9562306a36Sopenharmony_ci * Return 0 on success and -errno on error.
9662306a36Sopenharmony_ci */
9762306a36Sopenharmony_cistatic inline int ntfs_bitmap_clear_bit(struct inode *vi, const s64 bit)
9862306a36Sopenharmony_ci{
9962306a36Sopenharmony_ci	return ntfs_bitmap_clear_run(vi, bit, 1);
10062306a36Sopenharmony_ci}
10162306a36Sopenharmony_ci
10262306a36Sopenharmony_ci#endif /* NTFS_RW */
10362306a36Sopenharmony_ci
10462306a36Sopenharmony_ci#endif /* defined _LINUX_NTFS_BITMAP_H */
105