---
name: "mtp_basic"
section: "3"
platform: "linux"
package: "libmtp-doc"
version: "1.1.22-1"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/mtp_basic"
---

# mtp\_basic(3)

basic

## NAME

libmtp - basic

## SYNOPSIS

### Macros

\#define **LIBMTP\_STORAGE\_SORTBY\_NOTSORTED**   0\
 \#define **LIBMTP\_STORAGE\_SORTBY\_FREESPACE**   1\
 \#define **LIBMTP\_STORAGE\_SORTBY\_MAXSPACE**   2\

### Functions

**LIBMTP\_error\_number\_t** **LIBMTP\_Detect\_Raw\_Devices** (**LIBMTP\_raw\_device\_t** \*\*, int \*)\
 int **LIBMTP\_Check\_Specific\_Device** (int busno, int devno)\
 **LIBMTP\_mtpdevice\_t** \* **LIBMTP\_Open\_Raw\_Device** (**LIBMTP\_raw\_device\_t** \*)\
 **LIBMTP\_mtpdevice\_t** \* **LIBMTP\_Open\_Raw\_Device\_Uncached** (**LIBMTP\_raw\_device\_t** \*)\
 **LIBMTP\_mtpdevice\_t** \* **LIBMTP\_Get\_Device** (int)\
 **LIBMTP\_mtpdevice\_t** \* **LIBMTP\_Get\_First\_Device** (void)\
 **LIBMTP\_mtpdevice\_t** \* **LIBMTP\_Get\_Device\_By\_SerialNumber** (char \*)\
 **LIBMTP\_mtpdevice\_t** \* **LIBMTP\_Get\_Device\_By\_ID** (char \*)\
 **LIBMTP\_error\_number\_t** **LIBMTP\_Get\_Connected\_Devices** (**LIBMTP\_mtpdevice\_t** \*\*)\
 uint32\_t **LIBMTP\_Number\_Devices\_In\_List** (**LIBMTP\_mtpdevice\_t** \*)\
 void **LIBMTP\_Release\_Device\_List** (**LIBMTP\_mtpdevice\_t** \*)\
 void **LIBMTP\_Release\_Device** (**LIBMTP\_mtpdevice\_t** \*)\
 void **LIBMTP\_Dump\_Device\_Info** (**LIBMTP\_mtpdevice\_t** \*)\
 int **LIBMTP\_Reset\_Device** (**LIBMTP\_mtpdevice\_t** \*)\
 char \* **LIBMTP\_Get\_Manufacturername** (**LIBMTP\_mtpdevice\_t** \*)\
 char \* **LIBMTP\_Get\_Modelname** (**LIBMTP\_mtpdevice\_t** \*)\
 char \* **LIBMTP\_Get\_Serialnumber** (**LIBMTP\_mtpdevice\_t** \*)\
 char \* **LIBMTP\_Get\_Deviceversion** (**LIBMTP\_mtpdevice\_t** \*)\
 char \* **LIBMTP\_Get\_Friendlyname** (**LIBMTP\_mtpdevice\_t** \*)\
 int **LIBMTP\_Set\_Friendlyname** (**LIBMTP\_mtpdevice\_t** \*, char const \*const)\
 char \* **LIBMTP\_Get\_Syncpartner** (**LIBMTP\_mtpdevice\_t** \*)\
 int **LIBMTP\_Set\_Syncpartner** (**LIBMTP\_mtpdevice\_t** \*, char const \*const)\
 int **LIBMTP\_Get\_Batterylevel** (**LIBMTP\_mtpdevice\_t** \*, uint8\_t \*const, uint8\_t \*const)\
 int **LIBMTP\_Get\_Secure\_Time** (**LIBMTP\_mtpdevice\_t** \*, char \*\*const)\
 int **LIBMTP\_Get\_Device\_Certificate** (**LIBMTP\_mtpdevice\_t** \*, char \*\*const)\
 int **LIBMTP\_Get\_Supported\_Filetypes** (**LIBMTP\_mtpdevice\_t** \*, uint16\_t \*\*const, uint16\_t \*const)\
 int **LIBMTP\_Check\_Capability** (**LIBMTP\_mtpdevice\_t** \*, **LIBMTP\_devicecap\_t**)\
 **LIBMTP\_error\_t** \* **LIBMTP\_Get\_Errorstack** (**LIBMTP\_mtpdevice\_t** \*)\
 void **LIBMTP\_Clear\_Errorstack** (**LIBMTP\_mtpdevice\_t** \*)\
 void **LIBMTP\_Dump\_Errorstack** (**LIBMTP\_mtpdevice\_t** \*)\
 void **LIBMTP\_FreeMemory** (void \*)\
 int **LIBMTP\_Get\_Storage** (**LIBMTP\_mtpdevice\_t** \*, int const)\
 int **LIBMTP\_Format\_Storage** (**LIBMTP\_mtpdevice\_t** \*, **LIBMTP\_devicestorage\_t** \*)\
 char \* **LIBMTP\_Get\_String\_From\_Object** (**LIBMTP\_mtpdevice\_t** \*, uint32\_t const, **LIBMTP\_property\_t** const)\
 uint64\_t **LIBMTP\_Get\_u64\_From\_Object** (**LIBMTP\_mtpdevice\_t** \*, uint32\_t const, **LIBMTP\_property\_t** const, uint64\_t const)\
 uint32\_t **LIBMTP\_Get\_u32\_From\_Object** (**LIBMTP\_mtpdevice\_t** \*, uint32\_t const, **LIBMTP\_property\_t** const, uint32\_t const)\
 uint16\_t **LIBMTP\_Get\_u16\_From\_Object** (**LIBMTP\_mtpdevice\_t** \*, uint32\_t const, **LIBMTP\_property\_t** const, uint16\_t const)\
 uint8\_t **LIBMTP\_Get\_u8\_From\_Object** (**LIBMTP\_mtpdevice\_t** \*, uint32\_t const, **LIBMTP\_property\_t** const, uint8\_t const)\
 int **LIBMTP\_Set\_Object\_String** (**LIBMTP\_mtpdevice\_t** \*, uint32\_t const, **LIBMTP\_property\_t** const, char const \*const)\
 int **LIBMTP\_Set\_Object\_u32** (**LIBMTP\_mtpdevice\_t** \*, uint32\_t const, **LIBMTP\_property\_t** const, uint32\_t const)\
 int **LIBMTP\_Set\_Object\_u16** (**LIBMTP\_mtpdevice\_t** \*, uint32\_t const, **LIBMTP\_property\_t** const, uint16\_t const)\
 int **LIBMTP\_Set\_Object\_u8** (**LIBMTP\_mtpdevice\_t** \*, uint32\_t const, **LIBMTP\_property\_t** const, uint8\_t const)\
 char const \* **LIBMTP\_Get\_Property\_Description** (**LIBMTP\_property\_t** inproperty)\
 int **LIBMTP\_Is\_Property\_Supported** (**LIBMTP\_mtpdevice\_t** \*, **LIBMTP\_property\_t** const, **LIBMTP\_filetype\_t** const)\
 int **LIBMTP\_Get\_Allowed\_Property\_Values** (**LIBMTP\_mtpdevice\_t** \*, **LIBMTP\_property\_t** const, **LIBMTP\_filetype\_t** const, **LIBMTP\_allowed\_values\_t** \*)\
 void **LIBMTP\_destroy\_allowed\_values\_t** (**LIBMTP\_allowed\_values\_t** \*)\

