5 Star 0 Fork 1

OpenHarmony-SIG/third_party_libmtp

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
LGPL-2.1
Building and Installing
-----------------------

See the "INSTALL" file.


Initiator and Responder
-----------------------

libmtp implements an MTP initiator, which means it initiate
MTP sessions with devices. The devices responding are known
as MTP responders. libmtp runs on something with a USB host
controller interface, using libusb to access the host
controller.

If you're more interested in the MTP responders, gadgets like
MP3 players, mobile phones etc, look into:
- MeeGo:s Buteo Sync:
  https://github.com/nemomobile/buteo-mtp
  https://wiki.merproject.org/wiki/Buteo/MTP
- Android has an MTP responder implementation:
  https://android.googlesource.com/platform/frameworks/base/+/master/media/jni/
- Ubuntu/Ricardo Salveti has mtp-server and libmtp-server going:
  https://code.launchpad.net/~phablet-team/mtp/trunk
  https://bazaar.launchpad.net/~phablet-team/mtp/trunk/files

Heritage
--------

libmtp is based on several ancestors:

* libptp2 by Mariusz Woloszyn was the starting point used
  by Richard A. Low for the initial starter port. You can
  find it at https://libptp.sourceforge.net/

* libgphoto2 by Mariusz Woloszyn and Marcus Meissner was
  used at a later stage since it was (is) more actively
  maintained. libmtp tracks the PTP implementation in
  libgphoto2 and considers it an upstream project. We will
  try to submit anything generally useful back to libgphoto2
  and not make double efforts. In practice this means we
  use ptp.c, ptp.h and ptp-pack.c verbatim from the libgphoto2
  source code. If you need to change things in these files,
  make sure it is so general that libgphoto2 will want to
  merge it to their codebase too. You find libgphoto2 as part
  of gPhoto: https://gphoto.sourceforge.net/

* libnjb was a project that Richard and Linus were working
  on before libmtp. When Linus took Richards initial port
  and made an generic C API he re-used the philosophy and
  much code from libnjb. Many of the sample programs are for
  example taken quite literally from libnjb. You find it here:
  https://libnjb.sourceforge.net/


Contacting and Contributing
---------------------------

See the project page at https://libmtp.sourceforge.net/
We always need your help. There is a mailinglist and a
bug report system there.

You can also file github issues at https://github.com/libmtp/libmtp

People who want to discuss MTP devices in fora seem to
hang out on the forums at AnythingbutiPod:
https://www.anythingbutipod.com/forum/


Compiling programs for libmtp
-----------------------------

libmtp has support for the pkg-config script by adding a libmtp.pc
entry in $(prefix)/lib/pkgconfig. To compile a libmtp program,
"just" write:

gcc -o foo `pkg-config --cflags --libs libmtp` foo.c

This also simplifies compilation using autoconf and pkg-config: just
write e.g.

PKG_CHECK_MODULES(MTP, libmtp)
AC_SUBST(MTP_CFLAGS)
AC_SUBST(MTP_LIBS)

To have libmtp LIBS and CFLAGS defined. Needless to say, this will
only work if you have pkgconfig installed on your system, but most
people have nowadays.

If your library is installed in e.g. /usr/local you may have to tell
this to pkgconfig by setting the PKG_CONFIG_PATH thus:

export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig


Documentation
-------------

Read the API documentation that can be generated with doxygen.
It will be output in doc/html if you have Doxygen properly
installed. (It will not be created unless you have Doxygen!)

For information about the Media Transfer Protocol, see:
https://en.wikipedia.org/wiki/Media_Transfer_Protocol

The official 1.0 specification for MTP was released by the
USB Implementers Forum in may, 2008. Prior to this, only a
proprietary Microsoft version was available, and quite a few
devices out there still use some aspects of the Microsoft
version, which deviates from the specified standard. You can
find the official specification here:
https://www.usb.org/developers/devclass_docs/MTP_1.0.zip


The Examples
------------

In the subdirectory "examples" you find a number of
command-line tools, illustrating the use of libmtp in very
simple terms.

Please do not complain about the usability or documentation
of these examples, they look like they do for two reasons:

1. They are examples, not tools. If they were intended for
   day-to-day usage by commandline freaks, I would have
   called them "tools" not "examples".

2. The MTP usage paradigm is that a daemon should hook
   the device upon connection, and that it should be
   released by unplugging. GUI tools utilizing HAL (hald)
   and D-Bus do this much better than any commandline
   program ever can. (See below on bugs.) Specificationwise
   this is a bug, however it is present in many, many
   devices.

That said, if you want to pick up and maintain the examples,
please volunteer.


FAQ: Common Problems
--------------------

Some MTP devices have strange pecularities. We try to work around
these whenever we can, sometimes we cannot work around it or we
cannot test your solution.

* Android locked screen: some devices just report zero files
  and no storages when the device screen is locked, it looks like
  so:

  mtp-detect
  Device 0 (VID=04e8 and PID=6860) is a Samsung Galaxy models (MTP).
  Attempting to connect device(s)
  Error 1: Get Storage information failed.
  Device: SHV-E210K
  LIBMTP_Get_Storage(): No data available
  OK.

  This is probably so as not to allow the MTP access to be used
  as a "backdoor" into the device. Unlock the device before listing
  files, set the autolock to some large value or disabled if it
  disturbs you, you are causing this to yourself, or should we say
  that your vendor is prioritizing security and privacy over
  ease-of-use. (You may talk to your vendor about this.)

* mtp-* tools doesn't work because someone else is already hogging
  the device

  This is a common problem, the most common case could be that
  gphoto2 (which can also talk PTP/MTP) is taking over the device
  as soon as it's plugged in. Some distributions are configured that
  way. Counter it like this:

  gvfs-mount -s gphoto2

  Then re-attach the device.

  Sometimes some gvfs daemons are running on the
  system and hogging the device, try stopping them
  with something like these commands:

  killall gvfs-mtp-volume-monitor
  killall gvfs-gphoto2-volume-monitor

  Then plug in the device and issue "mtp-detect" to figure out if
  this may be the case.

