From: Ehud Gavron 602-570-2546 <GAVRON@IT.SUNQUEST.COM>
Newsgroups: vmsnet.internals
Subject: Help!  (sys$init_vol)
Date: Tue, 13 Oct 1992 14:24:54 -0700 (MST)
Organization: Macro32<==>Vmsnet.Internals Gateway
X-Gateway-Source-Info: Mailing List

Date sent:  13-OCT-1992 14:22:55


        I'm trying to create a piece of code to initialize a disk or
        tape volume.  However, when I call sys$init_vol I get back
        ss$_badparam.  Can anyone either
                a. tell me what I'm doing wrong
                b. show me how to do it right?

        Thanks

        Ehud

--
Ehud Gavron        (EG76)
gavron@vesta.sunquest.com                                       This was sent
"The world bores you when you're cool."                         from an Alpha

init.c:
#include <descrip.h>
#include "initdef.h"
#include "itemlist.h"
#include <ssdef.h>
#define check_status(x) {if ((sav_stat = x) != SS$_NORMAL) sys$exit(sav_stat);}
unsigned long sav_stat;
static $DESCRIPTOR(one,"1");
struct dsc$descriptor_s errdsc;
char errbuf[128];

#define DSMexit if (!(sav_stat &1))  \
                return((long)lib$scopy_dxdx(&errdsc,vmsstatus));
#define ISMexit *vmsstatus = one;                              \
                if (!(sav_stat &1)) *vmsstatus = errdsc;                \
                return(SS$_NORMAL);
#ifdef DSM
#define mumps_return    DSMexit
#define mumps_descriptor dsc$descriptor_d
#else
#define mumps_return    ISMexit
#define mumps_descriptor dsc$descriptor_s
#endif

#ifdef __alpha
int sys$exit(),sys$init_vol(),strchr(),strncpy(),strcat(),strlen(),
        sprintf(),atoi(),printf(),scanf(),initvol();
#endif
#ifdef STANDALONE
main()
{
struct dsc$descriptor_s devnam,label,density,owner,stat;
char devbuf[64],labbuf[64],densbuf[20],ownbuf[20],statbuf[128];
int ss_status;
devnam.dsc$b_class = DSC$K_CLASS_S;
devnam.dsc$b_dtype = DSC$K_DTYPE_T;
devnam.dsc$a_pointer = (char *)&devbuf;
devnam.dsc$w_length = sizeof(devbuf);

label.dsc$b_class = DSC$K_CLASS_S;
label.dsc$b_dtype = DSC$K_DTYPE_T;
label.dsc$a_pointer = (char *)&labbuf;
label.dsc$w_length = sizeof(labbuf);

density.dsc$b_class = DSC$K_CLASS_S;
density.dsc$b_dtype = DSC$K_DTYPE_T;
density.dsc$a_pointer = (char *)&densbuf;
density.dsc$w_length = sizeof(densbuf);

owner.dsc$b_class = DSC$K_CLASS_S;
owner.dsc$b_dtype = DSC$K_DTYPE_T;
owner.dsc$a_pointer = (char *)&ownbuf;
owner.dsc$w_length = sizeof(ownbuf);

stat.dsc$b_class = DSC$K_CLASS_S;
stat.dsc$b_dtype = DSC$K_DTYPE_T;
stat.dsc$a_pointer = (char *)&statbuf;
stat.dsc$w_length = sizeof(statbuf);

        printf("Enter device name: ");
        scanf("%s",(char *)&devbuf);
        devnam.dsc$w_length = strlen(devbuf);

        printf("\nEnter volume label: ");
        scanf("%s",(char *)&labbuf);
        label.dsc$w_length = strlen(labbuf);

        printf("\nEnter optional owner uic: (\\ for none)");
        scanf("%s",(char *)&ownbuf);
        owner.dsc$w_length = strlen(ownbuf);
        if (ownbuf[0] == '\\') owner.dsc$w_length = 0;

        printf("\nEnter optional density: (\\ for none)");
        scanf("%s",(char *)&densbuf);
        density.dsc$w_length = strlen(densbuf);
        if (densbuf[0] == '\\') density.dsc$w_length = 0;

        ss_status = initvol(&devnam,&label,&density,&owner,&stat);
        printf("\nReturn status string was %s\n",stat);
        }
#endif  /* Standalone */
initvol(device_name,volume_label,density_str,owner,vmsstatus)
struct dsc$descriptor_s *device_name;
struct dsc$descriptor_s *volume_label;
struct dsc$descriptor_s *density_str;
struct dsc$descriptor_s *owner;
struct mumps_descriptor *vmsstatus;
{
        ITEMLIST initlist[3];
        int owner_uic;
        int density;
        int density_value;
        char *list_pointer;
        char *p,*q;
        char tmp[128];
        int i;
        q = (char *)&tmp;
        errdsc.dsc$b_class = DSC$K_CLASS_S;
        errdsc.dsc$b_dtype = DSC$K_DTYPE_T;
        errdsc.dsc$a_pointer = (char *)&errbuf;
        errdsc.dsc$w_length  = sizeof(errbuf);


/*      sys$init_vol(input_device_name_desc,input_label_desc,item_list); */


        initlist[0].itemcode = INIT$_OWNER;
        initlist[0].bufaddr  = (char *)&owner_uic;
        initlist[0].buflen   = sizeof(owner_uic);
        initlist[0].retlen  = 0;

        initlist[1].itemcode = INIT$_DENSITY;
        initlist[1].bufaddr  = (char *)&density;
        initlist[1].buflen   = sizeof(density);
        initlist[1].retlen  = 0;

        initlist[2].end      = 0;


        if (density_str->dsc$w_length  != 0) {
          density_value = atoi((char *)density_str->dsc$a_pointer);
          if ((density_value != 800) &&
              (density_value != 1600) &&
              (density_value != 6250)) {
             sprintf((char *)&errbuf,"MZF:initvol(): invalid density %d\n",
                density_value);
             errdsc.dsc$w_length = strlen((char *)&errbuf);
             sav_stat = 0;
             mumps_return;
             }
          switch(density_value) {
             case  800: density = INIT$K_DENSITY_800_BPI;
                        break;
             case 1600: density = INIT$K_DENSITY_1600_BPI;
                        break;
             case 6250: density = INIT$K_DENSITY_6250_BPI;
                        break;
             }
          }
        else {  /* no density specified */
          initlist[1].end = 0;  /* terminate item list after owner */
        }

        if (owner->dsc$w_length == 0) {
           list_pointer = (char *)&initlist[1];
           }
        else {
           list_pointer = (char *)&initlist[0];
           p = owner->dsc$a_pointer;            /* pointer to [x,y] */
           *(p+owner->dsc$w_length) = ']';      /* pointer to [x,y]] */
           if (*p == '[') p++;                  /* pointer to x,y]] */
           i = (int)strchr(p,',')-(int)p;                       /* i = index(,)
*/
           strncpy(q,p,i);                      /* q = 'x' */
           *(q+i) = '\0';
           owner_uic = 0x10000 * atoi(q);       /* uic = left part */
           p +=i;                               /* pointer to ,y]] */
           p++;                                 /* pointer to y]] */
           i = (int)strchr(p,']')-(int)p;                       /* i = index(])
*/
           strncpy(q,p,i);                      /* q = 'y' */
           *(q+i) = '\0';
           owner_uic += atoi(q);
           }

        i =sys$init_vol((char *)device_name,(char *)volume_label,&list_pointer);
        sav_stat = i;
        mumps_return;
}

itemlist.h:
typedef union {
        struct {
                short s_buflen;
                short s_itemcode;
                char *s_bufaddr;
                int *s_retlen;
                } s;
        unsigned long end;
        } ITEMLIST;
#define buflen          s.s_buflen
#define itemcode        s.s_itemcode
#define bufaddr         s.s_bufaddr
#define retlen          s.s_retlen
Newsgroups: vmsnet.internals