Beispiel #1
0
        /* find which block should be searched next for the entry; -1 if no block */
        public static Int32 FindInPmgi(byte[] page_buf, UInt32 block_len, string objPath)
        {
            /* XXX: modify this to do a binary search using the nice index structure
             *      that is provided for us
             */
            chmPmgiHeader header = new chmPmgiHeader();
            uint          hremain;
            int           page = -1;
            uint          end;
            uint          cur;
            UInt64        strLen;

            char[] buffer = new char[Storage.CHM_MAX_PATHLEN];

            /* figure out where to start and end */
            cur     = 0;
            hremain = CHM_PMGI_LEN;
            if (!UnmarshalPmgiHeader(ref page_buf, ref cur, ref hremain, ref header))
            {
                return(-1);
            }
            end = block_len - (header.free_space);

            /* now, scan progressively */
            while (cur < end)
            {
                /* grab the name */
                strLen = Storage.ParseCWord(page_buf, ref cur);
                if (strLen > Storage.CHM_MAX_PATHLEN)
                {
                    return(-1);
                }
                if (!Storage.ParseUTF8(page_buf, ref cur, strLen, ref buffer))
                {
                    return(-1);
                }

                /* check if it is the right name */
                if (strcasecmp(new String(buffer), objPath) > 0)
                {
                    return(page);
                }

                /* load next value for path */
                page = (int)Storage.ParseCWord(page_buf, ref cur);
            }

            return(page);
        }
Beispiel #2
0
        public static bool UnmarshalPmgiHeader(ref byte[] pData, ref uint pDataPos,
            ref uint pDataLen, ref chmPmgiHeader dest)
        {
            /* we only know how to deal with a 0x8 byte structures */
            if (pDataLen != CHM_PMGI_LEN)
                return false;

            InitialisePmgiHeader(ref dest);

            /* unmarshal fields */
            Unmarshal.ToCharArray(ref pData, ref pDataPos, ref pDataLen, ref dest.signature, 4);
            Unmarshal.ToUInt32(ref pData, ref pDataPos, ref pDataLen, ref dest.free_space);

            /* check structure */
            if (new String(dest.signature, 0, 4).CompareTo(CHM_PMGI_MARKER) != 0)
                return false;

            return true;
        }
Beispiel #3
0
        /* find which block should be searched next for the entry; -1 if no block */
        public static Int32 FindInPmgi(byte[] page_buf, UInt32 block_len, string objPath)
        {
            /* XXX: modify this to do a binary search using the nice index structure
             *      that is provided for us
             */
            chmPmgiHeader header = new chmPmgiHeader();
            uint hremain;
            int page = -1;
            uint end;
            uint cur;
            UInt64 strLen;
            char[] buffer = new char[Storage.CHM_MAX_PATHLEN];

            /* figure out where to start and end */
            cur = 0;
            hremain = CHM_PMGI_LEN;
            if (!UnmarshalPmgiHeader(ref page_buf, ref cur, ref hremain, ref header))
                return -1;
            end = block_len - (header.free_space);

            /* now, scan progressively */
            while (cur < end) {
                /* grab the name */
                strLen = Storage.ParseCWord(page_buf, ref cur);
                if (strLen > Storage.CHM_MAX_PATHLEN)
                    return -1;
                if (!Storage.ParseUTF8(page_buf, ref cur, strLen, ref buffer))
                    return -1;

                /* check if it is the right name */
                if (String.Compare(new String(buffer), objPath, true) == 0)
                    return page;

                /* load next value for path */
                page = (int)Storage.ParseCWord(page_buf, ref cur);
            }

            return page;
        }
Beispiel #4
0
        public static bool UnmarshalPmgiHeader(ref byte[] pData, ref uint pDataPos,
                                               ref uint pDataLen, ref chmPmgiHeader dest)
        {
            /* we only know how to deal with a 0x8 byte structures */
            if (pDataLen != CHM_PMGI_LEN)
            {
                return(false);
            }

            InitialisePmgiHeader(ref dest);

            /* unmarshal fields */
            Unmarshal.ToCharArray(ref pData, ref pDataPos, ref pDataLen, ref dest.signature, 4);
            Unmarshal.ToUInt32(ref pData, ref pDataPos, ref pDataLen, ref dest.free_space);

            /* check structure */
            if (new String(dest.signature, 0, 4).CompareTo(CHM_PMGI_MARKER) != 0)
            {
                return(false);
            }

            return(true);
        }
Beispiel #5
0
 public static void InitialisePmgiHeader(ref chmPmgiHeader dest)
 {
     dest.signature = new char[4];
 }
Beispiel #6
0
 public static void InitialisePmgiHeader(ref chmPmgiHeader dest)
 {
     dest.signature = new char[4];
 }