summaryrefslogtreecommitdiff
path: root/hscript/disk.cc
diff options
context:
space:
mode:
authorA. Wilcox <AWilcox@Wilcox-Tech.com>2019-10-26 02:12:27 -0500
committerA. Wilcox <AWilcox@Wilcox-Tech.com>2019-10-26 02:12:27 -0500
commitf6c8b2ff99be070e22477156f8ccdcf89aec8861 (patch)
tree9e63851f88f72dce4296a0c9e015eb5fb24070ff /hscript/disk.cc
parentcd2ab0ea31fd4dc9305c1d5e08100eafaff19f7e (diff)
downloadhorizon-f6c8b2ff99be070e22477156f8ccdcf89aec8861.tar.gz
horizon-f6c8b2ff99be070e22477156f8ccdcf89aec8861.tar.bz2
horizon-f6c8b2ff99be070e22477156f8ccdcf89aec8861.tar.xz
horizon-f6c8b2ff99be070e22477156f8ccdcf89aec8861.zip
hscript: Implement DiskLabel::execute
Diffstat (limited to 'hscript/disk.cc')
-rw-r--r--hscript/disk.cc46
1 files changed, 44 insertions, 2 deletions
diff --git a/hscript/disk.cc b/hscript/disk.cc
index 3423928..c02d4c8 100644
--- a/hscript/disk.cc
+++ b/hscript/disk.cc
@@ -18,6 +18,7 @@
# include <assert.h> /* assert */
# include <blkid/blkid.h> /* blkid_get_tag_value */
# include <libudev.h> /* udev_* */
+# include <parted/parted.h> /* ped_* */
# include <sys/mount.h> /* mount */
# include <sys/stat.h> /* mkdir, stat */
# include <sys/types.h> /* S_* */
@@ -183,9 +184,50 @@ bool DiskLabel::validate(ScriptOptions options) const {
return true;
}
-bool DiskLabel::execute(ScriptOptions) const {
- /* TODO XXX NOTIMPLEMENTED */
+bool DiskLabel::execute(ScriptOptions options) const {
+ std::string type_str;
+ switch(this->type()) {
+ case APM:
+ type_str = "apm";
+ break;
+ case MBR:
+ type_str = "mbr";
+ break;
+ case GPT:
+ type_str = "gpt";
+ break;
+ }
+
+ if(options.test(Simulate)) {
+ std::cout << "parted -ms " << this->device() << " mklabel "
+ << type_str << std::endl;
+ return true;
+ }
+
+#ifdef HAS_INSTALL_ENV
+ PedDevice *pdevice = ped_device_get(this->device().c_str());
+ PedDiskType *label = ped_disk_type_get(type_str.c_str());
+ if(label == nullptr) {
+ output_error("installfile:" + std::to_string(this->lineno()),
+ "disklabel: Parted does not support label type " +
+ type_str + "!");
+ return false;
+ }
+
+ /* REQ: Runner.Execute.disklabel.Overwrite */
+ ped_disk_clobber(pdevice);
+ PedDisk *disk = ped_disk_new_fresh(pdevice, label);
+ if(disk == nullptr) {
+ output_error("installfile:" + std::to_string(this->lineno()),
+ "disklabel: internal error creating new " +
+ type_str + " label on " + _block);
+ return false;
+ }
+
+ return (ped_disk_commit_to_dev(disk) == 0);
+#else
return false;
+#endif /* HAS_INSTALL_ENV */
}