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

浏览源代码.

函数

static int iov_trans_to_buf (char *buf, ssize_t totallen, const struct iovec *iov, int iovcnt)
 
ssize_t vfs_writev (int fd, const struct iovec *iov, int iovcnt, off_t *offset)
 
ssize_t writev (int fd, const struct iovec *iov, int iovcnt)
 

函数说明

◆ iov_trans_to_buf()

static int iov_trans_to_buf ( char *  buf,
ssize_t  totallen,
const struct iovec *  iov,
int  iovcnt 
)
static

在文件 vfs_writev.c41 行定义.

42{
43 int i;
44 size_t ret, writepart;
45 size_t bytestowrite;
46 char *writebuf = NULL;
47 char *curbuf = buf;
48
49 for (i = 0; i < iovcnt; ++i) {
50 writebuf = (char *)iov[i].iov_base;
51 bytestowrite = iov[i].iov_len;
52 if (bytestowrite == 0) {
53 continue;
54 }
55
56 if (totallen == 0) {
57 break;
58 }
59
60 bytestowrite = (totallen < bytestowrite) ? totallen : bytestowrite;
61 ret = LOS_CopyToKernel(curbuf, bytestowrite, writebuf, bytestowrite);
62 if (ret != 0) {
63 if (ret == bytestowrite) {
64 set_errno(EFAULT);
65 return VFS_ERROR;
66 } else {
67 writepart = bytestowrite - ret;
68 curbuf += writepart;
69 totallen -= writepart;
70 break;
71 }
72 }
73 curbuf += bytestowrite;
74 totallen -= bytestowrite;
75 }
76
77 return (int)((intptr_t)curbuf - (intptr_t)buf);
78}
INT32 LOS_CopyToKernel(VOID *dest, UINT32 max, const VOID *src, UINT32 count)
将用户空间的数据拷贝到内核空间
Definition: user_copy.c:101
函数调用图:
这是这个函数的调用关系图:

◆ vfs_writev()

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

在文件 vfs_writev.c80 行定义.

81{
82 int i, ret;
83 char *buf = NULL;
84 size_t buflen = 0;
85 size_t bytestowrite;
86 ssize_t totalbyteswritten;
87 size_t totallen;
88
89 if ((iov == NULL) || (iovcnt > IOV_MAX)) {
90 return VFS_ERROR;
91 }
92
93 for (i = 0; i < iovcnt; ++i) {
94 if (SSIZE_MAX - buflen < iov[i].iov_len) {
95 set_errno(EINVAL);
96 return VFS_ERROR;
97 }
98 buflen += iov[i].iov_len;
99 }
100
101 if (buflen == 0) {
102 return 0;
103 }
104
105 totallen = buflen * sizeof(char);
106#ifdef LOSCFG_KERNEL_VM
107 buf = (char *)LOS_VMalloc(totallen);
108#else
109 buf = (char *)malloc(totallen);
110#endif
111 if (buf == NULL) {
112 return VFS_ERROR;
113 }
114
115 ret = iov_trans_to_buf(buf, totallen, iov, iovcnt);
116 if (ret <= 0) {
117#ifdef LOSCFG_KERNEL_VM
118 LOS_VFree(buf);
119#else
120 free(buf);
121#endif
122 return VFS_ERROR;
123 }
124
125 bytestowrite = (ssize_t)ret;
126 totalbyteswritten = (offset == NULL) ? write(fd, buf, bytestowrite)
127 : pwrite(fd, buf, bytestowrite, *offset);
128#ifdef LOSCFG_KERNEL_VM
129 LOS_VFree(buf);
130#else
131 free(buf);
132#endif
133 return totalbyteswritten;
134}
INT64 ssize_t
Definition: los_typedef.h:79
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
static int iov_trans_to_buf(char *buf, ssize_t totallen, const struct iovec *iov, int iovcnt)
Definition: vfs_writev.c:41
函数调用图:
这是这个函数的调用关系图:

◆ writev()

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

在文件 vfs_writev.c136 行定义.

137{
138 return vfs_writev(fd, iov, iovcnt, NULL);
139}
ssize_t vfs_writev(int fd, const struct iovec *iov, int iovcnt, off_t *offset)
Definition: vfs_writev.c:80
函数调用图:
这是这个函数的调用关系图: