From 9e98ea36fd14c9c0e072eedb30280a653304933d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Fri, 17 Dec 2004 08:34:34 +0000 Subject: [PATCH] The DataEditor now has a separate entry_ref for attributes - that's used to have access to the attributes of a root directory. Internally, only this ref is used when accessing attribute data. Also fixed an initialization bug in case the stream couldn't be properly opened; some values were just set too late (could lead to strange things as well as a crash). git-svn-id: file:///srv/svn/repos/haiku/trunk/current@10481 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/apps/diskprobe/DataEditor.cpp | 28 ++++++++++++++-------------- src/apps/diskprobe/DataEditor.h | 11 ++++++----- 2 files changed, 20 insertions(+), 19 deletions(-) diff --git a/src/apps/diskprobe/DataEditor.cpp b/src/apps/diskprobe/DataEditor.cpp index 5749ffd9f5..4c2c51eee8 100644 --- a/src/apps/diskprobe/DataEditor.cpp +++ b/src/apps/diskprobe/DataEditor.cpp @@ -399,17 +399,21 @@ status_t DataEditor::SetTo(BEntry &entry, const char *attribute) { fSize = 0; + fLastChange = fFirstChange = NULL; + fChangesFromSaved = 0; + fView = NULL; + fRealViewOffset = 0; + fViewOffset = 0; + fRealViewSize = fViewSize = fBlockSize = 512; struct stat stat; - stat.st_mode = 0; - status_t status = entry.GetStat(&stat); if (status < B_OK) return status; - bool isFileSystem = false; + entry.GetRef(&fAttributeRef); - fBlockSize = 512; + bool isFileSystem = false; if (entry.IsDirectory()) { // we redirect root directories to their volumes @@ -443,7 +447,6 @@ DataEditor::SetTo(BEntry &entry, const char *attribute) fIsReadOnly = false; entry.GetRef(&fRef); - fIsDevice = S_ISBLK(stat.st_mode) || S_ISCHR(stat.st_mode); if (attribute != NULL) @@ -452,8 +455,9 @@ DataEditor::SetTo(BEntry &entry, const char *attribute) fAttribute = NULL; if (IsAttribute()) { + BNode node(&fAttributeRef); attr_info info; - status = fFile.GetAttrInfo(fAttribute, &info); + status = node.GetAttrInfo(fAttribute, &info); if (status != B_OK) { fFile.Unset(); return status; @@ -488,11 +492,6 @@ DataEditor::SetTo(BEntry &entry, const char *attribute) } } - fLastChange = fFirstChange = NULL; - fChangesFromSaved = 0; - fView = NULL; - fRealViewOffset = 0; - fViewOffset = 0; fRealViewSize = fViewSize = fBlockSize; fNeedsUpdate = true; @@ -921,9 +920,10 @@ status_t DataEditor::Update() { ssize_t bytesRead; - if (IsAttribute()) - bytesRead = fFile.ReadAttr(fAttribute, fType, fRealViewOffset, fView, fRealViewSize); - else + if (IsAttribute()) { + BNode node(&fAttributeRef); + bytesRead = node.ReadAttr(fAttribute, fType, fRealViewOffset, fView, fRealViewSize); + } else bytesRead = fFile.ReadAt(fRealViewOffset, fView, fRealViewSize); if (bytesRead < B_OK) diff --git a/src/apps/diskprobe/DataEditor.h b/src/apps/diskprobe/DataEditor.h index ce44b82448..cace088965 100644 --- a/src/apps/diskprobe/DataEditor.h +++ b/src/apps/diskprobe/DataEditor.h @@ -1,7 +1,7 @@ -/* -** Copyright 2004, Axel Dörfler, axeld@pinc-software.de. All rights reserved. -** Distributed under the terms of the OpenBeOS License. -*/ +/* + * Copyright 2004, Axel Dörfler, axeld@pinc-software.de. All rights reserved. + * Distributed under the terms of the MIT License. + */ #ifndef DATA_EDITOR_H #define DATA_EDITOR_H @@ -78,6 +78,7 @@ class DataEditor : public BLocker { BMessenger progressMessenger, volatile bool *stop = NULL); BFile &File() { return fFile; } + const entry_ref &AttributeRef() const { return fAttributeRef; } const entry_ref &Ref() const { return fRef; } private: @@ -94,7 +95,7 @@ class DataEditor : public BLocker { BObjectList fObservers; - entry_ref fRef; + entry_ref fRef, fAttributeRef; BFile fFile; const char *fAttribute; type_code fType;