Changeset 827d73f in mainline for uspace/srv/bd/file_bd/file_bd.c
- Timestamp:
- 2010-02-12T14:09:22Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- a70bda4
- Parents:
- 918e9910 (diff), e70edd1 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/bd/file_bd/file_bd.c
r918e9910 r827d73f 48 48 #include <devmap.h> 49 49 #include <sys/types.h> 50 #include <sys/typefmt.h> 50 51 #include <errno.h> 51 52 #include <bool.h> … … 56 57 57 58 static const size_t block_size = 512; 59 static aoff64_t num_blocks; 58 60 static FILE *img; 59 61 … … 99 101 { 100 102 int rc; 103 long img_size; 101 104 102 105 rc = devmap_driver_register(NAME, file_bd_connection); … … 109 112 if (img == NULL) 110 113 return EINVAL; 114 115 if (fseek(img, 0, SEEK_END) != 0) { 116 fclose(img); 117 return EIO; 118 } 119 120 img_size = ftell(img); 121 if (img_size < 0) { 122 fclose(img); 123 return EIO; 124 } 125 126 num_blocks = img_size / block_size; 111 127 112 128 fibril_mutex_initialize(&dev_lock); … … 174 190 ipc_answer_1(callid, EOK, block_size); 175 191 continue; 192 case BD_GET_NUM_BLOCKS: 193 ipc_answer_2(callid, EOK, LOWER32(num_blocks), 194 UPPER32(num_blocks)); 195 continue; 176 196 default: 177 197 retval = EINVAL; … … 186 206 { 187 207 size_t n_rd; 208 int rc; 209 210 /* Check whether access is within device address bounds. */ 211 if (ba + cnt > num_blocks) { 212 printf(NAME ": Accessed blocks %" PRIuOFF64 "-%" PRIuOFF64 ", while " 213 "max block number is %" PRIuOFF64 ".\n", ba, ba + cnt - 1, 214 num_blocks - 1); 215 return ELIMIT; 216 } 188 217 189 218 fibril_mutex_lock(&dev_lock); 190 219 191 fseek(img, ba * block_size, SEEK_SET); 220 clearerr(img); 221 rc = fseek(img, ba * block_size, SEEK_SET); 222 if (rc < 0) { 223 fibril_mutex_unlock(&dev_lock); 224 return EIO; 225 } 226 192 227 n_rd = fread(buf, block_size, cnt, img); 193 228 … … 209 244 { 210 245 size_t n_wr; 246 int rc; 247 248 /* Check whether access is within device address bounds. */ 249 if (ba + cnt > num_blocks) { 250 printf(NAME ": Accessed blocks %" PRIuOFF64 "-%" PRIuOFF64 ", while " 251 "max block number is %" PRIuOFF64 ".\n", ba, ba + cnt - 1, 252 num_blocks - 1); 253 return ELIMIT; 254 } 211 255 212 256 fibril_mutex_lock(&dev_lock); 213 257 214 fseek(img, ba * block_size, SEEK_SET); 215 n_wr = fread(buf, block_size, cnt, img); 258 clearerr(img); 259 rc = fseek(img, ba * block_size, SEEK_SET); 260 if (rc < 0) { 261 fibril_mutex_unlock(&dev_lock); 262 return EIO; 263 } 264 265 n_wr = fwrite(buf, block_size, cnt, img); 216 266 217 267 if (ferror(img) || n_wr < cnt) { 218 268 fibril_mutex_unlock(&dev_lock); 219 269 return EIO; /* Write error */ 270 } 271 272 if (fflush(img) != 0) { 273 fibril_mutex_unlock(&dev_lock); 274 return EIO; 220 275 } 221 276
Note:
See TracChangeset
for help on using the changeset viewer.