Back to index

php5  5.3.10
Defines | Functions | Variables
cdf.c File Reference
#include "file.h"
#include <assert.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <time.h>
#include <ctype.h>
#include "cdf.h"

Go to the source code of this file.

Defines

#define UINT32_MAX   (0xffffffff)
#define EFTYPE   EINVAL
#define __arraycount(a)   (sizeof(a) / sizeof(a[0]))
#define DPRINTF(a)
#define NEED_SWAP   (cdf_bo.u == (uint32_t)0x01020304)
#define CDF_TOLE8(x)   (NEED_SWAP ? cdf_tole8(x) : (uint64_t)(x))
#define CDF_TOLE4(x)   (NEED_SWAP ? cdf_tole4(x) : (uint32_t)(x))
#define CDF_TOLE2(x)   (NEED_SWAP ? cdf_tole2(x) : (uint16_t)(x))
#define CDF_UNPACK(a)   (void)memcpy(&(a), &buf[len], sizeof(a)), len += sizeof(a)
#define CDF_UNPACKA(a)   (void)memcpy((a), &buf[len], sizeof(a)), len += sizeof(a)
#define CDF_SEC_LIMIT   (UINT32_MAX / (4 * ss))
#define CDF_SHLEN_LIMIT   (UINT32_MAX / 8)
#define CDF_PROP_LIMIT   (UINT32_MAX / (4 * sizeof(*inp)))

Functions

uint16_t cdf_tole2 (uint16_t sv)
uint32_t cdf_tole4 (uint32_t sv)
uint64_t cdf_tole8 (uint64_t sv)
void cdf_swap_header (cdf_header_t *h)
void cdf_unpack_header (cdf_header_t *h, char *buf)
void cdf_swap_dir (cdf_directory_t *d)
void cdf_swap_class (cdf_classid_t *d)
void cdf_unpack_dir (cdf_directory_t *d, char *buf)
static int cdf_check_stream_offset (const cdf_stream_t *sst, const void *p, size_t tail)
static ssize_t cdf_read (const cdf_info_t *info, off_t off, void *buf, size_t len)
int cdf_read_header (const cdf_info_t *info, cdf_header_t *h)
ssize_t cdf_read_sector (const cdf_info_t *info, void *buf, size_t offs, size_t len, const cdf_header_t *h, cdf_secid_t id)
ssize_t cdf_read_short_sector (const cdf_stream_t *sst, void *buf, size_t offs, size_t len, const cdf_header_t *h, cdf_secid_t id)
int cdf_read_sat (const cdf_info_t *info, cdf_header_t *h, cdf_sat_t *sat)
size_t cdf_count_chain (const cdf_sat_t *sat, cdf_secid_t sid, size_t size)
int cdf_read_long_sector_chain (const cdf_info_t *info, const cdf_header_t *h, const cdf_sat_t *sat, cdf_secid_t sid, size_t len, cdf_stream_t *scn)
int cdf_read_short_sector_chain (const cdf_header_t *h, const cdf_sat_t *ssat, const cdf_stream_t *sst, cdf_secid_t sid, size_t len, cdf_stream_t *scn)
int cdf_read_sector_chain (const cdf_info_t *info, const cdf_header_t *h, const cdf_sat_t *sat, const cdf_sat_t *ssat, const cdf_stream_t *sst, cdf_secid_t sid, size_t len, cdf_stream_t *scn)
int cdf_read_dir (const cdf_info_t *info, const cdf_header_t *h, const cdf_sat_t *sat, cdf_dir_t *dir)
int cdf_read_ssat (const cdf_info_t *info, const cdf_header_t *h, const cdf_sat_t *sat, cdf_sat_t *ssat)
int cdf_read_short_stream (const cdf_info_t *info, const cdf_header_t *h, const cdf_sat_t *sat, const cdf_dir_t *dir, cdf_stream_t *scn)
static int cdf_namecmp (const char *d, const uint16_t *s, size_t l)
int cdf_read_summary_info (const cdf_info_t *info, const cdf_header_t *h, const cdf_sat_t *sat, const cdf_sat_t *ssat, const cdf_stream_t *sst, const cdf_dir_t *dir, cdf_stream_t *scn)
int cdf_read_property_info (const cdf_stream_t *sst, uint32_t offs, cdf_property_info_t **info, size_t *count, size_t *maxcount)
int cdf_unpack_summary_info (const cdf_stream_t *sst, cdf_summary_info_header_t *ssi, cdf_property_info_t **info, size_t *count)
int cdf_print_classid (char *buf, size_t buflen, const cdf_classid_t *id)
int cdf_print_property_name (char *buf, size_t bufsiz, uint32_t p)
int cdf_print_elapsed_time (char *buf, size_t bufsiz, cdf_timestamp_t ts)