* Generic MTP/PTP disconnect misbehaviour: we have noticed that
  Windows Media Player apparently never close the session to an MTP
  device. There is a daemon in Windows that "hooks" the device
  by opening a PTP session to any MTP device, whenever it is
  plugged in. This daemon proxies any subsequent transactions
  to/from the device and will never close the session, thus
  Windows simply does not close sessions at all.

  For example this means that a device may work the first time
  you run some command-line example like "mtp-detect" while
  subsequent runs fail.

  Typical sign of this illness: broken pipes on closing sessions,
  on the main transfer pipes(s) or the interrupt pipe:

    Closing session
    usb_clear_halt() on INTERRUPT endpoint: Broken pipe
    OK.

  This means that device manufacturers doesn't notice any problems
  with devices that do not correctly handle closing PTP/MTP
  sessions, since Windows never do it. The proper way of closing
  a session in Windows is to unplug the device, simply put.

  Since libmtp actually tries to close sessions, some devices
  may fail since the close session functionality has never been
  properly tested, and "it works with Windows" is sort of the
  testing criteria at some companies.

  You can get Windows-like behaviour on Linux by running a udev-aware
  libmtp GUI client like Rhythmbox or Gnomad2, which will "hook"
  the device when you plug it in, and "release" it if you unplug
  it, and you start/end you transfer sessions by plugging/unplugging
  the USB cable.

  The "Unix way" of running small programs that open the device,
  do something, then close the device, isn't really working with
  such devices and you cannot expect to have command line tools
  like the mtp examples work with them. You could implement new
  example programs that just call to a mediating daemon like the
  Windows MTP stack does. (And change all programs using libmtp
  directly today.)

  If this bug in your device annoys you, contact your device
  manufacturer and ask them to test their product with some libmtp
  program.

* Samsung Android 2.3.x devices: these have a special MTP stack
  with some specific bugs that we have maybe nailed down now.
  It suffers from an "immediate connect" syndrome, i.e. you have
  to connect to the device within 7 seconds of plugging in, or it
  will go numb. This also goes for command-line activity with
  the example programs, so this device is better used with a
  GUI tool like Rhythmbox, gnomad2...

* Generic USB misbehaviour: some devices behave badly under MTP
  and USB mass storage alike, even down to the lowest layers
  of USB. You can always discuss such issues at the linux-usb
  mailing list if you're using Linux:
  https://www.linux-usb.org/mailing.html

  If you have a problem specific to USB mass storage mode, there
  is a list of strange behaving devices in the Linux kernel:
  https://lxr.linux.no/linux/drivers/usb/storage/unusual_devs.h
  You can discuss this too on the mentioned list, for understanding
  the quirks, see:
  https://www2.one-eyed-alien.net/~mdharm/linux-usb/target_offenses.txt

* Generic certificate misbehaviour. All devices are actually
  required to support a device certificate to be able to
  encrypt Windows Media (WMA/WMV) files. However there are
  obviously a lot of devices out there which doesn't support
  this at all but instead crash. Typical printout:

  Error 2: PTP Layer error 02ff: get_device_unicode_property(): failed
  to get unicode property.

  This should only affect "mtp-detect", there is no other
  application currently retrieveing the certificate (not that we
  know anyway).

* Kernel bug on Linux. Linux 2.6.16 is generally speaking required
  to use any MTP device under USB 2.0. This is because the EHCI
  driver previously did not support zero-length writes to endpoints.
  It should work in most cases however, or if you connect it
  to an UHCI/OHCI port instead (yielding lower speed). But
  please just use a recent kernel.

* Zen models AVI file seeking problem: the Zens cannot parse the
  files for the runlength metadata. Do not transfer file with e.g.
  mtp-sendfile, use mtp-sendtr and set the length of the track to
  the appropriate number of seconds and it will work. In graphical
  clients, use a "track transfer" function to send these AVI files,
  the Zens need the metadata associated with tracks to play back
  movies properly. Movies are considered "tracks" in the MTP world.

* Some devices that disregard the metadata sent with the MTP
  commands will parse the files for e.g. ID3 metadata. Some still
  of these devices expect only ID3v2.3 metadata and will fail with
  a modern ID3v2,4 tag writer, like many of those found in Linux
  applications. Windows Media Player use ID3v2.3 only, so many
  manufacturers only test this version.

* The Zen Vision:M (possibly more Creative Zens) has a firmware bug
  that makes it drop the last two characters off a playlist name.
  It is fixed in later firmware.

* For Creative Technology devices, there are hard limits on how
  many files can be put onto the device. For a 30 GiB device (like
  the Zen Xtra) the limit is 6000, for a 60 GiB device the limit
  is 15000 files. For further Creative pecularities, see the
  FAQ sections at www.nomadness.net.

* Sandisk sansa c150 and probably several other Sandisk devices
  (and possibly devices from other manufacturers) have a dual
  mode with MTP and USB mass storage. The device will initially
  claim to be mass storage so udev will capture is and make the
  use of MTP mode impossible. One way of avoiding it could be to
  be to blacklist the "usb-storage" module in
  /etc/modprobe.c/blacklist with a row like this:
  "blacklist usb-storage". Some have even removed the
  "usb-storage.ko" (kernel module file) to avoid loading.

* Sandisk Sansa Fuze has three modes: auto, MTP or mass storage
  (MSC). Please set it to MTP to avoid problems with libmtp.

* The iriver devices (possibly all of them) cannot handle the
  enhanced GetObjectPropList MTP command (0x9805) properly. So
  they have been banned from using it.

* iriver devices have problems with older versions of libmtp and
  with new devices libmtp does not know of as of yet, since it
  has an oldstyle USB device controller that cannot handle zero
  writes. (Register your device with us!) All their devices are
  likely to need a special device flag in the src/libusb-glue.c
  database.

* The Samsung Yepp T9 has several strange characteristics, some
  that we've managed to work around. (For example it will return
  multiple PTP packages in a single transaction.)

* The early firmware for Philips HDD players is known to be
  problematic. Please upgrade to as new firmware as you can get.
  (Yes this requires some kind of Windows Installation I think.)

* Philips HDD 1630/16 or 1630/17 etc may lock themselves up,
  turning inresponsive due to internal corruption. This typically
  gives an error in opening the PTP session. Apparently you can
  do a "repair" with the firmware utility (Windows only) which
  will often fix this problem and make the device responsive
  again.

* Some devices that implement GetObjectPropList (0x9805) will
  not return the entire object list if you request a list for object
  0xffffffffu. (But they should.) So they may need the special
  DEVICE_FLAG_BROKEN_MTPGETOBJPROPLIST_ALL.

* Some (smaller) subset of devices cannot even get all the
  properties for a single object in one go, these need the
  DEVICE_FLAG_BROKEN_MTPGETOBJPROPLIST. Currently only the
  iriver devices seem to have this bug.

* The Toshiba Gigabeat S (and probably its sibling the
  Microsoft Zune and other Toshiba devices) will only display
  album information tags for a song in case there is also
  an abstract album (created with the album interface) with
  the exact same name.

