]> granicus.if.org Git - sysstat/blob - ioconf.h
Merge pull request #346 from Kwstubbs/Kwstubbs/add-codeql-workflow
[sysstat] / ioconf.h
1 /*
2  * ioconf: ioconf configuration file handling code
3  * Original code (C) 2004 by Red Hat (Charlie Bennett <ccb@redhat.com>)
4  *
5  * Modified and maintained by Sebastien GODARD (sysstat <at> orange.fr)
6  */
7
8 #ifndef _IOCONF_H
9 #define _IOCONF_H
10
11 #include "sysconfig.h"
12
13 #define IOC_NAMELEN     32
14 #define IOC_DESCLEN     64
15 #define IOC_DEVLEN      48
16 #define IOC_LINESIZ     256
17 #define IOC_FMTLEN      16
18 #define IOC_XFMTLEN     (IOC_FMTLEN + IOC_NAMELEN + 3)
19
20 #ifndef MINORBITS
21 #define MINORBITS       20
22 #endif
23 #define IOC_MAXMINOR    ((1U << MINORBITS) - 1)
24 #ifndef MAX_BLKDEV
25 /* #define MAX_BLKDEV   ((1U << (32 - MINORBITS)) - 1) */
26 /* Use a lower value since this value is used to allocate arrays statically in ioconf.c */
27 #define MAX_BLKDEV      511
28 #endif
29
30 #define K_NODEV "nodev"
31
32 #define IS_WHOLE(maj,min)       ((min % ioconf[maj]->blkp->pcount) == 0)
33
34 /*
35  * When is C going to get templates?
36  */
37 #define IOC_ALLOC(P,TYPE,SIZE)                  \
38      do {                                       \
39          if (P == NULL) {                       \
40               P = (TYPE *) malloc(SIZE);        \
41               if (P == NULL) {                  \
42                    perror("malloc");            \
43                    ioc_free();                  \
44                    goto free_and_return;        \
45               }                                 \
46          }                                      \
47      }                                          \
48      while (0)
49 /* That dummy while allows ';' on the line that invokes the macro... */
50
51
52 struct blk_config {
53         char name[IOC_NAMELEN]; /* device basename */
54         char cfmt[IOC_XFMTLEN]; /* controller format string */
55         char dfmt[IOC_FMTLEN];  /* disk format string */
56         char pfmt[IOC_FMTLEN + 2];      /* partition format string */
57         /* ctrlno is in the ioc_entry */
58         unsigned int ctrl_explicit;     /* use "cN" in name */
59         unsigned int dcount;            /* number of devices handled by this major */
60         unsigned int pcount;            /* partitions per device */
61         char desc[IOC_DESCLEN];
62         /* disk info unit # conversion function */
63         char *(*cconv)(unsigned int);
64
65         /* extension properties (all this for initrd?) */
66         char ext_name[IOC_NAMELEN];
67         unsigned int ext;               /* flag - this is an extension record */
68         unsigned int ext_minor;         /* which minor does this apply to */
69 };
70
71 #define BLK_CONFIG_SIZE (sizeof(struct blk_config))
72
73
74 struct ioc_entry {
75         int live;                       /* is this a Direct entry? */
76         unsigned int ctrlno;            /* controller number */
77         unsigned int basemajor;         /* Major number of the template */
78         char *desc;                     /* (dynamic) per-controller description */
79         struct blk_config *blkp;        /* the real info, may be a shared ref */
80 };
81
82 #define IOC_ENTRY_SIZE  (sizeof(struct ioc_entry))
83
84
85 int ioc_iswhole
86         (unsigned int, unsigned int);
87 char *ioc_name
88         (unsigned int, unsigned int);
89 char *transform_devmapname
90         (unsigned int, unsigned int);
91
92 #endif