<commit_before>#include "fs.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>

#define DEFAULT_NR_BUFS 1024

struct glue_context {
  int fd;
  int block_size;
  int rdwt_err;
  struct buf buf_head;
};

static struct glue_context *ctx = NULL;

#define BUF_LIST_FOREACH(bp) for ((bp) = ctx->buf_head.lmfs_next; (bp) != &ctx->buf_head; (bp) = (bp)->lmfs_next)

static void buf_list_init(void) {
  ctx->buf_head.lmfs_next = &ctx->buf_head;
  ctx->buf_head.lmfs_prev = &ctx->buf_head;
}

static int buf_list_empty(void) {
  return ctx->buf_head.lmfs_next == &ctx->buf_head;
}

static void buf_list_add(struct buf *bp) {
  bp->lmfs_prev = &ctx->buf_head;
  bp->lmfs_next = ctx->buf_head.lmfs_next;
  ctx->buf_head.lmfs_next = bp;
  bp->lmfs_next->lmfs_prev = bp;
}

static void buf_list_remove(struct buf *bp) {
  bp->lmfs_prev->lmfs_next = bp->lmfs_next;
  bp->lmfs_next->lmfs_prev = bp->lmfs_prev;
  bp->lmfs_next = NULL;
  bp->lmfs_prev = NULL;
}

void panic(const char *format, ...) {
  va_list ap;

  va_start(ap, format);
  vfprintf(stderr, format, ap);
  va_end(ap);
  fprintf(stderr, "\n");

  exit(EXIT_FAILURE);
}

void util_stacktrace(void) {
}

time_t clock_time(struct timespec *tv) {
  assert(tv == NULL);
  return time(NULL);
}

void glue_setup(const char *path) {
  ctx = (struct glue_context*)malloc(sizeof(struct glue_context));
  if (ctx == NULL) {
    panic("couldn't alloc memory");
  }

  if ((ctx->fd = open(path, O_RDWR)) < 0) {
    panic("%s: %s", strerror(errno), path);
  }

  ctx->block_size = PAGE_SIZE;
  ctx->rdwt_err = OK;

  buf_list_init();
}

int bdev_open(dev_t dev, int access) {<commit_msg>fixed clock_time<commit_after>#include "fs.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>

#define DEFAULT_NR_BUFS 1024

struct glue_context {
  int fd;
  int block_size;
  int rdwt_err;
  struct buf buf_head;
};

static struct glue_context *ctx = NULL;

#define BUF_LIST_FOREACH(bp) for ((bp) = ctx->buf_head.lmfs_next; (bp) != &ctx->buf_head; (bp) = (bp)->lmfs_next)

static void buf_list_init(void) {
  ctx->buf_head.lmfs_next = &ctx->buf_head;
  ctx->buf_head.lmfs_prev = &ctx->buf_head;
}

static int buf_list_empty(void) {
  return ctx->buf_head.lmfs_next == &ctx->buf_head;
}

static void buf_list_add(struct buf *bp) {
  bp->lmfs_prev = &ctx->buf_head;
  bp->lmfs_next = ctx->buf_head.lmfs_next;
  ctx->buf_head.lmfs_next = bp;
  bp->lmfs_next->lmfs_prev = bp;
}

static void buf_list_remove(struct buf *bp) {
  bp->lmfs_prev->lmfs_next = bp->lmfs_next;
  bp->lmfs_next->lmfs_prev = bp->lmfs_prev;
  bp->lmfs_next = NULL;
  bp->lmfs_prev = NULL;
}

void panic(const char *format, ...) {
  va_list ap;

  va_start(ap, format);
  vfprintf(stderr, format, ap);
  va_end(ap);
  fprintf(stderr, "\n");

  exit(EXIT_FAILURE);
}

void util_stacktrace(void) {
}

time_t clock_time(struct timespec *tv) {
  time_t t = time(NULL);
  if (tv) {
    tv->tv_sec  = t;
    tv->tv_nsec = 0;
  }
  return t;
}

void glue_setup(const char *path) {
  ctx = (struct glue_context*)malloc(sizeof(struct glue_context));
  if (ctx == NULL) {
    panic("couldn't alloc memory");
  }

  if ((ctx->fd = open(path, O_RDWR)) < 0) {
    panic("%s: %s", strerror(errno), path);
  }

  ctx->block_size = PAGE_SIZE;
  ctx->rdwt_err = OK;

  buf_list_init();
}

int bdev_open(dev_t dev, int access) {
{'fraction_non_alphanumeric': 0.16355274504167863, 'fraction_numerical': 0.0031618281115263006, 'mean_word_length': 4.225225225225225, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 73, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1110013', 'n_tokens_mistral': 1508, 'n_tokens_neox': 1450, 'n_words': 290}