Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/fs/hfs I started to KNF this file but quickly ended up f...



details:   https://anonhg.NetBSD.org/src/rev/42024e3108e7
branches:  trunk
changeset: 335190:42024e3108e7
user:      maxv <maxv%NetBSD.org@localhost>
date:      Mon Dec 29 17:02:39 2014 +0000

description:
I started to KNF this file but quickly ended up figuring out I was not
courageous enough for such ugliness. So I only KNF'ed the first 300
lines.

I'll come back later.

diffstat:

 sys/fs/hfs/libhfs.c |  199 ++++++++++++++++++++++++---------------------------
 1 files changed, 93 insertions(+), 106 deletions(-)

diffs (truncated from 396 to 300 lines):

diff -r 6e58fa7e1f75 -r 42024e3108e7 sys/fs/hfs/libhfs.c
--- a/sys/fs/hfs/libhfs.c       Mon Dec 29 16:37:27 2014 +0000
+++ b/sys/fs/hfs/libhfs.c       Mon Dec 29 17:02:39 2014 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: libhfs.c,v 1.12 2012/07/28 00:43:23 matt Exp $ */
+/*     $NetBSD: libhfs.c,v 1.13 2014/12/29 17:02:39 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.12 2012/07/28 00:43:23 matt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: libhfs.c,v 1.13 2014/12/29 17:02:39 maxv Exp $");
 
 #include "libhfs.h"
 
@@ -59,7 +59,8 @@
        &hfs_gMetadataDirectoryKey,
        &hfs_gJournalInfoBlockFileKey,
        &hfs_gJournalBufferFileKey,
-       NULL};
+       NULL
+};
 
 
 extern uint16_t be16tohp(void** inout_ptr);
@@ -100,21 +101,21 @@
 hfslib_init(hfs_callbacks* in_callbacks)
 {
        unichar_t       temp[256];
-       
-       if(in_callbacks!=NULL)
+
+       if (in_callbacks != NULL)
                memcpy(&hfs_gcb, in_callbacks, sizeof(hfs_callbacks));
-       
+
        hfs_gcft = NULL;
-       
+
        /*
         * Create keys for the HFS+ "private" files so we can reuse them whenever
         * we perform a user-visible operation, such as listing directory contents.
         */
-               
+
 #define ATOU(str, len) /* quick & dirty ascii-to-unicode conversion */ \
        do{ int i; for(i=0; i<len; i++) temp[i]=str[i]; } \
        while( /*CONSTCOND*/ 0)
-       
+
        ATOU("\0\0\0\0HFS+ Private Data", 21);
        hfslib_make_catalog_key(HFS_CNID_ROOT_FOLDER, 21, temp, 
                &hfs_gMetadataDirectoryKey);
