⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 readdir.c

📁 这是DVD中伺服部分的核心代码
💻 C
📖 第 1 页 / 共 3 页
字号:
                        {
                            break;
                        }
                    }

                    if ((d_loc_order[loc_order_idx] - file_start) < sbuf_count)
                    {
                        order_idx = loc_order_idx * 12;
                        offset = (d_loc_order[loc_order_idx] - file_start) * 2048;
                        d_loc_order[loc_order_idx] = 0;
                        loc_order_idx++;
                        break;
                    }
                    else
                    {
                        loc_order_idx++;
                    }
                }

                /* For the .bup and .ifo files we don't need CGMS info so we can just
                 * parse out the standrd data. */
                if (strncmp(&d_order[order_idx], "VIDEO_TS.BUP", 12) == 0 || strncmp(&d_order[order_idx], "video_ts.bup", 12) == 0)
                {
                    get_file_entry(&video_ts.bup_length, &video_ts.bup_address, udf_start, offset);
                }
                else if (strncmp(&d_order[order_idx], "VIDEO_TS.IFO", 12) == 0 || strncmp(&d_order[order_idx], "video_ts.ifo", 12) == 0)
                {
                    get_file_entry(&video_ts.ifo_length, &video_ts.ifo_address, udf_start, offset);
                    DBGPRINT(DBG_ON(DBG_VERBOSE), ("\n\n2 video_ts.ifo_address: %x\n\n", video_ts.ifo_address));
                }
                /* For the .vob files we need to get the CGMS data as well so we need to
                 * parse out the extended attributes. */
                else if (strncmp(&d_order[order_idx], "VIDEO_TS.VOB", 12) == 0 || strncmp(&d_order[order_idx], "video_ts.vob", 12) == 0)
                {
                    get_file_entry(&video_ts.vob_length, &video_ts.vob_address, udf_start, offset);

                    if (get_le(offset + 168))  /* Extended Attribues? */
                    {
                        temp = get_le(192 + offset);        /* (176 + 16), offsets from the entry start */

                        cgms_offset = temp + 176 + offset;

                        while (cgms_offset < (2048 + offset))
                        {
                            if (get_le(cgms_offset) != 2048)
                            {
                                break;
                            }
                            for (temp = 0; temp < 12; temp++)
                            {
                                ts[temp] = NON_CACHED_SBUF[cgms_offset + 17 + temp];
                            }
                            /* get the cgms info for Macrovision */
                            if (strncmp(ts, "*UDF DVD CGMS", 12) == 0)
                            {
                                video_ts.vob_cgms = NON_CACHED_SBUF[cgms_offset + 50];
                                cgms_offset += 2048;
                            }
                            else
                            {
                                l_iu = (USHORT)(get_le(cgms_offset + 12));
                                cgms_offset += 48 + l_iu;
                            }
                        }
                    }
                }
                else
                {
                    if (strncmp(&d_order[order_idx + 8], ".BUP", 4) == 0 || strncmp(&d_order[order_idx + 8], ".bup", 4) == 0)
                    {
                        ts_num = get_ts_num(&d_order[order_idx + 4]);

                        if ((ts_num + 1) > video_ts.vts_num_max)
                        {
                            video_ts.vts_num_max = ts_num + 1;
                        }
                        get_file_entry(&vts_file[ts_num].bup_length, &vts_file[ts_num].bup_address, udf_start, offset);
                    }
                    else if (strncmp(&d_order[order_idx + 8], ".IFO", 4) == 0 || strncmp(&d_order[order_idx + 8], ".ifo", 4) == 0)
                    {
                        ts_num = get_ts_num(&d_order[order_idx + 4]);

                        if ((ts_num + 1) > video_ts.vts_num_max)
                        {
                            video_ts.vts_num_max = ts_num + 1;
                        }
                        get_file_entry(&vts_file[ts_num].ifo_length, &vts_file[ts_num].ifo_address, udf_start, offset);
                    }
                    else
                    {
                        if (strncmp(&d_order[order_idx + 8], ".VOB", 4) == 0 || strncmp(&d_order[order_idx + 8], ".vob", 4) == 0)
                        {
                            ts_num = get_ts_num(&d_order[order_idx + 4]);

                            ts_tso = (UBYTE) d_order[order_idx + 7] - 0x30;

                            if ((ts_num + 1) > video_ts.vts_num_max)
                            {
                                video_ts.vts_num_max = ts_num + 1;
                            }
                            if (ts_tso > vts_file[ts_num].tso_num)
                            {
                                vts_file[ts_num].tso_num = ts_tso;
                            }
                            get_file_entry(&vts_file[ts_num].ts[ts_tso].length, &vts_file[ts_num].ts[ts_tso].address, udf_start, offset);

                            if (get_le(offset + 168))  /* Extended Attribues? */
                            {
                                temp = get_le(192 + offset);        /* 176 + 16 */

                                cgms_offset = temp + 176 + offset;

                                while (cgms_offset < (2048 + offset))
                                {
                                    if (get_le(cgms_offset) != 2048)
                                    {
                                        break;
                                    }
                                    for (temp = 0; temp < 12; temp++)
                                    {
                                        ts[temp] = NON_CACHED_SBUF[cgms_offset + 17 + temp];
                                    }
                                    /* get the cgms info for Macrovision */
                                    if (strncmp(ts, "*UDF DVD CGMS", 12) == 0)
                                    {
                                        vts_file[ts_num].ts[ts_tso].cgms = NON_CACHED_SBUF[cgms_offset + 50];
                                        cgms_offset += 2048;
                                    }
                                    else
                                    {
                                        l_iu = (USHORT)(get_le(cgms_offset + 12));
                                        cgms_offset += 48 + l_iu;
                                    }
                                }
                            }
                        }
                    }
                }
            }

            DBGPRINT(DBG_ON(DBG_TRACE), ("read_directory() - file_start +=30\n"));

            file_start += 30;
        }
    }

#ifdef AUDIO_TS
    /* The AUDIO_TS system is parsed exactly the same way as the VIDEO_TS
     * system except that some of the files names are a little different. */
    if (audio_ts.present)
    {
        audio_ts.ats_num_max = 0;

        order_idx = 0;
        offset = 0;
        loc_order_idx = 0;

        for (i = 0; i < 14292; i++)     /* (12 * 1191) */
        {
            d_order[i] = 0;
        }
        /* ok, go to the audio_ts ICB */
        cur_sec = udf_start + audio_ts.ifo_address;
        ret = disc_fread(cur_sec, 1);

        if (ret)
        {
            OS_MemFree(d_loc_order);
            d_loc_order = NULL;

            OS_MemFree(d_order);
            d_order = NULL;

            if (ret == 0xFF)
            {
                return (ret);
            }
            else
            {
                read_in_progress = 0;
                return (6);
            }
        }

        l_ea = get_le(168);
        icb_length = get_le(56);
        if (icb_length > 122880)
        {
            icb_length = 122880; /*60 sectors*/
        }
        icb_sec = icb_length / 2048;
        if (icb_length % 2048)
        {
            icb_sec++;
        }
        if (icb_sec > 30)
        {
            cur_icb_sec = 30;
            i = 2;
        }
        else
        {
            i = 1;
            cur_icb_sec = icb_sec;
        }

        /* get offset to identifier descriptors for this directory */
        offset = 176 + l_ea;

        cur_sec = ((NON_CACHED_SBUF[offset + 5] << 8) | (NON_CACHED_SBUF[offset + 4])) + udf_start;

        audio_ts.present = 0;

        file_start = 0xFFFF;

        for (j = 0; j < i; j++)
        {
            /* getting the file identifiers for the video_ts files */
            ret = disc_fread(cur_sec, cur_icb_sec);
            if (ret)
            {
                OS_MemFree(d_loc_order);
                d_loc_order = NULL;

                OS_MemFree(d_order);
                d_order = NULL;

                if (ret == 0xFF)
                {
                    return (ret);
                }
                else
                {
                    read_in_progress = 0;
                    return (2);
                }
            }

            /* to bypass the parent descriptor */
            if (j == 0)
            {
                offset = 1;
            }
            else
            {
                offset = 0;
            }
            /* Check the file descriptors */
            while (offset < (cur_icb_sec * 2048))      /* (2048 * length) */
            {
                while ( ((NON_CACHED_SBUF[offset + 1] << 8) | (NON_CACHED_SBUF[offset])) != 0x101 )
                {
                    offset++;
                    if ((offset > (cur_icb_sec * 2048))||(offset > icb_length))
                    {
                        break;
                    }
                }

                l_iu = (NON_CACHED_SBUF[offset + 36]) | (NON_CACHED_SBUF[offset + 37] << 8);

                for (i = 0; i < 12; i++)
                {
                    d_order[i + order_idx] = NON_CACHED_SBUF[offset + 39 + i + l_iu];
                }

                if (strncmp(&d_order[order_idx], "AUDIO_TS.BUP", 12) == 0 || strncmp(&d_order[order_idx], "audio_ts.bup", 12) == 0)
                {
                    audio_ts.present = 1;
                }
                if (strncmp(&d_order[order_idx], "AUDIO_TS.IFO", 12) == 0 || strncmp(&d_order[order_idx], "auido_ts.ifo", 12) == 0)
                {
                    audio_ts.present = 1;
                }

                if (strncmp(&d_order[order_idx + 8], ".BUP", 4) == 0 || strncmp(&d_order[order_idx + 8], ".bup", 4) == 0)
                {
                    d_loc_order[loc_order_idx] = (NON_CACHED_SBUF[offset + 25] << 8) | (NON_CACHED_SBUF[offset + 24]);
                    if (d_loc_order[loc_order_idx] < file_start)
                    {
                        file_start = d_loc_order[loc_order_idx];
                    }
                    order_idx += 12;
                    loc_order_idx++;
                }
                else if (strncmp(&d_order[order_idx + 8], ".IFO", 4) == 0 || strncmp(&d_order[order_idx + 8], ".ifo", 4) == 0)
                {
                    d_loc_order[loc_order_idx] = (NON_CACHED_SBUF[offset + 25] << 8) | (NON_CACHED_SBUF[offset + 24]);
                    if (d_loc_order[loc_order_idx] < file_start)
                    {
                        file_start = d_loc_order[loc_order_idx];
                    }
                    order_idx += 12;
                    loc_order_idx++;
                }
                else
                {
                    if (strncmp(&d_order[order_idx + 8], ".AOB", 4) == 0 || strncmp(&d_order[order_idx + 8], ".aob", 4) == 0)
                    {
                        d_loc_order[loc_order_idx] = (NON_CACHED_SBUF[offset + 25] << 8) | (NON_CACHED_SBUF[offset + 24]);
                        if (d_loc_order[loc_order_idx] < file_start)
                        {
                            file_start = d_loc_order[loc_order_idx];
                        }
                        order_idx += 12;
                        loc_order_idx++;
                    }
                }

                offset += 51;
                if (offset >= icb_length)
                {
                    j = i;
                    offset = (cur_icb_sec * 2048);
                }
            }
            cur_icb_sec = icb_sec - 30;
            cur_sec += 30;
        }
    }

    if (audio_ts.present)
    {
        num_files = loc_order_idx + 1;

        num_count = num_files;

        while (num_files > 0)
        {
            ret = disc_fread(udf_start + file_start, 30);
            if (ret)
            {
                read_in_progress = 0;

                OS_MemFree(d_loc_order);
                d_loc_order = NULL;

                OS_MemFree(d_order);
                d_order = NULL;

                if (ret == 0xFF)
                {
                    return (ret);
                }
                else
                {
                    return (6);
                }
            }

            order_idx = 0;
            offset = 0;
            loc_order_idx = 0;

            if (num_files < 31)
            {
                sbuf_count = num_files;
                num_files = 0;
            }
            else
            {
                sbuf_count = 30;
                num_files -= 30;
            }

            while (loc_order_idx < num_count)
            {
                while (loc_order_idx < num_count)
                {
                    while (d_loc_order[loc_order_idx] == 0)
                    {
                        if (loc_order_idx != num_count)
                        {
                            loc_order_idx++;
                        }
                        else
                        {
                            break;
                        }
                    }

                    if ((d_loc_order[loc_order_idx] - file_start) < sbuf_count)
                    {
                        order_idx = loc_order_idx * 12;
                        offset = (d_loc_order[loc_order_idx] - file_start) * 2048;
                        d_loc_order[loc_order_idx] = 0;
                        loc_order_idx++;
                        break;
                    }
                    else
                    {
                        loc_order_idx++;
                    }
                }

                if (strncmp(&d_order[order_idx], "AUDIO_TS.BUP", 12) == 0 || strncmp(&d_order[order_idx], "audio_ts.bup", 12) == 0)
                {
                    get_file_entry(&audio_ts.bup_length, &audio_ts.bup_address, udf_start, offset);
                }
                else if (strncmp(&d_order[order_idx], "AUDIO_TS.IFO", 12) == 0 || strncmp(&d_order[order_idx], "audio_ts.ifo", 12) == 0
                {
                    get_file_entry(&audio_ts.ifo_length, &audio_ts.ifo_address, udf_start, offset);
                }
                else
                {
                    if (strncmp(&d_order[order_idx + 8], ".BUP", 4) == 0 || strncmp(&d_order[order_idx + 8], ".bup", 4) == 0)
                    {
                        ts_num = get_ts_num(&d_order[order_idx + 4]);

                        if ((ts_num + 1) > audio_ts.ats_num_max)
                        {
                            audio_ts.ats_num_max = ts_num + 1;
                        }
                        get_file_entry(&ats_file[ts_num].bup_length, &ats_file[ts_num].bup_address, udf_start, offset);
                    }

                    else if (strncmp(&d_order[order_idx + 8], ".IFO", 4) == 0 || strncmp(&d_order[order_idx + 8], ".ifo", 4) == 0)
                    {
                        ts_num = get_ts_num(&d_order[order_idx + 4]);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -