Home Download Docs Code Community
     1	/*
     2	Copyright 2013 The Perkeep Authors
     3	
     4	Licensed under the Apache License, Version 2.0 (the "License");
     5	you may not use this file except in compliance with the License.
     6	You may obtain a copy of the License at
     7	
     8	     http://www.apache.org/licenses/LICENSE-2.0
     9	
    10	Unless required by applicable law or agreed to in writing, software
    11	distributed under the License is distributed on an "AS IS" BASIS,
    12	WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13	See the License for the specific language governing permissions and
    14	limitations under the License.
    15	*/
    16	
    17	package diskpacked
    18	
    19	import (
    20		"errors"
    21		"os"
    22		"syscall"
    23	)
    24	
    25	const (
    26		// FALLOC_FL_KEEP_SIZE: default is extend size
    27		falloc_fl_keep_size = 0x01
    28	
    29		// FALLOC_FL_PUNCH_HOLE: de-allocates range
    30		falloc_fl_punch_hole = 0x02
    31	)
    32	
    33	func init() {
    34		punchHole = punchHoleLinux
    35	}
    36	
    37	// puncHoleLinux punches a hole into the given file starting at offset,
    38	// measuring "size" bytes
    39	func punchHoleLinux(file *os.File, offset int64, size int64) error {
    40		err := syscall.Fallocate(int(file.Fd()),
    41			falloc_fl_punch_hole|falloc_fl_keep_size,
    42			offset, size)
    43		if errors.Is(err, syscall.ENOSYS) || errors.Is(err, syscall.EOPNOTSUPP) {
    44			return errNoPunch
    45		}
    46		return err
    47	}
Website layout inspired by memcached.
Content by the authors.