libnjb 2.2.7

Functions | Variables
datafile.c File Reference
`#include <string.h>`
`#include "libnjb.h"`
`#include "njb_error.h"`
`#include "defs.h"`
`#include "base.h"`
`#include "unicode.h"`
`#include "protocol3.h"`
`#include "byteorder.h"`
`#include "datafile.h"`

## Functions
njb_datafile_t * | datafile_new (void)
void | NJB_Datafile_Destroy (njb_datafile_t *df)
u_int64_t | datafile_size (njb_datafile_t *df)
void | datafile_set_size (njb_datafile_t *df, u_int64_t size)
void | datafile_set_time (njb_datafile_t *df, time_t ts)
int | datafile_set_name (njb_datafile_t *df, const char *filename)
int | datafile_set_folder (njb_datafile_t *df, const char *folder)
njb_datafile_t * | datafile_unpack (unsigned char *data, size_t nbytes)
unsigned char * | datafile_pack (njb_datafile_t *df, u_int32_t *size)
unsigned char * | datafile_pack3 (njb_t *njb, njb_datafile_t *df, u_int32_t *size)
unsigned char * | new_folder_pack3 (njb_t *njb, const char *name, u_int32_t *size)

## Variables
int | __sub_depth
int | njb_unicode_flag

## Detailed Description

This file contains functions that deal with putting regular data files onto the devices. It is not quite a "file system" but metadata elements in a database that have all the attributes of regular files.

## Function Documentation

## ◆ datafile_new()

njb_datafile_t* datafile_new | ( | void |  | ) |

Creates a new datafile struct.

Returns
  a nullified and freshly allocated njb_datafile_t struct

Referenced by datafile_unpack().

## ◆ datafile_pack()

unsigned char* datafile_pack | ( | njb_datafile_t * | df,
|  | u_int32_t * | size
| ) |  |

A function that packs a datafile tag into the format used by the NJB1.

Parameters

  df | the datafile tag to pack.
  size | a pointer to a variable that shall hold the size of the packed object after this function has been called.

Returns
  a pointer to the packed struct, which must be freed by the caller after use.

## ◆ datafile_pack3()

unsigned char* datafile_pack3 | ( | njb_t * | njb,
|  | njb_datafile_t * | df,
|  | u_int32_t * | size
| ) |  |

This function packs (serialize, marshall) a high-level representation of a datafile metadata structure into a simple byte-array as used by the series 3 devices.

Parameters

  njb | the NJB object to use
  df | the datafile in libnjb structure format
  size | a pointer to an integer that will hold the resulting size of the packed structure

Returns
  the packed structure as a newly allocated byte array. The caller shall free this memory after use. Returns NULL on failure.

References EO_NOMEM, njb_datafile_struct::filename, njb_datafile_struct::folder, and strtoucs2().

## ◆ datafile_set_folder()

int datafile_set_folder | ( | njb_datafile_t * | df,
|  | const char * | folder
| ) |  |

Helper function that sets the foldername of a datafile.

Parameters

  df | the datafile to be altered.
  folder | the new folder name. Folder names always begin and end with a backslash () with a backslash separator between levels, like this: "\foo\bar\fnord\".

Returns
  0 on success, -1 on failure.

References njb_datafile_struct::folder.

## ◆ datafile_set_name()

int datafile_set_name | ( | njb_datafile_t * | df,
|  | const char * | filename
| ) |  |

Helper function that sets the name of a datafile.

Parameters

  df | the datafile to be altered.
  filename | the new name.

Returns
  0 on success, -1 on failure.

References njb_datafile_struct::filename.

## ◆ datafile_set_size()

void datafile_set_size | ( | njb_datafile_t * | df,
|  | u_int64_t | size
| ) |  |

Helper function that sets the size of the datafile.

Parameters

  df | the datafile to be altered.
  size | the size of the file as a 64bit unsigned integer.

References njb_datafile_struct::filesize.

## ◆ datafile_set_time()

void datafile_set_time | ( | njb_datafile_t * | df,
|  | time_t | ts
| ) |  |

Helper function that sets the timestamp for a datafile.

Parameters

  df | the datafile to be altered.
  ts | the new timestamp for this datafile.

References njb_datafile_struct::timestamp.

## ◆ datafile_size()

u_int64_t datafile_size | ( | njb_datafile_t * | df | ) |

Helper function that returns the size of the datafile as a 64bit unsigned integer

Parameters

  df | the datafile whose size we are interested in.

Returns
  the size.

References njb_datafile_struct::filesize.

## ◆ datafile_unpack()

njb_datafile_t* datafile_unpack | ( | unsigned char * | data,
|  | size_t | nbytes
| ) |  |

Unpacks a datafile struct from NJB1.

Parameters

  data | the raw binary data to unpack
  nbytes | the size of the raw binary data in bytes

Returns
  a newly allocated and filled in njb_datafile_t struct.

References datafile_new(), njb_datafile_struct::filename, njb_datafile_struct::filesize, njb1_bytes_to_16bit(), njb1_bytes_to_64bit(), and NJB_Datafile_Destroy().

## ◆ new_folder_pack3()

unsigned char* new_folder_pack3 | ( | njb_t * | njb,
|  | const char * | name,
|  | u_int32_t * | size
| ) |  |

This creates a folder metadata entry for a new folder on the series 3 devices. (Not applicable for NJB1.)

Parameters

  njb | the NJB object to use
  name | the name of the new folder, must have a reasonable format!
  size | a pointer to an integer that will hold the resulting size of the packed folder structure

Returns
  the packed folder structure as a newly allocated byte array. the caller shall free this memory after use. Returns NULL on failure.

References EO_NOMEM, from_16bit_to_njb3_bytes(), and strtoucs2().

## Variable Documentation

## ◆ __sub_depth

int __sub_depth

The current subroutine depth for all of libnjb (global)