aboutsummaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
Diffstat (limited to 'util')
-rw-r--r--util/hbitmap.c33
-rw-r--r--util/osdep.c21
2 files changed, 33 insertions, 21 deletions
diff --git a/util/hbitmap.c b/util/hbitmap.c
index 305b894a63..dd0501d9a7 100644
--- a/util/hbitmap.c
+++ b/util/hbitmap.c
@@ -301,6 +301,39 @@ bool hbitmap_next_dirty_area(const HBitmap *hb, int64_t start, int64_t end,
return true;
}
+bool hbitmap_status(const HBitmap *hb, int64_t start, int64_t count,
+ int64_t *pnum)
+{
+ int64_t next_dirty, next_zero;
+
+ assert(start >= 0);
+ assert(count > 0);
+ assert(start + count <= hb->orig_size);
+
+ next_dirty = hbitmap_next_dirty(hb, start, count);
+ if (next_dirty == -1) {
+ *pnum = count;
+ return false;
+ }
+
+ if (next_dirty > start) {
+ *pnum = next_dirty - start;
+ return false;
+ }
+
+ assert(next_dirty == start);
+
+ next_zero = hbitmap_next_zero(hb, start, count);
+ if (next_zero == -1) {
+ *pnum = count;
+ return true;
+ }
+
+ assert(next_zero > start);
+ *pnum = next_zero - start;
+ return false;
+}
+
bool hbitmap_empty(const HBitmap *hb)
{
return hb->count == 0;
diff --git a/util/osdep.c b/util/osdep.c
index 723cdcb004..7c4deda6fe 100644
--- a/util/osdep.c
+++ b/util/osdep.c
@@ -33,7 +33,6 @@
extern int madvise(char *, size_t, int);
#endif
-#include <dirent.h>
#include "qemu-common.h"
#include "qemu/cutils.h"
#include "qemu/sockets.h"
@@ -619,23 +618,3 @@ writev(int fd, const struct iovec *iov, int iov_cnt)
return readv_writev(fd, iov, iov_cnt, true);
}
#endif
-
-struct dirent *
-qemu_dirent_dup(struct dirent *dent)
-{
- size_t sz = 0;
-#if defined _DIRENT_HAVE_D_RECLEN
- /* Avoid use of strlen() if platform supports d_reclen. */
- sz = dent->d_reclen;
-#endif
- /*
- * Test sz for zero even if d_reclen is available
- * because some drivers may set d_reclen to zero.
- */
- if (sz == 0) {
- /* Fallback to the most portable way. */
- sz = offsetof(struct dirent, d_name) +
- strlen(dent->d_name) + 1;
- }
- return g_memdup(dent, sz);
-}