#include <sys/types.h>#include <sys/uio.h>#include <sys/param.h>#include <unistd.h>#include <string.h>#include <strings.h>#include <ctype.h>#include <stdio.h>#include <atalk/adouble.h>#include <atalk/util.h>#include <netatalk/endian.h>#include "nad.h"#include "megatron.h"#include "macbin.h"#include "crc16.h"Data Structures | |
| struct | bin_file_data |
Macros | |
| #define | MACBINARY_PLAY_NICE_WITH_OTHERS |
| #define | NOWAY 0 |
| #define | SURETHANG 1 |
| #define | HEADBUFSIZ 128 |
| #define | MACBIN_NAMELEN 63 |
Functions | |
| static uint16_t | macbin_u16_from_bytes (unsigned char high, unsigned char low) |
| static uint32_t | macbin_u32_from_header (const unsigned char *header, size_t offset) |
| static uint16_t | macbin_fdflags_from_header (const unsigned char *header, int revision) |
| static void | macbin_fdflags_to_header (unsigned char *header, uint16_t fdflags) |
| static int | macbin_ad_date_from_header (uint32_t mac_date, uint32_t *ad_date) |
| static int | macbin_ad_date_to_header (uint32_t ad_date, uint32_t *mac_date) |
| static int | macbin_discard_bytes (size_t length) |
| static int | macbin_write_repeat (unsigned char value, size_t length) |
| static int | macbin_skip_padding (void) |
| static int | macbin_write_padding (void) |
| int | bin_open (char *binfile, int flags, struct FHeader *fh, int options) |
| Open a MacBinary file for reading or writing. | |
| int | bin_close (int keepflag) |
| Close the active MacBinary file. | |
| const char * | bin_path (void) |
| ssize_t | bin_read (int fork, char *buffer, size_t length) |
| Read data from a MacBinary fork. | |
| ssize_t | bin_write (int fork, char *buffer, size_t length) |
| Write data to a MacBinary fork. | |
| int | bin_header_read (struct FHeader *fh, int revision) |
| Read a MacBinary header into a file header. | |
| int | bin_header_write (struct FHeader *fh) |
| Write a file header as a MacBinary header. | |
| int | test_header (void) |
| Test the input header for a supported MacBinary revision. | |
Variables | |
| static struct bin_file_data | bin |
| char * | forkname [] |
| static unsigned char | head_buf [HEADBUFSIZ] |
| #define HEADBUFSIZ 128 |
| #define MACBIN_NAMELEN 63 |
| #define MACBINARY_PLAY_NICE_WITH_OTHERS |
| #define NOWAY 0 |
| #define SURETHANG 1 |
| int bin_close | ( | int | keepflag | ) |
Close the active MacBinary file.
This must be called before opening another file with bin_open(). KEEP closes the file and preserves it. TRASH closes the file and removes incomplete output.
| int bin_header_read | ( | struct FHeader * | fh, |
| int | revision ) |
Read a MacBinary header into a file header.
This is called by bin_open() before any fork data is read. It validates the MacBinary revision, decodes header fields, and initializes fork lengths.
| [out] | fh | file header to populate |
| [in] | revision | MacBinary revision returned by test_header() |
| int bin_header_write | ( | struct FHeader * | fh | ) |
Write a file header as a MacBinary header.
This is called by bin_open() before any fork data is written. It encodes the file header as a MacBinary III header and initializes fork lengths.
| [in] | fh | file header to write |
| int bin_open | ( | char * | binfile, |
| int | flags, | ||
| struct FHeader * | fh, | ||
| int | options ) |
Open a MacBinary file for reading or writing.
This must be called before other MacBinary operations. When opening for reading, it validates and reads the MacBinary header. When opening for writing, it initializes output state and writes the header.
| [in] | binfile | input file path, or - for standard input |
| [in] | flags | open flags; O_RDONLY selects read mode |
| [in,out] | fh | file header to read or write |
| [in] | options | output options, such as OPTION_STDOUT |
| const char * bin_path | ( | void | ) |
| ssize_t bin_read | ( | int | fork, |
| char * | buffer, | ||
| size_t | length ) |
Read data from a MacBinary fork.
Call this until it returns zero for each fork. When the data fork is complete, it skips MacBinary padding before the resource fork begins.
| [in] | fork | fork selector, DATA or RESOURCE |
| [out] | buffer | destination buffer |
| [in] | length | maximum number of bytes to read |
| ssize_t bin_write | ( | int | fork, |
| char * | buffer, | ||
| size_t | length ) |
Write data to a MacBinary fork.
Data must be written in fork order. The resource fork cannot be written until the data fork is complete. Padding is written when each fork is finished.
| [in] | fork | fork selector, DATA or RESOURCE |
| [in] | buffer | source buffer |
| [in] | length | number of bytes to write |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
| int test_header | ( | void | ) |
Test the input header for a supported MacBinary revision.
Reads the first 128 bytes and determines whether the file is MacBinary, MacBinary II, MacBinary III, or not a MacBinary file.
|
static |
|
extern |
|
static |