initial build
This commit is contained in:
commit
790062a152
8 changed files with 281 additions and 0 deletions
116
.random data
Normal file
116
.random data
Normal file
|
@ -0,0 +1,116 @@
|
|||
// package main
|
||||
|
||||
// import (
|
||||
// "fmt"
|
||||
// "os"
|
||||
// "os/exec"
|
||||
// )
|
||||
|
||||
// func main() {
|
||||
// devices, err := listStorageDevices()
|
||||
// if err != nil {
|
||||
// fmt.Println("Error:", err)
|
||||
// return
|
||||
// }
|
||||
|
||||
// fmt.Println("Connected storage devices:")
|
||||
// var storageDevices []string
|
||||
// for _, device := range devices {
|
||||
// // filter out non-disk devices
|
||||
// if device[:2] != "sd" {
|
||||
// continue
|
||||
// }
|
||||
// // show only ones that end with a number
|
||||
// if device[len(device)-1] < '0' || device[len(device)-1] > '9' {
|
||||
// continue
|
||||
// }
|
||||
// fmt.Println(device)
|
||||
// storageDevices = append(storageDevices, device)
|
||||
// }
|
||||
|
||||
// if len(storageDevices) == 0 {
|
||||
// fmt.Println("No storage devices found.")
|
||||
// return
|
||||
// }
|
||||
|
||||
// // if there are storage devices, check if they are mounted
|
||||
// for _, device := range storageDevices {
|
||||
// mounted, err := isMounted(device)
|
||||
// if err != nil {
|
||||
// fmt.Println("Error:", err)
|
||||
// return
|
||||
// }
|
||||
|
||||
// // if not mounted, mount it to /mnt/init/<device>
|
||||
// if !mounted {
|
||||
// err = mountDevice(device)
|
||||
// if err != nil {
|
||||
// fmt.Println("Error:", err)
|
||||
// return
|
||||
// }
|
||||
// fmt.Println("Device", device, "mounted to /mnt/init/"+device)
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// func mountDevice(device string) error {
|
||||
// // ensure the mount point exists
|
||||
// err := os.MkdirAll("/mnt/init/"+device, 0755)
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
|
||||
// // Use `mount` command to mount the device
|
||||
// cmd := exec.Command("mount", "/dev/"+device, "/mnt/init/"+device)
|
||||
// err = cmd.Run()
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
// return nil
|
||||
// }
|
||||
|
||||
// func isMounted(device string) (bool, error) {
|
||||
// file, err := os.Open("/proc/mounts")
|
||||
// if err != nil {
|
||||
// return false, err
|
||||
// }
|
||||
// defer file.Close()
|
||||
|
||||
// var devicePath string
|
||||
// for {
|
||||
// var path, dev string
|
||||
// _, err := fmt.Fscanf(file, "%s %s\n", &path, &dev)
|
||||
// if err != nil {
|
||||
// break
|
||||
// }
|
||||
// if dev == "/dev/"+device {
|
||||
// devicePath = path
|
||||
// break
|
||||
// }
|
||||
// }
|
||||
|
||||
// return devicePath != "", nil
|
||||
|
||||
// }
|
||||
|
||||
// func listStorageDevices() ([]string, error) {
|
||||
// dir, err := os.Open("/dev")
|
||||
// if err != nil {
|
||||
// return nil, err
|
||||
// }
|
||||
// defer dir.Close()
|
||||
|
||||
// files, err := dir.Readdir(-1)
|
||||
// if err != nil {
|
||||
// return nil, err
|
||||
// }
|
||||
|
||||
// devices := make([]string, 0)
|
||||
// for _, file := range files {
|
||||
// if file.Mode()&os.ModeDevice != 0 {
|
||||
// devices = append(devices, file.Name())
|
||||
// }
|
||||
// }
|
||||
|
||||
// return devices, nil
|
||||
// }
|
Loading…
Add table
Add a link
Reference in a new issue