libisofs  1.5.4
About: libisofs is a library to create an ISO 9660 filesystem, supports extensions like RockRidge or Joliet, makes bootable ISO 9660, and records file attributes which are of interest for data backups.
  Fossies Dox: libisofs-1.5.4.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

node.h File Reference
#include "libisofs.h"
#include "stream.h"
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
Include dependency graph for node.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  iso_extended_info
 
struct  Iso_Node
 
struct  Iso_Dir
 
struct  Iso_File
 
struct  Iso_Symlink
 
struct  Iso_Special
 
struct  iso_dir_iter_iface
 
struct  Iso_Dir_Iter
 An iterator for directory children. More...
 
struct  zisofs_zf_info
 Parameter structure which is to be managed by zisofs_zf_xinfo_func. More...
 

Macros

#define LIBISOFS_NODE_NAME_MAX   255
 
#define LIBISOFS_NODE_PATH_MAX   1024
 

Typedefs

typedef struct iso_extended_info IsoExtendedInfo
 The extended information is a way to attach additional information to each IsoNode. More...
 

Functions

int iso_node_new_root (IsoDir **root)
 
int iso_node_new_dir (char *name, IsoDir **dir)
 Create a new IsoDir. More...
 
int iso_node_new_file (char *name, IsoStream *stream, IsoFile **file)
 Create a new file node. More...
 
int iso_node_new_symlink (char *name, char *dest, IsoSymlink **link)
 Creates a new IsoSymlink node. More...
 
int iso_node_new_special (char *name, mode_t mode, dev_t dev, IsoSpecial **special)
 Create a new special file node. More...
 
int iso_node_is_valid_name (const char *name)
 Check if a given name is valid for an iso node. More...
 
int iso_node_is_valid_link_dest (const char *dest)
 Check if a given path is valid for the destination of a link. More...
 
void iso_dir_find (IsoDir *dir, const char *name, IsoNode ***pos)
 Find the position where to insert a node. More...
 
int iso_dir_exists (IsoDir *dir, const char *name, IsoNode ***pos)
 Check if a node with the given name exists in a dir. More...
 
int iso_dir_insert (IsoDir *dir, IsoNode *node, IsoNode **pos, enum iso_replace_mode replace)
 Inserts a given node in a dir, at the specified position. More...
 
int iso_dir_iter_register (IsoDirIter *iter)
 Add a new iterator to the registry. More...
 
void iso_dir_iter_unregister (IsoDirIter *iter)
 Unregister a directory iterator. More...
 
void iso_notify_dir_iters (IsoNode *node, int flag)
 
int iso_node_set_perms_internal (IsoNode *node, mode_t mode, int flag)
 See API function iso_node_set_permissions() More...
 
int iso_aa_get_acl_text (unsigned char *aa_string, mode_t st_mode, char **access_text, char **default_text, int flag)
 Like iso_node_get_acl_text() with param node replaced by aa_string and st_mode from where to obtain the ACLs. More...
 
int iso_aa_get_attrs (unsigned char *aa_string, size_t *num_attrs, char ***names, size_t **value_lengths, char ***values, int flag)
 Backend of iso_node_get_attrs() with parameter node replaced by the AAIP string from where to get the attribute list. More...
 
int iso_aa_lookup_attr (unsigned char *aa_string, char *name, size_t *value_length, char **value, int flag)
 Search given name. More...
 
int zisofs_zf_xinfo_func (void *data, int flag)
 Function to identify and manage ZF parameters which do not stem from ZF fields (those are known to the FileSource) and do not stem from filters ("ziso" knows them globally, "osiz" knows them individually) but rather from an inspection of the file content header for zisofs magic number and plausible parameters. More...
 
int iso_file_zf_by_magic (IsoFile *file, int flag)
 Checks whether a file effectively bears a zisofs file header and eventually marks this by a struct zisofs_zf_info as xinfo of the file node. More...
 
int iso_node_get_id (IsoNode *node, unsigned int *fs_id, dev_t *dev_id, ino_t *ino_id, int flag)
 
int iso_node_set_unique_id (IsoNode *node, IsoImage *image, int flag)
 
int iso_node_set_ino (IsoNode *node, ino_t ino, int flag)
 
int iso_node_cmp_flag (IsoNode *n1, IsoNode *n2, int flag)
 
int iso_file_set_isofscx (IsoFile *file, unsigned int checksum_index, int flag)
 Set the checksum index (typically coming from IsoFileSrc.checksum_index) of a regular file node. More...
 
int iso_root_set_isofsca (IsoNode *node, uint32_t start_lba, uint32_t end_lba, uint32_t count, uint32_t size, char *typetext, int flag)
 Set the checksum area description. More...
 
int iso_root_get_isofsca (IsoNode *node, uint32_t *start_lba, uint32_t *end_lba, uint32_t *count, uint32_t *size, char typetext[81], int flag)
 Get the checksum area description. More...
 
int iso_root_set_isofsnt (IsoNode *node, uint32_t truncate_mode, uint32_t truncate_length, int flag)
 Record and get truncation parameters as of iso_image_set_truncate_mode() by "isofs.nt". More...
 
int iso_root_get_isofsnt (IsoNode *node, uint32_t *truncate_mode, uint32_t *truncate_length, int flag)
 
int iso_node_clone_xinfo (IsoNode *from_node, IsoNode *to_node, int flag)
 Copy the xinfo list from one node to the another. More...
 
int iso_px_ino_xinfo_func (void *data, int flag)
 The iso_node_xinfo_func instance which governs the storing of the inode number from Rock Ridge field PX. More...
 
int iso_px_ino_xinfo_cloner (void *old_data, void **new_data, int flag)
 
int zisofs_zf_xinfo_cloner (void *old_data, void **new_data, int flag)
 
int iso_dir_get_node_trunc (IsoDir *dir, int truncate_length, const char *name, IsoNode **node)
 

Macro Definition Documentation

◆ LIBISOFS_NODE_NAME_MAX

#define LIBISOFS_NODE_NAME_MAX   255

Definition at line 43 of file node.h.

◆ LIBISOFS_NODE_PATH_MAX

#define LIBISOFS_NODE_PATH_MAX   1024

Definition at line 53 of file node.h.

Typedef Documentation

◆ IsoExtendedInfo

The extended information is a way to attach additional information to each IsoNode.

External applications may want to use this extension system to store application specific information related to each node. On the other side, libisofs may make use of this struct to attach information to nodes in some particular, uncommon, cases, without incrementing the size of the IsoNode struct.

It is implemented like a chained list.

Definition at line 1 of file node.h.

Function Documentation

◆ iso_aa_get_acl_text()

int iso_aa_get_acl_text ( unsigned char *  aa_string,
mode_t  st_mode,
char **  access_text,
char **  default_text,
int  flag 
)

Like iso_node_get_acl_text() with param node replaced by aa_string and st_mode from where to obtain the ACLs.

All other parameter specs apply.

Definition at line 2180 of file node.c.

2182 {
2183  int ret;
2184  size_t num_attrs = 0, *value_lengths = NULL;
2185  char **names = NULL, **values = NULL;
2186 
2187  if (flag & (1 << 15)) {
2188  iso_attr_get_acl_text(num_attrs, names, value_lengths, values, st_mode,
2189  access_text, default_text, 1 << 15);
2190  return 1;
2191  }
2192  ret = iso_aa_get_attrs(aa_string, &num_attrs, &names,
2193  &value_lengths, &values, 1);
2194  if (ret < 0)
2195  goto ex;
2196  ret = iso_attr_get_acl_text(num_attrs, names, value_lengths, values,
2197  st_mode, access_text, default_text, flag);
2198 ex:;
2199  iso_aa_get_attrs(aa_string, &num_attrs, &names, &value_lengths, &values,
2200  1 << 15);
2201  return ret;
2202 }
int iso_aa_get_attrs(unsigned char *aa_string, size_t *num_attrs, char ***names, size_t **value_lengths, char ***values, int flag)
Backend of iso_node_get_attrs() with parameter node replaced by the AAIP string from where to get the...
Definition: node.c:1647
static int iso_attr_get_acl_text(size_t num_attrs, char **names, size_t *value_lengths, char **values, mode_t st_mode, char **access_text, char **default_text, int flag)
Backend of iso_node_get_acl_text() with parameter node replaced by the attribute list from where to g...
Definition: node.c:2089

References iso_aa_get_attrs(), and iso_attr_get_acl_text().

Referenced by default_create_node(), and src_aa_to_node().

◆ iso_aa_get_attrs()

int iso_aa_get_attrs ( unsigned char *  aa_string,
size_t *  num_attrs,
char ***  names,
size_t **  value_lengths,
char ***  values,
int  flag 
)

Backend of iso_node_get_attrs() with parameter node replaced by the AAIP string from where to get the attribute list.

All other parameter specs apply.

Definition at line 1647 of file node.c.

