File: devtype.h

package info (click to toggle)
s390-tools 2.35.0-3
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 12,248 kB
  • sloc: ansic: 184,236; sh: 12,152; cpp: 4,954; makefile: 2,763; perl: 2,519; asm: 1,085; python: 697; xml: 29
file content (112 lines) | stat: -rw-r--r-- 3,687 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/*
 * zdev - Modify and display the persistent configuration of devices
 *
 * Copyright IBM Corp. 2016, 2017
 *
 * s390-tools is free software; you can redistribute it and/or modify
 * it under the terms of the MIT license. See LICENSE for details.
 */

#ifndef DEVTYPE_H
#define DEVTYPE_H

#include <stddef.h>

#include "exit_code.h"
#include "misc.h"

#define DEVTYPE_TITLE_LEN	60

struct devtype;
struct device;
struct devnode;
struct namespace;
struct selected_dev_node;
struct subtype;
struct util_list;

/* NULL-terminated list of device types. */
extern struct devtype *devtypes[];

/* Define a NULL-terminated list of struct subtypes */
#define SUBTYPE_ARRAY(...)	((struct subtype *[]) { __VA_ARGS__ NULL })

/**
 * struct devtype - Definition of a device type
 * @name: Short name of this device type
 * @title: Short description of this device type (max. 60 characters).
 *         devtypes with empty title will not be shown with --list-types.
 * @devname: Short name for devices of this device type
 * @modules: (Optional) Array of kernel modules required for this devtype
 * @site_support: Support for site-specific configuration for the device-type
 * @subtypes: Array of subtypes
 * @type_attribs: Array of device type attributes (may point to empty array)
 * @unknown_type_attribs: Allow specification of unknown device type attributes
 * @processed: Set if device type has already been processed
 *
 * @active_settings: Device type settings from the active configuration
 * @persistent_settings: Device type settings from the persistent configuration
 * @active_exists: Devtype configuration exists in active configuration
 * @persistent_exists: Devtype configuration exists in persistent configuration
 *
 * @init: Initialize device type
 * @exit: Release dynamically allocated resources associated with this type
 * @read_settings: Retrieve device type settings from specified configuration
 * @write_settings: Apply device type settings to specified configuration
 */
struct devtype {
	/* Static data */
	const char	*name;
	const char	title[DEVTYPE_TITLE_LEN + 1];
	const char	*devname;
	const char	**modules;
	unsigned int	site_support:1;

	struct subtype **subtypes;
	struct attrib **type_attribs;
	unsigned int	unknown_type_attribs:1;

	/* Dynamic data */
	struct setting_list *active_settings;
	struct setting_list *persistent_settings;
	unsigned int	active_exists:1;
	unsigned int	persistent_exists:1;
	unsigned int	processed:1;

	/* Methods */
	void		(*init)(struct devtype *);
	void		(*exit)(struct devtype *);

	/* Devtype settings. */
	exit_code_t	(*read_settings)(struct devtype *, config_t);
	exit_code_t	(*write_settings)(struct devtype *, config_t);
};

void devtypes_init(void);
void devtypes_exit(void);

void devtype_print(struct devtype *, int);

struct devtype *devtype_find(const char *);
struct attrib *devtype_find_type_attrib(struct devtype *, const char *);
struct attrib *devtype_find_dev_attrib(struct devtype *, const char *);

exit_code_t devtype_apply_settings(struct devtype *, config_t,
				   struct util_list *);
exit_code_t devtype_apply_strlist(struct devtype *, config_t,
				  struct util_list *);

bool devtype_is_id_valid(struct devtype *, const char *);
bool devtype_is_id_range_valid(struct devtype *, const char *);
bool devtype_needs_writing(struct devtype *, config_t);

void devtype_add_modules(struct util_list *, struct devtype *, int);
bool devtype_is_module_loaded(struct devtype *);
int devtype_count_namespaces(struct devtype *);
int devtype_count_subtypes(struct devtype *);

struct namespace *devtype_most_similar_namespace(struct devtype *,
						 struct subtype *,
						 const char *id);

#endif /* DEVTYPE_H */