// writeXLMetadata - writes `xl.json` to a single disk.
499609
func writeXLMetadata(ctx context.Context, disk StorageAPI, bucket, prefix string, xlMeta xlMetaV1) error {
	jsonFile := path.Join(prefix, xlMetaJSONFile)

	// Marshal json.
	metadataBytes, err := json.Marshal(&xlMeta)
	if err != nil {
		logger.LogIf(ctx, err)
		return err
	}

	// Persist marshaled data.
	err = disk.WriteAll(bucket, jsonFile, metadataBytes)
	logger.LogIf(ctx, err)
	return err
}
1270248
func WriteMetaPayload(w io.Writer, meta *Meta, pl *Payload) error {
	payloadBuf, err := pl.Encode()
	if err != nil {
		return err
	}
	meta.Size = uint32(len(payloadBuf))
	meta.WriteBinary(w)
	_, err = w.Write(payloadBuf)
	return err
}
825175
func writeAll(d []byte, w io.Writer) (err error) {
    i := 0
    n := 0
    l := len(d)
    for i < l && err != nil {
        n, err = w.Write(d[i:])
        i += n
    }
    return
}
1025949
func (l *linuxDatapath) writeStaticData(fw io.Writer, e datapath.EndpointConfiguration) {
	fmt.Fprint(fw, defineIPv6("LXC_IP", e.IPv6Address()))
	fmt.Fprint(fw, defineIPv4("LXC_IPV4", e.IPv4Address()))

	fmt.Fprint(fw, defineMAC("NODE_MAC", e.GetNodeMAC()))
	fmt.Fprint(fw, defineUint32("LXC_ID", uint32(e.GetID())))

	secID := e.GetIdentity().Uint32()
	fmt.Fprintf(fw, defineUint32("SECLABEL", secID))
	fmt.Fprintf(fw, defineUint32("SECLABEL_NB", byteorder.HostToNetwork(secID).(uint32)))

	epID := uint16(e.GetID())
	fmt.Fprintf(fw, "#define POLICY_MAP %s\n", bpf.LocalMapName(policymap.MapName, epID))
	fmt.Fprintf(fw, "#define CALLS_MAP %s\n", bpf.LocalMapName("cilium_calls_", epID))
	fmt.Fprintf(fw, "#define CONFIG_MAP %s\n", bpf.LocalMapName(bpfconfig.MapNamePrefix, epID))
}
622357
func (tx *Tx) writeMeta() error {
	// Create a temporary buffer for the meta page.
	buf := make([]byte, tx.db.pageSize)
	p := tx.db.pageInBuffer(buf, 0)
	tx.meta.write(p)

	// Write the meta page to file.
	if _, err := tx.db.ops.writeAt(buf, int64(p.id)*int64(tx.db.pageSize)); err != nil {
		return err
	}
	if !tx.db.NoSync || IgnoreNoSync {
		if err := fdatasync(tx.db); err != nil {
			return err
		}
	}

	// Update statistics.
	tx.stats.Write++

	return nil
}
748223
func (api *ExternalSigner) SignData(account accounts.Account, mimeType string, data []byte) ([]byte, error) {
	var res hexutil.Bytes
	var signAddress = common.NewMixedcaseAddress(account.Address)
	if err := api.client.Call(&res, "account_signData",
		mimeType,
		&signAddress, // Need to use the pointer here, because of how MarshalJSON is defined
		hexutil.Encode(data)); err != nil {
		return nil, err
	}
	// If V is on 27/28-form, convert to to 0/1 for Clique
	if mimeType == accounts.MimetypeClique && (res[64] == 27 || res[64] == 28) {
		res[64] -= 27 // Transform V from 27/28 to 0/1 for Clique use
	}
	return res, nil
}
479713
func formatData(value interface{}) (formatted interface{}) {
	switch value := value.(type) {
	case json.Marshaler:
		return value
	case error:
		return value.Error()
	case fmt.Stringer:
		return value.String()
	default:
		return value
	}
}
647484
func (h *DBHeader) writeTo(w io.Writer) error {
	var buffer bytes.Buffer
	mw := io.MultiWriter(w, &buffer)

	binary.Write(mw, binary.LittleEndian, h.Signature)

	if h.IsKdbx4() {
		h.FileHeaders.writeTo4(mw, &buffer)
	} else {
		h.FileHeaders.writeTo31(mw)
	}

	h.RawData = buffer.Bytes()

	return nil
}
335167
func (image *Image) Write(data []byte) (n int, err error) {
	ret := int(C.rbd_write(image.image, C.uint64_t(image.offset),
		C.size_t(len(data)), (*C.char)(unsafe.Pointer(&data[0]))))

	if ret >= 0 {
		image.offset += int64(ret)
	}

	if ret != len(data) {
		err = RBDError(-C.EPERM)
	}

	return ret, err
}
1222240
func WriteXML(writer io.Writer, v interface{}, options XML) (int, error) {
	if prefix := options.Prefix; prefix != "" {
		writer.Write([]byte(prefix))
	}

	if indent := options.Indent; indent != "" {
		result, err := xml.MarshalIndent(v, "", indent)
		if err != nil {
			return 0, err
		}
		result = append(result, newLineB...)
		return writer.Write(result)
	}

	result, err := xml.Marshal(v)
	if err != nil {
		return 0, err
	}
	return writer.Write(result)
}
811120
func formatXLMigrate(export string) error {
	formatPath := pathJoin(export, minioMetaBucket, formatConfigFile)
	backend, err := formatMetaGetFormatBackendXL(formatPath)
	if err != nil {
		return err
	}
	if backend != formatBackendXL {
		return fmt.Errorf(`Disk %s: found backend %s, expected %s`, export, backend, formatBackendXL)
	}
	version, err := formatXLGetVersion(formatPath)
	if err != nil {
		return err
	}
	switch version {
	case formatXLVersionV1:
		if err = formatXLMigrateV1ToV2(export); err != nil {
			return err
		}
		fallthrough
	case formatXLVersionV2:
		if err = formatXLMigrateV2ToV3(export); err != nil {
			return err
		}
		fallthrough
	case formatXLVersionV3:
		// format-V3 is the latest verion.
		return nil
	}
	return fmt.Errorf(`%s: unknown format version %s`, export, version)
}
79633
func initFormatXL(ctx context.Context, storageDisks []StorageAPI, setCount, disksPerSet int) (format *formatXLV3, err error) {
	format = newFormatXLV3(setCount, disksPerSet)
	formats := make([]*formatXLV3, len(storageDisks))

	for i := 0; i < setCount; i++ {
		for j := 0; j < disksPerSet; j++ {
			newFormat := *format
			newFormat.XL.This = format.XL.Sets[i][j]
			formats[i*disksPerSet+j] = &newFormat
		}
	}

	// Initialize meta volume, if volume already exists ignores it.
	if err = initFormatXLMetaVolume(storageDisks, formats); err != nil {
		return format, fmt.Errorf("Unable to initialize '.minio.sys' meta volume, %s", err)
	}

	// Save formats `format.json` across all disks.
	if err = saveFormatXLAll(ctx, storageDisks, formats); err != nil {
		return nil, err
	}

	return format, nil
}
1334166
func (handle *MemifPacketHandle) WritePacketData(data []byte) (err error) {
	handle.writeMu.Lock()
	defer handle.writeMu.Unlock()

	if handle.stop {
		err = io.EOF
		return
	}

	count, err := handle.memif.TxBurst(handle.queueId, []RawPacketData{data})

	if err != nil {
		return
	}

	if count == 0 {
		err = io.EOF
	}

	return
}
81583
func addToMetadata(md metadata.MD, key string, value string) error {
	if value == "" {
		return nil
	}
	if _, ok := md[key]; ok {
		return yarpcerrors.InvalidArgumentErrorf("duplicate key: %s", key)
	}
	md[key] = []string{value}
	return nil
}
981660
func UnmarshalVolumeMetadata(text string) ([]VolumeMetadata, error) {
	var v []VolumeMetadata
	err := json.Unmarshal([]byte(text), &v)
	return v, err
}
1172229
func (c *xContext) MapData(i interface{}, data map[string][]string, names ...string) error {
	var name string
	if len(names) > 0 {
		name = names[0]
	}
	return NamedStructMap(c.echo, i, data, name)
}
943690
func HexData(b []uint8) string {
	td := b[:]
	m := senv.MaxBodyLength()
	if m > 0 {
		if m < len(td) {
			td = td[:m]
		}
	}
	return "\n" + hex.Dump(td)
}