Abhishekmishra2808 commented on code in PR #19166:
URL: https://github.com/apache/nuttx/pull/19166#discussion_r3446824935
##########
fs/littlefs/lfs_vfs.c:
##########
@@ -337,6 +341,192 @@ static FAR const char *littlefs_convert_path(FAR const
char *path)
return path;
}
+#if defined(CONFIG_FS_PERMISSION) && defined(CONFIG_FS_LITTLEFS_ATTR_UPDATE)
+
+/****************************************************************************
+ * Name: littlefs_statbuf_locked
+ ****************************************************************************/
+
+static int littlefs_statbuf_locked(FAR struct littlefs_mountpt_s *fs,
+ FAR const char *relpath,
+ FAR struct stat *buf)
+{
+ struct lfs_info info;
+ struct littlefs_attr_s attr;
+ int ret;
+
+ memset(buf, 0, sizeof(*buf));
+
+ ret = lfs_stat(&fs->lfs, relpath, &info);
+ if (ret < 0)
+ {
+ return littlefs_convert_result(ret);
+ }
+
+ ret = littlefs_convert_result(lfs_getattr(&fs->lfs, relpath, 0,
+ &attr, sizeof(attr)));
+ if (ret < 0)
+ {
+ if (ret != -ENODATA)
+ {
+ return ret;
+ }
+
+ memset(&attr, 0, sizeof(attr));
+ attr.at_mode = S_IRWXG | S_IRWXU | S_IRWXO;
+ }
+
+ buf->st_mode = attr.at_mode;
+ buf->st_uid = attr.at_uid;
+ buf->st_gid = attr.at_gid;
+ buf->st_atim.tv_sec = attr.at_atim / 1000000000ull;
+ buf->st_atim.tv_nsec = attr.at_atim % 1000000000ull;
+ buf->st_mtim.tv_sec = attr.at_mtim / 1000000000ull;
+ buf->st_mtim.tv_nsec = attr.at_mtim % 1000000000ull;
+ buf->st_ctim.tv_sec = attr.at_ctim / 1000000000ull;
+ buf->st_ctim.tv_nsec = attr.at_ctim % 1000000000ull;
+ buf->st_blksize = fs->cfg.block_size;
+
+ if (info.type == LFS_TYPE_REG)
+ {
+ buf->st_mode |= S_IFREG;
+ buf->st_size = info.size;
+ }
+ else
+ {
+ buf->st_mode |= S_IFDIR;
+ buf->st_size = 0;
+ }
+
+ buf->st_blocks = (buf->st_size + buf->st_blksize - 1) / buf->st_blksize;
+ return OK;
+}
+
+/****************************************************************************
+ * Name: littlefs_check_pathperm_locked
+ ****************************************************************************/
+
+static int littlefs_check_pathperm_locked(FAR struct littlefs_mountpt_s *fs,
+ FAR const char *relpath,
+ int final_amode)
+{
+ struct stat st;
+ char subpath[NAME_MAX + 1];
+ size_t len;
+ size_t begin = 0;
+ size_t end;
+ int ret;
+
+ len = strlen(relpath);
+ while (begin < len && relpath[begin] == '/')
+ {
+ begin++;
+ }
+
+ if (begin >= len)
+ {
+ return OK;
+ }
+
+ end = begin;
+ while (end <= len)
+ {
+ if (end < len && relpath[end] != '/')
+ {
+ end++;
+ continue;
+ }
+
+ if ((end - begin) > NAME_MAX)
+ {
+ return -ENAMETOOLONG;
+ }
+
+ memcpy(subpath, relpath + begin, end - begin);
+ subpath[end - begin] = '\0';
+
+ ret = littlefs_statbuf_locked(fs, subpath, &st);
+ if (ret < 0)
+ {
+ return ret;
+ }
+
+ ret = fs_checkmode(st.st_uid, st.st_gid, st.st_mode,
+ (relpath[end] == '\0') ? final_amode : X_OK);
+ if (ret < 0)
+ {
+ return ret;
+ }
+
+ if (relpath[end] == '\0')
+ {
+ break;
+ }
+
+ end++;
+ }
+
+ return OK;
+}
+
+/****************************************************************************
+ * Name: littlefs_check_openperm_locked
+ ****************************************************************************/
+
+static int littlefs_check_openperm_locked(FAR struct littlefs_mountpt_s *fs,
+ FAR const char *relpath,
+ int oflags)
+{
+ return littlefs_check_pathperm_locked(fs, relpath,
+ fs_open_amode(oflags));
+}
+
+/****************************************************************************
+ * Name: littlefs_check_parentperm_locked
+ ****************************************************************************/
+
+static int littlefs_check_parentperm_locked(
+ FAR struct littlefs_mountpt_s *fs,
+ FAR const char *relpath, int amode)
+{
+ FAR const char *slash;
+ char parent[NAME_MAX + 1];
Review Comment:
Done
##########
fs/littlefs/lfs_vfs.c:
##########
@@ -337,6 +341,192 @@ static FAR const char *littlefs_convert_path(FAR const
char *path)
return path;
}
+#if defined(CONFIG_FS_PERMISSION) && defined(CONFIG_FS_LITTLEFS_ATTR_UPDATE)
+
+/****************************************************************************
+ * Name: littlefs_statbuf_locked
+ ****************************************************************************/
+
+static int littlefs_statbuf_locked(FAR struct littlefs_mountpt_s *fs,
+ FAR const char *relpath,
+ FAR struct stat *buf)
+{
+ struct lfs_info info;
+ struct littlefs_attr_s attr;
+ int ret;
+
+ memset(buf, 0, sizeof(*buf));
+
+ ret = lfs_stat(&fs->lfs, relpath, &info);
+ if (ret < 0)
+ {
+ return littlefs_convert_result(ret);
+ }
+
+ ret = littlefs_convert_result(lfs_getattr(&fs->lfs, relpath, 0,
+ &attr, sizeof(attr)));
+ if (ret < 0)
+ {
+ if (ret != -ENODATA)
+ {
+ return ret;
+ }
+
+ memset(&attr, 0, sizeof(attr));
+ attr.at_mode = S_IRWXG | S_IRWXU | S_IRWXO;
+ }
+
+ buf->st_mode = attr.at_mode;
+ buf->st_uid = attr.at_uid;
+ buf->st_gid = attr.at_gid;
+ buf->st_atim.tv_sec = attr.at_atim / 1000000000ull;
+ buf->st_atim.tv_nsec = attr.at_atim % 1000000000ull;
+ buf->st_mtim.tv_sec = attr.at_mtim / 1000000000ull;
+ buf->st_mtim.tv_nsec = attr.at_mtim % 1000000000ull;
+ buf->st_ctim.tv_sec = attr.at_ctim / 1000000000ull;
+ buf->st_ctim.tv_nsec = attr.at_ctim % 1000000000ull;
+ buf->st_blksize = fs->cfg.block_size;
+
+ if (info.type == LFS_TYPE_REG)
+ {
+ buf->st_mode |= S_IFREG;
+ buf->st_size = info.size;
+ }
+ else
+ {
+ buf->st_mode |= S_IFDIR;
+ buf->st_size = 0;
+ }
+
+ buf->st_blocks = (buf->st_size + buf->st_blksize - 1) / buf->st_blksize;
+ return OK;
+}
+
+/****************************************************************************
+ * Name: littlefs_check_pathperm_locked
+ ****************************************************************************/
+
+static int littlefs_check_pathperm_locked(FAR struct littlefs_mountpt_s *fs,
+ FAR const char *relpath,
+ int final_amode)
+{
+ struct stat st;
+ char subpath[NAME_MAX + 1];
Review Comment:
Done
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]