package sysfs

import (
	
	

	experimentalsys 
	
	
)

func ( string) experimentalsys.FS {
	return &dirFS{
		dir:        ,
		cleanedDir: ensureTrailingPathSeparator(),
	}
}

func ensureTrailingPathSeparator( string) string {
	if !os.IsPathSeparator([len()-1]) {
		return  + string(os.PathSeparator)
	}
	return 
}

// dirFS is not exported because the input fields must be maintained together.
// This is likely why os.DirFS doesn't, either!
type dirFS struct {
	experimentalsys.UnimplementedFS

	dir string
	// cleanedDir is for easier OS-specific concatenation, as it always has
	// a trailing path separator.
	cleanedDir string
}

// String implements fmt.Stringer
func ( *dirFS) () string {
	return .dir
}

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

// Lstat implements the same method as documented on sys.FS
func ( *dirFS) ( string) (sys.Stat_t, experimentalsys.Errno) {
	return lstat(.join())
}

// Stat implements the same method as documented on sys.FS
func ( *dirFS) ( string) (sys.Stat_t, experimentalsys.Errno) {
	return stat(.join())
}

// Mkdir implements the same method as documented on sys.FS
func ( *dirFS) ( string,  fs.FileMode) ( experimentalsys.Errno) {
	 := os.Mkdir(.join(), )
	if  = experimentalsys.UnwrapOSError();  == experimentalsys.ENOTDIR {
		 = experimentalsys.ENOENT
	}
	return
}

// Readlink implements the same method as documented on sys.FS
func ( *dirFS) ( string) (string, experimentalsys.Errno) {
	// Note: do not use syscall.Readlink as that causes race on Windows.
	// In any case, syscall.Readlink does almost the same logic as os.Readlink.
	,  := os.Readlink(.join())
	if  != nil {
		return "", experimentalsys.UnwrapOSError()
	}
	return platform.ToPosixPath(), 0
}

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

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

func ( *dirFS) ( string) string {
	switch  {
	case "", ".", "/":
		if .cleanedDir == "/" {
			return "/"
		}
		// cleanedDir includes an unnecessary delimiter for the root path.
		return .cleanedDir[:len(.cleanedDir)-1]
	}
	// TODO: Enforce similar to safefilepath.FromFS(path), but be careful as
	// relative path inputs are allowed. e.g. dir or path == ../
	return .cleanedDir + 
}