/*
 * SPDX-FileCopyrightText: 2026 Didier Kryn <kryn@in2p3.fr>
 *
 * SPDX-License-Identifier: GPL-3.0-or-later
 */
#ifndef SLASH_SYS_H
#define SLASH_SYS_H
/*-------------------------------------------------------------------------*/
/* In the following comments, we call devicepath  the absolute path to the */
/* directory under /sys/devices which contains the properties of a device. */
/*-------------------------------------------------------------------------*/
typedef struct device_properties
{
  char dt[32];         /* device type */
  char dn[32];         /* device name */
  unsigned int major, minor;    /* device id */
} dev_prop;

/*  Build a pathname by concatenating dirname and fname, then canonicalize */
/* this pathname and return it. Typical use with fname= ".."               */
char *canonpath(const char *dname, const char *fname, char *buf);

/*  Given a device name (eg sda) return its devicepath                     */
char *devpath(const char *devname, char *namebuf);

/*  From a devicepath, navigate  up the directory tree  until a  devicepath */
/* matching  the given device type,  or any device,  if type is NULL. Store */
/* device properties at dp, and return the absolute path of the directory.  */
/*  The first directory checked  is the one given by  device_path_name,  so */
/* that the navigation can stop immediately  if the type matches.           */
char *get_device_prop(const char *device_path_name,    /* initial path name */
                      const char *type,   /* optional requested device type */
                      dev_prop *dp);

/*  Starting from a devicepath,  search from a disk and invoke the callback */
/* with the name of the device and its size.  If the disk is virtual  (RAID */
/* or Logical Volume, do the same with all the slave disks.                 */
void lookup_disk(char *device_path, void (*callback)(const char *, size_t));

/* List all disks involved in mounted partitions or disks,
   not counting the partitions or disks mounted under /media */
int lsmtab(FILE *mnt, void(*add_to_list)(const char *name, size_t len),
           const char *devname);

/* check that the filesystem is not mounted and that it does not involve a
   disk in use by the system. The argument is a device name (eg sdb2) */
int osuse(const char *);
#endif