* The Zen Vision:M has an older firmware which is very corrupt,
  it is incompatible with the Linux USB stack altogether. The
  kernel dmesg will look something like this, and you have to
  upgrade the firmware using Windows:
  usb 4-5: new high speed USB device using ehci_hcd and address 5
  usb 4-5: configuration #1 chosen from 1 choice
  usb 4-5: can't set config #1, error -110

* The Sirus Stiletto does not seem to allow you to copy any files
  off the device. This may be someone's idea of copy protection.

* The Samsung P2 assigns parent folder ID 0 to all unknown file
  types.(i.e. moves them to the root folder)

* The Sandisk Sansa Clip+ needs a firmware upgrade in earlier
  versions in order to work properly.


New Devices
-----------

If you happen upon a device which libmtp claims it cannot
autodetect, please submit the vendor ID and device ID
(these can be obtained from the "lsusb" and "lsusb -n"
commands run as root) as a bug, patch or feature request
on the Sourceforge bug tracker at our homepage. If it
gives a sensible  output from "mtp-detect" then please attach
the result as well as it teach us some stuff about your
device. If you've done some additional hacking, join our
mailinglist and post your experiences there.

If you want to be able to hack some more and you're not
afraid of C hacking, add an entry for your device's
vendor/product ID and a descriptive string to the database
in the file src/music-players.h.

If you want to poke around to see if your device has some
special pecularities, you can test some special device
flags (defined in src/device-flags.h) by inserting them
together with your device entry in src/music-players.h.
Flags can be tested in isolation or catenated with "|"
(binary OR). If relatives to your device use a certain
flag, chances are high that a new device will need it
too, typically from the same manufacturer.

The most common flag that needs to be set is the
DEVICE_FLAG_UNLOAD_DRIVER that detach any Linux kernel
drivers that may have attached to the device making
MTP access impossible. This is however not expected to
really work: this is a problem being tracked as of
now (2007-08-04). See the "last resort" solutions below
if you really need to get your dual-mode device to work
with MTP.

Another flag which is easy to identify is the
DEVICE_FLAG_NO_ZERO_READS, which remedies connection
timeouts when getting files, and some timeouts on e.g.
successive "mtp-connect" calls.

If your device is very problematic we are curious of how it
works under Windows, so we enjoy reading USB packet sniffs
that reveal the low-level traffic carried out between
Windows Media Player and your device. This can be done
using e.g.:

* USBsnoop:
  https://benoit.papillault.free.fr/usbsnoop/

