delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2000/07/20/13:01:08

From: "Thorsten Erdmann" <thorsten DOT erdmann AT gmx DOT de>
Newsgroups: comp.os.msdos.djgpp
Subject: DJGPP's filesystem extension
Date: Thu, 20 Jul 2000 18:33:41 +0200
Organization: AddCom AG
Lines: 131
Message-ID: <8l7agq$t7f$1@riker.addcom.de>
NNTP-Posting-Host: 62.96.142.165
X-Trace: riker.addcom.de 964111706 29935 62.96.142.165 (20 Jul 2000 16:48:26 GMT)
X-Complaints-To: news AT news DOT addcom DOT de
NNTP-Posting-Date: 20 Jul 2000 16:48:26 GMT
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 5.00.2014.211
X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2014.211
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

Hi,

I have some problems hooking an own filesystem driver to DJGPPs filesystem
extension. All works fine except the close function. It works for a few
times but after a while the program crashes on a file close. I stepped
through my tiny close routine and it runs until the return statement. But
after that return there is the crash, so that the calling program never gets
control back. I think the crash happens when I open a file for a second
time.

My fs driver is a Joliet driver for an MP3 player. When I read all the ID3
tags from all files on the CD it works fine.
If I rescan the same files, e.g. because I had opened and closed the CD
drive, the crash happens at the first file read.

In the following you see the open and close functions. Maybe you see whats
wrong. I think it has something to do with that DOS file handle.

Please help.

bye
Thorsten

/**********************************************************************/
/* lfn_fopen : open file                                              */
/**------------------------------------------------------------------**/
/* input : pathname - search pattern, may include path                */
/*         attrib   - file mode                                       */
/* output: file descriptor                                            */
/**********************************************************************/
int lfn_open(char *pathname, int attrib)
{
  _MYFILE *f;
  int     drive,fd;
  char    *p,*pa,*fname,ch;
  long    lbn;

  /* is there a drive letter? */
  if (pathname[1]==':')
  {
    if (!isalpha(pathname[0])) return 0;
    drive=toupper(pathname[0])-'A';
    pa=pathname+2;
  }
  else
  {
    pa=pathname;
    drive=currdrive;
  }
  if (isDriveCD(drive)<0) return -2; /* drive is not CD, so let DOS do the
rest */

  /* Get a file descriptor we can use */
  if ((fd = __FSEXT_alloc_fd(lfn_handler))<0) return -1;

 /* here comes some initialization stuff */
 /* [...]*/

  /* store file descriptor so we can lookup it up quickly later. */
  __FSEXT_set_data(fd, f);
  return fd;
}

/**********************************************************************/
/* lfn_fclose : close file                                            */
/**------------------------------------------------------------------**/
/* input : fd     - file descriptor                                   */
/* output: zero if ok, else feof                                      */
/**********************************************************************/
int lfn_close(int fd)
{
  _MYFILE *f;
  if (!(f=__FSEXT_get_data(fd))) return -2;
  free(f->sector);
  free(f);
  _dos_close(fd);

  return 0;
}

int lfn_handler(__FSEXT_Fnumber op, int *rv, va_list args)
{
  char* path;
  int   attrib;
  void* buffer;
  long  size;
  int fd;
  _MYFILE* f;

  switch (op)
  {
    case __FSEXT_open: /* open file */
      path   = va_arg(args, char*);
      attrib = va_arg(args, int);
      *rv = lfn_open(path,attrib);
      if (*rv==-2) return 0;
      return 1;

    case __FSEXT_read: /* Read from file. */
      fd     = va_arg(args, int);
      buffer = va_arg(args, void*);
      size   = va_arg(args, size_t);
      *rv = lfn_read(fd,buffer,size);
      if (*rv == -2) return 0;
      return 1;

    case __FSEXT_close: /* close file */
      fd     = va_arg(args, int);
      *rv = lfn_close(fd);
      if (*rv == -2) return 0;
      return 1;

    case __FSEXT_lseek: /* seek file */
      fd     = va_arg(args, int);
      size   = va_arg(args, long);
      attrib = va_arg(args, int);
      *rv = lfn_lseek(fd,size,attrib);
      if (*rv == -2) return 0;
      return 1;

  }
  return 0;
}








- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019