S_UNIX.C
资源名称:bootmenu.zip [点击查看]
上传用户:yeshiping1
上传日期:2007-01-06
资源大小:29k
文件大小:2k
源码类别:
磁盘编程
开发平台:
Others
- /* This file contains system-specific functions for generic UNIX.
- * The program pfdisk.c calls these routines.
- */
- #include <stdio.h>
- #include <fcntl.h>
- #define extern
- #include "sysdep.h"
- #undef extern
- int usage(prog) /* print a usage message */
- char *prog; /* program name */
- {
- fprintf(stderr,"Usage: %s devn
- twhere 'dev' is the device name, i.e. /dev/hd0n
- t(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 */
- {
- fprintf(stderr,
- "ntWarning: The device "%s" is assumed to have:n
- tcyls=%d, heads=%d, sectors=%d (an arbitrary guess).n",
- dev, *c, *h, *s);
- fprintf(stderr,
- "ntThis program was compiled for generic UNIX and thereforen
- tdoes not know how to determine the disk parameters. You mustn
- tdescribe the disk geometry manually, using the 'G' command.n");
- }
- 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);
- }