commit c88ba3750ec6e139034e468d5a56166268188981
parent 35a94791414922982718280d86fb77e3b5dc7fe4
Author: sin <sin@2f30.org>
Date: Thu, 26 Jun 2014 16:16:15 +0100
Add freeramdisk(8)
Diffstat:
3 files changed, 47 insertions(+), 0 deletions(-)
diff --git a/Makefile b/Makefile
@@ -31,6 +31,7 @@ SRC = \
eject.c \
fallocate.c \
free.c \
+ freeramdisk.c \
fsfreeze.c \
getty.c \
halt.c \
@@ -93,6 +94,7 @@ MAN1 = \
MAN8 = \
ctrlaltdel.8 \
+ freeramdisk.8 \
fsfreeze.8 \
getty.8 \
halt.8 \
diff --git a/freeramdisk.8 b/freeramdisk.8
@@ -0,0 +1,8 @@
+.TH FREERAMDISK 8 ubase-VERSION
+.SH NAME
+\fBfreeramdisk\fR - Free memory used by the loadlin ramdisk
+.SH SYNOPSIS
+\fBfreeramdisk\fR
+.SH DESCRIPTION
+\fBfreeramdisk\fR frees the memory that is used by the ramdisk.
+It uses the \fI/dev/ram\fR device node.
diff --git a/freeramdisk.c b/freeramdisk.c
@@ -0,0 +1,37 @@
+/* See LICENSE file for copyright and license details. */
+#include <fcntl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/ioctl.h>
+#include <sys/mount.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include "util.h"
+
+static void
+usage(void)
+{
+ eprintf("usage: %s\n", argv0);
+}
+
+int
+main(int argc, char *argv[])
+{
+ char *dev = "/dev/ram";
+ int fd;
+
+ ARGBEGIN {
+ default:
+ usage();
+ } ARGEND;
+
+ if (argc != 0)
+ usage();
+
+ if ((fd = open(dev, O_RDWR)) < 0)
+ eprintf("open: %s:", dev);
+ if (ioctl(fd, BLKFLSBUF, dev) < 0)
+ eprintf("BLKFLSBUF %s:", dev);
+ close(fd);
+ return EXIT_SUCCESS;
+}