- // FIXME: for now just rewrite it by random
- return _crypt_wipe_random(fd, bsize, buffer, offset, size);
+ int r;
+
+ if (pattern == CRYPT_WIPE_SPECIAL)
+ return crypt_wipe_special(cd, devfd, device_block_size, alignment,
+ sf, offset, wipe_block_size);
+
+ if (*need_block_init) {
+ if (pattern == CRYPT_WIPE_ZERO) {
+ memset(sf, 0, wipe_block_size);
+ *need_block_init = false;
+ r = 0;
+ } else if (pattern == CRYPT_WIPE_RANDOM) {
+ r = crypt_random_get(cd, sf, wipe_block_size,
+ CRYPT_RND_NORMAL) ? -EIO : 0;
+ *need_block_init = true;
+ } else if (pattern == CRYPT_WIPE_ENCRYPTED_ZERO) {
+ // FIXME
+ r = crypt_random_get(cd, sf, wipe_block_size,
+ CRYPT_RND_NORMAL) ? -EIO : 0;
+ *need_block_init = true;
+ } else
+ r = -EINVAL;
+
+ if (r)
+ return r;
+ }
+
+ if (write_blockwise(devfd, device_block_size, alignment, sf,
+ wipe_block_size) == (ssize_t)wipe_block_size)
+ return 0;
+
+ return -EIO;