Changeset 99de22b in mainline for uspace/srv/bd/file_bd/file_bd.c
- Timestamp:
- 2010-01-15T18:30:25Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- eeb643d
- Parents:
- 387416b (diff), 563d6077 (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
r387416b r99de22b 56 56 57 57 static const size_t block_size = 512; 58 static bn_t num_blocks; 58 59 static FILE *img; 59 60 … … 99 100 { 100 101 int rc; 102 long img_size; 101 103 102 104 rc = devmap_driver_register(NAME, file_bd_connection); … … 109 111 if (img == NULL) 110 112 return EINVAL; 113 114 if (fseek(img, 0, SEEK_END) != 0) { 115 fclose(img); 116 return EIO; 117 } 118 119 img_size = ftell(img); 120 if (img_size < 0) { 121 fclose(img); 122 return EIO; 123 } 124 125 num_blocks = img_size / block_size; 111 126 112 127 fibril_mutex_initialize(&dev_lock); … … 174 189 ipc_answer_1(callid, EOK, block_size); 175 190 continue; 191 case BD_GET_NUM_BLOCKS: 192 ipc_answer_2(callid, EOK, LOWER32(num_blocks), 193 UPPER32(num_blocks)); 194 continue; 176 195 default: 177 196 retval = EINVAL; … … 186 205 { 187 206 size_t n_rd; 207 int rc; 188 208 189 209 fibril_mutex_lock(&dev_lock); 190 210 191 fseek(img, ba * block_size, SEEK_SET); 211 clearerr(img); 212 rc = fseek(img, ba * block_size, SEEK_SET); 213 if (rc < 0) { 214 fibril_mutex_unlock(&dev_lock); 215 return EIO; 216 } 217 192 218 n_rd = fread(buf, block_size, cnt, img); 193 219 … … 209 235 { 210 236 size_t n_wr; 237 int rc; 211 238 212 239 fibril_mutex_lock(&dev_lock); 213 240 214 fseek(img, ba * block_size, SEEK_SET); 215 n_wr = fread(buf, block_size, cnt, img); 241 clearerr(img); 242 rc = fseek(img, ba * block_size, SEEK_SET); 243 if (rc < 0) { 244 fibril_mutex_unlock(&dev_lock); 245 return EIO; 246 } 247 248 n_wr = fwrite(buf, block_size, cnt, img); 216 249 217 250 if (ferror(img) || n_wr < cnt) { 218 251 fibril_mutex_unlock(&dev_lock); 219 252 return EIO; /* Write error */ 253 } 254 255 if (fflush(img) != 0) { 256 fibril_mutex_unlock(&dev_lock); 257 return EIO; 220 258 } 221 259
Note:
See TracChangeset
for help on using the changeset viewer.