1
1
forked from 0ad/0ad

more comments; also SECTOR_SIZE constant added

This was SVN commit r914.
This commit is contained in:
janwas 2004-08-05 14:01:49 +00:00
parent aabfd9a49d
commit d274e4c7f9
2 changed files with 19 additions and 10 deletions

View File

@ -38,6 +38,10 @@
const size_t BLOCK_SIZE_LOG2 = 16; // 2**16 = 64 KB const size_t BLOCK_SIZE_LOG2 = 16; // 2**16 = 64 KB
const size_t BLOCK_SIZE = 1ul << BLOCK_SIZE_LOG2; const size_t BLOCK_SIZE = 1ul << BLOCK_SIZE_LOG2;
const size_t SECTOR_SIZE = 4096;
// reasonable guess. if too small, aio will do alignment.
// rationale for aio, instead of only using mmap: // rationale for aio, instead of only using mmap:
// - parallelism: instead of just waiting for the transfer to complete, // - parallelism: instead of just waiting for the transfer to complete,
@ -236,10 +240,13 @@ static bool dirent_less(const DirEnt* const d1, const DirEnt* const d2)
{ return d1->name.compare(d2->name) < 0; } { return d1->name.compare(d2->name) < 0; }
// we give the callback the directory-entry-name only - not the // we give the callback the directory-entry-name only - not the
// absolute path, nor <dir> prepended. rationale: some users don't need it, // absolute path, nor <dir> prepended.
// rationale: some users don't need it,
// and would need to strip it. there are not enough users requiring it to // and would need to strip it. there are not enough users requiring it to
// justify that. this routine does actually generate the absolute path // justify that. this routine does actually generate the absolute path
// for use with stat, but in native form - can't use that. // for use with stat, but in native form - can't use that.
//
// not recursive - returns only the ents in <dir> itself!
int file_enum(const char* const dir, const FileCB cb, const uintptr_t user) int file_enum(const char* const dir, const FileCB cb, const uintptr_t user)
{ {
char n_path[PATH_MAX+1]; char n_path[PATH_MAX+1];
@ -609,13 +616,11 @@ debug_out("file_start_io hio=%I64x ofs=%d size=%d\n", hio, user_ofs, user_size);
// optimization: pad to eliminate a memcpy if unaligned // optimization: pad to eliminate a memcpy if unaligned
ofs = user_ofs; ofs = user_ofs;
const size_t sector_size = 4096; padding = ofs % SECTOR_SIZE;
// reasonable guess. if too small, aio will do alignment.
padding = ofs % sector_size;
ofs -= (off_t)padding; ofs -= (off_t)padding;
size = round_up(padding + user_size, sector_size); size = round_up(padding + user_size, SECTOR_SIZE);
buf = mem_alloc(size, sector_size); buf = mem_alloc(size, SECTOR_SIZE);
if(!buf) if(!buf)
return ERR_NO_MEM; return ERR_NO_MEM;
} }
@ -755,6 +760,7 @@ debug_out("file_io fd=%d size=%d ofs=%d\n", f->fd, raw_size, raw_ofs);
} }
// FIXME: currently doesn't handle caller requesting we alloc buffer
if(f->flags & FILE_NO_AIO) if(f->flags & FILE_NO_AIO)
{ {
lseek(f->fd, raw_ofs, SEEK_SET); lseek(f->fd, raw_ofs, SEEK_SET);

View File

@ -94,7 +94,10 @@ extern int file_rel_chdir(const char* argv0, const char* rel_path);
typedef int(*FileCB)(const char* const name, const uint flags, const ssize_t size, const uintptr_t user); typedef int(*FileCB)(const char* const name, const uint flags, const ssize_t size, const uintptr_t user);
// not recursive - only the files in <dir>! // we give the callback the directory-entry-name only - not the
// absolute path, nor <dir> prepended.
//
// not recursive - returns only the ents in <dir> itself!
extern int file_enum(const char* dir, FileCB cb, uintptr_t user); extern int file_enum(const char* dir, FileCB cb, uintptr_t user);
extern int file_stat(const char* path, struct stat*); extern int file_stat(const char* path, struct stat*);