code: func (devices *DeviceSet) writeMetaFile(jsonData []byte, filePath string) error {
  	tmpFile, err := ioutil.TempFile(devices.metadataDir(), ".tmp")
  	if err != nil {
  		return fmt.Errorf("devmapper: Error creating metadata file: %s", err)
  	}
  
  	n, err := tmpFile.Write(jsonData)
  	if err != nil {
  		return fmt.Errorf("devmapper: Error writing metadata to %s: %s", tmpFile.Name(), err)
  	}
  	if n < len(jsonData) {
  		return io.ErrShortWrite
  	}
  	if err := tmpFile.Sync(); err != nil {
  		return fmt.Errorf("devmapper: Error syncing metadata file %s: %s", tmpFile.Name(), err)
  	}
  	if err := tmpFile.Close(); err != nil {
  		return fmt.Errorf("devmapper: Error closing metadata file %s: %s", tmpFile.Name(), err)
  	}
  	if err := os.Rename(tmpFile.Name(), filePath); err != nil {
  		return fmt.Errorf("devmapper: Error committing metadata file %s: %s", tmpFile.Name(), err)
  	}
  
  	return nil
  }
docs: // Given json data and file path, write it to disk