diff options
| author | Dominik Riebeling <Dominik.Riebeling@gmail.com> | 2009-06-12 16:35:34 +0000 |
|---|---|---|
| committer | Dominik Riebeling <Dominik.Riebeling@gmail.com> | 2009-06-12 16:35:34 +0000 |
| commit | 11fa12c366a0d33b198fea657dca18bc9d658b61 (patch) | |
| tree | 11ea8b241b5c4b962ad3b7f1d6a4fc072aa0c82a /utils/MTP/beastpatcher/mtp_libmtp.c | |
| parent | 1240216a7581adf9dd018282e33bd6261934f4c2 (diff) | |
| download | rockbox-11fa12c366a0d33b198fea657dca18bc9d658b61.zip rockbox-11fa12c366a0d33b198fea657dca18bc9d658b61.tar.gz rockbox-11fa12c366a0d33b198fea657dca18bc9d658b61.tar.bz2 rockbox-11fa12c366a0d33b198fea657dca18bc9d658b61.tar.xz | |
Implement sendfirm functionality in beastpatcher. Set svn:eol-style properties.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@21260 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'utils/MTP/beastpatcher/mtp_libmtp.c')
| -rw-r--r-- | utils/MTP/beastpatcher/mtp_libmtp.c | 58 |
1 files changed, 50 insertions, 8 deletions
diff --git a/utils/MTP/beastpatcher/mtp_libmtp.c b/utils/MTP/beastpatcher/mtp_libmtp.c index c29e527..90477fb 100644 --- a/utils/MTP/beastpatcher/mtp_libmtp.c +++ b/utils/MTP/beastpatcher/mtp_libmtp.c @@ -47,6 +47,8 @@ #include "libmtp.h" #include "mtp_common.h" +static int mtp_send_fileptr(struct mtp_info_t* mtp_info, FILE* fwfile, size_t fwsize); + int mtp_init(struct mtp_info_t* mtp_info) { /* Fill the info struct with zeros - mainly for the strings */ @@ -74,8 +76,8 @@ int mtp_scan(struct mtp_info_t* mtp_info) if (mtp_info->device == NULL) { return -1; - } - else + } + else { /* NOTE: These strings are filled with zeros in mtp_init() */ #ifndef REALLYOLDMTP @@ -117,7 +119,6 @@ static int progress(uint64_t const sent, uint64_t const total, int mtp_send_firmware(struct mtp_info_t* mtp_info, unsigned char* fwbuf, int fwsize) { - LIBMTP_file_t *genfile; int ret; size_t n; FILE* fwfile; @@ -142,6 +143,20 @@ int mtp_send_firmware(struct mtp_info_t* mtp_info, unsigned char* fwbuf, /* Reset file pointer */ fseek(fwfile, SEEK_SET, 0); + ret = mtp_send_fileptr(mtp_info, fwfile, fwsize); + + /* Close the temporary file - this also deletes it. */ + fclose(fwfile); + + return 0; +} + + +static int mtp_send_fileptr(struct mtp_info_t* mtp_info, FILE* fwfile, size_t fwsize) +{ + LIBMTP_file_t* genfile; + int ret; + /* Prepare for uploading firmware */ genfile = LIBMTP_new_file_t(); genfile->filetype = LIBMTP_FILETYPE_FIRMWARE; @@ -149,10 +164,10 @@ int mtp_send_firmware(struct mtp_info_t* mtp_info, unsigned char* fwbuf, genfile->filesize = fwsize; #ifdef OLDMTP - ret = LIBMTP_Send_File_From_File_Descriptor(mtp_info->device, + ret = LIBMTP_Send_File_From_File_Descriptor(mtp_info->device, fileno(fwfile), genfile, progress, NULL, 0); #else - ret = LIBMTP_Send_File_From_File_Descriptor(mtp_info->device, + ret = LIBMTP_Send_File_From_File_Descriptor(mtp_info->device, fileno(fwfile), genfile, progress, NULL); #endif @@ -167,8 +182,35 @@ int mtp_send_firmware(struct mtp_info_t* mtp_info, unsigned char* fwbuf, /* Cleanup */ LIBMTP_destroy_file_t(genfile); - /* Close the temporary file - this also deletes it. */ - fclose(fwfile); + return ret; +} - return 0; + +int mtp_send_file(struct mtp_info_t* mtp_info, const char* filename) +{ + FILE* fwfile; + int ret; +#ifdef _LARGEFILE64_SOURCE + struct stat64 sb; + ret = stat64(filename, &sb); +#else + struct stat sb; + ret = stat(filename, &sb); +#endif + if (ret == -1) + { + perror("[ERR] "); + } + + fwfile = fopen(filename, "r"); + if (fwfile == NULL) + { + fprintf(stderr,"[ERR] Could not create temporary file.\n"); + return -1; + } + ret = mtp_send_fileptr(mtp_info, fwfile, sb.st_size); + + fclose(fwfile); + return ret; } + |