- Added a version of _RestoreAttributes() that accepts a fd as a parameter.

Usefull when, for some reason, you already have an fd around.
- Changed the non-parameter version to set the fd and call the parametrized
  version.
- CD-Text reasing is expensive (takes up to 4 seconds on my machine) so now it
  is only done if this is the first time the CD is inserted (technically, if it
  errors out when trying to open the attributes file for the CD). With this, the
  first time I mount a CD still takes 4 seconds, but consecutive mounts happen
  almost instantaneously.



git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@27109 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Bruno G. Albuquerque
2008-08-21 14:36:25 +00:00
parent 233871e4d4
commit b29b6eb84a
@@ -110,6 +110,7 @@ class Volume {
int _OpenAttributes(int mode, int _OpenAttributes(int mode,
enum attr_mode attrMode = kDiscIDAttributes); enum attr_mode attrMode = kDiscIDAttributes);
void _RestoreAttributes(); void _RestoreAttributes();
void _RestoreAttributes(int fd);
void _StoreAttributes(); void _StoreAttributes();
void _RestoreSharedAttributes(); void _RestoreSharedAttributes();
void _StoreSharedAttributes(); void _StoreSharedAttributes();
@@ -580,10 +581,16 @@ Volume::Mount(const char* device)
bool doLookup = true; bool doLookup = true;
cdtext text; cdtext text;
if (read_cdtext(fDevice, text) < B_OK) int fd = _OpenAttributes(O_RDONLY);
dprintf("CDDA: no CD-Text found.\n"); if (fd < 0) {
else // We do not seem to have an attribute file so this is probably the
doLookup = false; // first time this CD is inserted. In this case, try to read CD-Text
// data.
if (read_cdtext(fDevice, text) < B_OK)
dprintf("CDDA: no CD-Text found.\n");
else
doLookup = false;
}
int32 trackCount = toc->last_track + 1 - toc->first_track; int32 trackCount = toc->last_track + 1 - toc->first_track;
off_t totalFrames = 0; off_t totalFrames = 0;
@@ -653,7 +660,8 @@ Volume::Mount(const char* device)
(const uint8*)&doLookup, sizeof(bool)); (const uint8*)&doLookup, sizeof(bool));
_RestoreSharedAttributes(); _RestoreSharedAttributes();
_RestoreAttributes(); if (fd >= 0)
_RestoreAttributes(fd);
free(toc); free(toc);
@@ -819,11 +827,18 @@ Volume::_RestoreAttributes()
if (fd < 0) if (fd < 0)
return; return;
_RestoreAttributes(fd);
close(fd);
}
void
Volume::_RestoreAttributes(int fd)
{
char line[B_FILE_NAME_LENGTH]; char line[B_FILE_NAME_LENGTH];
if (!read_line(fd, line, B_FILE_NAME_LENGTH)) { if (!read_line(fd, line, B_FILE_NAME_LENGTH))
close(fd);
return; return;
}
SetName(line); SetName(line);
@@ -840,8 +855,6 @@ Volume::_RestoreAttributes()
break; break;
} }
} }
close(fd);
} }