diff options
Diffstat (limited to 'vendor/codeberg.org/gruf/go-mmap')
| -rw-r--r-- | vendor/codeberg.org/gruf/go-mmap/LICENSE | 9 | ||||
| -rw-r--r-- | vendor/codeberg.org/gruf/go-mmap/README.md | 3 | ||||
| -rw-r--r-- | vendor/codeberg.org/gruf/go-mmap/copy_fill_stat.sh | 14 | ||||
| -rw-r--r-- | vendor/codeberg.org/gruf/go-mmap/fs.go | 79 | ||||
| -rw-r--r-- | vendor/codeberg.org/gruf/go-mmap/mmap.go | 142 | ||||
| -rw-r--r-- | vendor/codeberg.org/gruf/go-mmap/open.go | 62 | ||||
| -rw-r--r-- | vendor/codeberg.org/gruf/go-mmap/stat_darwin.go | 49 | ||||
| -rw-r--r-- | vendor/codeberg.org/gruf/go-mmap/stat_freebsd.go | 49 | ||||
| -rw-r--r-- | vendor/codeberg.org/gruf/go-mmap/stat_linux.go | 49 | ||||
| -rw-r--r-- | vendor/codeberg.org/gruf/go-mmap/stat_netbsd.go | 49 | ||||
| -rw-r--r-- | vendor/codeberg.org/gruf/go-mmap/stat_openbsd.go | 49 |
11 files changed, 0 insertions, 554 deletions
diff --git a/vendor/codeberg.org/gruf/go-mmap/LICENSE b/vendor/codeberg.org/gruf/go-mmap/LICENSE deleted file mode 100644 index d6f08d0ab..000000000 --- a/vendor/codeberg.org/gruf/go-mmap/LICENSE +++ /dev/null @@ -1,9 +0,0 @@ -MIT License - -Copyright (c) gruf - -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/vendor/codeberg.org/gruf/go-mmap/README.md b/vendor/codeberg.org/gruf/go-mmap/README.md deleted file mode 100644 index 76fc5fccd..000000000 --- a/vendor/codeberg.org/gruf/go-mmap/README.md +++ /dev/null @@ -1,3 +0,0 @@ -# go-mmap - -Optimized large file reads in Go
\ No newline at end of file diff --git a/vendor/codeberg.org/gruf/go-mmap/copy_fill_stat.sh b/vendor/codeberg.org/gruf/go-mmap/copy_fill_stat.sh deleted file mode 100644 index 5babab154..000000000 --- a/vendor/codeberg.org/gruf/go-mmap/copy_fill_stat.sh +++ /dev/null @@ -1,14 +0,0 @@ -#!/bin/bash -set -e - -for file in "$(go env GOROOT)"/src/os/stat_{linux,netbsd,openbsd,freebsd,darwin}.go; do - cp "$file" . - name="$(basename "$file")" - sed -i "./${name}" -E -e 's|package os|package mmap|' \ - -e 's|internal/filepathlite|path|' \ - -e 's|filepathlite|path|g' \ - -e 's| FileMode| os.FileMode|g' \ - -e 's| Mode| os.Mode|g' \ - -e 's| FileInfo| os.FileInfo|g' - gofmt -w "./${name}"; goimports -w "./${name}" -done diff --git a/vendor/codeberg.org/gruf/go-mmap/fs.go b/vendor/codeberg.org/gruf/go-mmap/fs.go deleted file mode 100644 index 743523259..000000000 --- a/vendor/codeberg.org/gruf/go-mmap/fs.go +++ /dev/null @@ -1,79 +0,0 @@ -package mmap - -import ( - "io/fs" - "syscall" - "time" -) - -type fileStat struct { - name string - size int64 - mode fs.FileMode - modTime time.Time - sys syscall.Stat_t -} - -func (fs *fileStat) Name() string { return fs.name } -func (fs *fileStat) Size() int64 { return fs.size } -func (fs *fileStat) IsDir() bool { return fs.mode.IsDir() } -func (fs *fileStat) Mode() fs.FileMode { return fs.mode } -func (fs *fileStat) ModTime() time.Time { return fs.modTime } -func (fs *fileStat) Sys() any { return &fs.sys } - -// open is a simple wrapper around syscall.Open(). -func open(filepath string, mode int, perm uint32) (fd int, err error) { - err = retryOnEINTR(func() (err error) { - fd, err = syscall.Open(filepath, mode, perm) - return - }) - return -} - -// stat is a simple wrapper around syscall.Stat(). -func stat(filepath string) (*fileStat, error) { - var stat fileStat - err := retryOnEINTR(func() error { - return syscall.Stat(filepath, &stat.sys) - }) - if err != nil { - return nil, err - } - fillFileStatFromSys(&stat, filepath) - return &stat, nil -} - -// mmap is a simple wrapper around syscall.Mmap(). -func mmap(fd int, offset int64, length int, prot int, flags int) (b []byte, err error) { - err = retryOnEINTR(func() error { - b, err = syscall.Mmap(fd, offset, length, prot, flags) - return err - }) - return -} - -// munmap is a simple wrapper around syscall.Munmap(). -func munmap(b []byte) error { - return retryOnEINTR(func() error { - return syscall.Munmap(b) - }) -} - -// close_ is a simple wrapper around syscall.Close(). -func close_(fd int) error { - return retryOnEINTR(func() error { - return syscall.Close(fd) - }) -} - -// retryOnEINTR is a low-level filesystem function -// for retrying syscalls on O_EINTR received. -func retryOnEINTR(do func() error) error { - for { - err := do() - if err == syscall.EINTR { - continue - } - return err - } -} diff --git a/vendor/codeberg.org/gruf/go-mmap/mmap.go b/vendor/codeberg.org/gruf/go-mmap/mmap.go deleted file mode 100644 index 797ed3e73..000000000 --- a/vendor/codeberg.org/gruf/go-mmap/mmap.go +++ /dev/null @@ -1,142 +0,0 @@ -package mmap - -import ( - "errors" - "io" - "io/fs" - "runtime" - "syscall" -) - -// MmapFile maps file at path into memory using syscall.mmap(), -// and returns a protected MmapReader{} for accessing the mapped data. -// Note that the mapped memory is not concurrency safe (other than -// concurrent ReadAt() calls). Any other calls made concurrently to -// Read() or Close() (including ReadAt()) require protection. -func MmapFile(path string) (*MmappedFile, error) { - - // Stat file information. - stat, err := stat(path) - if err != nil { - return nil, err - } - - // Mmap file into memory. - return openMmap(path, stat) -} - -func openMmap(path string, stat *fileStat) (*MmappedFile, error) { - if stat.Size() <= 0 { - // Empty file, no-op read. - return &MmappedFile{}, nil - } - - // Check file data size is accessible. - if stat.Size() != int64(int(stat.Size())) { - return nil, errors.New("file is too large") - } - - // Open file at path for read-only access. - fd, err := open(path, syscall.O_RDONLY, 0) - if err != nil { - return nil, err - } - - // Map this file into memory as slice. - mem, err := mmap(fd, 0, int(stat.Size()), - syscall.PROT_READ, syscall.MAP_PRIVATE) - - // Done with file. - _ = close_(fd) - - if err != nil { - return nil, err - } - - // Return as wrapped reader type. - return newMmapReader(mem, stat), nil -} - -// newMmapReader wraps a mapped memory slice in an -// MmappedFile{}, also setting a GC finalizer function. -func newMmapReader(mem []byte, stat *fileStat) *MmappedFile { - r := &MmappedFile{b: mem, s: stat} - runtime.SetFinalizer(r, (*MmappedFile).Close) - return r -} - -type MmappedFile struct { - b []byte // mapped memory - n int // read index - s *fileStat // file info -} - -func (r *MmappedFile) Name() string { - return r.s.name -} - -func (r *MmappedFile) Stat() (fs.FileInfo, error) { - return r.s, nil -} - -func (r *MmappedFile) Read(b []byte) (n int, err error) { - if r.n >= len(r.b) { - return 0, io.EOF - } - n = copy(b, r.b[r.n:]) - r.n += n - return -} - -func (r *MmappedFile) ReadAt(b []byte, off int64) (n int, err error) { - if off > int64(len(r.b)) { - return 0, io.EOF - } - n = copy(b, r.b[off:]) - return n, nil -} - -func (r *MmappedFile) WriteTo(w io.Writer) (int64, error) { - if r.n >= len(r.b) { - return 0, io.EOF - } - n, err := w.Write(r.b[r.n:]) - r.n += n - return int64(n), err -} - -func (r *MmappedFile) Seek(off int64, whence int) (int64, error) { - var n int - switch whence { - case io.SeekCurrent: - n = r.n + int(off) - case io.SeekStart: - n = 0 + int(off) - case io.SeekEnd: - n = len(r.b) + int(off) - default: - return 0, errors.New("invalid argument") - } - if n < 0 || n > len(r.b) { - return 0, errors.New("invalid argument") - } - r.n = n - return int64(n), nil -} - -func (r *MmappedFile) Len() int { - return len(r.b) - r.n -} - -func (r *MmappedFile) Size() int64 { - return int64(len(r.b)) -} - -func (r *MmappedFile) Close() error { - if b := r.b; b != nil { - r.b = nil - runtime.SetFinalizer(r, nil) - return munmap(b) - } - return nil -} diff --git a/vendor/codeberg.org/gruf/go-mmap/open.go b/vendor/codeberg.org/gruf/go-mmap/open.go deleted file mode 100644 index c12a091d3..000000000 --- a/vendor/codeberg.org/gruf/go-mmap/open.go +++ /dev/null @@ -1,62 +0,0 @@ -package mmap - -import ( - "io" - "io/fs" - "os" - "runtime" - "syscall" -) - -// MmapThreshold defines the threshold file size (in bytes) for which -// a call to OpenRead() will deem as big enough for a file to be worth -// opening using an `mmap` syscall. This is a runtime initialized number -// based on the number of available CPUs as in concurrent conditions Go -// can make optimizations for blocking `read` syscalls which scales with -// the number of available goroutines it can have running at once. -var MmapThreshold = int64(runtime.NumCPU() * syscall.Getpagesize()) - -// FileReader defines the base interface -// of a readable file, whether accessed -// via `read` or `mmap` syscalls. -type FileReader interface { - fs.File - io.ReaderAt - io.WriterTo - io.Seeker - Name() string -} - -// Threshold is a receiving type for OpenRead() -// that allows defining a custom MmapThreshold. -type Threshold struct{ At int64 } - -// OpenRead: see mmap.OpenRead(). -func (t Threshold) OpenRead(path string) (FileReader, error) { - stat, err := stat(path) - if err != nil { - return nil, err - } - if stat.Size() >= t.At { - return openMmap(path, stat) - } else { - return os.OpenFile(path, syscall.O_RDONLY, 0) - } -} - -// OpenRead will open the file as read only (erroring if it does -// not already exist). If the file at path is beyond 'MmapThreshold' -// it will be opened for reads using an `mmap` syscall, by calling -// MmappedRead(path). Else, it will be opened using os.OpenFile(). -// -// Please note that the reader returned by this function is not -// guaranteed to be concurrency-safe. Calls returned by os.OpenFile() -// follow the usual standard library concurrency guarantees, but the -// reader returned by MmappedRead() provides no concurrent protection. -// -// Also note that this may not always be faster! If the file you need -// to open will be immediately drained to another file, TCP or Unix -// connection, then the standard library will used optimized syscalls. -func OpenRead(path string) (FileReader, error) { - return Threshold{MmapThreshold}.OpenRead(path) -} diff --git a/vendor/codeberg.org/gruf/go-mmap/stat_darwin.go b/vendor/codeberg.org/gruf/go-mmap/stat_darwin.go deleted file mode 100644 index 3075e94e9..000000000 --- a/vendor/codeberg.org/gruf/go-mmap/stat_darwin.go +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright 2009 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package mmap - -import ( - "os" - "path" - "syscall" - "time" -) - -func fillFileStatFromSys(fs *fileStat, name string) { - fs.name = path.Base(name) - fs.size = fs.sys.Size - fs.modTime = time.Unix(fs.sys.Mtimespec.Unix()) - fs.mode = os.FileMode(fs.sys.Mode & 0777) - switch fs.sys.Mode & syscall.S_IFMT { - case syscall.S_IFBLK, syscall.S_IFWHT: - fs.mode |= os.ModeDevice - case syscall.S_IFCHR: - fs.mode |= os.ModeDevice | os.ModeCharDevice - case syscall.S_IFDIR: - fs.mode |= os.ModeDir - case syscall.S_IFIFO: - fs.mode |= os.ModeNamedPipe - case syscall.S_IFLNK: - fs.mode |= os.ModeSymlink - case syscall.S_IFREG: - // nothing to do - case syscall.S_IFSOCK: - fs.mode |= os.ModeSocket - } - if fs.sys.Mode&syscall.S_ISGID != 0 { - fs.mode |= os.ModeSetgid - } - if fs.sys.Mode&syscall.S_ISUID != 0 { - fs.mode |= os.ModeSetuid - } - if fs.sys.Mode&syscall.S_ISVTX != 0 { - fs.mode |= os.ModeSticky - } -} - -// For testing. -func atime(fi os.FileInfo) time.Time { - return time.Unix(fi.Sys().(*syscall.Stat_t).Atimespec.Unix()) -} diff --git a/vendor/codeberg.org/gruf/go-mmap/stat_freebsd.go b/vendor/codeberg.org/gruf/go-mmap/stat_freebsd.go deleted file mode 100644 index 271ca30e8..000000000 --- a/vendor/codeberg.org/gruf/go-mmap/stat_freebsd.go +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright 2009 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package mmap - -import ( - "os" - "path" - "syscall" - "time" -) - -func fillFileStatFromSys(fs *fileStat, name string) { - fs.name = path.Base(name) - fs.size = fs.sys.Size - fs.modTime = time.Unix(fs.sys.Mtimespec.Unix()) - fs.mode = os.FileMode(fs.sys.Mode & 0777) - switch fs.sys.Mode & syscall.S_IFMT { - case syscall.S_IFBLK: - fs.mode |= os.ModeDevice - case syscall.S_IFCHR: - fs.mode |= os.ModeDevice | os.ModeCharDevice - case syscall.S_IFDIR: - fs.mode |= os.ModeDir - case syscall.S_IFIFO: - fs.mode |= os.ModeNamedPipe - case syscall.S_IFLNK: - fs.mode |= os.ModeSymlink - case syscall.S_IFREG: - // nothing to do - case syscall.S_IFSOCK: - fs.mode |= os.ModeSocket - } - if fs.sys.Mode&syscall.S_ISGID != 0 { - fs.mode |= os.ModeSetgid - } - if fs.sys.Mode&syscall.S_ISUID != 0 { - fs.mode |= os.ModeSetuid - } - if fs.sys.Mode&syscall.S_ISVTX != 0 { - fs.mode |= os.ModeSticky - } -} - -// For testing. -func atime(fi os.FileInfo) time.Time { - return time.Unix(fi.Sys().(*syscall.Stat_t).Atimespec.Unix()) -} diff --git a/vendor/codeberg.org/gruf/go-mmap/stat_linux.go b/vendor/codeberg.org/gruf/go-mmap/stat_linux.go deleted file mode 100644 index 4f4ebc164..000000000 --- a/vendor/codeberg.org/gruf/go-mmap/stat_linux.go +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright 2009 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package mmap - -import ( - "os" - "path" - "syscall" - "time" -) - -func fillFileStatFromSys(fs *fileStat, name string) { - fs.name = path.Base(name) - fs.size = fs.sys.Size - fs.modTime = time.Unix(fs.sys.Mtim.Unix()) - fs.mode = os.FileMode(fs.sys.Mode & 0777) - switch fs.sys.Mode & syscall.S_IFMT { - case syscall.S_IFBLK: - fs.mode |= os.ModeDevice - case syscall.S_IFCHR: - fs.mode |= os.ModeDevice | os.ModeCharDevice - case syscall.S_IFDIR: - fs.mode |= os.ModeDir - case syscall.S_IFIFO: - fs.mode |= os.ModeNamedPipe - case syscall.S_IFLNK: - fs.mode |= os.ModeSymlink - case syscall.S_IFREG: - // nothing to do - case syscall.S_IFSOCK: - fs.mode |= os.ModeSocket - } - if fs.sys.Mode&syscall.S_ISGID != 0 { - fs.mode |= os.ModeSetgid - } - if fs.sys.Mode&syscall.S_ISUID != 0 { - fs.mode |= os.ModeSetuid - } - if fs.sys.Mode&syscall.S_ISVTX != 0 { - fs.mode |= os.ModeSticky - } -} - -// For testing. -func atime(fi os.FileInfo) time.Time { - return time.Unix(fi.Sys().(*syscall.Stat_t).Atim.Unix()) -} diff --git a/vendor/codeberg.org/gruf/go-mmap/stat_netbsd.go b/vendor/codeberg.org/gruf/go-mmap/stat_netbsd.go deleted file mode 100644 index 271ca30e8..000000000 --- a/vendor/codeberg.org/gruf/go-mmap/stat_netbsd.go +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright 2009 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package mmap - -import ( - "os" - "path" - "syscall" - "time" -) - -func fillFileStatFromSys(fs *fileStat, name string) { - fs.name = path.Base(name) - fs.size = fs.sys.Size - fs.modTime = time.Unix(fs.sys.Mtimespec.Unix()) - fs.mode = os.FileMode(fs.sys.Mode & 0777) - switch fs.sys.Mode & syscall.S_IFMT { - case syscall.S_IFBLK: - fs.mode |= os.ModeDevice - case syscall.S_IFCHR: - fs.mode |= os.ModeDevice | os.ModeCharDevice - case syscall.S_IFDIR: - fs.mode |= os.ModeDir - case syscall.S_IFIFO: - fs.mode |= os.ModeNamedPipe - case syscall.S_IFLNK: - fs.mode |= os.ModeSymlink - case syscall.S_IFREG: - // nothing to do - case syscall.S_IFSOCK: - fs.mode |= os.ModeSocket - } - if fs.sys.Mode&syscall.S_ISGID != 0 { - fs.mode |= os.ModeSetgid - } - if fs.sys.Mode&syscall.S_ISUID != 0 { - fs.mode |= os.ModeSetuid - } - if fs.sys.Mode&syscall.S_ISVTX != 0 { - fs.mode |= os.ModeSticky - } -} - -// For testing. -func atime(fi os.FileInfo) time.Time { - return time.Unix(fi.Sys().(*syscall.Stat_t).Atimespec.Unix()) -} diff --git a/vendor/codeberg.org/gruf/go-mmap/stat_openbsd.go b/vendor/codeberg.org/gruf/go-mmap/stat_openbsd.go deleted file mode 100644 index 4f4ebc164..000000000 --- a/vendor/codeberg.org/gruf/go-mmap/stat_openbsd.go +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright 2009 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package mmap - -import ( - "os" - "path" - "syscall" - "time" -) - -func fillFileStatFromSys(fs *fileStat, name string) { - fs.name = path.Base(name) - fs.size = fs.sys.Size - fs.modTime = time.Unix(fs.sys.Mtim.Unix()) - fs.mode = os.FileMode(fs.sys.Mode & 0777) - switch fs.sys.Mode & syscall.S_IFMT { - case syscall.S_IFBLK: - fs.mode |= os.ModeDevice - case syscall.S_IFCHR: - fs.mode |= os.ModeDevice | os.ModeCharDevice - case syscall.S_IFDIR: - fs.mode |= os.ModeDir - case syscall.S_IFIFO: - fs.mode |= os.ModeNamedPipe - case syscall.S_IFLNK: - fs.mode |= os.ModeSymlink - case syscall.S_IFREG: - // nothing to do - case syscall.S_IFSOCK: - fs.mode |= os.ModeSocket - } - if fs.sys.Mode&syscall.S_ISGID != 0 { - fs.mode |= os.ModeSetgid - } - if fs.sys.Mode&syscall.S_ISUID != 0 { - fs.mode |= os.ModeSetuid - } - if fs.sys.Mode&syscall.S_ISVTX != 0 { - fs.mode |= os.ModeSticky - } -} - -// For testing. -func atime(fi os.FileInfo) time.Time { - return time.Unix(fi.Sys().(*syscall.Stat_t).Atim.Unix()) -} |
