3 Clusters Bitmap creation code.
5 Copyright (C) 2011, 2012 Andrew Nayenko
7 This program is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>.
27 static off_t cbm_alignment(void)
29 return get_cluster_size();
32 static off_t cbm_size(void)
35 (get_volume_size() - get_position(&cbm)) / get_cluster_size(),
39 static int cbm_write(struct exfat_dev* dev)
41 uint32_t allocated_clusters =
42 DIV_ROUND_UP(cbm.get_size(), get_cluster_size()) +
43 DIV_ROUND_UP(uct.get_size(), get_cluster_size()) +
44 DIV_ROUND_UP(rootdir.get_size(), get_cluster_size());
45 size_t bitmap_size = DIV_ROUND_UP(allocated_clusters, CHAR_BIT);
46 uint8_t* bitmap = malloc(bitmap_size);
51 exfat_error("failed to allocate bitmap of %zu bytes", bitmap_size);
55 for (i = 0; i < bitmap_size * CHAR_BIT; i++)
56 if (i < allocated_clusters)
60 if (exfat_write(dev, bitmap, bitmap_size) < 0)
62 exfat_error("failed to write bitmap of %zu bytes", bitmap_size);
69 const struct fs_object cbm =
71 .get_alignment = cbm_alignment,