⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 hydir.c

📁 德国Hyperstone公司dsp的CF卡驱动程序
💻 C
字号:
/*
 **************************************************************
 *
 *  hyperstone MS-DOS FAT File System Drivers
 *
 *  MS-DOS like application routines
 *
 *  Christoph Baumhof 2000-03-21
 *  Reinhard K乭ne 2000-03-21
 *  Mihajlo Varga 2000-03-21
 *
 *  Copyright (C) 1997-2000 hyperstone electronics GmbH Konstanz
 *
 *  2000-03-21 initial release
 *
 * $Id$
 *
 * $Log$
 *
 **************************************************************
 *
 * Changes:
 *
 **************************************************************
 */


#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
#include <errno.h>
#include <io.h>
#include "hy_dos.h"

#define VFAT_SUPPORT

struct unicode_char {
	char lchar;
	char uchar;
};

/* #define MAX_VFAT_SUBENTRIES 32 */ /* Theoretical max # of VSEs */
#define MAX_VFAT_SUBENTRIES 20		/* Max useful # of VSEs */
#define VSE_NAMELEN 13

#define VSE1SIZE 5
#define VSE2SIZE 6
#define VSE3SIZE 2

struct vfat_subentry {
	unsigned char id;		/* 0x40 = last; & 0x1f = VSE ID */
	struct unicode_char text1[VSE1SIZE] PACKED;
	unsigned char attribute;	/* 0x0f for VFAT */
	unsigned char hash1;		/* Always 0? */
	unsigned char sum;		/* Checksum of short name */
	struct unicode_char text2[VSE2SIZE] PACKED;
	unsigned char sector_l;		/* 0 for VFAT */
	unsigned char sector_u;		/* 0 for VFAT */
	struct unicode_char text3[VSE3SIZE] PACKED;
};

/* Enough size for a worst case number of full VSEs plus a null */
#define VBUFSIZE ((MAX_VFAT_SUBENTRIES*VSE_NAMELEN) + 1)

/* Max legal length of a VFAT long name */
#define MAX_VNAMELEN (255)

#define VSE_PRESENT 0x01
#define VSE_LAST 0x40
#define VSE_MASK 0x1f

struct vfat_state {
	char name[VBUFSIZE];
	int status; /* is now a bit map of 32 bits */
	int subentries;
	unsigned char sum; /* no need to remember the sum for each entry,
			    * it is the same anyways */
};


#define DO_OPEN 1
#define ACCEPT_NO_DOTS 0x4
#define ACCEPT_PLAIN 0x20
#define ACCEPT_DIR 0x10
#define ACCEPT_LABEL 0x08
#define SINGLE 2
#define MATCH_ANY 0x40
#define NO_MSG 0x80
#define NO_DOTS 0x100



/*
 * Print an MSDOS directory date stamp.
 */
static void print_date(struct directory *dir)
{
	printf("%02d-%02d-%02d", DOS_DAY(dir), DOS_MONTH(dir), DOS_YEAR(dir));
}

/*
 * Print an MSDOS directory time stamp.
 */
static void print_time(struct directory *dir)
{
	char am_pm;
	int hour = DOS_HOUR(dir);

	am_pm = (hour >= 12) ? 'p' : 'a';
	if (hour > 12)
		hour = hour - 12;
	if (hour == 0)
		hour = 12;

	printf("%2d:%02d%c", hour, DOS_MINUTE(dir), am_pm);
}



static char *files = "files";
static char *dirs  = "dirs";

int _hy_dir(int argc, char **argv, int type) {
   struct directory *dir, *tmp;
   int size, size_acc, alignsize_acc, cnt_files, cnt_dir, found;
   char fname[13];

   dir = malloc(size = _ROOTEntrySize(0, 0));
   if (dir)
      _readROOTEntry(0, 0, dir);
   else
      return -1;

   tmp = dir;
   fname[11] = 0;
   /* search for volume label */
   found = 0;
   do {
      if ( tmp->name[0] != DELMARK ) {
          if (tmp->attr & D_VOLID) {
             memcpy(fname, tmp->name, 11);
             found = 1;
          }
      }
      tmp++;
   }
   while(tmp->name[0] && !found);
   if (!found) {
       free(dir);
       return -1;
   }
   size_acc = _getserialnum(0, 0);
   printf(" Volume in drive Z is %s     Serial number is %04X:%04X\n", fname,
            (unsigned long)size_acc >> 16, (unsigned long)size_acc & 0xFFFF);
   printf(" Directory of Z:\%s\n\n", "xxx");

   size_acc = 0;
   alignsize_acc = 0;
   cnt_files = 0;
   cnt_dir = 0;
   fname[12] = 0;
   fname[8] = ' ';
   tmp = dir;
   do {
      if ( tmp->name[0] != DELMARK ) {
         if (!(tmp->attr & D_VOLID)) {
            memcpy(fname, tmp->name, 8);
            memcpy(&fname[9], tmp->ext, 3);
            if (size = CvtByteOrder32(tmp->size))
               cnt_files ++;
            size_acc += size;
            alignsize_acc += _alignClusterSize(size, 0, 0);
            if (tmp->attr & D_DIR) {
               cnt_dir++;
               printf("%s    <DIR>     %02d-%02d-%02d   ", fname, DOS_DAY(tmp), \
                    DOS_MONTH(tmp), DOS_YEAR(tmp));
            }
            else
               printf("%s %10d   %02d-%02d-%02d   ", fname, size, DOS_DAY(tmp), \
                    DOS_MONTH(tmp), DOS_YEAR(tmp));
            print_time(tmp);
            printf("\n");
         }
      }
      tmp++;
   }
   while(tmp->name[0]);
   if (cnt_files < 2)
        files[4] = 0;
   if (cnt_dir < 2)
        dirs[3] = 0;

   printf("     %10d bytes in %d %s and %d %s %d bytes allocated\n", size_acc, \
                cnt_files, files, cnt_dir, dirs, alignsize_acc);
   free(dir);
   return 0;
}

int _hy_attrib(int argc, char **argv, int type) {
   struct directory *dir, *tmp;
   int i;
   char fname[13];
   char attrib_str[6];

   dir = malloc(_ROOTEntrySize(0, 0));
   if (dir)
      _readROOTEntry(0, 0, dir);
   else
      return -1;

   tmp = dir;
   fname[12] = 0;
   fname[8] = ' ';
   for (i=0; i < 5; i++)
      attrib_str[i] = '_';
   attrib_str[5] = 0;
   do {
      int attr;
      if ( tmp->name[0] != DELMARK ) {
         attr = tmp->attr;
         if (attr & FA_RDONLY)
             attrib_str[0] = 'R';
         if (attr & FA_HIDDEN)
             attrib_str[1] = 'H';
         if (attr & FA_SYSTEM)
             attrib_str[2] = 'S';
         if (attr & FA_ARCH)
             attrib_str[3] = 'A';
         memcpy(fname, tmp->name, 8);
         memcpy(&fname[9], tmp->ext, 3);
         printf("%s  %s\n", attrib_str, fname);
      }
      tmp++;
   }
   while(tmp->name[0]);
   free(dir);
   return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -