Minor cleanup, I hope I'm not interfering, Korli :-)

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@18762 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2006-09-05 15:27:21 +00:00
parent d69e258f4c
commit 242dab1257
@@ -135,6 +135,10 @@ typedef struct iso9660_directory_record {
uint16 volume_space_le; uint16 volume_space_le;
} __attribute__((packed)) iso9660_directory_record; } __attribute__((packed)) iso9660_directory_record;
static void dump_directory_record(iso9660_directory_record *record, const char *indent);
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
// iso9660_info // iso9660_info
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
@@ -232,9 +236,9 @@ iso9660_info::set_string(char **string, const char *new_string, uint32 new_lengt
} }
} }
//----------------------------------------------------------------------------
// C functions // #pragma mark - C functions
//----------------------------------------------------------------------------
/*! \brief Converts the given unicode character to utf8. /*! \brief Converts the given unicode character to utf8.
@@ -243,8 +247,7 @@ iso9660_info::set_string(char **string, const char *new_string, uint32 new_lengt
\todo Once OpenTracker's locale kit is done, perhaps that functionality \todo Once OpenTracker's locale kit is done, perhaps that functionality
should be used rather than outright stealing the code. should be used rather than outright stealing the code.
*/ */
static static void
void
unicode_to_utf8(uint32 c, char **out) unicode_to_utf8(uint32 c, char **out)
{ {
char *s = *out; char *s = *out;
@@ -267,8 +270,8 @@ unicode_to_utf8(uint32 c, char **out)
*out = s; *out = s;
} }
static
const char* static const char*
volume_descriptor_type_to_string(iso9660_volume_descriptor_type type) volume_descriptor_type_to_string(iso9660_volume_descriptor_type type)
{ {
switch (type) { switch (type) {
@@ -281,14 +284,14 @@ volume_descriptor_type_to_string(iso9660_volume_descriptor_type type)
} }
} }
static
void static void
dump_common_volume_descriptor(iso9660_common_volume_descriptor *common, const char *indent, dump_common_volume_descriptor(iso9660_common_volume_descriptor *common,
bool print_header) const char *indent, bool print_header)
{ {
if (print_header) if (print_header)
TRACE(("%siso9660_common_volume_descriptor:\n", indent)); TRACE(("%siso9660_common_volume_descriptor:\n", indent));
TRACE(("%s volume descriptor type == %d (%s)\n", indent, TRACE(("%s volume descriptor type == %d (%s)\n", indent,
common->volume_descriptor_type, common->volume_descriptor_type,
volume_descriptor_type_to_string((iso9660_volume_descriptor_type)common->volume_descriptor_type))); volume_descriptor_type_to_string((iso9660_volume_descriptor_type)common->volume_descriptor_type)));
@@ -297,14 +300,10 @@ dump_common_volume_descriptor(iso9660_common_volume_descriptor *common, const ch
TRACE(("%s volume descriptor version == %d\n", indent, common->volume_descriptor_version)); TRACE(("%s volume descriptor version == %d\n", indent, common->volume_descriptor_version));
} }
static
void
dump_directory_record(iso9660_directory_record *record, const char *indent);
static static void
void dump_primary_volume_descriptor(iso9660_primary_volume_descriptor *primary,
dump_primary_volume_descriptor(iso9660_primary_volume_descriptor *primary, const char *indent, const char *indent, bool print_header)
bool print_header)
{ {
if (print_header) if (print_header)
TRACE(("%siso9660_primary_volume_descriptor:\n", indent)); TRACE(("%siso9660_primary_volume_descriptor:\n", indent));
@@ -327,15 +326,16 @@ dump_primary_volume_descriptor(iso9660_primary_volume_descriptor *primary, const
dump_directory_record((iso9660_directory_record*)primary->root_directory_record, indent); dump_directory_record((iso9660_directory_record*)primary->root_directory_record, indent);
} }
static
void static void
dump_supplementary_volume_descriptor(iso9660_supplementary_volume_descriptor *supplementary, const char *indent, dump_supplementary_volume_descriptor(iso9660_supplementary_volume_descriptor *supplementary,
bool print_header) const char *indent, bool print_header)
{ {
if (print_header) if (print_header)
TRACE(("%siso9660_supplementary_volume_descriptor:\n", indent)); TRACE(("%siso9660_supplementary_volume_descriptor:\n", indent));
dump_primary_volume_descriptor((iso9660_primary_volume_descriptor*)supplementary, indent, false); dump_primary_volume_descriptor((iso9660_primary_volume_descriptor*)supplementary,
indent, false);
TRACE(("%s escape sequences ==", indent)); TRACE(("%s escape sequences ==", indent));
for (int i = 0; i < ISO9660_ESCAPE_SEQUENCE_LENGTH; i++) { for (int i = 0; i < ISO9660_ESCAPE_SEQUENCE_LENGTH; i++) {
TRACE((" %2x", supplementary->escape_sequences[i])); TRACE((" %2x", supplementary->escape_sequences[i]));
@@ -344,9 +344,9 @@ dump_supplementary_volume_descriptor(iso9660_supplementary_volume_descriptor *su
} }
TRACE(("\n")); TRACE(("\n"));
} }
static
void static void
dump_directory_record(iso9660_directory_record *record, const char *indent) dump_directory_record(iso9660_directory_record *record, const char *indent)
{ {
TRACE(("%s root directory record:\n", indent)); TRACE(("%s root directory record:\n", indent));
@@ -356,19 +356,22 @@ dump_directory_record(iso9660_directory_record *record, const char *indent)
TRACE(("%s volume sequence number == %d\n", indent, record->volume_space_le)); TRACE(("%s volume sequence number == %d\n", indent, record->volume_space_le));
} }
static
status_t static status_t
check_common_volume_descriptor(iso9660_common_volume_descriptor *common) check_common_volume_descriptor(iso9660_common_volume_descriptor *common)
{ {
status_t error = common ? B_OK : B_BAD_VALUE; status_t error = common ? B_OK : B_BAD_VALUE;
if (!error) { if (!error) {
error = strncmp(common->standard_identifier, kISO9660Signature, error = strncmp(common->standard_identifier, kISO9660Signature, 5) == 0
5) == 0 ? B_OK : B_BAD_DATA; ? B_OK : B_BAD_DATA;
} }
return error; return error;
} }
// #pragma mark - Public functions
// iso9660_fs_identify // iso9660_fs_identify
/*! \brief Returns true if the given partition is a valid iso9660 partition. /*! \brief Returns true if the given partition is a valid iso9660 partition.
@@ -383,34 +386,32 @@ iso9660_fs_identify(int deviceFD, iso9660_info *info)
bool exit = false; bool exit = false;
status_t error = B_OK; status_t error = B_OK;
nspace *vol; nspace *vol;
TRACE(("identify(%d, %p)\n", deviceFD, info)); TRACE(("identify(%d, %p)\n", deviceFD, info));
off_t offset = 0x8000; off_t offset = 0x8000;
vol = (nspace *)calloc(sizeof(nspace), 1); vol = (nspace *)calloc(sizeof(nspace), 1);
if (vol == NULL) { if (vol == NULL)
return ENOMEM; return ENOMEM;
}
vol->fd = deviceFD; vol->fd = deviceFD;
// Read through the volume descriptors looking for a primary descriptor. // Read through the volume descriptors looking for a primary descriptor.
// If for some reason there are more than one primary descriptor, the // If for some reason there are more than one primary descriptor, the
// volume name from the last encountered descriptor will be used. // volume name from the last encountered descriptor will be used.
while (!error && !exit) {// && count++ < 10) { while (!error && !exit) {// && count++ < 10) {
iso9660_common_volume_descriptor *common = NULL; iso9660_common_volume_descriptor *common = NULL;
// Read the block containing the current descriptor // Read the block containing the current descriptor
error = read_pos (vol->fd, offset, (void *)&buffer, ISO_PVD_SIZE); error = read_pos (vol->fd, offset, (void *)&buffer, ISO_PVD_SIZE);
offset += ISO_PVD_SIZE; offset += ISO_PVD_SIZE;
if (error < ISO_PVD_SIZE) { if (error < ISO_PVD_SIZE)
break; break;
}
common = (iso9660_common_volume_descriptor*)buffer; common = (iso9660_common_volume_descriptor*)buffer;
error = check_common_volume_descriptor(common); error = check_common_volume_descriptor(common);
// dump_common_volume_descriptor(common, "", true); // dump_common_volume_descriptor(common, "", true);
// Handle each type of descriptor appropriately // Handle each type of descriptor appropriately
if (!error) { if (!error) {
TRACE(("found %s descriptor\n", volume_descriptor_type_to_string((iso9660_volume_descriptor_type)common->volume_descriptor_type))); TRACE(("found %s descriptor\n", volume_descriptor_type_to_string((iso9660_volume_descriptor_type)common->volume_descriptor_type)));
@@ -418,14 +419,14 @@ iso9660_fs_identify(int deviceFD, iso9660_info *info)
switch (common->volume_descriptor_type) { switch (common->volume_descriptor_type) {
case ISO9660VD_BOOT: case ISO9660VD_BOOT:
break; break;
case ISO9660VD_PRIMARY: case ISO9660VD_PRIMARY:
{ {
int i; int i;
iso9660_primary_volume_descriptor *primary = (iso9660_primary_volume_descriptor*)buffer; iso9660_primary_volume_descriptor *primary = (iso9660_primary_volume_descriptor*)buffer;
dump_primary_volume_descriptor(primary, " ", true); dump_primary_volume_descriptor(primary, " ", true);
// Cut off any trailing spaces from the volume id. Note // Cut off any trailing spaces from the volume id. Note
// that this allows for spaces INSIDE the volume id, even // that this allows for spaces INSIDE the volume id, even
// though that's not technically allowed by the standard; // though that's not technically allowed by the standard;
@@ -445,22 +446,22 @@ iso9660_fs_identify(int deviceFD, iso9660_info *info)
"instead of former (`%s')\n", str, "instead of former (`%s')\n", str,
info->iso9660_volume_name)); info->iso9660_volume_name));
} }
info->set_iso9660_volume_name(primary->volume_identifier, i+1); info->set_iso9660_volume_name(primary->volume_identifier, i+1);
info->maxBlocks = primary->volume_set_size_little_endian; info->maxBlocks = primary->volume_set_size_little_endian;
break; break;
} }
case ISO9660VD_SUPPLEMENTARY: case ISO9660VD_SUPPLEMENTARY:
{ {
iso9660_supplementary_volume_descriptor *supplementary = (iso9660_supplementary_volume_descriptor*)buffer; iso9660_supplementary_volume_descriptor *supplementary = (iso9660_supplementary_volume_descriptor*)buffer;
dump_supplementary_volume_descriptor((iso9660_supplementary_volume_descriptor*)supplementary, " ", true); dump_supplementary_volume_descriptor((iso9660_supplementary_volume_descriptor*)supplementary, " ", true);
// Copy and null terminate the escape sequences // Copy and null terminate the escape sequences
char escapes[ISO9660_ESCAPE_SEQUENCE_LENGTH+1]; char escapes[ISO9660_ESCAPE_SEQUENCE_LENGTH+1];
strncpy(escapes, supplementary->escape_sequences, ISO9660_ESCAPE_SEQUENCE_LENGTH); strncpy(escapes, supplementary->escape_sequences, ISO9660_ESCAPE_SEQUENCE_LENGTH);
escapes[ISO9660_ESCAPE_SEQUENCE_LENGTH] = 0; escapes[ISO9660_ESCAPE_SEQUENCE_LENGTH] = 0;
// Check for a Joliet VD // Check for a Joliet VD
if (strstr(escapes, "%/@") || strstr(escapes, "%/C") || strstr(escapes, "%/E")) { if (strstr(escapes, "%/@") || strstr(escapes, "%/C") || strstr(escapes, "%/E")) {
char str[(ISO9660_VOLUME_IDENTIFIER_LENGTH*3/2)+1]; char str[(ISO9660_VOLUME_IDENTIFIER_LENGTH*3/2)+1];
@@ -469,7 +470,7 @@ iso9660_fs_identify(int deviceFD, iso9660_info *info)
// we start out with. // we start out with.
char *str_iterator = str; char *str_iterator = str;
uint16 ch; uint16 ch;
// Walk thru the unicode volume name, converting to utf8 as we go. // Walk thru the unicode volume name, converting to utf8 as we go.
for (int i = 0; for (int i = 0;
(ch = B_BENDIAN_TO_HOST_INT16(((uint16*)supplementary->volume_identifier)[i])) (ch = B_BENDIAN_TO_HOST_INT16(((uint16*)supplementary->volume_identifier)[i]))
@@ -498,19 +499,19 @@ iso9660_fs_identify(int deviceFD, iso9660_info *info)
"instead of former (`%s')\n", str, "instead of former (`%s')\n", str,
info->joliet_volume_name)); info->joliet_volume_name));
} }
info->set_joliet_volume_name(str, strlen(str)); info->set_joliet_volume_name(str, strlen(str));
} // end "if Joliet VD" } // end "if Joliet VD"
break; break;
} }
case ISO9660VD_PARTITION: case ISO9660VD_PARTITION:
break; break;
case ISO9660VD_TERMINATOR: case ISO9660VD_TERMINATOR:
exit = true; exit = true;
break; break;
default: default:
break; break;
} }