2001-09-25 16:49:28 +04:00
/*
2004-03-30 23:35:44 +04:00
* Copyright ( C ) 2001 - 2004 Sistina Software , Inc . All rights reserved .
* Copyright ( C ) 2004 Red Hat , Inc . All rights reserved .
2001-09-25 16:49:28 +04: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
* of the GNU General Public License v .2 .
*
* You should have received a copy of the GNU General Public License
* along with this program ; if not , write to the Free Software Foundation ,
* Inc . , 59 Temple Place , Suite 330 , Boston , MA 02111 - 1307 USA
2001-09-25 16:49:28 +04:00
*/
# ifndef _LVM_DEVICE_H
# define _LVM_DEVICE_H
2002-11-18 17:01:16 +03:00
# include "uuid.h"
2003-07-05 02:34:56 +04:00
# include <fcntl.h>
2001-10-03 16:41:29 +04:00
2002-04-24 22:20:51 +04:00
# define DEV_ACCESSED_W 0x00000001 /* Device written to? */
2003-07-05 02:34:56 +04:00
# define DEV_REGULAR 0x00000002 /* Regular file? */
# define DEV_ALLOCED 0x00000004 /* dbg_malloc used */
2002-04-24 22:20:51 +04:00
2001-10-03 16:41:29 +04:00
/*
* All devices in LVM will be represented by one of these .
* pointer comparisons are valid .
*/
struct device {
2002-11-18 17:01:16 +03:00
struct list aliases ; /* struct str_list from lvm-types.h */
2001-10-03 16:41:29 +04:00
dev_t dev ;
2001-11-14 13:01:52 +03:00
/* private */
int fd ;
2003-07-05 02:34:56 +04:00
int open_count ;
2002-04-24 22:20:51 +04:00
uint32_t flags ;
2003-07-05 02:34:56 +04:00
uint64_t end ;
struct list open_list ;
2002-11-18 17:01:16 +03:00
char pvid [ ID_LEN + 1 ] ;
2001-10-03 16:41:29 +04:00
} ;
2002-01-15 13:24:48 +03:00
struct device_list {
struct list list ;
struct device * dev ;
} ;
2002-11-18 17:01:16 +03:00
struct device_area {
struct device * dev ;
uint64_t start ; /* Bytes */
uint64_t size ; /* Bytes */
} ;
2001-10-03 16:41:29 +04:00
/*
2001-11-14 13:01:52 +03:00
* All io should use these routines .
2001-10-03 16:41:29 +04:00
*/
2004-08-11 17:15:35 +04:00
int dev_get_size ( const struct device * dev , uint64_t * size ) ;
2001-12-11 13:18:49 +03:00
int dev_get_sectsize ( struct device * dev , uint32_t * size ) ;
2001-11-14 13:01:52 +03:00
2003-07-05 02:34:56 +04:00
/* Use quiet version if device number could change e.g. when opening LV */
int dev_open ( struct device * dev ) ;
int dev_open_quiet ( struct device * dev ) ;
int dev_open_flags ( struct device * dev , int flags , int append , int quiet ) ;
2001-11-14 13:01:52 +03:00
int dev_close ( struct device * dev ) ;
2003-11-14 20:55:39 +03:00
int dev_close_immediate ( struct device * dev ) ;
2003-07-05 02:34:56 +04:00
void dev_close_all ( void ) ;
2001-11-14 13:01:52 +03:00
2002-11-18 17:01:16 +03:00
static inline int dev_fd ( struct device * dev )
{
return dev - > fd ;
}
2003-07-05 02:34:56 +04:00
int dev_read ( struct device * dev , uint64_t offset , size_t len , void * buffer ) ;
int dev_write ( struct device * dev , uint64_t offset , size_t len , void * buffer ) ;
int dev_append ( struct device * dev , size_t len , void * buffer ) ;
2002-12-20 02:25:55 +03:00
int dev_zero ( struct device * dev , uint64_t offset , size_t len ) ;
2003-07-05 02:34:56 +04:00
void dev_flush ( struct device * dev ) ;
struct device * dev_create_file ( const char * filename , struct device * dev ,
struct str_list * alias ) ;
2001-10-03 16:41:29 +04:00
2002-12-20 02:25:55 +03:00
static inline const char * dev_name ( const struct device * dev )
2002-11-18 17:01:16 +03:00
{
2002-04-30 21:12:37 +04:00
return ( dev ) ? list_item ( dev - > aliases . n , struct str_list ) - > str :
2002-11-18 17:01:16 +03:00
" unknown device " ;
2001-10-25 18:04:18 +04:00
}
2002-01-25 02:16:19 +03:00
/* Return a valid device name from the alias list; NULL otherwise */
2003-07-05 02:34:56 +04:00
const char * dev_name_confirmed ( struct device * dev , int quiet ) ;
2001-09-25 16:49:28 +04:00
2002-12-20 02:25:55 +03:00
/* FIXME Check partition type if appropriate */
# define is_lvm_partition(a) 1
/*
static inline int is_lvm_partition ( const char * name )
2002-11-18 17:01:16 +03:00
{
2002-12-20 02:25:55 +03:00
return 1 ;
2002-11-18 17:01:16 +03:00
}
2002-12-20 02:25:55 +03:00
*/
2001-09-25 16:49:28 +04:00
2002-11-18 17:01:16 +03:00
# endif