[dfs] Add DFS v2.0 (#7606)

This commit is contained in:
Bernard Xiong
2023-06-10 21:35:25 +08:00
committed by GitHub
parent c33a21509a
commit 99e80f8d33
68 changed files with 5563 additions and 11680 deletions
+141 -2
View File
@@ -16,6 +16,7 @@ if RT_USING_DFS
bool "Using working directory"
default y
if RT_USING_DFS_V1
config RT_USING_DFS_MNTTABLE
bool "Using mount table for file system"
default n
@@ -27,6 +28,7 @@ if RT_USING_DFS
{0}
};
The mount_table must be terminated with NULL.
endif
config DFS_FD_MAX
int "The maximal number of opened files"
@@ -44,8 +46,145 @@ if RT_USING_DFS
bool "DFS v2.0"
endchoice
source "$RTT_DIR/components/dfs/dfs_v1/Kconfig"
source "$RTT_DIR/components/dfs/dfs_v2/Kconfig"
if RT_USING_DFS_V1
config DFS_FILESYSTEMS_MAX
int "The maximal number of mounted file system"
default 4
config DFS_FILESYSTEM_TYPES_MAX
int "The maximal number of file system type"
default 4
endif
config RT_USING_DFS_ELMFAT
bool "Enable elm-chan fatfs"
default n
help
FatFs is a generic FAT/exFAT file system module for small embedded systems.
if RT_USING_DFS_ELMFAT
menu "elm-chan's FatFs, Generic FAT Filesystem Module"
config RT_DFS_ELM_CODE_PAGE
int "OEM code page"
default 437
config RT_DFS_ELM_WORD_ACCESS
bool "Using RT_DFS_ELM_WORD_ACCESS"
default y
choice
prompt "Support long file name"
default RT_DFS_ELM_USE_LFN_3
config RT_DFS_ELM_USE_LFN_0
bool "0: LFN disable"
config RT_DFS_ELM_USE_LFN_1
bool "1: LFN with static LFN working buffer"
config RT_DFS_ELM_USE_LFN_2
bool "2: LFN with dynamic LFN working buffer on the stack"
config RT_DFS_ELM_USE_LFN_3
bool "3: LFN with dynamic LFN working buffer on the heap"
endchoice
config RT_DFS_ELM_USE_LFN
int
default 0 if RT_DFS_ELM_USE_LFN_0
default 1 if RT_DFS_ELM_USE_LFN_1
default 2 if RT_DFS_ELM_USE_LFN_2
default 3 if RT_DFS_ELM_USE_LFN_3
choice
prompt "Support unicode for long file name"
default RT_DFS_ELM_LFN_UNICODE_0
config RT_DFS_ELM_LFN_UNICODE_0
bool "0: ANSI/OEM in current CP (TCHAR = char)"
config RT_DFS_ELM_LFN_UNICODE_1
bool "1: Unicode in UTF-16 (TCHAR = WCHAR)"
config RT_DFS_ELM_LFN_UNICODE_2
bool "2: Unicode in UTF-8 (TCHAR = char)"
config RT_DFS_ELM_LFN_UNICODE_3
bool "3: Unicode in UTF-32 (TCHAR = DWORD)"
endchoice
config RT_DFS_ELM_LFN_UNICODE
int
default 0 if RT_DFS_ELM_LFN_UNICODE_0
default 1 if RT_DFS_ELM_LFN_UNICODE_1
default 2 if RT_DFS_ELM_LFN_UNICODE_2
default 3 if RT_DFS_ELM_LFN_UNICODE_3
config RT_DFS_ELM_MAX_LFN
int "Maximal size of file name length"
range 12 255
default 255
config RT_DFS_ELM_DRIVES
int "Number of volumes (logical drives) to be used."
default 2
config RT_DFS_ELM_MAX_SECTOR_SIZE
int "Maximum sector size to be handled."
default 512
help
If you use some spi nor flash for fatfs, please set this the erase sector size, for example 4096.
config RT_DFS_ELM_USE_ERASE
bool "Enable sector erase feature"
default n
config RT_DFS_ELM_REENTRANT
bool "Enable the reentrancy (thread safe) of the FatFs module"
default y
config RT_DFS_ELM_MUTEX_TIMEOUT
int "Timeout of thread-safe protection mutex"
range 0 1000000
default 3000
depends on RT_DFS_ELM_REENTRANT
endmenu
endif
config RT_USING_DFS_DEVFS
bool "Using devfs for device objects"
default y
config RT_USING_DFS_ROMFS
bool "Enable ReadOnly file system on flash"
default n
if RT_USING_DFS_V1
config RT_USING_DFS_CROMFS
bool "Enable ReadOnly compressed file system on flash"
default n
# select PKG_USING_ZLIB
config RT_USING_DFS_RAMFS
bool "Enable RAM file system"
select RT_USING_MEMHEAP
default n
endif
config RT_USING_DFS_TMPFS
bool "Enable TMP file system"
default n
if RT_USING_DFS_V1
config RT_USING_DFS_NFS
bool "Using NFS v3 client file system"
depends on RT_USING_LWIP
default n
if RT_USING_DFS_NFS
config RT_NFS_HOST_EXPORT
string "NFSv3 host export"
default "192.168.1.5:/"
endif
endif
endif
-138
View File
@@ -1,138 +0,0 @@
if RT_USING_DFS_V1
config DFS_FILESYSTEMS_MAX
int "The maximal number of mounted file system"
default 4
config DFS_FILESYSTEM_TYPES_MAX
int "The maximal number of file system type"
default 4
config RT_USING_DFS_ELMFAT
bool "Enable elm-chan fatfs"
default n
help
FatFs is a generic FAT/exFAT file system module for small embedded systems.
if RT_USING_DFS_ELMFAT
menu "elm-chan's FatFs, Generic FAT Filesystem Module"
config RT_DFS_ELM_CODE_PAGE
int "OEM code page"
default 437
config RT_DFS_ELM_WORD_ACCESS
bool "Using RT_DFS_ELM_WORD_ACCESS"
default y
choice
prompt "Support long file name"
default RT_DFS_ELM_USE_LFN_3
config RT_DFS_ELM_USE_LFN_0
bool "0: LFN disable"
config RT_DFS_ELM_USE_LFN_1
bool "1: LFN with static LFN working buffer"
config RT_DFS_ELM_USE_LFN_2
bool "2: LFN with dynamic LFN working buffer on the stack"
config RT_DFS_ELM_USE_LFN_3
bool "3: LFN with dynamic LFN working buffer on the heap"
endchoice
config RT_DFS_ELM_USE_LFN
int
default 0 if RT_DFS_ELM_USE_LFN_0
default 1 if RT_DFS_ELM_USE_LFN_1
default 2 if RT_DFS_ELM_USE_LFN_2
default 3 if RT_DFS_ELM_USE_LFN_3
choice
prompt "Support unicode for long file name"
default RT_DFS_ELM_LFN_UNICODE_0
config RT_DFS_ELM_LFN_UNICODE_0
bool "0: ANSI/OEM in current CP (TCHAR = char)"
config RT_DFS_ELM_LFN_UNICODE_1
bool "1: Unicode in UTF-16 (TCHAR = WCHAR)"
config RT_DFS_ELM_LFN_UNICODE_2
bool "2: Unicode in UTF-8 (TCHAR = char)"
config RT_DFS_ELM_LFN_UNICODE_3
bool "3: Unicode in UTF-32 (TCHAR = DWORD)"
endchoice
config RT_DFS_ELM_LFN_UNICODE
int
default 0 if RT_DFS_ELM_LFN_UNICODE_0
default 1 if RT_DFS_ELM_LFN_UNICODE_1
default 2 if RT_DFS_ELM_LFN_UNICODE_2
default 3 if RT_DFS_ELM_LFN_UNICODE_3
config RT_DFS_ELM_MAX_LFN
int "Maximal size of file name length"
range 12 255
default 255
config RT_DFS_ELM_DRIVES
int "Number of volumes (logical drives) to be used."
default 2
config RT_DFS_ELM_MAX_SECTOR_SIZE
int "Maximum sector size to be handled."
default 512
help
If you use some spi nor flash for fatfs, please set this the erase sector size, for example 4096.
config RT_DFS_ELM_USE_ERASE
bool "Enable sector erase feature"
default n
config RT_DFS_ELM_REENTRANT
bool "Enable the reentrancy (thread safe) of the FatFs module"
default y
config RT_DFS_ELM_MUTEX_TIMEOUT
int "Timeout of thread-safe protection mutex"
range 0 1000000
default 3000
depends on RT_DFS_ELM_REENTRANT
endmenu
endif
config RT_USING_DFS_DEVFS
bool "Using devfs for device objects"
default y
config RT_USING_DFS_ROMFS
bool "Enable ReadOnly file system on flash"
default n
config RT_USING_DFS_CROMFS
bool "Enable ReadOnly compressed file system on flash"
default n
# select PKG_USING_ZLIB
config RT_USING_DFS_RAMFS
bool "Enable RAM file system"
select RT_USING_MEMHEAP
default n
config RT_USING_DFS_TMPFS
bool "Enable TMP file system"
default n
config RT_USING_DFS_NFS
bool "Using NFS v3 client file system"
depends on RT_USING_LWIP
default n
if RT_USING_DFS_NFS
config RT_NFS_HOST_EXPORT
string "NFSv3 host export"
default "192.168.1.5:/"
endif
endif
+2
View File
@@ -76,6 +76,8 @@ struct dfs_mmap2_args
};
void dfs_vnode_mgr_init(void);
int dfs_vnode_init(struct dfs_vnode *vnode, int type, const struct dfs_file_ops *fops);
int dfs_file_is_open(const char *pathname);
int dfs_file_open(struct dfs_file *fd, const char *path, int flags);
int dfs_file_close(struct dfs_file *fd);
+14
View File
@@ -47,6 +47,20 @@ void dfs_vnode_mgr_init(void)
}
}
int dfs_vnode_init(struct dfs_vnode *vnode, int type, const struct dfs_file_ops *fops)
{
if (vnode)
{
rt_memset(vnode, 0, sizeof(struct dfs_vnode));
vnode->type = type;
vnode->fops = fops;
rt_list_init(&(vnode->list));
vnode->ref_count = 1;
}
return 0;
}
/* BKDR Hash Function */
static unsigned int bkdr_hash(const char *str)
{
-35
View File
@@ -1,35 +0,0 @@
if RT_USING_DFS_V2
config RT_USING_DFS_DEVFS
bool "Using devfs for device objects"
default y
config RT_USING_DFS_ROMFS
bool "Enable ReadOnly file system on flash"
default n
config RT_USING_DFS_CROMFS
bool "Enable ReadOnly compressed file system on flash"
default n
# select PKG_USING_ZLIB
config RT_USING_DFS_RAMFS
bool "Enable RAM file system"
select RT_USING_MEMHEAP
default n
config RT_USING_DFS_TMPFS
bool "Enable TMP file system"
default n
config RT_USING_DFS_NFS
bool "Using NFS v3 client file system"
depends on RT_USING_LWIP
default n
if RT_USING_DFS_NFS
config RT_NFS_HOST_EXPORT
string "NFSv3 host export"
default "192.168.1.5:/"
endif
endif
+15 -10
View File
@@ -2,19 +2,24 @@ from building import *
import os
# The set of source files associated with this SConscript file.
src = []
cwd = GetCurrentDir()
src = Split('''
src/dfs.c
src/dfs_file.c
src/dfs_fs.c
src/dfs_dentry.c
src/dfs_vnode.c
src/dfs_mnt.c
src/dfs_posix.c
''')
cwd = GetCurrentDir()
CPPPATH = [cwd + "/include"]
group = []
if GetDepend('RT_USING_POSIX'):
src += ['src/poll.c', 'src/select.c']
group = DefineGroup('Filesystem', src, depend = ['RT_USING_DFS', 'RT_USING_DFS_V2'], CPPPATH = CPPPATH)
if GetDepend('RT_USING_DFS') and GetDepend('RT_USING_DFS_V2'):
src = ['src/dfs.c', 'src/dfs_file.c', 'src/dfs_fs.c']
if GetDepend('DFS_USING_POSIX'):
src += ['src/dfs_posix.c']
group = DefineGroup('Filesystem', src, depend = ['RT_USING_DFS'], CPPPATH = CPPPATH)
# search in the file system implementation
list = os.listdir(cwd)
File diff suppressed because it is too large Load Diff
@@ -10,8 +10,6 @@
#ifndef __DEVICE_FS_H__
#define __DEVICE_FS_H__
#include <rtthread.h>
int devfs_init(void);
int dfs_devfs_init(void);
#endif
File diff suppressed because it is too large Load Diff
@@ -4077,7 +4077,6 @@ FRESULT f_sync (
DWORD tm;
BYTE *dir;
res = validate(&fp->obj, &fs); /* Check validity of the file object */
if (res == FR_OK) {
if (fp->flag & FA_MODIFIED) { /* Is there any change to the file? */
@@ -4201,7 +4200,6 @@ FRESULT f_chdrive (
}
FRESULT f_chdir (
const TCHAR* path /* Pointer to the directory path */
)
@@ -4746,7 +4744,7 @@ FRESULT f_stat (
res = follow_path(&dj, path); /* Follow the file path */
if (res == FR_OK) { /* Follow completed */
if (dj.fn[NSFLAG] & NS_NONAME) { /* It is origin directory */
res = FR_INVALID_NAME;
fno->fattrib = AM_DIR;
} else { /* Found an object */
if (fno) get_fileinfo(&dj, fno);
}
@@ -1,13 +0,0 @@
# RT-Thread building script for component
from building import *
cwd = GetCurrentDir()
src = Glob('*.c') + Glob('rpc/*.c')
CPPPATH = [cwd]
SrcRemove(src, ['rpc/auth_none.c'])
group = DefineGroup('Filesystem', src, depend = ['RT_USING_DFS', 'RT_USING_DFS_NFS'], CPPPATH = CPPPATH)
Return('group')
File diff suppressed because it is too large Load Diff
@@ -1,15 +0,0 @@
/*
* Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
*/
#ifndef __NFS_H__
#define __NFS_H__
int nfs_init(void);
#endif
@@ -1,131 +0,0 @@
/*
* Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
*/
/*
* Please do not edit this file.
* It was generated using rpcgen.
*/
#ifndef _MOUNT_H_RPCGEN
#define _MOUNT_H_RPCGEN
#include <rpc/rpc.h>
#ifdef __cplusplus
extern "C" {
#endif
/* This file is copied from RFC1813
* Copyright 1995 Sun Micrososystems (I assume)
*/
#define MNTPATHLEN 1024
#define MNTNAMLEN 255
#define FHSIZE3 64
typedef struct {
unsigned int fhandle3_len;
char *fhandle3_val;
} fhandle3;
typedef char *dirpath;
typedef char *name;
typedef struct exportnode *exports;
typedef struct groupnode *groups;
typedef struct mountbody *mountlist;
enum mountstat3 {
MNT3_OK = 0,
MNT3ERR_PERM = 1,
MNT3ERR_NOENT = 2,
MNT3ERR_IO = 5,
MNT3ERR_ACCES = 13,
MNT3ERR_NOTDIR = 20,
MNT3ERR_INVAL = 22,
MNT3ERR_NAMETOOLONG = 63,
MNT3ERR_NOTSUPP = 10004,
MNT3ERR_SERVERFAULT = 10006
};
typedef enum mountstat3 mountstat3;
struct mountres3_ok {
fhandle3 fhandle;
struct {
unsigned int auth_flavors_len;
int *auth_flavors_val;
} auth_flavors;
};
typedef struct mountres3_ok mountres3_ok;
struct mountres3 {
mountstat3 fhs_status;
union {
mountres3_ok mountinfo;
} mountres3_u;
};
typedef struct mountres3 mountres3;
struct mountbody {
name ml_hostname;
dirpath ml_directory;
mountlist ml_next;
};
typedef struct mountbody mountbody;
struct groupnode {
name gr_name;
groups gr_next;
};
typedef struct groupnode groupnode;
struct exportnode {
dirpath ex_dir;
groups ex_groups;
exports ex_next;
};
typedef struct exportnode exportnode;
#define MOUNT_PROGRAM 100005
#define MOUNT_V3 3
#define MOUNTPROC3_NULL 0
extern enum clnt_stat mountproc3_null_3(void *, CLIENT *);
#define MOUNTPROC3_MNT 1
extern enum clnt_stat mountproc3_mnt_3(dirpath , mountres3 *, CLIENT *);
#define MOUNTPROC3_DUMP 2
extern enum clnt_stat mountproc3_dump_3(mountlist *, CLIENT *);
#define MOUNTPROC3_UMNT 3
extern enum clnt_stat mountproc3_umnt_3(dirpath , void *, CLIENT *);
#define MOUNTPROC3_UMNTALL 4
extern enum clnt_stat mountproc3_umntall_3(void *, CLIENT *);
#define MOUNTPROC3_EXPORT 5
extern enum clnt_stat mountproc3_export_3(exports *, CLIENT *);
/* the xdr functions */
extern bool_t xdr_fhandle3(XDR *, fhandle3*);
extern bool_t xdr_dirpath(XDR *, dirpath*);
extern bool_t xdr_name(XDR *, name*);
extern bool_t xdr_exports(XDR *, exports*);
extern bool_t xdr_groups(XDR *, groups*);
extern bool_t xdr_mountlist(XDR *, mountlist*);
extern bool_t xdr_mountstat3(XDR *, mountstat3*);
extern bool_t xdr_mountres3_ok(XDR *, mountres3_ok*);
extern bool_t xdr_mountres3(XDR *, mountres3*);
extern bool_t xdr_mountbody(XDR *, mountbody*);
extern bool_t xdr_groupnode(XDR *, groupnode*);
extern bool_t xdr_exportnode(XDR *, exportnode*);
#ifdef __cplusplus
}
#endif
#endif /* !_MOUNT_H_RPCGEN */
@@ -1,68 +0,0 @@
%/* This file is copied from RFC1813
% * Copyright 1995 Sun Micrososystems (I assume)
% */
const MNTPATHLEN = 1024; /* Maximum bytes in a path name */
const MNTNAMLEN = 255; /* Maximum bytes in a name */
const FHSIZE3 = 64; /* Maximum bytes in a V3 file handle */
typedef opaque fhandle3<FHSIZE3>;
typedef string dirpath<MNTPATHLEN>;
typedef string name<MNTNAMLEN>;
typedef struct exportnode *exports;
typedef struct groupnode *groups;
typedef struct mountbody *mountlist;
enum mountstat3 {
MNT3_OK = 0, /* no error */
MNT3ERR_PERM = 1, /* Not owner */
MNT3ERR_NOENT = 2, /* No such file or directory */
MNT3ERR_IO = 5, /* I/O error */
MNT3ERR_ACCES = 13, /* Permission denied */
MNT3ERR_NOTDIR = 20, /* Not a directory */
MNT3ERR_INVAL = 22, /* Invalid argument */
MNT3ERR_NAMETOOLONG = 63, /* Filename too long */
MNT3ERR_NOTSUPP = 10004, /* Operation not supported */
MNT3ERR_SERVERFAULT = 10006 /* A failure on the server */
};
struct mountres3_ok {
fhandle3 fhandle;
int auth_flavors<>;
};
union mountres3 switch (mountstat3 fhs_status) {
case MNT3_OK:
mountres3_ok mountinfo;
default:
void;
};
struct mountbody {
name ml_hostname;
dirpath ml_directory;
mountlist ml_next;
};
struct groupnode {
name gr_name;
groups gr_next;
};
struct exportnode {
dirpath ex_dir;
groups ex_groups;
exports ex_next;
};
program MOUNT_PROGRAM {
version MOUNT_V3 {
void MOUNTPROC3_NULL(void) = 0;
mountres3 MOUNTPROC3_MNT(dirpath) = 1;
mountlist MOUNTPROC3_DUMP(void) = 2;
void MOUNTPROC3_UMNT(dirpath) = 3;
void MOUNTPROC3_UMNTALL(void) = 4;
exports MOUNTPROC3_EXPORT(void) = 5;
} = 3;
} = 100005;
@@ -1,78 +0,0 @@
/*
* Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
*/
/*
* Please do not edit this file.
* It was generated using rpcgen.
*/
#include <string.h> /* for memset */
#include "mount.h"
/* This file is copied from RFC1813
* Copyright 1995 Sun Micrososystems (I assume)
*/
typedef char* caddr_t;
/* Default timeout can be changed using clnt_control() */
static struct timeval TIMEOUT = { 25, 0 };
enum clnt_stat
mountproc3_null_3(void *clnt_res, CLIENT *clnt)
{
return (clnt_call(clnt, MOUNTPROC3_NULL,
(xdrproc_t) xdr_void, (caddr_t) NULL,
(xdrproc_t) xdr_void, (caddr_t) clnt_res,
TIMEOUT));
}
enum clnt_stat
mountproc3_mnt_3(dirpath arg1, mountres3 *clnt_res, CLIENT *clnt)
{
return (clnt_call(clnt, MOUNTPROC3_MNT,
(xdrproc_t) xdr_dirpath, (caddr_t) &arg1,
(xdrproc_t) xdr_mountres3, (caddr_t) clnt_res,
TIMEOUT));
}
enum clnt_stat
mountproc3_dump_3(mountlist *clnt_res, CLIENT *clnt)
{
return (clnt_call(clnt, MOUNTPROC3_DUMP,
(xdrproc_t) xdr_void, (caddr_t) NULL,
(xdrproc_t) xdr_mountlist, (caddr_t) clnt_res,
TIMEOUT));
}
enum clnt_stat
mountproc3_umnt_3(dirpath arg1, void *clnt_res, CLIENT *clnt)
{
return (clnt_call(clnt, MOUNTPROC3_UMNT,
(xdrproc_t) xdr_dirpath, (caddr_t) &arg1,
(xdrproc_t) xdr_void, (caddr_t) clnt_res,
TIMEOUT));
}
enum clnt_stat
mountproc3_umntall_3(void *clnt_res, CLIENT *clnt)
{
return (clnt_call(clnt, MOUNTPROC3_UMNTALL,
(xdrproc_t) xdr_void, (caddr_t) NULL,
(xdrproc_t) xdr_void, (caddr_t) clnt_res,
TIMEOUT));
}
enum clnt_stat
mountproc3_export_3(exports *clnt_res, CLIENT *clnt)
{
return (clnt_call(clnt, MOUNTPROC3_EXPORT,
(xdrproc_t) xdr_void, (caddr_t) NULL,
(xdrproc_t) xdr_exports, (caddr_t) clnt_res,
TIMEOUT));
}
@@ -1,142 +0,0 @@
/*
* Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
*/
/*
* Please do not edit this file.
* It was generated using rpcgen.
*/
#include "mount.h"
/* This file is copied from RFC1813
* Copyright 1995 Sun Micrososystems (I assume)
*/
bool_t
xdr_fhandle3(register XDR *xdrs, fhandle3 *objp)
{
if (!xdr_bytes(xdrs, (char **)&objp->fhandle3_val, (unsigned int *) &objp->fhandle3_len, FHSIZE3))
return (FALSE);
return (TRUE);
}
bool_t
xdr_dirpath(register XDR *xdrs, dirpath *objp)
{
if (!xdr_string(xdrs, objp, MNTPATHLEN))
return (FALSE);
return (TRUE);
}
bool_t
xdr_name(register XDR *xdrs, name *objp)
{
if (!xdr_string(xdrs, objp, MNTNAMLEN))
return (FALSE);
return (TRUE);
}
bool_t
xdr_exports(register XDR *xdrs, exports *objp)
{
if (!xdr_pointer(xdrs, (char **)objp, sizeof (struct exportnode), (xdrproc_t) xdr_exportnode))
return (FALSE);
return (TRUE);
}
bool_t
xdr_groups(register XDR *xdrs, groups *objp)
{
if (!xdr_pointer(xdrs, (char **)objp, sizeof (struct groupnode), (xdrproc_t) xdr_groupnode))
return (FALSE);
return (TRUE);
}
bool_t
xdr_mountlist(register XDR *xdrs, mountlist *objp)
{
if (!xdr_pointer(xdrs, (char **)objp, sizeof (struct mountbody), (xdrproc_t) xdr_mountbody))
return (FALSE);
return (TRUE);
}
bool_t
xdr_mountstat3(register XDR *xdrs, mountstat3 *objp)
{
int enum_objp;
enum_objp = *objp;
if (!xdr_enum(xdrs, (enum_t *)&enum_objp))
{
*objp = (mountstat3)enum_objp;
return (FALSE);
}
return (TRUE);
}
bool_t
xdr_mountres3_ok(register XDR *xdrs, mountres3_ok *objp)
{
if (!xdr_fhandle3(xdrs, &objp->fhandle))
return (FALSE);
if (!xdr_array(xdrs, (char **)&objp->auth_flavors.auth_flavors_val, (unsigned int *) &objp->auth_flavors.auth_flavors_len, ~0,
sizeof (int), (xdrproc_t) xdr_int))
return (FALSE);
return (TRUE);
}
bool_t
xdr_mountres3(register XDR *xdrs, mountres3 *objp)
{
if (!xdr_mountstat3(xdrs, &objp->fhs_status))
return (FALSE);
switch (objp->fhs_status) {
case MNT3_OK:
if (!xdr_mountres3_ok(xdrs, &objp->mountres3_u.mountinfo))
return (FALSE);
break;
default :
return (FALSE);
}
return (TRUE);
}
bool_t
xdr_mountbody(register XDR *xdrs, mountbody *objp)
{
if (!xdr_name(xdrs, &objp->ml_hostname))
return (FALSE);
if (!xdr_dirpath(xdrs, &objp->ml_directory))
return (FALSE);
if (!xdr_mountlist(xdrs, &objp->ml_next))
return (FALSE);
return (TRUE);
}
bool_t
xdr_groupnode(register XDR *xdrs, groupnode *objp)
{
if (!xdr_name(xdrs, &objp->gr_name))
return (FALSE);
if (!xdr_groups(xdrs, &objp->gr_next))
return (FALSE);
return (TRUE);
}
bool_t
xdr_exportnode(register XDR *xdrs, exportnode *objp)
{
if (!xdr_dirpath(xdrs, &objp->ex_dir))
return (FALSE);
if (!xdr_groups(xdrs, &objp->ex_groups))
return (FALSE);
if (!xdr_exports(xdrs, &objp->ex_next))
return (FALSE);
return (TRUE);
}
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
@@ -1,172 +0,0 @@
/*
* Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
*/
#include <rpc/types.h>
#include <rpc/xdr.h>
#include <rpc/auth.h>
#define MAX_MARSHEL_SIZE 64
struct nfs_credentia
{
rt_uint32_t stamp;
char *name;
rt_uint32_t uid;
rt_uint32_t gid;
rt_uint32_t *auxi;
rt_uint32_t auxi_count;
};
static void authnone_verf(AUTH *);
static bool_t authnone_validate(AUTH *, struct opaque_auth *);
static bool_t authnone_refresh(AUTH *);
static void authnone_destroy(AUTH *);
static bool_t authnone_marshal(AUTH *client, XDR *xdrs);
static struct nfs_credentia _credentia = {
.stamp = 0,
.name = "rt-thread",
.uid = 0,
.gid = 0,
.auxi = NULL,
.auxi_count = 0,
};
struct opaque_auth _null_auth;
static struct auth_ops ops =
{
authnone_verf,
authnone_marshal,
authnone_validate,
authnone_refresh,
authnone_destroy
};
static struct authnone_private
{
AUTH no_client;
char marshalled_client[MAX_MARSHEL_SIZE];
unsigned int mcnt;
} *authnone_private;
AUTH *authnone_create(void)
{
register struct authnone_private *ap = authnone_private;
XDR xdr_stream;
register XDR *xdrs;
extern bool_t xdr_opaque_auth(XDR * xdrs, struct opaque_auth * ap);
struct opaque_auth auth;
rt_uint32_t *auth_buf, *auth_base;
int buf_len = 0, str_len = 0;
if (_credentia.name)
{
str_len = strlen(_credentia.name);
}
if (str_len == 0)
{
_credentia.name = "unknown";
str_len = strlen(_credentia.name);
}
buf_len = ((str_len) + (sizeof(rt_uint32_t)) - 1) & ~((sizeof(rt_uint32_t)) - 1);
buf_len += sizeof(struct nfs_credentia);
if (_credentia.auxi && _credentia.auxi_count)
{
buf_len += sizeof(rt_uint32_t) * _credentia.auxi_count;
}
auth_buf = auth_base = rt_malloc(buf_len);
if (auth_buf == NULL)
{
return NULL;
}
memset(auth_buf, 0, buf_len);
*auth_buf++ = htonl(rt_tick_get());
*auth_buf++ = htonl(str_len);
memcpy(auth_buf, _credentia.name, str_len);
auth_buf += (str_len + sizeof(rt_uint32_t) - 1) >> 2;
*auth_buf++ = htonl(_credentia.uid);
*auth_buf++ = htonl(_credentia.gid);
if (_credentia.auxi && _credentia.auxi_count)
{
rt_uint32_t tmp_cnt = 0;
*auth_buf++ = htonl(_credentia.auxi_count);
while (tmp_cnt < _credentia.auxi_count)
{
*auth_buf++ = htonl(_credentia.auxi[tmp_cnt]);
}
}
else
{
*auth_buf++ = htonl(0);
}
if (ap == 0)
{
ap = (struct authnone_private *) rt_malloc(sizeof(*ap));
if (ap == 0)
{
rt_free(auth_base);
return NULL;
}
memset(ap, 0, sizeof(*ap));
authnone_private = ap;
}
if (!ap->mcnt)
{
memset(&auth, 0, sizeof(auth));
auth.oa_flavor = 1;
auth.oa_base = (char *)auth_base;
auth.oa_length = (auth_buf - auth_base) * sizeof(rt_uint32_t);
ap->no_client.ah_cred = auth;
ap->no_client.ah_verf = _null_auth;
ap->no_client.ah_ops = &ops;
xdrs = &xdr_stream;
xdrmem_create(xdrs, ap->marshalled_client,
(unsigned int) MAX_MARSHEL_SIZE, XDR_ENCODE);
(void) xdr_opaque_auth(xdrs, &ap->no_client.ah_cred);
(void) xdr_opaque_auth(xdrs, &ap->no_client.ah_verf);
ap->mcnt = XDR_GETPOS(xdrs);
XDR_DESTROY(xdrs);
}
rt_free(auth_base);
return (&ap->no_client);
}
/*ARGSUSED*/
static bool_t authnone_marshal(AUTH *client, XDR *xdrs)
{
register struct authnone_private *ap = authnone_private;
if (ap == 0)
return (0);
return ((*xdrs->x_ops->x_putbytes)(xdrs,
ap->marshalled_client, ap->mcnt));
}
static void authnone_verf(AUTH *x)
{
}
static bool_t authnone_validate(AUTH *x, struct opaque_auth *x1)
{
return (TRUE);
}
static bool_t authnone_refresh(AUTH *x)
{
return (FALSE);
}
static void authnone_destroy(AUTH *x)
{
}
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
@@ -1,112 +0,0 @@
/*
* Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
*/
#ifndef __AUTH_H__
#define __AUTH_H__
#include <rpc/xdr.h>
/*
* Status returned from authentication check
*/
enum auth_stat {
AUTH_OK=0,
/*
* failed at remote end
*/
AUTH_BADCRED=1, /* bogus credentials (seal broken) */
AUTH_REJECTEDCRED=2, /* client should begin new session */
AUTH_BADVERF=3, /* bogus verifier (seal broken) */
AUTH_REJECTEDVERF=4, /* verifier expired or was replayed */
AUTH_TOOWEAK=5, /* rejected due to security reasons */
/*
* failed locally
*/
AUTH_INVALIDRESP=6, /* bogus response verifier */
AUTH_FAILED=7 /* some unknown reason */
};
union des_block {
struct {
uint32_t high;
uint32_t low;
} key;
char c[8];
};
typedef union des_block des_block;
/*
* Authentication info. Opaque to client.
*/
struct opaque_auth {
enum_t oa_flavor; /* flavor of auth */
char* oa_base; /* address of more auth stuff */
unsigned int oa_length; /* not to exceed MAX_AUTH_BYTES */
};
/*
* Auth handle, interface to client side authenticators.
*/
typedef struct AUTH AUTH;
struct AUTH {
struct opaque_auth ah_cred;
struct opaque_auth ah_verf;
union des_block ah_key;
struct auth_ops {
void (*ah_nextverf) (AUTH *);
int (*ah_marshal) (AUTH *, XDR *); /* nextverf & serialize */
int (*ah_validate) (AUTH *, struct opaque_auth *);
/* validate verifier */
int (*ah_refresh) (AUTH *); /* refresh credentials */
void (*ah_destroy) (AUTH *); /* destroy this structure */
} *ah_ops;
char* ah_private;
};
extern struct opaque_auth _null_auth;
/*
* Authentication ops.
* The ops and the auth handle provide the interface to the authenticators.
*
* AUTH *auth;
* XDR *xdrs;
* struct opaque_auth verf;
*/
#define AUTH_NEXTVERF(auth) \
((*((auth)->ah_ops->ah_nextverf))(auth))
#define auth_nextverf(auth) \
((*((auth)->ah_ops->ah_nextverf))(auth))
#define AUTH_MARSHALL(auth, xdrs) \
((*((auth)->ah_ops->ah_marshal))(auth, xdrs))
#define auth_marshall(auth, xdrs) \
((*((auth)->ah_ops->ah_marshal))(auth, xdrs))
#define AUTH_VALIDATE(auth, verfp) \
((*((auth)->ah_ops->ah_validate))((auth), verfp))
#define auth_validate(auth, verfp) \
((*((auth)->ah_ops->ah_validate))((auth), verfp))
#define AUTH_REFRESH(auth) \
((*((auth)->ah_ops->ah_refresh))(auth))
#define auth_refresh(auth) \
((*((auth)->ah_ops->ah_refresh))(auth))
#define AUTH_DESTROY(auth) \
((*((auth)->ah_ops->ah_destroy))(auth))
#define auth_destroy(auth) \
((*((auth)->ah_ops->ah_destroy))(auth))
#define MAX_AUTH_BYTES 400
#define MAXNETNAMELEN 255 /* maximum length of network user's name */
AUTH *authnone_create(void);
#endif
@@ -1,135 +0,0 @@
/*
* Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
*/
/* @(#)auth_none.c 2.1 88/07/29 4.0 RPCSRC */
/*
* Sun RPC is a product of Sun Microsystems, Inc. and is provided for
* unrestricted use provided that this legend is included on all tape
* media and as a part of the software program in whole or part. Users
* may copy or modify Sun RPC without charge, but are not authorized
* to license or distribute it to anyone else except as part of a product or
* program developed by the user.
*
* SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
* WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
* PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
*
* Sun RPC is provided with no support and without any obligation on the
* part of Sun Microsystems, Inc. to assist in its use, correction,
* modification or enhancement.
*
* SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
* INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
* OR ANY PART THEREOF.
*
* In no event will Sun Microsystems, Inc. be liable for any lost revenue
* or profits or other special, indirect and consequential damages, even if
* Sun has been advised of the possibility of such damages.
*
* Sun Microsystems, Inc.
* 2550 Garcia Avenue
* Mountain View, California 94043
*/
#if !defined(lint) && defined(SCCSIDS)
static char sccsid[] =
"@(#)auth_none.c 1.19 87/08/11 Copyr 1984 Sun Micro";
#endif
/*
* auth_none.c
* Creates a client authentication handle for passing "null"
* credentials and verifiers to remote systems.
*
* Copyright (C) 1984, Sun Microsystems, Inc.
*/
#include <rpc/types.h>
#include <rpc/xdr.h>
#include <rpc/auth.h>
#define MAX_MARSHEL_SIZE 20
static void authnone_verf(AUTH *);
static bool_t authnone_validate(AUTH *, struct opaque_auth *);
static bool_t authnone_refresh(AUTH *);
static void authnone_destroy(AUTH *);
static bool_t authnone_marshal(AUTH *client, XDR *xdrs);
struct opaque_auth _null_auth;
static struct auth_ops ops = {
authnone_verf,
authnone_marshal,
authnone_validate,
authnone_refresh,
authnone_destroy
};
static struct authnone_private {
AUTH no_client;
char marshalled_client[MAX_MARSHEL_SIZE];
unsigned int mcnt;
} *authnone_private;
AUTH *authnone_create()
{
register struct authnone_private *ap = authnone_private;
XDR xdr_stream;
register XDR *xdrs;
extern bool_t xdr_opaque_auth(XDR *xdrs, struct opaque_auth *ap);
if (ap == 0) {
ap = (struct authnone_private *) rt_malloc (sizeof(*ap));
if (ap == 0) return NULL;
memset(ap, 0, sizeof(*ap));
authnone_private = ap;
}
if (!ap->mcnt) {
ap->no_client.ah_cred = ap->no_client.ah_verf = _null_auth;
ap->no_client.ah_ops = &ops;
xdrs = &xdr_stream;
xdrmem_create(xdrs, ap->marshalled_client,
(unsigned int) MAX_MARSHEL_SIZE, XDR_ENCODE);
(void) xdr_opaque_auth(xdrs, &ap->no_client.ah_cred);
(void) xdr_opaque_auth(xdrs, &ap->no_client.ah_verf);
ap->mcnt = XDR_GETPOS(xdrs);
XDR_DESTROY(xdrs);
}
return (&ap->no_client);
}
/*ARGSUSED*/
static bool_t authnone_marshal(AUTH *client, XDR *xdrs)
{
register struct authnone_private *ap = authnone_private;
if (ap == 0)
return (0);
return ((*xdrs->x_ops->x_putbytes) (xdrs,
ap->marshalled_client, ap->mcnt));
}
static void authnone_verf(AUTH *x)
{
}
static bool_t authnone_validate(AUTH *x, struct opaque_auth *x1)
{
return (TRUE);
}
static bool_t authnone_refresh(AUTH *x)
{
return (FALSE);
}
static void authnone_destroy(AUTH *x)
{
}
File diff suppressed because it is too large Load Diff
@@ -1,95 +0,0 @@
/*
* Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
*/
/* @(#)clnt_generic.c 2.2 88/08/01 4.0 RPCSRC */
/*
* Sun RPC is a product of Sun Microsystems, Inc. and is provided for
* unrestricted use provided that this legend is included on all tape
* media and as a part of the software program in whole or part. Users
* may copy or modify Sun RPC without charge, but are not authorized
* to license or distribute it to anyone else except as part of a product or
* program developed by the user.
*
* SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
* WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
* PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
*
* Sun RPC is provided with no support and without any obligation on the
* part of Sun Microsystems, Inc. to assist in its use, correction,
* modification or enhancement.
*
* SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
* INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
* OR ANY PART THEREOF.
*
* In no event will Sun Microsystems, Inc. be liable for any lost revenue
* or profits or other special, indirect and consequential damages, even if
* Sun has been advised of the possibility of such damages.
*
* Sun Microsystems, Inc.
* 2550 Garcia Avenue
* Mountain View, California 94043
*/
#if !defined(lint) && defined(SCCSIDS)
static char sccsid[] = "@(#)clnt_generic.c 1.4 87/08/11 (C) 1987 SMI";
#endif
/*
* Copyright (C) 1987, Sun Microsystems, Inc.
*/
#include <rpc/rpc.h>
#include <string.h>
/*
* Generic client creation: takes (hostname, program-number, protocol) and
* returns client handle. Default options are set, which the user can
* change using the rpc equivalent of ioctl()'s.
*/
CLIENT *clnt_create(const char *hostname, const unsigned long prog,
const unsigned long vers, const char *proto)
{
int sock;
struct sockaddr_in server;
struct addrinfo hint, *res = NULL;
struct timeval tv;
CLIENT *client;
int ret;
memset(&hint, 0, sizeof(hint));
ret = getaddrinfo(hostname, NULL, &hint, &res);
if (ret != 0)
{
rt_kprintf("getaddrinfo err: %d '%s'\n", ret, hostname);
return NULL;
}
memcpy(&server, res->ai_addr, sizeof(struct sockaddr_in));
freeaddrinfo(res);
sock = -1;
if (strcmp(proto, "udp") == 0)
{
tv.tv_sec = 5;
tv.tv_usec = 0;
client = clntudp_create(&server, prog, vers, tv, &sock);
if (client == NULL) return NULL;
tv.tv_sec = 1;
clnt_control(client, CLSET_TIMEOUT, (char *)&tv);
}
else
{
rt_kprintf("unknow protocol\n");
return NULL;
}
return (client);
}
void clnt_perror(CLIENT *rpch, const char *s)
{
rt_kprintf("rpc client error:%s\n", s);
}
File diff suppressed because it is too large Load Diff
@@ -1,62 +0,0 @@
/*
* Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
*/
#include "pmap.h"
#include "clnt.h"
#include <rpc/rpc.h>
static struct timeval timeout = { 5, 0 };
static struct timeval tottimeout = { 60, 0 };
bool_t xdr_pmap(XDR *xdrs, struct pmap *regs)
{
if (xdr_u_long(xdrs, &regs->pm_prog) &&
xdr_u_long(xdrs, &regs->pm_vers) &&
xdr_u_long(xdrs, &regs->pm_prot))
return (xdr_u_long(xdrs, &regs->pm_port));
return (FALSE);
}
/*
* Find the mapped port for program,version.
* Calls the pmap service remotely to do the lookup.
* Returns 0 if no map exists.
*/
unsigned short pmap_getport(struct sockaddr_in *address, unsigned long program, unsigned long version, unsigned int protocol)
{
unsigned short port = 0;
int socket = -1;
register CLIENT *client = RT_NULL;
struct pmap parms;
address->sin_port = htons((unsigned short)PMAPPORT);
if (protocol == IPPROTO_UDP)
client = clntudp_bufcreate(address, PMAPPROG, PMAPVERS, timeout,
&socket, RPCSMALLMSGSIZE,
RPCSMALLMSGSIZE);
if (client != (CLIENT *) NULL)
{
parms.pm_prog = program;
parms.pm_vers = version;
parms.pm_prot = protocol;
parms.pm_port = 0; /* not needed or used */
if (CLNT_CALL(client, PMAPPROC_GETPORT, (xdrproc_t)xdr_pmap, (char*)&parms,
(xdrproc_t)xdr_u_short, (char*)&port, tottimeout) != RPC_SUCCESS)
{
rt_kprintf("pmap failure\n");
}
CLNT_DESTROY(client);
}
(void) lwip_close(socket);
address->sin_port = 0;
return (port);
}
@@ -1,66 +0,0 @@
/*
* Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
*/
#ifndef __RPC_PMAP_PROT_H__
#define __RPC_PMAP_PROT_H__
#include <rpc/xdr.h>
/* The following procedures are supported by the protocol:
*
* PMAPPROC_NULL() returns ()
* takes nothing, returns nothing
*
* PMAPPROC_SET(struct pmap) returns (bool_t)
* TRUE is success, FALSE is failure. Registers the tuple
* [prog, vers, prot, port].
*
* PMAPPROC_UNSET(struct pmap) returns (bool_t)
* TRUE is success, FALSE is failure. Un-registers pair
* [prog, vers]. prot and port are ignored.
*
* PMAPPROC_GETPORT(struct pmap) returns (long unsigned).
* 0 is failure. Otherwise returns the port number where the pair
* [prog, vers] is registered. It may lie!
*
* PMAPPROC_DUMP() RETURNS (struct pmaplist *)
*
* PMAPPROC_CALLIT(unsigned, unsigned, unsigned, string<>)
* RETURNS (port, string<>);
* usage: encapsulatedresults = PMAPPROC_CALLIT(prog, vers, proc, encapsulatedargs);
* Calls the procedure on the local machine. If it is not registered,
* this procedure is quite; ie it does not return error information!!!
* This procedure only is supported on rpc/udp and calls via
* rpc/udp. This routine only passes null authentication parameters.
* This file has no interface to xdr routines for PMAPPROC_CALLIT.
*
* The service supports remote procedure calls on udp/ip or tcp/ip socket 111.
*/
#define PMAPPORT ((unsigned short)111)
#define PMAPPROG ((unsigned long)100000)
#define PMAPVERS ((unsigned long)2)
#define PMAPVERS_PROTO ((unsigned long)2)
#define PMAPVERS_ORIG ((unsigned long)1)
#define PMAPPROC_NULL ((unsigned long)0)
#define PMAPPROC_SET ((unsigned long)1)
#define PMAPPROC_UNSET ((unsigned long)2)
#define PMAPPROC_GETPORT ((unsigned long)3)
#define PMAPPROC_DUMP ((unsigned long)4)
#define PMAPPROC_CALLIT ((unsigned long)5)
struct pmap {
long unsigned pm_prog;
long unsigned pm_vers;
long unsigned pm_prot;
long unsigned pm_port;
};
extern bool_t xdr_pmap (XDR *__xdrs, struct pmap *__regs);
#endif
@@ -1,62 +0,0 @@
/*
* Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
*/
/* @(#)rpc.h 2.3 88/08/10 4.0 RPCSRC; from 1.9 88/02/08 SMI */
/*
* Sun RPC is a product of Sun Microsystems, Inc. and is provided for
* unrestricted use provided that this legend is included on all tape
* media and as a part of the software program in whole or part. Users
* may copy or modify Sun RPC without charge, but are not authorized
* to license or distribute it to anyone else except as part of a product or
* program developed by the user.
*
* SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
* WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
* PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
*
* Sun RPC is provided with no support and without any obligation on the
* part of Sun Microsystems, Inc. to assist in its use, correction,
* modification or enhancement.
*
* SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
* INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
* OR ANY PART THEREOF.
*
* In no event will Sun Microsystems, Inc. be liable for any lost revenue
* or profits or other special, indirect and consequential damages, even if
* Sun has been advised of the possibility of such damages.
*
* Sun Microsystems, Inc.
* 2550 Garcia Avenue
* Mountain View, California 94043
*/
/*
* rpc.h, Just includes the billions of rpc header files necessary to
* do remote procedure calling.
*
* Copyright (C) 1984, Sun Microsystems, Inc.
*/
#ifndef _RPC_RPC_H
#define _RPC_RPC_H 1
#include <rpc/types.h> /* some typedefs */
/* external data representation interfaces */
#include <rpc/xdr.h> /* generic (de)serializer */
#include <rpc/auth.h>
/* Client side (mostly) remote procedure call */
#include <rpc/clnt.h> /* generic rpc stuff */
/* semi-private protocol headers */
#include <rpc/rpc_msg.h> /* protocol for rpc messages */
#endif
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
@@ -1,89 +0,0 @@
/*
* Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
*/
/*
* Sun RPC is a product of Sun Microsystems, Inc. and is provided for
* unrestricted use provided that this legend is included on all tape
* media and as a part of the software program in whole or part. Users
* may copy or modify Sun RPC without charge, but are not authorized
* to license or distribute it to anyone else except as part of a product or
* program developed by the user.
*
* SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
* WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
* PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
*
* Sun RPC is provided with no support and without any obligation on the
* part of Sun Microsystems, Inc. to assist in its use, correction,
* modification or enhancement.
*
* SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
* INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
* OR ANY PART THEREOF.
*
* In no event will Sun Microsystems, Inc. be liable for any lost revenue
* or profits or other special, indirect and consequential damages, even if
* Sun has been advised of the possibility of such damages.
*
* Sun Microsystems, Inc.
* 2550 Garcia Avenue
* Mountain View, California 94043
*/
/* fixincludes should not add extern "C" to this file */
/*
* Rpc additions to <sys/types.h>
*/
#ifndef _RPC_TYPES_H
#define _RPC_TYPES_H 1
#include <rtthread.h>
#include <lwip/netdb.h>
#include <lwip/sockets.h>
#include <string.h>
#include <stdint.h>
#ifndef RT_USING_MINILIBC
typedef unsigned int u_int;
typedef unsigned char u_char;
typedef unsigned long u_long;
#else
#include <sys/types.h>
#include <stdint.h>
#endif
typedef int bool_t;
typedef int enum_t;
#if !defined(RT_USING_NEWLIB) && !defined(RT_USING_MUSL)
typedef unsigned long dev_t;
#endif
/* This needs to be changed to uint32_t in the future */
typedef unsigned long rpcprog_t;
typedef unsigned long rpcvers_t;
typedef unsigned long rpcproc_t;
typedef unsigned long rpcprot_t;
typedef unsigned long rpcport_t;
#define __dontcare__ -1
#ifndef FALSE
# define FALSE (0)
#endif
#ifndef TRUE
# define TRUE (1)
#endif
#ifndef MAXHOSTNAMELEN
#define MAXHOSTNAMELEN 64
#endif
#endif /* rpc/types.h */
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
@@ -1,172 +0,0 @@
/*
* Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
*/
/* @(#)xdr_mem.c 2.1 88/07/29 4.0 RPCSRC */
/*
* Sun RPC is a product of Sun Microsystems, Inc. and is provided for
* unrestricted use provided that this legend is included on all tape
* media and as a part of the software program in whole or part. Users
* may copy or modify Sun RPC without charge, but are not authorized
* to license or distribute it to anyone else except as part of a product or
* program developed by the user.
*
* SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
* WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
* PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
*
* Sun RPC is provided with no support and without any obligation on the
* part of Sun Microsystems, Inc. to assist in its use, correction,
* modification or enhancement.
*
* SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
* INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
* OR ANY PART THEREOF.
*
* In no event will Sun Microsystems, Inc. be liable for any lost revenue
* or profits or other special, indirect and consequential damages, even if
* Sun has been advised of the possibility of such damages.
*
* Sun Microsystems, Inc.
* 2550 Garcia Avenue
* Mountain View, California 94043
*/
#if !defined(lint) && defined(SCCSIDS)
static char sccsid[] = "@(#)xdr_mem.c 1.19 87/08/11 Copyr 1984 Sun Micro";
#endif
/*
* xdr_mem.h, XDR implementation using memory buffers.
*
* Copyright (C) 1984, Sun Microsystems, Inc.
*
* If you have some data to be interpreted as external data representation
* or to be converted to external data representation in a memory buffer,
* then this is the package for you.
*
*/
#include <rpc/types.h>
#include <rpc/xdr.h>
#include <string.h>
#include <limits.h>
static bool_t xdrmem_getlong (XDR *, long *);
static bool_t xdrmem_putlong (XDR *, const long *);
static bool_t xdrmem_getbytes (XDR *, char *, unsigned int);
static bool_t xdrmem_putbytes (XDR *, const char *, unsigned int);
static unsigned int xdrmem_getpos (const XDR *);
static bool_t xdrmem_setpos (XDR *, unsigned int);
static int32_t *xdrmem_inline (XDR *, unsigned int);
static void xdrmem_destroy (XDR *);
static struct xdr_ops xdrmem_ops = {
xdrmem_getlong,
xdrmem_putlong,
xdrmem_getbytes,
xdrmem_putbytes,
xdrmem_getpos,
xdrmem_setpos,
xdrmem_inline,
xdrmem_destroy,
NULL,
NULL
};
/*
* The procedure xdrmem_create initializes a stream descriptor for a
* memory buffer.
*/
void
xdrmem_create (XDR *xdrs, const char* addr, unsigned int size, enum xdr_op op)
{
xdrs->x_op = op;
xdrs->x_ops = &xdrmem_ops;
xdrs->x_private = xdrs->x_base = (char*)addr;
xdrs->x_handy = size;
}
static void
xdrmem_destroy (XDR *xdrs)
{
}
static bool_t
xdrmem_getlong (XDR *xdrs, long *lp)
{
if (xdrs->x_handy < 4) return FALSE;
xdrs->x_handy -= 4;
*lp = (int32_t) ntohl((*((int32_t *) (xdrs->x_private))));
xdrs->x_private += 4;
return TRUE;
}
static bool_t
xdrmem_putlong (XDR *xdrs, const long *lp)
{
if (xdrs->x_handy < 4) return FALSE;
xdrs->x_handy -= 4;
*(int32_t *) xdrs->x_private = htonl(*lp);
xdrs->x_private += 4;
return (TRUE);
}
static bool_t
xdrmem_getbytes (XDR *xdrs, char *addr, unsigned int len)
{
if (xdrs->x_handy < len) return FALSE;
xdrs->x_handy -= len;
memmove(addr, xdrs->x_private, len);
xdrs->x_private += len;
return TRUE;
}
static bool_t
xdrmem_putbytes (XDR *xdrs, const char *addr, unsigned int len)
{
if (xdrs->x_handy < len) return FALSE;
xdrs->x_handy -= len;
memmove(xdrs->x_private, addr, len);
xdrs->x_private += len;
return (TRUE);
}
static unsigned int xdrmem_getpos (const XDR *xdrs)
{
return ((unsigned long) xdrs->x_private - (unsigned long) xdrs->x_base);
}
static bool_t xdrmem_setpos(XDR *xdrs, unsigned int pos)
{
register char* newaddr = xdrs->x_base + pos;
register char* lastaddr = xdrs->x_private + xdrs->x_handy;
if ((long) newaddr > (long) lastaddr
|| (UINT_MAX < LONG_MAX
&& (long) UINT_MAX < (long) lastaddr - (long) newaddr))
return (FALSE);
xdrs->x_private = newaddr;
xdrs->x_handy = (long) lastaddr - (long) newaddr;
return (TRUE);
}
static int32_t *
xdrmem_inline (XDR *xdrs, unsigned int len)
{
int32_t *buf = 0;
if (xdrs->x_handy >= len) {
xdrs->x_handy -= len;
buf = (int32_t *) xdrs->x_private;
xdrs->x_private += len;
}
return (buf);
}
File diff suppressed because it is too large Load Diff
@@ -27,6 +27,8 @@ static const unsigned char _dummy_txt[] =
rt_weak const struct romfs_dirent _root_dirent[] =
{
{ROMFS_DIRENT_DIR, "dev", RT_NULL, 0},
{ROMFS_DIRENT_DIR, "mnt", RT_NULL, 0},
{ROMFS_DIRENT_DIR, "dummy", (rt_uint8_t *)_dummy, sizeof(_dummy) / sizeof(_dummy[0])},
{ROMFS_DIRENT_FILE, "dummy.txt", _dummy_txt, sizeof(_dummy_txt)},
};
@@ -35,4 +37,3 @@ rt_weak const struct romfs_dirent romfs_root =
{
ROMFS_DIRENT_DIR, "/", (rt_uint8_t *)_root_dirent, sizeof(_root_dirent) / sizeof(_root_dirent[0])
};
@@ -94,4 +94,3 @@ int dfs_skt_init(void)
return 0;
}
INIT_COMPONENT_EXPORT(dfs_skt_init);
File diff suppressed because it is too large Load Diff
+30 -33
View File
@@ -1,11 +1,12 @@
/*
* Copyright (c) 2006-2021, RT-Thread Development Team
* Copyright (c) 2006-2023, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2005-02-22 Bernard The first version.
* 2023-05-05 Bernard change to dfs v2.0
*/
#ifndef __DFS_H__
@@ -15,21 +16,15 @@
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <dirent.h>
#include "../../libc/compilers/common/include/dirent.h"
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/statfs.h>
#include <sys/time.h>
#include <sys/errno.h>
#include <rtatomic.h>
#include <rtdevice.h>
#ifdef __cplusplus
extern "C" {
#endif
#ifndef DFS_FILESYSTEMS_MAX
#define DFS_FILESYSTEMS_MAX 4
#endif
#ifndef DFS_FD_MAX
#define DFS_FD_MAX 16
#endif
@@ -49,25 +44,32 @@ extern "C" {
#define SECTOR_SIZE 512
#endif
#ifndef DFS_FILESYSTEM_TYPES_MAX
#define DFS_FILESYSTEM_TYPES_MAX 2
#endif
#define DFS_FS_FLAG_DEFAULT 0x00 /* default flag */
#define DFS_FS_FLAG_FULLPATH 0x01 /* set full path to underlaying file system */
/* File types */
#define FT_REGULAR 0 /* regular file */
#define FT_SOCKET 1 /* socket file */
#define FT_DIRECTORY 2 /* directory */
#define FT_USER 3 /* user defined */
#define FT_DEVICE 4 /* device */
/* File flags */
#define DFS_F_OPEN 0x01000000
#define DFS_F_DIRECTORY 0x02000000
#define DFS_F_EOF 0x04000000
#define DFS_F_ERR 0x08000000
#define DFS_F_FREAD 0x01
#define DFS_F_FWRITE 0x02
#ifdef __cplusplus
extern "C" {
#endif
rt_inline int dfs_fflags(int oflags)
{
int rw = oflags & O_ACCMODE;
oflags &= ~O_ACCMODE;
return (rw + 1) | oflags;
}
rt_inline int dfs_oflags(int fflags)
{
int rw = fflags & (DFS_F_FREAD | DFS_F_FWRITE);
fflags &= ~(DFS_F_FREAD | DFS_F_FWRITE);
return (rw - 1) | fflags;
}
struct dfs_fdtable
{
@@ -81,18 +83,12 @@ int dfs_init(void);
char *dfs_normalize_path(const char *directory, const char *filename);
const char *dfs_subdir(const char *directory, const char *filename);
int fd_is_open(const char *pathname);
struct dfs_fdtable *dfs_fdtable_get(void);
void dfs_lock(void);
rt_err_t dfs_lock(void);
void dfs_unlock(void);
void dfs_file_lock(void);
rt_err_t dfs_file_lock(void);
void dfs_file_unlock(void);
void dfs_fm_lock(void);
void dfs_fm_unlock(void);
#ifdef DFS_USING_POSIX
/* FD APIs */
int fdt_fd_new(struct dfs_fdtable *fdt);
@@ -108,6 +104,7 @@ void fd_init(struct dfs_file *fd);
struct dfs_fdtable *dfs_fdtable_get(void);
struct dfs_fdtable *dfs_fdtable_get_global(void);
int dfs_dup(int oldfd, int startfd);
#endif /* DFS_USING_POSIX */
#ifdef __cplusplus
@@ -0,0 +1,64 @@
/*
* Copyright (c) 2006-2023, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2023-05-05 Bernard Implement dentry in dfs v2.0
*/
#ifndef __DFS_DENTRY_H__
#define __DFS_DENTRY_H__
#include "dfs_file.h"
#include "dfs_fs.h"
#ifdef __cplusplus
extern "C"
{
#endif
struct dfs_mnt;
struct dfs_vnode;
struct dfs_dentry
{
rt_list_t hashlist;
uint32_t flags;
#define DENTRY_IS_MOUNTED 0x1 /* dentry is mounted */
#define DENTRY_IS_ALLOCED 0x2 /* dentry is allocated */
#define DENTRY_IS_ADDHASH 0x4 /* dentry was added into hash table */
#define DENTRY_IS_OPENED 0x8 /* dentry was opened. */
char *pathname; /* the pathname under mounted file sytem */
struct dfs_vnode *vnode; /* the vnode of this dentry */
struct dfs_mnt *mnt; /* which mounted file system does this dentry belong to */
rt_atomic_t ref_count; /* the reference count */
};
struct dfs_dentry *dfs_dentry_create(struct dfs_mnt *mnt, char *fullpath);
struct dfs_dentry *dfs_dentry_unref(struct dfs_dentry *dentry);
struct dfs_dentry *dfs_dentry_ref(struct dfs_dentry *dentry);
void dfs_dentry_insert(struct dfs_dentry *dentry);
struct dfs_dentry *dfs_dentry_lookup(struct dfs_mnt *mnt, const char *path, uint32_t flags);
/* get full path of a dentry */
char* dfs_dentry_full_path(struct dfs_dentry* dentry);
/* get pathname (with mnt path) of a dentry */
char* dfs_dentry_pathname(struct dfs_dentry* dentry);
/* get full path crc32 */
uint32_t dfs_dentry_full_path_crc32(struct dfs_dentry* dentry);
int dfs_dentry_init(void);
#ifdef __cplusplus
}
#endif
#endif /*__DFS_DENTRY_H__*/
File diff suppressed because it is too large Load Diff
+63 -64
View File
@@ -1,99 +1,98 @@
/*
* Copyright (c) 2006-2021, RT-Thread Development Team
* Copyright (c) 2006-2023, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2005-02-22 Bernard The first version.
* 2023-05-05 Bernard Change to dfs v2.0
*/
#ifndef __DFS_FS_H__
#define __DFS_FS_H__
#include <dfs.h>
#include <sys/types.h>
#include <sys/errno.h>
#include <dfs_file.h>
#ifdef __cplusplus
extern "C" {
extern "C"
{
#endif
/* Pre-declaration */
struct dfs_filesystem;
struct dfs_file;
/* File system operations */
struct dfs_filesystem_ops
{
char *name;
uint32_t flags; /* flags for file system operations */
/* operations for file */
const struct dfs_file_ops *fops;
/* mount and unmount file system */
int (*mount) (struct dfs_filesystem *fs, unsigned long rwflag, const void *data);
int (*unmount) (struct dfs_filesystem *fs);
/* make a file system */
int (*mkfs) (rt_device_t dev_id, const char *fs_name);
int (*statfs) (struct dfs_filesystem *fs, struct statfs *buf);
int (*unlink) (struct dfs_filesystem *fs, const char *pathname);
int (*stat) (struct dfs_filesystem *fs, const char *filename, struct stat *buf);
int (*rename) (struct dfs_filesystem *fs, const char *oldpath, const char *newpath);
};
/* Mounted file system */
struct dfs_filesystem
{
rt_device_t dev_id; /* Attached device */
char *path; /* File system mount point */
const struct dfs_filesystem_ops *ops; /* Operations for file system type */
void *data; /* Specific file system data */
};
/* file system partition table */
struct dfs_partition
{
uint8_t type; /* file system type */
off_t offset; /* partition start offset */
size_t size; /* partition size */
uint8_t type; /* file system type */
off_t offset; /* partition start offset */
size_t size; /* partition size */
rt_sem_t lock;
};
/* mount table */
struct dfs_mount_tbl
struct dfs_attr
{
const char *device_name;
const char *path;
const char *filesystemtype;
unsigned long rwflag;
const void *data;
mode_t st_mode;
};
int dfs_register(const struct dfs_filesystem_ops *ops);
struct dfs_filesystem *dfs_filesystem_lookup(const char *path);
struct dfs_mnt;
struct dfs_dentry;
struct dfs_vnode;
struct statfs;
struct dfs_filesystem_ops
{
const char *name;
uint32_t flags;
#define FS_NEED_DEVICE 0x1
const struct dfs_file_ops *default_fops;
int (*mount)(struct dfs_mnt *mnt, unsigned long rwflag, const void *data);
int (*umount)(struct dfs_mnt *mnt);
int (*mkfs)(rt_device_t devid, const char *fs_name);
int (*readlink)(struct dfs_dentry *dentry, char *buf, int len);
int (*link)(struct dfs_dentry *src_dentry, struct dfs_dentry *dst_dentry); /*hard link interface */
int (*unlink)(struct dfs_dentry *dentry);
int (*symlink)(struct dfs_dentry *parent_dentry, const char *target, const char *newpath); /*soft link interface*/
int (*rename)(struct dfs_dentry *old_dentry, struct dfs_dentry *new_dentry);
int (*stat)(struct dfs_dentry *dentry, struct stat *buf);
int (*statfs)(struct dfs_mnt *mnt, struct statfs *buf);
int (*setattr) (struct dfs_dentry *dentry, struct dfs_attr *attr);
struct dfs_vnode* (*lookup)(struct dfs_dentry *dentry);
struct dfs_vnode* (*create_vnode)(struct dfs_dentry *dentry, int type, mode_t mode);
int (*free_vnode)(struct dfs_vnode* vnode);
};
struct dfs_filesystem_type
{
const struct dfs_filesystem_ops *fs_ops;
struct dfs_filesystem_type *next;
};
int dfs_unregister(struct dfs_filesystem_type *fs);
int dfs_register(struct dfs_filesystem_type *fs);
const char *dfs_filesystem_get_mounted_path(struct rt_device *device);
int dfs_filesystem_get_partition(struct dfs_partition *part,
uint8_t *buf,
uint32_t pindex);
int dfs_mount(const char *device_name,
const char *path,
const char *filesystemtype,
unsigned long rwflag,
const void *data);
const char *path,
const char *filesystemtype,
unsigned long rwflag,
const void *data);
int dfs_umount(const char *specialfile);
int dfs_unmount(const char *specialfile);
int dfs_mkfs(const char *fs_name, const char *device_name);
int dfs_statfs(const char *path, struct statfs *buffer);
int dfs_mount_device(rt_device_t dev);
int dfs_unmount_device(rt_device_t dev);
int dfs_filesystem_get_partition(struct dfs_partition *part,
uint8_t *buf,
uint32_t pindex);
#ifdef __cplusplus
}
+65
View File
@@ -0,0 +1,65 @@
/*
* Copyright (c) 2006-2023, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2023-05-05 Bernard Implement dentry in dfs v2.0
*/
#ifndef DFS_MNT_H__
#define DFS_MNT_H__
#include <rtservice.h>
#include <rtthread.h>
#ifdef __cplusplus
extern "C"
{
#endif
struct dfs_mnt;
struct dfs_dentry;
struct dfs_filesystem_ops;
struct dfs_mnt
{
struct dfs_mnt *parent; /* the parent mounted file system */
rt_list_t sibling; /* the sibling node for mounted list */
rt_list_t child; /* the child node for mounted list */
char *fullpath; /* the fullpath of this mounted file system */
int flags; /* the falgs of this mounted file system */
#define MNT_IS_ALLOCED 0x1 /* the mnt struct is allocated */
#define MNT_IS_ADDLIST 0x2 /* the mnt struct is added into list */
#define MNT_IS_MOUNTED 0x4 /* the mnt struct is mounted */
rt_atomic_t ref_count; /* reference count */
rt_device_t dev_id; /* the mounted device id */
const struct dfs_filesystem_ops *fs_ops;
void *data;
};
struct dfs_mnt *dfs_mnt_create(const char *path);
int dfs_mnt_destroy(struct dfs_mnt* mnt);
int dfs_mnt_list(struct dfs_mnt* mnt);
int dfs_mnt_insert(struct dfs_mnt* mnt, struct dfs_mnt* child);
struct dfs_mnt *dfs_mnt_lookup(const char *path);
const char *dfs_mnt_get_mounted_path(struct rt_device *device);
struct dfs_mnt* dfs_mnt_ref(struct dfs_mnt* mnt);
int dfs_mnt_unref(struct dfs_mnt* mnt);
rt_bool_t dfs_mnt_has_child_mnt(struct dfs_mnt *mnt, const char* fullpath);
#ifdef __cplusplus
}
#endif
#endif
+32
View File
@@ -0,0 +1,32 @@
/*
* Copyright (c) 2006-2023, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2009-05-27 Yi.qiu The first version.
* 2010-07-18 Bernard add stat and statfs structure definitions.
* 2011-05-16 Yi.qiu Change parameter name of rename, "new" is C++ key word.
* 2017-12-27 Bernard Add fcntl API.
* 2018-02-07 Bernard Change the 3rd parameter of open/fcntl/ioctl to '...'
*/
#ifndef __DFS_POSIX_H__
#define __DFS_POSIX_H__
#include <fcntl.h>
#include <errno.h>
#include <dfs.h>
#include <dfs_file.h>
#ifdef __cplusplus
extern "C" {
#endif
#ifdef __cplusplus
}
#endif
#endif
@@ -1,28 +0,0 @@
/*
* Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
*/
#ifndef DFS_PRIVATE_H__
#define DFS_PRIVATE_H__
#include <dfs.h>
#define DBG_TAG "DFS"
#define DBG_LVL DBG_INFO
#include <rtdbg.h>
#define NO_WORKING_DIR "system does not support working directory\n"
/* extern variable */
extern const struct dfs_filesystem_ops *filesystem_operation_table[];
extern struct dfs_filesystem filesystem_table[];
extern const struct dfs_mount_tbl mount_table[];
extern char working_directory[];
#endif
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+19
View File
@@ -0,0 +1,19 @@
/*
* Copyright (c) 2006-2023, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
*/
#ifndef DFS_PRIVATE_H__
#define DFS_PRIVATE_H__
#include <dfs.h>
#define NO_WORKING_DIR "system does not support working directory\n"
extern char working_directory[];
#endif
+134
View File
@@ -0,0 +1,134 @@
/*
* Copyright (c) 2006-2023, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2023-05-05 Bernard Implement vnode in dfs v2.0
*/
#include <dfs_file.h>
#include <dfs_mnt.h>
#define DBG_TAG "DFS.vnode"
#define DBG_LVL DBG_WARNING
#include <rtdbg.h>
int dfs_vnode_init(struct dfs_vnode *vnode, int type, const struct dfs_file_ops *fops)
{
if (vnode)
{
rt_memset(vnode, 0, sizeof(struct dfs_vnode));
vnode->type = type;
rt_atomic_store(&(vnode->ref_count), 1);
vnode->mnt = RT_NULL;
vnode->fops = fops;
}
return 0;
}
struct dfs_vnode *dfs_vnode_create(void)
{
struct dfs_vnode *vnode = rt_calloc(1, sizeof(struct dfs_vnode));
if (!vnode)
{
LOG_E("create a vnode failed.");
return RT_NULL;
}
rt_atomic_store(&(vnode->ref_count), 1);
LOG_I("create a vnode: %p", vnode);
return vnode;
}
int dfs_vnode_destroy(struct dfs_vnode* vnode)
{
rt_err_t ret = RT_EOK;
if (vnode)
{
ret = dfs_file_lock();
if (ret == RT_EOK)
{
if (rt_atomic_load(&(vnode->ref_count)) == 1)
{
LOG_I("free a vnode: %p", vnode);
if (vnode->mnt)
{
DLOG(msg, "vnode", vnode->mnt->fs_ops->name, DLOG_MSG, "fs_ops->free_vnode");
vnode->mnt->fs_ops->free_vnode(vnode);
}
else
{
DLOG(msg, "vnode", "vnode", DLOG_MSG, "destroy vnode(mnt=NULL)");
}
dfs_file_unlock();
rt_free(vnode);
}
else
{
dfs_file_unlock();
}
}
}
return 0;
}
struct dfs_vnode *dfs_vnode_ref(struct dfs_vnode *vnode)
{
if (vnode)
{
rt_atomic_add(&(vnode->ref_count), 1);
DLOG(note, "vnode", "vnode ref_count=%d", rt_atomic_load(&(vnode->ref_count)));
}
return vnode;
}
void dfs_vnode_unref(struct dfs_vnode *vnode)
{
rt_err_t ret = RT_EOK;
if (vnode)
{
ret = dfs_file_lock();
if (ret == RT_EOK)
{
rt_atomic_sub(&(vnode->ref_count), 1);
DLOG(note, "vnode", "vnode ref_count=%d", rt_atomic_load(&(vnode->ref_count)));
if (rt_atomic_load(&(vnode->ref_count)) == 0)
{
LOG_I("free a vnode: %p", vnode);
DLOG(msg, "vnode", "vnode", DLOG_MSG, "free vnode, ref_count=0");
if (vnode->mnt)
{
DLOG(msg, "vnode", vnode->mnt->fs_ops->name, DLOG_MSG, "fs_ops->free_vnode");
vnode->mnt->fs_ops->free_vnode(vnode);
}
dfs_file_unlock();
rt_free(vnode);
}
else
{
dfs_file_unlock();
DLOG(note, "vnode", "vnode ref_count=%d", rt_atomic_load(&(vnode->ref_count)));
}
}
}
return;
}
+14 -9
View File
@@ -200,7 +200,11 @@ static int pipe_fops_ioctl(struct dfs_file *fd, int cmd, void *args)
* When the return value is 0, it means O_NONBLOCK is enabled and there is no thread that has the pipe open for writing.
* When the return value is -EAGAIN, it means there are no data to be read.
*/
#ifdef RT_USING_DFS_V2
static int pipe_fops_read(struct dfs_file *fd, void *buf, size_t count, off_t *pos)
#else
static int pipe_fops_read(struct dfs_file *fd, void *buf, size_t count)
#endif
{
int len = 0;
rt_pipe_t *pipe;
@@ -254,7 +258,11 @@ out:
* When the return value is -EAGAIN, it means O_NONBLOCK is enabled and there are no space to be written.
* When the return value is -EPIPE, it means there is no thread that has the pipe open for reading.
*/
#ifdef RT_USING_DFS_V2
static int pipe_fops_write(struct dfs_file *fd, const void *buf, size_t count, off_t *pos)
#else
static int pipe_fops_write(struct dfs_file *fd, const void *buf, size_t count)
#endif
{
int len;
rt_pipe_t *pipe;
@@ -369,15 +377,12 @@ static int pipe_fops_poll(struct dfs_file *fd, rt_pollreq_t *req)
static const struct dfs_file_ops pipe_fops =
{
pipe_fops_open,
pipe_fops_close,
pipe_fops_ioctl,
pipe_fops_read,
pipe_fops_write,
RT_NULL,
RT_NULL,
RT_NULL,
pipe_fops_poll,
.open = pipe_fops_open,
.close = pipe_fops_close,
.ioctl = pipe_fops_ioctl,
.read = pipe_fops_read,
.write = pipe_fops_write,
.poll = pipe_fops_poll,
};
#endif /* defined(RT_USING_POSIX_DEVIO) && defined(RT_USING_POSIX_PIPE) */
+14 -9
View File
@@ -135,7 +135,11 @@ static int serial_fops_ioctl(struct dfs_file *fd, int cmd, void *args)
return rt_device_control(device, cmd, args);
}
#ifdef RT_USING_DFS_V2
static int serial_fops_read(struct dfs_file *fd, void *buf, size_t count, off_t *pos)
#else
static int serial_fops_read(struct dfs_file *fd, void *buf, size_t count)
#endif
{
int size = 0;
rt_device_t device;
@@ -169,7 +173,11 @@ static int serial_fops_read(struct dfs_file *fd, void *buf, size_t count)
return size;
}
#ifdef RT_USING_DFS_V2
static int serial_fops_write(struct dfs_file *fd, const void *buf, size_t count, off_t *pos)
#else
static int serial_fops_write(struct dfs_file *fd, const void *buf, size_t count)
#endif
{
rt_device_t device;
@@ -211,15 +219,12 @@ static int serial_fops_poll(struct dfs_file *fd, struct rt_pollreq *req)
static const struct dfs_file_ops _serial_fops =
{
serial_fops_open,
serial_fops_close,
serial_fops_ioctl,
serial_fops_read,
serial_fops_write,
RT_NULL, /* flush */
RT_NULL, /* lseek */
RT_NULL, /* getdents */
serial_fops_poll,
.open = serial_fops_open,
.close = serial_fops_close,
.ioctl = serial_fops_ioctl,
.read = serial_fops_read,
.write = serial_fops_write,
.poll = serial_fops_poll,
};
#endif /* RT_USING_POSIX_STDIO */
+15 -10
View File
@@ -338,7 +338,11 @@ static int tty_ioctl(struct dfs_file *fd, int cmd, void *args)
return ret;
}
#ifdef RT_USING_DFS_V2
static int tty_read(struct dfs_file *fd, void *buf, size_t count, off_t *pos)
#else
static int tty_read(struct dfs_file *fd, void *buf, size_t count)
#endif
{
int ret = 0;
struct tty_struct *tty = RT_NULL;
@@ -355,7 +359,11 @@ static int tty_read(struct dfs_file *fd, void *buf, size_t count)
return ret;
}
static int tty_write(struct dfs_file *fd, const void *buf, size_t count)
#ifdef RT_USING_DFS_V2
static int tty_write(struct dfs_file *fd, const void *buf, size_t count, off_t *pos)
#else
static int tty_write(struct dfs_file *fd, const void *buf, size_t count )
#endif
{
int ret = 0;
struct tty_struct *tty = RT_NULL;
@@ -391,15 +399,12 @@ static int tty_poll(struct dfs_file *fd, struct rt_pollreq *req)
static const struct dfs_file_ops tty_fops =
{
tty_open,
tty_close,
tty_ioctl,
tty_read,
tty_write,
RT_NULL, /* flush */
RT_NULL, /* lseek */
RT_NULL, /* getdents */
tty_poll,
.open = tty_open,
.close = tty_close,
.ioctl = tty_ioctl,
.read = tty_read,
.write = tty_write,
.poll = tty_poll,
};
const struct dfs_file_ops *tty_get_fops(void)
+14 -2
View File
@@ -677,9 +677,21 @@ void msh_auto_complete_path(char *path)
if (multi == 1)
{
struct stat buffer = {0};
if ((stat(path, &buffer) == 0) && (S_ISDIR(buffer.st_mode)))
if ((stat(path, &buffer) == 0))
{
strcat(path, "/");
if (S_ISDIR(buffer.st_mode))
{
strcat(path, "/");
}
else if (S_ISLNK(buffer.st_mode))
{
DIR *dir = opendir(path);
if (dir)
{
closedir(dir);
strcat(path, "/");
}
}
}
}
}
File diff suppressed because it is too large Load Diff
@@ -26,10 +26,14 @@ extern "C" {
#define FT_SOCKET 1 /* socket file */
#define FT_DIRECTORY 2 /* directory */
#define FT_USER 3 /* user defined */
#define FT_DEVICE 4 /* device */
#define FT_SYMLINK 5 /* symbol link */
#define DT_UNKNOWN 0x00
#define DT_REG 0x01
#define DT_DIR 0x02
#define DT_FIFO 0x01
#define DT_SYMLINK 0x03
#define DT_DIR 0x04
#define DT_REG 0x08
#ifndef HAVE_DIR_STRUCTURE
#define HAVE_DIR_STRUCTURE
@@ -61,7 +65,7 @@ DIR *opendir(const char *);
struct dirent *readdir(DIR *);
int readdir_r(DIR *, struct dirent *, struct dirent **);
void rewinddir(DIR *);
void seekdir(DIR *, long int);
void seekdir(DIR *, long);
long telldir(DIR *);
#ifdef __cplusplus
@@ -1,10 +1,32 @@
/*
* Copyright (c) 2006-2022, RT-Thread Development Team
* Copyright (c) 2006-2023, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2023/06/08 Bernard Add macro definition for `#pragma once`
*/
#ifndef UNISTD_H__
#define UNISTD_H__
#include "sys/unistd.h"
#ifndef F_OK
#define F_OK 0
#endif
#ifndef R_OK
#define R_OK 4
#endif
#ifndef W_OK
#define W_OK 2
#endif
#ifndef X_OK
#define X_OK 1
#endif
#endif /* UNISTD_H__ */
+14 -2
View File
@@ -13,12 +13,24 @@
#include <sys/_default_fcntl.h>
#ifndef O_DIRECTORY
#define O_DIRECTORY 0x200000
#ifndef O_EXEC
#define O_EXEC 0x400000
#endif
#ifndef O_TMPFILE
#define O_TMPFILE 0x800000
#endif
#ifndef O_BINARY
#define O_BINARY 0x10000
#endif
#ifndef O_NOFOLLOW
#define O_NOFOLLOW 0x100000
#endif
#ifndef O_DIRECTORY
#define O_DIRECTORY 0x200000
#endif
#endif
+3 -3
View File
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2006-2021, RT-Thread Development Team
* Copyright (c) 2006-2023, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
@@ -31,7 +31,7 @@ int libc_system_init(void)
if (dev_console)
{
int fd = libc_stdio_set_console(dev_console->parent.name, O_RDWR);
if (fd < 0)
if (fd < 0)
{
return -1;
}
@@ -43,7 +43,7 @@ int libc_system_init(void)
#endif /* RT_USING_POSIX_STDIO */
return 0;
}
INIT_COMPONENT_EXPORT(libc_system_init);
INIT_APP_EXPORT(libc_system_init);
#if defined(RT_USING_POSIX_STDIO) && defined(RT_USING_NEWLIBC)
+10 -22
View File
@@ -381,6 +381,7 @@ static int _ipc_msg_fd_new(void *file)
{
int fd;
struct dfs_file *d;
struct dfs_vnode *vnode = (struct dfs_vnode *)file;
fd = fd_new();
if (fd < 0)
@@ -395,7 +396,11 @@ static int _ipc_msg_fd_new(void *file)
return -1;
}
d->vnode = (struct dfs_vnode *)file;
#ifdef RT_USING_DFS_V2
d->fops = vnode->fops;
#endif
d->vnode = vnode;
d->flags = O_RDWR; /* set flags as read and write */
return fd;
@@ -946,15 +951,8 @@ static int channel_fops_close(struct dfs_file *file)
static const struct dfs_file_ops channel_fops =
{
NULL, /* open */
channel_fops_close,
NULL,
NULL,
NULL,
NULL,
NULL, /* lseek */
NULL, /* getdents */
channel_fops_poll,
.close = channel_fops_close, /* close */
.poll = channel_fops_poll, /* poll */
};
int lwp_channel_open(int fdt_type, const char *name, int flags)
@@ -980,18 +978,8 @@ int lwp_channel_open(int fdt_type, const char *name, int flags)
ch = rt_raw_channel_open(name, flags);
if (ch)
{
rt_memset(d->vnode, 0, sizeof(struct dfs_vnode));
rt_list_init(&d->vnode->list);
d->vnode->type = FT_USER;
d->vnode->path = NULL;
d->vnode->fullpath = NULL;
d->vnode->fops = &channel_fops;
d->flags = O_RDWR; /* set flags as read and write */
d->vnode->size = 0;
d->pos = 0;
d->vnode->ref_count = 1;
/* initialize vnode */
dfs_vnode_init(d->vnode, FT_USER, &channel_fops);
/* set socket to the data of dfs_file */
d->vnode->data = (void *)ch;
+70 -4
View File
@@ -40,6 +40,9 @@
#include <poll.h>
#include <sys/select.h>
#include <dfs_file.h>
#ifdef RT_USING_DFS_V2
#include <dfs_dentry.h>
#endif
#include <unistd.h>
#include <stdio.h> /* rename() */
#include <sys/stat.h>
@@ -482,6 +485,7 @@ sysret_t sys_open(const char *name, int flag, ...)
int ret = -1;
rt_size_t len = 0;
char *kname = RT_NULL;
mode_t mode = 0;
if (!lwp_user_accessable((void *)name, 1))
{
@@ -500,8 +504,16 @@ sysret_t sys_open(const char *name, int flag, ...)
return -ENOMEM;
}
if ((flag & O_CREAT) || (flag & O_TMPFILE) == O_TMPFILE)
{
va_list ap;
va_start(ap, flag);
mode = va_arg(ap, mode_t);
va_end(ap);
}
lwp_get_from_user(kname, (void *)name, len + 1);
ret = open(kname, flag, 0);
ret = open(kname, flag, mode);
if (ret < 0)
{
ret = GET_ERRNO();
@@ -511,11 +523,23 @@ sysret_t sys_open(const char *name, int flag, ...)
return ret;
#else
int ret;
mode_t mode = 0;
if (!lwp_user_accessable((void *)name, 1))
{
return -EFAULT;
}
int ret = open(name, flag, 0);
if ((flag & O_CREAT) || (flag & O_TMPFILE) == O_TMPFILE)
{
va_list ap;
va_start(ap, flag);
mode = va_arg(ap, mode_t);
va_end(ap);
}
ret = open(name, flag, mode);
return (ret < 0 ? GET_ERRNO() : ret);
#endif
}
@@ -3803,10 +3827,10 @@ sysret_t sys_rmdir(const char *path)
{
return -EFAULT;
}
err = unlink(path);
err = rmdir(path);
return (err < 0 ? GET_ERRNO() : err);
#else
int ret = unlink(path);
int ret = rmdir(path);
return (ret < 0 ? GET_ERRNO() : ret);
#endif
}
@@ -4294,7 +4318,28 @@ ssize_t sys_readlink(char* path, char *buf, size_t bufsz)
}
else
{
#ifdef RT_USING_DFS_V2
char *link_fn = (char *)rt_malloc(DFS_PATH_MAX);
if (link_fn)
{
err = dfs_file_readlink(copy_path, link_fn, DFS_PATH_MAX);
if (err > 0)
{
rtn = lwp_put_to_user(buf, link_fn, bufsz > err ? err : bufsz - 1);
}
else
{
rtn = -EIO;
}
rt_free(link_fn);
}
else
{
rtn = -ENOMEM;
}
#else
rtn = lwp_put_to_user(buf, copy_path, copy_len);
#endif
}
rt_free(copy_path);
return rtn;
@@ -4315,6 +4360,26 @@ ssize_t sys_readlink(char* path, char *buf, size_t bufsz)
return -EBADF;
}
#ifdef RT_USING_DFS_V2
{
char *fullpath = dfs_dentry_full_path(d->dentry);
if (fullpath)
{
copy_len = strlen(fullpath);
if (copy_len > bufsz)
{
copy_len = bufsz;
}
bufsz = lwp_put_to_user(buf, fullpath, copy_len);
rt_free(fullpath);
}
else
{
bufsz = 0;
}
}
#else
copy_len = strlen(d->vnode->fullpath);
if (copy_len > bufsz)
{
@@ -4322,6 +4387,7 @@ ssize_t sys_readlink(char* path, char *buf, size_t bufsz)
}
bufsz = lwp_put_to_user(buf, d->vnode->fullpath, copy_len);
#endif
return bufsz;
}
+16 -9
View File
@@ -46,7 +46,11 @@ static int dfs_net_ioctl(struct dfs_file* file, int cmd, void* args)
return ret;
}
#ifdef RT_USING_DFS_V2
static int dfs_net_read(struct dfs_file* file, void *buf, size_t count, off_t *pos)
#else
static int dfs_net_read(struct dfs_file* file, void *buf, size_t count)
#endif
{
int ret;
int socket = (int)(size_t)file->vnode->data;
@@ -57,10 +61,15 @@ static int dfs_net_read(struct dfs_file* file, void *buf, size_t count)
ret = rt_get_errno();
return (ret > 0) ? (-ret) : ret;
}
return ret;
}
#ifdef RT_USING_DFS_V2
static int dfs_net_write(struct dfs_file *file, const void *buf, size_t count, off_t *pos)
#else
static int dfs_net_write(struct dfs_file *file, const void *buf, size_t count)
#endif
{
int ret;
int socket = (int)(size_t)file->vnode->data;
@@ -71,8 +80,10 @@ static int dfs_net_write(struct dfs_file *file, const void *buf, size_t count)
ret = rt_get_errno();
return (ret > 0) ? (-ret) : ret;
}
return ret;
}
static int dfs_net_close(struct dfs_file* file)
{
int socket;
@@ -95,15 +106,11 @@ static int dfs_net_poll(struct dfs_file *file, struct rt_pollreq *req)
const struct dfs_file_ops _net_fops =
{
NULL, /* open */
dfs_net_close,
dfs_net_ioctl,
dfs_net_read,
dfs_net_write,
NULL,
NULL, /* lseek */
NULL, /* getdents */
dfs_net_poll,
.close = dfs_net_close,
.ioctl = dfs_net_ioctl,
.read = dfs_net_read,
.write = dfs_net_write,
.poll = dfs_net_poll,
};
const struct dfs_file_ops *dfs_net_get_fops(void)
+10 -22
View File
@@ -40,6 +40,9 @@ int accept(int s, struct sockaddr *addr, socklen_t *addrlen)
d = fd_get(fd);
if(d)
{
#ifdef RT_USING_DFS_V2
d->fops = dfs_net_get_fops();
#endif
/* this is a socket fd */
d->vnode = (struct dfs_vnode *)rt_malloc(sizeof(struct dfs_vnode));
if (!d->vnode)
@@ -50,16 +53,7 @@ int accept(int s, struct sockaddr *addr, socklen_t *addrlen)
return -1;
}
rt_memset(d->vnode, 0, sizeof(struct dfs_vnode));
rt_list_init(&d->vnode->list);
d->vnode->type = FT_SOCKET;
d->vnode->path = NULL;
d->vnode->fullpath = NULL;
d->vnode->ref_count = 1;
d->vnode->fops = dfs_net_get_fops();
d->flags = O_RDWR; /* set flags as read and write */
d->vnode->size = 0;
d->pos = 0;
dfs_vnode_init(d->vnode, FT_SOCKET, dfs_net_get_fops());
/* set socket to the data of dfs_file */
d->vnode->data = (void *)(size_t)new_socket;
@@ -238,6 +232,11 @@ int socket(int domain, int type, int protocol)
return -1;
}
d = fd_get(fd);
#ifdef RT_USING_DFS_V2
d->fops = dfs_net_get_fops();
#endif
d->vnode = (struct dfs_vnode *)rt_malloc(sizeof(struct dfs_vnode));
if (!d->vnode)
{
@@ -258,18 +257,7 @@ int socket(int domain, int type, int protocol)
socket = sal_socket(domain, type, protocol);
if (socket >= 0)
{
rt_memset(d->vnode, 0, sizeof(struct dfs_vnode));
rt_list_init(&d->vnode->list);
/* this is a socket fd */
d->vnode->type = FT_SOCKET;
d->vnode->path = NULL;
d->vnode->fullpath = NULL;
d->vnode->ref_count = 1;
d->vnode->fops = dfs_net_get_fops();
d->flags = O_RDWR; /* set flags as read and write */
d->vnode->size = 0;
d->pos = 0;
dfs_vnode_init(d->vnode, FT_SOCKET, dfs_net_get_fops());
/* set socket to the data of dfs_file */
d->vnode->data = (void *)(size_t)socket;