1 /*
   2  * device.h - Exports for low level device io. Part of the Linux-NTFS project.
   3  *
   4  * Copyright (c) 2000-2006 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 #ifdef HAVE_CONFIG_H
  26 #include "config.h"
  27 #endif
  28 
  29 #include "device_io.h"
  30 #include "types.h"
  31 #include "support.h"
  32 #include "volume.h"
  33 
  34 /**
  35  * enum ntfs_device_state_bits -
  36  *
  37  * Defined bits for the state field in the ntfs_device structure.
  38  */
  39 typedef enum {
  40         ND_Open,        /* 1: Device is open. */
  41         ND_ReadOnly,    /* 1: Device is read-only. */
  42         ND_Dirty,       /* 1: Device is dirty, needs sync. */
  43         ND_Block,       /* 1: Device is a block device. */
  44 } ntfs_device_state_bits;
  45 
  46 #define  test_ndev_flag(nd, flag)          test_bit(ND_##flag, (nd)->d_state)
  47 #define   set_ndev_flag(nd, flag)           set_bit(ND_##flag, (nd)->d_state)
  48 #define clear_ndev_flag(nd, flag)         clear_bit(ND_##flag, (nd)->d_state)
  49 
  50 #define NDevOpen(nd)             test_ndev_flag(nd, Open)
  51 #define NDevSetOpen(nd)           set_ndev_flag(nd, Open)
  52 #define NDevClearOpen(nd)       clear_ndev_flag(nd, Open)
  53 
  54 #define NDevReadOnly(nd)         test_ndev_flag(nd, ReadOnly)
  55 #define NDevSetReadOnly(nd)       set_ndev_flag(nd, ReadOnly)
  56 #define NDevClearReadOnly(nd)   clear_ndev_flag(nd, ReadOnly)
  57 
  58 #define NDevDirty(nd)            test_ndev_flag(nd, Dirty)
  59 #define NDevSetDirty(nd)          set_ndev_flag(nd, Dirty)
  60 #define NDevClearDirty(nd)      clear_ndev_flag(nd, Dirty)
  61 
  62 #define NDevBlock(nd)            test_ndev_flag(nd, Block)
  63 #define NDevSetBlock(nd)          set_ndev_flag(nd, Block)
  64 #define NDevClearBlock(nd)      clear_ndev_flag(nd, Block)
  65 
  66 /**
  67  * struct ntfs_device -
  68  *
  69  * The ntfs device structure defining all operations needed to access the low
  70  * level device underlying the ntfs volume.
  71  */
  72 struct ntfs_device {
  73         struct ntfs_device_operations *d_ops;   /* Device operations. */
  74         unsigned long d_state;                  /* State of the device. */
  75         char *d_name;                           /* Name of device. */
  76         void *d_private;                        /* Private data used by the
  77                                                    device operations. */
  78 };
  79 
  80 struct stat;
  81 
  82 /**
  83  * struct ntfs_device_operations -
  84  *
  85  * The ntfs device operations defining all operations that can be performed on
  86  * the low level device described by an ntfs device structure.
  87  */
  88 struct ntfs_device_operations {
  89         int (*open)(struct ntfs_device *dev, int flags);
  90         int (*close)(struct ntfs_device *dev);
  91         s64 (*seek)(struct ntfs_device *dev, s64 offset, int whence);
  92         s64 (*read)(struct ntfs_device *dev, void *buf, s64 count);
  93         s64 (*write)(struct ntfs_device *dev, const void *buf, s64 count);
  94         s64 (*pread)(struct ntfs_device *dev, void *buf, s64 count, s64 offset);
  95         s64 (*pwrite)(struct ntfs_device *dev, const void *buf, s64 count,
  96                         s64 offset);
  97         int (*sync)(struct ntfs_device *dev);
  98         int (*stat)(struct ntfs_device *dev, struct stat *buf);
  99         int (*ioctl)(struct ntfs_device *dev, int request, void *argp);
 100 };
 101 
 102 extern struct ntfs_device *ntfs_device_alloc(const char *name, const long state,
 103                 struct ntfs_device_operations *dops, void *priv_data);
 104 extern int ntfs_device_free(struct ntfs_device *dev);
 105 
 106 extern s64 ntfs_pread(struct ntfs_device *dev, const s64 pos, s64 count,
 107                 void *b);
 108 extern s64 ntfs_pwrite(struct ntfs_device *dev, const s64 pos, s64 count,
 109                 const void *b);
 110 
 111 extern s64 ntfs_mst_pread(struct ntfs_device *dev, const s64 pos, s64 count,
 112                 const u32 bksize, void *b);
 113 extern s64 ntfs_mst_pwrite(struct ntfs_device *dev, const s64 pos, s64 count,
 114                 const u32 bksize, void *b);
 115 
 116 extern s64 ntfs_cluster_read(const ntfs_volume *vol, const s64 lcn,
 117                 const s64 count, void *b);
 118 extern s64 ntfs_cluster_write(const ntfs_volume *vol, const s64 lcn,
 119                 const s64 count, const void *b);
 120 
 121 extern s64 ntfs_device_size_get(struct ntfs_device *dev, int block_size);
 122 extern s64 ntfs_device_partition_start_sector_get(struct ntfs_device *dev);
 123 extern int ntfs_device_heads_get(struct ntfs_device *dev);
 124 extern int ntfs_device_sectors_per_track_get(struct ntfs_device *dev);
 125 extern int ntfs_device_sector_size_get(struct ntfs_device *dev);
 126 extern int ntfs_device_block_size_set(struct ntfs_device *dev, int block_size);
 127 
 128 #endif /* defined _NTFS_DEVICE_H */