1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/pkg/landfall-examples/msc_block_client/msc_block_client.cc Tue Feb 27 17:27:25 2024 +0100
1.3 @@ -0,0 +1,93 @@
1.4 +/*
1.5 + * Test block server access to memory cards.
1.6 + *
1.7 + * Copyright (C) 2024 Paul Boddie <paul@boddie.org.uk>
1.8 + *
1.9 + * This program is free software; you can redistribute it and/or
1.10 + * modify it under the terms of the GNU General Public License as
1.11 + * published by the Free Software Foundation; either version 2 of
1.12 + * the License, or (at your option) any later version.
1.13 + *
1.14 + * This program is distributed in the hope that it will be useful,
1.15 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1.16 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1.17 + * GNU General Public License for more details.
1.18 + *
1.19 + * You should have received a copy of the GNU General Public License
1.20 + * along with this program; if not, write to the Free Software
1.21 + * Foundation, Inc., 51 Franklin Street, Fifth Floor,
1.22 + * Boston, MA 02110-1301, USA
1.23 + */
1.24 +
1.25 +#include <l4/sys/err.h>
1.26 +#include <fsclient/client.h>
1.27 +#include <systypes/fcntl.h>
1.28 +
1.29 +#include <stdint.h>
1.30 +#include <stdio.h>
1.31 +
1.32 +
1.33 +
1.34 +static int show_sector(file_t *device)
1.35 +{
1.36 + uint8_t sector[512];
1.37 +
1.38 + printf("Seek...\n");
1.39 + client_seek(device, 1024, SEEK_SET);
1.40 +
1.41 + printf("Read...\n");
1.42 + offset_t nread = client_read(device, sector, 512);
1.43 + int row, col;
1.44 +
1.45 + if (!nread)
1.46 + {
1.47 + printf("Could not read sector.\n");
1.48 + return 1;
1.49 + }
1.50 +
1.51 + for (row = 0; row < 512; row += 16)
1.52 + {
1.53 + printf("%04x:", row);
1.54 +
1.55 + for (col = 0; col < 16; col++)
1.56 + printf(" %02x", sector[row + col]);
1.57 +
1.58 + printf("\n");
1.59 + }
1.60 +
1.61 + return 0;
1.62 +}
1.63 +
1.64 +
1.65 +
1.66 +int main(int argc, char *argv[])
1.67 +{
1.68 + if (argc < 1)
1.69 + {
1.70 + printf("Need a partition number.\n");
1.71 + return 1;
1.72 + }
1.73 +
1.74 + /* Obtain filename and access parameters. */
1.75 +
1.76 + char *filename = argv[1];
1.77 + file_t *file;
1.78 +
1.79 + file = client_open(filename, O_RDONLY);
1.80 +
1.81 + if (!client_opened(file))
1.82 + {
1.83 + printf("Could not obtain file: %s\n", file != NULL ? l4sys_errtostr(file->error) : "(null)");
1.84 + return 1;
1.85 + }
1.86 +
1.87 + printf("Opened file: %s\n", filename);
1.88 +
1.89 + show_sector(file);
1.90 +
1.91 + client_close(file);
1.92 + printf("End of test.\n");
1.93 + return 0;
1.94 +}
1.95 +
1.96 +// vim: tabstop=2 expandtab shiftwidth=2