linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
To: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>,
	linux-fsdevel@vger.kernel.org
Cc: viro@zeniv.linux.org.uk, linux-kernel@vger.kernel.org,
	pali@kernel.org, dsterba@suse.cz, aaptel@suse.com,
	willy@infradead.org, rdunlap@infradead.org, joe@perches.com,
	mark@harmstone.com, nborisov@suse.com,
	linux-ntfs-dev@lists.sourceforge.net, anton@tuxera.com,
	dan.carpenter@oracle.com, hch@lst.de, ebiggers@kernel.org,
	andy.lavr@gmail.com, kari.argillander@gmail.com,
	oleksandr@natalenko.name
Subject: Re: [PATCH v27 03/10] fs/ntfs3: Add bitmap
Date: Fri, 30 Jul 2021 10:11:51 +0200	[thread overview]
Message-ID: <33a0225a-7264-ff4c-b48e-d1a1c3d368c4@wanadoo.fr> (raw)
In-Reply-To: <20210729134943.778917-4-almaz.alexandrovich@paragon-software.com>

Le 29/07/2021 à 15:49, Konstantin Komarov a écrit :
> This adds bitmap
> 
> Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
> ---
>   fs/ntfs3/bitfunc.c |  135 ++++
>   fs/ntfs3/bitmap.c  | 1519 ++++++++++++++++++++++++++++++++++++++++++++
>   2 files changed, 1654 insertions(+)
>   create mode 100644 fs/ntfs3/bitfunc.c
>   create mode 100644 fs/ntfs3/bitmap.c
> 
> diff --git a/fs/ntfs3/bitfunc.c b/fs/ntfs3/bitfunc.c
> new file mode 100644
> index 000000000..2de5faef2
> --- /dev/null
> +++ b/fs/ntfs3/bitfunc.c

[...]

> +bool are_bits_set(const ulong *lmap, size_t bit, size_t nbits)
> +{
> +	u8 mask;
> +	size_t pos = bit & 7;
> +	const u8 *map = (u8 *)lmap + (bit >> 3);
> +
> +	if (pos) {
> +		if (8 - pos >= nbits) {
> +			mask = fill_mask[pos + nbits] & zero_mask[pos];
> +			return !nbits || (*map & mask) == mask;
> +		}
> +
> +		mask = zero_mask[pos];
> +		if ((*map++ & mask) != mask)
> +			return false;
> +		nbits -= 8 - pos;
> +	}
> +
> +	pos = ((size_t)map) & (sizeof(size_t) - 1);
> +	if (pos) {
> +		pos = sizeof(size_t) - pos;
> +		if (nbits >= pos * 8) {
> +			for (nbits -= pos * 8; pos; pos--, map++) {
> +				if (*map != 0xFF)
> +					return false;
> +			}
> +		}
> +	}
> +
> +	for (pos = nbits / BITS_IN_SIZE_T; pos; pos--, map += sizeof(size_t)) {
> +		if (*((size_t *)map) != MINUS_ONE_T)
> +			return false;
> +	}
> +
> +	for (pos = (nbits % BITS_IN_SIZE_T) >> 3; pos; pos--, map++) {
> +		if (*map != 0xFF)
> +			return false;
> +	}
> +
> +	pos = nbits & 7;
> +	if (pos) {
> +		u8 mask = fill_mask[pos];

There is no need to define a new 'mask' variable here, it just shadows 
the already existing one. 'u8' can be removed.

> +
> +		if ((*map & mask) != mask)
> +			return false;
> +	}
> +
> +	// All bits are ones
> +	return true;
> +}
> diff --git a/fs/ntfs3/bitmap.c b/fs/ntfs3/bitmap.c
> new file mode 100644
> index 000000000..32aab0031
> --- /dev/null
> +++ b/fs/ntfs3/bitmap.c

[...]

> +bool wnd_is_used(struct wnd_bitmap *wnd, size_t bit, size_t bits)
> +{
> +	bool ret = false;
> +	struct super_block *sb = wnd->sb;
> +	size_t iw = bit >> (sb->s_blocksize_bits + 3);
> +	u32 wbits = 8 * sb->s_blocksize;
> +	u32 wbit = bit & (wbits - 1);
> +	size_t end;
> +	struct rb_node *n;
> +	struct e_node *e;
> +
> +	if (RB_EMPTY_ROOT(&wnd->start_tree))
> +		goto use_wnd;
> +
> +	end = bit + bits;
> +	n = rb_lookup(&wnd->start_tree, end - 1);
> +	if (!n)
> +		goto use_wnd;
> +
> +	e = rb_entry(n, struct e_node, start.node);
> +	if (e->start.key + e->count.key > bit)
> +		return false;
> +
> +use_wnd:
> +	while (iw < wnd->nwnd && bits) {
> +		u32 tail, op;
> +
> +		if (unlikely(iw + 1 == wnd->nwnd))
> +			wbits = wnd->bits_last;
> +
> +		tail = wbits - wbit;
> +		op = tail < bits ? tail : bits;
> +
> +		if (wnd->free_bits[iw]) {
> +			bool ret;

This 'ret' shadows the one defined above. It looks spurious and could 
certainly be removed.
However is looks safe because...

> +			struct buffer_head *bh = wnd_map(wnd, iw);
> +
> +			if (IS_ERR(bh))
> +				goto out;
> +
> +			ret = are_bits_set((ulong *)bh->b_data, wbit, op);
> +			put_bh(bh);
> +			if (!ret)
> +				goto out;

... if *this* 'ret' is false, the *other* 'ret' is false as well.

> +		}
> +
> +		bits -= op;
> +		wbit = 0;
> +		iw += 1;
> +	}
> +	ret = true;
> +
> +out:
> +	return ret;
> +}

