read DVD capacity code - VMS

This is a discussion on read DVD capacity code - VMS ; Hi, Here's the code. Far from being perfect, but at least a starting point. If you have built the executable, define the symbol dvdcap: $ dvdcap:==$ dvdcap.exe Usage: $ dvdcap DVD-drive: The result is stored in the symbol DISCCAP: $ ...

+ Reply to Thread
Results 1 to 2 of 2

Thread: read DVD capacity code

  1. read DVD capacity code

    Hi,

    Here's the code. Far from being perfect, but at least a starting point.

    If you have built the executable, define the symbol dvdcap:

    $ dvdcap:==$dvdcap.exe

    Usage:
    $ dvdcap DVD-drive:

    The result is stored in the symbol DISCCAP:

    $ dvdcap:==$DSA3:[DVDWRITE_V10.V6_6-1.READ_CAPACITY]dvdcap.exe
    $ dvdcap dqa0:
    Accessing target "DQA0:" Result: OK
    DVD read capacity Version 1.00
    Medium capacity: 9180416 blocks.
    $ sh symbol disccap
    DISCCAP = "9180416"

    ================================ file DVDCAP.C
    ===============================
    #ifdef __ALPHA
    #pragma nomember_alignment
    #endif

    #ifdef __ia64
    #pragma nomember_alignment
    #endif

    /* includes */
    #include
    #include
    #include
    #include
    #include
    #include
    #include
    #include
    #include
    #include
    #include
    #include


    /* defines */

    #define READ_TRACK_INFO 0x52
    #define disk$K_READ 0x1
    #define disk$K_FL_ENAB_DIS 0x2
    #define disk$K_FL_ENAB_SYNC 0x4
    #define status_is_ok(sts) ((sts) & 1)

    struct disk$DESC {
    unsigned int disk$L_OPCODE;
    unsigned int disk$L_FLAGS;
    unsigned char * disk$A_CMD_ADDR;
    unsigned int disk$L_CMD_LEN;
    char * disk$A_DATA_ADDR;
    unsigned int disk$L_DATA_LEN;
    unsigned int disk$L_PAD_LEN;
    unsigned int disk$L_PH_CH_TMOUT;
    unsigned int disk$L_DISCON_TMOUT;
    unsigned int disk$L_RES_1;
    unsigned int disk$L_RES_2;
    unsigned int disk$L_RES_3;
    unsigned int disk$L_RES_4;
    unsigned int disk$L_RES_5;
    unsigned int disk$L_RES_6;
    };

    struct disk$IOSB {
    unsigned short int disk$W_VMS_STAT;
    unsigned long int disk$L_IOSB_TFR_CNT;
    char disk$B_IOSB_FILL_1;
    unsigned char disk$B_IOSB_STS;
    };

    #ifndef VAX
    struct tms mytms;
    #endif
    time_t t_time;

    char *target_logical;
    static struct disk$DESC gk_desc;
    static unsigned char disk_data2[255];
    unsigned short gk_channel;
    static struct disk$IOSB disk_iosb;
    int cli$dcl_parse();
    #ifdef __ia64
    extern dvdcap_cld;
    #else
    int dvdcap_cld();
    #endif
    struct dsc$descriptor gk_device_d;
    int cli$get_value();
    int cli$present();

    char *cli_get_value(char *itm)
    {

    long stat;
    short l;
    char *s;
    struct dsc$descriptor itmdes,sdes;
    s=malloc(256);
    itmdes.dsc$w_length=strlen(itm);
    itmdes.dsc$b_dtype=DSC$K_DTYPE_T;
    itmdes.dsc$b_class=DSC$K_CLASS_S;
    itmdes.dsc$a_pointer=itm;
    sdes.dsc$w_length=256;
    sdes.dsc$b_dtype=DSC$K_DTYPE_T;
    sdes.dsc$b_class=DSC$K_CLASS_S;
    sdes.dsc$a_pointer=s;
    stat=cli$get_value(&itmdes,&sdes,&l);
    if(stat&1) {
    s[l]='\0';
    return s;
    } else {
    return NULL;
    }
    }

    int cli_present(char *itm)
    {
    long stat;
    struct dsc$descriptor itmdes;
    itmdes.dsc$w_length=strlen(itm);
    itmdes.dsc$b_dtype=DSC$K_DTYPE_T;
    itmdes.dsc$b_class=DSC$K_CLASS_S;
    itmdes.dsc$a_pointer=itm;
    stat=cli$present(&itmdes);
    if(stat&1) return 1;
    else return 0;
    }


    int cli_dcl_parse()
    {
    short l;
    long stat;
    char cmdlin[512],tmp[512];
    $DESCRIPTOR(cmddes,cmdlin);
    lib$get_foreign(&cmddes,0,&l);
    cmdlin[l]='\0';
    strcpy(tmp,cmdlin);
    sprintf(cmdlin,"DVDCAP %s",tmp);
    cmddes.dsc$w_length=strlen(cmdlin);
    #ifdef __ia64
    stat=cli$dcl_parse(&cmddes,&dvdcap_cld);
    #else
    stat=cli$dcl_parse(&cmddes,dvdcap_cld);
    #endif
    return stat;
    }

    void printhex(s, cp, n)
    char *s;
    unsigned char *cp;
    int n;

    {
    #ifndef VAX
    time_t actual_time;
    actual_time = times(&mytms);
    printf("%8.3f %s",(float) (actual_time - t_time)/CLK_TCK,s);
    t_time = actual_time;
    #endif
    while (--n >= 0)
    printf(" %02X", *cp++);
    printf("\n");
    return;
    }

    int read_track_info(void)

    {
    int status,cap;

    struct read_track_info_cmd
    {
    unsigned char opcode;
    unsigned adrtype:2;
    unsigned reserved1:6;
    unsigned char tracknr[4];
    char reserved2;
    unsigned char allocation_length[2];
    char control;
    }
    disk_command;

    disk_command.opcode = READ_TRACK_INFO;
    disk_command.adrtype = 0x01;
    disk_command.reserved1 = 0;
    disk_command.tracknr[0] = 0;
    disk_command.tracknr[1] = 0;
    disk_command.tracknr[2] = 0;
    disk_command.tracknr[3] = 1;
    disk_command.reserved2 = 0;
    disk_command.allocation_length[0] = 0;
    disk_command.allocation_length[1] = 0x24;
    disk_command.control = 0;

    gk_desc.disk$L_OPCODE = 1;
    gk_desc.disk$L_FLAGS = disk$K_FL_ENAB_SYNC
    | disk$K_READ
    | disk$K_FL_ENAB_DIS;
    gk_desc.disk$A_CMD_ADDR = &disk_command.opcode;
    gk_desc.disk$L_CMD_LEN = sizeof(disk_command);
    gk_desc.disk$A_DATA_ADDR = (char *) &disk_data2[0];
    gk_desc.disk$L_DATA_LEN = 0x24;
    gk_desc.disk$L_PAD_LEN = 0;
    gk_desc.disk$L_PH_CH_TMOUT = 180; /* disk phase change timeout, sec */
    gk_desc.disk$L_DISCON_TMOUT = 180; /* disk disconnect timeout, sec */
    gk_desc.disk$L_RES_1 = 0;
    gk_desc.disk$L_RES_2 = 0;
    gk_desc.disk$L_RES_3 = 0;
    gk_desc.disk$L_RES_4 = 0;
    gk_desc.disk$L_RES_5 = 0;
    gk_desc.disk$L_RES_6 = 0;

    status = sys$qiow ( 1, gk_channel, IO$_DIAGNOSE,
    &disk_iosb, 0, 0,
    &gk_desc, sizeof(gk_desc), 0, 0, 0, 0);

    disk_iosb.disk$B_IOSB_STS =
    ((disk_iosb.disk$B_IOSB_STS >> 4) & 0x7);

    /* Check the various returned status values */

    if (!(status & 1)) lib$stop (status);
    /*
    printhex("read track info command",&disk_command.opcode,
    sizeof(disk_command));
    printhex("read track info command Data",(unsigned char*
    )&disk_data2[0],0x22);
    */
    status = disk_iosb.disk$B_IOSB_STS;

    cap = 0;
    cap += disk_data2[24] << 24;
    cap += disk_data2[25] << 16;
    cap += disk_data2[26] << 8;
    cap += disk_data2[27];

    return (cap);

    }

    main(int argc, char *argv[])
    {

    char target_string[256] = "DVD_DEVICE\0";
    int cli_stat,rms_status,capacity,status;

    char caps[256];

    $DESCRIPTOR(caps_d,"DISCCAP");
    $DESCRIPTOR(value_d,caps);

    cli_stat = cli_dcl_parse();
    if (!(cli_stat&1)) {
    printf("Command-line error. Status %x\n",
    cli_stat);
    exit(cli_stat);
    }

    target_logical = getenv("DVD_DEVICE");

    if(cli_present("TARGET")) {
    /*
    printf("target-parameter found\n");
    */
    sprintf (&target_string[0],"%s\0",cli_get_value("target"));
    target_logical = &target_string[0];
    }
    else
    {
    target_logical = getenv("DVD_DEVICE");
    if (target_logical == 0) target_logical=" ";
    }

    /*
    printf("Assigning channel\n");
    */

    gk_device_d.dsc$w_length = strlen(target_string);
    gk_device_d.dsc$b_dtype = DSC$K_DTYPE_T;
    gk_device_d.dsc$b_class = DSC$K_CLASS_S;
    gk_device_d.dsc$a_pointer = &target_string[0];
    rms_status = sys$assign ( &gk_device_d,
    &gk_channel,
    0,
    0);

    if (status_is_ok(rms_status))
    {
    fprintf(stderr,"Accessing target \"%s\" Result: OK\n",target_logical);
    }
    else
    {
    fprintf(stderr,"Accessing target \"%s\" Result: Error\n",target_logical);
    }

    fprintf (stderr,
    " DVD read capacity Version 1.00\n");

    capacity = 4*read_track_info();
    fprintf (stderr," Medium capacity: %lu blocks.\n",
    capacity);
    sprintf(caps,"%i\0",capacity);
    value_d.dsc$w_length = strlen(caps);
    status = lib$set_symbol(&caps_d,&value_d,0);
    exit(status);
    }
    =================================== file DVDCAP_CLD.CLD
    ======================
    module dvdcap_cld

    define verb dvdcap
    parameter p1, value(type=$file,list), label=target
    =================================== file BUILD.COM
    ======================
    $ cc/NOMEMBER_ALIGNMENT dvdcap.C
    $ set comm/obj dvdcap_CLD.CLD
    $ link/exe=dvdcap.exe dvdcap,dvdcap_CLD
    $ cc/NOMEMBER_ALIGNMENT/noopt/debug dvdcap.C
    $ link/debug/exe=dvdcap_debug.exe dvdcap,dvdcap_CLD
    $ delete *.obj;*


  2. Re: read DVD capacity code

    Eberhard Heuser wrote:
    >
    > Hi,
    >
    > Here's the code. Far from being perfect, but at least a starting point.
    >
    > If you have built the executable, define the symbol dvdcap:
    >
    > $ dvdcap:==$dvdcap.exe
    >
    > Usage:
    > $ dvdcap DVD-drive:
    >
    > The result is stored in the symbol DISCCAP:
    >
    > $ dvdcap:==$DSA3:[DVDWRITE_V10.V6_6-1.READ_CAPACITY]dvdcap.exe
    > $ dvdcap dqa0:
    > Accessing target "DQA0:" Result: OK
    > DVD read capacity Version 1.00
    > Medium capacity: 9180416 blocks.
    > $ sh symbol disccap
    > DISCCAP = "9180416"
    > [snip]


    I've put the source and Alpha and IA64 .OLBs in a kit on my freeware site:

    http://www.djesys.com/freeware/vms/ as
    http://www.djesys.com/freeware/vms/dvdcap.zip

    DCL proc.'s to build from source and LINK from .OLBs are provided. The BUILD.COM
    builds .OLBs for both .EXE's (non-debug and debug), then it invokes the LINK.COM
    to produce the .EXEs.

    I was only able to test that the compile and LINKs go through cleanly. I lack
    facilities to test Eberhard's code any further.

    I also do not have a VAX running at present.

    --
    David J Dachtera
    dba DJE Systems
    http://www.djesys.com/

    Unofficial OpenVMS Marketing Home Page
    http://www.djesys.com/vms/market/

    Unofficial Affordable OpenVMS Home Page:
    http://www.djesys.com/vms/soho/

    Unofficial OpenVMS-IA32 Home Page:
    http://www.djesys.com/vms/ia32/

    Unofficial OpenVMS Hobbyist Support Page:
    http://www.djesys.com/vms/support/

+ Reply to Thread