1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Based on sendfile.c from libmtp: http://libmtp.sourceforge.net
11 * Modified by Maurus Cuelenaere and Nicolas Pennequin.
13 * Copyright (C) 2005-2007 Linus Walleij
14 * Copyright (C) 2006 Chris A. Debenham
16 * All files in this archive are subject to the GNU General Public License.
17 * See the file COPYING in the source tree root for full license agreement.
19 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
20 * KIND, either express or implied.
22 ****************************************************************************/
24 #define _LARGEFILE_SOURCE
25 #define _LARGEFILE64_SOURCE
30 #include <sys/types.h>
34 LIBMTP_mtpdevice_t
*device
;
36 static int progress(u_int64_t
const sent
, u_int64_t
const total
,
37 void const *const data
)
39 int percent
= (sent
* 100) / total
;
41 printf("Progress: %I64u of %I64u (%d%%)\r", sent
, total
, percent
);
43 printf("Progress: %llu of %llu (%d%%)\r", sent
, total
, percent
);
51 fprintf(stderr
, "usage: sendfirm <local filename>\n");
54 int sendfile_function(char *from_path
)
56 printf("Sending %s\n", from_path
);
58 #ifdef __USE_LARGEFILE64
63 LIBMTP_file_t
*genfile
;
65 uint32_t parent_id
= 0;
67 #ifdef __USE_LARGEFILE64
68 if (stat64(from_path
, &sb
) == -1)
71 if (stat(from_path
, &sb
) == -1)
74 fprintf(stderr
, "%s: ", from_path
);
79 #ifdef __USE_LARGEFILE64
80 filesize
= sb
.st_size
;
82 filesize
= (uint64_t) sb
.st_size
;
85 genfile
= LIBMTP_new_file_t();
86 genfile
->filesize
= filesize
;
87 genfile
->filename
= strdup("nk.bin");
88 genfile
->filetype
= LIBMTP_FILETYPE_FIRMWARE
;
90 printf("Sending file...\n");
91 ret
= LIBMTP_Send_File_From_File(device
, from_path
, genfile
, progress
,
96 printf("Error sending file.\n");
97 LIBMTP_Dump_Errorstack(device
);
98 LIBMTP_Clear_Errorstack(device
);
102 printf("New file ID: %d\n", genfile
->item_id
);
105 LIBMTP_destroy_file_t(genfile
);
110 int main(int argc
, char **argv
)
120 fprintf(stdout
, "libmtp version: " LIBMTP_VERSION_STRING
"\n\n");
122 device
= LIBMTP_Get_First_Device();
125 printf("No devices.\n");
129 sendfile_function(argv
[1]);
131 LIBMTP_Release_Device(device
);