]>
cloudbase.mooo.com Git - z180-stamp.git/blob - avr/cmd_attach.c
2 * (C) Copyright 2016 Leo C. <erbl259-lmu@yahoo.de>
4 * SPDX-License-Identifier: GPL-2.0
8 * attach channels to devices
11 #include "cmd_attach.h"
14 #include "z180-serv.h"
15 #include "getopt-min.h"
19 * attach [[options] [unit [diskfile]]]
24 * attach -o reattach unit
25 * attach -o reattach unit diskfile
27 * attach unit diskfile
31 command_ret_t
do_attach(cmd_tbl_t
*cmdtp
, uint_fast8_t flag
, int argc
, char * const argv
[])
34 char *filename
= NULL
;
36 bool detach_all
= false;
37 drv_opt_t options
= 0;
40 (void) cmdtp
; (void) flag
;
43 if (argv
[0][0] == 'd') {
44 /* we are called as 'detach' */
46 } else if (argc
== 1) {
49 return CMD_RET_SUCCESS
;
53 while ((opt
= getopt(argc
, argv
, PSTR("darwo:"))) != -1) {
62 options
|= DRV_OPT_RO
;
65 options
&= ~DRV_OPT_RO
;
69 static const FLASH
char delim
[] = {", "};
70 char *p
= strtok_P(optarg
, delim
);
72 if (!strcmp_P(p
, PSTR("ro")))
73 options
|= DRV_OPT_RO
;
74 else if (!strcmp_P(p
, PSTR("rw")))
75 options
&= ~DRV_OPT_RO
;
76 else if (!strcmp_P(p
, PSTR("debug")))
77 options
|= DRV_OPT_DEBUG
;
78 else if (!strcmp_P(p
, PSTR("nodebug")))
79 options
&= ~DRV_OPT_DEBUG
;
80 else if (!strcmp_P(p
, PSTR("reattach")))
81 options
|= DRV_OPT_REATTATCH
;
85 p
= strtok_P(NULL
, delim
);
94 /* remaining arguments */
96 if ( !( (argc
== 0 && detach
&& detach_all
) ||
97 (argc
== 1 && detach
) ||
98 (argc
== 1 && (options
& DRV_OPT_REATTATCH
)) ||
100 return CMD_RET_USAGE
;
102 if (argc
> 0 && ((strlen(argv
[optind
]) != 4) ||
103 strncmp_P(argv
[optind
], PSTR("dsk"), 3) ||
104 (unit
= argv
[optind
][3] - '0') >= CONFIG_CPM_MAX_DRIVE
)) {
106 cmd_error(CMD_RET_FAILURE
, 0, PSTR("Invalid device: '%s'"), argv
[optind
]);
111 for (uint8_t i
= 0; i
< CONFIG_CPM_MAX_DRIVE
; i
++)
115 return CMD_RET_SUCCESS
;
119 filename
= argv
[++optind
];
121 res
= drv_attach(unit
, filename
, options
);
123 cmd_error(CMD_RET_FAILURE
, res
, PSTR("Attachment of '%s' to dsk%d failed"), filename
, unit
);
125 return CMD_RET_SUCCESS
;