dev.c (326ea986ac150acdc7656d57fca647db80b50158) dev.c (7c4213f6a52f35ff6ba2d97aa4eb04cbfc963b86)
1/*
2 *
3 * based on code of fs/reiserfs/dev.c by
4 *
5 * (C) Copyright 2003 - 2004
6 * Sysgo AG, <www.elinos.com>, Pavel Bartusek <pba@sysgo.com>
7 *
8 * SPDX-License-Identifier: GPL-2.0+

--- 41 unchanged lines hidden (view full) ---

50
51 if (zfs_block_dev_desc == NULL) {
52 printf("** Invalid Block Device Descriptor (NULL)\n");
53 return 1;
54 }
55
56 if (byte_offset != 0) {
57 /* read first part which isn't aligned with start of sector */
1/*
2 *
3 * based on code of fs/reiserfs/dev.c by
4 *
5 * (C) Copyright 2003 - 2004
6 * Sysgo AG, <www.elinos.com>, Pavel Bartusek <pba@sysgo.com>
7 *
8 * SPDX-License-Identifier: GPL-2.0+

--- 41 unchanged lines hidden (view full) ---

50
51 if (zfs_block_dev_desc == NULL) {
52 printf("** Invalid Block Device Descriptor (NULL)\n");
53 return 1;
54 }
55
56 if (byte_offset != 0) {
57 /* read first part which isn't aligned with start of sector */
58 if (zfs_block_dev_desc->block_read(zfs_block_dev_desc->dev,
59 part_info->start + sector, 1,
60 (unsigned long *)sec_buf) != 1) {
58 if (zfs_block_dev_desc->block_read(zfs_block_dev_desc,
59 part_info->start + sector, 1,
60 (void *)sec_buf)
61 != 1) {
61 printf(" ** zfs_devread() read error **\n");
62 return 1;
63 }
64 memcpy(buf, sec_buf + byte_offset,
65 min(SECTOR_SIZE - byte_offset, byte_len));
66 buf += min(SECTOR_SIZE - byte_offset, byte_len);
67 byte_len -= min(SECTOR_SIZE - byte_offset, byte_len);
68 sector++;

--- 4 unchanged lines hidden (view full) ---

73
74 /* read sector aligned part */
75 block_len = byte_len & ~(SECTOR_SIZE - 1);
76
77 if (block_len == 0) {
78 u8 p[SECTOR_SIZE];
79
80 block_len = SECTOR_SIZE;
62 printf(" ** zfs_devread() read error **\n");
63 return 1;
64 }
65 memcpy(buf, sec_buf + byte_offset,
66 min(SECTOR_SIZE - byte_offset, byte_len));
67 buf += min(SECTOR_SIZE - byte_offset, byte_len);
68 byte_len -= min(SECTOR_SIZE - byte_offset, byte_len);
69 sector++;

--- 4 unchanged lines hidden (view full) ---

74
75 /* read sector aligned part */
76 block_len = byte_len & ~(SECTOR_SIZE - 1);
77
78 if (block_len == 0) {
79 u8 p[SECTOR_SIZE];
80
81 block_len = SECTOR_SIZE;
81 zfs_block_dev_desc->block_read(zfs_block_dev_desc->dev,
82 part_info->start + sector,
83 1, (unsigned long *)p);
82 zfs_block_dev_desc->block_read(zfs_block_dev_desc,
83 part_info->start + sector,
84 1, (void *)p);
84 memcpy(buf, p, byte_len);
85 return 0;
86 }
87
85 memcpy(buf, p, byte_len);
86 return 0;
87 }
88
88 if (zfs_block_dev_desc->block_read(zfs_block_dev_desc->dev,
89 part_info->start + sector, block_len / SECTOR_SIZE,
90 (unsigned long *) buf) != block_len / SECTOR_SIZE) {
89 if (zfs_block_dev_desc->block_read(zfs_block_dev_desc,
90 part_info->start + sector,
91 block_len / SECTOR_SIZE,
92 (void *)buf)
93 != block_len / SECTOR_SIZE) {
91 printf(" ** zfs_devread() read error - block\n");
92 return 1;
93 }
94
95 block_len = byte_len & ~(SECTOR_SIZE - 1);
96 buf += block_len;
97 byte_len -= block_len;
98 sector += block_len / SECTOR_SIZE;
99
100 if (byte_len != 0) {
101 /* read rest of data which are not in whole sector */
94 printf(" ** zfs_devread() read error - block\n");
95 return 1;
96 }
97
98 block_len = byte_len & ~(SECTOR_SIZE - 1);
99 buf += block_len;
100 byte_len -= block_len;
101 sector += block_len / SECTOR_SIZE;
102
103 if (byte_len != 0) {
104 /* read rest of data which are not in whole sector */
102 if (zfs_block_dev_desc->
103 block_read(zfs_block_dev_desc->dev,
104 part_info->start + sector, 1,
105 (unsigned long *) sec_buf) != 1) {
105 if (zfs_block_dev_desc->block_read(zfs_block_dev_desc,
106 part_info->start + sector,
107 1, (void *)sec_buf) != 1) {
106 printf(" ** zfs_devread() read error - last part\n");
107 return 1;
108 }
109 memcpy(buf, sec_buf, byte_len);
110 }
111 return 0;
112}
108 printf(" ** zfs_devread() read error - last part\n");
109 return 1;
110 }
111 memcpy(buf, sec_buf, byte_len);
112 }
113 return 0;
114}