It is accomplished ...
git-svn-id: file:///srv/svn/repos/haiku/trunk/current@10 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -0,0 +1,246 @@
|
||||
/* OS.h
|
||||
*
|
||||
* Quake with fear - it's back!!!
|
||||
*/
|
||||
|
||||
#ifndef _OS_H
|
||||
#define _OS_H
|
||||
|
||||
/**
|
||||
* @mainpage OpenBeOS Header Documentation
|
||||
*
|
||||
* @section Introduction
|
||||
* This is the header documentation as produced with doxygen. Anyone can
|
||||
* produce this using the doxygen tool and doing this
|
||||
* <pre>
|
||||
* cd docs
|
||||
* doxygen doxygen.conf
|
||||
* </pre>
|
||||
* The resulting files will be produced in dox/html.
|
||||
*
|
||||
* @section Updating
|
||||
* I will attempt to keep these up to date, but if they're not, just
|
||||
* give me a nudge!
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file kernel/OS.h
|
||||
* @brief Definitions, prototypes needed throughout the OS
|
||||
*/
|
||||
|
||||
/**
|
||||
* @defgroup OpenBeOS_Headers OpenBeOS System Headers
|
||||
* @brief Headers that are available for applications
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <ktypes.h>
|
||||
|
||||
#define B_OS_NAME_LENGTH 32
|
||||
|
||||
/**
|
||||
* @defgroup Areas Memory Areas
|
||||
* @ingroup OpenBeOS_Headers
|
||||
* @{
|
||||
*/
|
||||
|
||||
/* temporary hacks */
|
||||
typedef int32 team_id;
|
||||
typedef int32 area_id;
|
||||
|
||||
/* Areas */
|
||||
typedef struct area_info {
|
||||
area_id area;
|
||||
char name[B_OS_NAME_LENGTH];
|
||||
int foo;
|
||||
size_t size;
|
||||
uint32 lock;
|
||||
uint32 protection;
|
||||
team_id team;
|
||||
uint32 ram_size;
|
||||
uint32 copy_count;
|
||||
uint32 in_count;
|
||||
uint32 out_count;
|
||||
void *address;
|
||||
} area_info;
|
||||
|
||||
#define get_area_info(id, ainfo) \
|
||||
_get_area_info((id), (ainfo),sizeof(*(ainfo)))
|
||||
#define get_next_area_info(team, cookie, ainfo) \
|
||||
_get_next_area_info((team), (cookie), (ainfo), sizeof(*(ainfo)))
|
||||
|
||||
/** @} */
|
||||
|
||||
/**
|
||||
* @defgroup Ports Messaging Ports
|
||||
* @ingroup OpenBeOS_Headers
|
||||
* @{
|
||||
*/
|
||||
|
||||
/* Ports */
|
||||
typedef struct port_info {
|
||||
port_id port;
|
||||
team_id team;
|
||||
char name[B_OS_NAME_LENGTH];
|
||||
int32 capacity; /* queue depth */
|
||||
int32 queue_count; /* # msgs waiting to be read */
|
||||
int32 total_count; /* total # msgs read so far */
|
||||
} port_info;
|
||||
|
||||
port_id create_port(int32, const char *);
|
||||
port_id find_port(const char *);
|
||||
int read_port(port_id, int32 *, void *, size_t);
|
||||
int read_port_etc(port_id, int32 *, void *, size_t, uint32, bigtime_t);
|
||||
int write_port(port_id, int32, const void *, size_t);
|
||||
int write_port_etc(port_id, int32, const void *, size_t, uint32, bigtime_t);
|
||||
int close_port(port_id port);
|
||||
int delete_port(port_id port);
|
||||
|
||||
ssize_t port_buffer_size(port_id);
|
||||
ssize_t port_buffer_size_etc(port_id, uint32, bigtime_t);
|
||||
ssize_t port_count(port_id);
|
||||
int set_port_owner(port_id, team_id);
|
||||
|
||||
int _get_port_info(port_id, port_info *, size_t);
|
||||
int _get_next_port_info(team_id, int32 *, port_info *, size_t);
|
||||
|
||||
#define get_port_info(port, info) \
|
||||
_get_port_info((port), (info), sizeof(*(info)))
|
||||
|
||||
#define get_next_port_info(team, cookie, info) \
|
||||
_get_next_port_info((team), (cookie), (info), sizeof(*(info)))
|
||||
|
||||
/** @} */
|
||||
|
||||
/**
|
||||
* @defgroup Sems Semaphores
|
||||
* @ingroup OpenBeOS_Headers
|
||||
* @{
|
||||
*/
|
||||
|
||||
#define B_CAN_INTERRUPT 1
|
||||
#define B_DO_NOT_RESCHEDULE 2
|
||||
#define B_CHECK_PERMISSION 4
|
||||
#define B_TIMEOUT 8
|
||||
#define B_RELATIVE_TIMEOUT 8
|
||||
#define B_ABSOLUTE_TIMEOUT 16
|
||||
|
||||
typedef struct sem_info {
|
||||
sem_id sem;
|
||||
proc_id proc;
|
||||
char name[B_OS_NAME_LENGTH];
|
||||
int32 count;
|
||||
thread_id latest_holder;
|
||||
} sem_info;
|
||||
|
||||
sem_id create_sem_etc(int count, const char *name, proc_id owner);
|
||||
sem_id create_sem(int count, const char *name);
|
||||
int delete_sem(sem_id id);
|
||||
int delete_sem_etc(sem_id id, int return_code);
|
||||
int acquire_sem(sem_id id);
|
||||
int acquire_sem_etc(sem_id id, int count, int flags, bigtime_t timeout);
|
||||
int release_sem(sem_id id);
|
||||
int release_sem_etc(sem_id id, int count, int flags);
|
||||
int get_sem_count(sem_id id, int32* thread_count);
|
||||
int _get_sem_info(sem_id id, struct sem_info *info, size_t);
|
||||
int _get_next_sem_info(proc_id proc, uint32 *cookie, struct sem_info *info, size_t);
|
||||
int set_sem_owner(sem_id id, proc_id proc);
|
||||
|
||||
#define get_sem_info(sem, info) \
|
||||
_get_sem_info((sem), (info), sizeof(*(info)))
|
||||
|
||||
#define get_next_sem_info(team, cookie, info) \
|
||||
_get_next_sem_info((team), (cookie), (info), sizeof(*(info)))
|
||||
|
||||
/** @} */
|
||||
|
||||
/**
|
||||
* @defgroup Threads Threads
|
||||
* @ingroup OpenBeOS_Headers
|
||||
* @{
|
||||
*/
|
||||
|
||||
/* Threads */
|
||||
|
||||
//enum {
|
||||
// THREAD_STATE_READY = 0, // ready to run
|
||||
// THREAD_STATE_RUNNING, // running right now somewhere
|
||||
// THREAD_STATE_WAITING, // blocked on something
|
||||
// THREAD_STATE_SUSPENDED, // suspended, not in queue
|
||||
// THREAD_STATE_FREE_ON_RESCHED, // free the thread structure upon reschedule
|
||||
// THREAD_STATE_BIRTH // thread is being created
|
||||
//};
|
||||
|
||||
typedef enum {
|
||||
B_THREAD_RUNNING=1,
|
||||
B_THREAD_READY,
|
||||
B_THREAD_RECEIVING,
|
||||
B_THREAD_ASLEEP,
|
||||
B_THREAD_SUSPENDED,
|
||||
B_THREAD_WAITING
|
||||
} thread_state;
|
||||
|
||||
#define THREAD_IDLE_PRIORITY 0
|
||||
|
||||
#define THREAD_NUM_PRIORITY_LEVELS 64
|
||||
#define THREAD_MIN_PRIORITY (THREAD_IDLE_PRIORITY + 1)
|
||||
#define THREAD_MAX_PRIORITY (THREAD_NUM_PRIORITY_LEVELS - THREAD_NUM_RT_PRIORITY_LEVELS - 1)
|
||||
|
||||
#define THREAD_NUM_RT_PRIORITY_LEVELS 16
|
||||
#define THREAD_MIN_RT_PRIORITY (THREAD_MAX_PRIORITY + 1)
|
||||
#define THREAD_MAX_RT_PRIORITY (THREAD_NUM_PRIORITY_LEVELS - 1)
|
||||
|
||||
#define THREAD_LOWEST_PRIORITY THREAD_MIN_PRIORITY
|
||||
#define THREAD_LOW_PRIORITY 12
|
||||
#define THREAD_MEDIUM_PRIORITY 24
|
||||
#define THREAD_HIGH_PRIORITY 36
|
||||
#define THREAD_HIGHEST_PRIORITY THREAD_MAX_PRIORITY
|
||||
|
||||
#define THREAD_RT_LOW_PRIORITY THREAD_MIN_RT_PRIORITY
|
||||
#define THREAD_RT_HIGH_PRIORITY THREAD_MAX_RT_PRIORITY
|
||||
|
||||
#define B_LOW_PRIORITY 5
|
||||
#define B_NORMAL_PRIORITY 10
|
||||
#define B_DISPLAY_PRIORITY 15
|
||||
#define B_URGENT_DISPLAY_PRIORITY 20
|
||||
#define B_REAL_TIME_DISPLAY_PRIORITY 100
|
||||
#define B_URGENT_PRIORITY 110
|
||||
#define B_REAL_TIME_PRIORITY 120
|
||||
|
||||
typedef struct {
|
||||
thread_id thread;
|
||||
team_id team;
|
||||
char name[B_OS_NAME_LENGTH];
|
||||
thread_state state;
|
||||
int32 priority;
|
||||
sem_id sem;
|
||||
bigtime_t user_time;
|
||||
bigtime_t kernel_time;
|
||||
void *stack_base;
|
||||
void *stack_end;
|
||||
} thread_info;
|
||||
|
||||
typedef struct {
|
||||
bigtime_t user_time;
|
||||
bigtime_t kernel_time;
|
||||
} team_usage_info;
|
||||
|
||||
typedef int32 (*thread_func) (void *);
|
||||
|
||||
thread_id spawn_thread (thread_func, const char *, int32, void *);
|
||||
int kill_thread(thread_id thread);
|
||||
int resume_thread(thread_id thread);
|
||||
int suspend_thread(thread_id thread);
|
||||
|
||||
thread_id find_thread(const char *);
|
||||
|
||||
/** @} */
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _OS_H */
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
/**
|
||||
* @file dirent.h
|
||||
* @brief File Control functions and definitions
|
||||
*/
|
||||
|
||||
#ifndef _DIRENT_H
|
||||
#define _DIRENT_H
|
||||
|
||||
typedef struct dirent {
|
||||
vnode_id d_ino;
|
||||
unsigned short d_reclen;
|
||||
char d_name[1];
|
||||
} dirent_t;
|
||||
|
||||
typedef struct {
|
||||
int fd;
|
||||
struct dirent *ent;
|
||||
struct dirent me;
|
||||
} DIR;
|
||||
|
||||
#ifndef MAXNAMLEN
|
||||
#ifdef NAME_MAX
|
||||
#define MAXNAMLEN NAME_MAX
|
||||
#else
|
||||
#define MAXNAMLEN 256
|
||||
#endif
|
||||
#endif
|
||||
|
||||
DIR *opendir(const char *dirname);
|
||||
struct dirent *readdir(DIR *dirp);
|
||||
int closedir(DIR *dirp);
|
||||
void rewinddir(DIR *dirp);
|
||||
|
||||
#endif /* _DIRENT_H */
|
||||
|
||||
@@ -0,0 +1,341 @@
|
||||
/*-
|
||||
* Copyright (c) 1983, 1990, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
* (c) UNIX System Laboratories, Inc.
|
||||
* All or some portions of this file are derived from material licensed
|
||||
* to the University of California by American Telephone and Telegraph
|
||||
* Co. or Unix System Laboratories, Inc. and are reproduced herein with
|
||||
* the permission of UNIX System Laboratories, Inc.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the University of
|
||||
* California, Berkeley and its contributors.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* @(#)fcntl.h 8.3 (Berkeley) 1/21/94
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file fcntl.h
|
||||
* @brief File Control functions and definitions
|
||||
*/
|
||||
|
||||
#ifndef _FCNTL_H_
|
||||
#define _FCNTL_H_
|
||||
|
||||
/**
|
||||
* @defgroup Fcntl fcntl.h
|
||||
* @brief File Control functions and definitions
|
||||
* @note Definitions in this file also apply to open() and
|
||||
* internally in the kernel
|
||||
* @note Relevant kernel functions should be here as well
|
||||
* @ingroup OpenBeOS_POSIX
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef _KERNEL_
|
||||
//#include <sys/types.h>
|
||||
#endif
|
||||
|
||||
|
||||
/**
|
||||
* @defgroup File_Status_Flags File Status Flags
|
||||
* The flags described in this section are used by fcntl(), open() and also
|
||||
* withing the kernel.
|
||||
* @note O_ are used by fcntl() and open()
|
||||
* @note F flags are used by the kernel
|
||||
* @ingroup fcntl
|
||||
* @{
|
||||
*/
|
||||
/** open for reading only */
|
||||
#define O_RDONLY 0x0000
|
||||
/** open for writing only */
|
||||
#define O_WRONLY 0x0001
|
||||
/** open for reading and writing */
|
||||
#define O_RDWR 0x0002
|
||||
/** mask for above modes */
|
||||
#define O_ACCMODE 0x0003
|
||||
|
||||
#ifndef _POSIX_SOURCE
|
||||
/** kernel flag to allow testing of read/write directly
|
||||
* @note not #ifdef _KERNEL_ to allow TIOCFLUSH to work */
|
||||
#define FREAD 0x0001
|
||||
/** kernel flag to allow testing of read/write directly
|
||||
* @note not #ifdef _KERNEL_ to allow TIOCFLUSH to work */
|
||||
#define FWRITE 0x0002
|
||||
#endif
|
||||
|
||||
/** no delay */
|
||||
#define O_NONBLOCK 0x0004
|
||||
/** set append mode */
|
||||
#define O_APPEND 0x0008
|
||||
/** open with shared file lock */
|
||||
#define O_SHLOCK 0x0010
|
||||
/** open with exclusive file lock */
|
||||
#define O_EXLOCK 0x0020
|
||||
/** signal pgrp when data ready */
|
||||
#define O_ASYNC 0x0040
|
||||
/** backwards compatibility */
|
||||
#define O_FSYNC O_SYNC
|
||||
/** if path is a symlink, don't follow */
|
||||
#define O_NOFOLLOW 0x0100
|
||||
/** synchronous writes */
|
||||
#define O_SYNC 0x0080
|
||||
/** create if nonexistant */
|
||||
#define O_CREAT 0x0200
|
||||
/** truncate to zero length */
|
||||
#define O_TRUNC 0x0400
|
||||
/** error if already exists */
|
||||
#define O_EXCL 0x0800
|
||||
|
||||
#ifdef _KERNEL_
|
||||
/* mark during gc() */
|
||||
#define FMARK 0x1000
|
||||
/* defer for next gc pass */
|
||||
#define FDEFER 0x2000
|
||||
/* descriptor holds advisory lock */
|
||||
#define FHASLOCK 0x4000
|
||||
#endif
|
||||
|
||||
/*
|
||||
* POSIX 1003.1 specifies a higher granularity for syncronous operations
|
||||
* than are currently supported. We may want to look at what needs to be done
|
||||
* to support these. At present just map them.
|
||||
*/
|
||||
/** @def O_DSYNC synchronous data writes */
|
||||
#define O_DSYNC O_SYNC
|
||||
/** @def O_RSYNC synchronous reads */
|
||||
#define O_RSYNC O_SYNC
|
||||
|
||||
/* defined by POSIX 1003.1; BSD default, this bit is not required */
|
||||
/** @def O_NOCTTY don't assign controlling terminal */
|
||||
#define O_NOCTTY 0x8000
|
||||
|
||||
#ifdef _KERNEL_
|
||||
/*
|
||||
* convert from open() flags to/from fflags; convert O_RD/WR to FREAD/FWRITE.
|
||||
* For out-of-range values for the flags, be slightly careful (but lossy).
|
||||
*/
|
||||
/** @def FFLAGS(oflags) Convert from O_ flags to F flags for kernel */
|
||||
#define FFLAGS(oflags) (((oflags) & ~O_ACCMODE) | (((oflags) + 1) & O_ACCMODE))
|
||||
/** @def OFLAGS(fflags) Convert from F flags to O_ flags for open() */
|
||||
#define OFLAGS(fflags) (((fflags) & ~O_ACCMODE) | (((fflags) - 1) & O_ACCMODE))
|
||||
|
||||
/** @def FMASK bits to save after open */
|
||||
#define FMASK (FREAD|FWRITE|FAPPEND|FASYNC|FFSYNC|FNONBLOCK)
|
||||
/** @def FCNTLFLAGS bits settable by fcntl(F_SETFL, ...) */
|
||||
#define FCNTLFLAGS (FAPPEND|FASYNC|FFSYNC|FNONBLOCK)
|
||||
#endif
|
||||
|
||||
/*
|
||||
* The O_* flags used to have only F* names, which were used in the kernel
|
||||
* and by fcntl. We retain the F* names for the kernel f_flags field
|
||||
* and for backward compatibility for fcntl.
|
||||
*/
|
||||
#ifndef _POSIX_SOURCE
|
||||
/** kernel/compat */
|
||||
#define FAPPEND O_APPEND
|
||||
/** kernel/compat */
|
||||
#define FASYNC O_ASYNC
|
||||
/** kernel */
|
||||
#define FFSYNC O_SYNC
|
||||
/** kernel */
|
||||
#define FNONBLOCK O_NONBLOCK
|
||||
/** compat */
|
||||
#define FNDELAY O_NONBLOCK
|
||||
/** compat */
|
||||
#define O_NDELAY O_NONBLOCK
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
|
||||
/**
|
||||
* @defgroup FCNTL_Flags Flags used for fcntl()
|
||||
* @ingroup FCNTL
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @def F_DUPFD Return a new file descriptor that has
|
||||
* @li the lowest number available (>= fd used)
|
||||
* @li same object references as original fd
|
||||
* @li same offsets as original (file only)
|
||||
* @li same file status
|
||||
* @li close-on-exec flag is set so it will remain open across execv()
|
||||
*
|
||||
* @ref FD_CLOEXEC
|
||||
*/
|
||||
#define F_DUPFD 0 /* duplicate file descriptor */
|
||||
/** @def F_GETFD Get the close-on-exec flag for the fd
|
||||
* @note the argument is ignored
|
||||
* @ref FD_CLOEXEC */
|
||||
#define F_GETFD 1
|
||||
/** @def F_SETFD Set the close-on-exec flag for the fd
|
||||
* @ref FD_CLOEXEC */
|
||||
#define F_SETFD 2
|
||||
/** @def F_GETFL Get fd status flags */
|
||||
#define F_GETFL 3
|
||||
/** @def F_SETFL Set the fd status flags */
|
||||
#define F_SETFL 4
|
||||
/** @def F_GETOWN Get the process ID receiving SIGIO/SIGURG signals */
|
||||
#define F_GETOWN 5
|
||||
/** @def F_SETOWN Set the process ID receiving SIGIO/SIGURG signals */
|
||||
#define F_SETOWN 6
|
||||
/** @def F_GETLK Get the first lock that blocks the requested lock requested
|
||||
* int the flock structure passed in.
|
||||
* @li If the call succeeds then the structure is returned unaltered except
|
||||
* the lock type is set to F_UNLCK
|
||||
* @li If the call fails the details of the blocking lock will be inserted
|
||||
* into the strcture, overwriting the details submitted.
|
||||
*/
|
||||
#define F_GETLK 7
|
||||
/** @def F_SETLK Set/Clear a file segment lock based on the flock structure
|
||||
* passed in.
|
||||
* @note If a shared/exclusive lock cannot be set, EAGAIN will be returned
|
||||
*/
|
||||
#define F_SETLK 8
|
||||
/** @def F_SETLKW Same as F_SETLK but will block if a shared/exclusive
|
||||
* lock is requested and is not available.
|
||||
*/
|
||||
#define F_SETLKW 9
|
||||
|
||||
/* file descriptor flags (F_GETFD, F_SETFD) */
|
||||
/** @def FD_CLOEXEC Flag set in status is fd is set to remain open
|
||||
* across exec
|
||||
* @ref F_DUPFD
|
||||
* @ref F_GETFD
|
||||
* @ref F_SETFD
|
||||
*/
|
||||
#define FD_CLOEXEC 1 /* close-on-exec flag */
|
||||
/** @} */
|
||||
|
||||
/**
|
||||
* @defgroup FCNTL_FileLocks Locking types for fcntl()
|
||||
* @ingroup FCNTL
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** shared or read lock */
|
||||
#define F_RDLCK 1
|
||||
/** unlock */
|
||||
#define F_UNLCK 2
|
||||
/** exclusive or write lock */
|
||||
#define F_WRLCK 3
|
||||
|
||||
#ifdef _KERNEL_
|
||||
/** Wait until lock is granted */
|
||||
#define F_WAIT 0x010
|
||||
/** Use flock(2) semantics for lock */
|
||||
#define F_FLOCK 0x020
|
||||
/** Use POSIX semantics for lock */
|
||||
#define F_POSIX 0x040
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
|
||||
/**
|
||||
* Advisory file segment locking data type -
|
||||
* information passed to system by user
|
||||
* @note This structure can be used to lock all or part of a file
|
||||
* @note Not yet implemented in OpenBeOS
|
||||
*/
|
||||
struct flock {
|
||||
/** starting offset for lock */
|
||||
off_t l_start;
|
||||
/** length of lock required (0 means lock to end of file) */
|
||||
off_t l_len;
|
||||
/** process id of process owning lock */
|
||||
pid_t l_pid;
|
||||
/** type of lock
|
||||
* @link FCNTL_FileLocks */
|
||||
short l_type;
|
||||
/** type of start poition given */
|
||||
short l_whence;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @defgroup FCNTL_flock Locking types for flock()
|
||||
* @ingroup FCNTL
|
||||
* @{
|
||||
*/
|
||||
/** shared lock */
|
||||
#define LOCK_SH 0x01
|
||||
/** exclusive lock */
|
||||
#define LOCK_EX 0x02
|
||||
/** don't block when locking */
|
||||
#define LOCK_NB 0x04
|
||||
/** unlock */
|
||||
#define LOCK_UN 0x08
|
||||
/** @} */
|
||||
|
||||
|
||||
#ifndef _KERNEL_MODE
|
||||
//#include <sys/cdefs.h>
|
||||
#include <ktypes.h>
|
||||
|
||||
/** @fn int open(const char *path, int oflags, ...);
|
||||
* Used to open or create a file for reading/writing
|
||||
* @note oflags passed should be OR'd together, e.g.
|
||||
* @code
|
||||
* int fd = open("file.txt", O_RDWR | O_APPEND | O_CREAT);
|
||||
* @endcode
|
||||
* @note if the flag O_CREAT is supplied and the file given by path doesn't
|
||||
* exist it will be created.
|
||||
*
|
||||
* @ref File_Status_Flags
|
||||
*/
|
||||
int open (const char *, int, ...);
|
||||
|
||||
/** @fn int creat(const char *path, mode_t mode)
|
||||
* Creates a file.
|
||||
* @note Obsoleted by open()
|
||||
* @code
|
||||
* Same as doing open(path, O_CREAT | O_TRUNC | O_WRONLY, mode);
|
||||
* @endcode
|
||||
* @ref open()
|
||||
*/
|
||||
int creat (const char *, mode_t);
|
||||
|
||||
/** @fn int fcntl(int fd, int cmd, ...)
|
||||
* Provides control over the properties of a descriptor that is
|
||||
* already open. The 3rd paramater is technically a void *, but may
|
||||
* be interpretted as an int by some commands or cast by others.
|
||||
* @ref FCNTL_Flags should be used as the cmd parameter
|
||||
*/
|
||||
int fcntl (int, int, ...);
|
||||
|
||||
/** @fn int flock(int fd, int operation)
|
||||
* Applies or removes an advisory lock from descriptor fd.
|
||||
* @ref FCNTL_flock codes should be used as the operation parameter
|
||||
*/
|
||||
int flock (int, int);
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
|
||||
#endif /* !_SYS_FCNTL_H_ */
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
/* domain.h */
|
||||
|
||||
/* A domain is just a container for like minded protocols! */
|
||||
|
||||
#ifndef DOMAIN_H
|
||||
#define DOMAIN_H
|
||||
|
||||
struct domain {
|
||||
int dom_family; /* AF_INET and so on */
|
||||
char *dom_name;
|
||||
|
||||
void (*dom_init)(void); /* initialise */
|
||||
|
||||
struct protosw *dom_protosw; /* the protocols we have */
|
||||
struct domain *dom_next;
|
||||
|
||||
int (*dom_rtattach)(void **, int);
|
||||
int dom_rtoffset;
|
||||
int dom_maxrtkey;
|
||||
};
|
||||
|
||||
struct domain *domains;
|
||||
void add_domain(struct domain *dom, int fam);
|
||||
void remove_domain(int fam);
|
||||
|
||||
#endif /* DOMAIN_H */
|
||||
@@ -0,0 +1,40 @@
|
||||
/**
|
||||
* @file sys/filio.h
|
||||
* @brief ioctl() definitions for file descriptor operations
|
||||
*/
|
||||
|
||||
#ifndef _SYS_FILIO_H
|
||||
#define _SYS_FILIO_H
|
||||
/**
|
||||
* @defgroup IOCTL_filio sys/filio.h
|
||||
* @brief ioctl() definitions for file descriptor operations
|
||||
* @ingroup OpenBeOS_POSIX
|
||||
* @ingroup IOCTL
|
||||
* @{
|
||||
*/
|
||||
|
||||
#include <sys/ioccom.h>
|
||||
|
||||
/** @def FIOCLEX set close on exec
|
||||
* @ref FD_CLOEXEC */
|
||||
#define FIOCLEX _IO('f', 1)
|
||||
/** @def FIONCLEX remove close on exec flag
|
||||
* @ref FD_CLOEXEC*/
|
||||
#define FIONCLEX _IO('f', 2)
|
||||
/** @def FIBMAP get logical block
|
||||
* @note this is not yet implemented on OpenBeOS */
|
||||
#define FIBMAP _IOWR('f', 122, void *)
|
||||
/** @def FIOASYNC set/clear async I/O */
|
||||
#define FIOASYNC _IOW('f', 123, int)
|
||||
/** @def FIOGETOWN get owner */
|
||||
#define FIOGETOWN _IOR('f', 123, int)
|
||||
/** @def FIOSETOWN set owner */
|
||||
#define FIOSETOWN _IOW('f', 123, int)
|
||||
/** @def FIONBIO set/clear non-blocking I/O */
|
||||
#define FIONBIO _IOW('f', 126, int)
|
||||
/** @def FIONREAD get number of bytes available to read */
|
||||
#define FIONREAD _IOW('f', 127, int)
|
||||
|
||||
/** @} */
|
||||
|
||||
#endif /* _SYS_FILIO_H */
|
||||
@@ -0,0 +1,80 @@
|
||||
/**
|
||||
* @file sys/ioccom.h
|
||||
* @brief Definitions & maros common to ioctl
|
||||
*/
|
||||
|
||||
#ifndef _SYS_IOCCOM_H
|
||||
#define _SYS_IOCCOM_H
|
||||
|
||||
/**
|
||||
* @defgroup IOCTL_common sys/ioccom.h
|
||||
* @brief Definitions & maros common to ioctl()
|
||||
* @ingroup OpenBeOS_POSIX
|
||||
* @ingroup IOCTL
|
||||
* Ioctl values passed as the command (2nd) variable have the
|
||||
* command encoded in the lower word and the size of any parameters
|
||||
* in the upper word (in or out).
|
||||
* The high 3 bits are used to encode whether it's in or out.
|
||||
* Due to this you can't just give an ioctl value, you need to encode
|
||||
* it using macros described in
|
||||
* @ref IOCTL_macros
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup IOCTL_parm ioctl() parameter definitions
|
||||
* @ingroup IOCTL_common
|
||||
* @{
|
||||
*/
|
||||
/** @def IOC_VOID */
|
||||
#define IOC_VOID (ulong)0x20000000
|
||||
/** @def IOC_OUT ioctl expects data (output) */
|
||||
#define IOC_OUT (ulong)0x40000000
|
||||
/** @def IOC_IN ioctl passes a value in */
|
||||
#define IOC_IN (ulong)0x80000000
|
||||
/** @def IOC_INOUT ioctl passes data in and out */
|
||||
#define IOC_INOUT (IOC_IN|IOC_OUT)
|
||||
/** @def IOC_DIRMASK */
|
||||
#define IOC_DIRMASK (ulong)0xe0000000
|
||||
/** @} */
|
||||
|
||||
/**
|
||||
* @defgroup IOCTL_macros IOCTL macros
|
||||
* These should be used to define the values passed in as cmd to
|
||||
* ioctl()
|
||||
* @ingroup IOCTL_common
|
||||
* @{
|
||||
*/
|
||||
/** @def IOCPARM_MASK mask used to for following macros */
|
||||
#define IOCPARM_MASK 0x1fff
|
||||
/** @def IOCPARM_LEN(x) length of the data passed as param */
|
||||
#define IOCPARM_LEN(x) (((x) >> 16) & IOCPARM_MASK)
|
||||
/** @def IOCBASECMD(x) the base command encoded in the ioctl value */
|
||||
#define IOCBASECMD(x) ((x) & ~(IOCPARM_MASK << 16))
|
||||
/** @def IOCGROUP(x) which group of ioctl() commands does this belong to? */
|
||||
#define IOCGROUP(x) (((x) >> 8) & 0xff)
|
||||
/** @def IOCPARM_MAX Maximum size of parameter that can be passed (20 bytes) */
|
||||
#define IOCPARM_MAX 20
|
||||
|
||||
/**
|
||||
* @defgroup IOCTL_createmacros macro's to create ioctl() values
|
||||
* @brief these macro's should be used to create new ioctl() values
|
||||
* @ingroup IOCTL_common
|
||||
* @{
|
||||
*/
|
||||
/** @def _IOC(inout, group, num , len) create a new ioctl */
|
||||
#define _IOC(inout, group, num, len) \
|
||||
(inout | ((len & IOCPARM_MASK)<<16) | ((group) << 8) | (num))
|
||||
/** @def _IO(g,n) create a new void ioctl for group g, number n */
|
||||
#define _IO(g,n) _IOC(IOC_VOID, (g), (n), 0)
|
||||
/** @def _IOR(g,n,t) create a ioctl() that reads a value of type t*/
|
||||
#define _IOR(g,n,t) _IOC(IOC_OUT, (g), (n), sizeof(t))
|
||||
/** @def _IOW(g,n,t) ioctl() that writes value of type t, group g, number n */
|
||||
#define _IOW(g,n,t) _IOC(IOC_IN , (g), (n), sizeof(t))
|
||||
/** @def _IOWR(g,n,t) ioctl() that reads/writes value of type t
|
||||
* @note this isn't _IORW as this causes name conflicts on some systems */
|
||||
#define _IOWR(g,n,t) _IOC(IOC_INOUT, (g), (n), sizeof(t))
|
||||
/** @} */
|
||||
|
||||
/** @} */
|
||||
|
||||
#endif /* _SYS_IOCCOM_H */
|
||||
@@ -0,0 +1,37 @@
|
||||
/**
|
||||
* @file sys/ioctl.h
|
||||
* @brief I/O control functions
|
||||
*/
|
||||
|
||||
#ifndef _SYS_IOCTL_H
|
||||
#define _SYS_IOCTL_H
|
||||
|
||||
/**
|
||||
* @defgroup IOCTL sys/ioctl.h
|
||||
* @brief I/O control functions
|
||||
* @ingroup OpenBeOS_POSIX
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
#include <sys/ioccom.h>
|
||||
|
||||
#include <sys/filio.h>
|
||||
#include <sys/socket.h>
|
||||
|
||||
#ifndef _KERNEL_MODE
|
||||
/** @fn int ioctl(int fd, ulong cmd, ...)
|
||||
* Manipulates the characteristics of the affected descriptor. May be used
|
||||
* on all forms of descriptor, including sockets and pipes. cmd should be one
|
||||
* of the values given in
|
||||
* @ref IOCTL_cmds
|
||||
*/
|
||||
int ioctl(int, ulong, ...);
|
||||
#endif /* !_KERNEL_MODE */
|
||||
|
||||
/** @} */
|
||||
#endif /* _SYS_IOCTL_H */
|
||||
@@ -0,0 +1,147 @@
|
||||
/* protosw.h */
|
||||
|
||||
#ifndef PROTOSW_H
|
||||
#define PROTOSW_H
|
||||
|
||||
#include "sys/socketvar.h" /* for struct socket */
|
||||
#include "net/route.h"
|
||||
|
||||
#define PRCO_SETOPT 0
|
||||
#define PRCO_GETOPT 1
|
||||
|
||||
/* every protocol module init's one of these and passes it into
|
||||
* the add_protocol() function, defined below */
|
||||
/* NB The pr_domain pointer will be filled in during the
|
||||
* add_protocol() call
|
||||
*/
|
||||
struct protosw {
|
||||
char *name;
|
||||
char *mod_path;
|
||||
uint16 pr_type; /* SOCK_xxx */
|
||||
struct domain *pr_domain;
|
||||
uint16 pr_protocol; /* protocol number */
|
||||
uint16 pr_flags; /* flags, PR_xxx */
|
||||
int layer; /* which layer are we? */
|
||||
|
||||
/* the functions! */
|
||||
void (*pr_init)(void);
|
||||
void (*pr_input)(struct mbuf*, int);
|
||||
int (*pr_output)(struct mbuf *, struct mbuf *,
|
||||
struct route *,
|
||||
int, void *);
|
||||
|
||||
int (*pr_userreq)(struct socket *, int,
|
||||
struct mbuf *,
|
||||
struct mbuf *,
|
||||
struct mbuf *);
|
||||
int (*pr_sysctl)(int *, uint, void *, size_t *, void *, size_t);
|
||||
void (*pr_ctlinput)(int, struct sockaddr *, void *);
|
||||
int (*pr_ctloutput)(int, struct socket*, int, int, struct mbuf **);
|
||||
|
||||
struct protosw *pr_next; /* pointer to next proto structure */
|
||||
struct protosw *dom_next; /* next protosw pointed by the domain */
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
* Values for pr_flags.
|
||||
* PR_ADDR requires PR_ATOMIC;
|
||||
* PR_ADDR and PR_CONNREQUIRED are mutually exclusive.
|
||||
*/
|
||||
#define PR_ATOMIC 0x01 /* exchange atomic messages only */
|
||||
#define PR_ADDR 0x02 /* addresses given with messages */
|
||||
#define PR_CONNREQUIRED 0x04 /* connection required by protocol */
|
||||
#define PR_WANTRCVD 0x08 /* want PRU_RCVD calls */
|
||||
#define PR_RIGHTS 0x10 /* passes capabilities */
|
||||
#define PR_ABRTACPTDIS 0x20 /* abort on accept(2) to disconnected
|
||||
socket */
|
||||
|
||||
#define PR_SLOWHZ 2 /* 2 timeouts per second... */
|
||||
#define PR_FASTHZ 5 /* 5 timeouts per second */
|
||||
/*
|
||||
* Defines for the userreq function req field are below.
|
||||
*
|
||||
* (*usrreq)(up, req, m, nam, opt);
|
||||
*
|
||||
* up is a (struct socket *)
|
||||
* req is one of these requests,
|
||||
* m is a optional mbuf chain containing a message,
|
||||
* nam is an optional mbuf chain containing an address,
|
||||
* opt is a pointer to a socketopt structure or nil.
|
||||
*
|
||||
* The protocol is responsible for disposal of the mbuf chain m,
|
||||
* the caller is responsible for any space held by nam and opt.
|
||||
* A non-zero return from usrreq gives an
|
||||
* UNIX error number which should be passed to higher level software.
|
||||
*/
|
||||
#define PRU_ATTACH 0 /* attach protocol to up */
|
||||
#define PRU_DETACH 1 /* detach protocol from up */
|
||||
#define PRU_BIND 2 /* bind socket to address */
|
||||
#define PRU_LISTEN 3 /* listen for connection */
|
||||
#define PRU_CONNECT 4 /* establish connection to peer */
|
||||
#define PRU_ACCEPT 5 /* accept connection from peer */
|
||||
#define PRU_DISCONNECT 6 /* disconnect from peer */
|
||||
#define PRU_SHUTDOWN 7 /* won't send any more data */
|
||||
#define PRU_RCVD 8 /* have taken data; more room now */
|
||||
#define PRU_SEND 9 /* send this data */
|
||||
#define PRU_ABORT 10 /* abort (fast DISCONNECT, DETATCH) */
|
||||
#define PRU_CONTROL 11 /* control operations on protocol */
|
||||
#define PRU_SENSE 12 /* return status into m */
|
||||
#define PRU_RCVOOB 13 /* retrieve out of band data */
|
||||
#define PRU_SENDOOB 14 /* send out of band data */
|
||||
#define PRU_SOCKADDR 15 /* fetch socket's address */
|
||||
#define PRU_PEERADDR 16 /* fetch peer's address */
|
||||
#define PRU_CONNECT2 17 /* connect two sockets */
|
||||
/* begin for protocols internal use */
|
||||
#define PRU_FASTTIMO 18 /* 200ms timeout */
|
||||
#define PRU_SLOWTIMO 19 /* 500ms timeout */
|
||||
#define PRU_PROTORCV 20 /* receive from below */
|
||||
#define PRU_PROTOSEND 21 /* send to below */
|
||||
#define PRU_PEEREID 22 /* get local peer eid */
|
||||
|
||||
#define PRU_NREQ 22
|
||||
|
||||
/*
|
||||
* The arguments to the ctlinput routine are
|
||||
* (*protosw[].pr_ctlinput)(cmd, sa, arg);
|
||||
* where cmd is one of the commands below, sa is a pointer to a sockaddr,
|
||||
* and arg is an optional caddr_t argument used within a protocol family.
|
||||
*/
|
||||
#define PRC_IFDOWN 0 /* interface transition */
|
||||
#define PRC_ROUTEDEAD 1 /* select new route if possible ??? */
|
||||
#define PRC_MTUINC 2 /* increase in mtu to host */
|
||||
#define PRC_QUENCH2 3 /* DEC congestion bit says slow down */
|
||||
#define PRC_QUENCH 4 /* some one said to slow down */
|
||||
#define PRC_MSGSIZE 5 /* message size forced drop */
|
||||
#define PRC_HOSTDEAD 6 /* host appears to be down */
|
||||
#define PRC_HOSTUNREACH 7 /* deprecated (use PRC_UNREACH_HOST) */
|
||||
#define PRC_UNREACH_NET 8 /* no route to network */
|
||||
#define PRC_UNREACH_HOST 9 /* no route to host */
|
||||
#define PRC_UNREACH_PROTOCOL 10 /* dst says bad protocol */
|
||||
#define PRC_UNREACH_PORT 11 /* bad port # */
|
||||
/* was PRC_UNREACH_NEEDFRAG 12 (use PRC_MSGSIZE) */
|
||||
#define PRC_UNREACH_SRCFAIL 13 /* source route failed */
|
||||
#define PRC_REDIRECT_NET 14 /* net routing redirect */
|
||||
#define PRC_REDIRECT_HOST 15 /* host routing redirect */
|
||||
#define PRC_REDIRECT_TOSNET 16 /* redirect for type of service & net */
|
||||
#define PRC_REDIRECT_TOSHOST 17 /* redirect for tos & host */
|
||||
#define PRC_TIMXCEED_INTRANS 18 /* packet lifetime expired in transit */
|
||||
#define PRC_TIMXCEED_REASS 19 /* lifetime expired on reass q */
|
||||
#define PRC_PARAMPROB 20 /* header incorrect */
|
||||
|
||||
#define PRC_NCMDS 21
|
||||
|
||||
#define PRC_IS_REDIRECT(cmd) \
|
||||
((cmd) >= PRC_REDIRECT_NET && (cmd) <= PRC_REDIRECT_TOSHOST)
|
||||
|
||||
|
||||
/* Network stack defines... */
|
||||
#ifdef _NETWORK_STACK
|
||||
struct protosw *protocols;
|
||||
void add_protocol(struct protosw *pr, int fam);
|
||||
void remove_protocol(struct protosw *pr);
|
||||
#endif
|
||||
struct protosw *pffindproto(int domain, int protocol, int type);
|
||||
struct protosw *pffindtype(int domain, int type);
|
||||
|
||||
#endif /* PROTOSW_H */
|
||||
@@ -0,0 +1,251 @@
|
||||
/* sys/socket.h */
|
||||
|
||||
|
||||
#ifndef _SYS_SOCKET_H
|
||||
#define _SYS_SOCKET_H
|
||||
|
||||
#include <OS.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/ioctl.h>
|
||||
|
||||
/* These are the address/protocol families we'll be using... */
|
||||
/* NB these should be added to as required... */
|
||||
|
||||
/* If we want to have Binary compatability we may need to alter these
|
||||
* to agree with the Be versions...
|
||||
*/
|
||||
#define AF_UNSPEC 0
|
||||
#define AF_LOCAL 1
|
||||
#define AF_UNIX AF_LOCAL /* for compatability */
|
||||
#define AF_INET 2
|
||||
#define AF_ROUTE 3
|
||||
#define AF_IMPLINK 4
|
||||
#define AF_LINK 18
|
||||
#define AF_IPX 23
|
||||
#define AF_INET6 24
|
||||
|
||||
#define AF_MAX 24
|
||||
|
||||
#define PF_UNSPEC AF_UNSPEC
|
||||
#define PF_INET AF_INET
|
||||
#define PF_ROUTE AF_ROUTE
|
||||
#define PF_LINK AF_LINK
|
||||
#define PF_INET6 AF_INET6
|
||||
#define PF_IPX AF_IPX
|
||||
#define PF_IMPLINK AF_IMPLINK
|
||||
|
||||
/* Types of socket we can create (eventually) */
|
||||
#define SOCK_DGRAM 10
|
||||
#define SOCK_STREAM 11
|
||||
#define SOCK_RAW 12
|
||||
#define SOCK_MISC 255
|
||||
|
||||
/*
|
||||
* Option flags per-socket.
|
||||
*/
|
||||
#define SO_DEBUG 0x0001 /* turn on debugging info recording */
|
||||
#define SO_ACCEPTCONN 0x0002 /* socket has had listen() */
|
||||
#define SO_REUSEADDR 0x0004 /* allow local address reuse */
|
||||
#define SO_KEEPALIVE 0x0008 /* keep connections alive */
|
||||
#define SO_DONTROUTE 0x0010 /* just use interface addresses */
|
||||
#define SO_BROADCAST 0x0020 /* permit sending of broadcast msgs */
|
||||
#define SO_USELOOPBACK 0x0040 /* bypass hardware when possible */
|
||||
#define SO_LINGER 0x0080 /* linger on close if data present */
|
||||
#define SO_OOBINLINE 0x0100 /* leave received OOB data in line */
|
||||
#define SO_REUSEPORT 0x0200 /* allow local address & port reuse */
|
||||
|
||||
#define SOL_SOCKET 0xffff
|
||||
|
||||
/*
|
||||
* Additional options, not kept in so_options.
|
||||
*/
|
||||
#define SO_SNDBUF 0x1001 /* send buffer size */
|
||||
#define SO_RCVBUF 0x1002 /* receive buffer size */
|
||||
#define SO_SNDLOWAT 0x1003 /* send low-water mark */
|
||||
#define SO_RCVLOWAT 0x1004 /* receive low-water mark */
|
||||
#define SO_SNDTIMEO 0x1005 /* send timeout */
|
||||
#define SO_RCVTIMEO 0x1006 /* receive timeout */
|
||||
#define SO_ERROR 0x1007 /* get error status and clear */
|
||||
#define SO_TYPE 0x1008 /* get socket type */
|
||||
#define SO_NETPROC 0x1020 /* multiplex; network processing */
|
||||
|
||||
/*
|
||||
* These are the valid values for the "how" field used by shutdown(2).
|
||||
*/
|
||||
#define SHUT_RD 1
|
||||
#define SHUT_WR 2
|
||||
#define SHUT_RDWR 3
|
||||
|
||||
struct linger {
|
||||
int l_onoff;
|
||||
int l_linger;
|
||||
};
|
||||
|
||||
struct sockaddr {
|
||||
uint8 sa_len;
|
||||
uint8 sa_family;
|
||||
uint8 sa_data[30];
|
||||
};
|
||||
|
||||
/* this can hold ANY sockaddr we care to throw at it! */
|
||||
struct sockaddr_storage {
|
||||
uint8 ss_len; /* total length */
|
||||
uint8 ss_family; /* address family */
|
||||
uint8 __ss_pad1[6]; /* align to quad */
|
||||
uint64 __ss_pad2; /* force alignment for stupid compilers */
|
||||
uint8 __ss_pad3[240]; /* pad to a total of 256 bytes */
|
||||
};
|
||||
|
||||
struct sockproto {
|
||||
uint16 sp_family;
|
||||
uint16 sp_protocol;
|
||||
};
|
||||
|
||||
#define CTL_NET 4
|
||||
|
||||
#define CTL_NET_NAMES { \
|
||||
{ 0, 0 }, \
|
||||
{ "unix", CTLTYPE_NODE }, \
|
||||
{ "inet", CTLTYPE_NODE }, \
|
||||
{ "implink", CTLTYPE_NODE }, \
|
||||
{ "pup", CTLTYPE_NODE }, \
|
||||
{ "chaos", CTLTYPE_NODE }, \
|
||||
{ "xerox_ns", CTLTYPE_NODE }, \
|
||||
{ "iso", CTLTYPE_NODE }, \
|
||||
{ "emca", CTLTYPE_NODE }, \
|
||||
{ "datakit", CTLTYPE_NODE }, \
|
||||
{ "ccitt", CTLTYPE_NODE }, \
|
||||
{ "ibm_sna", CTLTYPE_NODE }, \
|
||||
{ "decnet", CTLTYPE_NODE }, \
|
||||
{ "dec_dli", CTLTYPE_NODE }, \
|
||||
{ "lat", CTLTYPE_NODE }, \
|
||||
{ "hylink", CTLTYPE_NODE }, \
|
||||
{ "appletalk", CTLTYPE_NODE }, \
|
||||
{ "route", CTLTYPE_NODE }, \
|
||||
{ "link_layer", CTLTYPE_NODE }, \
|
||||
{ "xtp", CTLTYPE_NODE }, \
|
||||
{ "coip", CTLTYPE_NODE }, \
|
||||
{ "cnt", CTLTYPE_NODE }, \
|
||||
{ "rtip", CTLTYPE_NODE }, \
|
||||
{ "ipx", CTLTYPE_NODE }, \
|
||||
{ "inet6", CTLTYPE_NODE }, \
|
||||
{ "pip", CTLTYPE_NODE }, \
|
||||
{ "isdn", CTLTYPE_NODE }, \
|
||||
{ "natm", CTLTYPE_NODE }, \
|
||||
{ "encap", CTLTYPE_NODE }, \
|
||||
{ "sip", CTLTYPE_NODE }, \
|
||||
{ "key", CTLTYPE_NODE }, \
|
||||
}
|
||||
|
||||
/*
|
||||
* PF_ROUTE - Routing table
|
||||
*
|
||||
* Three additional levels are defined:
|
||||
* Fourth: address family, 0 is wildcard
|
||||
* Fifth: type of info, defined below
|
||||
* Sixth: flag(s) to mask with for NET_RT_FLAGS
|
||||
*/
|
||||
#define NET_RT_DUMP 1 /* dump; may limit to a.f. */
|
||||
#define NET_RT_FLAGS 2 /* by flags, e.g. RESOLVING */
|
||||
#define NET_RT_IFLIST 3 /* survey interface list */
|
||||
#define NET_RT_MAXID 4
|
||||
|
||||
#define CTL_NET_RT_NAMES { \
|
||||
{ 0, 0 }, \
|
||||
{ "dump", CTLTYPE_STRUCT }, \
|
||||
{ "flags", CTLTYPE_STRUCT }, \
|
||||
{ "iflist", CTLTYPE_STRUCT }, \
|
||||
}
|
||||
|
||||
/* Max listen queue for a socket */
|
||||
#define SOMAXCONN 5 /* defined as 128 in OpenBSD */
|
||||
|
||||
struct msghdr {
|
||||
char * msg_name; /* address we're using (optional) */
|
||||
uint msg_namelen; /* length of address */
|
||||
struct iovec *msg_iov; /* scatter/gather array we'll use */
|
||||
uint msg_iovlen; /* # elements in msg_iov */
|
||||
char * msg_control; /* extra data */
|
||||
uint msg_controllen; /* length of extra data */
|
||||
int msg_flags; /* flags */
|
||||
};
|
||||
|
||||
/* Defines used in msghdr structure. */
|
||||
#define MSG_OOB 0x1 /* process out-of-band data */
|
||||
#define MSG_PEEK 0x2 /* peek at incoming message */
|
||||
#define MSG_DONTROUTE 0x4 /* send without using routing tables */
|
||||
#define MSG_EOR 0x8 /* data completes record */
|
||||
#define MSG_TRUNC 0x10 /* data discarded before delivery */
|
||||
#define MSG_CTRUNC 0x20 /* control data lost before delivery */
|
||||
#define MSG_WAITALL 0x40 /* wait for full request or error */
|
||||
#define MSG_DONTWAIT 0x80 /* this message should be nonblocking */
|
||||
#define MSG_BCAST 0x100 /* this message rec'd as broadcast */
|
||||
#define MSG_MCAST 0x200 /* this message rec'd as multicast */
|
||||
|
||||
struct cmsghdr {
|
||||
uint cmsg_len;
|
||||
int cmsg_level;
|
||||
int cmsg_type;
|
||||
/* there now follows uchar[] cmsg_data */
|
||||
};
|
||||
|
||||
#define SIOCSHIWAT _IOW('s', 0, int) /* set high watermark */
|
||||
#define SIOCGHIWAT _IOR('s', 1, int) /* get high watermark */
|
||||
#define SIOCSLOWAT _IOW('s', 2, int) /* set low watermark */
|
||||
#define SIOCGLOWAT _IOR('s', 3, int) /* get low watermark */
|
||||
#define SIOCATMARK _IOR('s', 7, int) /* at oob mark? */
|
||||
|
||||
#define SIOCADDRT _IOW('r', 10, struct ortentry) /* add route */
|
||||
#define SIOCDELRT _IOW('r', 11, struct ortentry) /* delete route */
|
||||
|
||||
#define SIOCSIFADDR _IOW('i', 12, struct ifreq) /* set ifnet address */
|
||||
#define OSIOCGIFADDR _IOWR('i', 13, struct ifreq) /* get ifnet address */
|
||||
#define SIOCGIFADDR _IOWR('i', 33, struct ifreq) /* get ifnet address */
|
||||
#define SIOCSIFDSTADDR _IOW('i', 14, struct ifreq) /* set p-p address */
|
||||
#define OSIOCGIFDSTADDR _IOWR('i', 15, struct ifreq) /* get p-p address */
|
||||
#define SIOCGIFDSTADDR _IOWR('i', 34, struct ifreq) /* get p-p address */
|
||||
#define SIOCSIFFLAGS _IOW('i', 16, struct ifreq) /* set ifnet flags */
|
||||
#define SIOCGIFFLAGS _IOWR('i', 17, struct ifreq) /* get ifnet flags */
|
||||
#define OSIOCGIFBRDADDR _IOWR('i', 18, struct ifreq) /* get broadcast addr */
|
||||
#define SIOCGIFBRDADDR _IOWR('i', 35, struct ifreq) /* get broadcast addr */
|
||||
#define SIOCSIFBRDADDR _IOW('i', 19, struct ifreq) /* set broadcast addr */
|
||||
#define OSIOCGIFCONF _IOWR('i', 20, struct ifconf) /* get ifnet list */
|
||||
#define SIOCGIFCONF _IOWR('i', 36, struct ifconf) /* get ifnet list */
|
||||
#define OSIOCGIFNETMASK _IOWR('i', 21, struct ifreq) /* get net addr mask */
|
||||
#define SIOCGIFNETMASK _IOWR('i', 37, struct ifreq) /* get net addr mask */
|
||||
#define SIOCSIFNETMASK _IOW('i', 22, struct ifreq) /* set net addr mask */
|
||||
#define SIOCGIFMETRIC _IOWR('i', 23, struct ifreq) /* get IF metric */
|
||||
#define SIOCSIFMETRIC _IOW('i', 24, struct ifreq) /* set IF metric */
|
||||
#define SIOCDIFADDR _IOW('i', 25, struct ifreq) /* delete IF addr */
|
||||
#define SIOCAIFADDR _IOW('i', 26, struct ifaliasreq)/* add/chg IF alias */
|
||||
#define SIOCGIFDATA _IOWR('i', 27, struct ifreq) /* get if_data */
|
||||
|
||||
#define SIOCGIFMTU _IOWR('i', 126, struct ifreq) /* get ifnet MTU */
|
||||
#define SIOCSIFMTU _IOW('i', 127, struct ifreq) /* set ifnet MTU */
|
||||
|
||||
#define SIOCADDMULTI _IOW('i', 49, struct ifreq) /* add m'cast addr */
|
||||
#define SIOCDELMULTI _IOW('i', 50, struct ifreq) /* del m'cast addr */
|
||||
|
||||
#ifndef _KERNEL_MODE
|
||||
/* Function declarations */
|
||||
int socket (int, int, int);
|
||||
int bind(int, const struct sockaddr *, int);
|
||||
int connect(int, const struct sockaddr *, int);
|
||||
int listen(int, int);
|
||||
int accept(int, struct sockaddr *, int *);
|
||||
int closesocket(int);
|
||||
int shutdown(int sock, int how);
|
||||
|
||||
ssize_t send(int, const void *, size_t, int);
|
||||
ssize_t recv(int, void *, size_t, int);
|
||||
ssize_t sendto(int, const void *, size_t, int, const struct sockaddr *, size_t);
|
||||
ssize_t recvfrom(int, void *, size_t, int, struct sockaddr *, size_t *);
|
||||
|
||||
int setsockopt(int, int, int, const void *, size_t);
|
||||
int getsockopt(int, int, int, void *, size_t *);
|
||||
int getpeername(int, struct sockaddr *, int *);
|
||||
int getsockname(int, struct sockaddr *, int *);
|
||||
#endif /* _KERNEL_MODE_ */
|
||||
|
||||
#endif /* _SYS_SOCKET_H */
|
||||
|
||||
@@ -0,0 +1,236 @@
|
||||
/* socketvar.h */
|
||||
|
||||
|
||||
#ifndef SYS_SOCKETVAR_H
|
||||
#define SYS_SOCKETVAR_H
|
||||
|
||||
#include <OS.h>
|
||||
#include <mbuf.h>
|
||||
#include <sys/uio.h>
|
||||
#include <sys/socket.h>
|
||||
|
||||
struct sockbuf {
|
||||
uint32 sb_cc; /* actual chars in buffer */
|
||||
uint32 sb_hiwat; /* max actual char count (high water mark) */
|
||||
uint32 sb_mbcnt; /* chars of mbufs used */
|
||||
uint32 sb_mbmax; /* max chars of mbufs to use */
|
||||
int32 sb_lowat; /* low water mark */
|
||||
struct mbuf *sb_mb; /* the mbuf chain */
|
||||
int16 sb_flags; /* flags, see below */
|
||||
int32 sb_timeo; /* timeout for read/write */
|
||||
sem_id sb_sleep; /* our sleep sem */
|
||||
sem_id sb_pop; /* sem to wait on... */
|
||||
};
|
||||
|
||||
#define SB_MAX (256*1024) /* default for max chars in sockbuf */
|
||||
#define SB_LOCK 0x01 /* lock on data queue */
|
||||
#define SB_WANT 0x02 /* someone is waiting to lock */
|
||||
#define SB_WAIT 0x04 /* someone is waiting for data/space */
|
||||
#define SB_SEL 0x08 /* someone is selecting */
|
||||
#define SB_ASYNC 0x10 /* ASYNC I/O, need signals */
|
||||
#define SB_NOINTR 0x40 /* operations not interruptible */
|
||||
#define SB_KNOTE 0x80 /* kernel note attached */
|
||||
#define SB_NOTIFY (SB_WAIT|SB_SEL|SB_ASYNC)
|
||||
|
||||
typedef void (*socket_event_callback)(void * socket, uint32 event, void * cookie);
|
||||
|
||||
struct socket {
|
||||
uint16 so_type; /* type of socket */
|
||||
uint16 so_options; /* socket options */
|
||||
int16 so_linger; /* dreaded linger value */
|
||||
int16 so_state; /* socket state */
|
||||
char *so_pcb; /* pointer to the control block */
|
||||
sem_id so_lock; /* socket lock */
|
||||
sem_id so_timeo; /* our wait channel */
|
||||
|
||||
struct protosw *so_proto; /* pointer to protocol module */
|
||||
|
||||
struct socket *so_head;
|
||||
struct socket *so_q0;
|
||||
struct socket *so_q;
|
||||
|
||||
int16 so_q0len;
|
||||
int16 so_qlen;
|
||||
int16 so_qlimit;
|
||||
int32 so_error;
|
||||
// pid_t so_pgid;
|
||||
uint32 so_oobmark;
|
||||
|
||||
/* our send/recv buffers */
|
||||
struct sockbuf so_snd;
|
||||
struct sockbuf so_rcv;
|
||||
|
||||
// event callback
|
||||
socket_event_callback event_callback;
|
||||
void * event_callback_cookie;
|
||||
int sel_ev;
|
||||
};
|
||||
|
||||
/* Select event bit mask */
|
||||
#define SEL_READ 0x01
|
||||
#define SEL_WRITE 0x02
|
||||
#define SEL_EX 0x04
|
||||
|
||||
/*
|
||||
* Socket state bits.
|
||||
*/
|
||||
#define SS_NOFDREF 0x001 /* no file table ref any more */
|
||||
#define SS_ISCONNECTED 0x002 /* socket connected to a peer */
|
||||
#define SS_ISCONNECTING 0x004 /* in process of connecting to peer */
|
||||
#define SS_ISDISCONNECTING 0x008 /* in process of disconnecting */
|
||||
#define SS_CANTSENDMORE 0x010 /* can't send more data to peer */
|
||||
#define SS_CANTRCVMORE 0x020 /* can't receive more data from peer */
|
||||
#define SS_RCVATMARK 0x040 /* at mark on input */
|
||||
#define SS_ISDISCONNECTED 0x800 /* socket disconnected from peer */
|
||||
|
||||
#define SS_PRIV 0x080 /* privileged for broadcast, raw... */
|
||||
#define SS_NBIO 0x100 /* non-blocking ops */
|
||||
#define SS_ASYNC 0x200 /* async i/o notify */
|
||||
#define SS_ISCONFIRMING 0x400 /* deciding to accept connection req */
|
||||
#define SS_CONNECTOUT 0x1000 /* connect, not accept, at this end */
|
||||
|
||||
/* helpful defines... */
|
||||
|
||||
/* adjust counters in sb reflecting freeing of m */
|
||||
#define sbfree(sb, m) { \
|
||||
(sb)->sb_cc -= (m)->m_len; \
|
||||
(sb)->sb_mbcnt -= MSIZE; \
|
||||
if ((m)->m_flags & M_EXT) \
|
||||
(sb)->sb_mbcnt -= (m)->m_ext.ext_size; \
|
||||
}
|
||||
|
||||
#define sbspace(sb) \
|
||||
((uint32) min((int)((sb)->sb_hiwat - (sb)->sb_cc), \
|
||||
(int)((sb)->sb_mbmax - (sb)->sb_mbcnt)))
|
||||
|
||||
/* do we have to send all at once on a socket? */
|
||||
#define sosendallatonce(so) \
|
||||
((so)->so_proto->pr_flags & PR_ATOMIC)
|
||||
|
||||
/* adjust counters in sb reflecting allocation of m */
|
||||
#define sballoc(sb, m) { \
|
||||
(sb)->sb_cc += (m)->m_len; \
|
||||
(sb)->sb_mbcnt += MSIZE; \
|
||||
if ((m)->m_flags & M_EXT) \
|
||||
(sb)->sb_mbcnt += (m)->m_ext.ext_size; \
|
||||
}
|
||||
|
||||
#define soreadable(so) \
|
||||
((so)->so_rcv.sb_cc >= (so)->so_rcv.sb_lowat || \
|
||||
((so)->so_state & SS_CANTRCVMORE) || \
|
||||
(so)->so_qlen || (so)->so_error)
|
||||
|
||||
#define sowriteable(so) \
|
||||
((sbspace(&(so)->so_snd) >= (so)->so_snd.sb_lowat) && \
|
||||
(((so)->so_state & SS_ISCONNECTED) || \
|
||||
(((so)->so_proto->pr_flags & PR_CONNREQUIRED) == 0) || \
|
||||
((so)->so_state & SS_CANTSENDMORE) || (so)->so_error))
|
||||
|
||||
#define M_WAITOK 0x0000
|
||||
#define M_NOWAIT 0x0001
|
||||
|
||||
/*
|
||||
* Set lock on sockbuf sb; sleep if lock is already held.
|
||||
* Unless SB_NOINTR is set on sockbuf, sleep is interruptible.
|
||||
* Returns error without lock if sleep is interrupted.
|
||||
*/
|
||||
#define sblock(sb, wf) ((sb)->sb_flags & SB_LOCK ? \
|
||||
(((wf) == M_WAITOK) ? sb_lock(sb) : EWOULDBLOCK) : \
|
||||
((sb)->sb_flags |= SB_LOCK), 0)
|
||||
|
||||
/* release lock on sockbuf sb */
|
||||
#define sbunlock(sb) { \
|
||||
(sb)->sb_flags &= ~SB_LOCK; \
|
||||
if ((sb)->sb_flags & SB_WANT) { \
|
||||
(sb)->sb_flags &= ~SB_WANT; \
|
||||
wakeup((sb)->sb_sleep); \
|
||||
} \
|
||||
}
|
||||
|
||||
#define sorwakeup(so) sowakeup((so), &(so)->so_rcv)
|
||||
/* we don't handle upcall for sockets */
|
||||
#define sowwakeup(so) sowakeup((so), &(so)->so_snd)
|
||||
|
||||
#ifdef _KERNEL_MODE
|
||||
|
||||
uint32 sb_max;
|
||||
|
||||
/* Function prototypes */
|
||||
|
||||
/* These are the ones we export to libnet.so */
|
||||
|
||||
int initsocket(void **);
|
||||
int socreate (int, struct socket **, int, int);
|
||||
int soshutdown(void *, int);
|
||||
int soclose (void *);
|
||||
|
||||
int sobind (void *, char *, int);
|
||||
int solisten (void *, int);
|
||||
int soconnect (void *, char *, int);
|
||||
int soaccept (void *, void **, void *, int *);
|
||||
|
||||
int writeit (void *, struct iovec *, int);
|
||||
int readit (void *, struct iovec *, int *);
|
||||
int sendit (void *, struct msghdr *, int, int *);
|
||||
int recvit (void *, struct msghdr *, char *, int *);
|
||||
|
||||
//int so_ioctl (void *, int, void *, size_t);
|
||||
int sosysctl (int *, uint, void *, size_t *, void *, size_t);
|
||||
int sosetopt (void *, int, int, const void *, size_t);
|
||||
int sogetopt (void *, int, int, void *, size_t *);
|
||||
|
||||
int sogetpeername(void *, struct sockaddr *, int *);
|
||||
int sogetsockname(void *, struct sockaddr *, int *);
|
||||
|
||||
|
||||
/* these are all private to the stack...although may be shared with
|
||||
* other network modules.
|
||||
*/
|
||||
|
||||
int sosend(struct socket *so, struct mbuf *addr, struct uio *uio,
|
||||
struct mbuf *top, struct mbuf *control, int flags);
|
||||
|
||||
struct socket *sonewconn(struct socket *head, int connstatus);
|
||||
int set_socket_event_callback(void *, socket_event_callback, void *, int);
|
||||
int soreserve (struct socket *so, uint32 sndcc, uint32 rcvcc);
|
||||
|
||||
void sbrelease (struct sockbuf *sb);
|
||||
int sbreserve (struct sockbuf *sb, uint32 cc);
|
||||
void sbdrop (struct sockbuf *sb, int len);
|
||||
void sbdroprecord (struct sockbuf *sb);
|
||||
void sbflush (struct sockbuf *sb);
|
||||
int sbwait (struct sockbuf *sb);
|
||||
void sbappend (struct sockbuf *sb, struct mbuf *m);
|
||||
int sbappendaddr (struct sockbuf *sb, struct sockaddr *asa,
|
||||
struct mbuf *m0, struct mbuf *control);
|
||||
int sbappendcontrol (struct sockbuf *sb, struct mbuf *m0,
|
||||
struct mbuf *control);
|
||||
void sbappendrecord (struct sockbuf *sb, struct mbuf *m0);
|
||||
void sbcheck (struct sockbuf *sb);
|
||||
void sbcompress (struct sockbuf *sb, struct mbuf *m, struct mbuf *n);
|
||||
int soreceive (struct socket *so, struct mbuf **paddr, struct uio *uio,
|
||||
struct mbuf **mp0, struct mbuf **controlp, int *flagsp);
|
||||
void sowakeup(struct socket *so, struct sockbuf *sb);
|
||||
int sbwait(struct sockbuf *sb);
|
||||
|
||||
int sodisconnect(struct socket *);
|
||||
void sofree(struct socket *);
|
||||
|
||||
void sohasoutofband(struct socket *so);
|
||||
void socantsendmore(struct socket *so);
|
||||
void socantrcvmore(struct socket *so);
|
||||
void soisconnected (struct socket *so);
|
||||
void soisconnecting (struct socket *so);
|
||||
void soisdisconnected (struct socket *so);
|
||||
void soisdisconnecting (struct socket *so);
|
||||
void soqinsque (struct socket *head, struct socket *so, int q);
|
||||
int soqremque (struct socket *so, int q);
|
||||
int sorflush(struct socket *so);
|
||||
|
||||
int sb_lock(struct sockbuf *sb);
|
||||
int nsleep(sem_id chan, char *msg, int timeo);
|
||||
void wakeup(sem_id chan);
|
||||
|
||||
#endif /* _NETWORK_STACK */
|
||||
|
||||
#endif /* SYS_SOCKETVAR_H */
|
||||
@@ -0,0 +1,229 @@
|
||||
/*-
|
||||
* Copyright (c) 1982, 1986, 1989, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
* (c) UNIX System Laboratories, Inc.
|
||||
* All or some portions of this file are derived from material licensed
|
||||
* to the University of California by American Telephone and Telegraph
|
||||
* Co. or Unix System Laboratories, Inc. and are reproduced herein with
|
||||
* the permission of UNIX System Laboratories, Inc.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the University of
|
||||
* California, Berkeley and its contributors.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* @(#)stat.h 8.9 (Berkeley) 8/17/94
|
||||
*/
|
||||
|
||||
#ifndef _SYS_STAT_H_
|
||||
#define _SYS_STAT_H_
|
||||
|
||||
//#include <sys/time.h>
|
||||
|
||||
/**
|
||||
* @file stat.h
|
||||
* @brief Stat structures and defines
|
||||
*/
|
||||
|
||||
/**
|
||||
* @defgroup OpenBeOS_POSIX POSIX Headers
|
||||
* @brief Headers to provide the POSIX layer
|
||||
*/
|
||||
|
||||
/**
|
||||
* @defgroup Stat sys/stat.h
|
||||
* @brief Structures and prototypes for stat operations
|
||||
* @ingroup OpenBeOS_POSIX
|
||||
* @{
|
||||
*/
|
||||
|
||||
/* XXX - some types we don't yet have in sys/types.h (because we don't yet
|
||||
* have a sys/types.h and these aren't in ktypes.h!)
|
||||
*/
|
||||
|
||||
#ifdef _KERNEL_MODE_
|
||||
struct ostat {
|
||||
mode_t st_mode; /* inode protection mode */
|
||||
ino_t st_ino; /* inode's number */
|
||||
uint16 st_dev; /* inode's device */
|
||||
nlink_t st_nlink; /* number of hard links */
|
||||
uid_t st_uid; /* user ID of the file's owner */
|
||||
gid_t st_gid; /* group ID of the file's group */
|
||||
off_t st_size; /* file size, in bytes */
|
||||
time_t st_atime; /* time of last access */
|
||||
time_t st_mtime; /* time of last data modification */
|
||||
time_t st_ctime; /* time of last file status change */
|
||||
int64 st_blocks; /* blocks allocated for file */
|
||||
int32 st_blksize; /* optimal blocksize for I/O */
|
||||
};
|
||||
#endif /* _KERNEL_MODE_ */
|
||||
|
||||
/* XXX - The stat structure, as defined by POSIX.
|
||||
* Just implement what we can for the time being.
|
||||
*/
|
||||
struct stat {
|
||||
mode_t st_mode; /* File mode */
|
||||
ino_t st_ino; /* vnode_id */
|
||||
// dev_t st_dev; /* inode's device */
|
||||
nlink_t st_nlink; /* number of hard links */
|
||||
uid_t st_uid; /* user ID of the file's owner */
|
||||
gid_t st_gid; /* group ID of the file's group */
|
||||
off_t st_size; /* file size, in bytes */
|
||||
time_t st_atime; /* time of last access */
|
||||
time_t st_mtime; /* time of last data modification */
|
||||
time_t st_ctime; /* time of last file status change */
|
||||
int64 st_blocks; /* blocks allocated for file */
|
||||
uint32 st_blksize; /* optimal blocksize for I/O */
|
||||
};
|
||||
|
||||
/**
|
||||
* @defgroup POSIX_filemodes File mode defines
|
||||
* @brief Defines of the file modes we allow
|
||||
* @ingroup Stat
|
||||
*@{
|
||||
*/
|
||||
/** set user id on execution */
|
||||
#define S_ISUID 0004000
|
||||
/** set group id on execution */
|
||||
#define S_ISGID 0002000
|
||||
/** sticky bit */
|
||||
#define S_ISTXT 0001000
|
||||
|
||||
/**
|
||||
* @def S_IRWXU RWX mask for owner
|
||||
* @def S_IRUSR R for owner
|
||||
* @def S_IWUSR W for owner
|
||||
* @def S_IXUSR X for owner
|
||||
*/
|
||||
#define S_IRWXU 0000700
|
||||
#define S_IRUSR 0000400
|
||||
#define S_IWUSR 0000200
|
||||
#define S_IXUSR 0000100
|
||||
|
||||
/* @def S_IRWXG RWX mask for group
|
||||
* @def S_IWGRP W for group
|
||||
* @def S_IRGRP R for group
|
||||
* @def S_IXGRP X for group
|
||||
*/
|
||||
#define S_IRWXG 0000070
|
||||
#define S_IRGRP 0000040
|
||||
#define S_IWGRP 0000020
|
||||
#define S_IXGRP 0000010
|
||||
|
||||
#define S_IRWXO 0000007 /* RWX mask for other */
|
||||
#define S_IROTH 0000004 /* R for other */
|
||||
#define S_IWOTH 0000002 /* W for other */
|
||||
#define S_IXOTH 0000001 /* X for other */
|
||||
|
||||
#define S_IFMT 0170000
|
||||
#define S_IFSOCK 0140000
|
||||
#define S_IFIFO 0010000
|
||||
#define S_IFCHR 0020000
|
||||
#define S_IFDIR 0040000
|
||||
#define S_IFBLK 0060000
|
||||
#define S_IFREG 0100000
|
||||
#define S_IFLNK 0120000
|
||||
#define S_IFWHT 0160000
|
||||
#define S_ISVTX 0001000
|
||||
|
||||
#define S_ISDIR(m) ((m & 0170000) == 0040000) /* directory */
|
||||
#define S_ISCHR(m) ((m & 0170000) == 0020000) /* char special */
|
||||
#define S_ISBLK(m) ((m & 0170000) == 0060000) /* block special */
|
||||
#define S_ISREG(m) ((m & 0170000) == 0100000) /* regular file */
|
||||
#define S_ISFIFO(m) ((m & 0170000) == 0010000) /* fifo */
|
||||
#define S_ISLNK(m) ((m & 0170000) == 0120000) /* symbolic link */
|
||||
#define S_ISSOCK(m) ((m & 0170000) == 0140000)/* socket */
|
||||
#define S_ISWHT(m)((m & 0170000) == 0160000)/* whiteout */
|
||||
|
||||
/** 00777 */
|
||||
#define ACCESSPERMS (S_IRWXU | S_IRWXG | S_IRWXO)
|
||||
/** 07777 */
|
||||
#define ALLPERMS (S_ISUID|S_ISGID|S_ISTXT|S_IRWXU|S_IRWXG|S_IRWXO)
|
||||
/** 00666 */
|
||||
#define DEFFILEMODE (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH)
|
||||
|
||||
/** @} */
|
||||
/*
|
||||
* Definitions of flags stored in file flags word.
|
||||
*
|
||||
* Super-user and owner changeable flags.
|
||||
*/
|
||||
#define UF_SETTABLE 0x0000ffff /* mask of owner changeable flags */
|
||||
#define UF_NODUMP 0x00000001 /* do not dump file */
|
||||
#define UF_IMMUTABLE 0x00000002 /* file may not be changed */
|
||||
#define UF_APPEND 0x00000004 /* writes to file may only append */
|
||||
#define UF_OPAQUE 0x00000008 /* directory is opaque wrt. union */
|
||||
/*
|
||||
* Super-user changeable flags.
|
||||
*/
|
||||
#define SF_SETTABLE 0xffff0000 /* mask of superuser changeable flags */
|
||||
#define SF_ARCHIVED 0x00010000 /* file is archived */
|
||||
#define SF_IMMUTABLE 0x00020000 /* file may not be changed */
|
||||
#define SF_APPEND 0x00040000 /* writes to file may only append */
|
||||
|
||||
#ifdef _KERNEL_MODE
|
||||
/*
|
||||
* Shorthand abbreviations of above.
|
||||
*/
|
||||
#define OPAQUE (UF_OPAQUE)
|
||||
#define APPEND (UF_APPEND | SF_APPEND)
|
||||
#define IMMUTABLE (UF_IMMUTABLE | SF_IMMUTABLE)
|
||||
#endif /* _KERNEL_MODE */
|
||||
|
||||
#ifndef _KERNEL_MODE_
|
||||
//#include <sys/cdefs.h>
|
||||
|
||||
/** @fn int chmod(const char *path, mode_t mode)
|
||||
* Changes the file protection modes to those given by mode
|
||||
*
|
||||
* @ref POISX_filemodes
|
||||
*/
|
||||
int chmod (const char *, mode_t);
|
||||
/** @fn int fstat(int fd, struct stat *stat)
|
||||
* get file information on a file identified by descriptor fd
|
||||
*
|
||||
* @ref stat
|
||||
*/
|
||||
int fstat (int, struct stat *);
|
||||
//int mknod (const char *, mode_t, dev_t);
|
||||
int mkdir (const char *, mode_t);
|
||||
int mkfifo (const char *, mode_t);
|
||||
/** @fn int stat(const char *path, struct stat *stat)
|
||||
* Get file information for file path and store it in the structure
|
||||
* stat
|
||||
*
|
||||
* @ref stat
|
||||
*/
|
||||
int stat (const char *, struct stat *);
|
||||
mode_t umask (mode_t);
|
||||
int fchmod (int, mode_t);
|
||||
int lstat (const char *, struct stat *);
|
||||
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
|
||||
#endif /* !_SYS_STAT_H_ */
|
||||
@@ -0,0 +1,41 @@
|
||||
/* uio.h */
|
||||
|
||||
#ifndef _SYS_UIO_H
|
||||
#define _SYS_UIO_H
|
||||
|
||||
#include <ktypes.h>
|
||||
|
||||
typedef struct iovec {
|
||||
void *iov_base;
|
||||
size_t iov_len;
|
||||
} iovec;
|
||||
|
||||
|
||||
#ifdef _KERNEL_MODE
|
||||
enum uio_rw { UIO_READ, UIO_WRITE };
|
||||
|
||||
/* Segment flag values. */
|
||||
enum uio_seg {
|
||||
UIO_USERSPACE, /* from user data space */
|
||||
UIO_SYSSPACE /* from system space */
|
||||
};
|
||||
|
||||
struct uio {
|
||||
struct iovec *uio_iov; /* pointer to array of iovecs */
|
||||
int uio_iovcnt; /* number of iovecs in array */
|
||||
off_t uio_offset; /* offset into file this uio corresponds to */
|
||||
size_t uio_resid; /* residual i/o count */
|
||||
enum uio_seg uio_segflg; /* see above */
|
||||
enum uio_rw uio_rw; /* see above */
|
||||
// struct proc *uio_procp; /* process if UIO_USERSPACE */
|
||||
};
|
||||
|
||||
int uiomove(char *cp, int n, struct uio *uio);
|
||||
#endif
|
||||
|
||||
ssize_t readv(int fd, const struct iovec *vector, size_t count);
|
||||
ssize_t readv_pos(int fd, off_t pos, const struct iovec *vec, size_t count);
|
||||
ssize_t writev(int fd, const struct iovec *vector, size_t count);
|
||||
ssize_t writev_pos(int fd, off_t pos, const struct iovec *vec, size_t count);
|
||||
|
||||
#endif /* _SYS_UIO_H */
|
||||
Executable
+128
@@ -0,0 +1,128 @@
|
||||
/*
|
||||
** Copyright 2001, Travis Geiselbrecht. All rights reserved.
|
||||
** Distributed under the terms of the NewOS License.
|
||||
*/
|
||||
#ifndef _LIBSYS_SYSCALLS_H
|
||||
#define _LIBSYS_SYSCALLS_H
|
||||
|
||||
#include <ktypes.h>
|
||||
#include <types.h>
|
||||
#include <defines.h>
|
||||
#include <resource.h>
|
||||
#include <vfs_types.h>
|
||||
#include <vm_types.h>
|
||||
#include <thread_types.h>
|
||||
#include <OS.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
int sys_null();
|
||||
|
||||
/* fs api */
|
||||
int sys_mount(const char *path, const char *device, const char *fs_name, void *args);
|
||||
int sys_unmount(const char *path);
|
||||
int sys_sync();
|
||||
int sys_open(const char *path, stream_type st, int omode);
|
||||
int sys_close(int fd);
|
||||
int sys_fsync(int fd);
|
||||
ssize_t sys_read(int fd, void *buf, off_t pos, size_t len);
|
||||
ssize_t sys_write(int fd, const void *buf, off_t pos, size_t len);
|
||||
int sys_seek(int fd, off_t pos, int seek_type);
|
||||
int sys_ioctl(int fd, ulong op, void *buf);
|
||||
int sys_create(const char *path, stream_type stream_type);
|
||||
int sys_unlink(const char *path);
|
||||
int sys_rename(const char *oldpath, const char *newpath);
|
||||
int sys_rstat(const char *path, struct stat *stat);
|
||||
int sys_wstat(const char *path, struct stat *stat, int stat_mask);
|
||||
int sys_fstat(int, struct stat *);
|
||||
char *sys_getcwd(char* buf, size_t size);
|
||||
int sys_setcwd(const char* path);
|
||||
int sys_dup(int fd);
|
||||
int sys_dup2(int ofd, int nfd);
|
||||
|
||||
bigtime_t sys_system_time();
|
||||
int sys_snooze(bigtime_t time);
|
||||
int sys_getrlimit(int resource, struct rlimit * rlp);
|
||||
int sys_setrlimit(int resource, const struct rlimit * rlp);
|
||||
|
||||
/* sem functions */
|
||||
sem_id kern_create_sem(int count, const char *name);
|
||||
int kern_delete_sem(sem_id id);
|
||||
int kern_acquire_sem(sem_id id);
|
||||
int kern_acquire_sem_etc(sem_id id, int count, int flags, bigtime_t timeout);
|
||||
int kern_release_sem(sem_id id);
|
||||
int kern_release_sem_etc(sem_id id, int count, int flags);
|
||||
int sys_sem_get_count(sem_id id, int32* thread_count);
|
||||
int kern_get_sem_info(sem_id, struct sem_info *, size_t);
|
||||
int kern_get_next_sem_info(proc_id, uint32 *, struct sem_info *, size_t);
|
||||
int sys_set_sem_owner(sem_id id, proc_id proc);
|
||||
|
||||
|
||||
int sys_proc_get_table(struct proc_info *pi, size_t len);
|
||||
void sys_exit(int retcode);
|
||||
proc_id sys_proc_create_proc(const char *path, const char *name, char **args, int argc, int priority);
|
||||
|
||||
thread_id kern_spawn_thread(int (*func)(void*), const char *, int, void *);
|
||||
thread_id kern_get_current_thread_id(void);
|
||||
int kern_suspend_thread(thread_id tid);
|
||||
int kern_resume_thread(thread_id tid);
|
||||
int kern_kill_thread(thread_id tid);
|
||||
|
||||
int sys_thread_wait_on_thread(thread_id tid, int *retcode);
|
||||
int sys_proc_kill_proc(proc_id pid);
|
||||
|
||||
proc_id sys_get_current_proc_id();
|
||||
int sys_proc_wait_on_proc(proc_id pid, int *retcode);
|
||||
|
||||
region_id sys_vm_create_anonymous_region(const char *name, void **address, int addr_type,
|
||||
addr size, int wiring, int lock);
|
||||
region_id sys_vm_clone_region(const char *name, void **address, int addr_type,
|
||||
region_id source_region, int mapping, int lock);
|
||||
region_id sys_vm_map_file(const char *name, void **address, int addr_type,
|
||||
addr size, int lock, int mapping, const char *path, off_t offset);
|
||||
int sys_vm_delete_region(region_id id);
|
||||
int sys_vm_get_region_info(region_id id, vm_region_info *info);
|
||||
|
||||
/* kernel port functions */
|
||||
port_id sys_port_create(int32 queue_length, const char *name);
|
||||
int sys_port_close(port_id id);
|
||||
int sys_port_delete(port_id id);
|
||||
port_id sys_port_find(const char *port_name);
|
||||
int sys_port_get_info(port_id id, struct port_info *info);
|
||||
int sys_port_get_next_port_info(proc_id proc, uint32 *cookie, struct port_info *info);
|
||||
ssize_t sys_port_buffer_size(port_id port);
|
||||
ssize_t sys_port_buffer_size_etc(port_id port, uint32 flags, bigtime_t timeout);
|
||||
int32 sys_port_count(port_id port);
|
||||
ssize_t sys_port_read(port_id port, int32 *msg_code, void *msg_buffer, size_t buffer_size);
|
||||
ssize_t sys_port_read_etc(port_id port, int32 *msg_code, void *msg_buffer, size_t buffer_size, uint32 flags, bigtime_t timeout);
|
||||
int sys_port_set_owner(port_id port, team_id proc);
|
||||
int sys_port_write(port_id port, int32 msg_code, const void *msg_buffer, size_t buffer_size);
|
||||
int sys_port_write_etc(port_id port, int32 msg_code, const void *msg_buffer, size_t buffer_size, uint32 flags, bigtime_t timeout);
|
||||
|
||||
/* atomic_* ops (needed for cpus that dont support them directly) */
|
||||
int sys_atomic_add(int *val, int incr);
|
||||
int sys_atomic_and(int *val, int incr);
|
||||
int sys_atomic_or(int *val, int incr);
|
||||
int sys_atomic_set(int *val, int set_to);
|
||||
int sys_test_and_set(int *val, int set_to, int test_val);
|
||||
|
||||
int sys_sysctl(int *, uint, void *, size_t *, void *, size_t);
|
||||
int sys_socket(int, int, int);
|
||||
|
||||
/* region prototypes */
|
||||
area_id sys_find_region_by_name(const char *);
|
||||
|
||||
/* This is a real BSD'ism :) Basically it returns the size of the
|
||||
* descriptor table for the current process as an integer.
|
||||
*/
|
||||
int kern_getdtablesize(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,172 @@
|
||||
#ifndef _KERNEL_THREAD_TYPES_H
|
||||
#define _KERNEL_THREAD_TYPES_H
|
||||
|
||||
/**
|
||||
* @file kernel/thread_types.h
|
||||
* @brief Definitions, structures and functions for threads.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @defgroup Kernel_Threads Threads
|
||||
* @ingroup OpenBeOS_Kernel
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stage2.h>
|
||||
#include <ktypes.h>
|
||||
#include <vm.h>
|
||||
#include <smp.h>
|
||||
#include <arch/thread_struct.h>
|
||||
|
||||
|
||||
#define THREAD_IDLE_PRIORITY 0
|
||||
|
||||
#define THREAD_NUM_PRIORITY_LEVELS 64
|
||||
#define THREAD_MIN_PRIORITY (THREAD_IDLE_PRIORITY + 1)
|
||||
#define THREAD_MAX_PRIORITY (THREAD_NUM_PRIORITY_LEVELS - THREAD_NUM_RT_PRIORITY_LEVELS - 1)
|
||||
|
||||
#define THREAD_NUM_RT_PRIORITY_LEVELS 16
|
||||
#define THREAD_MIN_RT_PRIORITY (THREAD_MAX_PRIORITY + 1)
|
||||
#define THREAD_MAX_RT_PRIORITY (THREAD_NUM_PRIORITY_LEVELS - 1)
|
||||
|
||||
#define THREAD_LOWEST_PRIORITY THREAD_MIN_PRIORITY
|
||||
#define THREAD_LOW_PRIORITY 12
|
||||
#define THREAD_MEDIUM_PRIORITY 24
|
||||
#define THREAD_HIGH_PRIORITY 36
|
||||
#define THREAD_HIGHEST_PRIORITY THREAD_MAX_PRIORITY
|
||||
|
||||
#define THREAD_RT_LOW_PRIORITY THREAD_MIN_RT_PRIORITY
|
||||
#define THREAD_RT_HIGH_PRIORITY THREAD_MAX_RT_PRIORITY
|
||||
|
||||
extern spinlock_t thread_spinlock;
|
||||
#define GRAB_THREAD_LOCK() acquire_spinlock(&thread_spinlock)
|
||||
#define RELEASE_THREAD_LOCK() release_spinlock(&thread_spinlock)
|
||||
|
||||
enum {
|
||||
THREAD_STATE_READY = 0, // ready to run
|
||||
THREAD_STATE_RUNNING, // running right now somewhere
|
||||
THREAD_STATE_WAITING, // blocked on something
|
||||
THREAD_STATE_SUSPENDED, // suspended, not in queue
|
||||
THREAD_STATE_FREE_ON_RESCHED, // free the thread structure upon reschedule
|
||||
THREAD_STATE_BIRTH // thread is being created
|
||||
};
|
||||
|
||||
enum {
|
||||
PROC_STATE_NORMAL, // normal state
|
||||
PROC_STATE_BIRTH, // being contructed
|
||||
PROC_STATE_DEATH // being killed
|
||||
};
|
||||
|
||||
#define SIG_NONE 0
|
||||
#define SIG_SUSPEND 1
|
||||
#define SIG_KILL 2
|
||||
|
||||
/**
|
||||
* The proc structure.
|
||||
* @note This is available only within the kernel.
|
||||
*/
|
||||
struct proc {
|
||||
/** Pointer to next proc structure */
|
||||
struct proc *next;
|
||||
/** The proc_id for this process.
|
||||
* @note This is equivalent to a team_id (???)
|
||||
*/
|
||||
proc_id id;
|
||||
/** name of the process
|
||||
* @note The maximum length is current SYS_MAX_OS_NAME_LEN chars.
|
||||
*/
|
||||
char name[SYS_MAX_OS_NAME_LEN];
|
||||
/** How many threads does this process have? */
|
||||
int num_threads;
|
||||
/** Current state of the process. */
|
||||
int state;
|
||||
/** Signals pending for the process? */
|
||||
int pending_signals;
|
||||
/** Pointer to the I/O context for this process.
|
||||
* @note see fd.h for definition of ioctx
|
||||
*/
|
||||
void *ioctx;
|
||||
/** Path ??? */
|
||||
char path[SYS_MAX_PATH_LEN];
|
||||
/** Our address space pointer */
|
||||
aspace_id _aspace_id;
|
||||
vm_address_space *aspace;
|
||||
vm_address_space *kaspace;
|
||||
struct thread *main_thread;
|
||||
struct thread *thread_list;
|
||||
struct arch_proc arch_info;
|
||||
};
|
||||
|
||||
struct thread {
|
||||
struct thread *all_next;
|
||||
struct thread *proc_next;
|
||||
struct thread *q_next;
|
||||
thread_id id;
|
||||
char name[SYS_MAX_OS_NAME_LEN];
|
||||
int priority;
|
||||
int state;
|
||||
int next_state;
|
||||
union cpu_ent *cpu;
|
||||
int pending_signals;
|
||||
bool in_kernel;
|
||||
sem_id sem_blocking;
|
||||
int sem_count;
|
||||
int sem_acquire_count;
|
||||
int sem_deleted_retcode;
|
||||
int sem_errcode;
|
||||
int sem_flags;
|
||||
addr fault_handler;
|
||||
addr entry;
|
||||
void *args;
|
||||
struct proc *proc;
|
||||
sem_id return_code_sem;
|
||||
region_id kernel_stack_region_id;
|
||||
addr kernel_stack_base;
|
||||
region_id user_stack_region_id;
|
||||
addr user_stack_base;
|
||||
|
||||
bigtime_t user_time;
|
||||
bigtime_t kernel_time;
|
||||
bigtime_t last_time;
|
||||
|
||||
// architecture dependant section
|
||||
struct arch_thread arch_info;
|
||||
};
|
||||
|
||||
struct thread_queue {
|
||||
struct thread *head;
|
||||
struct thread *tail;
|
||||
};
|
||||
|
||||
/**
|
||||
* Process information structure
|
||||
* @note Seem to be a lot of duplicated fields with main
|
||||
* proc structure???
|
||||
*/
|
||||
struct proc_info {
|
||||
proc_id id;
|
||||
char name[SYS_MAX_OS_NAME_LEN];
|
||||
int state;
|
||||
int num_threads;
|
||||
};
|
||||
|
||||
#if 1
|
||||
/**
|
||||
* Test routine for threads.
|
||||
* @note This function will be removed as is intended for test and
|
||||
* development purposes only.
|
||||
*/
|
||||
int thread_test(void);
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
/** @} */
|
||||
|
||||
#endif /* _KERNEL_THREAD_TYPES_H */
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
#ifndef VFS_TYPES_H
|
||||
#define VFS_TYPES_H
|
||||
|
||||
#include <sys/uio.h>
|
||||
|
||||
typedef enum {
|
||||
STREAM_TYPE_ANY = 0,
|
||||
STREAM_TYPE_FILE,
|
||||
STREAM_TYPE_DIR,
|
||||
STREAM_TYPE_DEVICE
|
||||
} stream_type;
|
||||
|
||||
typedef void * fs_cookie;
|
||||
typedef void * file_cookie;
|
||||
typedef void * fs_vnode;
|
||||
|
||||
//typedef struct iovec {
|
||||
// void *start;
|
||||
// size_t len;
|
||||
//} iovec;
|
||||
|
||||
typedef struct iovecs {
|
||||
size_t num;
|
||||
size_t total_len;
|
||||
iovec vec[0];
|
||||
} iovecs;
|
||||
|
||||
//struct file_stat {
|
||||
// vnode_id vnid;
|
||||
// stream_type type;
|
||||
// off_t size;
|
||||
//};
|
||||
|
||||
#endif
|
||||
|
||||
Executable
+183
@@ -0,0 +1,183 @@
|
||||
#ifndef _PUBLIC_KERNEL_VM_TYPES_H
|
||||
#define _PUBLIC_KERNEL_VM_TYPES_H
|
||||
|
||||
#include <kernel.h>
|
||||
#include <stage2.h>
|
||||
#include <defines.h>
|
||||
#include <vfs.h>
|
||||
#include <arch/vm_translation_map.h>
|
||||
|
||||
// vm page
|
||||
typedef struct vm_page {
|
||||
struct vm_page *queue_prev;
|
||||
struct vm_page *queue_next;
|
||||
|
||||
struct vm_page *hash_next;
|
||||
|
||||
addr ppn; // physical page number
|
||||
off_t offset;
|
||||
|
||||
struct vm_cache_ref *cache_ref;
|
||||
|
||||
struct vm_page *cache_prev;
|
||||
struct vm_page *cache_next;
|
||||
|
||||
unsigned int ref_count;
|
||||
|
||||
unsigned int type : 2;
|
||||
unsigned int state : 3;
|
||||
} vm_page;
|
||||
|
||||
enum {
|
||||
PAGE_TYPE_PHYSICAL = 0,
|
||||
PAGE_TYPE_DUMMY,
|
||||
PAGE_TYPE_GUARD
|
||||
};
|
||||
|
||||
enum {
|
||||
PAGE_STATE_ACTIVE = 0,
|
||||
PAGE_STATE_INACTIVE,
|
||||
PAGE_STATE_BUSY,
|
||||
PAGE_STATE_MODIFIED,
|
||||
PAGE_STATE_FREE,
|
||||
PAGE_STATE_CLEAR,
|
||||
PAGE_STATE_WIRED,
|
||||
PAGE_STATE_UNUSED
|
||||
};
|
||||
|
||||
// vm_cache_ref
|
||||
typedef struct vm_cache_ref {
|
||||
struct vm_cache *cache;
|
||||
mutex lock;
|
||||
|
||||
struct vm_region *region_list;
|
||||
|
||||
int ref_count;
|
||||
} vm_cache_ref;
|
||||
|
||||
// vm_cache
|
||||
typedef struct vm_cache {
|
||||
vm_page *page_list;
|
||||
vm_cache_ref *ref;
|
||||
struct vm_cache *source;
|
||||
struct vm_store *store;
|
||||
off_t virtual_size;
|
||||
unsigned int temporary : 1;
|
||||
unsigned int scan_skip : 1;
|
||||
} vm_cache;
|
||||
|
||||
// info about a region that external entities may want to know
|
||||
// used in vm_get_region_info()
|
||||
typedef struct vm_region_info {
|
||||
region_id id;
|
||||
addr base;
|
||||
addr size;
|
||||
int lock;
|
||||
int wiring;
|
||||
char name[SYS_MAX_OS_NAME_LEN];
|
||||
} vm_region_info;
|
||||
|
||||
// vm region
|
||||
typedef struct vm_region {
|
||||
char *name;
|
||||
region_id id;
|
||||
addr base;
|
||||
addr size;
|
||||
int lock;
|
||||
int wiring;
|
||||
int ref_count;
|
||||
|
||||
struct vm_cache_ref *cache_ref;
|
||||
off_t cache_offset;
|
||||
|
||||
struct vm_address_space *aspace;
|
||||
struct vm_region *aspace_next;
|
||||
struct vm_virtual_map *map;
|
||||
struct vm_region *cache_next;
|
||||
struct vm_region *cache_prev;
|
||||
struct vm_region *hash_next;
|
||||
} vm_region;
|
||||
|
||||
// virtual map (1 per address space)
|
||||
typedef struct vm_virtual_map {
|
||||
vm_region *region_list;
|
||||
vm_region *region_hint;
|
||||
int change_count;
|
||||
sem_id sem;
|
||||
struct vm_address_space *aspace;
|
||||
addr base;
|
||||
addr size;
|
||||
} vm_virtual_map;
|
||||
|
||||
enum {
|
||||
VM_ASPACE_STATE_NORMAL = 0,
|
||||
VM_ASPACE_STATE_DELETION
|
||||
};
|
||||
|
||||
// address space
|
||||
typedef struct vm_address_space {
|
||||
vm_virtual_map virtual_map;
|
||||
vm_translation_map translation_map;
|
||||
char *name;
|
||||
aspace_id id;
|
||||
int ref_count;
|
||||
int fault_count;
|
||||
int state;
|
||||
addr scan_va;
|
||||
addr working_set_size;
|
||||
addr max_working_set;
|
||||
addr min_working_set;
|
||||
bigtime_t last_working_set_adjust;
|
||||
struct vm_address_space *hash_next;
|
||||
} vm_address_space;
|
||||
|
||||
// vm_store
|
||||
typedef struct vm_store {
|
||||
struct vm_store_ops *ops;
|
||||
struct vm_cache *cache;
|
||||
void *data;
|
||||
off_t committed_size;
|
||||
} vm_store;
|
||||
|
||||
// vm_store_ops
|
||||
typedef struct vm_store_ops {
|
||||
void (*destroy)(struct vm_store *backing_store);
|
||||
off_t (*commit)(struct vm_store *backing_store, off_t size);
|
||||
int (*has_page)(struct vm_store *backing_store, off_t offset);
|
||||
ssize_t (*read)(struct vm_store *backing_store, off_t offset, iovecs *vecs);
|
||||
ssize_t (*write)(struct vm_store *backing_store, off_t offset, iovecs *vecs);
|
||||
int (*fault)(struct vm_store *backing_store, struct vm_address_space *aspace, off_t offset);
|
||||
void (*acquire_ref)(struct vm_store *backing_store);
|
||||
void (*release_ref)(struct vm_store *backing_store);
|
||||
} vm_store_ops;
|
||||
|
||||
// args for the create_area funcs
|
||||
enum {
|
||||
REGION_ADDR_ANY_ADDRESS = 0,
|
||||
REGION_ADDR_EXACT_ADDRESS
|
||||
};
|
||||
|
||||
enum {
|
||||
REGION_NO_PRIVATE_MAP = 0,
|
||||
REGION_PRIVATE_MAP
|
||||
};
|
||||
|
||||
enum {
|
||||
REGION_WIRING_LAZY = 0,
|
||||
REGION_WIRING_WIRED,
|
||||
REGION_WIRING_WIRED_ALREADY,
|
||||
REGION_WIRING_WIRED_CONTIG
|
||||
};
|
||||
|
||||
enum {
|
||||
PHYSICAL_PAGE_NO_WAIT = 0,
|
||||
PHYSICAL_PAGE_CAN_WAIT,
|
||||
};
|
||||
|
||||
#define LOCK_RO 0x0
|
||||
#define LOCK_RW 0x1
|
||||
#define LOCK_KERNEL 0x2
|
||||
#define LOCK_MASK 0x3
|
||||
|
||||
#endif /* _PUBLIC_KERNEL_VM_TYPES_H */
|
||||
|
||||
Reference in New Issue
Block a user