The branch main has been updated by imp:

URL: 
https://cgit.FreeBSD.org/src/commit/?id=81fbd74a4b598c52957b491896ec839316ceeec3

commit 81fbd74a4b598c52957b491896ec839316ceeec3
Author:     Warner Losh <[email protected]>
AuthorDate: 2023-02-03 15:38:22 +0000
Commit:     Warner Losh <[email protected]>
CommitDate: 2023-02-03 15:41:39 +0000

    kboot: space_avail -- how much space exists from 'start' to end of segment
    
    Sponsored by:           Netflix
    Reviewed by:            tsoome
    Differential Revision:  https://reviews.freebsd.org/D38313
---
 stand/kboot/kboot.h |  1 +
 stand/kboot/seg.c   | 19 +++++++++++++++++++
 2 files changed, 20 insertions(+)

diff --git a/stand/kboot/kboot.h b/stand/kboot/kboot.h
index dcf1487ce404..4a8fe497339e 100644
--- a/stand/kboot/kboot.h
+++ b/stand/kboot/kboot.h
@@ -44,6 +44,7 @@ void remove_avail(uint64_t start, uint64_t end, uint64_t 
type);
 uint64_t first_avail(uint64_t align, uint64_t min_size, uint64_t type);
 void print_avail(void);
 bool populate_avail_from_iomem(void);
+uint64_t space_avail(uint64_t start);
 
 /* util.c */
 bool file2str(const char *fn, char *buffer, size_t buflen);
diff --git a/stand/kboot/seg.c b/stand/kboot/seg.c
index 8cf3b833c9d1..947aa0a2a7a3 100644
--- a/stand/kboot/seg.c
+++ b/stand/kboot/seg.c
@@ -344,3 +344,22 @@ out:
        close(fd);
        return true;
 }
+
+/*
+ * Return the amount of space available in the segment that @start@ lives in,
+ * from @start@ to the end of the segment.
+ */
+uint64_t
+space_avail(uint64_t start)
+{
+       for (int i = 0; i < nr_seg; i++) {
+               if (start >= segs[i].start && start <= segs[i].end)
+                       return segs[i].end - start;
+       }
+
+       /*
+        * Properly used, we should never get here. Unsure if this should be a
+        * panic or not.
+        */
+       return 0;
+}

Reply via email to