@@ -134,8 +135,8 @@
 hfslib_done(void)
 {
        hfs_callback_args       cbargs;
-       
-       if(hfs_gcft!=NULL) {
+
+       if (hfs_gcft != NULL) {
                hfslib_init_cbargs(&cbargs);
                hfslib_free(hfs_gcft, &cbargs);
                hfs_gcft = NULL;
@@ -175,102 +176,97 @@
        result = 1;
        buffer = NULL;
 
-       if(in_device==NULL || out_vol==NULL)
+       if (in_device == NULL || out_vol == NULL)
                return 1;
 
        out_vol->readonly = in_readonly;
        out_vol->offset = 0;
 
-       if(hfslib_openvoldevice(out_vol, in_device, cbargs) != 0)
+       if (hfslib_openvoldevice(out_vol, in_device, cbargs) != 0)
                HFS_LIBERR("could not open device");
        isopen = 1;
 
        /*
-        *      Read the volume header.
+        * Read the volume header.
         */
        buffer = hfslib_malloc(max(sizeof(hfs_volume_header_t),
                sizeof(hfs_hfs_master_directory_block_t)), cbargs);
-       if(buffer==NULL)
+       if (buffer == NULL)
                HFS_LIBERR("could not allocate volume header");
-       if(hfslib_readd(out_vol, buffer, max(sizeof(hfs_volume_header_t),
-                           sizeof(hfs_hfs_master_directory_block_t)),
-              HFS_VOLUME_HEAD_RESERVE_SIZE, cbargs)!=0)
+       if (hfslib_readd(out_vol, buffer, max(sizeof(hfs_volume_header_t),
+           sizeof(hfs_hfs_master_directory_block_t)),
+           HFS_VOLUME_HEAD_RESERVE_SIZE, cbargs) != 0)
                HFS_LIBERR("could not read volume header");
 
        if (be16toh(*((uint16_t *)buffer)) == HFS_SIG_HFS) {
                if (hfslib_read_master_directory_block(buffer, &mdb) == 0)
                        HFS_LIBERR("could not parse master directory block");
-               if (mdb.embedded_signature == HFS_SIG_HFSP)
-               {
+               if (mdb.embedded_signature == HFS_SIG_HFSP) {
                        /* XXX: is 512 always correct? */
                        out_vol->offset =
                            mdb.first_block * 512
                            + mdb.embedded_extent.start_block
                            * (uint64_t)mdb.block_size;
 
-                       if(hfslib_readd(out_vol, buffer,
-                              sizeof(hfs_volume_header_t),
-                              HFS_VOLUME_HEAD_RESERVE_SIZE, cbargs)!=0)
+                       if (hfslib_readd(out_vol, buffer,
+                           sizeof(hfs_volume_header_t),
+                           HFS_VOLUME_HEAD_RESERVE_SIZE, cbargs) != 0)
                                HFS_LIBERR("could not read volume header");
-               }
-               else
+               } else
                        HFS_LIBERR("Plain HFS volumes not currently supported");
        }
 
-       if(hfslib_read_volume_header(buffer, &(out_vol->vh))==0)
+       if (hfslib_read_volume_header(buffer, &(out_vol->vh)) == 0)
                HFS_LIBERR("could not parse volume header");
-       
+
        /*
         * Check the volume signature to see if this is a legitimate HFS+ or HFSX
         * volume. If so, set the key comparison function pointers appropriately.
         */
-       switch(out_vol->vh.signature)
-       {
+       switch(out_vol->vh.signature) {
                case HFS_SIG_HFSP:
                        out_vol->keycmp = hfslib_compare_catalog_keys_cf;
                        break;
-               
                case HFS_SIG_HFSX:
                        out_vol->keycmp = NULL; /* will be set below */
                        break;
-                       
                default:
                        /* HFS_LIBERR("unrecognized volume format"); */
                        goto error;
                        break;
        }
 
-
        /*
-        *      Read the catalog header.
+        * Read the catalog header.
         */
        buffer2 = hfslib_realloc(buffer, 512, cbargs);
-       if(buffer2==NULL)
+       if (buffer2 == NULL)
                HFS_LIBERR("could not allocate catalog header node");
        buffer = buffer2;
-       
+
        /*
-         We are only interested in the node header, so read the first
-         512 bytes and construct the node descriptor by hand.
-       */
-       if(hfslib_readd(out_vol, buffer, 512,
-              out_vol->vh.catalog_file.extents[0].start_block
-              *(uint64_t)out_vol->vh.block_size,
-               cbargs) != 0)
+        * We are only interested in the node header, so read the first
+        * 512 bytes and construct the node descriptor by hand.
+        */
+       if (hfslib_readd(out_vol, buffer, 512,
+           out_vol->vh.catalog_file.extents[0].start_block *
+           (uint64_t)out_vol->vh.block_size, cbargs) != 0)
                HFS_LIBERR("could not read catalog header node");
        node_recs[0] = (char *)buffer+14;
        node_rec_sizes[0] = 120;
-       if(hfslib_read_header_node(node_recs, node_rec_sizes, 1,
-               &out_vol->chr, NULL, NULL)==0)
+       if (hfslib_read_header_node(node_recs, node_rec_sizes, 1,
+           &out_vol->chr, NULL, NULL) == 0)
                HFS_LIBERR("could not parse catalog header node");
-       
-       /* If this is an HFSX volume, the catalog header specifies the type of
-        * key comparison method (case-folding or binary compare) we should use. */
-       if(out_vol->keycmp == NULL)
-       {
-               if(out_vol->chr.keycomp_type == HFS_KEY_CASEFOLD)
+
+       /*
+        * If this is an HFSX volume, the catalog header specifies the type of
+        * key comparison method (case-folding or binary compare) we should
+        * use.
+        */
+       if (out_vol->keycmp == NULL) {
+               if (out_vol->chr.keycomp_type == HFS_KEY_CASEFOLD)
                        out_vol->keycmp = hfslib_compare_catalog_keys_cf;
-               else if(out_vol->chr.keycomp_type == HFS_KEY_BINARY)
+               else if (out_vol->chr.keycomp_type == HFS_KEY_BINARY)
                        out_vol->keycmp = hfslib_compare_catalog_keys_bc;
                else
                        HFS_LIBERR("undefined key compare method");
@@ -281,23 +277,22 @@
            sizeof(uint16_t) : sizeof(uint8_t);
 
        /*
-        *      Read the extent overflow header.
+        * Read the extent overflow header.
         */
        /*
-         We are only interested in the node header, so read the first
-         512 bytes and construct the node descriptor by hand.
-         buffer is already 512 bytes long.
-       */
-       if(hfslib_readd(out_vol, buffer, 512,
-              out_vol->vh.extents_file.extents[0].start_block
-              *(uint64_t)out_vol->vh.block_size,
-               cbargs) != 0)
+        * We are only interested in the node header, so read the first
+        * 512 bytes and construct the node descriptor by hand.
+        * buffer is already 512 bytes long.
+        */
+       if (hfslib_readd(out_vol, buffer, 512,
+           out_vol->vh.extents_file.extents[0].start_block *
+           (uint64_t)out_vol->vh.block_size, cbargs) != 0)
                HFS_LIBERR("could not read extent header node");
-       
+
        node_recs[0] = (char *)buffer+14;
        node_rec_sizes[0] = 120;
-       if(hfslib_read_header_node(node_recs, node_rec_sizes, 1,
-               &out_vol->ehr, NULL, NULL)==0)
+       if (hfslib_read_header_node(node_recs, node_rec_sizes, 1,
+           &out_vol->ehr, NULL, NULL) == 0)
                HFS_LIBERR("could not parse extent header node");
        out_vol->extkeysizefieldsize
            = (out_vol->ehr.attributes & HFS_BIG_KEYS_MASK) ?
@@ -305,48 +300,45 @@
        /*
         * Read the journal info block and journal header (if volume journaled).
         */
-       if(out_vol->vh.attributes & (1<<HFS_VOL_JOURNALED))
-       {
+       if (out_vol->vh.attributes & (1<<HFS_VOL_JOURNALED)) {
                /* journal info block */
                buffer2 = hfslib_realloc(buffer, sizeof(hfs_journal_info_t), cbargs);
-               if(buffer2==NULL)
+               if (buffer2 == NULL)
                        HFS_LIBERR("could not allocate journal info block");
                buffer = buffer2;
-       
-               if(hfslib_readd(out_vol, buffer, sizeof(hfs_journal_info_t),
-                       out_vol->vh.journal_info_block * out_vol->vh.block_size,
-                       cbargs) != 0)
+
+               if (hfslib_readd(out_vol, buffer, sizeof(hfs_journal_info_t),
+                   out_vol->vh.journal_info_block * out_vol->vh.block_size,
+                   cbargs) != 0)
                        HFS_LIBERR("could not read journal info block");
-               
-               if(hfslib_read_journal_info(buffer, &out_vol->jib)==0)
+
+               if (hfslib_read_journal_info(buffer, &out_vol->jib) == 0)
                        HFS_LIBERR("could not parse journal info block");
-                                       
+
                /* journal header */
-               buffer2 = hfslib_realloc(buffer, sizeof(hfs_journal_header_t),cbargs);
-               if(buffer2==NULL)
+               buffer2 = hfslib_realloc(buffer, sizeof(hfs_journal_header_t), cbargs);
+               if (buffer2 == NULL)
                        HFS_LIBERR("could not allocate journal header");
                buffer = buffer2;
-       
-               if(hfslib_readd(out_vol, buffer, sizeof(hfs_journal_header_t),
-                       out_vol->jib.offset, cbargs) != 0)
+
+               if (hfslib_readd(out_vol, buffer, sizeof(hfs_journal_header_t),
+                   out_vol->jib.offset, cbargs) != 0)
                        HFS_LIBERR("could not read journal header");
-               
-               if(hfslib_read_journal_header(buffer, &out_vol->jh)==0)
+
+               if (hfslib_read_journal_header(buffer, &out_vol->jh) == 0)
                        HFS_LIBERR("could not parse journal header");
 
                out_vol->journaled = 1;
-       }
-       else
-       {
+       } else {
                out_vol->journaled = 0;
        }
-       
+
        /*
         * If this volume uses case-folding comparison and the folding table hasn't



Home | Main Index | Thread Index | Old Index