paul@272 | 1 | /* |
paul@272 | 2 | * Test block server access to memory cards. |
paul@272 | 3 | * |
paul@272 | 4 | * Copyright (C) 2024 Paul Boddie <paul@boddie.org.uk> |
paul@272 | 5 | * |
paul@272 | 6 | * This program is free software; you can redistribute it and/or |
paul@272 | 7 | * modify it under the terms of the GNU General Public License as |
paul@272 | 8 | * published by the Free Software Foundation; either version 2 of |
paul@272 | 9 | * the License, or (at your option) any later version. |
paul@272 | 10 | * |
paul@272 | 11 | * This program is distributed in the hope that it will be useful, |
paul@272 | 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
paul@272 | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
paul@272 | 14 | * GNU General Public License for more details. |
paul@272 | 15 | * |
paul@272 | 16 | * You should have received a copy of the GNU General Public License |
paul@272 | 17 | * along with this program; if not, write to the Free Software |
paul@272 | 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, |
paul@272 | 19 | * Boston, MA 02110-1301, USA |
paul@272 | 20 | */ |
paul@272 | 21 | |
paul@272 | 22 | #include <l4/sys/err.h> |
paul@272 | 23 | #include <fsclient/client.h> |
paul@272 | 24 | #include <systypes/fcntl.h> |
paul@272 | 25 | |
paul@272 | 26 | #include <stdint.h> |
paul@272 | 27 | #include <stdio.h> |
paul@272 | 28 | |
paul@272 | 29 | |
paul@272 | 30 | |
paul@272 | 31 | static int show_sector(file_t *device) |
paul@272 | 32 | { |
paul@272 | 33 | uint8_t sector[512]; |
paul@272 | 34 | |
paul@272 | 35 | printf("Seek...\n"); |
paul@272 | 36 | client_seek(device, 1024, SEEK_SET); |
paul@272 | 37 | |
paul@272 | 38 | printf("Read...\n"); |
paul@272 | 39 | offset_t nread = client_read(device, sector, 512); |
paul@272 | 40 | int row, col; |
paul@272 | 41 | |
paul@272 | 42 | if (!nread) |
paul@272 | 43 | { |
paul@272 | 44 | printf("Could not read sector.\n"); |
paul@272 | 45 | return 1; |
paul@272 | 46 | } |
paul@272 | 47 | |
paul@272 | 48 | for (row = 0; row < 512; row += 16) |
paul@272 | 49 | { |
paul@272 | 50 | printf("%04x:", row); |
paul@272 | 51 | |
paul@272 | 52 | for (col = 0; col < 16; col++) |
paul@272 | 53 | printf(" %02x", sector[row + col]); |
paul@272 | 54 | |
paul@272 | 55 | printf("\n"); |
paul@272 | 56 | } |
paul@272 | 57 | |
paul@272 | 58 | return 0; |
paul@272 | 59 | } |
paul@272 | 60 | |
paul@272 | 61 | |
paul@272 | 62 | |
paul@272 | 63 | int main(int argc, char *argv[]) |
paul@272 | 64 | { |
paul@272 | 65 | if (argc < 1) |
paul@272 | 66 | { |
paul@272 | 67 | printf("Need a partition number.\n"); |
paul@272 | 68 | return 1; |
paul@272 | 69 | } |
paul@272 | 70 | |
paul@272 | 71 | /* Obtain filename and access parameters. */ |
paul@272 | 72 | |
paul@272 | 73 | char *filename = argv[1]; |
paul@272 | 74 | file_t *file; |
paul@272 | 75 | |
paul@272 | 76 | file = client_open(filename, O_RDONLY); |
paul@272 | 77 | |
paul@272 | 78 | if (!client_opened(file)) |
paul@272 | 79 | { |
paul@272 | 80 | printf("Could not obtain file: %s\n", file != NULL ? l4sys_errtostr(file->error) : "(null)"); |
paul@272 | 81 | return 1; |
paul@272 | 82 | } |
paul@272 | 83 | |
paul@272 | 84 | printf("Opened file: %s\n", filename); |
paul@272 | 85 | |
paul@272 | 86 | show_sector(file); |
paul@272 | 87 | |
paul@272 | 88 | client_close(file); |
paul@272 | 89 | printf("End of test.\n"); |
paul@272 | 90 | return 0; |
paul@272 | 91 | } |
paul@272 | 92 | |
paul@272 | 93 | // vim: tabstop=2 expandtab shiftwidth=2 |