42#include "sys/utsname.h"
47#ifdef LOSCFG_KERNEL_DYNLOAD
58#include "sys/statfs.h"
60#define HIGH_SHIFT_BIT 32
61#define TIMESPEC_TIMES_NUM 2
66 struct timespec stp = {0};
69 if (
times[0].tv_nsec == UTIME_OMIT) {
71 }
else if (
times[0].tv_nsec == UTIME_NOW) {
83 if (
times[1].tv_nsec == UTIME_OMIT) {
85 }
else if (
times[1].tv_nsec == UTIME_NOW) {
113 char *fullPath = NULL;
116 if ((fd != AT_FDCWD) && (path == NULL)) {
118 ret = fs_getfilep(fd, &
file);
123 if (fullPath == NULL) {
133 *filePath = fullPath;
140 for (i = 0; i < iovcnt; ++i) {
141 if (iov[i].iov_len == 0) {
152static int UserIovCopy(
struct iovec **iovBuf,
const struct iovec *iov,
const int iovcnt,
int *valid_iovcnt)
155 int bufLen = iovcnt *
sizeof(
struct iovec);
160 *iovBuf = (
struct iovec*)
LOS_MemAlloc(OS_SYS_MEM_ADDR, bufLen);
161 if (*iovBuf == NULL) {
182 if ((nfds != 0 && fds == NULL) || (pollFdsBak == NULL)) {
189 int *pollFds = (
int *)
malloc(
sizeof(
int) * nfds);
190 if (pollFds == NULL) {
194 for (
int i = 0; i < nfds; ++i) {
195 struct pollfd *p_fds = &fds[i];
196 pollFds[i] = p_fds->fd;
204 *pollFdsBak = pollFds;
208static void RestorePollfd(
struct pollfd *fds, nfds_t nfds,
const int *pollFds)
210 if ((fds == NULL) || (pollFds == NULL)) {
213 for (
int i = 0; i < nfds; ++i) {
214 struct pollfd *p_fds = &fds[i];
215 p_fds->fd = pollFds[i];
219static int UserPoll(
struct pollfd *fds, nfds_t nfds,
int timeout)
227 ret = poll(fds, nfds, timeout);
266 ret = read(fd, buf, nbytes);
287 ret = write(sysfd, buf, nbytes);
298 mode_t mode = DEFAULT_FILE_MODE;
299 char *pathRet = NULL;
314 if (oflags & O_CLOEXEC) {
318 if ((
unsigned int)oflags & O_DIRECTORY) {
322#ifdef LOSCFG_FILE_MODE
325 va_start(ap, oflags);
326 mode = va_arg(ap,
int);
331 ret =
do_open(AT_FDCWD, pathRet, oflags, mode);
340 if (pathRet != NULL) {
346 if (pathRet != NULL) {
375 char *pathRet = NULL;
377 if (pathname != NULL) {
390 ret = open((pathname ? pathRet : NULL), O_CREAT | O_TRUNC | O_WRONLY, mode);
400 if (pathRet != NULL) {
406int SysLink(
const char *oldpath,
const char *newpath)
409 char *oldpathRet = NULL;
410 char *newpathRet = NULL;
412 if (oldpath != NULL) {
419 if (newpath != NULL) {
426 ret = link(oldpathRet, newpathRet);
432 if (oldpathRet != NULL) {
435 if (newpathRet != NULL) {
444 char *pathRet = NULL;
450 if (pathname != NULL) {
462 ret = readlink(pathRet, buf, bufsize);
468 if (pathRet != NULL) {
477 char *targetRet = NULL;
478 char *pathRet = NULL;
480 if (target != NULL) {
487 if (linkpath != NULL) {
494 ret = symlink(targetRet, pathRet);
500 if (pathRet != NULL) {
504 if (targetRet != NULL) {
522 char *pathRet = NULL;
524 if (pathname != NULL) {
531 ret =
do_unlink(AT_FDCWD, (pathname ? pathRet : NULL));
537 if (pathRet != NULL) {
543#ifdef LOSCFG_KERNEL_DYNLOAD
548int SysExecve(
const char *fileName,
char *
const *argv,
char *
const *envp)
565 ret = fs_getfilep(sysFd, &
file);
581 char *pathRet = NULL;
590 ret =
chdir(path ? pathRet : NULL);
596 if (pathRet != NULL) {
607 return _lseek(fd, offset, whence);
620 ret =
_lseek64(fd, offsetHigh, offsetLow, &res, whence);
634static int NfsMountRef(
const char *serverIpAndPath,
const char *mountPath,
635 unsigned int uid,
unsigned int gid)
__attribute__((weakref(
"nfs_mount")));
637static int NfsMount(
const char *serverIpAndPath,
const char *mountPath,
638 unsigned int uid,
unsigned int gid)
642 if ((serverIpAndPath == NULL) || (mountPath == NULL)) {
645 ret =
NfsMountRef(serverIpAndPath, mountPath, uid, gid);
666int SysMount(
const char *source,
const char *target,
const char *filesystemtype,
unsigned long mountflags,
670 char *sourceRet = NULL;
671 char *targetRet = NULL;
672 char *dataRet = NULL;
673 char fstypeRet[FILESYSTEM_TYPE_MAX + 1] = {0};
679 if (target != NULL) {
686 if (filesystemtype != NULL) {
690 }
else if (ret > FILESYSTEM_TYPE_MAX) {
695 if (strcmp(fstypeRet,
"ramfs") && (source != NULL)) {
702 if (strcmp(fstypeRet,
"nfs") == 0) {
703 ret =
NfsMount(sourceRet, targetRet, 0, 0);
716 ret = mount(sourceRet, targetRet, (filesystemtype ? fstypeRet : NULL), mountflags, dataRet);
722 if (sourceRet != NULL) {
725 if (targetRet != NULL) {
728 if (dataRet != NULL) {
737 char *pathRet = NULL;
743 if (target != NULL) {
750 ret = umount(target ? pathRet : NULL);
756 if (pathRet != NULL) {
765 char *pathRet = NULL;
774 ret =
access(pathRet, amode);
780 if (pathRet != NULL) {
790 char *pathOldRet = NULL;
791 char *pathNewRet = NULL;
793 if (oldpath != NULL) {
800 if (newpath != NULL) {
807 ret =
do_rename(AT_FDCWD, (oldpath ? pathOldRet : NULL), AT_FDCWD,
808 (newpath ? pathNewRet : NULL));
814 if (pathOldRet != NULL) {
817 if (pathNewRet != NULL) {
826 char *pathRet = NULL;
828 if (pathname != NULL) {
835 ret =
do_mkdir(AT_FDCWD, (pathname ? pathRet : NULL), mode);
841 if (pathRet != NULL) {
850 char *pathRet = NULL;
852 if (pathname != NULL) {
859 ret =
do_rmdir(AT_FDCWD, (pathname ? pathRet : NULL));
865 if (pathRet != NULL) {
875 if ((sysfd < 0) || (sysfd >= CONFIG_NFILE_DESCRIPTORS)) {
905 unsigned int size = _IOC_SIZE((
unsigned int)req);
906 unsigned int dir = _IOC_DIR((
unsigned int)req);
907 if ((size == 0) && (dir != _IOC_NONE)) {
911 if ((dir != _IOC_NONE) && (((
void *)(uintptr_t)arg) == NULL)) {
915 if ((dir & _IOC_READ) || (dir & _IOC_WRITE)) {
924 ret = ioctl(fd, req, arg);
963 if (ret == CONTINE_NUTTX_FCNTL) {
964 ret = fcntl(sysfd, cmd, arg);
973#ifdef LOSCFG_KERNEL_PIPE
998 int pipeFdIntr[2] = {0};
1010 ret = pipe(pipeFdIntr);
1014 return -get_errno();
1016 int sysPipeFd0 = pipeFdIntr[0];
1017 int sysPipeFd1 = pipeFdIntr[1];
1022 pipeFdIntr[0] = procFd0;
1023 pipeFdIntr[1] = procFd1;
1045 if ((sysfd1 < 0) || (sysfd1 >= CONFIG_NFILE_DESCRIPTORS) || (
CheckProcessFd(fd2) != OK)) {
1061 ret = close(sysfd2);
1064 return -get_errno();
1078 fd_set *readfdsRet = NULL;
1079 fd_set *writefdsRet = NULL;
1080 fd_set *exceptfdsRet = NULL;
1082 *fdsBuf = (fd_set *)
LOS_MemAlloc(OS_SYS_MEM_ADDR,
sizeof(fd_set) * 3);
1083 if (*fdsBuf == NULL) {
1087 readfdsRet = *fdsBuf;
1088 writefdsRet = *fdsBuf + 1;
1089 exceptfdsRet = *fdsBuf + 2;
1091 if (readfds != NULL) {
1098 if (writefds != NULL) {
1105 if (exceptfds != NULL) {
1135int SysSelect(
int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
struct timeval *timeout)
1138 fd_set *fdsRet = NULL;
1139 fd_set *readfdsRet = NULL;
1140 fd_set *writefdsRet = NULL;
1141 fd_set *exceptfdsRet = NULL;
1142 struct timeval timeoutRet = {0};
1149 readfdsRet = fdsRet;
1150 writefdsRet = fdsRet + 1;
1151 exceptfdsRet = fdsRet + 2;
1153 if (timeout != NULL) {
1159 ret =
do_select(nfds, (readfds ? readfdsRet : NULL), (writefds ? writefdsRet : NULL),
1160 (exceptfds ? exceptfdsRet : NULL), (timeout ? (&timeoutRet) : NULL),
UserPoll);
1163 return -get_errno();
1166 if (readfds != NULL) {
1172 if (writefds != NULL) {
1178 if (exceptfds != 0) {
1196 char *pathRet = NULL;
1205 fd = open((path ? pathRet : NULL), O_RDWR);
1212 ret = ftruncate(fd, length);
1219 if (pathRet != NULL) {
1229 char *pathRet = NULL;
1238 fd = open((path ? pathRet : NULL), O_RDWR);
1245 ret = ftruncate64(fd, length);
1252 if (pathRet != NULL) {
1265 ret = ftruncate(fd, length);
1267 return -get_errno();
1275 char *pathRet = NULL;
1276 struct statfs bufRet = {0};
1285 ret = statfs((path ? pathRet : NULL), (buf ? (&bufRet) : NULL));
1297 if (pathRet != NULL) {
1306 char *pathRet = NULL;
1307 struct statfs bufRet = {0};
1316 if (sz !=
sizeof(*buf)) {
1321 ret = statfs((path ? pathRet : NULL), (buf ? (&bufRet) : NULL));
1333 if (pathRet != NULL) {
1342 char *pathRet = NULL;
1343 struct stat bufRet = {0};
1352 ret = stat((path ? pathRet : NULL), (buf ? (&bufRet) : NULL));
1364 if (pathRet != NULL) {
1373 char *pathRet = NULL;
1374 struct stat bufRet = {0};
1383 ret = stat((path ? pathRet : NULL), (buffer ? (&bufRet) : NULL));
1395 if (pathRet != NULL) {
1404 struct stat bufRet = {0};
1405 struct file *filep = NULL;
1410 ret = fs_getfilep(fd, &filep);
1412 return -get_errno();
1415 if (filep->
f_oflags & O_DIRECTORY) {
1419 ret = stat(filep->
f_path, (buf ? (&bufRet) : NULL));
1421 return -get_errno();
1432int SysStatx(
int fd,
const char *restrict path,
int flag,
unsigned mask,
struct statx *restrict stx)
1440 struct file *filep = NULL;
1446 ret = fs_getfilep(fd, &filep);
1449 return -get_errno();
1452 if (filep->
f_oflags & O_DIRECTORY) {
1457 ret = file_fsync(filep);
1459 return -get_errno();
1467 int valid_iovcnt = -1;
1468 struct iovec *iovRet = NULL;
1472 if ((iov == NULL) || (iovcnt < 0) || (iovcnt > IOV_MAX)) {
1480 ret =
UserIovCopy(&iovRet, iov, iovcnt, &valid_iovcnt);
1485 if (valid_iovcnt <= 0) {
1490 ret =
vfs_readv(fd, iovRet, valid_iovcnt, NULL);
1503 int valid_iovcnt = -1;
1504 struct iovec *iovRet = NULL;
1508 if ((iovcnt < 0) || (iovcnt > IOV_MAX)) {
1520 ret =
UserIovCopy(&iovRet, iov, iovcnt, &valid_iovcnt);
1525 if (valid_iovcnt != iovcnt) {
1530 ret =
writev(sysfd, iovRet, valid_iovcnt);
1552int SysPoll(
struct pollfd *fds, nfds_t nfds,
int timeout)
1555 struct pollfd *kfds = NULL;
1557 if ((nfds >= MAX_POLL_NFDS) || (nfds == 0) || (fds == NULL)) {
1561 kfds = (
struct pollfd *)
malloc(
sizeof(
struct pollfd) * nfds);
1569 int *pollFds = NULL;
1576 ret = poll(kfds, nfds, timeout);
1603 va_start(ap, option);
1604 if (option != PR_SET_NAME) {
1605 PRINT_ERR(
"%s: %d, no support option : 0x%x\n", __FUNCTION__, __LINE__, option);
1610 name = va_arg(ap,
unsigned long);
1617 if (err != LOS_OK) {
1632 char *bufRet = NULL;
1638 ret = pread64(fd, buf, nbytes, offset);
1640 return -get_errno();
1646 bufRet = (
char *)
LOS_MemAlloc(OS_SYS_MEM_ADDR, nbytes);
1647 if (bufRet == NULL) {
1651 ret = pread64(fd, (buf ? bufRet : NULL), nbytes, offset);
1654 return -get_errno();
1670 char *bufRet = NULL;
1676 ret = pwrite64(fd, buf, nbytes, offset);
1678 return -get_errno();
1683 bufRet = (
char *)
LOS_MemAlloc(OS_SYS_MEM_ADDR, nbytes);
1684 if (bufRet == NULL) {
1696 ret = pwrite64(fd, (buf ? bufRet : NULL), nbytes, offset);
1699 return -get_errno();
1709 char *bufRet = NULL;
1713 if (bufLen > PATH_MAX) {
1717 bufRet = (
char *)
LOS_MemAlloc(OS_SYS_MEM_ADDR, bufLen);
1718 if (bufRet == NULL) {
1719 return (
char *)(intptr_t)-ENOMEM;
1721 (
void)memset_s(bufRet, bufLen, 0, bufLen);
1723 ret =
getcwd((buf ? bufRet : NULL), bufLen);
1726 return (
char *)(intptr_t)-get_errno();
1732 return (
char *)(intptr_t)-EFAULT;
1754 ret = sendfile(outfd, infd, (offset ? (&offsetRet) : NULL), count);
1756 return -get_errno();
1774 ret = ftruncate64(fd, length);
1776 return -get_errno();
1785 char *pathRet = NULL;
1787#ifdef LOSCFG_FILE_MODE
1790 va_start(ap, oflags);
1791 mode = va_arg(ap,
int);
1810 if (oflags & O_CLOEXEC) {
1814 if (dirfd != AT_FDCWD) {
1819 ret =
do_open(dirfd, (path ? pathRet : NULL), oflags, mode);
1826 if (pathRet != NULL) {
1832 if (pathRet != NULL) {
1844 char *pathRet = NULL;
1846 if (pathname != NULL) {
1853 if (dirfd != AT_FDCWD) {
1858 ret =
do_mkdir(dirfd, (pathname ? pathRet : NULL), mode);
1864 if (pathRet != NULL) {
1870int SysLinkat(
int olddirfd,
const char *oldpath,
int newdirfd,
const char *newpath,
int flags)
1873 char *oldpathRet = NULL;
1874 char *newpathRet = NULL;
1876 if (oldpath != NULL) {
1883 if (newpath != NULL) {
1890 if (olddirfd != AT_FDCWD) {
1895 if (newdirfd != AT_FDCWD) {
1900 ret = linkat(olddirfd, oldpathRet, newdirfd, newpathRet, flags);
1906 if (oldpathRet != NULL) {
1909 if (newpathRet != NULL) {
1918 char *pathRet = NULL;
1919 char *targetRet = NULL;
1921 if (target != NULL) {
1928 if (linkpath != NULL) {
1935 if (dirfd != AT_FDCWD) {
1940 ret = symlinkat(targetRet, dirfd, pathRet);
1946 if (pathRet != NULL) {
1950 if (targetRet != NULL) {
1959 char *pathRet = NULL;
1965 if (pathname != NULL) {
1972 if (dirfd != AT_FDCWD) {
1982 ret = readlinkat(dirfd, pathRet, buf, bufsize);
1988 if (pathRet != NULL) {
1997 char *pathRet = NULL;
1999 if (pathname != NULL) {
2006 if (dirfd != AT_FDCWD) {
2011 ret = unlinkat(dirfd, (pathname ? pathRet : NULL), flag);
2017 if (pathRet != NULL) {
2023int SysRenameat(
int oldfd,
const char *oldpath,
int newdfd,
const char *newpath)
2026 char *pathOldRet = NULL;
2027 char *pathNewRet = NULL;
2029 if (oldpath != NULL) {
2036 if (newpath != NULL) {
2043 if (oldfd != AT_FDCWD) {
2047 if (newdfd != AT_FDCWD) {
2052 ret =
do_rename(oldfd, (oldpath ? pathOldRet : NULL), newdfd, (newpath ? pathNewRet : NULL));
2058 if (pathOldRet != NULL) {
2061 if (pathNewRet != NULL) {
2076 return -get_errno();
2090 return -get_errno();
2098 offsetflag = (off_t)((
unsigned long long)loffset | (((
unsigned long long)hoffset) << HIGH_SHIFT_BIT));
2101 int valid_iovcnt = -1;
2102 struct iovec *iovRet = NULL;
2106 if ((iov == NULL) || (iovcnt < 0) || (iovcnt > IOV_MAX)) {
2114 ret =
UserIovCopy(&iovRet, iov, iovcnt, &valid_iovcnt);
2119 if (valid_iovcnt <= 0) {
2124 ret =
preadv(fd, iovRet, valid_iovcnt, offsetflag);
2137 offsetflag = (off_t)((
unsigned long long)loffset | (((
unsigned long long)hoffset) << HIGH_SHIFT_BIT));
2139 int valid_iovcnt = -1;
2140 struct iovec *iovRet = NULL;
2144 if ((iov == NULL) || (iovcnt < 0) || (iovcnt > IOV_MAX)) {
2152 ret =
UserIovCopy(&iovRet, iov, iovcnt, &valid_iovcnt);
2157 if (valid_iovcnt != iovcnt) {
2162 ret =
pwritev(fd, iovRet, valid_iovcnt, offsetflag);
2176 char *devRet = NULL;
2189 ret =
format((dev ? devRet : NULL), sectors, option);
2195 if (devRet != NULL) {
2205 struct stat64 bufRet = {0};
2210 ret =
fstat64(fd, (buf ? (&bufRet) : NULL));
2212 return -get_errno();
2229 if (ret == CONTINE_NUTTX_FCNTL) {
2230 ret = fcntl64(sysfd, cmd, arg);
2234 return -get_errno();
2245 struct dirent *de_knl = NULL;
2254 if (de_knl != NULL) {
2266 char *pathRet = NULL;
2267 char *resolved_pathRet = NULL;
2268 char *result = NULL;
2271 if (resolved_path == NULL) {
2272 return (
char *)(intptr_t)-EINVAL;
2278 result = (
char *)(intptr_t)ret;
2283 resolved_pathRet =
realpath((path ? pathRet : NULL), NULL);
2284 if (resolved_pathRet == NULL) {
2285 result = (
char *)(intptr_t)-get_errno();
2289 ret =
LOS_ArchCopyToUser(resolved_path, resolved_pathRet, strlen(resolved_pathRet) + 1);
2291 result = (
char *)(intptr_t)-EFAULT;
2294 result = resolved_path;
2297 if (pathRet != NULL) {
2300 if (resolved_pathRet != NULL) {
2310 struct IATTR attr = {0};
2311 char *filePath = NULL;
2313 timeLen = TIMESPEC_TIMES_NUM *
sizeof(
struct timespec);
2314 CHECK_ASPACE(
times, timeLen);
2315 DUP_FROM_USER(
times, timeLen);
2327 ret =
chattr(filePath, &attr);
2333 PointerFree(filePath);
2340 char *pathRet = NULL;
2342 if (pathname != NULL) {
2349 ret =
chmod(pathRet, mode);
2355 if (pathRet != NULL) {
2364 char *pathRet = NULL;
2365 char *fullpath = NULL;
2366 struct IATTR attr = {
2368 .attr_chg_valid = CHG_MODE,
2378 if (fd != AT_FDCWD) {
2388 ret =
chattr(fullpath, &attr);
2394 PointerFree(pathRet);
2395 PointerFree(fullpath);
2404 struct IATTR attr = {
2406 .attr_chg_valid = CHG_MODE,
2415 ret = fs_getfilep(sysFd, &
file);
2417 return -get_errno();
2422 return -get_errno();
2428int SysFchownat(
int fd,
const char *path, uid_t owner, gid_t group,
int flag)
2431 char *fullpath = NULL;
2432 struct IATTR attr = {
2441 if (owner != (uid_t)-1) {
2445 if (group != (gid_t)-1) {
2450 ret =
chattr(fullpath, &attr);
2456 PointerFree(fullpath);
2465 struct IATTR attr = {0};
2474 ret = fs_getfilep(sysFd, &
file);
2476 return -get_errno();
2479 if (owner != (uid_t)-1) {
2483 if (group != (gid_t)-1) {
2495int SysChown(
const char *pathname, uid_t owner, gid_t group)
2498 char *pathRet = NULL;
2500 if (pathname != NULL) {
2507 ret =
chown(pathRet, owner, group);
2513 if (pathRet != NULL) {
2519int SysFstatat64(
int dirfd,
const char *restrict path,
struct kstat *restrict buf,
int flag)
2522 struct stat bufRet = {0};
2523 char *pathRet = NULL;
2524 char *fullpath = NULL;
2533 if (dirfd != AT_FDCWD) {
2543 ret = stat(fullpath, &bufRet);
2556 if (pathRet != NULL) {
2560 if (fullpath != NULL) {
2570 struct statfs fsBuf;
2571 char *fullDirectory = NULL;
2578 ret = statfs(fullDirectory, &fsBuf);
2584 if ((fsBuf.f_flags & MS_RDONLY) && ((
unsigned int)amode & W_OK)) {
2589 ret = stat(fullDirectory, &buf);
2600 PointerFree(fullDirectory);
2608 struct file *filep = NULL;
2609 struct statfs bufRet = {0};
2614 ret = fs_getfilep(fd, &filep);
2620 ret = statfs(filep->
f_path, &bufRet);
2638 if (sz !=
sizeof(
struct statfs)) {
2648int SysPpoll(
struct pollfd *fds, nfds_t nfds,
const struct timespec *tmo_p,
const sigset_t *sigMask,
int nsig)
2650 int timeout, retVal;
2654 CHECK_ASPACE(tmo_p,
sizeof(
struct timespec));
2655 CPY_FROM_USER(tmo_p);
2657 if (tmo_p != NULL) {
2658 timeout = tmo_p->tv_sec * OS_SYS_US_PER_MS + tmo_p->tv_nsec / OS_SYS_NS_PER_MS;
2666 if (sigMask != NULL) {
2676 retVal =
SysPoll(fds, nfds, timeout);
2682int SysPselect6(
int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
2683 const struct timespec *timeout,
const long data[2])
2690 CHECK_ASPACE(readfds,
sizeof(fd_set));
2691 CHECK_ASPACE(writefds,
sizeof(fd_set));
2692 CHECK_ASPACE(exceptfds,
sizeof(fd_set));
2693 CHECK_ASPACE(timeout,
sizeof(
struct timeval));
2695 CPY_FROM_USER(readfds);
2696 CPY_FROM_USER(writefds);
2697 CPY_FROM_USER(exceptfds);
2698 DUP_FROM_USER(timeout,
sizeof(
struct timeval));
2700 if (timeout != NULL) {
2701 ((
struct timeval *)timeout)->tv_usec = timeout->tv_nsec / 1000;
2714 ret =
do_select(nfds, readfds, writefds, exceptfds, (
struct timeval *)timeout,
UserPoll);
2723 CPY_TO_USER(readfds);
2724 CPY_TO_USER(writefds);
2725 CPY_TO_USER(exceptfds);
2771 if ((fd < 0) || (epfd < 0)) {
2784 return (ret == -1) ? -get_errno() : ret;
2800 ret =
epoll_wait(epfd, evs, maxevents, timeout);
2807 return (ret == -1) ? -get_errno() : ret;
2816 CHECK_ASPACE(mask,
sizeof(sigset_t));
2835 ret =
epoll_wait(epfd, evs, maxevents, timeout);
2844 return (ret == -1) ? -get_errno() : ret;
BOOL IsCapPermit(UINT32 capIndex)
int epoll_close(int epfd)
int epoll_wait(int epfd, FAR struct epoll_event *evs, int maxevents, int timeout)
int epoll_ctl(int epfd, int op, int fd, struct epoll_event *ev)
int epoll_create1(int flags)
int VfsFcntl(int fd, int cmd,...)
void SetCloexecFlag(int procFd)
int chattr(const char *pathname, struct IATTR *attr)
void ClearCloexecFlag(int procFd)
off64_t SysLseek64(int fd, int offsetHigh, int offsetLow, off64_t *result, int whence)
ssize_t SysWrite(int fd, const void *buf, size_t nbytes)
系统调用|写文件:将buf中(用户空间)nbytes长度的内容写到文件中
ssize_t SysReadlink(const char *pathname, char *buf, size_t bufsize)
int SysPoll(struct pollfd *fds, nfds_t nfds, int timeout)
SysPoll I/O多路转换
int SysRename(const char *oldpath, const char *newpath)
重命名文件
static int CheckNewAttrTime(struct IATTR *attr, struct timespec times[TIMESPEC_TIMES_NUM])
int SysRmdir(const char *pathname)
删除目录
int SysLstat(const char *path, struct kstat *buffer)
参见SysStat
int SysFallocate(int fd, int mode, off_t offset, off_t len)
int SysFsync(int fd)
把文件在内存中的部分写回磁盘
static int PollfdToSystem(struct pollfd *fds, nfds_t nfds, int **pollFdsBak)
int SysFstatfs64(int fd, size_t sz, struct statfs *buf)
static void RestorePollfd(struct pollfd *fds, nfds_t nfds, const int *pollFds)
int SysStat(const char *path, struct kstat *buf)
获取文件状态信息
int SysPselect6(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, const struct timespec *timeout, const long data[2])
int SysStatfs64(const char *path, size_t sz, struct statfs *buf)
获取文件系统信息
int SysTruncate(const char *path, off_t length)
系统调用|文件系统|截断功能
static int SelectParamCheckCopy(fd_set *readfds, fd_set *writefds, fd_set *exceptfds, fd_set **fdsBuf)
select()参数检查
int SysSymlinkat(const char *target, int dirfd, const char *linkpath)
int SysEpollCreate(int size)
int SysFchown(int fd, uid_t owner, gid_t group)
int SysLink(const char *oldpath, const char *newpath)
int SysEpollCreate1(int flags)
char * SysGetcwd(char *buf, size_t n)
int SysFaccessat(int fd, const char *filename, int amode, int flag)
int SysEpollWait(int epfd, struct epoll_event *evs, int maxevents, int timeout)
int SysIoctl(int fd, int req, void *arg)
I/O总控制函数
int SysFtruncate(int fd, off_t length)
系统调用|文件系统|截断功能
ssize_t SysReadlinkat(int dirfd, const char *pathname, char *buf, size_t bufsize)
int SysStatx(int fd, const char *restrict path, int flag, unsigned mask, struct statx *restrict stx)
ssize_t SysPwrite64(int fd, const void *buf, size_t nbytes, off64_t offset)
int SysDup2(int fd1, int fd2)
复制文件描述符
int SysFallocate64(int fd, int mode, off64_t offset, off64_t len)
int SysFstatfs(int fd, struct statfs *buf)
int SysStatfs(const char *path, struct statfs *buf)
获取指定路径下文件的文件系统信息
ssize_t SysReadv(int fd, const struct iovec *iov, int iovcnt)
通过FD读入数据到缓冲数组中,fd为进程描述符
int SysFcntl(int fd, int cmd, void *arg)
int SysOpen(const char *path, int oflags,...)
系统调用|打开文件, 正常情况下返回进程的FD值
ssize_t SysWritev(int fd, const struct iovec *iov, int iovcnt)
将缓冲数组里的数据写入文件
int SysFchmod(int fd, mode_t mode)
int SysChown(const char *pathname, uid_t owner, gid_t group)
static int NfsMount(const char *serverIpAndPath, const char *mountPath, unsigned int uid, unsigned int gid)
ssize_t SysSendFile(int outfd, int infd, off_t *offset, size_t count)
static int DoEpollCreate1(int flags)
int SysFchmodat(int fd, const char *path, mode_t mode, int flag)
int SysSelect(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout)
SysSelect 系统调用|文件系统|select .鸿蒙liteos目前也支持epoll方式
static int GetFullpathNull(int fd, const char *path, char **filePath)
获取全路径
int SysFstat64(int fd, struct kstat *buf)
void SysSync(void)
将内存缓冲区数据写回硬盘
int SysUtimensat(int fd, const char *path, struct timespec times[TIMESPEC_TIMES_NUM], int flag)
int SysSymlink(const char *target, const char *linkpath)
int SysExecve(const char *fileName, char *const *argv, char *const *envp)
动态加载程序过程
int SysUmount2(const char *target, int flags)
卸载文件系统
int SysRenameat(int oldfd, const char *oldpath, int newdfd, const char *newpath)
off_t SysLseek(int fd, off_t offset, int whence)
移动文件指针
int SysChmod(const char *pathname, mode_t mode)
int SysPpoll(struct pollfd *fds, nfds_t nfds, const struct timespec *tmo_p, const sigset_t *sigMask, int nsig)
char * SysRealpath(const char *path, char *resolved_path)
ssize_t SysPread64(int fd, void *buf, size_t nbytes, off64_t offset)
对进程进行特定操作
ssize_t SysPwritev(int fd, const struct iovec *iov, int iovcnt, long loffset, long hoffset)
int SysFtruncate64(int fd, off64_t length)
ssize_t SysRead(int fd, void *buf, size_t nbytes)
系统调用|读文件:从文件中读取nbytes长度的内容到buf中(用户空间)
static int UserIovCopy(struct iovec **iovBuf, const struct iovec *iov, const int iovcnt, int *valid_iovcnt)
int SysFstatat64(int dirfd, const char *restrict path, struct kstat *restrict buf, int flag)
int SysLinkat(int olddirfd, const char *oldpath, int newdirfd, const char *newpath, int flags)
int SysAccess(const char *path, int amode)
确定文件的可存取性
int SysUnlinkat(int dirfd, const char *pathname, int flag)
int SysUnlink(const char *pathname)
删除链:删除由装入点管理的文件
int SysCreat(const char *pathname, mode_t mode)
创建文件,从实现看 SysCreat 和 SysOpen 并没有太大的区别,只有打开方式的区别 SysCreat函数完全可以被SysOpen函数替代
int SysMkdirat(int dirfd, const char *pathname, mode_t mode)
int SysTruncate64(const char *path, off64_t length)
系统调用|文件系统|截断功能
int SysFstat(int fd, struct kstat *buf)
参见SysStat
int SysGetdents64(int fd, struct dirent *de_user, unsigned int count)
int SysEpollPwait(int epfd, struct epoll_event *evs, int maxevents, int timeout, const sigset_t *mask)
int SysUmount(const char *target)
卸载文件系统,当某个文件系统不需要再使用了,那么可以将它卸载掉。
int SysOpenat(int dirfd, const char *path, int oflags,...)
int SysFchownat(int fd, const char *path, uid_t owner, gid_t group, int flag)
int SysEpollCtl(int epfd, int op, int fd, struct epoll_event *ev)
int SysFormat(const char *dev, int sectors, int option)
static int UserPoll(struct pollfd *fds, nfds_t nfds, int timeout)
使用poll方式 实现IO多路复用的机制
int SysMkdir(const char *pathname, mode_t mode)
创建目录
int SysChdir(const char *path)
int SysFcntl64(int fd, int cmd, void *arg)
int SysMount(const char *source, const char *target, const char *filesystemtype, unsigned long mountflags, const void *data)
SysMount 挂载文件系统 挂载是指将一个存储设备挂接到一个已存在的路径上。我们要访问存储设备中的文件,必须将文件所在的分区挂载到一个已存在的路径上, 然后通过这个路径来访问存储设备。如果只有一个存...
int SysPrctl(int option,...)
对进程进行特定操作
static int UserIovItemCheck(const struct iovec *iov, const int iovcnt)
用户空间 io向量地址范围检查
ssize_t SysPreadv(int fd, const struct iovec *iov, int iovcnt, long loffset, long hoffset)
int SysPipe(int pipefd[2])
static int NfsMountRef(const char *serverIpAndPath, const char *mountPath, unsigned int uid, unsigned int gid) __attribute__((weakref("nfs_mount")))
int vfs_normalize_pathat(int dirfd, const char *filename, char **pathname)
VOID * LOS_MemAlloc(VOID *pool, UINT32 size)
从指定内存池中申请size长度的内存,注意这可不是从内核堆空间中申请内存
UINT32 LOS_MemFree(VOID *pool, VOID *ptr)
释放从指定动态内存中申请的内存
__attribute__((aligned(MMU_DESCRIPTOR_L1_SMALL_ENTRY_NUMBERS)))
INT32 LOS_DoExecveFile(const CHAR *fileName, CHAR *const *argv, CHAR *const *envp)
LOS_DoExecveFile 根据fileName执行一个新的用户程序 LOS_DoExecveFile接口一般由用户通过execve系列接口利用系统调用机制调用创建新的进程,内核不能直接调用该接口...
STATIC INLINE LosTaskCB * OsCurrTaskGet(VOID)
int OsSigprocMask(int how, const sigset_t_l *set, sigset_t_l *oldset)
int do_open(int dirfd, const char *path, int oflags, mode_t mode)
int do_mkdir(int dirfd, const char *pathname, mode_t mode)
int do_rename(int oldfd, const char *oldpath, int newfd, const char *newpath)
int do_unlink(int dirfd, const char *pathname)
int do_readdir(int fd, struct dirent **de, unsigned int count)
int do_rmdir(int dirfd, const char *pathname)
int do_select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout, PollFun poll)
int do_opendir(const char *path, int oflags)
LITE_OS_SEC_TEXT INT32 OsSetTaskName(LosTaskCB *taskCB, const CHAR *name, BOOL setPName)
STATIC INLINE BOOL LOS_IsUserAddressRange(VADDR_T vaddr, size_t len)
虚拟地址[vaddr,vaddr + len]是否在用户空间
STATIC INLINE BOOL LOS_IsUserAddress(VADDR_T vaddr)
虚拟地址是否在用户空间
void * malloc(size_t size)
动态分配内存块大小
void free(void *ptr)
释放ptr所指向的内存空间
off64_t _lseek64(int fd, int offsetHigh, int offsetLow, off64_t *result, int whence)
off_t _lseek(int fd, off_t offset, int whence)
INT32 LOS_StrncpyFromUser(CHAR *dst, const CHAR *src, INT32 count)
unsigned attr_chg_uid
用户ID
unsigned attr_chg_atime
节点最近访问时间
unsigned attr_chg_mode
确定了文件的类型,以及它的所有者、它的group、其它用户访问此文件的权限 (S_IWUSR | ...)
unsigned attr_chg_mtime
节点对应的文件内容被修改时间
unsigned int attr_chg_valid
节点改变有效性 (CHG_MODE | CHG_UID | ... )
unsigned long sig[MAX_SIG_ARRAY_IN_MUSL/sizeof(unsigned long)]
ARG_NUM_3 ARG_NUM_1 ARG_NUM_2 ARG_NUM_2 ARG_NUM_3 ARG_NUM_1 ARG_NUM_4 ARG_NUM_2 ARG_NUM_2 ARG_NUM_5 ARG_NUM_2 ARG_NUM_0 ARG_NUM_2 ARG_NUM_1 ARG_NUM_2 ARG_NUM_3 ARG_NUM_7 ARG_NUM_2 ARG_NUM_3 ARG_NUM_2 ARG_NUM_4 ARG_NUM_5 ARG_NUM_6 ARG_NUM_3 ARG_NUM_5 ARG_NUM_7 ARG_NUM_1 ARG_NUM_4 ARG_NUM_5 ARG_NUM_4 ARG_NUM_7 ARG_NUM_2 ARG_NUM_3 ARG_NUM_7 ARG_NUM_7 ARG_NUM_3 ARG_NUM_3 ARG_NUM_3 ARG_NUM_7 ARG_NUM_3 ARG_NUM_2 char ARG_NUM_2 ARG_NUM_1 ARG_NUM_0 ARG_NUM_0 ARG_NUM_3 void ARG_NUM_1 ARG_NUM_0 unsigned ARG_NUM_0 ARG_NUM_2 ARG_NUM_3 ARG_NUM_2 ARG_NUM_5 ARG_NUM_3 ARG_NUM_3 ARG_NUM_4 ARG_NUM_1 ARG_NUM_1 ARG_NUM_3 ARG_NUM_2 ARG_NUM_1 ARG_NUM_4 ARG_NUM_4 ARG_NUM_5 ARG_NUM_3 ARG_NUM_2 void ARG_NUM_6 unsigned ARG_NUM_0 unsigned ARG_NUM_0 ARG_NUM_3 ARG_NUM_3 ARG_NUM_2 ARG_NUM_2 ARG_NUM_1 ARG_NUM_2 ARG_NUM_1 char ARG_NUM_0 ARG_NUM_4 ARG_NUM_1 ARG_NUM_2 ARG_NUM_2 ARG_NUM_4 ARG_NUM_5 ARG_NUM_2 ARG_NUM_3 ARG_NUM_3 ARG_NUM_3 ARG_NUM_3 ARG_NUM_6 ARG_NUM_6 ARG_NUM_5 ARG_NUM_3 void ARG_NUM_3 ARG_NUM_3 ARG_NUM_5 ARG_NUM_1 unsigned ARG_NUM_3 long
ARG_NUM_3 ARG_NUM_1 ARG_NUM_2 ARG_NUM_2 ARG_NUM_3 ARG_NUM_1 ARG_NUM_4 ARG_NUM_2 ARG_NUM_2 ARG_NUM_5 ARG_NUM_2 void
ARG_NUM_3 ARG_NUM_1 ARG_NUM_2 ARG_NUM_2 ARG_NUM_3 ARG_NUM_1 ARG_NUM_4 ARG_NUM_2 ARG_NUM_2 ARG_NUM_5 ARG_NUM_2 ARG_NUM_0 ARG_NUM_2 ARG_NUM_1 ARG_NUM_2 ARG_NUM_3 ARG_NUM_7 ARG_NUM_2 ARG_NUM_3 ARG_NUM_2 ARG_NUM_4 off64_t
ARG_NUM_3 ARG_NUM_1 ARG_NUM_2 ARG_NUM_2 ARG_NUM_3 ARG_NUM_1 ARG_NUM_4 ARG_NUM_2 ARG_NUM_2 ARG_NUM_5 ARG_NUM_2 ARG_NUM_0 ARG_NUM_2 ARG_NUM_1 ARG_NUM_2 ARG_NUM_3 ARG_NUM_7 ARG_NUM_2 ARG_NUM_3 ARG_NUM_2 ARG_NUM_4 ARG_NUM_5 ARG_NUM_6 ARG_NUM_3 ARG_NUM_5 ARG_NUM_7 ARG_NUM_1 ARG_NUM_4 ARG_NUM_5 ARG_NUM_4 ARG_NUM_7 ARG_NUM_2 ARG_NUM_3 ARG_NUM_7 ARG_NUM_7 ARG_NUM_3 ARG_NUM_3 ARG_NUM_3 ARG_NUM_7 ARG_NUM_3 ARG_NUM_2 char ARG_NUM_2 ARG_NUM_1 ARG_NUM_0 ARG_NUM_0 ARG_NUM_3 void ARG_NUM_1 ARG_NUM_0 unsigned ARG_NUM_0 ARG_NUM_2 ARG_NUM_3 ARG_NUM_2 ARG_NUM_5 ARG_NUM_3 ARG_NUM_3 ARG_NUM_4 ARG_NUM_1 ARG_NUM_1 ARG_NUM_3 ARG_NUM_2 mode_t
int GetFullpath(int fd, const char *path, char **fullpath)
int UserPathCopy(const char *userPath, char **pathBuf)
clock_t times(struct tms *buf)
int clock_gettime(clockid_t clockID, struct timespec *tp)
当用户程序进行特定系统调用时(例如clock_gettime(CLOCK_REALTIME_COARSE, &ts)),VDSO代码页会将其拦截;
size_t LOS_ArchCopyToUser(void *dst, const void *src, size_t len)
从内核空间拷贝到用户空间
size_t LOS_ArchCopyFromUser(void *dst, const void *src, size_t len)
int VfsPermissionCheck(uint fuid, uint fgid, mode_t fileMode, int accMode)
int fallocate64(int fd, int mode, off64_t offset, off64_t len)
int fallocate(int fd, int mode, off_t offset, off_t len)
char * realpath(const char *path, char *resolved_path)
int chdir(const char *path)
int fstat64(int fd, struct stat64 *buf)
char * getcwd(char *buf, size_t n)
int chown(const char *pathname, uid_t owner, gid_t group)
int access(const char *path, int amode)
int chmod(const char *path, mode_t mode)
ssize_t preadv(int fd, const struct iovec *iov, int iovcnt, off_t offset)
int AllocAndAssocProcessFd(int sysFd, int minFd)
分配和绑定进程描述符
int CheckProcessFd(int procFd)
void AssociateSystemFd(int procFd, int sysFd)
参数进程FD和参数系统FD进行绑定(关联)
void FreeProcessFd(int procFd)
释放进程文件描述符
int DisassociateProcessFd(int procFd)
解绑系统文件描述符,返回系统文件描述符
int AllocProcessFd(void)
分配文件描述符
int AllocSpecifiedProcessFd(int procFd)
int GetAssociatedSystemFd(int procFd)
获取绑定的系统描述符
ssize_t pwritev(int fd, const struct iovec *iov, int iovcnt, off_t offset)
ssize_t vfs_readv(int fd, const struct iovec *iov, int iovcnt, off_t *offset)
供系统调用
ssize_t writev(int fd, const struct iovec *iov, int iovcnt)