in file.go [439:476]
func (f *File) mmap() reason {
const op = "txfile/mmap"
// update real file size
fileSize, fileErr := f.file.Size()
if fileErr != nil {
const msg = "unable to determine file size for mmap region"
return f.errWrap(op, fileErr).report(msg)
}
if fileSize < 0 {
msg := fmt.Sprintf("file size %v < 0", fileSize)
return f.err(op).of(InvalidFileSize).report(msg)
}
f.size = fileSize
f.sizeEstimate = fileSize // reset estimate
maxSize := f.allocator.maxSize
if em := uint(f.allocator.meta.endMarker); maxSize > 0 && em > f.allocator.maxPages {
maxSize = em * f.allocator.pageSize
}
pageSize := f.allocator.pageSize
sz, err := computePlatformMmapSize(uint(fileSize), maxSize, uint(pageSize))
if err != nil {
return err
}
// map file
buf, fileErr := f.file.MMap(int(sz))
if err != nil {
return f.errWrap(op, err).report("can not mmap file")
}
f.mapped = buf
f.meta[0] = castMetaPage(buf[0:])
f.meta[1] = castMetaPage(buf[pageSize:])
return nil
}