* @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
| 2032 | * -RT_ERROR for general errors |
| 2033 | */ |
| 2034 | int 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 | } |
no test coverage detected