|
|
1.1 root 1: /*
2: * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
3: *
4: * @APPLE_LICENSE_HEADER_START@
5: *
6: * Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
7: * Reserved. This file contains Original Code and/or Modifications of
8: * Original Code as defined in and that are subject to the Apple Public
9: * Source License Version 1.1 (the "License"). You may not use this file
10: * except in compliance with the License. Please obtain a copy of the
11: * License at http://www.apple.com/publicsource and read it before using
12: * this file.
13: *
14: * The Original Code and all software distributed under the License are
15: * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
16: * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
17: * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
18: * FITNESS FOR A PARTICULAR PURPOSE OR NON- INFRINGEMENT. Please see the
19: * License for the specific language governing rights and limitations
20: * under the License.
21: *
22: * @APPLE_LICENSE_HEADER_END@
23: */
24: /*
25: * slabel.m
26: */
27:
28: #import <bsd/sys/types.h>
29: #import <remote/NXConnection.h>
30: #import <driverkit/IODiskPartition.h>
31: #import <ansi/stdio.h>
32: #import <bsd/libc.h>
33: #import "defaults.h"
34: #import "buflib.h"
35:
36: void usage(char **argv);
37: void exit(int exitcode);
38:
39: char *label_name = (char *)0;
40: int label_version = 0;
41:
42: int main(int argc, char **argv) {
43:
44: char *hostname=HOST_DEFAULT;
45: char *devname=DEVICE_DEFAULT;
46: int arg;
47: char c;
48: id targetId;
49: IOReturn rtn;
50: char outstr[100];
51: struct disk_label label;
52:
53: /*
54: * Get standard defaults from environment or defaults.h
55: */
56: get_default_t("hostname", &hostname, HOST_DEFAULT);
57: get_default_t("devname", &devname, DEVICE_DEFAULT);
58:
59: for(arg=1; arg<argc; arg++) {
60: c = argv[arg][0];
61: switch(c) {
62: case 'h':
63: hostname = &argv[arg][2];
64: break;
65: case 'd':
66: devname = &argv[arg][2];
67: break;
68: case 'n':
69: label_name = &argv[arg][2];
70: break;
71: case 'v':
72: label_version = atoi(&argv[arg][2]);
73: break;
74:
75: default:
76: usage(argv);
77: }
78: }
79:
80: targetId = [NXConnection connectToName:devname
81: onHost:hostname];
82: if(targetId == nil) {
83: printf("connectToName:%s failed\n", devname);
84: exit(1);
85: }
86:
87: /*
88: * First read the existing label.
89: */
90: rtn = [targetId readLabel:&label];
91: if(rtn) {
92: sprintf(outstr, "Error on readLabel: %s\n",
93: [targetId stringFromReturn:rtn]);
94: printf(outstr);
95: exit(1);
96: }
97:
98: /*
99: * Anything to change?
100: */
101: if(label_name)
102: strncpy(label.dl_label, label_name, MAXLBLLEN);
103: if(label_version)
104: label.dl_version = label_version;
105:
106: /*
107: * write new label.
108: */
109: rtn = [targetId writeLabel:&label];
110: if(rtn) {
111: sprintf(outstr, "Error on writeLabel: %s\n",
112: [targetId stringFromReturn:rtn]);
113: printf(outstr);
114: exit(1);
115: }
116:
117: exit(0);
118:
119: } /* main() */
120:
121: void usage(char **argv) {
122: printf("usage: %s [options]\n", argv[0]);
123: printf("Options:\n");
124: printf("\th=hostname\n");
125: printf("\td=devname\n");
126: printf("\tn=new_label_name\n");
127: printf("\tv=new_version_num\n");
128: exit(1);
129: }
130:
131:
132:
133:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.