diff options
author | Sean Whitton <spwhitton@spwhitton.name> | 2021-04-12 13:59:37 -0700 |
---|---|---|
committer | Sean Whitton <spwhitton@spwhitton.name> | 2021-04-12 17:19:31 -0700 |
commit | 408e2df8464bcccc2b37435aa0c9e4998b6fea55 (patch) | |
tree | 44ce6191b407243e52acc471ae08bb66b6367fe0 /src/property/disk.lisp | |
parent | 0e91a3827a4e2ef8677033b0bbb6b44078daa9a7 (diff) | |
download | consfigurator-408e2df8464bcccc2b37435aa0c9e4998b6fea55.tar.gz |
add VOLUME-CONTENTS-MINIMUM-SIZE and VOLUME-MINIMUM-SIZE
Signed-off-by: Sean Whitton <spwhitton@spwhitton.name>
Diffstat (limited to 'src/property/disk.lisp')
-rw-r--r-- | src/property/disk.lisp | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/property/disk.lisp b/src/property/disk.lisp index 0e39a24..f780f50 100644 --- a/src/property/disk.lisp +++ b/src/property/disk.lisp @@ -57,6 +57,35 @@ plus any metadata (e.g. partition tables), this value will be ignored.") (:documentation "Something which contains filesystems and/or other volumes.")) +(defgeneric volume-contents-minimum-size (volume) + (:documentation + "Calculate the minimum size required to accomodate the contents of this volume.")) + +(defmethod volume-contents-minimum-size ((volume volume)) + (if (slot-boundp volume 'volume-contents) + (reduce #'+ (mapcar #'volume-minimum-size + (ensure-cons (volume-contents volume)))) + 0)) + +(defgeneric volume-minimum-size (volume) + (:documentation + "Return the VOLUME-SIZE of the volume or the minimum size required to +accommodate its contents, whichever is larger.")) + +(defmethod volume-minimum-size ((volume volume)) + (let ((volume-minimum-size + (cond ((not (slot-boundp volume 'volume-size)) + 0) + ((eql (volume-size volume) :remaining) + 1) + ((numberp (volume-size volume)) + (volume-size volume)) + (t + (simple-program-error "Invalid volume size ~A" + (volume-size volume)))))) + (max volume-minimum-size + (volume-contents-minimum-size volume)))) + (defgeneric open-volume-contents (volume file) (:documentation "Renders contents of VOLUME directly accessible. FILE is something in the filesystem which serves as a means of accessing |