1// Copyright 2019 the Go-FUSE Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style
3// license that can be found in the LICENSE file.
4
5package fs
6
7import (
8	"context"
9	"syscall"
10	"time"
11
12	"github.com/hanwen/go-fuse/v2/fuse"
13)
14
15func (f *loopbackFile) Allocate(ctx context.Context, off uint64, sz uint64, mode uint32) syscall.Errno {
16	f.mu.Lock()
17	defer f.mu.Unlock()
18	err := syscall.Fallocate(f.fd, mode, int64(off), int64(sz))
19	if err != nil {
20		return ToErrno(err)
21	}
22	return OK
23}
24
25// Utimens - file handle based version of loopbackFileSystem.Utimens()
26func (f *loopbackFile) utimens(a *time.Time, m *time.Time) syscall.Errno {
27	var ts [2]syscall.Timespec
28	ts[0] = fuse.UtimeToTimespec(a)
29	ts[1] = fuse.UtimeToTimespec(m)
30	err := futimens(int(f.fd), &ts)
31	return ToErrno(err)
32}
33
34func setBlocks(out *fuse.Attr) {
35	if out.Blksize > 0 {
36		return
37	}
38
39	out.Blksize = 4096
40	pages := (out.Size + 4095) / 4096
41	out.Blocks = pages * 8
42}
43