aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/char/random.c
diff options
context:
space:
mode:
authorAndrea Bastoni <bastoni@cs.unc.edu>2010-05-30 19:16:45 -0400
committerAndrea Bastoni <bastoni@cs.unc.edu>2010-05-30 19:16:45 -0400
commitada47b5fe13d89735805b566185f4885f5a3f750 (patch)
tree644b88f8a71896307d71438e9b3af49126ffb22b /drivers/char/random.c
parent43e98717ad40a4ae64545b5ba047c7b86aa44f4f (diff)
parent3280f21d43ee541f97f8cda5792150d2dbec20d5 (diff)
Merge branch 'wip-2.6.34' into old-private-masterarchived-private-master
Diffstat (limited to 'drivers/char/random.c')
-rw-r--r--drivers/char/random.c75
1 files changed, 11 insertions, 64 deletions
diff --git a/drivers/char/random.c b/drivers/char/random.c
index 04b505e5a5e2..2fd3d39995d5 100644
--- a/drivers/char/random.c
+++ b/drivers/char/random.c
@@ -1051,12 +1051,6 @@ random_read(struct file *file, char __user *buf, size_t nbytes, loff_t *ppos)
1051 /* like a named pipe */ 1051 /* like a named pipe */
1052 } 1052 }
1053 1053
1054 /*
1055 * If we gave the user some bytes, update the access time.
1056 */
1057 if (count)
1058 file_accessed(file);
1059
1060 return (count ? count : retval); 1054 return (count ? count : retval);
1061} 1055}
1062 1056
@@ -1107,7 +1101,6 @@ static ssize_t random_write(struct file *file, const char __user *buffer,
1107 size_t count, loff_t *ppos) 1101 size_t count, loff_t *ppos)
1108{ 1102{
1109 size_t ret; 1103 size_t ret;
1110 struct inode *inode = file->f_path.dentry->d_inode;
1111 1104
1112 ret = write_pool(&blocking_pool, buffer, count); 1105 ret = write_pool(&blocking_pool, buffer, count);
1113 if (ret) 1106 if (ret)
@@ -1116,8 +1109,6 @@ static ssize_t random_write(struct file *file, const char __user *buffer,
1116 if (ret) 1109 if (ret)
1117 return ret; 1110 return ret;
1118 1111
1119 inode->i_mtime = current_fs_time(inode->i_sb);
1120 mark_inode_dirty(inode);
1121 return (ssize_t)count; 1112 return (ssize_t)count;
1122} 1113}
1123 1114
@@ -1200,7 +1191,7 @@ const struct file_operations urandom_fops = {
1200void generate_random_uuid(unsigned char uuid_out[16]) 1191void generate_random_uuid(unsigned char uuid_out[16])
1201{ 1192{
1202 get_random_bytes(uuid_out, 16); 1193 get_random_bytes(uuid_out, 16);
1203 /* Set UUID version to 4 --- truely random generation */ 1194 /* Set UUID version to 4 --- truly random generation */
1204 uuid_out[6] = (uuid_out[6] & 0x0F) | 0x40; 1195 uuid_out[6] = (uuid_out[6] & 0x0F) | 0x40;
1205 /* Set the UUID variant to DCE */ 1196 /* Set the UUID variant to DCE */
1206 uuid_out[8] = (uuid_out[8] & 0x3F) | 0x80; 1197 uuid_out[8] = (uuid_out[8] & 0x3F) | 0x80;
@@ -1245,112 +1236,68 @@ static int proc_do_uuid(ctl_table *table, int write,
1245 if (uuid[8] == 0) 1236 if (uuid[8] == 0)
1246 generate_random_uuid(uuid); 1237 generate_random_uuid(uuid);
1247 1238
1248 sprintf(buf, "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-" 1239 sprintf(buf, "%pU", uuid);
1249 "%02x%02x%02x%02x%02x%02x", 1240
1250 uuid[0], uuid[1], uuid[2], uuid[3],
1251 uuid[4], uuid[5], uuid[6], uuid[7],
1252 uuid[8], uuid[9], uuid[10], uuid[11],
1253 uuid[12], uuid[13], uuid[14], uuid[15]);
1254 fake_table.data = buf; 1241 fake_table.data = buf;
1255 fake_table.maxlen = sizeof(buf); 1242 fake_table.maxlen = sizeof(buf);
1256 1243
1257 return proc_dostring(&fake_table, write, buffer, lenp, ppos); 1244 return proc_dostring(&fake_table, write, buffer, lenp, ppos);
1258} 1245}
1259 1246
1260static int uuid_strategy(ctl_table *table,
1261 void __user *oldval, size_t __user *oldlenp,
1262 void __user *newval, size_t newlen)
1263{
1264 unsigned char tmp_uuid[16], *uuid;
1265 unsigned int len;
1266
1267 if (!oldval || !oldlenp)
1268 return 1;
1269
1270 uuid = table->data;
1271 if (!uuid) {
1272 uuid = tmp_uuid;
1273 uuid[8] = 0;
1274 }
1275 if (uuid[8] == 0)
1276 generate_random_uuid(uuid);
1277
1278 if (get_user(len, oldlenp))
1279 return -EFAULT;
1280 if (len) {
1281 if (len > 16)
1282 len = 16;
1283 if (copy_to_user(oldval, uuid, len) ||
1284 put_user(len, oldlenp))
1285 return -EFAULT;
1286 }
1287 return 1;
1288}
1289
1290static int sysctl_poolsize = INPUT_POOL_WORDS * 32; 1247static int sysctl_poolsize = INPUT_POOL_WORDS * 32;
1291ctl_table random_table[] = { 1248ctl_table random_table[] = {
1292 { 1249 {
1293 .ctl_name = RANDOM_POOLSIZE,
1294 .procname = "poolsize", 1250 .procname = "poolsize",
1295 .data = &sysctl_poolsize, 1251 .data = &sysctl_poolsize,
1296 .maxlen = sizeof(int), 1252 .maxlen = sizeof(int),
1297 .mode = 0444, 1253 .mode = 0444,
1298 .proc_handler = &proc_dointvec, 1254 .proc_handler = proc_dointvec,
1299 }, 1255 },
1300 { 1256 {
1301 .ctl_name = RANDOM_ENTROPY_COUNT,
1302 .procname = "entropy_avail", 1257 .procname = "entropy_avail",
1303 .maxlen = sizeof(int), 1258 .maxlen = sizeof(int),
1304 .mode = 0444, 1259 .mode = 0444,
1305 .proc_handler = &proc_dointvec, 1260 .proc_handler = proc_dointvec,
1306 .data = &input_pool.entropy_count, 1261 .data = &input_pool.entropy_count,
1307 }, 1262 },
1308 { 1263 {
1309 .ctl_name = RANDOM_READ_THRESH,
1310 .procname = "read_wakeup_threshold", 1264 .procname = "read_wakeup_threshold",
1311 .data = &random_read_wakeup_thresh, 1265 .data = &random_read_wakeup_thresh,
1312 .maxlen = sizeof(int), 1266 .maxlen = sizeof(int),
1313 .mode = 0644, 1267 .mode = 0644,
1314 .proc_handler = &proc_dointvec_minmax, 1268 .proc_handler = proc_dointvec_minmax,
1315 .strategy = &sysctl_intvec,
1316 .extra1 = &min_read_thresh, 1269 .extra1 = &min_read_thresh,
1317 .extra2 = &max_read_thresh, 1270 .extra2 = &max_read_thresh,
1318 }, 1271 },
1319 { 1272 {
1320 .ctl_name = RANDOM_WRITE_THRESH,
1321 .procname = "write_wakeup_threshold", 1273 .procname = "write_wakeup_threshold",
1322 .data = &random_write_wakeup_thresh, 1274 .data = &random_write_wakeup_thresh,
1323 .maxlen = sizeof(int), 1275 .maxlen = sizeof(int),
1324 .mode = 0644, 1276 .mode = 0644,
1325 .proc_handler = &proc_dointvec_minmax, 1277 .proc_handler = proc_dointvec_minmax,
1326 .strategy = &sysctl_intvec,
1327 .extra1 = &min_write_thresh, 1278 .extra1 = &min_write_thresh,
1328 .extra2 = &max_write_thresh, 1279 .extra2 = &max_write_thresh,
1329 }, 1280 },
1330 { 1281 {
1331 .ctl_name = RANDOM_BOOT_ID,
1332 .procname = "boot_id", 1282 .procname = "boot_id",
1333 .data = &sysctl_bootid, 1283 .data = &sysctl_bootid,
1334 .maxlen = 16, 1284 .maxlen = 16,
1335 .mode = 0444, 1285 .mode = 0444,
1336 .proc_handler = &proc_do_uuid, 1286 .proc_handler = proc_do_uuid,
1337 .strategy = &uuid_strategy,
1338 }, 1287 },
1339 { 1288 {
1340 .ctl_name = RANDOM_UUID,
1341 .procname = "uuid", 1289 .procname = "uuid",
1342 .maxlen = 16, 1290 .maxlen = 16,
1343 .mode = 0444, 1291 .mode = 0444,
1344 .proc_handler = &proc_do_uuid, 1292 .proc_handler = proc_do_uuid,
1345 .strategy = &uuid_strategy,
1346 }, 1293 },
1347 { .ctl_name = 0 } 1294 { }
1348}; 1295};
1349#endif /* CONFIG_SYSCTL */ 1296#endif /* CONFIG_SYSCTL */
1350 1297
1351/******************************************************************** 1298/********************************************************************
1352 * 1299 *
1353 * Random funtions for networking 1300 * Random functions for networking
1354 * 1301 *
1355 ********************************************************************/ 1302 ********************************************************************/
1356 1303