Skip to content

Commit

Permalink
fs: move libc function prototypes to their correct locations
Browse files Browse the repository at this point in the history
This moves the function prototypes in include/fs.h which also exist
in the libc to the locations they would have in libc.

With this it becomes easier to share code between barebox and userspace
since the usual libc include files will exist. Also users of the libc
functions no longer have to include the barebox internal fs.h header.

Signed-off-by: Sascha Hauer <[email protected]>
  • Loading branch information
saschahauer committed Apr 15, 2016
1 parent e1385b3 commit 70bbeea
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 140 deletions.
20 changes: 20 additions & 0 deletions include/dirent.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#ifndef __DIRENT_H
#define __DIRENT_H

struct dirent {
char d_name[256];
};

typedef struct dir {
struct device_d *dev;
struct fs_driver_d *fsdrv;
struct node_d *node;
struct dirent d;
void *priv; /* private data for the fs driver */
} DIR;

DIR *opendir(const char *pathname);
struct dirent *readdir(DIR *dir);
int closedir(DIR *dir);

#endif /* __DIRENT_H */
100 changes: 5 additions & 95 deletions include/fcntl.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef _ASM_GENERIC_FCNTL_H
#define _ASM_GENERIC_FCNTL_H
#ifndef __FCNTL_H
#define __FCNTL_H

#include <linux/types.h>

Expand All @@ -24,97 +24,7 @@
#define O_RWSIZE_4 004000000
#define O_RWSIZE_8 010000000

#define F_DUPFD 0 /* dup */
#define F_GETFD 1 /* get close_on_exec */
#define F_SETFD 2 /* set/clear close_on_exec */
#define F_GETFL 3 /* get file->f_flags */
#define F_SETFL 4 /* set file->f_flags */
#ifndef F_GETLK
#define F_GETLK 5
#define F_SETLK 6
#define F_SETLKW 7
#endif
#ifndef F_SETOWN
#define F_SETOWN 8 /* for sockets. */
#define F_GETOWN 9 /* for sockets. */
#endif
#ifndef F_SETSIG
#define F_SETSIG 10 /* for sockets. */
#define F_GETSIG 11 /* for sockets. */
#endif
int open(const char *pathname, int flags, ...);
int creat(const char *pathname, mode_t mode);

/* for F_[GET|SET]FL */
#define FD_CLOEXEC 1 /* actually anything with low bit set goes */

/* for posix fcntl() and lockf() */
#ifndef F_RDLCK
#define F_RDLCK 0
#define F_WRLCK 1
#define F_UNLCK 2
#endif

/* for old implementation of bsd flock () */
#ifndef F_EXLCK
#define F_EXLCK 4 /* or 3 */
#define F_SHLCK 8 /* or 4 */
#endif

/* for leases */
#ifndef F_INPROGRESS
#define F_INPROGRESS 16
#endif

/* operations for bsd flock(), also used by the kernel implementation */
#define LOCK_SH 1 /* shared lock */
#define LOCK_EX 2 /* exclusive lock */
#define LOCK_NB 4 /* or'd with one of the above to prevent
blocking */
#define LOCK_UN 8 /* remove lock */

#define LOCK_MAND 32 /* This is a mandatory flock ... */
#define LOCK_READ 64 /* which allows concurrent read operations */
#define LOCK_WRITE 128 /* which allows concurrent write operations */
#define LOCK_RW 192 /* which allows concurrent read & write ops */

#define F_LINUX_SPECIFIC_BASE 1024

#ifndef HAVE_ARCH_STRUCT_FLOCK
#ifndef __ARCH_FLOCK_PAD
#define __ARCH_FLOCK_PAD
#endif

struct flock {
short l_type;
short l_whence;
off_t l_start;
off_t l_len;
pid_t l_pid;
__ARCH_FLOCK_PAD
};
#endif

#ifndef CONFIG_64BIT

#ifndef F_GETLK64
#define F_GETLK64 12 /* using 'struct flock64' */
#define F_SETLK64 13
#define F_SETLKW64 14
#endif

#ifndef HAVE_ARCH_STRUCT_FLOCK64
#ifndef __ARCH_FLOCK64_PAD
#define __ARCH_FLOCK64_PAD
#endif

struct flock64 {
short l_type;
short l_whence;
loff_t l_start;
loff_t l_len;
pid_t l_pid;
__ARCH_FLOCK64_PAD
};
#endif
#endif /* !CONFIG_64BIT */

#endif /* _ASM_GENERIC_FCNTL_H */
#endif /* __FCNTL_H */
51 changes: 6 additions & 45 deletions include/fs.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
#ifndef __FS_H
#define __FS_H

#include <unistd.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <dirent.h>
#include <sys/mount.h>
#include <sys/stat.h>
#include <driver.h>
#include <filetype.h>
#include <linux/fs.h>
Expand All @@ -11,18 +17,6 @@ struct partition;
struct node_d;
struct stat;

struct dirent {
char d_name[256];
};

typedef struct dir {
struct device_d *dev;
struct fs_driver_d *fsdrv;
struct node_d *node;
struct dirent d;
void *priv; /* private data for the fs driver */
} DIR;

typedef struct filep {
struct fs_device_d *fsdev; /* The device this FILE belongs to */
char *path;
Expand Down Expand Up @@ -107,40 +101,7 @@ struct fs_device_d {

#define drv_to_fs_driver(d) container_of(d, struct fs_driver_d, drv)

/*
* standard posix file functions
*/
int open(const char *pathname, int flags, ...);
int creat(const char *pathname, mode_t mode);
int unlink(const char *pathname);
int close(int fd);
int flush(int fd);
int lstat(const char *filename, struct stat *s);
int stat(const char *filename, struct stat *s);
int fstat(int fd, struct stat *s);
ssize_t read(int fd, void *buf, size_t count);
ssize_t pread(int fd, void *buf, size_t count, loff_t offset);
int ioctl(int fd, int request, void *buf);
ssize_t write(int fd, const void *buf, size_t count);
ssize_t pwrite(int fd, const void *buf, size_t count, loff_t offset);

loff_t lseek(int fildes, loff_t offset, int whence);
int mkdir (const char *pathname, mode_t mode);
int rmdir (const char *pathname);

const char *getcwd(void);
int chdir(const char *pathname);

DIR *opendir(const char *pathname);
struct dirent *readdir(DIR *dir);
int closedir(DIR *dir);

int symlink(const char *pathname, const char *newpath);
int readlink(const char *path, char *buf, size_t bufsiz);

int mount (const char *device, const char *fsname, const char *path,
const char *fsoptions);
int umount(const char *pathname);
int umount_by_cdev(struct cdev *cdev);

/* not-so-standard functions */
Expand Down
6 changes: 6 additions & 0 deletions include/sys/ioctl.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#ifndef __SYS_IOCTL_H
#define __SYS_IOCTL_H

int ioctl(int fd, int request, void *buf);

#endif /* __SYS_IOCTL_H */
8 changes: 8 additions & 0 deletions include/sys/mount.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#ifndef __SYS_MOUNT_H
#define __SYS_MOUNT_H

int mount(const char *device, const char *fsname, const char *path,
const char *fsoptions);
int umount(const char *pathname);

#endif /* __SYS_MOUNT_H */
9 changes: 9 additions & 0 deletions include/sys/stat.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#ifndef __STAT_H
#define __STAT_H

#include <linux/types.h>
#include <linux/stat.h>

int mkdir (const char *pathname, mode_t mode);

#endif /* __STAT_H */
24 changes: 24 additions & 0 deletions include/unistd.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#ifndef __UNISTD_H
#define __UNISTD_H

#include <linux/types.h>

struct stat;

int unlink(const char *pathname);
int close(int fd);
int lstat(const char *filename, struct stat *s);
int stat(const char *filename, struct stat *s);
int fstat(int fd, struct stat *s);
ssize_t read(int fd, void *buf, size_t count);
ssize_t pread(int fd, void *buf, size_t count, loff_t offset);
ssize_t write(int fd, const void *buf, size_t count);
ssize_t pwrite(int fd, const void *buf, size_t count, loff_t offset);
loff_t lseek(int fildes, loff_t offset, int whence);
int rmdir (const char *pathname);
int symlink(const char *pathname, const char *newpath);
int readlink(const char *path, char *buf, size_t bufsiz);
int chdir(const char *pathname);
const char *getcwd(void);

#endif /* __UNISTD_H */

0 comments on commit 70bbeea

Please sign in to comment.