blob: c7cc9b64f696dec00674ecd9f31ca255ccfd7de4
1 | /* |
2 | * device.h - Exports for low level device io. Originated from the Linux-NTFS project. |
3 | * |
4 | * Copyright (c) 2000-2013 Anton Altaparmakov |
5 | * Copyright (c) 2008-2013 Tuxera Inc. |
6 | * |
7 | * This program/include file is free software; you can redistribute it and/or |
8 | * modify it under the terms of the GNU General Public License as published |
9 | * by the Free Software Foundation; either version 2 of the License, or |
10 | * (at your option) any later version. |
11 | * |
12 | * This program/include file is distributed in the hope that it will be |
13 | * useful, but WITHOUT ANY WARRANTY; without even the implied warranty |
14 | * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | * GNU General Public License for more details. |
16 | * |
17 | * You should have received a copy of the GNU General Public License |
18 | * along with this program (in the main directory of the NTFS-3G |
19 | * distribution in the file COPYING); if not, write to the Free Software |
20 | * Foundation,Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
21 | */ |
22 | |
23 | #ifndef _NTFS_DEVICE_H |
24 | #define _NTFS_DEVICE_H |
25 | |
26 | #ifdef HAVE_CONFIG_H |
27 | #include "config.h" |
28 | #endif |
29 | |
30 | #include "device_io.h" |
31 | #include "types.h" |
32 | #include "support.h" |
33 | #include "volume.h" |
34 | |
35 | /** |
36 | * enum ntfs_device_state_bits - |
37 | * |
38 | * Defined bits for the state field in the ntfs_device structure. |
39 | */ |
40 | typedef enum { |
41 | ND_Open, /* 1: Device is open. */ |
42 | ND_ReadOnly, /* 1: Device is read-only. */ |
43 | ND_Dirty, /* 1: Device is dirty, needs sync. */ |
44 | ND_Block, /* 1: Device is a block device. */ |
45 | ND_Sync, /* 1: Device is mounted with "-o sync" */ |
46 | } ntfs_device_state_bits; |
47 | |
48 | #define test_ndev_flag(nd, flag) test_bit(ND_##flag, (nd)->d_state) |
49 | #define set_ndev_flag(nd, flag) set_bit(ND_##flag, (nd)->d_state) |
50 | #define clear_ndev_flag(nd, flag) clear_bit(ND_##flag, (nd)->d_state) |
51 | |
52 | #define NDevOpen(nd) test_ndev_flag(nd, Open) |
53 | #define NDevSetOpen(nd) set_ndev_flag(nd, Open) |
54 | #define NDevClearOpen(nd) clear_ndev_flag(nd, Open) |
55 | |
56 | #define NDevReadOnly(nd) test_ndev_flag(nd, ReadOnly) |
57 | #define NDevSetReadOnly(nd) set_ndev_flag(nd, ReadOnly) |
58 | #define NDevClearReadOnly(nd) clear_ndev_flag(nd, ReadOnly) |
59 | |
60 | #define NDevDirty(nd) test_ndev_flag(nd, Dirty) |
61 | #define NDevSetDirty(nd) set_ndev_flag(nd, Dirty) |
62 | #define NDevClearDirty(nd) clear_ndev_flag(nd, Dirty) |
63 | |
64 | #define NDevBlock(nd) test_ndev_flag(nd, Block) |
65 | #define NDevSetBlock(nd) set_ndev_flag(nd, Block) |
66 | #define NDevClearBlock(nd) clear_ndev_flag(nd, Block) |
67 | |
68 | #define NDevSync(nd) test_ndev_flag(nd, Sync) |
69 | #define NDevSetSync(nd) set_ndev_flag(nd, Sync) |
70 | #define NDevClearSync(nd) clear_ndev_flag(nd, Sync) |
71 | |
72 | /** |
73 | * struct ntfs_device - |
74 | * |
75 | * The ntfs device structure defining all operations needed to access the low |
76 | * level device underlying the ntfs volume. |
77 | * |
78 | * Note d_heads and d_sectors_per_track are only set as a result of a call to |
79 | * either ntfs_device_heads_get() or ntfs_device_sectors_per_track_get() (both |
80 | * calls will set up both fields or if getting them failed they will be left at |
81 | * -1). |
82 | */ |
83 | struct ntfs_device { |
84 | struct ntfs_device_operations *d_ops; /* Device operations. */ |
85 | unsigned long d_state; /* State of the device. */ |
86 | char *d_name; /* Name of device. */ |
87 | void *d_private; /* Private data used by the |
88 | device operations. */ |
89 | int d_heads; /* Disk geometry: number of |
90 | heads or -1. */ |
91 | int d_sectors_per_track; /* Disk geometry: number of |
92 | sectors per track or -1. */ |
93 | }; |
94 | |
95 | struct stat; |
96 | |
97 | /** |
98 | * struct ntfs_device_operations - |
99 | * |
100 | * The ntfs device operations defining all operations that can be performed on |
101 | * the low level device described by an ntfs device structure. |
102 | */ |
103 | struct ntfs_device_operations { |
104 | int (*open)(struct ntfs_device *dev, int flags); |
105 | int (*close)(struct ntfs_device *dev); |
106 | s64 (*seek)(struct ntfs_device *dev, s64 offset, int whence); |
107 | s64 (*read)(struct ntfs_device *dev, void *buf, s64 count); |
108 | s64 (*write)(struct ntfs_device *dev, const void *buf, s64 count); |
109 | s64 (*pread)(struct ntfs_device *dev, void *buf, s64 count, s64 offset); |
110 | s64 (*pwrite)(struct ntfs_device *dev, const void *buf, s64 count, |
111 | s64 offset); |
112 | int (*sync)(struct ntfs_device *dev); |
113 | int (*stat)(struct ntfs_device *dev, struct stat *buf); |
114 | int (*ioctl)(struct ntfs_device *dev, int request, void *argp); |
115 | }; |
116 | |
117 | extern struct ntfs_device *ntfs_device_alloc(const char *name, const long state, |
118 | struct ntfs_device_operations *dops, void *priv_data); |
119 | extern int ntfs_device_free(struct ntfs_device *dev); |
120 | extern int ntfs_device_sync(struct ntfs_device *dev); |
121 | |
122 | extern s64 ntfs_pread(struct ntfs_device *dev, const s64 pos, s64 count, |
123 | void *b); |
124 | extern s64 ntfs_pwrite(struct ntfs_device *dev, const s64 pos, s64 count, |
125 | const void *b); |
126 | |
127 | extern s64 ntfs_mst_pread(struct ntfs_device *dev, const s64 pos, s64 count, |
128 | const u32 bksize, void *b); |
129 | extern s64 ntfs_mst_pwrite(struct ntfs_device *dev, const s64 pos, s64 count, |
130 | const u32 bksize, void *b); |
131 | |
132 | extern s64 ntfs_cluster_read(const ntfs_volume *vol, const s64 lcn, |
133 | const s64 count, void *b); |
134 | extern s64 ntfs_cluster_write(const ntfs_volume *vol, const s64 lcn, |
135 | const s64 count, const void *b); |
136 | |
137 | extern s64 ntfs_device_size_get(struct ntfs_device *dev, int block_size); |
138 | extern s64 ntfs_device_partition_start_sector_get(struct ntfs_device *dev); |
139 | extern int ntfs_device_heads_get(struct ntfs_device *dev); |
140 | extern int ntfs_device_sectors_per_track_get(struct ntfs_device *dev); |
141 | extern int ntfs_device_sector_size_get(struct ntfs_device *dev); |
142 | extern int ntfs_device_block_size_set(struct ntfs_device *dev, int block_size); |
143 | |
144 | #endif /* defined _NTFS_DEVICE_H */ |
145 |