Fix stat for romfs:/
This commit is contained in:
parent
2e48185aed
commit
59e12a1b5e
@ -495,12 +495,9 @@ static int navigateToDir(romfs_mount *mount, romfs_dir** ppDir, const char** pPa
|
|||||||
|
|
||||||
*ppDir = searchForDir(mount, *ppDir, __utf16path, units);
|
*ppDir = searchForDir(mount, *ppDir, __utf16path, units);
|
||||||
if (!*ppDir)
|
if (!*ppDir)
|
||||||
return EEXIST;
|
return ENOENT;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isDir && !**pPath)
|
|
||||||
return EILSEQ;
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -542,6 +539,30 @@ static ino_t file_inode(romfs_mount *mount, romfs_file *file)
|
|||||||
return ((uint32_t*)file - (uint32_t*)mount->fileTable) + mount->header.dirTableSize/4;
|
return ((uint32_t*)file - (uint32_t*)mount->fileTable) + mount->header.dirTableSize/4;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void fill_dir(struct stat *st, romfs_mount *mount, romfs_dir *dir)
|
||||||
|
{
|
||||||
|
memset(st, 0, sizeof(*st));
|
||||||
|
st->st_ino = dir_inode(mount, dir);
|
||||||
|
st->st_mode = romFS_dir_mode;
|
||||||
|
st->st_nlink = dir_nlink(mount, dir);
|
||||||
|
st->st_size = dir_size(dir);
|
||||||
|
st->st_blksize = 512;
|
||||||
|
st->st_blocks = (st->st_blksize + 511) / 512;
|
||||||
|
st->st_atime = st->st_mtime = st->st_ctime = mount->mtime;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void fill_file(struct stat *st, romfs_mount *mount, romfs_file *file)
|
||||||
|
{
|
||||||
|
memset(st, 0, sizeof(*st));
|
||||||
|
st->st_ino = file_inode(mount, file);
|
||||||
|
st->st_mode = romFS_file_mode;
|
||||||
|
st->st_nlink = 1;
|
||||||
|
st->st_size = (off_t)file->dataSize;
|
||||||
|
st->st_blksize = 512;
|
||||||
|
st->st_blocks = (st->st_blksize + 511) / 512;
|
||||||
|
st->st_atime = st->st_mtime = st->st_ctime = mount->mtime;
|
||||||
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
int romfs_open(struct _reent *r, void *fileStruct, const char *path, int flags, int mode)
|
int romfs_open(struct _reent *r, void *fileStruct, const char *path, int flags, int mode)
|
||||||
@ -670,16 +691,8 @@ off_t romfs_seek(struct _reent *r, void *fd, off_t pos, int dir)
|
|||||||
|
|
||||||
int romfs_fstat(struct _reent *r, void *fd, struct stat *st)
|
int romfs_fstat(struct _reent *r, void *fd, struct stat *st)
|
||||||
{
|
{
|
||||||
romfs_fileobj* file = (romfs_fileobj*)fd;
|
romfs_fileobj* fileobj = (romfs_fileobj*)fd;
|
||||||
memset(st, 0, sizeof(struct stat));
|
fill_file(st, fileobj->mount, fileobj->file);
|
||||||
st->st_ino = file_inode(file->mount, file->file);
|
|
||||||
st->st_mode = romFS_file_mode;
|
|
||||||
st->st_nlink = 1;
|
|
||||||
st->st_size = (off_t)file->file->dataSize;
|
|
||||||
st->st_blksize = 512;
|
|
||||||
st->st_blocks = (st->st_blksize + 511) / 512;
|
|
||||||
st->st_atime = st->st_mtime = st->st_ctime = file->mount->mtime;
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -691,6 +704,12 @@ int romfs_stat(struct _reent *r, const char *path, struct stat *st)
|
|||||||
if(r->_errno != 0)
|
if(r->_errno != 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
|
if (!*path)
|
||||||
|
{
|
||||||
|
fill_dir(st, mount, curDir);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
ssize_t units = utf8_to_utf16(__utf16path, (const uint8_t*)path, PATH_MAX);
|
ssize_t units = utf8_to_utf16(__utf16path, (const uint8_t*)path, PATH_MAX);
|
||||||
if (units <= 0)
|
if (units <= 0)
|
||||||
{
|
{
|
||||||
@ -706,30 +725,14 @@ int romfs_stat(struct _reent *r, const char *path, struct stat *st)
|
|||||||
romfs_dir* dir = searchForDir(mount, curDir, __utf16path, units);
|
romfs_dir* dir = searchForDir(mount, curDir, __utf16path, units);
|
||||||
if(dir)
|
if(dir)
|
||||||
{
|
{
|
||||||
memset(st, 0, sizeof(*st));
|
fill_dir(st, mount, dir);
|
||||||
st->st_ino = dir_inode(mount, dir);
|
|
||||||
st->st_mode = romFS_dir_mode;
|
|
||||||
st->st_nlink = dir_nlink(mount, dir);
|
|
||||||
st->st_size = dir_size(dir);
|
|
||||||
st->st_blksize = 512;
|
|
||||||
st->st_blocks = (st->st_blksize + 511) / 512;
|
|
||||||
st->st_atime = st->st_mtime = st->st_ctime = mount->mtime;
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
romfs_file* file = searchForFile(mount, curDir, __utf16path, units);
|
romfs_file* file = searchForFile(mount, curDir, __utf16path, units);
|
||||||
if(file)
|
if(file)
|
||||||
{
|
{
|
||||||
memset(st, 0, sizeof(*st));
|
fill_file(st, mount, file);
|
||||||
st->st_ino = file_inode(mount, file);
|
|
||||||
st->st_mode = romFS_file_mode;
|
|
||||||
st->st_nlink = 1;
|
|
||||||
st->st_size = file->dataSize;
|
|
||||||
st->st_blksize = 512;
|
|
||||||
st->st_blocks = (st->st_blksize + 511) / 512;
|
|
||||||
st->st_atime = st->st_mtime = st->st_ctime = mount->mtime;
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user