Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Access to a FS from a shell #30

Open
vkuznet opened this issue Jun 13, 2024 · 0 comments
Open

Access to a FS from a shell #30

vkuznet opened this issue Jun 13, 2024 · 0 comments

Comments

@vkuznet
Copy link

vkuznet commented Jun 13, 2024

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant