2001-09-25 12:49:28 +00:00
/*
2004-03-30 19:35:44 +00:00
* Copyright ( C ) 2001 - 2004 Sistina Software , Inc . All rights reserved .
2007-08-20 20:55:30 +00:00
* Copyright ( C ) 2004 - 2007 Red Hat , Inc . All rights reserved .
2001-09-25 12:49:28 +00:00
*
2004-03-30 19:35:44 +00: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-20 20:55:30 +00:00
* of the GNU Lesser General Public License v .2 .1 .
2004-03-30 19:35:44 +00:00
*
2007-08-20 20:55:30 +00:00
* You should have received a copy of the GNU Lesser General Public License
2004-03-30 19:35:44 +00:00
* 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 12:49:28 +00:00
*/
# ifndef _LVM_DEVICE_H
# define _LVM_DEVICE_H
2002-11-18 14:01:16 +00:00
# include "uuid.h"
2005-10-16 23:03:59 +00:00
2003-07-04 22:34:56 +00:00
# include <fcntl.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? */
2003-07-04 22:34:56 +00:00
# define DEV_REGULAR 0x00000002 /* Regular file? */
2005-10-16 23:03:59 +00:00
# define DEV_ALLOCED 0x00000004 /* dm_malloc used */
2004-12-10 16:01:35 +00:00
# define DEV_OPENED_RW 0x00000008 /* Opened RW */
2005-10-03 21:10:41 +00:00
# define DEV_OPENED_EXCL 0x00000010 /* Opened EXCL */
# define DEV_O_DIRECT 0x00000020 /* Use O_DIRECT */
# define DEV_O_DIRECT_TESTED 0x00000040 /* DEV_O_DIRECT is reliable */
2002-04-24 18:20:51 +00:00
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 {
2008-11-03 22:14:30 +00:00
struct dm_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 ;
2003-07-04 22:34:56 +00:00
int open_count ;
2004-12-10 16:01:35 +00:00
int block_size ;
2009-05-20 11:09:49 +00:00
int read_ahead ;
2002-04-24 18:20:51 +00:00
uint32_t flags ;
2003-07-04 22:34:56 +00:00
uint64_t end ;
2008-11-03 22:14:30 +00:00
struct dm_list open_list ;
2002-11-18 14:01:16 +00:00
char pvid [ ID_LEN + 1 ] ;
2005-04-06 13:47:41 +00:00
char _padding [ 7 ] ;
2001-10-03 12:41:29 +00:00
} ;
2002-01-15 10:24:48 +00:00
struct device_list {
2008-11-03 22:14:30 +00:00
struct dm_list list ;
2002-01-15 10:24:48 +00:00
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
*/
2004-08-11 13:15:35 +00:00
int dev_get_size ( const struct device * dev , uint64_t * size ) ;
2001-12-11 10:18:49 +00:00
int dev_get_sectsize ( struct device * dev , uint32_t * size ) ;
2009-05-20 11:09:49 +00:00
int dev_get_read_ahead ( struct device * dev , uint32_t * read_ahead ) ;
2001-11-14 10:01:52 +00:00
2003-07-04 22:34:56 +00: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 ) ;
2005-04-07 12:17:46 +00:00
int dev_open_flags ( struct device * dev , int flags , int direct , int quiet ) ;
2001-11-14 10:01:52 +00:00
int dev_close ( struct device * dev ) ;
2003-11-14 17:55:39 +00:00
int dev_close_immediate ( struct device * dev ) ;
2003-07-04 22:34:56 +00:00
void dev_close_all ( void ) ;
2005-10-03 21:10:41 +00:00
int dev_test_excl ( struct device * dev ) ;
2001-11-14 10:01:52 +00:00
2006-04-19 15:33:07 +00:00
int dev_fd ( struct device * dev ) ;
const char * dev_name ( const struct device * dev ) ;
2002-11-18 14:01:16 +00:00
2003-07-04 22:34:56 +00:00
int dev_read ( struct device * dev , uint64_t offset , size_t len , void * buffer ) ;
2007-04-19 02:10:42 +00:00
int dev_read_circular ( struct device * dev , uint64_t offset , size_t len ,
uint64_t offset2 , size_t len2 , void * buf ) ;
2003-07-04 22:34:56 +00:00
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 ) ;
2006-05-11 18:39:24 +00:00
int dev_set ( struct device * dev , uint64_t offset , size_t len , int value ) ;
2003-07-04 22:34:56 +00:00
void dev_flush ( struct device * dev ) ;
struct device * dev_create_file ( const char * filename , struct device * dev ,
2005-05-03 17:28:23 +00:00
struct str_list * alias , int use_malloc ) ;
2001-10-03 12:41:29 +00:00
2002-01-24 23:16:19 +00:00
/* Return a valid device name from the alias list; NULL otherwise */
2003-07-04 22:34:56 +00:00
const char * dev_name_confirmed ( struct device * dev , int quiet ) ;
2001-09-25 12:49:28 +00:00
2004-11-18 20:02:21 +00:00
/* Does device contain md superblock? If so, where? */
int dev_is_md ( struct device * dev , uint64_t * sb ) ;
2009-03-17 13:59:56 +00:00
int dev_is_swap ( struct device * dev , uint64_t * signature ) ;
2009-07-06 19:04:24 +00:00
unsigned long dev_md_stripe_width ( const char * sysfs_dir , struct device * dev ) ;
2004-11-18 20:02:21 +00:00
2004-11-23 11:44:04 +00:00
int is_partitioned_dev ( struct device * dev ) ;
2001-09-25 12:49:28 +00:00
2009-08-01 17:11:02 +00:00
int get_primary_dev ( const char * sysfs_dir ,
struct device * dev , dev_t * result ) ;
2009-08-01 17:07:36 +00:00
unsigned long dev_alignment_offset ( const char * sysfs_dir ,
struct device * dev ) ;
2009-08-01 17:08:43 +00:00
unsigned long dev_minimum_io_size ( const char * sysfs_dir ,
struct device * dev ) ;
unsigned long dev_optimal_io_size ( const char * sysfs_dir ,
struct device * dev ) ;
2002-11-18 14:01:16 +00:00
# endif