aboutsummaryrefslogtreecommitdiff
path: root/src/libdiskfs
diff options
context:
space:
mode:
authorrsc <devnull@localhost>2007-05-28 17:34:27 +0000
committerrsc <devnull@localhost>2007-05-28 17:34:27 +0000
commit51d1a81c38d5ac3f89d2f22e11545b786040f198 (patch)
tree679864351ff07205006760e36ca075c562811aac /src/libdiskfs
parent27c1d3a4367ddc499d79183b33bacdd0542ed30f (diff)
downloadplan9port-51d1a81c38d5ac3f89d2f22e11545b786040f198.tar.gz
plan9port-51d1a81c38d5ac3f89d2f22e11545b786040f198.tar.bz2
plan9port-51d1a81c38d5ac3f89d2f22e11545b786040f198.zip
add disk partitions (David Swasey)
Diffstat (limited to 'src/libdiskfs')
-rw-r--r--src/libdiskfs/part.c60
1 files changed, 60 insertions, 0 deletions
diff --git a/src/libdiskfs/part.c b/src/libdiskfs/part.c
new file mode 100644
index 00000000..d156457d
--- /dev/null
+++ b/src/libdiskfs/part.c
@@ -0,0 +1,60 @@
+#include <u.h>
+#include <libc.h>
+#include <diskfs.h>
+
+typedef struct DiskPart DiskPart;
+struct DiskPart
+{
+ Disk disk;
+ Disk *subdisk;
+ u64int offset;
+ u64int size;
+};
+
+static Block*
+diskpartread(Disk *dd, u32int len, u64int offset)
+{
+ DiskPart *d = (DiskPart*)dd;
+
+ if(offset+len > d->size){
+ werrstr("read past region %llud + %lud > %llud", offset, len, d->size);
+ return nil;
+ }
+ return diskread(d->subdisk, len, offset+d->offset);
+}
+
+static int
+diskpartsync(Disk *dd)
+{
+ DiskPart *d = (DiskPart*)dd;
+
+ return disksync(d->subdisk);
+}
+
+static void
+diskpartclose(Disk *dd)
+{
+ DiskPart *d = (DiskPart*)dd;
+
+ diskclose(d->subdisk);
+ free(d);
+}
+
+Disk*
+diskpart(Disk *subdisk, u64int size, u64int offset)
+{
+ DiskPart *d;
+
+ d = mallocz(sizeof(DiskPart), 1);
+ if(d == nil)
+ return nil;
+
+ d->subdisk = subdisk;
+ d->offset = offset;
+ d->size = size;
+ d->disk._read = diskpartread;
+ d->disk._sync = diskpartsync;
+ d->disk._close = diskpartclose;
+
+ return &d->disk;
+}