更新日期: 2022/06/01 来源: https://gitee.com/weharmony/kernel_liteos_a_note
vfs_readv.c 文件参考

浏览源代码.

函数

static char * pread_buf_and_check (int fd, const struct iovec *iov, int iovcnt, ssize_t *totalbytesread, off_t *offset)
 
ssize_t vfs_readv (int fd, const struct iovec *iov, int iovcnt, off_t *offset)
 供系统调用 更多...
 
ssize_t readv (int fd, const struct iovec *iov, int iovcnt)
 

函数说明

◆ pread_buf_and_check()

static char * pread_buf_and_check ( int  fd,
const struct iovec *  iov,
int  iovcnt,
ssize_t totalbytesread,
off_t *  offset 
)
static

在文件 vfs_readv.c42 行定义.

43{
44 char *buf = NULL;
45 size_t buflen = 0;
46 int i;
47
48 if ((iov == NULL) || (iovcnt > IOV_MAX)) {
49 *totalbytesread = VFS_ERROR;
50 return NULL;
51 }
52
53 for (i = 0; i < iovcnt; ++i) {
54 if (SSIZE_MAX - buflen < iov[i].iov_len) {
55 set_errno(EINVAL);
56 return NULL;
57 }
58 buflen += iov[i].iov_len;
59 }
60
61 if (buflen == 0) {
62 *totalbytesread = 0;
63 return NULL;
64 }
65
66#ifdef LOSCFG_KERNEL_VM
67 buf = (char *)LOS_VMalloc(buflen * sizeof(char));
68#else
69 buf = (char *)malloc(buflen * sizeof(char));
70#endif
71 if (buf == NULL) {
72 set_errno(ENOMEM);
73 *totalbytesread = VFS_ERROR;
74 return buf;
75 }
76
77 *totalbytesread = (offset == NULL) ? read(fd, buf, buflen)
78 : pread(fd, buf, buflen, *offset);
79 if ((*totalbytesread == VFS_ERROR) || (*totalbytesread == 0)) {
80#ifdef LOSCFG_KERNEL_VM
81 LOS_VFree(buf);
82#else
83 free(buf);
84#endif
85 return NULL;
86 }
87
88 return buf;
89}
VOID LOS_VFree(const VOID *addr)
VOID * LOS_VMalloc(size_t size)
void * malloc(size_t size)
动态分配内存块大小
Definition: malloc.c:81
void free(void *ptr)
释放ptr所指向的内存空间
Definition: malloc.c:66
函数调用图:
这是这个函数的调用关系图:

◆ readv()

ssize_t readv ( int  fd,
const struct iovec *  iov,
int  iovcnt 
)

在文件 vfs_readv.c144 行定义.

145{
146 return vfs_readv(fd, iov, iovcnt, NULL);
147}
ssize_t vfs_readv(int fd, const struct iovec *iov, int iovcnt, off_t *offset)
供系统调用
Definition: vfs_readv.c:91
函数调用图:

◆ vfs_readv()

ssize_t vfs_readv ( int  fd,
const struct iovec *  iov,
int  iovcnt,
off_t *  offset 
)

供系统调用

在文件 vfs_readv.c91 行定义.

92{
93 int i;
94 int ret;
95 char *buf = NULL;
96 char *curbuf = NULL;
97 ssize_t bytestoread;
98 ssize_t totalbytesread = 0;
99 ssize_t bytesleft;
100
101 buf = pread_buf_and_check(fd, iov, iovcnt, &totalbytesread, offset);
102 if (buf == NULL) {
103 return totalbytesread;
104 }
105
106 curbuf = buf;
107 bytesleft = totalbytesread;
108 for (i = 0; i < iovcnt; ++i) {
109 bytestoread = iov[i].iov_len;
110 if (bytestoread == 0) {
111 continue;
112 }
113
114 if (bytesleft <= bytestoread) {
115 ret = LOS_CopyFromKernel(iov[i].iov_base, bytesleft, curbuf, bytesleft);
116 bytesleft = ret;
117 goto out;
118 }
119
120 ret = LOS_CopyFromKernel(iov[i].iov_base, bytestoread, curbuf, bytestoread);
121 if (ret != 0) {
122 bytesleft = bytesleft - (bytestoread - ret);
123 goto out;
124 }
125 bytesleft -= bytestoread;
126 curbuf += bytestoread;
127 }
128
129out:
130#ifdef LOSCFG_KERNEL_VM
131 LOS_VFree(buf);
132#else
133 free(buf);
134#endif
135 if ((i == 0) && (ret == iov[i].iov_len)) {
136 /* failed in the first iovec copy, and 0 bytes copied */
137 set_errno(EFAULT);
138 return VFS_ERROR;
139 }
140
141 return totalbytesread - bytesleft;
142}
INT64 ssize_t
Definition: los_typedef.h:79
INT32 LOS_CopyFromKernel(VOID *dest, UINT32 max, const VOID *src, UINT32 count)
将内核数据拷贝到用户空间
Definition: user_copy.c:88
static char * pread_buf_and_check(int fd, const struct iovec *iov, int iovcnt, ssize_t *totalbytesread, off_t *offset)
Definition: vfs_readv.c:42
函数调用图:
这是这个函数的调用关系图: