SAM_D...STORE(3)

πŸ’– SAM_D...STORE(3) β€” sam_data_restore πŸ’–

okay bestie, this one lives in the Corosync Cluster Engine Programmer's Manual, section 3 of the manual pages. it's the little sibling of sam_data_store, and it's here to hand your data back to you. let's get into it 🫢


✨ NAME ✨

sam_data_restore β€” bestie, it restores your previously saved user data. that's the whole job. no cap. πŸ’…


🌸 SYNOPSIS 🌸

#include <corosync/sam.h>

cs_error_t sam_data_restore (void *data, size_t size);

πŸ¦‹ DESCRIPTION πŸ¦‹

so the sam_data_restore function is the glow-up reversal of sam_data_store(3) β€” you use it to restore data that was previously saved by calling sam_data_store(3). and the iconic part? that data survives between instances. it's giving main character energy that outlives the whole process. periodt. πŸ‘‘

the data parameter is a pointer to memory that you, the caller, initialized. the stored data gets copied right there into it. which also means β€” and this is the important bit, don't skip it β€” the caller is responsible for freeing that memory. you malloc'd it, you free it. it's your child now. 😭

the size parameter is the length of data. and lowkey this one has rules:

  • it must be at least the same length as the previously stored data, otherwise an error gets returned. no sneaky shrinking, bestie. 🚫
  • it can be larger, but then only the stored data size bytes are changed. everything past that just sits there, untouched.

and if you need to know the length of the stored data first (which, honestly, you probably do), use sam_data_getsize(3). it's literally right there for you. 🌈


πŸ’œ RETURN VALUE πŸ’œ

this call returns the CS_OK value if it's successful. if it's not? an error gets returned instead. that's it, that's the vibe check. ✨


πŸŽ€ ERRORS πŸŽ€

  • CS_ERR_BAD_HANDLE β€” the component was not initialized by calling sam_initialize(3), or it was already finalized. like, you can't show up to the party after it ended, babe. πŸ’€
  • CS_ERR_INVALID_PARAM β€” the data parameter is NULL, or size is less than the currently stored data length. one of those two, pick your fighter. πŸ™ˆ

🧚 SEE ALSO 🧚

and also, while you're here, the whole lil squad of CS_ERR codes:

  • CS_ERR_TRY_AGAIN β€” Resource temporarily unavailable
  • CS_ERR_INVALID_PARAM β€” Invalid argument
  • CS_ERR_ACCESS β€” Permission denied
  • CS_ERR_LIBRARY β€” The connection failed
  • CS_ERR_INTERRUPT β€” System call interrupted by a signal
  • CS_ERR_NOT_SUPPORTED β€” The requested protocol/functionality not supported
  • CS_ERR_MESSAGE_ERROR β€” Incorrect auth message received
  • CS_ERR_NO_MEMORY β€” Not enough memory to complete the requested task

🌟 gentle reminder bestie: that data buffer is yours to free. the function copies into it, it does not adopt it. don't leak, okay? i'm watching. πŸ‘€

and that's the whole page, fr fr. this one came straight out of the corosync Man Page, dated 04/15/2010, and it's filed under SAM_D...STORE(3). slay, go restore some data, you absolute legend. πŸ’…πŸ’–βœ¨

πŸ“¦ where this page comes from