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

Function dfs_file_readlink

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

* @brief Read the contents of a symbolic link * * This function reads the contents of the symbolic link specified by path into * the buffer provided. * * @param[in] path The path to the symbolic link to be read * @param[out] buf Buffer to store the link contents * @param[in] bufsize Size of the buffer in bytes * * @return int Number of bytes placed in buffer on success, or negative error

Source from the content-addressed store, hash-verified

2032 * -RT_ERROR for general errors
2033 */
2034int dfs_file_readlink(const char *path, char *buf, int bufsize)
2035{
2036 int ret = -RT_ERROR;
2037 char *fullpath = RT_NULL;
2038 struct dfs_mnt *mnt = RT_NULL;
2039 struct dfs_dentry *dentry = RT_NULL;
2040
2041 fullpath = dfs_normalize_path(NULL, path);
2042 if (fullpath)
2043 {
2044 DLOG(msg, "dfs_file", "mnt", DLOG_MSG, "dfs_mnt_lookup(%s)", fullpath);
2045 mnt = dfs_mnt_lookup(fullpath);
2046 if (mnt)
2047 {
2048 char *tmp = dfs_file_realpath(&mnt, fullpath, DFS_REALPATH_EXCEPT_LAST);
2049 if (tmp)
2050 {
2051 rt_free(fullpath);
2052 fullpath = tmp;
2053 }
2054
2055 DLOG(msg, "dfs_file", "dentry", DLOG_MSG, "dfs_dentry_lookup(mnt, %s)", fullpath);
2056 dentry = dfs_dentry_lookup(mnt, fullpath, 0);
2057 if (dentry)
2058 {
2059 if (mnt->fs_ops->readlink)
2060 {
2061 if (dfs_is_mounted(mnt) == 0)
2062 {
2063 ret = mnt->fs_ops->readlink(dentry, buf, bufsize);
2064 }
2065 }
2066 else
2067 {
2068 ret = -ENOSYS;
2069 }
2070
2071 /* release this dentry */
2072 dfs_dentry_unref(dentry);
2073 }
2074 else
2075 {
2076 /* no this entry */
2077 ret = -ENOENT;
2078 }
2079 }
2080 else
2081 {
2082 ret = -ENOENT;
2083 }
2084
2085 /* release fullpath */
2086 rt_free(fullpath);
2087 }
2088 else
2089 {
2090 ret = -ENOMEM;
2091 }

Callers 3

sys_readlinkFunction · 0.85
utimensatFunction · 0.85
lsFunction · 0.85

Calls 7

dfs_mnt_lookupFunction · 0.85
dfs_file_realpathFunction · 0.85
rt_freeFunction · 0.85
dfs_dentry_lookupFunction · 0.85
dfs_is_mountedFunction · 0.85
dfs_dentry_unrefFunction · 0.85
dfs_normalize_pathFunction · 0.70

Tested by

no test coverage detected