mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
libmtp: Filter ro storage at the python level for better debugging
This commit is contained in:
parent
efd41d87ed
commit
34efc911ae
@ -146,6 +146,7 @@ class MTP_DEVICE(MTPDeviceBase):
|
|||||||
raise OpenFailed('')
|
raise OpenFailed('')
|
||||||
|
|
||||||
storage = sorted(self.dev.storage_info, key=operator.itemgetter('id'))
|
storage = sorted(self.dev.storage_info, key=operator.itemgetter('id'))
|
||||||
|
storage = [x for x in storage if x.get('rw', False)]
|
||||||
if not storage:
|
if not storage:
|
||||||
self.blacklisted_devices.add(connected_device)
|
self.blacklisted_devices.add(connected_device)
|
||||||
raise OpenFailed('No storage found for device %s'%(connected_device,))
|
raise OpenFailed('No storage found for device %s'%(connected_device,))
|
||||||
|
@ -347,28 +347,26 @@ static PyObject *
|
|||||||
libmtp_Device_storage_info(libmtp_Device *self, void *closure) {
|
libmtp_Device_storage_info(libmtp_Device *self, void *closure) {
|
||||||
PyObject *ans, *loc;
|
PyObject *ans, *loc;
|
||||||
LIBMTP_devicestorage_t *storage;
|
LIBMTP_devicestorage_t *storage;
|
||||||
|
int ro = 0;
|
||||||
ENSURE_DEV(NULL); ENSURE_STORAGE(NULL);
|
ENSURE_DEV(NULL); ENSURE_STORAGE(NULL);
|
||||||
|
|
||||||
ans = PyList_New(0);
|
ans = PyList_New(0);
|
||||||
if (ans == NULL) { PyErr_NoMemory(); return NULL; }
|
if (ans == NULL) { PyErr_NoMemory(); return NULL; }
|
||||||
|
|
||||||
for (storage = self->device->storage; storage != NULL; storage = storage->next) {
|
for (storage = self->device->storage; storage != NULL; storage = storage->next) {
|
||||||
// Ignore read only storage
|
ro = 0;
|
||||||
if (storage->StorageType == ST_FixedROM || storage->StorageType == ST_RemovableROM) continue;
|
// Check if read only storage
|
||||||
// Storage IDs with the lower 16 bits 0x0000 are not supposed to be
|
if (storage->StorageType == ST_FixedROM || storage->StorageType == ST_RemovableROM || (storage->id & 0x0000FFFFU) == 0x00000000U || storage->AccessCapability == AC_ReadOnly || storage->AccessCapability == AC_ReadOnly_with_Object_Deletion) ro = 1;
|
||||||
// writeable.
|
|
||||||
if ((storage->id & 0x0000FFFFU) == 0x00000000U) continue;
|
|
||||||
// Also check the access capability to avoid e.g. deletable only storages
|
|
||||||
if (storage->AccessCapability == AC_ReadOnly || storage->AccessCapability == AC_ReadOnly_with_Object_Deletion) continue;
|
|
||||||
|
|
||||||
loc = Py_BuildValue("{s:k,s:O,s:K,s:K,s:K,s:s,s:s}",
|
loc = Py_BuildValue("{s:k,s:O,s:K,s:K,s:K,s:s,s:s,s:O}",
|
||||||
"id", storage->id,
|
"id", storage->id,
|
||||||
"removable", ((storage->StorageType == ST_RemovableRAM) ? Py_True : Py_False),
|
"removable", ((storage->StorageType == ST_RemovableRAM) ? Py_True : Py_False),
|
||||||
"capacity", storage->MaxCapacity,
|
"capacity", storage->MaxCapacity,
|
||||||
"freespace_bytes", storage->FreeSpaceInBytes,
|
"freespace_bytes", storage->FreeSpaceInBytes,
|
||||||
"freespace_objects", storage->FreeSpaceInObjects,
|
"freespace_objects", storage->FreeSpaceInObjects,
|
||||||
"name", storage->StorageDescription,
|
"name", storage->StorageDescription,
|
||||||
"volume_id", storage->VolumeIdentifier
|
"volume_id", storage->VolumeIdentifier,
|
||||||
|
"rw", (ro) ? Py_False : Py_True
|
||||||
);
|
);
|
||||||
|
|
||||||
if (loc == NULL) return NULL;
|
if (loc == NULL) return NULL;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user