+
+void __fill_random_buf_percentage(unsigned long seed, void *buf,
+ unsigned int percentage,
+ unsigned int segment, unsigned int len,
+ char *pattern, unsigned int pbytes)
+{
+ unsigned int this_len;
+
+ if (percentage == 100) {
+ if (pbytes)
+ (void)cpy_pattern(pattern, pbytes, buf, len);
+ else
+ memset(buf, 0, len);
+ return;
+ }
+
+ if (segment > len)
+ segment = len;
+
+ while (len) {
+ /*
+ * Fill random chunk
+ */
+ this_len = (segment * (100 - percentage)) / 100;
+ if (this_len > len)
+ this_len = len;
+
+ __fill_random_buf(buf, this_len, seed);
+
+ len -= this_len;
+ if (!len)
+ break;
+ buf += this_len;
+
+ if (this_len > len)
+ this_len = len;
+ else if (len - this_len <= sizeof(long))
+ this_len = len;
+
+ if (pbytes)
+ (void)cpy_pattern(pattern, pbytes, buf, this_len);
+ else
+ memset(buf, 0, this_len);
+
+ len -= this_len;
+ buf += this_len;
+ }
+}
+
+unsigned long fill_random_buf_percentage(struct frand_state *fs, void *buf,
+ unsigned int percentage,
+ unsigned int segment, unsigned int len,
+ char *pattern, unsigned int pbytes)
+{
+ unsigned long r = __rand(fs);
+
+ if (sizeof(int) != sizeof(long *))
+ r *= (unsigned long) __rand(fs);
+
+ __fill_random_buf_percentage(r, buf, percentage, segment, len,
+ pattern, pbytes);
+ return r;
+}