]>
glassweightruler.freedombox.rocks Git - Ventoy.git/blob - LinuxGUI/Ventoy2Disk/Lib/exfat/src/mkfs/cbm.c
3 Clusters Bitmap creation code.
5 Free exFAT implementation.
6 Copyright (C) 2011-2018 Andrew Nayenko
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License along
19 with this program; if not, write to the Free Software Foundation, Inc.,
20 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
30 static off_t
cbm_alignment(void)
32 return get_cluster_size();
35 static off_t
cbm_size(void)
38 (get_volume_size() - get_position(&cbm
)) / get_cluster_size(),
42 static int cbm_write(struct exfat_dev
* dev
)
44 uint32_t allocated_clusters
=
45 DIV_ROUND_UP(cbm
.get_size(), get_cluster_size()) +
46 DIV_ROUND_UP(uct
.get_size(), get_cluster_size()) +
47 DIV_ROUND_UP(rootdir
.get_size(), get_cluster_size());
48 size_t bitmap_size
= ROUND_UP(allocated_clusters
, CHAR_BIT
);
49 bitmap_t
* bitmap
= malloc(BMAP_SIZE(bitmap_size
));
54 exfat_error("failed to allocate bitmap of %zu bytes",
55 BMAP_SIZE(bitmap_size
));
58 memset(bitmap
, 0, BMAP_SIZE(bitmap_size
));
60 for (i
= 0; i
< bitmap_size
; i
++)
61 if (i
< allocated_clusters
)
63 if (exfat_write(dev
, bitmap
, bitmap_size
/ CHAR_BIT
) < 0)
66 exfat_error("failed to write bitmap of %zu bytes",
67 bitmap_size
/ CHAR_BIT
);
74 const struct fs_object cbm
=
76 .get_alignment
= cbm_alignment
,