func Open(path string, mode os.FileMode, options *Options) (*DB, error) {
	db := &DB{
		opened: true,
	}
	if options == nil {
		options = DefaultOptions
	}
	db.NoSync = options.NoSync
	db.NoGrowSync = options.NoGrowSync
	db.MmapFlags = options.MmapFlags
	db.NoFreelistSync = options.NoFreelistSync
	db.MaxBatchSize = DefaultMaxBatchSize
	db.MaxBatchDelay = DefaultMaxBatchDelay
	db.AllocSize = DefaultAllocSize
	flag := os.O_RDWR
	if options.ReadOnly {
		flag = os.O_RDONLY
		db.readOnly = true
	}
	db.path = path
	var err error
	if db.file, err = os.OpenFile(db.path, flag|os.O_CREATE, mode); err != nil {
		_ = db.close()
		return nil, err
	}
	if err := flock(db, mode, !db.readOnly, options.Timeout); err != nil {
		db.lockfile = nil  
		_ = db.close()
		return nil, err
	}
	db.ops.writeAt = db.file.WriteAt
	if db.pageSize = options.PageSize; db.pageSize == 0 {
		db.pageSize = defaultPageSize
	}
	if info, err := db.file.Stat(); err != nil {
		return nil, err
	} else if info.Size() == 0 {
		if err := db.init(); err != nil {
			return nil, err
		}
	} else {
		var buf [0x1000]byte
		if bw, err := db.file.ReadAt(buf[:], 0); err == nil && bw == len(buf) {
			if m := db.pageInBuffer(buf[:], 0).meta(); m.validate() == nil {
				db.pageSize = int(m.pageSize)
			}
		} else {
			return nil, ErrInvalid
		}
	}
	db.pagePool = sync.Pool{
		New: func() interface{} {
			return make([]byte, db.pageSize)
		},
	}
	if err := db.mmap(options.InitialMmapSize); err != nil {
		_ = db.close()
		return nil, err
	}
	if db.readOnly {
		return db, nil
	}
	db.loadFreelist()
	if !db.NoFreelistSync && !db.hasSyncedFreelist() {
		tx, err := db.Begin(true)
		if tx != nil {
			err = tx.Commit()
		}
		if err != nil {
			_ = db.close()
			return nil, err
		}
	}
	return db, nil
}
Open creates and opens a database at the given path.
If the file does not exist then it will be created automatically.
Passing in nil options will cause Bolt to open the database with the default options.
package bolt
import (
	"errors"
	"fmt"
	"hash/fnv"
	"log"
	"os"
	"runtime"
	"sort"
	"sync"
	"time"
	"unsafe"
)
const maxMmapStep = 1 << 30  
const version = 2
const magic uint32 = 0xED0CDAED
const pgidNoFreelist pgid = 0xffffffffffffffff
const IgnoreNoSync = runtime.GOOS == "openbsd"
const (
	DefaultMaxBatchSize  int = 1000
	DefaultMaxBatchDelay     = 10 * time.Millisecond
	DefaultAllocSize         = 16 * 1024 * 1024
)
var defaultPageSize = os.Getpagesize()
const flockRetryTimeout = 50 * time.Millisecond
type DB struct {
	StrictMode bool
	NoSync bool
	NoFreelistSync bool
	NoGrowSync bool
	MmapFlags int
	MaxBatchSize int
	MaxBatchDelay time.Duration
	AllocSize int
	path     string
	file     *os.File
	lockfile *os.File  
	dataref  []byte    
	data     *[maxMapSize]byte
	datasz   int
	filesz   int  
	meta0    *meta
	meta1    *meta
	pageSize int
	opened   bool
	rwtx     *Tx
	txs      []*Tx
	stats    Stats
	freelist     *freelist
	freelistLoad sync.Once
	pagePool sync.Pool
	batchMu sync.Mutex
	batch   *batch
	rwlock   sync.Mutex    
	metalock sync.Mutex    
	mmaplock sync.RWMutex  
	statlock sync.RWMutex  
	ops struct {
		writeAt func(b []byte, off int64) (n int, err error)
	}
	readOnly bool
}
func (db *DB) Path() string {
	return db.path
}
func (db *DB) GoString() string {
	return fmt.Sprintf("bolt.DB{path:%q}", db.path)
}
func (db *DB) String() string {
	return fmt.Sprintf("DB<%q>", db.path)
}