## Detailed Description

## Function Documentation

### int LIBMTP\_Check\_Capability (LIBMTP\_mtpdevice\_t \* device, LIBMTP\_devicecap\_t cap)

This function checks if the device has some specific capabilities, in order to avoid calling APIs that may disturb the device.

**Parameters**

*device* a pointer to the device to check the capability on. \
 *cap* the capability to check.

**Returns**

0 if not supported, any other value means the device has the requested capability.

References **LIBMTP\_DEVICECAP\_CopyObject**, **LIBMTP\_DEVICECAP\_EditObjects**, **LIBMTP\_DEVICECAP\_GetPartialObject**, **LIBMTP\_DEVICECAP\_MoveObject**, **LIBMTP\_DEVICECAP\_SendPartialObject**, and **LIBMTP\_mtpdevice\_struct::params**.

### int LIBMTP\_Check\_Specific\_Device (int busno, int devno)

Checks if a specific device with a certain bus and device number has an MTP type device descriptor.

**Parameters**

*busno* the bus number of the device to check \
 *devno* the device number of the device to check

**Returns**

1 if the device is MTP else 0

### void LIBMTP\_Clear\_Errorstack (LIBMTP\_mtpdevice\_t \* device)

This function clears the error stack of a device and frees any memory used by it. Call this when you're finished with using the errors.

**Parameters**

*device* a pointer to the MTP device to clear the error stack for.

References **LIBMTP\_mtpdevice\_struct::errorstack**.

Referenced by **LIBMTP\_Release\_Device()**.

