mirror of
https://gitlab.rtems.org/rtems/rtos/rtems.git
synced 2025-11-16 12:34:45 +00:00
fs: Add struct dirent::d_type support
This commit is contained in:
@@ -236,6 +236,17 @@ msdos_dir_read(rtems_libio_t *iop, void *buffer, size_t count)
|
||||
continue;
|
||||
}
|
||||
|
||||
#ifdef DT_DIR
|
||||
if ((*MSDOS_DIR_ATTR(entry)) & MSDOS_ATTR_DIRECTORY)
|
||||
{
|
||||
tmp_dirent.d_type = DT_DIR;
|
||||
}
|
||||
else
|
||||
{
|
||||
tmp_dirent.d_type = DT_REG;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Move the entry to the return buffer
|
||||
*
|
||||
|
||||
@@ -74,6 +74,9 @@ static ssize_t IMFS_dir_read(
|
||||
dir_ent->d_off = current_entry;
|
||||
dir_ent->d_reclen = sizeof( *dir_ent );
|
||||
dir_ent->d_ino = IMFS_node_to_ino( imfs_node );
|
||||
#ifdef DT_DIR
|
||||
dir_ent->d_type = IFTODT( imfs_node->st_mode );
|
||||
#endif
|
||||
dir_ent->d_namlen =
|
||||
MIN( imfs_node->namelen, sizeof( dir_ent->d_name ) - 1 );
|
||||
dir_ent->d_name[ dir_ent->d_namlen ] = '\0';
|
||||
|
||||
@@ -3,12 +3,17 @@
|
||||
|
||||
#include <linux/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/dirent.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
#ifdef DT_DIR
|
||||
#define RTEMS_JFFS2_HAVE_D_TYPE
|
||||
#else
|
||||
#define DT_UNKNOWN 0
|
||||
#define DT_DIR 4
|
||||
#define DT_REG 8
|
||||
#define DT_LNK 10
|
||||
#endif
|
||||
|
||||
#define ATTR_MODE (1U << 0)
|
||||
#define ATTR_UID (1U << 1)
|
||||
|
||||
@@ -423,7 +423,7 @@ static int rtems_jffs2_fstat(
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int rtems_jffs2_fill_dirent(struct dirent *de, off_t off, uint32_t ino, const char *name)
|
||||
static int rtems_jffs2_fill_dirent(struct dirent *de, off_t off, uint32_t ino, const char *name, unsigned char type)
|
||||
{
|
||||
int eno = 0;
|
||||
size_t len;
|
||||
@@ -433,6 +433,9 @@ static int rtems_jffs2_fill_dirent(struct dirent *de, off_t off, uint32_t ino, c
|
||||
de->d_off = off * sizeof(*de);
|
||||
de->d_reclen = sizeof(*de);
|
||||
de->d_ino = ino;
|
||||
#ifdef RTEMS_JFFS2_HAVE_D_TYPE
|
||||
de->d_type = type;
|
||||
#endif
|
||||
|
||||
len = strlen(name);
|
||||
de->d_namlen = len;
|
||||
@@ -466,14 +469,14 @@ static ssize_t rtems_jffs2_dir_read(rtems_libio_t *iop, void *buf, size_t len)
|
||||
off = begin;
|
||||
|
||||
if (off == 0 && off < end) {
|
||||
eno = rtems_jffs2_fill_dirent(de, off, inode->i_ino, ".");
|
||||
eno = rtems_jffs2_fill_dirent(de, off, inode->i_ino, ".", DT_DIR);
|
||||
assert(eno == 0);
|
||||
++off;
|
||||
++de;
|
||||
}
|
||||
|
||||
if (off == 1 && off < end) {
|
||||
eno = rtems_jffs2_fill_dirent(de, off, inode->i_parent->i_ino, "..");
|
||||
eno = rtems_jffs2_fill_dirent(de, off, inode->i_parent->i_ino, "..", DT_DIR);
|
||||
assert(eno == 0);
|
||||
++off;
|
||||
++de;
|
||||
@@ -482,7 +485,7 @@ static ssize_t rtems_jffs2_dir_read(rtems_libio_t *iop, void *buf, size_t len)
|
||||
while (eno == 0 && off < end && fd != NULL) {
|
||||
if (fd->ino != 0) {
|
||||
if (off == fd_off) {
|
||||
eno = rtems_jffs2_fill_dirent(de, off, fd->ino, fd->name);
|
||||
eno = rtems_jffs2_fill_dirent(de, off, fd->ino, fd->name, fd->type);
|
||||
++off;
|
||||
++de;
|
||||
}
|
||||
|
||||
@@ -327,6 +327,9 @@ nfscookie *pcookie;
|
||||
pde->d_ino = fileid;
|
||||
pde->d_namlen = nlen;
|
||||
pde->d_off = di->ptr - di->buf;
|
||||
#ifdef DT_UNKNOWN
|
||||
pde->d_type = DT_UNKNOWN;
|
||||
#endif
|
||||
if (name == dummy.nambuf) {
|
||||
memcpy(pde->d_name, dummy.nambuf, nlen + 1);
|
||||
}
|
||||
|
||||
@@ -8,47 +8,82 @@
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <sys/stat.h>
|
||||
#include <dirent.h>
|
||||
#include <fcntl.h>
|
||||
#include <limits.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <tmacros.h>
|
||||
|
||||
#include "fstest.h"
|
||||
#include "fs_config.h"
|
||||
#include "fstest_support.h"
|
||||
#include "pmacros.h"
|
||||
|
||||
#include <dirent.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include <limits.h>
|
||||
|
||||
const char rtems_test_name[] = "FSSCANDIR " FILESYSTEM;
|
||||
|
||||
/*
|
||||
* This code is from the scandir() man page.
|
||||
*/
|
||||
static void test_scandir(void)
|
||||
#define FILE_NAME "aaa"
|
||||
|
||||
#define DIR_NAME "bbb"
|
||||
|
||||
void test(void)
|
||||
{
|
||||
struct dirent **namelist;
|
||||
struct dirent *d;
|
||||
int rv;
|
||||
int n;
|
||||
|
||||
n = scandir(".", &namelist, 0, NULL);
|
||||
if (n < 0) {
|
||||
perror("scandir");
|
||||
} else {
|
||||
while(n--) {
|
||||
printf("%s\n", namelist[n]->d_name);
|
||||
free(namelist[n]);
|
||||
}
|
||||
free(namelist);
|
||||
}
|
||||
int i;
|
||||
|
||||
rtems_test_assert(MAXNAMLEN == NAME_MAX);
|
||||
}
|
||||
|
||||
rv = mknod(FILE_NAME, S_IFREG | S_IRWXU | S_IRWXG | S_IRWXO, 0);
|
||||
rtems_test_assert(rv == 0);
|
||||
|
||||
void test (void)
|
||||
{
|
||||
test_scandir();
|
||||
rv = mkdir(DIR_NAME, S_IRWXU | S_IRWXG | S_IRWXO );
|
||||
rtems_test_assert(rv == 0);
|
||||
|
||||
n = scandir(".", &namelist, NULL, alphasort);
|
||||
rtems_test_assert(2 <= n || n == 4);
|
||||
|
||||
i = 0;
|
||||
d = namelist[i];
|
||||
|
||||
if (n >= 3) {
|
||||
rtems_test_assert(strcmp(d->d_name, ".") == 0);
|
||||
#ifdef DT_UNKNOWN
|
||||
rtems_test_assert(d->d_type == DT_DIR || d->d_type == DT_UNKNOWN);
|
||||
#endif
|
||||
free(d);
|
||||
++i;
|
||||
d = namelist[i];
|
||||
}
|
||||
|
||||
if (n == 4) {
|
||||
rtems_test_assert(strcmp(d->d_name, "..") == 0);
|
||||
#ifdef DT_UNKNOWN
|
||||
rtems_test_assert(d->d_type == DT_DIR || d->d_type == DT_UNKNOWN);
|
||||
#endif
|
||||
free(d);
|
||||
++i;
|
||||
d = namelist[i];
|
||||
}
|
||||
|
||||
rtems_test_assert(strcmp(d->d_name, FILE_NAME) == 0);
|
||||
#ifdef DT_UNKNOWN
|
||||
rtems_test_assert(d->d_type == DT_REG || d->d_type == DT_UNKNOWN);
|
||||
#endif
|
||||
free(d);
|
||||
++i;
|
||||
d = namelist[i];
|
||||
|
||||
rtems_test_assert(strcmp(d->d_name, DIR_NAME) == 0);
|
||||
#ifdef DT_UNKNOWN
|
||||
rtems_test_assert(d->d_type == DT_DIR || d->d_type == DT_UNKNOWN);
|
||||
#endif
|
||||
free(d);
|
||||
|
||||
free(namelist);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user