2 * Copyright (C) 2012, The AROS Development Team
4 * Author: Jason S. McMullan <jason.mcmullan@gmail.com>
6 * Licensed under the AROS PUBLIC LICENSE (APL) Version 1.1
16 #include <sys/types.h>
19 #include <adf/adflib.h>
20 #include <adf/adf_hd.h>
22 #define SZ_1G (1UL << 30)
23 #define SZ_2G (1UL << 31)
25 static int usage(const char *program
)
28 "%s /dev/sdb /path/to/Parthnope [/path/to/AROS]\n"
33 static void *openmem(const char *name
, size_t *sizep
)
39 fd
= open(name
, O_RDONLY
);
43 size
= lseek(fd
, 0, SEEK_END
);
46 lseek(fd
, 0, SEEK_SET
);
51 len
= read(fd
, mem
, size
);
63 static int copyToVolume(struct Volume
*vol
, const char *path
, int depth
)
66 DIR *dir
= opendir(path
);
68 SECTNUM acd
= adfCurrentDir(vol
);
69 int files
= 0, rc
= 0;
76 getcwd(here
, sizeof(here
));
79 while (rc
>= 0 && (de
= readdir(dir
))) {
81 if (strcmp(de
->d_name
,".") == 0 ||
82 strcmp(de
->d_name
,"..") == 0)
84 if (stat(de
->d_name
, &st
) == 0) {
85 if (S_ISDIR(st
.st_mode
)) {
86 printf("D %*c%s", depth
* 2, ' ', de
->d_name
);
87 if (adfCreateDir(vol
, acd
, de
->d_name
) == RC_OK
) {
88 if (adfChangeDir(vol
, de
->d_name
) == RC_OK
) {
90 rc
= copyToVolume(vol
, de
->d_name
, depth
+1);
95 printf(": Can't ChDir\n");
98 printf(": Can't create\n");
100 } else if (S_ISREG(st
.st_mode
)) {
101 int fd
= open(de
->d_name
, O_RDONLY
);
102 printf("F %*c%s\n", depth
* 2, ' ', de
->d_name
);
104 struct File
*file
= adfOpenFile(vol
, de
->d_name
, "w");
108 while ((len
= read(fd
, buff
, 256)) > 0) {
109 adfWriteFile(file
, len
, buff
);
126 int main(int argc
, char **argv
)
132 struct Partition part_boot
= {
134 .volType
= { 'D', 'O', 'S', 3 }, /* DOS\03 */
137 struct Partition part_work
= {
139 .volType
= { 'D', 'O', 'S', 3 }, /* DOS\03 */
141 struct Partition
*part
[] = { &part_boot
, &part_work
};
143 if (argc
!= 3 && argc
!= 4) {
144 return usage(argv
[0]);
147 code
= openmem(argv
[2], &size
);
155 dev
= adfMountDev(argv
[1], FALSE
);
156 if (dev
&& argc
== 3) {
157 if (adfWriteBOOT(dev
, code
, size
) == RC_OK
) {
158 printf("SLB updated\n");
166 lastcyl
= SZ_1G
/ 512 / dev
->sectors
/ dev
->heads
;
167 if (lastcyl
> dev
->cylinders
) {
168 lastcyl
= dev
->cylinders
;
171 part_boot
.startCyl
= 2;
172 part_boot
.lenCyl
= lastcyl
- part_boot
.startCyl
;
174 part_work
.startCyl
= lastcyl
;
175 part_work
.lenCyl
= dev
->cylinders
- lastcyl
;
177 if (adfCreateHd(dev
, parts
, part
) == RC_OK
) {
178 /* Add Parthenope to the boot blocks */
179 if (adfWriteBOOT(dev
, code
, size
) == RC_OK
) {
182 if ((vol
= adfMount(dev
, 0, FALSE
))) {
183 int files
= copyToVolume(vol
, argv
[3], 0);
185 printf("Copied %d files\n", files
);