cake
/
libp7
Archived
1
0
Fork 1
This repository has been archived on 2024-03-16. You can view files and clone it, but cannot push or open issues or pull requests.
libp7/src/protocol/backup_boot.c

57 lines
1.7 KiB
C

/* ************************************************************************** */
/* _____ _ */
/* protocol/backup_boot.c |_ _|__ _ _| |__ ___ _ _ */
/* | Project: libp7 | |/ _ \| | | | '_ \ / _ \ | | | */
/* | | (_) | |_| | | | | __/ |_| | */
/* By: thomas <thomas@touhey.fr> |_|\___/ \__,_|_| |_|\___|\__, |.fr */
/* Last updated: 2016/10/13 07:33:17 |___/ */
/* */
/* ************************************************************************** */
#include <libp7/internals.h>
/**
* p7_backup_boot:
* Backup the boot code.
*
* @arg handle the libp7 handle
* @arg file the filestream
* @return the error code (0 if ok)
*/
int p7_backup_boot(p7_handle_t *handle, FILE *file)
{
int err;
/* make checks */
chk_handle(handle);
chk_active(handle);
chk_iswrite(file);
/* send command packet */
log_info("sending command");
if ((err = p7_send_cmdbak_reqboot(handle))) {
log_fatal("couldn't send command/get response");
return (err);
} else if (response.type != p7_pt_ack) {
log_fatal("received an invalid answer");
return (p7_error_unknown);
}
/* send the roleswap */
log_info("sending the roleswap");
if ((err = p7_send_roleswp(handle))) {
log_fatal("couldn't send roleswap");
return (err);
} else if (response.type != p7_pt_cmd) {
log_fatal("didn't receive command");
return (p7_error_unknown);
}
/* get the data */
if ((err = p7_get_filestream(handle, file, 0x400000, 0, NULL)))
return (err);
/* we're good */
return (0);
}