File: extendfs.c

package info (click to toggle)
jfsutils 1.0.14-1
  • links: PTS
  • area: main
  • in suites: woody
  • size: 3,132 kB
  • ctags: 4,667
  • sloc: ansic: 41,422; sh: 335; makefile: 126
file content (327 lines) | stat: -rw-r--r-- 6,581 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
/*
 *   Copyright (c) International Business Machines  Corp., 2000
 *
 *   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 of the License, 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
 *
 *   MODULE_NAME:		extendfs.c
 *
 *   COMPONENT_NAME: 	jfsutil
 *
 *   FUNCTIONS:		main
 *			extendfs
 *			whatDoYouWant
 *		
*/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>

#include "jfs_types.h"
#include "jfs_superblock.h"
#include "jfs_filsys.h"
#include "jfs_dinode.h"
#include "jfs_dmap.h"
#include "jfs_imap.h"
#include "jfs_xtree.h"
#include "jfs_dtree.h"
#include "jfs_extendfs.h"
#include "jfs_debug.h"

#include "devices.h"
#include "debug.h"

#include "fssubs.h"
#include "utilsubs.h"
#include "message.h"

/* Global telling openLV to fail silently */
extern	int32_t	Fail_Quietly;

/* command parameters */
int32_t	LogSize = 0;
int64_t	FSSize = 0;

/*
 *	device under extendfs
 */
char	LVName[4];	/* device name */

/*
 *	Parameter array for messages
 */
#define MAXPARMS	2
#define MAXSTR		80
char	*msg_parms[MAXPARMS];
char	msgstr[MAXSTR];

/*
 * forward references
 */
static int32_t extendfs(void);
int32_t openLV(char *LVName);
static int32_t whatDoYouWant(int32_t argc, char **argv);
char *itoa(int n);

/*
 * NAME:	main()
 *
 * FUNCTION:	Main routine of extendfs utility.
 */
int main(int argc, char **argv)
{
	char		drive;
#ifdef _JFS_OS2  
	uint32_t	free_space;
	FSALLOCATE  fsalloc_buf;
#endif  
	int         rc;

#ifdef _JFS_OS2  
	DosError(FERR_DISABLEHARDERR);
#endif  

	/* parse command line arguments */
	if ( (rc = whatDoYouWant(argc, argv)) )
	{
		message_user(MSG_JFS_EXTENDFS_USAGE, NULL, 0, STDOUT_CODE,
			     NO_RESPONSE, JFS_MSG);
		goto out;
	}

	if (LVName[0] == '*')
	{
		/* Try to extend all partitions. */

		/* This tells openLV to fail silently */
		Fail_Quietly = 1;

		LVName[1] = ':';
		LVName[2] = 0;

		for (drive = 'C'; drive <= 'Z'; drive++)
		{
			LVName[0] = drive;
			rc = openLV(LVName);
			if (rc == 0)
			{
				extendfs();
				closeFS();
			}
		}
		return 0;
	}

	/* validate and open LV */
	if ( (rc = openLV(LVName)) )
		goto out;	

#ifdef	_JFS_DEBUG_EXTENDFS
	/* open FS */
	if (rc = openFS())
		goto out;
#endif	/* _JFS_DEBUG_EXTENDFS */

	/* extend the file system */
	rc = extendfs();

	if (rc == 0)
	{
		message_user(MSG_JFS_EXTENDFS_COMPLETE, NULL, 0, STDOUT_CODE,
			     NO_RESPONSE, JFS_MSG);
		sprintf(msgstr, "%lld", (long long)((lvMount->LVSize << lvMount->l2pbsize) >> 10));
		msg_parms[0] = msgstr;
		message_user(MSG_OSO_DISK_SPACE, msg_parms, 1, STDOUT_CODE,
			     NO_RESPONSE, OSO_MSG);

#ifdef _JFS_OS2  
		rc = DosQueryFSInfo((unsigned long)(toupper(LVName[0])-'A'+1), 1L,
				    (void *)&fsalloc_buf, sizeof(FSALLOCATE));
#endif 

		if (rc)
		{
			message_user(MSG_JFS_EXTENDFS_FAILED, NULL, 0,
				     STDOUT_CODE, NO_RESPONSE, JFS_MSG);
		}
		else
		{
#ifdef _JFS_OS2  
			free_space = (fsalloc_buf.cSectorUnit *
				      fsalloc_buf.cUnitAvail) /
				     (1024 / fsalloc_buf.cbSector);
			_itoa(free_space, msgstr, 10);
#endif  
			msg_parms[0] = msgstr;
			message_user(MSG_OSO_FREE_SPACE, msg_parms, 1,
				     STDOUT_CODE, NO_RESPONSE, OSO_MSG);
		}
	}
	else
	{
		message_user(MSG_JFS_EXTENDFS_FAILED, NULL, 0, STDOUT_CODE,
			     NO_RESPONSE, JFS_MSG);
	}
#ifdef	_JFS_DEBUG_EXTENDFS
	/* close FS */
	closeFS();
#endif	/* _JFS_DEBUG_EXTENDFS */

out:
	return rc;
}


