MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / dfs_file_read

Function dfs_file_read

components/dfs/dfs_v2/src/dfs_file.c:959–1008  ·  view source on GitHub ↗

* @brief Read data from a file at current position * * @param[in] file Pointer to the file structure to read from * @param[out] buf Buffer to store the read data * @param[in] len Number of bytes to read * * @return ssize_t Number of bytes read on success, or negative error code: * -EBADF if invalid file descriptor * -EPERM if read permission denied * -ENOSYS if rea

Source from the content-addressed store, hash-verified

957 * -EINVAL if invalid parameters or not mounted
958 */
959ssize_t dfs_file_read(struct dfs_file *file, void *buf, size_t len)
960{
961 ssize_t ret = -EBADF;
962
963 if (file)
964 {
965 /* check whether read */
966 if (!(dfs_fflags(file->flags) & DFS_F_FREAD))
967 {
968 ret = -EPERM;
969 }
970 else if (!file->fops || !file->fops->read)
971 {
972 ret = -ENOSYS;
973 }
974 else if (file->vnode && file->vnode->type != FT_DIRECTORY)
975 {
976 /* fpos lock */
977 off_t pos = dfs_file_get_fpos(file);
978
979 ret = rw_verify_area(file, &pos, len);
980 if (ret > 0)
981 {
982 len = ret;
983
984 if (dfs_is_mounted(file->vnode->mnt) == 0)
985 {
986#ifdef RT_USING_PAGECACHE
987 if (file->vnode->aspace && !(file->flags & O_DIRECT))
988 {
989 ret = dfs_aspace_read(file, buf, len, &pos);
990 }
991 else
992#endif
993 {
994 ret = file->fops->read(file, buf, len, &pos);
995 }
996 }
997 else
998 {
999 ret = -EINVAL;
1000 }
1001 }
1002 /* fpos unlock */
1003 dfs_file_set_fpos(file, pos);
1004 }
1005 }
1006
1007 return ret;
1008}
1009
1010/**
1011 * @brief Write data to a file at specified offset

Callers 3

readFunction · 0.70
catFunction · 0.70
copyfileFunction · 0.70

Calls 7

dfs_fflagsFunction · 0.85
dfs_file_get_fposFunction · 0.85
rw_verify_areaFunction · 0.85
dfs_is_mountedFunction · 0.85
dfs_aspace_readFunction · 0.85
dfs_file_set_fposFunction · 0.85
readMethod · 0.45

Tested by

no test coverage detected