[...]

  reply	other threads:[~2021-07-30  8:11 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-29 13:49 [PATCH v27 00/10] NTFS read-write driver GPL implementation by Paragon Software Konstantin Komarov
2021-07-29 13:49 ` [PATCH v27 01/10] fs/ntfs3: Add headers and misc files Konstantin Komarov
2021-07-29 13:49 ` [PATCH v27 02/10] fs/ntfs3: Add initialization of super block Konstantin Komarov
2021-07-29 15:59   ` Matthew Wilcox
2021-07-30  8:28   ` Christophe JAILLET
2021-08-10  9:02   ` Christoph Hellwig
2021-07-29 13:49 ` [PATCH v27 03/10] fs/ntfs3: Add bitmap Konstantin Komarov
2021-07-30  8:11   ` Christophe JAILLET [this message]
2021-07-29 13:49 ` [PATCH v27 04/10] fs/ntfs3: Add file operations and implementation Konstantin Komarov
2021-07-30  7:40   ` Christophe JAILLET
2021-08-22 12:20   ` Pali Rohár
2021-08-22 14:31     ` Kari Argillander
2021-08-24 11:33       ` Pali Rohár
2021-07-29 13:49 ` [PATCH v27 05/10] fs/ntfs3: Add attrib operations Konstantin Komarov
2021-07-30  7:30   ` Christophe JAILLET
2021-07-29 13:49 ` [PATCH v27 06/10] fs/ntfs3: Add compression Konstantin Komarov
2021-07-29 13:49 ` [PATCH v27 07/10] fs/ntfs3: Add NTFS journal Konstantin Komarov
2021-07-30  8:06   ` Christophe JAILLET
2021-07-29 13:49 ` [PATCH v27 08/10] fs/ntfs3: Add Kconfig, Makefile and doc Konstantin Komarov
2021-08-10  7:47   ` Kari Argillander
2021-08-10  8:19     ` Pali Rohár
2021-08-10  8:46       ` Kari Argillander
2021-07-29 13:49 ` [PATCH v27 09/10] fs/ntfs3: Add NTFS3 in fs/Kconfig and fs/Makefile Konstantin Komarov
2021-07-29 13:49 ` [PATCH v27 10/10] fs/ntfs3: Add MAINTAINERS Konstantin Komarov
2021-08-09 10:56   ` David Sterba
2021-08-09 16:16     ` Konstantin Komarov
2021-08-09 16:44       ` Kari Argillander
2021-08-09 16:54         ` Randy Dunlap
2021-08-09 18:56           ` Dan Williams
2021-08-09 19:45             ` Kari Argillander
2021-07-29 16:24 ` [PATCH v27 00/10] NTFS read-write driver GPL implementation by Paragon Software Darrick J. Wong
2021-08-02  3:23   ` Theodore Ts'o
2021-08-02 15:05     ` Theodore Ts'o
2021-08-12 17:03     ` Kari Argillander
2021-08-13 15:53       ` Kari Argillander
2021-08-21 12:38     ` Yan Pashkovsky
2021-08-03 11:57 ` [PATCH] Restyle comments to better align with kernel-doc Kari Argillander
2021-08-03 13:38   ` Dan Carpenter
2021-08-03 15:26     ` Kari Argillander
2021-08-03 15:41       ` Matthew Wilcox
2021-08-30 16:10   ` Konstantin Komarov
2021-08-30 17:13     ` Kari Argillander
2021-08-10  5:46 ` [PATCH v27 00/10] NTFS read-write driver GPL implementation by Paragon Software Kari Argillander
2021-08-10  6:47   ` Darrick J. Wong

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=33a0225a-7264-ff4c-b48e-d1a1c3d368c4@wanadoo.fr \
    --to=christophe.jaillet@wanadoo.fr \
    --cc=aaptel@suse.com \
    --cc=almaz.alexandrovich@paragon-software.com \
    --cc=andy.lavr@gmail.com \
    --cc=anton@tuxera.com \
    --cc=dan.carpenter@oracle.com \
    --cc=dsterba@suse.cz \
    --cc=ebiggers@kernel.org \
    --cc=hch@lst.de \
    --cc=joe@perches.com \
    --cc=kari.argillander@gmail.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-ntfs-dev@lists.sourceforge.net \
    --cc=mark@harmstone.com \
    --cc=nborisov@suse.com \
    --cc=oleksandr@natalenko.name \
    --cc=pali@kernel.org \
    --cc=rdunlap@infradead.org \
    --cc=viro@zeniv.linux.org.uk \
    --cc=willy@infradead.org \
    --subject='Re: [PATCH v27 03/10] fs/ntfs3: Add bitmap' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).