root/lm-sensors/tags/V2-10-2/lib/data.h

Revision 4287, 6.2 kB (checked in by mmh, 2 years ago)

The sensors library relied on one structure having an identical layout in
memory as part of another structure. This rather large patch fixes that by
making the smaller piece an explicit member of the larger.

I brought this patch into sync with the latest SVN, and tested it by comparing
objects files from the tree pre- and post- patch.

The remaining 99% of the credit goes to Bob Schlärmann <bob2@dsv.nl> for
creating the original patch... thanks Bob!

* Bob Schlärmann <bob2@dsv.nl> [2006-12-24 18:29:39 +0100]:

The following patch changes all of the lib/chips.c entries and any function
that uses sensors_chip_feature. Most of the conversion was done through a
perl script, so if you don't agree with the syntax it'll be easy to change.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1 /*
2     data.h - Part of libsensors, a Linux library for reading sensor data.
3     Copyright (c) 1998, 1999  Frodo Looijaard <frodol@dds.nl>
4
5     This program is free software; you can redistribute it and/or modify
6     it under the terms of the GNU General Public License as published by
7     the Free Software Foundation; either version 2 of the License, or
8     (at your option) any later version.
9
10     This program is distributed in the hope that it will be useful,
11     but WITHOUT ANY WARRANTY; without even the implied warranty of
12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13     GNU General Public License for more details.
14
15     You should have received a copy of the GNU General Public License
16     along with this program; if not, write to the Free Software
17     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19
20 #ifndef LIB_SENSORS_DATA_H
21 #define LIB_SENSORS_DATA_H
22
23 #include "sensors.h"
24
25 /* This header file contains all kinds of data structures which are used
26    for the representation of the config file data and the /proc/...
27    data. */
28
29 /* Kinds of expression operators recognized */
30 typedef enum sensors_operation {
31   sensors_add, sensors_sub, sensors_multiply, sensors_divide,
32   sensors_negate, sensors_exp, sensors_log } sensors_operation;
33
34 /* An expression can have several forms */
35 typedef enum sensors_expr_kind {
36   sensors_kind_val, sensors_kind_source, sensors_kind_var,
37   sensors_kind_sub } sensors_expr_kind;
38
39 /* An expression. It is either a floating point value, a variable name,
40    an operation on subexpressions, or the special value 'sub' } */
41 struct sensors_expr;
42
43 typedef struct sensors_subexpr {
44   sensors_operation op;
45   struct sensors_expr *sub1;
46   struct sensors_expr *sub2;
47 } sensors_subexpr;
48
49 typedef struct sensors_expr {
50   sensors_expr_kind kind;
51   union {
52     double val;
53     char *var;
54     sensors_subexpr subexpr;
55   } data;
56 } sensors_expr;
57
58 /* Config file label declaration: a feature name, combined with the label
59    value */
60 typedef struct sensors_label {
61   char *name;
62   char *value;
63   int lineno;
64 } sensors_label;
65
66 /* Config file set declaration: a feature name, combined with an expression */
67 typedef struct sensors_set {
68   char *name;
69   sensors_expr *value;
70   int lineno;
71 } sensors_set;
72
73 /* Config file compute declaration: a feature name, combined with two
74    expressions */
75 typedef struct sensors_compute {
76   char *name;
77   sensors_expr *from_proc;
78   sensors_expr *to_proc;
79   int lineno;
80 } sensors_compute;
81
82 /* Config file ignore declaration: a feature name */
83 typedef struct sensors_ignore {
84   char *name;
85   int lineno;
86 } sensors_ignore;
87
88 /* A list of chip names, used to represent a config file chips declaration */
89 typedef struct sensors_chip_name_list {
90   sensors_chip_name *fits;
91   int fits_count;
92   int fits_max;
93 } sensors_chip_name_list;
94
95 /* A config file chip block */
96 typedef struct sensors_chip {
97   sensors_chip_name_list chips;
98   sensors_label *labels;
99   int labels_count;
100   int labels_max;
101   sensors_set *sets;
102   int sets_count;
103   int sets_max;
104   sensors_compute *computes;
105   int computes_count;
106   int computes_max;
107   sensors_ignore *ignores;
108   int ignores_count;
109   int ignores_max;
110   int lineno;
111 } sensors_chip;
112
113 /* Config file bus declaration: the i2c bus number, combined with adapter
114    name */
115 typedef struct sensors_bus {
116   int number;
117   char *adapter;
118   int lineno;
119 } sensors_bus;
120
121 /* /proc/sys/dev/sensors/chips line representation */
122 typedef struct sensors_proc_chips_entry {
123   int sysctl;
124   sensors_chip_name name;
125 } sensors_proc_chips_entry;
126
127 /* Internal data about a single chip feature.
128    name is the string name used to refer to this feature (both in config
129      files and through user functions);
130    number is the internal feature number, used in many functions to refer
131      to this feature
132    logical_mapping is either SENSORS_NO_MAPPING if this is feature is the
133      main element of category; or it is the number of a feature with which
134      this feature is logically grouped (a group could be fan, fan_max and
135      fan_div)
136    compute_mapping is like logical_mapping, only it refers to another
137      feature whose compute line will be inherited (a group could be fan and
138      fan_max, but not fan_div)
139    mode is SENSORS_MODE_NO_RW, SENSORS_MODE_R, SENSORS_MODE_W or
140      SENSORS_MODE_RW, for unaccessible, readable, writable, and both readable
141      and writable.
142    sysctl is the SYSCTL id of the file the value can be found in.
143    offset is the (byte) offset of the place this feature can be found.
144    scaling is the number of decimal points to scale by.
145      This scaling is performed on the raw sysctl value, NOT the value
146      seen in /proc. Therefore the scaling value must be the same as
147      the value returned in nrels_mag by the SENSORS_PROC_REAL_INFO
148      operation in the chip drivers.
149      Divide the read value by 10**scaling to get the real value.
150      Scaling can be positive or negative but negative values aren't
151      very useful because the driver can scale that direction itself. */
152 typedef struct sensors_chip_feature {
153   sensors_feature_data data;
154   int sysctl;
155   int offset;
156   int scaling;
157   const char *sysname;
158   int sysscaling;
159   const char *altsysname;
160 } sensors_chip_feature;
161
162 /* Internal data about all features of a type of chip */
163 typedef struct sensors_chip_features {
164   const char *prefix;
165   struct sensors_chip_feature *feature;
166 } sensors_chip_features;
167
168 extern sensors_chip *sensors_config_chips;
169 extern int sensors_config_chips_count;
170 extern int sensors_config_chips_max;
171
172 extern sensors_bus *sensors_config_busses;
173 extern int sensors_config_busses_count;
174 extern int sensors_config_busses_max;
175
176 extern sensors_proc_chips_entry *sensors_proc_chips;
177 extern int sensors_proc_chips_count;
178 extern int sensors_proc_chips_max;
179
180 #define sensors_add_proc_chips(el) sensors_add_array_el( \
181         (el), &sensors_proc_chips, &sensors_proc_chips_count,\
182         &sensors_proc_chips_max, sizeof(struct sensors_proc_chips_entry))
183
184 extern sensors_bus *sensors_proc_bus;
185 extern int sensors_proc_bus_count;
186 extern int sensors_proc_bus_max;
187
188 #define sensors_add_proc_bus(el) sensors_add_array_el( \
189         (el), &sensors_proc_bus, &sensors_proc_bus_count,\
190         &sensors_proc_bus_max, sizeof(struct sensors_bus))
191
192 extern sensors_chip_features sensors_chip_features_list[];
193
194 #endif /* def LIB_SENSORS_DATA_H */
Note: See TracBrowser for help on using the browser.