* The trial version of HHD Softwares software-only
  USB monitor. You need to get a copy of version 2.37 since
  the newer trial versions won't let you carry out the
  needed packet sniffs. (As of 2007-03-10 a copy can be found
  at: https://www.cobbleware.com/files/usb-monitor-237.exe)

There are other USB monitors as well, some more expensive
alternatives use hardware and even measure electronic
characteristics of the traffic (which is far too much
detail for us).

Device sniffs are an easy read since the PTP/MTP protocol
is nicely structured. All commands will have a structure such
as this in the log, we examplify with a object list request:

PTP REQEUST:
000120: Bulk or Interrupt Transfer (UP), 03.09.2007 12:49:25.9843750 +0.0
Pipe Handle: 0x863ce234 (Endpoint Address: 0x2)
Send 0x20 bytes to the device:
 20 00 00 00 01 00 05 98 23 00 00 00 27 03 00 10    ......?#...'...
 Length      TYPE  CMD   Trans#      Param1

 00 00 00 00 02 DC 00 00 00 00 00 00 00 00 00 00   .....Ü..........
 Param2      Param3      Param4      Param5

[OPTIONAL] DATA PHASE:
000121: Bulk or Interrupt Transfer (UP), 03.09.2007 12:49:26.0 +0.0156250
Pipe Handle: 0x863ce214 (Endpoint Address: 0x81)
Get 0x1a bytes from the device:
 1A 00 00 00 02 00 05 98 23 00 00 00 01 00 00 00   .......?#.......
 Length      TYPE  CMD   Trans#      DATA

 27 03 00 10 02 DC 04 00 00 30                     '....Ü...0

RESPONSE:
000122: Bulk or Interrupt Transfer (UP), 03.09.2007 12:49:26.0 +0.0
Pipe Handle: 0x863ce214 (Endpoint Address: 0x81)
Get 0xc bytes from the device:
 0C 00 00 00 03 00 01 20 23 00 00 00               ....... #...
 Length      TYPE  CODE  Trans#

* One send (OUT to the device), two reads (IN from the device).

* All three byte chunks commands are
  sent/recieved/recieeved by the function  ptp_transaction()
  in the file ptp.c.

* It boils down to ptp_usb_sendreq(), optionally ptp_usb_senddata()
  or ptp_usb_getdata() and finally ptp_usb_getresp() in the file
  libusb-glue.c. Notice ptp_usb_sendreq() and ptp_usb_getresp()
  are ALWAYS called. The TYPE field correspond to this, so the
  TYPES in this case are "COMMAND" (0x0001), "DATA" (0x0002),
  and "RESPONSE" (0x0003).

* Notice that the byte order is little endian, so you need to read
  each field from right to left.

* This COMMAND has:
  CMD 0x99805, we see in ptp.h that this is PTP_OC_MTP_GetObjPropList.
  Transaction# 0x00000023.
  REQUEST parameters 0x10000327, 0x00000000, 0x0000DC02, 0x00000000
    0x00000000, in this case it means "get props for object 0x10000327",
    "any format", "property 0xDC02" (PTP_OPC_ObjectFormat), then two
    parameters that are always zero (no idea what they mean or their
    use).

* The DATA has:
  CMD 0x99805, we see in ptp.h that this is PTP_OC_MTP_GetObjPropList.
  Transaction# 0x00000023.
  Then comes data 0x00000001, 0x10000327, 0xDC02, 0x0004, 0x3000
  Which means in this case, (and this is the tricky part) "here
  you have 1 property", "for object 0x10000327", "it is property
  0xDC02" (PTP_OPC_ObjectFormat), "which is of type 0x0004"
  (PTP_DTC_UINT16), "and set to 0x3000" (PTP_OFC_Undefined, it
  is perfectly valid to have undefined object formats, since it
  is a legal value defining this).

* This RESPONSE has:
  CMD 0x99805, we see in ptp.h that this is PTP_OC_MTP_GetObjPropList.
  Return Code ("RC") = 0x2001, PTP_RC_OK, all went fine.
  Transaction# 0x00000023.

If you want to compare the Windows behaviour with a similar
operation using libmtp you can go into the src/libusb-glue.c
file and uncomment the row that reads:

//#define ENABLE_USB_BULK_DEBUG

(I.e. remove the two //.)

This will make libmtp print out a hex dump of every bulk USB
transaction. The bulk transactions contain all the PTP/MTP layer
data, which is usually where the problems appear.


Notes to assist with debugging new devices:
-------------------------------------------

In debugging new hardware, we highly recommend that you only
use the example mtp-* applications that come with libmtp, as other
applications may have their own bugs that may interfere with your
new device working correctly. Using another application instead of
those that come with libmtp just adds another point of failure.

For debugging, there are 3 main options:

1. Use the env variable: LIBMTP_DEBUG to increase the
verboseness of the debugging output for any application using
libmtp. Relevant codes are:
* 0x00 [0000 0000] : no debug (default)
* 0x01 [0000 0001] : PTP debug
* 0x02 [0000 0010] : Playlist debug
* 0x04 [0000 0100] : USB debug
* 0x08 [0000 1000] : USB data debug
// Codes are hex and binary respectively. Simple add them togther
// to get your desired level of output.

(Assuming bash)
eg:
$ export LIBMTP_DEBUG=12
$ mtp-detect
  // To get USB debug and USB data debug information.

$ export LIBMTP_DEBUG=2
$ mtp-detect
    // To get Playlist debug information.

Also note, an application may also use the LIBMTP_debug() API
function to achieve the same options as listed above.

2. Use "strace" on the various mtp-* commands to see where/what
is falling over or getting stuck at.
* On Solaris and FreeBSD, use "truss" or "dtrace" instead on "strace".
* On Mac OS X, use "ktrace" or "dtrace" instead of "strace".
* On OpenBSD and NetBSD, use "ktrace" instead of "strace".

This will at least help pinpoint where the application is failing, or
a device is reporting incorrect information. (This is extremely helpful
with devices that have odd disconnection requirements).

The use of these tools may also pinpoint issues with libusb as
implemented by each OS vendor or issues with the MTP implementation
on the new device as well, so please be prepared for either case.

3. Use "gdb" or similar debugger to step through the code as it is
run. This is time consuming, and not needed just to pinpoint where
the fault is.

The use of gdb or another debugger may also miss or actually cause
command and data timing issues with some devices, leading to false
information. So please consider this a last resort option.

Also please read the "It's Not Our Bug!" section below, as it does
contain some useful information that may assist with your device.


Dual-mode devices does not work - last resort:
----------------------------------------------

Some devices that are dual-mode are simply impossible to get
to work under Linux because the usb-storage(.ko) kernel
module hook them first, and refuse to release them, even
when we specify the DEVICE_FLAG_UNLOAD_DRIVER flag. (Maybe
it DOES release it but the device will immediately be probed
at the USB mass storage interface AGAIN because it
enumerates.)

Here is what some people do:

 1. Plug in the device.
 2. USB-mass storage folder will open automatically.
 3. Unmount the device.
 4. Run mtp-detect. It will most likely fail the first time.
 5. Run mtp-detect again, it might work this time, or fail. Keep running
    till it works. 99% it works by the third try.
 6. Once mtp-detect gives you an "Ok", open either Rhythmbox or Gnomad2,
    everything should work.

Linux: Try this, if you have a recent Linux kernel,
add the file (as root):

/etc/modprobe.d/no-usb-storage.conf

With the contents:

options usb-storage quirks=1234:4321:i

This will tell usb-storage to ignore this device when it's inserted
so it is not hogged by the mass storage interfaces. Remove and re-insert
the device and see if it works. Usually this does the trick.

For older systems, or as a bigger hammer, run (as root) something
like:

> rmmod usb_storage ; mtp-detect

You can run most any command or a client like gnomad2 or
Amarok immediately after the rmmod command. This works
sometimes. Another even more brutal approach is this:

* Edit /etc/modprobe.d/blacklist
* Add the line "blacklist usb-storage"
* Reboot.

Now none of you USB disks, flash memory sticks etc will be
working (you just disabled them all). However you *can* try
your device, and it might have started working because there
is no longer a USB mass storage driver that tries to hook onto
the mass storage interface of your device.

If not even blacklisting works (check with
"lsmod | grep usb-storage"), there is some problem with
something else and you may need to remove or rename the file
/lib/modules/<VERSION>/kernel/drivers/usb/storage/usb-storage.ko
manually.

If you find the PerfectSolution(TM) to this dilemma, so you
can properly switch for individual devices whether to use it
as USB mass storage or not, please tell us how you did it. We
know we cannot use udev, because udev is called after-the-fact:
the device is already configured for USB mass storage when
udev is called.

On Mac OS there is another ugly hack:

1. Open up a terminal window
2. Type:
sudo mv /System/Library/Extensions/IOUSBMassStorageClass.kext
/System/Library/Extensions/IOUSBMassStorageClass.kext.disabled

and when prompted enter your password.

3. Restart.

To reverse this change, just reverse the filenames:

sudo mv /System/Library/Extensions/
IOUSBMassStorageClass.kext.disabled /System/Library/Extensions/
IOUSBMassStorageClass.kext

and restart.


Calendar and contact support:
-----------------------------

The Creative Zen series can read VCALENDAR2 (.ics) files
and VCard (.vcf) files from programs like for example
Evolution with the following limitations/conditions:

- The file must be in DOS (CR/LF) format, use the unix2dos
  program to convert if needed

- Repeat events in calendar files do not seem to be supported,
  entries will only appear once.

- Calendar (.ics) files should be stored in the folder "My Organizer"
  when sent to the device (this directory should be autodetected
  for use with calendar files, otherwise use the option
  -f "My Organizer" to sendfile for this) Apparently this file can
  also contain tasklists.

- Contact (.vcf) files should be stored in the folder "My Contacts"
  when sent to the device. (-f "My Contacts")

- Some devices are picky about the name of the calendar and
  contact files. For example the Zen Microphoto wants:

  Calendar: My Organizer/6651416.ics
  Contacts: My Organizer/6651416.vcf


Syncing in with Evolution and Creative Devices
----------------------------------------------

Evolution can easily export .ics an .vcf files, but you currently
need some command-line hacking to get you stuff copied over in
one direction host -> device. The examples/ directory contains a script
created for the Creative Zen Microphoto by Nicolas Tetreault.


Lost symbols
------------

Shared libraries can be troublesome to users not experienced with
them. The following is a condensed version of a generic question
that has appeared on the libmtp mailing list from time to time.

> PTP: Opening session
> Queried Creative Zen Vision:M
> gnomad2: relocation error: gnomad2: undefined symbol:
> LIBMTP_Get_Storageinfo
> (...)
> Are these type of errors related to libmtp or something else?

The problem is of a generic nature, and related to dynamic library
loading. It is colloquially known as "dependency hell".
(https://en.wikipedia.org/wiki/Dependency_hell)

The gnomad2 application calls upon the dynamic linker in Linux to
resolve the symbol "LIBMTP_Get_Storageinfo" or any other symbol
(ELF symbol, or link point or whatever you want to call them, a
symbol is a label on a memory address that the linker shall
resolve from label to actual address.)
For generic information on this subject see the INSTALL file and
this Wikipedia page:

https://en.wikipedia.org/wiki/Library_(computing)

When Linux /lib/ld-linux.so.X is called to link the symbols compiled
into gnomad2 (or any other executable using libmtp), it examines the
ELF file for the libmtp.so.X file it finds first and cannot resolve
the symbol "LIBMTP_Get_Storageinfo" (or whichever symbol you have a
problem witj) from it, since it's probably not there. There are many
possible causes of this symbol breakage:

1) You installed precompiled libmtp and gnomad2 packages (RPMs, debs
    whatever) that do not match up. Typical cause: your gnomad2 package was
    built against a newer version of libmtp than what's installed on your
    machine. Another typical cause: you installed a package you found on
    the web, somewhere, the dependency resolution system did not protest
    properly (as it should) or you forced it to install anyway, ignoring
    some warnings.

2) You compiled libmtp and/or gnomad2 from source, installing both or
    either in /usr/local/lib and /usr/local/bin. This means at compile-time
    gnomad2 finds the libmtp library in /usr/local/lib but at runtime, it
    depends on the Linux system wide library loader (/lib/ld-linux.so.X) in
    order to resolve the symbols. This loader will look into the file
    /etc/ld.so.conf and/or the folder /etc/ld.so.conf.d in order to find
    paths to libraries to be used for resolving the symbols. If you have
    some older version of libmtp in e.g. /usr/lib (typically installed by a
    package manager) it will take precedence over the new version you just
    installed in /usr/local/lib and the newly compiled library in
    /usr/local/lib will *not* be used, resulting in this error message.

3) You really did install the very latest versions (as of writing libmtp
    0.1.5 and gnomad2 2.8.11) from source and there really is no
    pre-installed package of either on your machine. In that case I'm
    totally lost, I have no idea what's causing this.

