forked from Imagelibrary/rtems
2009-03-30 Sebastian Huber <sebastian.huber@embedded-brains.de>
* libcsupport/src/symlink.c: Check if path evaluation handler exists. * libnetworking/lib/ftpfs.c: Cleanup.
This commit is contained in:
@@ -1,3 +1,8 @@
|
|||||||
|
2009-03-30 Sebastian Huber <sebastian.huber@embedded-brains.de>
|
||||||
|
|
||||||
|
* libcsupport/src/symlink.c: Check if path evaluation handler exists.
|
||||||
|
* libnetworking/lib/ftpfs.c: Cleanup.
|
||||||
|
|
||||||
2009-03-27 Sebastian Huber <sebastian.huber@embedded-brains.de>
|
2009-03-27 Sebastian Huber <sebastian.huber@embedded-brains.de>
|
||||||
|
|
||||||
* Makefile.am, preinstall.am, libmisc/Makefile.am,
|
* Makefile.am, preinstall.am, libmisc/Makefile.am,
|
||||||
|
|||||||
@@ -29,6 +29,11 @@ int symlink(
|
|||||||
int result;
|
int result;
|
||||||
|
|
||||||
rtems_filesystem_get_start_loc( sympath, &i, &loc );
|
rtems_filesystem_get_start_loc( sympath, &i, &loc );
|
||||||
|
|
||||||
|
if ( !loc.ops->evalformake_h ) {
|
||||||
|
rtems_set_errno_and_return_minus_one( ENOTSUP );
|
||||||
|
}
|
||||||
|
|
||||||
result = (*loc.ops->evalformake_h)( &sympath[i], &loc, &name_start );
|
result = (*loc.ops->evalformake_h)( &sympath[i], &loc, &name_start );
|
||||||
if ( result != 0 )
|
if ( result != 0 )
|
||||||
return -1;
|
return -1;
|
||||||
|
|||||||
@@ -292,10 +292,10 @@ static rtems_ftpfs_reply rtems_ftpfs_send_command_with_parser(
|
|||||||
|
|
||||||
/* Send command argument if necessary */
|
/* Send command argument if necessary */
|
||||||
if (arg != NULL) {
|
if (arg != NULL) {
|
||||||
rv = send( socket, arg, strlen( arg), 0);
|
rv = send( socket, arg, strlen( arg), 0);
|
||||||
if (rv < 0) {
|
if (rv < 0) {
|
||||||
return RTEMS_FTPFS_REPLY_ERROR;
|
return RTEMS_FTPFS_REPLY_ERROR;
|
||||||
}
|
}
|
||||||
if (verbose) {
|
if (verbose) {
|
||||||
write( STDERR_FILENO, arg, strlen( arg));
|
write( STDERR_FILENO, arg, strlen( arg));
|
||||||
}
|
}
|
||||||
@@ -438,8 +438,10 @@ static socklen_t rtems_ftpfs_create_address(
|
|||||||
return sizeof( *sa);
|
return sizeof( *sa);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void rtems_ftpfs_terminate( rtems_ftpfs_entry *e, rtems_libio_t *iop)
|
static void rtems_ftpfs_terminate( rtems_libio_t *iop)
|
||||||
{
|
{
|
||||||
|
rtems_ftpfs_entry *e = iop->data1;
|
||||||
|
|
||||||
if (e != NULL) {
|
if (e != NULL) {
|
||||||
/* Close data connection if necessary */
|
/* Close data connection if necessary */
|
||||||
if (e->data_socket >= 0) {
|
if (e->data_socket >= 0) {
|
||||||
@@ -558,7 +560,6 @@ static int rtems_ftpfs_open_data_connection_active(
|
|||||||
int rv = 0;
|
int rv = 0;
|
||||||
int eno = 0;
|
int eno = 0;
|
||||||
rtems_ftpfs_reply reply = RTEMS_FTPFS_REPLY_ERROR;
|
rtems_ftpfs_reply reply = RTEMS_FTPFS_REPLY_ERROR;
|
||||||
struct in_addr address = { .s_addr = 0 };
|
|
||||||
struct sockaddr_in sa;
|
struct sockaddr_in sa;
|
||||||
socklen_t size = 0;
|
socklen_t size = 0;
|
||||||
int port_socket = -1;
|
int port_socket = -1;
|
||||||
@@ -676,7 +677,7 @@ static void rtems_ftpfs_pasv_parser(
|
|||||||
void *arg
|
void *arg
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
rtems_ftpfs_pasv_entry *e = (rtems_ftpfs_pasv_entry *) arg;
|
rtems_ftpfs_pasv_entry *e = arg;
|
||||||
size_t i = 0;
|
size_t i = 0;
|
||||||
|
|
||||||
for (i = 0; i < len; ++i) {
|
for (i = 0; i < len; ++i) {
|
||||||
@@ -725,7 +726,6 @@ static int rtems_ftpfs_open_data_connection_passive(
|
|||||||
int rv = 0;
|
int rv = 0;
|
||||||
rtems_ftpfs_reply reply = RTEMS_FTPFS_REPLY_ERROR;
|
rtems_ftpfs_reply reply = RTEMS_FTPFS_REPLY_ERROR;
|
||||||
struct sockaddr_in sa;
|
struct sockaddr_in sa;
|
||||||
socklen_t size = 0;
|
|
||||||
uint32_t data_address = 0;
|
uint32_t data_address = 0;
|
||||||
uint16_t data_port = 0;
|
uint16_t data_port = 0;
|
||||||
|
|
||||||
@@ -786,7 +786,6 @@ static int rtems_ftpfs_open(
|
|||||||
uint32_t mode
|
uint32_t mode
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
int rv = 0;
|
|
||||||
int eno = 0;
|
int eno = 0;
|
||||||
bool ok = false;
|
bool ok = false;
|
||||||
rtems_ftpfs_entry *e = NULL;
|
rtems_ftpfs_entry *e = NULL;
|
||||||
@@ -798,9 +797,12 @@ static int rtems_ftpfs_open(
|
|||||||
? "STOR "
|
? "STOR "
|
||||||
: "RETR ";
|
: "RETR ";
|
||||||
uint32_t client_address = 0;
|
uint32_t client_address = 0;
|
||||||
char *location = strdup( (const char *) iop->file_info);
|
char *location = iop->file_info;
|
||||||
|
|
||||||
/* Check allocation */
|
/* Invalidate data handle */
|
||||||
|
iop->data1 = NULL;
|
||||||
|
|
||||||
|
/* Check location, it was allocated during path evaluation */
|
||||||
if (location == NULL) {
|
if (location == NULL) {
|
||||||
return ENOMEM;
|
return ENOMEM;
|
||||||
}
|
}
|
||||||
@@ -810,8 +812,7 @@ static int rtems_ftpfs_open(
|
|||||||
(iop->flags & LIBIO_FLAGS_WRITE) != 0
|
(iop->flags & LIBIO_FLAGS_WRITE) != 0
|
||||||
&& (iop->flags & LIBIO_FLAGS_READ) != 0
|
&& (iop->flags & LIBIO_FLAGS_READ) != 0
|
||||||
) {
|
) {
|
||||||
eno = ENOTSUP;
|
return ENOTSUP;
|
||||||
goto cleanup;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Split location into parts */
|
/* Split location into parts */
|
||||||
@@ -823,8 +824,7 @@ static int rtems_ftpfs_open(
|
|||||||
&filename
|
&filename
|
||||||
);
|
);
|
||||||
if (!ok) {
|
if (!ok) {
|
||||||
eno = ENOENT;
|
return ENOENT;
|
||||||
goto cleanup;
|
|
||||||
}
|
}
|
||||||
DEBUG_PRINTF(
|
DEBUG_PRINTF(
|
||||||
"user = '%s', password = '%s', filename = '%s'\n",
|
"user = '%s', password = '%s', filename = '%s'\n",
|
||||||
@@ -836,8 +836,7 @@ static int rtems_ftpfs_open(
|
|||||||
/* Allocate connection entry */
|
/* Allocate connection entry */
|
||||||
e = malloc( sizeof( *e));
|
e = malloc( sizeof( *e));
|
||||||
if (e == NULL) {
|
if (e == NULL) {
|
||||||
eno = ENOMEM;
|
return ENOMEM;
|
||||||
goto cleanup;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Initialize connection entry */
|
/* Initialize connection entry */
|
||||||
@@ -845,6 +844,9 @@ static int rtems_ftpfs_open(
|
|||||||
e->data_socket = -1;
|
e->data_socket = -1;
|
||||||
e->eof = false;
|
e->eof = false;
|
||||||
|
|
||||||
|
/* Save connection state */
|
||||||
|
iop->data1 = e;
|
||||||
|
|
||||||
/* Open control connection */
|
/* Open control connection */
|
||||||
eno = rtems_ftpfs_open_ctrl_connection(
|
eno = rtems_ftpfs_open_ctrl_connection(
|
||||||
e,
|
e,
|
||||||
@@ -876,15 +878,9 @@ static int rtems_ftpfs_open(
|
|||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
|
|
||||||
/* Free location parts buffer */
|
if (eno != 0) {
|
||||||
free( location);
|
|
||||||
|
|
||||||
if (eno == 0) {
|
|
||||||
/* Save connection state */
|
|
||||||
iop->data1 = e;
|
|
||||||
} else {
|
|
||||||
/* Free all resources if an error occured */
|
/* Free all resources if an error occured */
|
||||||
rtems_ftpfs_terminate( e, iop);
|
rtems_ftpfs_terminate( iop);
|
||||||
}
|
}
|
||||||
|
|
||||||
return eno;
|
return eno;
|
||||||
@@ -896,8 +892,8 @@ static ssize_t rtems_ftpfs_read(
|
|||||||
size_t count
|
size_t count
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
rtems_ftpfs_entry *e = (rtems_ftpfs_entry *) iop->data1;
|
rtems_ftpfs_entry *e = iop->data1;
|
||||||
char *in = (char *) buffer;
|
char *in = buffer;
|
||||||
size_t todo = count;
|
size_t todo = count;
|
||||||
|
|
||||||
if (e->eof) {
|
if (e->eof) {
|
||||||
@@ -934,8 +930,8 @@ static ssize_t rtems_ftpfs_write(
|
|||||||
size_t count
|
size_t count
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
rtems_ftpfs_entry *e = (rtems_ftpfs_entry *) iop->data1;
|
rtems_ftpfs_entry *e = iop->data1;
|
||||||
const char *out = (const char *) buffer;
|
const char *out = buffer;
|
||||||
size_t todo = count;
|
size_t todo = count;
|
||||||
|
|
||||||
if (e->eof) {
|
if (e->eof) {
|
||||||
@@ -968,9 +964,7 @@ static ssize_t rtems_ftpfs_write(
|
|||||||
|
|
||||||
static int rtems_ftpfs_close( rtems_libio_t *iop)
|
static int rtems_ftpfs_close( rtems_libio_t *iop)
|
||||||
{
|
{
|
||||||
rtems_ftpfs_entry *e = (rtems_ftpfs_entry *) iop->data1;
|
rtems_ftpfs_terminate( iop);
|
||||||
|
|
||||||
rtems_ftpfs_terminate( e, iop);
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -990,24 +984,18 @@ static int rtems_ftpfs_eval_path(
|
|||||||
/*
|
/*
|
||||||
* The caller of this routine has striped off the mount prefix from the path.
|
* The caller of this routine has striped off the mount prefix from the path.
|
||||||
* We need to store this path here or otherwise we would have to do this job
|
* We need to store this path here or otherwise we would have to do this job
|
||||||
* again. It is not possible to allocate resources here since there is no
|
* again. The path is used in rtems_ftpfs_open() via iop->file_info.
|
||||||
* way to free them later in every case. The path is used in
|
|
||||||
* rtems_ftpfs_open() via iop->file_info.
|
|
||||||
*
|
|
||||||
* FIXME: Avoid to discard the const qualifier.
|
|
||||||
*/
|
*/
|
||||||
pathloc->node_access = (void *) pathname;
|
pathloc->node_access = strdup( pathname);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int rtems_ftpfs_eval_for_make(
|
static int rtems_ftpfs_free_node( rtems_filesystem_location_info_t *pathloc)
|
||||||
const char *pathname,
|
|
||||||
rtems_filesystem_location_info_t *pathloc,
|
|
||||||
const char **name
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
rtems_set_errno_and_return_minus_one( EIO);
|
free( pathloc->node_access);
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static rtems_filesystem_node_types_t rtems_ftpfs_node_type(
|
static rtems_filesystem_node_types_t rtems_ftpfs_node_type(
|
||||||
@@ -1064,13 +1052,13 @@ static int rtems_ftpfs_fstat(
|
|||||||
|
|
||||||
const rtems_filesystem_operations_table rtems_ftpfs_ops = {
|
const rtems_filesystem_operations_table rtems_ftpfs_ops = {
|
||||||
.evalpath_h = rtems_ftpfs_eval_path,
|
.evalpath_h = rtems_ftpfs_eval_path,
|
||||||
.evalformake_h = rtems_ftpfs_eval_for_make,
|
.evalformake_h = NULL,
|
||||||
.link_h = NULL,
|
.link_h = NULL,
|
||||||
.unlink_h = NULL,
|
.unlink_h = NULL,
|
||||||
.node_type_h = rtems_ftpfs_node_type,
|
.node_type_h = rtems_ftpfs_node_type,
|
||||||
.mknod_h = NULL,
|
.mknod_h = NULL,
|
||||||
.chown_h = NULL,
|
.chown_h = NULL,
|
||||||
.freenod_h = NULL,
|
.freenod_h = rtems_ftpfs_free_node,
|
||||||
.mount_h = NULL,
|
.mount_h = NULL,
|
||||||
.fsmount_me_h = rtems_ftpfs_mount_me,
|
.fsmount_me_h = rtems_ftpfs_mount_me,
|
||||||
.unmount_h = NULL,
|
.unmount_h = NULL,
|
||||||
|
|||||||
Reference in New Issue
Block a user