### 例 5-4　仮想アドレス空間の定義された領域へのセクションのマッピング

         #include <ssdef.h>
         #include <stdio.h>
         #include <stsdef.h>
         #include <descrip.h>
         #include <dvidef.h>
         #include <rms.h>
         #include <secdef.h>

         struct FAB fab;

         char *filename = "maptest.dat";

         char _align(page) buffer[512];

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

              int    status = 0;
              long   flags = 0;
              long   inadr[2];
              long   retadr[2];
              int    fileChannel;

         /********  create disk file to be mapped *************/

              fab = cc$rms_fab;
              fab.fab$l_fna = filename;
              fab.fab$b_fns = strlen( filename );
              fab.fab$l_fop = FAB$M_CIF | FAB$M_UFO;  /* must be UFO */

              status = sys$create( &fab );

              if( status & STS$M_SUCCESS )
                 printf("Opened mapfile %s\n",filename);
              else
              {
                 printf("Cannot open mapfile %s\n",filename);
                 exit( status );
              }
              fileChannel = fab.fab$l_stv;

         /**********  create and map the section  ****************/

              inadr[0] = &buffer[0];
              inadr[1] = &buffer[511];

              printf("inadr[0]=%u,inadr[1]=%u\n",inadr[0],inadr[1]);

              status = SYS$CRMPSC(inadr, /* inadr=address target for map */
                                 &retadr, /* retadr= what was actually mapped */
                                       0, /* acmode  */
                                       0, /* flags */
                                       0, /* gsdnam, only for global sections */
                                       0, /* ident, only for global sections */
                                       0, /* relpag, only for global sections */
                             fileChannel, /* returned by SYS$CREATE */
                                       0, /* pagcnt = size of sect. file used */
                                       0, /* vbn = first block of file used */
                                       0, /* prot = default okay */
                                       0 ); /* page fault cluster size */

              if( status & STS$M_SUCCESS )
              {
                   printf("Map succeeded\n");
                   printf("retadr[0]=%u,retadr[1]=%u\n",retadr[0],retadr[1]);
              }
              else
              {
                   printf("Map failed\n");
                   exit( status );
              }
         }

[ 本文に戻る ]