1649 {
1650  struct aaip_state *aaip= NULL;
1651  unsigned char *rpt;
1652  size_t len, todo, consumed;
1653  int is_done = 0, first_round= 1, ret;
1654 
1655  if (flag & (1 << 15))
1656  aaip_get_decoded_attrs(&aaip, num_attrs, names,
1657  value_lengths, values, 1 << 15);
1658  *num_attrs = 0;
1659  *names = NULL;
1660  *value_lengths = NULL;
1661  *values = NULL;
1662  if (flag & (1 << 15))
1663  return 1;
1664 
1665  rpt = aa_string;
1666  len = aaip_count_bytes(rpt, 0);
1667  while (!is_done) {
1668  todo = len - (rpt - aa_string);
1669  if (todo > 2048)
1670  todo = 2048;
1671  if (todo == 0) {
1672  /* Out of data while still prompted to submit */
1673  ret = ISO_AAIP_BAD_AASTRING;
1674  goto ex;
1675  }
1676  /* Allow 1 million bytes of memory consumption, 100,000 attributes */
1677  ret = aaip_decode_attrs(&aaip, (size_t) 1000000, (size_t) 100000,
1678  rpt, todo, &consumed, first_round);
1679  rpt+= consumed;
1680  first_round= 0;
1681  if (ret == 1)
1682  continue;
1683  if (ret == 2)
1684  break;
1685 
1686  /* aaip_decode_attrs() reports error */
1687  ret = ISO_AAIP_BAD_AASTRING;
1688  goto ex;
1689  }
1690 
1691  if ((size_t) (rpt - aa_string) != len) {
1692  /* aaip_decode_attrs() returns 2 but still bytes are left */
1693  ret = ISO_AAIP_BAD_AASTRING;
1694  goto ex;
1695  }
1696 
1697  ret = aaip_get_decoded_attrs(&aaip, num_attrs, names,
1698  value_lengths, values, 0);
1699  if (ret != 1) {
1700  /* aaip_get_decoded_attrs() failed */
1701  ret = ISO_AAIP_BAD_AASTRING;
1702  goto ex;
1703  }
1704  if (!(flag & 1)) {
1705  /* Clean out eventual ACL attribute resp. all other xattr */
1706  attrs_cleanout_name("", num_attrs, *names, *value_lengths, *values,
1707  !!(flag & 4));
1708  }
1709 
1710  ret = 1;
1711 ex:;
1712  aaip_decode_attrs(&aaip, (size_t) 1000000, (size_t) 100000,
1713  rpt, todo, &consumed, 1 << 15);
1714  return ret;
1715 }
size_t aaip_count_bytes(unsigned char *data, int flag)
Definition: aaip_0_2.c:966
int aaip_get_decoded_attrs(struct aaip_state **handle, size_t *num_attrs, char ***names, size_t **value_lengths, char ***values, int flag)
Definition: aaip_0_2.c:1971
int aaip_decode_attrs(struct aaip_state **handle, size_t memory_limit, size_t num_attr_limit, unsigned char *data, size_t num_data, size_t *consumed, int flag)
Definition: aaip_0_2.c:1785
#define ISO_AAIP_BAD_AASTRING
Error with decoding AAIP info for ACL or xattr (FAILURE, HIGH, -340)
Definition: libisofs.h:8939
static int attrs_cleanout_name(char *del_name, size_t *num_attrs, char **names, size_t *value_lengths, char **values, int flag)
Definition: node.c:1612

References aaip_count_bytes(), aaip_decode_attrs(), aaip_get_decoded_attrs(), attrs_cleanout_name(), and ISO_AAIP_BAD_AASTRING.

Referenced by iso_aa_get_acl_text(), iso_aa_lookup_attr(), and iso_node_get_attrs().

◆ iso_aa_lookup_attr()

int iso_aa_lookup_attr ( unsigned char *  aa_string,
char *  name,
size_t *  value_length,
char **  value,
int  flag 
)

Search given name.

Eventually calloc() and copy value. Add trailing 0 byte for caller convenience.

Returns
1= found , 0= not found , <0 error

Definition at line 1724 of file node.c.

1726 {
1727  size_t num_attrs = 0, *value_lengths = NULL;
1728  char **names = NULL, **values = NULL;
1729  int i, ret = 0, found = 0;
1730 
1731  ret = iso_aa_get_attrs(aa_string, &num_attrs, &names,
1732  &value_lengths, &values, 0);
1733  if (ret < 0)
1734  return ret;
1735  for (i = 0; i < (int) num_attrs; i++) {
1736  if (strcmp(names[i], name))
1737  continue;
1738  *value_length = value_lengths[i];
1739  *value = calloc(*value_length + 1, 1);
1740  if (*value == NULL) {
1741  found = ISO_OUT_OF_MEM;
1742  break;
1743  }
1744  if (*value_length > 0)
1745  memcpy(*value, values[i], *value_length);
1746  (*value)[*value_length] = 0;
1747  found = 1;
1748  break;
1749  }
1750  iso_aa_get_attrs(aa_string, &num_attrs, &names,
1751  &value_lengths, &values, 1 << 15);
1752  return found;
1753 }
#define ISO_OUT_OF_MEM
Memory allocation error (FATAL,HIGH, -6)
Definition: libisofs.h:8745

References iso_aa_get_attrs(), and ISO_OUT_OF_MEM.

Referenced by iso_image_import(), and iso_node_lookup_attr().

◆ iso_dir_exists()

int iso_dir_exists ( IsoDir dir,
const char *  name,
IsoNode ***  pos 
)

Check if a node with the given name exists in a dir.

Parameters
dirA valid dir. It can't be NULL
nameThe node name to search for. It can't be NULL
posIf not NULL, will be filled with the position where to insert. If the node exists, (**pos) will refer to the given node.
Returns
1 if node exists, 0 if not

Definition at line 1338 of file node.c.

1339 {
1340  IsoNode **node;
1341 
1342  iso_dir_find(dir, name, &node);
1343  if (pos) {
1344  *pos = node;
1345  }
1346  return (*node != NULL && !strcmp((*node)->name, name)) ? 1 : 0;
1347 }
void iso_dir_find(IsoDir *dir, const char *name, IsoNode ***pos)
Find the position where to insert a node.
Definition: node.c:1330
Definition: node.h:100

References iso_dir_find().

Referenced by iso_add_dir_src_rec(), iso_dir_get_node(), iso_tree_add_new_cut_out_node(), iso_tree_add_new_dir(), iso_tree_add_new_file(), iso_tree_add_new_node(), iso_tree_add_new_special(), iso_tree_add_new_symlink(), iso_tree_add_node_builder(), and make_really_unique_name().

◆ iso_dir_find()

void iso_dir_find ( IsoDir dir,
const char *  name,
IsoNode ***  pos 
)

Find the position where to insert a node.

Parameters
dirA valid dir. It can't be NULL
nameThe node name to search for. It can't be NULL
posWill be filled with the position where to insert. It can't be NULL

Definition at line 1330 of file node.c.

1331 {
1332  *pos = &(dir->children);
1333  while (**pos != NULL && strcmp((**pos)->name, name) < 0) {
1334  *pos = &((**pos)->next);
1335  }
1336 }
IsoNode * children
list of children.
Definition: node.h:144

References Iso_Dir::children.

Referenced by iso_dir_add_node(), and iso_dir_exists().

◆ iso_dir_get_node_trunc()

int iso_dir_get_node_trunc ( IsoDir dir,
int  truncate_length,
const char *  name,
IsoNode **  node 
)

Definition at line 654 of file node.c.

656 {
657  int ret;
658  char *trunc = NULL;
659 
660  if ((int) strlen(name) <= truncate_length) {
661  ret = iso_dir_get_node(dir, name, node);
662  return ret;
663  }
664  trunc = strdup(name);
665  if (trunc == NULL)
666  return ISO_OUT_OF_MEM;
667  ret = iso_truncate_rr_name(1, truncate_length, trunc, 1);
668  if (ret < 0)
669  goto ex;
670  ret = iso_dir_get_node(dir, trunc, node);
671  if (ret == 0)
672  ret = 2;
673 ex:;
674  LIBISO_FREE_MEM(trunc);
675  return ret;
676 }
int iso_dir_get_node(IsoDir *dir, const char *name, IsoNode **node)
Locate a node inside a given dir.
Definition: node.c:632
int iso_truncate_rr_name(int truncate_mode, int truncate_length, char *name, int flag)
Definition: util.c:2425
#define LIBISO_FREE_MEM(pt)
Definition: util.h:627

References iso_dir_get_node(), ISO_OUT_OF_MEM, iso_truncate_rr_name(), and LIBISO_FREE_MEM.

Referenced by iso_image_dir_get_node(), and iso_tree_path_to_node_flag().

◆ iso_dir_insert()

int iso_dir_insert ( IsoDir dir,
IsoNode node,
IsoNode **  pos,
enum iso_replace_mode  replace 
)

Inserts a given node in a dir, at the specified position.

Parameters
dirDir where to insert. It can't be NULL
nodeThe node to insert. It can't be NULL
posPosition where the node will be inserted. It is a pointer previously obtained with a call to iso_dir_exists() or iso_dir_find(). It can't be NULL.
replaceWhether to replace an old node with the same name with the new node.
Returns
If success, number of children in dir. < 0 on error

Definition at line 1349 of file node.c.

1351 {
1352  if (*pos != NULL && !strcmp((*pos)->name, node->name)) {
1353  /* a node with same name already exists */
1354  switch(replace) {
1355  case ISO_REPLACE_NEVER:
1356  return ISO_NODE_NAME_NOT_UNIQUE;
1357  case ISO_REPLACE_IF_NEWER:
1358  if ((*pos)->mtime >= node->mtime) {
1359  /* old file is newer */
1360  return ISO_NODE_NAME_NOT_UNIQUE;
1361  }
1362  break;
1364  if ((*pos)->mtime >= node->mtime) {
1365  /* old file is newer */
1366  return ISO_NODE_NAME_NOT_UNIQUE;
1367  }
1368  if ((node->mode & S_IFMT) != ((*pos)->mode & S_IFMT)) {
1369  /* different file types */
1370  return ISO_NODE_NAME_NOT_UNIQUE;
1371  }
1372  break;
1374  if ((node->mode & S_IFMT) != ((*pos)->mode & S_IFMT)) {
1375  /* different file types */
1376  return ISO_NODE_NAME_NOT_UNIQUE;
1377  }
1378  break;
1379  case ISO_REPLACE_ALWAYS:
1380  break;
1381  default:
1382  /* CAN'T HAPPEN */
1383  return ISO_ASSERT_FAILURE;
1384  }
1385 
1386  /* if we are reach here we have to replace */
1387  node->next = (*pos)->next;
1388  (*pos)->parent = NULL;
1389  (*pos)->next = NULL;
1390  iso_node_unref(*pos);
1391  *pos = node;
1392  node->parent = dir;
1393  return dir->nchildren;
1394  }
1395 
1396  node->next = *pos;
1397  *pos = node;
1398  node->parent = dir;
1399 
1400  return ++dir->nchildren;
1401 }
@ ISO_REPLACE_IF_SAME_TYPE_AND_NEWER
Replace with the new node if it is the same file type and its ctime is newer than the old one.
Definition: libisofs.h:365
@ ISO_REPLACE_ALWAYS
Always replace the old node with the new.
Definition: libisofs.h:356
@ ISO_REPLACE_IF_NEWER
Replace with the new node if its ctime is newer than the old one.
Definition: libisofs.h:369
@ ISO_REPLACE_IF_SAME_TYPE
Replace with the new node if it is the same file type.
Definition: libisofs.h:360
@ ISO_REPLACE_NEVER
Never replace an existing node, and instead fail with ISO_NODE_NAME_NOT_UNIQUE.
Definition: libisofs.h:352
#define ISO_NODE_NAME_NOT_UNIQUE
Node with same name already exists (FAILURE,HIGH, -65)
Definition: libisofs.h:8766
#define ISO_ASSERT_FAILURE
Internal programming error.
Definition: libisofs.h:8737
void iso_node_unref(IsoNode *node)
Decrements the reference counting of the given node.
Definition: node.c:56
size_t nchildren
The number of children of this directory.
Definition: node.h:143
char * name
Real name, in default charset.
Definition: node.h:113
IsoDir * parent
parent node, NULL for root
Definition: node.h:126
mode_t mode
protection
Definition: node.h:115
IsoNode * next
Definition: node.h:131
time_t mtime
time of last modification
Definition: node.h:121

References ISO_ASSERT_FAILURE, ISO_NODE_NAME_NOT_UNIQUE, iso_node_unref(), ISO_REPLACE_ALWAYS, ISO_REPLACE_IF_NEWER, ISO_REPLACE_IF_SAME_TYPE, ISO_REPLACE_IF_SAME_TYPE_AND_NEWER, ISO_REPLACE_NEVER, Iso_Node::mode, Iso_Node::mtime, Iso_Node::name, Iso_Dir::nchildren, Iso_Node::next, and Iso_Node::parent.

Referenced by iso_add_dir_src_rec(), iso_dir_add_node(), iso_tree_add_new_cut_out_node(), iso_tree_add_new_dir(), iso_tree_add_new_file(), iso_tree_add_new_node(), iso_tree_add_new_special(), iso_tree_add_new_symlink(), and iso_tree_add_node_builder().

◆ iso_dir_iter_register()

int iso_dir_iter_register ( IsoDirIter iter)

Add a new iterator to the registry.

The iterator register keeps track of all iterators being used, and are notified when directory structure changes.

Definition at line 1418 of file node.c.

1419 {
1420  struct iter_reg_node *new;
1421  new = malloc(sizeof(struct iter_reg_node));
1422  if (new == NULL) {
1423  return ISO_OUT_OF_MEM;
1424  }
1425  new->iter = iter;
1426  new->next = iter_reg;
1427  iter_reg = new;
1428  return ISO_SUCCESS;
1429 }
#define ISO_SUCCESS
successfully execution
Definition: libisofs.h:8719
static struct iter_reg_node * iter_reg
Definition: node.c:1411
IsoDirIter * iter
Definition: node.c:1405

References ISO_OUT_OF_MEM, ISO_SUCCESS, iter_reg_node::iter, and iter_reg.

Referenced by iso_dir_find_children(), and iso_dir_get_children().

◆ iso_dir_iter_unregister()

void iso_dir_iter_unregister ( IsoDirIter iter)

Unregister a directory iterator.

Definition at line 1434 of file node.c.

1435 {
1436  struct iter_reg_node **pos;
1437  pos = &iter_reg;
1438  while (*pos != NULL && (*pos)->iter != iter) {
1439  pos = &(*pos)->next;
1440  }
1441  if (*pos) {
1442  struct iter_reg_node *tmp = (*pos)->next;
1443  free(*pos);
1444  *pos = tmp;
1445  }
1446 }
struct iter_reg_node * next
Definition: node.c:1406

References iter_reg_node::iter, iter_reg, and iter_reg_node::next.

Referenced by iso_dir_iter_free().

◆ iso_file_set_isofscx()

int iso_file_set_isofscx ( IsoFile file,
unsigned int  checksum_index,
int  flag 
)

Set the checksum index (typically coming from IsoFileSrc.checksum_index) of a regular file node.

The index is encoded as xattr "isofs.cx" with four bytes of value.

Definition at line 2887 of file node.c.

2889 {
2890  static char *names = "isofs.cx";
2891  static size_t value_lengths[1] = {4};
2892  unsigned char value[4];
2893  char *valuept;
2894  int i, ret;
2895 
2896  valuept= (char *) value;
2897  if (flag & 1) {
2898  ret = iso_node_set_attrs((IsoNode *) file, (size_t) 1,
2899  &names, value_lengths, &valuept, 4 | 8);
2900  return ret;
2901  }
2902  for(i = 0; i < 4; i++)
2903  value[3 - i] = (checksum_index >> (8 * i)) & 0xff;
2904  ret = iso_node_set_attrs((IsoNode *) file, (size_t) 1,
2905  &names, value_lengths, &valuept, 2 | 8);
2906  return ret;
2907 }
int iso_node_set_attrs(IsoNode *node, size_t num_attrs, char **names, size_t *value_lengths, char **values, int flag)
Set the list of xattr which is associated with the node.
Definition: node.c:1973

References iso_node_set_attrs().

Referenced by checksum_prepare_nodes(), iso_file_src_create(), and process_preserved_cx().

◆ iso_file_zf_by_magic()

int iso_file_zf_by_magic ( IsoFile file,
int  flag 
)

Checks whether a file effectively bears a zisofs file header and eventually marks this by a struct zisofs_zf_info as xinfo of the file node.

Parameters
flagbit0= inquire the most original stream of the file bit1= permission to overwrite existing zisofs_zf_info bit2= if no zisofs header is found: create xinfo with parameters which indicate no zisofs
Returns
1= zf xinfo added, 0= no zisofs data found , 2= found existing zf xinfo and flag bit1 was not set <0 means error

Definition at line 2448 of file node.c.

