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