1. Си / Говнокод #26631

    0

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    56. 56
    57. 57
    58. 58
    59. 59
    60. 60
    61. 61
    62. 62
    63. 63
    64. 64
    65. 65
    66. 66
    67. 67
    68. 68
    69. 69
    70. 70
    71. 71
    72. 72
    73. 73
    74. 74
    75. 75
    76. 76
    77. 77
    78. 78
    79. 79
    80. 80
    81. 81
    82. 82
    83. 83
    84. 84
    85. 85
    86. 86
    87. 87
    88. 88
    89. 89
    90. 90
    91. 91
    92. 92
    93. 93
    94. 94
    dev_t name_to_dev_t(const char *name)
    {
    	char s[32];
    	char *p;
    	dev_t res = 0;
    	int part;
    
    #ifdef CONFIG_BLOCK
    	if (strncmp(name, "PARTUUID=", 9) == 0) {
    		name += 9;
    		res = devt_from_partuuid(name);
    		if (!res)
    			goto fail;
    		goto done;
    	} else if (strncmp(name, "PARTLABEL=", 10) == 0) {
    		struct device *dev;
    
    		dev = class_find_device(&block_class, NULL, name + 10,
    					&match_dev_by_label);
    		if (!dev)
    			goto fail;
    
    		res = dev->devt;
    		put_device(dev);
    		goto done;
    	}
    #endif
    
    	if (strncmp(name, "/dev/", 5) != 0) {
    		unsigned maj, min, offset;
    		char dummy;
    
    		if ((sscanf(name, "%u:%u%c", &maj, &min, &dummy) == 2) ||
    		    (sscanf(name, "%u:%u:%u:%c", &maj, &min, &offset, &dummy) == 3)) {
    			res = MKDEV(maj, min);
    			if (maj != MAJOR(res) || min != MINOR(res))
    				goto fail;
    		} else {
    			res = new_decode_dev(simple_strtoul(name, &p, 16));
    			if (*p)
    				goto fail;
    		}
    		goto done;
    	}
    
    	name += 5;
    	res = Root_NFS;
    	if (strcmp(name, "nfs") == 0)
    		goto done;
    	res = Root_CIFS;
    	if (strcmp(name, "cifs") == 0)
    		goto done;
    	res = Root_RAM0;
    	if (strcmp(name, "ram") == 0)
    		goto done;
    
    	if (strlen(name) > 31)
    		goto fail;
    	strcpy(s, name);
    	for (p = s; *p; p++)
    		if (*p == '/')
    			*p = '!';
    	res = blk_lookup_devt(s, 0);
    	if (res)
    		goto done;
    
    	/*
    	 * try non-existent, but valid partition, which may only exist
    	 * after revalidating the disk, like partitioned md devices
    	 */
    	while (p > s && isdigit(p[-1]))
    		p--;
    	if (p == s || !*p || *p == '0')
    		goto fail;
    
    	/* try disk name without <part number> */
    	part = simple_strtoul(p, NULL, 10);
    	*p = '\0';
    	res = blk_lookup_devt(s, part);
    	if (res)
    		goto done;
    
    	/* try disk name without p<part number> */
    	if (p < s + 2 || !isdigit(p[-2]) || p[-1] != 'p')
    		goto fail;
    	p[-1] = '\0';
    	res = blk_lookup_devt(s, part);
    	if (res)
    		goto done;
    
    fail:
    	return 0;
    done:
    	return res;

    прыщи 32, 10

    Запостил: MAKAKA, 02 Мая 2020

    Комментарии (6) RSS

    Добавить комментарий