Implement list function
This commit is contained in:
parent
8afb7e73e3
commit
06057a578b
|
@ -55,7 +55,7 @@ endif
|
|||
#CMOREFLAGS :=
|
||||
|
||||
CFLAGS := -I $(INCDIR) $(CWARN) -std=c99 -pedantic \
|
||||
$(if $(STATIC),-DLIBCASIO_STATIC,-fPIC) $(if $(OPTIMIZE_SIZE),-Os,-O2) \
|
||||
$(if $(STATIC),-DLIBCASIO_STATIC,-fPIC) $(if $(OPTIMIZE), $(if $(OPTIMIZE_SIZE),-Os,-O2), ) \
|
||||
-D LOGLEVEL="casio_loglevel_$(LOG_LEVEL)" \
|
||||
$(shell $(PKGCONFIG) --cflags $(ALLDEPS) 2>/dev/null) \
|
||||
$(CMOREFLAGS)
|
||||
|
|
|
@ -32,6 +32,7 @@ no_libusb=
|
|||
static=
|
||||
windows=
|
||||
optimize_size=
|
||||
optimize=y
|
||||
no_log=
|
||||
loglevel=none # none, info, warn, error, fatal
|
||||
|
||||
|
@ -83,6 +84,7 @@ Build options:
|
|||
--static build a static library (by default, dynamic)
|
||||
--windows build DLLs and .libs instead of ELF and archives
|
||||
--optimize-size optimize size instead of speed
|
||||
--optimize-disable disable optimization
|
||||
|
||||
--no-file do not use the libc FILE interface
|
||||
--no-libusb do not use libusb
|
||||
|
@ -158,6 +160,7 @@ for arg ; do case "$arg" in
|
|||
--static) static=y ;;
|
||||
--windows) windows=y ;;
|
||||
--optimize-size) optimize_size=y ;;
|
||||
--optimize-disable) optimize= ;;
|
||||
--no-file) no_file=y ;;
|
||||
--no-libusb) no_libusb=y ;;
|
||||
--no-log) no_log=y ;;
|
||||
|
@ -306,6 +309,7 @@ cat <<EOF
|
|||
STATIC := $static
|
||||
TARGET = $target
|
||||
OPTIMIZE_SIZE := $optimize_size
|
||||
OPTIMIZE := $optimize
|
||||
LOG_LEVEL = $loglevel
|
||||
NO_LIBUSB = $no_libusb
|
||||
DEFAULT_ZOOM := $default_zoom
|
||||
|
|
|
@ -321,6 +321,12 @@ CASIO_EXTERN int CASIO_EXPORT casio_open_nat
|
|||
CASIO_EXTERN int CASIO_EXPORT casio_optimize
|
||||
OF((casio_fs_t *casio__fs, const char *casio__device));
|
||||
|
||||
/* List all files/directories */
|
||||
|
||||
CASIO_EXTERN int CASIO_EXPORT casio_list
|
||||
OF((casio_fs_t *casio__fs, casio_path_t *casio__path,
|
||||
casio_fs_list_func_t *casio__callback, void *casio__cbcookie));
|
||||
|
||||
CASIO_END_DECLS
|
||||
CASIO_END_NAMESPACE
|
||||
#endif /* LIBCASIO_FS_H */
|
||||
|
|
|
@ -0,0 +1,50 @@
|
|||
/* ****************************************************************************
|
||||
* fs/delete.c -- delete an element from a libcasio filesystem.
|
||||
* Copyright (C) 2019 Alan "Lailouezzz" Le Bouder <alanlebouder@gmail.com>
|
||||
*
|
||||
* This file is part of libcasio.
|
||||
* libcasio is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation; either version 3.0 of the License,
|
||||
* or (at your option) any later version.
|
||||
*
|
||||
* libcasio is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
* See the GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with libcasio; if not, see <http://www.gnu.org/licenses/>.
|
||||
* ************************************************************************* */
|
||||
#include "fs.h"
|
||||
|
||||
/**
|
||||
* casio_list:
|
||||
* List all files/directories.
|
||||
*
|
||||
* @arg fs the filesystem.
|
||||
* @arg path the path.
|
||||
* @arg callback the callback list function.
|
||||
* @arg cbcookie the callback cookie.
|
||||
* @return the error code (0 if ok).
|
||||
*/
|
||||
|
||||
int CASIO_EXPORT casio_list(casio_fs_t *fs, casio_path_t *path,
|
||||
casio_fs_list_func_t *callback, void *cbcookie)
|
||||
{
|
||||
int err; void *nat;
|
||||
casio_fs_list_t *list;
|
||||
|
||||
/* Get the function */
|
||||
list = fs->casio_fs_funcs.casio_fsfuncs_list;
|
||||
if(!list) return (casio_error_op);
|
||||
|
||||
/* Make the native path. */
|
||||
err = casio_make_native_path(fs, &nat, path);
|
||||
if (err) return (err);
|
||||
|
||||
/* Make the operation. */
|
||||
err = (*list)(fs->casio_fs_cookie, nat, callback, cbcookie);
|
||||
casio_free_native_path(fs, nat);
|
||||
return (err);
|
||||
}
|
|
@ -0,0 +1,148 @@
|
|||
/* ****************************************************************************
|
||||
* link/seven_fs/delete.c -- delete an element from a Protocol 7.00 filesystem.
|
||||
* Copyright (C) 2019 Alan "Lailouezzz" Le Bouder <alanlebouder@gmail.com>
|
||||
*
|
||||
* This file is part of libcasio.
|
||||
* libcasio is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation; either version 3.0 of the License,
|
||||
* or (at your option) any later version.
|
||||
*
|
||||
* libcasio is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
* See the GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with libcasio; if not, see <http://www.gnu.org/licenses/>.
|
||||
* ************************************************************************* */
|
||||
#include "seven_fs.h"
|
||||
|
||||
/**
|
||||
* casio_sevenfs_list:
|
||||
* List all files/directories from a Protocol 7.00 filesystem.
|
||||
*
|
||||
* @arg cookie the cookie.
|
||||
* @arg path the path.
|
||||
* @arg callback the callback list function.
|
||||
* @arg cbcookie the callback cookie.
|
||||
* @return the error code (0 if ok).
|
||||
*/
|
||||
|
||||
int CASIO_EXPORT casio_sevenfs_list(sevenfs_cookie_t *cookie, sevenfs_path_t *path,
|
||||
casio_fs_list_func_t *callback, void *cbcookie)
|
||||
{
|
||||
int err; casio_link_t *handle = cookie;
|
||||
const char *dev;
|
||||
|
||||
/* Make the vars. */
|
||||
dev = &path->sevenfs_path_data[path->sevenfs_path_dev];
|
||||
|
||||
/* send command packet */
|
||||
msg((ll_info, "Sending the list command"));
|
||||
if((err = casio_seven_send_cmdfls_reqallinfo(handle, dev))) {
|
||||
msg((ll_fatal, "Couldn't send file transfer request/didn't receive answer"));
|
||||
return (err);
|
||||
} else if (response.casio_seven_packet_type == casio_seven_type_nak
|
||||
&& response.casio_seven_packet_code == casio_seven_err_other) {
|
||||
msg((ll_fatal, "Invalid filesystem"));
|
||||
return (casio_error_device); // FIXME : unsupported device error
|
||||
} else if (response.casio_seven_packet_type != casio_seven_type_ack) {
|
||||
msg((ll_fatal, "Didn't receive ack or known error..."));
|
||||
return (casio_error_unknown);
|
||||
}
|
||||
|
||||
/* swap roles */
|
||||
msg((ll_info, "Sending roleswap"));
|
||||
if((err = casio_seven_send_roleswp(handle))) {
|
||||
msg((ll_fatal, "Couldn't swap roles"));
|
||||
return (err);
|
||||
}
|
||||
|
||||
/* - Note: we are now in passive mode - */
|
||||
while(1) {
|
||||
/* check answer */
|
||||
char *dir, *filename, *cdev; unsigned int fs, ldir, lfilename;
|
||||
casio_pathnode_t *fnode = NULL;
|
||||
casio_stat_t fstat;
|
||||
switch (response.casio_seven_packet_type)
|
||||
{
|
||||
/* - If is roleswap, we have finished our job here - */
|
||||
case casio_seven_type_swp:
|
||||
return (0);
|
||||
break;
|
||||
|
||||
/* - If is command, should be another file info - */
|
||||
case casio_seven_type_cmd:
|
||||
|
||||
/* Check args */
|
||||
dir = response.casio_seven_packet_args[0];
|
||||
filename = response.casio_seven_packet_args[1];
|
||||
cdev = response.casio_seven_packet_args[4];
|
||||
fs = response.casio_seven_packet_filesize;
|
||||
|
||||
/* Device root should not be sent */
|
||||
if(!dir && !filename) continue;
|
||||
|
||||
/* Create node and stat */
|
||||
ldir = dir ? strlen(dir) : 0;
|
||||
lfilename = filename ? strlen(filename) : 0;
|
||||
if(dir && filename) {
|
||||
} else {
|
||||
casio_make_pathnode(&fnode, 1);
|
||||
}
|
||||
|
||||
if(dir && filename) {
|
||||
/* Create node size 2 */
|
||||
casio_make_pathnode(&fnode, 2);
|
||||
casio_make_pathnode(&fnode->casio_pathnode_next, 1);
|
||||
|
||||
/* Dir node */
|
||||
memcpy(&fnode->casio_pathnode_name, dir, ldir);
|
||||
fnode->casio_pathnode_name[ldir] = '\0';
|
||||
|
||||
/* File node */
|
||||
memcpy(&fnode->casio_pathnode_next->casio_pathnode_name, filename, lfilename);
|
||||
fnode->casio_pathnode_next->casio_pathnode_name[lfilename] = '\0';
|
||||
} else if(filename && !dir) {
|
||||
/* Create node size 1 */
|
||||
casio_make_pathnode(&fnode, 1);
|
||||
|
||||
/* File node */
|
||||
memcpy(&fnode->casio_pathnode_name, filename, lfilename);
|
||||
fnode->casio_pathnode_name[lfilename] = '\0';
|
||||
} else if(dir && !filename) {
|
||||
/* Create node size 1 */
|
||||
casio_make_pathnode(&fnode, 1);
|
||||
|
||||
/* Dir node */
|
||||
memcpy(&fnode->casio_pathnode_name, dir, ldir);
|
||||
fnode->casio_pathnode_name[ldir] = '\0';
|
||||
}
|
||||
|
||||
/* Call callback and free node */
|
||||
(*callback)(cbcookie, fnode, &fstat);
|
||||
if(dir && filename) {
|
||||
casio_free_pathnode(fnode->casio_pathnode_next);
|
||||
fnode->casio_pathnode_next = NULL;
|
||||
}
|
||||
casio_free_pathnode(fnode);
|
||||
fnode = NULL;
|
||||
break;
|
||||
|
||||
default:
|
||||
// Unknown
|
||||
msg((ll_fatal, "Error packet type unknown"));
|
||||
return (casio_error_unknown);
|
||||
break;
|
||||
}
|
||||
|
||||
/* send ack to continue */
|
||||
msg((ll_info, "Sending ack to continue"));
|
||||
if ((err = casio_seven_send_ack(handle, 1))) {
|
||||
msg((ll_fatal, "Unable to send ack/receive answer!"));
|
||||
return (err);
|
||||
}
|
||||
}
|
||||
return (0);
|
||||
}
|
|
@ -24,9 +24,12 @@ CASIO_LOCAL casio_fsfuncs_t sevenfs_callbacks = {
|
|||
NULL,
|
||||
(casio_fs_makepath_t*)&casio_make_sevenfs_path,
|
||||
(casio_fs_freepath_t*)&casio_free_sevenfs_path,
|
||||
NULL, NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
(casio_fs_del_t*)&casio_sevenfs_delete,
|
||||
NULL, NULL, NULL,
|
||||
NULL,
|
||||
(casio_fs_list_t*)&casio_sevenfs_list,
|
||||
NULL,
|
||||
(casio_fs_optim_t*)&casio_sevenfs_optimize
|
||||
};
|
||||
|
||||
|
|
|
@ -51,4 +51,10 @@ CASIO_EXTERN int CASIO_EXPORT casio_sevenfs_delete
|
|||
CASIO_EXTERN int CASIO_EXPORT casio_sevenfs_optimize
|
||||
OF((sevenfs_cookie_t *casio__cookie, const char *casio__device));
|
||||
|
||||
/* List all files/directories. */
|
||||
|
||||
CASIO_EXTERN int CASIO_EXPORT casio_sevenfs_list
|
||||
OF((sevenfs_cookie_t *casio__cookie, sevenfs_path_t *casio__path,
|
||||
casio_fs_list_func_t *casio__callback, void *casio__cbcookie));
|
||||
|
||||
#endif /* LOCAL_LINK_SEVEN_FS_H */
|
||||
|
|
|
@ -41,8 +41,8 @@ int CASIO_EXPORT casio_make_sevenfs_path(sevenfs_cookie_t *cookie,
|
|||
|
||||
/* Check the device. */
|
||||
|
||||
if (!memcmp(array->casio_path_device, "fls0", 4)
|
||||
|| !memcmp(array->casio_path_device, "crd0", 4))
|
||||
if (memcmp(array->casio_path_device, "fls0", 4) != 0
|
||||
&& memcmp(array->casio_path_device, "crd0", 4) != 0)
|
||||
return (casio_error_invalid);
|
||||
|
||||
/* Get directory name and file name. */
|
||||
|
@ -89,8 +89,8 @@ int CASIO_EXPORT casio_make_sevenfs_path(sevenfs_cookie_t *cookie,
|
|||
data[filesz - 1] = 0;
|
||||
path->sevenfs_path_file = off;
|
||||
data += filesz; off += filesz;
|
||||
memcpy(data, array->casio_path_device, 3);
|
||||
data[3] = 0;
|
||||
memcpy(data, array->casio_path_device, 4);
|
||||
data[4] = 0;
|
||||
path->sevenfs_path_dev = off;
|
||||
|
||||
/* No error! */
|
||||
|
|
|
@ -163,24 +163,13 @@ static void sendfile_display(unsigned int id, unsigned int total)
|
|||
* @arg size the filesize
|
||||
*/
|
||||
|
||||
static void print_file_info(void *cookie, const char *dir, const char *name,
|
||||
unsigned long size)
|
||||
static void print_file_info(void *cookie,
|
||||
const casio_pathnode_t *node, const casio_stat_t *stat)
|
||||
{
|
||||
(void)cookie;
|
||||
/* initialize buffer */
|
||||
static char buf[45];
|
||||
|
||||
/* clean buffer */
|
||||
memset(buf, ' ', 28);
|
||||
/* put path in buffer */
|
||||
char *b = buf;
|
||||
if (dir) b += sprintf(b, "%s/", dir);
|
||||
if (name) b[sprintf(b, "%s", name)] = ' ';
|
||||
/* put size */
|
||||
sprintf(&buf[28], "%10uo", (unsigned)size);
|
||||
|
||||
/* put the string */
|
||||
puts(buf);
|
||||
printf("callback called : %s\n", node->casio_pathnode_name);
|
||||
}
|
||||
|
||||
/* ---
|
||||
|
@ -247,6 +236,7 @@ int main(int ac, char **av)
|
|||
|
||||
/* Check according to menu */
|
||||
|
||||
casio_path_t path;
|
||||
switch (args.menu) {
|
||||
#if 0
|
||||
case mn_send:
|
||||
|
@ -284,23 +274,26 @@ int main(int ac, char **av)
|
|||
args.newdir, args.newname, args.storage);
|
||||
break;
|
||||
case mn_del:
|
||||
err = casio_delete(handle, args.dirname, args.filename,
|
||||
err = casio_delete(fs, args.dirname, args.filename,
|
||||
args.storage);
|
||||
break;
|
||||
case mn_list:
|
||||
err = casio_list(handle, args.storage, &print_file_info, NULL);
|
||||
break;
|
||||
case mn_reset:
|
||||
err = casio_reset(handle, args.storage);
|
||||
break;
|
||||
#endif
|
||||
case mn_list:
|
||||
path.casio_path_device = args.storage;
|
||||
casio_make_pathnode(&path.casio_path_nodes, 1);
|
||||
if ((err = casio_open_seven_fs(&fs, handle))
|
||||
|| (err = casio_list(fs, &path, print_file_info, NULL)))
|
||||
break;
|
||||
|
||||
break;
|
||||
case mn_optimize:
|
||||
if ((err = casio_open_seven_fs(&fs, handle))
|
||||
|| (err = casio_optimize(fs, args.storage)))
|
||||
break;
|
||||
|
||||
casio_close_fs(fs);
|
||||
fs = NULL;
|
||||
break;
|
||||
|
||||
case mn_info:
|
||||
|
@ -330,6 +323,7 @@ int main(int ac, char **av)
|
|||
/* Terminate communication and de-initialize link handle. */
|
||||
|
||||
casio_close_fs(fs);
|
||||
fs = NULL;
|
||||
casio_close_link(handle);
|
||||
handle = NULL;
|
||||
|
||||
|
@ -365,6 +359,7 @@ fail:
|
|||
|
||||
/* that doesn't mean you shouldn't exit, heh. */
|
||||
casio_close_fs(fs);
|
||||
fs = NULL;
|
||||
casio_close_link(handle);
|
||||
handle = NULL;
|
||||
|
||||
|
|
|
@ -109,6 +109,6 @@ fail:
|
|||
default:
|
||||
fprintf(stderr, error_unplanned, casio_strerror(err));
|
||||
}
|
||||
|
||||
|
||||
return (1);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue