http://linux-ntfs.sourceforge.net/snapshots/ntfsprogs-200307311516.tar.bz2
[ntfsprogs.git] / include / device.h
1 /*
2  * device.h - Exports for low level device io. Part of the Linux-NTFS project.
3  *
4  * Copyright (c) 2003 Anton Altaparmakov
5  *
6  * This program/include file is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License as published
8  * by the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program/include file is distributed in the hope that it will be
12  * useful, but WITHOUT ANY WARRANTY; without even the implied warranty
13  * of 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 (in the main directory of the Linux-NTFS
18  * distribution in the file COPYING); if not, write to the Free Software
19  * Foundation,Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20  */
21
22 #ifndef _NTFS_DEVICE_H
23 #define _NTFS_DEVICE_H
24
25 #include <sys/stat.h>
26
27 #include "types.h"
28 #include "support.h"
29
30 /*
31  * Defined bits for the state field in the ntfs_device structure.
32  */
33 typedef enum {
34         ND_Open,        /* 1: Device is open. */
35         ND_ReadOnly,    /* 1: Device is read-only. */
36         ND_Dirty,       /* 1: Device is dirty, needs sync. */
37 } ntfs_device_state_bits;
38
39 #define  test_ndev_flag(nd, flag)          test_bit(ND_##flag, (nd)->d_state)
40 #define   set_ndev_flag(nd, flag)           set_bit(ND_##flag, (nd)->d_state)
41 #define clear_ndev_flag(nd, flag)         clear_bit(ND_##flag, (nd)->d_state)
42
43 #define NDevOpen(nd)             test_ndev_flag(nd, Open)
44 #define NDevSetOpen(nd)           set_ndev_flag(nd, Open)
45 #define NDevClearOpen(nd)       clear_ndev_flag(nd, Open)
46
47 #define NDevReadOnly(nd)         test_ndev_flag(nd, ReadOnly)
48 #define NDevSetReadOnly(nd)       set_ndev_flag(nd, ReadOnly)
49 #define NDevClearReadOnly(nd)   clear_ndev_flag(nd, ReadOnly)
50
51 #define NDevDirty(nd)            test_ndev_flag(nd, Dirty)
52 #define NDevSetDirty(nd)          set_ndev_flag(nd, Dirty)
53 #define NDevClearDirty(nd)      clear_ndev_flag(nd, Dirty)
54
55 /* Forward declaration. */
56 struct ntfs_device_operations;
57
58 /*
59  * The ntfs device structure defining all operations needed to access the low
60  * level device underlying the ntfs volume.
61  */
62 struct ntfs_device {
63         struct ntfs_device_operations *d_ops;   /* Device operations. */
64         unsigned long d_state;                  /* State of the device. */
65         char *d_name;                           /* Name of device. */
66         void *d_private;                        /* Private data used by the
67                                                    device operations. */
68 };
69
70 /*
71  * The ntfs device operations defining all operations that can be performed on
72  * the low level device described by a ntfs device structure.
73  */
74 struct ntfs_device_operations {
75         int (*open)(struct ntfs_device *dev, int flags);
76         int (*close)(struct ntfs_device *dev);
77         s64 (*seek)(struct ntfs_device *dev, s64 offset, int whence);
78         s64 (*read)(struct ntfs_device *dev, void *buf, s64 count);
79         s64 (*write)(struct ntfs_device *dev, const void *buf, s64 count);
80         s64 (*pread)(struct ntfs_device *dev, void *buf, s64 count, s64 offset);
81         s64 (*pwrite)(struct ntfs_device *dev, const void *buf, s64 count,
82                         s64 offset);
83         int (*sync)(struct ntfs_device *dev);
84         int (*stat)(struct ntfs_device *dev, struct stat *buf);
85         int (*ioctl)(struct ntfs_device *dev, int request, void *argp);
86 };
87
88 struct ntfs_device *ntfs_device_alloc(const char *name, const long state,
89                 struct ntfs_device_operations *dops, void *private);
90 int ntfs_device_free(struct ntfs_device *dev);
91
92 #endif /* defined _NTFS_DEVICE_H */