Typical remedies:

1) If you don't want to mess around with your system and risk these
    situations, only use pre-packaged software that came with the
    distribution or its official support channels. If it still breaks,
    blame your distribution, they're not packaging correctly. Relying on
    properly packaged software and not installing things yourself *is* the
    Linux solution to the "dependency hell" problem.

2) Read about dynamically linked library handling until the stuff I wrote
    about in the previous list sounds like music to your ears, inspect
    your /lib, /usr/lib, /usr/local/lib, /etc/ld.so.conf and the
    /etc/ld.so.conf.d, remove all pre-packed versions using RPM, APT,
    YaST or whatever your distribution uses, compile libmtp and gnomad2
    (or whatever) from source only and you will be enlighted.

I don't know if this helps you, it's the best answer we can give.


API is obscure - I want plain files!
------------------------------------

PTP/MTP devices does not actually contain "files", they contain
objects. These objects have file names, but that is actually
just a name tag on the object.

Folders/directories aren't really such entities: they are just
objects too, albeit objects that can act as parent to other
objects. They are called "associations" and are created in atomic
fashion and even though there is an MTP command to get all the
associations of a certain object, this command is optional
so it is perfectly possible (and most common, actually) to create
devices where the "folders" (which are actually associations) have
no idea whatsoever of what files they are associated as parents to
(i.e. which files they contain). This is very easy for device
manufacturers to implement, all the association (i.e. finding out
which files are in a certain folder) has to be done by the MTP
Initiator / host computer.

Moving a file to a new folder is for example very simple in a
"real" file system. In PTP/MTP devices it is often not even possible,
some devices *may* be able to do that, if they support command
0x1019 "Move Object", but actually the only reliable way of executing
file movement is to upload the file to the host, download it with
the new parent, then delete the old file. We have played with the
idea of implementing this time consuming function as a fallback
in case the device does not support command 0x1019, perhaps one day
we will do that. (Some devices also support command 0x101a
"Copy Object".)

Then the issue that in PTP/MTP it is legal for two files to have
exactly the same path as long as their object IDs differ. A
folder/association can contain two files with the exact same name.
(And on the Creative devices this even works, too, though most devices
implicitly fail at this.) Perhaps one could add some custom hook for
handling that, so they become  /Foo.mp3 and /Foo.mp3(1) or something
similar, but it's really a bit kludgy.

Playlists and albums aren't really files, thinking about
them as files like the hacks in libgphoto2 is really backwards. They are
called associations and are more like a symbolic link that links in a
star-shaped pattern to all the files that are part of the album/playlist.
Some devices (Samsung) thought that was too complicated and have a
different way of storing playlists in an UTF-16 encoded .spl-like file
instead! This is why playlists/albums must have their own structs and
functions.

Plain file access also assumes to be able to write files of an
undetermined size, which is simply not possible in a transactional
file system like PTP/MTP. (See further below.)


I Want Streaming!
-----------------

Streaming reads is easy. Just connect the output file descriptor from
LIBMTP_Get_File_To_File_Descriptor() (and a similar function for tracks)
wherever you want.

People have connected this to TCP sockets for streaming web servers
etc, works like a charm. Some devices will even survive if the callback
functions return non-zero and cancel the download. Some devices will
lock up and even require a reset if you do that. Devices are poorly
implemented so that's life. If you want to stream off a device, the
best idea is always to stream the entire file and discard the stuff
at the end you don't want. It will incur a delay if you e.g. want to
skip between tracks, sadly.

Then we get to the complicated things: streaming WRITES...

There is a function:
LIBMTP_Send_File_From_File_Descriptor() (and similar for tracks)
which will write a file to a device from a file descriptor, which may
be a socket or whatever.

HOWEVER: this requires a piece of metadata with the .filesize properly
set first.

This is not because we think it is funny to require that, the protocol
requires it. The reason is that PTP/MTP is a transactional file system
and it wants to be able to deny file transfer if the file won't fit on
the device, so the transaction never even starts, it's impossible to
start a transaction without giving file length.