### void LIBMTP\_destroy\_allowed\_values\_t (LIBMTP\_allowed\_values\_t \* allowed\_vals)

Destroys a LIBMTP\_allowed\_values\_t struct

**Parameters**

*allowed\_vals* the struct to destroy

References **LIBMTP\_allowed\_values\_struct::datatype**, and **LIBMTP\_allowed\_values\_struct::is\_range**.

### LIBMTP\_error\_number\_t LIBMTP\_Detect\_Raw\_Devices (LIBMTP\_raw\_device\_t \*\* devices, int \* numdevs)

Detect the raw MTP device descriptors and return a list of of the devices found.

**Parameters**

*devices* a pointer to a variable that will hold the list of raw devices found. This may be NULL on return if the number of detected devices is zero. The user shall simply `free()` this variable when finished with the raw devices, in order to release memory. \
 *numdevs* a pointer to an integer that will hold the number of devices in the list. This may be 0.

**Returns**

0 if successful, any other value means failure.

**Examples** **detect.c**, **files.c**, **folders.c**, and **tracks.c**.

References **LIBMTP\_raw\_device\_struct::bus\_location**, **LIBMTP\_raw\_device\_struct::device\_entry**, **LIBMTP\_device\_entry\_struct::device\_flags**, **device\_unknown()**, **LIBMTP\_raw\_device\_struct::devnum**, **LIBMTP\_device\_entry\_struct::product**, **LIBMTP\_device\_entry\_struct::product\_id**, **LIBMTP\_device\_entry\_struct::vendor**, and **LIBMTP\_device\_entry\_struct::vendor\_id**.

Referenced by **LIBMTP\_Get\_Connected\_Devices()**, **LIBMTP\_Get\_Device()**, and **LIBMTP\_Get\_Device\_By\_SerialNumber()**.

### void LIBMTP\_Dump\_Device\_Info (LIBMTP\_mtpdevice\_t \* device)

This function dumps out a large chunk of textual information provided from the PTP protocol and additionally some extra MTP-specific information where applicable.

**Parameters**

*device* a pointer to the MTP device to report info from.

References **LIBMTP\_devicestorage\_struct::AccessCapability**, **LIBMTP\_mtpdevice\_struct::default\_album\_folder**, **LIBMTP\_mtpdevice\_struct::default\_music\_folder**, **LIBMTP\_mtpdevice\_struct::default\_organizer\_folder**, **LIBMTP\_mtpdevice\_struct::default\_picture\_folder**, **LIBMTP\_mtpdevice\_struct::default\_playlist\_folder**, **LIBMTP\_mtpdevice\_struct::default\_text\_folder**, **LIBMTP\_mtpdevice\_struct::default\_video\_folder**, **LIBMTP\_mtpdevice\_struct::default\_zencast\_folder**, **LIBMTP\_mtpdevice\_struct::extensions**, **LIBMTP\_devicestorage\_struct::FilesystemType**, **LIBMTP\_devicestorage\_struct::FreeSpaceInBytes**, **LIBMTP\_devicestorage\_struct::FreeSpaceInObjects**, **LIBMTP\_devicestorage\_struct::id**, **LIBMTP\_Get\_Property\_Description()**, **LIBMTP\_device\_extension\_struct::major**, **LIBMTP\_devicestorage\_struct::MaxCapacity**, **LIBMTP\_device\_extension\_struct::minor**, **LIBMTP\_device\_extension\_struct::name**, **LIBMTP\_device\_extension\_struct::next**, **LIBMTP\_devicestorage\_struct::next**, **LIBMTP\_mtpdevice\_struct::object\_bitsize**, **LIBMTP\_mtpdevice\_struct::params**, **LIBMTP\_mtpdevice\_struct::storage**, **LIBMTP\_devicestorage\_struct::StorageDescription**, **LIBMTP\_devicestorage\_struct::StorageType**, **LIBMTP\_mtpdevice\_struct::usbinfo**, and **LIBMTP\_devicestorage\_struct::VolumeIdentifier**.

### void LIBMTP\_Dump\_Errorstack (LIBMTP\_mtpdevice\_t \* device)

This function dumps the error stack to `stderr`. (You still have to clear the stack though.)

**Parameters**

*device* a pointer to the MTP device to dump the error stack for.

References **LIBMTP\_mtpdevice\_struct::errorstack**.

### int LIBMTP\_Format\_Storage (LIBMTP\_mtpdevice\_t \* device, LIBMTP\_devicestorage\_t \* storage)

Formats device storage (if the device supports the operation). WARNING: This WILL delete all data from the device. Make sure you've got confirmation from the user BEFORE you call this function.

