Always close fd when reading super block.

This commit is contained in:
Eric Pouech 2002-04-22 22:34:00 +00:00 committed by Alexandre Julliard
parent 493e9d7d11
commit ac24236d9a

View File

@ -521,6 +521,7 @@ int DRIVE_ReadSuperblock (int drive, char * buff)
#define DRIVE_SUPER 96 #define DRIVE_SUPER 96
int fd; int fd;
off_t offs; off_t offs;
int ret = 0;
if (memset(buff,0,DRIVE_SUPER)!=buff) return -1; if (memset(buff,0,DRIVE_SUPER)!=buff) return -1;
if ((fd=open(DOSDrives[drive].device,O_RDONLY)) == -1) if ((fd=open(DOSDrives[drive].device,O_RDONLY)) == -1)
@ -551,8 +552,16 @@ int DRIVE_ReadSuperblock (int drive, char * buff)
break; break;
} }
if ((offs) && (lseek(fd,offs,SEEK_SET)!=offs)) return -4; if ((offs) && (lseek(fd,offs,SEEK_SET)!=offs))
if (read(fd,buff,DRIVE_SUPER)!=DRIVE_SUPER) return -2; {
ret = -4;
goto the_end;
}
if (read(fd,buff,DRIVE_SUPER)!=DRIVE_SUPER)
{
ret = -2;
goto the_end;
}
switch(DOSDrives[drive].type) switch(DOSDrives[drive].type)
{ {
@ -565,20 +574,27 @@ int DRIVE_ReadSuperblock (int drive, char * buff)
{ {
ERR("The filesystem is not FAT !! (device=%s)\n", ERR("The filesystem is not FAT !! (device=%s)\n",
DOSDrives[drive].device); DOSDrives[drive].device);
return -3; ret = -3;
goto the_end;
} }
break; break;
case DRIVE_CDROM: case DRIVE_CDROM:
if (strncmp(&buff[1],"CD001",5)) /* Check for iso9660 present */ if (strncmp(&buff[1],"CD001",5)) /* Check for iso9660 present */
return -3; {
ret = -3;
goto the_end;
}
/* FIXME: do we need to check for "CDROM", too ? (high sierra) */ /* FIXME: do we need to check for "CDROM", too ? (high sierra) */
break; break;
default: default:
return -3; ret = -3;
break; goto the_end;
} }
return close(fd); return close(fd);
the_end:
close(fd);
return ret;
} }