source: rtems/cpukit/libmisc/shell/mknod-pack_dev.c @ eb649786

4.104.115
Last change on this file since eb649786 was eb649786, checked in by Chris Johns <chrisj@…>, on 10/08/09 at 07:07:36

2009-10-08 Chris Johns <chrisj@…>

  • Makefile.am, preinstall.am: Added statvfs.h.
  • libcsupport/Makefile.am: Add statvfs.c.
  • libcsupport/include/sys/statvfs.h, libcsupport/src/statvfs.c: New.
  • libcsupport/include/rtems/libio.h: Add a file system handler for the statvfs call.
  • libfs/src/devfs/devfs_init.c, libfs/src/dosfs/msdos_init.c, libfs/src/imfs/imfs_init.c, libfs/src/nfsclient/src/nfs.c: Set the statvfs handler to NULL.
  • include/rtems/fs.h: Add a second node access field for the RFS file system to hold a directory offset while the existing field holds the inode number. This save a rescan of the directory when working with directories.
  • libblock/include/rtems/bdbuf.h: Added references and user fields to the buffer descriptor.
  • libblock/src/bdbuf.c: Added dynamic buffer support for different block sizes. Fixed a number of bugs.
  • libblock/src/blkdev.c: Release the disk device on an error.
  • libblock/src/diskdevs.c: Set the block size to the media block size during initialisation of the disk device.
  • libblock/src/flashdisk.c, libblock/src/nvdisk.c, libblock/src/ramdisk.c: Updated the drivers to handle variable block sizes.
  • libfs/src/dosfs/fat.c, libfs/src/dosfs/fat.h: Release any buffers when an error occurs. The FAT buffer layer hangs onto a single buffer while mounted. This should be fixed.
  • sapi/inline/rtems/chain.inl: Added rtems_chain_set_off_chain, rtems_chain_is_node_off_chain, and rtems_chain_previous.
  • score/inline/rtems/score/chain.inl: Added _Chain_Set_off_chain, and _Chain_Is_node_off_chain.
  • libmisc/shell/main_ln.c, libmisc/shell/main_mknod.c, libmisc/shell/mknod-pack_dev.c, libmisc/shell/mknod-pack_dev.h: New shell commands.
  • libmisc/Makefile.am, libmisc/shell/shellconfig.h: Added ln and mknod commands.
  • libmisc/shell/hexdump-display.c: Fixed the reopen bug which showed up as a free with a bad pointer.
  • libmisc/shell/main_mount.c: List the user adding file system when listing the available file systems to mount.
  • libmisc/shell/utils-cp.c: Remove the fixed static copy buffer and use a large dynamic buffer.
  • score/inline/rtems/score/address.inl, score/src/coremsgsubmit.c, score/src/objectallocate.c, score/src/objectfree.c: Remove warnings.
  • Property mode set to 100644
File size: 8.0 KB
RevLine 
[eb649786]1/*      $NetBSD: pack_dev.c,v 1.10 2009/02/13 01:37:23 lukem Exp $      */
2
3/*-
4 * Copyright (c) 1998, 2001 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Charles M. Hannum.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 *    notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 *    notice, this list of conditions and the following disclaimer in the
17 *    documentation and/or other materials provided with the distribution.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
30 */
31
32#if HAVE_NBTOOL_CONFIG_H
33#include "nbtool_config.h"
34#endif
35
36#if 0
37#include <sys/cdefs.h>
38#if !defined(lint)
39__RCSID("$NetBSD: pack_dev.c,v 1.10 2009/02/13 01:37:23 lukem Exp $");
40#endif /* not lint */
41
42#include <sys/types.h>
43#include <sys/stat.h>
44
45#include <limits.h>
46#include <stdio.h>
47#include <stdlib.h>
48#include <string.h>
49#include <unistd.h>
50
51#include "pack_dev.h"
52#endif
53
54static  pack_t  pack_netbsd;
55static  pack_t  pack_freebsd;
56static  pack_t  pack_8_8;
57static  pack_t  pack_12_20;
58static  pack_t  pack_14_18;
59static  pack_t  pack_8_24;
60static  pack_t  pack_bsdos;
61static  int     compare_format(const void *, const void *);
62
63static const char iMajorError[] = "invalid major number";
64static const char iMinorError[] = "invalid minor number";
65static const char tooManyFields[] = "too many fields for format";
66
67#define makedev(x,y) rtems_filesystem_make_dev_t(x,y)
68#define major(d)     rtems_filesystem_dev_major_t(d)
69#define minor(d)     rtems_filesystem_dev_minor_t(d)
70
71        /* exported */
72portdev_t
73pack_native(int n, u_long numbers[], const char **error)
74{
75        portdev_t dev = 0;
76
77        if (n == 2) {
78                dev = makedev(numbers[0], numbers[1]);
79                if ((u_long)major(dev) != numbers[0])
80                        *error = iMajorError;
81                else if ((u_long)minor(dev) != numbers[1])
82                        *error = iMinorError;
83        } else
84                *error = tooManyFields;
85        return (dev);
86}
87
88
89static portdev_t
90pack_netbsd(int n, u_long numbers[], const char **error)
91{
92        portdev_t dev = 0;
93
94        if (n == 2) {
95                dev = makedev_netbsd(numbers[0], numbers[1]);
96                if ((u_long)major_netbsd(dev) != numbers[0])
97                        *error = iMajorError;
98                else if ((u_long)minor_netbsd(dev) != numbers[1])
99                        *error = iMinorError;
100        } else
101                *error = tooManyFields;
102        return (dev);
103}
104
105
106#define major_freebsd(x)        ((int32_t)(((x) & 0x0000ff00) >> 8))
107#define minor_freebsd(x)        ((int32_t)(((x) & 0xffff00ff) >> 0))
108#define makedev_freebsd(x,y)    ((portdev_t)((((x) << 8) & 0x0000ff00) | \
109                                         (((y) << 0) & 0xffff00ff)))
110
111static portdev_t
112pack_freebsd(int n, u_long numbers[], const char **error)
113{
114        portdev_t dev = 0;
115
116        if (n == 2) {
117                dev = makedev_freebsd(numbers[0], numbers[1]);
118                if ((u_long)major_freebsd(dev) != numbers[0])
119                        *error = iMajorError;
120                if ((u_long)minor_freebsd(dev) != numbers[1])
121                        *error = iMinorError;
122        } else
123                *error = tooManyFields;
124        return (dev);
125}
126
127
128#define major_8_8(x)            ((int32_t)(((x) & 0x0000ff00) >> 8))
129#define minor_8_8(x)            ((int32_t)(((x) & 0x000000ff) >> 0))
130#define makedev_8_8(x,y)        ((portdev_t)((((x) << 8) & 0x0000ff00) | \
131                                         (((y) << 0) & 0x000000ff)))
132
133static portdev_t
134pack_8_8(int n, u_long numbers[], const char **error)
135{
136        portdev_t dev = 0;
137
138        if (n == 2) {
139                dev = makedev_8_8(numbers[0], numbers[1]);
140                if ((u_long)major_8_8(dev) != numbers[0])
141                        *error = iMajorError;
142                if ((u_long)minor_8_8(dev) != numbers[1])
143                        *error = iMinorError;
144        } else
145                *error = tooManyFields;
146        return (dev);
147}
148
149
150#define major_12_20(x)          ((int32_t)(((x) & 0xfff00000) >> 20))
151#define minor_12_20(x)          ((int32_t)(((x) & 0x000fffff) >>  0))
152#define makedev_12_20(x,y)      ((portdev_t)((((x) << 20) & 0xfff00000) | \
153                                         (((y) <<  0) & 0x000fffff)))
154
155static portdev_t
156pack_12_20(int n, u_long numbers[], const char **error)
157{
158        portdev_t dev = 0;
159
160        if (n == 2) {
161                dev = makedev_12_20(numbers[0], numbers[1]);
162                if ((u_long)major_12_20(dev) != numbers[0])
163                        *error = iMajorError;
164                if ((u_long)minor_12_20(dev) != numbers[1])
165                        *error = iMinorError;
166        } else
167                *error = tooManyFields;
168        return (dev);
169}
170
171
172#define major_14_18(x)          ((int32_t)(((x) & 0xfffc0000) >> 18))
173#define minor_14_18(x)          ((int32_t)(((x) & 0x0003ffff) >>  0))
174#define makedev_14_18(x,y)      ((portdev_t)((((x) << 18) & 0xfffc0000) | \
175                                         (((y) <<  0) & 0x0003ffff)))
176
177static portdev_t
178pack_14_18(int n, u_long numbers[], const char **error)
179{
180        portdev_t dev = 0;
181
182        if (n == 2) {
183                dev = makedev_14_18(numbers[0], numbers[1]);
184                if ((u_long)major_14_18(dev) != numbers[0])
185                        *error = iMajorError;
186                if ((u_long)minor_14_18(dev) != numbers[1])
187                        *error = iMinorError;
188        } else
189                *error = tooManyFields;
190        return (dev);
191}
192
193
194#define major_8_24(x)           ((int32_t)(((x) & 0xff000000) >> 24))
195#define minor_8_24(x)           ((int32_t)(((x) & 0x00ffffff) >>  0))
196#define makedev_8_24(x,y)       ((portdev_t)((((x) << 24) & 0xff000000) | \
197                                         (((y) <<  0) & 0x00ffffff)))
198
199static portdev_t
200pack_8_24(int n, u_long numbers[], const char **error)
201{
202        portdev_t dev = 0;
203
204        if (n == 2) {
205                dev = makedev_8_24(numbers[0], numbers[1]);
206                if ((u_long)major_8_24(dev) != numbers[0])
207                        *error = iMajorError;
208                if ((u_long)minor_8_24(dev) != numbers[1])
209                        *error = iMinorError;
210        } else
211                *error = tooManyFields;
212        return (dev);
213}
214
215
216#define major_12_12_8(x)        ((int32_t)(((x) & 0xfff00000) >> 20))
217#define unit_12_12_8(x)         ((int32_t)(((x) & 0x000fff00) >>  8))
218#define subunit_12_12_8(x)      ((int32_t)(((x) & 0x000000ff) >>  0))
219#define makedev_12_12_8(x,y,z)  ((portdev_t)((((x) << 20) & 0xfff00000) | \
220                                         (((y) <<  8) & 0x000fff00) | \
221                                         (((z) <<  0) & 0x000000ff)))
222
223static portdev_t
224pack_bsdos(int n, u_long numbers[], const char **error)
225{
226        portdev_t dev = 0;
227
228        if (n == 2) {
229                dev = makedev_12_20(numbers[0], numbers[1]);
230                if ((u_long)major_12_20(dev) != numbers[0])
231                        *error = iMajorError;
232                if ((u_long)minor_12_20(dev) != numbers[1])
233                        *error = iMinorError;
234        } else if (n == 3) {
235                dev = makedev_12_12_8(numbers[0], numbers[1], numbers[2]);
236                if ((u_long)major_12_12_8(dev) != numbers[0])
237                        *error = iMajorError;
238                if ((u_long)unit_12_12_8(dev) != numbers[1])
239                        *error = "invalid unit number";
240                if ((u_long)subunit_12_12_8(dev) != numbers[2])
241                        *error = "invalid subunit number";
242        } else
243                *error = tooManyFields;
244        return (dev);
245}
246
247
248                /* list of formats and pack functions */
249                /* this list must be sorted lexically */
250struct format {
251        const char      *name;
252        pack_t          *pack;
253} formats[] = {
254        {"386bsd",  pack_8_8},
255        {"4bsd",    pack_8_8},
256        {"bsdos",   pack_bsdos},
257        {"freebsd", pack_freebsd},
258        {"hpux",    pack_8_24},
259        {"isc",     pack_8_8},
260        {"linux",   pack_8_8},
261        {"native",  pack_native},
262        {"netbsd",  pack_netbsd},
263        {"osf1",    pack_12_20},
264        {"sco",     pack_8_8},
265        {"solaris", pack_14_18},
266        {"sunos",   pack_8_8},
267        {"svr3",    pack_8_8},
268        {"svr4",    pack_14_18},
269        {"ultrix",  pack_8_8},
270};
271
272static int
273compare_format(const void *key, const void *element)
274{
275        const char              *name;
276        const struct format     *format;
277
278        name = key;
279        format = element;
280
281        return (strcmp(name, format->name));
282}
283
284
285pack_t *
286pack_find(const char *name)
287{
288        struct format   *format;
289
290        format = bsearch(name, formats,
291            sizeof(formats)/sizeof(formats[0]),
292            sizeof(formats[0]), compare_format);
293        if (format == 0)
294                return (NULL);
295        return (format->pack);
296}
Note: See TracBrowser for help on using the repository browser.