People really want streaming so I tried a lot of hacks to see if they
would work, such as setting file size to 0xffffffffU or something other
unnaturally big and then aborting the file transfer when the stream ends.
It doesn't work: either the device crashes or the file simply disappears
since the device rolls back all failed transactions.

So this is an inherent limitation of the PTP/MTP protocol.


I want to remote control my device!
-----------------------------------

I have both good and bad news for you.

The good news is that the MTP protocol has well-defined commands to play
back content on a device. Operation 0xD411 (PTP_DPC_MTP_PlaybackObject)
will start playing back a file on the device (whatever that may mean if
this is not a music or video file), and operation 0xD403 can set the
playback volume to save your ears. Then there are operations to
determine how far into the current file you currently are, so as to
support say progress bars.

Since these commands have been around since the dawn of the MTP protocol
and since it was developed in cooperation with Creative Technology, this
is probably a requested feature from the Creative people who already had
support for playback on their devices using the PDE protocol back then.

Anyway, here are the bad news:
[logs]$ grep d411 *
mtp-detect-trekstor-vibez.txt:   0xd411: Playback Object

Aha there is only one known device in the world which actually supports
playback on the device. So either you go buy the Trekstor Vibez, or you
can forget about this. You could always try asking your hardware vendor
of choice to go implement this.

Since none of the core developers of libmtp has the Trekstor device, this
is not yet implemented in libmtp.


I make MTP devices!
-------------------

If you are a device vendor there is a lot you can do for libmtp:

* Please consider assigning one of your employees as a contact person
  for libmtp, have them sign up to the libmtp development list and answer
  questions and post new device ID:s as they are released to our
  mailing list.

* If you want to help even more, assign someone to look deeper into
  error reports on your specific devices, understand why your firmware
  may require some special device flags and what can be done about it.

* Do you have spare devices you can give us? Send them to Richard (Mac
  support) or Linus (Linux support). (So far nobody did that except for
  Microsoft who sent us a Zune by proxy!)

Vendors do need help from libmtp too, especially we want to help
vendors improve their MTP stacks, because they all suffer from the
same problem: the lack of a proper conformance test has made many devices
incompliant with the MTP specification as it is published today: most
devices are just compliant with the Windows MTP stack, and don't work
out-of-the-box with libmtp. We need someone on the inside to help in
bug reporting vendors MTP stacks internally so these issues are raised.
A good way to go toward better MTP compliance is to test with an
alternative implementation of the stack. In e.g. IETF standardization
it is compulsory for an RFC to have atleast two independent implementations
for it to reach the status as standard.

Being compliant with libmtp is also more and more important for
vendors: libmtp is being deployed in some embedded systems like
set-top-boxes etc. It will be very irritating for customers if a device
will not dock properly with some home entertainment equipment just because
it is based on Linux and libmtp and not the Windows MTP stack.

Autodetect with gudev
---------------------

Previously you would use HAL to detect devices being plugged in. Nowadays
we use udev directly, or though the GNOME libgudev library. LIBMTPs
default udev rules export the proper properties to detect any MTP device
automatically, here is a verbose example derived from gnomad2:

#define G_UDEV_API_IS_SUBJECT_TO_CHANGE
#include <gudev/gudev.h>
const char * const gudev_subsystems[] = { "usb", NULL };
GUdevClient *gudev_client;
guint uevent_id;
guint uevent_bus_hooked = 0;
guint uevent_device_hooked = 0;