**Parameters**

*device* a pointer to the device containing the storage to format. \
 *storage* the actual storage to format.

**Returns**

0 on success, any other value means failure.

References **LIBMTP\_devicestorage\_struct::id**, and **LIBMTP\_mtpdevice\_struct::params**.

### void LIBMTP\_FreeMemory (void \* mem)

Free memory allocated by libmtp. Is doing the same as libc free(mem) in most cases. @mem pointer to allocated memory.

### int LIBMTP\_Get\_Allowed\_Property\_Values (LIBMTP\_mtpdevice\_t \* device, LIBMTP\_property\_t const property, LIBMTP\_filetype\_t const filetype, LIBMTP\_allowed\_values\_t \* allowed\_vals)

Gets the allowed values (range or enum) for a property

**Parameters**

*device* a pointer to an MTP device \
 *property* the property to query \
 *filetype* the filetype of the object you want to set values for \
 *allowed\_vals* pointer to a LIBMTP\_allowed\_values\_t struct to receive the allowed values. Call LIBMTP\_destroy\_allowed\_values\_t on this on successful completion.

**Returns**

0 on success, any other value means failure

References **LIBMTP\_allowed\_values\_struct::datatype**, **LIBMTP\_allowed\_values\_struct::is\_range**, **LIBMTP\_allowed\_values\_struct::num\_entries**, and **LIBMTP\_mtpdevice\_struct::params**.

### int LIBMTP\_Get\_Batterylevel (LIBMTP\_mtpdevice\_t \* device, uint8\_t \*const maximum\_level, uint8\_t \*const current\_level)

This function retrieves the current battery level on the device.

**Parameters**

*device* a pointer to the device to get the battery level for. \
 *maximum\_level* a pointer to a variable that will hold the maximum level of the battery if the call was successful. \
 *current\_level* a pointer to a variable that will hold the current level of the battery if the call was successful. A value of 0 means that the device is on external power.

**Returns**

0 if the storage info was successfully retrieved, any other means failure. A typical cause of failure is that the device does not support the battery level property.

References **LIBMTP\_mtpdevice\_struct::maximum\_battery\_level**, **LIBMTP\_mtpdevice\_struct::params**, and **LIBMTP\_mtpdevice\_struct::usbinfo**.

### LIBMTP\_error\_number\_t LIBMTP\_Get\_Connected\_Devices (LIBMTP\_mtpdevice\_t \*\* device\_list)

Get the first connected MTP device node in the linked list of devices. Currently this only provides access to USB devices

**Parameters**

*device\_list* A list of devices ready to be used by the caller. You need to know how many there are.

**Returns**

Any error information gathered from device connections

**See also**

**LIBMTP\_Number\_Devices\_In\_List()**

References **LIBMTP\_Detect\_Raw\_Devices()**.

### LIBMTP\_mtpdevice\_t \* LIBMTP\_Get\_Device (int device\_nr)

Get connected MTP device by list position.

**Returns**

a device pointer.

**See also**

**LIBMTP\_Get\_Connected\_Devices()**

References **LIBMTP\_Detect\_Raw\_Devices()**.

Referenced by **LIBMTP\_Get\_Device\_By\_ID()**, and **LIBMTP\_Get\_First\_Device()**.

### LIBMTP\_mtpdevice\_t \* LIBMTP\_Get\_Device\_By\_ID (char \* device\_id)

Get connected MTP device by list position or serial number.

**Returns**

a device pointer.

**See also**

**LIBMTP\_Get\_Connected\_Devices()**

References **LIBMTP\_Get\_Device()**, and **LIBMTP\_Get\_Device\_By\_SerialNumber()**.

### LIBMTP\_mtpdevice\_t \* LIBMTP\_Get\_Device\_By\_SerialNumber (char \* serial\_number)

Get connected MTP device by serial number.

**Returns**

a device pointer.

**See also**

**LIBMTP\_Get\_Connected\_Devices()**

References **LIBMTP\_Detect\_Raw\_Devices()**, **LIBMTP\_Release\_Device()**, and **LIBMTP\_mtpdevice\_struct::params**.

Referenced by **LIBMTP\_Get\_Device\_By\_ID()**.

### int LIBMTP\_Get\_Device\_Certificate (LIBMTP\_mtpdevice\_t \* device, char \*\*const devcert)

This function returns the device (public key) certificate as an XML document string from the device.

**Parameters**

*device* a pointer to the device to get the device certificate for. \
 *devcert* the device certificate as an XML string or NULL if the call failed or the device certificate property is not supported. This string must be `free()`:ed by the caller after use.

