@@ -65,7 +65,7 @@ typedef struct {
65
65
static fs_object_info_t fs_objects [FS_MAX_NODES ] = {
66
66
{
67
67
.handle = 1 ,
68
- .parent = 0xffffffff ,
68
+ .parent = 0 ,
69
69
.allocated = true,
70
70
.association = false,
71
71
.name = "readme.txt" ,
@@ -80,7 +80,7 @@ static fs_object_info_t fs_objects[FS_MAX_NODES] = {
80
80
#define STORAGE_DESCRIPTRION { 'd', 'i', 's', 'k', 0 }
81
81
#define VOLUME_IDENTIFIER { 'v', 'o', 'l', 0 }
82
82
83
- typedef MTP_STORAGE_INFO_TYPEDEF (TU_ARRAY_SIZE ((uint16_t []) STORAGE_DESCRIPTRION ),
83
+ typedef MTP_STORAGE_INFO_STRUCT (TU_ARRAY_SIZE ((uint16_t []) STORAGE_DESCRIPTRION ),
84
84
TU_ARRAY_SIZE (((uint16_t [])VOLUME_IDENTIFIER ))
85
85
) storage_info_t ;
86
86
@@ -261,7 +261,8 @@ int32_t tud_mtp_command_received_cb(uint8_t idx, mtp_generic_container_t* cmd_bl
261
261
uint32_t handles [FS_MAX_NODES ] = { 0 };
262
262
uint32_t count = 0 ;
263
263
for (uint8_t i = 0 , h = 0 ; i < FS_MAX_NODES ; i ++ ) {
264
- if (fs_objects [i ].allocated && parent_handle == fs_objects [i ].parent ) {
264
+ if (fs_objects [i ].allocated && parent_handle == fs_objects [i ].parent ||
265
+ (parent_handle == 0xFFFFFFFF && fs_objects [i ].parent == 0 )) {
265
266
handles [count ++ ] = fs_objects [i ].handle ;
266
267
}
267
268
}
@@ -270,6 +271,40 @@ int32_t tud_mtp_command_received_cb(uint8_t idx, mtp_generic_container_t* cmd_bl
270
271
break ;
271
272
}
272
273
274
+ case MTP_OP_GET_OBJECT_INFO : {
275
+ const uint32_t object_handle = cmd_block -> data [0 ];
276
+ fs_object_info_t * obj = fs_object_get_from_handle (object_handle );
277
+ if (obj == NULL ) {
278
+ TU_LOG1 ("ERR: Object with handle %ld does not exist\r\n" , object_handle );
279
+ return MTP_RESP_INVALID_OBJECT_HANDLE ;
280
+ }
281
+ mtp_object_info_header_t object_info_header = {
282
+ .storage_id = SUPPORTED_STORAGE_ID ,
283
+ .object_format = MTP_OBJ_FORMAT_TEXT ,
284
+ .protection_status = MTP_PROTECTION_STATUS_NO_PROTECTION ,
285
+ .object_compressed_size = obj -> size ,
286
+ .thumb_format = MTP_OBJ_FORMAT_UNDEFINED ,
287
+ .thumb_compressed_size = 0 ,
288
+ .thumb_pix_width = 0 ,
289
+ .thumb_pix_height = 0 ,
290
+ .image_pix_width = 0 ,
291
+ .image_pix_height = 0 ,
292
+ .image_bit_depth = 0 ,
293
+ .parent_object = obj -> parent ,
294
+ .association_type = MTP_ASSOCIATION_UNDEFINED ,
295
+ .association_desc = 0 ,
296
+ .sequence_number = 0
297
+ };
298
+ mtp_container_add_raw (out_block , & object_info_header , sizeof (object_info_header ));
299
+ mtp_container_add_cstring (out_block , obj -> name );
300
+ mtp_container_add_cstring (out_block , obj -> created );
301
+ mtp_container_add_cstring (out_block , obj -> modified );
302
+ mtp_container_add_cstring (out_block , "" ); // keywords, not used
303
+
304
+ tud_mtp_data_send (out_block );
305
+ break ;
306
+ }
307
+
273
308
default : return MTP_RESP_OPERATION_NOT_SUPPORTED ;
274
309
}
275
310
@@ -346,7 +381,7 @@ mtp_response_t tud_mtp_storage_association_get_object_handle(uint32_t storage_id
346
381
}
347
382
348
383
mtp_response_t tud_mtp_storage_object_write_info (uint32_t storage_id , uint32_t parent_object ,
349
- uint32_t * new_object_handle , const mtp_object_info_t * info ) {
384
+ uint32_t * new_object_handle , const mtp_object_info_header_t * info ) {
350
385
fs_object_info_t * obj = NULL ;
351
386
352
387
if (_fs_operation .session_id == 0 ) {
@@ -402,7 +437,7 @@ mtp_response_t tud_mtp_storage_object_write_info(uint32_t storage_id, uint32_t p
402
437
obj -> association = info -> object_format == MTP_OBJ_FORMAT_ASSOCIATION ;
403
438
404
439
// Extract variable data
405
- uint16_t offset_data = sizeof (mtp_object_info_t );
440
+ uint16_t offset_data = sizeof (mtp_object_info_header_t );
406
441
mtpd_gct_get_string (& offset_data , obj -> name , FS_MAX_NODE_NAME_LEN );
407
442
mtpd_gct_get_string (& offset_data , obj -> created , FS_ISODATETIME_LEN );
408
443
mtpd_gct_get_string (& offset_data , obj -> modified , FS_ISODATETIME_LEN );
@@ -417,46 +452,6 @@ mtp_response_t tud_mtp_storage_object_write_info(uint32_t storage_id, uint32_t p
417
452
return MTP_RESP_OK ;
418
453
}
419
454
420
- mtp_response_t tud_mtp_storage_object_read_info (uint32_t object_handle , mtp_object_info_t * info ) {
421
- const fs_object_info_t * obj ;
422
-
423
- if (_fs_operation .session_id == 0 ) {
424
- TU_LOG1 ("ERR: Session not open\r\n" );
425
- return MTP_RESP_SESSION_NOT_OPEN ;
426
- }
427
-
428
- obj = fs_object_get_from_handle (object_handle );
429
- if (obj == NULL ) {
430
- TU_LOG1 ("ERR: Object with handle %ld does not exist\r\n" , object_handle );
431
- return MTP_RESP_INVALID_OBJECT_HANDLE ;
432
- }
433
-
434
- memset (info , 0 , sizeof (mtp_object_info_t ));
435
- info -> storage_id = STORAGE_ID (0x0001 , 0x0001 );
436
- if (obj -> association ) {
437
- info -> object_format = MTP_OBJ_FORMAT_ASSOCIATION ;
438
- info -> protection_status = MTP_PROTECTION_STATUS_NO_PROTECTION ;
439
- info -> object_compressed_size = 0 ;
440
- info -> association_type = MTP_ASSOCIATION_UNDEFINED ;
441
- } else {
442
- info -> object_format = MTP_OBJ_FORMAT_UNDEFINED ;
443
- info -> protection_status = MTP_PROTECTION_STATUS_NO_PROTECTION ;
444
- info -> object_compressed_size = obj -> size ;
445
- info -> association_type = MTP_ASSOCIATION_UNDEFINED ;
446
- }
447
- info -> thumb_format = MTP_OBJ_FORMAT_UNDEFINED ;
448
- info -> parent_object = obj -> parent ;
449
-
450
- mtpd_gct_append_wstring (obj -> name );
451
- mtpd_gct_append_wstring (obj -> created ); // date_created
452
- mtpd_gct_append_wstring (obj -> modified ); // date_modified
453
- mtpd_gct_append_wstring ("" ); // keywords, not used
454
-
455
- TU_LOG1 ("Retrieve object %s with handle %ld\r\n" , obj -> name , obj -> handle );
456
-
457
- return MTP_RESP_OK ;
458
- }
459
-
460
455
mtp_response_t tud_mtp_storage_object_write (uint32_t object_handle , const uint8_t * buffer , uint32_t size ) {
461
456
fs_object_info_t * obj ;
462
457
0 commit comments