1*86d7f5d3SJohn Marino /* $NetBSD: label.h,v 1.1.1.1 2008/12/22 00:18:02 haad Exp $ */ 2*86d7f5d3SJohn Marino 3*86d7f5d3SJohn Marino /* 4*86d7f5d3SJohn Marino * Copyright (C) 2002-2004 Sistina Software, Inc. All rights reserved. 5*86d7f5d3SJohn Marino * Copyright (C) 2004-2007 Red Hat, Inc. All rights reserved. 6*86d7f5d3SJohn Marino * 7*86d7f5d3SJohn Marino * This file is part of LVM2. 8*86d7f5d3SJohn Marino * 9*86d7f5d3SJohn Marino * This copyrighted material is made available to anyone wishing to use, 10*86d7f5d3SJohn Marino * modify, copy, or redistribute it subject to the terms and conditions 11*86d7f5d3SJohn Marino * of the GNU Lesser General Public License v.2.1. 12*86d7f5d3SJohn Marino * 13*86d7f5d3SJohn Marino * You should have received a copy of the GNU Lesser General Public License 14*86d7f5d3SJohn Marino * along with this program; if not, write to the Free Software Foundation, 15*86d7f5d3SJohn Marino * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 16*86d7f5d3SJohn Marino */ 17*86d7f5d3SJohn Marino 18*86d7f5d3SJohn Marino #ifndef _LVM_LABEL_H 19*86d7f5d3SJohn Marino #define _LVM_LABEL_H 20*86d7f5d3SJohn Marino 21*86d7f5d3SJohn Marino #include "uuid.h" 22*86d7f5d3SJohn Marino #include "device.h" 23*86d7f5d3SJohn Marino 24*86d7f5d3SJohn Marino #define LABEL_ID "LABELONE" 25*86d7f5d3SJohn Marino #define LABEL_SIZE SECTOR_SIZE /* Think very carefully before changing this */ 26*86d7f5d3SJohn Marino #define LABEL_SCAN_SECTORS 4L 27*86d7f5d3SJohn Marino #define LABEL_SCAN_SIZE (LABEL_SCAN_SECTORS << SECTOR_SHIFT) 28*86d7f5d3SJohn Marino 29*86d7f5d3SJohn Marino struct labeller; 30*86d7f5d3SJohn Marino 31*86d7f5d3SJohn Marino /* On disk - 32 bytes */ 32*86d7f5d3SJohn Marino struct label_header { 33*86d7f5d3SJohn Marino int8_t id[8]; /* LABELONE */ 34*86d7f5d3SJohn Marino uint64_t sector_xl; /* Sector number of this label */ 35*86d7f5d3SJohn Marino uint32_t crc_xl; /* From next field to end of sector */ 36*86d7f5d3SJohn Marino uint32_t offset_xl; /* Offset from start of struct to contents */ 37*86d7f5d3SJohn Marino int8_t type[8]; /* LVM2 001 */ 38*86d7f5d3SJohn Marino } __attribute__ ((packed)); 39*86d7f5d3SJohn Marino 40*86d7f5d3SJohn Marino /* In core */ 41*86d7f5d3SJohn Marino struct label { 42*86d7f5d3SJohn Marino char type[8]; 43*86d7f5d3SJohn Marino uint64_t sector; 44*86d7f5d3SJohn Marino struct labeller *labeller; 45*86d7f5d3SJohn Marino void *info; 46*86d7f5d3SJohn Marino }; 47*86d7f5d3SJohn Marino 48*86d7f5d3SJohn Marino struct labeller; 49*86d7f5d3SJohn Marino 50*86d7f5d3SJohn Marino struct label_ops { 51*86d7f5d3SJohn Marino /* 52*86d7f5d3SJohn Marino * Is the device labelled with this format ? 53*86d7f5d3SJohn Marino */ 54*86d7f5d3SJohn Marino int (*can_handle) (struct labeller * l, void *buf, uint64_t sector); 55*86d7f5d3SJohn Marino 56*86d7f5d3SJohn Marino /* 57*86d7f5d3SJohn Marino * Write a label to a volume. 58*86d7f5d3SJohn Marino */ 59*86d7f5d3SJohn Marino int (*write) (struct label * label, void *buf); 60*86d7f5d3SJohn Marino 61*86d7f5d3SJohn Marino /* 62*86d7f5d3SJohn Marino * Read a label from a volume. 63*86d7f5d3SJohn Marino */ 64*86d7f5d3SJohn Marino int (*read) (struct labeller * l, struct device * dev, 65*86d7f5d3SJohn Marino void *buf, struct label ** label); 66*86d7f5d3SJohn Marino 67*86d7f5d3SJohn Marino /* 68*86d7f5d3SJohn Marino * Additional consistency checks for the paranoid. 69*86d7f5d3SJohn Marino */ 70*86d7f5d3SJohn Marino int (*verify) (struct labeller * l, void *buf, uint64_t sector); 71*86d7f5d3SJohn Marino 72*86d7f5d3SJohn Marino /* 73*86d7f5d3SJohn Marino * Populate label_type etc. 74*86d7f5d3SJohn Marino */ 75*86d7f5d3SJohn Marino int (*initialise_label) (struct labeller * l, struct label * label); 76*86d7f5d3SJohn Marino 77*86d7f5d3SJohn Marino /* 78*86d7f5d3SJohn Marino * Destroy a previously read label. 79*86d7f5d3SJohn Marino */ 80*86d7f5d3SJohn Marino void (*destroy_label) (struct labeller * l, struct label * label); 81*86d7f5d3SJohn Marino 82*86d7f5d3SJohn Marino /* 83*86d7f5d3SJohn Marino * Destructor. 84*86d7f5d3SJohn Marino */ 85*86d7f5d3SJohn Marino void (*destroy) (struct labeller * l); 86*86d7f5d3SJohn Marino }; 87*86d7f5d3SJohn Marino 88*86d7f5d3SJohn Marino struct labeller { 89*86d7f5d3SJohn Marino struct label_ops *ops; 90*86d7f5d3SJohn Marino const void *private; 91*86d7f5d3SJohn Marino }; 92*86d7f5d3SJohn Marino 93*86d7f5d3SJohn Marino int label_init(void); 94*86d7f5d3SJohn Marino void label_exit(void); 95*86d7f5d3SJohn Marino 96*86d7f5d3SJohn Marino int label_register_handler(const char *name, struct labeller *handler); 97*86d7f5d3SJohn Marino 98*86d7f5d3SJohn Marino struct labeller *label_get_handler(const char *name); 99*86d7f5d3SJohn Marino 100*86d7f5d3SJohn Marino int label_remove(struct device *dev); 101*86d7f5d3SJohn Marino int label_read(struct device *dev, struct label **result, 102*86d7f5d3SJohn Marino uint64_t scan_sector); 103*86d7f5d3SJohn Marino int label_write(struct device *dev, struct label *label); 104*86d7f5d3SJohn Marino int label_verify(struct device *dev); 105*86d7f5d3SJohn Marino struct label *label_create(struct labeller *labeller); 106*86d7f5d3SJohn Marino void label_destroy(struct label *label); 107*86d7f5d3SJohn Marino 108*86d7f5d3SJohn Marino #endif 109