Subversion Repositories SvarDOS

Rev

Rev 2046 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2046 Rev 2047
Line 35... Line 35...
35
#include <stdlib.h>
35
#include <stdlib.h>
36
#include <string.h>
36
#include <string.h>
37
 
37
 
38
#include "dosdisk.h"
38
#include "dosdisk.h"
39
 
39
 
40
#define searchAttr ( FILE_ATTRIBUTE_DIRECTORY | FILE_ATTRIBUTE_HIDDEN | \
40
#define searchAttr ( FILE_A_DIR | FILE_A_HIDDEN | FILE_A_SYSTEM | FILE_A_READONLY | FILE_A_ARCH )
41
   FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_ARCHIVE )
-
 
42
 
41
 
43
 
42
 
44
/* copy old style findfirst data FFDTA to a WIN32_FIND_DATA
43
/* copy old style findfirst data FFDTA to a WIN32_FIND_DATA
45
 * NOTE: does not map exactly.
44
 * NOTE: does not map exactly.
46
 * internal to this module only.
45
 * internal to this module only.
47
 */
46
 */
48
static void copyFileData(struct WIN32_FIND_DATA *findData, const struct FFDTA *finfo)
47
static void copyFileData(struct WIN32_FIND_DATA *findData, const struct FFDTA *finfo)
49
{
48
{
50
  /* Copy requried contents over into required structure */
49
  /* Copy requried contents over into required structure */
51
  strcpy(findData->cFileName, finfo->ff_name);
50
  strcpy(findData->cFileName, finfo->ff_name);
52
  findData->dwFileAttributes = (DWORD)finfo->ff_attr;
51
  findData->attrib = finfo->ff_attr;
53
 
52
 
54
  /* copy over rest (not quite properly) */
53
  /* copy over rest (not quite properly) */
55
  findData->ftCreationTime.ldw[0] = finfo->ff_ftime;
54
  findData->ftCreationTime.ldw[0] = finfo->ff_ftime;
56
  findData->ftLastAccessTime.ldw[0] = finfo->ff_ftime;
55
  findData->ftLastAccessTime.ldw[0] = finfo->ff_ftime;
57
  findData->ftLastWriteTime.ldw[0] = finfo->ff_ftime;
56
  findData->ftLastWriteTime.ldw[0] = finfo->ff_ftime;
Line 72... Line 71...
72
  static char path[1024];
71
  static char path[1024];
73
  struct FFDTA *hnd;
72
  struct FFDTA *hnd;
74
  short cflag = 0;  /* used to indicate if findfirst is succesful or not */
73
  short cflag = 0;  /* used to indicate if findfirst is succesful or not */
75
 
74
 
76
  /* verify findData is valid */
75
  /* verify findData is valid */
77
  if (findData == NULL)
-
 
78
    return INVALID_HANDLE_VALUE;
76
  if (findData == NULL) return INVALID_HANDLE_VALUE;
79
 
77
 
80
  /* allocate memory for the handle */
78
  /* allocate memory for the handle */
81
  if ((hnd = malloc(sizeof(*hnd))) == NULL) return INVALID_HANDLE_VALUE;
79
  if ((hnd = malloc(sizeof(*hnd))) == NULL) return INVALID_HANDLE_VALUE;
82
 
80
 
83
  /* initialize structure (clear) */
81
  /* initialize structure (clear) */
Line 297... Line 295...
297
  } else {
295
  } else {
298
    strcat(pathname, "*.*");
296
    strcat(pathname, "*.*");
299
  }
297
  }
300
 
298
 
301
  /* Search for volume using old findfirst, as LFN version (NT5 DOS box) does
299
  /* Search for volume using old findfirst, as LFN version (NT5 DOS box) does
302
   * not recognize FILE_ATTRIBUTE_LABEL = 0x0008 as label attribute.
300
   * not recognize FILE_A_VOL = 0x0008 as label attribute.
303
   */
301
   */
