Good Afternoon Golfgeneers.
This is reasonably long and detailed question. Given what it was asking, it needed to be. If you have any questions, please ask them. If there is anything that isn't clear, please alert me to it so I can fix it. This is probably on the tougher side of codegolf.
We are building a lightweight computer, and we need the lightest weight file system possible. The shortest code will be chosen.
We are providing a cutting edge 65536 byte hard drive. For the sake of this prototype, it will be a direct image file, which your program can assume exists, and is in whichever location suits you - ie, a binary file representing the entire hard disk. You may assume that this image is already 'formatted' - ie. if your program relies on something being in the file to work, it can be. If you require the initial empty state to be something other then all-zeros, please state what it is.
There is no memory limit as to RAM used by your application.
The input and output commands will require an interface to the actual hard drive. Like the disk image, your program can assume that the file for input exists, and is wherever you want it to be. Likewise, your program can output wherever is convenient. It must however close the file after executing the input or output command.
You are not being provided with a format which you must use for the disc image - you are free to develop your own. It must be capable of storing up to 248 files. Any file greater then 256 bytes can count as a new file for the sake of this limit for every 256 bytes or part thereof. A file can be up to 63488 bytes. Basically - it must be as capable as a hard drive with 248 sectors of 256 bytes each.
The reasoning behind these seemingly sizes is to give you 2048 bytes of 'administration' - to store details of the files. Each file/folder must be accessible by a name of 4 alphanumeric characters, which may be case sensitive or insensitive as per your preference. If your program supports names of 4 or less characters, then there is bonus of a 0.95 multiplier.
Your program must accept, via stdin, the following commands. Parameters will be separated by a space. The command will be terminated by a newline.
- L - List the names to stdout of all the current files and their sizes in bytes, separated by newlines.
- C a b - Copy file a to new file b.
- D a - Delete file a
- R a b - Renames file a to new name b
- I a - Adds the input file (see note above) as file a
- O a - Outputs file a to the output file
The following errors may be reported to STDOUT or STDERR as valid reasons for a command to fail to execute. You may choose to only print ERR# where # is the number of the error:
- 1 - File doesn't exist
- 2 - File already exists
- 3 - Out of space*
* Note that your program can not issue this just because it is out of continuous space. If you still have sectors available, you must defragment the disk to make it work.
A folder system is optional - however, will net a bonus of a 0.8 multiplier to your score. If it supports more then 1 level of directory, it will net a bonus of a 0.7 multiplier (not in addition to the 0.8). For the bonus, you must have
- L, R, C and D only work within the current directory. L must list folders in the current directory, as well as the files.
- New command M a b moves file a to folder b. If b is '.', moves file to the parent director
- New command G a goes to folder a. If a is '.', goes to parent folder
- R must also rename folders
- D must also delete folders, and any files/folders within them
- C must also copy folders, and any files/folders within them
The following additional errors may be reported to STDOUT or STDERR as valid reasons for a command to fail to execute.
- 4 - Folder doesn't exist
- 5 - File, not folder required - where, I and O require file names, and a folder was given
Your score is:
- The size, in bytes, of your source code
- 0.95 if you support names of 4, or less characters
- 0.8 if you support a single level of folders
- 0.7 if you support multiple levels of folders
- 0.95 if you support commands (not necessarily file names) in lower or uppercase