Re: [PATCH v2] hfs: avoid reusing occupied CNIDs after deletion

From: Viacheslav Dubeyko

Date: Mon Nov 23 2026 - 17:08:39 EST


On Sat, 2026-11-21 at 05:19 -0500, Hengyu Liang wrote:
> Hi Slava,
>
> Sorry for the late reply. I have an important deadline in early
> December, so I may be slow to reply until then.

No problem. Take your time.

>
> On Mon, 2026-11-16 at 15:21 -0800, Viacheslav Dubeyko wrote:
> > You explained a simple case. :) My worry was about the case when we
> > could delete some number of items between [16, 20]. For example, we
> > delete 17, 18, and 19 at first. And now we delete item with #20.
> > So,
> > leaf A should have 16 as a maximum CNID. And we can use 17 as a
> > next_id. Correct?
>
> Correct. I ran this case with the patch on a fresh volume. Creating
> a, c, e, b, d gives CNIDs 16 to 20 in three leaves:
>
>   leaf 1: root folder (2), thread of 2, a (16), b (19)   max 19
>   leaf 2: c (17), d (20), e (18)                         max 20
>   leaf 4: threads of 16 to 20                            no file or
> folder
>
>   rm c (17), rm e (18): not the newest CNID, next_id stays 21;
>                         leaf maximums 19 and 20 stay
>   rm b (19):            leaf 1's maximum has to be recomputed, the
>                         root keeps 20 (from leaf 2)
>   rm d (20):            leaf 2 is now empty and goes away, the root's
>                         maximum has to be recomputed: leaf 1 -> 16,
>                         root -> 16, next_id = 17
>
> The next new file gets CNID 17. I checked it three ways: with the
> values cached before the deletes, with nothing cached yet, and with a
> remount between the creates and the deletes. A debug build that
> compares every cached value with the records after each insert and
> remove found no mismatch.
>
> A larger case: 2000 files created in shuffled name order, so the
> CNIDs are spread over the leaves. Deleting CNIDs 1916..2014 first and
> then 2015 gives next_id 1916, and the next file gets 1916. Without
> the
> patch the same steps end with "File exists". fsck.hfs reports all
> images as OK.
>
>

OK. Sounds good.

Thanks,
Slava.