Subversion Repositories SvarDOS

Rev

Rev 2040 | Rev 2042 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2040 Rev 2041
Line 29... Line 29...
29
****************************************************************************/
29
****************************************************************************/
30
 
30
 
31
 
31
 
32
/*** Expects Pointers to be near (Tiny, Small, and Medium models ONLY) ***/
32
/*** Expects Pointers to be near (Tiny, Small, and Medium models ONLY) ***/
33
 
33
 
34
#include "dosdisk.h"
34
#include <dos.h>
35
#include <stdlib.h>
35
#include <stdlib.h>
36
#include <string.h>
36
#include <string.h>
37
 
37
 
-
 
38
#include "dosdisk.h"
-
 
39
 
38
#define searchAttr ( FILE_ATTRIBUTE_DIRECTORY | FILE_ATTRIBUTE_HIDDEN | \
40
#define searchAttr ( FILE_ATTRIBUTE_DIRECTORY | FILE_ATTRIBUTE_HIDDEN | \
39
   FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_ARCHIVE )
41
   FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_ARCHIVE )
40
 
42
 
41
/* If this variable is nonzero then will 1st attempt LFN findfirst
43
/* If this variable is nonzero then will 1st attempt LFN findfirst
42
 * (findfirst calls sets flag, so findnext/findclose know proper method to continue)
44
 * (findfirst calls sets flag, so findnext/findclose know proper method to continue)
Line 49... Line 51...
49
 
51
 
50
/* copy old style findfirst data FFDTA to a WIN32_FIND_DATA
52
/* copy old style findfirst data FFDTA to a WIN32_FIND_DATA
51
 * NOTE: does not map exactly.
53
 * NOTE: does not map exactly.
52
 * internal to this module only.
54
 * internal to this module only.
53
 */
55
 */
54
static void copyFileData(struct WIN32_FIND_DATA *findData, FFDTA *finfo)
56
static void copyFileData(struct WIN32_FIND_DATA *findData, const struct FFDTA *finfo)
55
{
57
{
56
  /* Copy requried contents over into required structure */
58
  /* Copy requried contents over into required structure */
57
  strcpy(findData->cFileName, finfo->ff_name);
59
  strcpy(findData->cFileName, finfo->ff_name);
58
  findData->dwFileAttributes = (DWORD)finfo->ff_attrib;
60
  findData->dwFileAttributes = (DWORD)finfo->ff_attr;
59
 
61
 
60
  /* copy over rest (not quite properly) */
62
  /* copy over rest (not quite properly) */
61
  findData->ftCreationTime.ldw[0] = finfo->ff_ftime;
63
  findData->ftCreationTime.ldw[0] = finfo->ff_ftime;
62
  findData->ftLastAccessTime.ldw[0] = finfo->ff_ftime;
64
  findData->ftLastAccessTime.ldw[0] = finfo->ff_ftime;
63
  findData->ftLastWriteTime.ldw[0] = finfo->ff_ftime;
65
  findData->ftLastWriteTime.ldw[0] = finfo->ff_ftime;
Line 132... Line 134...
132
 
134
 
133
  /* Use DOS (0x4E) findfirst, returning if error */
135
  /* Use DOS (0x4E) findfirst, returning if error */
134
  hnd->flag = FINDFILEOLD;
136
  hnd->flag = FINDFILEOLD;
135
 
137
 
136
  /* allocate memory for the FFDTA */
138
  /* allocate memory for the FFDTA */
137
  if ((hnd->fhnd.ffdtaptr = (FFDTA *)malloc(sizeof(struct FFDTA))) == NULL)
139
  if ((hnd->fhnd.ffdtaptr = (struct FFDTA *)malloc(sizeof(struct FFDTA))) == NULL)
138
  {
140
  {
139
    free(hnd);
141
    free(hnd);
140
    return INVALID_HANDLE_VALUE;
142
    return INVALID_HANDLE_VALUE;
141
  }
143
  }
142
 
144
 
Line 317... Line 319...
317
  DWORD nVolumeNameSize, DWORD *lpVolumeSerialNumber,
319
  DWORD nVolumeNameSize, DWORD *lpVolumeSerialNumber,
318
  DWORD *lpMaximumComponentLength, DWORD *lpFileSystemFlags,
320
  DWORD *lpMaximumComponentLength, DWORD *lpFileSystemFlags,
319
  char *lpFileSystemNameBuffer, DWORD nFileSystemNameSize)
321
  char *lpFileSystemNameBuffer, DWORD nFileSystemNameSize)
