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