diff --git a/cache/filecache.go b/cache/filecache.go index e923ae2..df7b803 100644 --- a/cache/filecache.go +++ b/cache/filecache.go @@ -19,14 +19,14 @@ type CacheBlock struct { // CachedFile supports contiguous reads via cache type CachedFile struct { - lru *lru.Cache[int, *CacheBlock] - dataRequestCallback func(offset, length int) ([]byte, error) - fileSize int + lru *lru.Cache[int64, *CacheBlock] + dataRequestCallback func(offset, length int64) ([]byte, error) + fileSize int64 mu sync.Mutex } -func NewCachedFile(fSize int, dataRequestCallback func(offset int, length int) ([]byte, error)) *CachedFile { - blockLru, _ := lru.New[int, *CacheBlock](MEM_PER_FILE_CACHE_B / BLOCKSIZE) +func NewCachedFile(fSize int64, dataRequestCallback func(offset int64, length int64) ([]byte, error)) *CachedFile { + blockLru, _ := lru.New[int64, *CacheBlock](MEM_PER_FILE_CACHE_B / BLOCKSIZE) cf := &CachedFile{ dataRequestCallback: dataRequestCallback, fileSize: fSize, @@ -35,7 +35,7 @@ func NewCachedFile(fSize int, dataRequestCallback func(offset int, length int) ( return cf } -func (cf *CachedFile) fillLruBlock(blockNumber int, block *CacheBlock) error { +func (cf *CachedFile) fillLruBlock(blockNumber int64, block *CacheBlock) error { for i := 0; i < 5; i++ { buf, err := cf.dataRequestCallback(blockNumber*BLOCKSIZE, BLOCKSIZE) if err != nil { @@ -50,7 +50,7 @@ func (cf *CachedFile) fillLruBlock(blockNumber int, block *CacheBlock) error { return errors.New("Failed to fill block") } -func (cf *CachedFile) Read(offset, length int) ([]byte, error) { +func (cf *CachedFile) Read(offset, length int64) ([]byte, error) { if offset > cf.fileSize { return []byte{}, nil } @@ -74,20 +74,20 @@ func (cf *CachedFile) Read(offset, length int) ([]byte, error) { } blck.lock.Lock() defer blck.lock.Unlock() - for i := 0; i < 3; i++ { + for i := int64(0); i < 3; i++ { go cf.ReadNewData(lruBlock + i) time.Sleep(10 * time.Nanosecond) } - if len(blck.data) < blockOffset { + if int64(len(blck.data)) < blockOffset { return []byte{}, nil } - if len(blck.data) < blockOffset+length { - length = len(blck.data) - blockOffset + if int64(len(blck.data)) < blockOffset+length { + length = int64(len(blck.data)) - blockOffset } return blck.data[blockOffset : blockOffset+length], nil } -func (cf *CachedFile) ReadNewData(lrublock int) { +func (cf *CachedFile) ReadNewData(lrublock int64) { if cf.lru.Contains(lrublock) { return } diff --git a/common/types.go b/common/types.go index 9a4b4f0..4fc8869 100644 --- a/common/types.go +++ b/common/types.go @@ -1,7 +1,7 @@ package common type Finfo struct { - NameLength int `struc:"int16,sizeof=Name"` + NameLength int64 `struc:"int16,sizeof=Name"` Name string Size int64 IsDir bool diff --git a/fileretriever/fileclient.go b/fileretriever/fileclient.go index 0f8cb2c..7977744 100644 --- a/fileretriever/fileclient.go +++ b/fileretriever/fileclient.go @@ -41,7 +41,7 @@ func (r RemotePath) Append(name string) RemotePath { type PeerInfo struct { Load int64 - Rate int + Rate int64 CurrentRequests *semaphore.Weighted } @@ -239,7 +239,7 @@ func (f *FileClient) localFileInfo(path RemotePath) (*common.Finfo, error) { }, nil } -func (f *FileClient) netRead(path RemotePath, offset int, length int) ([]byte, error) { +func (f *FileClient) netRead(path RemotePath, offset int64, length int64) ([]byte, error) { nextLoad := new(int64) *nextLoad = 3000 log.Trace().Msgf("doing net read at %d for len %d", offset, length) @@ -308,7 +308,7 @@ func (f *FileClient) netRead(path RemotePath, offset int, length int) ([]byte, e return response.Content, nil } -func (f *FileClient) localRead(remotePath RemotePath, off, length int) ([]byte, error) { +func (f *FileClient) localRead(remotePath RemotePath, off, length int64) ([]byte, error) { localPath := f.Re2Lo(remotePath) file, err := os.Open(localPath.String()) if err != nil { @@ -320,7 +320,7 @@ func (f *FileClient) localRead(remotePath RemotePath, off, length int) ([]byte, log.Warn().Err(err).Msgf("Failed to stat file %s", localPath) return nil, err } - if off >= int(finfo.Size()) { + if off >= int64(finfo.Size()) { return []byte{}, nil } seek, err := file.Seek(int64(off), 0) @@ -336,7 +336,7 @@ func (f *FileClient) localRead(remotePath RemotePath, off, length int) ([]byte, return buf[:read], nil } -func (f *FileClient) Read(path RemotePath, off, length int) ([]byte, error) { +func (f *FileClient) Read(path RemotePath, off, length int64) ([]byte, error) { log.Trace().Msgf("doing read at %d for len %d", off, length) buf, err := f.localRead(path, off, length) if err != nil { diff --git a/fileretriever/fileserver.go b/fileretriever/fileserver.go index a46f2a3..1fae18a 100644 --- a/fileretriever/fileserver.go +++ b/fileretriever/fileserver.go @@ -22,22 +22,22 @@ const ( // TODO use remote path type and custom packer type FileRequest struct { - Offset int - Length int - PathLength int `struc:"int16,sizeof=Path"` + Offset int64 + Length int64 + PathLength int64 `struc:"int16,sizeof=Path"` Path string } type FileResponse struct { - Length int `struc:"int64,sizeof=Content"` - FileSize int + Length int64 `struc:"int64,sizeof=Content"` + FileSize int64 Content []byte } type DirResponse struct { - DirLength int `struc:"int32,sizeof=Dirs"` + DirLength int64 `struc:"int32,sizeof=Dirs"` Dirs []byte - FileLength int `struc:"int32,sizeof=Files"` + FileLength int64 `struc:"int32,sizeof=Files"` Files []byte } diff --git a/readnetfs.go b/readnetfs.go index 52a372e..face875 100644 --- a/readnetfs.go +++ b/readnetfs.go @@ -34,13 +34,13 @@ func (n *VirtNode) Read(ctx context.Context, fh fusefs.FileHandle, dest []byte, log.Trace().Msgf("Reading at %d from %s", off, n.path) cacheEntry := n.fc.GetCachedFile(n.path) if cacheEntry != nil { - buf, err := cacheEntry.Read(int(off), len(dest)) + buf, err := cacheEntry.Read(int64(off), int64(len(dest))) if err != nil { log.Warn().Err(err).Msgf("Failed to read %s", n.path) return nil, syscall.EIO } if len(buf) < len(dest) && len(buf) > 0 { - nb, err := cacheEntry.Read(int(off)+len(buf), len(dest)-len(buf)) + nb, err := cacheEntry.Read((off)+int64(len(buf)), int64(len(dest)-len(buf))) if err != nil { log.Warn().Err(err).Msgf("Failed to read %s", n.path) return fuse.ReadResultData(buf), 0 @@ -54,15 +54,16 @@ func (n *VirtNode) Read(ctx context.Context, fh fusefs.FileHandle, dest []byte, log.Debug().Err(err).Msgf("Failed to read file info for %s", n.path) return nil, syscall.EIO } - cf := cache.NewCachedFile(int(fInfo.Size), func(offset, length int) ([]byte, error) { + cf := cache.NewCachedFile(int64(fInfo.Size), func(offset, length int64) ([]byte, error) { return n.fc.Read(n.path, offset, length) }) cf = n.fc.PutOrGet(n.path, cf) - buf, err := cf.Read(int(off), fuse.MAX_KERNEL_WRITE) + buf, err := cf.Read(int64(off), fuse.MAX_KERNEL_WRITE) if err != nil { log.Warn().Err(err).Msgf("Failed to read %s", n.path) return nil, syscall.EIO } + return fuse.ReadResultData(buf), 0 }