Implemented some more calls in unistd.h.

Replaced the unused syscall for getdtablesize() with one for access().
Implemented sys_access() and added it to the file system interface.
Removed the fs function interface from vfs.h.


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@738 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler 2002-08-13 13:51:36 +00:00
parent 9c3e90a54e
commit 854fc92a7c
9 changed files with 95 additions and 118 deletions

View File

@ -67,7 +67,7 @@ extern "C" {
// ToDo: unimplemented functions are commented out
/* file functions */
//extern int access(const char *path, int amode);
extern int access(const char *path, int accessMode);
extern int chdir(const char *path);
extern int fchdir(int fd);
@ -84,8 +84,8 @@ extern int close(int fd);
extern ssize_t readlink(const char *path, char *buffer, size_t bufferSize);
extern int symlink(const char *from, const char *to);
//extern int ftruncate(int fd, off_t newsize);
//extern int truncate(const char *path, off_t newsize);
extern int ftruncate(int fd, off_t newSize);
extern int truncate(const char *path, off_t newSize);
extern int ioctl(int fd, unsigned long op, ...);
extern ssize_t read(int fd, void *buffer, size_t count);
@ -99,9 +99,9 @@ extern off_t lseek(int fd, off_t offset, int whence);
//extern int sync(void);
//extern int fsync(int fd);
//extern int chown(const char *path, uid_t owner, gid_t group);
//extern int fchown(int fd, uid_t owner, gid_t group);
//extern int lchown(const char *path, uid_t owner, gid_t group);
extern int chown(const char *path, uid_t owner, gid_t group);
extern int fchown(int fd, uid_t owner, gid_t group);
extern int lchown(const char *path, uid_t owner, gid_t group);
//extern int mknod(const char *name, mode_t mode, dev_t dev);
@ -121,19 +121,19 @@ extern long pathconf(const char *path, int name);
/* process functions */
//extern pid_t fork(void);
//extern int execve(const char *path, char * const argv[], char * const envp[]);
//extern int execl(const char *path, const char *arg, ...);
//extern int execv(const char *path, char *const *argv);
//extern int execlp(const char *file, const char *arg, ...);
//extern int execle(const char *path, const char *arg , ... /*, char **envp */);
//extern int exect(const char *path, char *const *argv);
//extern int execvp(const char *file, char *const *argv);
//extern int execl(const char *path, const char *arg, ...);
//extern int execv(const char *path, char *const *argv);
//extern int execlp(const char *file, const char *arg, ...);
//extern int execle(const char *path, const char *arg , ... /*, char **envp */);
//extern int exect(const char *path, char *const *argv);
//extern int execvp(const char *file, char *const *argv);
//extern void _exit(int status);
//extern int system(const char *string);
//extern pid_t tcgetpgrp(int fd);
//extern int tcsetpgrp(int fd, pid_t pgrpid);
//extern void *sbrk(long incr);
//extern pid_t tcgetpgrp(int fd);
//extern int tcsetpgrp(int fd, pid_t pgrpid);
//extern void *sbrk(long incr);
//extern uint alarm(unsigned int seconds);
//extern uint ualarm(unsigned int microSeconds);
@ -164,13 +164,13 @@ extern int usleep(unsigned int microSeconds);
/* tty */
//extern int isatty(int fd);
//extern char *ttyname(int fd);
//extern char *ttyname(int fd);
//extern int ttyname_r(int fd, char *buf, size_t buflen);
//extern char *ctermid(char *s);
//extern char *ctermid(char *s);
/* misc */
//extern char *crypt(const char *key, const char *salt);
extern int getopt(int argc, char *const *argv, const char *shortopts);
extern int getopt(int argc, char *const *argv, const char *shortopts);
/* getopt() related external variables */
extern char *optarg;

View File

@ -81,8 +81,8 @@ enum {
SYSCALL_TEST_AND_SET, /* 70 */
SYSCALL_SYSCTL,
SYSCALL_SOCKET,
SYSCALL_GETDTABLESIZE, /* ToDo: to be removed, can be reused */
SYSCALL_FD_STAT,
SYSCALL_ACCESS,
SYSCALL_READ_STAT_FD,
SYSCALL_READ_DIR,
SYSCALL_REWIND_DIR,
SYSCALL_OPEN_DIR,

View File

@ -10,6 +10,7 @@
#include <stage2.h>
#include <sys/stat.h>
#include <dirent.h>
#include <fs_interface.h>
#define DEFAULT_FD_TABLE_SIZE 128
#define MAX_FD_TABLE_SIZE 2048
@ -21,100 +22,11 @@
uint8 _##name[sizeof(iovecs) + (size)*sizeof(iovec)]; \
iovecs *name = (iovecs *)_##name
struct fs_info;
typedef void *fs_cookie;
typedef void *file_cookie;
typedef void *fs_vnode;
#ifdef __cplusplus
extern "C" {
#endif
struct fs_calls {
/* general operations */
int (*fs_mount)(fs_id id, const char *device, void *args, fs_cookie *_fs, vnode_id *_rootVnodeID);
int (*fs_unmount)(fs_cookie fs);
int (*fs_read_fs_info)(fs_cookie fs, struct fs_info *info);
int (*fs_write_fs_info)(fs_cookie fs, const struct fs_info *info, int mask);
int (*fs_sync)(fs_cookie fs);
/* vnode operations */
int (*fs_lookup)(fs_cookie fs, fs_vnode dir, const char *name, vnode_id *_id, int *_type);
int (*fs_get_vnode_name)(fs_cookie fs, fs_vnode vnode, char *buffer, size_t bufferSize);
int (*fs_get_vnode)(fs_cookie fs, vnode_id id, fs_vnode *_vnode, bool reenter);
int (*fs_put_vnode)(fs_cookie fs, fs_vnode vnode, bool reenter);
int (*fs_remove_vnode)(fs_cookie fs, fs_vnode vnode, bool reenter);
/* VM file access */
int (*fs_can_page)(fs_cookie fs, fs_vnode v);
ssize_t (*fs_read_page)(fs_cookie fs, fs_vnode v, iovecs *vecs, off_t pos);
ssize_t (*fs_write_page)(fs_cookie fs, fs_vnode v, iovecs *vecs, off_t pos);
/* common operations */
int (*fs_ioctl)(fs_cookie fs, fs_vnode v, file_cookie cookie, ulong op, void *buffer, size_t length);
int (*fs_fsync)(fs_cookie fs, fs_vnode v);
int (*fs_read_link)(fs_cookie fs, fs_vnode link, char *buffer, size_t bufferSize);
int (*fs_write_link)(fs_cookie fs, fs_vnode link, char *toPath);
int (*fs_symlink)(fs_cookie fs, fs_vnode dir, const char *name, const char *path, int mode);
int (*fs_unlink)(fs_cookie fs, fs_vnode dir, const char *name);
int (*fs_rename)(fs_cookie fs, fs_vnode olddir, const char *oldname, fs_vnode newdir, const char *newname);
int (*fs_read_stat)(fs_cookie fs, fs_vnode v, struct stat *stat);
int (*fs_write_stat)(fs_cookie fs, fs_vnode v, const struct stat *stat, int statMask);
/* file operations */
int (*fs_create)(fs_cookie fs, fs_vnode dir, const char *name, int omode, int perms, file_cookie *_cookie, vnode_id *_newVnodeID);
int (*fs_open)(fs_cookie fs, fs_vnode v, int oflags, file_cookie *_cookie);
int (*fs_close)(fs_cookie fs, fs_vnode v, file_cookie cookie);
int (*fs_free_cookie)(fs_cookie fs, fs_vnode v, file_cookie cookie);
ssize_t (*fs_read)(fs_cookie fs, fs_vnode v, file_cookie cookie, off_t pos, void *buffer, size_t *length);
ssize_t (*fs_write)(fs_cookie fs, fs_vnode v, file_cookie cookie, off_t pos, const void *buffer, size_t *length);
off_t (*fs_seek)(fs_cookie fs, fs_vnode v, file_cookie cookie, off_t pos, int seekType);
/* directory operations */
int (*fs_create_dir)(fs_cookie fs, fs_vnode parent, const char *name, int perms, vnode_id *_newVnodeID);
int (*fs_open_dir)(fs_cookie fs, fs_vnode v, file_cookie *_cookie);
int (*fs_close_dir)(fs_cookie fs, fs_vnode v, file_cookie cookie);
int (*fs_free_dir_cookie)(fs_cookie fs, fs_vnode v, file_cookie cookie);
int (*fs_read_dir)(fs_cookie fs, fs_vnode v, file_cookie cookie, struct dirent *buffer, size_t bufferSize, uint32 *_num);
int (*fs_rewind_dir)(fs_cookie fs, fs_vnode v, file_cookie cookie);
/* attribute directory operations */
// int (*fs_open_attr_dir)(fs_cookie fs, fs_vnode v, file_cookie *cookie, int oflags);
// int (*fs_close_attr_dir)(fs_cookie fs, fs_vnode v, file_cookie cookie);
// int (*fs_free_attr_dir_cookie)(fs_cookie fs, fs_vnode v, file_cookie cookie);
// int (*fs_read_attr_dir)(fs_cookie fs, fs_vnode v, file_cookie cookie, struct dirent *buffer, size_t bufferSize, uint32 *_num);
// int (*fs_rewind_attr_dir)(fs_cookie fs, fs_vnode v, file_cookie cookie);
//
// /* attribute operations */
// int (*fs_open_attr)(fs_cookie fs, fs_vnode v, file_cookie *cookie, stream_type st, int oflags);
// int (*fs_close_attr)(fs_cookie fs, fs_vnode v, file_cookie cookie);
// int (*fs_free_attr_cookie)(fs_cookie fs, fs_vnode v, file_cookie cookie);
// ssize_t (*fs_read_attr)(fs_cookie fs, fs_vnode v, file_cookie cookie, void *buf, off_t pos, size_t *len);
// ssize_t (*fs_write_attr)(fs_cookie fs, fs_vnode v, file_cookie cookie, const void *buf, off_t pos, size_t *len);
// int (*fs_seek_attr)(fs_cookie fs, fs_vnode v, file_cookie cookie, off_t pos, int st);
// int (*fs_rename_attr)(fs_cookie fs, fs_vnode file, const char *oldname, const char *newname);
//
// /* index directory & index operations */
// int (*fs_open_index_dir)(fs_cookie fs, fs_vnode v, file_cookie *cookie, int oflags);
// int (*fs_close_index_dir)(fs_cookie fs, fs_vnode v, file_cookie cookie);
// int (*fs_free_index_dir_cookie)(fs_cookie fs, fs_vnode v, file_cookie cookie);
// int (*fs_read_index_dir)(fs_cookie fs, fs_vnode v, file_cookie cookie, struct dirent *buffer, size_t bufferSize, uint32 *_num);
// int (*fs_rewind_index_dir)(fs_cookie fs, fs_vnode v, file_cookie cookie);
//
// /* query operations */
// int (*fs_open_query)(fs_cookie fs, fs_vnode v, file_cookie *cookie, int oflags);
// int (*fs_close_query)(fs_cookie fs, fs_vnode v, file_cookie cookie);
// int (*fs_free_query_cookie)(fs_cookie fs, fs_vnode v, file_cookie cookie);
// int (*fs_read_query)(fs_cookie fs, fs_vnode v, file_cookie cookie, struct dirent *buffer, size_t bufferSize, uint32 *_num);
// int (*fs_rewind_query)(fs_cookie fs, fs_vnode v, file_cookie cookie);
};
int vfs_init(kernel_args *ka);
int vfs_bootstrap_all_filesystems(void);
int vfs_register_filesystem(const char *name, struct fs_calls *calls);
@ -165,6 +77,7 @@ int sys_write_link(const char *path, const char *toPath);
int sys_create_symlink(const char *path, const char *toPath, int mode);
int sys_unlink(const char *path);
int sys_rename(const char *oldpath, const char *newpath);
int sys_access(const char *path, int mode);
int sys_read_stat(const char *path, bool traverseLink, struct stat *stat);
int sys_write_stat(int fd, const char *path, bool traverseLink, struct stat *stat, int statMask);
int sys_getcwd(char *buffer, size_t size);
@ -190,6 +103,7 @@ int user_write_link(const char *path, const char *toPath);
int user_create_symlink(const char *path, const char *toPath, int mode);
int user_unlink(const char *path);
int user_rename(const char *oldpath, const char *newpath);
int user_access(const char *path, int mode);
int user_read_stat(const char *path, bool traverseLink, struct stat *stat);
int user_write_stat(int fd, const char *path, bool traverseLink, struct stat *stat, int statMask);
int user_getcwd(char *buffer, size_t size);

View File

@ -348,6 +348,8 @@ KernelStaticLibraryObjects libc.a :
<$(SOURCE_GRIST)!libc!system>wrappers.o
<$(SOURCE_GRIST)!libc!system!arch!$(OBOS_ARCH)>atomic.o
<$(SOURCE_GRIST)!libc!unistd>access.o
<$(SOURCE_GRIST)!libc!unistd>chown.o
<$(SOURCE_GRIST)!libc!unistd>close.o
<$(SOURCE_GRIST)!libc!unistd>dup.o
<$(SOURCE_GRIST)!libc!unistd>dup2.o
@ -360,6 +362,7 @@ KernelStaticLibraryObjects libc.a :
<$(SOURCE_GRIST)!libc!unistd>write.o
<$(SOURCE_GRIST)!libc!unistd>sleep.o
<$(SOURCE_GRIST)!libc!unistd>usleep.o
<$(SOURCE_GRIST)!libc!unistd>truncate.o
<$(SOURCE_GRIST)!libc!unistd>ioctl.o
<$(SOURCE_GRIST)!libc!unistd>mount.o
<$(SOURCE_GRIST)!libc!unistd>conf.o
@ -466,6 +469,8 @@ KernelLd libc.so :
<$(SOURCE_GRIST)!libc!system>wrappers.o
<$(SOURCE_GRIST)!libc!system!arch!$(OBOS_ARCH)>atomic.o
<$(SOURCE_GRIST)!libc!unistd>access.o
<$(SOURCE_GRIST)!libc!unistd>chown.o
<$(SOURCE_GRIST)!libc!unistd>close.o
<$(SOURCE_GRIST)!libc!unistd>dup.o
<$(SOURCE_GRIST)!libc!unistd>dup2.o
@ -478,6 +483,7 @@ KernelLd libc.so :
<$(SOURCE_GRIST)!libc!unistd>write.o
<$(SOURCE_GRIST)!libc!unistd>sleep.o
<$(SOURCE_GRIST)!libc!unistd>usleep.o
<$(SOURCE_GRIST)!libc!unistd>truncate.o
<$(SOURCE_GRIST)!libc!unistd>ioctl.o
<$(SOURCE_GRIST)!libc!unistd>mount.o
<$(SOURCE_GRIST)!libc!unistd>conf.o

View File

@ -1034,6 +1034,7 @@ static struct fs_calls bootfs_calls = {
&bootfs_unlink,
&bootfs_rename,
NULL, // access
&bootfs_read_stat,
&bootfs_write_stat,

View File

@ -1072,6 +1072,7 @@ static struct fs_calls devfs_calls = {
&devfs_unlink,
&devfs_rename,
NULL, // access
&devfs_read_stat,
&devfs_write_stat,

View File

@ -925,6 +925,7 @@ static struct fs_calls rootfs_calls = {
&rootfs_unlink,
&rootfs_rename,
NULL, // fs_access()
&rootfs_read_stat,
&rootfs_write_stat,

View File

@ -2111,6 +2111,27 @@ common_unlink(char *path, bool kernel)
}
static int
common_access(char *path, int mode, bool kernel)
{
struct vnode *vnode;
int status;
status = path_to_vnode(path, true, &vnode, kernel);
if (status < B_OK)
return status;
if (FS_CALL(vnode,fs_access) != NULL)
status = FS_CALL(vnode,fs_access)(vnode->mount->cookie, vnode->private_node, mode);
else
status = EOPNOTSUPP;
put_vnode(vnode);
return status;
}
static int
common_rename(char *path, char *newPath, bool kernel)
{
@ -2749,6 +2770,18 @@ sys_rename(const char *oldpath, const char *newpath)
}
int
sys_access(const char *path, int mode)
{
char pathCopy[SYS_MAX_PATH_LEN + 1];
int status;
strlcpy(pathCopy, path, SYS_MAX_PATH_LEN - 1);
return common_access(pathCopy, mode, true);
}
int
sys_read_stat(const char *path, bool traverseLeafLink, struct stat *stat)
{
@ -3127,18 +3160,18 @@ user_create_symlink(const char *userPath, const char *userToPath, int mode)
int
user_unlink(const char *upath)
user_unlink(const char *userPath)
{
char path[SYS_MAX_PATH_LEN + 1];
int rc;
int status;
if ((addr)upath >= KERNEL_BASE && (addr)upath <= KERNEL_TOP)
return ERR_VM_BAD_USER_MEMORY;
if (!CHECK_USER_ADDRESS(userPath))
return B_BAD_ADDRESS;
rc = user_strncpy(path, upath, SYS_MAX_PATH_LEN);
if (rc < 0)
return rc;
path[SYS_MAX_PATH_LEN] = 0;
status = user_strncpy(path, userPath, SYS_MAX_PATH_LEN - 1);
if (status < 0)
return status;
path[SYS_MAX_PATH_LEN - 1] = '\0';
return common_unlink(path, false);
}
@ -3171,6 +3204,24 @@ user_rename(const char *uoldpath, const char *unewpath)
}
int
user_access(const char *userPath, int mode)
{
char path[SYS_MAX_PATH_LEN + 1];
int status;
if (!CHECK_USER_ADDRESS(userPath))
return B_BAD_ADDRESS;
status = user_strncpy(path, userPath, SYS_MAX_PATH_LEN - 1);
if (status < 0)
return status;
path[SYS_MAX_PATH_LEN - 1] = '\0';
return common_access(path, mode, false);
}
int
user_read_stat(const char *userPath, bool traverseLink, struct stat *userStat)
{

View File

@ -126,12 +126,15 @@ int syscall_dispatcher(unsigned long call_num, void *arg_buffer, uint64 *call_re
case SYSCALL_READ_STAT:
*call_ret = user_read_stat((const char *)arg0, (bool)arg1, (struct stat *)arg2);
break;
case SYSCALL_FD_STAT:
case SYSCALL_READ_STAT_FD:
*call_ret = user_fstat((int)arg0, (struct stat*)arg1);
break;
case SYSCALL_WRITE_STAT:
*call_ret = user_write_stat((int)arg0, (const char *)arg1, (bool)arg2, (struct stat *)arg3, (int)arg4);
break;
case SYSCALL_ACCESS:
*call_ret = user_access((const char *)arg0, (int)arg1);
break;
case SYSCALL_SYSTEM_TIME:
*call_ret = system_time();
break;