/*
 *	extendfs()
 */
static int32_t extendfs(void)
{
	int32_t	       rc;
#ifdef _JFS_OS2  
	int32_t	       pList;
	unsigned long  pListLen = 0;
#endif 
	extendfs_t     pData;
	unsigned long  pDataLen = 0;

	pDataLen = sizeof(extendfs_t);

	/*
	 *	extend file system
	 */
	pData.flag = 0;
	pData.dev = lvMount->LVNumber;
	pData.LVSize = lvMount->LVSize;
	pData.LogSize = LogSize;
	pData.FSSize = FSSize;


#ifdef _JFS_OS2  
	rc = fscntl(JFSCTL_EXTENDFS,
	       (void *)&pList, &pListLen,
	       (void *)&pData, &pDataLen);
#endif 

	return rc;
}


/*
 *	whatDoYouWant()
 *
 * function: extend file system;
 *
 * extendfs [-l LogSize] {device_name}
 *
 *   |-------------------------------|----------|----------|
 *   file system space               fsck       inline log
 *                                   workspace  space
 *
 * input:
 *	option:
 *	 -ls:LogSize: new inline log size in megabytes;
 *	device_name - device under extension.
 */
static int32_t whatDoYouWant( int32_t  argc,
	                          char	   **argv)
{
	int32_t	 rc = 0;
	int32_t	 i;
	char	 *argp;
	bool	 devFound = false;

#ifdef NO_DRIVE_NEEDED
	char	 cwd[80];

	/* initialize the disk name to be the current drive */
	getcwd(cwd, 80);
	LVName[0] = cwd[0];
	LVName[1] = cwd[1];
	LVName[2] = '\0';
#endif

	if (argc < 2)
		return ERROR_INVALID_PARAMETER;

	/* parse each of the command line parameters */
	for (i = 1; i < argc; i++)
	{
		argp = argv[i];

		/* an option ? */
		if (*argp == '/' || *argp == '-')  
		{
			argp++;  /* increment past / or - */
			if (strncmp(argp, "ls", 2) == 0 || 
			    strncmp(argp, "LS", 2) == 0 || 
			    strncmp(argp, "Ls", 2) == 0 ||
			    strncmp(argp, "lS", 2) == 0)
			{
				if (argp[2] == ':')
					LogSize = strtoll(argp + 3, NULL, 0);
				else
					return ERROR_INVALID_PARAMETER;
			}
			else
				return ERROR_INVALID_PARAMETER;

			continue;
		}

		/* a drive letter */
		if (isalpha(*argp) && argp[1] == ':' && !argp[2])
		{  
			/* only allow one drive letter to be specified */
			if (devFound == true)  
				return ERROR_INVALID_PARAMETER;
			else
			{
				strcpy(LVName, argp);
				devFound = true;
			}

			continue;
		}
		if ((*argp == '*') && ! argp[1])
		{
			if (devFound == true)
				return ERROR_INVALID_PARAMETER;

			LVName[0] = '*';
			LVName[1] = 0;
			devFound = true;

			continue;
		}

		/* UFO parameter */
		return ERROR_INVALID_PARAMETER;
	} /* end for */

	if (devFound == false)
		rc = ERROR_INVALID_PARAMETER;

	return (rc);
}


char *itoa(int n)
{
	static char retbuf[20];
	sprintf(retbuf, "%d", n);
	return retbuf;
}