aboutsummaryrefslogtreecommitdiff
path: root/lib/libufs/type.c
diff options
context:
space:
mode:
authorJuli Mallett <jmallett@FreeBSD.org>2003-01-29 23:19:46 +0000
committerJuli Mallett <jmallett@FreeBSD.org>2003-01-29 23:19:46 +0000
commit7dc95357f8ead71486742a81bf3500482fad7778 (patch)
tree8a1103e737a809923744dbe2a8a1a50ddb0d372c /lib/libufs/type.c
parent5a29754e3f2b408d8df01c00b9e32675f0757778 (diff)
downloadsrc-7dc95357f8ead71486742a81bf3500482fad7778.tar.gz
src-7dc95357f8ead71486742a81bf3500482fad7778.zip
API for opening (and tracking) writable file descriptors per disk.
Notes
Notes: svn path=/head/; revision=110066
Diffstat (limited to 'lib/libufs/type.c')
-rw-r--r--lib/libufs/type.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/lib/libufs/type.c b/lib/libufs/type.c
index 41eacfd6a977..54554654d240 100644
--- a/lib/libufs/type.c
+++ b/lib/libufs/type.c
@@ -50,6 +50,8 @@ __FBSDID("$FreeBSD$");
/* Internally, track the 'name' value, it's ours. */
#define MINE_NAME 0x01
+/* Track if its fd points to a writable device. */
+#define MINE_WRITE 0x02
struct uufsd *
ufs_disk_ctor(const char *name)
@@ -175,3 +177,27 @@ again: if (stat(name, &st) < 0) {
return 0;
}
+
+int
+ufs_disk_write(struct uufsd *disk)
+{
+ int rofd;
+
+ ERROR(disk, NULL);
+
+ if (disk->d_mine & MINE_WRITE)
+ return 0;
+
+ rofd = disk->d_fd;
+
+ disk->d_fd = open(disk->d_name, O_RDWR);
+ if (disk->d_fd < 0) {
+ ERROR(disk, "failed to open disk for writing");
+ disk->d_fd = rofd;
+ return -1;
+ }
+
+ disk->d_mine |= MINE_WRITE;
+
+ return 0;
+}