summaryrefslogtreecommitdiff
path: root/utils/MTP/beastpatcher/mtp_libmtp.c
diff options
context:
space:
mode:
authorDominik Riebeling <Dominik.Riebeling@gmail.com>2009-06-12 16:35:34 +0000
committerDominik Riebeling <Dominik.Riebeling@gmail.com>2009-06-12 16:35:34 +0000
commit11fa12c366a0d33b198fea657dca18bc9d658b61 (patch)
tree11ea8b241b5c4b962ad3b7f1d6a4fc072aa0c82a /utils/MTP/beastpatcher/mtp_libmtp.c
parent1240216a7581adf9dd018282e33bd6261934f4c2 (diff)
downloadrockbox-11fa12c366a0d33b198fea657dca18bc9d658b61.tar.gz
rockbox-11fa12c366a0d33b198fea657dca18bc9d658b61.zip
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.c58
1 files changed, 50 insertions, 8 deletions
diff --git a/utils/MTP/beastpatcher/mtp_libmtp.c b/utils/MTP/beastpatcher/mtp_libmtp.c
index c29e5277b2..90477fb0e7 100644
--- a/utils/MTP/beastpatcher/mtp_libmtp.c
+++ b/utils/MTP/beastpatcher/mtp_libmtp.c
@@ -47,6 +47,8 @@
47#include "libmtp.h" 47#include "libmtp.h"
48#include "mtp_common.h" 48#include "mtp_common.h"
49 49
50static int mtp_send_fileptr(struct mtp_info_t* mtp_info, FILE* fwfile, size_t fwsize);
51
50int mtp_init(struct mtp_info_t* mtp_info) 52int mtp_init(struct mtp_info_t* mtp_info)
51{ 53{
52 /* Fill the info struct with zeros - mainly for the strings */ 54 /* Fill the info struct with zeros - mainly for the strings */
@@ -74,8 +76,8 @@ int mtp_scan(struct mtp_info_t* mtp_info)
74 if (mtp_info->device == NULL) 76 if (mtp_info->device == NULL)
75 { 77 {
76 return -1; 78 return -1;
77 } 79 }
78 else 80 else
79 { 81 {
80 /* NOTE: These strings are filled with zeros in mtp_init() */ 82 /* NOTE: These strings are filled with zeros in mtp_init() */
81#ifndef REALLYOLDMTP 83#ifndef REALLYOLDMTP
@@ -117,7 +119,6 @@ static int progress(uint64_t const sent, uint64_t const total,
117int mtp_send_firmware(struct mtp_info_t* mtp_info, unsigned char* fwbuf, 119int mtp_send_firmware(struct mtp_info_t* mtp_info, unsigned char* fwbuf,
118 int fwsize) 120 int fwsize)
119{ 121{
120 LIBMTP_file_t *genfile;
121 int ret; 122 int ret;
122 size_t n; 123 size_t n;
123 FILE* fwfile; 124 FILE* fwfile;
@@ -142,6 +143,20 @@ int mtp_send_firmware(struct mtp_info_t* mtp_info, unsigned char* fwbuf,
142 /* Reset file pointer */ 143 /* Reset file pointer */
143 fseek(fwfile, SEEK_SET, 0); 144 fseek(fwfile, SEEK_SET, 0);
144 145
146 ret = mtp_send_fileptr(mtp_info, fwfile, fwsize);
147
148 /* Close the temporary file - this also deletes it. */
149 fclose(fwfile);
150
151 return 0;
152}
153
154
155static int mtp_send_fileptr(struct mtp_info_t* mtp_info, FILE* fwfile, size_t fwsize)
156{
157 LIBMTP_file_t* genfile;
158 int ret;
159
145 /* Prepare for uploading firmware */ 160 /* Prepare for uploading firmware */
146 genfile = LIBMTP_new_file_t(); 161 genfile = LIBMTP_new_file_t();
147 genfile->filetype = LIBMTP_FILETYPE_FIRMWARE; 162 genfile->filetype = LIBMTP_FILETYPE_FIRMWARE;
@@ -149,10 +164,10 @@ int mtp_send_firmware(struct mtp_info_t* mtp_info, unsigned char* fwbuf,
149 genfile->filesize = fwsize; 164 genfile->filesize = fwsize;
150 165
151#ifdef OLDMTP 166#ifdef OLDMTP
152 ret = LIBMTP_Send_File_From_File_Descriptor(mtp_info->device, 167 ret = LIBMTP_Send_File_From_File_Descriptor(mtp_info->device,
153 fileno(fwfile), genfile, progress, NULL, 0); 168 fileno(fwfile), genfile, progress, NULL, 0);
154#else 169#else
155 ret = LIBMTP_Send_File_From_File_Descriptor(mtp_info->device, 170 ret = LIBMTP_Send_File_From_File_Descriptor(mtp_info->device,
156 fileno(fwfile), genfile, progress, NULL); 171 fileno(fwfile), genfile, progress, NULL);
157#endif 172#endif
158 173
@@ -167,8 +182,35 @@ int mtp_send_firmware(struct mtp_info_t* mtp_info, unsigned char* fwbuf,
167 /* Cleanup */ 182 /* Cleanup */
168 LIBMTP_destroy_file_t(genfile); 183 LIBMTP_destroy_file_t(genfile);
169 184
170 /* Close the temporary file - this also deletes it. */ 185 return ret;
171 fclose(fwfile); 186}
172 187
173 return 0; 188
189int mtp_send_file(struct mtp_info_t* mtp_info, const char* filename)
190{
191 FILE* fwfile;
192 int ret;
193#ifdef _LARGEFILE64_SOURCE
194 struct stat64 sb;
195 ret = stat64(filename, &sb);
196#else
197 struct stat sb;
198 ret = stat(filename, &sb);
199#endif
200 if (ret == -1)
201 {
202 perror("[ERR] ");
203 }
204
205 fwfile = fopen(filename, "r");
206 if (fwfile == NULL)
207 {
208 fprintf(stderr,"[ERR] Could not create temporary file.\n");
209 return -1;
210 }
211 ret = mtp_send_fileptr(mtp_info, fwfile, sb.st_size);
212
213 fclose(fwfile);
214 return ret;
174} 215}
216