platform/os2.c
changeset 416 eadb08626c80
parent 412 f743cf88c61f
child 420 8869f1432112
equal deleted inserted replaced
415:cd3495c18f03 416:eadb08626c80
   231     PTIB ptib;
   231     PTIB ptib;
   232     PPIB ppib;
   232     PPIB ppib;
   233     PHYSFS_sint32 len;
   233     PHYSFS_sint32 len;
   234 
   234 
   235     assert(baseDir == NULL);
   235     assert(baseDir == NULL);
   236 
       
   237     BAIL_IF_MACRO(os2err(DosGetInfoBlocks(&ptib, &ppib)) != NO_ERROR, NULL, 0);
   236     BAIL_IF_MACRO(os2err(DosGetInfoBlocks(&ptib, &ppib)) != NO_ERROR, NULL, 0);
   238     rc = DosQueryModuleName(ppib->pib_hmte, sizeof (buf), (PCHAR) buf);
   237     rc = DosQueryModuleName(ppib->pib_hmte, sizeof (buf), (PCHAR) buf);
   239     BAIL_IF_MACRO(os2err(rc) != NO_ERROR, NULL, 0);
   238     BAIL_IF_MACRO(os2err(rc) != NO_ERROR, NULL, 0);
   240 
   239 
   241     /* chop off filename, leave path. */
   240     /* chop off filename, leave path. */
   246             buf[len] = '\0';
   245             buf[len] = '\0';
   247             break;
   246             break;
   248         } /* if */
   247         } /* if */
   249     } /* for */
   248     } /* for */
   250 
   249 
   251     assert(len > 0);  /* should have been an "x:\\" on the front on string. */
   250     assert(len > 0);  /* should have been a "x:\\" on the front on string. */
   252 
   251 
   253     baseDir = (char *) malloc(len + 1);
   252     baseDir = (char *) malloc(len + 1);
   254     BAIL_IF_MACRO(baseDir == NULL, ERR_OUT_OF_MEMORY, 0);
   253     BAIL_IF_MACRO(baseDir == NULL, ERR_OUT_OF_MEMORY, 0);
   255     strcpy(baseDir, buf);
   254     strcpy(baseDir, buf);
   256 
   255 
   276     DosError(FERR_ENABLEHARDERR | FERR_ENABLEEXCEPTION);
   275     DosError(FERR_ENABLEHARDERR | FERR_ENABLEEXCEPTION);
   277     return(rc == NO_ERROR);
   276     return(rc == NO_ERROR);
   278 } /* is_cdrom_inserted */
   277 } /* is_cdrom_inserted */
   279 
   278 
   280 
   279 
       
   280 /* looks like "CD01" in ASCII (littleendian)...used for an ioctl. */
       
   281 #define CD01 0x31304443
       
   282 
   281 static int is_cdrom_drive(ULONG drive)
   283 static int is_cdrom_drive(ULONG drive)
   282 {
   284 {
   283     PHYSFS_uint16 cmd = (((drive & 0xFF) << 8) | 0);
   285     PHYSFS_uint32 param, data;
   284     BIOSPARAMETERBLOCK bpb;
       
   285     ULONG ul1, ul2;
   286     ULONG ul1, ul2;
   286     APIRET rc;
   287     APIRET rc;
   287 
   288     HFILE hfile = NULLHANDLE;
   288     rc = DosDevIOCtl((HFILE) -1, IOCTL_DISK,
   289     char drivename[3] = { 'A' + drive, ':', '\0' };
   289                      DSK_GETDEVICEPARAMS,
   290 
   290                      &cmd, sizeof (cmd), &ul1,
   291     rc = DosOpen(drivename, &hfile, &ul1, 0, 0,
   291                      &bpb, sizeof (bpb), &ul2);
   292                  OPEN_ACTION_OPEN_IF_EXISTS | OPEN_ACTION_FAIL_IF_NEW,
   292 
   293                  OPEN_FLAGS_DASD | OPEN_FLAGS_FAIL_ON_ERROR |
   293     /*
   294                  OPEN_FLAGS_NOINHERIT | OPEN_SHARE_DENYNONE, NULL);
   294      * !!! FIXME: Note that this tells us that the media is REMOVABLE...
   295     BAIL_IF_MACRO(rc != NO_ERROR, NULL, 0);
   295      * !!! FIXME:  but it might not be a CD-ROM...check driver name?
   296 
   296      */
   297     data = 0;
   297     return((rc == NO_ERROR) && ((bpb.fsDeviceAttr & 0x0001) == 0));
   298     param = PHYSFS_swapULE32(CD01);
       
   299     ul1 = ul2 = sizeof (PHYSFS_uint32);
       
   300     rc = DosDevIOCtl(hfile, IOCTL_CDROMDISK, CDROMDISK_GETDRIVER,
       
   301                      &param, sizeof (param), &ul1, &data, sizeof (data), &ul2);
       
   302 
       
   303     DosClose(hfile);
       
   304     return((rc == NO_ERROR) && (PHYSFS_swapULE32(data) == CD01));
   298 } /* is_cdrom_drive */
   305 } /* is_cdrom_drive */
   299 
   306 
   300 
   307 
   301 char **__PHYSFS_platformDetectAvailableCDs(void)
   308 char **__PHYSFS_platformDetectAvailableCDs(void)
   302 {
   309 {
   303     ULONG dummy;
   310     ULONG dummy;
   304     ULONG drivemap;
   311     ULONG drivemap;
   305     ULONG i, bit;
   312     ULONG i, bit;
   306     APIRET rc;
   313     APIRET rc;
   307     char **retval;
   314     char **retval;
   308     PHYSFS_uint32 cd_count = 0;
   315     PHYSFS_uint32 cd_count = 1;   /* we count the NULL entry. */
   309 
   316 
   310     retval = (char **) malloc(sizeof (char *));
   317     retval = (char **) malloc(sizeof (char *));
   311     BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
   318     BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
   312     *retval = NULL;
   319     *retval = NULL;
   313 
   320 
   338                 } /* if */
   345                 } /* if */
   339             } /* if */
   346             } /* if */
   340         } /* if */
   347         } /* if */
   341     } /* for */
   348     } /* for */
   342 
   349 
       
   350     retval[cd_count - 1] = NULL;
   343     return(retval);
   351     return(retval);
   344 } /* __PHYSFS_platformDetectAvailableCDs */
   352 } /* __PHYSFS_platformDetectAvailableCDs */
   345 
   353 
   346 
   354 
   347 char *__PHYSFS_platformCalcBaseDir(const char *argv0)
   355 char *__PHYSFS_platformCalcBaseDir(const char *argv0)
   439 
   447 
   440 LinkedStringList *__PHYSFS_platformEnumerateFiles(const char *dirname,
   448 LinkedStringList *__PHYSFS_platformEnumerateFiles(const char *dirname,
   441                                                   int omitSymLinks)
   449                                                   int omitSymLinks)
   442 {
   450 {
   443     char spec[CCHMAXPATH];
   451     char spec[CCHMAXPATH];
   444     LinkedStringList *retval = NULL, *p = NULL;
   452     LinkedStringList *ret = NULL, *p = NULL;
   445     FILEFINDBUF3 fb;
   453     FILEFINDBUF3 fb;
   446     HDIR hdir = HDIR_CREATE;
   454     HDIR hdir = HDIR_CREATE;
   447     ULONG count = 1;
   455     ULONG count = 1;
   448     APIRET rc;
   456     APIRET rc;
   449 
   457 
   450     BAIL_IF_MACRO(strlen(dirname) > sizeof (spec) - 4, ERR_OS_ERROR, NULL);
   458     BAIL_IF_MACRO(strlen(dirname) > sizeof (spec) - 5, ERR_OS_ERROR, NULL);
   451     strcpy(spec, dirname);
   459     strcpy(spec, dirname);
   452     strcat(spec, "*.*");
   460     strcat(spec, (spec[strlen(spec) - 1] != '\\') ? "\\*.*" : "*.*");
   453 
   461 
   454     rc = DosFindFirst(spec, &hdir,
   462     rc = DosFindFirst(spec, &hdir,
   455                       FILE_DIRECTORY | FILE_ARCHIVED |
   463                       FILE_DIRECTORY | FILE_ARCHIVED |
   456                       FILE_READONLY | FILE_HIDDEN | FILE_SYSTEM,
   464                       FILE_READONLY | FILE_HIDDEN | FILE_SYSTEM,
   457                       &fb, sizeof (fb), &count, FIL_STANDARD);
   465                       &fb, sizeof (fb), &count, FIL_STANDARD);
   458     BAIL_IF_MACRO(os2err(rc) != NO_ERROR, NULL, 0);
   466     BAIL_IF_MACRO(os2err(rc) != NO_ERROR, NULL, 0);
   459     while (count == 1)
   467     while (count == 1)
   460     {
   468     {
   461         if (strcmp(fb.achName, ".") == 0)
   469         if ((strcmp(fb.achName, ".") != 0) && (strcmp(fb.achName, "..") != 0))
   462             continue;
   470             ret = __PHYSFS_addToLinkedStringList(ret, &p, fb.achName, -1);
   463 
       
   464         if (strcmp(fb.achName, "..") == 0)
       
   465             continue;
       
   466 
       
   467         retval = __PHYSFS_addToLinkedStringList(retval, &p, fb.achName, -1);
       
   468 
   471 
   469         DosFindNext(hdir, &fb, sizeof (fb), &count);
   472         DosFindNext(hdir, &fb, sizeof (fb), &count);
   470     } /* while */
   473     } /* while */
   471 
   474 
   472     DosFindClose(hdir);
   475     DosFindClose(hdir);
   473     return(retval);
   476     return(ret);
   474 } /* __PHYSFS_platformEnumerateFiles */
   477 } /* __PHYSFS_platformEnumerateFiles */
   475 
   478 
   476 
   479 
   477 char *__PHYSFS_platformCurrentDir(void)
   480 char *__PHYSFS_platformCurrentDir(void)
   478 {
   481 {