Skip to content

Access to a FS from a shell #30

@vkuznet

Description

@vkuznet

I'm not sure if it is possible but I would like to see an example where we can create any kind of FS but it should be visible on underlying OS under some mount point. For instance, here is a code I came up with:

package main

import (
	"log"
	"os"
	"time"

	"github.com/blang/vfs"
	"github.com/blang/vfs/memfs"
	"github.com/blang/vfs/mountfs"
)

func main() {
	// Create a vfs accessing the filesystem of the underlying OS
	osfs := vfs.OS()

	// Create a fully writable filesystem in memory
	mfs := memfs.Create()

	// Create a vfs supporting mounts
	fs := mountfs.Create(osfs)

	// Mount a memfs inside /memfs
	fs.Mount(mfs, "/memfs")

	f, err := mfs.OpenFile("file.efs", os.O_CREATE|os.O_WRONLY, 0)
	defer f.Close()

	if err == nil {
		log.Println("created /memfs/file.efs")
		_, err := f.Write([]byte("Some content"))
		if err != nil {
			log.Println("unable to write content to file.efs", err)
		}
	} else {
		log.Println("failed to create /memfs/file.efs", err)
	}
	for {
		time.Sleep(10 * time.Second)
	}

}

So, if I compile and run it it serves as a daemon, but I would like to see my /memfs from underlying OS shell. Is it possible?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions