Subversion Repositories shark

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
422 giacomo 1
#ifndef _LINUX_GENHD_H
2
#define _LINUX_GENHD_H
3
 
4
/*
5
 *      genhd.h Copyright (C) 1992 Drew Eckhardt
6
 *      Generic hard disk header file by  
7
 *              Drew Eckhardt
8
 *
9
 *              <drew@colorado.edu>
10
 */
11
 
12
#include <linux/config.h>
13
#include <linux/types.h>
14
#include <linux/major.h>
15
#include <linux/device.h>
16
#include <linux/smp.h>
17
#include <linux/string.h>
18
#include <linux/fs.h>
19
 
20
enum {
21
/* These three have identical behaviour; use the second one if DOS FDISK gets
22
   confused about extended/logical partitions starting past cylinder 1023. */
23
        DOS_EXTENDED_PARTITION = 5,
24
        LINUX_EXTENDED_PARTITION = 0x85,
25
        WIN98_EXTENDED_PARTITION = 0x0f,
26
 
27
        LINUX_SWAP_PARTITION = 0x82,
28
        LINUX_RAID_PARTITION = 0xfd,    /* autodetect RAID partition */
29
 
30
        SOLARIS_X86_PARTITION = LINUX_SWAP_PARTITION,
31
 
32
        DM6_AUX1PARTITION = 0x51,       /* no DDO:  use xlated geom */
33
        DM6_AUX3PARTITION = 0x53,       /* no DDO:  use xlated geom */
34
        DM6_PARTITION = 0x54,           /* has DDO: use xlated geom & offset */
35
        EZD_PARTITION = 0x55,           /* EZ-DRIVE */
36
 
37
        FREEBSD_PARTITION = 0xa5,       /* FreeBSD Partition ID */
38
        OPENBSD_PARTITION = 0xa6,       /* OpenBSD Partition ID */
39
        NETBSD_PARTITION = 0xa9,        /* NetBSD Partition ID */
40
        BSDI_PARTITION = 0xb7,          /* BSDI Partition ID */
41
        MINIX_PARTITION = 0x81,         /* Minix Partition ID */
42
        UNIXWARE_PARTITION = 0x63,      /* Same as GNU_HURD and SCO Unix */
43
};
44
 
45
struct partition {
46
        unsigned char boot_ind;         /* 0x80 - active */
47
        unsigned char head;             /* starting head */
48
        unsigned char sector;           /* starting sector */
49
        unsigned char cyl;              /* starting cylinder */
50
        unsigned char sys_ind;          /* What partition type */
51
        unsigned char end_head;         /* end head */
52
        unsigned char end_sector;       /* end sector */
53
        unsigned char end_cyl;          /* end cylinder */
54
        unsigned int start_sect;        /* starting sector counting from 0 */
55
        unsigned int nr_sects;          /* nr of sectors in partition */
56
} __attribute__((packed));
57
 
58
#ifdef __KERNEL__
59
struct hd_struct {
60
        sector_t start_sect;
61
        sector_t nr_sects;
62
        struct kobject kobj;
63
        unsigned reads, read_sectors, writes, write_sectors;
64
        int policy, partno;
65
};
66
 
67
#define GENHD_FL_REMOVABLE  1
68
#define GENHD_FL_DRIVERFS  2
69
#define GENHD_FL_CD     8
70
#define GENHD_FL_UP     16
71
 
72
struct disk_stats {
73
        unsigned read_sectors, write_sectors;
74
        unsigned reads, writes;
75
        unsigned read_merges, write_merges;
76
        unsigned read_ticks, write_ticks;
77
        unsigned io_ticks;
78
        unsigned time_in_queue;
79
};
80
 
81
struct gendisk {
82
        int major;                      /* major number of driver */
83
        int first_minor;
84
        int minors;
85
        char disk_name[16];             /* name of major driver */
86
        struct hd_struct **part;        /* [indexed by minor] */
87
        struct block_device_operations *fops;
88
        struct request_queue *queue;
89
        void *private_data;
90
        sector_t capacity;
91
 
92
        int flags;
93
        char devfs_name[64];            /* devfs crap */
94
        int number;                     /* more of the same */
95
        struct device *driverfs_dev;
96
        struct kobject kobj;
97
 
98
        struct timer_rand_state *random;
99
        int policy;
100
 
101
        unsigned sync_io;               /* RAID */
102
        unsigned long stamp, stamp_idle;
103
        int in_flight;
104
#ifdef  CONFIG_SMP
105
        struct disk_stats *dkstats;
106
#else
107
        struct disk_stats dkstats;
108
#endif
109
};
110
 
111
/*
112
 * Macros to operate on percpu disk statistics:
113
 * Since writes to disk_stats are serialised through the queue_lock,
114
 * smp_processor_id() should be enough to get to the per_cpu versions
115
 * of statistics counters
116
 */
117
#ifdef  CONFIG_SMP
118
#define disk_stat_add(gendiskp, field, addnd)   \
119
        (per_cpu_ptr(gendiskp->dkstats, smp_processor_id())->field += addnd)
120
#define disk_stat_read(gendiskp, field)                                 \
121
({                                                                      \
122
        typeof(gendiskp->dkstats->field) res = 0;                       \
123
        int i;                                                          \
124
        for (i=0; i < NR_CPUS; i++) {                                   \
125
                if (!cpu_possible(i))                                   \
126
                        continue;                                       \
127
                res += per_cpu_ptr(gendiskp->dkstats, i)->field;        \
128
        }                                                               \
129
        res;                                                            \
130
})
131
 
132
static inline void disk_stat_set_all(struct gendisk *gendiskp, int value)       {
133
        int i;
134
        for (i=0; i < NR_CPUS; i++) {
135
                if (cpu_possible(i)) {
136
                        memset(per_cpu_ptr(gendiskp->dkstats, i), value,       
137
                                        sizeof (struct disk_stats));
138
                }
139
        }
140
}              
141
 
142
#else
143
#define disk_stat_add(gendiskp, field, addnd) (gendiskp->dkstats.field += addnd)
144
#define disk_stat_read(gendiskp, field) (gendiskp->dkstats.field)
145
 
146
static inline void disk_stat_set_all(struct gendisk *gendiskp, int value)       {
147
        memset(&gendiskp->dkstats, value, sizeof (struct disk_stats));
148
}
149
#endif
150
 
151
#define disk_stat_inc(gendiskp, field) disk_stat_add(gendiskp, field, 1)
152
#define disk_stat_dec(gendiskp, field) disk_stat_add(gendiskp, field, -1)
153
#define disk_stat_sub(gendiskp, field, subnd) \
154
                disk_stat_add(gendiskp, field, -subnd)
155
 
156
 
157
/* Inlines to alloc and free disk stats in struct gendisk */
158
#ifdef  CONFIG_SMP
159
static inline int init_disk_stats(struct gendisk *disk)
160
{
161
        disk->dkstats = alloc_percpu(struct disk_stats);
162
        if (!disk->dkstats)
163
                return 0;
164
        return 1;
165
}
166
 
167
static inline void free_disk_stats(struct gendisk *disk)
168
{
169
        free_percpu(disk->dkstats);
170
}
171
#else   /* CONFIG_SMP */
172
static inline int init_disk_stats(struct gendisk *disk)
173
{
174
        return 1;
175
}
176
 
177
static inline void free_disk_stats(struct gendisk *disk)
178
{
179
}
180
#endif  /* CONFIG_SMP */
181
 
182
/* drivers/block/ll_rw_blk.c */
183
extern void disk_round_stats(struct gendisk *disk);
184
 
185
/* drivers/block/genhd.c */
186
extern void add_disk(struct gendisk *disk);
187
extern void del_gendisk(struct gendisk *gp);
188
extern void unlink_gendisk(struct gendisk *gp);
189
extern struct gendisk *get_gendisk(dev_t dev, int *part);
190
 
191
extern void set_device_ro(struct block_device *bdev, int flag);
192
extern void set_disk_ro(struct gendisk *disk, int flag);
193
 
194
/* drivers/char/random.c */
195
extern void add_disk_randomness(struct gendisk *disk);
196
extern void rand_initialize_disk(struct gendisk *disk);
197
 
198
static inline sector_t get_start_sect(struct block_device *bdev)
199
{
200
        return bdev->bd_contains == bdev ? 0 : bdev->bd_part->start_sect;
201
}
202
static inline sector_t get_capacity(struct gendisk *disk)
203
{
204
        return disk->capacity;
205
}
206
static inline void set_capacity(struct gendisk *disk, sector_t size)
207
{
208
        disk->capacity = size;
209
}
210
 
211
#endif  /*  __KERNEL__  */
212
 
213
#ifdef CONFIG_SOLARIS_X86_PARTITION
214
 
215
#define SOLARIS_X86_NUMSLICE    8
216
#define SOLARIS_X86_VTOC_SANE   (0x600DDEEEUL)
217
 
218
struct solaris_x86_slice {
219
        ushort  s_tag;                  /* ID tag of partition */
220
        ushort  s_flag;                 /* permission flags */
221
        unsigned int s_start;           /* start sector no of partition */
222
        unsigned int s_size;            /* # of blocks in partition */
223
};
224
 
225
struct solaris_x86_vtoc {
226
        unsigned int v_bootinfo[3];     /* info needed by mboot (unsupported) */
227
        unsigned int v_sanity;          /* to verify vtoc sanity */
228
        unsigned int v_version;         /* layout version */
229
        char    v_volume[8];            /* volume name */
230
        ushort  v_sectorsz;             /* sector size in bytes */
231
        ushort  v_nparts;               /* number of partitions */
232
        unsigned int v_reserved[10];    /* free space */
233
        struct solaris_x86_slice
234
                v_slice[SOLARIS_X86_NUMSLICE]; /* slice headers */
235
        unsigned int timestamp[SOLARIS_X86_NUMSLICE]; /* timestamp (unsupported) */
236
        char    v_asciilabel[128];      /* for compatibility */
237
};
238
 
239
#endif /* CONFIG_SOLARIS_X86_PARTITION */
240
 
241
#ifdef CONFIG_BSD_DISKLABEL
242
/*
243
 * BSD disklabel support by Yossi Gottlieb <yogo@math.tau.ac.il>
244
 * updated by Marc Espie <Marc.Espie@openbsd.org>
245
 */
246
 
247
/* check against BSD src/sys/sys/disklabel.h for consistency */
248
 
249
#define BSD_DISKMAGIC   (0x82564557UL)  /* The disk magic number */
250
#define BSD_MAXPARTITIONS       8
251
#define OPENBSD_MAXPARTITIONS   16
252
#define BSD_FS_UNUSED           0       /* disklabel unused partition entry ID */
253
struct bsd_disklabel {
254
        __u32   d_magic;                /* the magic number */
255
        __s16   d_type;                 /* drive type */
256
        __s16   d_subtype;              /* controller/d_type specific */
257
        char    d_typename[16];         /* type name, e.g. "eagle" */
258
        char    d_packname[16];                 /* pack identifier */
259
        __u32   d_secsize;              /* # of bytes per sector */
260
        __u32   d_nsectors;             /* # of data sectors per track */
261
        __u32   d_ntracks;              /* # of tracks per cylinder */
262
        __u32   d_ncylinders;           /* # of data cylinders per unit */
263
        __u32   d_secpercyl;            /* # of data sectors per cylinder */
264
        __u32   d_secperunit;           /* # of data sectors per unit */
265
        __u16   d_sparespertrack;       /* # of spare sectors per track */
266
        __u16   d_sparespercyl;         /* # of spare sectors per cylinder */
267
        __u32   d_acylinders;           /* # of alt. cylinders per unit */
268
        __u16   d_rpm;                  /* rotational speed */
269
        __u16   d_interleave;           /* hardware sector interleave */
270
        __u16   d_trackskew;            /* sector 0 skew, per track */
271
        __u16   d_cylskew;              /* sector 0 skew, per cylinder */
272
        __u32   d_headswitch;           /* head switch time, usec */
273
        __u32   d_trkseek;              /* track-to-track seek, usec */
274
        __u32   d_flags;                /* generic flags */
275
#define NDDATA 5
276
        __u32   d_drivedata[NDDATA];    /* drive-type specific information */
277
#define NSPARE 5
278
        __u32   d_spare[NSPARE];        /* reserved for future use */
279
        __u32   d_magic2;               /* the magic number (again) */
280
        __u16   d_checksum;             /* xor of data incl. partitions */
281
 
282
                        /* filesystem and partition information: */
283
        __u16   d_npartitions;          /* number of partitions in following */
284
        __u32   d_bbsize;               /* size of boot area at sn0, bytes */
285
        __u32   d_sbsize;               /* max size of fs superblock, bytes */
286
        struct  bsd_partition {         /* the partition table */
287
                __u32   p_size;         /* number of sectors in partition */
288
                __u32   p_offset;       /* starting sector */
289
                __u32   p_fsize;        /* filesystem basic fragment size */
290
                __u8    p_fstype;       /* filesystem type, see below */
291
                __u8    p_frag;         /* filesystem fragments per block */
292
                __u16   p_cpg;          /* filesystem cylinders per group */
293
        } d_partitions[BSD_MAXPARTITIONS];      /* actually may be more */
294
};
295
 
