<commit_before>/*
 * This file is part of clr-boot-manager.
 *
 * Copyright © 2016-2017 Intel Corporation
 *
 * clr-boot-manager is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 2.1
 * of the License, or (at your option) any later version.
 */

#define _GNU_SOURCE

#include <ctype.h>
#include <dirent.h>
#include <errno.h>
#include <fcntl.h>
#include <ftw.h>
#include <glob.h>
#include <libgen.h>
#include <limits.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/mman.h>
#include <sys/sendfile.h>
#include <sys/stat.h>
#include <unistd.h>

#include "blkid_stub.h"
#include "files.h"
#include "log.h"
#include "nica/files.h"
#include "system_stub.h"
#include "util.h"

/**
 * Legacy boot bit, i.e. partition flag on a GPT disk
 */
#define CBM_MBR_BOOT_FLAG (1ULL << 2)

/**
 * By default we call sync() - for testing however we disable this due to timeout
 * issues.
 */
static bool cbm_should_sync = true;

void cbm_sync(void)
{
        if (cbm_should_sync) {
                sync();
        }
}

bool cbm_files_match(const char *p1, const char *p2)
{
        autofree(CbmMappedFile) *m1 = CBM_MAPPED_FILE_INIT;
        autofree(CbmMappedFile) *m2 = CBM_MAPPED_FILE_INIT;

        if (!cbm_mapped_file_open(p1, m1)) {
                return false;
        }

        if (!cbm_mapped_file_open(p2, m2)) {
                return false;
        }

        /* If the lengths are different they're clearly not the same file */
        if (m1->length != m2->length) {
                return false;
        }

        /* Compare both buffers */
        if (memcmp(m1->buffer, m2->buffer, m1->length) == 0) {
                return true;
        }
        return false;
}

char *get_boot_device()
{
        glob_t glo = { 0 };
        char read_buf[4096];
        glo.gl_offs = 1;
        int fd = -1;
        ;
        ssize_t size = 0;
        autofree(char) *uuid = NULL;
        autofree(char) *p = NULL;
        autofree(char) *glob_path = NULL;
        autofree(char) *dev_path = NULL;

        glob_path = string_printf("%s/firmware/efi/efivars/LoaderDevicePartUUID*",
                                  cbm_system_get_sysfs_path());

        glob(glob_path, GLOB_DOOFFS, NULL, &glo);

        if (glo.gl_pathc < 1) {
                globfree(&glo);<commit_msg>lib: Remove stray semicolon<commit_after>/*
 * This file is part of clr-boot-manager.
 *
 * Copyright © 2016-2017 Intel Corporation
 *
 * clr-boot-manager is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 2.1
 * of the License, or (at your option) any later version.
 */

#define _GNU_SOURCE

#include <ctype.h>
#include <dirent.h>
#include <errno.h>
#include <fcntl.h>
#include <ftw.h>
#include <glob.h>
#include <libgen.h>
#include <limits.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/mman.h>
#include <sys/sendfile.h>
#include <sys/stat.h>
#include <unistd.h>

#include "blkid_stub.h"
#include "files.h"
#include "log.h"
#include "nica/files.h"
#include "system_stub.h"
#include "util.h"

/**
 * Legacy boot bit, i.e. partition flag on a GPT disk
 */
#define CBM_MBR_BOOT_FLAG (1ULL << 2)

/**
 * By default we call sync() - for testing however we disable this due to timeout
 * issues.
 */
static bool cbm_should_sync = true;

void cbm_sync(void)
{
        if (cbm_should_sync) {
                sync();
        }
}

bool cbm_files_match(const char *p1, const char *p2)
{
        autofree(CbmMappedFile) *m1 = CBM_MAPPED_FILE_INIT;
        autofree(CbmMappedFile) *m2 = CBM_MAPPED_FILE_INIT;

        if (!cbm_mapped_file_open(p1, m1)) {
                return false;
        }

        if (!cbm_mapped_file_open(p2, m2)) {
                return false;
        }

        /* If the lengths are different they're clearly not the same file */
        if (m1->length != m2->length) {
                return false;
        }

        /* Compare both buffers */
        if (memcmp(m1->buffer, m2->buffer, m1->length) == 0) {
                return true;
        }
        return false;
}

char *get_boot_device()
{
        glob_t glo = { 0 };
        char read_buf[4096];
        glo.gl_offs = 1;
        int fd = -1;

        ssize_t size = 0;
        autofree(char) *uuid = NULL;
        autofree(char) *p = NULL;
        autofree(char) *glob_path = NULL;
        autofree(char) *dev_path = NULL;

        glob_path = string_printf("%s/firmware/efi/efivars/LoaderDevicePartUUID*",
                                  cbm_system_get_sysfs_path());

        glob(glob_path, GLOB_DOOFFS, NULL, &glo);

        if (glo.gl_pathc < 1) {
                globfree(&glo);
{'fraction_non_alphanumeric': 0.12482095355023531, 'fraction_numerical': 0.014323715981174545, 'mean_word_length': 2.380359612724758, 'pattern_counts': {'":': 0, '<': 41, '<?xml version=': 0, '>': 45, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '865716', 'n_tokens_mistral': 1788, 'n_tokens_neox': 1719, 'n_words': 454}