@@ -49,10 +49,12 @@ type file struct {
49
49
// The opCount is used to judge whether "lastWrittenOffset" is still
50
50
// guaranteed to be correct.
51
51
lastOpCount uint64
52
+ // Parent filesystem
53
+ fs * FS
52
54
}
53
55
54
56
// NewFile returns a new go-fuse File instance.
55
- func NewFile (fd * os.File , writeOnly bool , contentEnc * contentenc. ContentEnc ) (nodefs.File , fuse.Status ) {
57
+ func NewFile (fd * os.File , writeOnly bool , fs * FS ) (nodefs.File , fuse.Status ) {
56
58
var st syscall.Stat_t
57
59
err := syscall .Fstat (int (fd .Fd ()), & st )
58
60
if err != nil {
@@ -65,10 +67,11 @@ func NewFile(fd *os.File, writeOnly bool, contentEnc *contentenc.ContentEnc) (no
65
67
return & file {
66
68
fd : fd ,
67
69
writeOnly : writeOnly ,
68
- contentEnc : contentEnc ,
70
+ contentEnc : fs . contentEnc ,
69
71
devIno : di ,
70
72
fileTableEntry : t ,
71
73
loopbackFile : nodefs .NewLoopbackFile (fd ),
74
+ fs : fs ,
72
75
}, fuse .OK
73
76
}
74
77
@@ -107,10 +110,12 @@ func (f *file) createHeader() (fileID []byte, err error) {
107
110
h := contentenc .RandomHeader ()
108
111
buf := h .Pack ()
109
112
// Prevent partially written (=corrupt) header by preallocating the space beforehand
110
- err = syscallcompat .EnospcPrealloc (int (f .fd .Fd ()), 0 , contentenc .HeaderLen )
111
- if err != nil {
112
- tlog .Warn .Printf ("ino%d: createHeader: prealloc failed: %s\n " , f .devIno .ino , err .Error ())
113
- return nil , err
113
+ if ! f .fs .args .NoPrealloc {
114
+ err = syscallcompat .EnospcPrealloc (int (f .fd .Fd ()), 0 , contentenc .HeaderLen )
115
+ if err != nil {
116
+ tlog .Warn .Printf ("ino%d: createHeader: prealloc failed: %s\n " , f .devIno .ino , err .Error ())
117
+ return nil , err
118
+ }
114
119
}
115
120
// Actually write header
116
121
_ , err = f .fd .WriteAt (buf , 0 )
@@ -285,19 +290,22 @@ func (f *file) doWrite(data []byte, off int64) (uint32, fuse.Status) {
285
290
writeChain [i ] = blockData
286
291
numOutBytes += len (blockData )
287
292
}
288
- // Concatenenate all elements in the writeChain into one contigous buffer
293
+ // Concatenenate all elements in the writeChain into one contiguous buffer
289
294
tmp := make ([]byte , numOutBytes )
290
295
writeBuf := bytes .NewBuffer (tmp [:0 ])
291
296
for _ , w := range writeChain {
292
297
writeBuf .Write (w )
293
298
}
294
299
// Preallocate so we cannot run out of space in the middle of the write.
295
300
// This prevents partially written (=corrupt) blocks.
301
+ var err error
296
302
cOff := blocks [0 ].BlockCipherOff ()
297
- err := syscallcompat .EnospcPrealloc (int (f .fd .Fd ()), int64 (cOff ), int64 (writeBuf .Len ()))
298
- if err != nil {
299
- tlog .Warn .Printf ("ino%d fh%d: doWrite: prealloc failed: %s" , f .devIno .ino , f .intFd (), err .Error ())
300
- return 0 , fuse .ToStatus (err )
303
+ if ! f .fs .args .NoPrealloc {
304
+ err = syscallcompat .EnospcPrealloc (int (f .fd .Fd ()), int64 (cOff ), int64 (writeBuf .Len ()))
305
+ if err != nil {
306
+ tlog .Warn .Printf ("ino%d fh%d: doWrite: prealloc failed: %s" , f .devIno .ino , f .intFd (), err .Error ())
307
+ return 0 , fuse .ToStatus (err )
308
+ }
301
309
}
302
310
// Write
303
311
_ , err = f .fd .WriteAt (writeBuf .Bytes (), int64 (cOff ))
0 commit comments