296
#endif  /* CONFIG_BSD_DISKLABEL */
297
 
298
#ifdef CONFIG_UNIXWARE_DISKLABEL
299
/*
300
 * Unixware slices support by Andrzej Krzysztofowicz <ankry@mif.pg.gda.pl>
301
 * and Krzysztof G. Baranowski <kgb@knm.org.pl>
302
 */
303
 
304
#define UNIXWARE_DISKMAGIC     (0xCA5E600DUL)   /* The disk magic number */
305
#define UNIXWARE_DISKMAGIC2    (0x600DDEEEUL)   /* The slice table magic nr */
306
#define UNIXWARE_NUMSLICE      16
307
#define UNIXWARE_FS_UNUSED     0                /* Unused slice entry ID */
308
 
309
struct unixware_slice {
310
        __u16   s_label;        /* label */
311
        __u16   s_flags;        /* permission flags */
312
        __u32   start_sect;     /* starting sector */
313
        __u32   nr_sects;       /* number of sectors in slice */
314
};
315
 
316
struct unixware_disklabel {
317
        __u32   d_type;                 /* drive type */
318
        __u32   d_magic;                /* the magic number */
319
        __u32   d_version;              /* version number */
320
        char    d_serial[12];           /* serial number of the device */
321
        __u32   d_ncylinders;           /* # of data cylinders per device */
322
        __u32   d_ntracks;              /* # of tracks per cylinder */
323
        __u32   d_nsectors;             /* # of data sectors per track */
324
        __u32   d_secsize;              /* # of bytes per sector */
325
        __u32   d_part_start;           /* # of first sector of this partition */
326
        __u32   d_unknown1[12];         /* ? */
327
        __u32   d_alt_tbl;              /* byte offset of alternate table */
328
        __u32   d_alt_len;              /* byte length of alternate table */
329
        __u32   d_phys_cyl;             /* # of physical cylinders per device */
330
        __u32   d_phys_trk;             /* # of physical tracks per cylinder */
331
        __u32   d_phys_sec;             /* # of physical sectors per track */
332
        __u32   d_phys_bytes;           /* # of physical bytes per sector */
333
        __u32   d_unknown2;             /* ? */
334
        __u32   d_unknown3;             /* ? */
335
        __u32   d_pad[8];               /* pad */
336
 
337
        struct unixware_vtoc {
338
                __u32   v_magic;                /* the magic number */
339
                __u32   v_version;              /* version number */
340
                char    v_name[8];              /* volume name */
341
                __u16   v_nslices;              /* # of slices */
342
                __u16   v_unknown1;             /* ? */
343
                __u32   v_reserved[10];         /* reserved */
344
                struct unixware_slice
345
                        v_slice[UNIXWARE_NUMSLICE];     /* slice headers */
346
        } vtoc;
347
 
348
};  /* 408 */
349
 
350
#endif /* CONFIG_UNIXWARE_DISKLABEL */
351
 
352
#ifdef CONFIG_MINIX_SUBPARTITION
353
#   define MINIX_NR_SUBPARTITIONS  4
354
#endif /* CONFIG_MINIX_SUBPARTITION */
355
 
356
#ifdef __KERNEL__
357
 
358
char *disk_name (struct gendisk *hd, int part, char *buf);
359
 
360
extern int rescan_partitions(struct gendisk *disk, struct block_device *bdev);
361
extern void add_partition(struct gendisk *, int, sector_t, sector_t);
362
extern void delete_partition(struct gendisk *, int);
363
 
364
extern struct gendisk *alloc_disk(int minors);
365
extern struct kobject *get_disk(struct gendisk *disk);
366
extern void put_disk(struct gendisk *disk);
367
 
368
extern void blk_register_region(dev_t dev, unsigned long range,
369
                        struct module *module,
370
                        struct kobject *(*probe)(dev_t, int *, void *),
371
                        int (*lock)(dev_t, void *),
372
                        void *data);
373
extern void blk_unregister_region(dev_t dev, unsigned long range);
374
 
375
static inline struct block_device *bdget_disk(struct gendisk *disk, int index)
376
{
377
        return bdget(MKDEV(disk->major, disk->first_minor) + index);
378
}
379
 
380
#endif
381
 
382
#endif