From 3a1a3bb8879141fb2b6f7e97278c5903b0c651d4 Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Sat, 15 Feb 2020 18:56:18 +0100 Subject: osmo-sim-test: Recurse through subdirectories Don't just iterate over all files in the current working directory (cwd), but also recurse through all sub-directories. Change-Id: I737b01d9a845e37d8be9d4709ef0de04e749daec --- utils/osmo-sim-test.c | 52 ++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 39 insertions(+), 13 deletions(-) diff --git a/utils/osmo-sim-test.c b/utils/osmo-sim-test.c index cd983975..ea3ce2a6 100644 --- a/utils/osmo-sim-test.c +++ b/utils/osmo-sim-test.c @@ -374,6 +374,44 @@ static void handle_options(int argc, char **argv) } } + +static void iterate_fs(struct osim_chan_hdl *chan) +{ + const struct osim_file_desc *prev_cwd; + struct osim_file_desc *ofd; + + /* iterate over all files in current working directory */ + llist_for_each_entry(ofd, &chan->cwd->child_list, list) { + struct msgb *m; + printf("\n\n================ %s (%s) ==================\n", + ofd->short_name, ofd->long_name); + + m = select_file(chan, ofd->fid); + if (msgb_apdu_sw(m) != 0x9000) { + msgb_free(m); + continue; + } + dump_fcp_template_msg(m); + msgb_free(m); + + /* If this is a DF, recurse into it */ + switch (ofd->type) { + case TYPE_DF: + /* the select above has just changed into this directory */ + prev_cwd = chan->cwd; + chan->cwd = ofd; + iterate_fs(chan); + /* "pop" the directory from the stack */ + chan->cwd = prev_cwd; + break; + default: + dump_file(chan, ofd->fid); + break; + } + } +} + + int main(int argc, char **argv) { struct osim_reader_hdl *reader; @@ -410,19 +448,7 @@ int main(int argc, char **argv) dump_fcp_template_msg(msg); msgb_free(msg); - { - struct osim_file_desc *ofd; - llist_for_each_entry(ofd, &chan->cwd->child_list, list) { - struct msgb *m; - printf("\n\n================ %s (%s) ==================\n", - ofd->short_name, ofd->long_name); - - m = select_file(chan, ofd->fid); - dump_fcp_template_msg(m); - msgb_free(m); - dump_file(chan, ofd->fid); - } - } + iterate_fs(chan); exit(0); } -- cgit v1.2.3