Variables

union {
char s [4]
uint32_t u
cdf_bo
struct {
uint32_t v
const char * n
vn []

Define Documentation

#define __arraycount (   a)    (sizeof(a) / sizeof(a[0]))

Definition at line 65 of file cdf.c.

#define CDF_PROP_LIMIT   (UINT32_MAX / (4 * sizeof(*inp)))
#define CDF_SEC_LIMIT   (UINT32_MAX / (4 * ss))
#define CDF_SHLEN_LIMIT   (UINT32_MAX / 8)
#define CDF_TOLE2 (   x)    (NEED_SWAP ? cdf_tole2(x) : (uint16_t)(x))

Definition at line 83 of file cdf.c.

#define CDF_TOLE4 (   x)    (NEED_SWAP ? cdf_tole4(x) : (uint32_t)(x))

Definition at line 82 of file cdf.c.

#define CDF_TOLE8 (   x)    (NEED_SWAP ? cdf_tole8(x) : (uint64_t)(x))

Definition at line 81 of file cdf.c.

#define CDF_UNPACK (   a)    (void)memcpy(&(a), &buf[len], sizeof(a)), len += sizeof(a)

Definition at line 135 of file cdf.c.

#define CDF_UNPACKA (   a)    (void)memcpy((a), &buf[len], sizeof(a)), len += sizeof(a)

Definition at line 137 of file cdf.c.

#define DPRINTF (   a)

Definition at line 71 of file cdf.c.

#define EFTYPE   EINVAL

Definition at line 59 of file cdf.c.

#define NEED_SWAP   (cdf_bo.u == (uint32_t)0x01020304)

Definition at line 79 of file cdf.c.

#define UINT32_MAX   (0xffffffff)

Definition at line 51 of file cdf.c.


Function Documentation

static int cdf_check_stream_offset ( const cdf_stream_t sst,
const void *  p,
size_t  tail 
) [static]

Definition at line 241 of file cdf.c.

{
       const char *b = (const char *)sst->sst_tab;
       const char *e = ((const char *)p) + tail;
       if (e >= b && (size_t)(e - b) < sst->sst_dirlen * sst->sst_len)
              return 0;
       DPRINTF((stderr, "offset begin %p end %p %zu >= %zu\n", b, e,
           (size_t)(e - b), sst->sst_dirlen * sst->sst_len));
       errno = EFTYPE;
       return -1;
}

Here is the caller graph for this function:

size_t cdf_count_chain ( const cdf_sat_t sat,
cdf_secid_t  sid,
size_t  size 
)

Definition at line 417 of file cdf.c.

{
       size_t i, j;
       cdf_secid_t maxsector = (cdf_secid_t)(sat->sat_len * size);

       DPRINTF(("Chain:"));
       for (j = i = 0; sid >= 0; i++, j++) {
              DPRINTF((" %d", sid));
              if (j >= CDF_LOOP_LIMIT) {
                     DPRINTF(("Counting chain loop limit"));
                     errno = EFTYPE;
                     return (size_t)-1;
              }
              if (sid > maxsector) {
                     DPRINTF(("Sector %d > %d\n", sid, maxsector));
                     errno = EFTYPE;
                     return (size_t)-1;
              }
              sid = CDF_TOLE4(sat->sat_tab[sid]);
       }
       DPRINTF(("\n"));
       return i;
}

Here is the caller graph for this function:

static int cdf_namecmp ( const char *  d,
const uint16_t s,
size_t  l 
) [static]

Definition at line 664 of file cdf.c.

{
       for (; l--; d++, s++)
              if (*d != CDF_TOLE2(*s))
                     return (unsigned char)*d - CDF_TOLE2(*s);
       return 0;
}

Here is the caller graph for this function:

int cdf_print_classid ( char *  buf,
size_t  buflen,
const cdf_classid_t id 
)

Definition at line 890 of file cdf.c.

{
       return snprintf(buf, buflen, "%.8x-%.4x-%.4x-%.2x%.2x-"
           "%.2x%.2x%.2x%.2x%.2x%.2x", id->cl_dword, id->cl_word[0],
           id->cl_word[1], id->cl_two[0], id->cl_two[1], id->cl_six[0],
           id->cl_six[1], id->cl_six[2], id->cl_six[3], id->cl_six[4],
           id->cl_six[5]);
}
int cdf_print_elapsed_time ( char *  buf,
size_t  bufsiz,
cdf_timestamp_t  ts 
)

Definition at line 937 of file cdf.c.

{
       size_t len = 0;
       int days, hours, mins, secs;

       ts /= CDF_TIME_PREC;
       secs = ts % 60;
       ts /= 60;
       mins = ts % 60;
       ts /= 60;
       hours = ts % 24;
       ts /= 24;
       days = ts;

       if (days) {
              len += snprintf(buf + len, bufsiz - len, "%dd+", days);
              if (len >= bufsiz)
                     return len;
       }

       if (days || hours) {
              len += snprintf(buf + len, bufsiz - len, "%.2d:", hours);
              if (len >= bufsiz)
                     return len;
       }

       len += snprintf(buf + len, bufsiz - len, "%.2d:", mins);
       if (len >= bufsiz)
              return len;

       len += snprintf(buf + len, bufsiz - len, "%.2d", secs);
       return len;
}

Here is the caller graph for this function:

int cdf_print_property_name ( char *  buf,
size_t  bufsiz,
uint32_t  p 
)

Definition at line 926 of file cdf.c.

{
       size_t i;

       for (i = 0; i < __arraycount(vn); i++)
              if (vn[i].v == p)
                     return snprintf(buf, bufsiz, "%s", vn[i].n);
       return snprintf(buf, bufsiz, "0x%x", p);
}

Here is the caller graph for this function:

static ssize_t cdf_read ( const cdf_info_t info,
off_t  off,
void *  buf,
size_t  len 
) [static]

Definition at line 254 of file cdf.c.

{
       size_t siz = (size_t)off + len;

       if ((off_t)(off + len) != (off_t)siz) {
              errno = EINVAL;
              return -1;
       }

       if (info->i_buf != NULL && info->i_len >= siz) {
              (void)memcpy(buf, &info->i_buf[off], len);
              return (ssize_t)len;
       }

       if (info->i_fd == -1)
              return -1;

       if (lseek(info->i_fd, off, SEEK_SET) == (off_t)-1)
              return -1;

       if (read(info->i_fd, buf, len) != (ssize_t)len)
              return -1;

       return (ssize_t)len;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int cdf_read_dir ( const cdf_info_t info,
const cdf_header_t h,
const cdf_sat_t sat,
cdf_dir_t dir 
)

Definition at line 541 of file cdf.c.

{
       size_t i, j;
       size_t ss = CDF_SEC_SIZE(h), ns, nd;
       char *buf;
       cdf_secid_t sid = h->h_secid_first_directory;

       ns = cdf_count_chain(sat, sid, ss);
       if (ns == (size_t)-1)
              return -1;

       nd = ss / CDF_DIRECTORY_SIZE;

       dir->dir_len = ns * nd;
       dir->dir_tab = calloc(dir->dir_len, sizeof(dir->dir_tab[0]));
       if (dir->dir_tab == NULL)
              return -1;

       if ((buf = malloc(ss)) == NULL) {
              free(dir->dir_tab);
              return -1;
       }

       for (j = i = 0; i < ns; i++, j++) {
              if (j >= CDF_LOOP_LIMIT) {
                     DPRINTF(("Read dir loop limit"));
                     errno = EFTYPE;
                     goto out;
              }
              if (cdf_read_sector(info, buf, 0, ss, h, sid) != (ssize_t)ss) {
                     DPRINTF(("Reading directory sector %d", sid));
                     goto out;
              }
              for (j = 0; j < nd; j++) {
                     cdf_unpack_dir(&dir->dir_tab[i * nd + j],
                         &buf[j * CDF_DIRECTORY_SIZE]);
              }
              sid = CDF_TOLE4(sat->sat_tab[sid]);
       }
       if (NEED_SWAP)
              for (i = 0; i < dir->dir_len; i++)
                     cdf_swap_dir(&dir->dir_tab[i]);
       free(buf);
       return 0;
out:
       free(dir->dir_tab);
       free(buf);
       return -1;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int cdf_read_header ( const cdf_info_t info,
cdf_header_t h 
)

Definition at line 281 of file cdf.c.

{
       char buf[512];

       (void)memcpy(cdf_bo.s, "\01\02\03\04", 4);
       if (cdf_read(info, (off_t)0, buf, sizeof(buf)) == -1)
              return -1;
       cdf_unpack_header(h, buf);
       cdf_swap_header(h);
       if (h->h_magic != CDF_MAGIC) {
              DPRINTF(("Bad magic 0x%llx != 0x%llx\n",
                  (unsigned long long)h->h_magic,
                  (unsigned long long)CDF_MAGIC));
              goto out;
       }
       if (h->h_sec_size_p2 > 20) {
              DPRINTF(("Bad sector size 0x%u\n", h->h_sec_size_p2));
              goto out;
       }
       if (h->h_short_sec_size_p2 > 20) {
              DPRINTF(("Bad short sector size 0x%u\n",
                  h->h_short_sec_size_p2));
              goto out;
       }
       return 0;
out:
       errno = EFTYPE;
       return -1;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int cdf_read_long_sector_chain ( const cdf_info_t info,
const cdf_header_t h,
const cdf_sat_t sat,
cdf_secid_t  sid,
size_t  len,
cdf_stream_t scn 
)

Definition at line 442 of file cdf.c.

{
       size_t ss = CDF_SEC_SIZE(h), i, j;
       ssize_t nr;
       scn->sst_len = cdf_count_chain(sat, sid, ss);
       scn->sst_dirlen = len;

       if (scn->sst_len == (size_t)-1)
              return -1;

       scn->sst_tab = calloc(scn->sst_len, ss);
       if (scn->sst_tab == NULL)
              return -1;

       for (j = i = 0; sid >= 0; i++, j++) {
              if (j >= CDF_LOOP_LIMIT) {
                     DPRINTF(("Read long sector chain loop limit"));
                     errno = EFTYPE;
                     goto out;
              }
              if (i >= scn->sst_len) {
                     DPRINTF(("Out of bounds reading long sector chain "
                         "%u > %u\n", i, scn->sst_len));
                     errno = EFTYPE;
                     goto out;
              }
              if ((nr = cdf_read_sector(info, scn->sst_tab, i * ss, ss, h,
                  sid)) != (ssize_t)ss) {
                     if (i == scn->sst_len - 1 && nr > 0) {
                            /* Last sector might be truncated */
                            return 0;
                     }
                     DPRINTF(("Reading long sector chain %d", sid));
                     goto out;
              }
              sid = CDF_TOLE4(sat->sat_tab[sid]);
       }
       return 0;
out:
       free(scn->sst_tab);
       return -1;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int cdf_read_property_info ( const cdf_stream_t sst,
uint32_t  offs,
cdf_property_info_t **  info,
size_t count,
size_t maxcount 
)

Definition at line 698 of file cdf.c.

{
       const cdf_section_header_t *shp;
       cdf_section_header_t sh;
       const uint32_t *p, *q, *e;
       int16_t s16;
       int32_t s32;
       uint32_t u32;
       int64_t s64;
       uint64_t u64;
       cdf_timestamp_t tp;
       size_t i, o, nelements, j;
       cdf_property_info_t *inp;

       if (offs > UINT32_MAX / 4) {
              errno = EFTYPE;
              goto out;
       }
       shp = (const void *)((const char *)sst->sst_tab + offs);
       if (cdf_check_stream_offset(sst, shp, sizeof(*shp)) == -1)
              goto out;
       sh.sh_len = CDF_TOLE4(shp->sh_len);
#define CDF_SHLEN_LIMIT (UINT32_MAX / 8)
       if (sh.sh_len > CDF_SHLEN_LIMIT) {
              errno = EFTYPE;
              goto out;
       }
       sh.sh_properties = CDF_TOLE4(shp->sh_properties);
#define CDF_PROP_LIMIT (UINT32_MAX / (4 * sizeof(*inp)))
       if (sh.sh_properties > CDF_PROP_LIMIT)
              goto out;
       DPRINTF(("section len: %u properties %u\n", sh.sh_len,
           sh.sh_properties));
       if (*maxcount) {
              if (*maxcount > CDF_PROP_LIMIT)
                     goto out;
              *maxcount += sh.sh_properties;
              inp = realloc(*info, *maxcount * sizeof(*inp));
       } else {
              *maxcount = sh.sh_properties;
              inp = malloc(*maxcount * sizeof(*inp));
       }
       if (inp == NULL)
              goto out;
       *info = inp;
       inp += *count;
       *count += sh.sh_properties;
       p = (const void *)((const char *)sst->sst_tab + offs + sizeof(sh));
       e = (const void *)(((const char *)shp) + sh.sh_len);
       if (cdf_check_stream_offset(sst, e, 0) == -1)
              goto out;
       for (i = 0; i < sh.sh_properties; i++) {
              q = (const uint32_t *)((const char *)p +
                  CDF_TOLE4(p[(i << 1) + 1])) - 2;
              if (q > e) {
                     DPRINTF(("Ran of the end %p > %p\n", q, e));
                     goto out;
              }
              inp[i].pi_id = CDF_TOLE4(p[i << 1]);
              inp[i].pi_type = CDF_TOLE4(q[0]);
              DPRINTF(("%d) id=%x type=%x offs=%x\n", i, inp[i].pi_id,
                  inp[i].pi_type, (const char *)q - (const char *)p));
              if (inp[i].pi_type & CDF_VECTOR) {
                     nelements = CDF_TOLE4(q[1]);
                     o = 2;
              } else {
                     nelements = 1;
                     o = 1;
              }
              if (inp[i].pi_type & (CDF_ARRAY|CDF_BYREF|CDF_RESERVED))
                     goto unknown;
              switch (inp[i].pi_type & CDF_TYPEMASK) {
              case CDF_EMPTY:
                     break;
              case CDF_SIGNED16:
                     if (inp[i].pi_type & CDF_VECTOR)
                            goto unknown;
                     (void)memcpy(&s16, &q[o], sizeof(s16));
                     inp[i].pi_s16 = CDF_TOLE2(s16);
                     break;
              case CDF_SIGNED32:
                     if (inp[i].pi_type & CDF_VECTOR)
                            goto unknown;
                     (void)memcpy(&s32, &q[o], sizeof(s32));
                     inp[i].pi_s32 = CDF_TOLE4(s32);
                     break;
              case CDF_BOOL:
              case CDF_UNSIGNED32:
                     if (inp[i].pi_type & CDF_VECTOR)
                            goto unknown;
                     (void)memcpy(&u32, &q[o], sizeof(u32));
                     inp[i].pi_u32 = CDF_TOLE4(u32);
                     break;
              case CDF_SIGNED64:
                     if (inp[i].pi_type & CDF_VECTOR)
                            goto unknown;
                     (void)memcpy(&s64, &q[o], sizeof(s64));
                     inp[i].pi_s64 = CDF_TOLE4(s64);
                     break;
              case CDF_UNSIGNED64:
                     if (inp[i].pi_type & CDF_VECTOR)
                            goto unknown;
                     (void)memcpy(&u64, &q[o], sizeof(u64));
                     inp[i].pi_u64 = CDF_TOLE4(u64);
                     break;
              case CDF_LENGTH32_STRING:
                     if (nelements > 1) {
                            size_t nelem = inp - *info;
                            if (*maxcount > CDF_PROP_LIMIT
                                || nelements > CDF_PROP_LIMIT)
                                   goto out;
                            *maxcount += nelements;
                            inp = realloc(*info, *maxcount * sizeof(*inp));
                            if (inp == NULL)
                                   goto out;
                            *info = inp;
                            inp = *info + nelem;
                     }
                     DPRINTF(("nelements = %d\n", nelements));
                     for (j = 0; j < nelements; j++, i++) {
                            uint32_t l = CDF_TOLE4(q[o]);
                            inp[i].pi_str.s_len = l;
                            inp[i].pi_str.s_buf = (const char *)(&q[o+1]);
                            DPRINTF(("l = %d, r = %d, s = %s\n", l,
                                CDF_ROUND(l, sizeof(l)),
                                inp[i].pi_str.s_buf));
                            l = 4 + CDF_ROUND(l, sizeof(l));
                            o += l >> 2;
                     }
                     i--;
                     break;
              case CDF_FILETIME:
                     if (inp[i].pi_type & CDF_VECTOR)
                            goto unknown;
                     (void)memcpy(&tp, &q[o], sizeof(tp));
                     inp[i].pi_tp = CDF_TOLE8(tp);
                     break;
              case CDF_CLIPBOARD:
                     if (inp[i].pi_type & CDF_VECTOR)
                            goto unknown;
                     break;
              default:
              unknown:
                     DPRINTF(("Don't know how to deal with %x\n",
                         inp[i].pi_type));
                     goto out;
              }
       }
       return 0;
out:
       free(*info);
       return -1;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int cdf_read_sat ( const cdf_info_t info,
cdf_header_t h,
cdf_sat_t sat 
)

Definition at line 335 of file cdf.c.

{
       size_t i, j, k;
       size_t ss = CDF_SEC_SIZE(h);
       cdf_secid_t *msa, mid, sec;
       size_t nsatpersec = (ss / sizeof(mid)) - 1;

       for (i = 0; i < __arraycount(h->h_master_sat); i++)
              if (h->h_master_sat[i] == CDF_SECID_FREE)
                     break;

#define CDF_SEC_LIMIT (UINT32_MAX / (4 * ss))
       if (h->h_num_sectors_in_master_sat > CDF_SEC_LIMIT / nsatpersec ||
           i > CDF_SEC_LIMIT) {
              DPRINTF(("Number of sectors in master SAT too big %u %zu\n",
                  h->h_num_sectors_in_master_sat, i));
              errno = EFTYPE;
              return -1;
       }

       sat->sat_len = h->h_num_sectors_in_master_sat * nsatpersec + i;
       DPRINTF(("sat_len = %zu ss = %zu\n", sat->sat_len, ss));
       if ((sat->sat_tab = calloc(sat->sat_len, ss)) == NULL)
              return -1;

       for (i = 0; i < __arraycount(h->h_master_sat); i++) {
              if (h->h_master_sat[i] < 0)
                     break;
              if (cdf_read_sector(info, sat->sat_tab, ss * i, ss, h,
                  h->h_master_sat[i]) != (ssize_t)ss) {
                     DPRINTF(("Reading sector %d", h->h_master_sat[i]));
                     goto out1;
              }
       }

       if ((msa = calloc(1, ss)) == NULL)
              goto out1;

       mid = h->h_secid_first_sector_in_master_sat;
       for (j = 0; j < h->h_num_sectors_in_master_sat; j++) {
              if (mid < 0)
                     goto out;
              if (j >= CDF_LOOP_LIMIT) {
                     DPRINTF(("Reading master sector loop limit"));
                     errno = EFTYPE;
                     goto out2;
              }
              if (cdf_read_sector(info, msa, 0, ss, h, mid) != (ssize_t)ss) {
                     DPRINTF(("Reading master sector %d", mid));
                     goto out2;
              }
              for (k = 0; k < nsatpersec; k++, i++) {
                     sec = CDF_TOLE4(msa[k]);
                     if (sec < 0)
                            goto out;
                     if (i >= sat->sat_len) {
                         DPRINTF(("Out of bounds reading MSA %u >= %u",
                            i, sat->sat_len));
                         errno = EFTYPE;
                         goto out2;
                     }
                     if (cdf_read_sector(info, sat->sat_tab, ss * i, ss, h,
                         sec) != (ssize_t)ss) {
                            DPRINTF(("Reading sector %d",
                                CDF_TOLE4(msa[k])));
                            goto out2;
                     }
              }
              mid = CDF_TOLE4(msa[nsatpersec]);
       }
out:
       sat->sat_len = i;
       free(msa);
       return 0;
out2:
       free(msa);
out1:
       free(sat->sat_tab);
       return -1;
}

Here is the call graph for this function:

Here is the caller graph for this function:

ssize_t cdf_read_sector ( const cdf_info_t info,
void *  buf,
size_t  offs,
size_t  len,
const cdf_header_t h,
cdf_secid_t  id 
)

Definition at line 313 of file cdf.c.

{
       assert((size_t)CDF_SEC_SIZE(h) == len);
       return cdf_read(info, (off_t)CDF_SEC_POS(h, id),
           ((char *)buf) + offs, len);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int cdf_read_sector_chain ( const cdf_info_t info,
const cdf_header_t h,
const cdf_sat_t sat,
const cdf_sat_t ssat,
const cdf_stream_t sst,
cdf_secid_t  sid,
size_t  len,
cdf_stream_t scn 
)

Definition at line 528 of file cdf.c.

{

       if (len < h->h_min_size_standard_stream)
              return cdf_read_short_sector_chain(h, ssat, sst, sid, len,
                  scn);
       else
              return cdf_read_long_sector_chain(info, h, sat, sid, len, scn);
}

Here is the call graph for this function:

Here is the caller graph for this function:

ssize_t cdf_read_short_sector ( const cdf_stream_t sst,
void *  buf,
size_t  offs,
size_t  len,
const cdf_header_t h,
cdf_secid_t  id 
)

Definition at line 322 of file cdf.c.

{
       assert((size_t)CDF_SHORT_SEC_SIZE(h) == len);
       (void)memcpy(((char *)buf) + offs,
           ((const char *)sst->sst_tab) + CDF_SHORT_SEC_POS(h, id), len);
       return len;
}

Here is the caller graph for this function:

int cdf_read_short_sector_chain ( const cdf_header_t h,
const cdf_sat_t ssat,
const cdf_stream_t sst,
cdf_secid_t  sid,
size_t  len,
cdf_stream_t scn 
)

Definition at line 487 of file cdf.c.

{
       size_t ss = CDF_SHORT_SEC_SIZE(h), i, j;
       scn->sst_len = cdf_count_chain(ssat, sid, CDF_SEC_SIZE(h));
       scn->sst_dirlen = len;

       if (sst->sst_tab == NULL || scn->sst_len == (size_t)-1)
              return -1;

       scn->sst_tab = calloc(scn->sst_len, ss);
       if (scn->sst_tab == NULL)
              return -1;

       for (j = i = 0; sid >= 0; i++, j++) {
              if (j >= CDF_LOOP_LIMIT) {
                     DPRINTF(("Read short sector chain loop limit"));
                     errno = EFTYPE;
                     goto out;
              }
              if (i >= scn->sst_len) {
                     DPRINTF(("Out of bounds reading short sector chain "
                         "%u > %u\n", i, scn->sst_len));
                     errno = EFTYPE;
                     goto out;
              }
              if (cdf_read_short_sector(sst, scn->sst_tab, i * ss, ss, h,
                  sid) != (ssize_t)ss) {
                     DPRINTF(("Reading short sector chain %d", sid));
                     goto out;
              }
              sid = CDF_TOLE4(ssat->sat_tab[sid]);
       }
       return 0;
out:
       free(scn->sst_tab);
       return -1;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int cdf_read_short_stream ( const cdf_info_t info,
const cdf_header_t h,
const cdf_sat_t sat,
const cdf_dir_t dir,
cdf_stream_t scn 
)

Definition at line 635 of file cdf.c.

{
       size_t i;
       const cdf_directory_t *d;

       for (i = 0; i < dir->dir_len; i++)
              if (dir->dir_tab[i].d_type == CDF_DIR_TYPE_ROOT_STORAGE)
                     break;

       /* If the it is not there, just fake it; some docs don't have it */
       if (i == dir->dir_len)
              goto out;
       d = &dir->dir_tab[i];

       /* If the it is not there, just fake it; some docs don't have it */
       if (d->d_stream_first_sector < 0)
              goto out;

       return  cdf_read_long_sector_chain(info, h, sat,
           d->d_stream_first_sector, d->d_size, scn);
out:
       scn->sst_tab = NULL;
       scn->sst_len = 0;
       scn->sst_dirlen = 0;
       return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int cdf_read_ssat ( const cdf_info_t info,
const cdf_header_t h,
const cdf_sat_t sat,
cdf_sat_t ssat 
)

Definition at line 594 of file cdf.c.

{
       size_t i, j;
       size_t ss = CDF_SEC_SIZE(h);
       cdf_secid_t sid = h->h_secid_first_sector_in_short_sat;

       ssat->sat_len = cdf_count_chain(sat, sid, CDF_SEC_SIZE(h));
       if (ssat->sat_len == (size_t)-1)
              return -1;

       ssat->sat_tab = calloc(ssat->sat_len, ss);
       if (ssat->sat_tab == NULL)
              return -1;

       for (j = i = 0; sid >= 0; i++, j++) {
              if (j >= CDF_LOOP_LIMIT) {
                     DPRINTF(("Read short sat sector loop limit"));
                     errno = EFTYPE;
                     goto out;
              }
              if (i >= ssat->sat_len) {
                     DPRINTF(("Out of bounds reading short sector chain "
                         "%u > %u\n", i, ssat->sat_len));
                     errno = EFTYPE;
                     goto out;
              }
              if (cdf_read_sector(info, ssat->sat_tab, i * ss, ss, h, sid) !=
                  (ssize_t)ss) {
                     DPRINTF(("Reading short sat sector %d", sid));
                     goto out;
              }
              sid = CDF_TOLE4(sat->sat_tab[sid]);
       }
       return 0;
out:
       free(ssat->sat_tab);
       return -1;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int cdf_read_summary_info ( const cdf_info_t info,
const cdf_header_t h,
const cdf_sat_t sat,
const cdf_sat_t ssat,
const cdf_stream_t sst,
const cdf_dir_t dir,
cdf_stream_t scn 
)

Definition at line 673 of file cdf.c.

{
       size_t i;
       const cdf_directory_t *d;
       static const char name[] = "\05SummaryInformation";

       for (i = 0; i < dir->dir_len; i++)
              if (dir->dir_tab[i].d_type == CDF_DIR_TYPE_USER_STREAM &&
                  cdf_namecmp(name, dir->dir_tab[i].d_name, sizeof(name))
                  == 0)
                     break;

       if (i == dir->dir_len) {
              DPRINTF(("Cannot find summary information section\n"));
              errno = EFTYPE;
              return -1;
       }
       d = &dir->dir_tab[i];
       return cdf_read_sector_chain(info, h, sat, ssat, sst,
           d->d_stream_first_sector, d->d_size, scn);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 212 of file cdf.c.

{
       d->cl_dword = CDF_TOLE4(d->cl_dword);
       d->cl_word[0] = CDF_TOLE2(d->cl_word[0]);
       d->cl_word[1] = CDF_TOLE2(d->cl_word[1]);
}

Here is the caller graph for this function:

Definition at line 89 of file cdf.c.

{
       uint16_t rv;
       uint8_t *s = (uint8_t *)(void *)&sv; 
       uint8_t *d = (uint8_t *)(void *)&rv; 
       d[0] = s[1];
       d[1] = s[0];
       return rv;
}

Definition at line 103 of file cdf.c.

{
       uint32_t rv;
       uint8_t *s = (uint8_t *)(void *)&sv; 
       uint8_t *d = (uint8_t *)(void *)&rv; 
       d[0] = s[3];
       d[1] = s[2];
       d[2] = s[1];
       d[3] = s[0];
       return rv;
}

Definition at line 119 of file cdf.c.

{
       uint64_t rv;
       uint8_t *s = (uint8_t *)(void *)&sv; 
       uint8_t *d = (uint8_t *)(void *)&rv; 
       d[0] = s[7];
       d[1] = s[6];
       d[2] = s[5];
       d[3] = s[4];
       d[4] = s[3];
       d[5] = s[2];
       d[6] = s[1];
       d[7] = s[0];
       return rv;
}
void cdf_unpack_dir ( cdf_directory_t d,
char *  buf 
)

Definition at line 220 of file cdf.c.

Here is the caller graph for this function:

void cdf_unpack_header ( cdf_header_t h,
char *  buf 
)

Definition at line 854 of file cdf.c.

{
       size_t i, maxcount;
       const cdf_summary_info_header_t *si = sst->sst_tab;
       const cdf_section_declaration_t *sd = (const void *)
           ((const char *)sst->sst_tab + CDF_SECTION_DECLARATION_OFFSET);

       if (cdf_check_stream_offset(sst, si, sizeof(*si)) == -1 ||
           cdf_check_stream_offset(sst, sd, sizeof(*sd)) == -1)
              return -1;
       ssi->si_byte_order = CDF_TOLE2(si->si_byte_order);
       ssi->si_os_version = CDF_TOLE2(si->si_os_version);
       ssi->si_os = CDF_TOLE2(si->si_os);
       ssi->si_class = si->si_class;
       cdf_swap_class(&ssi->si_class);
       ssi->si_count = CDF_TOLE2(si->si_count);
       *count = 0;
       maxcount = 0;
       *info = NULL;
       for (i = 0; i < CDF_TOLE4(si->si_count); i++) {
              if (i >= CDF_LOOP_LIMIT) {
                     DPRINTF(("Unpack summary info loop limit"));
                     errno = EFTYPE;
                     return -1;
              }
              if (cdf_read_property_info(sst, CDF_TOLE4(sd->sd_offset),
                  info, count, &maxcount) == -1)
                     return -1;
       }
       return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

union { ... } cdf_bo [static]
struct { ... } vn[] [static]