// SetattrV2 handles OpSetattrV2 requests
171958
func (s *Server) SetattrV2(p *Packet) (interface{}, error) {
	res := &ReplySetattrV2{}

	req := new(RequestSetattrV2)
	err := UnmarshalBinary(p.Payload, req)
	if err != nil {
		return nil, err
	}

	name := req.FileName.Path()

	_, err = os.Stat(name)
	if err != nil && os.IsNotExist(err) {
		// assuming this is a virtual file
		return res, nil
	}

	uid := -1
	if req.Attr.Mask&AttrValidUserID == AttrValidUserID {
		uid = int(req.Attr.UserID)
	}

	gid := -1
	if req.Attr.Mask&AttrValidGroupID == AttrValidGroupID {
		gid = int(req.Attr.GroupID)
	}

	err = s.chown(name, uid, gid)
	if err != nil {
		return nil, err
	}

	var perm os.FileMode

	if req.Attr.Mask&AttrValidOwnerPerms == AttrValidOwnerPerms {
		perm |= os.FileMode(req.Attr.OwnerPerms) << 6
	}

	if req.Attr.Mask&AttrValidGroupPerms == AttrValidGroupPerms {
		perm |= os.FileMode(req.Attr.GroupPerms) << 3
	}

	if req.Attr.Mask&AttrValidOtherPerms == AttrValidOtherPerms {
		perm |= os.FileMode(req.Attr.OtherPerms)
	}

	if perm != 0 {
		err = s.chmod(name, perm)
		if err != nil {
			return nil, err
		}
	}

	return res, nil
}
525388
func (s *Item) SetAttributes(v []*Attribute) *Item {
	s.Attributes = v
	return s
}
613826
func (c *connector) SetAttr(key string, value interface{}) {
	c.Lock()
	c.attrs[key] = value
	c.Unlock()
}
1078237
func (s *EndpointRequest) SetAttributes(v map[string][]*string) *EndpointRequest {
	s.Attributes = v
	return s
}
120965
func (s *UnmappedAttribute) SetAttribute(v *Attribute) *UnmappedAttribute {
	s.Attribute = v
	return s
}
108078
func (s *ContainerInstance) SetAttributes(v []*Attribute) *ContainerInstance {
	s.Attributes = v
	return s
}
328924
func (s *PlatformApplication) SetAttributes(v map[string]*string) *PlatformApplication {
	s.Attributes = v
	return s
}
968401
func Setattr(fd int, action uint, state *Termios) (err error) {
	switch action {
	case TCSANOW:
		action = TCSETS
	case TCSADRAIN:
		action = TCSETSW
	case TCSAFLUSH:
		action = TCSETSF
	}

	_, _, e1 := unix.Syscall(unix.SYS_IOCTL, uintptr(fd),
		uintptr(action), uintptr(unsafe.Pointer(state)))
	if e1 != 0 {
		err = e1
	}
	return
}
956467
func (s *PlacementDescription) SetAttributes(v map[string]*string) *PlacementDescription {
	s.Attributes = v
	return s
}
643771
func (s *RegisterInstanceInput) SetAttributes(v map[string]*string) *RegisterInstanceInput {
	s.Attributes = v
	return s
}
1190878
func (s *BatchGetLinkAttributesResponse) SetAttributes(v []*AttributeKeyAndValue) *BatchGetLinkAttributesResponse {
	s.Attributes = v
	return s
}
383791
func (s *CloneStackInput) SetAttributes(v map[string]*string) *CloneStackInput {
	s.Attributes = v
	return s
}
1353008
func (o *Object) SetAttrs(keyval ...string) error {
	_, err := o.SetAttrs2(keyval...)
	return err
}
402055
func (s *DeviceRegistryEnrichActivity) SetAttribute(v string) *DeviceRegistryEnrichActivity {
	s.Attribute = &v
	return s
}
806123
func (s *ThingGroupDocument) SetAttributes(v map[string]*string) *ThingGroupDocument {
	s.Attributes = v
	return s
}
723145
func (s *UserType) SetAttributes(v []*AttributeType) *UserType {
	s.Attributes = v
	return s
}
689579
func (o *Object) SetAttr(key, value string) error {
	ctx := context.TODO() // TODO: make it possible to get a context via Object; either new context field, or via some "ImportRun" field?
	if o.Attr(key) == value {
		return nil
	}
	_, err := o.h.upload(ctx, schema.NewSetAttributeClaim(o.pn, key, value))
	if err != nil {
		return err
	}
	o.mu.Lock()
	defer o.mu.Unlock()
	if o.attr == nil {
		o.attr = make(map[string][]string)
	}
	o.attr[key] = []string{value}
	return nil
}