1/*
2 libparted - a library for manipulating disk partitions
3 Copyright (C) 1998-2001, 2005, 2007-2008, 2011-2012 Free Software
4 Foundation, Inc.
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
18*/
19
20/**
21 * \addtogroup PedDevice
22 * @{
23 */
24
25/** \file device.h */
26
27#ifndef PED_DEVICE_H_INCLUDED
28#define PED_DEVICE_H_INCLUDED
29
30/** We can address 2^63 sectors */
31typedef long long PedSector;
32
33typedef enum {
34 PED_DEVICE_UNKNOWN = 0,
35 PED_DEVICE_SCSI = 1,
36 PED_DEVICE_IDE = 2,
37 PED_DEVICE_DAC960 = 3,
38 PED_DEVICE_CPQARRAY = 4,
39 PED_DEVICE_FILE = 5,
40 PED_DEVICE_ATARAID = 6,
41 PED_DEVICE_I2O = 7,
42 PED_DEVICE_UBD = 8,
43 PED_DEVICE_DASD = 9,
44 PED_DEVICE_VIODASD = 10,
45 PED_DEVICE_SX8 = 11,
46 PED_DEVICE_DM = 12,
47 PED_DEVICE_XVD = 13,
48 PED_DEVICE_SDMMC = 14,
49 PED_DEVICE_VIRTBLK = 15,
50 PED_DEVICE_AOE = 16,
51 PED_DEVICE_MD = 17,
52 PED_DEVICE_LOOP = 18
53} PedDeviceType;
54
55typedef struct _PedDevice PedDevice;
56typedef struct _PedDeviceArchOps PedDeviceArchOps;
57typedef struct _PedCHSGeometry PedCHSGeometry;
58
59/**
60 * A cylinder-head-sector "old-style" geometry.
61 *
62 * A device addressed in this way has C*H*S sectors.
63 */
64struct _PedCHSGeometry {
65 int cylinders;
66 int heads;
67 int sectors;
68};
69
70/** A block device - for example, /dev/hda, not /dev/hda3 */
71struct _PedDevice {
72 PedDevice* next;
73
74 char* model; /**< \brief description of hardware
75 (manufacturer, model) */
76 char* path; /**< device /dev entry */
77
78 PedDeviceType type; /**< SCSI, IDE, etc. \sa PedDeviceType */
79 long long sector_size; /**< logical sector size */
80 long long phys_sector_size; /**< physical sector size */
81 PedSector length; /**< device length (LBA) */
82
83 int open_count; /**< the number of times this device has
84 been opened with ped_device_open(). */
85 int read_only;
86 int external_mode;
87 int dirty;
88 int boot_dirty;
89
90 PedCHSGeometry hw_geom;
91 PedCHSGeometry bios_geom;
92 short host, did;
93
94 void* arch_specific;
95};
96
97#include <parted/natmath.h>
98
99/**
100 * List of functions implementing architecture-specific operations.
101 */
102struct _PedDeviceArchOps {
103 PedDevice* (*_new) (const char* path);
104 void (*destroy) (PedDevice* dev);
105 int (*is_busy) (PedDevice* dev);
106 int (*open) (PedDevice* dev);
107 int (*refresh_open) (PedDevice* dev);
108 int (*close) (PedDevice* dev);
109 int (*refresh_close) (PedDevice* dev);
110 int (*read) (const PedDevice* dev, void* buffer,
111 PedSector start, PedSector count);
112 int (*write) (PedDevice* dev, const void* buffer,
113 PedSector start, PedSector count);
114 int (*sync) (PedDevice* dev);
115 int (*sync_fast) (PedDevice* dev);
116 PedSector (*check) (PedDevice* dev, void* buffer,
117 PedSector start, PedSector count);
118 void (*probe_all) ();
119 /* These functions are optional */
120 PedAlignment *(*get_minimum_alignment)(const PedDevice *dev);
121 PedAlignment *(*get_optimum_alignment)(const PedDevice *dev);
122};
123
124#include <parted/constraint.h>
125#include <parted/timer.h>
126
127extern void ped_device_probe_all ();
128extern void ped_device_free_all ();
129
130extern PedDevice* ped_device_get (const char* name);
131extern PedDevice* ped_device_get_next (const PedDevice* dev)
132#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96)
133 __attribute ((__pure__))
134#endif
135;
136extern int ped_device_is_busy (PedDevice* dev);
137extern int ped_device_open (PedDevice* dev);
138extern int ped_device_close (PedDevice* dev);
139extern void ped_device_destroy (PedDevice* dev);
140extern void ped_device_cache_remove (PedDevice* dev);
141
142extern int ped_device_begin_external_access (PedDevice* dev);
143extern int ped_device_end_external_access (PedDevice* dev);
144
145extern int ped_device_read (const PedDevice* dev, void* buffer,
146 PedSector start, PedSector count);
147extern int ped_device_write (PedDevice* dev, const void* buffer,
148 PedSector start, PedSector count);
149extern int ped_device_sync (PedDevice* dev);
150extern int ped_device_sync_fast (PedDevice* dev);
151extern PedSector ped_device_check (PedDevice* dev, void* buffer,
152 PedSector start, PedSector count);
153extern PedConstraint* ped_device_get_constraint (const PedDevice* dev);
154
155extern PedConstraint *ped_device_get_minimal_aligned_constraint(
156 const PedDevice *dev);
157extern PedConstraint *ped_device_get_optimal_aligned_constraint(
158 const PedDevice *dev);
159
160extern PedAlignment *ped_device_get_minimum_alignment(const PedDevice *dev);
161extern PedAlignment *ped_device_get_optimum_alignment(const PedDevice *dev);
162
163/* private stuff ;-) */
164
165extern void _ped_device_probe (const char* path);
166
167#endif /* PED_DEVICE_H_INCLUDED */
168
169/** @} */
170