Subset 0 To complete subset 0, you need to implement code that can • print a list of the contents of an egg, and • print
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am
Subset 0 To complete subset 0, you need to implement code that can • print a list of the contents of an egg, and • print
HINT: chicken_main.c calls the function list_egg in chicken.c when either of the - 1 or-L options are specified on the command line Add code to list_egg in chicken.c. Use fopen to open the egg file. Use fgetc to read bytes Make sure you understand the egglet format specification below Use C bitwise operations such as <<& and to combine bytes into integers. Think carefully about the functions you can construct to avoid repeated code. Review print_borts_file.c from our week 8 tutorial and print_bytes.c from our week 8 lab. fseek can be used to skip over parts of the egg file, but you can also use a loop and fgetc NOTE: The order you list files is the order they appear in the egg. egg files do not necessarily end with egg. This has been done with the provided example files purely as a convenience Hint: use a format like "slu" to print the file size.
name The egg and egglet format eggs must follow exactly the format produced by the reference implementation An egg consists of a sequence of one or more egglets. Each egglet contains the information about one file or directory. The first byte of an egg file is the first byte of the first egglet. That egglet is immediately followed by either another egglet, or by the end of the egg file. length type description magic 1.B unsigned, 8-bit. byte 0 in every egglet must be 0x63 (ASCII C") number little-endian egglet format 18 unsigned, 8-bit byte 1 in every egglet must be one of Ox36, 0x37, 0x38 little-endian (ASCII '6', '7', '8') permissions 10B characters bytes 2–11 are the type and permissions as a 's-like character array; eg. "-rwxr-xr-x" pathname unsigned, 16-bit, bytes 12—13 are an unsigned 2-byte (16-bit) little- length little-endian endian integer, giving the length of pathname pathname-length characters the filename of the object in this egglet. content unsigned, 48-bit, the next bytes are an unsigned 6-byte (48-bit) little length little-endian endian integer giving the length of the file that was encoded to give content content-length for 8-bit bytes the data of the object in this egglet. format, see below for other formats hash 1B unsigned, 8-bit, the last byte of an egglet is an egglet-hash of all bytes little-endian of this egglet except this byte. 2 100 6B
9 10 11 12 13 #include <stdio.h> #include <stdint.h> #include <stdlib.h> #include <assert.h> #include <sys/types.h> #include <sys/stat.h> #include <unistd.h> 14 15 16 17 #include "chicken.h" 18 19 20 // ADD ANY extra #defines HERE 21 22 23 24 25 // ADD YOUR FUNCTION PROTOTYPES HERE 26 27 28 29 30 // print the files & directories stored in egg pathname (subset o) // // if long_listing is non-zero then file/directory permissions, formats & sizes are also prin // // if long_listing is non-zero then egglet hashes should also be checked (subset 1) 31 void list_egg(char *egg_pathname, int long_listing) { 32 33 34 // REPLACE THIS CODE WITH YOUR CODE 35 printf("list_egg called to list egg: %s'\n", egg_pathname); 36 37 38 39 if (long_listing) { printf("long listing with permissions & sizes specified\n"); } 40 41 }