2004-06-07 23:10:21 +04:00
/*
2008-01-30 17:00:02 +03:00
* Copyright ( C ) 1997 - 2004 Sistina Software , Inc . All rights reserved .
2007-08-21 00:55:30 +04:00
* Copyright ( C ) 2004 - 2006 Red Hat , Inc . All rights reserved .
2004-06-07 23:10:21 +04:00
*
* This file is part of LVM2 .
*
* This copyrighted material is made available to anyone wishing to use ,
* modify , copy , or redistribute it subject to the terms and conditions
2007-08-21 00:55:30 +04:00
* of the GNU Lesser General Public License v .2 .1 .
2004-06-07 23:10:21 +04:00
*
2007-08-21 00:55:30 +04:00
* You should have received a copy of the GNU Lesser General Public License
2004-06-07 23:10:21 +04:00
* along with this program ; if not , write to the Free Software Foundation ,
2016-01-21 13:49:46 +03:00
* Inc . , 51 Franklin Street , Fifth Floor , Boston , MA 02110 - 1301 USA
2004-06-07 23:10:21 +04:00
*/
# include "lib.h"
# include "label.h"
# include "metadata.h"
# include "disk_rep.h"
# include "pool_label.h"
# include <sys/stat.h>
# include <fcntl.h>
2006-04-19 19:33:07 +04:00
static void _pool_not_supported ( const char * op )
2004-06-07 23:10:21 +04:00
{
log_error ( " The '%s' operation is not supported for the pool labeller. " ,
op ) ;
}
2010-07-09 19:34:40 +04:00
static int _pool_can_handle ( struct labeller * l __attribute__ ( ( unused ) ) , void * buf , uint64_t sector )
2004-06-07 23:10:21 +04:00
{
struct pool_disk pd ;
/*
* POOL label must always be in first sector
*/
if ( sector )
return 0 ;
pool_label_in ( & pd , buf ) ;
/* can ignore 8 rightmost bits for ondisk format check */
if ( ( pd . pl_magic = = POOL_MAGIC ) & &
( pd . pl_version > > 8 = = POOL_VERSION > > 8 ) )
return 1 ;
return 0 ;
}
2010-07-09 19:34:40 +04:00
static int _pool_write ( struct label * label __attribute__ ( ( unused ) ) , void * buf __attribute__ ( ( unused ) ) )
2004-06-07 23:10:21 +04:00
{
2006-04-19 19:33:07 +04:00
_pool_not_supported ( " write " ) ;
2004-06-07 23:10:21 +04:00
return 0 ;
}
2018-04-20 18:43:50 +03:00
static int _pool_read ( struct labeller * l , struct device * dev , void * buf ,
struct label * * label )
2004-06-07 23:10:21 +04:00
{
struct pool_list pl ;
2018-04-20 18:43:50 +03:00
return read_pool_label ( & pl , l , dev , buf , label ) ;
2004-06-07 23:10:21 +04:00
}
2010-07-09 19:34:40 +04:00
static int _pool_initialise_label ( struct labeller * l __attribute__ ( ( unused ) ) , struct label * label )
2004-06-07 23:10:21 +04:00
{
strcpy ( label - > type , " POOL " ) ;
return 1 ;
}
2010-07-09 19:34:40 +04:00
static void _pool_destroy_label ( struct labeller * l __attribute__ ( ( unused ) ) , struct label * label __attribute__ ( ( unused ) ) )
2004-06-07 23:10:21 +04:00
{
}
2006-04-19 19:33:07 +04:00
static void _label_pool_destroy ( struct labeller * l )
2004-06-07 23:10:21 +04:00
{
2005-10-17 03:03:59 +04:00
dm_free ( l ) ;
2004-06-07 23:10:21 +04:00
}
struct label_ops _pool_ops = {
2006-05-10 01:23:51 +04:00
. can_handle = _pool_can_handle ,
. write = _pool_write ,
. read = _pool_read ,
. initialise_label = _pool_initialise_label ,
. destroy_label = _pool_destroy_label ,
. destroy = _label_pool_destroy ,
2004-06-07 23:10:21 +04:00
} ;
struct labeller * pool_labeller_create ( struct format_type * fmt )
{
struct labeller * l ;
2005-10-17 03:03:59 +04:00
if ( ! ( l = dm_malloc ( sizeof ( * l ) ) ) ) {
2004-06-07 23:10:21 +04:00
log_error ( " Couldn't allocate labeller object. " ) ;
return NULL ;
}
l - > ops = & _pool_ops ;
2013-07-29 17:58:18 +04:00
l - > fmt = fmt ;
2004-06-07 23:10:21 +04:00
return l ;
}