pax_global_header00006660000000000000000000000064121341152470014512gustar00rootroot0000000000000052 comment=60b4a4efc05eb8bd20859fd251a5733c1eb8b533 genromfs-0.5.2/000075500000000000000000000000001213411524700133345ustar00rootroot00000000000000genromfs-0.5.2/.gear-rules000064400000000000000000000000071213411524700154000ustar00rootroot00000000000000tar: . genromfs-0.5.2/.gitignore000064400000000000000000000000151213411524700153200ustar00rootroot00000000000000*.o genromfs genromfs-0.5.2/COPYING000064400000000000000000000430771213411524700144020ustar00rootroot00000000000000 GNU GENERAL PUBLIC LICENSE Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc. 675 Mass Ave, Cambridge, MA 02139, USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Library General Public License instead.) You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. 7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. 10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS Appendix: How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) 19yy This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) 19yy name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (which makes passes at compilers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice This General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Library General Public License instead of this License. genromfs-0.5.2/ChangeLog000064400000000000000000000064221213411524700151120ustar00rootroot000000000000002002-04-30 15:09 Janos Farkas * genromfs.c: romfs_checksum(); avoid potential side effects of an ntohl() macro; processdir(): don't readdir() on NULLs. Thanks to Ilguiz Latypov. 2002-03-05 09:58 Janos Farkas * genromfs.c: Cygwin needs to include sys/sysmacros.h, Thanks to Arthur Shipkowski. 2002-01-23 11:32 Janos Farkas * Makefile: update version; check for correct release on dist. * checkdist: new file to check for misversioned dists. 2002-01-22 10:00 Janos Farkas * NEWS: update version, release 0.5.1. * genromfs.lsm: likewise. 2002-01-22 09:54 Janos Farkas * Makefile: remove mis-installed man-page first. Also fix directories to not use //. 2002-01-22 08:37 Janos Farkas * genromfs.8: document special @files, clarify wording of some other options, and update version/date. 2002-01-21 10:37 Janos Farkas * Makefile: install man page in man-dir. oops. 2002-01-21 09:30 Janos Farkas * bump version for next release. 2002-01-20 12:03 Janos Farkas * Makefile: bump version, release 0.5. 2002-01-20 11:47 Janos Farkas * Makefile: more fixes for FreeBSD build. 2002-01-20 11:32 Janos Farkas * Makefile: build fixes, add version, dist. 2002-01-20 10:57 Janos Farkas * genrommkdev: a sample script to generate special nodes from a device list file. 2002-01-20 10:29 Janos Farkas * genromfs.c: use O_BINARY, and "wb" if possible to ease porting. 2002-01-20 10:03 Janos Farkas * Makefile: add prefix/bindir/mandir to ease relocated build. 2002-01-20 09:36 Janos Farkas * genromfs.c: include sys/types.h, and use int32_t, clear up hopefully all ntohl/htonl confusion. (thanks to Debian patches) 2002-01-19 17:20 Janos Farkas * genromfs.c: refactor fnmatch() usage to nodematch() * genromfs.c: spelling nad => and * romfs.txt: thinkos 2002-01-18 11:22 Janos Farkas * imported from http://www.uclinux.org/pub/uClinux/utilities/ without the indent changes (sorry) * Fri Aug 17 23:21:00 2001 Greg Ungerer (gerg@lineo.com) * incorporated patches from many uClinux users * fixed @ device link problem (profesor@sidehack.sat.gweep.net) addition of -x option to skip files * compilation on Solaris (The LEOX team ) * filename device insertion (davidm@lineo.com) Tue Feb 8 09:52:51 2000 Pavel Roskin * genromfs.c (main): don't rely on char being signed when parsing the arguments Mon Sep 21 16:35:33 1998 Jakub Jelinek * genromfs.c: add support for `-a' and `-A'. * genromfs.8: document it. Tue Aug 5 15:54:47 1997 Janos Farkas * Version 0.2. * genromfs.8: the manual page has been initially written by Cristoph Lameter, now I reworked it to be less repetitive with respect to the comments in the source :) * genromfs.c: just helpful help, and process `-h' too. * Makefile: add an install target. genromfs-0.5.2/Makefile000064400000000000000000000022661213411524700150020ustar00rootroot00000000000000 # Makefile for the genromfs program. all: genromfs PACKAGE = genromfs VERSION = 0.5.2 CC = gcc CFLAGS = -O2 -Wall -DVERSION=\"$(VERSION)\"#-g# LDFLAGS = -s#-g DISTDIR = $(PACKAGE)-$(VERSION) FILES = COPYING NEWS ChangeLog Makefile \ genromfs.8 genromfs.c genromfs.lsm \ readme-kernel-patch genrommkdev romfs.txt \ checkdist prefix = /usr bindir = $(prefix)/bin mandir = $(prefix)/man genromfs: genromfs.o $(CC) $(LDFLAGS) genromfs.o -o genromfs .c.o: $(CC) $(CFLAGS) $< -c -o $@ clean: rm -f genromfs *.o distclean: clean rm -rf $(DISTDIR) $(DISTDIR).tar.gz dist: ./checkdist $(VERSION) rm -rf $(DISTDIR).tar.gz $(DISTDIR) mkdir $(DISTDIR); for i in $(FILES); do \ cp $$i $(DISTDIR)/; \ done; \ tar --owner=root --group=root -zcf $(DISTDIR).tar.gz $(DISTDIR); rm -rf $(DISTDIR) install: all install-bin install-man install-bin: mkdir -p $(PREFIX)$(bindir) install -m 755 genromfs $(PREFIX)$(bindir)/ install-man: # genromfs 0.5 installed the man page in this file, # remove it before someone notices :) if [ -f $(PREFIX)$(bindir)/man8 ]; then \ rm -f $(PREFIX)$(bindir)/man8; \ fi mkdir -p $(PREFIX)$(mandir)/man8 install -m 644 genromfs.8 $(PREFIX)$(mandir)/man8/ genromfs-0.5.2/NEWS000064400000000000000000000013621213411524700140350ustar00rootroot00000000000000Changes since release 0.5.1: * distribution is now checked for correct version Changes in release 0.5.1: * the man page is now installed correctly * documented @ special files, updated man page version * manual wording updates Changes in release 0.5: * genromfs builds on Linux (libc5, glibc), FreeBSD, Solaris, with gcc * added a script to generate device special files * merged in the uClinux changes, thanks to: Greg Ungerer (gerg -at- snapgear.com) The LEOX team (lpm/bdl/bronche -at- leox.org) profesor -at- sidehack.sat.gweep.net ** allow specifying device files by names @dev,b,major,minor ** -x option to exclude files ** portability fixes to compile on Solaris * print version * spelling fixes Changes in release 0.3: * in progress genromfs-0.5.2/checkdist000075500000000000000000000003631213411524700152250ustar00rootroot00000000000000#!/bin/sh current=$1 # check for previous versions echo "The following files have not been updated for $current" grep -L $current NEWS ChangeLog genromfs.lsm genromfs.8 && echo "(all ok)" # find -type f|xargs egrep '(0\.3|0\.5|0\.5.1)' exit 0 genromfs-0.5.2/genromfs.8000064400000000000000000000065241213411524700152540ustar00rootroot00000000000000.TH GENROMFS 8 "Jan 2002" "Version 0.5.1" .SH NAME genromfs \- create a romfs image .SH SYNOPSIS .B genromfs .B \-f device [ .B \-d source ] [ .B \-V label ] [ .B \-a alignment ] [ .B \-A alignment,pattern ] [ .B \-x pattern ] [ .B \-v ] .SH DESCRIPTION .B genromfs is used to create a romfs file system image, usually directly on a block device, or for test purposes, in a plain file. It is the .I mkfs equivalent of other filesystems. .PP .B genromfs will scan the current directory and its subdirectories, build a romfs image from the files found, and output it to the file or device you specified. .PP During scanning, it recognizes a special notation. If a file begins with the @ sign (and is empty otherwise), it refers to a device special node in the format: .B @name,type,major,minor. type can be .I b for block devices, .I c for character devices, and .I p for fifos. The linux virtual console 1 can thus be included as a file with the name: .B @tty1,c,4,1 .SH OPTIONS .TP .BI -f \ output Specifies the file to output the image to. This option is required. .TP .BI -d \ source Use the specified directory as the source, not the current directory. .TP .BI -V \ label Build the image with the specified volume label. Currently it is not used by the kernel, but it will be recorded in the image. .TP .BI -a \ alignment Align regular files to a larger boundary. .B genromfs will align data of each regular file in the resulting image to the specified alignment, while keeping the image compatible with the original romfs definition (by adding pad bytes between last node before the file and file's header). By default, .B genromfs will guarantee only an alignment of 16 bytes. .TP .BI -A \ alignment,pattern Align objects matching shell wildcard pattern to alignment bytes. If one object matches more patterns, then the highest alignment is chosen. Alignment has to be a power of two. Patterns either don't contain any slashes, in which case files matching those patterns are matched in all directories, or start with a leading slash, in which case they are matched against absolute paths inside of the romfs filesystem (that is, as if you chrooted into the rom filesystem). .TP .BI -x \ pattern Allow to exclude files that match a pattern. It's useful to exclude CVS directories and backup files (ending in a '~'). .TP .BI -v Verbose operation, .B genromfs will print each file which is included in the image, along with its offset. .SH EXAMPLES .EX .B genromfs -d root -f /dev/fd0 -V 'Secret labs install disk' .EE All files in the .I root directory will be written to .B /dev/fd0 as a new romfs filesystem image. .EX .B genromfs -d root -f /dev/fd0 -A 2048,/.. -A '4096,*.boot' -a 512 -V 'Bootable floppy' .EE Generate the image and place file data of all regular files on 512 bytes boundaries or on 4K boundaries, if they have the .boot extension. Additionally, align the romfs header of the '..' entry in the root directory on a 2K boundary. Effectively, this makes sure that the romfs image uses the least possible space in the first 2048 bytes. .PP You can use the generated image (if you have the romfs module loaded, or compiled into the kernel) via: .EX .B mount -t romfs /dev/fd0 /mnt .EE .SH AUTHOR This manual page was initially written by Christoph Lameter , for the Debian GNU/Linux system. .SH SEE ALSO .BR mkfs (8), .BR mount (8), .BR mkisofs (8) genromfs-0.5.2/genromfs.c000064400000000000000000000465121213411524700153300ustar00rootroot00000000000000 /* Generate a ROMFS file system * * Copyright (C) 1997,1998 Janos Farkas * Copyright (C) 1998 Jakub Jelinek * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version * 2 of the License, or (at your option) any later version. * * Changes: * 2 Jan 1997 Initial release * 6 Aug 1997 Second release * 11 Sep 1998 Alignment support * 11 Jan 2001 special files of name @name,[cpub],major,minor */ /* * Some sparse words about how to use the program * * `genromfs' is the `mkfs' equivalent of the other filesystems, but * you must tell it from which directory you want to build the * filesystem. I.e. all files (and directories) in that directory * will be part of the newly created filesystem. Imagine it like * building a cd image, or creating an archive (tar, zip) file. * * Basic usage: * * # genromfs -d rescue/ -f /dev/fd0 * * All files in the rescue directory will be written to /dev/fd0 as a * new romfs filesystem image. You can mount it (if you have the * romfs module loaded, or compiled into the kernel) via: * * # mount -t romfs /dev/fd0 /mnt * * You can also set the volume name of the filesystem (which is not * currently used by the kernel) with the -V option. If you don't * specify one, genromfs will create a volume name of the form: 'rom * xxxxxxxx', where the x's represent the current time in a cryptic * form. * * All in all, it's as simple as: * * # genromfs -d rescue -f testimg.rom -V "Install disk" * * Other options: * -a N force all regular file data to be aligned on N bytes boundary * -A N,/name force named file(s) (shell globbing applied against the filenames) * to be aligned on N bytes boundary * In both cases, N must be a power of two. */ /* * Warning! Quite spaghetti code, it was born in a few hours. * Sorry about that. Feel free to contact me if you have problems. */ #include /* Userland pieces of the ANSI C standard I/O package */ #include /* Userland prototypes of the ANSI C std lib functions */ #include /* Userland prototypes of the string handling funcs */ #include /* Userland prototypes of the Unix std system calls */ #include /* Flag value for file handling functions */ #include #include #include #include #include #include /* Consts & structs defined by the internet system */ /* good old times without autoconf... */ #if defined(__linux__) || defined(__sun__) || defined(__CYGWIN__) #include #endif struct romfh { int32_t nextfh; int32_t spec; int32_t size; int32_t checksum; }; #define ROMFS_MAXFN 128 #define ROMFH_HRD 0 #define ROMFH_DIR 1 #define ROMFH_REG 2 #define ROMFH_LNK 3 #define ROMFH_BLK 4 #define ROMFH_CHR 5 #define ROMFH_SCK 6 #define ROMFH_FIF 7 #define ROMFH_EXEC 8 struct filenode; struct filehdr { /* leave h, t, tp at front, this is a linked list header */ struct filenode *head; struct filenode *tail; struct filenode *tailpred; /* end fragile header */ struct filenode *owner; }; struct filenode { /* leave n, p at front, this is a linked list item */ struct filenode *next; struct filenode *prev; /* end fragile header */ struct filenode *parent; struct filehdr dirlist; struct filenode *orig_link; char *name; char *realname; dev_t ondev; dev_t devnode; ino_t onino; mode_t modes; unsigned int offset; unsigned int size; unsigned int pad; }; struct aligns { struct aligns *next; int align; char pattern[0]; }; struct excludes { struct excludes *next; char pattern[0]; }; void initlist(struct filehdr *fh, struct filenode *owner) { fh->head = (struct filenode *)&fh->tail; fh->tail = NULL; fh->tailpred = (struct filenode *)&fh->head; fh->owner = owner; } int listisempty(struct filehdr *fh) { return fh->head == (struct filenode *)&fh->tail; } void append(struct filehdr *fh, struct filenode *n) { struct filenode *tail = (struct filenode *)&fh->tail; n->next = tail; n->prev = tail->prev; tail->prev = n; n->prev->next =n; n->parent = fh->owner; } void shownode(int level, struct filenode *node, FILE *f) { struct filenode *p; fprintf(f, "%-4d %-20s [0x%-8x, 0x%-8x] %07o, sz %5u, at 0x%-6x", level, node->name, (int)node->ondev, (int)node->onino, node->modes, node->size, node->offset); if (node->orig_link) fprintf(f, " [link to 0x%-6x]", node->orig_link->offset); fprintf(f, "\n"); p = node->dirlist.head; while (p->next) { shownode(level+1, p, f); p = p->next; } } /* Dumping functions */ static char bigbuf[4096]; static char fixbuf[512]; static int atoffs = 0; static int align = 16; struct aligns *alignlist = NULL; struct excludes *excludelist = NULL; int realbase; /* helper function to match an exclusion or align pattern */ int nodematch(char *pattern, struct filenode *node) { char *start = node->name; /* XXX: ugly realbase is global */ if (pattern[0] == '/') start = node->realname + realbase; return fnmatch(pattern,start,FNM_PATHNAME|FNM_PERIOD); } int findalign(struct filenode *node) { struct aligns *pa; int i; if (S_ISREG(node->modes)) i = align; else i = 16; for (pa = alignlist; pa; pa = pa->next) { if (pa->align > i) { if (!nodematch(pa->pattern,node)) i = pa->align; } } return i; } int romfs_checksum(void *data, int size) { int32_t sum, word, *ptr; sum = 0; ptr = data; size>>=2; while (size>0) { word = *ptr++; sum += ntohl(word); size--; } return sum; } void fixsum(struct romfh *ri, int size) { ri->checksum = 0; ri->checksum = htonl(-romfs_checksum(ri, size)); } void dumpdata(void *addr, int len, FILE *f) { int tocopy; struct romfh *ri; if (!len) return; if (atoffs >= 512) { if (fwrite(addr, len, 1, f) != 1) { fprintf(stderr, "write error: %m\n"); exit(1); } atoffs+=len; return; } tocopy = len < 512-atoffs ? len : 512-atoffs; memcpy(fixbuf+atoffs, addr, tocopy); atoffs+=tocopy; addr=(char*)addr+tocopy; len-=tocopy; if (atoffs==512) { ri = (struct romfh *)&fixbuf; fixsum(ri, atoffssize)?atoffs:ntohl(ri->size)); if (fwrite(fixbuf, atoffs, 1, f) != 1) { fprintf(stderr, "write error: %m\n"); exit(1); } } if (len) { if (fwrite(addr, len, 1, f) != 1) { fprintf(stderr, "write error: %m\n"); exit(1); } atoffs+=len; } } void dumpzero(int len, FILE *f) { memset(bigbuf, 0, len); dumpdata(bigbuf, len, f); } void dumpdataa(void *addr, int len, FILE *f) { dumpdata(addr, len, f); if ((len & 15) != 0) dumpzero(16-(len&15), f); } void dumpstring(char *str, FILE *f) { dumpdataa(str, strlen(str)+1, f); } void dumpri(struct romfh *ri, struct filenode *n, FILE *f) { int len; len = strlen(n->name)+1; memcpy(bigbuf, ri, sizeof(*ri)); memcpy(bigbuf+16, n->name, len); if (len&15) { memset(bigbuf+16+len, 0, 16-(len&15)); len += 16-(len&15); } len+=16; ri=(struct romfh *)bigbuf; if (n->offset) fixsum(ri, len); dumpdata(bigbuf, len, f); #if 0 fprintf(stderr, "RI: [at %06x] %08lx, %08lx, %08lx, %08lx [%s]\n", n->offset, ntohl(ri->nextfh), ntohl(ri->spec), ntohl(ri->size), ntohl(ri->checksum), n->name); #endif } void dumpnode(struct filenode *node, FILE *f) { struct romfh ri; struct filenode *p; ri.nextfh = 0; ri.spec = 0; ri.size = htonl(node->size); ri.checksum = htonl(0x55555555); if (node->pad) dumpzero(node->pad, f); if (node->next && node->next->next) ri.nextfh = htonl(node->next->offset); if ((node->modes & 0111) && (S_ISDIR(node->modes) || S_ISREG(node->modes))) ri.nextfh |= htonl(ROMFH_EXEC); if (node->orig_link) { ri.nextfh |= htonl(ROMFH_HRD); /* Don't allow hardlinks to convey attributes */ ri.nextfh &= ~htonl(ROMFH_EXEC); ri.spec = htonl(node->orig_link->offset); dumpri(&ri, node, f); } else if (S_ISDIR(node->modes)) { ri.nextfh |= htonl(ROMFH_DIR); if (listisempty(&node->dirlist)) { ri.spec = htonl(node->offset); } else { ri.spec = htonl(node->dirlist.head->offset); } dumpri(&ri, node, f); } else if (S_ISLNK(node->modes)) { ssize_t len; ri.nextfh |= htonl(ROMFH_LNK); dumpri(&ri, node, f); len = readlink(node->realname, bigbuf, sizeof(bigbuf) - 1); if (len > 0) { bigbuf[len] = '\0'; dumpdataa(bigbuf, len, f); } } else if (S_ISREG(node->modes)) { int offset, len, fd, max, avail; ri.nextfh |= htonl(ROMFH_REG); dumpri(&ri, node, f); offset = 0; max = node->size; /* XXX warn about size mismatch */ fd = open(node->realname, O_RDONLY #ifdef O_BINARY | O_BINARY #endif ); if (fd) { while(offset < max) { avail = max-offset < sizeof(bigbuf) ? max-offset : sizeof(bigbuf); len = read(fd, bigbuf, avail); if (len <= 0) break; dumpdata(bigbuf, len, f); offset+=len; } close(fd); } max = (max+15)&~15; while (offset < max) { avail = max-offset < sizeof(bigbuf) ? max-offset : sizeof(bigbuf); memset(bigbuf, 0, avail); dumpdata(bigbuf, avail, f); offset+=avail; } } else if (S_ISCHR(node->modes)) { ri.nextfh |= htonl(ROMFH_CHR); ri.spec = htonl(major(node->devnode)<<16|minor(node->devnode)); dumpri(&ri, node, f); } else if (S_ISBLK(node->modes)) { ri.nextfh |= htonl(ROMFH_BLK); ri.spec = htonl(major(node->devnode)<<16|minor(node->devnode)); dumpri(&ri, node, f); } else if (S_ISFIFO(node->modes)) { ri.nextfh |= htonl(ROMFH_FIF); dumpri(&ri, node, f); } else if (S_ISSOCK(node->modes)) { ri.nextfh |= htonl(ROMFH_SCK); dumpri(&ri, node, f); } p = node->dirlist.head; while (p->next) { dumpnode(p, f); p = p->next; } } void dumpall(struct filenode *node, int lastoff, FILE *f) { struct romfh ri; struct filenode *p; ri.nextfh = htonl(0x2d726f6d); ri.spec = htonl(0x3166732d); ri.size = htonl(lastoff); ri.checksum = htonl(0x55555555); dumpri(&ri, node, f); p = node->dirlist.head; while (p->next) { dumpnode(p, f); p = p->next; } /* Align the whole bunch to ROMBSIZE boundary */ if (lastoff&1023) dumpzero(1024-(lastoff&1023), f); } /* Node manipulating functions */ void freenode(struct filenode *n) { /* Rare, not yet */ } void setnode(struct filenode *n, dev_t dev, ino_t ino, mode_t um) { n->ondev = dev; n->onino = ino; n->modes = um; } struct filenode *newnode(const char *base, const char *name, int curroffset) { struct filenode *node; int len; char *str; node = malloc(sizeof (*node)); if (!node) { fprintf(stderr,"out of memory\n"); exit(1); } len = strlen(name); str = malloc(len+1); if (!str) { fprintf(stderr,"out of memory\n"); exit(1); } strcpy(str, name); node->name = str; if (!curroffset) { len = 1; name = "."; } if (strlen(base)) len++; str = malloc(strlen(base)+len+1); if (!str) { fprintf(stderr,"out of memory\n"); exit(1); } if (strlen(base)) { sprintf(str, "%s/%s", base, name); } else { strcpy(str, name); } node->realname = str; node->next = node->prev = NULL; node->parent = NULL; initlist(&node->dirlist, node); node->ondev = -1; node->onino = -1; node->modes = -1; node->size = 0; node->devnode = 0; node->orig_link = NULL; node->offset = curroffset; node->pad = 0; return node; } struct filenode *findnode(struct filenode *node, dev_t dev, ino_t ino) { struct filenode *found, *p; /* scan the whole tree */ if (node->ondev == dev && node->onino == ino) return node; p = node->dirlist.head; while (p->next) { found = findnode(p, dev, ino); if (found) return found; p = p->next; } return NULL; } #define ALIGNUP16(x) (((x)+15)&~15) int spaceneeded(struct filenode *node) { return 16 + ALIGNUP16(strlen(node->name)+1) + ALIGNUP16(node->size); } int alignnode(struct filenode *node, int curroffset, int extraspace) { int align = findalign(node), d; d = ((curroffset + extraspace) & (align - 1)); if (d) { align -= d; curroffset += align; node->offset += align; node->pad = align; } return curroffset; } int processdir(int level, const char *base, const char *dirname, struct stat *sb, struct filenode *dir, struct filenode *root, int curroffset) { DIR *dirfd; struct dirent *dp; struct filenode *n, *link; struct excludes *pe; if (level <= 1) { /* Ok, to make sure . and .. are handled correctly * we add them first. Note also that we alloc them * first to get to know the real name */ link = newnode(base, ".", curroffset); if (!lstat(link->realname, sb)) { setnode(link, sb->st_dev, sb->st_ino, sb->st_mode); append(&dir->dirlist, link); /* special case for root node - '..'s in subdirs should link to * '.' of root node, not root node itself. */ dir->dirlist.owner = link; curroffset = alignnode(link, curroffset, 0) + spaceneeded(link); n = newnode(base, "..", curroffset); if (!lstat(n->realname, sb)) { setnode(n, sb->st_dev, sb->st_ino, sb->st_mode); append(&dir->dirlist, n); n->orig_link = link; curroffset = alignnode(n, curroffset, 0) + spaceneeded(n); } } } dirfd = opendir(dir->realname); if (dirfd == NULL) { perror(dir->realname); } while(dirfd && (dp = readdir(dirfd))) { /* don't process main . and .. twice */ if (level <= 1 && (strcmp(dp->d_name, ".") == 0 || strcmp(dp->d_name, "..") == 0)) continue; n = newnode(base, dp->d_name, curroffset); /* Process exclude list. */ for (pe = excludelist; pe; pe = pe->next) { if (!nodematch(pe->pattern, n)) { freenode(n); break; } } if (pe) continue; if (lstat(n->realname, sb)) { fprintf(stderr, "ignoring '%s' (lstat failed)\n", n->realname); freenode(n); continue; } /* Handle special names */ if ( n->name[0] == '@' ) { if (S_ISLNK(sb->st_mode)) { ssize_t len; /* this is a link to follow at build time */ n->name = n->name + 1; /* strip off the leading @ */ len = readlink(n->realname, bigbuf, sizeof(bigbuf) - 1); if (len <= 0) { fprintf(stderr, "ignoring '%s' (readlink failed)\n", n->realname); freenode(n); continue; } bigbuf[len] = '\0'; n->realname = strdup(bigbuf); if (lstat(n->realname, sb)) { fprintf(stderr, "ignoring '%s' (lstat failed)\n", n->realname); freenode(n); continue; } } else if (S_ISREG(sb->st_mode) && sb->st_size == 0) { /* * special file @name,[bcp..],major,minor */ char devname[32]; char type; int major; int minor; if (sscanf(n->name, "@%[a-zA-Z0-9_+-],%c,%d,%d", devname, &type, &major, &minor) == 4 ) { strcpy(n->name, devname); sb->st_rdev = makedev(major, minor); sb->st_mode &= ~S_IFMT; switch (type) { case 'c': case 'u': sb->st_mode |= S_IFCHR; break; case 'b': sb->st_mode |= S_IFBLK; break; case 'p': sb->st_mode |= S_IFIFO; break; default: fprintf(stderr, "Invalid special device type '%c' " "for file %s\n", type, n->realname); freenode(n); continue; } } } } setnode(n, sb->st_dev, sb->st_ino, sb->st_mode); /* Skip unreadable files/dirs */ if (!S_ISLNK(n->modes) && access(n->realname, R_OK)) { fprintf(stderr, "ignoring '%s' (access failed)\n", n->realname); freenode(n); continue; } /* Look up old links */ if ( strcmp(n->name, ".") == 0 ) { append(&dir->dirlist, n); link = n->parent; } else if (strcmp(n->name, "..") == 0) { append(&dir->dirlist, n); link = n->parent->parent; } else { link = findnode(root, n->ondev, n->onino); append(&dir->dirlist, n); } if (link) { n->orig_link = link; curroffset = alignnode(n, curroffset, 0) + spaceneeded(n); continue; } if (S_ISREG(sb->st_mode)) { curroffset = alignnode(n, curroffset, spaceneeded(n)); n->size = sb->st_size; } else curroffset = alignnode(n, curroffset, 0); if (S_ISLNK(sb->st_mode)) { n->size = sb->st_size; } curroffset += spaceneeded(n); if (S_ISCHR(sb->st_mode) || S_ISBLK(sb->st_mode)) { n->devnode = sb->st_rdev; } if (S_ISDIR(sb->st_mode)) { if (!strcmp(n->name, "..")) { curroffset = processdir(level+1, dir->realname, dp->d_name, sb, dir, root, curroffset); } else { curroffset = processdir(level+1, n->realname, dp->d_name, sb, n, root, curroffset); } } } if (dirfd) closedir(dirfd); return curroffset; } void showhelp(const char *argv0) { printf("genromfs %s\n",VERSION); printf("Usage: %s [OPTIONS] -f IMAGE\n",argv0); printf("Create a romfs filesystem image from a directory\n"); printf("\n"); printf(" -f IMAGE Output the image into this file\n"); printf(" -d DIRECTORY Use this directory as source\n"); printf(" -v (Too) verbose operation\n"); printf(" -V VOLUME Use the specified volume name\n"); printf(" -a ALIGN Align regular file data to ALIGN bytes\n"); printf(" -A ALIGN,PATTERN Align all objects matching pattern to at least ALIGN bytes\n"); printf(" -x PATTERN Exclude all objects matching pattern\n"); printf(" -h Show this help\n"); printf("\n"); printf("Report bugs to chexum@shadow.banki.hu\n"); } int main(int argc, char *argv[]) { int c; char *dir = "."; char *outf = NULL; char *volname = NULL; int verbose=0; char buf[256]; struct filenode *root; struct stat sb; int lastoff; int i; char *p; struct aligns *pa, *pa2; struct excludes *pe, *pe2; FILE *f; while ((c = getopt(argc, argv, "V:vd:f:ha:A:x:")) != EOF) { switch(c) { case 'd': dir = optarg; break; case 'f': outf = optarg; break; case 'V': volname = optarg; break; case 'v': verbose = 1; break; case 'h': showhelp(argv[0]); exit(0); case 'a': align = strtoul(optarg, NULL, 0); if (align < 16 || (align & (align - 1))) { fprintf(stderr, "Align has to be at least 16 bytes and a power of two\n"); exit(1); } break; case 'A': i = strtoul(optarg, &p, 0); if (i < 16 || (i & (i - 1))) { fprintf(stderr, "Align has to be at least 16 bytes and a power of two\n"); exit(1); } if (*p != ',' || !p[1]) { fprintf(stderr, "-A takes N,PATTERN format of argument, where N is a number\n"); exit(1); } /* strlen(p+1) + 1 eq strlen(p) */ pa = (struct aligns *)malloc(sizeof(*pa) + strlen(p)); pa->align = i; pa->next = NULL; strcpy(pa->pattern, p + 1); if (!alignlist) alignlist = pa; else { for (pa2 = alignlist; pa2->next; pa2 = pa2->next) ; pa2->next = pa; } break; case 'x': pe = (struct excludes *)malloc(sizeof(*pe) + strlen(optarg) + 1); pe->next = NULL; strcpy(pe->pattern, optarg); if (!excludelist) excludelist = pe; else { for (pe2 = excludelist; pe2->next; pe2 = pe2->next) ; pe2->next = pe; } break; default: exit(1); } } if (!volname) { sprintf(buf, "rom %08lx", time(NULL)); volname = buf; } if (!outf) { fprintf(stderr, "%s: you must specify the destination file\n", argv[0]); fprintf(stderr, "Try `%s -h' for more information\n",argv[0]); exit(1); } if (strcmp(outf, "-") == 0) { f = fdopen(1,"wb"); } else f = fopen(outf, "wb"); if (!f) { perror(outf); exit(1); } realbase = strlen(dir); root = newnode(dir, volname, 0); root->parent = root; lastoff = processdir (1, dir, dir, &sb, root, root, spaceneeded(root)); if (verbose) shownode(0, root, stderr); dumpall(root, lastoff, f); exit(0); } genromfs-0.5.2/genromfs.lsm000064400000000000000000000012301213411524700156650ustar00rootroot00000000000000Begin3 Title: genromfs Version: 0.5.1 Entered-date: 22 Jan 2002 Description: This is the mkfs equivalent for romfs filesystem. You need it to build such a filesystem. romfs is a small, read-only filesystem intended for installation/rescue disks or embedded applications. Keywords: small read-only filesystem rom eprom embedded romable install rescue mkfs romfs Author: chexum@shadow.banki.hu (Janos Farkas) Maintained-by: chexum@shadow.banki.hu (Janos Farkas) Primary-site: ftp.banki.hu /pub/Linux/local 20kB genromfs-0.5.1.tar.gz Alternate-site: sunsite.unc.edu /pub/Linux/system/recovery/ Platforms: Linux 2.0 or later, gcc Copying-policy: GPL End genromfs-0.5.2/genromfs.spec000064400000000000000000000053331213411524700160340ustar00rootroot00000000000000Name: genromfs Version: 0.5.2 Release: alt0.3 Summary: Utility for creating romfs filesystems License: GPLv2+ Group: System/Kernel and hardware Url: http://romfs.sourceforge.net Source: http://prdownloads.sourceforge.net/romfs/genromfs-%version.tar Provides: /bin/genromfs %description Genromfs is a tool for creating romfs filesystems, which are lightweight, read-only filesystems supported by the Linux kernel. Romfs filesystems are mainly used for the initial RAM disks used during installation. %prep %setup %build %def_enable Werror make CFLAGS="%optflags $(getconf LFS_CFLAGS) -DVERSION=\\\"%version\\\"" \ LDFLAGS="%optflags" %install install -pDm755 genromfs %buildroot/bin/genromfs install -pDm644 genromfs.8 %buildroot%_man8dir/genromfs.8 mkdir -p %buildroot%_bindir ln -r -s %buildroot/bin/genromfs %buildroot%_bindir/ %files /bin/* %_bindir/* %_man8dir/* %doc NEWS *.txt genrommkdev %changelog * Fri Apr 19 2013 Dmitry V. Levin 0.5.2-alt0.3 - Built with LFS support enabled. * Mon Oct 16 2006 Dmitry V. Levin 0.5.2-alt0.2 - Fixed build with -D_FORTIFY_SOURCE=2 -Werror. * Mon Oct 16 2006 Dmitry V. Levin 0.5.2-alt0.1 - Updated to cvs snapshot 20050818. * Thu Sep 22 2005 Dmitry V. Levin 0.5.1-alt5 - Converted absolute symlink into relative. * Mon Oct 25 2004 Dmitry V. Levin 0.5.1-alt4 - Specfile cleanup. * Thu Oct 24 2002 Konstantin Volckov 0.5.1-alt3 - Rebuilt in new environment * Mon Aug 19 2002 Konstantin Volckov 0.5.1-alt2 - Moved genromfs to /bin - Added Provides: /bin/genromfs (Required by new mkinitrd) * Thu Mar 07 2002 Dmitry V. Levin 0.5.1-alt1 - 0.5.1 - Added more docs. - Fixed Url and Source tags. * Sun Feb 10 2002 Rider 0.5-alt1 - Russian summary - URL tag - 0.5 * Wed Jan 17 2001 Dmitry V. Levin 0.3-ipl10mdk - RE adaptions. * Thu Jul 20 2000 Thierry Vignaud 0.3-10mdk - BM, macros * Sat Jun 10 2000 Etienne Faure 0.3-9mdk -rebuild on kenobi * Wed Apr 05 2000 John Buswell 0.3-8mdk - fixed vendor tag * Thu Mar 30 2000 John Buswell 0.3-7mdk - fixed groups - spec helper * Wed Dec 01 1999 Chmouel Boudjnah - Add a defattr. * Tue May 11 1999 Bernhard Rosenkraenzer - Mandrake adaptions - handle RPM_OPT_FLAGS * Sun Mar 21 1999 Cristian Gafton - auto rebuild in the new build environment (release 4) * Thu Nov 5 1998 Jeff Johnson - import from ultrapenguin 1.1. * Thu Oct 30 1998 Jakub Jelinek - new package genromfs-0.5.2/genrommkdev000075500000000000000000000006371213411524700156060ustar00rootroot00000000000000#!/bin/sh # this is a sample device list file converter # $ cat devices.lst # /dev/hda1 b 3 1 # /dev/tty1 c 4 1 # $ genrommkdev