From da933464e58abb5facde9fd40ede76e0ca9cf055 Mon Sep 17 00:00:00 2001 From: Jonas 'Sortie' Termansen Date: Fri, 3 Jan 2014 22:20:52 +0100 Subject: [PATCH] Add d_namlen, d_dev, and d_type to struct dirent. --- kernel/include/sortix/__/dirent.h | 40 +++++++++++++++++++++++++ kernel/include/sortix/__/dt.h | 44 +++++++++++++++++++++++++++ kernel/include/sortix/__/stat.h | 40 +++++++++++++++++++++++++ kernel/include/sortix/dirent.h | 49 +++++++++++++++++++++++++------ kernel/include/sortix/stat.h | 37 +++++++++++++---------- libc/dirent/fdopendir.cpp | 5 +++- libc/include/dirent.h | 34 +++++++++++++++++---- 7 files changed, 218 insertions(+), 31 deletions(-) create mode 100644 kernel/include/sortix/__/dirent.h create mode 100644 kernel/include/sortix/__/dt.h create mode 100644 kernel/include/sortix/__/stat.h diff --git a/kernel/include/sortix/__/dirent.h b/kernel/include/sortix/__/dirent.h new file mode 100644 index 00000000..7bfacd38 --- /dev/null +++ b/kernel/include/sortix/__/dirent.h @@ -0,0 +1,40 @@ +/******************************************************************************* + + Copyright(C) Jonas 'Sortie' Termansen 2012, 2013, 2014. + + This file is part of Sortix. + + Sortix is free software: you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation, either version 3 of the License, or (at your option) any later + version. + + Sortix is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + details. + + You should have received a copy of the GNU General Public License along with + Sortix. If not, see . + + sortix/__/dirent.h + Format of directory entries. + +*******************************************************************************/ + +#ifndef INCLUDE_SORTIX____DIRENT_H +#define INCLUDE_SORTIX____DIRENT_H + +#include + +#include +#include + +__BEGIN_DECLS + +#define __IFTODT(mode) (((mode) & __S_IFMT) >> __S_IFMT_SHIFT) +#define __DTTOIF(dirtype) ((dirtype) << __S_IFMT_SHIFT) + +__END_DECLS + +#endif diff --git a/kernel/include/sortix/__/dt.h b/kernel/include/sortix/__/dt.h new file mode 100644 index 00000000..65b8b706 --- /dev/null +++ b/kernel/include/sortix/__/dt.h @@ -0,0 +1,44 @@ +/******************************************************************************* + + Copyright(C) Jonas 'Sortie' Termansen 2012, 2013, 2014. + + This file is part of Sortix. + + Sortix is free software: you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation, either version 3 of the License, or (at your option) any later + version. + + Sortix is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + details. + + You should have received a copy of the GNU General Public License along with + Sortix. If not, see . + + sortix/__/dt.h + Defines the values for the d_type field. + +*******************************************************************************/ + +#ifndef INCLUDE_SORTIX____DT_H +#define INCLUDE_SORTIX____DT_H + +#include + +__BEGIN_DECLS + +#define __DT_UNKNOWN 0x0 +#define __DT_FIFO 0x1 +#define __DT_CHR 0x2 +#define __DT_DIR 0x4 +#define __DT_BLK 0x6 +#define __DT_REG 0x8 +#define __DT_LNK 0xA +#define __DT_SOCK 0xC +#define __DT_BITS 0xF + +__END_DECLS + +#endif diff --git a/kernel/include/sortix/__/stat.h b/kernel/include/sortix/__/stat.h new file mode 100644 index 00000000..8ba4c970 --- /dev/null +++ b/kernel/include/sortix/__/stat.h @@ -0,0 +1,40 @@ +/******************************************************************************* + + Copyright(C) Jonas 'Sortie' Termansen 2012, 2013, 2014. + + This file is part of Sortix. + + Sortix is free software: you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation, either version 3 of the License, or (at your option) any later + version. + + Sortix is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + details. + + You should have received a copy of the GNU General Public License along with + Sortix. If not, see . + + sortix/__/stat.h + Defines the struct stat used for file meta-information and other useful + macros and values relating to values stored in it. + +*******************************************************************************/ + +#ifndef INCLUDE_SORTIX____STAT_H +#define INCLUDE_SORTIX____STAT_H + +#include + +#include + +__BEGIN_DECLS + +#define __S_IFMT_SHIFT 12 +#define __S_IFMT_MASK __DT_BITS + +__END_DECLS + +#endif diff --git a/kernel/include/sortix/dirent.h b/kernel/include/sortix/dirent.h index cd7241b2..0e9dbed9 100644 --- a/kernel/include/sortix/dirent.h +++ b/kernel/include/sortix/dirent.h @@ -1,6 +1,6 @@ /******************************************************************************* - Copyright(C) Jonas 'Sortie' Termansen 2012. + Copyright(C) Jonas 'Sortie' Termansen 2012, 2014. This file is part of Sortix. @@ -27,16 +27,47 @@ #include +#include + +#include + +#include +#include + __BEGIN_DECLS -#define DT_UNKNOWN 0 -#define DT_BLK 1 -#define DT_CHR 2 -#define DT_DIR 3 -#define DT_FIFO 4 -#define DT_LNK 5 -#define DT_REG 6 -#define DT_SOCK 7 +#ifndef __dev_t_defined +#define __dev_t_defined +typedef __dev_t dev_t; +#endif + +#ifndef __ino_t_defined +#define __ino_t_defined +typedef __ino_t ino_t; +#endif + +#ifndef __size_t_defined +#define __size_t_defined +#define __need_size_t +#include +#endif + +#ifndef NULL +#define __need_NULL +#include +#endif + +#define DT_UNKNOWN __DT_UNKNOWN +#define DT_BLK __DT_BLK +#define DT_CHR __DT_CHR +#define DT_DIR __DT_DIR +#define DT_FIFO __DT_FIFO +#define DT_LNK __DT_LNK +#define DT_REG __DT_REG +#define DT_SOCK __DT_SOCK + +#define IFTODT(x) __IFTODT(x) +#define DTTOIF(x) __DTTOIF(x) struct kernel_dirent { diff --git a/kernel/include/sortix/stat.h b/kernel/include/sortix/stat.h index e133c041..7f3a753b 100644 --- a/kernel/include/sortix/stat.h +++ b/kernel/include/sortix/stat.h @@ -1,6 +1,6 @@ /******************************************************************************* - Copyright(C) Jonas 'Sortie' Termansen 2012, 2013. + Copyright(C) Jonas 'Sortie' Termansen 2012, 2013, 2014. This file is part of Sortix. @@ -29,6 +29,11 @@ #include #include + +#include +#include +#include + #include __BEGIN_DECLS @@ -62,26 +67,26 @@ struct stat #define S_IWUSR 0200 #define S_IRUSR 0400 #define S_IRWXU 0700 -#define S_IFMT 0xF000 -#define S_IFSOCK 0xC000 -#define S_IFLNK 0xA000 -#define S_IFREG 0x8000 -#define S_IFBLK 0x6000 -#define S_IFDIR 0x4000 -#define S_IFCHR 0x2000 -#define S_IFIFO 0x1000 +#define S_IFMT __DTTOIF(__DT_BITS) +#define S_IFSOCK __DTTOIF(__DT_SOCK) +#define S_IFLNK __DTTOIF(__DT_LNK) +#define S_IFREG __DTTOIF(__DT_REG) +#define S_IFBLK __DTTOIF(__DT_BLK) +#define S_IFDIR __DTTOIF(__DT_DIR) +#define S_IFCHR __DTTOIF(__DT_CHR) +#define S_IFIFO __DTTOIF(__DT_FIFO) /* Intentionally not part of Sortix. */ /*#define S_ISUID 0x0800 */ /*#define S_ISGID 0x0400 */ #define S_ISVTX 0x0200 #define S_SETABLE (0777 | 0x0200 | 0x0400 | 0x0800) -#define S_ISSOCK(mode) ((mode & S_IFMT) == S_IFSOCK) -#define S_ISLNK(mode) ((mode & S_IFMT) == S_IFLNK) -#define S_ISREG(mode) ((mode & S_IFMT) == S_IFREG) -#define S_ISBLK(mode) ((mode & S_IFMT) == S_IFBLK) -#define S_ISDIR(mode) ((mode & S_IFMT) == S_IFDIR) -#define S_ISCHR(mode) ((mode & S_IFMT) == S_IFCHR) -#define S_ISFIFO(mode) ((mode & S_IFMT) == S_IFIFO) +#define S_ISSOCK(mode) (((mode) & S_IFMT) == S_IFSOCK) +#define S_ISLNK(mode) (((mode) & S_IFMT) == S_IFLNK) +#define S_ISREG(mode) (((mode) & S_IFMT) == S_IFREG) +#define S_ISBLK(mode) (((mode) & S_IFMT) == S_IFBLK) +#define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR) +#define S_ISCHR(mode) (((mode) & S_IFMT) == S_IFCHR) +#define S_ISFIFO(mode) (((mode) & S_IFMT) == S_IFIFO) __END_DECLS diff --git a/libc/dirent/fdopendir.cpp b/libc/dirent/fdopendir.cpp index c5fc1fe4..28e66d7b 100644 --- a/libc/dirent/fdopendir.cpp +++ b/libc/dirent/fdopendir.cpp @@ -89,8 +89,11 @@ static int fddir_sortix_read(void* user, struct dirent* dirent, size_t* size) if ( provided < needed ) return 1; - dirent->d_ino = info->current->d_ino; dirent->d_reclen = needed; + dirent->d_namlen = info->current->d_namlen; + dirent->d_ino = info->current->d_ino; + dirent->d_dev = info->current->d_dev; + dirent->d_type = info->current->d_type; strcpy(dirent->d_name, info->current->d_name); info->current = kernel_dirent_next(info->current); diff --git a/libc/include/dirent.h b/libc/include/dirent.h index 87b40747..8dd44ddc 100644 --- a/libc/include/dirent.h +++ b/libc/include/dirent.h @@ -29,8 +29,15 @@ #include +#include + __BEGIN_DECLS +#ifndef __dev_t_defined +#define __dev_t_defined +typedef __dev_t dev_t; +#endif + #ifndef __ino_t_defined #define __ino_t_defined typedef __ino_t ino_t; @@ -47,19 +54,36 @@ typedef __ino_t ino_t; typedef struct DIR DIR; #endif +#define DT_UNKNOWN __DT_UNKNOWN +#define DT_BLK __DT_BLK +#define DT_CHR __DT_CHR +#define DT_DIR __DT_DIR +#define DT_FIFO __DT_FIFO +#define DT_LNK __DT_LNK +#define DT_REG __DT_REG +#define DT_SOCK __DT_SOCK + +#define IFTODT(x) __IFTODT(x) +#define DTTOIF(x) __DTTOIF(x) + struct dirent { - ino_t d_ino; size_t d_reclen; + size_t d_namlen; + ino_t d_ino; + dev_t d_dev; + unsigned char d_type; char d_name[0]; }; -#undef _DIRENT_HAVE_D_NAMLEN #define _DIRENT_HAVE_D_RECLEN -#define _DIRENT_HAVE_D_OFF -#undef _DIRENT_HAVE_D_TYPE +#define _DIRENT_HAVE_D_NAMLEN +#undef _DIRENT_HAVE_D_OFF +#define _DIRENT_HAVE_D_INO +#define _DIRENT_HAVE_D_DEV +#define _DIRENT_HAVE_D_TYPE -#define _D_EXACT_NAMLEN(d) ((d)->d_reclen - __builtin_offsetof(struct dirent, d_name) - 1) +#define _D_EXACT_NAMLEN(d) ((d)->d_namlen) #define _D_ALLOC_NAMLEN(d) (_D_EXACT_NAMLEN(d) + 1) int alphasort(const struct dirent**, const struct dirent**);