Module Name: src
Committed By: maxv
Date: Sun Jun 21 13:40:25 UTC 2015
Modified Files:
src/sys/fs/hfs: libhfs.c
Log Message:
KNF
To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 src/sys/fs/hfs/libhfs.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sys/fs/hfs/libhfs.c
diff -u src/sys/fs/hfs/libhfs.c:1.13 src/sys/fs/hfs/libhfs.c:1.14
--- src/sys/fs/hfs/libhfs.c:1.13 Mon Dec 29 17:02:39 2014
+++ src/sys/fs/hfs/libhfs.c Sun Jun 21 13:40:25 2015
@@ -1,4 +1,4 @@
-/* $NetBSD: libhfs.c,v 1.13 2014/12/29 17:02:39 maxv Exp $ */
+/* $NetBSD: libhfs.c,v 1.14 2015/06/21 13:40:25 maxv Exp $ */
/*-
* Copyright (c) 2005, 2007 The NetBSD Foundation, Inc.
@@ -47,7 +47,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: libhfs.c,v 1.13 2014/12/29 17:02:39 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: libhfs.c,v 1.14 2015/06/21 13:40:25 maxv Exp $");
#include "libhfs.h"
@@ -359,7 +359,7 @@ hfslib_open_volume(
error:
if (result != 0 && isopen)
hfslib_close_volume(out_vol, cbargs);
- if(buffer!=NULL)
+ if (buffer != NULL)
hfslib_free(buffer, cbargs);
return result;
}
@@ -425,36 +425,35 @@ hfslib_path_to_cnid(hfs_volume* in_vol,
memcpy(path + path_offset, parent_thread.name.unicode,
parent_thread.name.length*2);
-
- /* Add a forward slash. The unicode string was specified in big endian
- * format, so convert to core format if necessary. */
- path[512]=0x00;
- path[513]=0x2F;
+
+ /* Add a forward slash. The unicode string was specified in big endian
+ * format, so convert to core format if necessary. */
+ path[512] = 0x00;
+ path[513] = 0x2F;
ptr = (uint16_t*)path + 256;
uchar = be16tohp((void*)&ptr);
*(ptr-1) = uchar;
total_path_length += parent_thread.name.length + 1;
-
child_cnid = parent_cnid;
}
-
+
/*
- * At this point, 'path' holds a sequence of unicode characters which
- * represent the absolute path to the given cnid. This string is missing
- * a terminating null char and an initial forward slash that represents
- * the root of the filesystem. It most likely also has extra space in
- * the beginning, due to the fact that we reserve 512 bytes for each path
- * component and won't usually use all that space. So, we allocate the
- * final string based on the actual length of the absolute path, plus four
- * additional bytes (two unichars) for the forward slash and the null char.
+ * At this point, 'path' holds a sequence of unicode characters which
+ * represent the absolute path to the given cnid. This string is missing
+ * a terminating null char and an initial forward slash that represents
+ * the root of the filesystem. It most likely also has extra space in
+ * the beginning, due to the fact that we reserve 512 bytes for each path
+ * component and won't usually use all that space. So, we allocate the
+ * final string based on the actual length of the absolute path, plus four
+ * additional bytes (two unichars) for the forward slash and the null char.
*/
-
+
*out_unicode = hfslib_malloc((total_path_length+2)*2, cbargs);
- if(*out_unicode == NULL)
+ if (*out_unicode == NULL)
goto exit;
-
+
/* copy only the bytes that are actually used */
memcpy(*out_unicode + 2, path + path_offset, total_path_length*2);
@@ -465,15 +464,14 @@ hfslib_path_to_cnid(hfs_volume* in_vol,
/* insert null char at end */
(*out_unicode)[total_path_length*2+2] = 0x00;
(*out_unicode)[total_path_length*2+3] = 0x00;
-
+
*out_length = total_path_length + 1 /* extra for forward slash */ ;
result = 0;
-
+
exit:
- if(path!=NULL)
+ if (path != NULL)
hfslib_free(path, cbargs);
-
return result;
}
@@ -486,16 +484,16 @@ hfslib_find_parent_thread(
{
hfs_catalog_key_t childkey;
- if(in_vol==NULL || in_child==0 || out_thread==NULL)
+ if (in_vol == NULL || in_child == 0 || out_thread == NULL)
return 0;
-
- if(hfslib_make_catalog_key(in_child, 0, NULL, &childkey)==0)
+
+ if (hfslib_make_catalog_key(in_child, 0, NULL, &childkey) == 0)
return 0;
-
- if(hfslib_find_catalog_record_with_key(in_vol, &childkey,
- (hfs_catalog_keyed_record_t*)out_thread, cbargs)!=0)
+
+ if (hfslib_find_catalog_record_with_key(in_vol, &childkey,
+ (hfs_catalog_keyed_record_t*)out_thread, cbargs) != 0)
return 0;
-
+
return out_thread->parent_cnid;
}
@@ -517,24 +515,24 @@ hfslib_find_catalog_record_with_cnid(
hfs_cnid_t parentcnid;
hfs_thread_record_t parentthread;
hfs_catalog_key_t key;
-
- if(in_vol==NULL || in_cnid==0 || out_rec==NULL)
+
+ if (in_vol == NULL || in_cnid == 0 || out_rec == NULL)
return 0;
parentcnid =
hfslib_find_parent_thread(in_vol, in_cnid, &parentthread, cbargs);
- if(parentcnid == 0)
+ if (parentcnid == 0)
HFS_LIBERR("could not find parent thread for cnid %i", in_cnid);
- if(hfslib_make_catalog_key(parentthread.parent_cnid,
+ if (hfslib_make_catalog_key(parentthread.parent_cnid,
parentthread.name.length, parentthread.name.unicode, &key) == 0)
HFS_LIBERR("could not make catalog search key");
-
- if(out_key!=NULL)
+
+ if (out_key != NULL)
memcpy(out_key, &key, sizeof(key));
return hfslib_find_catalog_record_with_key(in_vol, &key, out_rec, cbargs);
-
+
error:
return 1;
}
@@ -562,29 +560,29 @@ hfslib_find_catalog_record_with_key(
int keycompare;
int result;
- if(in_key==NULL || out_rec==NULL || in_vol==NULL)
+ if (in_key == NULL || out_rec == NULL || in_vol == NULL)
return 1;
-
+
result = 1;
buffer = NULL;
curkey = NULL;
extents = NULL;
recs = NULL;
recsizes = NULL;
-
+
/* The key takes up over half a kb of ram, which is a lot for the BSD
* kernel stack. So allocate it in the heap instead to play it safe. */
curkey = hfslib_malloc(sizeof(hfs_catalog_key_t), cbargs);
- if(curkey==NULL)
+ if (curkey == NULL)
HFS_LIBERR("could not allocate catalog search key");
-
+
buffer = hfslib_malloc(in_vol->chr.node_size, cbargs);
- if(buffer==NULL)
+ if (buffer == NULL)
HFS_LIBERR("could not allocate node buffer");
numextents = hfslib_get_file_extents(in_vol, HFS_CNID_CATALOG,
HFS_DATAFORK, &extents, cbargs);
- if(numextents==0)
+ if (numextents == 0)
HFS_LIBERR("could not locate fork extents");
nd.num_recs = 0;
@@ -595,27 +593,26 @@ hfslib_find_catalog_record_with_key(
dlo_print_key(in_key);
printf("\n");
#endif
-
- do
- {
+
+ do {
#ifdef DLO_DEBUG
printf("--> node %d\n", curnode);
#endif
- if(hfslib_readd_with_extents(in_vol, buffer,
+ if (hfslib_readd_with_extents(in_vol, buffer,
&bytesread,in_vol->chr.node_size, curnode * in_vol->chr.node_size,
- extents, numextents, cbargs)!=0)
+ extents, numextents, cbargs) != 0)
HFS_LIBERR("could not read catalog node #%i", curnode);
- if(hfslib_reada_node(buffer, &nd, &recs, &recsizes, HFS_CATALOG_FILE,
- in_vol, cbargs)==0)
+ if (hfslib_reada_node(buffer, &nd, &recs, &recsizes, HFS_CATALOG_FILE,
+ in_vol, cbargs) == 0)
HFS_LIBERR("could not parse catalog node #%i", curnode);
- for(recnum=0; recnum<nd.num_recs; recnum++)
+ for (recnum = 0; recnum < nd.num_recs; recnum++)
{
leaftype = nd.kind;
- if(hfslib_read_catalog_keyed_record(recs[recnum], out_rec,
- &leaftype, curkey, in_vol)==0)
+ if (hfslib_read_catalog_keyed_record(recs[recnum], out_rec,
+ &leaftype, curkey, in_vol) == 0)
HFS_LIBERR("could not read catalog record #%i",recnum);
#ifdef DLO_DEBUG
@@ -629,14 +626,13 @@ hfslib_find_catalog_record_with_key(
keycompare < 0 ? '<'
: keycompare == 0 ? '=' : '>');
#endif
-
- if(keycompare < 0)
- {
+
+ if (keycompare < 0) {
/* Check if key is less than *every* record, which should never
* happen if the volume is consistent and the key legit. */
- if(recnum==0)
+ if (recnum == 0)
HFS_LIBERR("all records greater than key");
-
+
/* Otherwise, we've found the first record that exceeds our key,
* so retrieve the previous record, which is still less... */
memcpy(out_rec, &lastrec,
@@ -646,19 +642,14 @@ hfslib_find_catalog_record_with_key(
* a key which is smaller than the search key, in the previous
* loop, to a key which is larger, in this loop, and that
* implies that our search key does not exist on the volume. */
- if(nd.kind==HFS_LEAFNODE)
+ if (nd.kind == HFS_LEAFNODE)
result = -1;
-
break;
- }
- else if(keycompare == 0)
- {
+ } else if (keycompare == 0) {
/* If leaf node, found an exact match. */
result = 0;
break;
- }
- else if(recnum==nd.num_recs-1 && keycompare > 0)
- {
+ } else if (recnum == nd.num_recs-1 && keycompare > 0) {
/* If leaf node, we've reached the last record with no match,
* which means this key is not present on the volume. */
result = -1;
@@ -667,26 +658,23 @@ hfslib_find_catalog_record_with_key(
memcpy(&lastrec, out_rec, sizeof(hfs_catalog_keyed_record_t));
}
-
- if(nd.kind==HFS_INDEXNODE)
+
+ if (nd.kind == HFS_INDEXNODE)
curnode = out_rec->child;
- else if(nd.kind==HFS_LEAFNODE)
+ else if (nd.kind == HFS_LEAFNODE)
break;
-
hfslib_free_recs(&recs, &recsizes, &nd.num_recs, cbargs);
- }
- while(nd.kind!=HFS_LEAFNODE);
-
+ } while (nd.kind != HFS_LEAFNODE);
+
/* FALLTHROUGH */
error:
- if(extents!=NULL)
+ if (extents != NULL)
hfslib_free(extents, cbargs);
hfslib_free_recs(&recs, &recsizes, &nd.num_recs, cbargs);
- if(curkey!=NULL)
+ if (curkey != NULL)
hfslib_free(curkey, cbargs);
- if(buffer!=NULL)
+ if (buffer != NULL)
hfslib_free(buffer, cbargs);
-
return result;
}
@@ -713,85 +701,77 @@ hfslib_find_extent_record_with_key(hfs_v
int keycompare;
int result;
- if(in_vol==NULL || in_key==NULL || out_rec==NULL)
+ if (in_vol == NULL || in_key == NULL || out_rec == NULL)
return 1;
-
+
result = 1;
buffer = NULL;
extents = NULL;
recs = NULL;
recsizes = NULL;
-
+
buffer = hfslib_malloc(in_vol->ehr.node_size, cbargs);
- if(buffer==NULL)
+ if (buffer == NULL)
HFS_LIBERR("could not allocate node buffer");
-
+
numextents = hfslib_get_file_extents(in_vol, HFS_CNID_EXTENTS,
HFS_DATAFORK, &extents, cbargs);
- if(numextents==0)
+ if (numextents == 0)
HFS_LIBERR("could not locate fork extents");
nd.num_recs = 0;
curnode = in_vol->ehr.root_node;
-
- do
- {
+
+ do {
hfslib_free_recs(&recs, &recsizes, &nd.num_recs, cbargs);
recnum = 0;
- if(hfslib_readd_with_extents(in_vol, buffer, &bytesread,
+ if (hfslib_readd_with_extents(in_vol, buffer, &bytesread,
in_vol->ehr.node_size, curnode * in_vol->ehr.node_size, extents,
- numextents, cbargs)!=0)
+ numextents, cbargs) != 0)
HFS_LIBERR("could not read extents overflow node #%i", curnode);
-
- if(hfslib_reada_node(buffer, &nd, &recs, &recsizes, HFS_EXTENTS_FILE,
- in_vol, cbargs)==0)
+
+ if (hfslib_reada_node(buffer, &nd, &recs, &recsizes, HFS_EXTENTS_FILE,
+ in_vol, cbargs) == 0)
HFS_LIBERR("could not parse extents overflow node #%i",curnode);
- for(recnum=0; recnum<nd.num_recs; recnum++)
- {
+ for (recnum = 0; recnum < nd.num_recs; recnum++) {
memcpy(&lastrec, out_rec, sizeof(hfs_extent_record_t));
-
- if(hfslib_read_extent_record(recs[recnum], out_rec, nd.kind,
- &curkey, in_vol)==0)
+
+ if (hfslib_read_extent_record(recs[recnum], out_rec, nd.kind,
+ &curkey, in_vol) == 0)
HFS_LIBERR("could not read extents record #%i",recnum);
keycompare = hfslib_compare_extent_keys(in_key, &curkey);
- if(keycompare < 0)
- {
+ if (keycompare < 0) {
/* this should never happen for any legitimate key */
- if(recnum==0)
+ if (recnum == 0)
return 1;
-
memcpy(out_rec, &lastrec, sizeof(hfs_extent_record_t));
-
break;
- }
- else if(keycompare == 0 ||
- (recnum==nd.num_recs-1 && keycompare > 0))
+ } else if (keycompare == 0 ||
+ (recnum == nd.num_recs-1 && keycompare > 0))
break;
}
- if(nd.kind==HFS_INDEXNODE)
+ if (nd.kind == HFS_INDEXNODE)
curnode = *((uint32_t *)out_rec); /* out_rec is a node ptr in this case */
- else if(nd.kind==HFS_LEAFNODE)
+ else if (nd.kind == HFS_LEAFNODE)
break;
else
HFS_LIBERR("unknwon node type for extents overflow node #%i",curnode);
- }
- while(nd.kind!=HFS_LEAFNODE);
-
+ } while (nd.kind != HFS_LEAFNODE);
+
result = 0;
/* FALLTHROUGH */
error:
- if(buffer!=NULL)
+ if (buffer != NULL)
hfslib_free(buffer, cbargs);
- if(extents!=NULL)
+ if (extents != NULL)
hfslib_free(extents, cbargs);
hfslib_free_recs(&recs, &recsizes, &nd.num_recs, cbargs);
-
return result;
}
@@ -812,112 +792,105 @@ hfslib_get_file_extents(hfs_volume* in_v
hfs_extent_record_t nextextentrec;
uint32_t numblocks;
uint16_t numextents, n;
-
- if(in_vol==NULL || in_cnid==0)
+
+ if (in_vol == NULL || in_cnid == 0)
return 0;
-
- if(out_extents!=NULL)
- {
+
+ if (out_extents != NULL) {
*out_extents = hfslib_malloc(sizeof(hfs_extent_descriptor_t), cbargs);
- if(*out_extents==NULL)
+ if (*out_extents == NULL)
return 0;
}
-
+
switch(in_cnid)
{
case HFS_CNID_CATALOG:
fork = in_vol->vh.catalog_file;
break;
-
+
case HFS_CNID_EXTENTS:
fork = in_vol->vh.extents_file;
break;
-
+
case HFS_CNID_ALLOCATION:
fork = in_vol->vh.allocation_file;
break;
-
+
case HFS_CNID_ATTRIBUTES:
fork = in_vol->vh.attributes_file;
break;
-
+
case HFS_CNID_STARTUP:
fork = in_vol->vh.startup_file;
break;
-
+
default:
- if(hfslib_find_parent_thread(in_vol, in_cnid, &fileparent,
- cbargs)==0)
+ if (hfslib_find_parent_thread(in_vol, in_cnid, &fileparent,
+ cbargs) == 0)
goto error;
-
- if(hfslib_make_catalog_key(fileparent.parent_cnid,
- fileparent.name.length, fileparent.name.unicode, &filekey)==0)
+
+ if (hfslib_make_catalog_key(fileparent.parent_cnid,
+ fileparent.name.length, fileparent.name.unicode, &filekey) == 0)
goto error;
-
- if(hfslib_find_catalog_record_with_key(in_vol, &filekey,
- (hfs_catalog_keyed_record_t*)&file, cbargs)!=0)
+
+ if (hfslib_find_catalog_record_with_key(in_vol, &filekey,
+ (hfs_catalog_keyed_record_t*)&file, cbargs) != 0)
goto error;
-
+
/* only files have extents, not folders or threads */
- if(file.rec_type!=HFS_REC_FILE)
+ if (file.rec_type != HFS_REC_FILE)
goto error;
-
- if(in_forktype==HFS_DATAFORK)
+
+ if (in_forktype == HFS_DATAFORK)
fork = file.data_fork;
- else if(in_forktype==HFS_RSRCFORK)
+ else if (in_forktype == HFS_RSRCFORK)
fork = file.rsrc_fork;
}
-
+
numextents = 0;
numblocks = 0;
memcpy(&nextextentrec, &fork.extents, sizeof(hfs_extent_record_t));
- while(1)
- {
- for(n=0; n<8; n++)
- {
- if(nextextentrec[n].block_count==0)
+ while (1) {
+ for (n = 0; n < 8; n++) {
+ if (nextextentrec[n].block_count == 0)
break;
-
numblocks += nextextentrec[n].block_count;
}
-
- if(out_extents!=NULL)
- {
+ if (out_extents != NULL) {
dummy = hfslib_realloc(*out_extents,
(numextents+n) * sizeof(hfs_extent_descriptor_t),
cbargs);
- if(dummy==NULL)
+ if (dummy == NULL)
goto error;
*out_extents = dummy;
-
+
memcpy(*out_extents + numextents,
&nextextentrec, n*sizeof(hfs_extent_descriptor_t));
}
numextents += n;
- if(numblocks >= fork.total_blocks)
+ if (numblocks >= fork.total_blocks)
break;
-
- if(hfslib_make_extent_key(in_cnid, in_forktype, numblocks,
- &extentkey)==0)
+
+ if (hfslib_make_extent_key(in_cnid, in_forktype, numblocks,
+ &extentkey) == 0)
goto error;
-
- if(hfslib_find_extent_record_with_key(in_vol, &extentkey,
- &nextextentrec, cbargs)!=0)
+
+ if (hfslib_find_extent_record_with_key(in_vol, &extentkey,
+ &nextextentrec, cbargs) != 0)
goto error;
}
goto exit;
error:
- if(out_extents!=NULL && *out_extents!=NULL)
- {
+ if (out_extents != NULL && *out_extents != NULL) {
hfslib_free(*out_extents, cbargs);
*out_extents = NULL;
}
return 0;
-
+
exit:
return numextents;
}
@@ -966,9 +939,9 @@ hfslib_get_directory_contents(
int keycompare;
int result;
- if(in_vol==NULL || in_dir==0 || out_numchildren==NULL)
+ if (in_vol == NULL || in_dir == 0 || out_numchildren == NULL)
return 1;
-
+
result = 1;
buffer = NULL;
extents = NULL;
@@ -976,61 +949,58 @@ hfslib_get_directory_contents(
recs = NULL;
recsizes = NULL;
*out_numchildren = 0;
- if(out_children!=NULL)
+ if (out_children != NULL)
*out_children = NULL;
- if(out_childnames!=NULL)
+ if (out_childnames != NULL)
*out_childnames = NULL;
buffer = hfslib_malloc(in_vol->chr.node_size, cbargs);
- if(buffer==NULL)
+ if (buffer == NULL)
HFS_LIBERR("could not allocate node buffer");
numextents = hfslib_get_file_extents(in_vol, HFS_CNID_CATALOG,
HFS_DATAFORK, &extents, cbargs);
- if(numextents==0)
+ if (numextents == 0)
HFS_LIBERR("could not locate fork extents");
nd.num_recs = 0;
curnode = in_vol->chr.root_node;
-
- while(1)
+
+ while (1)
{
hfslib_free_recs(&recs, &recsizes, &nd.num_recs, cbargs);
recnum = 0;
- if(hfslib_readd_with_extents(in_vol, buffer, &bytesread,
+ if (hfslib_readd_with_extents(in_vol, buffer, &bytesread,
in_vol->chr.node_size, curnode * in_vol->chr.node_size, extents,
- numextents, cbargs)!=0)
+ numextents, cbargs) != 0)
HFS_LIBERR("could not read catalog node #%i", curnode);
- if(hfslib_reada_node(buffer, &nd, &recs, &recsizes, HFS_CATALOG_FILE,
- in_vol, cbargs)==0)
+ if (hfslib_reada_node(buffer, &nd, &recs, &recsizes, HFS_CATALOG_FILE,
+ in_vol, cbargs) == 0)
HFS_LIBERR("could not parse catalog node #%i", curnode);
- for(recnum=0; recnum<nd.num_recs; recnum++)
+ for (recnum = 0; recnum < nd.num_recs; recnum++)
{
leaftype = nd.kind; /* needed b/c leaftype might be modified now */
- if(hfslib_read_catalog_keyed_record(recs[recnum], &currec,
- &leaftype, &curkey, in_vol)==0)
+ if (hfslib_read_catalog_keyed_record(recs[recnum], &currec,
+ &leaftype, &curkey, in_vol) == 0)
HFS_LIBERR("could not read cat record %i:%i", curnode, recnum);
- if(nd.kind==HFS_INDEXNODE)
+ if (nd.kind == HFS_INDEXNODE)
{
keycompare = in_dir - curkey.parent_cnid;
- if(keycompare < 0)
- {
+ if (keycompare < 0) {
/* Check if key is less than *every* record, which should
* never happen if the volume and key are good. */
- if(recnum==0)
+ if (recnum == 0)
HFS_LIBERR("all records greater than key");
-
+
/* Otherwise, we've found the first record that exceeds our
* key, so retrieve the previous, lesser record. */
curnode = lastnode;
break;
- }
- else if(keycompare == 0)
- {
+ } else if (keycompare == 0) {
/*
* Normally, if we were doing a typical catalog lookup with
* both a parent cnid AND a name, keycompare==0 would be an
@@ -1046,19 +1016,15 @@ hfslib_get_directory_contents(
*/
curnode = lastnode;
break;
- }
- else if (recnum==nd.num_recs-1 && keycompare > 0)
- {
+ } else if (recnum == nd.num_recs-1 && keycompare > 0) {
/* Descend to child node if we found an exact match, or if
* this is the last pointer record. */
curnode = currec.child;
break;
}
-
+
lastnode = currec.child;
- }
- else
- {
+ } else {
/*
* We have now descended down the hierarchy of index nodes into
* the leaf node that contains the first catalog record with a
@@ -1070,39 +1036,36 @@ hfslib_get_directory_contents(
*/
curnode = nd.flink;
- if(curkey.parent_cnid<in_dir)
+ if (curkey.parent_cnid < in_dir) {
continue;
- else if(curkey.parent_cnid==in_dir)
- {
+ } else if (curkey.parent_cnid == in_dir) {
/* Hide files/folders which are supposed to be invisible
* to users, according to the hfs+ spec. */
- if(hfslib_is_private_file(&curkey))
+ if (hfslib_is_private_file(&curkey))
continue;
-
+
/* leaftype has now been set to the catalog record type */
- if(leaftype==HFS_REC_FLDR || leaftype==HFS_REC_FILE)
+ if (leaftype == HFS_REC_FLDR || leaftype == HFS_REC_FILE)
{
(*out_numchildren)++;
-
- if(out_children!=NULL)
- {
+
+ if (out_children != NULL) {
ptr = hfslib_realloc(*out_children,
*out_numchildren *
sizeof(hfs_catalog_keyed_record_t), cbargs);
- if(ptr==NULL)
+ if (ptr == NULL)
HFS_LIBERR("could not allocate child record");
*out_children = ptr;
-
+
memcpy(&((*out_children)[*out_numchildren-1]),
&currec, sizeof(hfs_catalog_keyed_record_t));
}
- if(out_childnames!=NULL)
- {
+ if (out_childnames != NULL) {
ptr = hfslib_realloc(*out_childnames,
*out_numchildren * sizeof(hfs_unistr255_t),
cbargs);
- if(ptr==NULL)
+ if (ptr == NULL)
HFS_LIBERR("could not allocate child name");
*out_childnames = ptr;
@@ -1121,37 +1084,34 @@ hfslib_get_directory_contents(
}
result = 0;
-
- goto exit;
+ goto exit;
error:
- if(out_children!=NULL && *out_children!=NULL)
+ if (out_children != NULL && *out_children != NULL)
hfslib_free(*out_children, cbargs);
- if(out_childnames!=NULL && *out_childnames!=NULL)
+ if (out_childnames != NULL && *out_childnames != NULL)
hfslib_free(*out_childnames, cbargs);
-
/* FALLTHROUGH */
exit:
- if(extents!=NULL)
+ if (extents != NULL)
hfslib_free(extents, cbargs);
hfslib_free_recs(&recs, &recsizes, &nd.num_recs, cbargs);
- if(buffer!=NULL)
+ if (buffer != NULL)
hfslib_free(buffer, cbargs);
-
return result;
}
int
hfslib_is_journal_clean(hfs_volume* in_vol)
{
- if(in_vol==NULL)
+ if (in_vol == NULL)
return 0;
-
+
/* return true if no journal */
- if(!(in_vol->vh.attributes & (1<<HFS_VOL_JOURNALED)))
+ if (!(in_vol->vh.attributes & (1<<HFS_VOL_JOURNALED)))
return 1;
-
+
return (in_vol->jh.start == in_vol->jh.end);
}
@@ -1166,27 +1126,25 @@ hfslib_is_private_file(hfs_catalog_key_t
{
hfs_catalog_key_t* curkey = NULL;
int i = 0;
-
+
/*
* According to the HFS+ spec to date, all special objects are located in
* the root directory of the volume, so don't bother going further if the
* requested object is not.
*/
- if(filekey->parent_cnid != HFS_CNID_ROOT_FOLDER)
+ if (filekey->parent_cnid != HFS_CNID_ROOT_FOLDER)
return 0;
-
- while((curkey = hfs_gPrivateObjectKeys[i]) != NULL)
- {
+
+ while ((curkey = hfs_gPrivateObjectKeys[i]) != NULL) {
/* XXX Always use binary compare here, or use volume's specific key
* XXX comparison routine? */
- if(filekey->name.length == curkey->name.length
- && memcmp(filekey->name.unicode, curkey->name.unicode,
- 2 * curkey->name.length)==0)
+ if (filekey->name.length == curkey->name.length &&
+ memcmp(filekey->name.unicode, curkey->name.unicode,
+ 2 * curkey->name.length) == 0)
return 1;
-
i++;
}
-
+
return 0;
}
@@ -1217,12 +1175,12 @@ hfslib_read_volume_header(void* in_bytes
void* ptr;
size_t last_bytes_read;
int i;
-
- if(in_bytes==NULL || out_header==NULL)
+
+ if (in_bytes == NULL || out_header == NULL)
return 0;
-
+
ptr = in_bytes;
-
+
out_header->signature = be16tohp(&ptr);
out_header->version = be16tohp(&ptr);
out_header->attributes = be32tohp(&ptr);
@@ -1248,34 +1206,34 @@ hfslib_read_volume_header(void* in_bytes
out_header->write_count = be32tohp(&ptr);
out_header->encodings = be64tohp(&ptr);
- for(i=0;i<8;i++)
+ for (i =0 ; i < 8; i++)
out_header->finder_info[i] = be32tohp(&ptr);
- if((last_bytes_read = hfslib_read_fork_descriptor(ptr,
- &out_header->allocation_file))==0)
+ if ((last_bytes_read = hfslib_read_fork_descriptor(ptr,
+ &out_header->allocation_file)) == 0)
return 0;
ptr = (uint8_t*)ptr + last_bytes_read;
-
- if((last_bytes_read = hfslib_read_fork_descriptor(ptr,
- &out_header->extents_file))==0)
+
+ if ((last_bytes_read = hfslib_read_fork_descriptor(ptr,
+ &out_header->extents_file)) == 0)
return 0;
ptr = (uint8_t*)ptr + last_bytes_read;
-
- if((last_bytes_read = hfslib_read_fork_descriptor(ptr,
- &out_header->catalog_file))==0)
+
+ if ((last_bytes_read = hfslib_read_fork_descriptor(ptr,
+ &out_header->catalog_file)) == 0)
return 0;
ptr = (uint8_t*)ptr + last_bytes_read;
-
- if((last_bytes_read = hfslib_read_fork_descriptor(ptr,
- &out_header->attributes_file))==0)
+
+ if ((last_bytes_read = hfslib_read_fork_descriptor(ptr,
+ &out_header->attributes_file)) == 0)
return 0;
ptr = (uint8_t*)ptr + last_bytes_read;
-
- if((last_bytes_read = hfslib_read_fork_descriptor(ptr,
- &out_header->startup_file))==0)
+
+ if ((last_bytes_read = hfslib_read_fork_descriptor(ptr,
+ &out_header->startup_file)) == 0)
return 0;
ptr = (uint8_t*)ptr + last_bytes_read;
-
+
return ((uint8_t*)ptr - (uint8_t*)in_bytes);
}
@@ -1292,69 +1250,67 @@ size_t
hfslib_read_master_directory_block(void* in_bytes,
hfs_hfs_master_directory_block_t* out_mdr)
{
- void* ptr;
- int i;
-
- if(in_bytes==NULL || out_mdr==NULL)
- return 0;
-
- ptr = in_bytes;
-
- out_mdr->signature = be16tohp(&ptr);
-
- out_mdr->date_created = be32tohp(&ptr);
- out_mdr->date_modified = be32tohp(&ptr);
-
- out_mdr->attributes = be16tohp(&ptr);
- out_mdr->root_file_count = be16tohp(&ptr);
- out_mdr->volume_bitmap = be16tohp(&ptr);
-
- out_mdr->next_alloc_block = be16tohp(&ptr);
- out_mdr->total_blocks = be16tohp(&ptr);
- out_mdr->block_size = be32tohp(&ptr);
-
- out_mdr->clump_size = be32tohp(&ptr);
- out_mdr->first_block = be16tohp(&ptr);
- out_mdr->next_cnid = be32tohp(&ptr);
- out_mdr->free_blocks = be16tohp(&ptr);
-
- memcpy(out_mdr->volume_name, ptr, 28);
- ptr = (char *)ptr + 28;
-
- out_mdr->date_backedup = be32tohp(&ptr);
- out_mdr->backup_seqnum = be16tohp(&ptr);
-
- out_mdr->write_count = be32tohp(&ptr);
-
- out_mdr->extents_clump_size = be32tohp(&ptr);
- out_mdr->catalog_clump_size = be32tohp(&ptr);
-
- out_mdr->root_folder_count = be16tohp(&ptr);
- out_mdr->file_count = be32tohp(&ptr);
- out_mdr->folder_count = be32tohp(&ptr);
-
- for(i=0;i<8;i++)
- out_mdr->finder_info[i] = be32tohp(&ptr);
-
- out_mdr->embedded_signature = be16tohp(&ptr);
- out_mdr->embedded_extent.start_block = be16tohp(&ptr);
- out_mdr->embedded_extent.block_count = be16tohp(&ptr);
-
- out_mdr->extents_size = be32tohp(&ptr);
- for (i = 0; i < 3; i++)
- {
- out_mdr->extents_extents[i].start_block = be16tohp(&ptr);
- out_mdr->extents_extents[i].block_count = be16tohp(&ptr);
- }
-
- out_mdr->catalog_size = be32tohp(&ptr);
- for (i = 0; i < 3; i++)
- {
- out_mdr->catalog_extents[i].start_block = be16tohp(&ptr);
- out_mdr->catalog_extents[i].block_count = be16tohp(&ptr);
- }
+ void* ptr;
+ int i;
+
+ if (in_bytes == NULL || out_mdr == NULL)
+ return 0;
+
+ ptr = in_bytes;
+
+ out_mdr->signature = be16tohp(&ptr);
+
+ out_mdr->date_created = be32tohp(&ptr);
+ out_mdr->date_modified = be32tohp(&ptr);
+
+ out_mdr->attributes = be16tohp(&ptr);
+ out_mdr->root_file_count = be16tohp(&ptr);
+ out_mdr->volume_bitmap = be16tohp(&ptr);
+
+ out_mdr->next_alloc_block = be16tohp(&ptr);
+ out_mdr->total_blocks = be16tohp(&ptr);
+ out_mdr->block_size = be32tohp(&ptr);
+
+ out_mdr->clump_size = be32tohp(&ptr);
+ out_mdr->first_block = be16tohp(&ptr);
+ out_mdr->next_cnid = be32tohp(&ptr);
+ out_mdr->free_blocks = be16tohp(&ptr);
+
+ memcpy(out_mdr->volume_name, ptr, 28);
+ ptr = (char *)ptr + 28;
- return ((uint8_t*)ptr - (uint8_t*)in_bytes);
+ out_mdr->date_backedup = be32tohp(&ptr);
+ out_mdr->backup_seqnum = be16tohp(&ptr);
+
+ out_mdr->write_count = be32tohp(&ptr);
+
+ out_mdr->extents_clump_size = be32tohp(&ptr);
+ out_mdr->catalog_clump_size = be32tohp(&ptr);
+
+ out_mdr->root_folder_count = be16tohp(&ptr);
+ out_mdr->file_count = be32tohp(&ptr);
+ out_mdr->folder_count = be32tohp(&ptr);
+
+ for (i = 0; i < 8; i++)
+ out_mdr->finder_info[i] = be32tohp(&ptr);
+
+ out_mdr->embedded_signature = be16tohp(&ptr);
+ out_mdr->embedded_extent.start_block = be16tohp(&ptr);
+ out_mdr->embedded_extent.block_count = be16tohp(&ptr);
+
+ out_mdr->extents_size = be32tohp(&ptr);
+ for (i = 0; i < 3; i++) {
+ out_mdr->extents_extents[i].start_block = be16tohp(&ptr);
+ out_mdr->extents_extents[i].block_count = be16tohp(&ptr);
+ }
+
+ out_mdr->catalog_size = be32tohp(&ptr);
+ for (i = 0; i < 3; i++) {
+ out_mdr->catalog_extents[i].start_block = be16tohp(&ptr);
+ out_mdr->catalog_extents[i].block_count = be16tohp(&ptr);
+ }
+
+ return ((uint8_t*)ptr - (uint8_t*)in_bytes);
}
/*
@@ -1406,21 +1362,21 @@ hfslib_reada_node(void* in_bytes,
uint16_t free_space_offset; /* offset to free space in node */
int keysizefieldsize;
int i;
-
+
numrecords = 0;
rec_offsets = NULL;
- if(out_record_ptrs_array!=NULL)
+ if (out_record_ptrs_array != NULL)
*out_record_ptrs_array = NULL;
- if(out_record_ptr_sizes_array!=NULL)
+ if (out_record_ptr_sizes_array != NULL)
*out_record_ptr_sizes_array = NULL;
-
- if(in_bytes==NULL || inout_volume==NULL || out_node_descriptor==NULL
- || (out_record_ptrs_array==NULL && out_record_ptr_sizes_array!=NULL)
- || (out_record_ptrs_array!=NULL && out_record_ptr_sizes_array==NULL) )
+
+ if (in_bytes == NULL || inout_volume == NULL || out_node_descriptor == NULL
+ || (out_record_ptrs_array == NULL && out_record_ptr_sizes_array != NULL)
+ || (out_record_ptrs_array != NULL && out_record_ptr_sizes_array == NULL) )
goto error;
-
+
ptr = in_bytes;
-
+
out_node_descriptor->flink = be32tohp(&ptr);
out_node_descriptor->blink = be32tohp(&ptr);
out_node_descriptor->kind = *(((int8_t*)ptr));
@@ -1429,9 +1385,9 @@ hfslib_reada_node(void* in_bytes,
ptr = (uint8_t*)ptr + 1;
out_node_descriptor->num_recs = be16tohp(&ptr);
out_node_descriptor->reserved = be16tohp(&ptr);
-
+
numrecords = out_node_descriptor->num_recs;
-
+
/*
* To go any further, we will need to know the size of this node, as well
* as the width of keyed records' key_len parameters for this btree. If
@@ -1441,24 +1397,24 @@ hfslib_reada_node(void* in_bytes,
* extent files, respectively. However, if this is a header node, this
* information has not yet been determined, so this is the place to do it.
*/
- if(out_node_descriptor->kind == HFS_HEADERNODE)
+ if (out_node_descriptor->kind == HFS_HEADERNODE)
{
hfs_header_record_t hr;
void* header_rec_offset[1];
uint16_t header_rec_size[1];
-
+
/* sanity check to ensure this is a good header node */
- if(numrecords!=3)
+ if (numrecords != 3)
HFS_LIBERR("header node does not have exactly 3 records");
-
+
header_rec_offset[0] = ptr;
header_rec_size[0] = sizeof(hfs_header_record_t);
-
+
last_bytes_read = hfslib_read_header_node(header_rec_offset,
header_rec_size, 1, &hr, NULL, NULL);
- if(last_bytes_read==0)
+ if (last_bytes_read == 0)
HFS_LIBERR("could not read header node");
-
+
switch(in_parent_file)
{
case HFS_CATALOG_FILE:
@@ -1467,14 +1423,14 @@ hfslib_reada_node(void* in_bytes,
(hr.attributes & HFS_BIG_KEYS_MASK) ?
sizeof(uint16_t):sizeof(uint8_t);
break;
-
+
case HFS_EXTENTS_FILE:
inout_volume->ehr.node_size = hr.node_size;
inout_volume->extkeysizefieldsize =
(hr.attributes & HFS_BIG_KEYS_MASK) ?
sizeof(uint16_t):sizeof(uint8_t);
break;
-
+
case HFS_ATTRIBUTES_FILE:
default:
HFS_LIBERR("invalid parent file type specified");
@@ -1482,18 +1438,18 @@ hfslib_reada_node(void* in_bytes,
}
}
- switch(in_parent_file)
+ switch (in_parent_file)
{
case HFS_CATALOG_FILE:
nodesize = inout_volume->chr.node_size;
keysizefieldsize = inout_volume->catkeysizefieldsize;
break;
-
+
case HFS_EXTENTS_FILE:
nodesize = inout_volume->ehr.node_size;
keysizefieldsize = inout_volume->extkeysizefieldsize;
break;
-
+
case HFS_ATTRIBUTES_FILE:
default:
HFS_LIBERR("invalid parent file type specified");
@@ -1507,24 +1463,24 @@ hfslib_reada_node(void* in_bytes,
* get at the node descriptor, but then tries to call it again on a non-
* header node without first setting inout_volume->cat/extnodesize.
*/
- if(out_record_ptrs_array==NULL)
+ if (out_record_ptrs_array == NULL)
return ((uint8_t*)ptr - (uint8_t*)in_bytes);
-
+
rec_offsets = hfslib_malloc(numrecords * sizeof(uint16_t), cbargs);
*out_record_ptr_sizes_array =
hfslib_malloc(numrecords * sizeof(uint16_t), cbargs);
- if(rec_offsets==NULL || *out_record_ptr_sizes_array==NULL)
+ if (rec_offsets == NULL || *out_record_ptr_sizes_array == NULL)
HFS_LIBERR("could not allocate node record offsets");
*out_record_ptrs_array = hfslib_malloc(numrecords * sizeof(void*), cbargs);
- if(*out_record_ptrs_array==NULL)
+ if (*out_record_ptrs_array == NULL)
HFS_LIBERR("could not allocate node records");
-
+
last_bytes_read = hfslib_reada_node_offsets((uint8_t*)in_bytes + nodesize -
numrecords * sizeof(uint16_t), rec_offsets);
- if(last_bytes_read==0)
+ if (last_bytes_read == 0)
HFS_LIBERR("could not read node record offsets");
-
+
/* The size of the last record (i.e. the first one listed in the offsets)
* must be determined using the offset to the node's free space. */
free_space_offset = be16toh(*(uint16_t*)((uint8_t*)in_bytes + nodesize -
@@ -1532,20 +1488,19 @@ hfslib_reada_node(void* in_bytes,
(*out_record_ptr_sizes_array)[numrecords-1] =
free_space_offset - rec_offsets[0];
- for(i=1;i<numrecords;i++)
- {
+ for (i = 1; i < numrecords; i++) {
(*out_record_ptr_sizes_array)[numrecords-i-1] =
rec_offsets[i-1] - rec_offsets[i];
}
- for(i=0;i<numrecords;i++)
+ for (i = 0; i < numrecords; i++)
{
(*out_record_ptrs_array)[i] =
hfslib_malloc((*out_record_ptr_sizes_array)[i], cbargs);
- if((*out_record_ptrs_array)[i]==NULL)
+ if ((*out_record_ptrs_array)[i] == NULL)
HFS_LIBERR("could not allocate node record #%i",i);
-
+
/*
* If this is a keyed node (i.e., a leaf or index node), there are two
* boundary rules that each record must obey:
@@ -1560,25 +1515,24 @@ hfslib_reada_node(void* in_bytes,
* and correspondingly decrement the record size. In the second case
* we decrement the record size.
*/
- if(out_node_descriptor->kind == HFS_LEAFNODE ||
- out_node_descriptor->kind == HFS_INDEXNODE)
+ if (out_node_descriptor->kind == HFS_LEAFNODE ||
+ out_node_descriptor->kind == HFS_INDEXNODE)
{
hfs_catalog_key_t reckey;
uint16_t rectype;
-
+
rectype = out_node_descriptor->kind;
last_bytes_read = hfslib_read_catalog_keyed_record(ptr, NULL,
&rectype, &reckey, inout_volume);
- if(last_bytes_read==0)
+ if (last_bytes_read == 0)
HFS_LIBERR("could not read node record");
-
- if((reckey.key_len + keysizefieldsize) % 2 == 1)
- {
+
+ if ((reckey.key_len + keysizefieldsize) % 2 == 1) {
ptr = (uint8_t*)ptr + 1;
(*out_record_ptr_sizes_array)[i]--;
}
-
- if((*out_record_ptr_sizes_array)[i] % 2 == 1)
+
+ if ((*out_record_ptr_sizes_array)[i] % 2 == 1)
(*out_record_ptr_sizes_array)[i]--;
}
@@ -1588,7 +1542,7 @@ hfslib_reada_node(void* in_bytes,
}
goto exit;
-
+
error:
hfslib_free_recs(out_record_ptrs_array, out_record_ptr_sizes_array,
&numrecords, cbargs);
@@ -1598,11 +1552,10 @@ error:
/* warn("error occurred in hfslib_reada_node()"); */
/* FALLTHROUGH */
-
+
exit:
- if(rec_offsets!=NULL)
+ if (rec_offsets != NULL)
hfslib_free(rec_offsets, cbargs);
-
return ((uint8_t*)ptr - (uint8_t*)in_bytes);
}
@@ -1616,26 +1569,24 @@ size_t
hfslib_reada_node_offsets(void* in_bytes, uint16_t* out_offset_array)
{
void* ptr;
-
- if(in_bytes==NULL || out_offset_array==NULL)
+
+ if (in_bytes == NULL || out_offset_array == NULL)
return 0;
-
+
ptr = in_bytes;
/*
- * The offset for record 0 (which is the very last offset in the node) is
- * always equal to 14, the size of the node descriptor. So, once we hit
- * offset=14, we know this is the last offset. In this way, we don't need
- * to know the number of records beforehand.
- */
+ * The offset for record 0 (which is the very last offset in the node) is
+ * always equal to 14, the size of the node descriptor. So, once we hit
+ * offset=14, we know this is the last offset. In this way, we don't need
+ * to know the number of records beforehand.
+ */
out_offset_array--;
- do
- {
+ do {
out_offset_array++;
*out_offset_array = be16tohp(&ptr);
- }
- while(*out_offset_array != (uint16_t)14);
-
+ } while (*out_offset_array != (uint16_t)14);
+
return ((uint8_t*)ptr - (uint8_t*)in_bytes);
}
@@ -1657,9 +1608,9 @@ hfslib_read_header_node(void** in_recs,
KASSERT(out_hr != NULL);
- if(in_recs==NULL || in_rec_sizes==NULL)
+ if (in_recs == NULL || in_rec_sizes == NULL)
return 0;
-
+
ptr = in_recs[0];
out_hr->tree_depth = be16tohp(&ptr);
out_hr->root_node = be32tohp(&ptr);
@@ -1677,17 +1628,15 @@ hfslib_read_header_node(void** in_recs,
out_hr->keycomp_type = *(((uint8_t*)ptr));
ptr = (uint8_t*)ptr + 1;
out_hr->attributes = be32tohp(&ptr);
- for(i=0;i<16;i++)
+ for (i = 0; i < 16; i++)
out_hr->reserved2[i] = be32tohp(&ptr);
- if(out_userdata!=NULL)
- {
+ if (out_userdata != NULL) {
memcpy(out_userdata, in_recs[1], in_rec_sizes[1]);
}
ptr = (uint8_t*)ptr + in_rec_sizes[1]; /* size of user data record */
- if(out_map!=NULL)
- {
+ if (out_map != NULL) {
memcpy(out_map, in_recs[2], in_rec_sizes[2]);
}
ptr = (uint8_t*)ptr + in_rec_sizes[2]; /* size of map record */
@@ -1714,51 +1663,47 @@ hfslib_read_catalog_keyed_record(
{
void* ptr;
size_t last_bytes_read;
-
- if(in_bytes==NULL || out_key==NULL || inout_rectype==NULL)
+
+ if (in_bytes == NULL || out_key == NULL || inout_rectype == NULL)
return 0;
-
+
ptr = in_bytes;
/* For HFS+, the key length is always a 2-byte number. This is indicated
* by the HFS_BIG_KEYS_MASK bit in the attributes field of the catalog
* header record. However, we just assume this bit is set, since all HFS+
* volumes should have it set anyway. */
- if(in_volume->catkeysizefieldsize == sizeof(uint16_t))
+ if (in_volume->catkeysizefieldsize == sizeof(uint16_t))
out_key->key_len = be16tohp(&ptr);
else if (in_volume->catkeysizefieldsize == sizeof(uint8_t)) {
out_key->key_len = *(((uint8_t*)ptr));
ptr = (uint8_t*)ptr + 1;
}
-
+
out_key->parent_cnid = be32tohp(&ptr);
last_bytes_read = hfslib_read_unistr255(ptr, &out_key->name);
- if(last_bytes_read==0)
+ if (last_bytes_read == 0)
return 0;
ptr = (uint8_t*)ptr + last_bytes_read;
/* don't waste time if the user just wanted the key and/or record type */
- if(out_recdata==NULL)
- {
- if(*inout_rectype == HFS_LEAFNODE)
+ if (out_recdata == NULL) {
+ if (*inout_rectype == HFS_LEAFNODE)
*inout_rectype = be16tohp(&ptr);
- else if(*inout_rectype != HFS_INDEXNODE)
+ else if (*inout_rectype != HFS_INDEXNODE)
return 0; /* should not happen if we were given valid arguments */
return ((uint8_t*)ptr - (uint8_t*)in_bytes);
}
- if(*inout_rectype == HFS_INDEXNODE)
- {
+ if (*inout_rectype == HFS_INDEXNODE) {
out_recdata->child = be32tohp(&ptr);
- }
- else
- {
+ } else {
/* first need to determine what kind of record this is */
*inout_rectype = be16tohp(&ptr);
out_recdata->type = *inout_rectype;
-
+
switch(out_recdata->type)
{
case HFS_REC_FLDR:
@@ -1771,30 +1716,30 @@ hfslib_read_catalog_keyed_record(
out_recdata->folder.date_attrib_mod = be32tohp(&ptr);
out_recdata->folder.date_accessed = be32tohp(&ptr);
out_recdata->folder.date_backedup = be32tohp(&ptr);
-
+
last_bytes_read = hfslib_read_bsd_data(ptr,
&out_recdata->folder.bsd);
- if(last_bytes_read==0)
+ if (last_bytes_read == 0)
return 0;
ptr = (uint8_t*)ptr + last_bytes_read;
-
+
last_bytes_read = hfslib_read_folder_userinfo(ptr,
&out_recdata->folder.user_info);
- if(last_bytes_read==0)
+ if (last_bytes_read == 0)
return 0;
ptr = (uint8_t*)ptr + last_bytes_read;
-
+
last_bytes_read = hfslib_read_folder_finderinfo(ptr,
&out_recdata->folder.finder_info);
- if(last_bytes_read==0)
+ if (last_bytes_read == 0)
return 0;
ptr = (uint8_t*)ptr + last_bytes_read;
-
+
out_recdata->folder.text_encoding = be32tohp(&ptr);
out_recdata->folder.reserved = be32tohp(&ptr);
}
break;
-
+
case HFS_REC_FILE:
{
out_recdata->file.flags = be16tohp(&ptr);
@@ -1805,62 +1750,62 @@ hfslib_read_catalog_keyed_record(
out_recdata->file.date_attrib_mod = be32tohp(&ptr);
out_recdata->file.date_accessed = be32tohp(&ptr);
out_recdata->file.date_backedup = be32tohp(&ptr);
-
+
last_bytes_read = hfslib_read_bsd_data(ptr,
&out_recdata->file.bsd);
- if(last_bytes_read==0)
+ if (last_bytes_read == 0)
return 0;
ptr = (uint8_t*)ptr + last_bytes_read;
-
+
last_bytes_read = hfslib_read_file_userinfo(ptr,
&out_recdata->file.user_info);
- if(last_bytes_read==0)
+ if (last_bytes_read == 0)
return 0;
ptr = (uint8_t*)ptr + last_bytes_read;
-
+
last_bytes_read = hfslib_read_file_finderinfo(ptr,
&out_recdata->file.finder_info);
- if(last_bytes_read==0)
+ if (last_bytes_read == 0)
return 0;
ptr = (uint8_t*)ptr + last_bytes_read;
-
+
out_recdata->file.text_encoding = be32tohp(&ptr);
out_recdata->file.reserved2 = be32tohp(&ptr);
-
+
last_bytes_read = hfslib_read_fork_descriptor(ptr,
&out_recdata->file.data_fork);
- if(last_bytes_read==0)
+ if (last_bytes_read == 0)
return 0;
ptr = (uint8_t*)ptr + last_bytes_read;
-
+
last_bytes_read = hfslib_read_fork_descriptor(ptr,
&out_recdata->file.rsrc_fork);
- if(last_bytes_read==0)
+ if (last_bytes_read == 0)
return 0;
ptr = (uint8_t*)ptr + last_bytes_read;
}
break;
-
+
case HFS_REC_FLDR_THREAD:
case HFS_REC_FILE_THREAD:
{
out_recdata->thread.reserved = be16tohp(&ptr);
out_recdata->thread.parent_cnid = be32tohp(&ptr);
-
+
last_bytes_read = hfslib_read_unistr255(ptr,
&out_recdata->thread.name);
- if(last_bytes_read==0)
+ if (last_bytes_read == 0)
return 0;
ptr = (uint8_t*)ptr + last_bytes_read;
}
break;
-
+
default:
return 1;
/* NOTREACHED */
}
}
-
+
return ((uint8_t*)ptr - (uint8_t*)in_bytes);
}
@@ -1875,24 +1820,24 @@ hfslib_read_extent_record(
{
void* ptr;
size_t last_bytes_read;
-
- if(in_bytes==NULL || out_key==NULL
- || (in_nodekind!=HFS_LEAFNODE && in_nodekind!=HFS_INDEXNODE))
+
+ if (in_bytes == NULL || out_key == NULL
+ || (in_nodekind!=HFS_LEAFNODE && in_nodekind!=HFS_INDEXNODE))
return 0;
-
+
ptr = in_bytes;
- /* For HFS+, the key length is always a 2-byte number. This is indicated
- * by the HFS_BIG_KEYS_MASK bit in the attributes field of the extent
- * overflow header record. However, we just assume this bit is set, since
- * all HFS+ volumes should have it set anyway. */
- if(in_volume->extkeysizefieldsize == sizeof(uint16_t))
+ /* For HFS+, the key length is always a 2-byte number. This is indicated
+ * by the HFS_BIG_KEYS_MASK bit in the attributes field of the extent
+ * overflow header record. However, we just assume this bit is set, since
+ * all HFS+ volumes should have it set anyway. */
+ if (in_volume->extkeysizefieldsize == sizeof(uint16_t))
out_key->key_length = be16tohp(&ptr);
else if (in_volume->extkeysizefieldsize == sizeof(uint8_t)) {
out_key->key_length = *(((uint8_t*)ptr));
ptr = (uint8_t*)ptr + 1;
}
-
+
out_key->fork_type = *(((uint8_t*)ptr));
ptr = (uint8_t*)ptr + 1;
out_key->padding = *(((uint8_t*)ptr));
@@ -1901,25 +1846,22 @@ hfslib_read_extent_record(
out_key->start_block = be32tohp(&ptr);
/* don't waste time if the user just wanted the key */
- if(out_rec==NULL)
+ if (out_rec == NULL)
return ((uint8_t*)ptr - (uint8_t*)in_bytes);
- if(in_nodekind==HFS_LEAFNODE)
- {
+ if (in_nodekind == HFS_LEAFNODE) {
last_bytes_read = hfslib_read_extent_descriptors(ptr, out_rec);
- if(last_bytes_read==0)
+ if (last_bytes_read == 0)
return 0;
ptr = (uint8_t*)ptr + last_bytes_read;
- }
- else
- {
+ } else {
/* XXX: this is completely bogus */
- /* (uint32_t*)*out_rec = be32tohp(&ptr); */
+ /* (uint32_t*)*out_rec = be32tohp(&ptr); */
uint32_t *ptr_32 = (uint32_t *)out_rec;
*ptr_32 = be32tohp(&ptr);
- /* (*out_rec)[0].start_block = be32tohp(&ptr); */
+ /* (*out_rec)[0].start_block = be32tohp(&ptr); */
}
-
+
return ((uint8_t*)ptr - (uint8_t*)in_bytes);
}
@@ -1931,31 +1873,26 @@ hfslib_free_recs(
hfs_callback_args* cbargs)
{
uint16_t i;
-
- if(inout_num_recs==NULL || *inout_num_recs==0)
+
+ if (inout_num_recs == NULL || *inout_num_recs == 0)
return;
-
- if(inout_node_recs!=NULL && *inout_node_recs!=NULL)
- {
- for(i=0;i<*inout_num_recs;i++)
- {
- if((*inout_node_recs)[i]!=NULL)
- {
+
+ if (inout_node_recs != NULL && *inout_node_recs != NULL) {
+ for (i = 0 ; i < *inout_num_recs; i++) {
+ if ((*inout_node_recs)[i] != NULL) {
hfslib_free((*inout_node_recs)[i], cbargs);
(*inout_node_recs)[i] = NULL;
}
}
-
hfslib_free(*inout_node_recs, cbargs);
*inout_node_recs = NULL;
}
-
- if(inout_rec_sizes!=NULL && *inout_rec_sizes!=NULL)
- {
+
+ if (inout_rec_sizes != NULL && *inout_rec_sizes != NULL) {
hfslib_free(*inout_rec_sizes, cbargs);
*inout_rec_sizes = NULL;
}
-
+
*inout_num_recs = 0;
}
@@ -1969,18 +1906,18 @@ hfslib_read_fork_descriptor(void* in_byt
{
void* ptr;
size_t last_bytes_read;
-
- if(in_bytes==NULL || out_forkdata==NULL)
+
+ if (in_bytes == NULL || out_forkdata == NULL)
return 0;
-
+
ptr = in_bytes;
-
+
out_forkdata->logical_size = be64tohp(&ptr);
out_forkdata->clump_size = be32tohp(&ptr);
out_forkdata->total_blocks = be32tohp(&ptr);
-
- if((last_bytes_read = hfslib_read_extent_descriptors(ptr,
- &out_forkdata->extents))==0)
+
+ if ((last_bytes_read = hfslib_read_extent_descriptors(ptr,
+ &out_forkdata->extents)) == 0)
return 0;
ptr = (uint8_t*)ptr + last_bytes_read;
@@ -1994,20 +1931,19 @@ hfslib_read_extent_descriptors(
{
void* ptr;
int i;
-
- if(in_bytes==NULL || out_extentrecord==NULL)
+
+ if (in_bytes == NULL || out_extentrecord == NULL)
return 0;
-
+
ptr = in_bytes;
-
- for(i=0;i<8;i++)
- {
+
+ for (i = 0; i < 8; i++) {
(((hfs_extent_descriptor_t*)*out_extentrecord)[i]).start_block =
be32tohp(&ptr);
(((hfs_extent_descriptor_t*)*out_extentrecord)[i]).block_count =
be32tohp(&ptr);
}
-
+
return ((uint8_t*)ptr - (uint8_t*)in_bytes);
}
@@ -2016,22 +1952,21 @@ hfslib_read_unistr255(void* in_bytes, hf
{
void* ptr;
uint16_t i, length;
-
- if(in_bytes==NULL || out_string==NULL)
+
+ if (in_bytes == NULL || out_string == NULL)
return 0;
-
+
ptr = in_bytes;
-
+
length = be16tohp(&ptr);
- if(length>255)
+ if (length > 255)
length = 255; /* hfs+ folder/file names have a limit of 255 chars */
out_string->length = length;
-
- for(i=0; i<length; i++)
- {
+
+ for (i = 0; i < length; i++) {
out_string->unicode[i] = be16tohp(&ptr);
}
-
+
return ((uint8_t*)ptr - (uint8_t*)in_bytes);
}
@@ -2039,10 +1974,10 @@ size_t
hfslib_read_bsd_data(void* in_bytes, hfs_bsd_data_t* out_perms)
{
void* ptr;
-
- if(in_bytes==NULL || out_perms==NULL)
+
+ if (in_bytes == NULL || out_perms == NULL)
return 0;
-
+
ptr = in_bytes;
out_perms->owner_id = be32tohp(&ptr);
@@ -2061,19 +1996,19 @@ size_t
hfslib_read_file_userinfo(void* in_bytes, hfs_macos_file_info_t* out_info)
{
void* ptr;
-
- if(in_bytes==NULL || out_info==NULL)
+
+ if (in_bytes == NULL || out_info == NULL)
return 0;
-
+
ptr = in_bytes;
-
+
out_info->file_type = be32tohp(&ptr);
out_info->file_creator = be32tohp(&ptr);
out_info->finder_flags = be16tohp(&ptr);
out_info->location.v = be16tohp(&ptr);
out_info->location.h = be16tohp(&ptr);
out_info->reserved = be16tohp(&ptr);
-
+
return ((uint8_t*)ptr - (uint8_t*)in_bytes);
}
@@ -2083,19 +2018,19 @@ hfslib_read_file_finderinfo(
hfs_macos_extended_file_info_t* out_info)
{
void* ptr;
-
- if(in_bytes==NULL || out_info==NULL)
+
+ if (in_bytes == NULL || out_info == NULL)
return 0;
-
+
ptr = in_bytes;
-
+
#if 0
#pragma warn Fill in with real code!
#endif
/* FIXME: Fill in with real code! */
memset(out_info, 0, sizeof(*out_info));
ptr = (uint8_t*)ptr + sizeof(hfs_macos_extended_file_info_t);
-
+
return ((uint8_t*)ptr - (uint8_t*)in_bytes);
}
@@ -2103,19 +2038,19 @@ size_t
hfslib_read_folder_userinfo(void* in_bytes, hfs_macos_folder_info_t* out_info)
{
void* ptr;
-
- if(in_bytes==NULL || out_info==NULL)
+
+ if (in_bytes == NULL || out_info == NULL)
return 0;
-
+
ptr = in_bytes;
-
+
#if 0
#pragma warn Fill in with real code!
#endif
/* FIXME: Fill in with real code! */
memset(out_info, 0, sizeof(*out_info));
ptr = (uint8_t*)ptr + sizeof(hfs_macos_folder_info_t);
-
+
return ((uint8_t*)ptr - (uint8_t*)in_bytes);
}
@@ -2125,19 +2060,19 @@ hfslib_read_folder_finderinfo(
hfs_macos_extended_folder_info_t* out_info)
{
void* ptr;
-
- if(in_bytes==NULL || out_info==NULL)
+
+ if (in_bytes == NULL || out_info == NULL)
return 0;
-
+
ptr = in_bytes;
-
+
#if 0
#pragma warn Fill in with real code!
#endif
/* FIXME: Fill in with real code! */
memset(out_info, 0, sizeof(*out_info));
ptr = (uint8_t*)ptr + sizeof(hfs_macos_extended_folder_info_t);
-
+
return ((uint8_t*)ptr - (uint8_t*)in_bytes);
}
@@ -2146,24 +2081,22 @@ hfslib_read_journal_info(void* in_bytes,
{
void* ptr;
int i;
-
- if(in_bytes==NULL || out_info==NULL)
+
+ if (in_bytes == NULL || out_info == NULL)
return 0;
-
+
ptr = in_bytes;
-
+
out_info->flags = be32tohp(&ptr);
- for(i=0; i<8; i++)
- {
+ for (i = 0; i < 8; i++) {
out_info->device_signature[i] = be32tohp(&ptr);
}
out_info->offset = be64tohp(&ptr);
out_info->size = be64tohp(&ptr);
- for(i=0; i<32; i++)
- {
+ for (i = 0; i < 32; i++) {
out_info->reserved[i] = be64tohp(&ptr);
}
-
+
return ((uint8_t*)ptr - (uint8_t*)in_bytes);
}
@@ -2171,10 +2104,10 @@ size_t
hfslib_read_journal_header(void* in_bytes, hfs_journal_header_t* out_header)
{
void* ptr;
-
- if(in_bytes==NULL || out_header==NULL)
+
+ if (in_bytes == NULL || out_header == NULL)
return 0;
-
+
ptr = in_bytes;
out_header->magic = be32tohp(&ptr);
@@ -2217,43 +2150,42 @@ hfslib_readd_with_extents(
uint64_t ext_length, last_offset;
uint16_t i;
int error;
-
- if(in_vol==NULL || out_bytes==NULL || in_extents==NULL || in_numextents==0
- || out_bytesread==NULL)
+
+ if (in_vol == NULL || out_bytes == NULL || in_extents == NULL ||
+ in_numextents == 0 || out_bytesread == NULL)
return -1;
-
+
*out_bytesread = 0;
last_offset = 0;
- for(i=0; i<in_numextents; i++)
+ for (i = 0; i < in_numextents; i++)
{
- if(in_extents[i].block_count==0)
+ if (in_extents[i].block_count == 0)
continue;
ext_length = in_extents[i].block_count * in_vol->vh.block_size;
- if(in_offset < last_offset+ext_length
+ if (in_offset < last_offset+ext_length
&& in_offset+in_length >= last_offset)
{
uint64_t isect_start, isect_end;
-
+
isect_start = max(in_offset, last_offset);
isect_end = min(in_offset+in_length, last_offset+ext_length);
error = hfslib_readd(in_vol, out_bytes, isect_end-isect_start,
isect_start - last_offset + (uint64_t)in_extents[i].start_block
* in_vol->vh.block_size, cbargs);
-
- if(error!=0)
+
+ if (error != 0)
return error;
-
+
*out_bytesread += isect_end-isect_start;
out_bytes = (uint8_t*)out_bytes + isect_end-isect_start;
}
last_offset += ext_length;
}
-
-
+
return 0;
}
@@ -2266,16 +2198,13 @@ void
hfslib_error(const char* in_format, const char* in_file, int in_line, ...)
{
va_list ap;
-
- if(in_format==NULL)
+
+ if (in_format == NULL)
return;
-
- if(hfs_gcb.error!=NULL)
- {
+
+ if (hfs_gcb.error != NULL) {
va_start(ap, in_line);
-
hfs_gcb.error(in_format, in_file, in_line, ap);
-
va_end(ap);
}
}
@@ -2283,16 +2212,16 @@ hfslib_error(const char* in_format, cons
void*
hfslib_malloc(size_t size, hfs_callback_args* cbargs)
{
- if(hfs_gcb.allocmem!=NULL)
+ if (hfs_gcb.allocmem != NULL)
return hfs_gcb.allocmem(size, cbargs);
-
+
return NULL;
}
void*
hfslib_realloc(void* ptr, size_t size, hfs_callback_args* cbargs)
{
- if(hfs_gcb.reallocmem!=NULL)
+ if (hfs_gcb.reallocmem != NULL)
return hfs_gcb.reallocmem(ptr, size, cbargs);
return NULL;
@@ -2301,7 +2230,7 @@ hfslib_realloc(void* ptr, size_t size, h
void
hfslib_free(void* ptr, hfs_callback_args* cbargs)
{
- if(hfs_gcb.freemem!=NULL && ptr!=NULL)
+ if (hfs_gcb.freemem != NULL && ptr != NULL)
hfs_gcb.freemem(ptr, cbargs);
}
@@ -2311,7 +2240,7 @@ hfslib_openvoldevice(
const char* in_device,
hfs_callback_args* cbargs)
{
- if(hfs_gcb.openvol!=NULL && in_device!=NULL)
+ if (hfs_gcb.openvol != NULL && in_device != NULL)
return hfs_gcb.openvol(in_vol, in_device, cbargs);
return 1;
@@ -2320,7 +2249,7 @@ hfslib_openvoldevice(
void
hfslib_closevoldevice(hfs_volume* in_vol, hfs_callback_args* cbargs)
{
- if(hfs_gcb.closevol!=NULL)
+ if (hfs_gcb.closevol != NULL)
hfs_gcb.closevol(in_vol, cbargs);
}
@@ -2332,12 +2261,12 @@ hfslib_readd(
uint64_t in_offset,
hfs_callback_args* cbargs)
{
- if(in_vol==NULL || out_bytes==NULL)
+ if (in_vol == NULL || out_bytes == NULL)
return -1;
-
- if(hfs_gcb.read!=NULL)
+
+ if (hfs_gcb.read != NULL)
return hfs_gcb.read(in_vol, out_bytes, in_length, in_offset, cbargs);
-
+
return -1;
}
@@ -2354,18 +2283,19 @@ hfslib_make_catalog_key(
unichar_t* in_unicode,
hfs_catalog_key_t* out_key)
{
- if(in_parent_cnid==0 || (in_name_len>0 && in_unicode==NULL) || out_key==0)
+ if (in_parent_cnid == 0 || (in_name_len > 0 && in_unicode == NULL) ||
+ out_key == 0)
return 0;
-
- if(in_name_len>255)
+
+ if (in_name_len > 255)
in_name_len = 255;
-
+
out_key->key_len = 6 + 2 * in_name_len;
out_key->parent_cnid = in_parent_cnid;
out_key->name.length = in_name_len;
- if(in_name_len>0)
+ if (in_name_len > 0)
memcpy(&out_key->name.unicode, in_unicode, in_name_len*2);
-
+
return out_key->key_len;
}
@@ -2377,15 +2307,15 @@ hfslib_make_extent_key(
uint32_t in_startblock,
hfs_extent_key_t* out_key)
{
- if(in_cnid==0 || out_key==0)
+ if (in_cnid == 0 || out_key == 0)
return 0;
-
+
out_key->key_length = HFS_MAX_EXT_KEY_LEN;
out_key->fork_type = in_forktype;
out_key->padding = 0;
out_key->file_cnid = in_cnid;
out_key->start_block = in_startblock;
-
+
return out_key->key_length;
}
@@ -2402,13 +2332,10 @@ hfslib_compare_catalog_keys_cf (
a = (const hfs_catalog_key_t*)ap;
b = (const hfs_catalog_key_t*)bp;
-
- if(a->parent_cnid != b->parent_cnid)
- {
+
+ if (a->parent_cnid != b->parent_cnid) {
return (a->parent_cnid - b->parent_cnid);
- }
- else
- {
+ } else {
/*
* The following code implements the pseudocode suggested by
* the HFS+ technote.
@@ -2421,32 +2348,32 @@ hfslib_compare_catalog_keys_cf (
#define lbyte(x) ((x) & 0x00FF)
apos = bpos = 0;
- while(1)
+ while (1)
{
/* get next valid character from a */
- for (lc=0; lc == 0 && apos < a->name.length; apos++) {
+ for (lc = 0; lc == 0 && apos < a->name.length; apos++) {
ac = a->name.unicode[apos];
lc = hfs_gcft[hbyte(ac)];
- if(lc==0)
+ if (lc == 0)
lc = ac;
else
lc = hfs_gcft[lc + lbyte(ac)];
};
- ac=lc;
+ ac = lc;
/* get next valid character from b */
- for (lc=0; lc == 0 && bpos < b->name.length; bpos++) {
+ for (lc = 0; lc == 0 && bpos < b->name.length; bpos++) {
bc = b->name.unicode[bpos];
lc = hfs_gcft[hbyte(bc)];
- if(lc==0)
+ if (lc == 0)
lc = bc;
else
lc = hfs_gcft[lc + lbyte(bc)];
};
- bc=lc;
+ bc = lc;
/* on end of string ac/bc are 0, otherwise > 0 */
- if (ac != bc || (ac == 0 && bc == 0))
+ if (ac != bc || (ac == 0 && bc == 0))
return ac - bc;
}
#undef hbyte
@@ -2460,16 +2387,16 @@ hfslib_compare_catalog_keys_bc (
const void *a,
const void *b)
{
- if(((const hfs_catalog_key_t*)a)->parent_cnid
+ if (((const hfs_catalog_key_t*)a)->parent_cnid
== ((const hfs_catalog_key_t*)b)->parent_cnid)
{
- if(((const hfs_catalog_key_t*)a)->name.length == 0 &&
+ if (((const hfs_catalog_key_t*)a)->name.length == 0 &&
((const hfs_catalog_key_t*)b)->name.length == 0)
return 0;
- if(((const hfs_catalog_key_t*)a)->name.length == 0)
+ if (((const hfs_catalog_key_t*)a)->name.length == 0)
return -1;
- if(((const hfs_catalog_key_t*)b)->name.length == 0)
+ if (((const hfs_catalog_key_t*)b)->name.length == 0)
return 1;
/* FIXME: This does a byte-per-byte comparison, whereas the HFS spec
@@ -2478,9 +2405,7 @@ hfslib_compare_catalog_keys_bc (
((const hfs_catalog_key_t*)b)->name.unicode,
min(((const hfs_catalog_key_t*)a)->name.length,
((const hfs_catalog_key_t*)b)->name.length));
- }
- else
- {
+ } else {
return (((const hfs_catalog_key_t*)a)->parent_cnid -
((const hfs_catalog_key_t*)b)->parent_cnid);
}
@@ -2497,31 +2422,25 @@ hfslib_compare_extent_keys (
* CNID -> fork type -> start block
*/
- if(((const hfs_extent_key_t*)a)->file_cnid
+ if (((const hfs_extent_key_t*)a)->file_cnid
== ((const hfs_extent_key_t*)b)->file_cnid)
{
- if(((const hfs_extent_key_t*)a)->fork_type
+ if (((const hfs_extent_key_t*)a)->fork_type
== ((const hfs_extent_key_t*)b)->fork_type)
{
- if(((const hfs_extent_key_t*)a)->start_block
+ if (((const hfs_extent_key_t*)a)->start_block
== ((const hfs_extent_key_t*)b)->start_block)
{
return 0;
- }
- else
- {
+ } else {
return (((const hfs_extent_key_t*)a)->start_block -
((const hfs_extent_key_t*)b)->start_block);
}
- }
- else
- {
+ } else {
return (((const hfs_extent_key_t*)a)->fork_type -
((const hfs_extent_key_t*)b)->fork_type);
}
- }
- else
- {
+ } else {
return (((const hfs_extent_key_t*)a)->file_cnid -
((const hfs_extent_key_t*)b)->file_cnid);
}
@@ -2535,17 +2454,17 @@ hfslib_create_casefolding_table(void)
unichar_t* t; /* convenience */
uint16_t s; /* current subtable * 256 */
uint16_t i; /* current subtable index (0 to 255) */
-
- if(hfs_gcft!=NULL)
+
+ if (hfs_gcft != NULL)
return 0; /* no sweat, table already exists */
-
+
hfslib_init_cbargs(&cbargs);
hfs_gcft = hfslib_malloc(5632, &cbargs);
- if(hfs_gcft==NULL)
+ if (hfs_gcft == NULL)
HFS_LIBERR("could not allocate case folding table");
-
+
t = hfs_gcft; /* easier to type :) */
-
+
/*
* high byte indices
*/
@@ -2561,17 +2480,17 @@ hfslib_create_casefolding_table(void)
t[s+ 33] = 0x0800;
t[s+254] = 0x0900;
t[s+255] = 0x0a00;
-
+
/*
* table 1 (high byte 0x00)
*/
s = 1 * 256;
- for(i=0; i<65; i++)
+ for (i = 0; i < 65; i++)
t[s+i] = i;
t[s+ 0] = 0xffff;
- for(i=65; i<91; i++)
+ for (i = 65; i < 91; i++)
t[s+i] = i + 0x20;
- for(i=91; i<256; i++)
+ for (i = 91; i < 256; i++)
t[s+i] = i;
t[s+198] = 0x00e6;
t[s+208] = 0x00f0;
@@ -2582,7 +2501,7 @@ hfslib_create_casefolding_table(void)
* table 2 (high byte 0x01)
*/
s = 2 * 256;
- for(i=0; i<256; i++)
+ for (i = 0; i < 256; i++)
t[s+i] = i + 0x0100;
t[s+ 16] = 0x0111;
t[s+ 38] = 0x0127;
@@ -2639,22 +2558,22 @@ hfslib_create_casefolding_table(void)
* table 3 (high byte 0x03)
*/
s = 3 * 256;
- for(i=0; i<145; i++)
+ for (i = 0; i < 145; i++)
t[s+i] = i + 0x0300;
- for(i=145; i<170; i++)
+ for (i = 145; i < 170; i++)
t[s+i] = i + 0x0320;
t[s+162] = 0x03a2;
- for(i=170; i<256; i++)
+ for (i = 170; i < 256; i++)
t[s+i] = i + 0x0300;
- for(i=226; i<239; i+=2)
+ for (i = 226; i < 239; i += 2)
t[s+i] = i + 0x0301;
/*
* table 4 (high byte 0x04)
*/
s = 4 * 256;
- for(i=0; i<16; i++)
+ for (i = 0; i < 16; i++)
t[s+i] = i + 0x0400;
t[s+ 2] = 0x0452;
t[s+ 4] = 0x0454;
@@ -2666,55 +2585,55 @@ hfslib_create_casefolding_table(void)
t[s+ 11] = 0x045b;
t[s+ 15] = 0x045f;
- for(i=16; i<48; i++)
+ for (i = 16; i < 48; i++)
t[s+i] = i + 0x0420;
t[s+ 25] = 0x0419;
- for(i=48; i<256; i++)
+ for (i = 48; i < 256; i++)
t[s+i] = i + 0x0400;
t[s+195] = 0x04c4;
t[s+199] = 0x04c8;
t[s+203] = 0x04cc;
- for(i=96; i<129; i+=2)
+ for (i = 96; i < 129; i += 2)
t[s+i] = i + 0x0401;
t[s+118] = 0x0476;
- for(i=144; i<191; i+=2)
+ for (i = 144; i < 191; i += 2)
t[s+i] = i + 0x0401;
/*
* table 5 (high byte 0x05)
*/
s = 5 * 256;
- for(i=0; i<49; i++)
+ for (i = 0; i < 49; i++)
t[s+i] = i + 0x0500;
- for(i=49; i<87; i++)
+ for (i = 49; i < 87; i++)
t[s+i] = i + 0x0530;
- for(i=87; i<256; i++)
+ for (i = 87; i < 256; i++)
t[s+i] = i + 0x0500;
-
+
/*
* table 6 (high byte 0x10)
*/
s = 6 * 256;
- for(i=0; i<160; i++)
+ for (i = 0; i < 160; i++)
t[s+i] = i + 0x1000;
- for(i=160; i<198; i++)
+ for (i = 160; i < 198; i++)
t[s+i] = i + 0x1030;
- for(i=198; i<256; i++)
+ for (i = 198; i < 256; i++)
t[s+i] = i + 0x1000;
-
+
/*
* table 7 (high byte 0x20)
*/
s = 7 * 256;
- for(i=0; i<256; i++)
+ for (i = 0; i < 256; i++)
t[s+i] = i + 0x2000;
{
uint8_t zi[15] = { 12, 13, 14, 15,
42, 43, 44, 45, 46,
106, 107, 108, 109, 110, 111};
- for(i=0; i<15; i++)
+ for (i = 0; i < 15; i++)
t[s+zi[i]] = 0x0000;
}
@@ -2722,18 +2641,18 @@ hfslib_create_casefolding_table(void)
* table 8 (high byte 0x21)
*/
s = 8 * 256;
- for(i=0; i<96; i++)
+ for (i = 0; i < 96; i++)
t[s+i] = i + 0x2100;
- for(i=96; i<112; i++)
+ for (i = 96; i < 112; i++)
t[s+i] = i + 0x2110;
- for(i=112; i<256; i++)
+ for (i = 112; i < 256; i++)
t[s+i] = i + 0x2100;
/*
* table 9 (high byte 0xFE)
*/
s = 9 * 256;
- for(i=0; i<256; i++)
+ for (i = 0; i < 256; i++)
t[s+i] = i + 0xFE00;
t[s+255] = 0x0000;
@@ -2741,15 +2660,15 @@ hfslib_create_casefolding_table(void)
* table 10 (high byte 0xFF)
*/
s = 10 * 256;
- for(i=0; i<33; i++)
+ for (i = 0; i < 33; i++)
t[s+i] = i + 0xFF00;
- for(i=33; i<59; i++)
+ for (i = 33; i < 59; i++)
t[s+i] = i + 0xFF20;
- for(i=59; i<256; i++)
+ for (i = 59; i < 256; i++)
t[s+i] = i + 0xFF00;
-
+
return 0;
-
+
error:
return 1;
}
@@ -2773,9 +2692,9 @@ hfslib_get_hardlink(hfs_volume *vol, uin
return -1;
len = snprintf(name, sizeof(name), "iNode%d", inode_num);
- for (i=0; i<len; i++)
+ for (i = 0; i < len; i++)
name_uni[i] = name[i];
-
+
if (hfslib_make_catalog_key(metadata.folder.cnid, len, name_uni,
&key) == 0)
return -1;