* The file map needs to know the actual file size to be able to know if it has
the complete extent info or not. * file_map_translate() now cuts down the request to the file bounds. * Adjusted BFS and FAT to the API changes. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@22913 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -67,7 +67,7 @@ extern status_t file_cache_write(void *_cacheRef, void *cookie, off_t offset,
|
|||||||
const void *buffer, size_t *_size);
|
const void *buffer, size_t *_size);
|
||||||
|
|
||||||
/* file map */
|
/* file map */
|
||||||
extern void *file_map_create(dev_t mountID, ino_t vnodeID);
|
extern void *file_map_create(dev_t mountID, ino_t vnodeID, off_t size);
|
||||||
extern void file_map_delete(void *_map);
|
extern void file_map_delete(void *_map);
|
||||||
extern void file_map_set_size(void *_map, off_t size);
|
extern void file_map_set_size(void *_map, off_t size);
|
||||||
extern void file_map_invalidate(void *_map, off_t offset, off_t size);
|
extern void file_map_invalidate(void *_map, off_t offset, off_t size);
|
||||||
|
|||||||
@@ -84,7 +84,7 @@ extern fssh_status_t fssh_file_cache_write(void *_cacheRef, void *cookie,
|
|||||||
|
|
||||||
/* file map */
|
/* file map */
|
||||||
extern void * fssh_file_map_create(fssh_mount_id mountID,
|
extern void * fssh_file_map_create(fssh_mount_id mountID,
|
||||||
fssh_vnode_id vnodeID);
|
fssh_vnode_id vnodeID, fssh_off_t size);
|
||||||
extern void fssh_file_map_delete(void *_map);
|
extern void fssh_file_map_delete(void *_map);
|
||||||
extern void fssh_file_map_set_size(void *_map, fssh_off_t size);
|
extern void fssh_file_map_set_size(void *_map, fssh_off_t size);
|
||||||
extern void fssh_file_map_invalidate(void *_map, fssh_off_t offset,
|
extern void fssh_file_map_invalidate(void *_map, fssh_off_t offset,
|
||||||
|
|||||||
@@ -195,7 +195,7 @@ Inode::Inode(Volume *volume, ino_t id)
|
|||||||
fTree = new BPlusTree(this);
|
fTree = new BPlusTree(this);
|
||||||
if (IsFile() || IsAttribute()) {
|
if (IsFile() || IsAttribute()) {
|
||||||
SetFileCache(file_cache_create(fVolume->ID(), ID(), Size()));
|
SetFileCache(file_cache_create(fVolume->ID(), ID(), Size()));
|
||||||
SetMap(file_map_create(volume->ID(), ID()));
|
SetMap(file_map_create(volume->ID(), ID(), Size()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2417,7 +2417,8 @@ Inode::Create(Transaction &transaction, Inode *parent, const char *name,
|
|||||||
if (inode->IsFile() || inode->IsAttribute()) {
|
if (inode->IsFile() || inode->IsAttribute()) {
|
||||||
inode->SetFileCache(file_cache_create(volume->ID(), inode->ID(),
|
inode->SetFileCache(file_cache_create(volume->ID(), inode->ID(),
|
||||||
inode->Size()));
|
inode->Size()));
|
||||||
inode->SetMap(file_map_create(volume->ID(), inode->ID()));
|
inode->SetMap(file_map_create(volume->ID(), inode->ID(),
|
||||||
|
inode->Size()));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_created)
|
if (_created)
|
||||||
|
|||||||
@@ -858,7 +858,7 @@ bfs_create_symlink(void *_ns, void *_directory, const char *name,
|
|||||||
|
|
||||||
// links usually don't have a file cache attached - but we now need one
|
// links usually don't have a file cache attached - but we now need one
|
||||||
link->SetFileCache(file_cache_create(volume->ID(), link->ID(), 0));
|
link->SetFileCache(file_cache_create(volume->ID(), link->ID(), 0));
|
||||||
link->SetMap(file_map_create(volume->ID(), link->ID()));
|
link->SetMap(file_map_create(volume->ID(), link->ID(), 0));
|
||||||
|
|
||||||
// The following call will have to write the inode back, so
|
// The following call will have to write the inode back, so
|
||||||
// we don't have to do that here...
|
// we don't have to do that here...
|
||||||
|
|||||||
@@ -1039,7 +1039,7 @@ dosfs_read_vnode(void *_vol, ino_t vnid, void **_node, bool reenter)
|
|||||||
if (entry->filename) strcpy(entry->filename, filename);
|
if (entry->filename) strcpy(entry->filename, filename);
|
||||||
#endif
|
#endif
|
||||||
entry->cache = file_cache_create(vol->id, vnid, entry->st_size);
|
entry->cache = file_cache_create(vol->id, vnid, entry->st_size);
|
||||||
entry->file_map = file_map_create(vol->id, vnid);
|
entry->file_map = file_map_create(vol->id, vnid, entry->st_size);
|
||||||
if (!(entry->mode & FAT_SUBDIR))
|
if (!(entry->mode & FAT_SUBDIR))
|
||||||
set_mime_type(entry, filename);
|
set_mime_type(entry, filename);
|
||||||
|
|
||||||
|
|||||||
Vendored
+18
-6
@@ -40,7 +40,7 @@ struct file_extent {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct file_map {
|
struct file_map {
|
||||||
file_map();
|
file_map(off_t size);
|
||||||
~file_map();
|
~file_map();
|
||||||
|
|
||||||
file_extent *operator[](uint32 index);
|
file_extent *operator[](uint32 index);
|
||||||
@@ -54,13 +54,15 @@ struct file_map {
|
|||||||
};
|
};
|
||||||
size_t count;
|
size_t count;
|
||||||
struct vnode *vnode;
|
struct vnode *vnode;
|
||||||
|
off_t size;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
file_map::file_map()
|
file_map::file_map(off_t _size)
|
||||||
{
|
{
|
||||||
array = NULL;
|
array = NULL;
|
||||||
count = 0;
|
count = 0;
|
||||||
|
size = _size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -179,11 +181,12 @@ find_file_extent(file_map &map, off_t offset, uint32 *_index)
|
|||||||
|
|
||||||
|
|
||||||
extern "C" void *
|
extern "C" void *
|
||||||
file_map_create(dev_t mountID, ino_t vnodeID)
|
file_map_create(dev_t mountID, ino_t vnodeID, off_t size)
|
||||||
{
|
{
|
||||||
TRACE(("file_map_create(mountID = %ld, vnodeID = %Ld)\n", mountID, vnodeID));
|
TRACE(("file_map_create(mountID = %ld, vnodeID = %Ld, size = %Ld)\n",
|
||||||
|
mountID, vnodeID, size));
|
||||||
|
|
||||||
file_map *map = new file_map;
|
file_map *map = new file_map(size);
|
||||||
if (map == NULL)
|
if (map == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
@@ -218,7 +221,9 @@ file_map_set_size(void *_map, off_t size)
|
|||||||
|
|
||||||
// TODO: honour offset/size parameters
|
// TODO: honour offset/size parameters
|
||||||
file_map *map = (file_map *)_map;
|
file_map *map = (file_map *)_map;
|
||||||
map->Free();
|
if (size < map->size)
|
||||||
|
map->Free();
|
||||||
|
map->size = size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -248,6 +253,13 @@ file_map_translate(void *_map, off_t offset, size_t size, file_io_vec *vecs,
|
|||||||
size_t maxVecs = *_count;
|
size_t maxVecs = *_count;
|
||||||
status_t status = B_OK;
|
status_t status = B_OK;
|
||||||
|
|
||||||
|
if (offset > map.size) {
|
||||||
|
*_count = 0;
|
||||||
|
return B_OK;
|
||||||
|
}
|
||||||
|
if (offset + size > map.size)
|
||||||
|
size = map.size - offset;
|
||||||
|
|
||||||
if (map.count == 0) {
|
if (map.count == 0) {
|
||||||
// we don't yet have the map of this file, so let's grab it
|
// we don't yet have the map of this file, so let's grab it
|
||||||
// (ordered by offset, so that we can do a binary search on them)
|
// (ordered by offset, so that we can do a binary search on them)
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ struct file_extent {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct file_map {
|
struct file_map {
|
||||||
file_map();
|
file_map(fssh_off_t size);
|
||||||
~file_map();
|
~file_map();
|
||||||
|
|
||||||
file_extent *operator[](uint32_t index);
|
file_extent *operator[](uint32_t index);
|
||||||
@@ -49,13 +49,15 @@ struct file_map {
|
|||||||
};
|
};
|
||||||
fssh_size_t count;
|
fssh_size_t count;
|
||||||
void *vnode;
|
void *vnode;
|
||||||
|
fssh_off_t size;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
file_map::file_map()
|
file_map::file_map(fssh_off_t _size)
|
||||||
{
|
{
|
||||||
array = NULL;
|
array = NULL;
|
||||||
count = 0;
|
count = 0;
|
||||||
|
size = size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -178,11 +180,12 @@ find_file_extent(file_map &map, fssh_off_t offset, uint32_t *_index)
|
|||||||
|
|
||||||
|
|
||||||
extern "C" void *
|
extern "C" void *
|
||||||
fssh_file_map_create(fssh_mount_id mountID, fssh_vnode_id vnodeID)
|
fssh_file_map_create(fssh_mount_id mountID, fssh_vnode_id vnodeID,
|
||||||
|
fssh_off_t size)
|
||||||
{
|
{
|
||||||
TRACE(("file_map_create(mountID = %ld, vnodeID = %Ld)\n", mountID, vnodeID));
|
TRACE(("file_map_create(mountID = %ld, vnodeID = %Ld)\n", mountID, vnodeID));
|
||||||
|
|
||||||
file_map *map = new file_map;
|
file_map *map = new file_map(size);
|
||||||
if (map == NULL)
|
if (map == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
@@ -217,7 +220,9 @@ fssh_file_map_set_size(void *_map, fssh_off_t size)
|
|||||||
|
|
||||||
// TODO: honour offset/size parameters
|
// TODO: honour offset/size parameters
|
||||||
file_map *map = (file_map *)_map;
|
file_map *map = (file_map *)_map;
|
||||||
map->Free();
|
if (size < map->size)
|
||||||
|
map->Free();
|
||||||
|
map->size = size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -244,6 +249,13 @@ fssh_file_map_translate(void *_map, fssh_off_t offset, fssh_size_t size,
|
|||||||
fssh_size_t maxVecs = *_count;
|
fssh_size_t maxVecs = *_count;
|
||||||
fssh_status_t status = FSSH_B_OK;
|
fssh_status_t status = FSSH_B_OK;
|
||||||
|
|
||||||
|
if (offset > map.size) {
|
||||||
|
*_count = 0;
|
||||||
|
return FSSH_B_OK;
|
||||||
|
}
|
||||||
|
if (offset + size > map.size)
|
||||||
|
size = map.size - offset;
|
||||||
|
|
||||||
if (map.count == 0) {
|
if (map.count == 0) {
|
||||||
// we don't yet have the map of this file, so let's grab it
|
// we don't yet have the map of this file, so let's grab it
|
||||||
// (ordered by offset, so that we can do a binary search on them)
|
// (ordered by offset, so that we can do a binary search on them)
|
||||||
|
|||||||
Reference in New Issue
Block a user