summaryrefslogtreecommitdiff
path: root/hscript/disk.cc
diff options
context:
space:
mode:
authorA. Wilcox <AWilcox@Wilcox-Tech.com>2019-10-31 18:03:00 -0500
committerA. Wilcox <AWilcox@Wilcox-Tech.com>2019-10-31 18:03:00 -0500
commitf97ac86dc0dadc20b53d66dade311e4b4e50b7fc (patch)
treea40a77feec79df0169a8e322e3f93febaba89bbc /hscript/disk.cc
parentcce8d9ba1541ef977260472d54461019e0e415ae (diff)
downloadhorizon-f97ac86dc0dadc20b53d66dade311e4b4e50b7fc.tar.gz
horizon-f97ac86dc0dadc20b53d66dade311e4b4e50b7fc.tar.bz2
horizon-f97ac86dc0dadc20b53d66dade311e4b4e50b7fc.tar.xz
horizon-f97ac86dc0dadc20b53d66dade311e4b4e50b7fc.zip
hscript: Implement fs, add tests
Diffstat (limited to 'hscript/disk.cc')
-rw-r--r--hscript/disk.cc52
1 files changed, 52 insertions, 0 deletions
diff --git a/hscript/disk.cc b/hscript/disk.cc
index a54b36d..72604d9 100644
--- a/hscript/disk.cc
+++ b/hscript/disk.cc
@@ -13,6 +13,7 @@
#include <algorithm>
#include <cstring> /* strerror */
#include <fstream>
+#include <set>
#include <string>
#ifdef HAS_INSTALL_ENV
# include <assert.h> /* assert */
@@ -606,6 +607,57 @@ bool LVMVolume::execute(ScriptOptions) const {
}
+const static std::set<std::string> valid_fses = {
+ "ext2", "ext3", "ext4", "jfs", "vfat", "xfs"
+};
+
+
+Key *Filesystem::parseFromData(const std::string &data, int lineno,
+ int *errors, int *) {
+ if(std::count(data.begin(), data.end(), ' ') != 1) {
+ if(errors) *errors += 1;
+ output_error("installfile:" + std::to_string(lineno),
+ "fs: expected exactly two elements",
+ "syntax is: fs [device] [fstype]");
+ return nullptr;
+ }
+
+ std::string::size_type sep = data.find(' ');
+ std::string device(data.substr(0, sep));
+ std::string fstype(data.substr(sep + 1));
+
+ if(device.size() < 6 || device.compare(0, 5, "/dev/")) {
+ if(errors) *errors += 1;
+ output_error("installfile:" + std::to_string(lineno),
+ "fs: element 1: expected device node",
+ "'" + device + "' is not a valid device node");
+ return nullptr;
+ }
+
+ if(valid_fses.find(fstype) == valid_fses.end()) {
+ std::string fses;
+ for(auto &&fs : valid_fses) fses += fs + " ";
+
+ if(errors) *errors += 1;
+ output_error("installfile:" + std::to_string(lineno),
+ "fs: element 2: expected filesystem type",
+ "valid filesystems are: " + fses);
+ return nullptr;
+ }
+
+ return new Filesystem(lineno, device, fstype);
+}
+
+bool Filesystem::validate(ScriptOptions) const {
+ /* Validation is done during parsing. */
+ return true;
+}
+
+bool Filesystem::execute(ScriptOptions) const {
+ return false;
+}
+
+
Key *Mount::parseFromData(const std::string &data, int lineno, int *errors,
int *warnings) {
std::string dev, where, opt;