github.com/anacrolix/torrent@v1.61.0/storage/sys_unix.go (about) 1 //go:build unix 2 3 package storage 4 5 import ( 6 "io" 7 "os" 8 9 "github.com/edsrzf/mmap-go" 10 "golang.org/x/sys/unix" 11 ) 12 13 // Returns io.EOF if there's no data after offset. That doesn't mean there isn't zeroes for a sparse 14 // hole. Note that lseek returns -1 on error. 15 func seekData(f *os.File, offset int64) (ret int64, err error) { 16 ret, err = unix.Seek(int(f.Fd()), offset, unix.SEEK_DATA) 17 // TODO: Handle filesystems that don't support sparse files. 18 if err == unix.ENXIO { 19 // File has no more data. Treat as short write like io.CopyN. 20 err = io.EOF 21 } 22 return 23 } 24 25 var pageSize = unix.Getpagesize() 26 27 func msync(mm mmap.MMap, offset, nbytes int) error { 28 getDown := offset % pageSize 29 return unix.Msync(mm[offset-getDown:offset+nbytes], unix.MS_SYNC) 30 }