/* ***************************************************************************** * usage/storage/copy.c -- copy a file on the calculator. * Copyright (C) 2016-2017 Thomas "Cakeisalie5" Touhey * * This file is part of libp7. * libp7 is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 3.0 of the License, * or (at your option) any later version. * * libp7 is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with libp7; if not, see . * ************************************************************************** */ #include /** * p7_copy: * Copies a file into another on distant device. * * @arg handle the libp7 handle * @arg dirname the directory name * @arg filename the filename * @arg newdir the new directory name * @arg newname the new filename * @arg devname the device name * @return if it worked */ int p7_copy(p7_handle_t *handle, const char *dirname, const char *filename, const char *newdir, const char *newname, const char *devname) { int err; /* make checks */ chk_handle(handle); chk_active(handle); chk_required_filename(filename); chk_required_filename(newname); chk_dirname(dirname); chk_dirname(newdir); /* send command packet */ log_info("sending command"); if ((err = p7_send_cmdfls_copyfile(handle, dirname, filename, newdir, newname, devname))) { log_fatal("couldn't send command/get its response"); return (err); } else if (response.type != p7_pt_ack && response.type != p7_pt_error) { log_fatal("received an invalid answer"); return (p7_error_unknown); } /* - check error - */ if (response.type == p7_pt_error) switch (response.code) { /* overwrite impossible */ case p7_err_dont_overwrite: case p7_err_other: log_error("overwrite impossible"); return (p7_error_unsupported_device); /* memory full */ case p7_err_fullmem: log_error("distant memory is full"); return (p7_error_fullmem); /* resend error - just here to stfu the warning */ default: return (p7_error_unknown); } /* we're done */ return (0); }