Add d_namlen, d_dev, and d_type to struct dirent.

This commit is contained in:
Jonas 'Sortie' Termansen 2014-01-03 22:20:52 +01:00
parent 5dd70aa4ff
commit da933464e5
7 changed files with 218 additions and 31 deletions

View File

@ -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 <http://www.gnu.org/licenses/>.
sortix/__/dirent.h
Format of directory entries.
*******************************************************************************/
#ifndef INCLUDE_SORTIX____DIRENT_H
#define INCLUDE_SORTIX____DIRENT_H
#include <sys/cdefs.h>
#include <sortix/__/dt.h>
#include <sortix/__/stat.h>
__BEGIN_DECLS
#define __IFTODT(mode) (((mode) & __S_IFMT) >> __S_IFMT_SHIFT)
#define __DTTOIF(dirtype) ((dirtype) << __S_IFMT_SHIFT)
__END_DECLS
#endif

View File

@ -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 <http://www.gnu.org/licenses/>.
sortix/__/dt.h
Defines the values for the d_type field.
*******************************************************************************/
#ifndef INCLUDE_SORTIX____DT_H
#define INCLUDE_SORTIX____DT_H
#include <sys/cdefs.h>
__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

View File

@ -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 <http://www.gnu.org/licenses/>.
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 <sys/cdefs.h>
#include <sortix/__/dt.h>
__BEGIN_DECLS
#define __S_IFMT_SHIFT 12
#define __S_IFMT_MASK __DT_BITS
__END_DECLS
#endif

View File

@ -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 <sys/cdefs.h>
#include <sys/__/types.h>
#include <stdint.h>
#include <sortix/__/dirent.h>
#include <sortix/__/dt.h>
__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 <stddef.h>
#endif
#ifndef NULL
#define __need_NULL
#include <stddef.h>
#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
{

View File

@ -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 <sys/cdefs.h>
#include <sys/types.h>
#include <sortix/__/dirent.h>
#include <sortix/__/dt.h>
#include <sortix/__/stat.h>
#include <sortix/timespec.h>
__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

View File

@ -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);

View File

@ -29,8 +29,15 @@
#include <sys/__/types.h>
#include <sortix/__/dirent.h>
__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**);