2449 {
2450  int ret, stream_type, header_size_div4, block_size_log2, version;
2451  uint64_t uncompressed_size;
2452  IsoStream *stream, *input_stream;
2453  struct zisofs_zf_info *zf = NULL;
2454  void *xipt;
2455  uint8_t algo[2];
2456 
2457  /* Intimate friendship with this function in filters/zisofs.c */
2458  int ziso_is_zisofs_stream(IsoStream *stream, int *stream_type,
2459  uint8_t zisofs_algo[2],
2460  int *header_size_div4, int *block_size_log2,
2461  uint64_t *uncompressed_size, int flag);
2462 
2463  ret = iso_node_get_xinfo((IsoNode *) file, zisofs_zf_xinfo_func, &xipt);
2464  if (ret == 1) {
2465  if (!(flag & 2))
2466  return 2;
2468  if (ret < 0)
2469  return ret;
2470  }
2471  input_stream = stream = iso_file_get_stream(file);
2472  while (flag & 1) {
2473  input_stream = iso_stream_get_input_stream(stream, 0);
2474  if (input_stream == NULL)
2475  break;
2476  stream = input_stream;
2477  }
2478  version = ((flag >> 8) & 0xff);
2479  algo[0] = algo[1] = 0;
2480  ret = ziso_is_zisofs_stream(stream, &stream_type, algo, &header_size_div4,
2482  if (ret < 0)
2483  return ret;
2484  if (version < 2 && ret > 0 && (algo[0] != 'p' || algo[1] != 'z'))
2485  ret = 0;
2486  if (ret != 1 || stream_type != 2) {
2487  if (!(flag & 4))
2488  return 0;
2489  algo[0] = algo[1] = 0;
2490  header_size_div4 = 0;
2491  block_size_log2 = 0;
2492  uncompressed_size = 0;
2493  }
2494  zf = calloc(1, sizeof(struct zisofs_zf_info));
2495  if (zf == NULL)
2496  return ISO_OUT_OF_MEM;
2497  zf->zisofs_algo[0] = algo[0];
2498  zf->zisofs_algo[1] = algo[1];
2502  ret = iso_node_add_xinfo((IsoNode *) file, zisofs_zf_xinfo_func, zf);
2503  return ret;
2504 }
IsoStream * iso_stream_get_input_stream(IsoStream *stream, int flag)
Obtain the eventual input stream of a filter stream.
Definition: stream.c:867
IsoStream * iso_file_get_stream(IsoFile *file)
Get the IsoStream that represents the contents of the given IsoFile.
Definition: node.c:1161
int iso_node_remove_xinfo(IsoNode *node, iso_node_xinfo_func proc)
Remove the given extended info (defined by the proc function) from the given node.
Definition: node.c:172
int iso_node_get_xinfo(IsoNode *node, iso_node_xinfo_func proc, void **data)
Get the given extended info (defined by the proc function) from the given node.
Definition: node.c:213
int iso_node_add_xinfo(IsoNode *node, iso_node_xinfo_func proc, void *data)
Add extended information to the given node.
Definition: node.c:136
int zisofs_zf_xinfo_func(void *data, int flag)
Function to identify and manage ZF parameters which do not stem from ZF fields (those are known to th...
Definition: node.c:2411
Representation of file contents as a stream of bytes.
Definition: libisofs.h:1184
Parameter structure which is to be managed by zisofs_zf_xinfo_func.
Definition: node.h:439
uint8_t header_size_div4
Definition: node.h:441
uint8_t block_size_log2
Definition: node.h:442
uint8_t zisofs_algo[2]
Definition: node.h:443
uint64_t uncompressed_size
Definition: node.h:440
int ziso_is_zisofs_stream(IsoStream *stream, int *stream_type, uint8_t zisofs_algo[2], int *header_size_div4, int *block_size_log2, uint64_t *uncompressed_size, int flag)
Definition: zisofs.c:1601

References zisofs_zf_info::block_size_log2, zisofs_zf_info::header_size_div4, iso_file_get_stream(), iso_node_add_xinfo(), iso_node_get_xinfo(), iso_node_remove_xinfo(), ISO_OUT_OF_MEM, iso_stream_get_input_stream(), zisofs_zf_info::uncompressed_size, ziso_is_zisofs_stream(), zisofs_zf_info::zisofs_algo, and zisofs_zf_xinfo_func().

Referenced by iso_node_zf_by_magic().

◆ iso_node_clone_xinfo()

int iso_node_clone_xinfo ( IsoNode from_node,
IsoNode to_node,
int  flag 
)

Copy the xinfo list from one node to the another.

Definition at line 286 of file node.c.

287 {
288  void *handle = NULL, *data, *new_data;
289  iso_node_xinfo_func proc;
290  iso_node_xinfo_cloner cloner;
291  int ret;
292 
293  iso_node_remove_all_xinfo(to_node, 0);
294  while (1) {
295  ret = iso_node_get_next_xinfo(from_node, &handle, &proc, &data);
296  if (ret <= 0)
297  break;
298  ret = iso_node_xinfo_get_cloner(proc, &cloner, 0);
299  if (ret == 0)
300  return ISO_XINFO_NO_CLONE;
301  if (ret < 0)
302  return ret;
303  ret = (*cloner)(data, &new_data, 0);
304  if (ret < 0)
305  break;
306  ret = iso_node_add_xinfo(to_node, proc, new_data);
307  if (ret < 0)
308  break;
309  }
310  if (ret < 0) {
311  iso_node_remove_all_xinfo(to_node, 0);
312  } else {
313  ret = iso_node_revert_xinfo_list(to_node, 0);
314  }
315  return ret;
316 }
int(* iso_node_xinfo_func)(void *data, int flag)
Class of functions to handle particular extended information.
Definition: libisofs.h:4838
#define ISO_XINFO_NO_CLONE
Extended information class offers no cloning method (FAILURE, HIGH, -375)
Definition: libisofs.h:9093
int(* iso_node_xinfo_cloner)(void *old_data, void **new_data, int flag)
Class of functions to clone extended information.
Definition: libisofs.h:4968
int iso_node_xinfo_get_cloner(iso_node_xinfo_func proc, iso_node_xinfo_cloner *cloner, int flag)
Inquire the registered cloner function for a particular class of extended information.
Definition: messages.c:119
int iso_node_get_next_xinfo(IsoNode *node, void **handle, iso_node_xinfo_func *proc, void **data)
Get the next pair of function pointer and data of an iteration of the list of extended information.
Definition: node.c:236
int iso_node_remove_all_xinfo(IsoNode *node, int flag)
Remove all extended information from the given node.
Definition: node.c:258
static int iso_node_revert_xinfo_list(IsoNode *node, int flag)
Definition: node.c:272

References iso_node_add_xinfo(), iso_node_get_next_xinfo(), iso_node_remove_all_xinfo(), iso_node_revert_xinfo_list(), iso_node_xinfo_get_cloner(), and ISO_XINFO_NO_CLONE.

Referenced by iso_tree_copy_node_attr().

◆ iso_node_cmp_flag()

int iso_node_cmp_flag ( IsoNode n1,
IsoNode n2,
int  flag 
)

Definition at line 2743 of file node.c.

2744 {
2745  int ret1, ret2;
2746  unsigned int fs_id1, fs_id2;
2747  dev_t dev_id1, dev_id2;
2748  ino_t ino_id1, ino_id2;
2749  IsoFile *f1 = NULL, *f2 = NULL;
2750  IsoSymlink *l1 = NULL, *l2 = NULL;
2751  IsoSpecial *s1 = NULL, *s2 = NULL;
2752  void *x1, *x2;
2753 
2754  if (n1 == n2)
2755  return 0;
2756  if (n1->type != n2->type)
2757  return (n1->type < n2->type ? -1 : 1);
2758 
2759  /* Imported or explicit ISO image node id has priority */
2760  ret1 = (iso_node_get_id(n1, &fs_id1, &dev_id1, &ino_id1, 1) > 0);
2761  ret2 = (iso_node_get_id(n2, &fs_id2, &dev_id2, &ino_id2, 1) > 0);
2762  if (ret1 != ret2)
2763  return (ret1 < ret2 ? -1 : 1);
2764  if (ret1) {
2765  /* fs_id and dev_id do not matter here.
2766  Both nodes have explicit inode numbers of the emerging image.
2767  */
2768  if (ino_id1 != ino_id2)
2769  return (ino_id1 < ino_id2 ? -1 : 1);
2770  if (ino_id1 == 0) /* Image ino 0 is always unique */
2771  return (n1 < n2 ? -1 : 1);
2772  goto image_inode_match;
2773  }
2774 
2775  if (n1->type == LIBISO_FILE) {
2776 
2777  f1 = (IsoFile *) n1;
2778  f2 = (IsoFile *) n2;
2779  ret1 = iso_stream_cmp_ino(f1->stream, f2->stream, 0);
2780  if (ret1)
2781  return ret1;
2782  goto inode_match;
2783 
2784  } else if (n1->type == LIBISO_SYMLINK) {
2785 
2786  l1 = (IsoSymlink *) n1;
2787  l2 = (IsoSymlink *) n2;
2788  fs_id1 = l1->fs_id;
2789  dev_id1 = l1->st_dev;
2790  ino_id1 = l1->st_ino;
2791  fs_id2 = l2->fs_id;
2792  dev_id2 = l2->st_dev;
2793  ino_id2 = l2->st_ino;
2794 
2795  } else if (n1->type == LIBISO_SPECIAL) {
2796 
2797  s1 = (IsoSpecial *) n1;
2798  s2 = (IsoSpecial *) n2;
2799  fs_id1 = s1->fs_id;
2800  dev_id1 = s1->st_dev;
2801  ino_id1 = s1->st_ino;
2802  fs_id2 = s2->fs_id;
2803  dev_id2 = s2->st_dev;
2804  ino_id2 = s2->st_ino;
2805 
2806  } else {
2807  return (n1 < n2 ? -1 : 1); /* case n1 == n2 is handled above */
2808  }
2809  if (fs_id1 != fs_id2)
2810  return (fs_id1 < fs_id2 ? -1 : 1);
2811  if (dev_id1 != dev_id2)
2812  return (dev_id1 < dev_id2 ? -1 : 1);
2813  if (ino_id1 != ino_id2)
2814  return (ino_id1 < ino_id2 ? -1 : 1);
2815  if (fs_id1 == 0 && dev_id1 == 0 && ino_id1 == 0)
2816  return (n1 < n2 ? -1 : 1);
2817 
2818 inode_match:;
2819 
2820  if (flag & 2) {
2821  /* What comes here has no predefined image ino resp. image_ino == 0 .
2822  Regard this as not equal.
2823  */
2824  return (n1 < n2 ? -1 : 1);
2825  }
2826 
2827 image_inode_match:;
2828 
2829  if (!(flag & 1))
2830  return 0;
2831  if (n1->type == LIBISO_SYMLINK) {
2832  l1 = (IsoSymlink *) n1;
2833  l2 = (IsoSymlink *) n2;
2834  ret1 = strcmp(l1->dest, l2->dest);
2835  if (ret1)
2836  return ret1;
2837  } else if (n1->type == LIBISO_SPECIAL) {
2838  s1 = (IsoSpecial *) n1;
2839  s2 = (IsoSpecial *) n2;
2840  if (s1->dev != s2->dev)
2841  return (s1->dev < s2->dev ? -1 : 1);
2842  }
2843 
2844  if (n1->mode != n2->mode)
2845  return (n1->mode < n2->mode ? -1 : 1);
2846  if (n1->uid != n2->uid)
2847  return (n1->uid < n2->uid ? -1 : 1);
2848  if (n1->gid != n2->gid)
2849  return (n1->gid < n2->gid ? -1 : 1);
2850  if (n1->atime != n2->atime)
2851  return (n1->atime < n2->atime ? -1 : 1);
2852  if (n1->mtime != n2->mtime)
2853  return (n1->mtime < n2->mtime ? -1 : 1);
2854  if (n1->ctime != n2->ctime)
2855  return (n1->ctime < n2->ctime ? -1 : 1);
2856 
2857  /* Compare xinfo */
2858  /* :( cannot compare general xinfo because data length is not known :( */
2859 
2860  /* compare aa_string */
2861  ret1 = iso_node_get_xinfo(n1, aaip_xinfo_func, &x1);
2862  ret2 = iso_node_get_xinfo(n2, aaip_xinfo_func, &x2);
2863  if (ret1 != ret2)
2864  return (ret1 < ret2 ? -1 : 1);
2865  if (ret1 == 1) {
2866  ret1 = aaip_count_bytes((unsigned char *) x1, 0);
2867  ret2 = aaip_count_bytes((unsigned char *) x2, 0);
2868  if (ret1 != ret2)
2869  return (ret1 < ret2 ? -1 : 1);
2870  ret1 = memcmp(x1, x2, ret1);
2871  if (ret1)
2872  return ret1;
2873  }
2874 
2875  return 0;
2876 }
@ LIBISO_FILE
Definition: libisofs.h:230
@ LIBISO_SYMLINK
Definition: libisofs.h:231
@ LIBISO_SPECIAL
Definition: libisofs.h:232
int aaip_xinfo_func(void *data, int flag)
Function to identify and manage AAIP strings as xinfo of IsoNode.
Definition: rockridge.c:1118
int iso_stream_cmp_ino(IsoStream *s1, IsoStream *s2, int flag)
Compare two streams whether they are based on the same input and will produce the same output.
Definition: stream.c:1042
int iso_node_get_id(IsoNode *node, unsigned int *fs_id, dev_t *dev_id, ino_t *ino_id, int flag)
Definition: node.c:2592
Definition: node.h:149
IsoStream * stream
Definition: node.h:166
gid_t gid
group ID of owner
Definition: node.h:117
time_t ctime
time of last status change
Definition: node.h:122
uid_t uid
user ID of owner
Definition: node.h:116
time_t atime
time of last access
Definition: node.h:120
enum IsoNodeType type
Type of the IsoNode, do not confuse with mode.
Definition: node.h:111
ino_t st_ino
Definition: node.h:195
dev_t st_dev
Definition: node.h:194
unsigned int fs_id
Definition: node.h:193
dev_t dev
Definition: node.h:187

References aaip_count_bytes(), aaip_xinfo_func(), Iso_Node::atime, Iso_Node::ctime, Iso_Symlink::dest, Iso_Special::dev, Iso_Symlink::fs_id, Iso_Special::fs_id, Iso_Node::gid, iso_node_get_id(), iso_node_get_xinfo(), iso_stream_cmp_ino(), LIBISO_FILE, LIBISO_SPECIAL, LIBISO_SYMLINK, Iso_Node::mode, Iso_Node::mtime, Iso_Symlink::st_dev, Iso_Special::st_dev, Iso_Symlink::st_ino, Iso_Special::st_ino, Iso_File::stream, Iso_Node::type, and Iso_Node::uid.

Referenced by ecma119_node_cmp_flag(), and iso_node_cmp_ino().

◆ iso_node_get_id()

int iso_node_get_id ( IsoNode node,
unsigned int *  fs_id,
dev_t *  dev_id,
ino_t *  ino_id,
int  flag 
)

Definition at line 2592 of file node.c.

2594 {
2595  int ret;
2596  IsoFile *file;
2597  IsoSymlink *symlink;
2598  IsoSpecial *special;
2599  void *xipt;
2600 
2601  ret = iso_node_get_xinfo(node, iso_px_ino_xinfo_func, &xipt);
2602  if (ret < 0)
2603  goto no_id;
2604  if (ret == 1) {
2605  *fs_id = ISO_IMAGE_FS_ID;
2606  *dev_id = 0;
2607  *ino_id = *((ino_t *) xipt);
2608  return 2;
2609  }
2610 
2611  if (node->type == LIBISO_FILE) {
2612  file= (IsoFile *) node;
2613  iso_stream_get_id(file->stream, fs_id, dev_id, ino_id);
2614  if (*fs_id != ISO_IMAGE_FS_ID && (flag & 1)) {
2615  ret = 0;
2616  goto no_id;
2617  }
2618  return 1;
2619 
2620  } else if (node->type == LIBISO_SYMLINK) {
2621  symlink = (IsoSymlink *) node;
2622  if (symlink->fs_id != ISO_IMAGE_FS_ID && (flag & 1)) {
2623  ret = 0;
2624  goto no_id;
2625  }
2626  *fs_id = symlink->fs_id;
2627  *dev_id = symlink->st_dev;
2628  *ino_id = symlink->st_ino;
2629  return 1;
2630 
2631  } else if (node->type == LIBISO_SPECIAL) {
2632  special = (IsoSpecial *) node;
2633  if (special->fs_id != ISO_IMAGE_FS_ID && (flag & 1)) {
2634  ret = 0;
2635  goto no_id;
2636  }
2637  *fs_id = special->fs_id;
2638  *dev_id = special->st_dev;
2639  *ino_id = special->st_ino;
2640  return 1;
2641 
2642  }
2643 
2644  ret = 0;
2645 no_id:;
2646  *fs_id = 0;
2647  *dev_id = 0;
2648  *ino_id = 0;
2649  return ret;
2650 }
#define ISO_IMAGE_FS_ID
Definition: fsource.h:22
void iso_stream_get_id(IsoStream *stream, unsigned int *fs_id, dev_t *dev_id, ino_t *ino_id)
Get an unique identifier for a given IsoStream.
Definition: stream.c:835
int iso_px_ino_xinfo_func(void *data, int flag)
The iso_node_xinfo_func instance which governs the storing of the inode number from Rock Ridge field ...
Definition: node.c:2559

References Iso_Symlink::fs_id, Iso_Special::fs_id, ISO_IMAGE_FS_ID, iso_node_get_xinfo(), iso_px_ino_xinfo_func(), iso_stream_get_id(), LIBISO_FILE, LIBISO_SPECIAL, LIBISO_SYMLINK, Iso_Symlink::st_dev, Iso_Special::st_dev, Iso_Symlink::st_ino, Iso_Special::st_ino, Iso_File::stream, and Iso_Node::type.

Referenced by img_register_ino(), img_update_ino(), iso_node_cmp_flag(), and match_hardlinks().

◆ iso_node_is_valid_link_dest()

int iso_node_is_valid_link_dest ( const char *  dest)

Check if a given path is valid for the destination of a link.

Returns
1 if yes, 0 if not

Definition at line 1283 of file node.c.

1284 {
1285  int ret;
1286  char *ptr, *brk_info, *component;
1287 
1288  /* a dest can't be NULL */
1289  if (dest == NULL) {
1290  return ISO_NULL_POINTER;
1291  }
1292 
1293  /* guard against the empty string or big dest... */
1294  if (dest[0] == '\0') {
1295 #ifdef Libisofs_debug_rr_reserveD
1296  fprintf(stderr, "libisofs_DEBUG: ISO_RR_NAME_RESERVED by empty link target\n");
1297 #endif
1298  return ISO_RR_NAME_RESERVED;
1299  }
1300  if (strlen(dest) > LIBISOFS_NODE_PATH_MAX)
1301  return ISO_RR_PATH_TOO_LONG;
1302 
1303  /* check that all components are valid */
1304  if (!strcmp(dest, "/")) {
1305  /* "/" is a valid component */
1306  return 1;
1307  }
1308 
1309  ptr = strdup(dest);
1310  if (ptr == NULL) {
1311  return ISO_OUT_OF_MEM;
1312  }
1313 
1314  ret = 1;
1315  component = strtok_r(ptr, "/", &brk_info);
1316  while (component) {
1317  if (strcmp(component, ".") && strcmp(component, "..")) {
1318  ret = iso_node_is_valid_name(component);
1319  if (ret < 0) {
1320  break;
1321  }
1322  }
1323  component = strtok_r(NULL, "/", &brk_info);
1324  }
1325  free(ptr);
1326 
1327  return ret;
1328 }
#define ISO_RR_PATH_TOO_LONG
Rock Ridge path too long (FAILURE, HIGH, -379)
Definition: libisofs.h:9105
#define ISO_NULL_POINTER
NULL pointer as value for an arg.
Definition: libisofs.h:8742
#define ISO_RR_NAME_RESERVED
Reserved Rock Ridge leaf name (FAILURE, HIGH, -378)
Definition: libisofs.h:9102
int iso_node_is_valid_name(const char *name)
Check if a given name is valid for an iso node.
Definition: node.c:1245
#define LIBISOFS_NODE_PATH_MAX
Definition: node.h:53

References iso_node_is_valid_name(), ISO_NULL_POINTER, ISO_OUT_OF_MEM, ISO_RR_NAME_RESERVED, ISO_RR_PATH_TOO_LONG, and LIBISOFS_NODE_PATH_MAX.

Referenced by iso_node_new_symlink(), and iso_symlink_set_dest().

◆ iso_node_is_valid_name()

int iso_node_is_valid_name ( const char *  name)

Check if a given name is valid for an iso node.

Returns
1 if yes, <0 if not. The value is a specific ISO_* error code.
1 if yes, 0 if not

Definition at line 1245 of file node.c.

1246 {
1247  /* a name can't be NULL */
1248  if (name == NULL) {
1249  return ISO_NULL_POINTER;
1250  }
1251 
1252  /* guard against the empty string or big names... */
1253  if (name[0] == '\0')
1254  goto rr_reserved;
1255  if (strlen(name) > LIBISOFS_NODE_NAME_MAX)
1256  return ISO_RR_NAME_TOO_LONG;
1257 
1258  /* ...against "." and ".." names... */
1259  if (!strcmp(name, ".") || !strcmp(name, ".."))
1260  goto rr_reserved;
1261 
1262  /* ...and against names with '/' */
1263  if (strchr(name, '/') != NULL)
1264  goto rr_reserved;
1265 
1266  return 1;
1267 
1268 rr_reserved:;
1269 /* # define Libisofs_debug_rr_reserveD */
1270 #ifdef Libisofs_debug_rr_reserveD
1271  fprintf(stderr, "libisofs_DEBUG: ISO_RR_NAME_RESERVED with '%s'\n", name);
1272 #endif
1273 
1274  return ISO_RR_NAME_RESERVED;
1275 }
#define ISO_RR_NAME_TOO_LONG
Rock Ridge leaf name too long (FAILURE, HIGH, -377)
Definition: libisofs.h:9099
#define LIBISOFS_NODE_NAME_MAX
Definition: node.h:43

References ISO_NULL_POINTER, ISO_RR_NAME_RESERVED, ISO_RR_NAME_TOO_LONG, and LIBISOFS_NODE_NAME_MAX.

Referenced by iso_node_is_valid_link_dest(), iso_node_new_dir(), iso_node_new_file(), iso_node_new_special(), iso_node_new_symlink(), iso_node_set_name_trunc(), and iso_tree_add_boot_node().

◆ iso_node_new_dir()

int iso_node_new_dir ( char *  name,
IsoDir **  dir 
)

Create a new IsoDir.

Attributes, uid/gid, timestamps, etc are set to default (0) values. You must set them.

Parameters
nameName for the node. It is not strdup() so you shouldn't use this reference when this function returns successfully. NULL is not allowed.
dir
Returns
1 on success, < 0 on error.

Definition at line 1481 of file node.c.

1482 {
1483  IsoDir *new;
1484  int ret;
1485 
1486  if (dir == NULL || name == NULL) {
1487  return ISO_NULL_POINTER;
1488  }
1489 
1490  /* check if the name is valid */
1491  ret = iso_node_is_valid_name(name);
1492  if (ret < 0)
1493  return ret;
1494 
1495  new = calloc(1, sizeof(IsoDir));
1496  if (new == NULL) {
1497  return ISO_OUT_OF_MEM;
1498  }
1499  new->node.refcount = 1;
1500  new->node.type = LIBISO_DIR;
1501  new->node.name = name;
1502  new->node.mode = S_IFDIR;
1503  *dir = new;
1504  return ISO_SUCCESS;
1505 }
@ LIBISO_DIR
Definition: libisofs.h:229
Definition: node.h:140

References iso_node_is_valid_name(), ISO_NULL_POINTER, ISO_OUT_OF_MEM, ISO_SUCCESS, and LIBISO_DIR.

Referenced by default_create_node(), and iso_tree_add_new_dir().

◆ iso_node_new_file()

int iso_node_new_file ( char *  name,
IsoStream stream,
IsoFile **  file 
)

Create a new file node.

Attributes, uid/gid, timestamps, etc are set to default (0) values. You must set them.

Parameters
nameName for the node. It is not strdup() so you shouldn't use this reference when this function returns successfully. NULL is not allowed.
streamSource for file contents. The reference is taken by the node, you must call iso_stream_ref() if you need your own ref.
Returns
1 on success, < 0 on error.

Definition at line 1507 of file node.c.

1508 {
1509  IsoFile *new;
1510  int ret;
1511 
1512  if (file == NULL || name == NULL || stream == NULL) {
1513  return ISO_NULL_POINTER;
1514  }
1515 
1516  /* check if the name is valid */
1517  ret = iso_node_is_valid_name(name);
1518  if (ret < 0)
1519  return ret;
1520 
1521  new = calloc(1, sizeof(IsoFile));
1522  if (new == NULL) {
1523  return ISO_OUT_OF_MEM;
1524  }
1525  new->node.refcount = 1;
1526  new->node.type = LIBISO_FILE;
1527  new->node.name = name;
1528  new->node.mode = S_IFREG;
1529  new->from_old_session = 0;
1530  new->explicit_weight = 0;
1531  new->sort_weight = 0;
1532  new->stream = stream;
1533 
1534  *file = new;
1535  return ISO_SUCCESS;
1536 }

References iso_node_is_valid_name(), ISO_NULL_POINTER, ISO_OUT_OF_MEM, ISO_SUCCESS, and LIBISO_FILE.

Referenced by default_create_file(), default_create_node(), and iso_tree_add_new_file().

◆ iso_node_new_root()

int iso_node_new_root ( IsoDir **  root)

Definition at line 1460 of file node.c.

1461 {
1462  IsoDir *dir;
1463  time_t now;
1464 
1465  dir = calloc(1, sizeof(IsoDir));
1466  if (dir == NULL) {
1467  return ISO_OUT_OF_MEM;
1468  }
1469  dir->node.refcount = 1;
1470  dir->node.type = LIBISO_DIR;
1471  iso_nowtime(&now, 0);
1472  dir->node.atime = dir->node.ctime = dir->node.mtime = now;
1473  dir->node.mode = S_IFDIR | 0555;
1474 
1475  /* set parent to itself, to prevent root to be added to another dir */
1476  dir->node.parent = dir;
1477  *root = dir;
1478  return ISO_SUCCESS;
1479 }
int iso_nowtime(time_t *now, int flag)
Inquire and maybe define the time which is considered to be "now" and used for timestamps of freshly ...
Definition: util.c:2494
IsoNode node
Definition: node.h:141
int refcount
Definition: node.h:108

References Iso_Node::atime, Iso_Node::ctime, iso_nowtime(), ISO_OUT_OF_MEM, ISO_SUCCESS, LIBISO_DIR, Iso_Node::mode, Iso_Node::mtime, Iso_Dir::node, Iso_Node::parent, Iso_Node::refcount, and Iso_Node::type.

Referenced by iso_image_import(), and iso_image_new().

◆ iso_node_new_special()

int iso_node_new_special ( char *  name,
mode_t  mode,
dev_t  dev,
IsoSpecial **  special 
)

Create a new special file node.

As far as libisofs concerns, an special file is a block device, a character device, a FIFO (named pipe) or a socket. You can choose the specific kind of file you want to add by setting mode properly (see man 2 stat).

Note that special files are only written to image when Rock Ridge extensions are enabled. Moreover, a special file is just a directory entry in the image tree, no data is written beyond that.

Owner and hidden atts are taken from parent. You can modify any of them later.

Parameters
namename for the new special file. It is not strdup() so you shouldn't use this reference when this function returns successfully. NULL is not allowed.
modefile type and permissions for the new node. Note that you can't specify any kind of file here, only special types are allowed. i.e, S_IFSOCK, S_IFBLK, S_IFCHR and S_IFIFO are valid types; S_IFLNK, S_IFREG and S_IFDIR aren't.
devdevice ID, equivalent to the st_rdev field in man 2 stat.
specialplace where to store a pointer to the newly created special file.
Returns
1 on success, < 0 otherwise

Definition at line 1573 of file node.c.

1575 {
1576  IsoSpecial *new;
1577  int ret;
1578 
1579  if (special == NULL || name == NULL) {
1580  return ISO_NULL_POINTER;
1581  }
1582  if (S_ISLNK(mode) || S_ISREG(mode) || S_ISDIR(mode)) {
1583  return ISO_WRONG_ARG_VALUE;
1584  }
1585 
1586  /* check if the name is valid */
1587  ret = iso_node_is_valid_name(name);
1588  if (ret < 0)
1589  return ret;
1590 
1591  new = calloc(1, sizeof(IsoSpecial));
1592  if (new == NULL) {
1593  return ISO_OUT_OF_MEM;
1594  }
1595  new->node.refcount = 1;
1596  new->node.type = LIBISO_SPECIAL;
1597  new->node.name = name;
1598 
1599  new->node.mode = mode;
1600  new->dev = dev;
1601  new->fs_id = 0;
1602  new->st_dev = 0;
1603  new->st_ino = 0;
1604  *special = new;
1605  return ISO_SUCCESS;
1606 }
#define ISO_WRONG_ARG_VALUE
Invalid parameter value (FAILURE,HIGH, -8)
Definition: libisofs.h:8751

References iso_node_is_valid_name(), ISO_NULL_POINTER, ISO_OUT_OF_MEM, ISO_SUCCESS, ISO_WRONG_ARG_VALUE, and LIBISO_SPECIAL.

Referenced by default_create_node(), and iso_tree_add_new_special().

◆ iso_node_new_symlink()

int iso_node_new_symlink ( char *  name,
char *  dest,
IsoSymlink **  link 
)

Creates a new IsoSymlink node.

Attributes, uid/gid, timestamps, etc are set to default (0) values. You must set them.

Parameters
namename for the new symlink. It is not strdup() so you shouldn't use this reference when this function returns successfully. NULL is not allowed.
destdestination of the link. It is not strdup() so you shouldn't use this reference when this function returns successfully. NULL is not allowed.
linkplace where to store a pointer to the newly created link.
Returns
1 on success, < 0 otherwise

Definition at line 1538 of file node.c.

1539 {
1540  IsoSymlink *new;
1541  int ret;
1542 
1543  if (link == NULL || name == NULL || dest == NULL) {
1544  return ISO_NULL_POINTER;
1545  }
1546 
1547  /* check if the name is valid */
1548  ret = iso_node_is_valid_name(name);
1549  if (ret < 0)
1550  return ret;
1551 
1552  /* check if destination is valid */
1553  ret = iso_node_is_valid_link_dest(dest);
1554  if (ret < 0)
1555  return ret;
1556 
1557  new = calloc(1, sizeof(IsoSymlink));
1558  if (new == NULL) {
1559  return ISO_OUT_OF_MEM;
1560  }
1561  new->node.refcount = 1;
1562  new->node.type = LIBISO_SYMLINK;
1563  new->node.name = name;
1564  new->dest = dest;
1565  new->node.mode = S_IFLNK;
1566  new->fs_id = 0;
1567  new->st_dev = 0;
1568  new->st_ino = 0;
1569  *link = new;
1570  return ISO_SUCCESS;
1571 }
int iso_node_is_valid_link_dest(const char *dest)
Check if a given path is valid for the destination of a link.
Definition: node.c:1283

References iso_node_is_valid_link_dest(), iso_node_is_valid_name(), ISO_NULL_POINTER, ISO_OUT_OF_MEM, ISO_SUCCESS, and LIBISO_SYMLINK.

Referenced by default_create_node(), and iso_tree_add_new_symlink().

◆ iso_node_set_ino()

int iso_node_set_ino ( IsoNode node,
ino_t  ino,
int  flag 
)

Definition at line 2672 of file node.c.

2673 {
2674  int ret;
2675  IsoFile *file;
2676  IsoSymlink *symlink;
2677  IsoSpecial *special;
2678  void *xipt;
2679 
2680  ret = iso_node_get_xinfo(node, iso_px_ino_xinfo_func, &xipt);
2681  if (ret < 0)
2682  return ret;
2683  if (ret == 1) {
2684  ret = iso_node_set_ino_xinfo(node, ino, 1);
2685  if (ret < 0)
2686  return ret;
2687  return 2;
2688  }
2689  if (node->type == LIBISO_FILE) {
2690  file= (IsoFile *) node;
2691  ret = iso_stream_set_image_ino(file->stream, ino, 0);
2692  if (ret < 0 || ret == 1)
2693  return ret;
2694  /* ret == 0 means that the stream is not from loaded ISO image */
2695 
2696  } else if (node->type == LIBISO_SYMLINK) {
2697  symlink = (IsoSymlink *) node;
2698  if (symlink->fs_id == ISO_IMAGE_FS_ID) {
2699  symlink->st_ino = ino;
2700  return 1;
2701  }
2702 
2703  } else if (node->type == LIBISO_SPECIAL) {
2704  special = (IsoSpecial *) node;
2705  if (special->fs_id == ISO_IMAGE_FS_ID) {
2706  special->st_ino = ino;
2707  return 1;
2708  }
2709 
2710  }
2711  ret = iso_node_set_ino_xinfo(node, ino, 0);
2712  if (ret < 0)
2713  return ret;
2714  return 2;
2715 }
static int iso_node_set_ino_xinfo(IsoNode *node, ino_t ino, int flag)
Definition: node.c:2654
int iso_stream_set_image_ino(IsoStream *stream, ino_t ino, int flag)
Set the inode number of a stream that is based on FSrcStreamData, i.e.
Definition: stream.c:923

References Iso_Symlink::fs_id, Iso_Special::fs_id, ISO_IMAGE_FS_ID, iso_node_get_xinfo(), iso_node_set_ino_xinfo(), iso_px_ino_xinfo_func(), iso_stream_set_image_ino(), LIBISO_FILE, LIBISO_SPECIAL, LIBISO_SYMLINK, Iso_Symlink::st_ino, Iso_Special::st_ino, Iso_File::stream, and Iso_Node::type.

Referenced by image_builder_create_node(), iso_image_import(), and iso_node_set_unique_id().

◆ iso_node_set_perms_internal()

int iso_node_set_perms_internal ( IsoNode node,
mode_t  mode,
int  flag 
)

See API function iso_node_set_permissions()

Parameters
flagbit0= do not adjust ACL
Returns
>0 success , <0 error

Definition at line 430 of file node.c.

431 {
432  int ret;
433 
434  node->mode = (node->mode & S_IFMT) | (mode & ~S_IFMT);
435 
436  /* If the node has ACL info : update ACL */
437  ret = 1;
438  if (!(flag & 1))
439  ret = iso_node_set_acl_text(node, "", "", 2);
440 
441  return ret;
442 }
int iso_node_set_acl_text(IsoNode *node, char *access_text, char *default_text, int flag)
Set the ACLs of the given node to the lists in parameters access_text and default_text or delete them...
Definition: node.c:2205

References iso_node_set_acl_text(), and Iso_Node::mode.

Referenced by default_create_node(), iso_node_set_acl_text(), and iso_node_set_permissions().

◆ iso_node_set_unique_id()

int iso_node_set_unique_id ( IsoNode node,
IsoImage image,
int  flag 
)

Definition at line 2718 of file node.c.

2719 {
2720  int ret;
2721  ino_t ino;
2722 
2723  ino = img_give_ino_number(image, 0);
2724  ret = iso_node_set_ino(node, ino, 0);
2725  return ret;
2726 }
uint32_t img_give_ino_number(IsoImage *image, int flag)
A global counter for Rock Ridge inode numbers in the ISO image filesystem.
Definition: image.c:713
int iso_node_set_ino(IsoNode *node, ino_t ino, int flag)
Definition: node.c:2672

References img_give_ino_number(), and iso_node_set_ino().

Referenced by img_update_ino().

◆ iso_notify_dir_iters()

void iso_notify_dir_iters ( IsoNode node,
int  flag 
)

Definition at line 1448 of file node.c.

1449 {
1450  struct iter_reg_node *pos = iter_reg;
1451  while (pos != NULL) {
1452  IsoDirIter *iter = pos->iter;
1453  if (iter->dir == node->parent) {
1454  iter->class->notify_child_taken(iter, node);
1455  }
1456  pos = pos->next;
1457  }
1458 }
An iterator for directory children.
Definition: node.h:222
struct iso_dir_iter_iface * class
Definition: node.h:223
IsoDir * dir
Definition: node.h:226
void(* notify_child_taken)(IsoDirIter *iter, IsoNode *node)
This is called just before remove a node from a directory.
Definition: node.h:215

References Iso_Dir_Iter::class, Iso_Dir_Iter::dir, iter_reg_node::iter, iter_reg, iter_reg_node::next, iso_dir_iter_iface::notify_child_taken, and Iso_Node::parent.

Referenced by iso_node_take().

◆ iso_px_ino_xinfo_cloner()

int iso_px_ino_xinfo_cloner ( void *  old_data,
void **  new_data,
int  flag 
)

Definition at line 2571 of file node.c.

2572 {
2573  *new_data = NULL;
2574  if (flag)
2575  return ISO_XINFO_NO_CLONE;
2576  *new_data = calloc(1, sizeof(ino_t));
2577  if (*new_data == NULL)
2578  return ISO_OUT_OF_MEM;
2579  memcpy(*new_data, old_data, sizeof(ino_t));
2580  return (int) sizeof(ino_t);
2581 }

References ISO_OUT_OF_MEM, and ISO_XINFO_NO_CLONE.

Referenced by iso_init_with_flag().

◆ iso_px_ino_xinfo_func()

int iso_px_ino_xinfo_func ( void *  data,
int  flag 
)

The iso_node_xinfo_func instance which governs the storing of the inode number from Rock Ridge field PX.

Definition at line 2559 of file node.c.

2560 {
2561  if (flag == 1) {
2562  free(data);
2563  }
2564  return 1;
2565 }

Referenced by iso_init_with_flag(), iso_node_get_id(), iso_node_set_ino(), and iso_node_set_ino_xinfo().

◆ iso_root_get_isofsca()

int iso_root_get_isofsca ( IsoNode node,
uint32_t *  start_lba,
uint32_t *  end_lba,
uint32_t *  count,
uint32_t *  size,
char  typetext[81],
int  flag 
)

Get the checksum area description.

node should be the root node. It is encoded as xattr "isofs.ca".

Definition at line 2941 of file node.c.

2944 {
2945  int ret, len;
2946  size_t value_len;
2947  char *value = NULL, *rpt;
2948 
2949  ret = iso_node_lookup_attr(node, "isofs.ca", &value_len, &value, 0);
2950  if (ret <= 0)
2951  goto ex;
2952 
2953  /* Parse value of isofs.ca with
2954  4 byte START, 4 byte END, 4 byte COUNT, SIZE = 16, MD5 */
2955  rpt = value;
2956  iso_util_decode_len_bytes(start_lba, rpt, &len,
2957  value_len - (rpt - value), 0);
2958  rpt += len + 1;
2959  iso_util_decode_len_bytes(end_lba, rpt, &len,
2960  value_len - (rpt - value), 0);
2961  rpt += len + 1;
2962  iso_util_decode_len_bytes(count, rpt, &len,
2963  value_len - (rpt - value), 0);
2964  rpt += len + 1;
2965  iso_util_decode_len_bytes(size, rpt, &len,
2966  value_len - (rpt - value), 0);
2967  rpt += len + 1;
2968  len = value_len - (rpt - value);
2969  if (len > 80)
2970  len = 80;
2971  memcpy(typetext, rpt, len);
2972  typetext[len] = 0;
2973 
2974  ret= ISO_SUCCESS;
2975 ex:;
2976  if (value != NULL)
2977  free(value);
2978  return ret;
2979 }
int iso_node_lookup_attr(IsoNode *node, char *name, size_t *value_length, char **value, int flag)
Obtain the value of a particular xattr name.
Definition: node.c:1757
int iso_util_decode_len_bytes(uint32_t *data, char *buffer, int *data_len, int buffer_len, int flag)
Decode an integer as LEN,BYTES for being a component in certain AAIP attribute values.
Definition: util.c:2069

References iso_node_lookup_attr(), ISO_SUCCESS, and iso_util_decode_len_bytes().

Referenced by iso_image_import().

◆ iso_root_get_isofsnt()

int iso_root_get_isofsnt ( IsoNode node,
uint32_t *  truncate_mode,
uint32_t *  truncate_length,
int  flag 
)

Definition at line 3001 of file node.c.

3003 {
3004  int ret, len;
3005  size_t value_len;
3006  char *value = NULL, *rpt;
3007 
3008  ret = iso_node_lookup_attr(node, "isofs.nt", &value_len, &value, 0);
3009  if (ret <= 0)
3010  goto ex;
3011 
3012  rpt = value;
3013  iso_util_decode_len_bytes(truncate_mode, rpt, &len,
3014  value_len - (rpt - value), 0);
3015  rpt += len + 1;
3016  iso_util_decode_len_bytes(truncate_length, rpt, &len,
3017  value_len - (rpt - value), 0);
3018  ret= ISO_SUCCESS;
3019 ex:;
3020  if (value != NULL)
3021  free(value);
3022  return ret;
3023 }

References iso_node_lookup_attr(), ISO_SUCCESS, and iso_util_decode_len_bytes().

Referenced by iso_image_import().

◆ iso_root_set_isofsca()

int iso_root_set_isofsca ( IsoNode node,
uint32_t  start_lba,
uint32_t  end_lba,
uint32_t  count,
uint32_t  size,
char *  typetext,
int  flag 
)

Set the checksum area description.

node should be the root node. It is encoded as xattr "isofs.ca".

Definition at line 2910 of file node.c.

2913 {
2914  char buffer[5 + 5 + 5 + 2 + 81], *wpt = buffer, *valuept = buffer;
2915  int result_len, ret;
2916  static char *names = "isofs.ca";
2917  static size_t value_lengths[1];
2918 
2919  /* Set value of isofs.ca with
2920  4 byte START, 4 byte END, 4 byte COUNT, SIZE = 16, MD5 */
2921  iso_util_encode_len_bytes(start_lba, wpt, 4, &result_len, 0);
2922  wpt += result_len;
2923  iso_util_encode_len_bytes(end_lba, wpt, 4, &result_len, 0);
2924  wpt += result_len;
2925  iso_util_encode_len_bytes(count, wpt, 4, &result_len, 0);
2926  wpt += result_len;
2927  iso_util_encode_len_bytes(size, wpt, 1, &result_len, 0);
2928  wpt += result_len;
2929  strncpy(wpt, typetext, 80);
2930  if (strlen(typetext) > 80)
2931  wpt += 80;
2932  else
2933  wpt += strlen(typetext);
2934  value_lengths[0] = wpt - buffer;
2935  ret = iso_node_set_attrs(node, (size_t) 1,
2936  &names, value_lengths, &valuept, 2 | 8);
2937  return ret;
2938 }
int iso_util_encode_len_bytes(uint32_t data, char *buffer, int data_len, int *result_len, int flag)
Encode an integer as LEN,BYTES for being a component in certain AAIP attribute values.
Definition: util.c:2045

References iso_node_set_attrs(), and iso_util_encode_len_bytes().

Referenced by checksum_prepare_image(), checksum_writer_compute_data_blocks(), and ecma119_writer_write_dirs().

◆ iso_root_set_isofsnt()

int iso_root_set_isofsnt ( IsoNode node,
uint32_t  truncate_mode,
uint32_t  truncate_length,
int  flag 
)

Record and get truncation parameters as of iso_image_set_truncate_mode() by "isofs.nt".

Definition at line 2982 of file node.c.

2984 {
2985  char buffer[5 + 5], *wpt = buffer, *valuept = buffer;
2986  int result_len, ret;
2987  static char *names = "isofs.nt";
2988  static size_t value_lengths[1];
2989 
2990  iso_util_encode_len_bytes(truncate_mode, wpt, 0, &result_len, 0);
2991  wpt += result_len;
2992  iso_util_encode_len_bytes(truncate_length, wpt, 0, &result_len, 0);
2993  wpt += result_len;
2994  value_lengths[0] = wpt - buffer;
2995  ret = iso_node_set_attrs(node, (size_t) 1,
2996  &names, value_lengths, &valuept, 2 | 8);
2997  return ret;
2998 }

References iso_node_set_attrs(), and iso_util_encode_len_bytes().

Referenced by ecma119_image_new().

◆ zisofs_zf_xinfo_cloner()

int zisofs_zf_xinfo_cloner ( void *  old_data,
void **  new_data,
int  flag 
)

Definition at line 2423 of file node.c.

2424 {
2425  *new_data = NULL;
2426  if (flag)
2427  return ISO_XINFO_NO_CLONE;
2428  if (old_data == NULL)
2429  return 0;
2430  *new_data = calloc(1, sizeof(struct zisofs_zf_info));
2431  if (*new_data == NULL)
2432  return ISO_OUT_OF_MEM;
2433  memcpy(*new_data, old_data, sizeof(struct zisofs_zf_info));
2434  return (int) sizeof(struct zisofs_zf_info);
2435 }

References ISO_OUT_OF_MEM, and ISO_XINFO_NO_CLONE.

Referenced by iso_init_with_flag().

◆ zisofs_zf_xinfo_func()

int zisofs_zf_xinfo_func ( void *  data,
int  flag 
)

Function to identify and manage ZF parameters which do not stem from ZF fields (those are known to the FileSource) and do not stem from filters ("ziso" knows them globally, "osiz" knows them individually) but rather from an inspection of the file content header for zisofs magic number and plausible parameters.

The parameters get attached in struct zisofs_zf_info as xinfo to an IsoNode.

Definition at line 2411 of file node.c.

2412 {
2413  if (flag & 1) {
2414  free(data);
2415  }
2416  return 1;
2417 }

Referenced by add_zf_field(), iso_file_zf_by_magic(), iso_init_with_flag(), and iso_node_zf_by_magic().