grub2: bring back build of aros-side grub2 tools
[AROS.git] / workbench / c / Relabel.c
blobe67738d8b75751c6b27a382e2248efcb281ac173
1 /*
2 Copyright © 1995-2007, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 /******************************************************************************
9 NAME
11 Relabel
13 SYNOPSIS
15 DRIVE/A, NAME/A
17 LOCATION
21 FUNCTION
23 Rename a volume
25 INPUTS
27 DRIVE -- The volume to rename
28 NAME -- The new name
30 RESULT
32 NOTES
34 EXAMPLE
36 BUGS
38 SEE ALSO
40 INTERNALS
42 ******************************************************************************/
44 #include <dos/dos.h>
45 #include <dos/dosextens.h>
46 #include <dos/rdargs.h>
47 #include <dos/stdio.h>
48 #include <proto/dos.h>
49 #include <proto/exec.h>
50 #include <string.h>
52 const TEXT version[] = "$VER: Relabel 41.1 (2.6.2000)\n";
54 enum { ARG_DRIVE = 0, ARG_NAME };
56 int __nocommandline;
58 int main(void)
60 int retval = RETURN_FAIL;
61 IPTR args[] = { (IPTR) NULL, (IPTR) NULL };
62 struct RDArgs *rda;
64 rda = ReadArgs("DRIVE/A,NAME/A", args, NULL);
66 if(rda != NULL)
68 if(strchr((STRPTR)args[ARG_NAME], ':') == NULL)
70 ULONG len = strlen((STRPTR)args[ARG_DRIVE]);
71 UBYTE *tmp = AllocVec(len + 1, MEMF_ANY);
72 struct DosList *dl;
74 if (tmp == NULL || !len || ((STRPTR)args[ARG_DRIVE])[len - 1] != ':')
75 goto invalid;
77 len--;
78 memcpy(tmp, (STRPTR)args[ARG_DRIVE], len);
79 tmp[len] = '\0';
81 dl = LockDosList(LDF_READ | LDF_DEVICES | LDF_VOLUMES);
82 dl = FindDosEntry(dl, tmp, LDF_DEVICES | LDF_VOLUMES);
83 UnLockDosList(LDF_READ | LDF_DEVICES | LDF_VOLUMES);
85 if (dl)
87 if (Relabel((STRPTR)args[ARG_DRIVE], (STRPTR)args[ARG_NAME]))
89 retval = RETURN_OK;
91 else
93 PrintFault(IoErr(), NULL);
96 else
98 invalid:
99 PutStr("Invalid device or volume name\n");
102 if (tmp != NULL)
103 FreeVec(tmp);
105 else
107 PutStr("':' is not a valid character in a volume name.\n");
108 retval = RETURN_FAIL;
111 else
113 PrintFault(IoErr(), "Relabel");
114 retval = RETURN_FAIL;
117 FreeArgs(rda);
119 return retval;