12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- package mount
- import (
- "github.com/hanwen/go-fuse/v2/fuse"
- "github.com/seaweedfs/seaweedfs/weed/util"
- "net/http"
- "syscall"
- "time"
- )
- func (wfs *WFS) Write(cancel <-chan struct{}, in *fuse.WriteIn, data []byte) (written uint32, code fuse.Status) {
- if wfs.IsOverQuota {
- return 0, fuse.Status(syscall.ENOSPC)
- }
- fh := wfs.GetHandle(FileHandleId(in.Fh))
- if fh == nil {
- return 0, fuse.ENOENT
- }
- fh.dirtyPages.writerPattern.MonitorWriteAt(int64(in.Offset), int(in.Size))
- tsNs := time.Now().UnixNano()
- fhActiveLock := fh.wfs.fhLockTable.AcquireLock("Write", fh.fh, util.ExclusiveLock)
- defer fh.wfs.fhLockTable.ReleaseLock(fh.fh, fhActiveLock)
- entry := fh.GetEntry()
- if entry == nil {
- return 0, fuse.OK
- }
- entry.Content = nil
- offset := int64(in.Offset)
- entry.Attributes.FileSize = uint64(max(offset+int64(len(data)), int64(entry.Attributes.FileSize)))
-
- fh.dirtyPages.AddPage(offset, data, fh.dirtyPages.writerPattern.IsSequentialMode(), tsNs)
- written = uint32(len(data))
- if offset == 0 {
-
- fh.contentType = http.DetectContentType(data)
- }
- fh.dirtyMetadata = true
- if IsDebugFileReadWrite {
-
- fh.mirrorFile.WriteAt(data, offset)
- }
- return written, fuse.OK
- }
|