github.com/bugraaydogar/snapd@v0.0.0-20210315170335-8c70bb858939/cmd/libsnap-confine-private/mountinfo.h (about)

     1  /*
     2   * Copyright (C) 2016 Canonical Ltd
     3   *
     4   * This program is free software: you can redistribute it and/or modify
     5   * it under the terms of the GNU General Public License version 3 as
     6   * published by the Free Software Foundation.
     7   *
     8   * This program is distributed in the hope that it will be useful,
     9   * but WITHOUT ANY WARRANTY; without even the implied warranty of
    10   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    11   * GNU General Public License for more details.
    12   *
    13   * You should have received a copy of the GNU General Public License
    14   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
    15   */
    16  
    17  #ifndef SNAP_CONFINE_MOUNTINFO_H
    18  #define SNAP_CONFINE_MOUNTINFO_H
    19  
    20  /**
    21   * Structure describing a single entry in /proc/self/sc_mountinfo
    22   **/
    23  typedef struct sc_mountinfo_entry {
    24  	/**
    25  	 * The mount identifier of a given mount entry.
    26  	 **/
    27  	int mount_id;
    28  	/**
    29  	 * The parent mount identifier of a given mount entry.
    30  	 **/
    31  	int parent_id;
    32  	unsigned dev_major, dev_minor;
    33  	/**
    34  	 * The root directory of a given mount entry.
    35  	 **/
    36  	char *root;
    37  	/**
    38  	 * The mount point of a given mount entry.
    39  	 **/
    40  	char *mount_dir;
    41  	/**
    42  	 * The mount options of a given mount entry.
    43  	 **/
    44  	char *mount_opts;
    45  	/**
    46  	 * Optional tagged data associated of a given mount entry.
    47  	 *
    48  	 * The return value is a string (possibly empty but never NULL) in the format
    49  	 * tag[:value]. Known tags are:
    50  	 *
    51  	 * "shared:X":
    52  	 * 		mount is shared in peer group X
    53  	 * "master:X":
    54  	 * 		mount is slave to peer group X
    55  	 * "propagate_from:X"
    56  	 * 		mount is slave and receives propagation from peer group X (*)
    57  	 * "unbindable":
    58  	 * 		mount is unbindable
    59  	 *
    60  	 * (*) X is the closest dominant peer group under the process's root.
    61  	 * If X is the immediate master of the mount, or if there's no dominant peer
    62  	 * group under the same root, then only the "master:X" field is present and not
    63  	 * the "propagate_from:X" field.
    64  	 **/
    65  	char *optional_fields;
    66  	/**
    67  	 * The file system type of a given mount entry.
    68  	 **/
    69  	char *fs_type;
    70  	/**
    71  	 * The source of a given mount entry.
    72  	 **/
    73  	char *mount_source;
    74  	/**
    75  	 * The super block options of a given mount entry.
    76  	 **/
    77  	char *super_opts;
    78  
    79  	struct sc_mountinfo_entry *next;
    80  
    81  	// Buffer holding all of the text data above.
    82  	//
    83  	// The buffer must be the last element of the structure. It is allocated
    84  	// along with the structure itself and does not need to be freed
    85  	// separately.
    86  	char line_buf[0];
    87  } sc_mountinfo_entry;
    88  
    89  /**
    90   * Structure describing entire /proc/self/sc_mountinfo file
    91   **/
    92  typedef struct sc_mountinfo {
    93  	sc_mountinfo_entry *first;
    94  } sc_mountinfo;
    95  
    96  /**
    97   * Parse a file in according to sc_mountinfo syntax.
    98   *
    99   * The argument can be used to parse an arbitrary file.  NULL can be used to
   100   * implicitly parse /proc/self/sc_mountinfo, that is the mount information
   101   * associated with the current process.
   102   **/
   103  sc_mountinfo *sc_parse_mountinfo(const char *fname);
   104  
   105  /**
   106   * Free a sc_mountinfo structure.
   107   *
   108   * This function is designed to be used with __attribute__((cleanup)) so it
   109   * takes a pointer to the freed object (which is also a pointer).
   110   **/
   111  void sc_cleanup_mountinfo(sc_mountinfo ** ptr)
   112      __attribute__((nonnull(1)));
   113  
   114  /**
   115   * Get the first sc_mountinfo entry.
   116   *
   117   * The returned value may be NULL if the parsed file contained no entries. The
   118   * returned value is bound to the lifecycle of the whole sc_mountinfo structure
   119   * and should not be freed explicitly.
   120   **/
   121  sc_mountinfo_entry *sc_first_mountinfo_entry(sc_mountinfo * info)
   122      __attribute__((nonnull(1)));
   123  
   124  /**
   125   * Get the next sc_mountinfo entry.
   126   *
   127   * The returned value is a pointer to the next sc_mountinfo entry or NULL if this
   128   * was the last entry. The returned value is bound to the lifecycle of the
   129   * whole sc_mountinfo structure and should not be freed explicitly.
   130   **/
   131  sc_mountinfo_entry *sc_next_mountinfo_entry(sc_mountinfo_entry * entry)
   132      __attribute__((nonnull(1)));
   133  
   134  #endif