1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/media/MediaManager.h
12 #ifndef ZYPP_MEDIA_MEDIAMANAGER_H
13 #define ZYPP_MEDIA_MEDIAMANAGER_H
15 #include <zypp/media/MediaAccess.h>
17 #include <zypp/base/Deprecated.h>
18 #include <zypp/base/NonCopyable.h>
19 #include <zypp/base/PtrTypes.h>
20 #include <zypp/Pathname.h>
26 //////////////////////////////////////////////////////////////////////
28 { ////////////////////////////////////////////////////////////////////
30 ////////////////////////////////////////////////////////////////////
32 { //////////////////////////////////////////////////////////////////
35 ///////////////////////////////////////////////////////////////////
36 typedef zypp::RW_pointer<MediaAccess> MediaAccessRef;
39 typedef MediaAccessId MediaId;
40 typedef unsigned int MediaNr;
43 ///////////////////////////////////////////////////////////////////
44 // forward declaration
48 ///////////////////////////////////////////////////////////////////
50 // CLASS NAME : MediaVerifierBase
53 * Interface to implement a media verifier.
55 class MediaVerifierBase //: private zypp::NonCopyable
66 ** Check if the specified attached media contains
67 ** the desired media (e.g. SLES10 CD1).
70 isDesiredMedia(const MediaAccessRef &ref) = 0;
74 ///////////////////////////////////////////////////////////////////
76 // CLASS NAME : NoVerifier
79 * Dummy default media verifier, which is always happy.
81 class NoVerifier : public MediaVerifierBase
84 NoVerifier(): MediaVerifierBase()
92 ** Don't check if the specified attached media contains
93 ** the desired media number. Always return true.
96 isDesiredMedia(const MediaAccessRef &ref)
104 ///////////////////////////////////////////////////////////////////
106 // CLASS NAME : MediaVerifierRef
109 * A shared reference to the MediaVerifier implementation.
111 typedef zypp::RW_pointer<MediaVerifierBase> MediaVerifierRef;
114 ///////////////////////////////////////////////////////////////////
116 // CLASS NAME : MediaManager
119 * Manages coordinated access to 'physical' media, e.g CDROM
120 * drives using \ref MediaAccessUrl's.
122 * \note The MediaManager class is just an envelope around an
123 * inner singleton like implementation.<br>
124 * This means, you can create as many managers as you want,
125 * also temporary in a function call.<br>
126 * Don't declare static MediaManager instances, unless
127 * you want to force (mutex) initialization order problems!
129 * \section MediaAccessUrl Media Access Url
130 * The Media Manager currently supports following access handlers
131 * (backends), that can be specified by the media access URLs in
132 * the media manager's open() method.
135 * Supports multiple CD or DVD drives.
139 * "cd:/?devices=/dev/hda,/dev/hdb"
140 * "cd:/subdir?devices=/dev/hda,/dev/hdb"
142 * "dvd:/?devices=/dev/hda,/dev/hdb"
143 * "dvd:/subdir?devices=/dev/hda,/dev/hdb"
146 * - <b>cd</b>: Requires a drive supporting CD media.
147 * - <b>dvd</b>: Requires a drive supporting DVD media.
149 * A non-empty authority URL component (e.g. containing a host
150 * name) is not allowed.
152 * Specifies a subdirectory on the CD/DVD, where the desired files
153 * are located. In case of "/", the CD/DVD's root directory (the
154 * mount point) is used.
155 * - Query parameters:
156 * - <tt>devices</tt>:
157 * Optional parameter, containing a comma separated list of block
158 * device names to use.
160 * The device names will be verified using a HAL query. If one of
161 * the provided devices is not usable (not a block device, or does
162 * not support required media type), exception is thrown.
164 * If the devices parameter is not provided (or empty), all
165 * avaliable CD/DVD drives 'detected' using a HAL query. The
166 * preferred drive (used as first drive) is the drive pointed to
167 * by the symlink "/dev/dvd" ("dvd" scheme only) or "/dev/cdrom".
172 * "nfs://nfs-server/exported/path"
173 * "nfs://nfs-server/exported/path?mountoptions=ro"
178 * The authority component has to provide a hostname.
179 * Username, password and port are currently ignored.
181 * Exported (sub-)directory on the NFS server where the desired
183 * - Query parameters:
184 * - <tt>mountoptions</tt>:
185 * The mount options separated by comma ','.
186 * Default is the "ro" option.
188 * - MediaCIFS (MediaSMB):
191 * "cifs://servername/share/path/on/the/share"
192 * "cifs://username:passwd@servername/share/path/on/the/share?mountoptions=ro"
193 * "smb://servername/share/path/on/the/share"
194 * "smb://username:passwd@servername/share/path/on/the/share?mountoptions=ro"
198 * - <b>smb</b>: Just an alias for 'cifs'.
200 * The authority component has to provide a hostname. Optionally
201 * also a username and password.
203 * The share name with optional subdirectory where the desired
205 * - Query parameters:
206 * - <tt>mountoptions</tt>:
207 * The mount options separated by a comma ','. Default are the
208 * "ro" and "guest" options.
209 * - <tt>workgroup</tt>:
210 * The name of the workgroup.
211 * - <tt>username</tt>:
212 * Alternative username to username in URL authority.
213 * - <tt>password</tt>:
214 * Alternative password to password in URL authority.
216 * Alternative username (cifs specific variant?)
218 * Alternative password (cifs specific variant?)
223 * "ftp://server/path/on/server"
224 * "http://server/path/on/server"
225 * "https://server/path/on/server"
226 * "http://user:pass@server/path"
227 * "http://user:pass@server/path?proxy=foo&proxyuser=me&proxypass=pw"
234 * The authority component has to provide a hostname. Optionally
235 * also a username and password. In case of the 'ftp' scheme,
236 * username and password defaults to 'anonymous' and 'yast2@'.
238 * The path name on the server where the desired files are located.
239 * - Query parameters:
241 * A proxy hostname or hostname and port separated by ':'.
242 * - <tt>proxyport</tt>:
243 * Alternative way to provide the proxy port.
244 * - <tt>proxyuser</tt>:
245 * The proxy username.
246 * - <tt>proxypass</tt>:
247 * The proxy password.
252 * "dir:/directory/name"
253 * "file:/directory/name"
259 * A non-empty authority URL component (e.g. containing
260 * a host name) is not allowed.
262 * Specifies a directory, where the desired files are located.
263 * - Query parameters:
269 * "hd:/?device=/dev/hda1"
270 * "hd:/subdir?device=/dev/sda1"
271 * "hd:/subdir?device=/dev/sda1&filesystem=reiserfs"
276 * A non-empty authority URL component is not allowed.
278 * Specifies a subdirectory on the disk partition, where the desired
279 * files are located. In case of "/", the partition's root directory
280 * (its mount point) is used.
281 * - Query parameters:
283 * Mandatory parameter specifying the name of the block device of
284 * the partition to mount.
285 * - <tt>filesystem</tt>:
286 * The name of the filesystem. Defaults to "auto".
291 * "iso:/?iso=/local/directory/filename.iso"
292 * "iso:/?iso=filename.iso&url=nfs://nfs-server/exported/directory"
293 * "iso:/isoSubdir?iso=urlSubdir/filename.iso&filesystem=iso9660&mnt=/urlAttachPoint&url=nfs://nfs-server/directory"
298 * A non-empty authority URL component is not allowed.
300 * Specifies a subdirectory inside of the iso file, where the desired
301 * files are located. In case of "/", the iso files's root directory
302 * (its mount point) is used.
303 * - Query parameters:
305 * Mandatory parameter specifying the name of the iso file.
306 * - If the url parameter is present, the filename can contain a
307 * relative path to the iso file below of the location pointed by
309 * - If the url parameter is missed, the iso parameter has to point
310 * to the absolute iso file name.
312 * Optional parameter specifying the iso filename's source media url
313 * pointing to a directory.
315 * Note: <i>The iso filename's source media url schemes are limited
316 * to: <b>hd</b>, <b>dir</b>, <b>file</b>,
317 * <b>nfs</b>, <b>smb</b>, <b>cifs</b>.</i>
319 * Optional parameter specifying the prefered attach point for the
321 * - <tt>filesystem</tt>:
322 * Optional name of the filesystem used in the iso file. Defaults
325 class MediaManager: private zypp::base::NonCopyable
329 * Creates a MediaManager envelope instance.
331 * In the case, that the inner implementation is not already
332 * allocated, and the MediaManager constructor was unable to
333 * allocate it, a std::bad_alloc exception is thrown.
335 * All further instances increase the use counter only.
337 * \throws std::bad_alloc
342 * Destroys MediaManager envelope instance.
343 * Decreases the use counter of the inner implementation.
348 * Opens the media access for specified with the url.
350 * If the \p preferred_attach_point parameter does not
351 * point to a usable attach point directory, the media
352 * manager automatically creates a temporary attach
353 * point in a default directory. This default directory
354 * can be changed using setAttachPrefix() function.
356 * Remember to close() each id you've opened and not
357 * need any more. It is like a new and delete!
359 * \param url The \ref MediaAccessUrl.
360 * \param preferred_attach_point The preferred, already
361 * existing directory, where the media should be
363 * \return a new media access id.
364 * \throws std::bad_alloc
365 * \throws MediaException
368 open(const Url &url, const Pathname & preferred_attach_point = "");
371 * Close the media access with specified id.
372 * \param accessId The media access id to close.
375 close(MediaAccessId accessId);
378 * Query if the media access is open / exists.
380 * \param accessId The media access id to query.
381 * \return true, if access id is known and open.
384 isOpen(MediaAccessId accessId) const;
387 * Query the protocol name used by the media access
388 * handler. Similar to url().getScheme().
390 * \param accessId The media access id to query.
391 * \return The protocol name used by the media access
392 * handler, otherwise 'unknown'.
393 * \throws MediaNotOpenException for invalid access id.
396 protocol(MediaAccessId accessId) const;
399 * Hint if files are downloaded or not.
400 * \param accessId The media access id to query.
401 * \return True, if provideFile downloads files.
404 downloads(MediaAccessId accessId) const;
407 * Returns the \ref MediaAccessUrl of the media access id.
409 * \param accessId The media access id to query.
410 * \return The \ref MediaAccessUrl used by the media access id.
411 * \throws MediaNotOpenException for invalid access id.
414 url(MediaAccessId accessId) const;
418 * Add verifier implementation for the specified media id.
419 * By default, the NoVerifier is used.
421 * \param accessId A media access id.
422 * \param verifier The new verifier.
423 * \throws MediaNotOpenException for invalid access id.
426 addVerifier(MediaAccessId accessId,
427 const MediaVerifierRef &verifier);
430 * Remove verifier for specified media id.
431 * It resets the verifier to NoVerifier.
433 * \param accessId A media access id.
434 * \throws MediaNotOpenException for invalid access id.
437 delVerifier(MediaAccessId accessId);
441 * Set or resets the directory name, where the media manager
442 * handlers create their temporary attach points (see open()
444 * It has effect to newly created temporary attach points only.
446 * \param attach_prefix The new prefix for temporary attach
447 * points, or empty pathname to reset to defaults.
448 * \return True on success, false if the \p attach_prefix
449 * parameters contains a path name, that does not
450 * point to a writable directory.
453 setAttachPrefix(const Pathname &attach_prefix);
456 * Attach the media using the concrete handler.
458 * Remember to release() or close() each id you've attached
459 * and not need any more. Attach is like an open of a file!
461 * \param accessId A media access id.
462 * \param next Whether to try the next drive if avaliable.
463 * \throws MediaNotOpenException for invalid access id.
466 attach(MediaAccessId accessId, bool next = false);
469 * Reattach to a new attach point.
471 * \deprecated This function will be removed, because the
472 * reattach function has race conditions (e.g. open file
473 * in the old attach point). Use setAttachPrefix() instead.
475 * \param accessId A media access Id.
476 * \param attach_point A new attach point directory.
477 * \param temporary Whether to reattach to a temporary
478 * attach point bellow of \p attach_point and cleanup
479 * it on release (temporary=true), or use the provided
480 * directory as attach point without to cleanup it on
481 * release (temporary=false, default behaviour).
482 * \throws MediaNotOpenException
483 * \throws MediaNotSupportedException
487 reattach(MediaAccessId accessId,
488 const Pathname &attach_point,
489 bool temporary = false) ZYPP_DEPRECATED;
493 * Release the attached media and optionally eject.
495 * If the \p eject parameter is set to true and there
496 * is currently an attached drive, all other access
497 * id's are released and the drive (CD/DVD drive) is
499 * In case that there is currently no attached drive,
500 * a \p eject set to true causes to eject all drives
501 * that are _not_ used by another access id's.
503 * \param accessId A media access id.
504 * \param eject Whether to eject the drive.
505 * \throws MediaNotOpenException for invalid access id.
508 release(MediaAccessId accessId, bool eject = false);
511 * Disconnect a remote media.
513 * This is useful for media which e.g. holds open a connection
514 * to a server like FTP. After calling disconnect() the media
515 * object (attach point) is still valid and files are present.
517 * But after calling disconnect() it's not possible to call
518 * fetch more data using the provideFile() or provideDir()
521 * \param accessId A media access id.
522 * \throws MediaNotOpenException for invalid access id.
525 disconnect(MediaAccessId accessId);
528 * Check if media is attached or not.
530 * \param accessId A media access id.
531 * \return True if media is attached.
532 * \throws MediaNotOpenException for invalid access id.
535 isAttached(MediaAccessId accessId) const;
538 * Returns information if media is on a shared
539 * physical device or not.
541 * \param accessId A media access id.
542 * \return True if it is shared, false if not.
543 * \throws MediaNotOpenException for invalid access id.
546 isSharedMedia(MediaAccessId accessId) const;
549 * Ask the registered verifier if the attached
550 * media is the desired one or not.
552 * \param accessId A media access id.
553 * \return True if media is attached and desired
554 * according to the actual verifier.
555 * \throws MediaNotOpenException for invalid access id.
558 isDesiredMedia(MediaAccessId accessId) const;
561 * Ask the specified verifier if the attached
562 * media is the desired one or not.
564 * \param accessId A media access id.
565 * \param verifier A verifier to use.
566 * \return True if media is attached and desired
567 * according to the specified verifier.
568 * \throws MediaNotOpenException for invalid access id.
571 isDesiredMedia(MediaAccessId accessId,
572 const MediaVerifierRef &verifier) const;
575 * Return the local directory that corresponds to medias url,
576 * no matter if media isAttached or not. Files requested will
577 * be available at 'localRoot() + filename' or even better
578 * 'localPath( filename )'
580 * \param accessId A media access id.
581 * \returns The directory name pointing to the media root
582 * in local filesystem or an empty pathname if the
583 * media is not attached.
584 * \throws MediaNotOpenException for invalid access id.
587 localRoot(MediaAccessId accessId) const;
590 * Shortcut for 'localRoot() + pathname', but returns an empty
591 * pathname if media is not attached.
592 * Files provided will be available at 'localPath(filename)'.
594 * \param accessId A media access id.
595 * \param pathname A path name relative to the localRoot().
596 * \returns The directory name in local filesystem pointing
597 * to the desired relative pathname on the media
598 * or an empty pathname if the media is not attached.
599 * \throws MediaNotOpenException for invalid access id.
602 localPath(MediaAccessId accessId, const Pathname & pathname) const;
606 * Provide provide file denoted by relative path below of the
607 * 'attach point' of the specified media and the path prefix
610 * \param accessId The media access id to use.
611 * \param filename The filename to provide, relative to localRoot().
612 * \param cached If cached is set to true, the function checks, if
613 * the file already exists and doesn't download it again
614 * if it does. Currently only the existence is checked,
615 * no other file attributes.
616 * \param checkonly If this and 'cached' are set to true only the
617 * existence of the file is checked but it's not
618 * downloaded. If 'cached' is unset an errer is
621 * \throws MediaNotOpenException in case of invalid access id.
622 * \throws MediaNotAttachedException in case, that the media is not attached.
623 * \throws MediaNotDesiredException in case, that the media verification failed.
624 * \throws MediaNotAFileException in case, that the requested filename is not a file.
625 * \throws MediaFileNotFoundException in case, that the requested filenamedoes not exists.
626 * \throws MediaWriteException in case, that the file can't be copied from from remote source.
627 * \throws MediaSystemException in case a system operation fails.
628 * \throws MediaException derived exception, depending on the url (handler).
631 provideFile(MediaAccessId accessId,
632 const Pathname &filename,
634 bool checkonly = false) const;
637 * FIXME: see MediaAccess class.
640 provideDir(MediaAccessId accessId,
641 const Pathname &dirname) const;
644 * FIXME: see MediaAccess class.
647 provideDirTree(MediaAccessId accessId,
648 const Pathname &dirname) const;
651 * FIXME: see MediaAccess class.
654 releaseFile(MediaAccessId accessId,
655 const Pathname &filename) const;
658 * FIXME: see MediaAccess class.
661 releaseDir(MediaAccessId accessId,
662 const Pathname &dirname) const;
665 * FIXME: see MediaAccess class.
668 releasePath(MediaAccessId accessId,
669 const Pathname &pathname) const;
672 * FIXME: see MediaAccess class.
675 dirInfo(MediaAccessId accessId,
676 std::list<std::string> &retlist,
677 const Pathname &dirname,
678 bool dots = true) const;
681 * FIXME: see MediaAccess class.
684 dirInfo(MediaAccessId accessId,
685 filesystem::DirContent &retlist,
686 const Pathname &dirname,
687 bool dots = true) const;
692 * Get the modification time of the /etc/mtab file.
693 * \return Modification time of the /etc/mtab file.
696 getMountTableMTime() const;
699 * Get current mount entries from /etc/mtab file.
700 * \return Current mount entries from /etc/mtab file.
702 std::vector<MountEntry>
703 getMountEntries() const;
706 * Check if the specified \p path is useable as
709 * \param path The attach point to check.
710 * \return True, if it is a directory and there are
711 * no another attach points bellow of it.
714 isUseableAttachPoint(const Pathname &path) const;
717 friend class MediaHandler;
721 * Return the attached media reference of the specified
722 * media access id. Used to resolve nested attachments
723 * as used in the MediaISO (iso-loop) handler.
724 * Causes temporary creation of a shared attachment
725 * (increases reference counters on attachedMedia).
726 * \param media A media access id.
729 getAttachedMedia(MediaAccessId &accessId) const;
733 * Called by media handler in while attach() to retrieve
734 * attached media reference matching the specified media
736 * Causes temporary creation of a shared attachment
737 * (increases reference counters on attachedMedia).
738 * \param media The media source reference to search for.
741 findAttachedMedia(const MediaSourceRef &media) const;
745 * Called by media handler in case of relase(eject=true)
746 * to release all access id's using the specified media.
747 * Causes temporary creation of a shared attachment
748 * (increases reference counters on attachedMedia).
749 * \param media The media source reference to release.
752 forceMediaRelease(const MediaSourceRef &media);
757 * Static reference to the implementation (singleton).
759 static zypp::RW_pointer<MediaManager::Impl> m_impl;
763 //////////////////////////////////////////////////////////////////
765 ////////////////////////////////////////////////////////////////////
767 ////////////////////////////////////////////////////////////////////
769 //////////////////////////////////////////////////////////////////////
771 #endif // ZYPP_MEDIA_MEDIAMANAGER_H
774 ** vim: set ts=2 sts=2 sw=2 ai et: