package sysfs

import (
	
	
	

	experimentalsys 
	
)

type AdaptFS struct {
	FS fs.FS
}

// String implements fmt.Stringer
func ( *AdaptFS) () string {
	return fmt.Sprintf("%v", .FS)
}

// OpenFile implements the same method as documented on sys.FS
func ( *AdaptFS) ( string,  experimentalsys.Oflag,  fs.FileMode) (experimentalsys.File, experimentalsys.Errno) {
	return OpenFSFile(.FS, cleanPath(), , )
}

// Lstat implements the same method as documented on sys.FS
func ( *AdaptFS) ( string) (sys.Stat_t, experimentalsys.Errno) {
	// At this time, we make the assumption sys.FS instances do not support
	// symbolic links, therefore Lstat is the same as Stat. This is obviously
	// not true, but until FS.FS has a solid story for how to handle symlinks,
	// we are better off not making a decision that would be difficult to
	// revert later on.
	//
	// For further discussions on the topic, see:
	// https://github.com/golang/go/issues/49580
	return .Stat()
}

// Stat implements the same method as documented on sys.FS
func ( *AdaptFS) ( string) (sys.Stat_t, experimentalsys.Errno) {
	,  := .OpenFile(, experimentalsys.O_RDONLY, 0)
	if  != 0 {
		return sys.Stat_t{}, 
	}
	defer .Close()
	return .Stat()
}

// Readlink implements the same method as documented on sys.FS
func ( *AdaptFS) (string) (string, experimentalsys.Errno) {
	return "", experimentalsys.ENOSYS
}

// Mkdir implements the same method as documented on sys.FS
func ( *AdaptFS) (string, fs.FileMode) experimentalsys.Errno {
	return experimentalsys.ENOSYS
}

// Chmod implements the same method as documented on sys.FS
func ( *AdaptFS) (string, fs.FileMode) experimentalsys.Errno {
	return experimentalsys.ENOSYS
}

// Rename implements the same method as documented on sys.FS
func ( *AdaptFS) (string, string) experimentalsys.Errno {
	return experimentalsys.ENOSYS
}

// Rmdir implements the same method as documented on sys.FS
func ( *AdaptFS) (string) experimentalsys.Errno {
	return experimentalsys.ENOSYS
}

// Link implements the same method as documented on sys.FS
func ( *AdaptFS) (string, string) experimentalsys.Errno {
	return experimentalsys.ENOSYS
}

// Symlink implements the same method as documented on sys.FS
func ( *AdaptFS) (string, string) experimentalsys.Errno {
	return experimentalsys.ENOSYS
}

// Unlink implements the same method as documented on sys.FS
func ( *AdaptFS) (string) experimentalsys.Errno {
	return experimentalsys.ENOSYS
}

// Utimens implements the same method as documented on sys.FS
func ( *AdaptFS) (string, int64, int64) experimentalsys.Errno {
	return experimentalsys.ENOSYS
}

func cleanPath( string) string {
	if len() == 0 {
		return 
	}
	// fs.ValidFile cannot be rooted (start with '/')
	 := 
	if [0] == '/' {
		 = [1:]
	}
	 = path.Clean() // e.g. "sub/." -> "sub"
	return 
}