added disk quota
This commit is contained in:
parent
4499e88245
commit
9cc2b04342
26 changed files with 1376 additions and 61 deletions
|
|
@ -5,14 +5,23 @@ package fs
|
|||
import (
|
||||
"os"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
)
|
||||
|
||||
func now() int64 {
|
||||
return time.Now().UTC().Unix()
|
||||
}
|
||||
|
||||
type MetadataMap map[string]*Metadata
|
||||
|
||||
type Metadata struct {
|
||||
mu sync.RWMutex `json:"-"`
|
||||
fs *FS `json:"-"`
|
||||
f *os.File `json:"-"`
|
||||
name string `json:"-"`
|
||||
Size int64 `json:"s"`
|
||||
Atime int64 `json:"a"`
|
||||
Chunks Chunks `json:"c"`
|
||||
preload bool `json:"-"`
|
||||
}
|
||||
|
|
@ -23,6 +32,7 @@ func (md *Metadata) Delete() error {
|
|||
md.Chunks = Chunks{}
|
||||
md.f.Close()
|
||||
md.f = nil
|
||||
atomic.StoreInt64(&md.Atime, now())
|
||||
return md.fs.RemoveDst(md.name)
|
||||
}
|
||||
|
||||
|
|
@ -45,6 +55,7 @@ func (md *Metadata) ReadAt(p []byte, pos int64) (int, error) {
|
|||
return 0, err
|
||||
}
|
||||
}
|
||||
atomic.StoreInt64(&md.Atime, now())
|
||||
return md.f.ReadAt(p, pos)
|
||||
}
|
||||
|
||||
|
|
@ -55,6 +66,8 @@ func (md *Metadata) WriteAt(data []byte, pos int64) (int, error) {
|
|||
return 0, err
|
||||
}
|
||||
}
|
||||
atomic.StoreInt64(&md.Atime, now())
|
||||
md.fs.q.Add(len(data))
|
||||
return md.f.WriteAt(data, pos)
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue