2002-11-18 17:01:16 +03:00
/*
2008-01-30 17:00:02 +03:00
* Copyright ( C ) 2002 - 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 .
2002-11-18 17:01:16 +03:00
*
2004-03-30 23:35:44 +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-03-30 23:35:44 +04:00
*
2007-08-21 00:55:30 +04:00
* You should have received a copy of the GNU Lesser General Public License
2004-03-30 23:35:44 +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
2002-11-18 17:01:16 +03:00
*/
# include "lib.h"
# include "lvm1-label.h"
# include "disk-rep.h"
# include "label.h"
# include "metadata.h"
# include "xlate.h"
2008-02-06 18:47:28 +03:00
# include "format1.h"
2002-11-18 17:01:16 +03:00
# include <sys/stat.h>
# include <fcntl.h>
static void _not_supported ( const char * op )
{
2009-07-16 00:02:46 +04:00
log_error ( " The '%s' operation is not supported for the lvm1 labeller. " ,
op ) ;
2002-11-18 17:01:16 +03:00
}
2010-07-09 19:34:40 +04:00
static int _lvm1_can_handle ( struct labeller * l __attribute__ ( ( unused ) ) , void * buf , uint64_t sector )
2002-11-18 17:01:16 +03:00
{
struct pv_disk * pvd = ( struct pv_disk * ) buf ;
uint32_t version ;
/* LVM1 label must always be in first sector */
if ( sector )
return 0 ;
version = xlate16 ( pvd - > version ) ;
if ( pvd - > id [ 0 ] = = ' H ' & & pvd - > id [ 1 ] = = ' M ' & &
( version = = 1 | | version = = 2 ) )
return 1 ;
return 0 ;
}
2010-07-09 19:34:40 +04:00
static int _lvm1_write ( struct label * label __attribute__ ( ( unused ) ) , void * buf __attribute__ ( ( unused ) ) )
2002-11-18 17:01:16 +03:00
{
_not_supported ( " write " ) ;
return 0 ;
}
2006-12-01 02:11:42 +03:00
static int _lvm1_read ( struct labeller * l , struct device * dev , void * buf ,
2002-11-18 17:01:16 +03:00
struct label * * label )
{
struct pv_disk * pvd = ( struct pv_disk * ) buf ;
2006-04-11 02:09:00 +04:00
struct vg_disk vgd ;
2003-07-05 02:34:56 +04:00
struct lvmcache_info * info ;
2008-02-06 18:47:28 +03:00
const char * vgid = FMT_LVM1_ORPHAN_VG_NAME ;
const char * vgname = FMT_LVM1_ORPHAN_VG_NAME ;
2006-05-10 01:23:51 +04:00
unsigned exported = 0 ;
2002-11-18 17:01:16 +03:00
2004-05-04 22:38:11 +04:00
munge_pvd ( dev , pvd ) ;
2008-02-06 18:47:28 +03:00
if ( * pvd - > vg_name ) {
if ( ! read_vgd ( dev , & vgd , pvd ) )
return_0 ;
2006-05-10 01:23:51 +04:00
vgid = ( char * ) vgd . vg_uuid ;
2008-02-06 18:47:28 +03:00
vgname = ( char * ) pvd - > vg_name ;
2006-04-11 21:42:15 +04:00
exported = pvd - > pv_status & VG_EXPORTED ;
}
2006-04-11 02:09:00 +04:00
2008-02-06 18:47:28 +03:00
if ( ! ( info = lvmcache_add ( l , ( char * ) pvd - > pv_uuid , dev , vgname , vgid ,
2008-01-30 16:19:47 +03:00
exported ) ) )
return_0 ;
2012-02-10 05:28:27 +04:00
* label = lvmcache_get_label ( info ) ;
2002-11-18 17:01:16 +03:00
2012-08-16 22:07:30 +04:00
lvmcache_set_device_size ( info , ( ( uint64_t ) xlate32 ( pvd - > pv_size ) ) < < SECTOR_SHIFT ) ;
2016-02-11 18:25:36 +03:00
lvmcache_set_ext_version ( info , 0 ) ;
2015-03-09 14:52:07 +03:00
lvmcache_set_ext_flags ( info , 0 ) ;
2012-02-10 05:28:27 +04:00
lvmcache_del_mdas ( info ) ;
2016-02-02 15:54:19 +03:00
lvmcache_del_bas ( info ) ;
2012-02-10 05:28:27 +04:00
lvmcache_make_valid ( info ) ;
2002-11-18 17:01:16 +03:00
return 1 ;
}
2010-07-09 19:34:40 +04:00
static int _lvm1_initialise_label ( struct labeller * l __attribute__ ( ( unused ) ) , struct label * label )
2002-11-18 17:01:16 +03:00
{
strcpy ( label - > type , " LVM1 " ) ;
return 1 ;
}
2010-07-09 19:34:40 +04:00
static void _lvm1_destroy_label ( struct labeller * l __attribute__ ( ( unused ) ) , struct label * label __attribute__ ( ( unused ) ) )
2002-11-18 17:01:16 +03:00
{
}
2006-04-19 19:33:07 +04:00
static void _lvm1_destroy ( struct labeller * l )
2002-11-18 17:01:16 +03:00
{
2005-10-17 03:03:59 +04:00
dm_free ( l ) ;
2002-11-18 17:01:16 +03:00
}
struct label_ops _lvm1_ops = {
2006-05-10 01:23:51 +04:00
. can_handle = _lvm1_can_handle ,
. write = _lvm1_write ,
. read = _lvm1_read ,
. initialise_label = _lvm1_initialise_label ,
. destroy_label = _lvm1_destroy_label ,
. destroy = _lvm1_destroy ,
2002-11-18 17:01:16 +03:00
} ;
struct labeller * lvm1_labeller_create ( struct format_type * fmt )
{
struct labeller * l ;
2005-10-17 03:03:59 +04:00
if ( ! ( l = dm_malloc ( sizeof ( * l ) ) ) ) {
2009-07-16 00:02:46 +04:00
log_error ( " Couldn't allocate labeller object. " ) ;
2002-11-18 17:01:16 +03:00
return NULL ;
}
l - > ops = & _lvm1_ops ;
2013-07-29 17:58:18 +04:00
l - > fmt = fmt ;
2002-11-18 17:01:16 +03:00
return l ;
}