Plan 9 from Bell Labs’s /usr/web/sources/contrib/de0u/root/sys/src/cmd/divergefs/fiddata.c

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


#include <u.h>
#include <libc.h>
#include <fcall.h>
#include <thread.h>
#include <9p.h>
#include <String.h>
#include "common.h"
#include "debug.h"
#include "utils.h"
#include "filepath.h"
#include "holemanager.h"
#include "rule.h"
#include "filehandle.h"
#include "fiddata.h"

enum { DEBUG_FIDDATA = false };

struct FidData
{
  FileHandle *handle;
  String *path;
};

FidData *fiddata_new(String *path)
{
  FidData *result;
  assert_valid(path);

  result = (FidData *)emallocz_fs(sizeof(*result));
  result->path = s_clone(path);
  return result;
}

FidData *fiddata_charpath_new(char *path)
{
  FidData *result;
  String *pathstring;
  assert_valid(path);

  pathstring = s_copy(path);
  result = fiddata_new(pathstring);
  s_free(pathstring);
  return result;
}

void fiddata_free(FidData *self)
{
  if(self == nil)
  {
    return;
  }

  s_free(self->path);
  fiddata_clear_handle(self);
  free(self);
}

FidData *fiddata_copy(FidData *self)
{
  return fiddata_new(self->path);
}

char *fiddata_path(FidData *self)
{
  assert_valid(self);
  return s_to_c(self->path);
}

String *fiddata_path_string(FidData *self)
{
  assert_valid(self);
  return self->path;
}

void fiddata_set_path_string(FidData *self, String *path)
{
  assert_valid(self);
  assert_valid(path);
  filepath_copy(&(self->path), path);
}

void fiddata_read(FidData *self, Req *request, HoleManager *holemanager)
{
  assert_valid(self);
  assert_valid(request);
  filehandle_read(self->handle, request, holemanager);
}

void fiddata_write(FidData *self, Req *request)
{
  assert_valid(self);
  assert_valid(request);
  filehandle_write(self->handle, request);
}

void fiddata_clear_handle(FidData *self)
{
  assert_valid(self);
  fiddata_set_handle(self, nil);
}

void fiddata_set_handle(FidData *self, FileHandle *handle)
{
  assert_valid(self);
  filehandle_free(self->handle);
  self->handle = handle;
}

int fiddata_isopen(FidData *self)
{
  assert_valid(self);
  return self->handle != nil;
}

void fiddata_dump(FidData *self)
{
  assert_valid(self);
  NOISE(DEBUG_FIDDATA, "fiddata path: %s", s_to_c(self->path));
}




Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to [email protected].