]> granicus.if.org Git - sysstat/blob - ioconf.h
ioconf.c: Fix several ressource leaks
[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     31
14 #define IOC_DESCLEN     63
15 #define IOC_DEVLEN      47
16 #define IOC_MAXMINOR    2047
17 #define IOC_LINESIZ     255
18 #define IOC_FMTLEN      15
19
20 #ifndef MAX_BLKDEV
21 #define MAX_BLKDEV      255
22 #endif
23
24 #define K_NODEV "nodev"
25
26 #define IS_WHOLE(maj,min)       ((min % ioconf[maj]->blkp->pcount) == 0)
27
28 /*
29  * When is C going to get templates?
30  */
31 #define IOC_ALLOC(P,TYPE,SIZE)                  \
32      do {                                       \
33          if (P == NULL) {                       \
34               P = (TYPE *) malloc(SIZE);        \
35               if (P == NULL) {                  \
36                    perror("malloc");            \
37                    ioc_free();                  \
38                    goto free_and_return;        \
39               }                                 \
40          }                                      \
41      }                                          \
42      while (0)
43 /* That dummy while allows ';' on the line that invokes the macro... */
44
45
46 struct blk_config {
47         char name[IOC_NAMELEN + 1];     /* device basename */
48         char cfmt[IOC_FMTLEN + 1];      /* controller format string */
49         char dfmt[IOC_FMTLEN + 1];      /* disk format string */
50         char pfmt[IOC_FMTLEN + 1];      /* partition format string */
51         /* ctrlno is in the ioc_entry */
52         unsigned int ctrl_explicit;     /* use "cN" in name */
53         unsigned int dcount;            /* number of devices handled by this major */
54         unsigned int pcount;            /* partitions per device */
55         char desc[IOC_DESCLEN + 1];
56         /* disk info unit # conversion function */
57         char *(*cconv)(unsigned int);
58
59         /* extension properties (all this for initrd?) */
60         char ext_name[IOC_NAMELEN + 1];
61         unsigned int ext;               /* flag - this is an extension record */
62         unsigned int ext_minor;         /* which minor does this apply to */
63 };
64
65 #define BLK_CONFIG_SIZE (sizeof(struct blk_config))
66
67
68 struct ioc_entry {
69         int live;                       /* is this a Direct entry? */
70         unsigned int ctrlno;            /* controller number */
71         unsigned int basemajor;         /* Major number of the template */
72         char *desc;                     /* (dynamic) per-controller description */
73         struct blk_config *blkp;        /* the real info, may be a shared ref */
74 };
75
76 #define IOC_ENTRY_SIZE  (sizeof(struct ioc_entry))
77
78
79 extern int   ioc_iswhole(unsigned int, unsigned int);
80 extern char *ioc_name(unsigned int, unsigned int);
81 extern char *transform_devmapname(unsigned int, unsigned int);
82
83 #endif