Changeset e272949 in mainline
- Timestamp:
- 2011-02-13T20:27:30Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 566c401
- Parents:
- 36bca8eb
- Location:
- uspace
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/ext2info/ext2info.c
r36bca8eb re272949 92 92 } 93 93 94 rc = ext2_superblock_read_direct( &superblock, handle);94 rc = ext2_superblock_read_direct(handle, &superblock); 95 95 if (rc != EOK) { 96 96 printf(NAME ": Error reading superblock.\n"); -
uspace/lib/block/libblock.c
r36bca8eb re272949 2 2 * Copyright (c) 2008 Jakub Jermar 3 3 * Copyright (c) 2008 Martin Decky 4 * Copyright (c) 2011 Martin Sucha 4 5 * All rights reserved. 5 6 * … … 809 810 } 810 811 812 /** Read bytes directly from the device (bypass cache) 813 * 814 * @param devmap_handle Device handle of the block device. 815 * @param abs_offset Absolute offset in bytes where to start reading 816 * @param bytes Number of bytes to read 817 * @param data Buffer that receives the data 818 * 819 * @return EOK on success or negative error code on failure. 820 */ 821 int block_read_bytes_direct(devmap_handle_t devmap_handle, aoff64_t abs_offset, 822 size_t bytes, void *data) 823 { 824 int rc; 825 size_t phys_block_size; 826 size_t buf_size; 827 void *buffer; 828 aoff64_t first_block; 829 aoff64_t last_block; 830 size_t blocks; 831 size_t offset; 832 833 rc = block_get_bsize(devmap_handle, &phys_block_size); 834 if (rc != EOK) { 835 return rc; 836 } 837 838 // calculate data position and required space 839 first_block = abs_offset / phys_block_size; 840 offset = abs_offset % phys_block_size; 841 last_block = (abs_offset + bytes - 1) / phys_block_size; 842 blocks = last_block - first_block + 1; 843 buf_size = blocks * phys_block_size; 844 845 // read the data into memory 846 buffer = malloc(buf_size); 847 if (buffer == NULL) { 848 return ENOMEM; 849 } 850 851 rc = block_read_direct(devmap_handle, first_block, blocks, buffer); 852 if (rc != EOK) { 853 free(buffer); 854 return rc; 855 } 856 857 // copy the data from the buffer 858 memcpy(data, buffer + offset, bytes); 859 free(buffer); 860 861 return EOK; 862 } 863 811 864 /** Read blocks from block device. 812 865 * -
uspace/lib/block/libblock.h
r36bca8eb re272949 2 2 * Copyright (c) 2008 Jakub Jermar 3 3 * Copyright (c) 2008 Martin Decky 4 * Copyright (c) 2011 Martin Sucha 4 5 * All rights reserved. 5 6 * … … 113 114 extern int block_get_nblocks(devmap_handle_t, aoff64_t *); 114 115 extern int block_read_direct(devmap_handle_t, aoff64_t, size_t, void *); 116 extern int block_read_bytes_direct(devmap_handle_t, aoff64_t, size_t, void *); 115 117 extern int block_write_direct(devmap_handle_t, aoff64_t, size_t, const void *); 116 118 -
uspace/lib/ext2/libext2.h
r36bca8eb re272949 75 75 inline uint32_t ext2_superblock_get_fragments_per_group(ext2_superblock_t *sb); 76 76 77 int ext2_superblock_read_direct(ext2_superblock_t **superblock, 78 devmap_handle_t dev); 77 int ext2_superblock_read_direct(devmap_handle_t, ext2_superblock_t **); 79 78 80 79 int ext2_filesystem_init(ext2_filesystem_t *fs, devmap_handle_t dev); -
uspace/lib/ext2/libext2_filesystem.c
r36bca8eb re272949 37 37 #include <errno.h> 38 38 #include <libblock.h> 39 #include <mem.h>40 39 #include <malloc.h> 41 42 int ext2_superblock_read_direct(ext2_superblock_t **superblock,43 devmap_handle_t dev) {44 int rc;45 size_t phys_block_size;46 size_t buf_size;47 uint8_t *buffer;48 size_t first_block;49 size_t last_block;50 size_t blocks;51 size_t offset;52 ext2_superblock_t *tmp_superblock;53 54 rc = block_get_bsize(dev, &phys_block_size);55 if (rc != EOK) {56 return rc;57 }58 59 // calculate superblock position and required space60 first_block = EXT2_SUPERBLOCK_OFFSET / phys_block_size;61 offset = EXT2_SUPERBLOCK_OFFSET % phys_block_size;62 last_block = EXT2_SUPERBLOCK_LAST_BYTE / phys_block_size;63 blocks = last_block - first_block + 1;64 buf_size = blocks * phys_block_size;65 66 // read the superblock into memory67 buffer = malloc(buf_size);68 if (buffer == NULL) {69 return ENOMEM;70 }71 72 rc = block_read_direct(dev, first_block, blocks, buffer);73 if (rc != EOK) {74 free(buffer);75 return rc;76 }77 78 // copy the superblock from the buffer79 // as it may not be at the start of the block80 // (i.e. blocks larger than 1K)81 tmp_superblock = malloc(EXT2_SUPERBLOCK_SIZE);82 if (tmp_superblock == NULL) {83 free(buffer);84 return ENOMEM;85 }86 87 memcpy(tmp_superblock, buffer + offset, EXT2_SUPERBLOCK_SIZE);88 free(buffer);89 (*superblock) = tmp_superblock;90 91 return EOK;92 }93 40 94 41 /** … … 108 55 } 109 56 110 rc = ext2_superblock_read_direct( &temp_superblock, dev);57 rc = ext2_superblock_read_direct(dev, &temp_superblock); 111 58 if (rc != EOK) { 112 59 block_fini(dev); -
uspace/lib/ext2/libext2_superblock.c
r36bca8eb re272949 35 35 36 36 #include "libext2.h" 37 #include <errno.h> 38 #include <malloc.h> 39 #include <libblock.h> 37 40 38 41 /** … … 104 107 105 108 109 /** Read a superblock directly from device (i.e. no libblock cache) 110 * 111 * @param devmap_handle Device handle of the block device. 112 * @param superblock Pointer where to store pointer to new superblock 113 * 114 * @return EOK on success or negative error code on failure. 115 */ 116 int ext2_superblock_read_direct(devmap_handle_t devmap_handle, 117 ext2_superblock_t **superblock) 118 { 119 void *data; 120 int rc; 121 122 data = malloc(EXT2_SUPERBLOCK_SIZE); 123 if (data == NULL) { 124 return ENOMEM; 125 } 126 127 rc = block_read_bytes_direct(devmap_handle, EXT2_SUPERBLOCK_OFFSET, 128 EXT2_SUPERBLOCK_SIZE, data); 129 if (rc != EOK) { 130 free(data); 131 return rc; 132 } 133 134 (*superblock) = data; 135 return EOK; 136 } 137 138 106 139 /** @} 107 140 */
Note:
See TracChangeset
for help on using the changeset viewer.