Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions components/dfs/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@ if RT_USING_DFS
bool "Using working directory"
default y

config RT_USING_DFS_LARGE_FILE
bool "Enable 64-bit DFS internal file offset"
default n
help
Enable this option to use a signed 64-bit file offset type inside
DFS. The POSIX off_t type is still provided by the selected C
library/toolchain, but DFS filesystem drivers and DFS-native helper
APIs can handle file positions and file sizes larger than 2GB.

if RT_USING_DFS_V1
config RT_USING_DFS_MNTTABLE
bool "Using mount table for file system"
Expand Down
8 changes: 4 additions & 4 deletions components/dfs/dfs_v1/filesystems/9pfs/dfs_9pfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -807,7 +807,7 @@ static int dfs_9pfs_flush(struct dfs_file *fd)
return p9_to_fs_err(rc);
}

static off_t dfs_9pfs_lseek(struct dfs_file *fd, off_t offset)
static dfs_off_t dfs_9pfs_lseek(struct dfs_file *fd, dfs_off_t offset)
{
int ret = -EIO;

Expand Down Expand Up @@ -1049,7 +1049,7 @@ static int dfs_9pfs_unlink(struct dfs_filesystem *fs, const char *pathname)
}

static int dfs_9pfs_stat(struct dfs_filesystem *fs,
const char *filename, struct stat *st)
const char *filename, struct dfs_stat *st)
{
int rc = 0, fid;
rt_uint32_t size, mode;
Expand Down Expand Up @@ -1108,8 +1108,8 @@ static int dfs_9pfs_stat(struct dfs_filesystem *fs,
st->st_mode |= S_ISVTX;
}

st->st_atime = get_rx_value32_of(conn, P9_MSG_STAT_ATIME);
st->st_mtime = get_rx_value32_of(conn, P9_MSG_STAT_MTIME);
st->atime = get_rx_value32_of(conn, P9_MSG_STAT_ATIME);
st->mtime = get_rx_value32_of(conn, P9_MSG_STAT_MTIME);
st->st_size = get_rx_value64_of(conn, P9_MSG_STAT_LEN);

/*
Expand Down
6 changes: 3 additions & 3 deletions components/dfs/dfs_v1/filesystems/cromfs/dfs_cromfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -788,7 +788,7 @@ static int dfs_cromfs_read(struct dfs_file *file, void *buf, size_t count)
return length;
}

static int dfs_cromfs_lseek(struct dfs_file *file, off_t offset)
static dfs_off_t dfs_cromfs_lseek(struct dfs_file *file, dfs_off_t offset)
{
if (offset <= file->vnode->size)
{
Expand Down Expand Up @@ -1012,7 +1012,7 @@ static int dfs_cromfs_open(struct dfs_file *file)
return ret;
}

static int dfs_cromfs_stat(struct dfs_filesystem *fs, const char *path, struct stat *st)
static int dfs_cromfs_stat(struct dfs_filesystem *fs, const char *path, struct dfs_stat *st)
{
uint32_t size = 0, osize = 0;
int is_dir = 0;
Expand Down Expand Up @@ -1042,7 +1042,7 @@ static int dfs_cromfs_stat(struct dfs_filesystem *fs, const char *path, struct s
st->st_size = osize;
}

st->st_mtime = 0;
st->mtime = 0;

return RT_EOK;
}
Expand Down
6 changes: 3 additions & 3 deletions components/dfs/dfs_v1/filesystems/devfs/devfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ int dfs_device_fs_unlink(struct dfs_filesystem *fs, const char *path)
return RT_EOK;
}

int dfs_device_fs_stat(struct dfs_filesystem *fs, const char *path, struct stat *st)
int dfs_device_fs_stat(struct dfs_filesystem *fs, const char *path, struct dfs_stat *st)
{
st->st_dev = (dev_t)((size_t)dfs_filesystem_lookup(fs->path));
/* stat root directory */
Expand All @@ -296,7 +296,7 @@ int dfs_device_fs_stat(struct dfs_filesystem *fs, const char *path, struct stat
st->st_mode |= S_IFDIR | S_IXUSR | S_IXGRP | S_IXOTH;

st->st_size = 0;
st->st_mtime = 0;
st->mtime = 0;

return RT_EOK;
}
Expand All @@ -322,7 +322,7 @@ int dfs_device_fs_stat(struct dfs_filesystem *fs, const char *path, struct stat
st->st_mode |= S_IFREG;

st->st_size = 0;
st->st_mtime = 0;
st->mtime = 0;

return RT_EOK;
}
Expand Down
21 changes: 16 additions & 5 deletions components/dfs/dfs_v1/filesystems/elmfat/dfs_elm.c
Original file line number Diff line number Diff line change
Expand Up @@ -504,13 +504,19 @@ int dfs_elm_ioctl(struct dfs_file *file, int cmd, void *args)
{
FIL *fd;
FSIZE_t fptr, length;
dfs_off_t dfs_length;
FRESULT result = FR_OK;
fd = (FIL *)(file->data);
RT_ASSERT(fd != RT_NULL);

/* save file read/write point */
fptr = fd->fptr;
length = *(off_t*)args;
dfs_length = *(dfs_off_t*)args;
if (dfs_length < 0 || (dfs_off_t)(FSIZE_t)dfs_length != dfs_length)
{
return -EINVAL;
}
length = (FSIZE_t)dfs_length;
if (length <= fd->obj.objsize)
{
fd->fptr = length;
Expand Down Expand Up @@ -591,9 +597,14 @@ int dfs_elm_flush(struct dfs_file *file)
return elm_result_to_dfs(result);
}

off_t dfs_elm_lseek(struct dfs_file *file, off_t offset)
dfs_off_t dfs_elm_lseek(struct dfs_file *file, dfs_off_t offset)
{
FRESULT result = FR_OK;
if (offset < 0 || (dfs_off_t)(FSIZE_t)offset != offset)
{
return -EINVAL;
}

if (file->vnode->type == FT_REGULAR)
{
FIL *fd;
Expand All @@ -602,7 +613,7 @@ off_t dfs_elm_lseek(struct dfs_file *file, off_t offset)
fd = (FIL *)(file->data);
RT_ASSERT(fd != RT_NULL);

result = f_lseek(fd, offset);
result = f_lseek(fd, (FSIZE_t)offset);
if (result == FR_OK)
{
/* return current position */
Expand Down Expand Up @@ -751,7 +762,7 @@ int dfs_elm_rename(struct dfs_filesystem *fs, const char *oldpath, const char *n
return elm_result_to_dfs(result);
}

int dfs_elm_stat(struct dfs_filesystem *fs, const char *path, struct stat *st)
int dfs_elm_stat(struct dfs_filesystem *fs, const char *path, struct dfs_stat *st)
{
FATFS *f;
FILINFO file_info;
Expand Down Expand Up @@ -836,7 +847,7 @@ int dfs_elm_stat(struct dfs_filesystem *fs, const char *path, struct stat *st)
tm_file.tm_min = min; /* Minutes: 0-59 */
tm_file.tm_sec = sec; /* Seconds: 0-59 */

st->st_mtime = timegm(&tm_file);
st->mtime = timegm(&tm_file);
} /* get st_mtime. */
}

Expand Down
8 changes: 4 additions & 4 deletions components/dfs/dfs_v1/filesystems/iso9660/dfs_iso9660.c
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ static ssize_t dfs_iso9660_read(struct dfs_file *fd, void *buf, size_t count)
return rcount;
}

static off_t dfs_iso9660_lseek(struct dfs_file *fd, off_t offset)
static dfs_off_t dfs_iso9660_lseek(struct dfs_file *fd, dfs_off_t offset)
{
int ret = -EIO;

Expand Down Expand Up @@ -648,7 +648,7 @@ static int dfs_iso9660_unmount(struct dfs_filesystem *fs)
}

static int dfs_iso9660_stat(struct dfs_filesystem *fs,
const char *filename, struct stat *st)
const char *filename, struct dfs_stat *st)
{
struct iso9660 *iso = fs->data;
struct iso9660_fd *fd = iso9660_lookup(iso, filename, RT_NULL);
Expand All @@ -668,9 +668,9 @@ static int dfs_iso9660_stat(struct dfs_filesystem *fs,
st->st_mode |= S_IFDIR | S_IXUSR | S_IXGRP | S_IXOTH;
}

st->st_atime = iso9660_convert_unixtime(iso->joliet ?
st->atime = iso9660_convert_unixtime(iso->joliet ?
&iso->supp.created : &iso->primary.created);
st->st_mtime = iso9660_convert_unixtime2(&fd->dirent.mtime);
st->mtime = iso9660_convert_unixtime2(&fd->dirent.mtime);
st->st_size = rt_le32_to_cpu(fd->dirent.size);

rt_free(fd);
Expand Down
4 changes: 2 additions & 2 deletions components/dfs/dfs_v1/filesystems/mqueue/dfs_mqueue.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,11 @@ int dfs_mqueue_open(struct dfs_file *file) {
return 0;
}

int dfs_mqueue_stat(struct dfs_filesystem *fs, const char *path, struct stat *st) {
int dfs_mqueue_stat(struct dfs_filesystem *fs, const char *path, struct dfs_stat *st) {
st->st_dev = 0;
st->st_mode = S_IFREG | S_IRUSR | S_IRGRP | S_IROTH | S_IWUSR | S_IWGRP | S_IWOTH;
st->st_size = 0;
st->st_mtime = 0;
st->mtime = 0;
return RT_EOK;
}

Expand Down
6 changes: 3 additions & 3 deletions components/dfs/dfs_v1/filesystems/nfs/dfs_nfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -685,7 +685,7 @@ int nfs_write(struct dfs_file *file, const void *buf, size_t count)
return total;
}

int nfs_lseek(struct dfs_file *file, off_t offset)
dfs_off_t nfs_lseek(struct dfs_file *file, dfs_off_t offset)
{
nfs_file *fd;
nfs_filesystem *nfs;
Expand Down Expand Up @@ -837,7 +837,7 @@ int nfs_open(struct dfs_file *file)
return 0;
}

int nfs_stat(struct dfs_filesystem *fs, const char *path, struct stat *st)
int nfs_stat(struct dfs_filesystem *fs, const char *path, struct dfs_stat *st)
{
GETATTR3args args;
GETATTR3res res;
Expand Down Expand Up @@ -880,7 +880,7 @@ int nfs_stat(struct dfs_filesystem *fs, const char *path, struct stat *st)
}

st->st_size = info->size;
st->st_mtime = info->mtime.seconds;
st->mtime = info->mtime.seconds;

xdr_free((xdrproc_t)xdr_GETATTR3res, (char *)&res);
xdr_free((xdrproc_t)xdr_nfs_fh3, (char *)handle);
Expand Down
8 changes: 4 additions & 4 deletions components/dfs/dfs_v1/filesystems/ramfs/dfs_ramfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,9 @@ ssize_t dfs_ramfs_write(struct dfs_file *fd, const void *buf, size_t count)
return count;
}

off_t dfs_ramfs_lseek(struct dfs_file *file, off_t offset)
dfs_off_t dfs_ramfs_lseek(struct dfs_file *file, dfs_off_t offset)
{
if (offset <= (off_t)file->vnode->size)
if (offset <= file->vnode->size)
{
file->pos = offset;

Expand Down Expand Up @@ -346,7 +346,7 @@ int dfs_ramfs_open(struct dfs_file *file)

int dfs_ramfs_stat(struct dfs_filesystem *fs,
const char *path,
struct stat *st)
struct dfs_stat *st)
{
rt_size_t size;
struct ramfs_dirent *dirent;
Expand All @@ -363,7 +363,7 @@ int dfs_ramfs_stat(struct dfs_filesystem *fs,
S_IWUSR | S_IWGRP | S_IWOTH;

st->st_size = dirent->size;
st->st_mtime = 0;
st->mtime = 0;

return RT_EOK;
}
Expand Down
6 changes: 3 additions & 3 deletions components/dfs/dfs_v1/filesystems/romfs/dfs_romfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ ssize_t dfs_romfs_read(struct dfs_file *file, void *buf, size_t count)
return length;
}

off_t dfs_romfs_lseek(struct dfs_file *file, off_t offset)
dfs_off_t dfs_romfs_lseek(struct dfs_file *file, dfs_off_t offset)
{
if (offset <= file->vnode->size)
{
Expand Down Expand Up @@ -269,7 +269,7 @@ int dfs_romfs_open(struct dfs_file *file)
return RT_EOK;
}

int dfs_romfs_stat(struct dfs_filesystem *fs, const char *path, struct stat *st)
int dfs_romfs_stat(struct dfs_filesystem *fs, const char *path, struct dfs_stat *st)
{
rt_size_t size;
struct romfs_dirent *dirent;
Expand All @@ -294,7 +294,7 @@ int dfs_romfs_stat(struct dfs_filesystem *fs, const char *path, struct stat *st)
}

st->st_size = dirent->size;
st->st_mtime = 0;
st->mtime = 0;

return RT_EOK;
}
Expand Down
4 changes: 2 additions & 2 deletions components/dfs/dfs_v1/filesystems/skeleton/skeleton.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ int dfs_skt_read(struct dfs_file *file, void *buf, rt_size_t count)
return count;
}

int dfs_skt_lseek(struct dfs_file *file, rt_off_t offset)
dfs_off_t dfs_skt_lseek(struct dfs_file *file, dfs_off_t offset)
{
return -RT_EIO;
}
Expand All @@ -49,7 +49,7 @@ int dfs_skt_open(struct dfs_file *file)
return RT_EOK;
}

int dfs_skt_stat(struct dfs_filesystem *fs, const char *path, struct stat *st)
int dfs_skt_stat(struct dfs_filesystem *fs, const char *path, struct dfs_stat *st)
{
return RT_EOK;
}
Expand Down
8 changes: 4 additions & 4 deletions components/dfs/dfs_v1/filesystems/tmpfs/dfs_tmpfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -392,9 +392,9 @@ ssize_t dfs_tmpfs_write(struct dfs_file *fd, const void *buf, size_t count)
return count;
}

off_t dfs_tmpfs_lseek(struct dfs_file *file, off_t offset)
dfs_off_t dfs_tmpfs_lseek(struct dfs_file *file, dfs_off_t offset)
{
if (offset <= (off_t)file->vnode->size)
if (offset <= file->vnode->size)
{
file->pos = offset;

Expand Down Expand Up @@ -550,7 +550,7 @@ int dfs_tmpfs_open(struct dfs_file *file)

int dfs_tmpfs_stat(struct dfs_filesystem *fs,
const char *path,
struct stat *st)
struct dfs_stat *st)
{
rt_size_t size;
struct tmpfs_file *d_file;
Expand All @@ -572,7 +572,7 @@ int dfs_tmpfs_stat(struct dfs_filesystem *fs,
}

st->st_size = d_file->size;
st->st_mtime = 0;
st->mtime = 0;

return RT_EOK;
}
Expand Down
31 changes: 31 additions & 0 deletions components/dfs/dfs_v1/include/dfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,37 @@ extern "C" {
#define DFS_F_EOF 0x04000000
#define DFS_F_ERR 0x08000000

#ifdef RT_USING_DFS_LARGE_FILE
typedef int64_t dfs_off_t;
#define DFS_OFF_MAX INT64_MAX
#else
typedef int32_t dfs_off_t;
#define DFS_OFF_MAX INT32_MAX
#endif

struct dfs_stat
{
dev_t st_dev;
uint16_t st_ino;
uint16_t st_mode;
uint16_t st_nlink;
uint16_t st_uid;
uint16_t st_gid;
struct rt_device *st_rdev;
dfs_off_t st_size;
time_t atime;
long st_spare1;
time_t mtime;
long st_spare2;
time_t ctime;
long st_spare3;
uint32_t st_blksize;
uint32_t st_blocks;
long st_spare4[2];
};

void dfs_print_off_t(dfs_off_t value);

struct dfs_fdtable
{
uint32_t maxfd;
Expand Down
Loading
Loading