📄 geometry.c
字号:
/* initiator/geometry.c *//* vi: set autoindent tabstop=8 shiftwidth=4 : *//* Prints "geometry" of a disk, such as "/dev/sda", or a partition, such as "/dev/sda1". Obtained by using ioct() system calls. You must be root to run this. Give the list of disks and/or partitions on the command line. If nothing given, "/dev/sda" is used as the default.*//* Copyright (C) 2001-2003 InterOperability Lab (IOL) University of New Hampshier (UNH) Durham, NH 03824 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. The name of IOL and/or UNH may not be used to endorse or promote products derived from this software without specific prior written permission.*/#define _POSIX_C_SOURCE 199506L#include <stdio.h>#include <stdlib.h>#include <unistd.h>#include <fcntl.h>#include <linux/fs.h>#include <linux/hdreg.h>extern int ioctl(int fd, int command, ...);#define DEFAULT_DEVICE_NAME "/dev/sda"voiddo_one_disk(char *name){ int fd; struct hd_geometry geo; unsigned long size, blocks; if ((fd = open(name, O_RDONLY)) < 0) { perror(name); return; } if (ioctl(fd, HDIO_GETGEO, &geo) < 0) { perror(name); close(fd); return; } printf("Geometry for %s\n", name); printf("%12s: %u\n", "heads", geo.heads); printf("%12s: %u %s\n", "sectors", geo.sectors, "per cylinder"); printf("%12s: %u %s\n", "cylinders", geo.cylinders, "per head"); printf("%12s: %lu\n", "start sector", geo.start); if (ioctl(fd, BLKGETSIZE, &blocks) < 0) { perror(name); close(fd); return; } printf("%12s: %lu %s\n", "size", blocks, "sectors total"); if (ioctl(fd, BLKSSZGET, &size) < 0) { perror(name); close(fd); return; } printf("%12s: %lu %s\n", "sector size", size, "bytes per sector"); printf("%12s: %lu %s\n", "size", blocks * size, "bytes total"); if (close(fd) < 0) { perror(name); return; }}intmain(int argc, char *argv[]){ int count; if (argc <= 1) do_one_disk(DEFAULT_DEVICE_NAME); else { for (count = 1; count < argc; count++) { if (count > 1) printf("\n"); do_one_disk(argv[count]); } } return EXIT_SUCCESS;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -