1 /* $NetBSD: device.h,v 1.1.1.2 2009/12/02 00:26:34 haad Exp $ */ 2 3 /* 4 * Copyright (C) 2001-2004 Sistina Software, Inc. All rights reserved. 5 * Copyright (C) 2004-2007 Red Hat, Inc. All rights reserved. 6 * 7 * This file is part of LVM2. 8 * 9 * This copyrighted material is made available to anyone wishing to use, 10 * modify, copy, or redistribute it subject to the terms and conditions 11 * of the GNU Lesser General Public License v.2.1. 12 * 13 * You should have received a copy of the GNU Lesser General Public License 14 * along with this program; if not, write to the Free Software Foundation, 15 * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 16 */ 17 18 #ifndef _LVM_DEVICE_H 19 #define _LVM_DEVICE_H 20 21 #include "uuid.h" 22 23 #include <fcntl.h> 24 25 #define DEV_ACCESSED_W 0x00000001 /* Device written to? */ 26 #define DEV_REGULAR 0x00000002 /* Regular file? */ 27 #define DEV_ALLOCED 0x00000004 /* dm_malloc used */ 28 #define DEV_OPENED_RW 0x00000008 /* Opened RW */ 29 #define DEV_OPENED_EXCL 0x00000010 /* Opened EXCL */ 30 #define DEV_O_DIRECT 0x00000020 /* Use O_DIRECT */ 31 #define DEV_O_DIRECT_TESTED 0x00000040 /* DEV_O_DIRECT is reliable */ 32 33 /* 34 * All devices in LVM will be represented by one of these. 35 * pointer comparisons are valid. 36 */ 37 struct device { 38 struct dm_list aliases; /* struct str_list from lvm-types.h */ 39 dev_t dev; 40 41 /* private */ 42 int fd; 43 int open_count; 44 int block_size; 45 int read_ahead; 46 uint32_t flags; 47 uint64_t end; 48 struct dm_list open_list; 49 50 char pvid[ID_LEN + 1]; 51 char _padding[7]; 52 }; 53 54 struct device_list { 55 struct dm_list list; 56 struct device *dev; 57 }; 58 59 struct device_area { 60 struct device *dev; 61 uint64_t start; /* Bytes */ 62 uint64_t size; /* Bytes */ 63 }; 64 65 /* 66 * All io should use these routines. 67 */ 68 int dev_get_size(const struct device *dev, uint64_t *size); 69 int dev_get_sectsize(struct device *dev, uint32_t *size); 70 int dev_get_read_ahead(struct device *dev, uint32_t *read_ahead); 71 72 /* Use quiet version if device number could change e.g. when opening LV */ 73 int dev_open(struct device *dev); 74 int dev_open_quiet(struct device *dev); 75 int dev_open_flags(struct device *dev, int flags, int direct, int quiet); 76 int dev_close(struct device *dev); 77 int dev_close_immediate(struct device *dev); 78 void dev_close_all(void); 79 int dev_test_excl(struct device *dev); 80 81 int dev_fd(struct device *dev); 82 const char *dev_name(const struct device *dev); 83 84 int dev_read(struct device *dev, uint64_t offset, size_t len, void *buffer); 85 int dev_read_circular(struct device *dev, uint64_t offset, size_t len, 86 uint64_t offset2, size_t len2, void *buf); 87 int dev_write(struct device *dev, uint64_t offset, size_t len, void *buffer); 88 int dev_append(struct device *dev, size_t len, void *buffer); 89 int dev_set(struct device *dev, uint64_t offset, size_t len, int value); 90 void dev_flush(struct device *dev); 91 92 struct device *dev_create_file(const char *filename, struct device *dev, 93 struct str_list *alias, int use_malloc); 94 95 /* Return a valid device name from the alias list; NULL otherwise */ 96 const char *dev_name_confirmed(struct device *dev, int quiet); 97 98 /* Does device contain md superblock? If so, where? */ 99 int dev_is_md(struct device *dev, uint64_t *sb); 100 int dev_is_swap(struct device *dev, uint64_t *signature); 101 unsigned long dev_md_stripe_width(const char *sysfs_dir, struct device *dev); 102 103 int is_partitioned_dev(struct device *dev); 104 105 int get_primary_dev(const char *sysfs_dir, 106 struct device *dev, dev_t *result); 107 108 unsigned long dev_alignment_offset(const char *sysfs_dir, 109 struct device *dev); 110 111 unsigned long dev_minimum_io_size(const char *sysfs_dir, 112 struct device *dev); 113 114 unsigned long dev_optimal_io_size(const char *sysfs_dir, 115 struct device *dev); 116 117 #endif 118