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