From 84719cae244ef5d9448896bc84fa1c1dd2353aef Mon Sep 17 00:00:00 2001 From: "Bruno G. Albuquerque" Date: Wed, 20 Aug 2008 13:10:18 +0000 Subject: [PATCH] - Add a new CD:do_lookup attribute. It will be used by userland programs (like cddblinkd) to know if they should lookup the CD or not. It will be true unless: 1 - The CD has CD-Text information. 2 - The user (or a userland program) changed the Volume name. 3 - The user (or a userland program) changed any track names. - Moved (again) attribute creation to before the stored attributes are read. As attribute operations happen in memory in cdda, we don't need to care about the IO cost and this way it is more in line with all the other attributes created. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@27079 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- .../file_systems/cdda/kernel_interface.cpp | 40 ++++++++++++++++--- 1 file changed, 34 insertions(+), 6 deletions(-) diff --git a/src/add-ons/kernel/file_systems/cdda/kernel_interface.cpp b/src/add-ons/kernel/file_systems/cdda/kernel_interface.cpp index 11e216d848..1242b59df1 100644 --- a/src/add-ons/kernel/file_systems/cdda/kernel_interface.cpp +++ b/src/add-ons/kernel/file_systems/cdda/kernel_interface.cpp @@ -248,6 +248,7 @@ static const uint32 kMaxAttributeSize = 65536; static const uint32 kMaxAttributes = 64; static const char* kCddbIdAttribute = "CD:cddbid"; +static const char* kDoLookupAttribute = "CD:do_lookup"; extern fs_volume_ops gCDDAVolumeOps; extern fs_vnode_ops gCDDAVnodeOps; @@ -571,9 +572,12 @@ Volume::Mount(const char* device) return status; } + bool do_lookup = true; cdtext text; if (read_cdtext(fDevice, text) < B_OK) dprintf("CDDA: no CD-Text found.\n"); + else + do_lookup = false; int32 trackCount = toc->last_track + 1 - toc->first_track; off_t totalFrames = 0; @@ -635,13 +639,16 @@ Volume::Mount(const char* device) inode->AddAttribute("BEOS:TYPE", B_MIME_STRING_TYPE, "audio/x-wav"); } + // Add CD:cddbid attribute. + fRootNode->AddAttribute(kCddbIdAttribute, B_UINT32_TYPE, fDiscID); + + // Add CD:do_lookup attribute. + fRootNode->AddAttribute(kDoLookupAttribute, B_BOOL_TYPE, true, + (const uint8*)&do_lookup, sizeof(bool)); + _RestoreSharedAttributes(); _RestoreAttributes(); - // Only add CD:cddbid attribute if it does not exist yet. - if (fRootNode->FindAttribute(kCddbIdAttribute) == NULL) - fRootNode->AddAttribute(kCddbIdAttribute, B_UINT32_TYPE, fDiscID); - free(toc); // determine volume title @@ -1381,8 +1388,18 @@ cdda_write_fs_stat(fs_volume* _volume, const struct fs_info* info, uint32 mask) status_t status = B_BAD_VALUE; - if ((mask & FS_WRITE_FSINFO_NAME) != 0) + if ((mask & FS_WRITE_FSINFO_NAME) != 0) { status = volume->SetName(info->volume_name); + if (status == B_OK) { + // The volume had its name changed from outside the filesystem + // add-on. Disable CDDB lookups. Note this will usually mean that + // the user manually renamed the volume or that cddblinkd (or other + // program) did this so we do not want to do it again. + bool do_lookup = false; + volume->RootNode().AddAttribute(kDoLookupAttribute, B_BOOL_TYPE, + true, (const uint8*)&do_lookup, sizeof(bool)); + } + } return status; } @@ -1644,7 +1661,18 @@ cdda_rename(fs_volume* _volume, fs_vnode* _oldDir, const char* oldName, if (volume->Find(newName) != NULL) return B_NAME_IN_USE; - return inode->SetName(newName); + status_t result = inode->SetName(newName); + if (result == B_OK) { + // One of the tracks had its name edited from outside the filesystem + // add-on. Disable CDDB lookups. Note this will usually mean that the + // user manually renamed a track or that cddblinkd (or other program) + // did this so we do not want to do it again. + bool do_lookup = false; + volume->RootNode().AddAttribute(kDoLookupAttribute, B_BOOL_TYPE, true, + (const uint8*)&do_lookup, sizeof(bool)); + } + + return result; }