320
{
322
{
321
  /* File info for getting  Volume Label (using directory entry) */
323
  /* File info for getting  Volume Label (using directory entry) */
322
  FFDTA finfo;
324
  struct FFDTA finfo;
323
 
325
 
324
  /* Using DOS interrupt to get serial number */
326
  /* Using DOS interrupt to get serial number */
325
  struct media_info
327
  struct media_info
326
  {
328
  {
327
    short dummy;
329
    short dummy;
Line 435... Line 437...
435
	MOV [cflag], AX           //; Set flag with error.
437
	MOV [cflag], AX           //; Set flag with error.
436
	JMP cleanup               //; Restore DTA
438
	JMP cleanup               //; Restore DTA
437
      }
439
      }
438
success:                        //; True volume entry only has volume attribute set [MS' LFNspec]
440
success:                        //; True volume entry only has volume attribute set [MS' LFNspec]
439
      asm {                     //;     But they may also have archive bit set!!!
441
      asm {                     //;     But they may also have archive bit set!!!
440
	LEA BX, finfo.ff_attrib   //; Load address of file's attributes returned by findfirst/next
442
	LEA BX, finfo.ff_attr   //; Load address of file's attributes returned by findfirst/next
441
	MOV AL, BYTE PTR [BX]     //; Looking for a BYTE that is FILE_ATTRIBUTE_LABEL only
443
	MOV AL, BYTE PTR [BX]     //; Looking for a BYTE that is FILE_ATTRIBUTE_LABEL only
442
      AND AL, 0xDF              //; Ignore Archive bit
444
      AND AL, 0xDF              //; Ignore Archive bit
443
	CMP AL, FILE_ATTRIBUTE_LABEL
445
	CMP AL, FILE_ATTRIBUTE_LABEL
444
	JE cleanup                //; They match, so should be true volume entry.
446
	JE cleanup                //; They match, so should be true volume entry.
445
	MOV AX, 4F00h             //; Otherwise keep looking (findnext)
447
	MOV AX, 4F00h             //; Otherwise keep looking (findnext)
Line 523... Line 525...
523
    return 0;   /* zero means error! */
525
    return 0;   /* zero means error! */
524
  else
526
  else
525
    return 1;   /* Success (drive exists we think anyway) */
527
    return 1;   /* Success (drive exists we think anyway) */
526
}
528
}
527
 
529
 
-
 
530
 
-
 
531
/* retrieve attributes (ReadOnly/System/...) about file or directory
-
 
532
 * returns (DWORD)-1 on error
-
 
533
 */
-
 
534
DWORD GetFileAttributes(const char *pathname) {
-
 
535
  union REGS r;
-
 
536
  struct SREGS s;
-
 
537
  char buffer[260];
-
 
538
  int slen;
-
 
539
 
-
 
540
  /* 1st try LFN - Extended get/set attributes (in case LFN used) */
-
 
541
  if (LFN_Enable_Flag)
-
 
542
  {
-
 
543
    r.x.ax = 0x7143;                  /* LFN API, Extended Get/Set Attributes */
-
 
544
    r.x.bx = 0x00;                    /* BL=0, get file attributes            */
-
 
545
    r.x.dx = FP_OFF(pathname);        /* DS:DX points to ASCIIZ filename      */
-
 
546
 
-
 
547
    segread(&s);                      /* load with current segment values     */
-
 
548
    s.ds = FP_SEG(pathname);          /* get Segment of our filename pointer  */
-
 
549
 
-
 
550
    r.x.cflag = 1;                    /* should be set when unsupported ***   */
-
 
551
    asm stc;                          /* but clib usually ignores on entry    */
-
 
552
 
-
 
553
    /* Actually perform the call, carry should be set on error or unuspported */
-
 
554
    intdosx(&r, &r, &s);         /* Clib function to invoke DOS int21h call   */
-
 
555
 
-
 
556
    if (!r.x.cflag)              /* if carry not set then cx has desired info */
-
 
557
      return (DWORD)r.x.cx;
-
 
558
    /* else error other than unsupported LFN api or invalid function [FreeDOS]*/
-
 
559
    else if ((r.x.ax != 0x7100) || (r.x.ax != 0x01))
-
 
560
      return (DWORD)-1;
-
 
561
    /* else fall through to standard get/set file attribute call */
-
 
562
  }
-
 
563
 
-
 
564
  /* we must remove any slashes from end */
-
 
565
  slen = strlen(pathname) - 1;  /* Warning, assuming pathname is not ""   */
-
 
566
  strcpy(buffer, pathname);
-
 
567
  if ((buffer[slen] == '\\') || (buffer[slen] == '/')) /* ends in a slash */
-
 
568
  {
-
 
569
    /* don't remove from root directory (slen == 0),
-
 
570
     * ignore UNC paths as SFN doesn't handle them anyway
-
 
571
     * if slen == 2, then check if drive given (e.g. C:\)
-
 
572
     */
-
 
573
    if (slen && !(slen == 2 &&  buffer[1] == ':'))
-
 
574
      buffer[slen] = '\0';
-
 
575
  }
-
 
576
  /* return standard attributes */
-
 
577
  r.x.ax = 0x4300;                  /* standard Get/Set File Attributes */
-
 
578
  r.x.dx = FP_OFF(buffer);          /* DS:DX points to ASCIIZ filename      */
-
 
579
  segread(&s);                      /* load with current segment values     */
-
 
580
  s.ds = FP_SEG(buffer);            /* get Segment of our filename pointer  */
-
 
581
  intdosx(&r, &r, &s);              /* invoke the DOS int21h call           */
-
 
582
 
-
 
583
  //if (r.x.cflag) printf("ERROR getting std attributes of %s, DOS err %i\n", buffer, r.x.ax);
-
 
584
  if (r.x.cflag) return (DWORD)-1;  /* error obtaining attributes           */
-
 
585
  return (DWORD)(0x3F & r.x.cx); /* mask off any DRDOS bits     */
-
 
586
}