**Returns**

0 on success, any other value means failure.

### char \* LIBMTP\_Get\_Deviceversion (LIBMTP\_mtpdevice\_t \* device)

This retrieves the device version (hardware and firmware version) of an MTP device.

**Parameters**

*device* a pointer to the device to get the device version for.

**Returns**

a newly allocated UTF-8 string representing the device version. The string must be freed by the caller after use. If the call was unsuccessful this will contain NULL.

References **LIBMTP\_mtpdevice\_struct::params**.

### LIBMTP\_error\_t \* LIBMTP\_Get\_Errorstack (LIBMTP\_mtpdevice\_t \* device)

This returns the error stack for a device in case you need to either reference the error numbers (e.g. when creating multilingual apps with multiple-language text representations for each error number) or when you need to build a multi-line error text widget or something like that. You need to call the `LIBMTP_Clear_Errorstack` to clear it when you're finished with it.

**Parameters**

*device* a pointer to the MTP device to get the error stack for.

**Returns**

the error stack or NULL if there are no errors on the stack.

**See also**

**LIBMTP\_Clear\_Errorstack()**

**LIBMTP\_Dump\_Errorstack()**

References **LIBMTP\_mtpdevice\_struct::errorstack**.

### LIBMTP\_mtpdevice\_t \* LIBMTP\_Get\_First\_Device (void)

Get the first (as in 'first in the list of') connected MTP device.

**Returns**

a device pointer.

**See also**

**LIBMTP\_Get\_Connected\_Devices()**

References **LIBMTP\_Get\_Device()**.

### char \* LIBMTP\_Get\_Friendlyname (LIBMTP\_mtpdevice\_t \* device)

This retrieves the 'friendly name' of an MTP device. Usually this is simply the name of the owner or something like 'John Doe's Digital Audio Player'. This property should be supported by all MTP devices.

**Parameters**

*device* a pointer to the device to get the friendly name for.

**Returns**

a newly allocated UTF-8 string representing the friendly name. The string must be freed by the caller after use.

**See also**

**LIBMTP\_Set\_Friendlyname()**

References **LIBMTP\_mtpdevice\_struct::params**.

### char \* LIBMTP\_Get\_Manufacturername (LIBMTP\_mtpdevice\_t \* device)

This retrieves the manufacturer name of an MTP device.

**Parameters**

*device* a pointer to the device to get the manufacturer name for.

**Returns**

a newly allocated UTF-8 string representing the manufacturer name. The string must be freed by the caller after use. If the call was unsuccessful this will contain NULL.

References **LIBMTP\_mtpdevice\_struct::params**.

### char \* LIBMTP\_Get\_Modelname (LIBMTP\_mtpdevice\_t \* device)

This retrieves the model name (often equal to product name) of an MTP device.

**Parameters**

*device* a pointer to the device to get the model name for.

**Returns**

a newly allocated UTF-8 string representing the model name. The string must be freed by the caller after use. If the call was unsuccessful this will contain NULL.

References **LIBMTP\_mtpdevice\_struct::params**.

### char const \* LIBMTP\_Get\_Property\_Description (LIBMTP\_property\_t inproperty)

This helper function returns a textual description for a libmtp property to be used in dialog boxes etc.

**Parameters**

*inproperty* the libmtp internal property to get a description for.

**Returns**

a string representing the filetype, this must **NOT** be free():ed by the caller!

References **propertymap\_struct::description**, and **propertymap\_struct::id**.

Referenced by **LIBMTP\_Dump\_Device\_Info()**.

### int LIBMTP\_Get\_Secure\_Time (LIBMTP\_mtpdevice\_t \* device, char \*\*const sectime)

This function returns the secure time as an XML document string from the device.

**Parameters**

*device* a pointer to the device to get the secure time for. \
 *sectime* the secure time string as an XML document or NULL if the call failed or the secure time property is not supported. This string must be `free()`:ed by the caller after use.

**Returns**

0 on success, any other value means failure.

### char \* LIBMTP\_Get\_Serialnumber (LIBMTP\_mtpdevice\_t \* device)

This retrieves the serial number of an MTP device.

**Parameters**

*device* a pointer to the device to get the serial number for.

**Returns**

a newly allocated UTF-8 string representing the serial number. The string must be freed by the caller after use. If the call was unsuccessful this will contain NULL.

References **LIBMTP\_mtpdevice\_struct::params**.

### int LIBMTP\_Get\_Storage (LIBMTP\_mtpdevice\_t \* device, int const sortby)

This function updates all the storage id's of a device and their properties, then creates a linked list and puts the list head into the device struct. It also optionally sorts this list. If you want to display storage information in your application you should call this function, then dereference the device struct (`device->storage`) to get out information on the storage.

You need to call this every time you want to update the `device->storage` list, for example anytime you need to check available storage somewhere.

**WARNING:** since this list is dynamically updated, do not reference its fields in external applications by pointer! E.g do not put a reference to any `char *` field. instead `strncpy()` it!

**Parameters**

*device* a pointer to the device to get the storage for. \
 *sortby* an integer that determines the sorting of the storage list. Valid sort methods are defined in **libmtp.h** with beginning with LIBMTP\_STORAGE\_SORTBY\_. 0 or LIBMTP\_STORAGE\_SORTBY\_NOTSORTED to not sort.

**Returns**

0 on success, 1 success but only with storage id's, storage properities could not be retrieved and -1 means failure.

References **LIBMTP\_devicestorage\_struct::AccessCapability**, **LIBMTP\_devicestorage\_struct::FilesystemType**, **LIBMTP\_devicestorage\_struct::FreeSpaceInBytes**, **LIBMTP\_devicestorage\_struct::FreeSpaceInObjects**, **LIBMTP\_devicestorage\_struct::id**, **LIBMTP\_devicestorage\_struct::MaxCapacity**, **LIBMTP\_devicestorage\_struct::next**, **LIBMTP\_mtpdevice\_struct::params**, **LIBMTP\_devicestorage\_struct::prev**, **LIBMTP\_mtpdevice\_struct::storage**, **LIBMTP\_devicestorage\_struct::StorageDescription**, **LIBMTP\_devicestorage\_struct::StorageType**, and **LIBMTP\_devicestorage\_struct::VolumeIdentifier**.

Referenced by **LIBMTP\_Open\_Raw\_Device\_Uncached()**.

### char \* LIBMTP\_Get\_String\_From\_Object (LIBMTP\_mtpdevice\_t \* device, uint32\_t const object\_id, LIBMTP\_property\_t const attribute\_id)

Get/set arbitrary properties. These do not update the cache; should only be used on properties not stored in structs

Retrieves a string from an object

**Parameters**

*device* a pointer to an MTP device. \
 *object\_id* Object reference \
 *attribute\_id* MTP attribute ID

**Returns**

valid string or NULL on failure. The returned string must bee `free()`:ed by the caller after use.

### int LIBMTP\_Get\_Supported\_Filetypes (LIBMTP\_mtpdevice\_t \* device, uint16\_t \*\*const filetypes, uint16\_t \*const length)

This function retrieves a list of supported file types, i.e. the file types that this device claims it supports, e.g. audio file types that the device can play etc. This list is mitigated to include the file types that libmtp can handle, i.e. it will not list filetypes that libmtp will handle internally like playlists and folders.

**Parameters**

*device* a pointer to the device to get the filetype capabilities for. \
 *filetypes* a pointer to a pointer that will hold the list of supported filetypes if the call was successful. This list must be `free()`:ed by the caller after use. \
 *length* a pointer to a variable that will hold the length of the list of supported filetypes if the call was successful.

**Returns**

0 on success, any other value means failure.

**See also**

**LIBMTP\_Get\_Filetype\_Description()**

References **LIBMTP\_mtpdevice\_struct::params**, and **LIBMTP\_mtpdevice\_struct::usbinfo**.

### char \* LIBMTP\_Get\_Syncpartner (LIBMTP\_mtpdevice\_t \* device)

This retrieves the synchronization partner of an MTP device. This property should be supported by all MTP devices.

**Parameters**

*device* a pointer to the device to get the sync partner for.

**Returns**

a newly allocated UTF-8 string representing the synchronization partner. The string must be freed by the caller after use.

**See also**

**LIBMTP\_Set\_Syncpartner()**

References **LIBMTP\_mtpdevice\_struct::params**.

### uint16\_t LIBMTP\_Get\_u16\_From\_Object (LIBMTP\_mtpdevice\_t \* device, uint32\_t const object\_id, LIBMTP\_property\_t const attribute\_id, uint16\_t const value\_default)

Retrieves an unsigned 16-bit integer from an object attribute

**Parameters**

*device* a pointer to an MTP device. \
 *object\_id* Object reference \
 *attribute\_id* MTP attribute ID \
 *value\_default* Default value to return on failure

**Returns**

a value

### uint32\_t LIBMTP\_Get\_u32\_From\_Object (LIBMTP\_mtpdevice\_t \* device, uint32\_t const object\_id, LIBMTP\_property\_t const attribute\_id, uint32\_t const value\_default)

Retrieves an unsigned 32-bit integer from an object attribute

**Parameters**

*device* a pointer to an MTP device. \
 *object\_id* Object reference \
 *attribute\_id* MTP attribute ID \
 *value\_default* Default value to return on failure

**Returns**

the value

### uint64\_t LIBMTP\_Get\_u64\_From\_Object (LIBMTP\_mtpdevice\_t \* device, uint32\_t const object\_id, LIBMTP\_property\_t const attribute\_id, uint64\_t const value\_default)

Retrieves an unsigned 64-bit integer from an object attribute

**Parameters**

*device* a pointer to an MTP device. \
 *object\_id* Object reference \
 *attribute\_id* MTP attribute ID \
 *value\_default* Default value to return on failure

**Returns**

the value

### uint8\_t LIBMTP\_Get\_u8\_From\_Object (LIBMTP\_mtpdevice\_t \* device, uint32\_t const object\_id, LIBMTP\_property\_t const attribute\_id, uint8\_t const value\_default)

Retrieves an unsigned 8-bit integer from an object attribute

**Parameters**

*device* a pointer to an MTP device. \
 *object\_id* Object reference \
 *attribute\_id* MTP attribute ID \
 *value\_default* Default value to return on failure

**Returns**

a value

### int LIBMTP\_Is\_Property\_Supported (LIBMTP\_mtpdevice\_t \* device, LIBMTP\_property\_t const property, LIBMTP\_filetype\_t const filetype)

Determine if a property is supported for a given file type

**Parameters**

*device* a pointer to an MTP device \
 *property* the property to query \
 *filetype* the filetype of the object you want to set values for

**Returns**

0 if not supported, positive if supported, negative on error

References **LIBMTP\_mtpdevice\_struct::params**.

### uint32\_t LIBMTP\_Number\_Devices\_In\_List (LIBMTP\_mtpdevice\_t \* device\_list)

Get the number of devices that are available in the listed device list

**Parameters**

*device\_list* Pointer to a linked list of devices

**Returns**

Number of devices in the device list device\_list

**See also**

**LIBMTP\_Get\_Connected\_Devices()**

References **LIBMTP\_mtpdevice\_struct::next**.

### LIBMTP\_mtpdevice\_t \* LIBMTP\_Open\_Raw\_Device\_Uncached (LIBMTP\_raw\_device\_t \* rawdevice)

This function opens a device from a raw device. It is the preferred way to access devices in the new interface where several devices can come and go as the library is working on a certain device.

**Parameters**

*rawdevice* the raw device to open a 'real' device for.

**Returns**

an open device.

References **LIBMTP\_raw\_device\_struct::bus\_location**, **LIBMTP\_mtpdevice\_struct::cached**, **LIBMTP\_mtpdevice\_struct::default\_album\_folder**, **LIBMTP\_mtpdevice\_struct::default\_music\_folder**, **LIBMTP\_mtpdevice\_struct::default\_organizer\_folder**, **LIBMTP\_mtpdevice\_struct::default\_picture\_folder**, **LIBMTP\_mtpdevice\_struct::default\_playlist\_folder**, **LIBMTP\_mtpdevice\_struct::default\_text\_folder**, **LIBMTP\_mtpdevice\_struct::default\_video\_folder**, **LIBMTP\_mtpdevice\_struct::default\_zencast\_folder**, **LIBMTP\_raw\_device\_struct::device\_entry**, **LIBMTP\_device\_entry\_struct::device\_flags**, **DEVICE\_FLAGS\_ANDROID\_BUGS**, **DEVICE\_FLAGS\_ARICENT\_BUGS**, **DEVICE\_FLAGS\_SONY\_NWZ\_BUGS**, **LIBMTP\_raw\_device\_struct::devnum**, **LIBMTP\_mtpdevice\_struct::errorstack**, **LIBMTP\_mtpdevice\_struct::extensions**, **LIBMTP\_Get\_Storage()**, **LIBMTP\_mtpdevice\_struct::maximum\_battery\_level**, **LIBMTP\_device\_extension\_struct::name**, **LIBMTP\_device\_extension\_struct::next**, **LIBMTP\_mtpdevice\_struct::object\_bitsize**, **LIBMTP\_mtpdevice\_struct::params**, **\_PTP\_USB::rawdevice**, **LIBMTP\_mtpdevice\_struct::storage**, and **LIBMTP\_mtpdevice\_struct::usbinfo**.

### void LIBMTP\_Release\_Device (LIBMTP\_mtpdevice\_t \* device)

