ReactOS  0.4.13-dev-79-gcd489d8
cdmake.c File Reference
#include <stdio.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
#include <sys/io.h>
#include <errno.h>
#include <sys/types.h>
#include <dirent.h>
#include <unistd.h>
#include <ctype.h>
#include <time.h>
#include "config.h"
#include "dirhash.h"
Include dependency graph for cdmake.c:

Go to the source code of this file.

Classes

struct  cd_image
 
struct  _boot_validation_header
 
struct  boot_entry
 
struct  boot_header
 
struct  date_and_time
 
struct  directory_record
 

Macros

#define TRUE   1
 
#define FALSE   0
 
#define MAX_LEVEL   8
 
#define MAX_NAME_LENGTH   64
 
#define MAX_CDNAME_LENGTH   8
 
#define MAX_EXTENSION_LENGTH   10
 
#define MAX_CDEXTENSION_LENGTH   3
 
#define SECTOR_SIZE   2048
 
#define BUFFER_SIZE   (8 * SECTOR_SIZE)
 
#define HIDDEN_FLAG   1
 
#define DIRECTORY_FLAG   2
 

Typedefs

typedef unsigned char BYTE
 
typedef unsigned short WORD
 
typedef unsigned long DWORD
 
typedef int BOOL
 
typedef struct _boot_validation_header BOOT_VALIDATION_HEADER
 
typedef struct _boot_validation_headerPBOOT_VALIDATION_HEADER
 
typedef struct boot_entry BOOT_ENTRY
 
typedef struct boot_entryPBOOT_ENTRY
 
typedef struct boot_header BOOT_HEADER
 
typedef struct boot_headerPBOOT_HEADER
 
typedef struct date_and_time DATE_AND_TIME
 
typedef struct date_and_timePDATE_AND_TIME
 
typedef struct directory_record DIR_RECORD
 
typedef struct directory_recordPDIR_RECORD
 
typedef enum directory_record_type DIR_RECORD_TYPE
 
typedef enum directory_record_typePDIR_RECORD_TYPE
 

Enumerations

enum  directory_record_type { DOT_RECORD, DOT_DOT_RECORD, SUBDIRECTORY_RECORD, FILE_RECORD }
 
enum  { QUIET, NORMAL, VERBOSE }
 

Functions

PDIR_RECORD sort_linked_list (PDIR_RECORD, unsigned, int(*)(PDIR_RECORD, PDIR_RECORD))
 
static charedit_with_commas (DWORD x, BOOL pad)
 
static void release_memory (void)
 
static void error_exit (const char *fmt,...)
 
static void flush_buffer (void)
 
static void write_byte (BYTE x)
 
static void write_little_endian_word (WORD x)
 
static void write_big_endian_word (WORD x)
 
static void write_both_endian_word (WORD x)
 
static void write_little_endian_dword (DWORD x)
 
static void write_big_endian_dword (DWORD x)
 
static void write_both_endian_dword (DWORD x)
 
static void fill_sector (void)
 
static void write_string (char *s)
 
static void write_bytecounted_string (unsigned bytecount, char *s, char padding)
 
static void write_string_as_big_endian_unicode (char *s)
 
static void write_bytecounted_string_as_big_endian_unicode (unsigned bytecount, char *s, char padding)
 
static void write_block (unsigned count, BYTE value)
 
static void write_word_block (unsigned count, WORD value)
 
static void write_directory_record (PDIR_RECORD d, DIR_RECORD_TYPE DirType, BOOL joliet)
 
static void convert_date_and_time (PDATE_AND_TIME dt, time_t *time)
 
static int check_for_punctuation (int c, const char *name)
 
static BOOL cdname_exists (PDIR_RECORD d)
 
static void parse_filename_into_dirrecord (const char *filename, PDIR_RECORD d, BOOL dir)
 
PDIR_RECORD new_directory_record (struct dirent *entry, struct stat *stbuf, PDIR_RECORD parent)
 
static int compare_directory_order (PDIR_RECORD p, PDIR_RECORD q)
 
static int compare_path_table_order (PDIR_RECORD p, PDIR_RECORD q)
 
static void append_string_to_source (char *s)
 
static void make_directory_records (PDIR_RECORD d)
 
static PDIR_RECORD new_empty_dirrecord (PDIR_RECORD d, BOOL directory)
 
static void scan_specified_files (PDIR_RECORD d, struct target_dir_entry *dir)
 
static void get_file_specifications (PDIR_RECORD d)
 
static void get_time_string (char *str)
 
static BOOL write_from_file (FILE *file, DWORD size)
 
static void pass (void)
 
charstrtok_s (char *str, const char *delim, char **ctx)
 
static void init_boot_entry (PBOOT_ENTRY boot_entry, BYTE boot_emu_type, WORD load_segment, char *bootimage)
 
int main (int argc, char **argv)
 

Variables

static char DIRECTORY_TIMESTAMP [] = "~Y$'KOR$.3K&"
 
static struct cd_image cd
 
DIR_RECORD root
 
char volume_label [32]
 
char source [512]
 
charend_source
 
enum { ... }  verbosity
 
BOOL show_progress
 
BOOL scan_files_only = FALSE
 
DWORD size_limit
 
BOOL accept_punctuation_marks
 
DWORD total_sectors
 
DWORD path_table_size
 
DWORD little_endian_path_table_sector
 
DWORD big_endian_path_table_sector
 
DWORD number_of_files
 
DWORD bytes_in_files
 
DWORD unused_bytes_at_ends_of_files
 
DWORD number_of_directories
 
DWORD bytes_in_directories
 
struct target_dir_hash specified_files
 
BOOL eltorito
 
BOOL multi_boot
 
DWORD boot_catalog_sector
 
BOOT_VALIDATION_HEADER boot_validation_header
 
BOOT_ENTRY default_boot_entry
 
PBOOT_HEADER boot_header_list
 
BOOL joliet
 
DWORD joliet_path_table_size
 
DWORD joliet_little_endian_path_table_sector
 
DWORD joliet_big_endian_path_table_sector
 
BOOL make_bridged_udf = TRUE
 
static char HELP []
 

Macro Definition Documentation

◆ BUFFER_SIZE

#define BUFFER_SIZE   (8 * SECTOR_SIZE)

Definition at line 89 of file cdmake.c.

◆ DIRECTORY_FLAG

#define DIRECTORY_FLAG   2

Definition at line 92 of file cdmake.c.

◆ FALSE

#define FALSE   0

Definition at line 68 of file cdmake.c.

◆ HIDDEN_FLAG

#define HIDDEN_FLAG   1

Definition at line 91 of file cdmake.c.

◆ MAX_CDEXTENSION_LENGTH

#define MAX_CDEXTENSION_LENGTH   3

Definition at line 87 of file cdmake.c.

◆ MAX_CDNAME_LENGTH

#define MAX_CDNAME_LENGTH   8

Definition at line 85 of file cdmake.c.

◆ MAX_EXTENSION_LENGTH

#define MAX_EXTENSION_LENGTH   10

Definition at line 86 of file cdmake.c.

◆ MAX_LEVEL

#define MAX_LEVEL   8

Definition at line 83 of file cdmake.c.

◆ MAX_NAME_LENGTH

#define MAX_NAME_LENGTH   64

Definition at line 84 of file cdmake.c.

◆ SECTOR_SIZE

#define SECTOR_SIZE   2048

Definition at line 88 of file cdmake.c.

◆ TRUE

#define TRUE   1

Definition at line 67 of file cdmake.c.

Typedef Documentation

◆ BOOL

typedef int BOOL

Definition at line 79 of file cdmake.c.

◆ BOOT_ENTRY

◆ BOOT_HEADER

◆ BOOT_VALIDATION_HEADER

◆ BYTE

typedef unsigned char BYTE

Definition at line 76 of file cdmake.c.

◆ DATE_AND_TIME

◆ DIR_RECORD

◆ DIR_RECORD_TYPE

◆ DWORD

typedef unsigned long DWORD

Definition at line 78 of file cdmake.c.

◆ PBOOT_ENTRY

◆ PBOOT_HEADER

◆ PBOOT_VALIDATION_HEADER

◆ PDATE_AND_TIME

◆ PDIR_RECORD

◆ PDIR_RECORD_TYPE

◆ WORD

typedef unsigned short WORD

Definition at line 77 of file cdmake.c.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
QUIET 
NORMAL 
VERBOSE 

Definition at line 189 of file cdmake.c.

Definition: cdmake.c:189
Definition: cdmake.c:189
enum @1488 verbosity

◆ directory_record_type

Enumerator
DOT_RECORD 
DOT_DOT_RECORD 
SUBDIRECTORY_RECORD 
FILE_RECORD 

Definition at line 167 of file cdmake.c.