304
  {
302
  {
305
    struct FFDTA finfo;
303
    struct FFDTA finfo;
306
    unsigned short attr_seg = FP_SEG(finfo.ff_attr);
304
    unsigned short attr_seg = FP_SEG(finfo.ff_attr);
307
    unsigned short attr_off = FP_OFF(finfo.ff_attr);
305
    unsigned short attr_off = FP_OFF(finfo.ff_attr);
Line 326... Line 324...
326
      push ds
324
      push ds
327
      mov ds, finfo_seg
325
      mov ds, finfo_seg
328
      int 0x21                  //; Execute interrupt
326
      int 0x21                  //; Execute interrupt
329
      pop ds
327
      pop ds
330
      mov ax, 0x4E00            //; Actual findfirst call
328
      mov ax, 0x4E00            //; Actual findfirst call
331
      mov cx, FILE_ATTRIBUTE_LABEL
329
      mov cx, FILE_A_VOL
332
      mov dx, pathname_off      //; Load DS:DX with pointer to modified RootPath for Findfirt
330
      mov dx, pathname_off      //; Load DS:DX with pointer to modified RootPath for Findfirt
333
      push ds
331
      push ds
334
      mov ds, pathname_seg
332
      mov ds, pathname_seg
335
      int 0x21                  //; Execute interrupt, Carry set on error, unset on success
333
      int 0x21                  //; Execute interrupt, Carry set on error, unset on success
336
      pop ds
334
      pop ds
Line 342... Line 340...
342
      push es
340
      push es
343
      mov es, attr_seg
341
      mov es, attr_seg
344
      mov al, [es:bx]              //; Looking for a BYTE that is FILE_ATTRIBUTE_LABEL only
342
      mov al, [es:bx]              //; Looking for a BYTE that is FILE_ATTRIBUTE_LABEL only
345
      pop es
343
      pop es
346
      and al, 0xDF              //; Ignore Archive bit
344
      and al, 0xDF              //; Ignore Archive bit
347
      cmp al, FILE_ATTRIBUTE_LABEL
345
      cmp al, FILE_A_VOL
348
      je cleanup                //; They match, so should be true volume entry.
346
      je cleanup                //; They match, so should be true volume entry.
349
      mov ax, 0x4F00            //; Otherwise keep looking (findnext)
347
      mov ax, 0x4F00            //; Otherwise keep looking (findnext)
350
      int 0x21                  //; Execute interrupt
348
      int 0x21                  //; Execute interrupt
351
      jnc success               //; If carry is not set then succesful
349
      jnc success               //; If carry is not set then succesful
352
      mov [cflag], ax           //; Set flag with error.
350
      mov [cflag], ax           //; Set flag with error.
Line 433... Line 431...
433
 
431
 
434
 
432
 
435
/* retrieve attributes (ReadOnly/System/...) about file or directory
433
/* retrieve attributes (ReadOnly/System/...) about file or directory
436
 * returns (DWORD)-1 on error
434
 * returns (DWORD)-1 on error
437
 */
435
 */
438
DWORD GetFileAttributes(const char *pathname) {
436
int GetFileAttributes(unsigned short *attr, const char *pathname) {
439
  union REGS r;
437
  union REGS r;
440
  struct SREGS s;
438
  struct SREGS s;
441
  char buffer[260];
439
  char buffer[260];
442
  int slen;
440
  int slen;
443
 
441
 
Line 458... Line 456...
458
  segread(&s);                      /* load with current segment values     */
456
  segread(&s);                      /* load with current segment values     */
459
  s.ds = FP_SEG(buffer);            /* get Segment of our filename pointer  */
457
  s.ds = FP_SEG(buffer);            /* get Segment of our filename pointer  */
460
  intdosx(&r, &r, &s);              /* invoke the DOS int21h call           */
458
  intdosx(&r, &r, &s);              /* invoke the DOS int21h call           */
461
 
459
 
462
  //if (r.x.cflag) printf("ERROR getting std attributes of %s, DOS err %i\n", buffer, r.x.ax);
460
  //if (r.x.cflag) printf("ERROR getting std attributes of %s, DOS err %i\n", buffer, r.x.ax);
463
  if (r.x.cflag) return (DWORD)-1;  /* error obtaining attributes           */
461
  if (r.x.cflag) return(-1);  /* error obtaining attributes           */
464
  return (DWORD)(0x3F & r.x.cx); /* mask off any DRDOS bits     */
462
  *attr = (0x3F & r.x.cx); /* mask off any DRDOS bits     */
-
 
463
  return(0);
465
}
464
}