List:Commits« Previous MessageNext Message »
From:Rafal Somla Date:October 21 2009 1:32pm
Subject:bzr commit into mysql-6.0-backup branch (Rafal.Somla:2881) Bug#40756
View as plain text  
#At file:///ext/mysql/bzr/backup/bug40756/ based on revid:thavamuni.alagu@stripped

 2881 Rafal Somla	2009-10-21
      Bug #40756 - Correct coding guideline violations in backup code.
      
      This patch fixes coding guidelines violations which could be found
      in backup code.

    modified:
      sql/backup/api_types.h
      sql/backup/backup_aux.h
      sql/backup/backup_engine.h
      sql/backup/backup_info.cc
      sql/backup/backup_info.h
      sql/backup/backup_kernel.h
      sql/backup/backup_test.cc
      sql/backup/be_default.cc
      sql/backup/be_default.h
      sql/backup/be_logical.h
      sql/backup/be_native.h
      sql/backup/be_nodata.cc
      sql/backup/be_nodata.h
      sql/backup/be_snapshot.cc
      sql/backup/be_snapshot.h
      sql/backup/be_thread.cc
      sql/backup/be_thread.h
      sql/backup/buffer_iterator.cc
      sql/backup/buffer_iterator.h
      sql/backup/data_backup.cc
      sql/backup/error.h
      sql/backup/image_info.cc
      sql/backup/image_info.h
      sql/backup/kernel.cc
      sql/backup/logger.cc
      sql/backup/logger.h
      sql/backup/restore_info.h
      sql/backup/stream.cc
      sql/backup/stream.h
      sql/backup/stream_v1.c
      sql/backup/stream_v1.h
      sql/backup/stream_v1_services.h
      sql/backup/stream_v1_transport.c
=== modified file 'sql/backup/api_types.h'
--- a/sql/backup/api_types.h	2008-12-18 21:46:36 +0000
+++ b/sql/backup/api_types.h	2009-10-21 13:32:24 +0000
@@ -5,7 +5,7 @@
   @file
 
   Declarations of common data types used in the backup API's
- */
+*/
 
 /*
  Note: Structures defined in this file use String class which introduces
@@ -16,7 +16,7 @@
 
  This seems to be not a problem for storage engine plugins as they use String
  class anyway.
- */
+*/
 
 /// A null string external reference.
 extern const String my_null_string;
@@ -30,12 +30,15 @@ typedef unsigned char byte;
   Values returned by backup/restore driver methods and other backup functions.
 
   @see @c Backup_driver::get_data and @c Restore_driver::send_data
- */
+*/
 
 /// Enumeration for result values.
 enum result_t { OK=0, READY, PROCESSING, BUSY, DONE, ERROR };
 
-/// Definition of version_t which is used as reference to version of backup interfaces.
+/**
+  Definition of version_t which is used as reference to version of backup
+  interfaces.
+*/
 typedef uint  version_t;
 
 //@{
@@ -44,27 +47,27 @@ typedef uint  version_t;
    Classes @c Db_ref and @c Table_ref are used to identify databases and tables
    inside mysql server instance.
 
-   These classes abstract the way a table or database is identified inside 
-   mysqld, so that when this changes (introduction of global db/table ids, 
-   introduction of catalogues) it is easy to adapt backup code to the new 
+   These classes abstract the way a table or database is identified inside
+   mysqld, so that when this changes (introduction of global db/table ids,
+   introduction of catalogues) it is easy to adapt backup code to the new
    identification schema.
 
    Regardless of the internal representation, classes provide methods returning
-   db/table name as a @c String object. Also, each table belongs to some 
+   db/table name as a @c String object. Also, each table belongs to some
    database and a method returning @c Db_ref object identifying this database is
    present. For @c Db_ref objects there is @c catalog() method returning name of
    the catalogue, but currently it always returns null string.
 
    Classes are implemented so that the memory for storing names can be allocated
-   outside an instance. This allows for sharing space used e.g., to store 
+   outside an instance. This allows for sharing space used e.g., to store
    database names among several @c Table_ref instances.
 
-   Instances of @c Table_ref and @c Db_ref should be considered cheap to use, 
-   equivalent to using pointers or other base types. Currently, single instance 
-   of each class uses as much memory as a single pointer (+some external memory 
-   to store names which can be shared among different instances). The methods 
+   Instances of @c Table_ref and @c Db_ref should be considered cheap to use,
+   equivalent to using pointers or other base types. Currently, single instance
+   of each class uses as much memory as a single pointer (+some external memory
+   to store names which can be shared among different instances). The methods
    are inlined to avoid function call costs.
- */
+*/
 
 class Db_ref
 {
@@ -72,7 +75,7 @@ class Db_ref
 
 public:
 
-  /// Construct invalid reference
+  /// Construct invalid reference.
   Db_ref() :m_name(NULL)
   {}
 
@@ -99,10 +102,10 @@ public:
 protected:
 
   // Constructors are made protected as clients of this class are
-  // not supposed to create instances (see comment inside Table_ref)
+  // not supposed to create instances (see comment inside Table_ref).
 
   /**
-    Constructor
+    Constructor.
 
     @param[in]  name  Name of the database.
   */
@@ -118,6 +121,7 @@ protected:
 
   This class is an encapsulation to allow easier access to table information.
 */
+
 class Table_ref
 {
   const Db_ref  m_db;     ///< The database for the table.
@@ -125,7 +129,7 @@ class Table_ref
 
 public:
 
-  // Construct invalid reference
+  // Construct invalid reference.
   Table_ref() :m_name(NULL)
   {}
 
@@ -155,18 +159,18 @@ public:
   /// Definition of a name buffer for the table name.
   typedef char name_buf[FN_REFLEN];
 
-  /// Produce string identifying the table (e.g. for error reporting)
+  /// Produce string identifying the table (e.g. for error reporting).
   const char* describe(char *buf, size_t len) const;
-  /// Produce string identifying the table (e.g. for error reporting)
+  /// Produce string identifying the table (e.g. for error reporting).
   const char* describe(name_buf &buf) const
   { return describe(buf, sizeof(buf)); }
 
-  /// Produce string identifying the table in internal format. 
+  /// Produce string identifying the table in internal format.
   const char* internal_name(char *buf, size_t len) const;
-  /// Produce string identifying the table in internal format. 
+  /// Produce string identifying the table in internal format.
   const char* internal_name(name_buf &buf) const
   { return internal_name(buf, sizeof(buf)); };
-  
+
 protected:
 
   /**
@@ -199,11 +203,11 @@ protected:
    Interface is made abstract, so that different implementations can be
    used in the backup code. For example it is possible to create a class which
    adds this interface to a list of tables represented by a linked list of
-   @c TABLE_LIST structures as used elsewhere in the code. On the other hand, 
-   much more space efficient implementations are possible, as for each table we 
-   need to store only table's identity (db/table name). In any case, the 
+   @c TABLE_LIST structures as used elsewhere in the code. On the other hand,
+   much more space efficient implementations are possible, as for each table we
+   need to store only table's identity (db/table name). In any case, the
    interface to the list remains the same, as defined by this class.
- */
+*/
 
 class Table_list
 {
@@ -225,7 +229,7 @@ public:
   @brief Used for data transfers between backup kernel and backup/restore
   drivers.
 
-  Apart from allocated memory a @c Buffer structure contains fields informing 
+  Apart from allocated memory a @c Buffer structure contains fields informing
   about its size and holding other information about contained data. Buffers are
   created and memory is allocated by backup kernel. It is also kernel's
   responsibility to write contents of buffers to a backup stream.
@@ -276,12 +280,13 @@ public:
   of the data in the buffer. It is possible to return no data in which case
   @c size should be zero. Such empty buffers are ignored by the
   kernel (no data is written to the archive).
- */
+*/
 
 struct Buffer
 {
-  size_t  size;       ///< size of the buffer (of memory block pointed by data).
-  uint    table_num;  ///< Number of the table to which data in the buffer belongs.
+  size_t  size;       ///< Size of the buffer (of memory block pointed by data).
+  /// Number of the table to which data in the buffer belongs.
+  uint    table_num;
   bool    last;       ///< TRUE if this is last block of data in the stream.
   byte    *data;      ///< Pointer to data area.
 
@@ -301,13 +306,15 @@ struct Buffer
   }
 };
 
-// forward declaration
+
+// Forward declarations.
 class Engine;
 class Backup_driver;
 class Restore_driver;
 
 } // backup namespace
 
+
 /// Definition of backup result value types.
 typedef backup::result_t Backup_result_t;
 /// Definition of backup engine class type.

=== modified file 'sql/backup/backup_aux.h'
--- a/sql/backup/backup_aux.h	2009-10-12 09:08:34 +0000
+++ b/sql/backup/backup_aux.h	2009-10-21 13:32:24 +0000
@@ -1,50 +1,57 @@
 #ifndef _BACKUP_AUX_H
 #define _BACKUP_AUX_H
 
-/** 
+/**
   @file
- 
-  @brief Auxiliary declarations used in MySQL backup code.
 
-*/ 
+  @brief Auxiliary declarations used in MySQL backup code.
+*/
 
 /// Definition for storage engine reference type.
 typedef st_plugin_int* storage_engine_ref;
 
-// Macro which transforms plugin_ref to storage_engine_ref
+// Macro which transforms plugin_ref to storage_engine_ref.
 #ifdef DBUG_OFF
-/// Macro to map plugin_ref to se_ref
+/// Macro to map plugin_ref to se_ref.
 #define plugin_ref_to_se_ref(A) (A)
-/// Macro to map se_ref ro plugin_ref
+/// Macro to map se_ref ro plugin_ref.
 #define se_ref_to_plugin_ref(A) (A)
 #else
-/// Macro to map plugin_ref to se_ref
+/// Macro to map plugin_ref to se_ref.
 #define plugin_ref_to_se_ref(A) ((A) ? *(A) : NULL)
-/// Macro to map se_ref ro plugin_ref
+/// Macro to map se_ref ro plugin_ref.
 #define se_ref_to_plugin_ref(A) &(A)
 #endif
 
+
 /// Return the storage engine name.
+
 inline
 const char* se_name(storage_engine_ref se)
 { return se->name.str; }
 
+
 /// Return the version of the plugin.
+
 inline
 uint se_version(storage_engine_ref se)
 { return se->plugin->version; }  // Q: Or, should it be A->plugin_dl->version?
 
+
 /// Return the pointer to the handlerton.
+
 inline
 handlerton* se_hton(storage_engine_ref se)
 { return (handlerton*)(se->data); }
 
+
 /// Return a storage engine reference by name.
+
 inline
 storage_engine_ref get_se_by_name(const LEX_STRING name)
-{ 
+{
   plugin_ref plugin= ::ha_resolve_by_name(::current_thd, &name);
-  return plugin_ref_to_se_ref(plugin); 
+  return plugin_ref_to_se_ref(plugin);
 }
 
 
@@ -54,7 +61,8 @@ namespace backup {
   Local version of LEX_STRING structure.
 
   Defines various constructors for convenience.
- */
+*/
+
 struct LEX_STRING: public ::LEX_STRING
 {
   /// Base constructor for null string.
@@ -64,7 +72,7 @@ struct LEX_STRING: public ::LEX_STRING
     length= 0;
   }
 
-  /** 
+  /**
     Constructor for LEX_STRING class.
 
     @param[in]  s  LEX_STRING string.
@@ -75,7 +83,7 @@ struct LEX_STRING: public ::LEX_STRING
     length= s.length;
   }
 
-  /** 
+  /**
     Constructor for LEX_STRING class.
 
     @param[in]  s  Character class.
@@ -86,7 +94,7 @@ struct LEX_STRING: public ::LEX_STRING
     length= strlen(s);
   }
 
-  /** 
+  /**
     Constructor for LEX_STRING class.
 
     @param[in]  s  String class.
@@ -116,16 +124,18 @@ struct LEX_STRING: public ::LEX_STRING
   }
 };
 
+
 /**
   Local version of String class.
 
   Defines various constructors for convenience.
  */
+
 class String: public ::String
 {
 public:
 
-  /** 
+  /**
     Constructor for string class.
 
     @param[in]  s  String class.
@@ -133,7 +143,7 @@ public:
   String(const ::String &s) : ::String(s)
   {}
 
-  /** 
+  /**
     Constructor for string class.
 
     @param[in]  s  LEX_STRING string.
@@ -146,9 +156,9 @@ public:
   }
 
   /**
-     Constructor 
+     Constructor.
 
-     This constructor takes a begging and ending pointer to construct the
+     This constructor takes a begin and end pointer to construct the
      string.
 
      @param[in]  begin  Pointer to start of string.
@@ -159,21 +169,22 @@ public:
   {
     // Check that string length is correct.
     DBUG_ASSERT(begin <= end);
-    /* 
+    /*
       This complex expression checks that the pointer difference fits into
       uint32 type reagardless of the size of pointer type and without generating
       compiler warnings (hopefully).
-      
+
       The idea is to check that in the difference (Which is positive) no bits
       beyond the ones used by unit32 type are set.
     */
     DBUG_ASSERT(!((size_t)(end - begin) & ~((size_t)~((uint32)0))));
 
+    // Note: explicit cast is needed to disambiguate.
     if (!begin)
-     set((char*)NULL, 0, NULL); // Note: explicit cast is needed to disambiguate.
+     set((char*)NULL, 0, NULL);
   }
 
-  /** 
+  /**
     Constructor for string class.
 
     @param[in]  s  Character string.
@@ -197,8 +208,9 @@ public:
 
   @retval  TABLE_LIST
 */
+
 inline
-TABLE_LIST* mk_table_list(const Table_ref &tbl, thr_lock_type lock_type, 
+TABLE_LIST* mk_table_list(const Table_ref &tbl, thr_lock_type lock_type,
                           MEM_ROOT *mem)
 {
   DBUG_ASSERT(mem);
@@ -217,14 +229,16 @@ TABLE_LIST* mk_table_list(const Table_re
   return ptr;
 }
 
+
 /**
   Link two table lists together.
 
   @param[in] tl   The list to append onto.
   @param[in] next The list to append.
-  
+
   @returns New list pointer.
 */
+
 inline
 TABLE_LIST* link_table_list(TABLE_LIST &tl, TABLE_LIST *next)
 {
@@ -232,102 +246,106 @@ TABLE_LIST* link_table_list(TABLE_LIST &
   return &tl;
 }
 
+
 TABLE_LIST *build_table_list(const Table_list &tables, thr_lock_type lock);
 void free_table_list(TABLE_LIST* tables);
 
 } // backup namespace
 
+
 /**
   Implements a dynamic map from A to B* (also known as hash array).
-  
-  An instance @c map of class @c Map<A,B> can store mappings from values of 
+
+  An instance @c map of class @c Map<A,B> can store mappings from values of
   type @c A to pointers of type @c B*. Such mappings are added with
   @code
    A a;
    B *ptr;
-   
+
    map.insert(a,ptr);
   @endcode
-  
+
   Later, one can examine the pointer assigned to a given value using operator[]
   @code
    A a
    B *ptr= map[a]
   @endcode
-  
-  If no mapping for the value a was defined, then returned pointer is NULL. 
-  
-  In case type @c A is @c int we obtain a dynamic array where pointers are 
+
+  If no mapping for the value a was defined, then returned pointer is NULL.
+
+  In case type @c A is @c int we obtain a dynamic array where pointers are
   stored at indicated positions.
   @code
-  
+
   Map<uint,B> map;
-  
+
   B x,y;
-  
+
   map.insert(1,&x);
   map.insert(7,&y);
-  
+
   B *p1= map[1];  // p1 points at x
   B *p2= map[2];  // p2 is NULL
   @endcode
-  
+
   However, it is also possible to have the pointers indexed by more complex
   values.
 
   @note We assume that type A has (fast) copy constructor.
- */ 
+*/
+
 template<class A, class B>
 class Map
 {
   HASH     m_hash;      ///< For implementing the map.
-  MEM_ROOT mem_root;    ///< For storing hash nodes
-  
+  MEM_ROOT mem_root;    ///< For storing hash nodes.
+
 public:
 
-  /// Constructor
+  /// Constructor.
   Map(size_t);
   ~Map();
 
   int insert(const A&, B*);
   B* operator[](const A&) const;
-  
+
 private:
- 
+
   struct Node;
 };
 
+
 /*****************************************************************
- 
+
   Implementation of Map template using HASH type.
- 
- *****************************************************************/
 
+ *****************************************************************/
 
 /**
   Nodes inserted into HASH table.
 
-  @note Such nodes can be allocated within a Map instance using placement 
+  @note Such nodes can be allocated within a Map instance using placement
   @c new() operator. In that case the memory will be freed when the instance
   is destroyed.
-*/  
+*/
+
 template<class A, class B>
 struct Map<A,B>::Node
 {
-  /* 
+  /*
     Note: In the HASH handling code we assume that first sizeof(A) bytes
     of this structure contain the key value. Therefore it is important that
     Map<A,B>::Node is a POD, without a base class and without virtual table
     which would change the alignment of the key member.
-   */
-  A key;   ///< key or index in hash/map.
-  B *ptr;  ///< pointer to item in hash/map.
+  */
+  A key;   ///< Key or index in hash/map.
+  B *ptr;  ///< Pointer to item in hash/map.
 
-  /// Constructor
+  /// Constructor.
   Node(const A &a, B *b) :key(a), ptr(b) {}
 
   static void *operator new(size_t size, Map<A,B> *map) throw ()
-  { 
+  {
     DBUG_ASSERT(map);
     return alloc_root(&(map->mem_root), size);
   }
@@ -349,22 +367,25 @@ Map<A,B>::Map(size_t init_size)
     never exceeds the maximal value of ulong and check this here
     with assertion.
   */
-  
+
   DBUG_ASSERT(init_size <= (size_t)(ulong)(~(ulong)0));
-  
+
   my_hash_init(&m_hash, &::my_charset_bin, (ulong)init_size,
                0, sizeof(A), NULL, NULL, MYF(0));
 }
 
+
 template<class A, class B>
 inline
 Map<A,B>::~Map()
 {
   my_hash_free(&m_hash);
-  free_root(&mem_root,MYF(0));
+  free_root(&mem_root, MYF(0));
 }
 
+
 /// Insert new mapping.
+
 template<class A, class B>
 inline
 int Map<A,B>::insert(const A &a, B *b)
@@ -374,29 +395,32 @@ int Map<A,B>::insert(const A &a, B *b)
   return my_hash_insert(&m_hash, (uchar*) n);
 }
 
+
 /// Get pointer corresponding to the given value.
+
 template<class A, class B>
 inline
 B* Map<A,B>::operator[](const A &a) const
 {
   Node *n= (Node*) my_hash_search(&m_hash, (uchar*) &a, sizeof(A));
-  
+
   return n ? n->ptr : NULL;
 }
 
 
 /**
-  Specialization of Map template with integer indexes implemented as a 
+  Specialization of Map template with integer indexes implemented as a
   Dynamic_array.
- */ 
+*/
+
 template<class T>
 class Map<uint,T>: public ::Dynamic_array< T* >
 {
   typedef Dynamic_array< T* > Base;
-  
+
 public:
 
-  /// Constructor
+  /// Constructor.
   Map(uint init_size, uint increment);
 
   /**
@@ -407,15 +431,16 @@ public:
     @returns The item and position @c pos.
   */
   T* operator[](ulong pos) const;
+
   /**
     Insert an item in the map.
 
     @param[in]  pos  Desired position.
-    @param[in]  ptr  Item to insert. 
+    @param[in]  ptr  Item to insert.
 
     @retval  Status of insert.
   */
-  int insert(ulong pos, T *ptr); 
+  int insert(ulong pos, T *ptr);
   ulong count() const;
 
 private:
@@ -423,6 +448,7 @@ private:
    void clear_free_space();
 };
 
+
 template<class T>
 inline
 Map<uint,T>::Map(uint init_size, uint increment) :Base(init_size, increment)
@@ -430,6 +456,7 @@ Map<uint,T>::Map(uint init_size, uint in
   clear_free_space();
 }
 
+
 template<class T>
 inline
 void Map<uint,T>::clear_free_space()
@@ -439,13 +466,14 @@ void Map<uint,T>::clear_free_space()
    /*
      Note: array_ptr is needed because dynamic_array_ptr() is a macro
      which applies -> operator to its argument.
-   */ 
+   */
    uchar *start= dynamic_array_ptr(array_ptr, array_ptr->elements);
    uchar *end= dynamic_array_ptr(array_ptr, array_ptr->max_element);
    if (end > start)
      bzero(start, end - start);
 }
 
+
 template<class T>
 inline
 int Map<uint,T>::insert(ulong pos, T *ptr)
@@ -470,10 +498,11 @@ int Map<uint,T>::insert(ulong pos, T *pt
 
   entry= dynamic_array_ptr(array_ptr, pos);
   *(T**)entry= ptr;
-   
+
   return 0;
 }
- 
+
+
 template<class T>
 inline
 T* Map<uint,T>::operator[](ulong pos) const
@@ -484,12 +513,14 @@ T* Map<uint,T>::operator[](ulong pos) co
   return Base::at(pos);
 }
 
-/** 
+
+/**
   Return number of entries in the dynamic array.
- 
+
   @note Some of the entries can store NULL pointers as no mapping was
   defined for them.
  */
+
 template<class T>
 inline
 ulong Map<uint,T>::count() const

=== modified file 'sql/backup/backup_engine.h'
--- a/sql/backup/backup_engine.h	2009-10-12 09:08:34 +0000
+++ b/sql/backup/backup_engine.h	2009-10-21 13:32:24 +0000
@@ -7,7 +7,7 @@
 
 /**
  @file backup_engine.h
- @brief Backup engine and backup/restore driver API
+ @brief Backup engine and backup/restore driver API.
 
  The interface between MySQL backup kernel and a backup solution has form of
  two abstract classes: @c Backup_driver implementing backup
@@ -15,13 +15,14 @@
  Instances of these two classes are created by a factory class
  @c Backup_engine which encapsulates and represents the backup
  solution as a whole.
- */
+*/
 
 #include <backup/api_types.h>
 
 namespace backup {
 
-// Forward declarations
+// Forward declarations.
+
 class Backup_driver;
 class Restore_driver;
 
@@ -41,7 +42,7 @@ class Restore_driver;
  class as they might be used by the kernel to query backup capabilities of an
  engine. On the other hand, kernel will take care to create driver instances
  only when they are really needed.
- */
+*/
 
 class Engine
 {
@@ -134,8 +135,9 @@ class Driver
 public:
 
   /// Types of backup/restore operations.
-  enum enum_flags { FULL    =0x1,  ///< concerns all tables from given storage engine
-                    PARTIAL =0     ///< backup/restore only selected tables
+  enum enum_flags { /// Concerns all tables from given storage engine.
+                    FULL    =0x1,
+                    PARTIAL =0     ///< Backup/restore only selected tables.
                   };
 
   /// Construct from list of tables. The list is stored for future use.
@@ -150,17 +152,15 @@ public:
    serve requests for sending/receiving image data.
 
    @param buf_size (in)  this is the minimal size of buffers backup kernel
-                         will provide in @c get_data(), @c send_data() methods. 
-                         The buffer can be actually bigger (and its real size 
-                         will be stored in buffers size member) but it will 
+                         will provide in @c get_data(), @c send_data() methods.
+                         The buffer can be actually bigger (and its real size
+                         will be stored in buffers size member) but it will
                          never be smaller.
 
    @return  Error code or @c OK on success.
   */
-
   virtual result_t  begin(const size_t buf_size) =0;
 
-
   /**
    @brief Finalize backup/restore process.
 
@@ -175,7 +175,6 @@ public:
 
    @return  Error code or @c OK on success.
   */
-
   virtual result_t  end()   =0;
 
   /// Cancel ongoing backup/restore process.
@@ -251,7 +250,7 @@ protected:
  @note The list of tables being backed-up is accessible via @c m_tables
  member inherited from @c Driver class
 
- @see Methods @c begin(), @c end(), @c get_data(), @c prelock(), @c lock(), 
+ @see Methods @c begin(), @c end(), @c get_data(), @c prelock(), @c lock(),
  @c unlock() and @c Driver class.
 */
 
@@ -259,286 +258,276 @@ class Backup_driver: public Driver
 {
 public:
 
-  /// Constructor
+  /// Constructor.
   Backup_driver(const Table_list &tables) :Driver(tables) {};
 
   virtual ~Backup_driver() {}; // We will derive from this class.
 
- /**
-   @fn result_t get_data(Buffer &buf)
+  /**
+    @fn result_t get_data(Buffer &buf)
 
-   @brief Accept a request for filling a buffer with next chunk of backup data
-   or check status of a previously accepted request.
+    @brief Accept a request for filling a buffer with next chunk of backup data
+    or check status of a previously accepted request.
 
-   Backup driver can implement its own policy of handling these requests. It can
-   return immediately from the call and use a separate thread to fill the buffer
-   or the calling thread can be used to do the job. It is also possible that
-   a driver accepts new requests while processing old ones, implementing
-   internal queue of requests.
-
-   The kernel learns about what happened to the request from the value returned
-   by the method (see below). The returned value is also used to inform the
-   kernel that the driver has finished the initial transfer phase (2) or the
-   prepare to lock phase (4) (see description of the class).
-
-   When a request is completed, members of @c buf should be filled
-   as described in the documentation of Buffer class. It is possible to complete
-   a request without putting any data in the buffer. In that case
-   @c buf.size should be set to zero. The return value (OK or READY)
-   and the @c buf.table_num and @c buf.last members are
-   interpreted as usual. However, no data is written to backup archive and such
-   empty buffers are not sent back to restore driver.
-
-
-   @param  buf (in/out) buffer to be filled with backup data. Its members are
-               initialized by backup kernel: @c buf.data points to a memory area 
-               where the data should be placed and @c buf.size is the size of 
-               the area. Upon completion of the request (@c OK or @c READY
-               returned), members of @c buf should be filled as described in 
-               the documentation of Buffer class.
-
-   @retval OK  The request is completed - new data is in the buffer and
-               @c size, @c table_num and @c last members of the buffer structure
-               are set accordingly.
-
-   @retval READY Same as OK and additionally informs that the initial transfer
-               phase (2) or the prepare to lock phase (4) are finished for that
-               driver.
-
-   @retval DONE Same as OK but also indicates that the backup process is
-               completed. This result can be returned only in the final transfer
-               phase (7).
-
-   @retval PROCESSING The request was accepted but is not completed yet. Further
-               calls to get_data() are needed to complete it (until it returns
-               OK or READY). Kernel will not reuse the buffer before it knows
-               that it is completely filled with data.
-
-   @retval BUSY The request can not be accepted now. Kernel can try to place a
-               request later. The buffer is not blocked and can be used for
-               other transfers.
-
-   @retval ERROR An error has happened while processing the request.
-
-   @note
-   If backup kernel calls @c get_data() when there is no more data
-   to be sent, the driver should:
-   -# set @c buf.size and @c buf.table_num to 0,
-   -# set @c buf.last to TRUE,
-   -# return @c DONE.
+    Backup driver can implement its own policy of handling these requests. It 
+    can return immediately from the call and use a separate thread to fill the 
+    buffer or the calling thread can be used to do the job. It is also possible 
+    that a driver accepts new requests while processing old ones, implementing
+    internal queue of requests.
+
+    The kernel learns about what happened to the request from the value returned
+    by the method (see below). The returned value is also used to inform the
+    kernel that the driver has finished the initial transfer phase (2) or the
+    prepare to lock phase (4) (see description of the class).
+
+    When a request is completed, members of @c buf should be filled as described 
+    in the documentation of Buffer class. It is possible to complete a request 
+    without putting any data in the buffer. In that case @c buf.size should be 
+    set to zero. The return value (OK or READY) and the @c buf.table_num and 
+    @c buf.last members are interpreted as usual. However, no data is written 
+    to backup archive and such empty buffers are not sent back to restore 
+    driver.
+
+
+    @param  buf (in/out) buffer to be filled with backup data. Its members are
+                initialized by backup kernel: @c buf.data points to a memory 
+                area where the data should be placed and @c buf.size is the 
+                size of the area. Upon completion of the request (@c OK or 
+                @c READY returned), members of @c buf should be filled as 
+                described in the documentation of @c Buffer class.
+
+    @retval OK  The request is completed - new data is in the buffer and
+                @c size, @c table_num and @c last members of the buffer 
+                structure are set accordingly.
+
+    @retval READY Same as OK and additionally informs that the initial transfer
+                phase (2) or the prepare to lock phase (4) are finished for that
+                driver.
+
+    @retval DONE Same as OK but also indicates that the backup process is
+                completed. This result can be returned only in the final 
+                transfer phase (7).
+
+    @retval PROCESSING The request was accepted but is not completed yet. 
+                Further calls to get_data() are needed to complete it (until it
+                returns OK or READY). Kernel will not reuse the buffer before 
+                it knows that it is completely filled with data.
+
+    @retval BUSY The request can not be accepted now. Kernel can try to place a
+                request later. The buffer is not blocked and can be used for
+                other transfers.
+
+    @retval ERROR An error has happened while processing the request.
+
+    @note
+    If backup kernel calls @c get_data() when there is no more data
+    to be sent, the driver should:
+    -# set @c buf.size and @c buf.table_num to 0,
+    -# set @c buf.last to TRUE,
+    -# return @c DONE.
 
-   @see @c Buffer class.
+    @see @c Buffer class.
   */
-
   virtual result_t  get_data(Buffer &buf) =0;
 
-
   /**
-   @fn result_t prelock()
+    @fn result_t prelock()
 
-   @brief Prepare for synchronization of backup image.
+    @brief Prepare for synchronization of backup image.
 
-   This method is called by backup kernel when all engines participating in
-   creation of the backup have finished their initial data transfer. After this
-   call the driver should prepare for the following @c lock() call
-   from the kernel.
-
-   It can do the preparations inside the @c prelock() method if it
-   doesn't require too long time. In that case it should return
-   @c READY. If the preparations require longer time (waiting for
-   ongoing operations to finish) or sending additional data to the kernel then
-   @c prelock() should return @c OK. Later on, the kernel
-   will call @c get_data() and driver can signal that it has finished
-   the preparations by returning @c READY result.
+    This method is called by backup kernel when all engines participating in
+    creation of the backup have finished their initial data transfer. After this
+    call the driver should prepare for the following @c lock() call
+    from the kernel.
+
+    It can do the preparations inside the @c prelock() method if it
+    doesn't require too long time. In that case it should return
+    @c READY. If the preparations require longer time (waiting for
+    ongoing operations to finish) or sending additional data to the kernel then
+    @c prelock() should return @c OK. Later on, the kernel
+    will call @c get_data() and driver can signal that it has finished
+    the preparations by returning @c READY result.
 
-   @retval READY The driver is ready for synchronization, i.e. it can accept the
-              following @c lock() call.
+    @retval READY The driver is ready for synchronization, i.e. it can accept 
+               the following @c lock() call.
 
-   @retval OK The driver is preparing for synchronization. Kernel should call
-              @c get_data() and wait until driver is ready.
+    @retval OK The driver is preparing for synchronization. Kernel should call
+               @c get_data() and wait until driver is ready.
 
-   @retval ERROR The driver can not prepare for synchronization.
+    @retval ERROR The driver can not prepare for synchronization.
   */
-
   virtual result_t  prelock()
   {  return READY; };
 
   /**
-   @brief Create validity point and freeze all backed-up data.
+    @brief Create validity point and freeze all backed-up data.
 
-   After sending @c prelock() requests to all backup drivers and
-   receiving @c READY confirmations, backup kernel calls
-   @c lock() method of each driver. The driver is supposed to do two
-   things in response:
-
-   -# Create a validity point of its backup image. The whole backup image should
-      describe data at this exact point in time.
-   -# Freeze its state until the following @c unlock() call. This
-      means that from now on the data stored in the backed-up tables should not
-      change in any way, so that the validity point remains valid during the
-      time other engines create their own validity points.
-
-   When all drivers have locked, backup kernel will call @c unlock()
-   on all of them. After this call the driver should unfreeze. Kernel will
-   continue polling backup data using @c get_data() method until
-   driver signals that there is no more data to be sent.
-
-   @note <b>Important!</b>. A call to @c lock() should return as
-   quickly as possible since it blocks other drivers. Ideally, only fast memory
-   access and/or (non-blocking) mutex manipulations should happen but no disk
-   operations. The backup kernel expects that this call will return in at most
-   few seconds.
+    After sending @c prelock() requests to all backup drivers and
+    receiving @c READY confirmations, backup kernel calls
+    @c lock() method of each driver. The driver is supposed to do two
+    things in response:
+
+    -# Create a validity point of its backup image. The whole backup image 
+       should describe data at this exact point in time.
+    -# Freeze its state until the following @c unlock() call. This
+       means that from now on the data stored in the backed-up tables should not
+       change in any way, so that the validity point remains valid during the
+       time other engines create their own validity points.
+
+    When all drivers have locked, backup kernel will call @c unlock()
+    on all of them. After this call the driver should unfreeze. Kernel will
+    continue polling backup data using @c get_data() method until
+    driver signals that there is no more data to be sent.
+
+    @note <b>Important!</b>. A call to @c lock() should return as
+    quickly as possible since it blocks other drivers. Ideally, only fast memory
+    access and/or (non-blocking) mutex manipulations should happen but no disk
+    operations. The backup kernel expects that this call will return in at most
+    few seconds.
 
-   @returns Error code or @c OK upon success.
+    @returns Error code or @c OK upon success.
   */
-
   virtual result_t  lock() =0;
 
   /**
-   @brief Unlock data after the @c lock() call.
+    @brief Unlock data after the @c lock() call.
 
-   After call to @c unlock() driver enters the final data transfer
-   phase. Any remaining data should be sent in the following
-   @c get_data() calls and all data streams should be closed. The
-   process is ended by returning @c DONE from the last
-   @c get_data() call.
-
-   @note <b>Important!</b>. Similar as with @c lock(), a call to
-   @c unlock() should return as quickly as possible to not block other
-   drivers.
+    After call to @c unlock() driver enters the final data transfer
+    phase. Any remaining data should be sent in the following
+    @c get_data() calls and all data streams should be closed. The
+    process is ended by returning @c DONE from the last
+    @c get_data() call.
+
+    @note <b>Important!</b>. Similar as with @c lock(), a call to
+    @c unlock() should return as quickly as possible to not block other
+    drivers.
   */
-
   virtual result_t  unlock() =0;
 
-
   /**
-   Return estimate (in bytes) of the size of the backup image.
+    Return estimate (in bytes) of the size of the backup image.
 
-   This estimate is used by backup kernel to give backup progress feedback to
-   users.
-   If estimating the size is impossible or very costly, the driver can return
-   @c UNKNOWN_SIZE.
+    This estimate is used by backup kernel to give backup progress feedback to
+    users.
+    If estimating the size is impossible or very costly, the driver can return
+    @c UNKNOWN_SIZE.
   */
-
   virtual size_t    size() =0;
 
   /**
-   Estimate how much data will be sent in the initial phase of backup.
+    Estimate how much data will be sent in the initial phase of backup.
 
-   This information is used by backup kernel to initialize backup drivers of
-   different types at correct times. Roughly, drivers with biggest
-   @c init_size() will be initialized and polled first. Drivers whose
-   @c init_size() is zero, will be initialized and polled last in the
-   process.
-
-   Thus "at begin" drivers which send all backup data in the final phase
-   of backup should return 0 here. Drivers of "at end" type should return
-   estimate for the size of data to be sent before they are ready for validity
-   point creation. If estimating this size is impossible or very expensive, the
-   driver can return UNKNOWN_SIZE. In that case  the driver will be initialized
-   and polled before any other drivers.
+    This information is used by backup kernel to initialize backup drivers of
+    different types at correct times. Roughly, drivers with biggest
+    @c init_size() will be initialized and polled first. Drivers whose
+    @c init_size() is zero, will be initialized and polled last in the
+    process.
+
+    Thus "at begin" drivers which send all backup data in the final phase
+    of backup should return 0 here. Drivers of "at end" type should return
+    estimate for the size of data to be sent before they are ready for validity
+    point creation. If estimating this size is impossible or very expensive, the
+    driver can return UNKNOWN_SIZE. In that case  the driver will be initialized
+    and polled before any other drivers.
   */
-
   virtual size_t    init_size() =0;
 
 }; // Backup_driver class
 
+
 /**
- @class Restore_driver
+  @class Restore_driver
 
- @brief Represents restore driver used for restoring a given list of tables.
+  @brief Represents restore driver used for restoring a given list of tables.
 
- This class provides all the methods used to implement the restore protocol
- for communication between backup kernel and the driver. Apart from the common
- driver methods of @c Driver class it provides
- @c send_data() method which is used by the kernel to send
- backup image data to the driver.
+  This class provides all the methods used to implement the restore protocol
+  for communication between backup kernel and the driver. Apart from the common
+  driver methods of @c Driver class it provides
+  @c send_data() method which is used by the kernel to send
+  backup image data to the driver.
 
- It is assumed that all tables are blocked during restore process.
+  It is assumed that all tables are blocked during restore process.
 
- @note The list of tables being restored is accessible via @c m_tables
- member inherited from @c Driver class
+  @note The list of tables being restored is accessible via @c m_tables
+  member inherited from @c Driver class
 
- @see @c Driver class.
+  @see @c Driver class.
 */
 
 class Restore_driver: public Driver
 {
 public:
 
-  /// Constructor
+  /// Constructor.
   Restore_driver(const Table_list &tables) :Driver(tables) {};
   virtual ~Restore_driver() {};
 
   /**
-   @fn result_t send_data(Buffer &buf)
+    @fn result_t send_data(Buffer &buf)
 
-   @brief Request processing of next block of backup image data or check
-   status of a previously accepted request.
+    @brief Request processing of next block of backup image data or check
+    status of a previously accepted request.
 
-   Upon restore, backup kernel calls this method periodically sending
-   consecutive blocks of data from the backup image. The @c table_num
-   field in the buffer is set to indicate from which stream the data comes.
-   Also, @c buf.last is TRUE if this is the last block
-   in the stream.
-
-   Blocks are sent to restore driver in the same order in which they were
-   created by a backup driver. This is true also when only selected blocks are
-   sent.
-
-   Restore driver can implement its own policy of handling data processing
-   requests. It is possible that it returns immediately from the call and uses
-   a separate thread to process data in the buffer and it is also possible that
-   the calling thread is used to do the job.
-
-   Returning OK means that the data has been successfully processed
-   and the buffer can be re-used for further transfers. If method returns
-   PROCESSING, it means that the request was accepted but is not
-   completed yet. The buffer will not be used for other purposes until a further
-   call to @c send_data() with the same buffer as argument returns OK.
-
-   @param  buf   (in) buffer filled with backup data. Fields @c size,
-                 @c table_num and @c last are set
-                 accordingly.
-
-   @retval OK    The data has been successfully processed - the buffer can be
-                 used for other transfers.
-
-   @retval DONE  Same as OK but also indicates that the restore process is
-                 completed.
-
-   @retval PROCESSING  The request was accepted but data is not processed yet -
-                 further calls to @c send_data() are needed to
-                 complete it. The buffer is blocked and can't be used for other
-                 transfers.
-
-   @retval BUSY  The request can not be processed right now. A call to
-                 @c send_data() should be repeated later.
-
-   @retval ERROR An error has happened. The request is cancelled and the buffer
-                 can be used for other transfers.
-
-   @note
-   Reporting ERROR means that restore process has been interrupted and can not 
-   be continued. The driver is assumed to be in error state and backup kernel 
-   will not call any of its methods except for @c free().
+    Upon restore, backup kernel calls this method periodically sending
+    consecutive blocks of data from the backup image. The @c table_num
+    field in the buffer is set to indicate from which stream the data comes.
+    Also, @c buf.last is TRUE if this is the last block
+    in the stream.
+
+    Blocks are sent to restore driver in the same order in which they were
+    created by a backup driver. This is true also when only selected blocks are
+    sent.
+
+    Restore driver can implement its own policy of handling data processing
+    requests. It is possible that it returns immediately from the call and uses
+    a separate thread to process data in the buffer and it is also possible that
+    the calling thread is used to do the job.
+
+    Returning OK means that the data has been successfully processed
+    and the buffer can be re-used for further transfers. If method returns
+    PROCESSING, it means that the request was accepted but is not
+    completed yet. The buffer will not be used for other purposes until 
+    a further call to @c send_data() with the same buffer as argument returns 
+    OK.
+
+    @param  buf   (in) buffer filled with backup data. Fields @c size,
+                  @c table_num and @c last are set
+                  accordingly.
+
+    @retval OK    The data has been successfully processed - the buffer can be
+                  used for other transfers.
+
+    @retval DONE  Same as OK but also indicates that the restore process is
+                  completed.
+
+    @retval PROCESSING  The request was accepted but data is not processed yet -
+                  further calls to @c send_data() are needed to
+                  complete it. The buffer is blocked and can't be used for other
+                  transfers.
+
+    @retval BUSY  The request can not be processed right now. A call to
+                  @c send_data() should be repeated later.
+
+    @retval ERROR An error has happened. The request is cancelled and the buffer
+                  can be used for other transfers.
+
+    @note
+    Reporting ERROR means that restore process has been interrupted and can not
+    be continued. The driver is assumed to be in error state and backup kernel
+    will not call any of its methods except for @c free().
 
-   @see @c Buffer class.
+    @see @c Buffer class.
   */
-
   virtual result_t  send_data(Buffer &buf) =0;
 
 }; // Restore_driver
 
-
-
-
 } // backup namespace
 
-// export Backup/Restore_driver classes to global namespace
+
+// Export Backup/Restore_driver classes to global namespace.
 
 using backup::Backup_driver;
 using backup::Restore_driver;
 
-
 #endif

=== modified file 'sql/backup/backup_info.cc'
--- a/sql/backup/backup_info.cc	2009-10-12 09:08:34 +0000
+++ b/sql/backup/backup_info.cc	2009-10-21 13:32:24 +0000
@@ -19,7 +19,6 @@
   Implementation of @c Backup_info class. Method @c find_backup_engine()
   implements algorithm for selecting backup engine used to backup
   given table.
-  
 */
 
 #include "../mysql_priv.h"
@@ -32,7 +31,9 @@
 #include "be_snapshot.h"
 #include "be_nodata.h"
 
+
 /// Return storage engine of a given table.
+
 static
 storage_engine_ref get_storage_engine(THD *thd, const backup::Table_ref &tbl)
 {
@@ -45,7 +46,7 @@ storage_engine_ref get_storage_engine(TH
   ::build_table_filename(path, sizeof(path), db, name, "", 0);
 
   ::TABLE *table= ::open_temporary_table(thd, path, db, name,
-                    FALSE /* don't link to thd->temporary_tables */,
+                    FALSE /* Don't link to thd->temporary_tables. */,
                     OTM_OPEN);
   if (table)
   {
@@ -54,7 +55,7 @@ storage_engine_ref get_storage_engine(TH
 #ifdef WITH_PARTITION_STORAGE_ENGINE
     /*
       Further check for underlying storage engine is needed
-      if table is partitioned
+      if table is partitioned.
     */
 
     storage_engine_ref se_tmp= NULL;
@@ -64,7 +65,7 @@ storage_engine_ref get_storage_engine(TH
       partition_info *p_info=  table->part_info;
       List_iterator<partition_element> p_it(p_info->partitions);
       partition_element *p_el;
-      
+
       while ((p_el= p_it++))
       {
         if (!se_tmp)
@@ -72,45 +73,47 @@ storage_engine_ref get_storage_engine(TH
           se_tmp= hton2plugin[p_el->engine_type->slot];
           ::handlerton *h= se_hton(se_tmp);
 
-          /* 
+          /*
              Native drivers don't support partitioning. Let Falcon and
              InnoDB use Snapshot driver; all other storage engines use
              Default.
           */
-          if (h->start_consistent_snapshot == NULL) 
-            goto close; // This is not a Falcon or InnoDB storage engine
+          if (h->start_consistent_snapshot == NULL)
+            goto close; // This is not a Falcon or InnoDB storage engine.
 
           continue;
         }
 
-        // use Default driver if partitions have different storage engines
+        // Use Default driver if partitions have different storage engines.
         if (se_tmp != hton2plugin[p_el->engine_type->slot])
           goto close;
       };
-      
+
       se= se_tmp;
     }
 #endif
 
  close:
-  
+
     ::intern_close_table(table);
     my_free(table, MYF(0));
   }
-  
+
   return se;
 }
 
+
 #ifndef DBUG_OFF
 
 /**
   Dummy backup engine factory function.
-  
+
   This factory function never creates any backup engines - it always returns
   ERROR. It is used in @c has_native_backup() method for testing purposes.
-  
-  @return Always ERROR. 
+
+  @return Always ERROR.
 */
+
 static
 Backup_result_t dummy_backup_engine_factory(handlerton*, Backup_engine* &eng)
 {
@@ -119,6 +122,7 @@ Backup_result_t dummy_backup_engine_fact
 }
 #endif
 
+
 static
 bool has_native_backup(storage_engine_ref se)
 {
@@ -127,62 +131,64 @@ bool has_native_backup(storage_engine_re
   return hton && hton->get_backup_engine;
 }
 
+
 /**
   Find backup engine which can backup data of a given table.
 
   @param[in] tbl  the table to be backed-up
 
-  @returns pointer to a Snapshot_info instance representing 
-  snapshot to which the given table can be added. 
- */
-backup::Snapshot_info* 
+  @returns pointer to a Snapshot_info instance representing
+  snapshot to which the given table can be added.
+*/
+
+backup::Snapshot_info*
 Backup_info::find_backup_engine(const backup::Table_ref &tbl)
 {
   using namespace backup;
 
   Table_ref::name_buf buf;
   Snapshot_info *snap= NULL;
-  
+
   DBUG_ENTER("Backup_info::find_backup_engine");
 
-  // See if table has native backup engine
+  // See if table has native backup engine.
 
   storage_engine_ref se= get_storage_engine(m_thd, tbl);
-  
+
   if (!se)
   {
     m_log.report_error(ER_NO_STORAGE_ENGINE, tbl.describe(buf));
     DBUG_RETURN(NULL);
   }
-  
+
   /*
-    The code below is used to test the backup engine selection logic. 
-    
-    In case a storage engine defines the handlerton::get_backup_engine pointer 
-    but the factory function pointed by it refuses to create a backup engine, 
-    backup kernel should try to use built-in backup engines, the same as if 
+    The code below is used to test the backup engine selection logic.
+
+    In case a storage engine defines the handlerton::get_backup_engine pointer
+    but the factory function pointed by it refuses to create a backup engine,
+    backup kernel should try to use built-in backup engines, the same as if
     handlerton::get_backup_engine was NULL.
-   
+
     To test this behaviour, if "backup_test_dummy_be_factory" debug symbol is
     defined (e.g., with --debug="d,backup_test_dummy_be_factory" option), we
-    set the get_backup_engine pointer for MyISAM handlerton to point at the 
+    set the get_backup_engine pointer for MyISAM handlerton to point at the
     dummy backup engine factory which never creates any engines.
-  */ 
+  */
 
 #ifndef DBUG_OFF
-  backup_factory *saved_factory; // to save hton->get_backup_engine
-  DBUG_EXECUTE_IF("backup_test_dummy_be_factory", 
+  backup_factory *saved_factory; // To save hton->get_backup_engine.
+  DBUG_EXECUTE_IF("backup_test_dummy_be_factory",
     {
       handlerton *hton= se_hton(se);
       saved_factory= hton->get_backup_engine;
-      if (hton == myisam_hton) 
+      if (hton == myisam_hton)
         hton->get_backup_engine= dummy_backup_engine_factory;
     });
 
 #endif /* !DBUG_OFF */
 
   snap= native_snapshots[se];
-  
+
   if (!snap)
     if (has_native_backup(se))
     {
@@ -198,37 +204,37 @@ Backup_info::find_backup_engine(const ba
         snapshots.push_front(nsnap);
         native_snapshots.insert(se, nsnap);
 
-        if (nsnap->accept(tbl, se))        
+        if (nsnap->accept(tbl, se))
           snap= nsnap;
       }
       else
         delete nsnap;
     }
-  
+
   /*
     If "backup_test_dummy_be_factory" is used, the hton->get_backup_engine
     pointer has been modified. Here we restore the original value.
-   */ 
-  DBUG_EXECUTE_IF("backup_test_dummy_be_factory", 
+  */
+  DBUG_EXECUTE_IF("backup_test_dummy_be_factory",
     {
       handlerton *hton= se_hton(se);
       hton->get_backup_engine= saved_factory;
     });
 
-  /* 
+  /*
     If we couldn't locate native snapshot for that table - iterate over
     all existing snapshots and see if one of them can accept the table.
-    
-    The order on the snapshots list determines the preferred backup method 
-    for a table. The snapshots for the built-in backup engines are always 
+
+    The order on the snapshots list determines the preferred backup method
+    for a table. The snapshots for the built-in backup engines are always
     present at the end of this list so that they can be selected as a last
     resort.
   */
-    
+
   if (!snap)
   {
     List_iterator<Snapshot_info> it(snapshots);
-    
+
     while ((snap= it++))
     {
       if (my_strcasecmp(system_charset_info, se->name.str, "NDBCLUSTER") == 0)
@@ -247,10 +253,11 @@ Backup_info::find_backup_engine(const ba
 
   if (!snap)
     m_log.report_error(ER_BACKUP_NO_BACKUP_DRIVER,tbl.describe(buf));
-  
+
   DBUG_RETURN(snap);
 }
 
+
 /*************************************************
 
    Implementation of Backup_info class
@@ -260,7 +267,8 @@ Backup_info::find_backup_engine(const ba
 /**
   Definition of Backup_info::Ts_hash_node structure used by Backup_info::ts_hash
   HASH.
-*/ 
+*/
+
 struct Backup_info::Ts_hash_node
 {
   const String *name;	///< Name of the tablespace.
@@ -278,14 +286,18 @@ struct Backup_info::Ts_hash_node
     @returns Pointer to the key.
   */
   static uchar* get_key(const uchar *record, size_t *key_length, my_bool attr);
+
   /// Free data.
   static void free(void *record);
 };
 
+
 inline
-Backup_info::Ts_hash_node::Ts_hash_node(const String *name) :name(name), it(NULL)
+Backup_info::Ts_hash_node::Ts_hash_node(const String *name) 
+  :name(name), it(NULL)
 {}
 
+
 extern "C"
 inline
 void Backup_info::Ts_hash_node::free(void *record)
@@ -293,10 +305,11 @@ void Backup_info::Ts_hash_node::free(voi
   delete (Ts_hash_node*)record;
 }
 
+
 extern "C"
 inline
-uchar* Backup_info::Ts_hash_node::get_key(const uchar *record, 
-                                          size_t *key_length, 
+uchar* Backup_info::Ts_hash_node::get_key(const uchar *record,
+                                          size_t *key_length,
                                           my_bool)
 {
   Ts_hash_node *n= (Ts_hash_node*)record;
@@ -309,20 +322,22 @@ uchar* Backup_info::Ts_hash_node::get_ke
   return (uchar*)(n->name->ptr());
 }
 
+
 /**
   Represents a node in the dependency list.
-  
+
   Such node can be an empty placeholder or store a pointer to a catalogue item
-  in @c obj member. Dependency list nodes are kept in a hash and thus 
+  in @c obj member. Dependency list nodes are kept in a hash and thus
   @c Dep_node contains all required infrastructure: the @c key member to store
-  a key string plus @c get_key() and @c free() functions used in @c HASH 
+  a key string plus @c get_key() and @c free() functions used in @c HASH
   operations.
- */ 
+*/
+
 struct Backup_info::Dep_node: public Sql_alloc
 {
   Dep_node *next; ///< Pointer to next node.
-  Dbobj *obj;     ///< Pointer to database object.
-  String key;     ///< The key name.
+  Dbobj    *obj;  ///< Pointer to database object.
+  String   key;   ///< The key name.
 
   /**
     Constructor using data items.
@@ -332,6 +347,7 @@ struct Backup_info::Dep_node: public Sql
     @param[in]  type      Type of object.
   */
   Dep_node(const ::String &db_name, const ::String &name, const obj_type type);
+
   /// Base constructor using existing node.
   Dep_node(const Dep_node&);
 
@@ -344,6 +360,7 @@ struct Backup_info::Dep_node: public Sql
     @returns Pointer to the key.
   */
   static uchar* get_key(const uchar *record, size_t *key_length, my_bool attr);
+
   /**
     Free the node.
 
@@ -352,19 +369,21 @@ struct Backup_info::Dep_node: public Sql
   static void free(void *record);
 };
 
+
 /**
   Create an empty dependency list node for a given per-database object.
 
   The object is identified by its name, the name of the database to
   which it belongs, and its type.
- */ 
+*/
+
 inline
 Backup_info::Dep_node::Dep_node(const ::String &db_name, const ::String &name,
                                 const obj_type type)
   :next(NULL), obj(NULL)
 {
   key.length(0);
-  // Add type to make sure keys are unique even between different namespaces
+  // Add type to make sure keys are unique even between different namespaces.
   key.set_int(type, TRUE, &my_charset_bin);
   key.append("|");
   key.append(db_name);
@@ -372,6 +391,7 @@ Backup_info::Dep_node::Dep_node(const ::
   key.append(name);
 }
 
+
 inline
 Backup_info::Dep_node::Dep_node(const Dep_node &n)
  :Sql_alloc(n), next(n.next), obj(n.obj)
@@ -379,6 +399,7 @@ Backup_info::Dep_node::Dep_node(const De
   key.copy(n.key);
 }
 
+
 extern "C"
 inline
 void Backup_info::Dep_node::free(void *record)
@@ -386,9 +407,10 @@ void Backup_info::Dep_node::free(void *r
   ((Dep_node*)record)->~Dep_node();
 }
 
+
 extern "C"
 inline
-uchar* 
+uchar*
 Backup_info::Dep_node::get_key(const uchar *record,
                               size_t *key_length,
                               my_bool) // not_used __attribute__((unused)))
@@ -402,17 +424,18 @@ Backup_info::Dep_node::get_key(const uch
 
 /**
   Create @c Backup_info instance and prepare it for populating with objects.
-  
+
   @param[in] log     A logger used to report errors
   @param[in] thd     THD handle
 
   Snapshots created by the built-in backup engines are added to @c snapshots
-  list to be used in the backup engine selection algorithm in 
+  list to be used in the backup engine selection algorithm in
   @c find_backup_engine().
- */
+*/
+
 Backup_info::Backup_info(backup::Logger &log, THD *thd)
   :m_log(log), m_thd(thd), m_state(Backup_info::ERROR), native_snapshots(8),
-   m_dep_list(NULL), m_dep_end(NULL), 
+   m_dep_list(NULL), m_dep_end(NULL),
    m_srout_end(NULL), m_view_end(NULL), m_trigger_end(NULL), m_event_end(NULL)
 {
   using namespace backup;
@@ -427,18 +450,21 @@ Backup_info::Backup_info(backup::Logger 
       my_hash_init(&dep_hash, &::my_charset_bin, 16, 0, 0,
                 Dep_node::get_key, Dep_node::free, MYF(0)))
   {
-    // Allocation failed. Error has been reported, but not logged to backup logs
+    /*
+      Allocation failed. Error has been reported, but not logged
+      to backup logs.
+    */
     m_log.log_error(ER_OUT_OF_RESOURCES);
     return;
   }
 
-  /* 
-    Create nodata, default, and CS snapshot objects and add them to the 
-    snapshots list. Note that the default snapshot should be the last 
-    element on that list, as a "catch all" entry. 
-   */
+  /*
+    Create nodata, default, and CS snapshot objects and add them to the
+    snapshots list. Note that the default snapshot should be the last
+    element on that list, as a "catch all" entry.
+  */
 
-  snap= new Nodata_snapshot(m_log);             // logs errors
+  snap= new Nodata_snapshot(m_log);             // Logs errors.
   if (!snap)
   {
     m_log.report_error(ER_OUT_OF_RESOURCES);
@@ -446,16 +472,19 @@ Backup_info::Backup_info(backup::Logger 
   }
 
   if (!snap->is_valid())
-    return;    // Error has been logged by Nodata_snapshot constructor
+    return;    // Error has been logged by Nodata_snapshot constructor.
 
   if (snapshots.push_back(snap))
   {
-    // Allocation failed. Error has been reported, but not logged to backup logs
+    /*
+      Allocation failed. Error has been reported, but not logged
+      to backup logs.
+    */
     m_log.log_error(ER_OUT_OF_RESOURCES);
     return;
   }
 
-  snap= new CS_snapshot(m_log);                 // logs errors
+  snap= new CS_snapshot(m_log);                 // Logs errors.
   if (!snap)
   {
     m_log.report_error(ER_OUT_OF_RESOURCES);
@@ -463,16 +492,19 @@ Backup_info::Backup_info(backup::Logger 
   }
 
   if (!snap->is_valid())
-    return;        // Error has been logged by CS_snapshot constructor
+    return;        // Error has been logged by CS_snapshot constructor.
 
   if (snapshots.push_back(snap))
   {
-    // Allocation failed. Error has been reported, but not logged to backup logs
+    /*
+      Allocation failed. Error has been reported, but not logged
+      to backup logs.
+    */
     m_log.log_error(ER_OUT_OF_RESOURCES);
-    return;                                   // Error has been logged
+    return;                                     // Error has been logged.
   }
 
-  snap= new Default_snapshot(m_log);            // logs errors
+  snap= new Default_snapshot(m_log);            // Logs errors.
   if (!snap)
   {
     m_log.report_error(ER_OUT_OF_RESOURCES);
@@ -480,25 +512,29 @@ Backup_info::Backup_info(backup::Logger 
   }
 
   if (!snap->is_valid())
-    return;  // Error has been logged by Default_snapshot constructor
+    return;  // Error has been logged by Default_snapshot constructor.
 
   if (snapshots.push_back(snap))
   {
-    // Allocation failed. Error has been reported, but not logged to backup logs
+    /*
+      Allocation failed. Error has been reported, but not logged
+      to backup logs.
+    */
     m_log.log_error(ER_OUT_OF_RESOURCES);
-    return;                                   // Error has been logged
+    return;                                    // Error has been logged.
   }
 
   m_state= CREATED;
 }
 
+
 Backup_info::~Backup_info()
 {
   using namespace backup;
 
   close();
 
-  // delete Snapshot_info instances.
+  // Delete Snapshot_info instances.
 
   Snapshot_info *snap;
   List_iterator<Snapshot_info> it(snapshots);
@@ -506,16 +542,18 @@ Backup_info::~Backup_info()
   while ((snap= it++))
     delete snap;
 
-  my_hash_free(&ts_hash);  
+  my_hash_free(&ts_hash);
   my_hash_free(&dep_hash);
 }
 
+
 /**
   Close @c Backup_info object after populating it with items.
 
   After this call the @c Backup_info object is ready for use as a catalogue
   for backup stream functions such as @c bstream_wr_preamble().
- */
+*/
+
 int Backup_info::close()
 {
   if (!is_valid())
@@ -524,26 +562,29 @@ int Backup_info::close()
   if (m_state == CLOSED)
     return 0;
 
-  // report backup drivers used in the image
-  
+  // Report backup drivers used in the image.
+
   for (ushort n=0; n < snap_count(); ++n)
     m_log.report_driver(m_snap[n]->name());
-  
+
   m_state= CLOSED;
   return 0;
-}  
+}
+
 
 /**
   Add tablespace to backup catalogue.
 
   @param[in]	obj		sever object representing the tablespace
-  
-  If tablespace is already present in the catalogue, the existing catalogue entry
-  is returned. Otherwise a new entry is created and tablespace info stored in it.
-  
-  @return Pointer to (the new or existing) catalogue entry holding info about the
-  tablespace.  
- */ 
+
+  If tablespace is already present in the catalogue, the existing catalogue
+  entry is returned. Otherwise a new entry is created and tablespace info
+  stored in it.
+
+  @return Pointer to (the new or existing) catalogue entry holding info about
+  the tablespace.
+*/
+
 backup::Image_info::Ts* Backup_info::add_ts(obs::Obj *obj)
 {
   const String *name;
@@ -552,7 +593,7 @@ backup::Image_info::Ts* Backup_info::add
   name= obj->get_name();
   DBUG_ASSERT(name);
 
-  /* 
+  /*
     Check if tablespace with that name is already present in the catalogue using
     ts_hash.
   */
@@ -563,11 +604,11 @@ backup::Image_info::Ts* Backup_info::add
 
   Ts_hash_node *n1= (Ts_hash_node*) my_hash_search(&ts_hash, key, klen);
 
-  // if tablespace was found, return the catalogue entry stored in the hash
+  // If tablespace was found, return the catalogue entry stored in the hash.
   if (n1)
     return n1->it;
 
-  // otherwise create a new catalogue entry
+  // Otherwise create a new catalogue entry.
 
   ulong pos= ts_count();
 
@@ -579,11 +620,11 @@ backup::Image_info::Ts* Backup_info::add
     return NULL;
   }
 
-  // store pointer to the server object instance
+  // Store pointer to the server object instance.
 
   ts->m_obj_ptr= obj;
 
-  // add new entry to ts_hash
+  // Add new entry to ts_hash.
 
   n1= new Ts_hash_node(n0);
 
@@ -596,28 +637,30 @@ backup::Image_info::Ts* Backup_info::add
   n1->it= ts;
   my_hash_insert(&ts_hash, (uchar*)n1);
 
-  return ts;  
+  return ts;
 }
 
+
 /**
   Select database object for backup.
-  
-  The object is added to the backup catalogue as an instance of 
-  @c Image_info::Db class. A pointer to the obj::Obj instance is saved there for
-  later usage.
-  
+
+  The object is added to the backup catalogue as an instance of
+  @c Image_info::Db class. A pointer to the obj::Obj instance is saved there
+  for later usage.
+
   @returns Pointer to the @c Image_info::Db instance or NULL if database could
   not be added.
- */ 
+*/
+
 backup::Image_info::Db* Backup_info::add_db(obs::Obj *obj)
 {
   ulong pos= db_count();
-  
+
   DBUG_ASSERT(obj);
 
   const ::String *name= obj->get_name();
-  
-  DBUG_ASSERT(name);  
+
+  DBUG_ASSERT(name);
 
   /*
     Check privileges for this database. User must have BACKUP
@@ -630,9 +673,7 @@ backup::Image_info::Db* Backup_info::add
     return NULL;
   }
 
-  /*
-    Check to see if the user can see all of the objects in the database.
-  */
+  // Check to see if the user can see all of the objects in the database.
   if (obs::check_user_access(m_thd, name))
   {
     m_log.report_error(ER_BACKUP_ACCESS_OBJS_INCOMPLETE, name->ptr());
@@ -640,7 +681,7 @@ backup::Image_info::Db* Backup_info::add
   }
 
   Db *db= Image_info::add_db(*name, pos);
-  
+
   if (!db)
   {
     m_log.report_error(ER_BACKUP_CATALOG_ADD_DB, name->ptr());
@@ -649,9 +690,10 @@ backup::Image_info::Db* Backup_info::add
 
   db->m_obj_ptr= obj;
 
-  return db;  
+  return db;
 }
 
+
 /**
   Select given databases for backup.
 
@@ -662,14 +704,15 @@ backup::Image_info::Db* Backup_info::add
   the image.
 
   @returns 0 on success, error code otherwise.
- */
+*/
+
 int Backup_info::add_dbs(THD *thd, List< ::LEX_STRING > &dbs)
 {
   using namespace obs;
 
   List_iterator< ::LEX_STRING > it(dbs);
   ::LEX_STRING *s;
-  String unknown_dbs; // comma separated list of databases which don't exist
+  String unknown_dbs; // Comma separated list of databases which don't exist.
 
   while ((s= it++))
   {
@@ -680,9 +723,9 @@ int Backup_info::add_dbs(THD *thd, List<
       m_log.report_error(ER_BACKUP_CANNOT_INCLUDE_DB, db_name.c_ptr());
       goto error;
     }
-    
-    obs::Obj *obj= get_database_stub(thd, &db_name); // reports errors
-    
+
+    obs::Obj *obj= get_database_stub(thd, &db_name); // Reports errors.
+
     if (!obj)
     {
       m_log.report_error(ER_BACKUP_CATALOG_ADD_DB, db_name.c_ptr());
@@ -694,30 +737,29 @@ int Backup_info::add_dbs(THD *thd, List<
       if (!unknown_dbs.is_empty())
         unknown_dbs.append(",");
       unknown_dbs.append(obj->get_db_name()->ptr());
-      
+
       delete obj;
       continue;
-    } 
-    else if (!unknown_dbs.is_empty()) // we just compose unknown_dbs list
+    }
+    else if (!unknown_dbs.is_empty()) // We just compose unknown_dbs list.
     {
       delete obj;
       continue;
     }
 
-
     // Normalize DB name; if case insensitive server, obj->get_db_name
-    // returns name in lower case
+    // returns name in lower case.
     db_name= obj->get_db_name()->ptr();
 
-    // Error if the same database is requested twice in the database list
+    // Error if the same database is requested twice in the database list.
     if (has_db(db_name))
     {
       m_log.report_error(ER_NONUNIQ_DB, db_name.c_ptr());;
       delete obj;
       goto error;
     }
-    
-    Db *db= add_db(obj);  // reports errors
+
+    Db *db= add_db(obj);    // Reports errors.
 
     if (!db)
     {
@@ -725,9 +767,8 @@ int Backup_info::add_dbs(THD *thd, List<
       goto error;
     }
 
-    if (add_db_items(*db))  // reports errors
+    if (add_db_items(*db))  // Reports errors.
       goto error;
-      
   }
 
   if (!unknown_dbs.is_empty())
@@ -744,6 +785,7 @@ int Backup_info::add_dbs(THD *thd, List<
   return backup::ERROR;
 }
 
+
 /**
   Select all existing databases for backup.
 
@@ -752,15 +794,14 @@ int Backup_info::add_dbs(THD *thd, List<
 
   @returns 0 on success, error code otherwise.
 */
+
 int Backup_info::add_all_dbs()
 {
   using namespace obs;
 
   int res= 0;
 
-  /*
-    Check to see if the user can see all of the databases.
-  */
+  // Check to see if the user can see all of the databases.
   if (check_user_access(m_thd, 0))
   {
     m_log.report_error(ER_BACKUP_ACCESS_DBS_INCOMPLETE);
@@ -768,7 +809,7 @@ int Backup_info::add_all_dbs()
   }
 
   Obj_iterator *dbit= get_databases(m_thd);
-  
+
   // Error code insertion for ER_BACKUP_LIST_DBS.
   DBUG_EXECUTE_IF("ER_BACKUP_LIST_DBS", dbit= 0;);
 
@@ -777,15 +818,15 @@ int Backup_info::add_all_dbs()
     m_log.report_error(ER_BACKUP_LIST_DBS);
     return ERROR;
   }
-  
+
   obs::Obj *obj;
-  
+
   while ((obj= dbit->next()))
   {
-    // skip internal databases
+    // Skip internal databases.
     if (is_internal_db_name(obj->get_name()))
     {
-      DBUG_PRINT("backup",(" Skipping internal database %s", 
+      DBUG_PRINT("backup",(" Skipping internal database %s",
                            obj->get_name()->ptr()));
       delete obj;
       continue;
@@ -793,7 +834,7 @@ int Backup_info::add_all_dbs()
 
     DBUG_PRINT("backup", (" Found database %s", obj->get_name()->ptr()));
 
-    Db *db= add_db(obj);  // reports errors
+    Db *db= add_db(obj);    // Reports errors.
 
     if (!db)
     {
@@ -802,7 +843,7 @@ int Backup_info::add_all_dbs()
       goto finish;
     }
 
-    if (add_db_items(*db))  // reports errors
+    if (add_db_items(*db))  // Reports errors.
     {
       res= ERROR;
       goto finish;
@@ -831,13 +872,14 @@ int Backup_info::add_all_dbs()
   @param[in] it   iterator enumerationg objects to be added
 
   @returns 0 on success, error code otherwise.
- */
+*/
+
 int Backup_info::add_objects(Db &db, const obj_type type, obs::Obj_iterator &it)
 {
   obs::Obj *obj;
-  
+
   while ((obj= it.next()))
-    if (!add_db_object(db, type, obj)) // reports errors
+    if (!add_db_object(db, type, obj)) // Reports errors.
     {
       delete obj;
       return ERROR;
@@ -846,11 +888,13 @@ int Backup_info::add_objects(Db &db, con
   return 0;
 }
 
+
 /**
   Add to image all objects belonging to a given database.
 
   @returns 0 on success, error code otherwise.
- */
+*/
+
 int Backup_info::add_db_items(Db &db)
 {
   using namespace obs;
@@ -867,7 +911,7 @@ int Backup_info::add_db_items(Db &db)
     m_log.report_error(ER_BACKUP_LIST_DB_TABLES, db.name().ptr());
     return ERROR;
   }
-  
+
   int res= 0;
   obs::Obj *obj= NULL;
 
@@ -877,10 +921,11 @@ int Backup_info::add_db_items(Db &db)
                            obj->get_name()->ptr(), db.name().ptr()));
 
     /*
-      add_table() method selects/creates a snapshot to which this table is added.
-      The backup engine is choosen in Backup_info::find_backup_engine() method.
+      add_table() method selects/creates a snapshot to which this table is
+      added. The backup engine is choosen in Backup_info::find_backup_engine()
+      method.
     */
-    Table *tbl= add_table(db, obj); // reports errors
+    Table *tbl= add_table(db, obj); // Reports errors.
 
     if (!tbl)
     {
@@ -894,7 +939,7 @@ int Backup_info::add_db_items(Db &db)
 
     if (obj)
     {
-      Ts *ts= add_ts(obj); // reports errors
+      Ts *ts= add_ts(obj); // Reports errors.
 
       if (!ts)
       {
@@ -906,9 +951,9 @@ int Backup_info::add_db_items(Db &db)
 
   // Add other objects.
 
-  delete it;  
+  delete it;
   it= get_db_stored_procedures(m_thd, &db.name());
-  
+
   // Error code insertion for ER_BACKUP_LIST_DB_SROUT.
   DBUG_EXECUTE_IF("ER_BACKUP_LIST_DB_SROUT_P", it= 0;);
 
@@ -917,7 +962,7 @@ int Backup_info::add_db_items(Db &db)
     m_log.report_error(ER_BACKUP_LIST_DB_SROUT, db.name().ptr());
     goto error;
   }
-  
+
   if (add_objects(db, BSTREAM_IT_SPROC, *it))
     goto error;
 
@@ -932,7 +977,7 @@ int Backup_info::add_db_items(Db &db)
     m_log.report_error(ER_BACKUP_LIST_DB_SROUT, db.name().ptr());
     goto error;
   }
-  
+
   if (add_objects(db, BSTREAM_IT_SFUNC, *it))
     goto error;
 
@@ -947,7 +992,7 @@ int Backup_info::add_db_items(Db &db)
     m_log.report_error(ER_BACKUP_LIST_DB_VIEWS, db.name().ptr());
     goto error;
   }
-  
+
   if (add_objects(db, BSTREAM_IT_VIEW, *it))
     goto error;
 
@@ -962,10 +1007,10 @@ int Backup_info::add_db_items(Db &db)
     m_log.report_error(ER_BACKUP_LIST_DB_EVENTS, db.name().ptr());
     goto error;
   }
-  
+
   if (add_objects(db, BSTREAM_IT_EVENT, *it))
     goto error;
-  
+
   delete it;
   it= get_db_triggers(m_thd, &db.name());
 
@@ -977,10 +1022,10 @@ int Backup_info::add_db_items(Db &db)
     m_log.report_error(ER_BACKUP_LIST_DB_TRIGGERS, db.name().ptr());
     goto error;
   }
-  
+
   if (add_objects(db, BSTREAM_IT_TRIGGER, *it))
     goto error;
-  
+
   delete it;
   it= get_all_db_grants(m_thd, &db.name());
 
@@ -1002,19 +1047,21 @@ int Backup_info::add_db_items(Db &db)
 
   res= res ? res : ERROR;
   m_state= ERROR;
-  
+
  finish:
 
   delete it;
   return res;
 }
 
+
 namespace {
 
 /**
   Implementation of @c Table_ref which gets table identity from a server
   object instance - to be used in @c Backup_info::add_table().
- */ 
+*/
+
 class Tbl: public backup::Table_ref
 {
 public:
@@ -1028,6 +1075,7 @@ public:
 
 } // anonymous namespace
 
+
 /**
   Select table object for backup.
 
@@ -1035,8 +1083,8 @@ public:
   @param[in]  obj   table object
 
   The object is added to the backup image's catalogue as an instance of
-  @c Image_info::Table class. A pointer to the obj::Obj instance is saved for 
-  later usage. This method picks the best available backup engine for the table 
+  @c Image_info::Table class. A pointer to the obj::Obj instance is saved for
+  later usage. This method picks the best available backup engine for the table
   using @c find_backup_engine() method.
 
   @todo Correctly handle temporary tables.
@@ -1044,32 +1092,33 @@ public:
   @returns Pointer to the @c Image_info::Table class instance or NULL if table
   could not be added.
 */
+
 backup::Image_info::Table* Backup_info::add_table(Db &dbi, obs::Obj *obj)
 {
   Table *tbl= NULL;
-  
+
   DBUG_ASSERT(obj);
 
   Tbl t(obj);
-  // TODO: skip table if it is a tmp one
-  
-  backup::Snapshot_info *snap= find_backup_engine(t); // reports errors
+  // TODO: skip table if it is a tmp one.
+
+  backup::Snapshot_info *snap= find_backup_engine(t); // Reports errors.
 
   if (!snap)
     return NULL;
 
-  // add table to the catalogue
+  // Add table to the catalogue.
 
   ulong pos= snap->table_count();
-  
+
   tbl= Image_info::add_table(dbi, t.name(), *snap, pos);
-  
+
   // Error code insertion for ER_BACKUP_CATALOG_ADD_TABLE.
   DBUG_EXECUTE_IF("ER_BACKUP_CATALOG_ADD_TABLE", tbl= 0;);
 
   if (!tbl)
   {
-    m_log.report_error(ER_BACKUP_CATALOG_ADD_TABLE, 
+    m_log.report_error(ER_BACKUP_CATALOG_ADD_TABLE,
                        dbi.name().ptr(), t.name().ptr());
     return NULL;
   }
@@ -1081,46 +1130,48 @@ backup::Image_info::Table* Backup_info::
   return tbl;
 }
 
+
 /**
-  For all views on which the given one depends directly or indirectly, add 
+  For all views on which the given one depends directly or indirectly, add
   placeholders to the dependency list ensuring correct order among them.
 
-  The main view being processed in this function should be added to the 
-  dependency list after all the placeholders created here. This way if one of 
-  the views on which the given one depends is added to the list later, it will 
+  The main view being processed in this function should be added to the
+  dependency list after all the placeholders created here. This way if one of
+  the views on which the given one depends is added to the list later, it will
   be placed at the correct position indicated by the placeholder.
 
   @param[in]  obj   server object for the view to be processed
 
   A recursive algorithm is used to insert placeholders in correct order.
-  That is, for each base view @c bv of the given one, @c add_view_deps(bv) 
+  That is, for each base view @c bv of the given one, @c add_view_deps(bv)
   is called to insert all dependencies of @c bv before @c bv itself is appended
   to the list.
-  
-  Function @c get_dep_node() used to create a node to be inserted into the 
+
+  Function @c get_dep_node() used to create a node to be inserted into the
   dependency list detects if the node was already created earlier. This ensures
-  correct behaviour of the algorithm even if the same view is visited several 
-  times during the depth-first walk of the dependency graph performed by the 
+  correct behaviour of the algorithm even if the same view is visited several
+  times during the depth-first walk of the dependency graph performed by the
   recursive algorithm. If it is detected that a node for a given view already
-  exists then this view is not processed for the second time.  
+  exists then this view is not processed for the second time.
 
   This also ensures termination of the algorithm even when there are
-  circular dependencies. Suppose that view @c v has itself as an (indirect) 
-  dependency. When processing @c v, a node will be created for it first 
-  and then its dependencies will be processed. When add_view_deps() comes across 
-  @c v for the second time it will see that a corresponding mode already 
+  circular dependencies. Suppose that view @c v has itself as an (indirect)
+  dependency. When processing @c v, a node will be created for it first
+  and then its dependencies will be processed. When add_view_deps() comes across
+  @c v for the second time it will see that a corresponding mode already
   exists and thus will break the recursion.
 
   @return Non-zero value if an error happened.
- */ 
+*/
+
 int Backup_info::add_view_deps(obs::Obj &obj)
 {
   const ::String *name= obj.get_name();
   const ::String *db_name= obj.get_db_name();
 
-  DBUG_ASSERT(name); 
-  DBUG_ASSERT(db_name); 
-  
+  DBUG_ASSERT(name);
+  DBUG_ASSERT(db_name);
+
   // Get an iterator to iterate over base views of the given one.
 
   obs::Obj_iterator *it= obs::get_view_base_views(m_thd, db_name, name);
@@ -1128,12 +1179,12 @@ int Backup_info::add_view_deps(obs::Obj 
   if (!it)
     return ERROR;
 
-  /* 
-    Iterate over base views and for each of them add it and its dependencies 
+  /*
+    Iterate over base views and for each of them add it and its dependencies
     to the dependency list (first its dependecies, then the base view).
   */
 
-  obs::Obj *bv; 
+  obs::Obj *bv;
 
   while ((bv= it->next()))
   {
@@ -1141,8 +1192,8 @@ int Backup_info::add_view_deps(obs::Obj 
     const ::String *name= bv->get_name();
     const ::String *db_name= bv->get_db_name();
 
-    DBUG_ASSERT(name); 
-    DBUG_ASSERT(db_name); 
+    DBUG_ASSERT(name);
+    DBUG_ASSERT(db_name);
 
     // Locate or create a dependency list node for the base view.
 
@@ -1154,10 +1205,10 @@ int Backup_info::add_view_deps(obs::Obj 
     DBUG_ASSERT(n);
 
     /*
-      If a node for this view already exists, the view has been processed 
+      If a node for this view already exists, the view has been processed
       (or is being processed now). Hence we skip it and continue with other
       base views.
-     */ 
+    */
     if (res == get_dep_node_res::EXISTING_NODE)
     {
       delete bv; // Need to delete the instance returned by it->next().
@@ -1169,12 +1220,12 @@ int Backup_info::add_view_deps(obs::Obj 
     if (add_view_deps(*bv))
       goto error;
 
-    /* 
+    /*
       Now add bv itself to the list (we keep in n a pointer to the dep. list
       node obtained earlier).
-     */
+    */
     if (add_to_dep_list(BSTREAM_IT_VIEW, n))
-      goto error;      
+      goto error;
 
     delete bv; // Server object instance is not needed any more.
   }
@@ -1190,6 +1241,7 @@ error:
   return ERROR;
 }
 
+
 /**
   Select a per database object for backup.
 
@@ -1205,10 +1257,11 @@ error:
   add_to_dep_list() method and to the catalogue. If it is a view, its
   dependencies are handled first using @c add_view_deps().
 
-  @returns Pointer to @c Image_info::Dbobj instance storing information 
-  about the object or NULL in case of error.  
- */
-backup::Image_info::Dbobj* 
+  @returns Pointer to @c Image_info::Dbobj instance storing information
+  about the object or NULL in case of error.
+*/
+
+backup::Image_info::Dbobj*
 Backup_info::add_db_object(Db &db, const obj_type type, obs::Obj *obj)
 {
   int error= 0;
@@ -1219,54 +1272,53 @@ Backup_info::add_db_object(Db &db, const
 
   switch (type) {
 
-  // Databases and tables should not be passed to this function.  
+  // Databases and tables should not be passed to this function.
   case BSTREAM_IT_DB:     DBUG_ASSERT(FALSE); break;
   case BSTREAM_IT_TABLE:  DBUG_ASSERT(FALSE); break;
 
-  case BSTREAM_IT_VIEW:   error= ER_BACKUP_CATALOG_ADD_VIEW; break;
-  case BSTREAM_IT_SPROC:  error= ER_BACKUP_CATALOG_ADD_SROUT; break;
-  case BSTREAM_IT_SFUNC:  error= ER_BACKUP_CATALOG_ADD_SROUT; break;
-  case BSTREAM_IT_EVENT:  error= ER_BACKUP_CATALOG_ADD_EVENT; break;
-  case BSTREAM_IT_TRIGGER: error= ER_BACKUP_CATALOG_ADD_TRIGGER; break;
+  case BSTREAM_IT_VIEW:      error= ER_BACKUP_CATALOG_ADD_VIEW; break;
+  case BSTREAM_IT_SPROC:     error= ER_BACKUP_CATALOG_ADD_SROUT; break;
+  case BSTREAM_IT_SFUNC:     error= ER_BACKUP_CATALOG_ADD_SROUT; break;
+  case BSTREAM_IT_EVENT:     error= ER_BACKUP_CATALOG_ADD_EVENT; break;
+  case BSTREAM_IT_TRIGGER:   error= ER_BACKUP_CATALOG_ADD_TRIGGER; break;
   case BSTREAM_IT_PRIVILEGE: error= ER_BACKUP_CATALOG_ADD_PRIV; break;
-  
+
   // Only known types of objects should be added to the catalogue.
   default: DBUG_ASSERT(FALSE);
 
   }
 
-  /* 
+  /*
     Add new object to the dependency list. If it is a view, add its
     dependencies first.
-   */
+  */
 
-  Dep_node *n= NULL; /* Note: set to NULL to make sure that get_dep_node() has 
-                        set the pointer. */ 
+  // Note: set to NULL to make sure that get_dep_node() has set the pointer.
+  Dep_node *n= NULL;
 
-  // Get a dep. list node for the object.  
+  // Get a dep. list node for the object.
 
   int res= get_dep_node(db.name(), *obj->get_name(), type, n);
 
 #if !defined(DBUG_OFF)
 
   /*
-    Debug insertion for errors. Here we setup the error to correspond 
+    Debug insertion for errors. Here we setup the error to correspond
     with the debug SESSION tag specified in the test.
 
     Note: Error code insertion won't work here as we need to generate
           the specific error message for each test case.
 
     Note: ER_BACKUP_CATALOG_ADD_TABLE is detected elsewhere.
-
   */
   ::String str;
   switch (type) {
-  case BSTREAM_IT_DB:     str.append("ER_BACKUP_CATALOG_ADD_DB"); break;
-  case BSTREAM_IT_VIEW:   str.append("ER_BACKUP_CATALOG_ADD_VIEW"); break;
-  case BSTREAM_IT_SPROC:  str.append("ER_BACKUP_CATALOG_ADD_SROUT_P"); break;
-  case BSTREAM_IT_SFUNC:  str.append("ER_BACKUP_CATALOG_ADD_SROUT_F"); break;
-  case BSTREAM_IT_EVENT:  str.append("ER_BACKUP_CATALOG_ADD_EVENT"); break;
-  case BSTREAM_IT_TRIGGER: str.append("ER_BACKUP_CATALOG_ADD_TRIGGER"); break;
+  case BSTREAM_IT_DB:        str.append("ER_BACKUP_CATALOG_ADD_DB"); break;
+  case BSTREAM_IT_VIEW:      str.append("ER_BACKUP_CATALOG_ADD_VIEW"); break;
+  case BSTREAM_IT_SPROC:     str.append("ER_BACKUP_CATALOG_ADD_SROUT_P"); break;
+  case BSTREAM_IT_SFUNC:     str.append("ER_BACKUP_CATALOG_ADD_SROUT_F"); break;
+  case BSTREAM_IT_EVENT:     str.append("ER_BACKUP_CATALOG_ADD_EVENT"); break;
+  case BSTREAM_IT_TRIGGER:   str.append("ER_BACKUP_CATALOG_ADD_TRIGGER"); break;
   case BSTREAM_IT_PRIVILEGE: str.append("ER_BACKUP_CATALOG_ADD_PRIV"); break;
   default: break;
   }
@@ -1276,12 +1328,12 @@ Backup_info::add_db_object(Db &db, const
   }
   // Tablespace is a special case since Falcon is disabled.
   DBUG_EXECUTE_IF("ER_BACKUP_CATALOG_ADD_TS",
-    m_log.report_error(ER_BACKUP_CATALOG_ADD_TS, 
+    m_log.report_error(ER_BACKUP_CATALOG_ADD_TS,
       "Debug insertion test");
     return NULL;);
 
 #endif
-  
+
   if (res == get_dep_node_res::ERROR)
   {
     m_log.report_error(error, db.name().ptr(), obj->get_name()->ptr());
@@ -1290,9 +1342,9 @@ Backup_info::add_db_object(Db &db, const
 
   /*
     If a new node was created, it must be added to the dependency list with
-    add_to_dep_list(). However, if the object is a view, we must first add 
+    add_to_dep_list(). However, if the object is a view, we must first add
     placeholders for all its dependencies which is done using add_view_deps().
-   */ 
+  */
 
   if (res == get_dep_node_res::NEW_NODE)
   {
@@ -1301,10 +1353,10 @@ Backup_info::add_db_object(Db &db, const
       {
         m_log.report_error(error, db.name().ptr(), obj->get_name()->ptr());
         return NULL;
-      } 
+      }
 
     add_to_dep_list(type, n);
-  } 
+  }
 
   /*
     The object has now been added to the dependancy list. If it is a
@@ -1314,10 +1366,10 @@ Backup_info::add_db_object(Db &db, const
     list before adding to catalogue ensures that an object will not be
     added to catalogue if there are problems with it's dependant
     objects.
-   */
+  */
 
   Dbobj *o= Image_info::add_db_object(db, type, *obj->get_name(), pos);
- 
+
   if (!o)
   {
     m_log.report_error(error, db.name().ptr(), obj->get_name()->ptr());
@@ -1326,27 +1378,28 @@ Backup_info::add_db_object(Db &db, const
 
   o->m_obj_ptr= obj;
 
-  /* 
+  /*
     Store a pointer to the catalogue item in the dep. list node. If this node
     was a placeholder inserted into the list before, now it will be filled with
     the object we are adding to the catalogue.
-   */
+  */
 
   DBUG_ASSERT(n);
-  n->obj= o;  
+  n->obj= o;
 
   DBUG_PRINT("backup",("Added object %s of type %d from database %s (pos=%lu)",
                        obj->get_name()->ptr(), type, db.name().ptr(), pos));
   return o;
 }
 
+
 /**
   Find or create a dependency list node for an object with a given name.
-  
+
   @param[in]  db_name  name of the database to which this object belongs
   @param[in]  name     name of the object
   @param[out] node     pointer to the created or located node
-  
+
   All nodes created using this function are keept inside @c dep_node HASH
   indexed by <db_name, name> pairs. This is used to detect that a node for
   a given object already exists. All created nodes are deleted when Backup_info
@@ -1354,7 +1407,7 @@ Backup_info::add_db_object(Db &db, const
 
   The node created by this function is not placed on the dependency list. This
   must be done explicitly using @c add_to_dep_list(). The node has @c obj member
-  set to NULL which means that it can be used as an empty placeholder in the 
+  set to NULL which means that it can be used as an empty placeholder in the
   dependency list.
 
   @return A code indicating whether the node was found or created.
@@ -1362,9 +1415,10 @@ Backup_info::add_db_object(Db &db, const
   @retval EXISTING_NODE a node for this object was created before and @c node
                         contains a pointer to it
   @retval ERROR         it was not possible to create or locate the node
- */ 
-int Backup_info::get_dep_node(const ::String &db_name, 
-                              const ::String &name, 
+*/
+
+int Backup_info::get_dep_node(const ::String &db_name,
+                              const ::String &name,
                               const obj_type type,
                               Dep_node* &node)
 {
@@ -1374,41 +1428,41 @@ int Backup_info::get_dep_node(const ::St
 
   node= (Dep_node*) my_hash_search(&dep_hash, key, klen);
 
-  // if we have found node in the hash there is nothing more to do
+  // If we have found node in the hash there is nothing more to do.
   if (node)
     return get_dep_node_res::EXISTING_NODE;
-  
-  /*
-    Otherwise insert node into the hash and return.
-   */
+
+  // Otherwise insert node into the hash and return.
 
   node= new (&mem_root) Dep_node(n);
 
   if (!node)
     return get_dep_node_res::ERROR;
 
-  return my_hash_insert(&dep_hash, (uchar*)node) ? 
+  return my_hash_insert(&dep_hash, (uchar*)node) ?
           get_dep_node_res::ERROR : get_dep_node_res::NEW_NODE;
 }
 
+
 /**
   Append node to the correct section of the dependency list, based on the
   type of the object.
 
-  @param[in]  type   type of the object indicating the section of the list 
+  @param[in]  type   type of the object indicating the section of the list
                      to which node will be appended
   @param[in]  node   points at the node to be appended
 
   The node is appended at the end of the corresponding section of the
   dependency list. Pointers m_dep_list, m_end_dep and the ones indicating end of
   each section are updated as necessary.
-  
-  A node added to the list is just a placeholder for an object from backup 
+
+  A node added to the list is just a placeholder for an object from backup
   catalogue. To insert such object into the list a pointer to the corresponding
   @c Dbobj instance should be stored in the @c obj member of a list node.
- 
-  @return Non-zero value in case of error. Currently should always succeed. 
- */ 
+
+  @return Non-zero value in case of error. Currently should always succeed.
+*/
+
 int Backup_info::add_to_dep_list(const obj_type type, Dep_node *node)
 {
   Dep_node* *end= NULL;
@@ -1416,28 +1470,28 @@ int Backup_info::add_to_dep_list(const o
   DBUG_ASSERT(node);
 
   /*
-    Set end to point at m_srout_end, m_trigger_end or m_view_end depending on 
+    Set end to point at m_srout_end, m_trigger_end or m_view_end depending on
     the type of the item.
-    
+
     If the corresponding section is empty, the *end pointer is set up to point
     at the node after which this section should start, or to NULL if section
     should be at the beginning of the dependency list.
-    
+
     After inserting the new node it becomes the last node in the section so
     the pointer is updated to point at it.
-   */ 
+  */
 
   switch (type) {
 
   case BSTREAM_IT_SPROC:
   case BSTREAM_IT_SFUNC:
     end= &m_srout_end;
-  break; 
+  break;
 
-  case BSTREAM_IT_VIEW:  
+  case BSTREAM_IT_VIEW:
     end= &m_view_end;
     if (!m_view_end)
-      m_view_end= m_srout_end; 
+      m_view_end= m_srout_end;
   break;
 
   case BSTREAM_IT_TRIGGER:
@@ -1445,27 +1499,28 @@ int Backup_info::add_to_dep_list(const o
     if (!m_trigger_end)
       m_trigger_end= m_view_end ? m_view_end : m_srout_end;
   break;
-  
-  case BSTREAM_IT_EVENT: 
+
+  case BSTREAM_IT_EVENT:
     end= &m_event_end;
     if (!m_event_end)
-      m_event_end= m_trigger_end ? m_trigger_end : m_view_end ? m_view_end : m_srout_end;
+      m_event_end= m_trigger_end ? m_trigger_end :
+                      m_view_end ? m_view_end : m_srout_end;
   break;
 
   case BSTREAM_IT_PRIVILEGE:
     end= &m_dep_end;
   break;
-   
-  default: DBUG_ASSERT(FALSE); // only known object types should be added   
+
+  default: DBUG_ASSERT(FALSE); // Only known object types should be added.
 
   }
 
-  DBUG_ASSERT(end); // end should point now at one of m_*_end pointers
+  DBUG_ASSERT(end); // End should point now at one of m_*_end pointers.
 
   /*
     The new node should be inserted after the node pointed by end or at
-    the begginging of the list if end == NULL. 
-   */
+    the begginging of the list if end == NULL.
+  */
 
   if (*end)
   {
@@ -1480,14 +1535,14 @@ int Backup_info::add_to_dep_list(const o
 
   /*
     Update m_dep_end pointer if appending to the end of the dependency list.
-    
+
     There are two cases:
-    
+
     - either the list is empty in which case both m_dep_end and *end are NULL
     - or it is not empty and *end points at the last node in the list.
-    
+
     In either case *end equals m_dep_end.
-   */ 
+  */
 
   if (*end == m_dep_end)
     m_dep_end= node;
@@ -1503,21 +1558,20 @@ int Backup_info::add_to_dep_list(const o
   neta-data section of backup image.
 
   Currently only global objects handled are tablespaces and databases.
- */
+*/
+
 class Backup_info::Global_iterator
  : public backup::Image_info::Iterator
 {
-  /**
-    Indicates whether tablespaces or databases are being currently enumerated.
-   */ 
+  /// Indicates whether tablespaces or databases are being currently enumerated.
   enum { TABLESPACES, DATABASES, DONE } mode;
 
-  Iterator *m_it; ///< Points at the currently used iterator.
-  Obj *m_obj;         ///< Points at next object to be returned by this iterator.
+  Iterator *m_it;   ///< Points at the currently used iterator.
+  Obj      *m_obj;  ///< Points at next object to be returned by this iterator.
 
 public:
 
-  /// Constructor
+  /// Constructor.
   Global_iterator(const Backup_info&);
 
   int init();
@@ -1528,6 +1582,7 @@ private:
   bool next();
 };
 
+
 inline
 Backup_info::Global_iterator::Global_iterator(const Backup_info &info)
  :Iterator(info), mode(TABLESPACES), m_it(NULL), m_obj(NULL)
@@ -1543,11 +1598,12 @@ int Backup_info::Global_iterator::init()
     const Backup_info* info= static_cast<const Backup_info*>(&m_info);
     return info->m_log.report_error(ER_OUT_OF_RESOURCES);
   }
-  next();                                       // Never errors
+  next();                                       // Never errors.
 
   return 0;
 }
 
+
 inline
 backup::Image_info::Obj*
 Backup_info::Global_iterator::get_ptr() const
@@ -1555,6 +1611,7 @@ Backup_info::Global_iterator::get_ptr() 
   return m_obj;
 }
 
+
 inline
 bool
 Backup_info::Global_iterator::next()
@@ -1564,7 +1621,7 @@ Backup_info::Global_iterator::next()
 
   DBUG_ASSERT(m_it);
 
-  // get next object from the current iterator
+  // Get next object from the current iterator.
   m_obj= (*m_it)++;
 
   if (m_obj)
@@ -1608,19 +1665,21 @@ Backup_info::Global_iterator::next()
   return FALSE;
 }
 
+
 /**
   Used to iterate over all per database objects, except tables.
 
   This iterator uses the dependency list maintained inside Backup_info
   instance to list objects in a dependency-respecting order.
- */ 
+*/
+
 class Backup_info::Perdb_iterator : public backup::Image_info::Iterator
 {
   Dep_node *ptr;
 
 public:
 
-  /// Constructor
+  /// Constructor.
   Perdb_iterator(const Backup_info&);
 
 private:
@@ -1629,6 +1688,7 @@ private:
   bool next();
 };
 
+
 inline
 Backup_info::Perdb_iterator::Perdb_iterator(const Backup_info &info)
  :Iterator(info), ptr(info.m_dep_list)
@@ -1639,14 +1699,18 @@ Backup_info::Perdb_iterator::Perdb_itera
     ptr= ptr->next;
 }
 
+
 /// Implementation of @c Image_info::Iterator virtual method.
+
 inline
 backup::Image_info::Obj* Backup_info::Perdb_iterator::get_ptr() const
 {
   return ptr ? ptr->obj : NULL;
 }
 
+
 /// Implementation of @c Image_info::Iterator virtual method.
+
 inline
 bool Backup_info::Perdb_iterator::next()
 {
@@ -1666,15 +1730,16 @@ bool Backup_info::Perdb_iterator::next()
 
 
 /// Wrapper to return global iterator.
+
 backup::Image_info::Iterator* Backup_info::get_global() const
 {
   Global_iterator* it = new Global_iterator(*this);
-  if (it == NULL) 
+  if (it == NULL)
   {
     m_log.report_error(ER_OUT_OF_RESOURCES);
     return NULL;
-  }    
-  if (it->init())                               // Error has been logged
+  }
+  if (it->init())  // Error has been logged.
   {
     return NULL;
   }
@@ -1682,16 +1747,18 @@ backup::Image_info::Iterator* Backup_inf
   return it;
 }
 
+
 /// Wrapper to return iterator for per-database objects.
+
 backup::Image_info::Iterator* Backup_info::get_perdb()  const
 {
   Perdb_iterator* it = new Perdb_iterator(*this);
-  if (it == NULL) 
+  if (it == NULL)
   {
     m_log.report_error(ER_OUT_OF_RESOURCES);
     return NULL;
-  }    
-  if (it->init())                               // Error has been logged
+  }
+  if (it->init())  // Error has been logged.
   {
     return NULL;
   }
@@ -1699,4 +1766,5 @@ backup::Image_info::Iterator* Backup_inf
   return it;
 }
 
+
 template class Map<storage_engine_ref, backup::Native_snapshot>;

=== modified file 'sql/backup/backup_info.h'
--- a/sql/backup/backup_info.h	2009-10-12 09:08:34 +0000
+++ b/sql/backup/backup_info.h	2009-10-21 13:32:24 +0000
@@ -4,30 +4,33 @@
 #include <backup/image_info.h>
 #include <backup/stream_services.h>
 
+
 class Backup_restore_ctx;
 class Backup_info;
 
+
 namespace backup {
 
 class Native_snapshot;
 class Logger;
 class Output_stream;
 
-int write_table_data(THD*, backup::Logger&, Backup_info&, 
+int write_table_data(THD*, backup::Logger&, Backup_info&,
                      backup::Output_stream&);
-
 } // backup namespace
 
+
 /**
   Specialization of @c Image_info which adds methods for selecting objects
   to backup.
 
-  A pointer to empty @c Backup_info instance is returned by 
-  @c Backup_restore_ctx::prepare_for_backup() method. Methods @c add_dbs() or 
-  @c add_all_dbs() can be used to select which databases should be backed up. 
-  When this is done, the @c Backup_info object should be "closed" with 
+  A pointer to empty @c Backup_info instance is returned by
+  @c Backup_restore_ctx::prepare_for_backup() method. Methods @c add_dbs() or
+  @c add_all_dbs() can be used to select which databases should be backed up.
+  When this is done, the @c Backup_info object should be "closed" with
   @c close() method. Only then we are ready for backup operation.
 */
+
 class Backup_info: public backup::Image_info
 {
 public:
@@ -54,24 +57,26 @@ private:
   */
   Backup_info(backup::Logger&, THD*);
 
-  // Prevent copying/assignments
+  // Prevent copying/assignments.
   Backup_info(const Backup_info&);
   Backup_info& operator=(const Backup_info&);
 
   THD *m_thd;
 
-  class Global_iterator; ///< Iterates over global items (for which metadata is stored).
-  class Perdb_iterator;  ///< Iterates over all per-database objects (except tables).
+  /// Iterates over global items (for which metadata is stored).
+  class Global_iterator;
+  /// Iterates over all per-database objects (except tables).
+  class Perdb_iterator;
 
   /// State of the info structure.
   enum {CREATED,
-        CLOSED,  
+        CLOSED,
         ERROR}   m_state;
 
   backup::Snapshot_info* find_backup_engine(const backup::Table_ref&);
 
-  Ts* add_ts(obs::Obj*);
-  Db* add_db(obs::Obj*);
+  Ts*    add_ts(obs::Obj*);
+  Db*    add_db(obs::Obj*);
   Dbobj* add_db_object(Db&, const obj_type, obs::Obj*);
   Table* add_table(Db&, obs::Obj*);
 
@@ -81,106 +86,108 @@ private:
 
   struct Dep_node;
 
-  int get_dep_node(const ::String&, const ::String&, const obj_type, 
+  int get_dep_node(const ::String&, const ::String&, const obj_type,
                    Dep_node*&);
   int add_to_dep_list(const obj_type, Dep_node*);
 
-  struct get_dep_node_res 
-  { 
+  struct get_dep_node_res
+  {
     enum value {
       NEW_NODE,
-      EXISTING_NODE, 
-      ERROR 
+      EXISTING_NODE,
+      ERROR
     };
   };
-  
+
   /**
     List of existing @c Snapshot_info objects.
-    
+
     This list is used when selecting a backup engine for a given table. Order
-    of this list is important -- more preferred snapshots should come first. 
-   */ 
+    of this list is important -- more preferred snapshots should come first.
+  */
   List<backup::Snapshot_info> snapshots;
-  
+
   /**
     Stores existing native snapshot objects.
-    
+
     Given reference to a storage engine, a corresponding native snapshot object
-    can be quickly located if it was already created. 
-   */ 
+    can be quickly located if it was already created.
+  */
   Map<storage_engine_ref, backup::Native_snapshot > native_snapshots;
 
   struct Ts_hash_node;	///< Hash nodes used in @c ts_hash.
 
   /**
     Hash storing all tablespaces added to the backup catalogue.
-    
+
     Used for quickly determining if the catalogue contains a given
     tablespace or not.
-   */ 
+  */
   HASH   ts_hash;
 
-
   /**
     Pointer to the first element on the dependency list.
-    
-    Dependency list lists all per-database objects in the order which takes 
-    into account possible dependencies between them. The list is divided into 
+
+    Dependency list lists all per-database objects in the order which takes
+    into account possible dependencies between them. The list is divided into
     three sections:
-    
+
     -# stored routines (functions and procedures)
     -# views
     -# triggers
     -# events
-   */ 
+  */
   Dep_node  *m_dep_list;
   Dep_node  *m_dep_end; ///< Pointer to the last element on the dependency list.
 
-  /** 
-    Points at the last element in the stored routines section of the dependency 
+  /**
+    Points at the last element in the stored routines section of the dependency
     list. NuLL if this section is empty.
-   */
+  */
   Dep_node  *m_srout_end;
 
-  /** 
-    Points at the last view on the dependency list. NuLL if views section is 
+  /**
+    Points at the last view on the dependency list. NuLL if views section is
     empty.
-   */
+  */
   Dep_node  *m_view_end;
 
-  /** 
+  /**
     Points at the last trigger on the dependency list. NULL if triggers section
     is empty.
-   */
+  */
   Dep_node  *m_trigger_end;
-  
-  /** 
+
+  /**
     Points at the last event on the dependency list. NULL if events section
     is empty.
-   */
+  */
   Dep_node  *m_event_end;
-  
+
   /**
     Hash keeping all elements stored in the dependency list.
 
     It is used to quickly check if a given object is on the list. Hash is
     indexed by <database name, object name> pairs.
-   */ 
+  */
   HASH dep_hash;
 
 
   String serialization_buf; ///< Used to store serialization strings of objects.
-  
-  friend int backup::write_table_data(THD*, backup::Logger&, Backup_info&, 
+
+
+  friend int backup::write_table_data(THD*, backup::Logger&, Backup_info&,
                                       backup::Output_stream&);
-  // Needs access to serialization_buf
+  // Needs access to serialization_buf.
   friend int ::bcat_get_item_create_query(st_bstream_image_header *catalogue,
                                struct st_bstream_item_info *item,
                                bstream_blob *stmt);
   friend class Backup_restore_ctx;  // Needs access to the constructor.
 };
 
+
 /// Check if instance is correctly created.
+
 inline
 bool Backup_info::is_valid()
 {

=== modified file 'sql/backup/backup_kernel.h'
--- a/sql/backup/backup_kernel.h	2009-10-21 12:15:53 +0000
+++ b/sql/backup/backup_kernel.h	2009-10-21 13:32:24 +0000
@@ -7,7 +7,7 @@
 /**
   @file
 
-  Functions and types forming the backup kernel API
+  Functions and types forming the backup kernel API.
 */
 
 
@@ -19,28 +19,29 @@
 
 /*
   Functions used to initialize and shut down the MySQL backup system.
-  
+
   Note: these functions are called at plugin load and plugin shutdown time,
   respectively.
- */ 
+*/
 int backup_init();
 void backup_shutdown();
 
 /*
   Called from the big switch in mysql_execute_command() to execute
-  backup related statement
+  backup related statement.
 */
-int execute_backup_command(THD *thd, 
-                           LEX *lex, 
-                           String *backupdir, 
+int execute_backup_command(THD *thd,
+                           LEX *lex,
+                           String *backupdir,
                            bool overwrite,
                            bool skip_gap_event);
 
-// forward declarations
+// Forward declarations.
 
 class Backup_info;
 class Restore_info;
 
+
 namespace backup {
 
 class Mem_allocator;
@@ -49,36 +50,39 @@ class Output_stream;
 class Input_stream;
 class Native_snapshot;
 
+
 int write_table_data(THD*, Backup_info&, Output_stream&);
 int restore_table_data(THD*, Restore_info&, Input_stream&);
 
 }
 
+
 /**
   Instances of this class are used for creating required context and performing
   backup/restore operations.
-  
+
   @see kernel.cc
- */ 
-class Backup_restore_ctx: public backup::Logger 
+*/
+
+class Backup_restore_ctx: public backup::Logger
 {
 public:
 
-  /// Constructor
+  /// Constructor.
   Backup_restore_ctx(THD*);
-  /// Destructor
+  /// Destructor.
   ~Backup_restore_ctx();
 
   bool is_valid() const;
   bool is_killed() const;
   ulonglong op_id() const;
 
-  Backup_info*  prepare_for_backup(String *location, 
-                                   LEX_STRING orig_loc, 
+  Backup_info*  prepare_for_backup(String *location,
+                                   LEX_STRING orig_loc,
                                    const char*, bool, bool);
-  Restore_info* prepare_for_restore(String *location, 
+  Restore_info* prepare_for_restore(String *location,
                                    LEX_STRING orig_loc,
-                                   const char*, bool);  
+                                   const char*, bool);
 
   int do_backup();
   int do_restore(bool overwrite);
@@ -90,23 +94,25 @@ public:
 
 private:
 
-  // Prevent copying/assignments
+  // Prevent copying/assignments.
   Backup_restore_ctx(const Backup_restore_ctx&);
   Backup_restore_ctx& operator=(const Backup_restore_ctx&);
 
-  /** @c current_op points to the @c Backup_restore_ctx for the
-      ongoing backup/restore operation.  If pointer is null, no
-      operation is currently running. */
+  /**
+    @c current_op points to the @c Backup_restore_ctx for the
+    ongoing backup/restore operation.  If pointer is null, no
+    operation is currently running.
+  */
   static Backup_restore_ctx *current_op;
   /**
-     Indicates if @c run_lock mutex was initialized and thus it should
-     be properly destroyed during shutdown. @sa backup_shutdown().
-   */
+    Indicates if @c run_lock mutex was initialized and thus it should
+    be properly destroyed during shutdown. @sa backup_shutdown().
+  */
   static bool run_lock_initialized;
   static pthread_mutex_t  run_lock; ///< To guard @c current_op.
 
-  /** 
-    @brief State of a context object. 
+  /**
+    @brief State of a context object.
 
     The following diagram illustrates the states in which a context object
     can be and how the state changes as a result of calling public methods.
@@ -129,10 +135,10 @@ private:
         close()                -> CLOSED
     @endverbatim
 
-    @note An instance of the context class can be used only once -- when it 
+    @note An instance of the context class can be used only once -- when it
     moves to CLOSED state no methods can be called except for close() which does
     nothing in that case.
-   */
+  */
   enum { CREATED,
          PREPARED_FOR_BACKUP,
          PREPARED_FOR_RESTORE,
@@ -142,22 +148,22 @@ private:
   /**
     @brief Tells if context object is in error state.
 
-    In case of fatal error, the context object is put into an error state 
+    In case of fatal error, the context object is put into an error state
     by setting @m_error to non-zero value. This can be the code of
     the detected error but currently the exact value is not used.
 
     When in error state, public methods of Backup_restore_ctx do not try
-    to perform their operations but report an error instead. @c Is_valid() 
+    to perform their operations but report an error instead. @c Is_valid()
     will return FALSE for an object in error state.
 
     @note The error state is an internal state of the context object. The
-    object can enter this state only as a result of executing one of its 
+    object can enter this state only as a result of executing one of its
     methods.
   */
   int m_error;
   int fatal_error(int);
-  
-  ::String  m_path;   ///< Path to where the backup image file is located.
+
+  ::String  m_path;         ///< Path to where the backup image file is located.
 
   backup::Stream *m_stream; ///< Pointer to the backup stream object, if opened.
   backup::Image_info *m_catalog;  ///< Pointer to the image catalogue object.
@@ -165,15 +171,13 @@ private:
   /** Memory allocator for backup stream library. */
   backup::Mem_allocator *mem_alloc;
 
-  int prepare_path(::String *backupdir, 
+  int prepare_path(::String *backupdir,
                    LEX_STRING orig_loc);
   int prepare(::String *backupdir, LEX_STRING location);
   void disable_fkey_constraints();
   int  restore_triggers_and_events();
-  
-  /** 
-    Indicates if tables have been locked with @c lock_tables_for_restore()
-  */
+
+  /// Indicates if tables have been locked with @c lock_tables_for_restore().
   bool m_tables_locked;
 
   /**
@@ -190,11 +194,11 @@ private:
 
   int lock_tables_for_restore();
   void unlock_tables();
-  
+
   int report_stream_open_failure(int open_error, const LEX_STRING *location);
 
-  /// Indicates if the operation has been successfully completed.  
-  bool m_completed;  
+  /// Indicates if the operation has been successfully completed.
+  bool m_completed;
 
   friend int backup_init();
   friend void backup_shutdown();
@@ -202,51 +206,61 @@ private:
   friend void bstream_free(bstream_byte *ptr);
 };
 
+
 /// Check if instance is correctly created.
+
 inline
 bool Backup_restore_ctx::is_valid() const
 {
   return m_error == 0;
 }
 
+
 /// Check if the operation has been interrupted.
+
 inline
 bool Backup_restore_ctx::is_killed() const
 {
   return m_thd->killed;
 }
 
+
 /// Return global id of the backup/restore operation.
+
 inline
 ulonglong Backup_restore_ctx::op_id() const
 {
-  return get_op_id(); // inherited from Logger class
+  return get_op_id(); // Inherited from Logger class.
 }
 
+
 /// Disable foreign key constraint checks (needed during restore).
+
 inline
 void Backup_restore_ctx::disable_fkey_constraints()
 {
   m_thd->options|= OPTION_NO_FOREIGN_KEY_CHECKS;
 }
 
+
 /**
   Move context object into error state.
-  
+
   After this method is called the context object is in error state and
-  cannot be normally used. The provided error code is saved in m_error 
+  cannot be normally used. The provided error code is saved in m_error
   member.
-  
+
   Only one fatal error can be reported. If context is already in error
   state when this method is called, it does nothing.
 
   @note Context object should enter error state only as a result of executing
-  one of its methods. Thus this private helper method is intended to be used 
-  only from within Backup_restore_ctx class.  
-  
+  one of its methods. Thus this private helper method is intended to be used
+  only from within Backup_restore_ctx class.
+
   @return error code given as input or stored in the context object if
   it is already in error state.
- */ 
+*/
+
 inline
 int Backup_restore_ctx::fatal_error(int error_code)
 {
@@ -261,6 +275,7 @@ int Backup_restore_ctx::fatal_error(int 
   return error_code;
 }
 
+
 /*
   Now, when Backup_restore_ctx is defined, include definitions
   of Backup_info and Restore_info classes.

=== modified file 'sql/backup/backup_test.cc'
--- a/sql/backup/backup_test.cc	2009-03-10 10:02:06 +0000
+++ b/sql/backup/backup_test.cc	2009-10-21 13:32:24 +0000
@@ -4,7 +4,7 @@
   Implementation of the backup test function.
 
   @todo Implement code to test service interface(s).
- */
+*/
 
 #include "../mysql_priv.h"
 #include "si_objects.h"
@@ -12,12 +12,13 @@
 
 using namespace obs;
 
+
 /**
    Call backup kernel API to execute backup related SQL statement.
 
    @param[in] thd  current thread
    @param[in] db_list  List of databases.
-  */
+*/
 int execute_backup_test_command(THD *thd, List<LEX_STRING> *db_list)
 {
   int res= 0;
@@ -42,11 +43,12 @@ int execute_backup_test_command(THD *thd
   field_list.push_back(new Item_empty_string("name", 5));
   field_list.push_back(new Item_empty_string("type", 4));
   field_list.push_back(new Item_empty_string("serialization", 13));
-  protocol->send_result_set_metadata(&field_list, Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF);
+  protocol->send_result_set_metadata(&field_list, Protocol::SEND_NUM_ROWS 
+                                                  | Protocol::SEND_EOF);
 
   //obs::Obj_iterator *it= obs::get_databases(thd);
   List_iterator<LEX_STRING> it(*db_list);
-  
+
   //if (it)
   {
     obs::Obj *db;
@@ -264,4 +266,3 @@ int execute_backup_test_command(THD *thd
   my_eof(thd);
   DBUG_RETURN(res);
 }
-

=== modified file 'sql/backup/be_default.cc'
--- a/sql/backup/be_default.cc	2009-10-12 09:08:34 +0000
+++ b/sql/backup/be_default.cc	2009-10-21 13:32:24 +0000
@@ -4,7 +4,7 @@
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; version 2 of the License.
 
-   This program is distributed in the hope that it will be useful, 
+   This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.
@@ -15,30 +15,30 @@
 */
 
 /**
-   @file 
- 
+   @file
+
    @brief Contains the default backup algorithm driver.
- 
+
    This file contains the default backup algorithm (also called a "driver"
    in the MySQL backup terminology. The default backup algorithm may be
    used in place of an engine-specific driver if one does not exist or if
    chosen by the user.
- 
+
    The default backup algorithm is a blocking algorithm that locks all of
    the tables given at the start of the backup/restore process. Once all of
    the data is backed up or restored, the locks are removed. The default
    backup is a row-level backup and therefore does not backup the indexes
    or any of the engine-specific files.
- 
+
    The classes in this file use the namespace @c default_backup to distinguish
    these classes from other backup drivers. The backup functionality is
    contained in the backup class shown below. Similarly, the restore
    functionality is contained in the restore class below.
- 
+
    The format of the backup is written as a series of data blocks where each
-   block contains a flag indicating what kind of data is in the block. The 
+   block contains a flag indicating what kind of data is in the block. The
    flags are:
- 
+
    <code>
      RCD_ONCE   - Single data block for record data
      RCD_FIRST  - First data block in buffer for record buffer
@@ -49,19 +49,20 @@
      BLOB_DATA  - Intermediate data block for blob buffer
      BLOB_LAST  - Last data block in buffer for blob buffer
    </code>
- 
+
    The flag is the first byte in the block. The remaining space in the block
    is the data -- either record data or blob fields.
- 
-   The block flagged as BLOB_FIRST also contains a 4-byte field which 
+
+   The block flagged as BLOB_FIRST also contains a 4-byte field which
    contains the total size of the blob field. This is necessary for restore
-   because the size of the blob field is unknown and the size is needed to 
+   because the size of the blob field is unknown and the size is needed to
    allocate memory for the buffer_iterator used to buffer large data from
    the kernel.
- 
+
    @todo Consider making the enums for BACKUP_MODE and RESTORE_MODE bit fields.
    @todo Change code to ignore blobs with no data (NULL).
- */
+*/
+
 #include "../mysql_priv.h"
 #include "backup_engine.h"
 #include "be_default.h"
@@ -85,17 +86,18 @@ Backup::Backup(const Table_list &tables,
   :Backup_thread_driver(tables)
 {
   DBUG_PRINT("default_backup",("Creating backup driver"));
-  locking_thd->m_thd= t_thd;  /* save current thread */
-  cur_table= NULL;      /* flag current table as null */
-  tbl_num= 0;           /* set table number to 0 */
-  mode= INITIALIZE;     /* initialize read */
-  locking_thd->lock_thd= NULL;  /* set lock thread to 0 */
+  locking_thd->m_thd=    t_thd;      /* Save current thread. */
+  cur_table=             NULL;       /* flag current table as null */
+  tbl_num=               0;          /* set table number to 0 */
+  mode=                  INITIALIZE; /* initialize read */
+  locking_thd->lock_thd= NULL;       /* Set lock thread to 0. */
 
   /*
      Create a TABLE_LIST * list for iterating through the tables.
      Initialize the list for opening the tables in read mode.
   */
-  all_tables= (TABLE_LIST*)my_malloc(tables.count()*sizeof(TABLE_LIST), MYF(MY_WME));
+  all_tables= 
+    (TABLE_LIST*)my_malloc(tables.count()*sizeof(TABLE_LIST), MYF(MY_WME));
   DBUG_ASSERT(all_tables); // TODO: report error instead
 
   for (uint i=0; i < tables.count(); ++i)
@@ -107,7 +109,7 @@ Backup::Backup(const Table_list &tables,
                                  tables[i].name().ptr(),
                                  lock_type);
 
-    // link previous entry to this one
+    // Link previous entry to this one.
     if (i > 0)
       backup::link_table_list(all_tables[i-1], &all_tables[i]);
   }
@@ -119,6 +121,7 @@ Backup::Backup(const Table_list &tables,
   m_cleanup= TRUE;
 }
 
+
 /**
   Cleanup backup
 
@@ -127,6 +130,7 @@ Backup::Backup(const Table_list &tables,
   table read then attempts to kill the locking thread if it is still
   running.
 */
+
 result_t Backup::cleanup()
 {
   DBUG_ENTER("Default_backup::cleanup()");
@@ -153,35 +157,39 @@ Backup::~Backup()
   */
   locking_thd->kill_locking_thread();
   locking_thd->wait_until_locking_thread_dies();
-  my_free(all_tables, MYF(0)); 
+  my_free(all_tables, MYF(0));
 }
 
 
 /**
   @brief Prelock call to setup locking.
-  
+
   Launches a separate thread ("locking thread") which will lock
   tables. Locking in a separate thread is needed to have a non-blocking
   prelock() (given that thr_lock() is blocking).
 */
+
 result_t Backup::prelock()
 {
   DBUG_ENTER("Default_backup::prelock()");
-  DBUG_RETURN(locking_thd->start_locking_thread("default driver locking thread"));
+  DBUG_RETURN(locking_thd->start_locking_thread("default driver"
+                                                " locking thread"));
 }
 
+
 /**
   @brief Start table read.
- 
+
   This method saves the handler for the table and initializes the
   handler for reading.
- 
+
   @retval OK     handler initialized properly.
   @retval ERROR  problem with hander initialization.
 */
+
 result_t Backup::start_tbl_read(TABLE *tbl)
 {
-  int last_read_res;  
+  int last_read_res;
 
   DBUG_ENTER("Default_backup::start_tbl_read)");
   DBUG_ASSERT(tbl->file);
@@ -195,13 +203,15 @@ result_t Backup::start_tbl_read(TABLE *t
   DBUG_RETURN(OK);
 }
 
+
 /**
   @brief End table read.
   This method signals the handler that the reading process is complete.
-  
+
   @retval OK     handler read stopped properly.
   @retval ERROR  problem with hander.
 */
+
 result_t Backup::end_tbl_read()
 {
   int last_read_res;
@@ -218,15 +228,17 @@ result_t Backup::end_tbl_read()
   DBUG_RETURN(OK);
 }
 
+
 /**
   @brief Get next table in the list.
- 
+
   This method iterates through the list of tables selecting the
   next table in the list and starting the read process.
- 
+
   @retval 0   no errors.
   @retval -1  no more tables in list.
 */
+
 int Backup::next_table()
 {
   DBUG_ENTER("Backup::next_table()");
@@ -252,18 +264,21 @@ int Backup::next_table()
   DBUG_RETURN(0);
 }
 
+
 /* Potential buffer on the stack for the bitmap */
+
 /// Define bitmap stack size.
 #define BITMAP_STACKBUF_SIZE (128/8)
 
 /**
   @brief Pack the data for a row in the table.
-   
+
   This method uses the binary log methods to pack a row from the
   internal row format to the binary log format.
- 
+
   @returns  Size of packed row.
 */
+
 uint Backup::pack(byte *rcd, byte *packed_row)
 {
   uint size= 0;
@@ -273,11 +288,13 @@ uint Backup::pack(byte *rcd, byte *packe
   if (cur_table)
   {
     MY_BITMAP cols;
-    /* Potential buffer on the stack for the bitmap */
-    uint32 bitbuf[BITMAP_STACKBUF_SIZE/sizeof(uint32)];
-    uint n_fields= cur_table->s->fields;
+    /* Potential buffer on the stack for the bitmap. */
+    uint32  bitbuf[BITMAP_STACKBUF_SIZE/sizeof(uint32)];
+    uint    n_fields=   cur_table->s->fields;
     my_bool use_bitbuf= n_fields <= sizeof(bitbuf) * 8;
-    error= bitmap_init(&cols, use_bitbuf ? bitbuf : NULL, (n_fields + 7) & ~7UL, FALSE);
+
+    error= bitmap_init(&cols, use_bitbuf ? bitbuf : NULL, 
+                       (n_fields + 7) & ~7UL, FALSE);
     bitmap_set_all(&cols);
     size= pack_row(cur_table, &cols, packed_row, rcd, FALSE);
     if (!use_bitbuf)
@@ -286,16 +303,17 @@ uint Backup::pack(byte *rcd, byte *packe
   DBUG_RETURN(size);
 }
 
+
 /**
   @brief Get the data for a row in the table.
   This method is the main method used in the backup operation. It is
   responsible for reading a row from the table and placing the data in
   the buffer (buf.data) and setting the correct attributes for processing
   (e.g., buf.size = size of record data).
-  
+
   Control of the method is accomplished by using several modes that
   signal portions of the method to run. These modes are:
-  
+
   <code>
   INITIALIZE          Indicates time to initialize read
   GET_NEXT_TABLE      Open next table in the list
@@ -305,15 +323,16 @@ uint Backup::pack(byte *rcd, byte *packe
   READ_BLOB           Reading blobs from record mode
   READ_BLOB_BUFFER    Buffer blobs mode
   </code>
-  
+
   @retval READY   initialization phase complete.
   @retval OK      data read.
   @retval ERROR   problem with reading data.
   @retval DONE    driver finished reading from all tables.
 */
+
 result_t Backup::get_data(Buffer &buf)
 {
-  int last_read_res;  
+  int last_read_res;
 
   DBUG_ENTER("Default_backup::get_data(Buffer &buf)");
 
@@ -326,18 +345,18 @@ result_t Backup::get_data(Buffer &buf)
   if (!locks_acquired)
   {
     buf.size= 0;
-    buf.table_num= 0; 
+    buf.table_num= 0;
     buf.last= TRUE;
     switch (locking_thd->lock_state) {
-    case LOCK_ERROR:             // Something ugly happened in locking
+    case LOCK_ERROR:             // Something ugly happened in locking.
       DBUG_RETURN(ERROR);
-    case LOCK_ACQUIRED:          // First time lock ready for validity point
+    case LOCK_ACQUIRED:          // First time lock ready for validity point.
     {
       locks_acquired= TRUE;
       DEBUG_SYNC(locking_thd->m_thd, "default_locking_thread_added");
       DBUG_RETURN(READY);
     }
-    default:                     // If first call, signal end of init phase
+    default:                     // If first call, signal end of init phase.
       if (init_phase_complete)
         DBUG_RETURN(OK);
       else
@@ -351,19 +370,13 @@ result_t Backup::get_data(Buffer &buf)
   buf.table_num= tbl_num;
   buf.last= FALSE;
 
-  /* 
-    get_data() should not be called after cancel has been called.
-  */
+  // get_data() should not be called after cancel has been called.
   DBUG_ASSERT(mode != CANCEL);
 
-  /* 
-    Determine mode of operation and execute mode.
-  */
+  // Determine mode of operation and execute mode.
   switch (mode) {
 
-  /*
-    Nothing to do in Initialize, continue to GET_NEXT_TABLE.
-  */
+  // Nothing to do in Initialize, continue to GET_NEXT_TABLE.
   case INITIALIZE:
 
   /*
@@ -381,13 +394,13 @@ result_t Backup::get_data(Buffer &buf)
     }
 
     cur_table= all_tables[tbl_num++].table;
-    DBUG_ASSERT(cur_table); // tables should be opened at that time
+    DBUG_ASSERT(cur_table); // Tables should be opened at that time.
     read_set=  cur_table->read_set;
     start_tbl_read(cur_table);
 
     // The first time the table is accessed after opening it,
     // cur_table->in_use points to the locking thread. It has to point
-    // to the backup thread before the table can be read
+    // to the backup thread before the table can be read.
     if (cur_table->in_use != locking_thd->m_thd) {
       DBUG_ASSERT(cur_table->in_use == locking_thd->lock_thd);
       cur_table->in_use= locking_thd->m_thd;
@@ -397,9 +410,7 @@ result_t Backup::get_data(Buffer &buf)
     mode= READ_RCD;
   }
 
-  /*
-    Read a row from the table and save the data in the buffer.
-  */
+  // Read a row from the table and save the data in the buffer.
   case READ_RCD:
   {
     uint32 size= cur_table->s->reclength;
@@ -408,9 +419,7 @@ result_t Backup::get_data(Buffer &buf)
     cur_blob= 0;
     cur_table->use_all_columns();
     last_read_res = hdl->rnd_next(cur_table->record[0]);
-    /*
-      Skip all records marked as deleted.
-    */
+    // Skip all records marked as deleted.
     while (last_read_res == HA_ERR_RECORD_DELETED)
       last_read_res= hdl->rnd_next(cur_table->record[0]);
     DBUG_EXECUTE_IF("SLEEP_DRIVER", sleep(4););
@@ -446,7 +455,7 @@ result_t Backup::get_data(Buffer &buf)
       */
       if ((size + META_SIZE) <= buf.size)
       {
-        *buf.data= RCD_ONCE; //only part 1 of 1
+        *buf.data= RCD_ONCE; // Only part 1 of 1.
         int packed_size= 0;
         packed_size= pack(cur_table->record[0], buf.data + META_SIZE);
         buf.size = packed_size + META_SIZE;
@@ -462,9 +471,9 @@ result_t Backup::get_data(Buffer &buf)
         rec_buffer.initialize(size);
         packed_ptr= rec_buffer.get_base_ptr();
         packed_size= pack(cur_table->record[0], packed_ptr);
-        rec_size= rec_buffer.get_next((byte **)&rec_ptr, 
+        rec_size= rec_buffer.get_next((byte **)&rec_ptr,
           (buf.size - META_SIZE));
-        *buf.data= RCD_FIRST; // first part
+        *buf.data= RCD_FIRST; // First part.
         memcpy((byte *)buf.data + META_SIZE, rec_ptr, rec_size);
         buf.size = rec_size + META_SIZE;
         mode= READ_RCD_BUFFER;
@@ -473,12 +482,10 @@ result_t Backup::get_data(Buffer &buf)
     break;
   }
 
-  /*
-    Read data from the record buffer and write to the kernel buffer.
-  */
+  // Read data from the record buffer and write to the kernel buffer.
   case READ_RCD_BUFFER:
   {
-    size_t rec_size= 0; 
+    size_t rec_size= 0;
 
     rec_size= rec_buffer.get_next((byte **)&ptr, (buf.size - META_SIZE));
     memcpy((byte *)buf.data + META_SIZE, ptr, rec_size);
@@ -487,7 +494,7 @@ result_t Backup::get_data(Buffer &buf)
     {
       *buf.data= RCD_LAST;
       mode= CHECK_BLOBS;   // Check for blobs.
-      rec_buffer.reset();  // dump the memory 
+      rec_buffer.reset();  // Dump the memory.
     }
     else
       *buf.data= RCD_DATA;
@@ -514,7 +521,7 @@ result_t Backup::get_data(Buffer &buf)
         Iterate to the next blob. If no more blobs, we're finished reading
         the row.
       */
-      else 
+      else
       {
         cur_blob++;
         if (cur_blob == last_blob_ptr)
@@ -526,9 +533,7 @@ result_t Backup::get_data(Buffer &buf)
     break;
   }
 
-  /*
-    Get next blob. Use blob buffer if blob field is too large for buffer.data.
-  */
+  // Get next blob. Use blob buffer if blob field is too large for buffer.data.
   case READ_BLOB:
   {
     uint32 size= ((Field_blob*) cur_table->field[*cur_blob])->get_length();
@@ -551,11 +556,11 @@ result_t Backup::get_data(Buffer &buf)
 
       ((Field_blob*) cur_table->field[*cur_blob])->get_ptr((uchar **)&ptr);
       blob_buffer.initialize((byte *)ptr, size);
-      *buf.data= BLOB_FIRST;   //first block
-      uint32 field_size= 
+      *buf.data= BLOB_FIRST;   // First block.
+      uint32 field_size=
         ((Field_blob*) cur_table->field[*cur_blob])->get_length();
-      int4store(buf.data + META_SIZE, field_size);     //save max size
-      bb_size= blob_buffer.get_next((byte **)&blob_ptr, 
+      int4store(buf.data + META_SIZE, field_size);     // Save max size.
+      bb_size= blob_buffer.get_next((byte **)&blob_ptr,
         (buf.size - META_SIZE - 4));
       memcpy((byte *)buf.data + META_SIZE + 4, blob_ptr, bb_size);
       buf.size = bb_size + META_SIZE + 4;
@@ -564,9 +569,7 @@ result_t Backup::get_data(Buffer &buf)
     break;
   }
 
-/*
-  Read data from the blob buffer.
-*/
+  // Read data from the blob buffer.
   case READ_BLOB_BUFFER:
   {
     size_t bb_size= 0;
@@ -578,7 +581,7 @@ result_t Backup::get_data(Buffer &buf)
     {
       *buf.data= BLOB_LAST;
       mode= CHECK_BLOBS;
-      blob_buffer.reset();     // dump the memory 
+      blob_buffer.reset();     // Dump the memory.
     }
     else
       *buf.data= BLOB_DATA;
@@ -588,18 +591,18 @@ result_t Backup::get_data(Buffer &buf)
   default:
     DBUG_RETURN(ERROR);
   }
-  DBUG_RETURN(OK); 
+  DBUG_RETURN(OK);
 }
 
 
-Restore::Restore(const backup::Logical_snapshot &snap, THD *t_thd) 
+Restore::Restore(const backup::Logical_snapshot &snap, THD *t_thd)
   :Restore_driver(snap.get_table_list()), m_snap(snap)
 {
   DBUG_PRINT("default_backup",("Creating restore driver"));
-  m_thd= t_thd;         /* save current thread */
-  cur_table= NULL;      /* flag current table as null */
-  tbl_num= 0;           /* set table number to 0 */
-  mode= INITIALIZE;     /* initialize write */
+  m_thd=     t_thd;       /* Save current thread. */
+  cur_table= NULL;        /* Flag current table as null. */
+  tbl_num=   0;           /* Set table number to 0. */
+  mode=      INITIALIZE;  /* Initialize write. */
 
   for (int i=0; i < MAX_FIELDS; i++)
     blob_ptrs[i]= 0;
@@ -607,6 +610,7 @@ Restore::Restore(const backup::Logical_s
   m_cleanup= TRUE;
 }
 
+
 /**
   Cleanup restore
 
@@ -614,6 +618,7 @@ Restore::Restore(const backup::Logical_s
   the driver to shutdown gracefully. The method call closes the
   table list by calling end() method.
 */
+
 result_t Restore::cleanup()
 {
   DBUG_ENTER("Default_backup::cleanup()");
@@ -626,28 +631,32 @@ result_t Restore::cleanup()
   DBUG_RETURN(OK);
 }
 
+
 /**
   @brief End restore process.
-  
+
   This method unlocks and closes all of the tables.
-  
+
   @retval OK    all tables unlocked.
 */
+
 result_t Restore::end()
 {
   DBUG_ENTER("Restore::end");
   DBUG_RETURN(OK);
 }
 
+
 /**
   @brief Unpack the data for a row in the table.
-  
+
   This method uses the binary log methods to unpack a row from the
   binary log format to the internal row format.
-  
+
   @retval 0   no errors.
   @retval !0  errors during unpack_row().
 */
+
 uint Restore::unpack(byte *packed_row)
 {
   int error= 0;
@@ -657,31 +666,34 @@ uint Restore::unpack(byte *packed_row)
   if (cur_table)
   {
     MY_BITMAP cols;
-    /* Potential buffer on the stack for the bitmap */
+    /* Potential buffer on the stack for the bitmap. */
     uint32 bitbuf[BITMAP_STACKBUF_SIZE/sizeof(uint32)];
     uint n_fields= cur_table->s->fields;
     /* Restore a default record -- MyISAM needs this to work properly. */
     restore_record(cur_table, s->default_values);
     my_bool use_bitbuf= n_fields <= sizeof(bitbuf) * 8;
-    error= bitmap_init(&cols, use_bitbuf ? bitbuf : NULL, (n_fields + 7) & ~7UL, FALSE);
+    error= bitmap_init(&cols, use_bitbuf ? bitbuf : NULL, 
+                       (n_fields + 7) & ~7UL, FALSE);
     bitmap_set_all(&cols);
     ulong length;
-    error= unpack_row(NULL, cur_table, n_fields, packed_row, &cols, &cur_row_end, &length, FALSE);
+    error= unpack_row(NULL, cur_table, n_fields, packed_row, &cols, 
+                      &cur_row_end, &length, FALSE);
     if (!use_bitbuf)
       bitmap_free(&cols);
   }
   DBUG_RETURN(error);
 }
 
+
 /**
   @brief Restore the data for a row in the table.
-  
+
   This method is the main method used in the restore operation. It is
   responsible for writing a row to the table.
-  
+
   Control of the method is accomplished by using several modes that
   Signal portions of the method to run. These modes are:
-  
+
   <code>
   INITIALIZE          Indicates time to initialize read
   GET_NEXT_TABLE      Open next table in the list
@@ -690,49 +702,42 @@ uint Restore::unpack(byte *packed_row)
   WRITE_BLOB          Writing blobs from record mode
   WRITE_BLOB_BUFFER   Buffer blobs mode
   </code>
-  
+
   @retval READY       initialization phase complete.
   @retval OK          data written.
   @retval ERROR       problem with writing data.
   @retval PROCESSING  switching modes -- do not advance stream.
   @retval DONE        driver finished writing to all tables.
 */
+
 result_t Restore::send_data(Buffer &buf)
 {
   byte *ptr= 0;
-  int last_write_res; 
+  int last_write_res;
   byte block_type= 0;
 
   DBUG_ENTER("Restore::send_data");
   DBUG_PRINT("default_restore",("Got packet with %lu bytes from stream %u",
                                 (unsigned long)buf.size, buf.table_num));
-  
+
   DBUG_EXECUTE_IF("restore_default_send_data", DBUG_RETURN(ERROR););
 
-  /* 
-    get_data() should not be called after cancel has been called.
-  */
+  // get_data() should not be called after cancel has been called.
   DBUG_ASSERT(mode != CANCEL);
 
-  /* 
-    Determine mode of operation and execute mode.
-  */
+  // Determine mode of operation and execute mode.
   switch (mode) {
 
-  /*
-    Nothing to do in Initialize, continue to WRITE_RCD.
-  */
+  // Nothing to do in Initialize, continue to WRITE_RCD.
   case INITIALIZE:
 
-  /*
-    Write a row to the table from the data in the buffer.
-  */
+  // Write a row to the table from the data in the buffer.
   case WRITE_RCD:
   {
     cur_blob= 0;
     max_blob_size= 0;
 
-    // We don't process any data on stream #0
+    // We don't process any data on stream #0.
     if (buf.table_num == 0)
       DBUG_RETURN(OK);
 
@@ -741,8 +746,8 @@ result_t Restore::send_data(Buffer &buf)
       DBUG_RETURN(OK);
 
     /*
-     Get the opened table instance corresponding to buf.table_num. Note that
-     tables are opened (and locked) by the kernel.
+      Get the opened table instance corresponding to buf.table_num. Note that
+      tables are opened (and locked) by the kernel.
     */
     cur_table= m_snap.get_opened_table(buf.table_num - 1);
     DBUG_ASSERT(cur_table); // All tables we are processing should be opened.
@@ -756,35 +761,29 @@ result_t Restore::send_data(Buffer &buf)
       cur_table->timestamp_field_type= TIMESTAMP_NO_AUTO_SET;
 
     hdl= cur_table->file;
-    DBUG_ASSERT(hdl); // table should be opened
+    DBUG_ASSERT(hdl); // Table should be opened.
 
     {
       uint32 size= buf.size - META_SIZE;
       block_type= *buf.data;
       cur_table->use_all_columns();
-      /*
-         Now we're reconstructing the rec from multiple parts.
-      */
+      // Now we're reconstructing the rec from multiple parts.
       switch (block_type) {
 
-      /*
-        Buffer iterator not needed, just write the data.
-      */
+      // Buffer iterator not needed, just write the data.
       case RCD_ONCE:
       {
         uint error= unpack((byte *)buf.data + META_SIZE);
         if (error)
           DBUG_RETURN(ERROR);
-        else 
+        else
         {
           mode= CHECK_BLOBS;
           DBUG_RETURN(PROCESSING);
         }
       }
 
-      /*
-        This is the first part of several, create new iterator.
-      */
+      // This is the first part of several, create new iterator.
       case RCD_FIRST:
       {
         rec_buffer.initialize(cur_table->s->reclength);
@@ -793,9 +792,7 @@ result_t Restore::send_data(Buffer &buf)
         break;
       }
 
-      /*
-        Save the part and keep reading.
-      */
+      // Save the part and keep reading.
       case RCD_DATA:
       {
         rec_buffer.put_next((byte *)buf.data + META_SIZE, size);
@@ -803,9 +800,8 @@ result_t Restore::send_data(Buffer &buf)
         break;
 
       }
-      /*
-        If this is the last part, assemble and write.
-      */
+
+      // If this is the last part, assemble and write.
       case RCD_LAST:
       {
         rec_buffer.put_next((byte *)buf.data + META_SIZE, size);
@@ -814,6 +810,7 @@ result_t Restore::send_data(Buffer &buf)
         rec_buffer.reset();
         mode= CHECK_BLOBS;
       }
+
       default:
         DBUG_RETURN(ERROR);
       }
@@ -841,10 +838,10 @@ result_t Restore::send_data(Buffer &buf)
         last_blob_ptr = cur_blob + cur_table->s->blob_fields;
       }
       /*
-        Iterate to the next blob. If no more blobs, we're finished writing 
+        Iterate to the next blob. If no more blobs, we're finished writing
         the row.
       */
-      else 
+      else
       {
         cur_blob++;
         if (cur_blob == last_blob_ptr)
@@ -860,9 +857,7 @@ result_t Restore::send_data(Buffer &buf)
       IF_DBUG(write_skip:); /* Label for error injection. */
       DBUG_PRINT("backup_default_write", ("%d", last_write_res));
 
-      /*
-        Free the blob pointers used.
-      */
+      // Free the blob pointers used.
       for (int i=0; i < blob_ptr_index; i++)
         if (blob_ptrs[i])
         {
@@ -889,14 +884,12 @@ result_t Restore::send_data(Buffer &buf)
     block_type= *buf.data;
     switch (block_type) {
 
-    /*
-      Buffer iterator not needed, just write the data.
-    */
+    // Buffer iterator not needed, just write the data.
     case BLOB_ONCE:
     {
       blob_ptrs[blob_ptr_index]= (byte *)my_malloc(size, MYF(MY_WME));
       memcpy(blob_ptrs[blob_ptr_index], (byte *)buf.data + META_SIZE, size);
-      ((Field_blob*) cur_table->field[*cur_blob])->set_ptr(size, 
+      ((Field_blob*) cur_table->field[*cur_blob])->set_ptr(size,
         (uchar *)blob_ptrs[blob_ptr_index]);
       cur_table->field[*cur_blob]->set_notnull();
       blob_ptr_index++;
@@ -904,9 +897,7 @@ result_t Restore::send_data(Buffer &buf)
       DBUG_RETURN(PROCESSING);
     }
 
-    /*
-      This is the first part of several, create new iterator.
-    */
+    // This is the first part of several, create new iterator.
     case BLOB_FIRST:
     {
       max_blob_size= uint4korr(buf.data + META_SIZE);
@@ -917,10 +908,8 @@ result_t Restore::send_data(Buffer &buf)
       mode= WRITE_BLOB;
       break;
     }
- 
-    /*
-      Save the part and keep reading.
-    */
+
+    // Save the part and keep reading.
     case BLOB_DATA:
     {
       blob_buffer.put_next((byte *)buf.data + META_SIZE, size);
@@ -928,14 +917,12 @@ result_t Restore::send_data(Buffer &buf)
       break;
     }
 
-    /*
-      If this is the last part, assemble and write.
-    */
+    // If this is the last part, assemble and write.
     case BLOB_LAST:
     {
       blob_buffer.put_next((byte *)buf.data + META_SIZE, size);
       ptr= (byte *)blob_buffer.get_base_ptr();
-      ((Field_blob*) cur_table->field[*cur_blob])->set_ptr(max_blob_size, 
+      ((Field_blob*) cur_table->field[*cur_blob])->set_ptr(max_blob_size,
         (uchar *)ptr);
       cur_table->field[*cur_blob]->set_notnull();
       blob_ptr_index++;
@@ -951,9 +938,7 @@ result_t Restore::send_data(Buffer &buf)
   default:
     DBUG_RETURN(ERROR);
   }
-  DBUG_RETURN(OK); 
+  DBUG_RETURN(OK);
 }
 
 } /* default_backup namespace */
-
-

=== modified file 'sql/backup/be_default.h'
--- a/sql/backup/be_default.h	2009-03-16 14:38:05 +0000
+++ b/sql/backup/be_default.h	2009-10-21 13:32:24 +0000
@@ -2,7 +2,7 @@
 #define _DEFAULT_BACKUP_H
 
 #include <backup_engine.h>
-#include <backup/image_info.h>  // to define default backup image class
+#include <backup/image_info.h>  // To define default backup image class.
 #include <backup/be_logical.h>
 #include <backup/buffer_iterator.h>
 #include <backup/be_thread.h>
@@ -20,64 +20,65 @@ const size_t META_SIZE= 1;
 
 /*
   The following are the flags for the first byte in the data layout for
-  the default and consistent snapshot algorithms. They describe what is 
+  the default and consistent snapshot algorithms. They describe what is
   included in the buffer going to the kernel.
 */
-const byte RCD_ONCE=    1U;     // Single data block for record data
-const byte RCD_FIRST=  (1U<<1); // First data block in buffer for record buffer
-const byte RCD_DATA=   (1U<<2); // Intermediate data block for record buffer
-const byte RCD_LAST=   (1U<<3); // Last data block in buffer for record buffer
-const byte BLOB_ONCE=   3U;     // Single data block for blob data
-const byte BLOB_FIRST= (3U<<1); // First data block in buffer for blob buffer
-const byte BLOB_DATA=  (3U<<2); // Intermediate data block for blob buffer
-const byte BLOB_LAST=  (3U<<3); // Last data block in buffer for blob buffer
+const byte RCD_ONCE=    1U;     // Single data block for record data.
+const byte RCD_FIRST=  (1U<<1); // First data block in buffer for record buffer.
+const byte RCD_DATA=   (1U<<2); // Intermediate data block for record buffer.
+const byte RCD_LAST=   (1U<<3); // Last data block in buffer for record buffer.
+const byte BLOB_ONCE=   3U;     // Single data block for blob data.
+const byte BLOB_FIRST= (3U<<1); // First data block in buffer for blob buffer.
+const byte BLOB_DATA=  (3U<<2); // Intermediate data block for blob buffer.
+const byte BLOB_LAST=  (3U<<3); // Last data block in buffer for blob buffer.
 
 
 /**
   @class Backup
- 
+
   @brief Contains the default backup algorithm backup functionality.
- 
+
   The backup class is a row-level backup mechanism designed to perform
   a table scan on each table reading the rows and saving the data to the
   buffer from the backup algorithm.
- 
+
   @see Backup_driver and Backup_thread_driver
 */
+
 class Backup: public Backup_thread_driver
 {
 public:
     /// Enumeration values for status of data.
     enum has_data_info { YES, WAIT, EOD };
-    /// Constructor
+    /// Constructor.
     Backup(const Table_list &tables, THD *t_thd, thr_lock_type lock_type);
-    virtual ~Backup(); 
-    /// Return current size of data
+    virtual ~Backup();
+    /// Return current size of data.
     size_t size()  { return UNKNOWN_SIZE; };
-    /// Return initial size of data
+    /// Return initial size of data.
     size_t init_size() { return 0; };
-    /// Initialize backup process
+    /// Initialize backup process.
     result_t  begin(const size_t) { return backup::OK; };
-    /// End backup process
+    /// End backup process.
     result_t end() { return backup::OK; };
     result_t get_data(Buffer &buf);
-    /// Lock signal
+    /// Lock signal.
     result_t lock() { return backup::OK; };
-    /// Unlock signal
+    /// Unlock signal.
     result_t unlock() { return backup::OK; };
-    /// Cancel the process
-    result_t cancel() 
-    { 
+    /// Cancel the process.
+    result_t cancel()
+    {
       mode= CANCEL;
       cleanup();
       DBUG_EXECUTE_IF("backup_driver_cancel_error", return backup::ERROR;);
       return backup::OK;
     }
-    /// Return table list containing all tables
+    /// Return table list containing all tables.
     TABLE_LIST *get_table_list() { return all_tables; }
-    /// Free the class resources
+    /// Free the class resources.
     void free() { delete this; };
-    result_t prelock(); 
+    result_t prelock();
 
 protected:
     TABLE *cur_table;              ///< The table currently being read.
@@ -85,68 +86,70 @@ protected:
     my_bool locks_acquired;        ///< Used to help kernel synchronize drivers.
     handler *hdl;                  ///< Pointer to table handler.
     my_bool m_cleanup;             ///< Is call to cleanup() needed?
-    result_t end_tbl_read(); 
+    result_t end_tbl_read();
 
 private:
     /*
-      We use an enum to control the flow of the algorithm. Each mode 
+      We use an enum to control the flow of the algorithm. Each mode
       invokes a different behavior through a large switch. The mode is
       set in the code as a response to conditions or flow of data.
     */
     typedef enum {
-      INITIALIZE,                  ///< Indicates time to initialize read
-      CANCEL,                      ///< Indicates time to cancel operation
-      GET_NEXT_TABLE,              ///< Open next table in the list
-      READ_RCD,                    ///< Reading rows from table mode
-      READ_RCD_BUFFER,             ///< Buffer records mode
-      CHECK_BLOBS,                 ///< See if record has blobs
-      READ_BLOB,                   ///< Reading blobs from record mode
-      READ_BLOB_BUFFER             ///< Buffer blobs mode
+      INITIALIZE,                ///< Indicates time to initialize read.
+      CANCEL,                    ///< Indicates time to cancel operation.
+      GET_NEXT_TABLE,            ///< Open next table in the list.
+      READ_RCD,                  ///< Reading rows from table mode.
+      READ_RCD_BUFFER,           ///< Buffer records mode.
+      CHECK_BLOBS,               ///< See if record has blobs.
+      READ_BLOB,                 ///< Reading blobs from record mode.
+      READ_BLOB_BUFFER           ///< Buffer blobs mode.
     } BACKUP_MODE;
 
     result_t start_tbl_read(TABLE *tbl);
     int next_table();
-    BACKUP_MODE mode;              ///< Indicates which mode the code is in
-    ulong tbl_num;                   ///< The index of the current table.
-    uint *cur_blob;                ///< The current blob field.
-    uint *last_blob_ptr;           ///< Position of last blob field.
-    MY_BITMAP *read_set;           ///< The file read set.
-    Buffer_iterator rec_buffer;    ///< Buffer iterator for windowing records
-    Buffer_iterator blob_buffer;   ///< Buffer iterator for windowing BLOB fields
-    byte *ptr;                     ///< Pointer to blob data from record.
-    TABLE_LIST *all_tables;        ///< Reference to list of tables used.
+    BACKUP_MODE mode;            ///< Indicates which mode the code is in.
+    ulong tbl_num;               ///< The index of the current table.
+    uint *cur_blob;              ///< The current blob field.
+    uint *last_blob_ptr;         ///< Position of last blob field.
+    MY_BITMAP *read_set;         ///< The file read set.
+    Buffer_iterator rec_buffer;  ///< Buffer iterator for windowing records.
+    Buffer_iterator blob_buffer; ///< Buffer iterator for windowing BLOB fields.
+    byte *ptr;                   ///< Pointer to blob data from record.
+    TABLE_LIST *all_tables;      ///< Reference to list of tables used.
 
     result_t cleanup();
     uint pack(byte *rcd, byte *packed_row);
 };
 
+
 /**
   @class Restore
- 
+
   @brief Contains the default backup algorithm restore functionality.
- 
+
   The restore class is a row-level backup mechanism designed to restore
   data for each table by writing the data for the rows from the
   buffer given by the backup algorithm.
- 
+
   @see Restore_driver
 */
+
 class Restore: public Restore_driver
 {
 public:
     /// Enumeration values for status of data.
     enum has_data_info { YES, WAIT, EOD };
-    /// Constructor
+    /// Constructor.
     Restore(const backup::Logical_snapshot &info, THD *t_thd);
     virtual ~Restore()
-    { 
+    {
       cleanup();
-    }; 
+    };
     result_t  begin(const size_t) { return backup::OK; };
     result_t  end();
     result_t  send_data(Buffer &buf);
     result_t  cancel()
-    { 
+    {
       mode= CANCEL;
       cleanup();
       DBUG_EXECUTE_IF("backup_driver_cancel_error", return backup::ERROR;);
@@ -156,35 +159,35 @@ public:
 
 private:
      /*
-      We use an enum to control the flow of the algorithm. Each mode 
+      We use an enum to control the flow of the algorithm. Each mode
       invokes a different behavior through a large switch. The mode is
       set in the code as a response to conditions or flow of data.
     */
     typedef enum {
-      INITIALIZE,                  ///< Indicates time to initialize read
-      CANCEL,                      ///< Indicates time to cancel operation
-      GET_NEXT_TABLE,              ///< Open next table in the list
-      WRITE_RCD,                   ///< Writing rows from table mode
-      CHECK_BLOBS,                 ///< See if record has blobs
-      WRITE_BLOB,                  ///< Writing blobs from record mode
-      WRITE_BLOB_BUFFER            ///< Buffer blobs mode
+      INITIALIZE,                  ///< Indicates time to initialize read.
+      CANCEL,                      ///< Indicates time to cancel operation.
+      GET_NEXT_TABLE,              ///< Open next table in the list.
+      WRITE_RCD,                   ///< Writing rows from table mode.
+      CHECK_BLOBS,                 ///< See if record has blobs.
+      WRITE_BLOB,                  ///< Writing blobs from record mode.
+      WRITE_BLOB_BUFFER            ///< Buffer blobs mode.
     } RESTORE_MODE;
 
-    /**
-      Reference to the corresponding logical snapshot object.
-    */
-    const backup::Logical_snapshot &m_snap;  
-    RESTORE_MODE mode;             ///< Indicates which mode the code is in
+    ///  Reference to the corresponding logical snapshot object.
+    const backup::Logical_snapshot &m_snap;
+    RESTORE_MODE mode;             ///< Indicates which mode the code is in.
     uint tbl_num;                  ///< The index of the current table.
-    uint32 max_blob_size;          ///< The total size (sum of parts) for the blob.
+    /// The total size (sum of parts) for the blob.
+    uint32 max_blob_size;
     TABLE *cur_table;              ///< The table currently being read.
     handler *hdl;                  ///< Pointer to table handler.
     uint *cur_blob;                ///< The current blob field.
     uint *last_blob_ptr;           ///< Position of last blob field.
-    Buffer_iterator rec_buffer;    ///< Buffer iterator for windowing records
-    Buffer_iterator blob_buffer;   ///< Buffer iterator for windowing BLOB fields
-    byte *blob_ptrs[MAX_FIELDS];   ///< List of blob pointers used
-    int blob_ptr_index;            ///< Position in blob pointer list
+    Buffer_iterator rec_buffer;    ///< Buffer iterator for windowing records.
+    /// Buffer iterator for windowing BLOB fields.
+    Buffer_iterator blob_buffer;
+    byte *blob_ptrs[MAX_FIELDS];   ///< List of blob pointers used.
+    int blob_ptr_index;            ///< Position in blob pointer list.
     THD *m_thd;                    ///< Pointer to current thread struct.
     timestamp_auto_set_type old_tm;///< Save old timestamp auto set type.
     my_bool m_cleanup;             ///< Is call to cleanup() needed?
@@ -192,6 +195,7 @@ private:
     result_t cleanup();
     uint unpack(byte *packed_row);
 };
+
 } // default_backup namespace
 
 
@@ -205,17 +209,16 @@ namespace backup {
 
 class Logger;
 
-/**
-  Extends Logical_info to implement the default backup driver.
-*/
+/// Extends Logical_info to implement the default backup driver.
+
 class Default_snapshot: public Logical_snapshot
 {
 public:
 
-  /// Constructor
-  Default_snapshot(Logger&) :Logical_snapshot(1) // current version number is 1
+  /// Constructor.
+  Default_snapshot(Logger&) :Logical_snapshot(1) // Current version number is 1.
   {}
-  /// Constructor
+  /// Constructor.
   Default_snapshot(Logger&, const version_t ver) :Logical_snapshot(ver)
   {}
 
@@ -228,13 +231,11 @@ public:
   { return "Default"; }
 
   bool accept(const backup::Table_ref &,const storage_engine_ref e)
-  { 
+  {
     bool accepted= TRUE;
     const char *ename= se_name(e);
 
-    /*
-      Do not accept nodata engines.
-    */
+    // Do not accept nodata engines.
     if ((my_strcasecmp(system_charset_info, "BLACKHOLE", ename) == 0) ||
         (my_strcasecmp(system_charset_info, "EXAMPLE", ename) == 0) ||
         (my_strcasecmp(system_charset_info, "FEDERATED", ename) == 0) ||
@@ -244,14 +245,19 @@ public:
   }
 
   result_t get_backup_driver(Backup_driver* &ptr)
-  { return (ptr= new default_backup::Backup(m_tables, ::current_thd,
-                                            TL_READ_NO_INSERT)) ? OK : ERROR; }
+  {
+    return (ptr= new default_backup::Backup(m_tables, ::current_thd,
+                                            TL_READ_NO_INSERT)) ? OK : ERROR;
+  }
 
   result_t get_restore_driver(Restore_driver* &ptr)
-  { return (ptr= new default_backup::Restore(*this, ::current_thd)) ? OK : ERROR; }
+  {
+    return (ptr= new default_backup::Restore(*this, ::current_thd)) ?
+           OK : ERROR;
+  }
 
   bool is_valid(){ return TRUE; };
-  
+
 };
 
 } // backup namespace

=== modified file 'sql/backup/be_logical.h'
--- a/sql/backup/be_logical.h	2008-12-18 21:46:36 +0000
+++ b/sql/backup/be_logical.h	2009-10-21 13:32:24 +0000
@@ -1,28 +1,30 @@
 #ifndef _BE_LOGICAL_H_
 #define _BE_LOGICAL_H_
 
-/** 
+/**
   @file
 
-  This header contains definitions needed for "logical" backup/restore 
+  This header contains definitions needed for "logical" backup/restore
   drivers which access tables using handlerton interface. The built-in
   drivers are of this type.
-*/ 
+*/
 
-#include <backup/image_info.h> // For definition of Snapshot_info
+#include <backup/image_info.h> // For definition of Snapshot_info.
 
 class Backup_restore_ctx;
 
 namespace backup {
 
 /**
-  Extends Snapshot_info with methods for accessing tables opened in the server.
+  Extends Snapshot_info with methods for accessing tables opened in the
+  server.
 */
+
 class Logical_snapshot :public Snapshot_info
 {
 public:
 
-  /// Constructor
+  /// Constructor.
   Logical_snapshot(version_t ver) :Snapshot_info(ver) {}
 
   /**
@@ -34,13 +36,14 @@ public:
     @param[in] pos The position of the table in the list.
 
     @returns Pointer to table.
-  */ 
+  */
   TABLE*      get_opened_table(ulong pos) const;
 
   /// Return the current table list.
   const Table_list& get_table_list() const;
 };
 
+
 inline
 TABLE *Logical_snapshot::get_opened_table(ulong pos) const
 {
@@ -52,6 +55,7 @@ TABLE *Logical_snapshot::get_opened_tabl
   return t ? t->m_table->table : NULL;
 }
 
+
 inline
 const Table_list& Logical_snapshot::get_table_list() const
 {

=== modified file 'sql/backup/be_native.h'
--- a/sql/backup/be_native.h	2009-10-12 09:08:34 +0000
+++ b/sql/backup/be_native.h	2009-10-21 13:32:24 +0000
@@ -7,20 +7,19 @@
 
 namespace backup {
 
-/**
-  Specialization of @c Image_info for images created by native backup drivers.
- */
+/// Specialization of @c Image_info for images created by native backup drivers.
+
 class Native_snapshot: public Snapshot_info
 {
-  const ::handlerton  *m_hton; ///< Pointer to storage engine.
-  Engine     *m_be;    ///< Pointer to the native backup engine.
-  const char *m_name;  ///< Saved name of storage engine.
-  uint       m_se_ver; ///< Storage engine version number.
+  const ::handlerton *m_hton;  ///< Pointer to storage engine.
+  Engine             *m_be;    ///< Pointer to the native backup engine.
+  const char         *m_name;  ///< Saved name of storage engine.
+  uint               m_se_ver; ///< Storage engine version number.
 
 public:
 
-  /// Constructor
-  Native_snapshot(Logger &log, const storage_engine_ref se) 
+  /// Constructor.
+  Native_snapshot(Logger &log, const storage_engine_ref se)
     :Snapshot_info(0), m_hton(NULL), m_be(NULL)
   {
     init(log, se);
@@ -28,8 +27,8 @@ public:
       m_version= m_be->version();
   }
 
-  /// Constructor
-  Native_snapshot(Logger &log, const version_t ver, const storage_engine_ref se) 
+  /// Constructor.
+  Native_snapshot(Logger &log, const version_t ver, const storage_engine_ref se)
     :Snapshot_info(ver), m_hton(NULL), m_be(NULL)
   {
     init(log, se);
@@ -59,9 +58,9 @@ public:
   { return se_name(); }
 
   bool accept(const Table_ref&, const storage_engine_ref se)
-  { 
-    // this assumes handlertons are single instance objects!
-    return se_hton(se) == m_hton; 
+  {
+    // This assumes handlertons are single instance objects!
+    return se_hton(se) == m_hton;
   }
 
   result_t get_backup_driver(Backup_driver* &drv)
@@ -81,6 +80,7 @@ private:
   int init(Logger &log, const storage_engine_ref se);
 };
 
+
 inline
 int Native_snapshot::init(Logger &log, const storage_engine_ref se)
 {
@@ -94,7 +94,8 @@ int Native_snapshot::init(Logger &log, c
 
   m_name= ::ha_resolve_storage_engine_name(m_hton);
 
-  result_t ret= m_hton->get_backup_engine(const_cast<handlerton*>(m_hton), m_be);
+  result_t ret= m_hton->get_backup_engine(const_cast<handlerton*>(m_hton),
+                                          m_be);
 
   // Error code insertion for ER_BACKUP_CREATE_BE.
   DBUG_EXECUTE_IF("ER_BACKUP_CREATE_BE", ret= ERROR;);
@@ -107,16 +108,15 @@ int Native_snapshot::init(Logger &log, c
     /*
       We only report warning here because even if we failed to create native
       backup engine it can be replaced by a built-in engine and the backup
-      operation might still succeed.  
+      operation might still succeed.
     */
     log.report_error(log_level::WARNING, ER_BACKUP_CREATE_BE, m_name);
     return 1;
   }
-  
+
   return 0;
 }
 
-
 } // backup namespace
 
 #endif /*BE_NATIVE_H_*/

=== modified file 'sql/backup/be_nodata.cc'
--- a/sql/backup/be_nodata.cc	2009-02-13 13:25:43 +0000
+++ b/sql/backup/be_nodata.cc	2009-10-21 13:32:24 +0000
@@ -4,7 +4,7 @@
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; version 2 of the License.
 
-   This program is distributed in the hope that it will be useful, 
+   This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.
@@ -15,13 +15,13 @@
 */
 
 /**
-  @file 
- 
+  @file
+
   @brief Contains the nodata backup algorithm driver.
- 
+
   This file contains the nodata backup algorithm (also called a "driver"
   in the MySQL backup terminology. The nodata driver does not read or
-  write to any files or tables. It is used to allow the backup and 
+  write to any files or tables. It is used to allow the backup and
   restore of storage engines that do not store data. These include:
 
     DB_TYPE_MRG_MYISAM
@@ -29,11 +29,13 @@
     DB_TYPE_FEDERATED_DB
     DB_TYPE_EXAMPLE_DB
 */
+
 #include "../mysql_priv.h"
 #include "backup_engine.h"
 #include "be_nodata.h"
 #include "backup_aux.h"
 
+
 namespace nodata_backup {
 
 using backup::byte;
@@ -47,16 +49,17 @@ using namespace backup;
 
 /**
   Create a nodata backup backup driver.
-  
+
   Creates a stubbed driver class for the backup kernel code. This
   allows the driver to be used in a backup while not reading data.
-  
+
   @param[in]  tables list of tables to be backed-up.
   @param[out] drv    pointer to backup driver instance.
-  
+
   @retval  ERROR  if cannot create backup driver class.
   @retval  OK     on success.
 */
+
 result_t Engine::get_backup(const uint32, const Table_list &tables,
                             Backup_driver* &drv)
 {
@@ -68,6 +71,7 @@ result_t Engine::get_backup(const uint32
   DBUG_RETURN(OK);
 }
 
+
 /**
   @brief Get the data for a row in the table.
 
@@ -78,6 +82,7 @@ result_t Engine::get_backup(const uint32
 
   @returns DONE
 */
+
 result_t Backup::get_data(Buffer &buf)
 {
   DBUG_ENTER("Nodata_backup::get_data)");
@@ -87,9 +92,10 @@ result_t Backup::get_data(Buffer &buf)
   DBUG_RETURN(DONE);
 }
 
+
 /**
   Create a nodata backup restore driver.
-  
+
   Creates a stubbed driver class for the backup kernel code. This
   allows the driver to be used in a restore while not writing data.
 
@@ -101,9 +107,10 @@ result_t Backup::get_data(Buffer &buf)
   @retval ERROR  if cannot create restore driver class.
   @retval OK     on success.
 */
-result_t Engine::get_restore(const version_t, 
-                             const uint32, 
-                             const Table_list &tables, 
+
+result_t Engine::get_restore(const version_t,
+                             const uint32,
+                             const Table_list &tables,
                              Restore_driver* &drv)
 {
   DBUG_ENTER("Engine::get_restore");
@@ -114,11 +121,13 @@ result_t Engine::get_restore(const versi
   DBUG_RETURN(OK);
 }
 
+
 /**
    @brief Restore the data for a row in the table.
-  
+
    This method is stubbed and does not write any data.
 */
+
 result_t Restore::send_data(Buffer &buf)
 {
   DBUG_ENTER("Nodata_backup::send_data)");
@@ -129,5 +138,3 @@ result_t Restore::send_data(Buffer &buf)
 }
 
 } /* nodata_backup namespace */
-
-

=== modified file 'sql/backup/be_nodata.h'
--- a/sql/backup/be_nodata.h	2009-02-13 13:25:43 +0000
+++ b/sql/backup/be_nodata.h	2009-10-21 13:32:24 +0000
@@ -2,7 +2,7 @@
 #define _NODATA_BACKUP_H
 
 #include <backup_engine.h>
-#include <backup/image_info.h>  // to define default backup image class
+#include <backup/image_info.h>  // To define default backup image class.
 
 namespace nodata_backup {
 
@@ -15,53 +15,52 @@ using backup::Buffer;
 
 /**
   @class Engine
- 
+
   Encapsulates nodata backup/restore functionality.
- 
+
   Using this class, the caller can create an instance of the nodata backup
-  backup and restore class. The nodata driver does not read or write to any 
-  files or tables. It is used to allow the backup and restore of storage 
+  backup and restore class. The nodata driver does not read or write to any
+  files or tables. It is used to allow the backup and restore of storage
   engines that do not store data.
 */
+
 class Engine: public Backup_engine
 {
 public:
-  /// Constructor
+  /// Constructor.
   Engine(THD *t_thd) { m_thd= t_thd; }
 
-  /*
-    Return version of backup images created by this engine.
-  */
+  // Return version of backup images created by this engine.
   version_t version() const { return 0; };
-  result_t get_backup(const uint32, const Table_list &tables, 
+  result_t get_backup(const uint32, const Table_list &tables,
                       Backup_driver* &drv);
-  result_t get_restore(const version_t version, const uint32 flags, 
+  result_t get_restore(const version_t version, const uint32 flags,
                        const Table_list &tables, Restore_driver* &drv);
 
-  /*
-   Free any resources allocated by the nodata backup engine.
-  */
+  // Free any resources allocated by the nodata backup engine.
   void free() { delete this; }
 
 private:
   THD *m_thd; ///< Current thread reference.
 };
 
+
 /**
   @class Backup
- 
+
   Contains the nodata backup algorithm backup functionality.
- 
+
   Creates a stubbed driver class for the backup kernel code. This
   allows the driver to be used in a backup while not reading data.
 */
+
 class Backup: public Backup_driver
 {
 public:
-  /// Constructor
+  /// Constructor.
   Backup(const backup::Table_list &tables):
   Backup_driver(tables) {};
-  virtual ~Backup() {}; 
+  virtual ~Backup() {};
   size_t size()  { return 0; };
   size_t init_size() { return 0; };
   result_t begin(const size_t) { return backup::OK; };
@@ -74,18 +73,20 @@ public:
   result_t prelock() { return backup::OK; };
 };
 
+
 /**
   @class Restore
- 
+
   Contains the nodata backup algorithm restore functionality.
- 
+
   Creates a stubbed driver class for the backup kernel code. This
   allows the driver to be used in a restore while not writing data.
 */
+
 class Restore: public Restore_driver
 {
 public:
-  /// Constructor
+  /// Constructor.
   Restore(const Table_list &tables, THD *t_thd):
          Restore_driver(tables) {};
   virtual ~Restore() {};
@@ -95,6 +96,7 @@ public:
   result_t cancel() { return backup::OK; };
   void free() { delete this; };
 };
+
 } // nodata_backup namespace
 
 
@@ -113,14 +115,15 @@ class Logger;
 
   This extends Snapshot_info for implementation of the no data backup driver.
 */
+
 class Nodata_snapshot: public Snapshot_info
 {
 public:
 
-  /// Constructor
-  Nodata_snapshot(Logger&) :Snapshot_info(1) // current version number is 1
+  /// Constructor.
+  Nodata_snapshot(Logger&) :Snapshot_info(1) // Current version number is 1.
   {}
-  /// Constructor
+  /// Constructor.
   Nodata_snapshot(Logger&, const version_t ver) :Snapshot_info(ver)
   {}
 
@@ -133,13 +136,11 @@ public:
   { return "Nodata"; }
 
   bool accept(const backup::Table_ref &,const storage_engine_ref e)
-  { 
+  {
     bool accepted= FALSE;
     const char *ename= se_name(e);
 
-    /*
-      Accept only nodata engines.
-    */
+    // Accept only nodata engines.
     if ((my_strcasecmp(system_charset_info, "BLACKHOLE", ename) == 0) ||
         (my_strcasecmp(system_charset_info, "EXAMPLE", ename) == 0) ||
         (my_strcasecmp(system_charset_info, "FEDERATED", ename) == 0) ||
@@ -152,9 +153,13 @@ public:
   { return (ptr= new nodata_backup::Backup(m_tables)) ? OK : ERROR; }
 
   result_t get_restore_driver(Restore_driver* &ptr)
-  { return (ptr= new nodata_backup::Restore(m_tables,::current_thd)) ? OK : ERROR; }
+  {
+    return (ptr= new nodata_backup::Restore(m_tables,::current_thd)) ?
+           OK : ERROR;
+  }
 
-  bool is_valid(){ return TRUE; };
+  bool is_valid()
+  { return TRUE; };
 
 };
 

=== modified file 'sql/backup/be_snapshot.cc'
--- a/sql/backup/be_snapshot.cc	2009-02-13 13:25:43 +0000
+++ b/sql/backup/be_snapshot.cc	2009-10-21 13:32:24 +0000
@@ -16,26 +16,26 @@
 
 /**
    @file
-  
+
    @brief Contains the snapshot backup algorithm driver.
-  
+
    This file contains the snapshot backup algorithm (also called a "driver"
    in the MySQL backup terminology. The snapshot backup algorithm may be
    used in place of an engine-specific driver if one does not exist or if
    chosen by the user.
-  
+
    The snapshot backup algorithm is a non-blocking algorithm that enables a
-   consistent read of the tables given at the start of the backup/restore 
+   consistent read of the tables given at the start of the backup/restore
    process. This is accomplished by using a consistent snapshot transaction
-   and table locks. Once all of the data is backed up or restored, the locks 
-   are removed. The snapshot backup is a row-level backup and therefore does 
+   and table locks. Once all of the data is backed up or restored, the locks
+   are removed. The snapshot backup is a row-level backup and therefore does
    not backup the indexes or any of the engine-specific files.
-  
+
    The classes in this file use the namespace "snapshot_backup" to distinguish
    these classes from other backup drivers. The backup functionality is
    contained in the backup class shown below. Similarly, the restore
    functionality is contained in the restore class below.
-  
+
    The format of the backup is the same as the default backup driver.
    Please see <code> be_default.cc </code> for a complete description.
 */
@@ -47,6 +47,7 @@
 #include "transaction.h"
 #include "debug_sync.h"
 
+
 namespace snapshot_backup {
 
 using backup::byte;
@@ -64,6 +65,7 @@ using namespace backup;
   the driver to shutdown gracefully. The method call ends the current
   transaction and closes the tables.
 */
+
 result_t Backup::cleanup()
 {
   DBUG_ENTER("Default_backup::cleanup()");
@@ -71,7 +73,8 @@ result_t Backup::cleanup()
   if (m_cleanup)
   {
     m_cleanup= FALSE;
-    locking_thd->lock_state= LOCK_DONE; // set lock done so destructor won't wait
+    // Set lock done so destructor won't wait.
+    locking_thd->lock_state= LOCK_DONE;
     if (m_trans_start)
     {
       trans_commit_stmt(locking_thd->m_thd);
@@ -89,21 +92,23 @@ result_t Backup::cleanup()
   DBUG_RETURN(OK);
 }
 
+
 /**
   Lock the tables
 
   This method creates the consistent read transaction and acquires the read
   lock.
 */
+
 result_t Backup::lock()
 {
   DBUG_ENTER("Snapshot_backup::lock()");
   /*
     We must fool the locking code to think this is a select because
     any other command type places the engine in a non-consistent read
-    state. 
+    state.
   */
-  locking_thd->m_thd->lex->sql_command= SQLCOM_SELECT; 
+  locking_thd->m_thd->lex->sql_command= SQLCOM_SELECT;
   locking_thd->m_thd->lex->start_transaction_opt=
     MYSQL_START_TRANS_OPT_WITH_CONS_SNAPSHOT;
   int res= trans_begin(locking_thd->m_thd,
@@ -117,24 +122,25 @@ result_t Backup::lock()
   DBUG_RETURN(OK);
 }
 
+
 result_t Backup::get_data(Buffer &buf)
 {
   result_t res;
 
   if (!tables_open && (locking_thd->lock_state == LOCK_ACQUIRED))
   {
-    // The lex needs to be cleaned up between consecutive calls to 
+    // The lex needs to be cleaned up between consecutive calls to
     // open_and_lock_tables. Otherwise, open_and_lock_tables will try to open
     // previously opened views and crash.
     locking_thd->m_thd->lex->cleanup_after_one_table_open();
     /*
       The MYSQL_OPEN_SKIP_TEMPORARY flag is needed so that temporary tables are
-      not opened which would occulde the regular tables selected for backup 
+      not opened which would occlude the regular tables selected for backup
       (BUG#33574).
-     */ 
-    open_and_lock_tables_derived(locking_thd->m_thd, 
+    */
+    open_and_lock_tables_derived(locking_thd->m_thd,
                                  locking_thd->tables_in_backup,
-                                 FALSE, /* do not process derived tables */
+                                 FALSE, /* Do not process derived tables. */
                                  MYSQL_OPEN_SKIP_TEMPORARY);
     tables_open= TRUE;
   }
@@ -157,6 +163,5 @@ result_t Backup::get_data(Buffer &buf)
   return(res);
 }
 
-} /* snapshot_backup namespace */
-
 
+} /* snapshot_backup namespace */

=== modified file 'sql/backup/be_snapshot.h'
--- a/sql/backup/be_snapshot.h	2009-03-16 14:38:05 +0000
+++ b/sql/backup/be_snapshot.h	2009-10-21 13:32:24 +0000
@@ -1,7 +1,7 @@
 #ifndef _SNAPSHOT_BACKUP_H
 #define _SNAPSHOT_BACKUP_H
 
-#include <backup/image_info.h>        
+#include <backup/image_info.h>
 #include <backup/buffer_iterator.h>
 #include <backup/be_default.h>
 
@@ -16,75 +16,79 @@ using backup::Buffer;
 
 /**
   @class Backup
- 
+
   Contains the snapshot backup algorithm backup functionality.
- 
+
   The backup class is a row-level backup mechanism designed to perform
   a table scan on each table reading the rows and saving the data to the
   buffer from the backup algorithm using a consistent read transaction.
- 
+
   @see Backup_driver
- */
+*/
+
 class Backup: public default_backup::Backup
 {
 public:
-    /// Constructor
-    Backup(const Table_list &tables, THD *t_thd) 
-      :default_backup::Backup(tables, t_thd, TL_READ) 
-    { 
+    /// Constructor.
+    Backup(const Table_list &tables, THD *t_thd)
+      :default_backup::Backup(tables, t_thd, TL_READ)
+    {
       tables_open= FALSE;
       m_cancel= FALSE;
       m_trans_start= FALSE;
     };
-    /// Destructor
+    /// Destructor.
     virtual ~Backup() { cleanup(); };
 
-    /// Initialize backup process
-    result_t begin(const size_t) { return backup::OK; }; 
-    /// End backup process
+    /// Initialize backup process.
+    result_t begin(const size_t) { return backup::OK; };
+    /// End backup process.
     result_t end() { return backup::OK; }
     result_t get_data(Buffer &buf);
-    /// Initiate a prelock
+    /// Initiate a prelock.
     result_t prelock() { return backup::READY; }
     result_t lock();
-    /// Unlock signal
+    /// Unlock signal.
     result_t unlock() { return backup::OK; };
-    /// Cancel the process
-    result_t cancel() 
-    { 
+    /// Cancel the process.
+    result_t cancel()
+    {
       m_cancel= TRUE;
       cleanup();
       DBUG_EXECUTE_IF("backup_driver_cancel_error", return backup::ERROR;);
       return backup::OK;
     }
 private:
-    my_bool tables_open;   ///< Indicates if tables are open
-    my_bool m_cancel;      ///< Cancel backup
+    my_bool tables_open;   ///< Indicates if tables are open.
+    my_bool m_cancel;      ///< Cancel backup.
     my_bool m_trans_start; ///< Is transaction stated?
 
    result_t cleanup();
 };
 
+
 /**
   @class Restore
- 
+
   Contains the snapshot backup algorithm restore functionality.
- 
+
   The restore class is a row-level backup mechanism designed to restore
   data for each table by writing the data for the rows from the
   buffer given by the backup algorithm.
- 
+
   @see Restore_driver
- */
+*/
+
 class Restore: public default_backup::Restore
 {
 public:
-    /// Constructor
+    /// Constructor.
     Restore(const backup::Logical_snapshot &snap, THD *t_thd)
       :default_backup::Restore(snap, t_thd){};
     virtual ~Restore(){};
     void free() { delete this; };
 };
+
 } // snapshot_backup namespace
 
 
@@ -99,14 +103,15 @@ namespace backup {
 /**
   Extends Logical_info to implement the consistent snapshot backup driver.
 */
+
 class CS_snapshot: public Logical_snapshot
 {
 public:
 
-  /// Constructor
-  CS_snapshot(Logger&) :Logical_snapshot(1) // current version number is 1
+  /// Constructor.
+  CS_snapshot(Logger&) :Logical_snapshot(1) // Current version number is 1.
   {}
-  /// Constructor
+  /// Constructor.
   CS_snapshot(Logger&, version_t ver) :Logical_snapshot(ver)
   {}
 
@@ -121,18 +126,24 @@ public:
   bool accept(const Table_ref&, const storage_engine_ref se)
   {
     ::handlerton *h= se_hton(se);
-
+    // Accept all tables that support consistent read.
     return (h->start_consistent_snapshot != NULL);
-  }; // accept all tables that support consistent read
+  };
 
   result_t get_backup_driver(Backup_driver* &ptr)
-  { return (ptr= new snapshot_backup::Backup(m_tables, ::current_thd)) ? OK : ERROR; }
+  {
+    return (ptr= new snapshot_backup::Backup(m_tables, ::current_thd)) ?
+           OK : ERROR;
+  }
 
   result_t get_restore_driver(Restore_driver* &ptr)
-  { return (ptr= new snapshot_backup::Restore(*this, ::current_thd)) ? OK : ERROR; }
-
-  bool is_valid(){ return TRUE; };
+  {
+    return (ptr= new snapshot_backup::Restore(*this, ::current_thd)) ?
+           OK : ERROR;
+  }
 
+  bool is_valid()
+  { return TRUE; };
 };
 
 } // backup namespace

=== modified file 'sql/backup/be_thread.cc'
--- a/sql/backup/be_thread.cc	2009-10-12 09:08:34 +0000
+++ b/sql/backup/be_thread.cc	2009-10-21 13:32:24 +0000
@@ -16,9 +16,9 @@
 
 /**
   @file
-  
+
   @brief Contains the thread methods for MYSQL backup.
-  
+
   The methods in this class are used to initialize the mutexes
   for the backup threads. Helper methods are included to make thread
   calls easier for the driver code.
@@ -29,18 +29,19 @@
 
 /**
   @brief Creates a new THD object.
-  
+
   Creates a new THD object for use in running as a separate thread.
-  
+
   @returns Pointer to new THD object or 0 if error.
-  
+
   @todo Move this method to a location where ha_ndbcluster_binlog.cc can
         use it and replace code in ndb_binlog_thread_func(void *arg) to
         call this function.
-  
-  @note my_net_init() this should be paired with my_net_end() on 
+
+  @note my_net_init() this should be paired with my_net_end() on
         close/kill of thread.
 */
+
 THD *create_new_thd()
 {
   THD *thd;
@@ -51,18 +52,18 @@ THD *create_new_thd()
     DBUG_RETURN(0);
   THD_CHECK_SENTRY(thd);
 
-  thd->thread_stack = (char*)&thd; // remember where our stack is  
+  thd->thread_stack = (char*)&thd; // Remember where our stack is.
   pthread_mutex_lock(&LOCK_thread_count);
   thd->thread_id= thread_id++;
   pthread_mutex_unlock(&LOCK_thread_count);
-  if (unlikely(thd->store_globals())) // for a proper MEM_ROOT  
+  if (unlikely(thd->store_globals())) // For a proper MEM_ROOT.
   {
     thd->cleanup();
     delete thd;
     DBUG_RETURN(0);
   }
 
-  thd->init_for_queries(); // opening tables needs a proper LEX
+  thd->init_for_queries(); // Opening tables needs a proper LEX.
   thd->command= COM_DAEMON;
   thd->system_thread= SYSTEM_THREAD_BACKUP;
   thd->version= refresh_version;
@@ -90,30 +91,28 @@ THD *create_new_thd()
   DBUG_RETURN(thd);
 }
 
+
 /**
   @brief Lock tables in driver.
-  
+
   This method creates a new THD for use in the new thread. It calls
   the method to open and lock the tables.
-  
-  @note my_thread_init() should be paired with my_thread_end() on 
+
+  @note my_thread_init() should be paired with my_thread_end() on
         close/kill of thread.
 */
+
 pthread_handler_t backup_thread_for_locking(void *arg)
 {
   Locking_thread_st *locking_thd= static_cast<Locking_thread_st *>(arg);
 
   DBUG_PRINT("info", ("Default_backup - lock_tables_in_separate_thread"));
 
-  /*
-    Turn off condition variable check for lock.
-  */
+  // Turn off condition variable check for lock.
   locking_thd->lock_state= LOCK_NOT_STARTED;
   my_thread_init();
 
-  /*
-    First, create a new THD object.
-  */
+  // First, create a new THD object.
   DBUG_PRINT("info",("Online backup creating THD struct for thread"));
   THD *thd= create_new_thd();
 
@@ -129,9 +128,7 @@ pthread_handler_t backup_thread_for_lock
   pthread_detach_this_thread();
   locking_thd->lock_thd= thd;
 
-  /* 
-    Now open and lock the tables.
-  */
+  // Now open and lock the tables.
 
   DBUG_PRINT("info",("Online backup open tables in thread"));
   if (!locking_thd->tables_in_backup)
@@ -154,17 +151,17 @@ pthread_handler_t backup_thread_for_lock
 
   /*
     As locking tables can be a long operation, we need to support
-    killing the thread. In this case, we need to close the tables 
+    killing the thread. In this case, we need to close the tables
     and exit.
   */
 
   /*
     The MYSQL_OPEN_SKIP_TEMPORARY flag is needed so that temporary tables are
-    not opened which would occulde the regular tables selected for backup 
+    not opened which would occulde the regular tables selected for backup
     (BUG#33574).
-  */ 
+  */
   if (open_and_lock_tables_derived(thd, locking_thd->tables_in_backup,
-                                   FALSE, /* do not process derived tables */
+                                   FALSE, /* Do not process derived tables. */
                                    MYSQL_OPEN_SKIP_TEMPORARY)
      )
   {
@@ -203,9 +200,8 @@ pthread_handler_t backup_thread_for_lock
 
   DBUG_PRINT("info",("Locking thread locking thread terminating"));
 
-  /*
-    Cleanup and return.
-  */
+  // Cleanup and return.
+
 end:
   close_thread_tables(thd);
 
@@ -223,9 +219,8 @@ end2:
   if (locking_thd->lock_state != LOCK_ERROR)
     locking_thd->lock_state= LOCK_DONE;
 
-  /*
-    Signal the driver thread that it's ok to proceed with destructor.
-  */
+  // Signal the driver thread that it's ok to proceed with destructor.
+
   pthread_cond_signal(&locking_thd->COND_caller_wait);
   pthread_mutex_unlock(&locking_thd->THR_LOCK_caller);
   my_thread_end(); /* always last, after all mutex usage */
@@ -233,32 +228,30 @@ end2:
   return (0);
 }
 
-/*
-  Constructor for Locking_thread_st structure.
-*/
+
+/// Constructor for Locking_thread_st structure.
+
 Locking_thread_st::Locking_thread_st()
  :m_thread_started(FALSE)
 {
-  /*
-    Initialize the thread mutex and cond variable.
-  */
+  // Initialize the thread mutex and cond variable.
   pthread_mutex_init(&THR_LOCK_thread, MY_MUTEX_INIT_FAST);
   pthread_cond_init(&COND_thread_wait, NULL);
   pthread_mutex_init(&THR_LOCK_caller, MY_MUTEX_INIT_FAST);
   pthread_cond_init(&COND_caller_wait, NULL);
   lock_state= LOCK_NOT_STARTED;
-  lock_thd= NULL; // set to 0 as precaution for get_data being called too soon
+  lock_thd= NULL; // Set to 0 as precaution for get_data being called too soon.
   thd_name.length(0);
 };
 
-/*
-  Destructor for Locking_thread_st structure.
-*/
+
+/// Destructor for Locking_thread_st structure.
+
 Locking_thread_st::~Locking_thread_st()
 {
   /*
-    If the locking thread has been started we need to kill it. We also need to 
-    wait until it dies before destroying the mutexes so that the locking thread 
+    If the locking thread has been started we need to kill it. We also need to
+    wait until it dies before destroying the mutexes so that the locking thread
     won't access them any more.
   */
   if (m_thread_started)
@@ -266,15 +259,16 @@ Locking_thread_st::~Locking_thread_st()
     kill_locking_thread();
     wait_until_locking_thread_dies();
   }
-  /*
-    Destroy the thread mutexes and cond variables.
-  */
+
+  // Destroy the thread mutexes and cond variables.
+
   pthread_mutex_destroy(&THR_LOCK_thread);
   pthread_cond_destroy(&COND_thread_wait);
   pthread_mutex_destroy(&THR_LOCK_caller);
   pthread_cond_destroy(&COND_caller_wait);
 }
 
+
 /**
    Start the driver's lock thread.
 
@@ -283,7 +277,8 @@ Locking_thread_st::~Locking_thread_st()
 
    @param[in] tname The name of the thread which will show in
               process list.
- */
+*/
+
 result_t Locking_thread_st::start_locking_thread(const char *tname)
 {
   DBUG_ENTER("Locking_thread_st::start_locking_thread");
@@ -296,13 +291,15 @@ result_t Locking_thread_st::start_lockin
   DBUG_RETURN(backup::OK);
 }
 
+
 /**
    Kill the driver's lock thread.
 
    This method issues the awake and broadcast to kill the locking thread.
    A mutex is used to prevent the locking thread from deleting the THD
    structure until this operation is complete.
- */
+*/
+
 void Locking_thread_st::kill_locking_thread()
 {
   DBUG_ENTER("Locking_thread_st::kill_locking_thread");
@@ -325,9 +322,7 @@ void Locking_thread_st::kill_locking_thr
   }
   pthread_mutex_unlock(&THR_LOCK_caller);
 
-  /*
-    This tells the CS driver that we're finished with the tables.
-  */
+  // This tells the CS driver that we're finished with the tables.
   if (!lock_thd && (lock_state == LOCK_ACQUIRED))
     lock_state= LOCK_SIGNAL;
   DBUG_VOID_RETURN;
@@ -340,6 +335,7 @@ void Locking_thread_st::kill_locking_thr
    @note It is important to use this function before freeing memory
          or destroying objects to which such thread might access.
 */
+
 void Locking_thread_st::wait_until_locking_thread_dies()
 {
   // Nothing to do if the locking thread has not been started.

=== modified file 'sql/backup/be_thread.h'
--- a/sql/backup/be_thread.h	2009-03-16 14:38:05 +0000
+++ b/sql/backup/be_thread.h	2009-10-21 13:32:24 +0000
@@ -4,16 +4,12 @@
 #include <backup_engine.h>
 #include <backup/image_info.h>
 
-/**
-   Macro for error handling.
-*/
-#define SET_STATE_TO_ERROR_AND_DBUG_RETURN {                                 \
+/// Macro for error handling.
+#define SET_STATE_TO_ERROR_AND_DBUG_RETURN {                                \
     DBUG_PRINT("error",("driver got an error at %s:%d",__FILE__,__LINE__)); \
     DBUG_RETURN(backup::ERROR); }
 
-/**
-   Locking of tables goes through several states.
-*/
+/// Locking of tables goes through several states.
 typedef enum {
   LOCK_NOT_STARTED,
   LOCK_IN_PROGRESS,
@@ -37,35 +33,36 @@ pthread_handler_t backup_thread_for_lock
 
 /**
   Locking_thread
- 
+
   @brief Adds variables for using a locking thread for opening tables.
- 
+
   The Backup_thread structure contains a mutex and condition variable
   for using a thread to open and lock the tables. This is meant to be a
   generic class that can be used elsewhere for opening and locking tables.
 
-  @note This class correctly handles the separate locking thread. However, 
+  @note This class correctly handles the separate locking thread. However,
   the class itself is *not* multi-thread safe. An instance of Locking_thread_st
-  should be used by one thread only. In particular, calling 
+  should be used by one thread only. In particular, calling
   @c start_locking_thread() from one thread and @c kill_locking_thread() from
   another thread running in parallel is not guaranteed to work.
 */
+
 struct Locking_thread_st
 {
 public:
   Locking_thread_st();
   ~Locking_thread_st();
 
-  pthread_mutex_t THR_LOCK_thread; ///< mutex for thread variables
-  pthread_cond_t COND_thread_wait; ///< condition variable for wait
-  pthread_mutex_t THR_LOCK_caller; ///< mutex for thread variables
-  pthread_cond_t COND_caller_wait; ///< condition variable for wait
-
-  TABLE_LIST *tables_in_backup;    ///< List of tables used in backup
-  THD *lock_thd;                   ///< Locking thread pointer
-  LOCK_STATE lock_state;           ///< Current state of the lock call
+  pthread_mutex_t THR_LOCK_thread; ///< Mutex for thread variables.
+  pthread_cond_t COND_thread_wait; ///< Condition variable for wait.
+  pthread_mutex_t THR_LOCK_caller; ///< Mutex for thread variables.
+  pthread_cond_t COND_caller_wait; ///< Condition variable for wait.
+
+  TABLE_LIST *tables_in_backup;    ///< List of tables used in backup.
+  THD *lock_thd;                   ///< Locking thread pointer.
+  LOCK_STATE lock_state;           ///< Current state of the lock call.
   THD *m_thd;                      ///< Pointer to current thread struct.
-  String thd_name;                 ///< Name of locking thread
+  String thd_name;                 ///< Name of locking thread.
   /// Indicates if the locking thread has been started.
   my_bool m_thread_started;
 
@@ -75,25 +72,27 @@ public:
 
 }; // Locking_thread_st
 
+
 /**
   @class Backup_thread_driver
- 
+
   @brief Adds variables for using a locking thread for opening tables.
- 
+
   The Backup_thread_driver class extends the Backup_driver class by adding
-  a mutex and condition variable for using a thread to open and lock the 
+  a mutex and condition variable for using a thread to open and lock the
   tables.
- 
+
   @see Backup_driver
 */
+
 class Backup_thread_driver : public Backup_driver
 {
 public:
 
-  /// Constructor
+  /// Constructor.
   Backup_thread_driver(const backup::Table_list &tables)
     :Backup_driver(tables) { locking_thd = new Locking_thread_st(); }
-  /// Destructor
+  /// Destructor.
   ~Backup_thread_driver() { delete locking_thd; }
 
   Locking_thread_st *locking_thd;  ///< Pointer to locking thread data.

=== modified file 'sql/backup/buffer_iterator.cc'
--- a/sql/backup/buffer_iterator.cc	2008-12-18 21:46:36 +0000
+++ b/sql/backup/buffer_iterator.cc	2009-10-21 13:32:24 +0000
@@ -4,7 +4,7 @@
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; version 2 of the License.
 
-   This program is distributed in the hope that it will be useful, 
+   This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.
@@ -16,9 +16,9 @@
 
 /**
   @file
- 
+
   @brief Contains a buffering class for breaking large data into parts.
- 
+
   This file contains a buffering class for buffering large chunks of
   data. It can be used to store a large chunk of data and iterate
   through windows of a specified size until all the data is read.
@@ -28,15 +28,17 @@
 #include "../mysql_priv.h"
 #include "buffer_iterator.h"
 
+
 /**
   @brief Create a buffer iterator.
- 
+
   Given a pointer to a block of data, its maximum size, and
   window size, start iterator for reading or writing data.
- 
+
   @param  buff_ptr (in) a pointer to a block of memory
   @param  size     (in) the maximum size of the data
 */
+
 int Buffer_iterator::initialize(byte *buff_ptr, size_t size)
 {
   DBUG_ENTER("buffer_iterator::initialize(buff_ptr, size, window)");
@@ -46,17 +48,19 @@ int Buffer_iterator::initialize(byte *bu
   alloc_used= false;
   cur_bytes_read= 0;
   cur_ptr= buffer;
-  DBUG_RETURN(0); 
+  DBUG_RETURN(0);
 }
 
+
 /**
   @brief Create a buffer iterator.
- 
+
   Given the maximum size of a block of data and the
   window size, start iterator for reading or writing data.
- 
+
   @param  size     (in) the maximum size of the data
 */
+
 int Buffer_iterator::initialize(size_t size)
 {
   DBUG_ENTER("buffer_iterator::initialize(size, window)");
@@ -66,14 +70,16 @@ int Buffer_iterator::initialize(size_t s
   alloc_used= true;
   cur_bytes_read= 0;
   cur_ptr= buffer;
-  DBUG_RETURN(0); 
+  DBUG_RETURN(0);
 }
 
+
 /**
   @brief Reset buffer iterator.
- 
+
   Destroy any memory used.
 */
+
 int Buffer_iterator::reset()
 {
   DBUG_ENTER("buffer_iterator::reset()");
@@ -84,19 +90,21 @@ int Buffer_iterator::reset()
   DBUG_RETURN(0);
 }
 
+
 /**
   @brief Get the next window of data in the iterator.
- 
+
   This method retrieves the next window in the iterator. It
   returns the number of bytes read (may be less if last
   window is smaller than the max window size), and updates
   the pointer passed as an argument.
- 
+
   @param  buff_ptr  (in) a pointer to the window to be read
   @param  window    (in) the size of the window
-  
+
   @retval the size of the window
 */
+
 size_t Buffer_iterator::get_next(byte **buff_ptr, size_t window)
 {
   size_t bytes_read;
@@ -114,7 +122,7 @@ size_t Buffer_iterator::get_next(byte **
       cur_bytes_read= cur_bytes_read + window_size;
     }
     else
-    { 
+    {
       cur_ptr= 0;
       bytes_read= max_size - cur_bytes_read;
       cur_bytes_read= max_size;
@@ -125,47 +133,51 @@ size_t Buffer_iterator::get_next(byte **
   DBUG_RETURN(bytes_read);
 }
 
+
 /**
   @brief Insert the next window of data into the iterator.
- 
+
   This method inserts the next window into the iterator. It
-  uses the pointer passed as an argument to copy data from 
+  uses the pointer passed as an argument to copy data from
   that location to the internal buffer based on the size of
   the window passed as an argument.
- 
+
   @param  buff_ptr (in/out) a pointer to the window to be written
   @param  size     (in) the size of the window to be written
-  
+
   @retval 0  success
   @retval 1  window size exceeds maximum size of the block of data
 */
+
 int Buffer_iterator::put_next(byte *buff_ptr, size_t size)
 {
   DBUG_ENTER("buffer_iterator::put_next()");
-  /*
-    This needs to be a memory copy. Copy to the cur_ptr.
-  */
+
+  // This needs to be a memory copy. Copy to the cur_ptr.
+
   if (cur_bytes_read + size > max_size)
-    DBUG_RETURN(-1); // error buffer overrun
+    DBUG_RETURN(-1); // Error buffer overrun.
   memcpy(cur_ptr, buff_ptr, size);
   cur_bytes_read= cur_bytes_read + size;
   cur_ptr= cur_ptr + size;
   DBUG_RETURN(0);
 }
 
+
 /**
   @brief Determines the number of windows left to read.
- 
+
   This method calculates how many windows are left to read in
   the iterator. Use this method following initialize() to
   determine the maximum windows you can write to the buffer or
-  use this method to determine how many more windows are 
+  use this method to determine how many more windows are
   remaining to be read.
-  
-  @param  size     (in) the size of the window 
- 
+
+  @param  size     (in) the size of the window
+
   @retval the number of windows left to read
 */
+
 int Buffer_iterator::num_windows(size_t size)
 {
   int num_windows;
@@ -177,21 +189,23 @@ int Buffer_iterator::num_windows(size_t 
   DBUG_RETURN(num_windows);
 }
 
+
 /**
   @brief Retrieve the pointer to the block of data.
- 
-  This method gets the base pointer to the block of data and 
+
+  This method gets the base pointer to the block of data and
   returns it to the caller. This method can be used after writing
   a series of windows to a buffer. When called, the method turns
   off the free() mechanism for freeing the base memory allocated.
-  This was included to allow callers to reuse the memory. For 
+  This was included to allow callers to reuse the memory. For
   example, this method is used in the default algorithm to read
   and write blob data. On write, the pointer to the blob data (the
   data in the buffer) is needed to write to the storage engine. Thus,
   when this method is called the memory is not freed on destruction.
-  
+
   @retval the pointer to the buffer
 */
+
 byte *Buffer_iterator::get_base_ptr()
 {
   byte *ptr;

=== modified file 'sql/backup/buffer_iterator.h'
--- a/sql/backup/buffer_iterator.h	2008-12-18 21:46:36 +0000
+++ b/sql/backup/buffer_iterator.h	2009-10-21 13:32:24 +0000
@@ -5,33 +5,33 @@ using backup::byte;
 
 /**
   @class Buffer_iterator
- 
+
   @brief Encapsulates data buffering functionality.
- 
+
   This class is used in the backup drivers for buffering large blocks
   of data into smaller windows. This allows the backup drivers to
   store a large field in multiple blocks of data allocated by the
   backup kernel.
- 
-  For example, if a driver needs to store a blob field of size 8000 
-  bytes, but the kernel provides a buffer of size 1024 bytes, this 
-  class can be used to break the data into 8 parts. Upon restore, 
+
+  For example, if a driver needs to store a blob field of size 8000
+  bytes, but the kernel provides a buffer of size 1024 bytes, this
+  class can be used to break the data into 8 parts. Upon restore,
   this class can be used to reassemble the parts into the original
   size of data and thus write the data as one block to the engine.
- 
+
   The class provides two methods for creation. The class can take
   a pointer to an existing memory block or if omitted will allocate
   a buffer of the size passed. See the class constructor for more
   details.
- 
+
   To use this class for reading, instantiate the class passing in
   a pointer to the block you want to read, the total size of the
   block, and the size of the window you want to read. Then call
   get_next() for each window you want to read. You can use the
   num_windows() method to indicate how many windows are left to
-  read. This is best used in a loop-like arrangement like the 
+  read. This is best used in a loop-like arrangement like the
   following:
- 
+
   byte *ptr;
   byte *outptr;
   ptr= (byte *)my_malloc(8000, MYF(0));
@@ -39,34 +39,35 @@ using backup::byte;
   while (my_buff->num_windows())
   {
     bytes_read= my_buff->get_next(&out_ptr);
-    // do something with the window in out_ptr here 
-  } 
- 
+    // do something with the window in out_ptr here
+  }
+
   Note: If you want to permit the Buffer_iterator class to create
   it's own buffer, you must use the put_next() method to copy the data
   from your own buffer into the buffer in the class.
- 
-  To use this class for writing, instantiate the class passing in 
+
+  To use this class for writing, instantiate the class passing in
   the total size of the block, and the size of the window you will be
   writing. Note: The window size is not used for writing. Then call
-  put_next() to insert a window into the buffer. Once all of the data 
+  put_next() to insert a window into the buffer. Once all of the data
   has been placed into the buffer, you can use the get_base_ptr() to
   retrieve the pointer to the buffer. This is best used in a loop-like
   arrangement like the following:
- 
+
   long size; //contains size of window to write
   byte *ptr; //contains the pointer to the window
- 
+
   size= read_my_data(&ptr); //read data here
   Buffer_iterator *my_buff = new Buffer_iterator(8000, 1024);
   while (there is data to read)
   {
     my_buff->put_next(&out_ptr, size);
-    // read more here 
-  } 
+    // read more here
+  }
   write_my_reassembled_block(my_buff->get_base_ptr(), total_size);
- 
+
 */
+
 class Buffer_iterator
 {
 public:
@@ -78,13 +79,13 @@ public:
     int num_windows(size_t size);
     byte *get_base_ptr();
 
-private: 
-    byte *buffer;          ///< The pointer to the block of data to iterate
-    byte *cur_ptr;         ///< The current position in the buffer
-    size_t max_size;       ///< The maximum size of the block of data
-    size_t window_size;    ///< The size of the window to read
-    size_t cur_bytes_read; ///< The number of bytes read
-    bool alloc_used;       ///< Indicates whether to dealloc memory or not
+private:
+    byte *buffer;          ///< The pointer to the block of data to iterate.
+    byte *cur_ptr;         ///< The current position in the buffer.
+    size_t max_size;       ///< The maximum size of the block of data.
+    size_t window_size;    ///< The size of the window to read.
+    size_t cur_bytes_read; ///< The number of bytes read.
+    bool alloc_used;       ///< Indicates whether to dealloc memory or not.
 };
 
 #endif

=== modified file 'sql/backup/data_backup.cc'
--- a/sql/backup/data_backup.cc	2009-10-12 09:08:34 +0000
+++ b/sql/backup/data_backup.cc	2009-10-21 13:32:24 +0000
@@ -1,24 +1,24 @@
 /**
   @file
 
-  Code used to backup table data.
+  Code used to backup and restore table data.
 
   Function @c write_table_data() and @c restore_table_data() use backup/restore
-  drivers and protocols to create snapshot of the data stored in the tables being
-  backed up.
+  drivers and protocols to create snapshot of the data stored in the tables
+  being backed up.
 
   @todo Implement better scheduling strategy in Scheduler::step
   @todo Add error reporting in the scheduler and elsewhere
   @todo If an error from driver is ignored (and operation retried) leave trace
         of the error in the log.
- */
+*/
 
 #include "../mysql_priv.h"
 
 #include "backup_kernel.h"
 #include "backup_engine.h"
 #include "stream.h"
-#include "be_default.h"  // needed for table locking code
+#include "be_default.h"  // Needed for table locking code.
 
 /***********************************************
 
@@ -33,12 +33,13 @@ namespace backup {
 
   Structure to store the backup state.
 */
+
 struct backup_state {
 
  /// State of a single backup driver.
  enum value { INACTIVE,   ///< Before backup process is started (phase 0).
               INIT,       ///< During initial data transfer (phase 1).
-              WAITING,    ///< Waiting for other drivers to finish init phase (phase 2).
+              WAITING,    ///< Waiting for others to finish init ph. (phase 2).
               PREPARING,  ///< Preparing for @c lock() call (phase 3).
               READY,      ///< Ready for @c lock() call (phase 4)
               FINISHING,  ///< Final data transfer (phase 7).
@@ -52,7 +53,7 @@ struct backup_state {
 
   static const char* name[];  ///< The text of the state.
 
-  /** 
+  /**
     Initializer
 
     Structure for containing state names.
@@ -82,19 +83,22 @@ private:
 
 };
 
+
 #ifndef DBUG_OFF
 
-const char* backup_state::name[backup_state::MAX];
-backup_state::Initializer init;  ///< Initializer state.
+const char*               backup_state::name[backup_state::MAX];
+backup_state::Initializer init;  ///< Initializer instance.
 
 #endif
 
+
 /**
   Used to write data blocks to a stream.
 
   This class defines how buffers are allocated for data transfers
   (@c get_buf() method). Each block is written as a separate chunk of data.
- */
+*/
+
 class Block_writer
 {
 public:
@@ -106,21 +110,22 @@ public:
   result_t  write_buf(const Buffer&);
   void      drop_buf(Buffer&);
 
-  /// Constructor
+  /// Constructor.
   Block_writer(byte, size_t, Output_stream&);
   ~Block_writer();
 
 private:
 
-  byte           snap_num;  ///< snapshot to which the data belongs
-  Output_stream  &m_str;    ///< stream to which we write
-  size_t         buf_size;  ///< size of a single data block
-  byte           *data_buf; ///< pointer to data buffer
-  bool           taken;     ///< flag which indicates that the buffer is in use
+  byte           snap_num;  ///< Snapshot to which the data belongs.
+  Output_stream  &m_str;    ///< Stream to which we write.
+  size_t         buf_size;  ///< Size of a single data block.
+  byte           *data_buf; ///< Pointer to data buffer.
+  bool           taken;     ///< Flag which indicates that the buffer is in use.
 
   friend class Backup_pump;
 };
 
+
 /**
   @class Backup_pump
 
@@ -146,7 +151,7 @@ public:
        } mode;    ///< mode of operation.
 
   size_t  init_size; ///< size as returned by backup driver's @c init_data().
-  size_t  bytes_in;  ///< number of bytes written. 
+  size_t  bytes_in;  ///< number of bytes written.
   size_t  bytes_out; ///< number of bytes read.
 
   const char *m_name; ///< Name of the driver (for debug purposes).
@@ -161,14 +166,15 @@ public:
 
   int pump(size_t*);
 
+  /*
+    The following calls are forwarded to the backup driver. See
+    @c Backup_driver.
+  */
   int begin();
   int end();
   int prepare();
-  /// Lock signal
   int lock();
-  /// Unlock signal
   int unlock();
-  /// Cancel the process
   int cancel();
 
   /// Return the backup driver used by the pump.
@@ -185,7 +191,7 @@ public:
 private:
 
   /// If block writer has no buffers, retry this many times before giving up.
-  static const uint get_buf_retries= 3; 
+  static const uint get_buf_retries= 3;
 
   Logger        *m_log;   ///< Used to report errors if not NULL.
   Backup_driver *m_drv;   ///< Pointer to the backup driver.
@@ -195,11 +201,11 @@ private:
   /**
     Pointer to the memory area used as write buffer.
 
-    If m_buf_head is NULL and we are in READ state, then we should allocate new 
-    write buffer and ask driver to fill it with data. M_buf_head is not NULL 
-    only when the write buffer is being filled with data but the operation is 
+    If m_buf_head is NULL and we are in READ state, then we should allocate new
+    write buffer and ask driver to fill it with data. M_buf_head is not NULL
+    only when the write buffer is being filled with data but the operation is
     not complete.
-   */
+  */
   byte          *m_buf_head;
 
   /// How many times failed to get a buffer from block writer.
@@ -220,21 +226,23 @@ private:
 
 };
 
+
 /*
   The constant is declared here (and memory allocated for it) because
   IBM's xlc compiler requires that. However, the intention was to make it
   a pure symbolic constant (no need to allocate memory). If someone knows
   how to achieve that and keep xlc happy, please let me know. /Rafal
-*/ 
+*/
 const uint Backup_pump::get_buf_retries;
 
+
 /**
  @class Scheduler
 
  Used to drive several backup pumps in a fair fashion. Also, keeps track of the
  state of these pumps.
-
 */
+
 class Scheduler
 {
   class Pump;
@@ -249,9 +257,9 @@ public:
   int lock();
   int unlock();
 
-  uint  init_count;     ///< no. drivers sending init data
-  uint  prepare_count;  ///< no. drivers preparing for lock
-  uint  finish_count;   ///< no. drivers sending final data
+  uint  init_count;     ///< Nr of drivers sending init data.
+  uint  prepare_count;  ///< Nr of drivers preparing for lock.
+  uint  finish_count;   ///< Nr of drivers sending final data.
 
   /// Return number of initial items left to process.
   size_t init_left() const
@@ -270,13 +278,13 @@ public:
 private:
 
   LIST   *m_pumps, *m_last;
-  Logger &m_log;        ///< for reporting errors          
-  uint   m_count;       ///< current number of pumps
-  size_t m_total;       ///< accumulated position of all drivers
-  size_t m_init_left;   ///< how much of init data is left (estimate)
-  uint   m_known_count; ///< no. drivers which can estimate init data size
-  Output_stream &m_str; ///< stream to which we write
-  bool   cancelled;     ///< true if backup process was cancelled
+  Logger &m_log;        ///< For reporting errors.
+  uint   m_count;       ///< Current number of pumps.
+  size_t m_total;       ///< Accumulated position of all drivers.
+  size_t m_init_left;   ///< How much of init data is left (estimate).
+  uint   m_known_count; ///< Nr of drivers which can estimate init data size.
+  Output_stream &m_str; ///< Stream to which we write.
+  bool   cancelled;     ///< True if backup process was cancelled.
 
   Scheduler(Output_stream &s, Logger &log)
     :init_count(0), prepare_count(0), finish_count(0),
@@ -289,14 +297,16 @@ private:
   void remove_pump(Pump_iterator&);
   void cancel_backup();
 
-  friend int write_table_data(THD*, Backup_info&, Output_stream&);
+  friend int   write_table_data(THD*, Backup_info&, Output_stream&);
   friend class Pump_iterator;
 };
 
+
 /**
   Extend Backup_pump with information about its position relative
   to other pumps.
- */
+*/
+
 class Scheduler::Pump: public Backup_pump
 {
   size_t start_pos;
@@ -306,7 +316,7 @@ class Scheduler::Pump: public Backup_pum
 
 public:
 
-  /// Constructor
+  /// Constructor.
   Pump(Snapshot_info &snap, Output_stream &s)
     :Backup_pump(snap, bw), start_pos(0),
     bw(snap.m_num - 1, DATA_BUFFER_SIZE, s)
@@ -365,7 +375,7 @@ public:
 
         This step unlocks the global read lock and thereby terminating the
         commit blocker.
-  */
+*/
 
 
 /**
@@ -379,18 +389,17 @@ public:
    @param  tables (in) list of tables to be backed-up.
 
    @returns 0 on success.
-  */
+*/
+
 int block_commits(THD *thd, TABLE_LIST *tables)
 {
   DBUG_ENTER("block_commits()");
 
-  DBUG_EXECUTE_IF("backup_grl_fail", 
-    /* Mimic behavior of a failing lock_global_read_lock */
+  DBUG_EXECUTE_IF("backup_grl_fail",
+    /* Mimic behavior of a failing lock_global_read_lock. */
     DBUG_RETURN(1););
 
-  /*
-    Step 1 - global read lock.
-  */
+  // Step 1 - global read lock.
   DEBUG_SYNC(thd, "before_commit_block");
   if (lock_global_read_lock(thd))
     DBUG_RETURN(1);
@@ -411,25 +420,24 @@ int block_commits(THD *thd, TABLE_LIST *
   */
 
   DBUG_EXECUTE_IF("backup_grl_block_commit_fail",
-    /* Mimic behavior of a failing make_global_read_lock_block_commit */
+    /* Mimic behavior of a failing make_global_read_lock_block_commit. */
     unlock_global_read_lock(thd);
     DBUG_RETURN(1);
   );
-  
-  /*
-    Step 3 - make the global read lock to block commits.
-  */
+
+  // Step 3 - make the global read lock to block commits.
   if (make_global_read_lock_block_commit(thd))
   {
-    /* Don't leave things in a half-locked state */
+    /* Don't leave things in a half-locked state. */
     unlock_global_read_lock(thd);
     DBUG_RETURN(1);
   }
   DBUG_RETURN(0);
 }
 
+
 /**
-   Unblock commits
+   Unblock commits.
 
    This method is used to terminate the commit blocker. It calls the last
    step of the algorithm (unlock global read lock).
@@ -437,7 +445,8 @@ int block_commits(THD *thd, TABLE_LIST *
    @param  thd    (in) the current thread structure.
 
    This method cannot fail.
-  */
+*/
+
 void unblock_commits(THD *thd)
 {
   DBUG_ENTER("unblock_commits()");
@@ -445,35 +454,33 @@ void unblock_commits(THD *thd)
   DBUG_VOID_RETURN;
 }
 
+
 /**
   Store information about validity point in @c Backup_info structure.
-  
+
   @note This function is called in a time critical synchronization phase
   of the backup process. Therefore it should not perform any time consuming
   or potentially waiting operations such as I/O.
 
   @returns 0 on success.
 */
+
 static
 int save_vp_info(Backup_info &info)
 {
   LOG_INFO binlog_start_pos;
   int ret=0;
 
-  /*
-    Save VP creation time.
-  */
+  // Save VP creation time.
   info.save_vp_time(my_time(0));
 
-  /*
-    Save current binlog position if it is enabled.
-  */
+  // Save current binlog position if it is enabled.
   if (mysql_bin_log.is_open())
   {
     ret= mysql_bin_log.get_current_log(&binlog_start_pos);
-    
+
     DBUG_EXECUTE_IF("ER_BACKUP_BINLOG", ret= TRUE;);
-    
+
     if (ret)
     {
       info.m_log.report_error(ER_BACKUP_BINLOG);
@@ -483,30 +490,30 @@ int save_vp_info(Backup_info &info)
       info.save_binlog_info(binlog_start_pos);
   }
 
-  /*
-    Save master's binlog information if we are a connected slave.
-  */
+  // Save master's binlog information if we are a connected slave.
   if (obs::is_slave() && active_mi)
     info.save_master_binlog_info(*active_mi);
 
   return ret;
 }
 
+
 /**
   Log validity point information.
 
   Information such as validity point time is logged using backup logger which,
   in particular, writes it to backup history and progress logs.
-  
+
   @note Logging the information may involve time consuming I/O. Therefore this
   function should not be called in the time critical synchronization phase, but
   after the synchronisation has been done.
-*/ 
+*/
+
 static
 void report_vp_info(Backup_info &info)
 {
-  info.m_log.report_vp_time(info.get_vp_time(), 
-                            TRUE // = also write to progress log
+  info.m_log.report_vp_time(info.get_vp_time(),
+                            TRUE // Also write to progress log.
                            );
   if (info.flags & BSTREAM_FLAG_BINLOG)
     info.m_log.report_binlog_info(info.binlog_info);
@@ -523,7 +530,8 @@ void report_vp_info(Backup_info &info)
   a round robin fashion.
 
   @returns 0 on success.
- */
+*/
+
 int write_table_data(THD* thd, Backup_info &info, Output_stream &s)
 {
   DBUG_ENTER("backup::write_table_data");
@@ -531,31 +539,31 @@ int write_table_data(THD* thd, Backup_in
   /*
     If there are no tables to backup, there is nothing to do in this function
     except for storing and reporting the validity point info.
-    
-    Note that since DDLs are disabled and backup image contains no table data, 
-    any time during backup operation is a good validity time -- there is no 
-    issue of synchronising the data stored in the image with the data in the 
+
+    Note that since DDLs are disabled and backup image contains no table data,
+    any time during backup operation is a good validity time -- there is no
+    issue of synchronising the data stored in the image with the data in the
     rest of the server.
-  */ 
+  */
   if (info.snap_count() == 0 || info.table_count() == 0) // nothing to backup
   {
-    int res= save_vp_info(info);    // logs errors
+    int res= save_vp_info(info);    // Logs errors.
     if (!res)
       report_vp_info(info);
     DBUG_RETURN(res);
   }
 
   Logger      &log= info.m_log;
-  Scheduler   sch(s, log);          // scheduler instance
-  List<Scheduler::Pump>  inactive;  // list of images not yet being created
+  Scheduler   sch(s, log);          // Scheduler instance.
+  List<Scheduler::Pump>  inactive;  // List of images not yet being activated.
 
-  // keeps maximal init size for images in inactive list
+  // Keeps maximal init size for images in inactive list.
   size_t  max_init_size=0;
-  bool    commits_blocked= FALSE;   // indicates if commit blocker is active
+  bool    commits_blocked= FALSE;   // Indicates if commit blocker is active.
 
   DBUG_PRINT("backup_data",("initializing scheduler"));
 
-  // add unknown "at end" drivers to scheduler, rest to inactive list
+  // Add unknown "at end" drivers to scheduler, rest to inactive list.
 
   for (uint n=0; n < info.snap_count(); ++n)
   {
@@ -586,7 +594,7 @@ int write_table_data(THD* thd, Backup_in
 
     if (init_size == Driver::UNKNOWN_SIZE)
     {
-      if (sch.add(p))    // logs errors
+      if (sch.add(p))    // Logs errors.
         goto error;
     }
     else
@@ -596,8 +604,9 @@ int write_table_data(THD* thd, Backup_in
 
       if (inactive.push_back(p))
       {
-        /* Allocation failed. 
-           Error has been reported, but not logged to backup logs.
+        /*
+          Allocation failed. Error has been reported, but not logged to
+          backup logs.
         */
         log.log_error(ER_OUT_OF_RESOURCES);
         goto error;
@@ -605,9 +614,7 @@ int write_table_data(THD* thd, Backup_in
     }
   }
 
-  /*
-    Each driver should be either in the scheduler or on inactive list.
-   */
+  // Each driver should be either in the scheduler or on inactive list.
   DBUG_ASSERT( !sch.is_empty() || !inactive.is_empty() );
 
   DBUG_PRINT("backup_data",("%u drivers initialized, %u inactive",
@@ -618,17 +625,17 @@ int write_table_data(THD* thd, Backup_in
   DEBUG_SYNC(thd, "before_backup_data_init");
 
   /*
-   Poll "at end" drivers activating inactive ones on the way.
+    Poll "at end" drivers activating inactive ones on the way.
 
-   Note: if scheduler is empty and there are images with non-zero
-   init size (max_init_size > 0) then enter the loop as one such image
-   will be added to the scheduler inside.
+    Note: if scheduler is empty and there are images with non-zero
+    init size (max_init_size > 0) then enter the loop as one such image
+    will be added to the scheduler inside.
   */
 
   while (sch.init_count > 0 || (sch.is_empty() && max_init_size > 0))
   {
 
-    // add inactive image if it is a time for it
+    // Add inactive image if it is a time for it.
 
     if (max_init_size > 0 && sch.init_left() <= max_init_size)
     {
@@ -655,14 +662,14 @@ int write_table_data(THD* thd, Backup_in
         goto error;
     }
 
-    // poll drivers
+    // Poll drivers.
 
-    if (sch.step())    // logs errors
+    if (sch.step())    // Logs errors.
       goto error;
   }
 
   {
-    // start "at begin" drivers
+    // Start "at begin" drivers.
     DBUG_PRINT("backup_data",("- activating \"at begin\" drivers"));
 
     List_iterator<Scheduler::Pump>  it1(inactive);
@@ -676,7 +683,7 @@ int write_table_data(THD* thd, Backup_in
     if (sch.step())
       goto error;
 
-    // prepare for VP
+    // Prepare for VP.
     DBUG_PRINT("backup_data",("-- PREPARE PHASE --"));
     DEBUG_SYNC(thd, "before_backup_data_prepare");
 
@@ -687,6 +694,7 @@ int write_table_data(THD* thd, Backup_in
       blocker has been implemented. WL#4610 tracks the work on a
       refined commit blocker
     */
+
     /*
       Block commits.
 
@@ -706,7 +714,7 @@ int write_table_data(THD* thd, Backup_in
       goto error;
     }
 
-    if (sch.prepare())    // logs errors
+    if (sch.prepare())    // Logs errors.
       goto error;
 
     while (sch.prepare_count > 0)
@@ -714,12 +722,10 @@ int write_table_data(THD* thd, Backup_in
       goto error;
 
     /**** VP creation (start) ********************************************/
-    
+
     DBUG_PRINT("backup_data",("-- SYNC PHASE --"));
 
-    /*
-      Before proceeding, check if the process is interrupted.
-    */
+    //  Before proceeding, check if the process is interrupted.
     if (log.report_killed())
       goto error;
 
@@ -730,30 +736,26 @@ int write_table_data(THD* thd, Backup_in
       timing of the validity point.
     */
     DEBUG_SYNC(thd, "after_backup_validated");
-    
-    /*
-      Refined commit blocker should be set here; see WL#4610
-    */
+
+    // Refined commit blocker should be set here; see WL#4610.
 
     DEBUG_SYNC(thd, "before_backup_data_lock");
     /*
-      Note: we do not detect/react to process interruptions during the 
+      Note: we do not detect/react to process interruptions during the
       synchronization. We let the protocol to go through and check for
       possible interruptions only at the end, i.e., after sch.unlock().
-    */ 
-    if (sch.lock())    // logs errors
+    */
+    if (sch.lock())    // Logs errors.
       goto error;
 
     if (save_vp_info(info))
       goto error;
 
     DEBUG_SYNC(thd, "before_backup_data_unlock");
-    if (sch.unlock() || log.report_killed())    // logs errors
+    if (sch.unlock() || log.report_killed())    // Logs errors.
       goto error;
 
-    /*
-      Unblock commits.
-    */
+    // Unblock commits.
     DEBUG_SYNC(thd, "before_backup_unblock_commit");
     unblock_commits(thd);
     commits_blocked= FALSE;
@@ -768,7 +770,7 @@ int write_table_data(THD* thd, Backup_in
 
     /**** VP creation (end) ********************************************/
 
-    // get final data from drivers
+    // Get final data from drivers.
     DBUG_PRINT("backup_data",("-- FINISH PHASE --"));
 
     DEBUG_SYNC(thd, "before_backup_data_finish");
@@ -792,6 +794,7 @@ int write_table_data(THD* thd, Backup_in
 
 } // backup namespace
 
+
 /**************************************************
 
         Implementation of Scheduler
@@ -800,9 +803,8 @@ int write_table_data(THD* thd, Backup_in
 
 namespace backup {
 
-/**
-  Used to iterate over backup pumps of a scheduler.
- */
+/** Used to iterate over backup pumps of a scheduler. */
+
 class Scheduler::Pump_iterator
 {
 public:
@@ -839,13 +841,15 @@ public:
 
 };
 
+
 /**
   Pick next backup pump and call its @c pump() method.
 
   Method updates statistics of number of drivers in each phase which is used
   to detect end of a backup process. A check for interruption is done each time
   this method is called.
- */
+*/
+
 int Scheduler::step()
 {
   if (m_log.report_killed())
@@ -863,7 +867,7 @@ int Scheduler::step()
         p= it;
   */
 
-  if (!p) // No active pumps
+  if (!p) // No active pumps.
   {
     init_count= prepare_count= finish_count= 0;  // safety
     return 0;
@@ -884,7 +888,7 @@ int Scheduler::step()
   DBUG_ASSERT(!(res && after_state != backup_state::ERROR));
   DBUG_ASSERT(!(!res && after_state == backup_state::ERROR));
 
-  // update statistics
+  // Update statistics.
 
   if (!res && howmuch > 0)
   {
@@ -932,44 +936,51 @@ int Scheduler::step()
       break;
 
     case backup_state::DONE:
-      res= p->end();  // Logs errors, fall-through to error handling below
+      res= p->end();   // Logs errors, fall-through to error handling below
 
     case backup_state::ERROR:
-      remove_pump(p);   // Note: never errors.
+      remove_pump(p);  // Never errors.
       break;
 
     default: break;
     }
 
-    DBUG_PRINT("backup_data",("driver counts: total=%u, init=%u, prepare=%u, finish=%u.",
-                              m_count, init_count, prepare_count, finish_count));
+    DBUG_PRINT("backup_data",("driver counts: "
+                              "total=%u, init=%u, prepare=%u, finish=%u.",
+                              m_count, init_count, prepare_count,
+                              finish_count));
   }
 
   return res;
 }
 
+
 /**
   Add backup pump to the scheduler.
 
   The pump is initialized with begin() call. In case of error, it is deleted.
- */
+*/
+
 int Scheduler::add(Pump *p)
 {
   size_t  avg= m_count? m_total/m_count + 1 : 0;
 
-  if (!p)  // no pump to add
+  if (!p)  // No pump to add.
     return 0;
 
   p->set_logger(&m_log);
   p->start_pos= avg;
 
-  if (p->begin() || m_log.report_killed())  // logs errors
+  if (p->begin() || m_log.report_killed())  // Logs errors.
   {
     delete p;
     return ERROR;
   }
 
-  // in case of error, above call should return non-zero code (and report error)
+  /*
+    In case of error, above call should return non-zero code
+    (and report error).
+  */
   DBUG_ASSERT(p->state != backup_state::ERROR);
 
   DBUG_PRINT("backup_data",("Adding %s to scheduler (at pos %lu)",
@@ -1005,15 +1016,17 @@ int Scheduler::add(Pump *p)
   default: break;
   }
 
-  DBUG_PRINT("backup_data",("driver counts: total=%u, init=%u, prepare=%u, finish=%u.",
+  DBUG_PRINT("backup_data",("driver counts: "
+                            "total=%u, init=%u, prepare=%u, finish=%u.",
                             m_count, init_count, prepare_count, finish_count));
   DBUG_PRINT("backup_data",("total init data size estimate: %lu",
                             (unsigned long)m_init_left));
-
   return 0;
 }
 
+
 /// Move backup pump to the end of scheduler's list.
+
 void Scheduler::move_pump_to_end(const Pump_iterator &p)
 {
   // The pump to move is in the m_pumps list so the list can't be empty.
@@ -1028,11 +1041,13 @@ void Scheduler::move_pump_to_end(const P
   }
 }
 
+
 /**
   Remove backup pump from the scheduler.
 
   The corresponding backup driver is shut down using @c end() call.
- */
+*/
+
 void Scheduler::remove_pump(Pump_iterator &p)
 {
   DBUG_ASSERT(p.pumps);
@@ -1048,19 +1063,21 @@ void Scheduler::remove_pump(Pump_iterato
 
   if (p)
   {
-    // destructor calls driver's free() method
+    // Destructor calls driver's free() method.
     delete static_cast<Pump*>(p.pumps->data);
     my_free(p.pumps, MYF(0));
   }
 }
 
+
 /// Shut down backup process.
+
 void Scheduler::cancel_backup()
 {
   if (cancelled)
     return;
 
-  // shutdown any remaining drivers
+  // Shutdown any remaining drivers.
   while (m_count && m_pumps)
   {
     Pump_iterator p(*this);
@@ -1073,50 +1090,57 @@ void Scheduler::cancel_backup()
 
 
 /// Start prepare phase for all drivers.
+
 int Scheduler::prepare()
 {
   DBUG_ASSERT(!cancelled);
-  // we should start prepare phase only when init phase is finished
+  // We should start prepare phase only when init phase is finished.
   DBUG_ASSERT(init_count == 0);
   DBUG_PRINT("backup_data",("calling prepare() for all drivers"));
 
   for (Pump_iterator it(*this); it; ++it)
   {
-    if (it->prepare() || m_log.report_killed())  // logs errors
+    if (it->prepare() || m_log.report_killed())  // Logs errors.
     {
-      remove_pump(it);  // Note: never errors.
+      remove_pump(it);  // Never errors.
       return ERROR;
     }
     if (it->state == backup_state::PREPARING)
      prepare_count++;
   }
 
-  DBUG_PRINT("backup_data",("driver counts: total=%u, init=%u, prepare=%u, finish=%u.",
+  DBUG_PRINT("backup_data",("driver counts: "
+                            "total=%u, init=%u, prepare=%u, finish=%u.",
                             m_count, init_count, prepare_count, finish_count));
   return 0;
 }
 
+
 /// Lock all drivers.
+
 int Scheduler::lock()
 {
   DBUG_ASSERT(!cancelled);
-  // lock only when init and prepare phases are finished
+  // Lock only when init and prepare phases are finished.
   DBUG_ASSERT(init_count == 0 && prepare_count == 0);
   DBUG_PRINT("backup_data",("calling lock() for all drivers"));
 
   for (Pump_iterator it(*this); it; ++it)
-   if (it->lock())    // logs errors
+   if (it->lock())    // Logs errors
    {
-     remove_pump(it);  // Note: never errors.
+     remove_pump(it);  // Never errors.
      return ERROR;
    }
 
-  DBUG_PRINT("backup_data",("driver counts: total=%u, init=%u, prepare=%u, finish=%u.",
+  DBUG_PRINT("backup_data",("driver counts: "
+                            "total=%u, init=%u, prepare=%u, finish=%u.",
                             m_count, init_count, prepare_count, finish_count));
   return 0;
 }
 
+
 /// Unlock all drivers.
+
 int Scheduler::unlock()
 {
   DBUG_ASSERT(!cancelled);
@@ -1124,9 +1148,9 @@ int Scheduler::unlock()
 
   for(Pump_iterator it(*this); it; ++it)
   {
-    if (it->unlock())   // logs errors
+    if (it->unlock())   // Logs errors.
     {
-      remove_pump(it);  // Note: never errors.
+      remove_pump(it);  // Never errors.
       return ERROR;
     }
     if (it->state == backup_state::FINISHING)
@@ -1154,9 +1178,9 @@ Backup_pump::Backup_pump(Snapshot_info &
   if (bitmap_init(&m_closed_streams,
               NULL,
               1 + snap.table_count(),
-              FALSE)) // not thread safe
+              FALSE)) // Not thread safe.
   {
-    state= backup_state::ERROR;  // Created object will be invalid
+    state= backup_state::ERROR;  // Created object will be invalid.
     return;
   }
 
@@ -1167,6 +1191,7 @@ Backup_pump::Backup_pump(Snapshot_info &
     init_size= m_drv->init_size();
 }
 
+
 Backup_pump::~Backup_pump()
 {
   if (m_drv)
@@ -1174,17 +1199,19 @@ Backup_pump::~Backup_pump()
   bitmap_free(&m_closed_streams);
 }
 
+
 /*
   Note: The standard report_error() method does not log an error in case
   the statement has been interrupted - the interruption is reported instead.
   But we want to always report errors signalled by a backup driver, even if an
-  interruption has just happened. Therefore, inside Backup_pump methods where 
-  errors from the driver are reported, we use the variant of 
-  Logger::report_error() with explicit log_level::ERROR. This variant does not 
+  interruption has just happened. Therefore, inside Backup_pump methods where
+  errors from the driver are reported, we use the variant of
+  Logger::report_error() with explicit log_level::ERROR. This variant does not
   check for interruptions and always reports given error.
-*/ 
+*/
 
 /// Initialize backup driver.
+
 int Backup_pump::begin()
 {
   state= backup_state::INIT;
@@ -1207,7 +1234,9 @@ int Backup_pump::begin()
   return 0;
 }
 
+
 /// Shut down the driver.
+
 int Backup_pump::end()
 {
   if (state != backup_state::SHUT_DOWN)
@@ -1234,12 +1263,14 @@ int Backup_pump::end()
   return 0;
 }
 
+
 /// Start prepare phase for the driver.
+
 int Backup_pump::prepare()
 {
   result_t res= m_drv->prelock();
 
-  // Error code insertion
+  // Error code insertion.
   DBUG_EXECUTE_IF("ER_BACKUP_PREPARE_DRIVER", res= ERROR;);
 
   switch (res) {
@@ -1266,7 +1297,9 @@ int Backup_pump::prepare()
   return 0;
 }
 
+
 /// Request VP from the driver.
+
 int Backup_pump::lock()
 {
   DBUG_PRINT("backup_data",(" locking %s", m_name));
@@ -1280,7 +1313,7 @@ int Backup_pump::lock()
   {
     state= backup_state::ERROR;
     if (m_log)
-      m_log->report_error(log_level::ERROR, 
+      m_log->report_error(log_level::ERROR,
                           ER_BACKUP_CREATE_VP, m_name);
     return ERROR;
   }
@@ -1288,22 +1321,24 @@ int Backup_pump::lock()
   return 0;
 }
 
+
 /// Unlock the driver after VP creation.
+
 int Backup_pump::unlock()
 {
   DBUG_PRINT("backup_data",(" unlocking %s, goes to FINISHING state", m_name));
   state= backup_state::FINISHING;
-  
+
   int res= m_drv->unlock();
 
-  // Error condition insertion for ER_BACKUP_UNLOCK_DRIVER 
+  // Error condition insertion for ER_BACKUP_UNLOCK_DRIVER.
   DBUG_EXECUTE_IF("ER_BACKUP_UNLOCK_DRIVER", res= ERROR;);
 
   if (res == ERROR)
   {
     state= backup_state::ERROR;
     if (m_log)
-      m_log->report_error(log_level::ERROR, 
+      m_log->report_error(log_level::ERROR,
                           ER_BACKUP_UNLOCK_DRIVER, m_name);
     return ERROR;
   }
@@ -1311,13 +1346,14 @@ int Backup_pump::unlock()
   return 0;
 }
 
+
 int Backup_pump::cancel()
 {
   if (ERROR == m_drv->cancel())
   {
     state= backup_state::ERROR;
     if (m_log)
-      m_log->report_error(log_level::ERROR, 
+      m_log->report_error(log_level::ERROR,
                           ER_BACKUP_CANCEL_BACKUP, m_name);
     return ERROR;
   }
@@ -1325,6 +1361,7 @@ int Backup_pump::cancel()
   return 0;
 }
 
+
 /**
   Poll the driver for next block of data and/or write data to stream.
 
@@ -1333,18 +1370,19 @@ int Backup_pump::cancel()
   to the stream. Answers from drivers @c get_data() method are interpreted and
   the state of the driver is updated accordingly.
 */
+
 int Backup_pump::pump(size_t *howmuch)
 {
-  // pumping not allowed in these states
+  // Pumping not allowed in these states.
   DBUG_ASSERT(state != backup_state::INACTIVE);
   DBUG_ASSERT(state != backup_state::SHUT_DOWN);
   DBUG_ASSERT(state != backup_state::CANCELLED);
 
-  // we have detected error before - report it once more
+  // We have detected error before - report it once more.
   if (state == backup_state::ERROR)
     return ERROR;
 
-  // we are done and thus there is nothing to do
+  // We are done and thus there is nothing to do.
   if (state == backup_state::DONE)
     return 0;
 
@@ -1387,7 +1425,7 @@ int Backup_pump::pump(size_t *howmuch)
       if (!m_buf_head)
       {
         backup::Block_writer::result_t buf_err= m_bw.get_buf(m_buf);
- 
+
         // Error condition insertion for ER_BACKUP_GET_BUF.
         DBUG_EXECUTE_IF("ER_BACKUP_GET_BUF", buf_err= Block_writer::ERROR;);
         switch (buf_err) {
@@ -1399,7 +1437,7 @@ int Backup_pump::pump(size_t *howmuch)
 
         case Block_writer::NO_RES:
           if (++m_buf_retries <= get_buf_retries)
-            return 0; // we shall try again
+            return 0; // We shall try again.
 
         case Block_writer::ERROR:
         default:
@@ -1438,8 +1476,8 @@ int Backup_pump::pump(size_t *howmuch)
 
         if (m_buf.size > 0)
           mode= WRITING;
-        else 
-          m_bw.drop_buf(m_buf);              // Never errors
+        else
+          m_bw.drop_buf(m_buf);         // Never errors.
 
         break;
 
@@ -1458,8 +1496,8 @@ int Backup_pump::pump(size_t *howmuch)
         state= backup_state::DONE;
 
       case BUSY:
-        m_bw.drop_buf(m_buf);                   // Never errors
-        m_buf_head=NULL;  // thus a new request will be made
+        m_bw.drop_buf(m_buf);           // Never errors.
+        m_buf_head=NULL;                // Thus a new request will be made.
       }
 
     } // if (mode == READING)
@@ -1470,7 +1508,7 @@ int Backup_pump::pump(size_t *howmuch)
     {
       backup::Block_writer::result_t res= m_bw.write_buf(m_buf);
 
-      // Error condition insertion for ER_BACKUP_WRITE_DATA 
+      // Error condition insertion for ER_BACKUP_WRITE_DATA.
       DBUG_EXECUTE_IF("ER_BACKUP_WRITE_DATA", res=Block_writer::ERROR;);
 
       switch (res) {
@@ -1494,7 +1532,7 @@ int Backup_pump::pump(size_t *howmuch)
         state= backup_state::ERROR;
         return ERROR;
 
-      default:  // retry write
+      default:  // Retry write.
         break;
 
       }
@@ -1521,8 +1559,10 @@ namespace backup {
 
 
 /**
-  Read backup image data from a backup stream and forward it to restore drivers.
- */
+  Read backup image data from a backup stream and forward it to restore
+  drivers.
+*/
+
 int restore_table_data(THD *thd, Restore_info &info, Input_stream &s)
 {
   st_bstream_data_chunk chunk_info; // For reading chunks from the stream.
@@ -1535,12 +1575,12 @@ int restore_table_data(THD *thd, Restore
     If there are no tables stored in the image, there is nothing to do in this
     function. However, we must call bstream_rd_data_chunk() which will absorb
     the 0x00 byte signalling end of (the empty) table data chunk sequence.
-  */ 
+  */
 
   if (info.snap_count() == 0 || info.table_count() == 0) // nothing to restore
   {
     int res= bstream_rd_data_chunk(&s, &chunk_info);
-    
+
     // Error code insertion for ER_BACKUP_UNEXPECTED_DATA.
     DBUG_EXECUTE_IF("ER_BACKUP_UNEXPECTED_DATA", res= BSTREAM_OK;);
 
@@ -1559,25 +1599,23 @@ int restore_table_data(THD *thd, Restore
   /* Drv[n] points at restore driver used to process snapshot n. */
   Restore_driver* drv[MAX_SNAP_COUNT];
   /*
-    Active[n] is not NULL if driver drv[n] has been activated. Such driver needs 
+    Active[n] is not NULL if driver drv[n] has been activated. Such driver needs
     an end() or cancel() call to shut it down properly.
-  */ 
+  */
   Restore_driver* active[MAX_SNAP_COUNT];
-  
-  /*
-   Zero out arrays. Can cause issues on some builds.
-   */
+
+  // Zero out arrays. Can cause issues on some builds.
   for (int i= 0; i < MAX_SNAP_COUNT; i++)
   {
     drv[i]= NULL;
     active[i]= NULL;
   }
-  
+
   /*
     Bad_drivers string for holding comma separated list of drivers which
     signalled errors during shutdown. If non-empty, an error will be logged
     at the end of the function (finish: label).
-   */   
+  */
   String bad_drivers;
 
   int count= info.snap_count();
@@ -1592,7 +1630,7 @@ int restore_table_data(THD *thd, Restore
     DBUG_RETURN(ERROR);
   }
 
-  // Create restore drivers
+  // Create restore drivers.
   DEBUG_SYNC(thd, "restore_before_drivers_create");
   result_t res;
 
@@ -1602,7 +1640,7 @@ int restore_table_data(THD *thd, Restore
 
     Snapshot_info *snap= info.m_snap[n];
 
-    // note: img can be NULL if it is not used in restore.
+    // Note: img can be NULL if it is not used in restore.
     if (!snap)
       continue;
 
@@ -1611,15 +1649,15 @@ int restore_table_data(THD *thd, Restore
       goto error;
 
     // Error code insertion for ER_BACKUP_CREATE_RESTORE_DRIVER.
-    DBUG_EXECUTE_IF("ER_BACKUP_CREATE_RESTORE_DRIVER", 
+    DBUG_EXECUTE_IF("ER_BACKUP_CREATE_RESTORE_DRIVER",
       res= backup::ERROR;);
 
     if (res == backup::ERROR)
     {
       log.report_error(ER_BACKUP_CREATE_RESTORE_DRIVER, snap->name());
       goto error;
-    };   
- }
+    };
+  }
 
   // Initialize the drivers.
   DEBUG_SYNC(thd, "restore_before_drivers_init");
@@ -1637,11 +1675,12 @@ int restore_table_data(THD *thd, Restore
       log.report_error(ER_BACKUP_INIT_RESTORE_DRIVER, info.m_snap[n]->name());
       goto error;
     }
-    
+
     active[n]= drv[n];
   }
 
   DEBUG_SYNC(thd, "restore_in_progress");
+
   {
     Buffer  buf;
     uint    snap_num= 0;
@@ -1650,10 +1689,10 @@ int restore_table_data(THD *thd, Restore
 
     static const uint MAX_REPEATS= 7;
 
-    Restore_driver  *drvr= NULL;  // pointer to the current driver
-    Snapshot_info   *snap= NULL;   // corresponding snapshot object
+    Restore_driver  *drvr= NULL;   // Pointer to the current driver.
+    Snapshot_info   *snap= NULL;   // Corresponding snapshot object.
 
-    // main data reading loop
+    // Main data reading loop.
 
     while ( state != DONE && state != ERROR )
     {
@@ -1692,7 +1731,7 @@ int restore_table_data(THD *thd, Restore
         if (state != SENDING)
           break;
 
-        // data chunk should never be empty
+        // Data chunk should never be empty.
         DBUG_ASSERT(chunk_info.data.begin);
         DBUG_ASSERT(chunk_info.data.begin < chunk_info.data.end);
 
@@ -1724,7 +1763,7 @@ int restore_table_data(THD *thd, Restore
          */
         DBUG_ASSERT(snap && drvr);
 
-        /* 
+        /*
            Note: For testing, error can be injected in default driver
            send_data by using dbug hook 'backup_default_send_data'
         */
@@ -1747,8 +1786,8 @@ int restore_table_data(THD *thd, Restore
         case backup::ERROR:
           log.report_error(ER_BACKUP_SEND_DATA, buf.table_num, snap->name());
           /*
-            If driver signals error then it is not active any longer - neither 
-            ->end() nor ->cancel() should be called on it, only ->free(). 
+            If driver signals error then it is not active any longer - neither
+            ->end() nor ->cancel() should be called on it, only ->free().
             This is why we need to remove it from active[] array.
           */
           active[snap_num]= NULL;
@@ -1759,7 +1798,7 @@ int restore_table_data(THD *thd, Restore
         default:
         {
           // Error code insertion for ER_BACKUP_SEND_DATA_RETRY.
-          DBUG_EXECUTE_IF("ER_BACKUP_SEND_DATA_RETRY", 
+          DBUG_EXECUTE_IF("ER_BACKUP_SEND_DATA_RETRY",
             repeats= (MAX_REPEATS + 1););
 
           if( repeats > MAX_REPEATS )
@@ -1776,7 +1815,7 @@ int restore_table_data(THD *thd, Restore
         break;
       } // switch(ret)
 
-    } // main reading loop
+    } // Main reading loop.
 
     DBUG_PRINT("restore",("End of backup stream"));
     if (state != DONE)
@@ -1790,7 +1829,7 @@ int restore_table_data(THD *thd, Restore
   for (uint n=0; n < info.snap_count(); ++n)
   {
     // Error code insertion for ER_BACKUP_STOP_RESTORE_DRIVERS.
-    DBUG_EXECUTE_IF("ER_BACKUP_STOP_RESTORE_DRIVERS", 
+    DBUG_EXECUTE_IF("ER_BACKUP_STOP_RESTORE_DRIVERS",
                     if (n > 0) goto error;);
     if (!active[n])
       continue;
@@ -1798,10 +1837,10 @@ int restore_table_data(THD *thd, Restore
     DBUG_PRINT("restore",("Shutting down restore driver %s",
                            info.m_snap[n]->name()));
     res= active[n]->end();
-    /* 
+    /*
       After ->end() call on a driver, it is no longer active and its ->cancel()
-      method should not be called if we jump to error. This is the case even 
-      when ->end() returned error because the only allowed driver call after 
+      method should not be called if we jump to error. This is the case even
+      when ->end() returned error because the only allowed driver call after
       an error is ->end(). Hence we set active[n] to NULL.
     */
     active[n]= NULL;
@@ -1809,7 +1848,7 @@ int restore_table_data(THD *thd, Restore
     /*
       In case of error, store driver's name in bad_drivers so that it is
       reported below.
-    */ 
+    */
     if (res == backup::ERROR)
     {
       state= ERROR;
@@ -1821,12 +1860,12 @@ int restore_table_data(THD *thd, Restore
 
     /*
       If interruption has happened, skip shutting down the rest of the drivers.
-      They will be canceled below.
-    */ 
+      They will be cancelled below.
+    */
     if (log.report_killed())
       goto error;
   }
- 
+
   goto finish;
 
 error:
@@ -1835,7 +1874,7 @@ error:
 
   DBUG_PRINT("restore",("Cancelling restore process"));
 
-  // Call cancel() for all active drivers
+  // Call cancel() for all active drivers.
 
   for (uint n=0; n < info.snap_count(); ++n)
   {
@@ -1846,9 +1885,9 @@ error:
     DBUG_PRINT("restore",("Cancelling restore driver %s",
                            info.m_snap[n]->name()));
     res= active[n]->cancel();
- 
+
     // Error code insertion for ER_BACKUP_STOP_RESTORE_DRIVERS.
-    DBUG_EXECUTE_IF("ER_BACKUP_STOP_RESTORE_DRIVERS", 
+    DBUG_EXECUTE_IF("ER_BACKUP_STOP_RESTORE_DRIVERS",
                     res= backup::ERROR;);
 
     if (res)
@@ -1859,7 +1898,7 @@ error:
     }
   }
 
-finish:  
+finish:
 
   /*
     We always log shutdown errors, even if an interruption has happened before.
@@ -1868,16 +1907,16 @@ finish:  
   */
 
   if (!bad_drivers.is_empty())
-    log.report_error(log_level::ERROR, 
+    log.report_error(log_level::ERROR,
                      ER_BACKUP_STOP_RESTORE_DRIVERS, bad_drivers.c_ptr());
 
-  // Call free() for all existing drivers
+  // Call free() for all existing drivers.
 
   for (uint n=0; n < info.snap_count(); ++n)
   {
     if (!drv[n])
       continue;
-    drv[n]->free();                             // Never errors
+    drv[n]->free();                             // Never errors.
   }
 
   DBUG_RETURN(state == ERROR ? backup::ERROR : 0);
@@ -1901,6 +1940,7 @@ Block_writer::Block_writer(byte snap_num
   data_buf= (byte*)my_malloc(buf_size, MYF(0));
 }
 
+
 Block_writer::~Block_writer()
 {
   if (data_buf)
@@ -1908,6 +1948,7 @@ Block_writer::~Block_writer()
   data_buf= NULL;
 }
 
+
 /**
   Allocate new buffer for data transfer.
 
@@ -1917,9 +1958,9 @@ Block_writer::~Block_writer()
   stream. It can handle only one buffer at a time.
 
   @returns @c NO_RES if buffer can not be allocated, @c OK otherwise.
- */
-Block_writer::result_t
-Block_writer::get_buf(Buffer &buf)
+*/
+
+Block_writer::result_t Block_writer::get_buf(Buffer &buf)
 {
   buf.table_num= 0;
   buf.last= FALSE;
@@ -1939,13 +1980,15 @@ Block_writer::get_buf(Buffer &buf)
   return OK;
 }
 
+
 /**
   Write block of data to stream.
 
   The buffer containing data must be obtained from a previous @c get_buf() call.
   After this call, buffer is returned to the buffer pool and can be reused for
   other transfers.
- */
+*/
+
 Block_writer::result_t
 Block_writer::write_buf(const Buffer &buf)
 {
@@ -1968,13 +2011,15 @@ Block_writer::write_buf(const Buffer &bu
     return ERROR;
 }
 
+
 /**
   Return buffer to the buffer pool.
 
   If a buffer obtained from @c get_buf() is not written to the stream, this
   method can return it to the buffer pool so that it can be reused for other
   transfers.
- */
+*/
+
 void
 Block_writer::drop_buf(Buffer &buf)
 {

=== modified file 'sql/backup/error.h'
--- a/sql/backup/error.h	2009-10-12 09:08:34 +0000
+++ b/sql/backup/error.h	2009-10-21 13:32:24 +0000
@@ -3,11 +3,12 @@
 
 namespace util {
 
-/// Used to save messages pushed into the stack
+/// Used to save messages pushed into the stack.
+
 struct SAVED_MYSQL_ERROR {
-  uint code;                             ///< error code
-  MYSQL_ERROR::enum_warning_level level; ///< warning level
-  char *msg;                             ///< error message
+  uint code;                             ///< Error code.
+  MYSQL_ERROR::enum_warning_level level; ///< Warning level.
+  char *msg;                             ///< Error message.
 };
 
 
@@ -17,14 +18,15 @@ struct SAVED_MYSQL_ERROR {
   If @c err doesn't contain any error code, the given error code is reported.
 
   @returns 0 if error was reported, non-zero otherwise.
- */
+*/
+
 inline
 int report_mysql_error(THD* thd, SAVED_MYSQL_ERROR *err, int code= 0)
 {
   DBUG_ASSERT(err);
 
   if (err->level == MYSQL_ERROR::WARN_LEVEL_END
-      && !err->msg && !err->code ) // err doesn't store any error
+      && !err->msg && !err->code ) // err doesn't store any error.
     return -1;
 
   switch (err->level) {
@@ -37,6 +39,7 @@ int report_mysql_error(THD* thd, SAVED_M
     thd->no_warnings_for_error= old_value;
     return 0;
   }
+
   default: // Q: What to do with warnings and notes? push them... ?
     return -1;
   }
@@ -44,4 +47,5 @@ int report_mysql_error(THD* thd, SAVED_M
 
 } // util namespace
 
+
 #endif

=== modified file 'sql/backup/image_info.cc'
--- a/sql/backup/image_info.cc	2009-10-12 09:08:34 +0000
+++ b/sql/backup/image_info.cc	2009-10-21 13:32:24 +0000
@@ -8,13 +8,12 @@
   @file
 
   @brief Implements @c Image_info class and friends.
-
 */
 
 namespace backup {
 
-Image_info::Image_info() :
-  data_size(0),
+Image_info::Image_info()
+  : data_size(0),
   m_table_count(0),
   m_view_count(0),
   m_routine_count(0),
@@ -22,25 +21,25 @@ Image_info::Image_info() :
   m_dbs(16, 16),
   m_ts_map(16,16)
 {
-  init_alloc_root(&mem_root, 4 * 1024, 0);      // Never errors
+  init_alloc_root(&mem_root, 4 * 1024, 0);      // Never errors.
 
-  /* initialize st_bstream_image_header members */
+  /* Initialize st_bstream_image_header members. */
 
   bzero(static_cast<st_bstream_image_header*>(this),
         sizeof(st_bstream_image_header));
 
-  /* 
-    This code reads and writes backup image using version 1 of the backup 
+  /*
+    This code reads and writes backup image using version 1 of the backup
     image format.
-   */ 
-  version= 1; 
+   */
+  version= 1;
 
   /*
     The arithmetic below assumes that MYSQL_VERSION_ID digits are arranged
     as follows: HLLRR where
-    H - major version number
-    L - minor version number
-    R - release
+    H - major version number,
+    L - minor version number,
+    R - release.
   */
   DBUG_PRINT("backup",("version %d", MYSQL_VERSION_ID));
   server_version.major= MYSQL_VERSION_ID / 10000;
@@ -60,15 +59,16 @@ Image_info::Image_info() :
   bzero(&master_binlog_info, sizeof(master_binlog_info));
 }
 
+
 Image_info::~Image_info()
 {
-  /* 
+  /*
     We need to explicitly call destructors for all objects in the catalogue
     since they are allocated using mem_root and thus destructors will not be
     invoked when the mem_root is freed.
   */
 
-  // first tablespaces
+  // First table spaces.
 
   Ts_iterator tsit(*this);
   Ts *ts;
@@ -79,11 +79,11 @@ Image_info::~Image_info()
   Db_iterator dbit(*this);
   Db *db;
 
-  // then databases and all objects inside each database
+  // Then databases and all objects inside each database.
 
   while ((db= static_cast<Db*>(dbit++)))
   {
-    // iterate over objects in the database
+    // Iterate over objects in the database.
 
     Dbobj_iterator it(*this,*db);
     Obj *o;
@@ -91,105 +91,111 @@ Image_info::~Image_info()
     while ((o= it++))
       o->~Obj();
 
-    db->~Db(); 
+    db->~Db();
   }
 
-  free_root(&mem_root, MYF(0)); 
+  free_root(&mem_root, MYF(0));
 }
 
+
 /**
   Add database to the catalogue.
 
   @param[in] db_name  name of the database
   @param[in] pos      position at which this database should be stored
 
-  @returns Pointer to @c Image_info::Db instance storing information 
+  @returns Pointer to @c Image_info::Db instance storing information
   about the database or NULL in case of error.
 
   @see @c get_db().
- */
-Image_info::Db* 
+*/
+
+Image_info::Db*
 Image_info::add_db(const String &db_name, uint pos)
 {
   Db *db= new (&mem_root) Db(db_name);
-  
+
   if (!db)
     return NULL;
-  
-  // call destructor if position is occupied
+
+  // Call destructor if position is occupied.
   if (m_dbs[pos])
     m_dbs[pos]->~Db();
 
   if (m_dbs.insert(pos, db))
     return NULL;
-  
+
   db->base.pos= pos;
-  
+
   return db;
 }
 
+
 /**
   Add tablespace to the catalogue.
 
   @param[in] ts_name  name of the tablespace
   @param[in] pos      position at which this database should be stored
 
-  @returns Pointer to @c Image_info::Ts instance storing information 
+  @returns Pointer to @c Image_info::Ts instance storing information
   about the tablespace or NULL in case of error.
 
   @see @c get_ts().
- */
-Image_info::Ts* 
+*/
+
+Image_info::Ts*
 Image_info::add_ts(const String &ts_name, uint pos)
 {
   Ts *ts= new (&mem_root) Ts(ts_name);
-  
+
   if (!ts)
     return NULL;
-  
-  // call destructor if position is occupied
+
+  // Call destructor if position is occupied.
   if (m_ts_map[pos])
     m_ts_map[pos]->~Ts();
 
   if (m_ts_map.insert(pos, ts))
     return NULL;
-  
+
   ts->base.pos= pos;
-  
+
   return ts;
 }
 
+
 /**
   Add snapshot to the catalogue.
-  
+
   The snapshot should be non-empty, that is contain data of at least one table.
   Snapshot is added to the list of snapshots used in the image and a number is
   assigned to it. This number is stored in @c snap.m_num. If snapshot's number
-  is @c n then pointer to a corresponding @c Snapshot_info object is stored in 
+  is @c n then pointer to a corresponding @c Snapshot_info object is stored in
   @c m_snap[n-1].
-  
+
   The @c Snapshot_info object is not owned by @c Image_info instance - it must
   be deleted externally.
 
   @returns Snapshot's number or -1 in case of error.
- */ 
+*/
+
 int Image_info::add_snapshot(Snapshot_info &snap)
 {
   uint num= st_bstream_image_header::snap_count++;
 
   if (num > MAX_SNAP_COUNT)
     return -1;
-  
+
   m_snap[num]= &snap;
   snap.m_num= num + 1;
-  
-  /* 
+
+  /*
     Store information about snapshot in the snapshot[] table for the
     backup stream library
-   */
+  */
 
   st_bstream_snapshot_info &info= snapshot[num];
-  
+
   bzero(&info, sizeof(st_bstream_snapshot_info));
   info.type= enum_bstream_snapshot_type(snap.type());
   info.version= snap.version();
@@ -198,19 +204,19 @@ int Image_info::add_snapshot(Snapshot_in
     Native_snapshot &ns= static_cast<Native_snapshot&>(snap);
     uint se_ver= ns.se_ver();
     const char *se_name= ns.se_name();
-    
+
     info.engine.major= se_ver >> 8;
     info.engine.minor= se_ver & 0xFF;
     info.engine.name.begin= (byte*)se_name;
-    info.engine.name.end= info.engine.name.begin + strlen(se_name);    
+    info.engine.name.end= info.engine.name.begin + strlen(se_name);
   }
-  
+
   return num + 1;
 }
 
-/**
-  Check if catalogue contains given database.
- */ 
+
+///  Check if catalogue contains given database.
+
 bool Image_info::has_db(const String &db_name) const
 {
   for (uint n=0; n < m_dbs.count() ; ++n)
@@ -220,7 +226,8 @@ bool Image_info::has_db(const String &db
   return FALSE;
 }
 
-/** 
+
+/**
   Add per database object to the catalogue.
 
   @param[in]  db  database to which this object belongs - this database must
@@ -230,42 +237,45 @@ bool Image_info::has_db(const String &db
   @param[in] pos  position where the object will be stored inside database's
                   object list
 
-  @returns Pointer to @c Image_info::Dbobj instance storing information 
+  @returns Pointer to @c Image_info::Dbobj instance storing information
   about the object or NULL in case of error.
 
   @note There is a specialized method @c add_table() for adding tables.
 
   @see @c get_db_object().
- */
+*/
+
 Image_info::Dbobj* Image_info::add_db_object(Db &db,
                                              const enum_bstream_item_type type,
                                              const ::String &name, ulong pos)
 {
-  Dbobj *o= new (&mem_root) Dbobj(db, type, name);
+  Dbobj *obj= new (&mem_root) Dbobj(db, type, name);
 
-  if (!o)
-    return NULL;  
-  
-  if (db.add_obj(*o, pos))
+  if (!obj)
     return NULL;
-    
-  o->base.pos= pos;
+
+  if (db.add_obj(*obj, pos))
+    return NULL;
+
+  obj->base.pos= pos;
   count_object(type);
 
-  return o;
+  return obj;
 }
 
+
 /**
   Return per database object stored in catalogue.
 
   This method is used only for non-table objects.
 
-  @param[in]  db_num  position of object's database in the catalogue 
+  @param[in]  db_num  position of object's database in the catalogue
   @param[in]  pos     position of the object inside the database
 
-  @returns Pointer to @c Image_info::Dbobj instance storing information 
+  @returns Pointer to @c Image_info::Dbobj instance storing information
   about the object or NULL if there is no object with given coordinates.
- */
+*/
+
 Image_info::Dbobj* Image_info::get_db_object(uint db_num, ulong pos) const
 {
   Db *db= get_db(db_num);
@@ -276,38 +286,40 @@ Image_info::Dbobj* Image_info::get_db_ob
   return db->get_obj(pos);
 }
 
+
 /**
   Add table to the catalogue.
 
-  @param[in] db   table's database - this database must already be in 
+  @param[in] db   table's database - this database must already be in
                   the catalogue
   @param[in] table_name name of the table
   @param[in] snap snapshot containing table's data
   @param[in] pos  table's position within the snapshot
 
-  @returns Pointer to @c Image_info::Table instance storing information 
+  @returns Pointer to @c Image_info::Table instance storing information
   about the table or NULL in case of error.
 
   @note The snapshot is added to the catalogue if it was not there already.
 
   @see @c get_table().
 */
-Image_info::Table* 
-Image_info::add_table(Db &db, const ::String &table_name, 
+
+Image_info::Table*
+Image_info::add_table(Db &db, const ::String &table_name,
                       Snapshot_info &snap, ulong pos)
 {
-  Table *t= new (&mem_root) Table(db, table_name);
-  
-  if (!t)
+  Table *tbl= new (&mem_root) Table(db, table_name);
+
+  if (!tbl)
     return NULL;
 
-  if (snap.add_table(*t, pos))  // reports errors
+  if (snap.add_table(*tbl, pos))    // Reports errors.
     return NULL;
 
-  db.add_table(*t);                             // Never errors
+  db.add_table(*tbl);               // Never errors.
 
   if (!snap.m_num)
-    snap.m_num= add_snapshot(snap); // reports errors
+    snap.m_num= add_snapshot(snap); // Reports errors.
 
   if (!snap.m_num)
    return NULL;
@@ -316,48 +328,52 @@ Image_info::add_table(Db &db, const ::St
   st_bstream_snapshot_info &info= snapshot[snap.m_num-1];
   info.table_count= snap.table_count();
 
-  t->snap_num= snap.m_num - 1;
-  t->base.base.pos= pos;
+  tbl->snap_num= snap.m_num - 1;
+  tbl->base.base.pos= pos;
 
   count_object(BSTREAM_IT_TABLE);
 
-  return t;  
+  return tbl;
 }
 
+
 /**
   Return table stored in the catalogue.
 
   @param[in] snap_num position of table's snapshot within the catalogue
   @param[in] pos      position of the table within the snapshot
 
-  @returns Pointer to @c Image_info::Table instance storing information 
+  @returns Pointer to @c Image_info::Table instance storing information
   about the table or NULL if there is no table with given coordinates.
- */ 
-Image_info::Table* 
+*/
+
+Image_info::Table*
 Image_info::get_table(ushort snap_num, ulong pos) const
 {
   if (snap_num > snap_count() || m_snap[snap_num] == NULL)
     return NULL;
-  
-  Table *t= m_snap[snap_num]->get_table(pos);
-  
-  if (!t)
+
+  Table *tbl= m_snap[snap_num]->get_table(pos);
+
+  if (!tbl)
     return NULL;
-  
-  return t;
+
+  return tbl;
 }
 
+
 /**
   Find object in the catalogue.
-  
-  The object is identified by its coordinates stored in a 
+
+  The object is identified by its coordinates stored in a
   @c st_bstream_item_info structure. Normally these coordinates are
   filled by backup stream library when reading backup image.
-  
+
   @returns Pointer to the corresponding @c Obj instance or NULL if object
   was not found.
- */ 
-Image_info::Obj *find_obj(const Image_info &info, 
+*/
+
+Image_info::Obj *find_obj(const Image_info &info,
                           const st_bstream_item_info &item)
 {
   switch (item.type) {
@@ -370,7 +386,7 @@ Image_info::Obj *find_obj(const Image_in
 
   case BSTREAM_IT_TABLE:
   {
-    const st_bstream_table_info &ti= 
+    const st_bstream_table_info &ti=
                            reinterpret_cast<const st_bstream_table_info&>(item);
 
     return info.get_table(ti.snap_num, item.pos);
@@ -394,16 +410,17 @@ Image_info::Obj *find_obj(const Image_in
   }
 }
 
+
 void Image_info::save_master_binlog_info(const ::Master_info &mi)
 {
-  // store binlog coordinates
+  // Store binlog coordinates.
   master_binlog_info.pos=  static_cast<unsigned long int>(mi.master_log_pos);
   master_binlog_info.file= const_cast<char*>(mi.master_log_name);
 }
 
-
 } // backup namespace
 
+
 template class Map<uint, backup::Image_info::Db>;
 template class Map<uint, backup::Image_info::Ts>;
 template class Map<uint, backup::Image_info::Table>;

=== modified file 'sql/backup/image_info.h'
--- a/sql/backup/image_info.h	2009-10-12 09:08:34 +0000
+++ b/sql/backup/image_info.h	2009-10-21 13:32:24 +0000
@@ -3,20 +3,21 @@
 
 /**
   @file
-  
-*/ 
+
+  Declaration of @c Image_info and related classes.
+*/
 
 #include <si_objects.h>
-#include <backup_stream.h> // for st_bstream_* types
-#include <backup/backup_aux.h>  // for Map template
+#include <backup_stream.h>      // For st_bstream_* types.
+#include <backup/backup_aux.h>  // For Map template.
 
 /**
   @brief The maximal number of table data snapshots per backup image.
-  
+
   @note This limit is determined by the backup image format used and can
   not be changed. Currently we use version 1 of the image format in which
   one byte is used to store snapshot numbers, hence the limit is 256.
-*/ 
+*/
 #define MAX_SNAP_COUNT  256
 
 
@@ -25,14 +26,15 @@ class Backup_restore_ctx;
 namespace backup {
 
 /********************************************************************
- 
+
    Image_info and Snapshot_info classes.
- 
- ********************************************************************/ 
+
+ ********************************************************************/
 
 class Snapshot_info;
 class Logical_snapshot;
 
+
 /**
   Describes contents of a backup image.
 
@@ -44,12 +46,12 @@ class Logical_snapshot;
   stored in table data snapshots created by backup drivers.
 
   For each snapshot present in the image there is a @c Snapshot_info object.
-  A pointer to n-th snapshot object is stored in @c m_snap[n]. This object 
-  contains list of tables whose data is stored in the snapshot. Note that each 
+  A pointer to n-th snapshot object is stored in @c m_snap[n]. This object
+  contains list of tables whose data is stored in the snapshot. Note that each
   table in the catalogue must belong to exactly one snapshot.
 
-  Each object in the catalogue has its coordinates. The format of these 
-  coordinates depends on the object type. For databases, it is just its number. 
+  Each object in the catalogue has its coordinates. The format of these
+  coordinates depends on the object type. For databases, it is just its number.
   For tables, its coordinates are the number of the snapshot to which it belongs
   and position within this snapshot. There are @c get_...() methods for getting
   objects given their coordinates. Objects can be also browsed using one of
@@ -57,16 +59,17 @@ class Logical_snapshot;
 
   For each type of object stored in the catalogue, there is a class derived
   from @c Image_info::Obj, whose instances are used to keep information about
-  such objects. These instances are owned by the @c Image_info object who is 
+  such objects. These instances are owned by the @c Image_info object who is
   responsible for freeing memory used by them. Currently a memory root is used
   for allocating this memory.
- */
+*/
+
 class Image_info: public st_bstream_image_header
 {
-public: // public interface
+public: // Public interface.
+
+  // Datatypes.
 
-   // datatypes
-   
   /// The object type from the stream item.
   typedef enum_bstream_item_type obj_type;
 
@@ -76,29 +79,29 @@ public: // public interface
   class Table; ///< Class representing a table.
   class Dbobj; ///< Class representing a per-database object other than table.
 
-  class Iterator;      ///< Base for all iterators.
-  class Ts_iterator;   ///< Iterates over all tablespaces.
-  class Db_iterator;   ///< Iterates over all databases.
-  class Dbobj_iterator;  ///< Iterates over objects in a database.
+  class Iterator;       ///< Base for all iterators.
+  class Ts_iterator;    ///< Iterates over all tablespaces.
+  class Db_iterator;    ///< Iterates over all databases.
+  class Dbobj_iterator; ///< Iterates over objects in a database.
 
   virtual ~Image_info();
- 
-  // info about image (most of it is in the st_bstream_image_header base
+
+  // Info about image (most of it is in the st_bstream_image_header base).
 
   virtual bool is_valid() =0;  ///< Is the structure valid?
 
   ulonglong  data_size;      ///< How much of table data is saved in the image.
   /// To store master position info.
-  st_bstream_binlog_info  master_binlog_info; 
+  st_bstream_binlog_info  master_binlog_info;
 
-  ulong      object_count() const;
-  ulong      table_count() const;
-  ulong      view_count() const;
-  ulong      routine_count() const;
-  ulong      priv_count() const;
-  ulong      db_count() const;
-  ulong      ts_count() const;
-  ushort     snap_count() const;
+  ulong   object_count() const;
+  ulong   table_count() const;
+  ulong   view_count() const;
+  ulong   routine_count() const;
+  ulong   priv_count() const;
+  ulong   db_count() const;
+  ulong   ts_count() const;
+  ushort  snap_count() const;
 
   // Examine contents of the catalogue.
 
@@ -120,14 +123,14 @@ public: // public interface
   /**
     Pointers to @c Snapshot_info objects corresponding to the snapshots
     present in the image.
-   */ 
+  */
   Snapshot_info *m_snap[MAX_SNAP_COUNT];
-   
-  // save timing & binlog info 
-   
-  void save_start_time(const time_t time);   
+
+  // Save timing & binlog info.
+
+  void save_start_time(const time_t time);
   void save_end_time(const time_t time);
-  void save_vp_time(const time_t time);   
+  void save_vp_time(const time_t time);
 
   void save_binlog_info(const ::LOG_INFO&);
   /// Save the master's binlog position.
@@ -137,19 +140,19 @@ public: // public interface
   time_t get_vp_time()  const;
   time_t get_end_time() const;
 
-protected: // internal interface
-  
-  // Populate the catalogue
-  
+protected: // Internal interface.
+
+  // Populate the catalogue.
+
   int    add_snapshot(Snapshot_info&);
   Db*    add_db(const String &db_name, uint pos);
   Ts*    add_ts(const String &db_name, uint pos);
   Dbobj* add_db_object(Db &db, const obj_type type,
                        const ::String &name, ulong pos);
-  Table* add_table(Db &db, const ::String &table_name, 
+  Table* add_table(Db &db, const ::String &table_name,
                    Snapshot_info &snap, ulong pos);
 
- // IMPLEMENTATION
+  // IMPLEMENTATION
 
 protected:
 
@@ -159,46 +162,48 @@ protected:
   ulong m_routine_count;  ///< Number of stored routines in the image
   ulong m_priv_count;     ///< Number of privileges in the image
 
-  MEM_ROOT  mem_root;    ///< Memory root for storage of catalogue items.
+  MEM_ROOT  mem_root;     ///< Memory root for storage of catalogue items.
 
-  class Tables; ///< Implementation of Table_list interface. 
+  class Tables; ///< Implementation of Table_list interface.
 
-  /// Increase counter for this object type
+  /// Increase counter for this object type.
   void count_object(const enum_bstream_item_type type);
 
 private:
 
-  Map<uint, Db>   m_dbs; ///< Pointers to Db instances.
+  Map<uint, Db>   m_dbs;    ///< Pointers to Db instances.
   Map<uint, Ts>   m_ts_map; ///< Pointers to Ts instances.
-  String    m_binlog_file; ///< To store binlog file name at VP time.
+  String    m_binlog_file;  ///< To store binlog file name at VP time.
 
-  // friends
+  // Friends.
 
   friend class Snapshot_info;
-  friend class backup::Logical_snapshot; // needs access to Tables class
+  friend class backup::Logical_snapshot; // Needs access to Tables class.
 };
 
-Image_info::Obj* find_obj(const Image_info &info, 
+
+Image_info::Obj* find_obj(const Image_info &info,
                           const st_bstream_item_info &item);
 
 
 /**
   Implements Table_list interface.
-  
+
   When list of tables is passed to a backup/restore driver, it is seen
   by the driver as an object of abstract type Table_list. This class implements
   that interface using a map, which for given table number returns a pointer
   to corresponding @c Image_info::Table instance.
-  
-  @note This class is not a container - it only stores pointers to 
+
+  @note This class is not a container - it only stores pointers to
   @c Image_info::Table objects which are owned by the @c Image_info instance.
- */ 
+*/
+
 class Image_info::Tables:
   public Table_list,
   public Map<uint, Image_info::Table>
 {
   typedef Map<uint, Image_info::Table> Base;
- 
+
 public:
 
   Tables(ulong, ulong);
@@ -207,18 +212,20 @@ public:
   Image_info::Table* get_table(ulong) const;
 };
 
+
 /**
   Create instance of @c Image_info::Tables class.
-  
+
   The parameters determine how memory is allocated.
-  
+
   @param[in] init_size  the initial number of slots
   @param[in] increase   the amount by which allocated memory is increased
                         when the current capacity is exceeded
- */ 
+*/
+
 inline
 Image_info::Tables::Tables(ulong init_size, ulong increase)
-  :Base(init_size, increase) 
+  :Base(init_size, increase)
 {}
 
 
@@ -227,33 +234,34 @@ Image_info::Tables::Tables(ulong init_si
 
   Such snapshot is created by a backup driver and read by a restore driver. For
   each type of snapshot a separate class is derived from @c Snapshot_info.
-  Currently we support 
-  
+  Currently we support
+
   - native snapshots (created by native backup engines),
   - CS snapshot      (created by built-in backup engine using consistent read),
   - default snapshot (created by built-in default backup engine).
-  
+
   A @c Snapshot_info instance stores the list of tables whose data are stored
-  in the snapshot. It also has methods for determining whether a given table 
-  can be added to the snapshot or not, and for creating backup/restore drivers 
+  in the snapshot. It also has methods for determining whether a given table
+  can be added to the snapshot or not, and for creating backup/restore drivers
   for processing the snapshot.
- */
+*/
+
 class Snapshot_info
 {
 public:
 
-  /// Enumeration for snapshot type
+  /// Enumeration for snapshot type.
   enum enum_snap_type {
-    NATIVE_SNAPSHOT= BI_NATIVE,   ///< created by native backup engine.
-    DEFAULT_SNAPSHOT= BI_DEFAULT, ///< created by blocking backup engine.
-    CS_SNAPSHOT= BI_CS,           ///< created by CS backup engine.
-    NODATA_SNAPSHOT= BI_NODATA    ///< created by No data backup engine.
+    NATIVE_SNAPSHOT= BI_NATIVE,   ///< Created by native backup engine.
+    DEFAULT_SNAPSHOT= BI_DEFAULT, ///< Created by blocking backup engine.
+    CS_SNAPSHOT= BI_CS,           ///< Created by CS backup engine.
+    NODATA_SNAPSHOT= BI_NODATA    ///< Created by No data backup engine.
   };
 
-  /// Enumeration for snapshot type type
-  virtual enum_snap_type type() const =0; 
+  /// Enumeration for snapshot type type.
+  virtual enum_snap_type type() const =0;
   version_t version() const; ///< Returns version of snapshot's format.
-  
+
   /**
     Position inside image's snapshot list.
 
@@ -272,15 +280,18 @@ public:
     Return name identifying the snapshot in debug messages.
 
     The name should fit into "%s backup/restore driver" pattern.
-   */
+  */
   virtual const char* name() const =0;
-               
-  /// Check if instance was correctly constructed
+
+  /// Check if instance was correctly constructed.
   virtual bool is_valid() =0;
 
   ulong table_count() const;
-  
-  /// Determine if a table using given storage engine can be saved in this image.
+
+  /**
+    Determine if a table using given storage engine can be saved in this
+    image.
+  */
   virtual bool accept(const Table_ref&, const storage_engine_ref) =0;
 
   /// Create backup driver for the image.
@@ -289,16 +300,16 @@ public:
   /// Create restore driver for the image.
   virtual result_t get_restore_driver(Restore_driver*&) =0;
 
-  /// Destructor
+  /// Destructor.
   virtual ~Snapshot_info();
 
   Image_info::Table* get_table(ulong pos) const;
 
 protected:
- 
+
   version_t m_version; ///< Stores version number of the snapshot's format.
 
-  /// Constructor
+  /// Constructor.
   Snapshot_info(const version_t);
 
   // Methods for adding and accessing tables stored in the table list.
@@ -306,7 +317,7 @@ protected:
   int add_table(Image_info::Table &t, ulong pos);
 
   // IMPLEMENTATION
- 
+
   Image_info::Tables m_tables; ///< List of tables stored in this image.
 
   friend class Image_info;
@@ -314,19 +325,21 @@ protected:
 
 
 inline
-Snapshot_info::Snapshot_info(const version_t version) 
+Snapshot_info::Snapshot_info(const version_t version)
   :m_num(0), init_size(0), m_version(version), m_tables(128, 1024)
 {}
 
+
 inline
 Snapshot_info::~Snapshot_info()
 {}
 
+
 /********************************************************************
- 
+
    Classes for representing various object types.
- 
- ********************************************************************/ 
+
+ ********************************************************************/
 
 /**
   Represents object stored in a backup image.
@@ -335,34 +348,35 @@ Snapshot_info::~Snapshot_info()
   an object. For each type of object a subclass of this class is derived
   which is specialized in storing information specific to that kind of object.
 
-  Method @c info() returns a pointer to @c st_bstream_item_info structure 
+  Method @c info() returns a pointer to @c st_bstream_item_info structure
   filled with data describing the corresponding object in the way required by
   backup stream library.
-  
+
   Method @c materialize() can be used to create a corresponding instance of
   @c obs::Obj, to be used by server's objects services API. If @c m_obj_ptr is
   not NULL then it contains a pointer to the corresponding @c obs::Obj instance
-  which was obtained earlier (either with @c materialize() or from server's 
-  object iterators). The @c Obj instance owns the server object and is 
+  which was obtained earlier (either with @c materialize() or from server's
+  object iterators). The @c Obj instance owns the server object and is
   responsible for deleting it.
 */
+
 class Image_info::Obj: public Sql_alloc
 {
 public:
- 
-  /* 
+
+  /*
     Note: Since we are using Sql_alloc and allocate instances using MEM_ROOT,
     destructors will not be called! This is also true for derived classes.
-   */
+  */
   virtual ~Obj();
 
-  /// The type of the object
+  /// The type of the object.
   obj_type type() const;
 
   /**
     Returns pointer to @c st_bstream_item_info structure filled with data about
     the object.
-   */ 
+  */
   virtual const st_bstream_item_info* info() const =0;
 
   /// Pointer to the corresponding @c obs::Obj instance, if it is known.
@@ -381,17 +395,19 @@ protected:
 
   String m_name;  ///< For storing object's name.
 
-  void store_name(const String&); 
+  void store_name(const String&);
 
   Obj();
 
   friend class Image_info;
 };
 
+
 inline
 Image_info::Obj::Obj() :m_obj_ptr(NULL)
 {}
 
+
 inline
 Image_info::Obj::~Obj()
 {
@@ -400,16 +416,15 @@ Image_info::Obj::~Obj()
 }
 
 
-/**
-  Specialization of @c Image_info::Obj for storing info about a tablespace.
-*/
+/// Specialization of @c Image_info::Obj for storing info about a tablespace.
+
 class Image_info::Ts
  : public st_bstream_ts_info,
    public Image_info::Obj
 {
 public:
 
-  /// Constructor
+  /// Constructor.
   Ts(const ::String&);
 
   /// The information about the image.
@@ -421,6 +436,7 @@ public:
   const char* describe(describe_buf&) const;
 };
 
+
 inline
 Image_info::Ts::Ts(const ::String &name)
 {
@@ -430,9 +446,8 @@ Image_info::Ts::Ts(const ::String &name)
 }
 
 
-/**
-  Specialization of @c Image_info::Obj for storing info about a database.
-*/
+/// Specialization of @c Image_info::Obj for storing info about a database.
+
 class Image_info::Db
  : public st_bstream_db_info,
    public Image_info::Obj,
@@ -442,7 +457,7 @@ class Image_info::Db
 
 public:
 
-  /// Constuctor
+  /// Constuctor.
   Db(const ::String&);
 
   const st_bstream_item_info* info() const;
@@ -457,20 +472,21 @@ public:
   const char* describe(describe_buf&) const;
 
 private:
- 
-  Table *first_table; ///< Pointer to the first table in database's table list. 
+
+  Table *first_table; ///< Pointer to the first table in database's table list.
   Table *last_table;  ///< Pointer to the last table in database's table list.
 
   /**
     For n-th object in this databse, @c m_objs[n] is a pointer to the
     corresponding Dbobj instance.
-   */ 
+  */
   Map<ulong, Dbobj> m_objs;
 
   friend class Dbobj_iterator;
   friend class Perdb_iterator;
 };
 
+
 inline
 Image_info::Db::Db(const ::String &name)
  :Db_ref(Image_info::Obj::m_name),
@@ -488,6 +504,7 @@ Image_info::Db::Db(const ::String &name)
 
   @note For tables, there is dedicated class @c Image_info::Table.
 */
+
 class Image_info::Dbobj
   : public st_bstream_dbitem_info,
     public Image_info::Obj,
@@ -497,7 +514,7 @@ class Image_info::Dbobj
 
 public:
 
-  /// Constructor
+  /// Constructor.
   Dbobj(const Db &db, const obj_type type, const ::String &name);
 
   const st_bstream_item_info* info() const;
@@ -509,6 +526,7 @@ public:
   friend class Dbobj_iterator;
 };
 
+
 inline
 Image_info::Dbobj::Dbobj(const Db &db, const obj_type type,
                          const ::String &name)
@@ -521,21 +539,20 @@ Image_info::Dbobj::Dbobj(const Db &db, c
 }
 
 
-/**
-  Specialization of @c Image_info::Obj for storing info about a table.
-*/
+/// Specialization of @c Image_info::Obj for storing info about a table.
+
 class Image_info::Table
  : public st_bstream_table_info,
    public Image_info::Obj,
    public Table_ref
 {
-  const Db &m_db;     ///< The database to which this table belongs.
-  Table  *next_table; ///< Used to crate a linked list of tables in a database.
+  const Db &m_db;      ///< The database to which this table belongs.
+  Table  *next_table;  ///< Used to crate a linked list of tables in a database.
   TABLE_LIST  *m_table; ///< If not NULL, points at opened table.
 
 public:
 
-  /// Constructor
+  /// Constructor.
   Table(const Db &db, const ::String &name);
 
   const st_bstream_item_info* info() const;
@@ -545,10 +562,11 @@ public:
 
   friend class Db;
   friend class Dbobj_iterator;
-  friend class Logical_snapshot;     // reads m_table
-  friend class ::Backup_restore_ctx; // sets m_table
+  friend class Logical_snapshot;     // Reads m_table.
+  friend class ::Backup_restore_ctx; // Sets m_table.
 };
 
+
 inline
 Image_info::Table::Table(const Db &db, const ::String &name)
   :Table_ref(db.name(), Image_info::Obj::m_name), m_db(db), next_table(NULL),
@@ -563,19 +581,19 @@ Image_info::Table::Table(const Db &db, c
 
 
 /********************************************************************
- 
+
    Iterators
- 
- ********************************************************************/ 
+
+ ********************************************************************/
 
 /**
   Base class for all iterators.
-  
+
   An iterator is used as follows
   @code
   Iterator_X      it;
   Image_info::Obj *obj;
-  
+
   while ((obj= it++))
   {
     <do something with obj>
@@ -584,23 +602,24 @@ Image_info::Table::Table(const Db &db, c
 
   This is an abstract class. Derived iterators must define @c get_ptr() and
   @c next() methods which are used to implement @c operator++().
- */ 
+*/
+
 class Image_info::Iterator
 {
 public:
 
-  /// Constructor
+  /// Constructor.
   Iterator(const Image_info &info);
   virtual ~Iterator();
 
-  
-  /** 
+
+  /**
     Initialize the iterator after construction.
     Subclasses need to implement this if initialization may generate errors.
-   
+
     @returns 0 if success.  Otherwise, error code.
-   */
-  virtual int init() { return 0; }  
+  */
+  virtual int init() { return 0; }
 
   /// The increment operation.
   Obj* operator++(int);
@@ -612,53 +631,57 @@ protected:
 
 private:
 
-  /** 
+  /**
     Return pointer to the current object of the iterator.
-   
+
     Returns NULL if iterator is past the last object in the sequence.
-   */
+  */
   virtual Obj* get_ptr() const =0;
-  
-  /** 
+
+  /**
     Move iterator to next object.
-   
+
     Returns FALSE if there are no more objects to enumerate.
-   */
+  */
   virtual bool next() =0;
 };
 
+
 inline
-Image_info::Iterator::Iterator(const Image_info &info) :m_info(info) 
+Image_info::Iterator::Iterator(const Image_info &info) :m_info(info)
 {}
 
+
 inline
-Image_info::Iterator::~Iterator() 
+Image_info::Iterator::~Iterator()
 {}
 
 
 /**
   Used to iterate over all tablespaces stored in a backup image.
 
-  @note Backup stream library infers position of each tablespace in the catalogue
-  from the order in which they are enumerated by this iterator. Therefore it
-  is important that tablespaces are listed in correct order - first tablespace 
-  at position 0, then at position 1 and so on.
- */ 
+  @note Backup stream library infers position of each tablespace in
+  the catalogue from the order in which they are enumerated by this iterator.
+  Therefore it is important that tablespaces are listed in correct order
+  - first tablespace at position 0, then at position 1 and so on.
+*/
+
 class Image_info::Ts_iterator
  : public Image_info::Iterator
 {
 public:
 
-  /// Constructor  
+  /// Constructor.
   Ts_iterator(const Image_info&);
 
 protected:
 
-  uint pos;              ///< position in the iterator
-  Obj* get_ptr() const;  
+  uint pos;              ///< Position in the iterator.
+  Obj* get_ptr() const;
   bool next();
 };
 
+
 inline
 Image_info::Ts_iterator::Ts_iterator(const Image_info &info)
   :Iterator(info), pos(0)
@@ -672,22 +695,24 @@ Image_info::Ts_iterator::Ts_iterator(con
   from the order in which they are enumerated by this iterator. Therefore it
   is important that databases are listed in correct order - first database at
   position 0, then at position 1 and so on.
- */ 
+*/
+
 class Image_info::Db_iterator
  : public Image_info::Iterator
 {
 public:
 
-  /// Constructor
+  /// Constructor.
   Db_iterator(const Image_info&);
 
 protected:
 
-  uint pos;  ///< Position in the iterator
+  uint pos;  ///< Position in the iterator.
   Obj* get_ptr() const;
   bool next();
 };
 
+
 inline
 Image_info::Db_iterator::Db_iterator(const Image_info &info)
   :Iterator(info), pos(0)
@@ -702,17 +727,18 @@ Image_info::Db_iterator::Db_iterator(con
   Therefore it is important that objects are listed in correct order - first
   all tables should be listed, then the non-table object stored at position 0,
   then at position 1 and so on.
- */
+*/
+
 class Image_info::Dbobj_iterator
  : public Image_info::Db_iterator
 {
-  const Db    &m_db;
-  Table *ptr;
-  ulong pos;
+  const Db  &m_db;
+  Table     *ptr;
+  ulong     pos;
 
 public:
 
-  /// Constructor
+  /// Constructor.
   Dbobj_iterator(const Image_info&, const Db&);
 
 private:
@@ -721,18 +747,18 @@ private:
   bool next();
 };
 
+
 inline
 Image_info::Dbobj_iterator::Dbobj_iterator(const Image_info &info, const Db &db)
  :Db_iterator(info), m_db(db), ptr(db.first_table), pos(0)
 {}
 
 
-
 /********************************************************************
- 
-   Inline members of Image_info class 
- 
- ********************************************************************/ 
+
+   Inline members of Image_info class
+
+ ********************************************************************/
 
 /**
    Increase counter for this type of object. This is displayed as info
@@ -740,47 +766,54 @@ Image_info::Dbobj_iterator::Dbobj_iterat
 
    @param[in] type type of the object
 */
+
 inline
 void Image_info::count_object(const enum_bstream_item_type type)
 {
 
   switch (type) {
 
-    case BSTREAM_IT_TABLE: 
-      m_table_count++;
-      break;
-    case BSTREAM_IT_VIEW: 
-      m_view_count++; 
-      break;
-    case BSTREAM_IT_SPROC: 
-    case BSTREAM_IT_SFUNC: 
-    case BSTREAM_IT_EVENT: 
-    case BSTREAM_IT_TRIGGER:
-      m_routine_count++;
-      break;
-    case BSTREAM_IT_PRIVILEGE: 
-      m_priv_count++;
-      break;
-                                  // ITEMS THAT ARE NOT COUNTED
-    case BSTREAM_IT_DB:           // counted via m_dbs.count()
-    case BSTREAM_IT_TABLESPACE:   // counted via m_ts_map.count()
-    case BSTREAM_IT_CHARSET:      // not counted yet
-    case BSTREAM_IT_USER:         // not counted yet
-      break;
-    default: 
-      // Fail if an item type is is not counted or ignored above. All
-      // item types should be explicitly handled by the switch
-      DBUG_ASSERT(FALSE);  
+  case BSTREAM_IT_TABLE:
+    m_table_count++;
+    break;
+
+  case BSTREAM_IT_VIEW:
+    m_view_count++;
+    break;
+
+  case BSTREAM_IT_SPROC:
+  case BSTREAM_IT_SFUNC:
+  case BSTREAM_IT_EVENT:
+  case BSTREAM_IT_TRIGGER:
+    m_routine_count++;
+    break;
+
+  case BSTREAM_IT_PRIVILEGE:
+    m_priv_count++;
+    break;
+                                // ITEMS THAT ARE NOT COUNTED
+  case BSTREAM_IT_DB:           // Counted via m_dbs.count().
+  case BSTREAM_IT_TABLESPACE:   // Counted via m_ts_map.count().
+  case BSTREAM_IT_CHARSET:      // Not counted yet.
+  case BSTREAM_IT_USER:         // Not counted yet.
+    break;
+
+  default:
+    // Fail if an item type is is not counted or ignored above. All
+    // item types should be explicitly handled by the switch.
+    DBUG_ASSERT(FALSE);
   }
 }
 
+
 /**
    Get number of named objects (ts, db, table, view, routines) in the
    image.
 */
+
 inline
 ulong Image_info::object_count() const
-{ 
+{
   return (db_count() +
 	  ts_count() +
 	  table_count() +
@@ -788,52 +821,66 @@ ulong Image_info::object_count() const
 	  routine_count());
 }
 
+
 /// Returns number of routines in the image.
+
 inline
 ulong Image_info::routine_count() const
-{ 
+{
   return m_routine_count;
 }
 
+
 /// Returns number of databases in the image.
+
 inline
 ulong Image_info::db_count() const
-{ 
+{
   return m_dbs.count();
 }
 
+
 /// Returns number of tablespaces in the image.
+
 inline
 ulong Image_info::ts_count() const
-{ 
+{
   return m_ts_map.count();
 }
 
+
 /// Returns total number of tables in the image.
+
 inline
 ulong Image_info::table_count() const
-{ 
+{
   return m_table_count;
 }
 
+
 /// Returns total number of views in the image.
+
 inline
 ulong Image_info::view_count() const
-{ 
+{
   return m_view_count;
 }
 
+
 /// Returns total number of privileges in the image.
+
 inline
 ulong Image_info::priv_count() const
-{ 
+{
   return m_priv_count;
 }
 
+
 /// Returns number of snapshots used by the image.
+
 inline
 ushort Image_info::snap_count() const
-{ 
+{
   return st_bstream_image_header::snap_count;
 }
 
@@ -841,37 +888,42 @@ ushort Image_info::snap_count() const
 /**
   Return database stored in the catalogue.
 
-  @param[in]  pos positon of the database in the catalogue
+  @param[in]  pos position of the database in the catalogue
 
-  @returns Pointer to @c Image_info::Db instance storing information 
+  @returns Pointer to @c Image_info::Db instance storing information
   about the database or NULL if no database is stored at given position.
- */ 
+*/
+
 inline
 Image_info::Db* Image_info::get_db(uint pos) const
 {
   return m_dbs[pos];
 }
 
+
 /**
   Return tablespace stored in the catalogue.
 
   @param[in]  pos positon of the tablespace in the catalogue
 
-  @returns Pointer to @c Image_info::Ts instance storing information 
+  @returns Pointer to @c Image_info::Ts instance storing information
   about the tablespace or NULL if no tablespace is stored at given position.
- */ 
+*/
+
 inline
 Image_info::Ts* Image_info::get_ts(uint pos) const
 {
   return m_ts_map[pos];
 }
 
+
 inline
 time_t Image_info::get_vp_time() const
 {
   return vp_time;
 }
 
+
 inline
 time_t Image_info::get_end_time() const
 {
@@ -879,147 +931,162 @@ time_t Image_info::get_end_time() const
 }
 
 
-/**
-  Store backup/restore start time inside image's header.
- */ 
+/// Store backup/restore start time inside image's header.
+
 inline
 void Image_info::save_start_time(const time_t time)
 {
   start_time= time;
 }
 
-/**
-  Store backup/restore end time inside image's header.
- */ 
+
+/// Store backup/restore end time inside image's header.
+
 inline
 void Image_info::save_end_time(const time_t time)
 {
   end_time= time;
 }
 
-/**
-  Store validity point time inside image's header.
- */ 
+
+/// Store validity point time inside image's header.
+
 inline
 void Image_info::save_vp_time(const time_t time)
 {
   vp_time= time;
 }
 
+
 /**
   Store validity point binlog position inside image's header. Also sets
   BSTREAM_FLAG_BINLOG in @c flags bitmap to indicate that this
   backup image contains a valid binlog position.
- */ 
+*/
+
 inline
 void Image_info::save_binlog_info(const ::LOG_INFO &li)
 {
-  // save current binlog file name only, not full path
+  // Save current binlog file name only, not full path.
   m_binlog_file.length(0);
   size_t dn_length= dirname_length(li.log_file_name);
   m_binlog_file.append(li.log_file_name + dn_length);
 
-  // store binlog coordinates
+  // Store binlog coordinates.
   binlog_info.pos= (unsigned long int)li.pos;
   binlog_info.file= const_cast<char*>(m_binlog_file.ptr());
 
-  // make flags bitmap reflect that this backup image contains a valid
-  // binlog position
+  // Make flags bitmap reflect that this backup image contains a valid
+  // binlog position.
   flags|= BSTREAM_FLAG_BINLOG;
 }
 
+
 /**
   Returns an iterator enumerating all databases stored in backup catalogue.
 
   @returns Pointer to @c Image_info::Db_iterator or NULL if allocation fails.
- */ 
+*/
+
 inline
 Image_info::Db_iterator* Image_info::get_dbs() const
 {
   Db_iterator* it = new Db_iterator(*this);
 
-  if (it && it->init()) // Initialization failed
+  if (it && it->init()) // Initialization failed.
     it= NULL;
 
-  return it; // Error logging context not available, caller must handle NULL
+  return it; // Error logging context not available, caller must handle NULL.
 }
 
+
 /**
   Returns an iterator enumerating all tablespaces stored in backup catalogue.
 
   @returns Pointer to @c Image_info::Ts_iterator or NULL if allocation fails.
- */
+*/
+
 inline
 Image_info::Ts_iterator* Image_info::get_tablespaces() const
 {
   Ts_iterator* it = new Ts_iterator(*this);
 
-  if (it && it->init()) // Initialization failed
+  if (it && it->init()) // Initialization failed.
     it= NULL;
 
-  return it; // Error logging context not available, caller must handle NULL
+  return it; // Error logging context not available, caller must handle NULL.
 }
 
+
 /**
   Returns an iterator enumerating all objects in a given database.
 
   @returns Pointer to @c Image_info::Dbobj_iterator or NULL if allocation fails.
- */
+*/
+
 inline
 Image_info::Dbobj_iterator* Image_info::get_db_objects(const Db &db) const
 {
   Dbobj_iterator* it = new Dbobj_iterator(*this, db);
 
-  if (it && it->init()) // Initialization failed
+  if (it && it->init()) // Initialization failed.
     it= NULL;
 
-  return it; // Error logging context not available, caller must handle NULL
+  return it; // Error logging context not available, caller must handle NULL.
 }
 
+
 /********************************************************************
- 
+
    Inline members of Image_info::Tables class.
- 
- ********************************************************************/ 
+
+ ********************************************************************/
 
 /// Return number of tables in the list.
+
 inline
 ulong Image_info::Tables::count() const
 { return Base::count(); }
 
-/** 
+
+/**
   Return table stored at a given position.
- 
+
   @returns pointer to the @c Image_info::Table instance stored at
   position @c pos or NULL if that position is empty.
- */
+*/
+
 inline
 Image_info::Table* Image_info::Tables::get_table(ulong pos) const
-{ 
+{
   return Base::operator[](pos);
-} 
+}
+
 
 /// Implementation of @c Table_list virtual method.
+
 inline
 Table_ref Image_info::Tables::operator[](ulong pos) const
-{ 
+{
   Table *t= get_table(pos);
   DBUG_ASSERT(t);
-  return *t; 
+  return *t;
 }
 
+
 /********************************************************************
- 
+
    Inline members of Image_info::Obj and derived classes.
- 
- ********************************************************************/ 
+
+ ********************************************************************/
 
 /**
   Store objects name inside the object.
-  
+
   The name is also stored inside the corresponding @c st_bstream_item_info
   structure (just pointer).
- */ 
+ */
+
 inline
 void Image_info::Obj::store_name(const String &name)
 {
@@ -1029,6 +1096,7 @@ void Image_info::Obj::store_name(const S
   info->name.end= info->name.begin + name.length();
 }
 
+
 inline
 Image_info::obj_type  Image_info::Obj::type() const
 {
@@ -1037,44 +1105,54 @@ Image_info::obj_type  Image_info::Obj::t
 
 
 /// Implementation of @c Image_info::Obj virtual method.
+
 inline
-const st_bstream_item_info* Image_info::Db::info() const 
+const st_bstream_item_info* Image_info::Db::info() const
 {
-  return &base; 
+  return &base;
 }
 
+
 inline
-const st_bstream_db_info* Image_info::Db::db_info() const 
+const st_bstream_db_info* Image_info::Db::db_info() const
 {
-  return this; 
+  return this;
 }
 
+
 /// Implementation of @c Image_info::Obj virtual method.
+
 inline
-const st_bstream_item_info* Image_info::Ts::info() const 
+const st_bstream_item_info* Image_info::Ts::info() const
 {
-  return &base; 
+  return &base;
 }
 
+
 /// Implementation of Image_info::ts_info virtual method.
+
 inline
-const st_bstream_ts_info* Image_info::Ts::ts_info() const 
+const st_bstream_ts_info* Image_info::Ts::ts_info() const
 {
-  return this; 
+  return this;
 }
 
+
 /// Implementation of @c Image_info::Obj virtual method.
+
 inline
-const st_bstream_item_info* Image_info::Table::info() const 
+const st_bstream_item_info* Image_info::Table::info() const
 {
-  return &base.base; 
+  return &base.base;
 }
 
+
 /// Implementation of @c Image_info::Obj virtual method.
+
 inline
-const st_bstream_item_info* Image_info::Dbobj::info() const 
+const st_bstream_item_info* Image_info::Dbobj::info() const
 {
-  return &base; 
+  return &base;
 }
 
 
@@ -1083,6 +1161,7 @@ const st_bstream_item_info* Image_info::
 
   @param[in] buf  The buffer for the desciption info.
 */
+
 inline
 const char* Image_info::Ts::describe(describe_buf &buf) const
 {
@@ -1090,7 +1169,9 @@ const char* Image_info::Ts::describe(des
   return buf;
 }
 
+
 /// Implementation of @c Image_info::Obj virtual method.
+
 inline
 const char* Image_info::Db::describe(describe_buf &buf) const
 {
@@ -1098,14 +1179,18 @@ const char* Image_info::Db::describe(des
   return buf;
 }
 
+
 /// Implementation of @c Image_info::Obj virtual method.
+
 inline
 const char* Image_info::Table::describe(Obj::describe_buf &buf) const
 {
   return Table_ref::describe(buf);
 }
 
+
 /// Implementation of @c Image_info::Obj virtual method.
+
 inline
 const char* Image_info::Dbobj::describe(Obj::describe_buf &buf) const
 {
@@ -1114,22 +1199,27 @@ const char* Image_info::Dbobj::describe(
 
 
 /// Implementation of @c Image_info::Obj virtual method.
+
 inline
 obs::Obj* Image_info::Ts::materialize(uint ver, const ::String &sdata)
 {
   delete m_obj_ptr;
-  return m_obj_ptr= obs::get_tablespace(&m_name, ver, &sdata); 
+  return m_obj_ptr= obs::get_tablespace(&m_name, ver, &sdata);
 }
 
+
 /// Implementation of @c Image_info::Obj virtual method.
+
 inline
 obs::Obj* Image_info::Db::materialize(uint ver, const ::String &sdata)
 {
   delete m_obj_ptr;
-  return m_obj_ptr= obs::get_database(&name(), ver, &sdata); 
+  return m_obj_ptr= obs::get_database(&name(), ver, &sdata);
 }
 
+
 /// Implementation of @c Image_info::Obj virtual method.
+
 inline
 obs::Obj* Image_info::Table::materialize(uint ver, const ::String &sdata)
 {
@@ -1137,33 +1227,41 @@ obs::Obj* Image_info::Table::materialize
   return m_obj_ptr= obs::get_table(&db().name(), &name(), ver, &sdata);
 }
 
+
 inline
 obs::Obj* Image_info::Dbobj::materialize(uint ver, const ::String &sdata)
-{ 
+{
   const ::String *db_name= &Table_ref::db().name();
   const ::String *name= &Table_ref::name();
 
   delete m_obj_ptr;
-  
+
   switch (base.type) {
-  case BSTREAM_IT_VIEW:   
+
+  case BSTREAM_IT_VIEW:
     m_obj_ptr= obs::get_view(db_name, name, ver, &sdata);
     break;
-  case BSTREAM_IT_SPROC:  
+
+  case BSTREAM_IT_SPROC:
     m_obj_ptr= obs::get_stored_procedure(db_name, name, ver, &sdata);
     break;
+
   case BSTREAM_IT_SFUNC:
-    m_obj_ptr= obs::get_stored_function(db_name, name, ver, &sdata); 
+    m_obj_ptr= obs::get_stored_function(db_name, name, ver, &sdata);
     break;
+
   case BSTREAM_IT_EVENT:
     m_obj_ptr= obs::get_event(db_name, name, ver, &sdata);
     break;
-  case BSTREAM_IT_TRIGGER:   
+
+  case BSTREAM_IT_TRIGGER:
     m_obj_ptr= obs::get_trigger(db_name, name, ver, &sdata);
     break;
+
   case BSTREAM_IT_PRIVILEGE:
     m_obj_ptr= obs::get_db_grant(db_name, name, ver, &sdata);
     break;
+
   default: m_obj_ptr= NULL;
   }
 
@@ -1173,14 +1271,15 @@ obs::Obj* Image_info::Dbobj::materialize
 
 /**
   Add table to a database.
-  
+
   The table is appended to database's table list.
- */
+*/
+
 inline
 void Image_info::Db::add_table(Table &tbl)
 {
   tbl.next_table= NULL;
-  
+
   if (!last_table)
     first_table= last_table= &tbl;
   else
@@ -1190,11 +1289,13 @@ void Image_info::Db::add_table(Table &tb
   }
 }
 
+
 /**
   Add object other than table to a database.
-  
+
   The object is stored in database's object list at given position.
- */ 
+*/
+
 inline
 result_t Image_info::Db::add_obj(Dbobj &obj, ulong pos)
 {
@@ -1206,14 +1307,18 @@ result_t Image_info::Db::add_obj(Dbobj &
   return OK;
 }
 
+
 /// Get database object stored at given position.
+
 inline
 Image_info::Dbobj* Image_info::Db::get_obj(ulong pos) const
 {
   return m_objs[pos];
 }
 
+
 /// Return number of objects, other than tables, belonging to database.
+
 inline
 ulong Image_info::Db::obj_count() const
 {
@@ -1222,65 +1327,79 @@ ulong Image_info::Db::obj_count() const
 
 
 /********************************************************************
- 
+
    Inline members of Snapshot_info class.
- 
- ********************************************************************/ 
 
-/// version of snapshot's format
+ ********************************************************************/
+
+/// Version of snapshot's format.
+
 inline
-version_t Snapshot_info::version() const  
-{ return m_version; }
+version_t Snapshot_info::version() const
+{
+  return m_version;
+}
+
 
 /// Add table at a given position.
+
 inline
 int Snapshot_info::add_table(Image_info::Table &t, ulong pos)
 {
   return m_tables.insert(pos, &t);
 }
 
-/// Get table at a given position
+
+/// Get table at a given position.
+
 inline
 Image_info::Table* Snapshot_info::get_table(ulong pos) const
 {
   return m_tables.get_table(pos);
 }
 
+
 /// Return number of tables stored in this snapshot.
+
 inline
 ulong Snapshot_info::table_count() const
 {
   return m_tables.count();
 }
 
+
 /********************************************************************
- 
+
    Inline members of iterators.
- 
- ********************************************************************/ 
+
+ ********************************************************************/
 
 inline
 Image_info::Obj* Image_info::Iterator::operator++(int)
 {
   Obj *obj= get_ptr();
   next();
-  return obj; 
+  return obj;
 }
 
+
 /// Implementation of @c Image_info::Iterator virtual method.
+
 inline
 Image_info::Obj* Image_info::Db_iterator::get_ptr() const
 {
   /*
     There should be no "holes" in the sequence of databases. That is,
-    if there are N databases in the catalogue then for i=0,1,..,N-1, 
+    if there are N databases in the catalogue then for i=0,1,..,N-1,
     m_info.m_dbs[i] should store pointer to the i-th database.
-   */ 
+  */
   DBUG_ASSERT(pos >= m_info.db_count() || m_info.m_dbs[pos]);
   return m_info.m_dbs[pos];
 }
 
+
 /// Implementation of @c Image_info::Iterator virtual method.
+
 inline
 bool Image_info::Db_iterator::next()
 {
@@ -1295,19 +1414,22 @@ bool Image_info::Db_iterator::next()
 
 
 /// Implementation of @c Image_info::Iterator virtual method.
+
 inline
 Image_info::Obj* Image_info::Ts_iterator::get_ptr() const
 {
   /*
     There should be no "holes" in the sequence of tablespaces. That is,
-    if there are N tablespaces in the catalogue then for i=0,1,..,N-1, 
+    if there are N tablespaces in the catalogue then for i=0,1,..,N-1,
     m_info.m_ts_map[i] should store pointer to the i-th database.
-   */ 
+  */
   DBUG_ASSERT(pos >= m_info.ts_count() || m_info.m_ts_map[pos]);
   return m_info.m_ts_map[pos];
 }
 
+
 /// Implementation of @c Image_info::Iterator virtual method.
+
 inline
 bool Image_info::Ts_iterator::next()
 {
@@ -1322,13 +1444,16 @@ bool Image_info::Ts_iterator::next()
 
 
 /// Implementation of @c Image_info::Iterator virtual method.
+
 inline
 Image_info::Obj* Image_info::Dbobj_iterator::get_ptr() const
 {
   return ptr ? static_cast<Obj*>(ptr) : m_db.get_obj(pos);
 }
 
+
 /// Implementation of @c Image_info::Iterator virtual method.
+
 inline
 bool Image_info::Dbobj_iterator::next()
 {

=== modified file 'sql/backup/kernel.cc'
--- a/sql/backup/kernel.cc	2009-10-21 12:15:53 +0000
+++ b/sql/backup/kernel.cc	2009-10-21 13:32:24 +0000
@@ -11,14 +11,14 @@
 */
 
 /**
-  @mainpage 
-  
-  @section Structure Structure of the MySQL Backup System 
-  
+  @mainpage
+
+  @section Structure Structure of the MySQL Backup System
+
   @verbatim
 
                 |      Online Backup Module
-                | 
+                |
             (1) |   +---------------+      +------------------------+
    Server      ---> | Backup Kernel | <--> | Backup/Restore drivers |
                 |   +---------------+ (3)  +------------------------+
@@ -29,14 +29,14 @@
                 +--------|---|----------------------------
                 |        v
                 |   Backup Stream Library
-                |                    
+                |
   @endverbatim
-  
-  Backup stream library is autonomous so that external applications can link 
-  against it to be able to read backup images created by the system. 
+
+  Backup stream library is autonomous so that external applications can link
+  against it to be able to read backup images created by the system.
   The format of backup images is described @ref stream_format "here".
-  
-  The components of the system communicate with each other using well defined 
+
+  The components of the system communicate with each other using well defined
   interfaces:
   -# @ref KernelAPI "Backup Kernel API"
   -# Object Services API and Backup Log API
@@ -51,52 +51,55 @@
   Backup kernel API is the interface between the backup system and its external
   users.
 
-  @section s1 How to use backup kernel API to perform backup and restore operations
-  
+  @section s1 How to use backup kernel API to perform backup and restore 
+              operations
+
   To perform backup or restore operation an appropriate context must be created.
   This involves creating required resources and correctly setting up the server.
   When operation is completed or interrupted, the context must be destroyed and
   all preparations reversed.
-  
-  All this is accomplished by creating an instance of Backup_create_ctx class and
-  then using its methods to perform the operation. When the instance is 
+
+  All this is accomplished by creating an instance of Backup_create_ctx class 
+  and then using its methods to perform the operation. When the instance is
   destroyed, the required clean-up is performed.
-  
+
   This is how backup is performed using the context object:
   @code
   {
-  
+
    Backup_restore_ctx context(thd); // create context instance
-   Backup_info *info= context.prepare_for_backup(location, 
-                                                 orig_loc); // prepare for backup
-  
+   
+   // prepare for backup
+   Backup_info *info= context.prepare_for_backup(location, orig_loc);
+
    // select objects to backup
    info->add_all_dbs();
    or
    info->add_dbs(<list of db names>);
-  
+
    info->close(); // indicate that selection is done
-  
+
    context.do_backup(); // perform backup
-   
+
    context.close(); // explicit clean-up
-  
+
   } // if code jumps here, context destructor will do the clean-up automatically
   @endcode
-  
-  Similar code will be used for restore (bit simpler as we don't support 
+
+  Similar code will be used for restore (bit simpler as we don't support
   selective restores yet):
   @code
   {
-  
+
    Backup_restore_ctx context(thd); // create context instance
-   Restore_info *info= context.prepare_for_restore(location,
-                                                   orig_loc); // prepare for restore
-  
-   context.do_restore(); // perform restore
    
+   // prepare for restore
+   Restore_info *info= context.prepare_for_restore(location, orig_loc); 
+
+   context.do_restore(); // perform restore
+
    context.close(); // explicit clean-up
-  
+
   } // if code jumps here, context destructor will do the clean-up automatically
   @endcode
 
@@ -117,12 +120,13 @@
 #include "transaction.h"
 
 
-/** 
+/**
   Global Initialization for MYSQL backup system.
- 
+
   @note This function is called in the server initialization sequence, just
   after it loads all its plugins.
- */
+*/
+
 int backup_init()
 {
   pthread_mutex_init(&Backup_restore_ctx::run_lock, MY_MUTEX_INIT_FAST);
@@ -130,16 +134,18 @@ int backup_init()
   return 0;
 }
 
+
 /**
   Global clean-up for MySQL backup system.
-  
+
   @note This function is called in the server shut-down sequences, just before
   it shuts-down all its plugins.
 
   @note Due to way in which server's code is organized this function might be
   called and should work normally even in situation when backup_init() was not
   called at all.
- */
+*/
+
 void backup_shutdown()
 {
   if (Backup_restore_ctx::run_lock_initialized)
@@ -149,10 +155,11 @@ void backup_shutdown()
   }
 }
 
+
 /*
-  Forward declarations of functions used for sending response from BACKUP/RESTORE
-  statement.
- */ 
+  Forward declarations of functions used for sending response from
+  BACKUP/RESTORE statement.
+*/
 static int send_error(Backup_restore_ctx &context, int error_code, ...);
 static int send_reply(Backup_restore_ctx &context);
 
@@ -176,29 +183,29 @@ static int send_reply(Backup_restore_ctx
   commands with appropriate flags in @c sql_command_flags[] in sql_parse.cc.
 
   @returns 0 on success, error code otherwise.
- */
+*/
 
 int
-execute_backup_command(THD *thd, 
-                       LEX *lex, 
-                       String *backupdir, 
+execute_backup_command(THD *thd,
+                       LEX *lex,
+                       String *backupdir,
                        bool overwrite,
                        bool skip_gap_event)
 {
   int res= 0;
-  
+
   DBUG_ENTER("execute_backup_command");
   DBUG_ASSERT(thd && lex);
   DEBUG_SYNC(thd, "before_backup_command");
 
-    
+
   using namespace backup;
 
-  Backup_restore_ctx context(thd); // reports errors
-  
+  Backup_restore_ctx context(thd); // Reports errors.
+
   res= !context.is_valid();
 
-  // Error code insertion for ER_BACKUP_CONTEXT_CREATE.
+  /* Error code insertion for ER_BACKUP_CONTEXT_CREATE. */
   DBUG_EXECUTE_IF("ER_BACKUP_CONTEXT_CREATE", res= 1;);
 
   if (res)
@@ -208,16 +215,16 @@ execute_backup_command(THD *thd, 
 
   case SQLCOM_BACKUP:
   {
-    // prepare for backup operation
-    
+    /* Prepare for backup operation. */
+
     DEBUG_SYNC(thd, "before_backup_prepare");
-    Backup_info *info= context.prepare_for_backup(backupdir, lex->backup_dir, 
+    Backup_info *info= context.prepare_for_backup(backupdir, lex->backup_dir,
                                                   thd->query,
                                                   lex->backup_compression,
                                                   overwrite);
-                                                              // reports errors
+                                                              // Reports errors.
 
-    // Error condition insertion for ER_BACKUP_BACKUP_PREPARE.
+    /* Error condition insertion for ER_BACKUP_BACKUP_PREPARE. */
     DBUG_EXECUTE_IF("ER_BACKUP_BACKUP_PREPARE_1", info= 0;);
 
     if (!info || !info->is_valid())
@@ -225,21 +232,21 @@ execute_backup_command(THD *thd, 
 
     DEBUG_SYNC(thd, "after_backup_start_backup");
 
-    // select objects to backup
+    /* Select objects to backup. */
 
     if (lex->db_list.is_empty())
-      res= info->add_all_dbs(); // backup all databases
+      res= info->add_all_dbs(); // Backup all databases.
     else
     {
       /* Backup databases specified by user. */
       res= info->add_dbs(thd, lex->db_list);
     }
 
-    info->close(); // close catalogue after filling it with objects to backup
+    info->close(); // Close catalogue after filling it with objects to backup.
 
-    DBUG_EXECUTE_IF("kill_backup", thd->killed= THD::KILL_QUERY;); 
+    DBUG_EXECUTE_IF("kill_backup", thd->killed= THD::KILL_QUERY;);
 
-    // Error condition insertion for ER_BACKUP_BACKUP_PREPARE.
+    /* Error condition insertion for ER_BACKUP_BACKUP_PREPARE. */
     DBUG_EXECUTE_IF("ER_BACKUP_BACKUP_PREPARE_2", res= 1;);
 
     if (res || !info->is_valid())
@@ -247,7 +254,7 @@ execute_backup_command(THD *thd, 
 
     int count= info->db_count();
 
-    // Error condition insertion for ER_BACKUP_NOTHING_TO_BACKUP.
+    /* Error condition insertion for ER_BACKUP_NOTHING_TO_BACKUP. */
     DBUG_EXECUTE_IF("ER_BACKUP_NOTHING_TO_BACKUP", count= 0;);
 
     if (count == 0)
@@ -256,11 +263,11 @@ execute_backup_command(THD *thd, 
       DBUG_RETURN(send_error(context, ER_BACKUP_NOTHING_TO_BACKUP));
     }
 
-    // perform backup
+    /* Perform backup. */
 
     DEBUG_SYNC(thd, "before_do_backup");
     res= context.do_backup();
- 
+
     DEBUG_SYNC(thd, "after_do_backup");
     DBUG_EXECUTE_IF("ER_BACKUP_BACKUP", res= 1;);
     if (res)
@@ -273,29 +280,29 @@ execute_backup_command(THD *thd, 
   {
     DEBUG_SYNC(thd, "before_restore_prepare");
 
-    Restore_info *info= context.prepare_for_restore(backupdir, lex->backup_dir, 
+    Restore_info *info= context.prepare_for_restore(backupdir, lex->backup_dir,
                                                     thd->query, skip_gap_event);
-    
-    // Error code insertion for ER_BACKUP_RESTORE_PREPARE.
+
+    /* Error code insertion for ER_BACKUP_RESTORE_PREPARE. */
     DBUG_EXECUTE_IF("ER_BACKUP_RESTORE_PREPARE_2", info= 0;);
 
     if (!info || !info->is_valid())
       DBUG_RETURN(send_error(context, ER_BACKUP_RESTORE_PREPARE));
-    
+
     DEBUG_SYNC(thd, "after_backup_start_restore");
 
-    DBUG_EXECUTE_IF("kill_restore", thd->killed= THD::KILL_QUERY;); 
+    DBUG_EXECUTE_IF("kill_restore", thd->killed= THD::KILL_QUERY;);
 
-    res= context.do_restore(overwrite);      
+    res= context.do_restore(overwrite);
 
     DEBUG_SYNC(thd, "restore_before_end");
 
-    // Error code insertion for ER_BACKUP_RESTORE.
+    /* Error code insertion for ER_BACKUP_RESTORE. */
     DBUG_EXECUTE_IF("ER_BACKUP_RESTORE_1", res= 1;);
 
     if (res)
       DBUG_RETURN(send_error(context, ER_BACKUP_RESTORE));
-    
+
     break;
   }
 
@@ -303,7 +310,7 @@ execute_backup_command(THD *thd, 
      /*
        execute_backup_command() should be called with correct command id
        from the parser. If not, we fail on this assertion.
-      */
+     */
      DBUG_ASSERT(FALSE);
 
   } // switch(lex->sql_command)
@@ -311,17 +318,18 @@ execute_backup_command(THD *thd, 
   res= context.close();
   DEBUG_SYNC(thd, "backup_restore_done");
 
-  // Error code insertion for ER_BACKUP_CONTEXT_REMOVE.
+  /* Error code insertion for ER_BACKUP_CONTEXT_REMOVE. */
   DBUG_EXECUTE_IF("ER_BACKUP_CONTEXT_REMOVE", res= 1;);
 
   if (res)
     DBUG_RETURN(send_error(context, ER_BACKUP_CONTEXT_REMOVE));
 
-  // All seems OK - send positive reply to client
+  /* All seems OK - send positive reply to client. */
 
   DBUG_RETURN(send_reply(context));
 }
 
+
 /**
   Sends error notification after failed backup/restore operation.
 
@@ -329,12 +337,13 @@ execute_backup_command(THD *thd, 
   @param[in]  error_code  Error to be reported if no errors reported yet.
 
   If an error has been already reported, or process has been interrupted,
-  then nothing is done - the first logged error or kill message will be sent 
+  then nothing is done - the first logged error or kill message will be sent
   to the client. Otherwise, if no errors were reported yet and no interruption
   has been detected the given error is sent to the client (but not reported).
-  
+
   @returns The error code given as argument.
 */
+
 static
 int send_error(Backup_restore_ctx &context, int error_code, ...)
 {
@@ -364,6 +373,7 @@ int send_error(Backup_restore_ctx &conte
 
   @returns 0 on success, error code otherwise.
 */
+
 int send_reply(Backup_restore_ctx &context)
 {
   Protocol *protocol= context.thd()->protocol;    // client comms
@@ -376,9 +386,7 @@ int send_reply(Backup_restore_ctx &conte
   if (context.error_reported())
     return send_error(context, ER_UNKNOWN_ERROR);
 
-  /*
-    Send field list.
-  */
+  /* Send field list. */
   if (field_list.push_back(new Item_empty_string(STRING_WITH_LEN("backup_id"))))
   {
     goto err;
@@ -389,32 +397,30 @@ int send_reply(Backup_restore_ctx &conte
     goto err;
   }
 
-  /*
-    Send field data.
-  */
-  protocol->prepare_for_resend();               // Never errors
-  llstr(context.op_id(), buf);                  // Never errors
+  /* Send field data. */
+  protocol->prepare_for_resend();               // Never errors.
+  llstr(context.op_id(), buf);                  // Never errors.
 
   res= protocol->store(buf, system_charset_info);
-  
-  // Error code insertion for ER_BACKUP_SEND_REPLY.
+
+  /* Error code insertion for ER_BACKUP_SEND_REPLY. */
   DBUG_EXECUTE_IF("ER_BACKUP_SEND_REPLY_1", res= 1;);
- 
+
   if (res)
   {
     goto err;
   }
 
   res= protocol->write();
-  
-  // Error code insertion for ER_BACKUP_SEND_REPLY.
+
+  /* Error code insertion for ER_BACKUP_SEND_REPLY. */
   DBUG_EXECUTE_IF("ER_BACKUP_SEND_REPLY_2", res= 1;);
-  
+
   if (res)
   {
     goto err;
   }
-  my_eof(context.thd());                        // Never errors
+  my_eof(context.thd());                        // Never errors.
 
   DBUG_RETURN(0);
 
@@ -433,6 +439,7 @@ namespace backup {
   An instance of this class is created during preparations for backup/restore
   operation. When it is deleted, all allocated memory is freed.
 */
+
 class Mem_allocator
 {
 public:
@@ -449,7 +456,6 @@ private:
   node *first;  ///< Pointer to the first segment in the list.
 };
 
-
 } // backup namespace
 
 
@@ -459,11 +465,11 @@ private:
 
  *************************************************/
 
-// static members
+/* static members */
 
-Backup_restore_ctx *Backup_restore_ctx::current_op= NULL;
-bool Backup_restore_ctx::run_lock_initialized= FALSE;
-pthread_mutex_t Backup_restore_ctx::run_lock;
+Backup_restore_ctx  *Backup_restore_ctx::current_op= NULL;
+bool                Backup_restore_ctx::run_lock_initialized= FALSE;
+pthread_mutex_t     Backup_restore_ctx::run_lock;
 
 
 Backup_restore_ctx::Backup_restore_ctx(THD *thd)
@@ -472,9 +478,7 @@ Backup_restore_ctx::Backup_restore_ctx(T
   m_catalog(NULL), mem_alloc(NULL), m_tables_locked(FALSE),
   m_engage_binlog(FALSE), m_completed(FALSE)
 {
-  /*
-    Check for progress tables.
-  */
+  /* Check for progress tables. */
   MYSQL_BACKUP_LOG *log_handler= logger.get_backup_history_log_file_handler();
   if (report_killed())
     m_error= ER_QUERY_INTERRUPTED;
@@ -482,16 +486,18 @@ Backup_restore_ctx::Backup_restore_ctx(T
     m_error= ER_BACKUP_PROGRESS_TABLES;
 }
 
+
 Backup_restore_ctx::~Backup_restore_ctx()
 {
   DEBUG_SYNC(m_thd, "backup_restore_ctx_dtor");
   close();
 
   delete mem_alloc;
-  delete m_catalog;  
+  delete m_catalog;
   delete m_stream;
 }
 
+
 /**
   Prepare path for access.
 
@@ -509,7 +515,7 @@ Backup_restore_ctx::~Backup_restore_ctx(
     @retval   0          ok
     @retval   != 0       error number
 */
-int Backup_restore_ctx::prepare_path(::String *backupdir, 
+int Backup_restore_ctx::prepare_path(::String *backupdir,
                                      LEX_STRING orig_loc)
 {
   const char    *datadir_ptr= "";
@@ -562,7 +568,7 @@ int Backup_restore_ctx::prepare_path(::S
 
     Relative paths are formed from the backupdir system variable.
 
-    Case 1: Backup image file name has relative path. 
+    Case 1: Backup image file name has relative path.
             Make relative to backupdir.
 
     Example BACKUP DATATBASE ... TO '../monthly/dec.bak'
@@ -570,7 +576,7 @@ int Backup_restore_ctx::prepare_path(::S
             calculated path becomes
             '/dev/monthly/dec.bak'
 
-    Case 2: Backup image file name has no path or has a subpath. 
+    Case 2: Backup image file name has no path or has a subpath.
 
     Example BACKUP DATABASE ... TO 'week2.bak'
             If backupdir = '/dev/weekly/' then the
@@ -581,7 +587,7 @@ int Backup_restore_ctx::prepare_path(::S
             calculated path becomes
             '/dev/monthly/jan/day1.bak'
 
-    Case 3: Backup image file name has hard path. 
+    Case 3: Backup image file name has hard path.
 
     Example BACKUP DATATBASE ... TO '/dev/dec.bak'
             If backupdir = '/dev/daily/backup' then the
@@ -618,17 +624,19 @@ int Backup_restore_ctx::prepare_path(::S
   DBUG_RETURN(plen ? 0 : ER_PATH_LENGTH);
 }
 
+
 /**
   Do preparations common to backup and restore operations.
-  
+
   It is checked if another operation is in progress and if yes then
   error is reported. Otherwise the current operation is registered so that
-  no other can be started. All preparations common to backup and restore 
+  no other can be started. All preparations common to backup and restore
   operations are done. In particular, all changes to meta data are blocked
   with DDL blocker.
 
   @returns 0 on success, error code otherwise.
- */ 
+*/
+
 int Backup_restore_ctx::prepare(::String *backupdir, LEX_STRING location)
 {
   if (m_error)
@@ -637,9 +645,9 @@ int Backup_restore_ctx::prepare(::String
   int ret= 0;
 
   /*
-    Check if another BACKUP/RESTORE is running and if not, register 
+    Check if another BACKUP/RESTORE is running and if not, register
     this operation.
-   */
+  */
 
   DEBUG_SYNC(m_thd, "before_backup_single_op");
   pthread_mutex_lock(&run_lock);
@@ -657,7 +665,7 @@ int Backup_restore_ctx::prepare(::String
     return m_error;
   }
 
-  // check if location is valid (we assume it is a file path)
+  /* Check if location is valid (we assume it is a file path). */
 
   /*
     For this error to work correctly, we need to check original
@@ -665,12 +673,12 @@ int Backup_restore_ctx::prepare(::String
     using the backupdir.
   */
   bool bad_filename= (location.length == 0);
-  
+
   /*
-    On some systems certain file names are invalid. We use 
+    On some systems certain file names are invalid. We use
     check_if_legal_filename() function from mysys to detect this.
-   */ 
-#if defined(__WIN__) || defined(__EMX__)  
+  */
+#if defined(__WIN__) || defined(__EMX__)
 
   bad_filename = bad_filename || check_if_legal_filename(location.str);
 
@@ -680,24 +688,20 @@ int Backup_restore_ctx::prepare(::String
   if (bad_filename || is_killed())
     return fatal_error(report_error(ER_BAD_PATH, location.str));
 
-  /*
-    Compute full path to backup file.
-  */
+  /* Compute full path to backup file. */
   ret= prepare_path(backupdir, location);
   if (ret)
     return ret;
 
-  // create new instance of memory allocator for backup stream library
-
-  using namespace backup;
+  /* Create new instance of memory allocator for backup stream library. */
 
   delete mem_alloc;
-  mem_alloc= new Mem_allocator();
+  mem_alloc= new backup::Mem_allocator();
 
   if (!mem_alloc)
     return fatal_error(report_error(ER_OUT_OF_RESOURCES));
 
-  // Freeze all metadata. 
+  /* Freeze all metadata. */
 
   DEBUG_SYNC(m_thd, "before_backup_ddl_block");
   ret= obs::bml_get(m_thd);
@@ -709,45 +713,46 @@ int Backup_restore_ctx::prepare(::String
   return 0;
 }
 
+
 /**
   Prepare for backup operation.
-  
+
   @param[in] backupdir  path to the file where backup image should be stored
   @param[in] orig_loc   path as specified on command line for backup image
   @param[in] query      BACKUP query starting the operation
   @param[in] with_compression  backup image compression switch
-  
+
   @returns Pointer to a @c Backup_info instance which can be used for selecting
   which objects to backup. NULL if an error was detected.
-  
+
   @note This function reports errors.
 
   @note It is important that changes of metadata are blocked as part of the
   preparations. The set of server objects and their definitions should not
   change after the backup context has been prepared and before the actual backup
   is performed using @c do_backup() method.
- */ 
-Backup_info* 
-Backup_restore_ctx::prepare_for_backup(String *backupdir, 
-                                       LEX_STRING orig_loc, 
+*/
+Backup_info*
+Backup_restore_ctx::prepare_for_backup(String *backupdir,
+                                       LEX_STRING orig_loc,
                                        const char *query,
                                        bool with_compression,
                                        bool overwrite)
 {
   using namespace backup;
-  
-  // Do nothing if context is in error state.
+
+  /* Do nothing if context is in error state. */
   if (m_error)
     return NULL;
 
   /*
-   Note: Logger must be initialized before any call to report_error() - 
-   otherwise an assertion will fail.
-  */ 
+    Note: Logger must be initialized before any call to report_error() -
+    otherwise an assertion will fail.
+  */
   DEBUG_SYNC(m_thd, "before_backup_logger_init");
-  int ret= Logger::init(BACKUP, query);  // Logs errors   
+  int ret= Logger::init(BACKUP, query);  // Logs errors
 
-  // Error condition insertion for ER_BACKUP_LOGGER_INIT.
+  /* Error condition insertion for ER_BACKUP_LOGGER_INIT. */
   DBUG_EXECUTE_IF("ER_BACKUP_LOGGER_INIT_1", ret= 1;);
 
   if (ret || is_killed())
@@ -758,20 +763,18 @@ Backup_restore_ctx::prepare_for_backup(S
 
   time_t when= my_time(0);
   report_start(when);
-  
+
   /*
     Do preparations common to backup and restore operations. After call
     to prepare() all metadata changes are blocked.
-   */ 
+  */
   DEBUG_SYNC(m_thd, "before_backup_common_prepare");
-  if (prepare(backupdir, orig_loc))  // Logs errors and detects interruptions
+  if (prepare(backupdir, orig_loc))  // Logs errors and detects interruptions.
     return NULL;
 
-  /*
-    Open output stream.
-   */
+  /* Open output stream. */
   DEBUG_SYNC(m_thd, "before_backup_open_stream");
-  Output_stream *s= new Output_stream(*this, 
+  Output_stream *s= new Output_stream(*this,
                                       &m_path,
                                       with_compression,
                                       overwrite);
@@ -786,17 +789,17 @@ Backup_restore_ctx::prepare_for_backup(S
   DEBUG_SYNC(m_thd, "before_backup_stream_open");
   int my_open_status= s->open();
 
-  // Error code insertion for ER_BACKUP_READ_LOC.
+  /* Error code insertion for ER_BACKUP_READ_LOC. */
   DBUG_EXECUTE_IF("ER_BACKUP_READ_LOC_1", my_open_status= ER_BACKUP_READ_LOC;);
-  
+
   /*
     Set state to PREPARED_FOR_BACKUP in case output file was opened successfuly.
     It is important to set the state here, because this ensures that the file
     will be removed in case of error or interruption.
-   */ 
-  if (! my_open_status)
+  */
+  if (!my_open_status)
     m_state= PREPARED_FOR_BACKUP;
-  
+
   if (my_open_status != 0 || is_killed())
   {
     if (report_killed())
@@ -806,12 +809,10 @@ Backup_restore_ctx::prepare_for_backup(S
     return NULL;
   }
 
-  /*
-    Create backup catalogue.
-   */
+  /* Create backup catalogue. */
 
   DEBUG_SYNC(m_thd, "before_backup_catalog");
-  Backup_info *info= new Backup_info(*this, m_thd);    // Logs errors
+  Backup_info *info= new Backup_info(*this, m_thd);    // Logs errors.
   m_catalog= info;
 
   if (!info || is_killed())
@@ -822,70 +823,71 @@ Backup_restore_ctx::prepare_for_backup(S
 
   bool res= info->is_valid();
 
-  // Error condition insertion for ER_BACKUP_BACKUP_PREPARE.
+  /* Error condition insertion for ER_BACKUP_BACKUP_PREPARE. */
   DBUG_EXECUTE_IF("ER_BACKUP_BACKUP_PREPARE_3", res= 0;);
 
   if (!res)
   {
-    // Error has been logged by Backup_info constructor
+    /* Error has been logged by Backup_info constructor. */
     fatal_error(ER_BACKUP_BACKUP_PREPARE);
-    return NULL;    
+    return NULL;
   }
 
   /*
     If binlog is enabled, set BSTREAM_FLAG_BINLOG in the header to indicate
-    that validity point's binlog position will be stored in the image 
+    that validity point's binlog position will be stored in the image
     (in its summary section).
-    
-    This is not completely safe because theoretically even if now binlog is 
-    active, it can be disabled before we reach the validity point and then we 
-    will not store binlog position even though the flag is set. To fix this 
-    problem the format of backup image must be changed (some flags must be 
-    stored in the summary section which is written at the end of backup 
+
+    This is not completely safe because theoretically even if now binlog is
+    active, it can be disabled before we reach the validity point and then we
+    will not store binlog position even though the flag is set. To fix this
+    problem the format of backup image must be changed (some flags must be
+    stored in the summary section which is written at the end of backup
     operation).
   */
   if (mysql_bin_log.is_open())
-    info->flags|= BSTREAM_FLAG_BINLOG; 
+    info->flags|= BSTREAM_FLAG_BINLOG;
 
   info->save_start_time(when);
 
   return info;
 }
 
+
 /**
   Prepare for restore operation.
-  
+
   @param[in] backupdir  path to the file where backup image is stored
   @param[in] orig_loc   path as specified on command line for backup image
   @param[in] query      RESTORE query starting the operation
   @param[in] skip_gap_event TRUE means do not write gap event
-  
+
   @returns Pointer to a @c Restore_info instance containing catalogue of the
   backup image (read from the image). NULL if errors were detected.
-  
+
   @note This function reports errors.
- */ 
-Restore_info* 
+*/
+
+Restore_info*
 Backup_restore_ctx::prepare_for_restore(String *backupdir,
-                                        LEX_STRING orig_loc, 
+                                        LEX_STRING orig_loc,
                                         const char *query,
                                         bool skip_gap_event)
 {
-  using namespace backup;  
-
+  using namespace backup;
 
-  // Do nothing if context is in error state.
+  /* Do nothing if context is in error state. */
   if (m_error)
     return NULL;
-  
+
   /*
-   Note: Logger must be initialized before any call to report_error() - 
-   otherwise an assertion will fail.
-  */ 
+    Note: Logger must be initialized before any call to report_error() -
+    otherwise an assertion will fail.
+  */
   DEBUG_SYNC(m_thd, "before_restore_logger_init");
-  int ret= Logger::init(RESTORE, query);  // Logs errors
+  int ret= Logger::init(RESTORE, query);  // Logs errors.
 
-  // Error condition insertion for ER_BACKUP_LOGGER_INIT.
+  /* Error condition insertion for ER_BACKUP_LOGGER_INIT. */
   DBUG_EXECUTE_IF("ER_BACKUP_LOGGER_INIT_2", ret= 1;);
 
   if (ret || is_killed())
@@ -894,48 +896,42 @@ Backup_restore_ctx::prepare_for_restore(
     return NULL;
   }
 
-  /*
-    Block replication from starting.
-  */
+  /* Block replication from starting. */
   obs::block_replication(TRUE, "RESTORE");
 
-  /*
-    Restore cannot be run on a slave while connected to a master.
-  */
+  /* Restore cannot be run on a slave while connected to a master. */
   if (obs::is_slave())
   {
     fatal_error(report_error(ER_RESTORE_ON_SLAVE));
     return NULL;
   }
 
-  time_t when= my_time(0);  
+  time_t when= my_time(0);
   report_start(when);
 
   /*
     Do preparations common to backup and restore operations. After this call
     changes of metadata are blocked.
-   */ 
+  */
   DEBUG_SYNC(m_thd, "before_restore_common_prepare");
   if (prepare(backupdir, orig_loc))
     return NULL;
-  
-  /*
-    Open input stream.
-   */
+
+  /* Open input stream. */
   DEBUG_SYNC(m_thd, "before_restore_open_stream");
   Input_stream *s= new Input_stream(*this, &m_path);
   m_stream= s;
-  
+
   if (!s || is_killed())
   {
     fatal_error(report_error(ER_OUT_OF_RESOURCES));
     return NULL;
   }
-  
+
   DEBUG_SYNC(m_thd, "before_restore_stream_open");
   int my_open_status= s->open();
 
-  // Error code insertion for ER_BACKUP_READ_LOC.
+  /* Error code insertion for ER_BACKUP_READ_LOC. */
   DBUG_EXECUTE_IF("ER_BACKUP_READ_LOC_2", my_open_status= ER_BACKUP_READ_LOC;);
 
   if (my_open_status != 0 || is_killed())
@@ -947,12 +943,10 @@ Backup_restore_ctx::prepare_for_restore(
     return NULL;
   }
 
-  /*
-    Create restore catalogue.
-   */
+  /* Create restore catalogue. */
 
   DEBUG_SYNC(m_thd, "before_restore_catalog");
-  Restore_info *info= new Restore_info(*this, m_thd);  // reports errors
+  Restore_info *info= new Restore_info(*this, m_thd);  // Reports errors.
   m_catalog= info;
 
   if (!info || is_killed())
@@ -963,21 +957,19 @@ Backup_restore_ctx::prepare_for_restore(
 
   int res= !info->is_valid();
 
-  // Error code insertion for ER_BACKUP_RESTORE_PREPARE.
+  /* Error code insertion for ER_BACKUP_RESTORE_PREPARE. */
   DBUG_EXECUTE_IF("ER_BACKUP_RESTORE_PREPARE_1", res= 1;);
 
   if (res)
   {
-    // Errors are logged by Restore_info constructor. 
-    fatal_error(ER_BACKUP_RESTORE_PREPARE); 
+    /* Errors are logged by Restore_info constructor. */
+    fatal_error(ER_BACKUP_RESTORE_PREPARE);
     return NULL;
   }
 
   info->save_start_time(when);
 
-  /*
-    Read header and catalogue from the input stream.
-   */
+  /* Read header and catalogue from the input stream. */
 
   DEBUG_SYNC(m_thd, "before_restore_read_header");
   ret= read_header(*info, *s);  // Can log errors via callback functions.
@@ -992,7 +984,7 @@ Backup_restore_ctx::prepare_for_restore(
   }
 
   ret= s->next_chunk();
-  /* Mimic error in next_chunk */
+  /* Mimic error in next_chunk. */
   DBUG_EXECUTE_IF("restore_prepare_next_chunk_1", ret= BSTREAM_ERROR; );
   if (ret != BSTREAM_OK || is_killed())
   {
@@ -1013,7 +1005,7 @@ Backup_restore_ctx::prepare_for_restore(
   }
 
   ret= s->next_chunk();
-  /* Mimic error in next_chunk */
+  /* Mimic error in next_chunk. */
   DBUG_EXECUTE_IF("restore_prepare_next_chunk_2", ret= BSTREAM_ERROR; );
   if (ret != BSTREAM_OK || is_killed())
   {
@@ -1052,6 +1044,7 @@ Backup_restore_ctx::prepare_for_restore(
   return info;
 }
 
+
 /*
   Lock tables being restored.
 
@@ -1067,7 +1060,8 @@ Backup_restore_ctx::prepare_for_restore(
 
   @todo Replace open_and_lock_tables() by a lighter solution.
   @todo Hide table locking behind the server API.
-*/ 
+*/
+
 int Backup_restore_ctx::lock_tables_for_restore()
 {
   int ret;
@@ -1093,7 +1087,7 @@ int Backup_restore_ctx::lock_tables_for_
       TABLE_LIST *ptr= backup::mk_table_list(*tbl, TL_WRITE, m_thd->mem_root);
       if (!ptr)
       {
-        // Error has been reported, but not logged to backup logs
+        /* Error has been reported, but not logged to backup logs. */
         return fatal_error(log_error(ER_OUT_OF_RESOURCES));
       }
 
@@ -1104,27 +1098,27 @@ int Backup_restore_ctx::lock_tables_for_
   }
 
   DBUG_EXECUTE_IF("restore_lock_tables_for_restore",
-    /* 
+    /*
        Mimic error in opening tables. Cannot be done by setting ret=1
        after open_and_lock_tables_derived becase that method is
        supposed to release the lock before returning error.
-     */
+    */
     return fatal_error(report_error(ER_BACKUP_OPEN_TABLES,"RESTORE"));
   );
 
   /*
     Open and lock the tables.
-    
+
     Note 1: It is important to not do derived tables processing here. Processing
     derived tables even leads to crashes as those reported in BUG#34758.
-  
+
     Note 2: Skiping tmp tables is also important because otherwise a tmp table
     can occlude a regular table with the same name (BUG#33574).
-  */ 
+  */
   ret= open_and_lock_tables_derived(m_thd, m_backup_tables,
-                                    FALSE, /* do not process derived tables */
-                                    MYSQL_OPEN_SKIP_TEMPORARY 
-                                          /* do not open tmp tables */
+                                    FALSE, /* Do not process derived tables. */
+                                    MYSQL_OPEN_SKIP_TEMPORARY
+                                           /* Do not open tmp tables. */
                                    );
   if (ret || is_killed())
     return fatal_error(report_error(ER_BACKUP_OPEN_TABLES,"RESTORE"));
@@ -1133,12 +1127,14 @@ int Backup_restore_ctx::lock_tables_for_
   return 0;
 }
 
+
 /**
   Unlock tables which were locked by @c lock_tables_for_restore.
- */ 
+*/
+
 void Backup_restore_ctx::unlock_tables()
 {
-  // Do nothing if tables are not locked.
+  /* Do nothing if tables are not locked. */
   if (!m_tables_locked)
     return;
 
@@ -1160,7 +1156,7 @@ void Backup_restore_ctx::unlock_tables()
   if (m_backup_tables)
     close_cached_tables(m_thd, m_backup_tables, FALSE, FALSE);
 
-  close_thread_tables(m_thd);                   // Never errors
+  close_thread_tables(m_thd);                   // Never errors.
   m_tables_locked= FALSE;
 
   return;
@@ -1169,16 +1165,17 @@ void Backup_restore_ctx::unlock_tables()
 
 /**
   Destroy a backup/restore context.
-  
+
   This should reverse all settings made when context was created and prepared.
   If it was requested, the backup/restore location is removed. Also, the backup
-  stream memory allocator is shut down. Any other allocated resources are 
+  stream memory allocator is shut down. Any other allocated resources are
   deleted in the destructor. Changes to metadata are unblocked.
-  
+
   @returns 0 or error code if error was detected.
-  
+
   @note This function reports errors.
- */ 
+*/
+
 int Backup_restore_ctx::close()
 {
   int res= 0;
@@ -1190,19 +1187,19 @@ int Backup_restore_ctx::close()
     Note: The standard report_error() method does not log an error in case
     the statement has been interrupted - the interruption is reported instead.
     But we want to always report errors which happen during shutdown phase.
-    Therefore, for reporting errors here we use the variant of 
-    Logger::report_error() with explicit log_level::ERROR. This variant does not 
+    Therefore, for reporting errors here we use the variant of
+    Logger::report_error() with explicit log_level::ERROR. This variant does not
     check for interruptions and always reports given error.
-  */ 
+  */
 
   using namespace backup;
 
   res= m_catalog ? !m_catalog->is_valid() : TRUE;
 
-  // Error code insertion for ER_BACKUP_RESTORE.
+  /* Error code insertion for ER_BACKUP_RESTORE. */
   DBUG_EXECUTE_IF("ER_BACKUP_RESTORE_2", res= 1;);
 
-  // Move context to error state if the catalog became corrupted.
+  /* Move context to error state if the catalog became corrupted. */
   if (res)
     fatal_error(m_type == BACKUP ? ER_BACKUP_BACKUP : ER_BACKUP_RESTORE);
 
@@ -1212,72 +1209,72 @@ int Backup_restore_ctx::close()
   time_t end_time= m_catalog ? m_catalog->get_end_time() : my_time(0);
 
   /*
-    Report end of the operation which has started if it has not been done 
-    before (Logger is in RUNNING state). 
-  */ 
+    Report end of the operation which has started if it has not been done
+    before (Logger is in RUNNING state).
+  */
   if (Logger::m_state == RUNNING)
   {
-    // Report either completion or interruption depending on m_completed flag.
+    /*
+      Report either completion or interruption depending on m_completed
+      flag.
+    */
     if (m_completed)
       report_completed(end_time);
     else
     {
       /*
-        If this is restore operation then m_data_changed flag in the 
+        If this is restore operation then m_data_changed flag in the
         Restore_info object tells if data has been modified or not.
-       */ 
-      const bool data_changed= m_type==RESTORE && m_catalog && 
+      */
+      const bool data_changed= m_type==RESTORE && m_catalog &&
                          static_cast<Restore_info*>(m_catalog)->m_data_changed;
       report_aborted(end_time, data_changed);
     }
   }
 
-  /*
-    Allow slaves connect after restore is complete.
-  */
+  /* Allow slaves connect after restore is complete. */
   obs::disable_slave_connections(FALSE);
 
-  /*
-    Allow replication to start after restore is complete.
-  */
+  /* Allow replication to start after restore is complete. */
   obs::block_replication(FALSE, "");
 
-  /*
-    Turn binlog back on iff it was turned off earlier.
-  */
+  /* Turn binlog back on iff it was turned off earlier. */
   if (m_engage_binlog)
     obs::engage_binlog(TRUE);
 
-  // unlock tables if they are still locked
-  unlock_tables();                              // Never errors
+  /* Unlock tables if they are still locked. */
+  unlock_tables();                              // Never errors.
 
-  // unfreeze metadata
-  obs::bml_release();                           // Never errors
+  /* Unfreeze metadata. */
+  obs::bml_release();                           // Never errors.
 
-  // restore thread options
+  /* Restore thread options. */
 
   m_thd->options= m_thd_options;
 
-  // close or remove stream if not closed already (in which case m_steam is NULL)
+  /*
+    Close or remove stream if not closed already (in which case m_steam is
+    NULL).
+  */
   if (m_stream)
   {
-    /* 
-      If this is backup operation which is not completed (due to error or 
+    /*
+      If this is backup operation which is not completed (due to error or
       interruption), call Stream::remove() so that the underlying file is
-      removed if it was earlier created. Otherwise, just close the stream. 
-    
-      Important: RESTORE should never try to remove the specified backup 
+      removed if it was earlier created. Otherwise, just close the stream.
+
+      Important: RESTORE should never try to remove the specified backup
       image!
     */
     if (!m_completed && m_state == PREPARED_FOR_BACKUP)
     {
-      int ret= m_stream->remove(); // reports errors
+      int ret= m_stream->remove(); // Reports errors.
       if (ret != BSTREAM_OK)
         fatal_error(ER_CANT_DELETE_FILE);
     }
     else
     {
-      int ret= m_stream->close(); // reports errors
+      int ret= m_stream->close();  // Reports errors.
 
       if (ret != BSTREAM_OK)
         fatal_error(ER_BACKUP_CLOSE);
@@ -1291,18 +1288,18 @@ int Backup_restore_ctx::close()
 
   Logger::close();
 
-  /* 
-    Destroy backup stream's memory allocator (this frees memory)
-  
-    Note that from now on data stored in this object might be corrupted. For 
+  /*
+    Destroy backup stream's memory allocator (this frees memory).
+
+    Note that from now on data stored in this object might be corrupted. For
     example the binlog file name is a string stored in memory allocated by
     the allocator which will be freed now.
   */
-  
+
   delete mem_alloc;
   mem_alloc= NULL;
-  
-  // deregister this operation if it was running
+
+  /* Deregister this operation if it was running. */
   pthread_mutex_lock(&run_lock);
   if (current_op == this) {
     current_op= NULL;
@@ -1313,33 +1310,35 @@ int Backup_restore_ctx::close()
   return m_error;
 }
 
+
 /**
   Create backup archive.
-  
+
   @pre @c prepare_for_backup() method was called.
 
   @returns 0 on success, error code otherwise.
 */
+
 int Backup_restore_ctx::do_backup()
 {
   DBUG_ENTER("do_backup");
 
-  // This function should not be called when context is not valid
+  /* This function should not be called when context is not valid. */
   DBUG_ASSERT(is_valid());
   DBUG_ASSERT(m_state == PREPARED_FOR_BACKUP);
   DBUG_ASSERT(m_thd);
   DBUG_ASSERT(m_stream);
   DBUG_ASSERT(m_catalog);
-  
+
   using namespace backup;
 
   int ret;
-  Output_stream &s= *static_cast<Output_stream*>(m_stream);
+  Output_stream &s=    *static_cast<Output_stream*>(m_stream);
   Backup_info   &info= *static_cast<Backup_info*>(m_catalog);
 
   DEBUG_SYNC(m_thd, "before_backup_meta");
 
-  report_stats_pre(info);                       // Never errors
+  report_stats_pre(info);                       // Never errors.
 
   if (report_killed())
     DBUG_RETURN(fatal_error(ER_QUERY_INTERRUPTED));
@@ -1349,9 +1348,9 @@ int Backup_restore_ctx::do_backup()
 
   ret= write_preamble(info, s);  // Can Log errors via callback functions.
 
-  // Error condition insertion for ER_BACKUP_WRITE_HEADER.
+  /* Error condition insertion for ER_BACKUP_WRITE_HEADER. */
   DBUG_EXECUTE_IF("ER_BACKUP_WRITE_HEADER_1", ret= 1;);
- 
+
   if (ret || is_killed())
   {
     if (report_killed())
@@ -1365,7 +1364,8 @@ int Backup_restore_ctx::do_backup()
 
   DEBUG_SYNC(m_thd, "before_backup_data");
 
-  ret= write_table_data(m_thd, info, s); // logs errors and detects interruptions
+  // Logs errors and detects interruptions.
+  ret= write_table_data(m_thd, info, s);
   if (ret)
     DBUG_RETURN(fatal_error(ret));
 
@@ -1376,9 +1376,9 @@ int Backup_restore_ctx::do_backup()
   DBUG_PRINT("backup",("Writing summary"));
 
   DEBUG_SYNC(m_thd, "before_backup_summary");
-  ret= write_summary(info, s);  
+  ret= write_summary(info, s);
 
-  // Error condition insertion for ER_BACKUP_WRITE_SUMMARY.
+  /* Error condition insertion for ER_BACKUP_WRITE_SUMMARY. */
   DBUG_EXECUTE_IF("ER_BACKUP_WRITE_SUMMARY", ret= 1;);
 
   if (ret || is_killed())
@@ -1393,20 +1393,22 @@ int Backup_restore_ctx::do_backup()
   DBUG_RETURN(close());
 }
 
+
 /**
   Create all triggers and events from restore catalogue.
 
-  This helper method iterates over all triggers and events stored in the 
-  restore catalogue and creates them. When metadata section of the backup image 
-  is read, trigger and event objects are materialized and stored in the 
-  catalogue but they are not executed then (see @c bcat_create_item()). 
-  This method can be used to re-create the corresponding server objects after 
+  This helper method iterates over all triggers and events stored in the
+  restore catalogue and creates them. When metadata section of the backup image
+  is read, trigger and event objects are materialized and stored in the
+  catalogue but they are not executed then (see @c bcat_create_item()).
+  This method can be used to re-create the corresponding server objects after
   all other objects and table data have been restored.
 
   Note that we first restore all triggers and then the events.
 
   @returns 0 on success, error code otherwise.
-*/ 
+*/
+
 int Backup_restore_ctx::restore_triggers_and_events()
 {
   using namespace backup;
@@ -1418,7 +1420,7 @@ int Backup_restore_ctx::restore_triggers
   Image_info::Obj *obj;
   List<Image_info::Obj> events;
   Image_info::Obj::describe_buf buf;
-  // Note: The two iterators below must be deleted upon exit.
+  /* Note: The two iterators below must be deleted upon exit. */
   Image_info::Iterator *trgit= NULL;
   Image_info::Iterator *dbit= m_catalog->get_dbs();
   if (!dbit || is_killed())
@@ -1427,9 +1429,9 @@ int Backup_restore_ctx::restore_triggers
     goto exit;
   }
 
-  // create all trigers and collect events in the events list
-  
-  while ((obj= (*dbit)++)) 
+  /* Create all trigers and collect events in the events list. */
+
+  while ((obj= (*dbit)++))
   {
     trgit= m_catalog->get_db_objects(*static_cast<Image_info::Db*>(obj));
     if (!trgit || is_killed())
@@ -1440,23 +1442,23 @@ int Backup_restore_ctx::restore_triggers
 
     while ((obj= (*trgit)++))
       switch (obj->type()) {
-      
+
       case BSTREAM_IT_EVENT:
         DBUG_ASSERT(obj->m_obj_ptr);
         if (events.push_back(obj))
         {
-          // Error has been reported, but not logged to backup logs
+          /* Error has been reported, but not logged to backup logs. */
           fatal_error(log_error(ER_OUT_OF_RESOURCES));
-          goto exit; 
+          goto exit;
         }
         break;
-      
+
       case BSTREAM_IT_TRIGGER:
       {
         DBUG_ASSERT(obj->m_obj_ptr);
         int ret= obj->m_obj_ptr->create(m_thd);
-        /* Mimic error in restore of trigger */
-        DBUG_EXECUTE_IF("restore_trigger", ret= TRUE;); 
+        /* Mimic error in restore of trigger. */
+        DBUG_EXECUTE_IF("restore_trigger", ret= TRUE;);
         if (ret || is_killed())
         {
           fatal_error(report_error(ER_BACKUP_CANT_RESTORE_TRIGGER,
@@ -1465,7 +1467,8 @@ int Backup_restore_ctx::restore_triggers
         }
         break;
       }
-      default: break;      
+
+      default: break;
       }
 
     delete trgit;
@@ -1475,34 +1478,35 @@ int Backup_restore_ctx::restore_triggers
   delete dbit;
   dbit= NULL;
 
-  // now create all events
-  
+  /* Now create all events. */
+
   {
     List_iterator<Image_info::Obj> it(events);
     Image_info::Obj *ev;
 
     while ((ev= it++))
     {
-      int ret= ev->m_obj_ptr->create(m_thd); 
+      int ret= ev->m_obj_ptr->create(m_thd);
 
       DBUG_EXECUTE_IF("ER_BACKUP_CANT_RESTORE_EVENT_1", ret= 1;);
 
       if (ret || is_killed())
       {
-        fatal_error(report_error(ER_BACKUP_CANT_RESTORE_EVENT,ev->describe(buf)));
+        fatal_error(report_error(ER_BACKUP_CANT_RESTORE_EVENT,
+                                 ev->describe(buf)));
         goto exit;
       }
     }
   }
 
-  /* 
+  /*
     FIXME: this call is here because object services doesn't clean the
     statement execution context properly, which leads to assertion failure.
     It should be fixed inside object services implementation and then the
     following line should be removed (see BUG#41294).
-   */
-  close_thread_tables(m_thd);                   // Never errors
-  m_thd->clear_error();                         // Never errors
+  */
+  close_thread_tables(m_thd);                   // Never errors.
+  m_thd->clear_error();                         // Never errors.
 
 exit:
 
@@ -1511,6 +1515,7 @@ exit:
   DBUG_RETURN(m_error);
 }
 
+
 /**
   Restore objects saved in backup image.
 
@@ -1523,6 +1528,7 @@ exit:
 
   @todo Remove the @c reset_diagnostic_area() hack.
 */
+
 int Backup_restore_ctx::do_restore(bool overwrite)
 {
   DBUG_ENTER("do_restore");
@@ -1536,19 +1542,19 @@ int Backup_restore_ctx::do_restore(bool 
   using namespace backup;
 
   int err;
-  Input_stream &s= *static_cast<Input_stream*>(m_stream);
+  Input_stream &s=    *static_cast<Input_stream*>(m_stream);
   Restore_info &info= *static_cast<Restore_info*>(m_catalog);
 
   DEBUG_SYNC(m_thd, "start_do_restore");
 
-  report_stats_pre(info);                       // Never errors
+  report_stats_pre(info);                       // Never errors.
 
   if (report_killed())
     DBUG_RETURN(fatal_error(ER_QUERY_INTERRUPTED));
 
   DBUG_PRINT("restore", ("Restoring metadata"));
 
-  // unless RESTORE... OVERWRITE: return error if database already exists
+  /* Unless RESTORE... OVERWRITE: return error if database already exists. */
   if (!overwrite)
   {
     Image_info::Db_iterator *dbit= info.get_dbs();
@@ -1560,7 +1566,7 @@ int Backup_restore_ctx::do_restore(bool 
     while ((mydb= static_cast<Image_info::Db*>((*dbit)++)))
     {
       err= obs::check_db_existence(m_thd, &mydb->name());
-      if (!err || is_killed()) 
+      if (!err || is_killed())
       {
         delete dbit;
         err= report_error(ER_RESTORE_DB_EXISTS, mydb->name().ptr());
@@ -1571,7 +1577,7 @@ int Backup_restore_ctx::do_restore(bool 
   }
 
   DEBUG_SYNC(m_thd, "before_restore_fkey_disable");
-  disable_fkey_constraints();                   // Never errors
+  disable_fkey_constraints();                   // Never errors.
 
   if (report_killed())
     DBUG_RETURN(fatal_error(ER_QUERY_INTERRUPTED));
@@ -1588,7 +1594,7 @@ int Backup_restore_ctx::do_restore(bool 
   }
 
   err= s.next_chunk();
-  /* Mimic error in next_chunk */
+  /* Mimic error in next_chunk. */
   DBUG_EXECUTE_IF("restore_stream_next_chunk", err= BSTREAM_ERROR; );
   if (err == BSTREAM_ERROR || is_killed())
   {
@@ -1598,32 +1604,33 @@ int Backup_restore_ctx::do_restore(bool 
   DBUG_PRINT("restore",("Restoring table data"));
 
   DEBUG_SYNC(m_thd, "before_restore_locks_tables");
-  err= lock_tables_for_restore();               // logs errors
+  err= lock_tables_for_restore();               // Logs errors.
   if (err || is_killed())
     DBUG_RETURN(fatal_error(report_killed() ? ER_QUERY_INTERRUPTED : err));
 
   DEBUG_SYNC(m_thd, "after_restore_locks_tables");
-  /* 
-   Here restore drivers are created to restore table data. Data is being
-   (potentially) changed so we set m_data_changed flag.
+  /*
+    Here restore drivers are created to restore table data. Data is being
+    (potentially) changed so we set m_data_changed flag.
   */
   info.m_data_changed= TRUE;
   DEBUG_SYNC(m_thd, "before_restore_table_data");
-  err= restore_table_data(m_thd, info, s);      // logs errors
+  err= restore_table_data(m_thd, info, s);      // Logs errors.
 
-  unlock_tables();                              // Never errors
+  unlock_tables();                              // Never errors.
   if (err || is_killed())
     DBUG_RETURN(fatal_error(report_killed() ? ER_QUERY_INTERRUPTED : err));
 
-  /* 
-   Re-create all triggers and events (it was not done in @c bcat_create_item()).
+  /*
+    Re-create all triggers and events (it was not done in
+    @c bcat_create_item()).
 
-   Note: it is important to do that after tables are unlocked, otherwise 
-   creation of these objects will fail.
+    Note: it is important to do that after tables are unlocked, otherwise
+    creation of these objects will fail.
   */
 
   DEBUG_SYNC(m_thd, "before_restore_triggers");
-  err= restore_triggers_and_events();   // logs errors and detects interruptions
+  err= restore_triggers_and_events();  // Logs errors and detects interruptions.
   if (err)
      DBUG_RETURN(fatal_error(err));
 
@@ -1639,9 +1646,10 @@ int Backup_restore_ctx::do_restore(bool 
   /*
     Report validity point time and binlog position stored in the backup image
     (in the summary section).
-   */ 
+  */
 
-  report_vp_time(info.get_vp_time(), FALSE); // FALSE = do not write to progress log
+  report_vp_time(info.get_vp_time(),
+                 FALSE /* Do not write to progress log. */);
   if (info.flags & BSTREAM_FLAG_BINLOG)
     report_binlog_info(info.binlog_info);
 
@@ -1650,40 +1658,49 @@ int Backup_restore_ctx::do_restore(bool 
   DBUG_RETURN(close());
 }
 
+
 /**
   Report stream open error and move context object into error state.
-  
+
   @return error code given as input or the one stored in the context
   object if a fatal error has already been reported.
- */ 
+*/
+
 int Backup_restore_ctx::report_stream_open_failure(int my_open_status,
                                                    const LEX_STRING *location)
 {
   int error= 0;
+
   switch (my_open_status) {
-    case ER_OPTION_PREVENTS_STATEMENT:
-      error= report_error(ER_OPTION_PREVENTS_STATEMENT, "--secure-backup-file-priv");
-      break;
-    case ER_BACKUP_WRITE_LOC:
-      /*
-        For this error, use the actual value returned instead of the
-        path complimented with backupdir.
-      */
-      error= report_error(ER_BACKUP_WRITE_LOC, location->str);
-      break;
-    case ER_BACKUP_READ_LOC:
-      /*
-        For this error, use the actual value returned instead of the
-        path complimented with backupdir.
-      */
-      error= report_error(ER_BACKUP_READ_LOC, location->str);
-      break;
-    default:
-      DBUG_ASSERT(FALSE);
+
+  case ER_OPTION_PREVENTS_STATEMENT:
+    error= report_error(ER_OPTION_PREVENTS_STATEMENT,
+                        "--secure-backup-file-priv");
+    break;
+
+  case ER_BACKUP_WRITE_LOC:
+    /*
+      For this error, use the actual value returned instead of the
+      path complimented with backupdir.
+    */
+    error= report_error(ER_BACKUP_WRITE_LOC, location->str);
+    break;
+
+  case ER_BACKUP_READ_LOC:
+    /*
+      For this error, use the actual value returned instead of the
+      path complimented with backupdir.
+    */
+    error= report_error(ER_BACKUP_READ_LOC, location->str);
+    break;
+
+  default:
+    DBUG_ASSERT(FALSE);
   }
   return fatal_error(error);
 }
 
+
 namespace backup {
 
 /*************************************************
@@ -1692,17 +1709,24 @@ namespace backup {
 
  *************************************************/
 
-/// All allocated memory segments are linked into a list using this structure.
+/**
+  All allocated memory segments are linked into a list using this
+  structure.
+*/
+
 struct Mem_allocator::node
 {
-  node *prev;   ///< pointer to previous node in list
-  node *next;   ///< pointer to next node in the list
+  node *prev;   ///< Pointer to previous node in list.
+  node *next;   ///< Pointer to next node in the list.
 };
 
+
 Mem_allocator::Mem_allocator() :first(NULL)
 {}
 
-/// Deletes all allocated segments which have not been freed explicitly.
+
+/** Deletes all allocated segments which have not been freed explicitly. */
+
 Mem_allocator::~Mem_allocator()
 {
   node *n= first;
@@ -1715,6 +1739,7 @@ Mem_allocator::~Mem_allocator()
   }
 }
 
+
 /**
   Allocate memory segment of given size.
 
@@ -1722,6 +1747,7 @@ Mem_allocator::~Mem_allocator()
   to previous and next segment in the segments list. This is used when
   deallocating allocated memory in the destructor.
 */
+
 void* Mem_allocator::alloc(size_t howmuch)
 {
   void *ptr= my_malloc(sizeof(node) + howmuch, MYF(0));
@@ -1741,6 +1767,7 @@ void* Mem_allocator::alloc(size_t howmuc
   return ptr;
 }
 
+
 /**
   Explicit deallocation of previously allocated segment.
 
@@ -1749,6 +1776,7 @@ void* Mem_allocator::alloc(size_t howmuc
 
   The deallocated fragment is removed from the allocated fragments list.
 */
+
 void Mem_allocator::free(void *ptr)
 {
   if (!ptr)
@@ -1780,33 +1808,35 @@ void Mem_allocator::free(void *ptr)
 /**
   Memory allocator for backup stream library.
 
-  @pre A backup/restore context has been created and prepared for the 
-  operation (one of @c Backup_restore_ctx::prepare_for_backup() or 
+  @pre A backup/restore context has been created and prepared for the
+  operation (one of @c Backup_restore_ctx::prepare_for_backup() or
   @c Backup_restore_ctx::prepare_for_restore() have been called).
- */
+*/
+
 extern "C"
 bstream_byte* bstream_alloc(unsigned long int size)
 {
   using namespace backup;
 
-  DBUG_ASSERT(Backup_restore_ctx::current_op 
+  DBUG_ASSERT(Backup_restore_ctx::current_op
               && Backup_restore_ctx::current_op->mem_alloc);
 
   return (bstream_byte*)Backup_restore_ctx::current_op->mem_alloc->alloc(size);
 }
 
-/**
-  Memory deallocator for backup stream library.
-*/
+
+/** Memory deallocator for backup stream library. */
+
 extern "C"
 void bstream_free(bstream_byte *ptr)
 {
   using namespace backup;
-  if (Backup_restore_ctx::current_op 
+  if (Backup_restore_ctx::current_op
       && Backup_restore_ctx::current_op->mem_alloc)
     Backup_restore_ctx::current_op->mem_alloc->free(ptr);
 }
 
+
 /**
   Prepare restore catalogue for populating it with items read from
   backup image.
@@ -1819,12 +1849,13 @@ void bstream_free(bstream_byte *ptr)
 
   @returns 0 on success, error code otherwise.
 */
+
 extern "C"
 int bcat_reset(st_bstream_image_header *catalogue)
 {
   using namespace backup;
 
-  uint n;
+  uint n;       // Snapshot number.
 
   DBUG_ASSERT(catalogue);
   Restore_info *info= static_cast<Restore_info*>(catalogue);
@@ -1832,10 +1863,10 @@ int bcat_reset(st_bstream_image_header *
 
   /*
     Iterate over the list of snapshots read from the backup image (and stored
-    in snapshot[] array in the catalogue) and for each snapshot create a 
+    in snapshot[] array in the catalogue) and for each snapshot create a
     corresponding Snapshot_info instance. A pointer to this instance is stored
     in m_snap[] array.
-   */ 
+  */
 
   for (n=0; n < info->snap_count(); ++n)
   {
@@ -1843,18 +1874,19 @@ int bcat_reset(st_bstream_image_header *
 
     DBUG_PRINT("restore",("Creating info for snapshot no. %d", n));
 
-    // Error code insertion for ER_BACKUP_UNKNOWN_BE.
+    /* Error code insertion for ER_BACKUP_UNKNOWN_BE. */
     DBUG_EXECUTE_IF("ER_BACKUP_UNKNOWN_BE", snap->type= BI_UNKNOWN;);
 
     switch (snap->type) {
 
     case BI_NATIVE:
     {
-      backup::LEX_STRING name_lex(snap->engine.name.begin, snap->engine.name.end);
+      backup::LEX_STRING name_lex(snap->engine.name.begin, 
+                                  snap->engine.name.end);
       storage_engine_ref se= get_se_by_name(name_lex);
       handlerton *hton= se_hton(se);
 
-      // Error condition insertion for ER_BACKUP_CANT_FIND_SE.
+      /* Error condition insertion for ER_BACKUP_CANT_FIND_SE. */
       DBUG_EXECUTE_IF("ER_BACKUP_CANT_FIND_SE", se= 0;);
 
       if (!se || !hton)
@@ -1865,7 +1897,7 @@ int bcat_reset(st_bstream_image_header *
 
       int res= !hton->get_backup_engine;
 
-      // Error code insertion for ER_BACKUP_NO_NATIVE_BE.
+      /* Error code insertion for ER_BACKUP_NO_NATIVE_BE. */
       DBUG_EXECUTE_IF("ER_BACKUP_NO_NATIVE_BE", res= 1;);
 
       if (res)
@@ -1875,27 +1907,27 @@ int bcat_reset(st_bstream_image_header *
       }
 
       info->m_snap[n]= new Native_snapshot(log, snap->version, se);
-                                                              // reports errors
+                                                              // Reports errors.
       break;
     }
 
     case BI_NODATA:
       info->m_snap[n]= new Nodata_snapshot(log, snap->version);
-                                                              // reports errors
+                                                              // Reports errors.
       break;
 
     case BI_CS:
       info->m_snap[n]= new CS_snapshot(log, snap->version);
-                                                              // reports errors
+                                                              // Reports errors.
       break;
 
     case BI_DEFAULT:
       info->m_snap[n]= new Default_snapshot(log, snap->version);
-                                                              // reports errors
+                                                              // Reports errors.
       break;
 
     default:
-      // note: we use convention that snapshots are counted starting from 1.
+      /* Note: we use convention that snapshots are counted starting from 1. */
       log.report_error(ER_BACKUP_UNKNOWN_BE, n + 1);
       return BSTREAM_ERROR;
     }
@@ -1913,37 +1945,41 @@ int bcat_reset(st_bstream_image_header *
   return BSTREAM_OK;
 }
 
+
 /**
   Called after reading backup image's catalogue and before processing
   metadata and table data.
 
   Nothing to do here.
 */
+
 extern "C"
 int bcat_close(st_bstream_image_header *catalogue)
 {
   return BSTREAM_OK;
 }
 
+
 /**
   Add item to restore catalogue.
 
   @todo Report errors.
 */
+
 extern "C"
-int bcat_add_item(st_bstream_image_header *catalogue, 
+int bcat_add_item(st_bstream_image_header *catalogue,
                   struct st_bstream_item_info *item)
 {
   using namespace backup;
 
   Restore_info *info= static_cast<Restore_info*>(catalogue);
-  Logger &log= info->m_log;
+  Logger       &log=  info->m_log;
 
   backup::String name_str(item->name.begin, item->name.end);
 
   DBUG_EXECUTE_IF("restore_catalog_uppercase_names",
                   my_caseup_str(system_charset_info, name_str.c_ptr());
-                  );
+                 );
   DBUG_PRINT("restore",("Adding item %s of type %d (pos=%ld)",
                         item->name.begin,
                         item->type,
@@ -1953,7 +1989,7 @@ int bcat_add_item(st_bstream_image_heade
 
   case BSTREAM_IT_TABLESPACE:
   {
-    Image_info::Ts *ts= info->add_ts(name_str, item->pos); // reports errors
+    Image_info::Ts *ts= info->add_ts(name_str, item->pos); // Reports errors.
 
     return ts ? BSTREAM_OK : BSTREAM_ERROR;
   }
@@ -1963,7 +1999,7 @@ int bcat_add_item(st_bstream_image_heade
 
     if (lower_case_table_names == 1)
       my_casedn_str(system_charset_info, name_str.c_ptr());
-    Image_info::Db *db= info->add_db(name_str, item->pos); // reports errors
+    Image_info::Db *db= info->add_db(name_str, item->pos); // Reports errors.
 
     return db ? BSTREAM_OK : BSTREAM_ERROR;
   }
@@ -1974,24 +2010,24 @@ int bcat_add_item(st_bstream_image_heade
 
     DBUG_PRINT("restore",(" table's snapshot no. is %d", it->snap_num));
 
-    // Error code insertion for ER_BACKUP_WRONG_TABLE_BE.
+    /* Error code insertion for ER_BACKUP_WRONG_TABLE_BE. */
     DBUG_EXECUTE_IF("ER_BACKUP_WRONG_TABLE_BE", it->snap_num= 99;);
 
     Snapshot_info *snap= info->m_snap[it->snap_num];
 
     if (!snap)
     {
-      /* 
+      /*
         This can happen only if the snapshot number is too big - if we failed
         to create one of the snapshots listed in image's header we would stop
         with error earlier.
-       */
+      */
       DBUG_ASSERT(it->snap_num >= info->snap_count());
       log.report_error(ER_BACKUP_WRONG_TABLE_BE, it->snap_num + 1);
       return BSTREAM_ERROR;
     }
 
-    Image_info::Db *db= info->get_db(it->base.db->base.pos); // reports errors
+    Image_info::Db *db= info->get_db(it->base.db->base.pos); // Reports errors.
 
     if (!db)
       return BSTREAM_ERROR;
@@ -2000,9 +2036,9 @@ int bcat_add_item(st_bstream_image_heade
 
     if (lower_case_table_names == 1)
       my_casedn_str(system_charset_info, name_str.c_ptr());
-    Image_info::Table *tbl= info->add_table(*db, name_str, *snap, item->pos); 
-                                                             // reports errors
-    
+    Image_info::Table *tbl= info->add_table(*db, name_str, *snap, item->pos);
+                                                             // Reports errors.
+
     return tbl ? BSTREAM_OK : BSTREAM_ERROR;
   }
 
@@ -2014,20 +2050,20 @@ int bcat_add_item(st_bstream_image_heade
   case BSTREAM_IT_PRIVILEGE:
   {
     st_bstream_dbitem_info *it= (st_bstream_dbitem_info*)item;
-    
+
     DBUG_ASSERT(it->db);
-    
+
     Image_info::Db *db= (Image_info::Db*) info->get_db(it->db->base.pos);
-  
+
     DBUG_ASSERT(db);
-    
+
     Image_info::Dbobj *it1= info->add_db_object(*db, item->type, name_str,
                                                 item->pos);
     if (!it1)
       return BSTREAM_ERROR;
-    
+
     return BSTREAM_OK;
-  }   
+  }
 
   default:
     return BSTREAM_OK;
@@ -2035,6 +2071,7 @@ int bcat_add_item(st_bstream_image_heade
   } // switch (item->type)
 }
 
+
 /*****************************************************************
 
    Iterators
@@ -2044,54 +2081,55 @@ int bcat_add_item(st_bstream_image_heade
 static uint cset_iter;  ///< Used to implement trivial charset iterator.
 static uint null_iter;  ///< Used to implement trivial empty iterator.
 
-/// Return pointer to an instance of iterator of a given type.
+/** Return pointer to an instance of iterator of a given type. */
+
 extern "C"
 void* bcat_iterator_get(st_bstream_image_header *catalogue, unsigned int type)
 {
-  typedef backup::Image_info::Iterator Iterator; // to save some typing
+  typedef backup::Image_info::Iterator Iterator; // To save some typing.
 
   DBUG_ASSERT(catalogue);
 
-  Backup_info *info= static_cast<Backup_info*>(catalogue);
-  backup::Logger &log= info->m_log;
+  Backup_info    *info= static_cast<Backup_info*>(catalogue);
+  backup::Logger &log=  info->m_log;
 
   switch (type) {
 
-  case BSTREAM_IT_CHARSET:  // character sets
+  case BSTREAM_IT_CHARSET:              // Character sets.
     cset_iter= 0;
     return &cset_iter;
 
-  case BSTREAM_IT_USER:     // users
+  case BSTREAM_IT_USER:                 // Users.
     return &null_iter;
 
-  case BSTREAM_IT_TABLESPACE:     // table spaces
+  case BSTREAM_IT_TABLESPACE:           // Table spaces.
   {
     Iterator *it= info->get_tablespaces();
-    if (!it) 
+    if (!it)
     {
       log.report_error(ER_OUT_OF_RESOURCES);
       return NULL;
     }
-  
+
     return it;
   }
 
-  case BSTREAM_IT_DB:       // all databases
+  case BSTREAM_IT_DB:                   // All databases.
   {
     Iterator *it= info->get_dbs();
-    if (!it) 
+    if (!it)
     {
       log.report_error(ER_OUT_OF_RESOURCES);
       return NULL;
     }
 
-    return it;  
+    return it;
   }
-  
-  case BSTREAM_IT_PERDB:    // per-db objects, except tables
+
+  case BSTREAM_IT_PERDB:                // Per-db objects, except tables.
   {
     Iterator *it= info->get_perdb();
-  
+
     // Error condition insertion for ER_BACKUP_CAT_ENUM.
     DBUG_EXECUTE_IF("ER_BACKUP_CAT_ENUM", it= 0;);
 
@@ -2104,27 +2142,31 @@ void* bcat_iterator_get(st_bstream_image
     return it;
   }
 
-  case BSTREAM_IT_GLOBAL:   // all global objects
+  case BSTREAM_IT_GLOBAL:               // All global objects.
   {
     Iterator *it= info->get_global();
 
-    return it;      // if (!it), error has been logged in get_global()
+    return it;      // If (!it), error has been logged in get_global().
   }
 
   default:
     return NULL;
-
   }
 }
 
-/// Return next item pointed by a given iterator and advance it to the next positon.
+
+/**
+  Return next item pointed by a given iterator and advance it to the next
+  positon.
+*/
+
 extern "C"
 struct st_bstream_item_info*
 bcat_iterator_next(st_bstream_image_header *catalogue, void *iter)
 {
   using namespace backup;
 
-  /* If this is the null iterator, return NULL immediately */
+  /* If this is the null iterator, return NULL immediately. */
   if (iter == &null_iter)
     return NULL;
 
@@ -2152,12 +2194,13 @@ bcat_iterator_next(st_bstream_image_head
   /*
     In all other cases assume that iter points at instance of
     @c Image_info::Iterator and use this instance to get next item.
-   */
+  */
   const Image_info::Obj *ptr= (*(Image_info::Iterator*)iter)++;
 
   return ptr ? (st_bstream_item_info*)(ptr->info()) : NULL;
 }
 
+
 extern "C"
 void  bcat_iterator_free(st_bstream_image_header *catalogue, void *iter)
 {
@@ -2174,24 +2217,26 @@ void  bcat_iterator_free(st_bstream_imag
   delete (backup::Image_info::Iterator*)iter;
 }
 
+
 /* db-items iterator */
 
-/** 
-  Return pointer to an iterator for iterating over objects inside a given 
+/**
+  Return pointer to an iterator for iterating over objects inside a given
   database.
- */
+*/
+
 extern "C"
 void* bcat_db_iterator_get(st_bstream_image_header *catalogue,
                            st_bstream_db_info *dbi)
 {
   DBUG_ASSERT(catalogue);
   DBUG_ASSERT(dbi);
-  
+
   Backup_info *info= static_cast<Backup_info*>(catalogue);
   backup::Logger &log= info->m_log;
   Backup_info::Db *db = info->get_db(dbi->base.pos);
 
-  // Error code insertion for ER_BACKUP_UNKNOWN_OBJECT.
+  /* Error code insertion for ER_BACKUP_UNKNOWN_OBJECT. */
   DBUG_EXECUTE_IF("ER_BACKUP_UNKNOWN_OBJECT", db= 0;);
 
   if (!db)
@@ -2210,6 +2255,7 @@ void* bcat_db_iterator_get(st_bstream_im
   return it;
 }
 
+
 extern "C"
 struct st_bstream_dbitem_info*
 bcat_db_iterator_next(st_bstream_image_header *catalogue,
@@ -2221,6 +2267,7 @@ bcat_db_iterator_next(st_bstream_image_h
   return ptr ? (st_bstream_dbitem_info*)ptr->info() : NULL;
 }
 
+
 extern "C"
 void  bcat_db_iterator_free(st_bstream_image_header *catalogue,
                             st_bstream_db_info *db,
@@ -2242,7 +2289,8 @@ void  bcat_db_iterator_free(st_bstream_i
 
   @todo Decide what to do if unknown item type is found. Right now we
   bail out.
- */ 
+*/
+
 extern "C"
 int bcat_create_item(st_bstream_image_header *catalogue,
                      struct st_bstream_item_info *item,
@@ -2256,33 +2304,33 @@ int bcat_create_item(st_bstream_image_he
   DBUG_ASSERT(item);
 
   Restore_info *info= static_cast<Restore_info*>(catalogue);
-  Logger &log= info->m_log;
-  THD *thd= info->m_thd;
-  int create_err= 0;
+  Logger       &log=  info->m_log;
+  THD          *thd=  info->m_thd;
+  int          create_err= 0;
 
   /*
-    Check for interruption before creating (and thus first destroying) 
+    Check for interruption before creating (and thus first destroying)
     next object.
-  */ 
+  */
   if (log.report_killed())
     return BSTREAM_ERROR;
 
-  // Error code insertion for ER_BACKUP_UNKNOWN_OBJECT_TYPE.
-  DBUG_EXECUTE_IF("ER_BACKUP_UNKNOWN_OBJECT_TYPE", 
-    item->type= BSTREAM_IT_LAST;);
+  /* Error code insertion for ER_BACKUP_UNKNOWN_OBJECT_TYPE. */
+  DBUG_EXECUTE_IF("ER_BACKUP_UNKNOWN_OBJECT_TYPE",
+                  item->type= BSTREAM_IT_LAST;);
 
   switch (item->type) {
-  
-  case BSTREAM_IT_DB:     create_err= ER_BACKUP_CANT_RESTORE_DB; break;
-  case BSTREAM_IT_TABLE:  create_err= ER_BACKUP_CANT_RESTORE_TABLE; break;
-  case BSTREAM_IT_VIEW:   create_err= ER_BACKUP_CANT_RESTORE_VIEW; break;
-  case BSTREAM_IT_SPROC:  create_err= ER_BACKUP_CANT_RESTORE_SROUT; break;
-  case BSTREAM_IT_SFUNC:  create_err= ER_BACKUP_CANT_RESTORE_SROUT; break;
-  case BSTREAM_IT_EVENT:  create_err= ER_BACKUP_CANT_RESTORE_EVENT; break;
-  case BSTREAM_IT_TRIGGER: create_err= ER_BACKUP_CANT_RESTORE_TRIGGER; break;
+
+  case BSTREAM_IT_DB:         create_err= ER_BACKUP_CANT_RESTORE_DB; break;
+  case BSTREAM_IT_TABLE:      create_err= ER_BACKUP_CANT_RESTORE_TABLE; break;
+  case BSTREAM_IT_VIEW:       create_err= ER_BACKUP_CANT_RESTORE_VIEW; break;
+  case BSTREAM_IT_SPROC:      create_err= ER_BACKUP_CANT_RESTORE_SROUT; break;
+  case BSTREAM_IT_SFUNC:      create_err= ER_BACKUP_CANT_RESTORE_SROUT; break;
+  case BSTREAM_IT_EVENT:      create_err= ER_BACKUP_CANT_RESTORE_EVENT; break;
+  case BSTREAM_IT_TRIGGER:    create_err= ER_BACKUP_CANT_RESTORE_TRIGGER; break;
   case BSTREAM_IT_TABLESPACE: create_err= ER_BACKUP_CANT_RESTORE_TS; break;
-  case BSTREAM_IT_PRIVILEGE: create_err= ER_BACKUP_CANT_RESTORE_PRIV; break;
-  
+  case BSTREAM_IT_PRIVILEGE:  create_err= ER_BACKUP_CANT_RESTORE_PRIV; break;
+
   /*
     TODO: Decide what to do when we come across unknown item:
     break the restore process as it is done now or continue
@@ -2291,7 +2339,7 @@ int bcat_create_item(st_bstream_image_he
 
   default:
     log.report_error(ER_BACKUP_UNKNOWN_OBJECT_TYPE);
-    return BSTREAM_ERROR;    
+    return BSTREAM_ERROR;
   }
 
   Image_info::Obj *obj= find_obj(*info, *item);
@@ -2309,7 +2357,7 @@ int bcat_create_item(st_bstream_image_he
   /*
     Note: The instance created by Image_info::Obj::materialize() is deleted
     when *info is destroyed.
-   */ 
+  */
   obs::Obj *sobj= obj->materialize(0, sdata);
 
   Image_info::Obj::describe_buf buf;
@@ -2318,7 +2366,7 @@ int bcat_create_item(st_bstream_image_he
 #if !defined(DBUG_OFF)
 
   /*
-    Debug insertion for errors. Here we setup the error to correspond 
+    Debug insertion for errors. Here we setup the error to correspond
     with the debug SESSION tag specified in the test.
 
     Note: Error code insertion won't work here as we need to generate
@@ -2326,12 +2374,12 @@ int bcat_create_item(st_bstream_image_he
   */
   ::String str;
   switch (item->type) {
-  case BSTREAM_IT_DB: str.append("ER_BACKUP_CANT_RESTORE_DB"); break;
-  case BSTREAM_IT_TABLE: str.append("ER_BACKUP_CANT_RESTORE_TABLE"); break;
-  case BSTREAM_IT_VIEW: str.append("ER_BACKUP_CANT_RESTORE_VIEW"); break;
-  case BSTREAM_IT_SPROC: str.append("ER_BACKUP_CANT_RESTORE_SROUT_P"); break;
-  case BSTREAM_IT_SFUNC: str.append("ER_BACKUP_CANT_RESTORE_SROUT_F"); break;
-  case BSTREAM_IT_EVENT: str.append("ER_BACKUP_CANT_RESTORE_EVENT_2"); break;
+  case BSTREAM_IT_DB:      str.append("ER_BACKUP_CANT_RESTORE_DB"); break;
+  case BSTREAM_IT_TABLE:   str.append("ER_BACKUP_CANT_RESTORE_TABLE"); break;
+  case BSTREAM_IT_VIEW:    str.append("ER_BACKUP_CANT_RESTORE_VIEW"); break;
+  case BSTREAM_IT_SPROC:   str.append("ER_BACKUP_CANT_RESTORE_SROUT_P"); break;
+  case BSTREAM_IT_SFUNC:   str.append("ER_BACKUP_CANT_RESTORE_SROUT_F"); break;
+  case BSTREAM_IT_EVENT:   str.append("ER_BACKUP_CANT_RESTORE_EVENT_2"); break;
   case BSTREAM_IT_TRIGGER: str.append("ER_BACKUP_CANT_RESTORE_TRIGGER"); break;
   default: break;
   }
@@ -2341,9 +2389,9 @@ int bcat_create_item(st_bstream_image_he
       log.report_error(create_err, desc);
       return BSTREAM_ERROR;);
   }
-  // Tablespace is a special case since Falcon is disabled.
+  /* Tablespace is a special case since Falcon is disabled. */
   DBUG_EXECUTE_IF("ER_BACKUP_CANT_RESTORE_TS",
-    log.report_error(ER_BACKUP_CANT_RESTORE_TS, 
+    log.report_error(ER_BACKUP_CANT_RESTORE_TS,
       "Debug insertion test");
     return BSTREAM_ERROR;);
 
@@ -2353,12 +2401,12 @@ int bcat_create_item(st_bstream_image_he
      would be deterministic.
   */
   DBUG_EXECUTE_IF("ER_BACKUP_CANT_RESTORE_PRIV",
-    log.report_error(ER_BACKUP_CANT_RESTORE_PRIV, 
+    log.report_error(ER_BACKUP_CANT_RESTORE_PRIV,
       "Debug insertion test");
     return BSTREAM_ERROR;);
 
 #endif
-  
+
   if (!sobj)
   {
     log.report_error(create_err, desc);
@@ -2369,8 +2417,8 @@ int bcat_create_item(st_bstream_image_he
     If the item we are creating is an event or trigger, we don't execute it
     yet. It will be done in @c Backup_restore_ctx::do_restore() after table
     data has been restored.
-   */ 
-  
+  */
+
   switch (item->type) {
 
   case BSTREAM_IT_EVENT:
@@ -2378,14 +2426,14 @@ int bcat_create_item(st_bstream_image_he
     return BSTREAM_OK;
 
   default: break;
-  
+
   }
 
-  // If we are to create a tablespace, first check if it already exists.
+  /* If we are to create a tablespace, first check if it already exists. */
 
   if (item->type == BSTREAM_IT_TABLESPACE)
   {
-    if (obs::find_tablespace(thd, sobj->get_name())) 
+    if (obs::find_tablespace(thd, sobj->get_name()))
     {
       // A tablespace with the same name exists. Nothing more to do.
       DBUG_PRINT("restore",(" skipping tablespace which exists"));
@@ -2393,16 +2441,16 @@ int bcat_create_item(st_bstream_image_he
     }
   }
 
-  // Create the object.
+  /* Create the object. */
 
   /*
-    We need to check to see if the user exists (grantee) and if not, 
-    do not execute the grant. 
+    We need to check to see if the user exists (grantee) and if not,
+    do not execute the grant.
   */
   if (item->type == BSTREAM_IT_PRIVILEGE)
   {
     /*
-      Issue warning to the user that grant was skipped. 
+      Issue warning to the user that grant was skipped.
 
       @todo Replace write_message() call with the result of the revised
             error handling work in WL#4384 with possible implementation
@@ -2418,27 +2466,29 @@ int bcat_create_item(st_bstream_image_he
     }
   }
 
-  // Mark that data is being changed.
+  /* Mark that data is being changed. */
   info->m_data_changed= TRUE;
   if (sobj->create(thd))
   {
     log.report_error(create_err, desc);
     return BSTREAM_ERROR;
   }
-  
+
   return BSTREAM_OK;
 }
 
+
 /**
   Get serialization string for a given object.
-  
+
   The catalogue should contain @c Image_info::Obj instance corresponding to the
-  object described by @c item. This instance should contain pointer to 
+  object described by @c item. This instance should contain pointer to
   @c obs::Obj instance which can be used for getting the serialization string.
 
-  @todo Decide what to do with the serialization string buffer - is it 
+  @todo Decide what to do with the serialization string buffer - is it
   acceptable to re-use a single buffer as it is done now?
- */ 
+*/
+
 extern "C"
 int bcat_get_item_create_query(st_bstream_image_header *catalogue,
                                struct st_bstream_item_info *item,
@@ -2455,54 +2505,50 @@ int bcat_get_item_create_query(st_bstrea
   Logger &log= info->m_log;
   int meta_err= 0;
 
-  /*
-    Check for interruption before proceeding.
-  */ 
+  /* Check for interruption before proceeding. */
   if (log.report_killed())
     return BSTREAM_ERROR;
 
   switch (item->type) {
-  
-  case BSTREAM_IT_DB:     meta_err= ER_BACKUP_GET_META_DB; break;
-  case BSTREAM_IT_TABLE:  meta_err= ER_BACKUP_GET_META_TABLE; break;
-  case BSTREAM_IT_VIEW:   meta_err= ER_BACKUP_GET_META_VIEW; break;
-  case BSTREAM_IT_SPROC:  meta_err= ER_BACKUP_GET_META_SROUT; break;
-  case BSTREAM_IT_SFUNC:  meta_err= ER_BACKUP_GET_META_SROUT; break;
-  case BSTREAM_IT_EVENT:  meta_err= ER_BACKUP_GET_META_EVENT; break;
-  case BSTREAM_IT_TRIGGER: meta_err= ER_BACKUP_GET_META_TRIGGER; break;
+
+  case BSTREAM_IT_DB:         meta_err= ER_BACKUP_GET_META_DB; break;
+  case BSTREAM_IT_TABLE:      meta_err= ER_BACKUP_GET_META_TABLE; break;
+  case BSTREAM_IT_VIEW:       meta_err= ER_BACKUP_GET_META_VIEW; break;
+  case BSTREAM_IT_SPROC:      meta_err= ER_BACKUP_GET_META_SROUT; break;
+  case BSTREAM_IT_SFUNC:      meta_err= ER_BACKUP_GET_META_SROUT; break;
+  case BSTREAM_IT_EVENT:      meta_err= ER_BACKUP_GET_META_EVENT; break;
+  case BSTREAM_IT_TRIGGER:    meta_err= ER_BACKUP_GET_META_TRIGGER; break;
   case BSTREAM_IT_TABLESPACE: meta_err= ER_BACKUP_GET_META_TS; break;
-  case BSTREAM_IT_PRIVILEGE: meta_err= ER_BACKUP_GET_META_PRIV; break;
-  
-  /*
-    This can't happen - the item was obtained from the backup kernel.
-  */
+  case BSTREAM_IT_PRIVILEGE:  meta_err= ER_BACKUP_GET_META_PRIV; break;
+
+  /* This can't happen - the item was obtained from the backup kernel. */
   default: DBUG_ASSERT(FALSE);
   }
 
   Image_info::Obj *obj= find_obj(*info, *item);
 
   /*
-    The catalogue should contain the specified object and it should have 
+    The catalogue should contain the specified object and it should have
     a corresponding server object instance.
-   */ 
+  */
   DBUG_ASSERT(obj);
   DBUG_ASSERT(obj->m_obj_ptr);
-  
+
   /*
     Note: Using single buffer here means that the string returned by
     this function will live only until the next call. This should be fine
     given the current ussage of the function inside the backup stream library.
-    
+
     TODO: document this or find better solution for string storage.
-   */ 
-  
+  */
+
   ::String *buf= &(info->serialization_buf);
   buf->length(0);
 
 #if !defined(DBUG_OFF)
 
   /*
-    Debug insertion for errors. Here we setup the error to correspond 
+    Debug insertion for errors. Here we setup the error to correspond
     with the debug SESSION tag specified in the test.
 
     Note: Error code insertion won't work here as we need to generate
@@ -2510,12 +2556,12 @@ int bcat_get_item_create_query(st_bstrea
   */
   ::String str;
   switch (item->type) {
-  case BSTREAM_IT_DB:     str.append("ER_BACKUP_GET_META_DB"); break;
-  case BSTREAM_IT_TABLE:  str.append("ER_BACKUP_GET_META_TABLE"); break;
-  case BSTREAM_IT_VIEW:   str.append("ER_BACKUP_GET_META_VIEW"); break;
-  case BSTREAM_IT_SPROC:  str.append("ER_BACKUP_GET_META_SROUT_P"); break;
-  case BSTREAM_IT_SFUNC:  str.append("ER_BACKUP_GET_META_SROUT_F"); break;
-  case BSTREAM_IT_EVENT:  str.append("ER_BACKUP_GET_META_EVENT"); break;
+  case BSTREAM_IT_DB:      str.append("ER_BACKUP_GET_META_DB"); break;
+  case BSTREAM_IT_TABLE:   str.append("ER_BACKUP_GET_META_TABLE"); break;
+  case BSTREAM_IT_VIEW:    str.append("ER_BACKUP_GET_META_VIEW"); break;
+  case BSTREAM_IT_SPROC:   str.append("ER_BACKUP_GET_META_SROUT_P"); break;
+  case BSTREAM_IT_SFUNC:   str.append("ER_BACKUP_GET_META_SROUT_F"); break;
+  case BSTREAM_IT_EVENT:   str.append("ER_BACKUP_GET_META_EVENT"); break;
   case BSTREAM_IT_TRIGGER: str.append("ER_BACKUP_GET_META_TRIGGER"); break;
   default: break;
   }
@@ -2526,9 +2572,9 @@ int bcat_get_item_create_query(st_bstrea
       log.report_error(meta_err, obj->describe(dbuf));
       return BSTREAM_ERROR;);
   }
-  // Tablespace is a special case since Falcon is disabled.
+  /* Tablespace is a special case since Falcon is disabled. */
   DBUG_EXECUTE_IF("ER_BACKUP_GET_META_TS",
-    log.report_error(ER_BACKUP_GET_META_TS, 
+    log.report_error(ER_BACKUP_GET_META_TS,
       "Debug insertion test");
     return BSTREAM_ERROR;);
 
@@ -2538,19 +2584,19 @@ int bcat_get_item_create_query(st_bstrea
      would be deterministic.
   */
   DBUG_EXECUTE_IF("ER_BACKUP_GET_META_PRIV",
-    log.report_error(ER_BACKUP_GET_META_PRIV, 
+    log.report_error(ER_BACKUP_GET_META_PRIV,
       "Debug insertion test");
     return BSTREAM_ERROR;);
 
 #endif
-  
+
   if (obj->m_obj_ptr->serialize(info->m_thd, buf))
   {
     Image_info::Obj::describe_buf dbuf;
 
     log.report_error(meta_err, obj->describe(dbuf));
 
-    return BSTREAM_ERROR;    
+    return BSTREAM_ERROR;
   }
 
   stmt->begin= (backup::byte*)buf->ptr();
@@ -2559,17 +2605,19 @@ int bcat_get_item_create_query(st_bstrea
   return BSTREAM_OK;
 }
 
+
 /**
   Get extra metadata (if any) for a given object.
- 
+
   @note Extra metadata is not used currently.
- */ 
+*/
+
 extern "C"
 int bcat_get_item_create_data(st_bstream_image_header *catalogue,
                             struct st_bstream_item_info *item,
                             bstream_blob *data)
 {
-  /* We don't use any extra data now */
+  /* We don't use any extra data now. */
   return BSTREAM_EOS;
 }
 
@@ -2582,32 +2630,46 @@ int bcat_get_item_create_data(st_bstream
 
 namespace backup {
 
-/** 
-  Produce string identifying the table in internal format (as used by 
+/**
+  Produce string identifying the table in internal format (as used by
   storage engines).
 */
+
 const char* Table_ref::internal_name(char *buf, size_t len) const
 {
-  uint plen= build_table_filename(buf, len, 
-                                  db().name().ptr(), name().ptr(), 
-                                  "", /* no extension */ 
-                                  0 /* not a temporary table - do conversions */);
+  uint plen= build_table_filename(buf, len,
+                                  db().name().ptr(), name().ptr(),
+                                  "", /* no extension */
+                                  0   /* not a tmp table - do conversions */);
   buf[plen]='\0';
-  return buf;    
+  return buf;
 }
 
-/** 
-    Produce human readable string identifying the table 
-    (e.g. for error reporting)
+
+/**
+  Produce human readable string identifying the table
+  (e.g. for error reporting).
 */
+
 const char* Table_ref::describe(char *buf, size_t len) const
 {
   my_snprintf(buf, len, "`%s`.`%s`", db().name().ptr(), name().ptr());
   return buf;
 }
 
+} // backup namespace
+
+
+/*************************************************
+
+                 Helper functions
+
+ *************************************************/
+
+namespace backup {
+
 /*
-  TODO: remove these functions. Currently they are only used by the myisam 
+  TODO: remove these functions. Currently they are only used by the myisam
   native backup engine.
 */
 
@@ -2619,6 +2681,7 @@ const char* Table_ref::describe(char *bu
 
   @retval  TABLE_LIST
 */
+
 TABLE_LIST *build_table_list(const Table_list &tables, thr_lock_type lock)
 {
   TABLE_LIST *tl= NULL;
@@ -2628,7 +2691,7 @@ TABLE_LIST *build_table_list(const Table
     TABLE_LIST *ptr = mk_table_list(tables[tno], lock, ::current_thd->mem_root);
     if (!ptr)
     {
-      // Failed to allocate (failure has been reported)
+      /* Failed to allocate (failure has been reported). */
       return NULL;
     }
     tl= link_table_list(*ptr,tl);
@@ -2637,43 +2700,23 @@ TABLE_LIST *build_table_list(const Table
   return tl;
 }
 
+
 /**
   Free the TABLE_LIST.
 
   @param[in]  tables  The list of tables to free.
 */
+
 void free_table_list(TABLE_LIST* tables)
 {}
 
-} // backup namespace
-
-
-/*************************************************
-
-                 Helper functions
-
- ***************************************