S_I386.C
资源名称:bootmenu.zip [点击查看]
上传用户:yeshiping1
上传日期:2007-01-06
资源大小:29k
文件大小:3k
源码类别:
磁盘编程
开发平台:
Others
- /* This file contains system-specific functions suitable for
- * most AT&T System V/386 variants (ISC,SCO,Intel...).
- * The program pfdisk.c calls these routines.
- */
- #include <stdio.h>
- #include <fcntl.h>
- #include <sys/types.h>
- #include <sys/vtoc.h>
- #define extern
- #include "sysdep.h"
- #undef extern
- int usage(prog) /* print a usage message */
- char *prog; /* program name */
- {
- fprintf(stderr,"Usage: %s devn
- where 'dev' is the device name, i.e. /dev/rdsk/0p0n
- (The device must start on absolute sector zero.)n",prog);
- }
- void getGeometry(dev, c, h, s)
- char *dev; /* device name */
- unsigned *c,*h,*s; /* cyls, heads, sectors */
- {
- int devfd, retval;
- struct disk_parms dp;
- devfd = open(dev, O_RDONLY, 0);
- if (devfd < 0) {
- fprintf(stderr,"%s: can't open for readingn", dev);
- return;
- }
- retval = ioctl(devfd, V_GETPARMS, &dp);
- close(devfd);
- if (retval < 0) {
- fprintf(stderr,"%s: can't get disk parametersn", dev);
- return;
- }
- if (dp.dp_type != DPT_WINI) {
- fprintf(stderr,"%s: not a Winchester Diskn", dev);
- return;
- }
- *c = dp.dp_cyls;
- *h = dp.dp_heads;
- *s = dp.dp_sectors;
- }
- int getFile(name, buf, len) /* read file into buffer */
- char *name, *buf;
- int len;
- { /* (open, read, close) */
- int devfd, retval;
- devfd = open(name, O_RDONLY, 0);
- if (devfd < 0) {
- fprintf(stderr,"%s: can't open for readingn", name);
- return(devfd);
- }
- retval = read(devfd, buf, len);
- if (retval < 0)
- fprintf(stderr,"%s: read failedn", name);
- close(devfd);
- return(retval);
- }
- int putFile(name, buf, len) /* write buffer to file */
- char *name, *buf;
- int len;
- { /* (open, write, close) */
- int devfd, retval;
- devfd = open(name, O_WRONLY|O_CREAT, 0666);
- if (devfd < 0) {
- fprintf(stderr,"%s: can't open for writingn", name);
- return(devfd);
- }
- retval = write(devfd, buf, len);
- if (retval < 0)
- fprintf(stderr,"%s: write failedn", name);
- close(devfd);
- return(retval);
- }
- int getBBlk(devname, buffer) /* read block into buffer */
- char *devname, *buffer; /* (open, read, close) */
- {
- int devfd, retval;
- devfd = open(devname,O_RDONLY);
- if (devfd < 0) {
- printf("%s: can't open for readn", devname);
- return(devfd);
- }
- retval = read(devfd, buffer, SECSIZE);
- close(devfd);
- return(retval);
- }
- int putBBlk(devname, buffer) /* write buffer to device */
- char *devname, *buffer; /* (open, write, close) */
- {
- int devfd, retval;
- devfd = open(devname,O_WRONLY);
- if (devfd < 0) {
- printf("%s: can't open for writen",devname);
- return(devfd);
- }
- retval = write(devfd, buffer, SECSIZE);
- sync();
- close(devfd);
- return(retval);
- }