📄 rf_setconfig.c
字号:
/* * Copyright (c) 1995 Carnegie-Mellon University. * All rights reserved. * * Author: Mark Holland * * Permission to use, copy, modify and distribute this software and * its documentation is hereby granted, provided that both the copyright * notice and this permission notice appear in all copies of the * software, derivative works or modified versions, and any portions * thereof, and that both notices appear in supporting documentation. * * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. * * Carnegie Mellon requests users of this software to return to * * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU * School of Computer Science * Carnegie Mellon University * Pittsburgh PA 15213-3890 * * any improvements or extensions that they make and grant Carnegie the * rights to redistribute these changes. *//* $Locker: $ * $Log: rf_setconfig.c,v $ * Revision 1.4 1996/06/05 18:06:02 jimz * Major code cleanup. The Great Renaming is now done. * Better modularity. Better typing. Fixed a bunch of * synchronization bugs. Made a lot of global stuff * per-desc or per-array. Removed dead code. * * Revision 1.3 1996/05/24 01:59:45 jimz * another checkpoint in code cleanup for release * time to sync kernel tree * * Revision 1.2 1996/05/01 16:25:50 jimz * fix bogus newline in linkbuf causing unlink to fail * * Revision 1.1 1995/11/29 22:12:39 wvcii * Initial revision * *//* rf_setconfig * * program to configure the kernelized driver */#include <stdio.h>#include <fcntl.h>#include <sys/stat.h>#include <sys/types.h>#include <sys/ioctl.h>#include "rf_raidframe.h"/* #define DEBUG */#ifdef DEBUG#define db_printf(a) printf(a), fflush(stdout)#else /* DEBUG */#define db_printf(a)#endif /* DEBUG */#define ISDIGIT(x) ( (x)>='0' && (x)<='9' )static RF_Config_t cfg;static char *linkname = "/dev/.rfconfig";static char linkbuf[100];static int nocopy = 0;static char *progname;static void DoConfigure();static void DoShutdown();static void usage(){ fprintf("Usage: (note: cfgfile name may not start with a digit)\n"); fprintf("%s [-s] -- cfg/shutdown device 0 from /dev/.rfconfig0\n", progname); fprintf("%s [-s] N -- cfg/shutdown device N from /dev/.rfconfigN\n", progname); fprintf("%s [-s] cfgfile -- cfg/shutdown device 0 from cfgfile\n", progname); fprintf("%s [-s] cfgfile devfile -- cfg/shutdown device indicated by devfile from cfgfile\n", progname);}main(argc,argv)int argc;char **argv;{ char shutdown = 0; char cfgbuf[256], devbuf[256]; struct stat statbuf; int fd, raidID, op; progname = argv[0]; argc--; argv++; while (argc && argv[0][0] == '-') { switch(argv[0][1]) { case 's': shutdown = 1; break; case 'h': usage(); exit(1); default: fprintf(stderr,"Unknown option '%s'\n",argv[0]); exit(1); } argc--; argv++; } if (!argc) { sprintf(cfgbuf,"/dev/.rfconfig0"); sprintf(devbuf,"/dev/raidframe_c"); nocopy = 1; /* using default config => don't copy it */ } else if (ISDIGIT(argv[0][0])) { sprintf(cfgbuf,"/dev/.rfconfig%d",atoi(argv[0])); sprintf(devbuf,"/dev/raidframe%d_c",atoi(argv[0])); nocopy = 1; } else if (argc==1) { sprintf(cfgbuf, argv[0]); sprintf(devbuf, "/dev/raidframe_c"); } else { sprintf(cfgbuf, argv[0]); sprintf(devbuf, argv[1]); } if (stat(devbuf, &statbuf) < 0) { fprintf(stderr,"setconfig: unable to stat file %s\n",devbuf); perror("setconfig"); exit(1); } raidID = minor(statbuf.st_rdev)>>6; sprintf(linkbuf, "%s%d",linkname, raidID); fd = open(devbuf, O_RDWR, 0644); if (fd < 0) { fprintf(stderr,"Unable to open raidframe device file\n"); perror("open"); exit(1); } if (shutdown) DoShutdown(fd); else DoConfigure(cfgbuf, fd); close(fd); exit(0);}static void DoConfigure(configfile, fd)char *configfile;int fd;{ void *p; char cmdbuf[256]; int status; if (rf_MakeConfig(configfile, &cfg) < 0) { fprintf(stderr,"Unable to create configuration structure\n"); exit(1); } db_printf(("got config\n")); /* the argument to ioctl is a pointer to the data to be copied in. * I want only the pointer to the configuration info to be copied in, * so I use p as an extra level of indirection */ p = (void *) &cfg; if (ioctl(fd, (unsigned long) RAIDFRAME_CONFIGURE, (void *) &p) < 0) { perror("config ioctl"); exit(1); } db_printf(("did ioctl\n")); if (!nocopy) { if (unlink(linkbuf)) { fprintf(stderr, "Could not remove \"%s\"\n", linkbuf); fflush(stderr); perror("unlink"); } sprintf(cmdbuf, "cp %s %s\n",configfile, linkbuf); if (status = system(cmdbuf)) { fprintf(stderr,"Warning: unable to copy file %s to %s\n",configfile, linkbuf); printf("cp exit status was %d\n",status); } else { fprintf(stderr,"A copy of config file %s was placed in %s\n",configfile,linkbuf); } } db_printf(("did copy\n"));}static void DoShutdown(fd)int fd;{ if (ioctl(fd, (unsigned long) RAIDFRAME_SHUTDOWN, NULL) < 0) { perror("shutdown ioctl"); exit(1); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -