]>
git.ipfire.org Git - thirdparty/util-linux.git/blob - misc-utils/lsblk.h
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>
6 #ifndef UTIL_LINUX_LSBLK_H
7 #define UTIL_LINUX_LSBLK_H
12 #include <sys/statvfs.h>
14 #include <libsmartcols.h>
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
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)
30 #define UL_DEBUG_CURRENT_MASK UL_DEBUG_MASK(lsblk)
34 struct libscols_table
*table
; /* output table */
35 struct libscols_column
*sort_col
;/* sort output by this column */
39 int flags
; /* LSBLK_* */
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 */
51 extern struct lsblk
*lsblk
; /* global handler */
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 */
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.
74 struct list_head ls_deps
; /* item in parent->deps */
75 struct lsblk_device
*child
;
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 */
85 struct lsblk_devtree
*tree
;
87 struct lsblk_devprop
*properties
;
88 struct libscols_line
*scols_line
;
90 struct lsblk_device
*parent
; /* obsolete */
93 char *name
; /* kernel name in /sys/block */
94 char *dm_name
; /* DM name (dm/block) */
96 char *filename
; /* path to device node */
98 struct path_cxt
*sysfs
;
100 int partition
; /* is partition? TRUE/FALSE */
102 char *mountpoint
; /* device mountpoint */
103 struct statvfs fsstat
; /* statvfs() result */
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 */
112 uint64_t size
; /* device size */
114 unsigned int is_mounted
: 1,
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:
126 * The flag 'is_inverted' turns the tree over (root is device without holders):
129 struct lsblk_devtree
{
132 struct list_head roots
; /* tree root devices */
133 struct list_head devices
; /* all devices */
135 unsigned int is_inverse
: 1; /* inverse tree */
143 struct list_head
*p
; /* current position */
144 struct list_head
*head
; /* start position */
145 int direction
; /* LSBLK_ITER_{FOR,BACK}WARD */
148 #define LSBLK_ITER_FORWARD 0
149 #define LSBLK_ITER_BACKWARD 1
151 #define IS_ITER_FORWARD(_i) ((_i)->direction == LSBLK_ITER_FORWARD)
152 #define IS_ITER_BACKWARD(_i) ((_i)->direction == LSBLK_ITER_BACKWARD)
154 #define LSBLK_ITER_INIT(itr, list) \
156 (itr)->p = IS_ITER_FORWARD(itr) ? \
157 (list)->next : (list)->prev; \
158 (itr)->head = (list); \
161 #define LSBLK_ITER_ITERATE(itr, res, restype, member) \
163 res = list_entry((itr)->p, restype, member); \
164 (itr)->p = IS_ITER_FORWARD(itr) ? \
165 (itr)->p->next : (itr)->p->prev; \
170 extern void lsblk_mnt_init(void);
171 extern void lsblk_mnt_deinit(void);
173 extern char *lsblk_device_get_mountpoint(struct lsblk_device
*dev
);
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);
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
);
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
);
204 #endif /* UTIL_LINUX_LSBLK_H */