2021-03-28 06:22:50 +09:00
|
|
|
/*
|
|
|
|
* lsfd-bdev.c - handle associations opening block devices
|
|
|
|
*
|
|
|
|
* Copyright (C) 2021 Red Hat, Inc. All rights reserved.
|
|
|
|
* Written by Masatake YAMATO <yamato@redhat.com>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it would be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
|
|
|
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "xalloc.h"
|
|
|
|
#include "nls.h"
|
|
|
|
#include "libsmartcols.h"
|
|
|
|
|
|
|
|
#include "lsfd.h"
|
|
|
|
|
2021-04-17 05:49:58 +09:00
|
|
|
static bool bdev_file_fill_column(struct proc *proc __attribute__((__unused__)),
|
|
|
|
struct file *file __attribute__((__unused__)),
|
|
|
|
struct libscols_line *ln,
|
|
|
|
int column_id,
|
|
|
|
size_t column_index)
|
2021-03-28 06:22:50 +09:00
|
|
|
{
|
|
|
|
char *str = NULL;
|
|
|
|
switch(column_id) {
|
|
|
|
case COL_TYPE:
|
|
|
|
if (scols_line_set_data(ln, column_index, "BLK"))
|
|
|
|
err(EXIT_FAILURE, _("failed to add output data"));
|
|
|
|
return true;
|
|
|
|
case COL_DEVICE:
|
|
|
|
xasprintf(&str, "%u:%u",
|
|
|
|
major(file->stat.st_rdev),
|
|
|
|
minor(file->stat.st_rdev));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!str)
|
|
|
|
err(EXIT_FAILURE, _("failed to add output data"));
|
|
|
|
if (scols_line_refer_data(ln, column_index, str))
|
|
|
|
err(EXIT_FAILURE, _("failed to add output data"));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-04-17 05:49:58 +09:00
|
|
|
const struct file_class bdev_file_class = {
|
|
|
|
.super = &file_class,
|
|
|
|
.size = sizeof(struct file),
|
|
|
|
.fill_column = bdev_file_fill_column,
|
2021-03-28 06:22:50 +09:00
|
|
|
.free_content = NULL,
|
|
|
|
};
|
|
|
|
|
2021-04-17 05:49:58 +09:00
|
|
|
struct file *make_bdev_file(const struct file_class *class,
|
2021-03-28 06:22:50 +09:00
|
|
|
struct stat *sb, const char *name, int fd)
|
|
|
|
{
|
2021-04-17 05:49:58 +09:00
|
|
|
return make_file(class? class: &bdev_file_class,
|
|
|
|
sb, name, fd);
|
2021-03-28 06:22:50 +09:00
|
|
|
}
|