MediumImpl.cpp revision 0ff7152ccdcc57edca12c5f17b9699c66eeff975
* General Public License (GPL) as published by the Free Software * Foundation, in version 2 as it comes in the "COPYING" file of the * VirtualBox OSE distribution. VirtualBox OSE is distributed in the * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind. * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa * additional information or have any questions. //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// // constructor / destructor //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// /* m.id is constant during life time, no need to lock */ /// @todo update m.description and save the global registry (and local /// registries of portable VMs referring to this medium), this will also /// require to add the mRegistered flag to data /* queryInfo() locks this for writing. */ /// @todo NEWMEDIA for file names, add the default extension if no extension /// is present (using the information from the VD backend which also implies /// that one more parameter should be passed to setLocation() requesting /// that functionality since it is only allwed when called from this method /// @todo NEWMEDIA rename the file and set m.location on success, then save /// the global registry (and local registries of portable VMs referring to /// this medium), this will also require to add the mRegistered flag to data //////////////////////////////////////////////////////////////////////////////// /* if the medium is attached to the machine in the current state, we * return its ID as the first element of the array */ * @note @a aState may be NULL if the state value is not needed (only for /* return the current state before */ * @note @a aState may be NULL if the state value is not needed (only for /* Reset the state after the last reader */ /* otherwise, queryInfo() is in progress; fall through */ tr (
"Medium '%ls' is not locked for reading"),
/* return the current state after */ * @note @a aState may be NULL if the state value is not needed (only for /* return the current state before */ * @note @a aState may be NULL if the state value is not needed (only for tr (
"Medium '%ls' is not locked for writing"),
/* return the current state after */ /* unregisterWithVirtualBox() is assumed to always need a write mVirtualBox * lock as it is intenede to modify its internal structires. Also, we want * to unregister ourselves atomically after detecting that closure is * possible to make sure that we don't do that after another thread has done * VirtualBox::find*() but before it starts using us (provided that it holds * a mVirtualBox lock of course). */ tr (
"Medium '%ls' is attached to %d virtual machines"),
/* perform extra media-dependent close checks */ /* remove from the list of known media before performing actual * uninitialization (to keep the media registry consistent on /* cause uninit() to happen on success */ // public methods for internal purposes only //////////////////////////////////////////////////////////////////////////////// * Checks if the given change of \a aOldPath to \a aNewPath affects the location * of this media and updates it if necessary to reflect the new location. * @param aOldPath Old path (full). * @param aNewPath New path (full). * @note Locks this object for writing. * Adds the given machine and optionally the snapshot to the list of the objects * this image is attached to. * @param aMachineId Machine ID. * @param aSnapshotId Snapshot ID; when non-empty, adds a snapshot attachment. /* sanity: no duplicate attachments */ /* sanity: no duplicate attachments */ * Removes the given machine and optionally the snapshot from the list of the * objects this image is attached to. * @param aMachineId Machine ID. * @param aSnapshotId Snapshot ID; when non-empty, removes the snapshot /* remove the current state attachment */ /* remove the snapshot attachment */ /* if the backref becomes empty, remove it */ //////////////////////////////////////////////////////////////////////////////// * Returns a short version of the location attribute. * @note Must be called from under this object's read or write lock. * Sets the value of m.location and calculates the value of m.locationFull. * @param aLocation Path to the image file (can be relative to the * VirtualBox home directory). * @note Must be called from under this object's write lock. /* get the full file name */ tr (
"Invalid image file location '%ls' (%Rrc)"),
* Queries information from the image file. * As a result of this call, the accessibility state and data members such as * size and description will be updated with the current information. * @note This method may block during a system I/O call that checks image file * @note Locks this object for writing. /* check if a blocking queryInfo() call is in progress on some other thread, * and wait for it to finish if so instead of querying data ourselves */ /* last waiting caller deletes the semaphore */ /* lazily create a semaphore for possible callers */ /* Cause other methods to prevent any modifications before leaving the * lock. Note that clients will never see this temporary state change * directly since any COMGETTER(State) is (or will be) blocked until we * finish and restore the actual state. This may be seen only through * error messages reported by other methods. */ /* leave the lock before a blocking operation */ /* get image file info */ tr (
"Could not access the image file '%ls' (%Rrc)"),
/* inform other callers if there are any */ /* delete the semaphore ourselves */ /* Set the proper state according to the result of the check */ /* we're locked, use a special field to store the result */ * Sets the extended error info according to the current media state. * @note Must be called from under this object's write or read lock. tr (
"Storage for the medium '%ls' is not created"),
tr (
"Storage for the medium '%ls' is already created"),
tr (
"Medium '%ls' is locked for reading by another task"),
tr (
"Medium '%ls' is locked for writing by another task"),
/* be in sync with Console::powerUpThread() */ tr (
"Medium '%ls' is not accessible. %ls"),
tr (
"Medium '%ls' is not accessible"),
tr (
"Storage for the medium '%ls' is being created"),
tr (
"Storage for the medium '%ls' is being deleted"),
//////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// * Initializes the image medium object by opening an image file at the specified * @param aVirtualBox Parent VirtualBox object. * @param aLocation Path to the image file (can be relative to the * VirtualBox home directory). * @param aId UUID of the image. /* Enclose the state transition NotReady->InInit->Ready */ /* share parent weakly */ /* register with parent early, since uninit() will unconditionally * unregister on failure */ /* there must be a storage unit */ /* get all the information about the medium from the file */ /* if the image file is not accessible, it's not acceptable for the * newly opened media so convert this into an error */ /* Confirm a successful initialization when it's the case */ * Initializes the image medium object by loading its data from the given * Note that it is assumed that this method is called only for registered media. * @param aVirtualBox Parent VirtualBox object. * @param aImageNode Either <DVDImage> or <FloppyImage> settings node. /* Enclose the state transition NotReady->InInit->Ready */ /* share parent weakly */ /* register with parent early, since uninit() will unconditionally * unregister on failure */ /* see below why we don't call queryInfo() (and therefore treat the medium * as inaccessible for now */ /* Don't call queryInfo() for registered media to prevent the calling * thread (i.e. the VirtualBox server startup thread) from an unexpected * freeze but mark it as initially inaccessible instead. The vital UUID and * location properties are read from the registry file above; to get the * actual state and the the rest of data, the user will have to call /* Confirm a successful initialization when it's the case */ * Uninitializes the instance. * Called either from FinalRelease() or by the parent when it gets destroyed. /* Enclose the state transition Ready->InUninit->NotReady */ // public methods for internal purposes only //////////////////////////////////////////////////////////////////////////////// * Saves image data by appending a new <Image> child node to the * given <Images> parent node. * @param aImagesNode <Images> node. * @note Locks this object for reading. //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// * @note Called from within this object's AutoMayUninitSpan and from under * mVirtualBox write lock. //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// * @note Called from within this object's AutoMayUninitSpan and from under * mVirtualBox write lock.