2001-09-25 12:49:28 +00:00
/*
2001-10-03 12:41:29 +00:00
* Copyright ( C ) 2001 Sistina Software ( UK ) Limited .
2001-09-25 12:49:28 +00:00
*
2001-10-03 12:41:29 +00:00
* This file is released under the GPL .
2001-09-25 12:49:28 +00:00
*/
# ifndef _LVM_DEVICE_H
# define _LVM_DEVICE_H
2002-11-18 14:01:16 +00:00
# include "uuid.h"
2001-10-03 12:41:29 +00:00
2002-04-24 18:20:51 +00:00
# define DEV_ACCESSED_W 0x00000001 /* Device written to? */
2001-10-03 12:41:29 +00:00
/*
* All devices in LVM will be represented by one of these .
* pointer comparisons are valid .
*/
struct device {
2002-11-18 14:01:16 +00:00
struct list aliases ; /* struct str_list from lvm-types.h */
2001-10-03 12:41:29 +00:00
dev_t dev ;
2001-11-14 10:01:52 +00:00
/* private */
int fd ;
2002-04-24 18:20:51 +00:00
uint32_t flags ;
2002-11-18 14:01:16 +00:00
char pvid [ ID_LEN + 1 ] ;
2001-10-03 12:41:29 +00:00
} ;
2002-01-15 10:24:48 +00:00
struct device_list {
struct list list ;
struct device * dev ;
} ;
2002-11-18 14:01:16 +00:00
struct device_area {
struct device * dev ;
uint64_t start ; /* Bytes */
uint64_t size ; /* Bytes */
} ;
2001-10-03 12:41:29 +00:00
/*
2001-11-14 10:01:52 +00:00
* All io should use these routines .
2001-10-03 12:41:29 +00:00
*/
int dev_get_size ( struct device * dev , uint64_t * size ) ;
2001-12-11 10:18:49 +00:00
int dev_get_sectsize ( struct device * dev , uint32_t * size ) ;
2001-11-14 10:01:52 +00:00
int dev_open ( struct device * dev , int flags ) ;
int dev_close ( struct device * dev ) ;
2002-11-18 14:01:16 +00:00
static inline int dev_fd ( struct device * dev )
{
return dev - > fd ;
}
2002-12-19 23:25:55 +00:00
ssize_t raw_read ( int fd , void * buf , size_t count ) ;
2002-11-18 14:01:16 +00:00
2002-12-19 23:25:55 +00:00
ssize_t dev_read ( struct device * dev , uint64_t offset , size_t len , void * buffer ) ;
int64_t dev_write ( struct device * dev , uint64_t offset , size_t len ,
void * buffer ) ;
int dev_zero ( struct device * dev , uint64_t offset , size_t len ) ;
2001-10-03 12:41:29 +00:00
2002-12-19 23:25:55 +00:00
static inline const char * dev_name ( const struct device * dev )
2002-11-18 14:01:16 +00:00
{
2002-04-30 17:12:37 +00:00
return ( dev ) ? list_item ( dev - > aliases . n , struct str_list ) - > str :
2002-11-18 14:01:16 +00:00
" unknown device " ;
2001-10-25 14:04:18 +00:00
}
2002-01-24 23:16:19 +00:00
/* Return a valid device name from the alias list; NULL otherwise */
const char * dev_name_confirmed ( struct device * dev ) ;
2001-10-12 10:32:06 +00:00
2002-12-19 23:25:55 +00:00
static inline int dev_is_open ( struct device * dev )
2002-11-18 14:01:16 +00:00
{
2002-12-19 23:25:55 +00:00
return dev - > fd > = 0 ? 1 : 0 ;
2001-10-12 10:32:06 +00:00
}
2001-09-25 12:49:28 +00:00
2002-12-19 23:25:55 +00: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 14:01:16 +00:00
{
2002-12-19 23:25:55 +00:00
return 1 ;
2002-11-18 14:01:16 +00:00
}
2002-12-19 23:25:55 +00:00
*/
2001-09-25 12:49:28 +00:00
2002-11-18 14:01:16 +00:00
# endif