]> git.ipfire.org Git - thirdparty/util-linux.git/blob - misc-utils/lsblk.h
lsblk: remove badly named debug interface name
[thirdparty/util-linux.git] / misc-utils / lsblk.h
1 /*
2 * Copyright (C) 2010-2018 Red Hat, Inc. All rights reserved.
3 * Written by Milan Broz <mbroz@redhat.com>
4 * Karel Zak <kzak@redhat.com>
5 */
6 #ifndef UTIL_LINUX_LSBLK_H
7 #define UTIL_LINUX_LSBLK_H
8
9 #include <stdint.h>
10 #include <inttypes.h>
11 #include <sys/stat.h>
12 #include <sys/statvfs.h>
13
14 #include <libsmartcols.h>
15
16 #include "c.h"
17 #include "list.h"
18 #include "debug.h"
19
20 #define LSBLK_DEBUG_INIT (1 << 1)
21 #define LSBLK_DEBUG_FILTER (1 << 2)
22 #define LSBLK_DEBUG_DEV (1 << 3)
23 #define LSBLK_DEBUG_TREE (1 << 4)
24 #define LSBLK_DEBUG_ALL 0xFFFF
25
26 UL_DEBUG_DECLARE_MASK(lsblk);
27 #define DBG(m, x) __UL_DBG(lsblk, LSBLK_DEBUG_, m, x)
28 #define ON_DBG(m, x) __UL_DBG_CALL(lsblk, LSBLK_DEBUG_, m, x)
29
30 #define UL_DEBUG_CURRENT_MASK UL_DEBUG_MASK(lsblk)
31 #include "debugobj.h"
32
33 struct lsblk {
34 struct libscols_table *table; /* output table */
35 struct libscols_column *sort_col;/* sort output by this column */
36 int sort_id;
37
38 const char *sysroot;
39 int flags; /* LSBLK_* */
40
41 unsigned int all_devices:1; /* print all devices, including empty */
42 unsigned int bytes:1; /* print SIZE in bytes */
43 unsigned int inverse:1; /* print inverse dependencies */
44 unsigned int nodeps:1; /* don't print slaves/holders */
45 unsigned int scsi:1; /* print only device with HCTL (SCSI) */
46 unsigned int paths:1; /* print devnames with "/dev" prefix */
47 unsigned int sort_hidden:1; /* sort column not between output columns */
48 unsigned int force_tree_order:1;/* sort lines by parent->tree relation */
49 };
50
51 extern struct lsblk *lsblk; /* global handler */
52
53 struct lsblk_devprop {
54 char *fstype; /* detected fs, NULL or "?" if cannot detect */
55 char *uuid; /* filesystem UUID (or stack uuid) */
56 char *ptuuid; /* partition table UUID */
57 char *pttype; /* partition table type */
58 char *label; /* filesystem label */
59 char *parttype; /* partition type UUID */
60 char *partuuid; /* partition UUID */
61 char *partlabel; /* partition label */
62 char *partflags; /* partition flags */
63 char *wwn; /* storage WWN */
64 char *serial; /* disk serial number */
65 char *model; /* disk model */
66 };
67
68 /* Device dependence
69 *
70 * Note that the same device may be slave/holder for more another devices. It
71 * means we need to allocate list member rather than use @child directly.
72 */
73 struct lsblk_devdep {
74 struct list_head ls_deps; /* item in parent->deps */
75 struct lsblk_device *child;
76 };
77
78 struct lsblk_device {
79 int refcount;
80
81 struct list_head deps; /* list with lsblk_devdep */
82 struct list_head ls_roots; /* item in devtree->roots list */
83 struct list_head ls_devices; /* item in devtree->devices list */
84
85 struct lsblk_devtree *tree;
86
87 struct lsblk_devprop *properties;
88 struct libscols_line *scols_line;
89
90 struct lsblk_device *parent; /* obsolete */
91 struct stat st;
92
93 char *name; /* kernel name in /sys/block */
94 char *dm_name; /* DM name (dm/block) */
95
96 char *filename; /* path to device node */
97
98 struct path_cxt *sysfs;
99
100 int partition; /* is partition? TRUE/FALSE */
101
102 char *mountpoint; /* device mountpoint */
103 struct statvfs fsstat; /* statvfs() result */
104
105 int npartitions; /* # of partitions this device has */
106 int nholders; /* # of devices mapped directly to this device
107 * /sys/block/.../holders */
108 int nslaves; /* # of devices this device maps to */
109 int maj, min; /* devno */
110 int discard; /* supports discard */
111
112 uint64_t size; /* device size */
113
114 unsigned int is_mounted : 1,
115 is_swap : 1,
116 udev_requested : 1,
117 blkid_requested : 1;
118 };
119
120
121 /*
122 * Note that lsblk tree uses botton devices (devices without slaves) as root
123 * of the tree, and partitions are interpreted as a dependence too; it means:
124 * sda -> sda1 -> md0
125 *
126 * The flag 'is_inverted' turns the tree over (root is device without holders):
127 * md0 -> sda1 -> sda
128 */
129 struct lsblk_devtree {
130 int refcount;
131
132 struct list_head roots; /* tree root devices */
133 struct list_head devices; /* all devices */
134
135 unsigned int is_inverse : 1; /* inverse tree */
136 };
137
138
139 /*
140 * Generic iterator
141 */
142 struct lsblk_iter {
143 struct list_head *p; /* current position */
144 struct list_head *head; /* start position */
145 int direction; /* LSBLK_ITER_{FOR,BACK}WARD */
146 };
147
148 #define LSBLK_ITER_FORWARD 0
149 #define LSBLK_ITER_BACKWARD 1
150
151 #define IS_ITER_FORWARD(_i) ((_i)->direction == LSBLK_ITER_FORWARD)
152 #define IS_ITER_BACKWARD(_i) ((_i)->direction == LSBLK_ITER_BACKWARD)
153
154 #define LSBLK_ITER_INIT(itr, list) \
155 do { \
156 (itr)->p = IS_ITER_FORWARD(itr) ? \
157 (list)->next : (list)->prev; \
158 (itr)->head = (list); \
159 } while(0)
160
161 #define LSBLK_ITER_ITERATE(itr, res, restype, member) \
162 do { \
163 res = list_entry((itr)->p, restype, member); \
164 (itr)->p = IS_ITER_FORWARD(itr) ? \
165 (itr)->p->next : (itr)->p->prev; \
166 } while(0)
167
168
169 /* lsblk-mnt.c */
170 extern void lsblk_mnt_init(void);
171 extern void lsblk_mnt_deinit(void);
172
173 extern char *lsblk_device_get_mountpoint(struct lsblk_device *dev);
174
175 /* lsblk-properties.c */
176 extern void lsblk_device_free_properties(struct lsblk_devprop *p);
177 extern struct lsblk_devprop *lsblk_device_get_properties(struct lsblk_device *dev);
178 extern void lsblk_properties_deinit(void);
179
180 /* lsblk-devtree.c */
181 void lsblk_reset_iter(struct lsblk_iter *itr, int direction);
182 struct lsblk_device *lsblk_new_device(struct lsblk_devtree *tree);
183 void lsblk_ref_device(struct lsblk_device *dev);
184 void lsblk_unref_device(struct lsblk_device *dev);
185 struct lsblk_devdep *lsblk_device_new_dependence(struct lsblk_device *parent, struct lsblk_device *child);
186 int lsblk_device_next_child(struct lsblk_device *dev,
187 struct lsblk_iter *itr,
188 struct lsblk_device **child);
189
190 struct lsblk_devtree *lsblk_new_devtree(void);
191 void lsblk_ref_devtree(struct lsblk_devtree *tr);
192 void lsblk_unref_devtree(struct lsblk_devtree *tr);
193 int lsblk_devtree_add_root(struct lsblk_devtree *tr, struct lsblk_device *dev);
194 int lsblk_devtree_next_root(struct lsblk_devtree *tr,
195 struct lsblk_iter *itr,
196 struct lsblk_device **dev);
197 int lsblk_devtree_add_device(struct lsblk_devtree *tr, struct lsblk_device *dev);
198 int lsblk_devtree_next_device(struct lsblk_devtree *tr,
199 struct lsblk_iter *itr,
200 struct lsblk_device **dev);
201 struct lsblk_device *lsblk_devtree_get_device(struct lsblk_devtree *tr, const char *name);
202
203
204 #endif /* UTIL_LINUX_LSBLK_H */