WriteFile writes a file from 'src' using memory mapping. It overwrites the entire contents of the previous file. The mapping size is calculated using the `Msgsize()` method of 'src', so it must produce a result equal to or greater than the actual encoded size of the object. Otherwise, a fault (SIGBU
(src MarshalSizer, file *os.File)
| 67 | // (Linux users should run a kernel and filesystem |
| 68 | // that support fallocate(2) for the best results.) |
| 69 | func WriteFile(src MarshalSizer, file *os.File) error { |
| 70 | sz := src.Msgsize() |
| 71 | err := fallocate(file, int64(sz)) |
| 72 | if err != nil { |
| 73 | return err |
| 74 | } |
| 75 | data, err := syscall.Mmap(int(file.Fd()), 0, sz, syscall.PROT_READ|syscall.PROT_WRITE, syscall.MAP_SHARED) |
| 76 | if err != nil { |
| 77 | return err |
| 78 | } |
| 79 | adviseWrite(data) |
| 80 | chunk := data[:0] |
| 81 | chunk, err = src.MarshalMsg(chunk) |
| 82 | if err != nil { |
| 83 | return err |
| 84 | } |
| 85 | uerr := syscall.Munmap(data) |
| 86 | if uerr != nil { |
| 87 | return uerr |
| 88 | } |
| 89 | return file.Truncate(int64(len(chunk))) |
| 90 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…