This closes and releases an allocated MTP device.

**Parameters**

*device* a pointer to the MTP device to release.

References **LIBMTP\_mtpdevice\_struct::extensions**, **LIBMTP\_Clear\_Errorstack()**, **LIBMTP\_device\_extension\_struct::name**, **LIBMTP\_device\_extension\_struct::next**, **LIBMTP\_mtpdevice\_struct::params**, and **LIBMTP\_mtpdevice\_struct::usbinfo**.

Referenced by **LIBMTP\_Get\_Device\_By\_SerialNumber()**, and **LIBMTP\_Release\_Device\_List()**.

### void LIBMTP\_Release\_Device\_List (LIBMTP\_mtpdevice\_t \* device)

This closes and releases an allocated MTP device.

**Parameters**

*device* a pointer to the MTP device to release.

References **LIBMTP\_Release\_Device()**, **LIBMTP\_Release\_Device\_List()**, and **LIBMTP\_mtpdevice\_struct::next**.

Referenced by **LIBMTP\_Release\_Device\_List()**.

### int LIBMTP\_Reset\_Device (LIBMTP\_mtpdevice\_t \* device)

This resets a device in case it supports the `PTP_OC_ResetDevice` operation code (0x1010).

**Parameters**

*device* a pointer to the device to reset.

**Returns**

0 on success, any other value means failure.

References **LIBMTP\_mtpdevice\_struct::params**.

### int LIBMTP\_Set\_Friendlyname (LIBMTP\_mtpdevice\_t \* device, char const \*const friendlyname)

Sets the 'friendly name' of an MTP device.

**Parameters**

*device* a pointer to the device to set the friendly name for. \
 *friendlyname* the new friendly name for the device.

**Returns**

0 on success, any other value means failure.

**See also**

**LIBMTP\_Get\_Friendlyname()**

References **LIBMTP\_mtpdevice\_struct::params**.

### int LIBMTP\_Set\_Object\_String (LIBMTP\_mtpdevice\_t \* device, uint32\_t const object\_id, LIBMTP\_property\_t const attribute\_id, char const \*const string)

Sets an object attribute from a string

**Parameters**

*device* a pointer to an MTP device. \
 *object\_id* Object reference \
 *attribute\_id* MTP attribute ID \
 *string* string value to set

**Returns**

0 on success, any other value means failure

### int LIBMTP\_Set\_Object\_u16 (LIBMTP\_mtpdevice\_t \* device, uint32\_t const object\_id, LIBMTP\_property\_t const attribute\_id, uint16\_t const value)

Sets an object attribute from an unsigned 16-bit integer

**Parameters**

*device* a pointer to an MTP device. \
 *object\_id* Object reference \
 *attribute\_id* MTP attribute ID \
 *value* 16-bit unsigned integer to set

**Returns**

0 on success, any other value means failure

### int LIBMTP\_Set\_Object\_u32 (LIBMTP\_mtpdevice\_t \* device, uint32\_t const object\_id, LIBMTP\_property\_t const attribute\_id, uint32\_t const value)

Sets an object attribute from an unsigned 32-bit integer

**Parameters**

*device* a pointer to an MTP device. \
 *object\_id* Object reference \
 *attribute\_id* MTP attribute ID \
 *value* 32-bit unsigned integer to set

**Returns**

0 on success, any other value means failure

### int LIBMTP\_Set\_Object\_u8 (LIBMTP\_mtpdevice\_t \* device, uint32\_t const object\_id, LIBMTP\_property\_t const attribute\_id, uint8\_t const value)

Sets an object attribute from an unsigned 8-bit integer

**Parameters**

*device* a pointer to an MTP device. \
 *object\_id* Object reference \
 *attribute\_id* MTP attribute ID \
 *value* 8-bit unsigned integer to set

**Returns**

0 on success, any other value means failure

### int LIBMTP\_Set\_Syncpartner (LIBMTP\_mtpdevice\_t \* device, char const \*const syncpartner)

Sets the synchronization partner of an MTP device. Note that we have no idea what the effect of setting this to 'foobar' may be. But the general idea seems to be to tell which program shall synchronize with this device and tell others to leave it alone.

**Parameters**

*device* a pointer to the device to set the sync partner for. \
 *syncpartner* the new synchronization partner for the device.

**Returns**

0 on success, any other value means failure.

**See also**

**LIBMTP\_Get\_Syncpartner()**

References **LIBMTP\_mtpdevice\_struct::params**.

## Author

Generated automatically by Doxygen for libmtp from the source code.
