Ejemplo n.º 1
0
// createHeader - create a new random header and write it to disk
func (f *file) createHeader() error {
	h := cryptfs.RandomHeader()
	buf := h.Pack()
	_, err := f.fd.WriteAt(buf, 0)
	if err != nil {
		return err
	}
	f.header = h

	return nil
}
Ejemplo n.º 2
0
// createHeader - create a new random header and write it to disk
func (f *file) createHeader() error {
	h := cryptfs.RandomHeader()
	buf := h.Pack()

	// Prevent partially written (=corrupt) header by preallocating the space beforehand
	f.fdLock.Lock()
	defer f.fdLock.Unlock()
	err := prealloc(int(f.fd.Fd()), 0, cryptfs.HEADER_LEN)
	if err != nil {
		cryptfs.Warn.Printf("createHeader: fallocateRetry failed: %s\n", err.Error())
		return err
	}

	// Actually write header
	_, err = f.fd.WriteAt(buf, 0)
	if err != nil {
		return err
	}
	f.header = h

	return nil
}