5ffa42cb8028833440040c2e240e0d788f11c112Tom Gundersen This file is part of systemd.
5ffa42cb8028833440040c2e240e0d788f11c112Tom Gundersen Copyright 2015 Tom Gundersen
5ffa42cb8028833440040c2e240e0d788f11c112Tom Gundersen systemd is free software; you can redistribute it and/or modify it
5ffa42cb8028833440040c2e240e0d788f11c112Tom Gundersen under the terms of the GNU Lesser General Public License as published by
5ffa42cb8028833440040c2e240e0d788f11c112Tom Gundersen the Free Software Foundation; either version 2.1 of the License, or
5ffa42cb8028833440040c2e240e0d788f11c112Tom Gundersen (at your option) any later version.
5ffa42cb8028833440040c2e240e0d788f11c112Tom Gundersen systemd is distributed in the hope that it will be useful, but
5ffa42cb8028833440040c2e240e0d788f11c112Tom Gundersen WITHOUT ANY WARRANTY; without even the implied warranty of
5ffa42cb8028833440040c2e240e0d788f11c112Tom Gundersen MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5ffa42cb8028833440040c2e240e0d788f11c112Tom Gundersen Lesser General Public License for more details.
5ffa42cb8028833440040c2e240e0d788f11c112Tom Gundersen You should have received a copy of the GNU Lesser General Public License
5ffa42cb8028833440040c2e240e0d788f11c112Tom Gundersen along with systemd; If not, see <http://www.gnu.org/licenses/>.
5ffa42cb8028833440040c2e240e0d788f11c112Tom Gundersen/* Bitmaps are only meant to store relatively small numbers
5ffa42cb8028833440040c2e240e0d788f11c112Tom Gundersen * (corresponding to, say, an enum), so it is ok to limit
5ffa42cb8028833440040c2e240e0d788f11c112Tom Gundersen * the max entry. 64k should be plenty. */
5ffa42cb8028833440040c2e240e0d788f11c112Tom Gundersen/* This indicates that we reached the end of the bitmap */
848d08b74eb0272774b1f8eff688d00ed9b63d9dDaniel Mack#define BITMAP_NUM_TO_OFFSET(n) ((n) / (sizeof(uint64_t) * 8))
848d08b74eb0272774b1f8eff688d00ed9b63d9dDaniel Mack#define BITMAP_NUM_TO_REM(n) ((n) % (sizeof(uint64_t) * 8))
848d08b74eb0272774b1f8eff688d00ed9b63d9dDaniel Mack#define BITMAP_OFFSET_TO_NUM(offset, rem) ((offset) * sizeof(uint64_t) * 8 + (rem))
5ffa42cb8028833440040c2e240e0d788f11c112Tom Gundersen /* we refuse to allocate huge bitmaps */
5ffa42cb8028833440040c2e240e0d788f11c112Tom Gundersen if (!GREEDY_REALLOC0(b->bitmaps, b->bitmaps_allocated, offset + 1))
370a2172ac0f455863a1ac8e7a9b0a284d810fd4Lennart Poettering bitmask = UINT64_C(1) << BITMAP_NUM_TO_REM(n);
370a2172ac0f455863a1ac8e7a9b0a284d810fd4Lennart Poettering bitmask = UINT64_C(1) << BITMAP_NUM_TO_REM(n);
5ffa42cb8028833440040c2e240e0d788f11c112Tom Gundersen return false;
5ffa42cb8028833440040c2e240e0d788f11c112Tom Gundersen return false;
370a2172ac0f455863a1ac8e7a9b0a284d810fd4Lennart Poettering bitmask = UINT64_C(1) << BITMAP_NUM_TO_REM(n);
5ffa42cb8028833440040c2e240e0d788f11c112Tom Gundersen for (i = 0; i < b->n_bitmaps; i++)
370a2172ac0f455863a1ac8e7a9b0a284d810fd4Lennart Poettering if (b->bitmaps[i] != 0)
5ffa42cb8028833440040c2e240e0d788f11c112Tom Gundersen return false;
cb57dd41595adddb08095298bb1ed258c8ea4877Tom Gundersenbool bitmap_iterate(Bitmap *b, Iterator *i, unsigned *n) {
5ffa42cb8028833440040c2e240e0d788f11c112Tom Gundersen return false;
5ffa42cb8028833440040c2e240e0d788f11c112Tom Gundersen return false;
5ffa42cb8028833440040c2e240e0d788f11c112Tom Gundersen return false;
d5fa81995849cb263ecfcd0aa6ab661360d9213eMartin Mikkelsen common_n_bitmaps = MIN(a->n_bitmaps, b->n_bitmaps);
d5fa81995849cb263ecfcd0aa6ab661360d9213eMartin Mikkelsen if (memcmp(a->bitmaps, b->bitmaps, sizeof(uint64_t) * common_n_bitmaps) != 0)
5ffa42cb8028833440040c2e240e0d788f11c112Tom Gundersen return false;
d5fa81995849cb263ecfcd0aa6ab661360d9213eMartin Mikkelsen for (i = common_n_bitmaps; i < c->n_bitmaps; i++)
d5fa81995849cb263ecfcd0aa6ab661360d9213eMartin Mikkelsen if (c->bitmaps[i] != 0)
d5fa81995849cb263ecfcd0aa6ab661360d9213eMartin Mikkelsen return false;