168 {
169  DOT_RECORD,
enum directory_record_type DIR_RECORD_TYPE
enum directory_record_type * PDIR_RECORD_TYPE

Function Documentation

◆ append_string_to_source()

static void append_string_to_source ( char s)
static

Definition at line 866 of file cdmake.c.

867 {
868  while (*s != 0)
869  *end_source++ = *s++;
870 }
char * end_source
Definition: cdmake.c:187
GLdouble s
Definition: gl.h:2039

Referenced by get_file_specifications(), and make_directory_records().

◆ cdname_exists()

static BOOL cdname_exists ( PDIR_RECORD  d)
static

Definition at line 654 of file cdmake.c.

655 {
656  PDIR_RECORD p = d->parent->first_record;
657  while (p)
658  {
659  if ( p != d
660  && !strcasecmp(p->name_on_cd, d->name_on_cd)
661  && !strcasecmp(p->extension_on_cd, d->extension_on_cd) )
662  return TRUE;
663  p = p->next_in_directory;
664  }
665  return FALSE;
666 }
#define FALSE
Definition: cdmake.c:68
#define strcasecmp
Definition: fake.h:9
#define d
Definition: ke_i.h:81
#define TRUE
Definition: cdmake.c:67
GLfloat GLfloat p
Definition: glext.h:8902

Referenced by parse_filename_into_dirrecord().

◆ check_for_punctuation()

static int check_for_punctuation ( int  c,
const char name 
)
static

Definition at line 638 of file cdmake.c.

639 {
640  c = toupper(c & 0xFF);
641  if (!accept_punctuation_marks && !isalnum(c) && c != '_')
642  error_exit("Punctuation mark in %s", name);
643  return c;
644 }
static void error_exit(const char *fmt,...)
Definition: cdmake.c:315
_Check_return_ _CRTIMP int __cdecl isalnum(_In_ int _C)
int toupper(int c)
Definition: utclib.c:881
const GLubyte * c
Definition: glext.h:8905
BOOL accept_punctuation_marks
Definition: cdmake.c:199
Definition: name.c:36
#define c
Definition: ke_i.h:80

Referenced by parse_filename_into_dirrecord().

◆ compare_directory_order()

static int compare_directory_order ( PDIR_RECORD  p,
PDIR_RECORD  q 
)
static

Definition at line 834 of file cdmake.c.

835 {
836  int n = strcmp(p->name_on_cd, q->name_on_cd);
837  if (n == 0)
838  n = strcmp(p->extension_on_cd, q->extension_on_cd);
839  return n;
840 }
GLdouble n
Definition: glext.h:7729
GLdouble GLdouble GLdouble GLdouble q
Definition: gl.h:2063
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
GLfloat GLfloat p
Definition: glext.h:8902

Referenced by compare_path_table_order(), make_directory_records(), and scan_specified_files().

◆ compare_path_table_order()

static int compare_path_table_order ( PDIR_RECORD  p,
PDIR_RECORD  q 
)
static

Definition at line 848 of file cdmake.c.

849 {
850  int n = p->level - q->level;
851  if (p == q)
852  return 0;
853  if (n == 0)
854  {
855  n = compare_path_table_order(p->parent, q->parent);
856  if (n == 0)
858  }
859  return n;
860 }
GLdouble n
Definition: glext.h:7729
static int compare_directory_order(PDIR_RECORD p, PDIR_RECORD q)
Definition: cdmake.c:834
GLdouble GLdouble GLdouble GLdouble q
Definition: gl.h:2063
GLfloat GLfloat p
Definition: glext.h:8902
static int compare_path_table_order(PDIR_RECORD p, PDIR_RECORD q)
Definition: cdmake.c:848

Referenced by main().

◆ convert_date_and_time()

static void convert_date_and_time ( PDATE_AND_TIME  dt,
time_t time 
)
static

Definition at line 618 of file cdmake.c.

619 {
620  struct tm *timedef;
621  timedef = gmtime(time);
622 
623  dt->second = timedef->tm_sec;
624  dt->minute = timedef->tm_min;
625  dt->hour = timedef->tm_hour;
626  dt->day = timedef->tm_mday;
627  dt->month = timedef->tm_mon + 1;
628  dt->year = timedef->tm_year + 1900;
629 }
BYTE hour
Definition: cdmake.c:138
int tm_min
Definition: time.h:78
int tm_mday
Definition: time.h:80
BYTE month
Definition: cdmake.c:140
int tm_year
Definition: time.h:82
__u16 time
Definition: mkdosfs.c:366
int tm_mon
Definition: time.h:81
BYTE second
Definition: cdmake.c:136
Definition: time.h:76
WORD year
Definition: cdmake.c:141
int tm_sec
Definition: time.h:77
int tm_hour
Definition: time.h:79
_CRTIMP struct tm *__cdecl gmtime(const time_t *_Time)
Definition: time.h:425
BYTE day
Definition: cdmake.c:139
BYTE minute
Definition: cdmake.c:137

Referenced by main(), make_directory_records(), new_directory_record(), and scan_specified_files().

◆ edit_with_commas()

static char* edit_with_commas ( DWORD  x,
BOOL  pad 
)
static

Definition at line 255 of file cdmake.c.

256 {
257  static char s[14];
258  unsigned i = 13;
259  do
260  {
261  if (i % 4 == 2) s[--i] = ',';
262  s[--i] = (char)(x % 10 + '0');
263  } while ((x/=10) != 0);
264  if (pad)
265  {
266  while (i > 0) s[--i] = ' ';
267  }
268  return s + i;
269 }
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
unsigned char
Definition: typeof.h:29
static void pad(Char *s)
Definition: bzip2.c:908
GLdouble s
Definition: gl.h:2039

Referenced by flush_buffer(), and main().

◆ error_exit()

static void error_exit ( const char fmt,
  ... 
)
static

Definition at line 315 of file cdmake.c.

316 {
317  va_list arg;
318 
319  va_start(arg, fmt);
320  vprintf(fmt, arg);
321  va_end(arg);
322  printf("\n");
323  if (cd.file != NULL)
324  fclose(cd.file);
325  release_memory();
326  exit(1);
327 }
static struct cd_image cd
Definition: cdmake.c:182
void * arg
Definition: msvc.h:12
#define va_end(ap)
Definition: acmsvcex.h:90
smooth NULL
Definition: ftsmooth.c:416
char * va_list
Definition: acmsvcex.h:78
static void release_memory(void)
Definition: cdmake.c:275
_Check_return_opt_ _CRTIMP int __cdecl vprintf(_In_z_ _Printf_format_string_ const char *_Format, va_list _ArgList)
_Check_return_opt_ _CRTIMP int __cdecl fclose(_Inout_ FILE *_File)
#define va_start(ap, A)
Definition: acmsvcex.h:91
void exit(int exitcode)
Definition: _exit.c:33
Definition: dsound.c:943
#define printf
Definition: config.h:203

Referenced by check_for_punctuation(), flush_buffer(), main(), make_directory_records(), new_directory_record(), parse_filename_into_dirrecord(), pass(), and scan_specified_files().

◆ fill_sector()

static void fill_sector ( void  )
static

Definition at line 418 of file cdmake.c.

419 {
420  while (cd.offset != 0)
421  write_byte(0);
422 }
static void write_byte(BYTE x)
Definition: cdmake.c:352
static struct cd_image cd
Definition: cdmake.c:182

Referenced by pass(), and write_directory_record().

◆ flush_buffer()

static void flush_buffer ( void  )
static

Definition at line 334 of file cdmake.c.

335 {
336  if (fwrite(cd.buffer, cd.count, 1, cd.file) < 1)
337  error_exit("File write error");
338  cd.count = 0;
339  if (show_progress)
340  {
341  printf("\r%s ",
343  }
344 }
static struct cd_image cd
Definition: cdmake.c:182
#define SECTOR_SIZE
Definition: cdmake.c:88
static void error_exit(const char *fmt,...)
Definition: cdmake.c:315
DWORD total_sectors
Definition: cdmake.c:201
_Check_return_opt_ _CRTIMP size_t __cdecl fwrite(_In_reads_bytes_(_Size *_Count) const void *_Str, _In_ size_t _Size, _In_ size_t _Count, _Inout_ FILE *_File)
BOOL show_progress
Definition: cdmake.c:190
static char * edit_with_commas(DWORD x, BOOL pad)
Definition: cdmake.c:255
#define TRUE
Definition: cdmake.c:67
#define printf
Definition: config.h:203

Referenced by main(), write_byte(), and write_from_file().

◆ get_file_specifications()

static void get_file_specifications ( PDIR_RECORD  d)
static

Definition at line 1343 of file cdmake.c.

1344 {
1345  if (d != &root)
1346  {
1347  get_file_specifications(d->parent);
1348  if (d->joliet_name == NULL)
1350  else
1351  append_string_to_source(d->joliet_name);
1352 
1353  if (((d->flags & DIRECTORY_FLAG) == 0 || joliet) && d->extension[0] != 0)
1354  {
1355  if (d->joliet_name == NULL)
1356  {
1357  *end_source++ = '.';
1358  append_string_to_source(d->extension);
1359  }
1360  }
1361  if (d->flags & DIRECTORY_FLAG)
1363  }
1364 }
char * name
Definition: wpp.c:36
static void get_file_specifications(PDIR_RECORD d)
Definition: cdmake.c:1343
char * end_source
Definition: cdmake.c:187
#define DIR_SEPARATOR_CHAR
Definition: config.h:5
smooth NULL
Definition: ftsmooth.c:416
#define d
Definition: ke_i.h:81
static void append_string_to_source(char *s)
Definition: cdmake.c:866
BOOL joliet
Definition: cdmake.c:232
#define DIRECTORY_FLAG
Definition: cdmake.c:92

Referenced by pass().

◆ get_time_string()

static void get_time_string ( char str)
static

Definition at line 1366 of file cdmake.c.

1367 {
1368  sprintf(str, "%04d%02d%02d%02d%02d%02d00",
1369  root.date_and_time.year,
1370  root.date_and_time.month,
1371  root.date_and_time.day,
1372  root.date_and_time.hour,
1373  root.date_and_time.minute,
1374  root.date_and_time.second);
1375 }
#define sprintf(buf, format,...)
Definition: sprintf.c:55
const WCHAR * str

Referenced by pass().

◆ init_boot_entry()

static void init_boot_entry ( PBOOT_ENTRY  boot_entry,
BYTE  boot_emu_type,
WORD  load_segment,
char bootimage 
)
static

Definition at line 1949 of file cdmake.c.

1952 {
1953  boot_entry->boot_id = 0x88; // Bootable entry
1954  boot_entry->boot_emu_type = boot_emu_type; // 0: No emulation, etc...
1955  boot_entry->load_segment = load_segment; // If 0 then use default 0x07C0
1956 
1957  boot_entry->bootimage[0] = '\0';
1958  strncpy(boot_entry->bootimage, bootimage, sizeof(boot_entry->bootimage));
1959  boot_entry->bootimage[sizeof(boot_entry->bootimage)-1] = '\0';
1960 }
char * strncpy(char *DstString, const char *SrcString, ACPI_SIZE Count)
Definition: utclib.c:427
WORD load_segment
Definition: cdmake.c:116
char bootimage[512]
Definition: cdmake.c:121
BYTE boot_emu_type
Definition: cdmake.c:115
Definition: cdmake.c:111
BYTE boot_id
Definition: cdmake.c:114

Referenced by main().

◆ main()

int main ( int argc  ,
char **  argv 
)

Definition at line 1962 of file cdmake.c.

1963 {
1965  int i;
1966  char *t;
1967 
1968  if (argc < 2)
1969  {
1970  puts(HELP);
1971  return 1;
1972  }
1973 
1974  // Initialize CD-ROM write buffer
1975 
1976  cd.file = NULL;
1977  cd.filespecs[0] = 0;
1978 
1979  cd.buffer = malloc(BUFFER_SIZE);
1980  if (cd.buffer == NULL)
1981  error_exit("Insufficient memory");
1982 
1983  // Initialize root directory
1984 
1985  memset(&root, 0, sizeof(root));
1986  root.level = 1;
1987  root.flags = DIRECTORY_FLAG;
1988  convert_date_and_time(&root.date_and_time, &timestamp);
1989 
1990  // Initialize parameters
1991 
1994  // compute_crc = FALSE;
1995 
1996  verbosity = NORMAL;
1997  show_progress = FALSE;
1998  size_limit = 0;
2000  source[0] = 0;
2001  volume_label[0] = 0;
2002 
2003  // Initialize boot information
2004  eltorito = FALSE;
2005  multi_boot = FALSE;
2006  boot_validation_header.header_id = 1; // Validation header ID
2007  boot_validation_header.platform_id = 0; // x86/64 BIOS system
2009  0, // No emulation
2010  0, // Use default 0x07C0
2011  "");
2015 
2016  // Scan command line arguments
2017 
2018  for (i = 1; i < argc; i++)
2019  {
2020  if (strncmp(argv[i], "-v", 2) == 0)
2021  {
2022  t = argv[i] + 2;
2023  if (*t == 0) // Normal verbosity level.
2024  verbosity = NORMAL;
2025  else // Verbosity level in decimal
2026  verbosity = strtoul(t, NULL, 10);
2027 
2028  // Check for validity
2029  if (verbosity > VERBOSE)
2030  verbosity = NORMAL;
2031 
2032  // Disable by default, unless we are in normal verbosity level.
2033  // If progress is still wanted, use '-p'.
2034  if (verbosity == QUIET || verbosity == VERBOSE)
2035  show_progress = FALSE;
2036  }
2037  else if (strcmp(argv[i], "-p") == 0)
2038  show_progress = TRUE;
2039  else if (strncmp(argv[i], "-s", 2) == 0)
2040  {
2041  t = argv[i] + 2;
2042  if (*t == 0)
2043  {
2044  if (++i < argc)
2045  t = argv[i];
2046  else
2047  error_exit("Missing size limit parameter");
2048  }
2049  // size_limit = strtoul(t, NULL, 10);
2050  while (isdigit(*t))
2051  size_limit = size_limit * 10 + *t++ - '0';
2052  if (size_limit < 1 || size_limit > 800)
2053  error_exit("Invalid size limit");
2054  size_limit <<= 9; // convert megabyte to sector count
2055  }
2056  else if (strcmp(argv[i], "-m") == 0)
2058  else if (strcmp(argv[i], "-j") == 0)
2059  joliet = TRUE;
2060  else if (strncmp(argv[i], "-e", 2) == 0)
2061  {
2062  // Check whether the multi-boot option '-bootdata:' was already set.
2063  // If so, print an error and bail out.
2064  if (eltorito && multi_boot)
2065  error_exit("Single-boot and multi-boot entries cannot be combined");
2066 
2067  eltorito = TRUE;
2068  multi_boot = FALSE;
2069 
2070  t = argv[i] + 2;
2071  if (*t == 0) // No emulation
2073  else // ID in decimal
2075  }
2076  else if (strncmp(argv[i], "-p", 2) == 0)
2077  {
2078  // Check whether the multi-boot option '-bootdata:' was already set.
2079  // If so, print an error and bail out.
2080  if (eltorito && multi_boot)
2081  error_exit("Single-boot and multi-boot entries cannot be combined");
2082 
2083  eltorito = TRUE;
2084  multi_boot = FALSE;
2085 
2086  // Platform ID in hexadecimal
2088  }
2089  else if (strcmp(argv[i], "-b") == 0)
2090  {
2091  // Check whether the multi-boot option '-bootdata:' was already set.
2092  // If so, print an error and bail out.
2093  if (eltorito && multi_boot)
2094  error_exit("Single-boot and multi-boot entries cannot be combined");
2095 
2096  eltorito = TRUE;
2097  multi_boot = FALSE;
2098 
2101  }
2102  else if (strncmp(argv[i], "-bootdata:", sizeof("-bootdata:") - 1) == 0)
2103  {
2104  char *bootdata, *entry_ctx, *option_ctx;
2105  DWORD num_boot_entries = 0;
2106 
2107  BOOL default_entry = TRUE; // Start by setting the default boot entry
2108  PBOOT_HEADER boot_header = NULL; // Current boot header
2109  PBOOT_ENTRY boot_entry = NULL; // The last boot entry in the current boot header
2110  BYTE platform_id, old_platform_id = 0;
2111  BYTE boot_emu_type;
2112  WORD load_segment;
2113  char bootimage[512];
2114 
2115  // Check whether the single-boot option '-b' was already set.
2116  // If so, print an error and bail out.
2117  if (eltorito && !multi_boot)
2118  error_exit("Single-boot and multi-boot entries cannot be combined");
2119 
2120  t = argv[i] + (sizeof("-bootdata:") - 1);
2121  bootdata = strdup(t);
2122  if (bootdata == NULL)
2123  error_exit("Insufficient memory");
2124 
2125  eltorito = TRUE;
2126  multi_boot = TRUE;
2127 
2128  // FIXME: Paths containing '#' or ',' or ' ' are not yet supported!!
2129 
2130  // Start parsing...
2131  t = strtok_s(bootdata, "#", &entry_ctx);
2132  if (t == NULL)
2133  {
2134  free(bootdata);
2135  error_exit("Malformed bootdata command");
2136  }
2137 
2138  num_boot_entries = strtoul(t, NULL, 10);
2139 
2140  while (num_boot_entries--)
2141  {
2142  // Reset to default values
2143  platform_id = 0; // x86/64 BIOS system
2144  boot_emu_type = 0; // No emulation
2145  load_segment = 0; // Use default 0x07C0
2146  bootimage[0] = '\0';
2147 
2148  t = strtok_s(NULL, "#", &entry_ctx);
2149  if (t == NULL)
2150  {
2151  free(bootdata);
2152  error_exit("Malformed bootdata command");
2153  }
2154 
2155  t = strtok_s(t, ",", &option_ctx);
2156  while (t != NULL)
2157  {
2158  switch (*t++)
2159  {
2160  case 'b': // Boot sector file
2161  {
2162  char *q;
2163 
2164  // Searches for any of the valid separators:
2165  // '#' starts a new boot entry;
2166  // ',' starts a new boot option;
2167  // ' ' finishes the bootdata command.
2168  q = strpbrk(t, "#, ");
2169  if (!q) q = t + strlen(t);
2170  strncpy(bootimage, t, q - t + 1);
2171  break;
2172  }
2173 
2174  case 'p': // Platform ID
2175  {
2176  // Platform ID in hexadecimal
2177  platform_id = (BYTE)strtoul(t, NULL, 16);
2178  break;
2179  }
2180 
2181  case 'e': // No floppy-disk emulation
2182  {
2183  if (*t == 0) // No emulation
2184  boot_emu_type = 0;
2185  else // ID in decimal
2186  boot_emu_type = (BYTE)strtoul(t, NULL, 10);
2187 
2188  break;
2189  }
2190 
2191  case 't': // Loading segment
2192  {
2193  if (*t == 0) // Not specified: use default 0x07C0
2194  load_segment = 0;
2195  else // Segment in hexadecimal
2196  load_segment = (BYTE)strtoul(t, NULL, 16);
2197 
2198  break;
2199  }
2200 
2201  default:
2202  free(bootdata);
2203  error_exit("Malformed bootdata command");
2204  }
2205 
2206  t = strtok_s(NULL, ",", &option_ctx);
2207  }
2208 
2209  // Create a new entry and possibly a boot header
2210  if (default_entry)
2211  {
2212  // Initialize the default boot entry and header
2213 
2214  boot_validation_header.header_id = 1; // Validation header ID
2215  boot_validation_header.platform_id = platform_id;
2216 
2217  init_boot_entry(&default_boot_entry, boot_emu_type, load_segment, bootimage);
2218 
2219  // Default entry is now initialized.
2220  default_entry = FALSE;
2221  }
2222  else
2223  {
2224  // Initialize a new boot entry
2225  PBOOT_ENTRY old_boot_entry = boot_entry;
2226 
2227  boot_entry = calloc(1, sizeof(*boot_entry));
2228  if (boot_entry == NULL)
2229  error_exit("Insufficient memory");
2230  // boot_entry->next_entry = NULL;
2231 
2232  init_boot_entry(boot_entry, boot_emu_type, load_segment, bootimage);
2233 
2234  // Create a new boot header if we don't have one yet
2235  if (boot_header == NULL)
2236  {
2237  boot_header = calloc(1, sizeof(*boot_header));
2238  if (boot_header == NULL)
2239  error_exit("Insufficient memory");
2240 
2241  boot_header->header_id = 0x91; // So far this is the last boot header
2242  boot_header->platform_id = platform_id;
2243  // boot_header->next_header = NULL;
2244  // boot_header->num_entries = 0;
2245  // boot_header->entry_list = NULL;
2246 
2247  old_boot_entry = NULL;
2248  old_platform_id = platform_id;
2249 
2251  }
2252  else
2253  {
2254  // Create a new boot header if we change the platform ID
2255  if (old_platform_id != platform_id)
2256  {
2257  PBOOT_HEADER prev_boot_header = boot_header;
2258 
2259  boot_header = calloc(1, sizeof(*boot_header));
2260  if (boot_header == NULL)
2261  error_exit("Insufficient memory");
2262 
2263  boot_header->header_id = 0x91; // So far this is the last boot header
2264  boot_header->platform_id = platform_id;
2265  // boot_header->next_header = NULL;
2266  // boot_header->num_entries = 0;
2267  // boot_header->entry_list = NULL;
2268 
2269  old_boot_entry = NULL;
2270  old_platform_id = platform_id;
2271 
2272  // Link into the header list
2273  prev_boot_header->header_id = 0x90; // The previous boot header was not the last one
2274  prev_boot_header->next_header = boot_header;
2275  }
2276  }
2277 
2278  // Add the entry into the header
2280  if (old_boot_entry == NULL)
2282  else
2283  old_boot_entry->next_entry = boot_entry;
2284  }
2285  }
2286 
2287  free(bootdata);
2288  }
2289  else if (strcmp(argv[i], "-q") == 0)
2291  // else if (strcmp(argv[i], "-x") == 0)
2292  // compute_crc = TRUE;
2293  else if (i + 2 < argc)
2294  {
2295  strcpy(source, argv[i++]);
2296  strncpy(volume_label, argv[i++], sizeof(volume_label) - 1);
2297  strcpy(cd.filespecs, argv[i]);
2298  }
2299  else
2300  error_exit("Missing command line argument");
2301  }
2302 
2303  if (source[0] == 0)
2304  error_exit("Missing source directory");
2305  if (volume_label[0] == 0)
2306  error_exit("Missing volume label");
2307  if (cd.filespecs[0] == 0)
2308  error_exit("Missing image file specifications");
2309 
2310  if (source[0] != '@')
2311  {
2312  /* set source[] and end_source to source directory,
2313  * with a terminating directory separator */
2315  if (end_source[-1] == ':')
2316  *end_source++ = '.';
2317  if (end_source[-1] != DIR_SEPARATOR_CHAR)
2319 
2320  /* scan all files and create directory structure in memory */
2322  }
2323  else
2324  {
2325  char *trimmedline, *targetname, *normdir, *srcname, *eq;
2326  char lineread[1024];
2327 
2328  FILE *f = fopen(source+1, "r");
2329  if (!f)
2330  {
2331  error_exit("Cannot open CD-ROM file description '%s'\n", source+1);
2332  }
2333  while (fgets(lineread, sizeof(lineread), f))
2334  {
2335  /* We treat these characters as line endings */
2336  trimmedline = strtok(lineread, "\t\r\n;");
2337  eq = strchr(trimmedline, '=');
2338  if (!eq)
2339  {
2340  /* Treat this as a directory name */
2341  targetname = trimmedline;
2342  normdir = strdup(targetname);
2343  normalize_dirname(normdir);
2344  dir_hash_create_dir(&specified_files, targetname, normdir);
2345  free(normdir);
2346  }
2347  else
2348  {
2349  targetname = strtok(lineread, "=");
2350  srcname = strtok(NULL, "");
2351 
2352 #ifdef _WIN32
2353  if (_access(srcname, R_OK) == 0)
2354 #else
2355  if (access(srcname, R_OK) == 0)
2356 #endif
2357  {
2358  if (!dir_hash_add_file(&specified_files, srcname, targetname))
2359  error_exit("Target '%s' (file '%s') is invalid\n", targetname, srcname);
2360  }
2361  else
2362  error_exit("Cannot access file '%s' (target '%s')\n", srcname, targetname);
2363  }
2364  }
2365  fclose(f);
2366 
2367  /* scan all files and create directory structure in memory */
2369  }
2370 
2371  /* sort path table entries */
2372  root.next_in_path_table = sort_linked_list(root.next_in_path_table,
2373  1,
2375 
2376  // initialize CD-ROM write buffer
2377 
2378  cd.file = NULL;
2379  cd.sector = 0;
2380  cd.offset = 0;
2381  cd.count = 0;
2382 
2383  // make non-writing pass over directory structure to obtain the proper
2384  // sector numbers and offsets and to determine the size of the image
2385 
2388  pass();
2389 
2390  if (verbosity >= NORMAL)
2391  {
2392  printf("%s bytes ", edit_with_commas(bytes_in_files, TRUE));
2393  printf("in %s files\n", edit_with_commas(number_of_files, FALSE));
2394  printf("%s unused bytes at ends of files\n",
2397  printf("in %s directories\n",
2399  printf("%s other bytes\n", edit_with_commas(root.sector * SECTOR_SIZE, TRUE));
2400  puts("-------------");
2401  printf("%s total bytes\n",
2403  puts("=============");
2404  }
2405 
2406  if (size_limit != 0 && total_sectors > size_limit)
2407  error_exit("Size limit exceeded");
2408 
2409  if (!scan_files_only)
2410  {
2411  // re-initialize CD-ROM write buffer
2412 
2413  cd.file = fopen(cd.filespecs, "w+b");
2414  if (cd.file == NULL)
2415  error_exit("Cannot open image file '%s'", cd.filespecs);
2416  cd.sector = 0;
2417  cd.offset = 0;
2418  cd.count = 0;
2419 
2420 
2421  // make writing pass over directory structure
2422 
2423  pass();
2424 
2425  if (cd.count > 0)
2426  flush_buffer();
2427  if (show_progress)
2428  printf("\r \n");
2429  if (fclose(cd.file) != 0)
2430  {
2431  cd.file = NULL;
2432  error_exit("File write error in image file '%s'", cd.filespecs);
2433  }
2434 
2435  if (verbosity >= NORMAL)
2436  puts("CD-ROM image made successfully");
2437  }
2438 
2440  release_memory();
2441  return 0;
2442 }
static void convert_date_and_time(PDATE_AND_TIME dt, time_t *time)
Definition: cdmake.c:618
static int argc
Definition: ServiceArgs.c:12
DWORD number_of_directories
Definition: cdmake.c:213
UINT32 strtoul(const char *String, char **Terminator, UINT32 Base)
Definition: utclib.c:696
#define FALSE
Definition: cdmake.c:68
BYTE header_id
Definition: cdmake.c:127
#define BUFFER_SIZE
Definition: cdmake.c:89
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
char * strpbrk(const char *String, const char *Delimiters)
Definition: utclib.c:302
BOOL make_bridged_udf
Definition: cdmake.c:240
static struct cd_image cd
Definition: cdmake.c:182
char * strncpy(char *DstString, const char *SrcString, ACPI_SIZE Count)
Definition: utclib.c:427
#define SECTOR_SIZE
Definition: cdmake.c:88
#define free
Definition: debug_ros.c:5
DWORD unused_bytes_at_ends_of_files
Definition: cdmake.c:212
GLdouble GLdouble t
Definition: gl.h:2047
PBOOT_ENTRY entry_list
Definition: cdmake.c:131
Definition: cdmake.c:189
static char HELP[]
Definition: cdmake.c:1854
struct boot_entry * next_entry
Definition: cdmake.c:113
static void error_exit(const char *fmt,...)
Definition: cdmake.c:315
DWORD total_sectors
Definition: cdmake.c:201
void dir_hash_destroy(struct target_dir_hash *dh)
Definition: dirhash.c:235
__u16 time
Definition: mkdosfs.c:366
WORD sector_count
Definition: cdmake.c:118
#define argv
Definition: mplay32.c:18
#define R_OK
Definition: io.h:171
static void pass(void)
Definition: cdmake.c:1410
#define eq(received, expected, label, type)
Definition: locale.c:144
char * strtok_s(char *str, const char *delim, char **ctx)
Definition: cdmake.c:1920
unsigned char BYTE
Definition: cdmake.c:76
PDIR_RECORD sort_linked_list(PDIR_RECORD, unsigned, int(*)(PDIR_RECORD, PDIR_RECORD))
char * end_source
Definition: cdmake.c:187
static void flush_buffer(void)
Definition: cdmake.c:334
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define DIR_SEPARATOR_CHAR
Definition: config.h:5
unsigned int BOOL
Definition: ntddk_ex.h:94
_Check_return_ _CRTIMP char *__cdecl strdup(_In_opt_z_ const char *_Src)
Definition: cdmake.c:189
BYTE platform_id
Definition: cdmake.c:128
DWORD number_of_files
Definition: cdmake.c:210
smooth NULL
Definition: ftsmooth.c:416
BOOL scan_files_only
Definition: cdmake.c:192
BOOL eltorito
Definition: cdmake.c:222
#define isdigit(c)
Definition: acclib.h:68
static void release_memory(void)
Definition: cdmake.c:275
char bootimage[512]
Definition: cdmake.c:121
GLfloat f
Definition: glext.h:7540
_Check_return_ _CRTIMP int __cdecl _access(_In_z_ const char *_Filename, _In_ int _AccessMode)
struct boot_header * next_header
Definition: cdmake.c:126
int strncmp(const char *String1, const char *String2, ACPI_SIZE Count)
Definition: utclib.c:534
unsigned short WORD
Definition: ntddk_ex.h:93
unsigned long DWORD
Definition: ntddk_ex.h:95
BOOL accept_punctuation_marks
Definition: cdmake.c:199
GLdouble GLdouble GLdouble GLdouble q
Definition: gl.h:2063
static void init_boot_entry(PBOOT_ENTRY boot_entry, BYTE boot_emu_type, WORD load_segment, char *bootimage)
Definition: cdmake.c:1949
struct target_dir_hash specified_files
Definition: cdmake.c:216
BOOL show_progress
Definition: cdmake.c:190
unsigned char BYTE
Definition: mem.h:68
_Check_return_opt_ _CRTIMP int __cdecl fclose(_Inout_ FILE *_File)
_Check_return_ _CRTIMP FILE *__cdecl fopen(_In_z_ const char *_Filename, _In_z_ const char *_Mode)
BYTE boot_emu_type
Definition: cdmake.c:115
Definition: cdmake.c:111
int puts(const char *string)
Definition: crtsupp.c:23
struct target_dir_entry * dir_hash_create_dir(struct target_dir_hash *dh, const char *casename, const char *targetnorm)
Definition: dirhash.c:118
DWORD bytes_in_files
Definition: cdmake.c:211
char volume_label[32]
Definition: cdmake.c:185
_Check_return_opt_ _CRTIMP char *__cdecl fgets(_Out_writes_z_(_MaxCount) char *_Buf, _In_ int _MaxCount, _Inout_ FILE *_File)
__kernel_time_t time_t
Definition: linux.h:252
DWORD load_rba
Definition: cdmake.c:119
GLuint GLint GLboolean GLint GLenum access
Definition: glext.h:7866
BOOL joliet
Definition: cdmake.c:232
struct target_file * dir_hash_add_file(struct target_dir_hash *dh, const char *source, const char *target)
Definition: dirhash.c:178
void normalize_dirname(char *filename)
Definition: dirhash.c:63
PBOOT_HEADER boot_header_list
Definition: cdmake.c:227
static char * edit_with_commas(DWORD x, BOOL pad)
Definition: cdmake.c:255
DWORD size_limit
Definition: cdmake.c:198
char * strtok(char *String, const char *Delimiters)
Definition: utclib.c:338
char * strchr(const char *String, int ch)
Definition: utclib.c:501
#define calloc
Definition: rosglue.h:14
char * strcpy(char *DstString, const char *SrcString)
Definition: utclib.c:388
#define TRUE
Definition: cdmake.c:67
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
#define malloc
Definition: debug_ros.c:4
static void scan_specified_files(PDIR_RECORD d, struct target_dir_entry *dir)
Definition: cdmake.c:1228
#define DIRECTORY_FLAG
Definition: cdmake.c:92
BOOT_ENTRY default_boot_entry
Definition: cdmake.c:226
#define memset(x, y, z)
Definition: compat.h:39
static void make_directory_records(PDIR_RECORD d)
Definition: cdmake.c:965
BOOT_VALIDATION_HEADER boot_validation_header
Definition: cdmake.c:225
enum @1488 verbosity
BOOL multi_boot
Definition: cdmake.c:223
static int compare_path_table_order(PDIR_RECORD p, PDIR_RECORD q)
Definition: cdmake.c:848
DWORD bytes_in_directories
Definition: cdmake.c:214
#define printf
Definition: config.h:203
WORD num_entries
Definition: cdmake.c:129

◆ make_directory_records()

static void make_directory_records ( PDIR_RECORD  d)
static

Definition at line 965 of file cdmake.c.

966 {
967  PDIR_RECORD new_d;
968  DIR *dirp;
969  struct dirent *entry;
970  char *old_end_source;
971  struct stat stbuf;
972  char buf[MAX_PATH];
973 
974  d->first_record = NULL;
975 
976 #ifdef HAVE_D_TYPE
977  dirp = opendir(source);
978  if (dirp != NULL)
979  {
980  while ((entry = readdir(dirp)) != NULL)
981  {
982  if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0)
983  continue; // skip self and parent
984 
985  if (entry->d_type == DT_REG) // normal file
986  {
987  // Check for an absolute path
988  if (source[0] == DIR_SEPARATOR_CHAR)
989  {
990  strcpy(buf, source);
992  strcat(buf, entry->d_name);
993  }
994  else
995  {
996  if (!getcwd(buf, sizeof(buf)))
997  error_exit("Cannot get CWD: %s\n", strerror(errno));
999  strcat(buf, source);
1000  strcat(buf, entry->d_name);
1001  }
1002 
1003  if (stat(buf, &stbuf) == -1)
1004  {
1005  error_exit("Cannot access '%s' (%s)\n", buf, strerror(errno));
1006  return;
1007  }
1008 
1009  if (strcmp(entry->d_name, DIRECTORY_TIMESTAMP) == 0)
1010  {
1011  convert_date_and_time(&d->date_and_time, &stbuf.st_ctime);
1012  }
1013  else
1014  {
1015  if (verbosity == VERBOSE)
1016  {
1017  printf("%d: file %s\n", d->level, buf);
1018  }
1019  (void) new_directory_record(entry, &stbuf, d);
1020  }
1021  }
1022  }
1023  closedir(dirp);
1024  }
1025  else
1026  {
1027  error_exit("Cannot open '%s'\n", source);
1028  return;
1029  }
1030 
1031  dirp = opendir(source);
1032  if (dirp != NULL)
1033  {
1034  while ((entry = readdir(dirp)) != NULL)
1035  {
1036  if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0)
1037  continue; // skip self and parent
1038 
1039  if (entry->d_type == DT_DIR) // directory
1040  {
1041  old_end_source = end_source;
1042  append_string_to_source(entry->d_name);
1044  *end_source = 0;
1045  if (verbosity == VERBOSE)
1046  {
1047  printf("%d: directory %s\n", d->level + 1, source);
1048  }
1049  if (d->level < MAX_LEVEL)
1050  {
1051  // Check for an absolute path
1052  if (source[0] == DIR_SEPARATOR_CHAR)
1053  {
1054  strcpy(buf, source);
1055  }
1056  else
1057  {
1058  if (!getcwd(buf, sizeof(buf)))
1059  error_exit("Cannot get CWD: %s\n", strerror(errno));
1061  strcat(buf, source);
1062  }
1063 
1064  if (stat(buf, &stbuf) == -1)
1065  {
1066  error_exit("Cannot access '%s' (%s)\n", buf, strerror(errno));
1067  return;
1068  }
1069  new_d = new_directory_record(entry, &stbuf, d);
1070  new_d->next_in_path_table = root.next_in_path_table;
1071  root.next_in_path_table = new_d;
1072  new_d->level = d->level + 1;
1073  make_directory_records(new_d);
1074  }
1075  else
1076  {
1077  error_exit("Directory is nested too deep");
1078  }
1079  end_source = old_end_source;
1080  *end_source = 0;
1081  }
1082  }
1083  closedir(dirp);
1084  }
1085  else
1086  {
1087  error_exit("Cannot open '%s'\n", source);
1088  return;
1089  }
1090 
1091 #else
1092 
1093  dirp = opendir(source);
1094  if (dirp != NULL)
1095  {
1096  while ((entry = readdir(dirp)) != NULL)
1097  {
1098  if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0)
1099  continue; // skip self and parent
1100 
1101  // Check for an absolute path
1102  if (source[0] == DIR_SEPARATOR_CHAR)
1103  {
1104  strcpy(buf, source);
1106  strcat(buf, entry->d_name);
1107  }
1108  else
1109  {
1110  if (!getcwd(buf, sizeof(buf)))
1111  error_exit("Cannot get CWD: %s\n", strerror(errno));
1113  strcat(buf, source);
1114  strcat(buf, entry->d_name);
1115  }
1116 
1117  if (stat(buf, &stbuf) == -1)
1118  {
1119  error_exit("Cannot access '%s' (%s)\n", buf, strerror(errno));
1120  return;
1121  }
1122 
1123  if (S_ISDIR(stbuf.st_mode))
1124  {
1125  old_end_source = end_source;
1126  append_string_to_source(entry->d_name);
1128  *end_source = 0;
1129  if (verbosity == VERBOSE)
1130  {
1131  printf("%d: directory %s\n", d->level + 1, source);
1132  }
1133 
1134  if (d->level < MAX_LEVEL)
1135  {
1136  new_d = new_directory_record(entry, &stbuf, d);
1137  new_d->next_in_path_table = root.next_in_path_table;
1138  root.next_in_path_table = new_d;
1139  new_d->level = d->level + 1;
1140  make_directory_records(new_d);
1141  }
1142  else
1143  {
1144  error_exit("Directory is nested too deep");
1145  }
1146 
1147  end_source = old_end_source;
1148  *end_source = 0;
1149  }
1150  else if (S_ISREG(stbuf.st_mode))
1151  {
1152  if (strcmp(entry->d_name, DIRECTORY_TIMESTAMP) == 0)
1153  {
1154  convert_date_and_time(&d->date_and_time, &stbuf.st_ctime);
1155  }
1156  else
1157  {
1158  if (verbosity == VERBOSE)
1159  {
1160  printf("%d: file %s\n", d->level, buf);
1161  }
1162  (void) new_directory_record(entry, &stbuf, d);
1163  }
1164  }
1165  }
1166  closedir(dirp);
1167  }
1168  else
1169  {
1170  error_exit("Cannot open '%s'\n", source);
1171  return;
1172  }
1173 
1174 #endif
1175 
1176  // sort directory
1177  d->first_record = sort_linked_list(d->first_record, 0, compare_directory_order);
1178 }
#define MAX_LEVEL
Definition: cdmake.c:83
static void convert_date_and_time(PDATE_AND_TIME dt, time_t *time)
Definition: cdmake.c:618
struct png_info_def **typedef void(__cdecl typeof(png_destroy_read_struct))(struct png_struct_def **
Definition: typeof.h:49
char * strcat(char *DstString, const char *SrcString)
Definition: utclib.c:568
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
uint8_t entry
Definition: isohybrid.c:63
static void error_exit(const char *fmt,...)
Definition: cdmake.c:315
int errno
static char DIRECTORY_TIMESTAMP[]
Definition: cdmake.c:180
const char * strerror(int err)
Definition: compat_str.c:23
Definition: fatfs.h:198
#define DT_DIR
Definition: fs.h:149
PDIR_RECORD sort_linked_list(PDIR_RECORD, unsigned, int(*)(PDIR_RECORD, PDIR_RECORD))
char * end_source
Definition: cdmake.c:187
DIR *__cdecl opendir(const char *)
#define DT_REG
Definition: fs.h:151
#define DIR_SEPARATOR_CHAR
Definition: config.h:5
Definition: dirent.h:39
smooth NULL
Definition: ftsmooth.c:416
#define d
Definition: ke_i.h:81
#define S_ISDIR(mode)
Definition: various.h:18
#define MAX_PATH
Definition: compat.h:26
static int compare_directory_order(PDIR_RECORD p, PDIR_RECORD q)
Definition: cdmake.c:834
PDIR_RECORD new_directory_record(struct dirent *entry, struct stat *stbuf, PDIR_RECORD parent)
Definition: cdmake.c:797
Definition: stat.h:55
int __cdecl closedir(DIR *)
_Check_return_ _Ret_opt_z_ _CRTIMP char *__cdecl getcwd(_Out_writes_opt_(_SizeInBytes) char *_DstBuf, _In_ int _SizeInBytes)
static void append_string_to_source(char *s)
Definition: cdmake.c:866
struct dirent *__cdecl readdir(DIR *)
_CRTIMP int __cdecl stat(const char *_Filename, struct stat *_Stat)
Definition: stat.h:345
char * strcpy(char *DstString, const char *SrcString)
Definition: utclib.c:388
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
#define DIR_SEPARATOR_STRING
Definition: config.h:6
static void make_directory_records(PDIR_RECORD d)
Definition: cdmake.c:965
enum @1488 verbosity
#define S_ISREG(mode)
Definition: various.h:17
#define printf
Definition: config.h:203

Referenced by main().

◆ new_directory_record()

PDIR_RECORD new_directory_record ( struct dirent entry,
struct stat stbuf,
PDIR_RECORD  parent 
)

Definition at line 797 of file cdmake.c.

800 {
801  PDIR_RECORD d;
802 
803  d = calloc(1, sizeof(*d));
804  if (d == NULL)
805  error_exit("Insufficient memory");
806  d->next_in_memory = root.next_in_memory;
807  root.next_in_memory = d;
808 
809  /* I need the parent set before calling parse_filename_into_dirrecord(),
810  because that functions checks for duplicate file names*/
811  d->parent = parent;
812 #ifdef HAVE_D_TYPE
813  parse_filename_into_dirrecord(entry->d_name, d, entry->d_type == DT_DIR);
814 #else
816 #endif
817 
818  convert_date_and_time(&d->date_and_time, &stbuf->st_mtime);
819  d->flags |= entry->d_name[0] == '.' ? HIDDEN_FLAG : 0;
820  d->size = d->joliet_size = stbuf->st_size;
821  d->next_in_directory = parent->first_record;
822  parent->first_record = d;
823  return d;
824 }
static void convert_date_and_time(PDATE_AND_TIME dt, time_t *time)
Definition: cdmake.c:618
uint8_t entry
Definition: isohybrid.c:63
static void error_exit(const char *fmt,...)
Definition: cdmake.c:315
#define DT_DIR
Definition: fs.h:149
smooth NULL
Definition: ftsmooth.c:416
static void parse_filename_into_dirrecord(const char *filename, PDIR_RECORD d, BOOL dir)
Definition: cdmake.c:668
#define HIDDEN_FLAG
Definition: cdmake.c:91
#define d
Definition: ke_i.h:81
r parent
Definition: btrfs.c:2659
#define S_ISDIR(mode)
Definition: various.h:18
unsigned short st_mode
Definition: stat.h:58
#define calloc
Definition: rosglue.h:14
time_t st_mtime
Definition: stat.h:65
_off_t st_size
Definition: stat.h:63

Referenced by make_directory_records().

◆ new_empty_dirrecord()

static PDIR_RECORD new_empty_dirrecord ( PDIR_RECORD  d,
BOOL  directory 
)
static

Definition at line 1183 of file cdmake.c.

1184 {
1185  PDIR_RECORD new_d;
1186  new_d = calloc(1, sizeof(*new_d));
1187  new_d->parent = d;
1188  new_d->level = d->level + 1;
1189  new_d->next_in_directory = d->first_record;
1190  d->first_record = new_d;
1191  new_d->next_in_memory = root.next_in_memory;
1192  root.next_in_memory = new_d;
1193  new_d->date_and_time = d->date_and_time;
1194  if (directory)
1195  {
1196  new_d->flags |= DIRECTORY_FLAG;
1197  new_d->next_in_path_table = root.next_in_path_table;
1198  root.next_in_path_table = new_d;
1199  }
1200  return new_d;
1201 }
#define d
Definition: ke_i.h:81
#define calloc
Definition: rosglue.h:14
#define DIRECTORY_FLAG
Definition: cdmake.c:92

Referenced by scan_specified_files().

◆ parse_filename_into_dirrecord()

static void parse_filename_into_dirrecord ( const char filename,
PDIR_RECORD  d,
BOOL  dir 
)
static

Definition at line 668 of file cdmake.c.

669 {
670  const char *s = filename;
671  char *t = d->name_on_cd;
672  char *n = d->name;
673  int joliet_length;
674  int filename_counter;
675  filename_counter = 1;
676  while (*s != 0)
677  {
678  if (*s == '.')
679  {
680  s++;
681  break;
682  }
683 
684  if ((size_t)(t-d->name_on_cd) < sizeof(d->name_on_cd)-1)
686  else if (!joliet)
687  error_exit("'%s' is not ISO-9660, aborting...", filename);
688 
689  if ((size_t)(n-d->name) < sizeof(d->name)-1)
690  *n++ = *s;
691  else if (!joliet)
692  error_exit("'%s' is not ISO-9660, aborting...", filename);
693  s++;
694  }
695  // Check for extension length
696  if (!joliet && strlen(s) > MAX_EXTENSION_LENGTH)
697  {
698  error_exit("'%s' has too long extension, aborting...", filename);
699  }
700  *t = 0;
701  strcpy(d->extension, s);
702  t = d->extension_on_cd;
703  while (*s != 0)
704  {
705  if ((size_t)(t-d->extension_on_cd) < sizeof(d->extension_on_cd)-1)
707  else if (!joliet)
708  error_exit("'%s' is not ISO-9660, aborting...", filename);
709  s++;
710  }
711  *t = 0;
712  *n = 0;
713 
714  if (dir)
715  {
716  if (d->extension[0] != 0)
717  {
718  if (!joliet)
719  error_exit("Directory with extension '%s'", filename);
720  }
721  d->flags = DIRECTORY_FLAG;
722  } else
723  {
724  d->flags = 0;
725  }
726 
727  filename_counter = 1;
728  while (cdname_exists(d))
729  {
730  // the file name must be at least 8 chars long
731  if (strlen(d->name_on_cd)<8)
732  error_exit("'%s' is a duplicate file name, aborting...", filename);
733 
734  if ((d->name_on_cd[8] == '.') && (strlen(d->name_on_cd) < 13))
735  error_exit("'%s' is a duplicate file name, aborting...", filename);
736 
737  // max 255 times for equal short filename
738  if (filename_counter>255)
739  error_exit("'%s' is a duplicate file name, aborting...", filename);
740 
741  d->name_on_cd[8] = '~';
742  memset(&d->name_on_cd[9],0,5);
743  sprintf(&d->name_on_cd[9],"%d",filename_counter);
744  filename_counter++;
745  }
746 
747  if (joliet)
748  {
749  joliet_length = strlen(filename);
750  if (joliet_length > 64)
751  error_exit("'%s' is not Joliet, aborting...", filename);
752  d->joliet_name = malloc(joliet_length + 1);
753  if (d->joliet_name == NULL)
754  error_exit("Insufficient memory");
755  strcpy(d->joliet_name, filename);
756  }
757 }
char * name
Definition: wpp.c:36
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
GLdouble n
Definition: glext.h:7729
GLdouble GLdouble t
Definition: gl.h:2047
static void error_exit(const char *fmt,...)
Definition: cdmake.c:315
static BOOL cdname_exists(PDIR_RECORD d)
Definition: cdmake.c:654
const char * filename
Definition: ioapi.h:135
#define sprintf(buf, format,...)
Definition: sprintf.c:55
smooth NULL
Definition: ftsmooth.c:416
unsigned int dir
Definition: maze.c:112
static int check_for_punctuation(int c, const char *name)
Definition: cdmake.c:638
#define d
Definition: ke_i.h:81
GLdouble s
Definition: gl.h:2039
BOOL joliet
Definition: cdmake.c:232
char * strcpy(char *DstString, const char *SrcString)
Definition: utclib.c:388
#define malloc
Definition: debug_ros.c:4
#define DIRECTORY_FLAG
Definition: cdmake.c:92
#define memset(x, y, z)
Definition: compat.h:39
#define MAX_EXTENSION_LENGTH
Definition: cdmake.c:86

Referenced by new_directory_record(), and scan_specified_files().

◆ pass()

static void pass ( void  )
static

Definition at line 1410 of file cdmake.c.

1411 {
1412  PDIR_RECORD d, q;
1413  unsigned int index;
1414  unsigned int name_length;
1415  DWORD size;
1416  DWORD number_of_sectors;
1417  char *old_end_source;
1418  FILE *file;
1419 
1422 
1423  char timestring[17];
1424 
1425  get_time_string(timestring);
1426 
1427  // first 16 sectors are zeros
1428  write_block(16 * SECTOR_SIZE, 0);
1429 
1430 
1431  // Primary Volume Descriptor
1432  if (make_bridged_udf)
1433  {
1434  write_string("\1CD001\1");
1435  write_byte(0);
1436  write_bytecounted_string(32, "", ' '); // system identifier
1437  write_bytecounted_string(32, volume_label, ' '); // volume label
1438 
1439  write_block(8, 0);
1441  write_block(32, 0);
1442  write_both_endian_word(1); // volume set size
1443  write_both_endian_word(1); // volume sequence number
1444  write_both_endian_word(2048); // sector size
1447  write_little_endian_dword(0); // second little endian path table
1449  write_big_endian_dword(0); // second big endian path table
1451 
1452  write_bytecounted_string(128, volume_label, ' '); // volume set identifier
1453  write_bytecounted_string(128, PUBLISHER_ID, ' '); // publisher identifier
1454  write_bytecounted_string(128, DATA_PREP_ID, ' '); // data preparer identifier
1455  write_bytecounted_string(128, APP_ID, ' '); // application identifier
1456 
1457  write_bytecounted_string(37, "", ' '); // copyright file identifier
1458  write_bytecounted_string(37, "", ' '); // abstract file identifier
1459  write_bytecounted_string(37, "", ' '); // bibliographic file identifier
1460 
1461  write_string(timestring); // volume creation
1462  write_byte(0);
1463  write_string(timestring); // most recent modification
1464  write_byte(0);
1465  write_string("0000000000000000"); // volume expires
1466  write_byte(0);
1467  write_string("0000000000000000"); // volume is effective
1468  write_byte(0);
1469  write_byte(1);
1470  write_byte(0);
1471  fill_sector();
1472  }
1473 
1474  // Boot Volume Descriptor
1475  if (eltorito)
1476  {
1477  write_byte(0); // Boot record ID
1478  write_string("CD001\1");
1479  write_bytecounted_string(32, "EL TORITO SPECIFICATION", 0); // El-Torito identifier
1480  write_block(32, 0); // unused
1481  write_little_endian_dword(boot_catalog_sector); // pointer to boot catalog
1482  fill_sector();
1483  }
1484 
1485  // Supplementary Volume Descriptor
1486  if (joliet)
1487  {
1488  write_string("\2CD001\1");
1489  write_byte(0);
1490  write_bytecounted_string_as_big_endian_unicode(32, "", ' '); // system identifier
1492 
1493  write_block(8, 0);
1495  write_string("%/E");
1496  write_block(29, 0);
1497  write_both_endian_word(1); // volume set size
1498  write_both_endian_word(1); // volume sequence number
1499  write_both_endian_word(2048); // sector size
1502  write_little_endian_dword(0); // second little endian path table
1504  write_big_endian_dword(0); // second big endian path table
1506 
1507  write_bytecounted_string_as_big_endian_unicode(128, volume_label, ' '); // volume set identifier
1508  write_bytecounted_string_as_big_endian_unicode(128, PUBLISHER_ID, ' '); // publisher identifier
1509  write_bytecounted_string_as_big_endian_unicode(128, DATA_PREP_ID, ' '); // data preparer identifier
1510  write_bytecounted_string_as_big_endian_unicode(128, APP_ID, ' '); // application identifier
1511 
1512  write_bytecounted_string_as_big_endian_unicode(37, "", ' '); // copyright file identifier
1513  write_bytecounted_string_as_big_endian_unicode(37, "", ' '); // abstract file identifier
1514  write_bytecounted_string_as_big_endian_unicode(37, "", ' '); // bibliographic file identifier
1515 
1516  write_string(timestring); // volume creation
1517  write_byte(0);
1518  write_string(timestring); // most recent modification
1519  write_byte(0);
1520  write_string("0000000000000000"); // volume expires
1521  write_byte(0);
1522  write_string("0000000000000000"); // volume is effective
1523  write_byte(0);
1524  write_byte(1);
1525  write_byte(0);
1526  fill_sector();
1527  }
1528 
1529  // Volume Descriptor Set Terminator
1530  if (make_bridged_udf)
1531  {
1532  write_string("\377CD001\1");
1533  fill_sector();
1534  }
1535 
1536  // TODO: Add UDF support!
1537 
1538  // Boot Catalog
1539  if (eltorito)
1540  {
1541  boot_catalog_sector = cd.sector;
1542 
1543  // Validation entry header
1546  write_little_endian_word(0); // reserved
1547  write_bytecounted_string(24, MANUFACTURER_ID, 0); // Manufacturer identifier
1548  write_little_endian_word(0x62E); // checksum // FIXME: This is hardcoded!!
1549  write_little_endian_word(0xAA55); // signature
1550 
1551  // Default entry
1555  write_byte(0); // partition type
1556  write_byte(0); // unused
1559  write_block(20, 0); // unused
1560 
1561  // Loop through each boot header
1563  while (header)
1564  {
1565  write_byte(header->header_id);
1566  write_byte(header->platform_id);
1567  write_little_endian_word(header->num_entries);
1568  write_block(28, 0); // Identifier string (unused)
1569 
1570  // Loop through each boot entry
1571  entry = header->entry_list;
1572  while (entry)
1573  {
1574  write_byte(entry->boot_id);
1575  write_byte(entry->boot_emu_type);
1576  write_little_endian_word(entry->load_segment);
1577  write_byte(0); // partition type
1578  write_byte(0); // unused
1579  write_little_endian_word(entry->sector_count);
1580  write_little_endian_dword(entry->load_rba);
1581  write_block(20, 0); // Selection criteria (unused)
1582 
1583  entry = entry->next_entry;
1584  }
1585 
1586  header = header->next_header;
1587  }
1588 
1589  fill_sector();
1590  }
1591 
1592 
1593  // Boot Images
1594  if (eltorito)
1595  {
1596  default_boot_entry.load_rba = cd.sector;
1597 
1599  if (file == NULL)
1600  error_exit("Cannot open '%s'\n", default_boot_entry.bootimage);
1601  fseek(file, 0, SEEK_END);
1602  size = ftell(file);
1603  if (size == 0 || (size % 2048))
1604  {
1605  fclose(file);
1606  error_exit("Invalid boot image size (%lu bytes)\n", size);
1607  }
1608  // Sector count in 512 byte sectors and rounded up
1609  default_boot_entry.sector_count = (size + 511) / 512;
1610  if (!write_from_file(file, size))
1611  {
1612  fclose(file);
1613  error_exit("Read error in file '%s'\n", default_boot_entry.bootimage);
1614  }
1615  fclose(file);
1616 
1617  // Loop through each boot header
1619  while (header)
1620  {
1621  // Loop through each boot entry
1622  entry = header->entry_list;
1623  while (entry)
1624  {
1625  entry->load_rba = cd.sector;
1626 
1627  file = fopen(entry->bootimage, "rb");
1628  if (file == NULL)
1629  error_exit("Cannot open '%s'\n", entry->bootimage);
1630  fseek(file, 0, SEEK_END);
1631  size = ftell(file);
1632  if (size == 0 || (size % 2048))
1633  {
1634  fclose(file);
1635  error_exit("Invalid boot image size (%lu bytes)\n", size);
1636  }
1637  // Sector count in 512 byte sectors and rounded up
1638  entry->sector_count = (size + 511) / 512;
1639  if (!write_from_file(file, size))
1640  {
1641  fclose(file);
1642  error_exit("Read error in file '%s'\n", entry->bootimage);
1643  }
1644  fclose(file);
1645 
1646  entry = entry->next_entry;
1647  }
1648 
1649  header = header->next_header;
1650  }
1651 
1652 // fill_sector();
1653  }
1654 
1655 
1656  // Little Endian Path Table
1657 
1659  write_byte(1);
1660  write_byte(0); // number of sectors in extended attribute record
1663  write_byte(0);
1664  write_byte(0);
1665 
1666  index = 1;
1667  root.path_table_index = 1;
1668  for (d = root.next_in_path_table; d != NULL; d = d->next_in_path_table)
1669  {
1670  name_length = strlen(d->name_on_cd);
1671  write_byte((BYTE)name_length);
1672  write_byte(0); // number of sectors in extended attribute record
1673  write_little_endian_dword(d->sector);
1674  write_little_endian_word(d->parent->path_table_index);
1675  write_string(d->name_on_cd);
1676  if (name_length & 1)
1677  write_byte(0);
1678  d->path_table_index = ++index;
1679  }
1680 
1682  SECTOR_SIZE + cd.offset;
1683  fill_sector();
1684 
1685 
1686  // Big Endian Path Table
1687 
1689  write_byte(1);
1690  write_byte(0); // number of sectors in extended attribute record
1691  write_big_endian_dword(root.sector);
1693  write_byte(0);
1694  write_byte(0);
1695 
1696  for (d = root.next_in_path_table; d != NULL; d = d->next_in_path_table)
1697  {
1698  name_length = strlen(d->name_on_cd);
1699  write_byte((BYTE)name_length);
1700  write_byte(0); // number of sectors in extended attribute record
1701  write_big_endian_dword(d->sector);
1702  write_big_endian_word(d->parent->path_table_index);
1703  write_string(d->name_on_cd);
1704  if (name_length & 1)
1705  write_byte(0);
1706  }
1707  fill_sector();
1708 
1709  if (joliet)
1710  {
1711  // Little Endian Path Table
1712 
1714  write_byte(1);
1715  write_byte(0); // number of sectors in extended attribute record
1716  write_little_endian_dword(root.joliet_sector);
1718  write_byte(0);
1719  write_byte(0);
1720 
1721  for (d = root.next_in_path_table; d != NULL; d = d->next_in_path_table)
1722  {
1723  name_length = strlen(d->joliet_name) * 2;
1724  write_byte((BYTE)name_length);
1725  write_byte(0); // number of sectors in extended attribute record
1726  write_little_endian_dword(d->joliet_sector);
1727  write_little_endian_word(d->parent->path_table_index);
1728  write_string_as_big_endian_unicode(d->joliet_name);
1729  }
1730 
1732  SECTOR_SIZE + cd.offset;
1733  fill_sector();
1734 
1735  // Big Endian Path Table
1736 
1738  write_byte(1);
1739  write_byte(0); // number of sectors in extended attribute record
1740  write_big_endian_dword(root.joliet_sector);
1742  write_byte(0);
1743  write_byte(0);
1744 
1745  for (d = root.next_in_path_table; d != NULL; d = d->next_in_path_table)
1746  {
1747  name_length = strlen(d->joliet_name) * 2;
1748  write_byte((BYTE)name_length);
1749  write_byte(0); // number of sectors in extended attribute record
1750  write_big_endian_dword(d->joliet_sector);
1751  write_big_endian_word(d->parent->path_table_index);
1752  write_string_as_big_endian_unicode(d->joliet_name);
1753  }
1754  fill_sector();
1755  }
1756 
1757  // TODO: Add UDF support!
1758 
1759 #if 0
1760  // Boot Images ??
1761 #endif
1762 
1763  // TODO: Add CRC block for header!
1764 
1765  // Directories and files
1766  for (d = &root; d != NULL; d = d->next_in_path_table)
1767  {
1768  // write directory
1769  d->sector = cd.sector;
1771  write_directory_record(d == &root ? d : d->parent, DOT_DOT_RECORD, FALSE);
1772  for (q = d->first_record; q != NULL; q = q->next_in_directory)
1773  {
1776  FALSE);
1777  }
1778  fill_sector();
1779  d->size = (cd.sector - d->sector) * SECTOR_SIZE;
1780 
1781  // write directory for joliet
1782  if (joliet)
1783  {
1784  d->joliet_sector = cd.sector;
1786  write_directory_record(d == &root ? d : d->parent, DOT_DOT_RECORD, TRUE);
1787  for (q = d->first_record; q != NULL; q = q->next_in_directory)
1788  {
1791  TRUE);
1792  }
1793  fill_sector();
1794  d->joliet_size = (cd.sector - d->joliet_sector) * SECTOR_SIZE;
1795  bytes_in_directories += d->joliet_size;
1796  }
1797 
1799  bytes_in_directories += d->size;
1800 
1801  // write file data
1802  for (q = d->first_record; q != NULL; q = q->next_in_directory)
1803  {
1804  if ((q->flags & DIRECTORY_FLAG) == 0)
1805  {
1806  q->sector = q->joliet_sector = cd.sector;
1807  size = q->size;
1808  if (cd.file == NULL)
1809  {
1810  number_of_sectors = (size + SECTOR_SIZE - 1) / SECTOR_SIZE;
1811  cd.sector += number_of_sectors;
1812  number_of_files++;
1813  bytes_in_files += size;
1815  number_of_sectors * SECTOR_SIZE - size;
1816  }
1817  else
1818  {
1819  const char *file_source;
1820  old_end_source = end_source;
1821  if (!q->orig_name)
1822  {
1824  *end_source = 0;
1825  file_source = source;
1826  }
1827  else
1828  {
1829  file_source = q->orig_name;
1830  }
1831  if (verbosity == VERBOSE)
1832  printf("Writing contents of %s\n", file_source);
1833  file = fopen(file_source, "rb");
1834  if (file == NULL)
1835  error_exit("Cannot open '%s'\n", file_source);
1836  if (!write_from_file(file, size))
1837  {
1838  fclose(file);
1839  error_exit("Read error in file '%s'\n", file_source);
1840  }
1841  fclose(file);
1842  end_source = old_end_source;
1843  fill_sector();
1844  }
1845  }
1846  }
1847  }
1848 
1849  // TODO: Add final CRC block!
1850 
1851  total_sectors = (DWORD)cd.sector;
1852 }
DWORD little_endian_path_table_sector
Definition: cdmake.c:203
DWORD number_of_directories
Definition: cdmake.c:213
#define DATA_PREP_ID
Definition: config.h:14
#define FALSE
Definition: cdmake.c:68
static void write_byte(BYTE x)
Definition: cdmake.c:352
static void write_string(char *s)
Definition: cdmake.c:429
static void write_both_endian_dword(DWORD x)
Definition: cdmake.c:406
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
DWORD path_table_size
Definition: cdmake.c:202
BOOL make_bridged_udf
Definition: cdmake.c:240
static void get_file_specifications(PDIR_RECORD d)
Definition: cdmake.c:1343
static struct cd_image cd
Definition: cdmake.c:182
#define SECTOR_SIZE
Definition: cdmake.c:88
WORD load_segment
Definition: cdmake.c:116
uint8_t entry
Definition: isohybrid.c:63
DWORD unused_bytes_at_ends_of_files
Definition: cdmake.c:212
static void error_exit(const char *fmt,...)
Definition: cdmake.c:315
DWORD total_sectors
Definition: cdmake.c:201
#define MANUFACTURER_ID
Definition: config.h:12
WORD sector_count
Definition: cdmake.c:118
char * end_source
Definition: cdmake.c:187
static void write_little_endian_word(WORD x)
Definition: cdmake.c:372
static void write_little_endian_dword(DWORD x)
Definition: cdmake.c:390
char source[512]
Definition: cdmake.c:186
DWORD number_of_files
Definition: cdmake.c:210
smooth NULL
Definition: ftsmooth.c:416
_Check_return_opt_ _CRTIMP int __cdecl fseek(_Inout_ FILE *_File, _In_ long _Offset, _In_ int _Origin)
GLuint index
Definition: glext.h:6031
BOOL eltorito
Definition: cdmake.c:222
static void write_big_endian_dword(DWORD x)
Definition: cdmake.c:398
char bootimage[512]
Definition: cdmake.c:121
GLsizeiptr size
Definition: glext.h:5919
#define d
Definition: ke_i.h:81
DWORD big_endian_path_table_sector
Definition: cdmake.c:204
const char file[]
Definition: icontest.c:11
#define APP_ID
Definition: config.h:15
unsigned long DWORD
Definition: ntddk_ex.h:95
DWORD joliet_big_endian_path_table_sector
Definition: cdmake.c:235
GLdouble GLdouble GLdouble GLdouble q
Definition: gl.h:2063
static void write_big_endian_word(WORD x)
Definition: cdmake.c:378
#define index(s, c)
Definition: various.h:29
DWORD joliet_path_table_size
Definition: cdmake.c:233
unsigned char BYTE
Definition: mem.h:68
static void write_block(unsigned count, BYTE value)
Definition: cdmake.c:485
_Check_return_opt_ _CRTIMP int __cdecl fclose(_Inout_ FILE *_File)
_Check_return_ _CRTIMP FILE *__cdecl fopen(_In_z_ const char *_Filename, _In_z_ const char *_Mode)
BYTE boot_emu_type
Definition: cdmake.c:115
Definition: cdmake.c:111
DWORD bytes_in_files
Definition: cdmake.c:211
char volume_label[32]
Definition: cdmake.c:185
DWORD load_rba
Definition: cdmake.c:119
static void write_bytecounted_string_as_big_endian_unicode(unsigned bytecount, char *s, char padding)
Definition: cdmake.c:462
static void write_both_endian_word(WORD x)
Definition: cdmake.c:384
static BOOL write_from_file(FILE *file, DWORD size)
Definition: cdmake.c:1377
BOOL joliet
Definition: cdmake.c:232
#define PUBLISHER_ID
Definition: config.h:13
static void write_directory_record(PDIR_RECORD d, DIR_RECORD_TYPE DirType, BOOL joliet)
Definition: cdmake.c:512
static void fill_sector(void)
Definition: cdmake.c:418
PBOOT_HEADER boot_header_list
Definition: cdmake.c:227
_Check_return_ _CRTIMP long __cdecl ftell(_Inout_ FILE *_File)
#define TRUE
Definition: cdmake.c:67
#define SEEK_END
Definition: cabinet.c:27
#define DIRECTORY_FLAG
Definition: cdmake.c:92
BOOT_ENTRY default_boot_entry
Definition: cdmake.c:226
DWORD boot_catalog_sector
Definition: cdmake.c:224
unsigned long DWORD
Definition: cdmake.c:78
static void get_time_string(char *str)
Definition: cdmake.c:1366
DWORD joliet_little_endian_path_table_sector
Definition: cdmake.c:234
BOOT_VALIDATION_HEADER boot_validation_header
Definition: cdmake.c:225
enum @1488 verbosity
static void write_bytecounted_string(unsigned bytecount, char *s, char padding)
Definition: cdmake.c:435
struct CFHEADER header
Definition: fdi.c:109
BYTE boot_id
Definition: cdmake.c:114
static void write_string_as_big_endian_unicode(char *s)
Definition: cdmake.c:454
DWORD bytes_in_directories
Definition: cdmake.c:214
#define printf
Definition: config.h:203
Definition: fci.c:126

Referenced by main().

◆ release_memory()

static void release_memory ( void  )
static

Definition at line 275 of file cdmake.c.

276 {
277  while (boot_header_list)
278  {
280 
282  {
285  boot_header_list->entry_list = next_entry;
286  }
287 
289  boot_header_list = next_header;
290  }
291 
292  while (root.next_in_memory != NULL)
293  {
294  PDIR_RECORD next = root.next_in_memory->next_in_memory;
295  if (joliet)
296  free(root.next_in_memory->joliet_name);
297  free(root.next_in_memory);
298  root.next_in_memory = next;
299  }
300  if (joliet)
301  free(root.joliet_name);
302 
303  if (cd.buffer != NULL)
304  {
305  free(cd.buffer);
306  cd.buffer = NULL;
307  }
308 }
static struct cd_image cd
Definition: cdmake.c:182
#define free
Definition: debug_ros.c:5
PBOOT_ENTRY entry_list
Definition: cdmake.c:131
struct boot_entry * next_entry
Definition: cdmake.c:113
smooth NULL
Definition: ftsmooth.c:416
struct boot_header * next_header
Definition: cdmake.c:126
Definition: cdmake.c:111
static unsigned __int64 next
Definition: rand_nt.c:6
BOOL joliet
Definition: cdmake.c:232
PBOOT_HEADER boot_header_list
Definition: cdmake.c:227

Referenced by error_exit(), and main().

◆ scan_specified_files()

static void scan_specified_files ( PDIR_RECORD  d,
struct target_dir_entry dir 
)
static

Definition at line 1228 of file cdmake.c.

1229 {
1230  PDIR_RECORD new_d;
1231 #ifdef _WIN32
1232  HANDLE open_file;
1234 #else
1235  struct stat stbuf;
1236 #endif
1237  struct target_file *file;
1238  struct target_dir_entry *child;
1239 
1240  d->first_record = NULL;
1241 
1242  for (file = dir->head; file; file = file->next)
1243  {
1244  if (strcmp(file->target_name, DIRECTORY_TIMESTAMP) == 0)
1245  {
1246 #ifdef _WIN32
1247  if ((open_file = CreateFileA(file->source_name,
1248  GENERIC_READ,
1250  NULL,
1251  OPEN_EXISTING,
1254  {
1255  error_exit("Cannot open timestamp file '%s'\n", file->source_name);
1256  }
1257 
1258  if (!get_cd_file_time(open_file, &d->date_and_time))
1259  {
1260  error_exit("Cannot stat timestamp file '%s'\n", file->source_name);
1261  }
1263 #else
1264  if (stat(file->target_name, &stbuf) == -1)
1265  {
1266  error_exit("Cannot stat timestamp file '%s'\n", file->source_name);
1267  }
1268  convert_date_and_time(&d->date_and_time, &stbuf.st_ctime);
1269 #endif
1270  }
1271  else
1272  {
1273  if (verbosity == VERBOSE)
1274  {
1275  printf("%d: file %s (from %s)\n",
1276  d->level,
1277  file->target_name,
1278  file->source_name);
1279  }
1280  new_d = new_empty_dirrecord(d, FALSE);
1281  parse_filename_into_dirrecord(file->target_name, new_d, FALSE);
1282 #ifdef _WIN32
1283  if ((open_file = CreateFileA(file->source_name,
1284  GENERIC_READ,
1286  NULL,
1287  OPEN_EXISTING,
1290  {
1291  error_exit("Cannot open file '%s'\n", file->source_name);
1292  }
1293  if (!get_cd_file_time(open_file, &new_d->date_and_time))
1294  {
1295  error_exit("Cannot stat file '%s'\n", file->source_name);
1296  }
1298  {
1299  error_exit("Cannot get file size of '%s'\n", file->source_name);
1300  }
1301  new_d->size = new_d->joliet_size = file_size.QuadPart;
1302  new_d->orig_name = file->source_name;
1304 #else
1305  if (stat(file->source_name, &stbuf) == -1)
1306  {
1307  error_exit("Cannot find '%s' (target '%s')\n",
1308  file->source_name,
1309  file->target_name);
1310  }
1311  convert_date_and_time(&new_d->date_and_time, &stbuf.st_mtime);
1312  new_d->size = new_d->joliet_size = stbuf.st_size;
1313  new_d->orig_name = file->source_name;
1314 #endif
1315  }
1316  }
1317 
1318  for (child = dir->child; child; child = child->next)
1319  {
1320  if (verbosity == VERBOSE)
1321  {
1322  printf("%d: directory %s\n", d->level, child->case_name);
1323  }
1324  new_d = new_empty_dirrecord(d, TRUE);
1325  parse_filename_into_dirrecord(child->case_name, new_d, TRUE);
1326  scan_specified_files(new_d, child);
1327  }
1328 
1329  /* sort directory */
1330  d->first_record = sort_linked_list(d->first_record,
1331  0,
1333  source[0] = 0;
1334  end_source = source;
1335 }
static void convert_date_and_time(PDATE_AND_TIME dt, time_t *time)
Definition: cdmake.c:618
#define CloseHandle
Definition: compat.h:398
#define FALSE
Definition: cdmake.c:68
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
static void error_exit(const char *fmt,...)
Definition: cdmake.c:315
static char DIRECTORY_TIMESTAMP[]
Definition: cdmake.c:180
static HWND child
Definition: cursoricon.c:298
#define FILE_SHARE_READ
Definition: compat.h:125
Definition: dirhash.h:21
PDIR_RECORD sort_linked_list(PDIR_RECORD, unsigned, int(*)(PDIR_RECORD, PDIR_RECORD))
char * end_source
Definition: cdmake.c:187
static PDIR_RECORD new_empty_dirrecord(PDIR_RECORD d, BOOL directory)
Definition: cdmake.c:1183
char source[512]
Definition: cdmake.c:186
smooth NULL
Definition: ftsmooth.c:416
static void parse_filename_into_dirrecord(const char *filename, PDIR_RECORD d, BOOL dir)
Definition: cdmake.c:668
unsigned int dir
Definition: maze.c:112
#define OPEN_EXISTING
Definition: compat.h:426
#define d
Definition: ke_i.h:81
const char file[]
Definition: icontest.c:11
static int compare_directory_order(PDIR_RECORD p, PDIR_RECORD q)
Definition: cdmake.c:834
#define GetFileSizeEx
Definition: compat.h:414
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:126
Definition: stat.h:55
#define GENERIC_READ
Definition: compat.h:124
_CRTIMP int __cdecl stat(const char *_Filename, struct stat *_Stat)
Definition: stat.h:345
#define TRUE
Definition: cdmake.c:67
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
static void scan_specified_files(PDIR_RECORD d, struct target_dir_entry *dir)
Definition: cdmake.c:1228
#define CreateFileA(a, b, c, d, e, f, g)
Definition: compat.h:399
enum @1488 verbosity
HANDLE open_file(char *filename, BOOL bWrite)
Definition: mspatcha.c:163
#define file_size(inode)
Definition: reiserfs_fs.h:1869
#define printf
Definition: config.h:203
Definition: fci.c:126

Referenced by main().

◆ sort_linked_list()

PDIR_RECORD sort_linked_list ( PDIR_RECORD  ,
unsigned  ,
int(*)(PDIR_RECORD, PDIR_RECORD  
)

◆ strtok_s()

char* strtok_s ( char str,
const char delim,
char **  ctx 
)

Definition at line 1920 of file cdmake.c.

1921 {
1922  if (delim == NULL || ctx == NULL || (str == NULL && *ctx == NULL))
1923  {
1924  return NULL;
1925  }
1926 
1927  if (!str)
1928  str = *ctx;
1929 
1930  while (*str && strchr(delim, *str))
1931  str++;
1932  if (!*str)
1933  {
1934  *ctx = str;
1935  return NULL;
1936  }
1937 
1938  *ctx = str + 1;
1939  while (**ctx && !strchr(delim, **ctx))
1940  (*ctx)++;
1941  if (**ctx)
1942  *(*ctx)++ = '\0';
1943 
1944  return str;
1945 }
const WCHAR * str
smooth NULL
Definition: ftsmooth.c:416
char * strchr(const char *String, int ch)
Definition: utclib.c:501

Referenced by main().

◆ write_big_endian_dword()

static void write_big_endian_dword ( DWORD  x)
static

Definition at line 398 of file cdmake.c.

399 {
400  write_byte((BYTE)(x >> 24));
401  write_byte((BYTE)(x >> 16));
402  write_byte((BYTE)(x >> 8));
403  write_byte((BYTE)x);
404 }
static void write_byte(BYTE x)
Definition: cdmake.c:352
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
unsigned char BYTE
Definition: mem.h:68

Referenced by pass(), and write_both_endian_dword().

◆ write_big_endian_word()

static void write_big_endian_word ( WORD  x)
static

Definition at line 378 of file cdmake.c.

379 {
380  write_byte((BYTE)(x >> 8));
381  write_byte((BYTE)x);
382 }
static void write_byte(BYTE x)
Definition: cdmake.c:352
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
unsigned char BYTE
Definition: mem.h:68

Referenced by pass(), write_both_endian_word(), write_bytecounted_string_as_big_endian_unicode(), write_string_as_big_endian_unicode(), and write_word_block().

◆ write_block()

static void write_block ( unsigned  count,
BYTE  value 
)
static

Definition at line 485 of file cdmake.c.

486 {
487  while (count != 0)
488  {
489  write_byte(value);
490  count--;
491  }
492 }
static void write_byte(BYTE x)
Definition: cdmake.c:352
GLuint GLuint GLsizei count
Definition: gl.h:1545

Referenced by pass().

◆ write_both_endian_dword()

static void write_both_endian_dword ( DWORD  x)
static

Definition at line 406 of file cdmake.c.

407 {
410 }
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
static void write_little_endian_dword(DWORD x)
Definition: cdmake.c:390
static void write_big_endian_dword(DWORD x)
Definition: cdmake.c:398

Referenced by pass(), and write_directory_record().

◆ write_both_endian_word()

static void write_both_endian_word ( WORD  x)
static

Definition at line 384 of file cdmake.c.

385 {
388 }
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
static void write_little_endian_word(WORD x)
Definition: cdmake.c:372
static void write_big_endian_word(WORD x)
Definition: cdmake.c:378

Referenced by pass(), and write_directory_record().

◆ write_byte()

static void write_byte ( BYTE  x)
static

Definition at line 352 of file cdmake.c.

353 {
354  if (cd.file != NULL)
355  {
356  cd.buffer[cd.count] = x;
357  if (++cd.count == BUFFER_SIZE)
358  flush_buffer();
359  }
360  if (++cd.offset == SECTOR_SIZE)
361  {
362  cd.sector++;
363  cd.offset = 0;
364  }
365 }
#define BUFFER_SIZE
Definition: cdmake.c:89
static struct cd_image cd
Definition: cdmake.c:182
#define SECTOR_SIZE
Definition: cdmake.c:88
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
static void flush_buffer(void)
Definition: cdmake.c:334
smooth NULL
Definition: ftsmooth.c:416

Referenced by fill_sector(), pass(), write_big_endian_dword(), write_big_endian_word(), write_block(), write_bytecounted_string(), write_bytecounted_string_as_big_endian_unicode(), write_directory_record(), write_little_endian_dword(), write_little_endian_word(), and write_string().

◆ write_bytecounted_string()

static void write_bytecounted_string ( unsigned  bytecount,
char s,
char  padding 
)
static

Definition at line 435 of file cdmake.c.

436 {
437  while (*s != 0 && bytecount != 0)
438  {
439  write_byte(*s++);
440  bytecount--;
441  }
442  while (bytecount != 0)
443  {
445  bytecount--;
446  }
447 }
static void write_byte(BYTE x)
Definition: cdmake.c:352
unsigned int padding
Definition: isohybrid.c:50
GLdouble s
Definition: gl.h:2039

Referenced by pass().

◆ write_bytecounted_string_as_big_endian_unicode()

static void write_bytecounted_string_as_big_endian_unicode ( unsigned  bytecount,
char s,
char  padding 
)
static

Definition at line 462 of file cdmake.c.

463 {
464  unsigned wordcount = bytecount / 2;
465 
466  while (*s != 0 && wordcount != 0)
467  {
469  wordcount--;
470  }
471  while (wordcount != 0)
472  {
474  wordcount--;
475  }
476 
477  if (bytecount % 2 != 0)
479 }
static void write_byte(BYTE x)
Definition: cdmake.c:352
unsigned int padding
Definition: isohybrid.c:50
static void write_big_endian_word(WORD x)
Definition: cdmake.c:378
GLdouble s
Definition: gl.h:2039

Referenced by pass().

◆ write_directory_record()

static void write_directory_record ( PDIR_RECORD  d,
DIR_RECORD_TYPE  DirType,
BOOL  joliet 
)
static

Definition at line 512 of file cdmake.c.

515 {
516  unsigned identifier_size;
517  unsigned record_size;
518 
519  if (joliet)
520  {
521  if (DirType == DOT_RECORD || DirType == DOT_DOT_RECORD)
522  identifier_size = 1;
523  else
524  identifier_size = strlen(d->joliet_name) * 2;
525  }
526  else
527  {
528  switch (DirType)
529  {
530  case DOT_RECORD:
531  case DOT_DOT_RECORD:
532  identifier_size = 1;
533  break;
534  case SUBDIRECTORY_RECORD:
535  /*printf("Subdir: %s\n", d->name_on_cd);*/
536  identifier_size = strlen(d->name_on_cd);
537  break;
538  case FILE_RECORD:
539  /*printf("File: %s.%s -> %s.%s\n", d->name, d->extension, d->name_on_cd, d->extension_on_cd);*/
540  identifier_size = strlen(d->name_on_cd) + 2;
541  if (d->extension_on_cd[0] != 0)
542  identifier_size += 1 + strlen(d->extension_on_cd);
543  break;
544  default:
545  identifier_size = 1;
546  break;
547  }
548  }
549  record_size = 33 + identifier_size;
550  if ((identifier_size & 1) == 0)
551  record_size++;
552  if (cd.offset + record_size > SECTOR_SIZE)
553  fill_sector();
554  write_byte((BYTE)record_size);
555  write_byte(0); // number of sectors in extended attribute record
556  if (joliet)
557  {
558  write_both_endian_dword(d->joliet_sector);
559  write_both_endian_dword(d->joliet_size);
560  }
561  else
562  {
563  write_both_endian_dword(d->sector);
564  write_both_endian_dword(d->size);
565  }
566  write_byte((BYTE)(d->date_and_time.year - 1900));
567  write_byte(d->date_and_time.month);
568  write_byte(d->date_and_time.day);
569  write_byte(d->date_and_time.hour);
570  write_byte(d->date_and_time.minute);
571  write_byte(d->date_and_time.second);
572  write_byte(0); // GMT offset
573  write_byte(d->flags);
574  write_byte(0); // file unit size for an interleaved file
575  write_byte(0); // interleave gap size for an interleaved file
576  write_both_endian_word(1); // volume sequence number
577  write_byte((BYTE)identifier_size);
578  switch (DirType)
579  {
580  case DOT_RECORD:
581  write_byte(0);
582  break;
583  case DOT_DOT_RECORD:
584  write_byte(1);
585  break;
586  case SUBDIRECTORY_RECORD:
587  if (joliet)
589  else
590  write_string(d->name_on_cd);
591  break;
592  case FILE_RECORD:
593  if (joliet)
594  {
596  }
597  else
598  {
599  write_string(d->name_on_cd);
600  if (d->extension_on_cd[0] != 0)
601  {
602  write_byte('.');
603  write_string(d->extension_on_cd);
604  }
605  write_string(";1");
606  }
607  break;
608  }
609  if ((identifier_size & 1) == 0)
610  write_byte(0);
611 }
static void write_byte(BYTE x)
Definition: cdmake.c:352
static void write_string(char *s)
Definition: cdmake.c:429
static void write_both_endian_dword(DWORD x)
Definition: cdmake.c:406
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
static struct cd_image cd
Definition: cdmake.c:182
#define SECTOR_SIZE
Definition: cdmake.c:88
#define d
Definition: ke_i.h:81
unsigned char BYTE
Definition: mem.h:68
static void write_both_endian_word(WORD x)
Definition: cdmake.c:384
BOOL joliet
Definition: cdmake.c:232
static void fill_sector(void)
Definition: cdmake.c:418
static void write_string_as_big_endian_unicode(char *s)
Definition: cdmake.c:454

Referenced by pass().

◆ write_from_file()

static BOOL write_from_file ( FILE file,
DWORD  size 
)
static

Definition at line 1377 of file cdmake.c.

1378 {
1379  if (cd.file != NULL)
1380  {
1381  int n;
1382 
1383  fseek(file, 0, SEEK_SET);
1384  while (size > 0)
1385  {
1386  n = BUFFER_SIZE - cd.count;
1387  if ((DWORD)n > size)
1388  n = size;
1389 
1390  if (fread(cd.buffer + cd.count, n, 1, file) < 1)
1391  return FALSE;
1392 
1393  cd.count += n;
1394  if (cd.count == BUFFER_SIZE)
1395  flush_buffer();
1396  cd.sector += n / SECTOR_SIZE;
1397  cd.offset += n % SECTOR_SIZE;
1398  size -= n;
1399  }
1400  }
1401  else
1402  {
1403  cd.sector += size / SECTOR_SIZE;
1404  cd.offset += size % SECTOR_SIZE;
1405  }
1406 
1407  return TRUE;
1408 }
#define FALSE
Definition: cdmake.c:68
#define BUFFER_SIZE
Definition: cdmake.c:89
static struct cd_image cd
Definition: cdmake.c:182
#define SECTOR_SIZE
Definition: cdmake.c:88
GLdouble n
Definition: glext.h:7729
static void flush_buffer(void)
Definition: cdmake.c:334
_Check_return_opt_ _CRTIMP size_t __cdecl fread(_Out_writes_bytes_(_ElementSize *_Count) void *_DstBuf, _In_ size_t _ElementSize, _In_ size_t _Count, _Inout_ FILE *_File)
smooth NULL
Definition: ftsmooth.c:416
_Check_return_opt_ _CRTIMP int __cdecl fseek(_Inout_ FILE *_File, _In_ long _Offset, _In_ int _Origin)
#define SEEK_SET
Definition: jmemansi.c:26
GLsizeiptr size
Definition: glext.h:5919
unsigned long DWORD
Definition: ntddk_ex.h:95
#define TRUE
Definition: cdmake.c:67
Definition: fci.c:126

Referenced by pass().

◆ write_little_endian_dword()

static void write_little_endian_dword ( DWORD  x)
static

Definition at line 390 of file cdmake.c.

391 {
392  write_byte((BYTE)x);
393  write_byte((BYTE)(x >> 8));
394  write_byte((BYTE)(x >> 16));
395  write_byte((BYTE)(x >> 24));
396 }
static void write_byte(BYTE x)
Definition: cdmake.c:352
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
unsigned char BYTE
Definition: mem.h:68

Referenced by pass(), and write_both_endian_dword().

◆ write_little_endian_word()

static void write_little_endian_word ( WORD  x)
static

Definition at line 372 of file cdmake.c.

373 {
374  write_byte((BYTE)x);
375  write_byte((BYTE)(x >> 8));
376 }
static void write_byte(BYTE x)
Definition: cdmake.c:352
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
unsigned char BYTE
Definition: mem.h:68

Referenced by pass(), and write_both_endian_word().

◆ write_string()

static void write_string ( char s)
static

Definition at line 429 of file cdmake.c.

430 {
431  while (*s != 0)
432  write_byte(*s++);
433 }
static void write_byte(BYTE x)
Definition: cdmake.c:352
GLdouble s
Definition: gl.h:2039

Referenced by pass(), and write_directory_record().

◆ write_string_as_big_endian_unicode()

static void write_string_as_big_endian_unicode ( char s)
static

Definition at line 454 of file cdmake.c.

455 {
456  while (*s != 0)
457  {
459  }
460 }
static void write_big_endian_word(WORD x)
Definition: cdmake.c:378
GLdouble s
Definition: gl.h:2039

Referenced by pass(), and write_directory_record().

◆ write_word_block()

static void write_word_block ( unsigned  count,
WORD  value 
)
static

Definition at line 498 of file cdmake.c.

499 {
500  while (count != 0)
501  {
503  count--;
504  }
505 }
GLuint GLuint GLsizei count
Definition: gl.h:1545
static void write_big_endian_word(WORD x)
Definition: cdmake.c:378

Variable Documentation

◆ accept_punctuation_marks

BOOL accept_punctuation_marks

Definition at line 199 of file cdmake.c.

Referenced by check_for_punctuation(), and main().

◆ big_endian_path_table_sector

DWORD big_endian_path_table_sector

Definition at line 204 of file cdmake.c.

Referenced by pass().

◆ boot_catalog_sector

DWORD boot_catalog_sector

Definition at line 224 of file cdmake.c.

Referenced by pass().

◆ boot_header_list

PBOOT_HEADER boot_header_list

Definition at line 227 of file cdmake.c.

Referenced by main(), pass(), and release_memory().

◆ boot_validation_header

BOOT_VALIDATION_HEADER boot_validation_header

Definition at line 225 of file cdmake.c.

Referenced by main(), and pass().

◆ bytes_in_directories

DWORD bytes_in_directories

Definition at line 214 of file cdmake.c.

Referenced by main(), and pass().

◆ bytes_in_files

DWORD bytes_in_files

Definition at line 211 of file cdmake.c.

Referenced by main(), and pass().

◆ cd

◆ default_boot_entry

BOOT_ENTRY default_boot_entry

Definition at line 226 of file cdmake.c.

Referenced by main(), and pass().

◆ DIRECTORY_TIMESTAMP

char DIRECTORY_TIMESTAMP[] = "~Y$'KOR$.3K&"
static

Definition at line 180 of file cdmake.c.

Referenced by make_directory_records(), and scan_specified_files().

◆ eltorito

BOOL eltorito

Definition at line 222 of file cdmake.c.

Referenced by main(), and pass().

◆ end_source

◆ HELP

char HELP[]
static

Definition at line 1854 of file cdmake.c.

Referenced by main().

◆ joliet

◆ joliet_big_endian_path_table_sector

DWORD joliet_big_endian_path_table_sector

Definition at line 235 of file cdmake.c.

Referenced by pass().

◆ joliet_little_endian_path_table_sector

DWORD joliet_little_endian_path_table_sector

Definition at line 234 of file cdmake.c.

Referenced by pass().

◆ joliet_path_table_size

DWORD joliet_path_table_size

Definition at line 233 of file cdmake.c.

Referenced by pass().

◆ little_endian_path_table_sector

DWORD little_endian_path_table_sector

Definition at line 203 of file cdmake.c.

Referenced by pass().

◆ make_bridged_udf

BOOL make_bridged_udf = TRUE

Definition at line 240 of file cdmake.c.

Referenced by main(), and pass().

◆ multi_boot

BOOL multi_boot

Definition at line 223 of file cdmake.c.

Referenced by main().

◆ number_of_directories

DWORD number_of_directories

Definition at line 213 of file cdmake.c.

Referenced by main(), and pass().

◆ number_of_files

DWORD number_of_files

Definition at line 210 of file cdmake.c.

Referenced by main(), and pass().

◆ path_table_size

DWORD path_table_size

Definition at line 202 of file cdmake.c.

Referenced by file_write(), generate_path_tables(), pass(), pvd_write(), and sort_n_finish().

◆ root

Definition at line 183 of file cdmake.c.

◆ scan_files_only

BOOL scan_files_only = FALSE

Definition at line 192 of file cdmake.c.

Referenced by main().

◆ show_progress

BOOL show_progress

Definition at line 190 of file cdmake.c.

Referenced by flush_buffer(), and main().

◆ size_limit

DWORD size_limit

Definition at line 198 of file cdmake.c.

Referenced by decode_open_write_delegation4(), and main().

◆ source

char source[512]

Definition at line 186 of file cdmake.c.

Referenced by pass(), and scan_specified_files().

◆ specified_files

struct target_dir_hash specified_files

Definition at line 216 of file cdmake.c.

Referenced by main().

◆ total_sectors

DWORD total_sectors

Definition at line 201 of file cdmake.c.

Referenced by flush_buffer(), main(), pass(), and read_boot().

◆ unused_bytes_at_ends_of_files

DWORD unused_bytes_at_ends_of_files

Definition at line 212 of file cdmake.c.

Referenced by main(), and pass().

◆ verbosity

◆ volume_label

char volume_label[32]

Definition at line 185 of file cdmake.c.

Referenced by main(), msi_package_add_media_disk(), and pass().