Commit 69d2ff7c authored by Mike Hibler's avatar Mike Hibler
Browse files

Make it work under Linux.

Does it matter? No.
Should you care? No. (So why are you still reading this? :-)

I needed a place to quickly test the technique for obtaining the
disk size under Linux.  That will matter in frisbee...
parent 9137350e
/* /*
* EMULAB-COPYRIGHT * EMULAB-COPYRIGHT
* Copyright (c) 2000-2004 University of Utah and the Flux Group. * Copyright (c) 2000-2005 University of Utah and the Flux Group.
* All rights reserved. * All rights reserved.
*/ */
...@@ -40,11 +40,19 @@ ...@@ -40,11 +40,19 @@
#include <unistd.h> #include <unistd.h>
#include <fcntl.h> #include <fcntl.h>
#include <err.h> #include <err.h>
#ifdef __FreeBSD__
#define DEFDISK "/dev/ad0"
#if __FreeBSD__ >= 5 #if __FreeBSD__ >= 5
#include <sys/disk.h> #include <sys/disk.h>
#else #else
#include <sys/disklabel.h> #include <sys/disklabel.h>
#endif #endif
#else
#ifdef __linux__
#define DEFDISK "/dev/hda"
#include <linux/fs.h>
#endif
#endif
#include "sliceinfo.h" #include "sliceinfo.h"
struct diskinfo { struct diskinfo {
...@@ -66,10 +74,10 @@ char optionstr[] = ...@@ -66,10 +74,10 @@ char optionstr[] =
" (default is to just show what would be done)\n" " (default is to just show what would be done)\n"
" -X extend the final partition to include the extra space\n" " -X extend the final partition to include the extra space\n"
" (alternative to -N)\n" " (alternative to -N)\n"
" [disk] is the disk special file to operate on\n" " [disk] is the disk special file to operate on";
" (default is /dev/ad0)";
#define usage() errx(1, "Usage: %s %s\n", progname, optionstr); #define usage() errx(1, "Usage: %s %s\nDefault disk is %s", \
progname, optionstr, DEFDISK);
void getdiskinfo(char *disk); void getdiskinfo(char *disk);
int setdiskinfo(char *disk); int setdiskinfo(char *disk);
...@@ -82,7 +90,7 @@ int list = 1, verbose, fdisk, usenewpart = 1; ...@@ -82,7 +90,7 @@ int list = 1, verbose, fdisk, usenewpart = 1;
main(int argc, char *argv[]) main(int argc, char *argv[])
{ {
int ch; int ch;
char *disk = "/dev/ad0"; char *disk = DEFDISK;
progname = argv[0]; progname = argv[0];
while ((ch = getopt(argc, argv, "fvhNWX")) != -1) while ((ch = getopt(argc, argv, "fvhNWX")) != -1)
...@@ -127,11 +135,15 @@ getdiskinfo(char *disk) ...@@ -127,11 +135,15 @@ getdiskinfo(char *disk)
unsigned short magic; unsigned short magic;
} *s0; } *s0;
memset(&diskinfo, 0, sizeof(diskinfo)); memset(&diskinfo, 0, sizeof(diskinfo));
fd = open(disk, O_RDONLY); fd = open(disk, O_RDONLY);
if (fd < 0) if (fd < 0)
err(1, "%s: opening for read", disk); err(1, "%s: opening for read", disk);
#ifdef __linux__
if (ioctl(fd, BLKGETSIZE, &diskinfo.disksize) < 0)
err(1, "%s: BLKGETSIZE", disk);
diskinfo.cpu = diskinfo.tpc = diskinfo.spt = 0;
#else
#ifdef DIOCGMEDIASIZE #ifdef DIOCGMEDIASIZE
{ {
unsigned ssize; unsigned ssize;
...@@ -145,6 +157,7 @@ getdiskinfo(char *disk) ...@@ -145,6 +157,7 @@ getdiskinfo(char *disk)
diskinfo.cpu = diskinfo.tpc = diskinfo.spt = 0; diskinfo.cpu = diskinfo.tpc = diskinfo.spt = 0;
} }
#else #else
#ifdef GIOCGDINFO
{ {
struct disklabel label; struct disklabel label;
...@@ -167,6 +180,8 @@ getdiskinfo(char *disk) ...@@ -167,6 +180,8 @@ getdiskinfo(char *disk)
diskinfo.disksize = chs; diskinfo.disksize = chs;
} }
} }
#endif
#endif
#endif #endif
if (read(fd, diskinfo.bootblock, sizeof(diskinfo.bootblock)) < 0) if (read(fd, diskinfo.bootblock, sizeof(diskinfo.bootblock)) < 0)
err(1, "%s: error reading bootblock", disk); err(1, "%s: error reading bootblock", disk);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment