]> git.ipfire.org Git - thirdparty/util-linux.git/blame - misc-utils/lsblk.h
docs: fix typos [codespell]
[thirdparty/util-linux.git] / misc-utils / lsblk.h
CommitLineData
14560b7f
KZ
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>
6529212d 11#include <sys/stat.h>
14560b7f
KZ
12#include <sys/statvfs.h>
13
14#include <libsmartcols.h>
15
16#include "c.h"
5bb395f4 17#include "list.h"
14560b7f
KZ
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)
3bf2a36c 23#define LSBLK_DEBUG_TREE (1 << 4)
0986f29a 24#define LSBLK_DEBUG_DEP (1 << 5)
14560b7f
KZ
25#define LSBLK_DEBUG_ALL 0xFFFF
26
27UL_DEBUG_DECLARE_MASK(lsblk);
28#define DBG(m, x) __UL_DBG(lsblk, LSBLK_DEBUG_, m, x)
29#define ON_DBG(m, x) __UL_DBG_CALL(lsblk, LSBLK_DEBUG_, m, x)
30
31#define UL_DEBUG_CURRENT_MASK UL_DEBUG_MASK(lsblk)
32#include "debugobj.h"
33
34struct lsblk {
35 struct libscols_table *table; /* output table */
dc4662f0 36
14560b7f
KZ
37 struct libscols_column *sort_col;/* sort output by this column */
38 int sort_id;
39
dc4662f0
KZ
40 int dedup_id;
41
14560b7f
KZ
42 const char *sysroot;
43 int flags; /* LSBLK_* */
44
45 unsigned int all_devices:1; /* print all devices, including empty */
46 unsigned int bytes:1; /* print SIZE in bytes */
47 unsigned int inverse:1; /* print inverse dependencies */
0bd05f5e 48 unsigned int merge:1; /* merge sub-trees */
14560b7f
KZ
49 unsigned int nodeps:1; /* don't print slaves/holders */
50 unsigned int scsi:1; /* print only device with HCTL (SCSI) */
51 unsigned int paths:1; /* print devnames with "/dev" prefix */
52 unsigned int sort_hidden:1; /* sort column not between output columns */
dc4662f0 53 unsigned int dedup_hidden :1; /* deduplication column not between output columns */
14560b7f
KZ
54 unsigned int force_tree_order:1;/* sort lines by parent->tree relation */
55};
56
57extern struct lsblk *lsblk; /* global handler */
58
baad6dcc
KZ
59struct lsblk_devprop {
60 char *fstype; /* detected fs, NULL or "?" if cannot detect */
61 char *uuid; /* filesystem UUID (or stack uuid) */
62 char *ptuuid; /* partition table UUID */
63 char *pttype; /* partition table type */
64 char *label; /* filesystem label */
65 char *parttype; /* partition type UUID */
66 char *partuuid; /* partition UUID */
67 char *partlabel; /* partition label */
68 char *partflags; /* partition flags */
69 char *wwn; /* storage WWN */
70 char *serial; /* disk serial number */
71 char *model; /* disk model */
72};
73
5bb395f4
KZ
74/* Device dependence
75 *
76 * Note that the same device may be slave/holder for more another devices. It
77 * means we need to allocate list member rather than use @child directly.
78 */
79struct lsblk_devdep {
0986f29a
KZ
80 struct list_head ls_childs; /* item in parent->childs */
81 struct list_head ls_parents; /* item in child->parents */
82
5bb395f4 83 struct lsblk_device *child;
0986f29a 84 struct lsblk_device *parent;
5bb395f4
KZ
85};
86
fed34a1e 87struct lsblk_device {
5bb395f4
KZ
88 int refcount;
89
0986f29a
KZ
90 struct list_head childs; /* list with lsblk_devdep */
91 struct list_head parents;
5bb395f4
KZ
92 struct list_head ls_roots; /* item in devtree->roots list */
93 struct list_head ls_devices; /* item in devtree->devices list */
14560b7f 94
10501add 95 struct lsblk_device *wholedisk; /* for partitions */
5bb395f4 96
0bd05f5e
KZ
97 struct libscols_line *scols_line;
98
5bb395f4 99 struct lsblk_devprop *properties;
14560b7f
KZ
100 struct stat st;
101
102 char *name; /* kernel name in /sys/block */
103 char *dm_name; /* DM name (dm/block) */
104
105 char *filename; /* path to device node */
dc4662f0 106 char *dedupkey; /* de-duplication key */
14560b7f
KZ
107
108 struct path_cxt *sysfs;
109
14560b7f
KZ
110 char *mountpoint; /* device mountpoint */
111 struct statvfs fsstat; /* statvfs() result */
112
113 int npartitions; /* # of partitions this device has */
114 int nholders; /* # of devices mapped directly to this device
115 * /sys/block/.../holders */
116 int nslaves; /* # of devices this device maps to */
117 int maj, min; /* devno */
8a2f175c
KZ
118
119 uint64_t discard_granularity; /* sunknown:-1, yes:1, not:0 */
14560b7f
KZ
120
121 uint64_t size; /* device size */
81a8936c 122 int removable; /* unknown:-1, yes:1, not:0 */
14560b7f 123
82dae67d 124 unsigned int is_mounted : 1,
baad6dcc 125 is_swap : 1,
0bd05f5e 126 is_printed : 1,
baad6dcc
KZ
127 udev_requested : 1,
128 blkid_requested : 1;
14560b7f
KZ
129};
130
10501add 131#define device_is_partition(_x) ((_x)->wholedisk != NULL)
5bb395f4
KZ
132
133/*
11026083 134 * Note that lsblk tree uses bottom devices (devices without slaves) as root
5bb395f4
KZ
135 * of the tree, and partitions are interpreted as a dependence too; it means:
136 * sda -> sda1 -> md0
137 *
138 * The flag 'is_inverted' turns the tree over (root is device without holders):
139 * md0 -> sda1 -> sda
140 */
141struct lsblk_devtree {
142 int refcount;
143
144 struct list_head roots; /* tree root devices */
145 struct list_head devices; /* all devices */
146
147 unsigned int is_inverse : 1; /* inverse tree */
148};
149
150
151/*
152 * Generic iterator
153 */
154struct lsblk_iter {
155 struct list_head *p; /* current position */
156 struct list_head *head; /* start position */
157 int direction; /* LSBLK_ITER_{FOR,BACK}WARD */
158};
159
160#define LSBLK_ITER_FORWARD 0
161#define LSBLK_ITER_BACKWARD 1
162
163#define IS_ITER_FORWARD(_i) ((_i)->direction == LSBLK_ITER_FORWARD)
164#define IS_ITER_BACKWARD(_i) ((_i)->direction == LSBLK_ITER_BACKWARD)
165
166#define LSBLK_ITER_INIT(itr, list) \
167 do { \
168 (itr)->p = IS_ITER_FORWARD(itr) ? \
169 (list)->next : (list)->prev; \
170 (itr)->head = (list); \
171 } while(0)
172
173#define LSBLK_ITER_ITERATE(itr, res, restype, member) \
174 do { \
175 res = list_entry((itr)->p, restype, member); \
176 (itr)->p = IS_ITER_FORWARD(itr) ? \
177 (itr)->p->next : (itr)->p->prev; \
178 } while(0)
179
180
04be258d 181/* lsblk-mnt.c */
e0c016f1
KZ
182extern void lsblk_mnt_init(void);
183extern void lsblk_mnt_deinit(void);
184
fed34a1e 185extern char *lsblk_device_get_mountpoint(struct lsblk_device *dev);
cfb715ed 186
ccafadb7
KZ
187/* lsblk-properties.c */
188extern void lsblk_device_free_properties(struct lsblk_devprop *p);
fed34a1e 189extern struct lsblk_devprop *lsblk_device_get_properties(struct lsblk_device *dev);
ccafadb7
KZ
190extern void lsblk_properties_deinit(void);
191
5bb395f4
KZ
192/* lsblk-devtree.c */
193void lsblk_reset_iter(struct lsblk_iter *itr, int direction);
10501add 194struct lsblk_device *lsblk_new_device(void);
5bb395f4
KZ
195void lsblk_ref_device(struct lsblk_device *dev);
196void lsblk_unref_device(struct lsblk_device *dev);
e2d7870b 197int lsblk_device_new_dependence(struct lsblk_device *parent, struct lsblk_device *child);
0986f29a 198int lsblk_device_has_child(struct lsblk_device *dev, struct lsblk_device *child);
5bb395f4
KZ
199int lsblk_device_next_child(struct lsblk_device *dev,
200 struct lsblk_iter *itr,
201 struct lsblk_device **child);
202
0bd05f5e
KZ
203int lsblk_device_is_last_parent(struct lsblk_device *dev, struct lsblk_device *parent);
204int lsblk_device_next_parent(
205 struct lsblk_device *dev,
206 struct lsblk_iter *itr,
207 struct lsblk_device **parent);
208
5bb395f4
KZ
209struct lsblk_devtree *lsblk_new_devtree(void);
210void lsblk_ref_devtree(struct lsblk_devtree *tr);
211void lsblk_unref_devtree(struct lsblk_devtree *tr);
212int lsblk_devtree_add_root(struct lsblk_devtree *tr, struct lsblk_device *dev);
213int lsblk_devtree_next_root(struct lsblk_devtree *tr,
214 struct lsblk_iter *itr,
215 struct lsblk_device **dev);
216int lsblk_devtree_add_device(struct lsblk_devtree *tr, struct lsblk_device *dev);
217int lsblk_devtree_next_device(struct lsblk_devtree *tr,
218 struct lsblk_iter *itr,
219 struct lsblk_device **dev);
21d4a48c 220int lsblk_devtree_has_device(struct lsblk_devtree *tr, struct lsblk_device *dev);
5bb395f4 221struct lsblk_device *lsblk_devtree_get_device(struct lsblk_devtree *tr, const char *name);
21d4a48c 222int lsblk_devtree_remove_device(struct lsblk_devtree *tr, struct lsblk_device *dev);
dc4662f0 223int lsblk_devtree_deduplicate_devices(struct lsblk_devtree *tr);
5bb395f4 224
14560b7f 225#endif /* UTIL_LINUX_LSBLK_H */