Exemplo n.º 1
0
func RawWriteMetadata(volume *gfapi.Volume, file interface{}, buf []byte) error {
	var err error
	for index := 0; len(buf) > 0; index++ {
		var metadataName string
		if index == 0 {
			metadataName = "user.swift.metadata"
		} else {
			metadataName = "user.swift.metadata" + strconv.Itoa(index)
		}
		writelen := METADATA_CHUNK_SIZE
		if len(buf) < writelen {
			writelen = len(buf)
		}
		switch v := file.(type) {
		case string:
			err = volume.Setxattr(v, metadataName, buf[0:writelen], 0)
		case *gfapi.File:
			err = v.Setxattr(metadataName, buf[0:writelen], 0)
		case gfapi.Fd:
			err = v.Fsetxattr(metadataName, buf[0:writelen], 0)
		}
		if err != nil {
			return err
		}
		buf = buf[writelen:len(buf)]
	}
	return nil
}
Exemplo n.º 2
0
func GetXAttr(volume *gfapi.Volume, fileNameOrFd interface{}, attr string, value []byte) (int64, error) {
	var err error
	var ret int64

	switch v := fileNameOrFd.(type) {
	case string:
		ret, err = volume.Getxattr(v, attr, value)
	case *gfapi.File:
		ret, err = v.Getxattr(attr, value)
	case gfapi.Fd:
		ret, err = v.Fgetxattr(attr, value)
	}
	return ret, err
}