Changeset ea0ff6b in mainline for uspace/srv/volsrv/empty.c
- Timestamp:
- 2015-10-15T20:43:30Z (9 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 44fe800
- Parents:
- edebb4a1
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/volsrv/empty.c
redebb4a1 rea0ff6b 57 57 } 58 58 59 int vol_part_is_empty(service_id_t sid, bool *rempty) 60 { 61 int rc; 62 bool block_inited = false; 63 void *buf = NULL; 64 aoff64_t nblocks; 59 /** Calculate number of blocks to check. 60 * 61 * Will store to @a *ncb the number of blocks that should be checked 62 * at the beginning and end of device each. 63 * 64 * @param nblocks Total number of blocks on block device 65 * @param block_size Block size 66 * @param ncb Place to store number of blocks to check. 67 */ 68 static void calc_num_check_blocks(aoff64_t nblocks, size_t block_size, 69 aoff64_t *ncb) 70 { 65 71 aoff64_t n; 66 aoff64_t i;67 size_t block_size;68 bool empty;69 70 rc = block_init(EXCHANGE_SERIALIZE, sid, 2048);71 if (rc != EOK) {72 log_msg(LOG_DEFAULT, LVL_ERROR, "Error opening "73 "block device service %zu", sid);74 rc = EIO;75 goto error;76 }77 78 block_inited = true;79 80 rc = block_get_bsize(sid, &block_size);81 if (rc != EOK) {82 log_msg(LOG_DEFAULT, LVL_ERROR, "Error getting "83 "block size.");84 rc = EIO;85 goto error;86 }87 88 rc = block_get_nblocks(sid, &nblocks);89 if (rc != EOK) {90 log_msg(LOG_DEFAULT, LVL_ERROR, "Error getting "91 "number of blocks.");92 rc = EIO;93 goto error;94 }95 72 96 73 /* Check first 16 kiB / 16 blocks, whichever is more */ … … 104 81 if (n > (nblocks + 1) / 2) 105 82 n = (nblocks + 1) / 2; 83 84 *ncb = n; 85 } 86 87 int vol_part_is_empty(service_id_t sid, bool *rempty) 88 { 89 int rc; 90 bool block_inited = false; 91 void *buf = NULL; 92 aoff64_t nblocks; 93 aoff64_t n; 94 aoff64_t i; 95 size_t block_size; 96 bool empty; 97 98 rc = block_init(EXCHANGE_SERIALIZE, sid, 2048); 99 if (rc != EOK) { 100 log_msg(LOG_DEFAULT, LVL_ERROR, "Error opening " 101 "block device service %zu", sid); 102 rc = EIO; 103 goto error; 104 } 105 106 block_inited = true; 107 108 rc = block_get_bsize(sid, &block_size); 109 if (rc != EOK) { 110 log_msg(LOG_DEFAULT, LVL_ERROR, "Error getting " 111 "block size."); 112 rc = EIO; 113 goto error; 114 } 115 116 rc = block_get_nblocks(sid, &nblocks); 117 if (rc != EOK) { 118 log_msg(LOG_DEFAULT, LVL_ERROR, "Error getting " 119 "number of blocks."); 120 rc = EIO; 121 goto error; 122 } 123 124 calc_num_check_blocks(nblocks, block_size, &n); 106 125 107 126 buf = calloc(block_size, 1); … … 157 176 } 158 177 178 int vol_part_empty(service_id_t sid) 179 { 180 int rc; 181 bool block_inited = false; 182 void *buf = NULL; 183 aoff64_t nblocks; 184 aoff64_t n; 185 aoff64_t i; 186 size_t block_size; 187 188 rc = block_init(EXCHANGE_SERIALIZE, sid, 2048); 189 if (rc != EOK) { 190 log_msg(LOG_DEFAULT, LVL_ERROR, "Error opening " 191 "block device service %zu", sid); 192 rc = EIO; 193 goto error; 194 } 195 196 block_inited = true; 197 198 rc = block_get_bsize(sid, &block_size); 199 if (rc != EOK) { 200 log_msg(LOG_DEFAULT, LVL_ERROR, "Error getting " 201 "block size."); 202 rc = EIO; 203 goto error; 204 } 205 206 rc = block_get_nblocks(sid, &nblocks); 207 if (rc != EOK) { 208 log_msg(LOG_DEFAULT, LVL_ERROR, "Error getting " 209 "number of blocks."); 210 rc = EIO; 211 goto error; 212 } 213 214 calc_num_check_blocks(nblocks, block_size, &n); 215 216 buf = calloc(block_size, 1); 217 if (buf == NULL) { 218 log_msg(LOG_DEFAULT, LVL_ERROR, "Error allocating buffer."); 219 rc = ENOMEM; 220 goto error; 221 } 222 223 for (i = 0; i < n; i++) { 224 rc = block_write_direct(sid, i, 1, buf); 225 if (rc != EOK) { 226 log_msg(LOG_DEFAULT, LVL_ERROR, "Error " 227 "reading blocks."); 228 rc = EIO; 229 goto error; 230 } 231 } 232 233 for (i = 0; i < n; i++) { 234 rc = block_write_direct(sid, nblocks - n + i, 1, buf); 235 if (rc != EOK) { 236 log_msg(LOG_DEFAULT, LVL_ERROR, "Error " 237 "reading blocks."); 238 rc = EIO; 239 goto error; 240 } 241 } 242 243 block_fini(sid); 244 free(buf); 245 return EOK; 246 error: 247 if (block_inited) 248 block_fini(sid); 249 if (buf != NULL) 250 free(buf); 251 return rc; 252 } 253 159 254 /** @} 160 255 */
Note:
See TracChangeset
for help on using the changeset viewer.