libzypp  16.13.0
MediaCD.cc
Go to the documentation of this file.
1 /*---------------------------------------------------------------------\
2 | ____ _ __ __ ___ |
3 | |__ / \ / / . \ . \ |
4 | / / \ V /| _/ _/ |
5 | / /__ | | | | | | |
6 | /_____||_| |_| |_| |
7 | |
8 \---------------------------------------------------------------------*/
12 extern "C"
13 {
14 #include <sys/ioctl.h>
15 #include <linux/cdrom.h>
16 #if HAVE_UDEV
17 #include <libudev.h>
18 #endif
19 }
20 
21 #ifndef HAVE_UDEV
22 #if HAVE_HAL
24 #endif
25 #endif
26 
27 #include <cstring> // strerror
28 #include <cstdlib> // getenv
29 #include <iostream>
30 
31 #include "zypp/base/Logger.h"
32 #include "zypp/ExternalProgram.h"
33 #include "zypp/media/Mount.h"
34 #include "zypp/media/MediaCD.h"
36 #include "zypp/Url.h"
37 #include "zypp/AutoDispose.h"
38 
39 
40 
41 /*
42 ** if to throw exception on eject errors or ignore them
43 */
44 #define REPORT_EJECT_ERRORS 0
45 
46 /*
47 ** If defined to the full path of the eject utility,
48 ** it will be used additionally to the eject-ioctl.
49 */
50 #define EJECT_TOOL_PATH "/bin/eject"
51 
52 
53 using namespace std;
54 
56 namespace zypp
57 {
59  namespace media
60  {
61 
63  namespace
64  {
65  typedef std::list<MediaSource> DeviceList;
66 
76  DeviceList systemDetectDevices( bool supportingDVD_r )
77  {
78  DeviceList detected;
79 
80 #ifdef HAVE_UDEV
81  // http://www.kernel.org/pub/linux/utils/kernel/hotplug/libudev/index.html
82  zypp::AutoDispose<struct udev *> udev( ::udev_new(), ::udev_unref );
83  if ( ! udev )
84  {
85  ERR << "Can't create udev context." << endl;
86  return DeviceList();
87  }
88 
89  zypp::AutoDispose<struct udev_enumerate *> enumerate( ::udev_enumerate_new(udev), ::udev_enumerate_unref );
90  if ( ! enumerate )
91  {
92  ERR << "Can't create udev list entry." << endl;
93  return DeviceList();
94  }
95 
96  ::udev_enumerate_add_match_subsystem( enumerate, "block" );
97  ::udev_enumerate_add_match_property( enumerate, "ID_CDROM", "1" );
98  ::udev_enumerate_scan_devices( enumerate );
99 
100  struct udev_list_entry * entry = 0;
101  udev_list_entry_foreach( entry, ::udev_enumerate_get_list_entry( enumerate ) )
102  {
103  zypp::AutoDispose<struct udev_device *> device( ::udev_device_new_from_syspath( ::udev_enumerate_get_udev( enumerate ),
104  ::udev_list_entry_get_name( entry ) ),
105  ::udev_device_unref );
106  if ( ! device )
107  {
108  ERR << "Can't create udev device." << endl;
109  continue;
110  }
111 
112  if ( supportingDVD_r && ! ::udev_device_get_property_value( device, "ID_CDROM_DVD" ) )
113  {
114  continue; // looking for dvd only
115  }
116 
117  const char * devnodePtr( ::udev_device_get_devnode( device ) );
118  if ( ! devnodePtr )
119  {
120  ERR << "Got NULL devicenode." << endl;
121  continue;
122  }
123 
124  // In case we need it someday:
125  //const char * mountpath = ::udev_device_get_property_value( device, "FSTAB_DIR" );
126 
127  PathInfo devnode( devnodePtr );
128  if ( devnode.isBlk() )
129  {
130  MediaSource media( "cdrom", devnode.path().asString(), devnode.devMajor(), devnode.devMinor() );
131  DBG << "Found (udev): " << media << std::endl;
132  detected.push_back( media );
133  }
134  }
135  if ( detected.empty() )
136  {
137  WAR << "Did not find any CD/DVD device." << endl;
138  }
139 #elif HAVE_HAL
140  using namespace zypp::target::hal;
141  try
142  {
143  HalContext hal(true);
144 
145  std::vector<std::string> drv_udis;
146  drv_udis = hal.findDevicesByCapability("storage.cdrom");
147 
148  DBG << "Found " << drv_udis.size() << " cdrom drive udis" << std::endl;
149  for(size_t d = 0; d < drv_udis.size(); d++)
150  {
151  HalDrive drv( hal.getDriveFromUDI( drv_udis[d]));
152 
153  if( drv)
154  {
155  bool supportsDVD=false;
156  if( supportingDVD_r)
157  {
158  std::vector<std::string> caps;
159  try {
160  caps = drv.getCdromCapabilityNames();
161  }
162  catch(const HalException &e)
163  {
164  ZYPP_CAUGHT(e);
165  }
166 
167  std::vector<std::string>::const_iterator ci;
168  for( ci=caps.begin(); ci != caps.end(); ++ci)
169  {
170  if( *ci == "dvd")
171  supportsDVD = true;
172  }
173  }
174 
175  MediaSource media("cdrom", drv.getDeviceFile(),
176  drv.getDeviceMajor(),
177  drv.getDeviceMinor());
178  DBG << "Found " << drv_udis[d] << ": "
179  << media.asString() << std::endl;
180  if( supportingDVD_r && supportsDVD)
181  {
182  detected.push_front(media);
183  }
184  else
185  {
186  detected.push_back(media);
187  }
188  }
189  }
190  }
191  catch(const zypp::target::hal::HalException &e)
192  {
193  ZYPP_CAUGHT(e);
194  }
195 #endif
196  return detected;
197  }
198 
199  } // namespace
201 
202 
203  MediaCD::MediaCD( const Url & url_r, const Pathname & attach_point_hint_r )
204  : MediaHandler( url_r, attach_point_hint_r, url_r.getPathName(), false )
205  , _lastdev( -1 )
206  , _lastdev_tried( -1 )
207  {
208  MIL << "MediaCD::MediaCD(" << url_r << ", " << attach_point_hint_r << ")" << endl;
209 
210  if ( url_r.getScheme() != "dvd" && url_r.getScheme() != "cd" )
211  {
212  ERR << "Unsupported schema in the Url: " << url_r.asString() << endl;
214  }
215 
216  string devices = _url.getQueryParam( "devices" );
217  if ( ! devices.empty() )
218  {
219  std::vector<std::string> words;
220  str::split( devices, std::back_inserter(words), "," );
221  for ( const std::string & device : words )
222  {
223  if ( device.empty() )
224  continue;
225 
226  MediaSource media( "cdrom", device, 0, 0 );
227  _devices.push_back( media );
228  DBG << "use device (delayed verify)" << device << endl;
229  }
230  }
231  else
232  {
233  DBG << "going to use on-demand device list" << endl;
234  return;
235  }
236 
237  if ( _devices.empty() )
238  {
239  ERR << "Unable to find any cdrom drive for " << _url.asString() << endl;
241  }
242  }
243 
245  //
246  //
247  // METHOD NAME : MediaCD::openTray
248  // METHOD TYPE : bool
249  //
250  bool MediaCD::openTray( const std::string & device_r )
251  {
252  int fd = ::open( device_r.c_str(), O_RDONLY|O_NONBLOCK|O_CLOEXEC );
253  int res = -1;
254 
255  if ( fd != -1)
256  {
257  res = ::ioctl( fd, CDROMEJECT );
258  ::close( fd );
259  }
260 
261  if ( res )
262  {
263  if( fd == -1)
264  {
265  WAR << "Unable to open '" << device_r
266  << "' (" << ::strerror( errno ) << ")" << endl;
267  }
268  else
269  {
270  WAR << "Eject " << device_r
271  << " failed (" << ::strerror( errno ) << ")" << endl;
272  }
273 
274 #if defined(EJECT_TOOL_PATH)
275  DBG << "Try to eject " << device_r << " using "
276  << EJECT_TOOL_PATH << " utility" << std::endl;
277 
278  const char *cmd[3];
279  cmd[0] = EJECT_TOOL_PATH;
280  cmd[1] = device_r.c_str();
281  cmd[2] = NULL;
283 
284  for(std::string out( eject.receiveLine());
285  out.length(); out = eject.receiveLine())
286  {
287  DBG << " " << out;
288  }
289 
290  if(eject.close() != 0)
291  {
292  WAR << "Eject of " << device_r << " failed." << std::endl;
293  return false;
294  }
295 #else
296  return false;
297 #endif
298  }
299  MIL << "Eject of " << device_r << " successful." << endl;
300  return true;
301  }
302 
304  //
305  //
306  // METHOD NAME : MediaCD::closeTray
307  // METHOD TYPE : bool
308  //
309  bool MediaCD::closeTray( const std::string & device_r )
310  {
311  int fd = ::open( device_r.c_str(), O_RDONLY|O_NONBLOCK|O_CLOEXEC );
312  if ( fd == -1 ) {
313  WAR << "Unable to open '" << device_r << "' (" << ::strerror( errno ) << ")" << endl;
314  return false;
315  }
316  int res = ::ioctl( fd, CDROMCLOSETRAY );
317  ::close( fd );
318  if ( res ) {
319  WAR << "Close tray " << device_r << " failed (" << ::strerror( errno ) << ")" << endl;
320  return false;
321  }
322  DBG << "Close tray " << device_r << endl;
323  return true;
324  }
325 
326 
327  MediaCD::DeviceList MediaCD::detectDevices( bool supportingDVD_r ) const
328  {
329  DeviceList detected( systemDetectDevices( supportingDVD_r ) );
330 
331  if ( detected.empty() )
332  {
333  WAR << "CD/DVD drive detection with HAL/UDEV failed! Guessing..." << std::endl;
334  PathInfo dvdinfo( "/dev/dvd" );
335  PathInfo cdrinfo( "/dev/cdrom" );
336  if ( dvdinfo.isBlk() )
337  {
338  MediaSource media( "cdrom", dvdinfo.path().asString(), dvdinfo.devMajor(), dvdinfo.devMinor() );
339  DBG << "Found (GUESS): " << media << std::endl;
340  detected.push_back( media );
341  }
342  if ( cdrinfo.isBlk()
343  && ! ( cdrinfo.devMajor() == dvdinfo.devMajor() && cdrinfo.devMinor() == dvdinfo.devMinor() ) )
344  {
345  MediaSource media( "cdrom", cdrinfo.path().asString(), cdrinfo.devMajor(), cdrinfo.devMinor() );
346  DBG << "Found (GUESS): " << media << std::endl;
347  detected.push_back( media );
348  }
349  }
350 
351  // NOTE: On the fly build on-demand device list. Code was moved to
352  // here to get rid of code duplication, while keeping the ABI. Acuallty
353  // this code should be moved to a _devices accessor method.
354  if ( _devices.empty() )
355  {
356  DBG << "creating on-demand device list" << endl;
357  //default is /dev/cdrom; for dvd: /dev/dvd if it exists
358  string device( "/dev/cdrom" );
359  if ( _url.getScheme() == "dvd" && PathInfo( "/dev/dvd" ).isBlk() )
360  {
361  device = "/dev/dvd";
362  }
363 
364  PathInfo dinfo( device );
365  if ( dinfo.isBlk() )
366  {
367  MediaSource media( "cdrom", device, dinfo.devMajor(), dinfo.devMinor() );
368  if ( detected.empty() )
369  {
370  _devices.push_front( media ); // better try this than nothing
371  }
372  else
373  {
374  for( const auto & d : detected )
375  {
376  // /dev/cdrom or /dev/dvd to the front
377  if ( media.equals( d ) )
378  _devices.push_front( d );
379  else
380  _devices.push_back( d );
381  }
382  }
383  }
384  else
385  {
386  // no /dev/cdrom or /dev/dvd link
387  _devices = detected;
388  }
389  }
390 
391  return detected;
392  }
393 
394 
396  //
397  //
398  // METHOD NAME : MediaCD::attachTo
399  // METHOD TYPE : PMError
400  //
401  // DESCRIPTION : Asserted that not already attached, and attachPoint is a directory.
402  //
403  void MediaCD::attachTo( bool next )
404  {
405  DBG << "next " << next << " last " << _lastdev << " last tried " << _lastdev_tried << endl;
406  if ( next && _lastdev == -1 )
408 
409  // This also fills the _devices list on demand
410  DeviceList detected( detectDevices( _url.getScheme() == "dvd" ? true : false ) );
411 
412  Mount mount;
413  MediaMountException merr;
414 
415  string options = _url.getQueryParam( "mountoptions" );
416  if ( options.empty() )
417  {
418  options="ro";
419  }
420 
421  //TODO: make configurable
422  list<string> filesystems;
423 
424  // if DVD, try UDF filesystem before iso9660
425  if ( _url.getScheme() == "dvd" )
426  filesystems.push_back("udf");
427 
428  filesystems.push_back("iso9660");
429 
430  // try all devices in sequence
431  int count = 0;
432  std::string mountpoint( attachPoint().asString() );
433  bool mountsucceeded = false;
434  for ( DeviceList::iterator it = _devices.begin() ; ! mountsucceeded && it != _devices.end() ; ++it, ++count )
435  {
436  DBG << "count " << count << endl;
437  if (next && count <=_lastdev_tried )
438  {
439  DBG << "skipping device " << it->name << endl;
440  continue;
441  }
442  _lastdev_tried = count;
443 
444  // bnc#755815: _devices contains either devices passed as url option
445  // or autodetected ones. Accept both as long as they are block
446  // devices.
447  MediaSource temp( *it );
448  PathInfo dinfo( temp.name );
449  if ( ! dinfo.isBlk() )
450  {
451  WAR << "skipping non block device: " << dinfo << endl;
452  continue;
453  }
454  DBG << "trying device " << dinfo << endl;
455 
456  temp.maj_nr = dinfo.devMajor();
457  temp.min_nr = dinfo.devMinor();
458  MediaSourceRef media( new MediaSource(temp));
459  AttachedMedia ret( findAttachedMedia( media));
460 
461  if( ret.mediaSource && ret.attachPoint &&
462  !ret.attachPoint->empty())
463  {
464  DBG << "Using a shared media "
465  << ret.mediaSource->name
466  << " attached on "
467  << ret.attachPoint->path
468  << endl;
472  _lastdev = count;
473  mountsucceeded = true;
474  break;
475  }
476 
477  {
478  MediaManager manager;
479  MountEntries entries( manager.getMountEntries());
480  MountEntries::const_iterator e;
481  for( e = entries.begin(); e != entries.end(); ++e)
482  {
483  bool is_device = false;
484  std::string dev_path(Pathname(e->src).asString());
485  PathInfo dev_info;
486 
487  if( dev_path.compare(0, sizeof("/dev/")-1, "/dev/") == 0 &&
488  dev_info(e->src) && dev_info.isBlk())
489  {
490  is_device = true;
491  }
492 
493  if( is_device && media->maj_nr == dev_info.devMajor() &&
494  media->min_nr == dev_info.devMinor())
495  {
496  AttachPointRef ap( new AttachPoint(e->dir, false));
497  AttachedMedia am( media, ap);
498  {
499  DBG << "Using a system mounted media "
500  << media->name
501  << " attached on "
502  << ap->path
503  << endl;
504 
505  media->iown = false; // mark attachment as foreign
506 
507  setMediaSource(media);
508  setAttachPoint(ap);
509  _lastdev = count;
510  mountsucceeded = true;
511  break;
512  }
513  }
514  }
515  if( mountsucceeded)
516  break;
517  }
518 
519  // close tray
520  closeTray( it->name );
521 
522  // try all filesystems in sequence
523  for(list<string>::iterator fsit = filesystems.begin()
524  ; !mountsucceeded && fsit != filesystems.end()
525  ; ++fsit)
526  {
527  try
528  {
530  {
532  mountpoint = attachPoint().asString();
533  }
534 
535  mount.mount(it->name, mountpoint, *fsit, options);
536 
537  setMediaSource(media);
538 
539  // wait for /etc/mtab update ...
540  // (shouldn't be needed)
541  int limit = 2;
542  while( !(mountsucceeded=isAttached()) && --limit)
543  {
544  WAR << "Wait for /proc/mounts update and retry...." << endl;
545  sleep(1);
546  }
547 
548  if( mountsucceeded)
549  {
550  _lastdev = count;
551  }
552  else
553  {
555  try
556  {
557  mount.umount(attachPoint().asString());
558  }
559  catch (const MediaException & excpt_r)
560  {
561  ZYPP_CAUGHT(excpt_r);
562  }
564  "Unable to verify that the media was mounted",
565  it->name, mountpoint
566  ));
567  }
568  }
569  catch (const MediaMountException &e)
570  {
571  merr = e;
573  ZYPP_CAUGHT(e);
574  }
575  catch (const MediaException & excpt_r)
576  {
578  ZYPP_CAUGHT(excpt_r);
579  }
580  } // for filesystems
581  } // for _devices
582 
583  if (!mountsucceeded)
584  {
585  _lastdev = -1;
586 
587  if( !merr.mountOutput().empty())
588  {
590  _url.asString(),
591  mountpoint,
592  merr.mountOutput()));
593  }
594  else
595  {
596  ZYPP_THROW(MediaMountException("Mounting media failed",
597  _url.asString(), mountpoint));
598  }
599  }
600  DBG << _lastdev << " " << count << endl;
601  }
602 
603 
605  //
606  //
607  // METHOD NAME : MediaCD::releaseFrom
608  // METHOD TYPE : PMError
609  //
610  // DESCRIPTION : Asserted that media is attached.
611  //
612  void MediaCD::releaseFrom( const std::string & ejectDev )
613  {
614  Mount mount;
615  try
616  {
618  if(am.mediaSource && am.mediaSource->iown)
619  mount.umount(am.attachPoint->path.asString());
620  }
621  catch (const Exception & excpt_r)
622  {
623  ZYPP_CAUGHT(excpt_r);
624  if (!ejectDev.empty())
625  {
626  forceRelaseAllMedia(false);
627  if(openTray( ejectDev ))
628  return;
629  }
630  ZYPP_RETHROW(excpt_r);
631  }
632 
633  // eject device
634  if (!ejectDev.empty())
635  {
636  forceRelaseAllMedia(false);
637  if( !openTray( ejectDev ))
638  {
639 #if REPORT_EJECT_ERRORS
641 #endif
642  }
643  }
644  }
645 
647  //
648  //
649  // METHOD NAME : MediaCD::forceEject
650  // METHOD TYPE : void
651  //
652  // Asserted that media is not attached.
653  //
654  void MediaCD::forceEject( const std::string & ejectDev_r )
655  {
656 #if REPORT_EJECT_ERRORS
657  bool ejected = false;
658 #endif
659  if ( ! isAttached() ) // no device mounted in this instance
660  {
661  // This also fills the _devices list on demand
662  DeviceList detected( detectDevices( _url.getScheme() == "dvd" ? true : false ) );
663  for_( it, _devices.begin(), _devices.end() )
664  {
665  MediaSourceRef media( new MediaSource( *it ) );
666  if ( media->name != ejectDev_r )
667  continue;
668 
669  // bnc#755815: _devices contains either devices passed as url option
670  // or autodetected ones. Accept both as long as they are block
671  // devices.
672  PathInfo dinfo( media->name );
673  if( ! dinfo.isBlk() )
674  {
675  WAR << "skipping non block device: " << dinfo << endl;
676  continue;
677  }
678  DBG << "trying device " << dinfo << endl;
679 
680  // FIXME: we have also to check if it is mounted in the system
681  AttachedMedia ret( findAttachedMedia( media));
682  if( !ret.mediaSource )
683  {
684  forceRelaseAllMedia( media, false );
685  if ( openTray( it->name ) )
686  {
687 #if REPORT_EJECT_ERRORS
688  ejected = true;
689 #endif
690  break; // on 1st success
691  }
692  }
693  }
694  }
695 #if REPORT_EJECT_ERRORS
696  if( !ejected)
697  {
699  }
700 #endif
701  }
702 
704  //
705  // METHOD NAME : MediaCD::isAttached
706  // METHOD TYPE : bool
707  //
708  // DESCRIPTION : Override check if media is attached.
709  //
710  bool
712  {
713  return checkAttached(false);
714  }
715 
717  //
718  // METHOD NAME : MediaCD::getFile
719  // METHOD TYPE : PMError
720  //
721  // DESCRIPTION : Asserted that media is attached.
722  //
723  void MediaCD::getFile( const Pathname & filename ) const
724  {
725  MediaHandler::getFile( filename );
726  }
727 
729  //
730  // METHOD NAME : MediaCD::getDir
731  // METHOD TYPE : PMError
732  //
733  // DESCRIPTION : Asserted that media is attached.
734  //
735  void MediaCD::getDir( const Pathname & dirname, bool recurse_r ) const
736  {
737  MediaHandler::getDir( dirname, recurse_r );
738  }
739 
741  //
742  //
743  // METHOD NAME : MediaCD::getDirInfo
744  // METHOD TYPE : PMError
745  //
746  // DESCRIPTION : Asserted that media is attached and retlist is empty.
747  //
748  void MediaCD::getDirInfo( std::list<std::string> & retlist,
749  const Pathname & dirname, bool dots ) const
750  {
751  MediaHandler::getDirInfo( retlist, dirname, dots );
752  }
753 
755  //
756  //
757  // METHOD NAME : MediaCD::getDirInfo
758  // METHOD TYPE : PMError
759  //
760  // DESCRIPTION : Asserted that media is attached and retlist is empty.
761  //
762  void MediaCD::getDirInfo( filesystem::DirContent & retlist, const Pathname & dirname, bool dots ) const
763  {
764  MediaHandler::getDirInfo( retlist, dirname, dots );
765  }
766 
767 
768  bool MediaCD::getDoesFileExist( const Pathname & filename ) const
769  {
770  return MediaHandler::getDoesFileExist( filename );
771  }
772 
773 
775  {
776  if (_devices.size() == 0)
777  return false;
778  else if (_lastdev_tried < 0)
779  return true;
780 
781  return (unsigned) _lastdev_tried < _devices.size() - 1;
782  }
783 
784 
785  void MediaCD::getDetectedDevices( std::vector<std::string> & devices, unsigned int & index ) const
786  {
787  if ( ! devices.empty() )
788  devices.clear();
789 
790  if ( _devices.empty() )
791  // This also fills the _devices list on demand
792  detectDevices( _url.getScheme() == "dvd" ? true : false );
793 
794  for ( const auto & it : _devices )
795  devices.push_back( it.name );
796 
797  index = ( _lastdev >= 0 ? (unsigned)_lastdev : 0 );
798 
799  MIL << "got " << devices.size() << " detected devices, current: "
800  << (index < devices.size() ? devices[index] : "<none>")
801  << "(" << index << ")" << endl;
802  }
803 
804  } // namespace media
806 } // namespace zypp
Hardware abstaction layer library wrapper.
Attach point of a media source.
Definition: MediaSource.h:105
std::vector< std::string > getCdromCapabilityNames() const
Definition: HalContext.cc:812
#define MIL
Definition: Logger.h:64
virtual void forceEject(const std::string &ejectDev)
Call concrete handler to physically eject the media (i.e.
Definition: MediaCD.cc:654
virtual void getFile(const Pathname &filename) const
Call concrete handler to provide file below attach point.
Definition: MediaCD.cc:723
Interface to the mount program.
Definition: Mount.h:69
std::string asString(const DefaultIntegral< Tp, TInitial > &obj)
#define ZYPP_THROW(EXCPT)
Drops a logline and throws the Exception.
Definition: Exception.h:321
Hardware abstaction layer storage drive object.
Definition: HalContext.h:177
HalDrive getDriveFromUDI(const std::string &udi) const
Construct a HalDrive object for the specified UDI.
Definition: HalContext.cc:377
virtual void getDirInfo(std::list< std::string > &retlist, const Pathname &dirname, bool dots=true) const =0
Call concrete handler to provide a content list of directory on media via retlist.
virtual bool isAttached() const
True if media is attached.
Definition: MediaCD.cc:711
zypp::RW_pointer< MediaSource > MediaSourceRef
Definition: MediaSource.h:124
unsigned int maj_nr
A major number if source is a device.
Definition: MediaSource.h:89
virtual void getDetectedDevices(std::vector< std::string > &devices, unsigned int &index) const
Fill in a vector of detected ejectable devices and the index of the currently attached device within ...
Definition: MediaCD.cc:785
void setAttachPoint(const Pathname &path, bool temp)
Set a new attach point.
Pathname createAttachPoint() const
Try to create a default / temporary attach point.
Definition: Arch.h:344
#define for_(IT, BEG, END)
Convenient for-loops using iterator.
Definition: Easy.h:27
std::list< MediaSource > DeviceList
Definition: MediaCD.h:31
std::string name
A media handler specific source name.
Definition: MediaSource.h:92
Hardware abstaction layer exception.
Definition: HalException.h:39
virtual void getDirInfo(std::list< std::string > &retlist, const Pathname &dirname, bool dots=true) const
Call concrete handler to provide a content list of directory on media via retlist.
Definition: MediaCD.cc:748
#define ERR
Definition: Logger.h:66
std::string asString() const
Returns a default string representation of the Url object.
Definition: Url.cc:491
void mount(const std::string &source, const std::string &target, const std::string &filesystem, const std::string &options, const Environment &environment=Environment())
mount device
Definition: Mount.cc:66
virtual void attachTo(bool next=false)
Call concrete handler to attach the media.
Definition: MediaCD.cc:403
#define ZYPP_RETHROW(EXCPT)
Drops a logline and rethrows, updating the CodeLocation.
Definition: Exception.h:329
static bool openTray(const std::string &device_r)
Definition: MediaCD.cc:250
AttachPointRef attachPoint
Definition: MediaSource.h:145
AttachedMedia findAttachedMedia(const MediaSourceRef &media) const
Ask the media manager if specified media source is already attached.
unsigned split(const C_Str &line_r, TOutputIterator result_r, const C_Str &sepchars_r=" \t")
Split line_r into words.
Definition: String.h:519
virtual void releaseFrom(const std::string &ejectDev)
Call concrete handler to release the media.
Definition: MediaCD.cc:612
MediaSourceRef mediaSource
Definition: MediaSource.h:144
AttachedMedia attachedMedia() const
Returns the attached media.
Abstract base class for &#39;physical&#39; MediaHandler like MediaCD, etc.
Definition: MediaHandler.h:45
A simple structure containing references to a media source and its attach point.
Definition: MediaSource.h:133
Execute a program and give access to its io An object of this class encapsulates the execution of an ...
const Url _url
Url to handle.
Definition: MediaHandler.h:110
virtual bool hasMoreDevices()
Check if the media has one more device available for attach(true).
Definition: MediaCD.cc:774
void setMediaSource(const MediaSourceRef &ref)
Set new media source reference.
Just inherits Exception to separate media exceptions.
#define EJECT_TOOL_PATH
Definition: MediaCD.cc:50
#define WAR
Definition: Logger.h:65
std::list< DirEntry > DirContent
Returned by readdir.
Definition: PathInfo.h:547
std::vector< std::string > findDevicesByCapability(const std::string &capability) const
Retrieve UDI&#39;s of all devices with a capability.
Definition: HalContext.cc:420
DeviceList _devices
list of devices to try to mount
Definition: MediaCD.h:33
std::string receiveLine()
Read one line from the input stream.
std::string getQueryParam(const std::string &param, EEncoding eflag=zypp::url::E_DECODED) const
Return the value for the specified query parameter.
Definition: Url.cc:654
bool isUseableAttachPoint(const Pathname &path, bool mtab=true) const
Ask media manager, if the specified path is already used as attach point or if there are another atta...
const std::string & mountError() const
void removeAttachPoint()
Remove unused attach point.
Media source internally used by MediaManager and MediaHandler.
Definition: MediaSource.h:36
int close()
Wait for the progamm to complete.
virtual void getDir(const Pathname &dirname, bool recurse_r) const
Call concrete handler to provide directory content (not recursive!) below attach point.
Definition: MediaCD.cc:735
virtual void getDir(const Pathname &dirname, bool recurse_r) const =0
Call concrete handler to provide directory content (not recursive!) below attach point.
#define ZYPP_CAUGHT(EXCPT)
Drops a logline telling the Exception was caught (in order to handle it).
Definition: Exception.h:325
Manages access to the &#39;physical&#39; media, e.g CDROM drives, Disk volumes, directory trees...
Definition: MediaManager.h:473
DeviceList detectDevices(bool supportingDVD) const
Definition: MediaCD.cc:327
void forceRelaseAllMedia(bool matchMountFs)
Call to this function will try to release all media matching the currenlty attached media source...
Pathname attachPoint() const
Return the currently used attach point.
Base class for Exception.
Definition: Exception.h:143
Reference counted access to a Tp object calling a custom Dispose function when the last AutoDispose h...
Definition: AutoDispose.h:92
const std::string & mountOutput() const
virtual bool getDoesFileExist(const Pathname &filename) const
check if a file exists
Definition: MediaCD.cc:768
bool checkAttached(bool matchMountFs) const
Check actual mediaSource attachment against the current mount table of the system.
std::string getScheme() const
Returns the scheme name of the URL.
Definition: Url.cc:527
unsigned int min_nr
A minor number if source is a device.
Definition: MediaSource.h:90
std::string strerror(int errno_r)
Return string describing the error_r code.
Definition: String.cc:53
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:1
int _lastdev
number of last successful mounted device in list
Definition: MediaCD.h:36
Url url() const
Url used.
Definition: MediaHandler.h:507
Url manipulation class.
Definition: Url.h:87
void umount(const std::string &path)
umount device
Definition: Mount.cc:162
#define DBG
Definition: Logger.h:63
static bool closeTray(const std::string &device_r)
Definition: MediaCD.cc:309
static std::vector< MountEntry > getMountEntries()
Get current mount entries from /etc/mtab file.
virtual bool getDoesFileExist(const Pathname &filename) const =0
check if a file exists
virtual void getFile(const Pathname &filename) const =0
Call concrete handler to provide file below attach point.