* Replaced some PRINT with TRACE

* Rename error to status
* Fix assignements in udf_read_stat
* Added udf_{close_dir,free_dir_cookie} hook functions which prevented
udf from mounting the partition

It seems mouting an udf partition works correctly but I'm still unable
to list its content.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@27138 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Salvatore Benedetto 2008-08-22 10:06:44 +00:00
parent 89264fe471
commit e2dc263c43
2 changed files with 135 additions and 114 deletions

View File

@ -16,28 +16,27 @@
status_t
DirectoryIterator::GetNextEntry(char *name, uint32 *length, ino_t *id)
{
DEBUG_INIT_ETC("DirectoryIterator",
("name: %p, length: %p, id: %p", name, length, id));
TRACE(("DirectoryIterator::GetNextEntry: name = %p, length = %p, id = %p\n",
name, length, id));
if (!id || !name || !length)
return B_BAD_VALUE;
PRINT(("fPosition: %Ld\n", fPosition));
PRINT(("Parent()->Length(): %Ld\n", Parent()->Length()));
TRACE(("\tfPosition: %Ld\n", fPosition));
TRACE(("\tParent()->Length(): %Ld\n", Parent()->Length()));
status_t error = B_OK;
status_t status = B_OK;
if (fAtBeginning) {
sprintf(name, ".");
*length = 2;
*id = Parent()->Id();
fAtBeginning = false;
} else {
if (uint64(fPosition) >= Parent()->Length())
RETURN(B_ENTRY_NOT_FOUND);
return B_ENTRY_NOT_FOUND;
uint8 data[kMaxFileIdSize];
file_id_descriptor *entry = reinterpret_cast<file_id_descriptor*>(data);
file_id_descriptor *entry = (file_id_descriptor *)data;
uint32 block = 0;
off_t offset = fPosition;
@ -46,8 +45,8 @@ DirectoryIterator::GetNextEntry(char *name, uint32 *length, ino_t *id)
// First read in the static portion of the file id descriptor,
// then, based on the information therein, read in the variable
// length tail portion as well.
error = Parent()->Read(offset, entry, &entryLength, &block);
if (!error && entryLength >= sizeof(file_id_descriptor)
status = Parent()->Read(offset, entry, &entryLength, &block);
if (!status && entryLength >= sizeof(file_id_descriptor)
&& entry->tag().init_check(block) == B_OK) {
PDUMP(entry);
offset += entry->total_length();
@ -57,7 +56,7 @@ DirectoryIterator::GetNextEntry(char *name, uint32 *length, ino_t *id)
*length = 3;
} else {
UdfString string(entry->id(), entry->id_length());
PRINT(("id == `%s'\n", string.Utf8()));
TRACE(("\tid == `%s'\n", string.Utf8()));
DUMP(entry->icb());
sprintf(name, "%s", string.Utf8());
*length = string.Utf8Length();
@ -65,11 +64,11 @@ DirectoryIterator::GetNextEntry(char *name, uint32 *length, ino_t *id)
*id = to_vnode_id(entry->icb());
}
if (!error)
if (!status)
fPosition = offset;
}
RETURN(error);
return status;
}
@ -102,31 +101,33 @@ Icb::Icb(Volume *volume, long_address address)
fFileEntry(&fData),
fExtendedEntry(&fData)
{
DEBUG_INIT_ETC("Icb", ("volume: %p, address(block: %ld, "
"partition: %d, length: %ld)", volume, address.block(),
address.partition(), address.length()));
status_t error = volume ? B_OK : B_BAD_VALUE;
if (!error) {
off_t block;
error = fVolume->MapBlock(address, &block);
if (!error) {
icb_header *header = (icb_header *)fData.SetTo(block);
if (header->tag().id() == TAGID_FILE_ENTRY) {
file_icb_entry *entry = reinterpret_cast<file_icb_entry*>(header);
PDUMP(entry);
(void)entry; // warning death
} else if (header->tag().id() == TAGID_EXTENDED_FILE_ENTRY) {
extended_file_icb_entry *entry = reinterpret_cast<extended_file_icb_entry*>(header);
PDUMP(entry);
(void)entry; // warning death
} else {
PDUMP(header);
}
error = header->tag().init_check(address.block());
TRACE(("Icb::Icb: volume = %p, address(block = %ld, partition = %d, "
"length = %ld)\n", volume, address.block(), address.partition(),
address.length()));
if (volume == NULL)
fInitStatus = B_BAD_VALUE;
off_t block;
status_t status = fVolume->MapBlock(address, &block);
if (!status) {
icb_header *header = (icb_header *)fData.SetTo(block);
if (header->tag().id() == TAGID_FILE_ENTRY) {
file_icb_entry *entry = (file_icb_entry *)header;
PDUMP(entry);
(void)entry; // warning death
} else if (header->tag().id() == TAGID_EXTENDED_FILE_ENTRY) {
extended_file_icb_entry *entry = (extended_file_icb_entry *)header;
PDUMP(entry);
(void)entry; // warning death
} else {
PDUMP(header);
}
}
fInitStatus = error;
PRINT(("result: 0x%lx, `%s'\n", error, strerror(error)));
status = header->tag().init_check(address.block());
}
fInitStatus = status;
TRACE(("Icb::Icb: status = 0x%lx, `%s'\n", status, strerror(status)));
}
@ -171,12 +172,12 @@ Icb::ModificationTime()
status_t
Icb::Read(off_t pos, void *buffer, size_t *length, uint32 *block)
{
DEBUG_INIT_ETC("Icb",
("pos: %Ld, buffer: %p, length: (%p)->%ld", pos, buffer, length, (length ? *length : 0)));
TRACE(("Icb::Read: pos = %Ld, buffer = %p, length = (%p)->%ld",
pos, buffer, length, (length ? *length : 0)));
if (!buffer || !length || pos < 0)
RETURN(B_BAD_VALUE);
return B_BAD_VALUE;
if (uint64(pos) >= Length()) {
*length = 0;
return B_OK;
@ -184,35 +185,36 @@ Icb::Read(off_t pos, void *buffer, size_t *length, uint32 *block)
switch (_IcbTag().descriptor_flags()) {
case ICB_DESCRIPTOR_TYPE_SHORT: {
PRINT(("descriptor type: short\n"));
TRACE(("Icb::Read: descriptor type -> short\n"));
AllocationDescriptorList<ShortDescriptorAccessor> list(this, ShortDescriptorAccessor(0));
RETURN(_Read(list, pos, buffer, length, block));
break;
}
case ICB_DESCRIPTOR_TYPE_LONG: {
PRINT(("descriptor type: long\n"));
TRACE(("Icb::Read: descriptor type -> long\n"));
AllocationDescriptorList<LongDescriptorAccessor> list(this);
RETURN(_Read(list, pos, buffer, length, block));
break;
}
case ICB_DESCRIPTOR_TYPE_EXTENDED: {
PRINT(("descriptor type: extended\n"));
TRACE(("Icb::Read: descriptor type -> extended\n"));
// AllocationDescriptorList<ExtendedDescriptorAccessor> list(this, ExtendedDescriptorAccessor(0));
// RETURN(_Read(list, pos, buffer, length, block));
RETURN(B_ERROR);
break;
}
case ICB_DESCRIPTOR_TYPE_EMBEDDED: {
PRINT(("descriptor type: embedded\n"));
TRACE(("Icb::Read: descriptor type: embedded\n"));
RETURN(B_ERROR);
break;
}
default:
PRINT(("Invalid icb descriptor flags! (flags = %d)\n", _IcbTag().descriptor_flags()));
TRACE(("Icb::Read: invalid icb descriptor flags! (flags = %d)\n",
_IcbTag().descriptor_flags()));
RETURN(B_BAD_VALUE);
break;
}
@ -222,34 +224,32 @@ Icb::Read(off_t pos, void *buffer, size_t *length, uint32 *block)
status_t
Icb::Find(const char *filename, ino_t *id)
{
DEBUG_INIT_ETC("Icb",
("filename: `%s', id: %p", filename, id));
TRACE(("Icb::Find: filename = `%s', id = %p\n", filename, id));
if (!filename || !id)
RETURN(B_BAD_VALUE);
DirectoryIterator *i;
status_t error = GetDirectoryIterator(&i);
if (!error) {
ino_t entryId;
uint32 length = B_FILE_NAME_LENGTH;
char name[B_FILE_NAME_LENGTH];
bool foundIt = false;
while (i->GetNextEntry(name, &length, &entryId) == B_OK)
{
if (strcmp(filename, name) == 0) {
foundIt = true;
break;
}
}
if (foundIt) {
*id = entryId;
} else {
error = B_ENTRY_NOT_FOUND;
}
status_t status = GetDirectoryIterator(&i);
if (status != B_OK)
return status;
ino_t entryId;
uint32 length = B_FILE_NAME_LENGTH;
char name[B_FILE_NAME_LENGTH];
bool foundIt = false;
while (i->GetNextEntry(name, &length, &entryId) == B_OK) {
if (strcmp(filename, name) == 0) {
foundIt = true;
break;
}
}
RETURN(error);
if (foundIt)
*id = entryId;
else
status = B_ENTRY_NOT_FOUND;
return status;
}

View File

@ -116,13 +116,14 @@ static status_t
udf_get_vnode(fs_volume *_volume, ino_t id, fs_vnode *_node, int *_type,
uint32 *_flags, bool reenter)
{
TRACE(("udf_get_vnode: id = %Ld, reenter = %s\n",
id, (reenter ? "true" : "false")));
TRACE(("udf_get_vnode: _volume = %p, _node = %p, reenter = %s\n",
_volume, _node, (reenter ? "true" : "false")));
Volume *volume = (Volume *)_volume->private_volume;
// Convert the given vnode id to an address, and create
// and return a corresponding Icb object for it.
TRACE(("udf_get_vnode: id = %d, blockSize = %d\n", id, volume->BlockSize()));
Icb *icb = new(std::nothrow) Icb(volume,
to_long_address(id, volume->BlockSize()));
if (icb) {
@ -166,17 +167,17 @@ udf_lookup(fs_volume *_volume, fs_vnode *_directory, const char *file,
return B_ENTRY_NOT_FOUND;
} else {
status = dir->Find(file, vnodeID);
if (status == B_OK) {
Icb *icb;
status = get_vnode(volume->FSVolume(), *vnodeID,
(void **)&icb);
if (status != B_OK)
return B_ENTRY_NOT_FOUND;
}
if (status != B_OK)
return status;
Icb *icb;
status = get_vnode(volume->FSVolume(), *vnodeID, (void **)&icb);
if (status != B_OK)
return B_ENTRY_NOT_FOUND;
}
TRACE(("udf_lookup: vnodeId = %Ld found!\n", *vnodeID));
return status;
return B_OK;
}
@ -201,24 +202,26 @@ udf_put_vnode(fs_volume *volume, fs_vnode *node, bool reenter)
static status_t
udf_read_stat(fs_volume *_volume, fs_vnode *node, struct stat *stat)
{
DEBUG_INIT(NULL);
TRACE(("udf_read_stat: _volume = %p, node = %p\n", _volume, node));
if (!_volume || !node || !stat)
RETURN(B_BAD_VALUE);
return B_BAD_VALUE;
Volume *volume = (Volume *)_volume->private_volume;
Icb *icb = reinterpret_cast<Icb*>(node);
Icb *icb = (Icb *)node->private_node;
//stat->st_dev = volume->Id();
stat->st_dev = volume->ID();
stat->st_ino = icb->Id();
stat->st_nlink = icb->FileLinkCount();
stat->st_blksize = volume->BlockSize();
TRACE(("udf_read_stat: st_dev = %d, st_ino = %d, st_blksize = %d\n",
stat->st_dev, stat->st_ino, stat->st_blksize));
stat->st_uid = icb->Uid();
stat->st_gid = icb->Gid();
stat->st_mode = icb->Mode();
TRACE(("mode = 0x%lx\n", uint32(icb->Mode())));
stat->st_size = icb->Length();
// File times. For now, treat the modification time as creation
@ -227,9 +230,10 @@ udf_read_stat(fs_volume *_volume, fs_vnode *node, struct stat *stat)
stat->st_atime = icb->AccessTime();
stat->st_mtime = stat->st_ctime = stat->st_crtime = icb->ModificationTime();
TRACE(("stat->st_ino: %Ld\n", stat->st_ino));
TRACE(("udf_read_stat: mode = 0x%lx, st_ino: %Ld\n", stat->st_mode,
stat->st_ino));
RETURN(B_OK);
return B_OK;
}
@ -286,29 +290,46 @@ udf_read(fs_volume *volume, fs_vnode *vnode, void *cookie, off_t pos,
static status_t
udf_open_dir(fs_volume *volume, fs_vnode *vnode, void **cookie)
{
DEBUG_INIT_ETC(NULL, ("node: %p, cookie: %p", node, cookie));
TRACE(("udf_open_dir: volume = %p, vnode = %p\n", volume, vnode));
if (!volume || !vnode || !cookie)
RETURN(B_BAD_VALUE);
Icb *dir = (Icb *)vnode->private_node;
status_t status = B_OK;
if (dir->IsDirectory()) {
DirectoryIterator *iterator = NULL;
status = dir->GetDirectoryIterator(&iterator);
if (!status) {
*cookie = reinterpret_cast<void*>(iterator);
} else {
PRINT(("Error getting directory iterator: 0x%lx, `%s'\n", status, strerror(error)));
}
} else {
PRINT(("Given icb is not a directory (type: %d)\n", dir->Type()));
status = B_BAD_VALUE;
if (!dir->IsDirectory()) {
TRACE_ERROR(("udf_open_dir: given Icb is not a directory (type: %d)\n",
dir->Type()));
return B_BAD_VALUE;
}
RETURN(status);
DirectoryIterator *iterator = NULL;
status_t status = dir->GetDirectoryIterator(&iterator);
if (status != B_OK) {
TRACE_ERROR(("udf_open_dir: error getting directory iterator: 0x%lx, "
"`%s'\n", status, strerror(error)));
return status;
}
*cookie = (void *)iterator;
TRACE(("udf_open_dir: *cookie = %p\n", *cookie));
return B_OK;
}
static status_t
udf_close_dir(fs_volume *_volume, fs_vnode *node, void *_cookie)
{
TRACE(("udf_close_dir: _volume = %p, node = %p\n", _volume, node));
return B_OK;
}
static status_t
udf_free_dir_cookie(fs_volume *_volume, fs_vnode *node, void *_cookie)
{
TRACE(("udf_free_dir_cookie: _volume = %p, node = %p\n", _volume, node));
return B_OK;
}
@ -316,19 +337,19 @@ static status_t
udf_read_dir(fs_volume *_volume, fs_vnode *vnode, void *cookie,
struct dirent *dirent, size_t bufferSize, uint32 *_num)
{
DEBUG_INIT_ETC(NULL,
("dir: %p, iterator: %p, bufferSize: %ld", node, cookie, bufferSize));
TRACE(("udf_read_dir: _volume = %p, vnode = %p, bufferSize = %ld\n",
_volume, vnode, bufferSize));
if (!_volume || !vnode || !cookie || !_num || bufferSize < sizeof(dirent))
RETURN(B_BAD_VALUE);
return B_BAD_VALUE;
Volume *volume = (Volume *)_volume->private_volume;
Icb *dir = (Icb *)vnode->private_node;
DirectoryIterator *iterator = reinterpret_cast<DirectoryIterator*>(cookie);
DirectoryIterator *iterator = (DirectoryIterator *)cookie;
if (dir != iterator->Parent()) {
PRINT(("Icb does not match parent Icb of given DirectoryIterator! (iterator->Parent = %p)\n",
iterator->Parent()));
TRACE_ERROR(("udf_read_dir: Icb does not match parent Icb of given "
"DirectoryIterator! (iterator->Parent = %p)\n", iterator->Parent()));
return B_BAD_VALUE;
}
@ -568,8 +589,8 @@ fs_vnode_ops gUDFVnodeOps = {
NULL, // create_dir
NULL, // remove_dir
&udf_open_dir,
NULL, // close_dir
NULL, // free_dir_cookie
&udf_close_dir,
&udf_free_dir_cookie,
&udf_read_dir,
&udf_rewind_dir,