9
size_desc(long long bytes)
18
sprintf(ret, "%.0f GiB", gib);
20
sprintf(ret, "%.1f GiB", gib);
21
else if (mib >= 100.0)
22
sprintf(ret, "%.0f MiB", mib);
24
sprintf(ret, "%.1f MiB", mib);
25
else if (kib >= 100.0)
26
sprintf(ret, "%.0f kiB", kib);
28
sprintf(ret, "%.1f kiB", kib);
30
sprintf(ret, "%lld B", bytes);
35
modprobe(const char *mod)
39
char printk[1024] = "";
41
if ((fp = fopen("/proc/sys/kernel/printk", "r")) != NULL) {
42
fgets(printk, sizeof(printk), fp);
45
if ((fp = fopen("/proc/sys/kernel/printk", "w")) != NULL) {
49
asprintf(&cmd, "modprobe %s >>/var/log/messages 2>&1", mod);
52
if ((fp = fopen("/proc/sys/kernel/printk", "w")) != NULL) {
59
* Check if something's already mounted on /target/mntpoint
62
check_proc_mounts(const char *mntpoint)
65
char buf[1024], mnt[1024];
68
if ((fp = fopen("/proc/mounts", "r")) == NULL)
70
asprintf(&tmp, "/target%s", mntpoint);
71
while (fgets(buf, sizeof(buf), fp) != NULL) {
72
sscanf(buf, "%*s %s", mnt);
73
if (strcmp(tmp, mnt) == 0) {
85
* Check if the given device is already activated as a swap
88
check_proc_swaps(const char *dev)
93
if ((fp = fopen("/proc/swaps", "r")) == NULL)
95
fgets(buf, sizeof(buf), fp);
96
while (fgets(buf, sizeof(buf), fp) != NULL) {
97
if (strstr(buf, dev) == buf) {
107
append_message(const char *fmt, ...)
112
if ((fp = fopen("/var/log/messages", "a")) == NULL)
115
vfprintf(fp, fmt, ap);
121
* Counts the number of occurrences of c in s
124
strcount(const char *s, int c)
130
while ((p = index(p, c)) != NULL) {
144
char buf[1024], mnt[1024];
147
int sort_func(const void *v1, const void *v2)
153
if (m1 == NULL && m2 == NULL)
159
if (strstr(m1, m2) == m1)
161
else if (strstr(m2, m1) == m2)
164
return strcmp(m2, m1);
167
if ((fp = fopen("/proc/mounts", "r")) == NULL)
169
while (fgets(buf, sizeof(buf), fp) != NULL) {
170
sscanf(buf, "%*s %s", mnt);
171
if (strstr(mnt, "/target") != mnt)
173
mounts[m_count++] = strdup(mnt);
178
qsort(mounts, m_count, sizeof(char *), sort_func);
179
for (i = 0; i < m_count; i++) {
180
if (umount(mounts[i]) < 0)