1 /* $NetBSD: cd9660_archimedes.c,v 1.2 2013/01/28 21:03:28 christos Exp $ */
4 * Copyright (c) 1998, 2009 Ben Harris
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 * cd9660_archimedes.c - support for RISC OS "ARCHIMEDES" extension
32 * RISC OS CDFS looks for a special block at the end of the System Use
33 * Field for each file. If present, this contains the RISC OS load
34 * and exec address (used to hold the file timestamp and type), the
35 * file attributes, and a flag indicating whether the first character
36 * of the filename should be replaced with '!' (since many special
37 * RISC OS filenames do).
40 #if HAVE_NBTOOL_CONFIG_H
41 #include "nbtool_config.h"
44 #include <sys/cdefs.h>
45 #if defined(__RCSID) && !defined(__lint)
46 __RCSID("$NetBSD: cd9660_archimedes.c,v 1.2 2013/01/28 21:03:28 christos Exp $");
57 #include "cd9660_archimedes.h"
60 * Convert a Unix time_t (non-leap seconds since 1970-01-01) to a RISC
61 * OS time (non-leap(?) centiseconds since 1900-01-01(?)).
65 riscos_date(time_t unixtime
)
69 base
= 31536000ULL * 70 + 86400 * 17;
70 return (((u_int64_t
)unixtime
) + base
)*100;
74 * Add "ARCHIMEDES" metadata to a node if that seems appropriate.
76 * We touch regular files with names matching /,[0-9a-f]{3}$/ and
77 * directories matching /^!/.
80 archimedes_convert_node(cd9660node
*node
)
82 struct ISO_ARCHIMEDES
*arc
;
87 if (node
->su_tail_data
!= NULL
)
88 /* Something else already has the tail. */
91 len
= strlen(node
->node
->name
);
94 if (len
>= 4 && node
->node
->name
[len
-4] == ',')
95 /* XXX should support ,xxx and ,lxa */
96 type
= strtoul(node
->node
->name
+ len
- 3, NULL
, 16);
97 if (type
== -1 && node
->node
->name
[0] != '!')
99 if (type
== -1) type
= 0;
101 assert(sizeof(*arc
) == 32);
102 arc
= ecalloc(1, sizeof(*arc
));
104 stamp
= riscos_date(node
->node
->inode
->st
.st_mtime
);
106 memcpy(arc
->magic
, "ARCHIMEDES", 10);
107 cd9660_731(0xfff00000 | (type
<< 8) | (stamp
>> 32), arc
->loadaddr
);
108 cd9660_731(stamp
& 0x00ffffffffULL
, arc
->execaddr
);
109 arc
->ro_attr
= RO_ACCESS_UR
| RO_ACCESS_OR
;
110 arc
->cdfs_attr
= node
->node
->name
[0] == '!' ? CDFS_PLING
: 0;
111 node
->su_tail_data
= (void *)arc
;
112 node
->su_tail_size
= sizeof(*arc
);
116 * Add "ARCHIMEDES" metadata to an entire tree recursively.
119 archimedes_convert_tree(cd9660node
*node
)
123 assert(node
!= NULL
);
125 archimedes_convert_node(node
);
127 /* Recurse on children. */
128 TAILQ_FOREACH(cn
, &node
->cn_children
, cn_next_child
)
129 archimedes_convert_tree(cn
);