예제 #1
0
def xfs_format_xfsbuf(buf: gdb.Value) -> str:
    """
    Returns a human-readable format of ``struct xfs_buf``

    Args:
        buf: The ``struct xfs_buf`` to decode.  The value must be of type
            ``struct xfs_buf``.

    Returns:
        :obj:`str`: The human-readable representation of the
            ``struct xfs_buf``.

    Raises:
        :obj:`gdb.NotAvailableError`: The target value was not available.
    """
    state = ""
    bflags = decode_flags(buf['b_flags'], XFS_BUF_FLAGS)

    if buf['b_pin_count']['counter']:
        state += "P"
    if buf['b_sema']['count'] >= 0:
        state += "L"

    return f"{int(buf):x} xfsbuf: logical offset {buf['b_bn']:d}, " \
           f"size {buf['b_buffer_len']:d}, block number {buf['b_bn']:d}, " \
           f"flags {bflags}, state {state}"
예제 #2
0
def mount_flags(mnt: gdb.Value, show_hidden: bool = False) -> str:
    """
    Returns the human-readable flags of the ``struct mount``
    :ref:`structure <mount_structure>`.

    Args:
        mnt: The :ref:`mount structure <mount_structure>` for which to
            return flags

        show_hidden: Whether to return hidden flags

    Returns:
        :obj:`str`: The mount flags in human-readable form
    """
    if struct_has_member(mnt, 'mnt'):
        mnt = mnt['mnt']
    if show_hidden:
        return decode_flags(mnt['mnt_flags'], MNT_FLAGS_HIDDEN, ",")
    return decode_flags(mnt['mnt_flags'], MNT_FLAGS, ",")
예제 #3
0
def xfs_mount_flags(mp: gdb.Value) -> str:
    """
    Return the XFS-internal mount flags in string form

    Args:
        mp: The ``struct xfs_mount`` for the file system.  The value must be of
            type ``struct xfs_mount``.

    Returns:
        :obj:`str`: The mount flags in string form

    Raises:
        :obj:`gdb.NotAvailableError`: The target value was not available.
    """
    return decode_flags(mp['m_flags'], XFS_MOUNT_FLAGS)
예제 #4
0
def super_flags(sb: gdb.Value) -> str:
    """
    Returns the flags associated with the given superblock.

    Args:
        sb: The ``struct super_block`` for which to return the flags.
            The value must be of type ``struct super_block``.

    Returns:
        :obj:`str`:The flags field in human-readable form.

    Raises:
        :obj:`gdb.NotAvailableError`: The target value was not available.
    """
    return decode_flags(sb['s_flags'], SB_FLAGS)
예제 #5
0
    def dump_ail(self, args: argparse.Namespace) -> None:
        try:
            sb = get_super_block(args.addr)
        except gdb.NotAvailableError as e:
            raise CommandError(str(e)) from e

        mp = xfs_mount(sb)
        ail = mp['m_ail']
        itemno = 0
        print("AIL @ {:x}".format(int(ail)))
        print("target={} last_pushed_lsn={} log_flush=".format(
            int(ail['xa_target']), int(ail['xa_last_pushed_lsn'])),
              end='')

        # This was added in Linux v3.2 (670ce93fef93b)
        if struct_has_member(ail, 'xa_log_flush'):
            print("{}".format(int(ail['xa_log_flush'])))
        else:
            print("[N/A]")

        for bitem in xfs_for_each_ail_log_item(mp):
            li_type = int(bitem['li_type'])
            lsn = int(bitem['li_lsn'])
            item = xfs_log_item_typed(bitem)
            print("{}: item={:x} lsn={} {} ".format(itemno, int(bitem.address),
                                                    lsn,
                                                    XFS_LI_TYPES[li_type][7:]),
                  end='')
            if li_type == XFS_LI_BUF:
                buf = item['bli_buf']
                flags = decode_flags(item['bli_flags'], XFS_BLI_FLAGS)
                print(" buf@{:x} bli_flags={}".format(int(buf), flags))

                print("     {}".format(xfs_format_xfsbuf(buf)))
            elif li_type == XFS_LI_INODE:
                ili_flags = int(item['ili_lock_flags'])
                xfs_inode = item['ili_inode']
                print("inode@{:x} i_ino={} ili_lock_flags={:x} ".format(
                    int(xfs_inode['i_vnode'].address), int(xfs_inode['i_ino']),
                    ili_flags))
            elif li_type == XFS_LI_EFI:
                efi = item['efi_format']
                print("efi@{:x} size={}, nextents={}, id={:x}".format(
                    int(item.address), int(efi['efi_size']),
                    int(efi['efi_nextents']), int(efi['efi_id'])))
            elif li_type == XFS_LI_EFI:
                efd = item['efd_format']
                print("efd@{:x} size={}, nextents={}, id={:x}".format(
                    int(item.address), int(efd['efd_size']),
                    int(efd['efd_nextents']), int(efd['efd_id'])))
            elif li_type == XFS_LI_DQUOT:
                dquot = item['qli_dquot']
                flags = decode_flags(dquot['dq_flags'], XFS_DQ_FLAGS)
                print("dquot@{:x} flags={}".format(int(dquot), flags))
            elif li_type == XFS_LI_QUOTAOFF:
                qoff = item['qql_format']
                print("qoff@{:x} type={} size={} flags={}".format(
                    int(qoff), int(qoff['qf_type']), int(qoff['qf_size']),
                    int(qoff['qf_flags'])))
            else:
                print("item@{:x}".format(int(item.address)))
            itemno += 1