static void uevent_cb(GUdevClient *client, const char *action, GUdevDevice *device, void *data)
{
  guint64 devicenum;
  guint vendor;
  guint model;
  guint busnum;
  guint devnum;
  guint mtpdevice;

  devicenum = (guint64) g_udev_device_get_device_number(device);
  g_print("%s event for %s (%"G_GINT64_MODIFIER"x)", action,
          g_udev_device_get_sysfs_path (device), devicenum);

  /* get device info */
  vendor = get_property_as_int(device, "ID_VENDOR_ID", 16);
  model = get_property_as_int(device, "ID_MODEL_ID", 16);
  busnum = get_property_as_int(device, "BUSNUM", 10);
  devnum = get_property_as_int(device, "DEVNUM", 10);
  mtpdevice = get_property_as_int(device, "ID_MTP_DEVICE", 10);

  if (vendor == 0 || model == 0) {
    g_print("couldn't get vendor or model ID for device at (%x:%x)\n",
            busnum, devnum);
    return;
  } else {
    g_print("vendor = %x, model = %x, bus = %x, device = %x\n",
            vendor, model, busnum, devnum);
  }

  if (mtpdevice) {
    g_print("device is MTP compliant\n");

    if (g_str_equal(action, "add") &&
       uevent_bus_hooked == 0 &&
       uevent_device_hooked == 0) {
      g_print(MTP device plugged in!\n");
      uevent_bus_hooked = busnum;
      uevent_device_hooked = devnum;
      scan_jukebox(NULL);
    } else if (g_str_equal (action, "remove") &&
       	   uevent_bus_hooked == busnum &&
           uevent_device_hooked == devnum) {
      g_print("MTP device removed!\n");
      uevent_bus_hooked = 0;
      uevent_device_hooked = 0;
    }
  }
}



(...)
  /*
   * Monitor udev device events - we're only really interested in events
   * for USB devices.
   */
  gudev_client = g_udev_client_new(gudev_subsystems);
  uevent_id = g_signal_connect_object(gudev_client,
                                      "uevent",
                                      G_CALLBACK(uevent_cb),
                                      NULL, 0);

SKETCH OF AN OVERVIEW
---------------------

Draft agenda for a talk on MTP devices submitted for the Android
builders summit, might come to recycle this:

- Protocol overview
  - Transactional filesystem - no corruption due to unplugged cables!
  - The host and the device can access the files simultaneously, the
    device will always "own" the physical file system and proxy the
    host (MTP initiator).
- libmtp interface
- relation to libgphoto2
- User expectations fall short:
  - Not really a mountable filesystem.
  - Streaming does not work. (Size needs to be known beforehand due to
    transactional nature.)
  - GVFS MTP backend to the rescue.
- Device sins
  - Using the same VID/PID for several modes, some of which are not MTP.
    HTC Zopo, HD2, Bird (0x0bb4/0x0c02). Thanks for that, now we cannot
    detect the protocol from just VID+PID but have to examine the interfaces.
  - Android bugs
  - Samsungs special Android MTP stack
  - SonyEricsson Aricent stack for Xperia Androids pre 4.0, broken headers!
  - Flat access model vs hierarchical, how Android uses MTP as an hierachical
    file system while it was previously a flat database.
  - Old paradigm: scan the entire non-hierarchical storage for all content,
    build a cache to speed up the (USB 1.1!) link. Usually all files were
    stored in the root folder or a single folder named "/Music" or similar.
  - Android introduced deeply nested folder hierarchies, not seen before
    on MTP devices.
  - Microsoft not using the complete metadata dump feature of the MTP
    protocol (once introduced by creative) instead they walk directories
    separately.
  - So caching a big device will take long time and/or timeout.
  - Go-MTPFS (FUSE) and GVFS MTP - doing the partial directory walk rather
    than caching all files.
  - Especially Android devices nowadays assume that
    you want to index a folder at the time, whereas older MTP devices (such
    as those from Creative) would assume that you wanted to index the entire
    device as it was plugged in, and device firmware is now ever more tailored
    toward per-folder filetree walking. This makes it harder for the library
    to provide the right abstractions: do we provide an API for indexing the
    whole device which is unacceptably slow on new devices, or do we provide
    an API for indexing a directory at the time which will somehow work on
    older devices too? Shall we deprecate the older API?
- Detecting from vendor extension, can fix in newer extensions!
- Autoprobing on Linux
  - Color devices do not like autoprobing
  - Devices need different PIDs for every alternative interface due to
    the Windows USB stack.
  - Multimode USB - one PID for each mode due to Windows limitations not
    applicable to Linux, SONY devices have ~5 different PIDs for a single
    device.
  - Mode switch devices? Maybe we do this wrong.
- MTPZ, came and went. Apparently deprecated by Microsoft with Windows
  Phone 8.
- Ideas??
GNU LESSER GENERAL PUBLIC LICENSE Version 2.1, February 1999 Copyright © 1991, 1999 Free Software Foundation, Inc. 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. [This is the first released version of the Lesser GPL. It also counts as the successor of the GNU Library Public License, version 2, hence the version number 2.1.] Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public Licenses are intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This license, the Lesser General Public License, applies to some specially designated software packages--typically libraries--of the Free Software Foundation and other authors who decide to use it. You can use it too, but we suggest you first think carefully about whether this license or the ordinary General Public License is the better strategy to use in any particular case, based on the explanations below. When we speak of free software, we are referring to freedom of use, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish); that you receive source code or can get it if you want it; that you can change the software and use pieces of it in new free programs; and that you are informed that you can do these things. To protect your rights, we need to make restrictions that forbid distributors to deny you these rights or to ask you to surrender these rights. These restrictions translate to certain responsibilities for you if you distribute copies of the library or if you modify it. For example, if you distribute copies of the library, whether gratis or for a fee, you must give the recipients all the rights that we gave you. You must make sure that they, too, receive or can get the source code. If you link other code with the library, you must provide complete object files to the recipients, so that they can relink them with the library after making changes to the library and recompiling it. And you must show them these terms so they know their rights. We protect your rights with a two-step method: (1) we copyright the library, and (2) we offer you this license, which gives you legal permission to copy, distribute and/or modify the library. To protect each distributor, we want to make it very clear that there is no warranty for the free library. Also, if the library is modified by someone else and passed on, the recipients should know that what they have is not the original version, so that the original author's reputation will not be affected by problems that might be introduced by others. Finally, software patents pose a constant threat to the existence of any free program. We wish to make sure that a company cannot effectively restrict the users of a free program by obtaining a restrictive license from a patent holder. Therefore, we insist that any patent license obtained for a version of the library must be consistent with the full freedom of use specified in this license. Most GNU software, including some libraries, is covered by the ordinary GNU General Public License. This license, the GNU Lesser General Public License, applies to certain designated libraries, and is quite different from the ordinary General Public License. We use this license for certain libraries in order to permit linking those libraries into non-free programs. When a program is linked with a library, whether statically or using a shared library, the combination of the two is legally speaking a combined work, a derivative of the original library. The ordinary General Public License therefore permits such linking only if the entire combination fits its criteria of freedom. The Lesser General Public License permits more lax criteria for linking other code with the library. We call this license the "Lesser" General Public License because it does Less to protect the user's freedom than the ordinary General Public License. It also provides other free software developers Less of an advantage over competing non-free programs. These disadvantages are the reason we use the ordinary General Public License for many libraries. However, the Lesser license provides advantages in certain special circumstances. For example, on rare occasions, there may be a special need to encourage the widest possible use of a certain library, so that it becomes a de-facto standard. To achieve this, non-free programs must be allowed to use the library. A more frequent case is that a free library does the same job as widely used non-free libraries. In this case, there is little to gain by limiting the free library to free software only, so we use the Lesser General Public License. In other cases, permission to use a particular library in non-free programs enables a greater number of people to use a large body of free software. For example, permission to use the GNU C Library in non-free programs enables many more people to use the whole GNU operating system, as well as its variant, the GNU/Linux operating system. Although the Lesser General Public License is Less protective of the users' freedom, it does ensure that the user of a program that is linked with the Library has the freedom and the wherewithal to run that program using a modified version of the Library. The precise terms and conditions for copying, distribution and modification follow. Pay close attention to the difference between a "work based on the library" and a "work that uses the library". The former contains code derived from the library, whereas the latter must be combined with the library in order to run. GNU LESSER GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License Agreement applies to any software library or other program which contains a notice placed by the copyright holder or other authorized party saying it may be distributed under the terms of this Lesser General Public License (also called "this License"). Each licensee is addressed as "you". A "library" means a collection of software functions and/or data prepared so as to be conveniently linked with application programs (which use some of those functions and data) to form executables. The "Library", below, refers to any such software library or work which has been distributed under these terms. A "work based on the Library" means either the Library or any derivative work under copyright law: that is to say, a work containing the Library or a portion of it, either verbatim or with modifications and/or translated straightforwardly into another language. (Hereinafter, translation is included without limitation in the term "modification".) "Source code" for a work means the preferred form of the work for making modifications to it. For a library, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the library. Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running a program using the Library is not restricted, and output from such a program is covered only if its contents constitute a work based on the Library (independent of the use of the Library in a tool for writing it). Whether that is true depends on what the Library does and what the program that uses the Library does. 1. You may copy and distribute verbatim copies of the Library's complete source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and distribute a copy of this License along with the Library. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Library or any portion of it, thus forming a work based on the Library, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) The modified work must itself be a software library. b) You must cause the files modified to carry prominent notices stating that you changed the files and the date of any change. c) You must cause the whole of the work to be licensed at no charge to all third parties under the terms of this License. d) If a facility in the modified Library refers to a function or a table of data to be supplied by an application program that uses the facility, other than as an argument passed when the facility is invoked, then you must make a good faith effort to ensure that, in the event an application does not supply such function or table, the facility still operates, and performs whatever part of its purpose remains meaningful. (For example, a function in a library to compute square roots has a purpose that is entirely well-defined independent of the application. Therefore, Subsection 2d requires that any application-supplied function or table used by this function must be optional: if the application does not supply it, the square root function must still compute square roots.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Library, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Library, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Library. In addition, mere aggregation of another work not based on the Library with the Library (or with a work based on the Library) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may opt to apply the terms of the ordinary GNU General Public License instead of this License to a given copy of the Library. To do this, you must alter all the notices that refer to this License, so that they refer to the ordinary GNU General Public License, version 2, instead of to this License. (If a newer version than version 2 of the ordinary GNU General Public License has appeared, then you can specify that version instead if you wish.) Do not make any other change in these notices. Once this change is made in a given copy, it is irreversible for that copy, so the ordinary GNU General Public License applies to all subsequent copies and derivative works made from that copy. This option is useful when you wish to copy part of the code of the Library into a program that is not a library. 4. You may copy and distribute the Library (or a portion or derivative of it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange. If distribution of object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place satisfies the requirement to distribute the source code, even though third parties are not compelled to copy the source along with the object code. 5. A program that contains no derivative of any portion of the Library, but is designed to work with the Library by being compiled or linked with it, is called a "work that uses the Library". Such a work, in isolation, is not a derivative work of the Library, and therefore falls outside the scope of this License. However, linking a "work that uses the Library" with the Library creates an executable that is a derivative of the Library (because it contains portions of the Library), rather than a "work that uses the library". The executable is therefore covered by this License. Section 6 states terms for distribution of such executables. When a "work that uses the Library" uses material from a header file that is part of the Library, the object code for the work may be a derivative work of the Library even though the source code is not. Whether this is true is especially significant if the work can be linked without the Library, or if the work is itself a library. The threshold for this to be true is not precisely defined by law. If such an object file uses only numerical parameters, data structure layouts and accessors, and small macros and small inline functions (ten lines or less in length), then the use of the object file is unrestricted, regardless of whether it is legally a derivative work. (Executables containing this object code plus portions of the Library will still fall under Section 6.) Otherwise, if the work is a derivative of the Library, you may distribute the object code for the work under the terms of Section 6. Any executables containing that work also fall under Section 6, whether or not they are linked directly with the Library itself. 6. As an exception to the Sections above, you may also combine or link a "work that uses the Library" with the Library to produce a work containing portions of the Library, and distribute that work under terms of your choice, provided that the terms permit modification of the work for the customer's own use and reverse engineering for debugging such modifications. You must give prominent notice with each copy of the work that the Library is used in it and that the Library and its use are covered by this License. You must supply a copy of this License. If the work during execution displays copyright notices, you must include the copyright notice for the Library among them, as well as a reference directing the user to the copy of this License. Also, you must do one of these things: a) Accompany the work with the complete corresponding machine-readable source code for the Library including whatever changes were used in the work (which must be distributed under Sections 1 and 2 above); and, if the work is an executable linked with the Library, with the complete machine-readable "work that uses the Library", as object code and/or source code, so that the user can modify the Library and then relink to produce a modified executable containing the modified Library. (It is understood that the user who changes the contents of definitions files in the Library will not necessarily be able to recompile the application to use the modified definitions.) b) Use a suitable shared library mechanism for linking with the Library. A suitable mechanism is one that (1) uses at run time a copy of the library already present on the user's computer system, rather than copying library functions into the executable, and (2) will operate properly with a modified version of the library, if the user installs one, as long as the modified version is interface-compatible with the version that the work was made with. c) Accompany the work with a written offer, valid for at least three years, to give the same user the materials specified in Subsection 6a, above, for a charge no more than the cost of performing this distribution. d) If distribution of the work is made by offering access to copy from a designated place, offer equivalent access to copy the above specified materials from the same place. e) Verify that the user has already received a copy of these materials or that you have already sent this user a copy. For an executable, the required form of the "work that uses the Library" must include any data and utility programs needed for reproducing the executable from it. However, as a special exception, the materials to be distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. It may happen that this requirement contradicts the license restrictions of other proprietary libraries that do not normally accompany the operating system. Such a contradiction means you cannot use both them and the Library together in an executable that you distribute. 7. You may place library facilities that are a work based on the Library side-by-side in a single library together with other library facilities not covered by this License, and distribute such a combined library, provided that the separate distribution of the work based on the Library and of the other library facilities is otherwise permitted, and provided that you do these two things: a) Accompany the combined library with a copy of the same work based on the Library, uncombined with any other library facilities. This must be distributed under the terms of the Sections above. b) Give prominent notice with the combined library of the fact that part of it is a work based on the Library, and explaining where to find the accompanying uncombined form of the same work. 8. You may not copy, modify, sublicense, link with, or distribute the Library except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense, link with, or distribute the Library is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 9. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Library or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Library (or any work based on the Library), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Library or works based on it. 10. Each time you redistribute the Library (or any work based on the Library), the recipient automatically receives a license from the original licensor to copy, distribute, link with or modify the Library subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties with this License. 11. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Library at all. For example, if a patent license would not permit royalty-free redistribution of the Library by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Library. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply, and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 12. If the distribution and/or use of the Library is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Library under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 13. The Free Software Foundation may publish revised and/or new versions of the Lesser General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Library specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Library does not specify a license version number, you may choose any version ever published by the Free Software Foundation. 14. If you wish to incorporate parts of the Library into other free programs whose distribution conditions are incompatible with these, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Libraries If you develop a new library, and you want it to be of the greatest possible use to the public, we recommend making it free software that everyone can redistribute and change. You can do so by permitting redistribution under these terms (or, alternatively, under the terms of the ordinary General Public License). To apply these terms, attach the following notices to the library. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. <one line to give the library's name and a brief idea of what it does.> Copyright © <year> <name of author> This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Also add information on how to contact you by electronic and paper mail. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the library, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the library `Frob' (a library for tweaking knobs) written by James Random Hacker. <signature of Ty Coon>, 1 April 1990 Ty Coon, President of Vice That's all there is to it!

简介

Third-party open-source software libmtp | 三方开源软件libmtp 展开 收起
LGPL-2.1
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/openharmony-sig/third_party_libmtp.git
git@gitee.com:openharmony-sig/third_party_libmtp.git
openharmony-sig
third_party_libmtp
third_party_libmtp
master

搜索帮助