metropolis/node/build: prepare fsspec for use in initramfs

This moves fsspec up into the node build directory as it's going to be
used in multiple tools (like mkinitcpio) in the future. It also adds
special files support to it as that's going to be required at least for
initramfs support but it may prove useful for erofs as well.

Change-Id: I8d559bb761b4da350c0070b23b5ab393ba6e9872
Reviewed-on: https://review.monogon.dev/c/monogon/+/521
Reviewed-by: Sergiusz Bazanski <serge@monogon.tech>
diff --git a/metropolis/node/build/mkerofs/BUILD.bazel b/metropolis/node/build/mkerofs/BUILD.bazel
index 6de1c73..3cbcbde 100644
--- a/metropolis/node/build/mkerofs/BUILD.bazel
+++ b/metropolis/node/build/mkerofs/BUILD.bazel
@@ -6,7 +6,7 @@
     importpath = "source.monogon.dev/metropolis/node/build/mkerofs",
     visibility = ["//visibility:public"],
     deps = [
-        "//metropolis/node/build/mkerofs/fsspec:go_default_library",
+        "//metropolis/node/build/fsspec:go_default_library",
         "//metropolis/pkg/erofs:go_default_library",
         "@com_github_golang_protobuf//proto:go_default_library",
     ],
diff --git a/metropolis/node/build/mkerofs/fsspec/BUILD.bazel b/metropolis/node/build/mkerofs/fsspec/BUILD.bazel
deleted file mode 100644
index bd0f036..0000000
--- a/metropolis/node/build/mkerofs/fsspec/BUILD.bazel
+++ /dev/null
@@ -1,30 +0,0 @@
-load("@rules_proto//proto:defs.bzl", "proto_library")
-load("@io_bazel_rules_go//go:def.bzl", "go_library")
-load("@io_bazel_rules_go//proto:def.bzl", "go_proto_library")
-
-proto_library(
-    name = "spec_proto",
-    srcs = ["spec.proto"],
-    visibility = ["//visibility:public"],
-)
-
-go_proto_library(
-    name = "spec_go_proto",
-    importpath = "source.monogon.dev/metropolis/node/build/mkerofs/spec",
-    proto = ":spec_proto",
-    visibility = ["//visibility:public"],
-)
-
-go_library(
-    name = "go_default_library",
-    embed = [":fsspec_go_proto"],
-    importpath = "source.monogon.dev/metropolis/node/build/mkerofs/fsspec",
-    visibility = ["//visibility:public"],
-)
-
-go_proto_library(
-    name = "fsspec_go_proto",
-    importpath = "source.monogon.dev/metropolis/node/build/mkerofs/fsspec",
-    proto = ":spec_proto",
-    visibility = ["//visibility:public"],
-)
diff --git a/metropolis/node/build/mkerofs/fsspec/spec.proto b/metropolis/node/build/mkerofs/fsspec/spec.proto
deleted file mode 100644
index 3d6e8dc..0000000
--- a/metropolis/node/build/mkerofs/fsspec/spec.proto
+++ /dev/null
@@ -1,70 +0,0 @@
-// Copyright 2020 The Monogon Project Authors.
-//
-// SPDX-License-Identifier: Apache-2.0
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-//     http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-syntax = "proto3";
-
-package metropolis.node.build.mkerofs.fsspec;
-option go_package = "source.monogon.dev/metropolis/node/build/mkerofs/fsspec";
-
-// FSSpec is the spec from which a filesystem is generated. It consists of files, directories and symbolic
-// links. Directories are also automatically inferred when required for the placement of files or symbolic
-// links. Inferred directories always have uid 0, gid 0 and permissions 0555. This can be overridden by
-// explicitly specifying a directory at a given path.
-message FSSpec {
-  repeated File file = 1;
-  repeated Directory directory = 2;
-  repeated SymbolicLink symbolic_link = 3;
-}
-
-// For internal use only. Represents all supported inodes in a oneof.
-message Inode {
-  oneof type {
-    File file = 1;
-    Directory directory = 2;
-    SymbolicLink symbolic_link = 3;
-  }
-}
-
-message File {
-  // The path where the file ends up in the filesystem.
-  string path = 1;
-  // The path on the host filesystem where the file contents should be taken from.
-  string source_path = 2;
-  // Unix permission bits
-  uint32 mode = 3;
-  // Owner uid
-  uint32 uid = 4;
-  // Owner gid
-  uint32 gid = 5;
-}
-
-message Directory {
-  // The path where the directory ends up in the filesystem.
-  string path = 1;
-  // Unix permission bits
-  uint32 mode = 2;
-  // Owner uid
-  uint32 uid = 3;
-  // Owner gid
-  uint32 gid = 4;
-}
-
-message SymbolicLink {
-  // The path where the symbolic link ends up in the filesystem.
-  string path = 1;
-  // The path to which the symbolic link resolves to.
-  string target_path = 2;
-}
\ No newline at end of file
diff --git a/metropolis/node/build/mkerofs/main.go b/metropolis/node/build/mkerofs/main.go
index d4e9d4d..651096b 100644
--- a/metropolis/node/build/mkerofs/main.go
+++ b/metropolis/node/build/mkerofs/main.go
@@ -30,7 +30,7 @@
 
 	"github.com/golang/protobuf/proto"
 
-	"source.monogon.dev/metropolis/node/build/mkerofs/fsspec"
+	"source.monogon.dev/metropolis/node/build/fsspec"
 	"source.monogon.dev/metropolis/pkg/erofs"
 )
 
@@ -161,6 +161,10 @@
 		entryRef.data.Type = &fsspec.Inode_SymbolicLink{SymbolicLink: symlink}
 	}
 
+	if len(spec.SpecialFile) > 0 {
+		log.Fatalf("special files are currently unimplemented in mkerofs")
+	}
+
 	fs, err := os.Create(*outPath)
 	if err != nil {
 		log.Fatalf("failed to open output file: %v", err)