Giter Site home page Giter Site logo

my_tar's Introduction

My tar

A Naive implementation of the legendary Tape Archiver.

Build

While in the project root directory, run make to build the binary:

$ make

Run clean to remove /bin/my_tar and .o artifacts.

$ make clean

Usage

$ .bin/my_tar [-cutx] [-f file.tar] file_to_archive ...

Options

  • -cf file.tar file_to_archive ... : Archive a file(s) or directory. Multiple files is also possible.
  • -uf file.tar file_to_archive ... : Updates archive with new file(s).
  • -tf file.tar : Lists files in the tape archive.
  • -xf file.tar : Extracts all files in a archive. Existing files in the disk will be overwritten.

When -cf directories, My tar will archive all files within the directory. Sub directories will be tar'ed as directories but their contents will not be included.

Dev options

Option -d <filename> for debug. While in debug mode, the program will skip archiving and print out a ASCII representation of the header produced from <filename>. Example:

./bin/my_tar -d <filename>

example output:

 Field: chksum -- length: 8  -- offset: 148
 |  0  |  1  |  3  |  2  |  0  |  0  |     |  _  |
    
 --
    
 Field: magic -- length: 6  -- offset: 257
 |  u  |  s  |  t  |  a  |  r  |  _  |
    
  (...)

where

  • | | represents a memory block of 1 byte. And empty block is an <space> char.
  • | _ | is an empty block
  • --- is a divider between fields.
  • field is the name of the field
  • length is the length of a field
  • offset is the memory offset of a field in within the header 512 bytes block and

Testing

There is a very basic script to help test some of this programs functionalities. First, make sure you set the permissions accordingly:

$ chmod u+x bin/test.sh

Run test:

$ ./bin/test.sh 

This command will run the program in all its available options consecutively. Appending with -u is not tested in this mode but using the --append option. The script will test My Tar against all file types in the test_files folder. This repo includes fifo, symlink, hardlink, regular and directory file types in test_files.

The script will clean up after itself removing all files.

The script will compile with make and make clean before/after attempting to run the program.

Other available options:

$ ./bin/test.sh --cat file_to_archive ...

--cat will archive a file in both my_tar and the original tar and cat their contents for comparisson. OSX users must install gtar to run the script. Darwin uses bdstar as its defaulttarand gtar ensures we get a consitent tar format.

$ ./bin/test.sh -d file_to_header

Runs in debug mode as described above.

$ ./bin/test.sh --append tar_file_to_apend.tar file_to_append

Use --append for testing th =uf option. Remember that you must pass in an existing file in the archive in other to append using -u.

If you have valgrind and want memory check:

$ ./bin/test.sh --append tar_file_to_apend.tar file_to_append

my_tar's People

Contributors

khalilmasri avatar pbotsaris avatar

Watchers

 avatar

my_tar's Issues

Link Files

/* [> Number of hard links <] */
my_itoa(header->linkname, stats.st_nlink, DECIMAL);

stats.st_nlink will return the number of links a file has not the name of the link or linkname.

We probably need to check if the file is a link then use lstat() to gather the link information.

prefix should only be the exceeding chars

void add_name(header_t *header, char *path)
{
/* name is prefix if more than 100 char */
size_t path_len = strlen(path);
if(path_len < MAX_NAME_SIZE){
strcpy(header->name, path);
header->prefix[0] = '\0';
}
else if(path_len < MAX_NAME_SIZE * 2){
strncpy(header->prefix, path, MAX_NAME_SIZE);
header->prefix[MAX_NAME_SIZE - 1] = '\0';
strncpy(header->name, &path[MAX_NAME_SIZE - 1], MAX_NAME_SIZE);
header->name[MAX_NAME_SIZE - 1] = '\0';
}
else
printf("%s", EXC_NAME_SIZE);

Move only the exceeding chars to prefix

Header

Merge all headers together

File size must be 0 when link

/* [> Total size, in bytes <] */
my_itoa(header->size, stats.st_size, DECIMAL);

According to the tar manual, the size should be specified as 0 if the file in question is a link.

Quoting from the manual:

"The size field is the size of the file in bytes; linked files are archived with this field specified as zero."

enum bool_t with swapped values

@khalilmasri

my_tar/src/my_tar.h

Lines 74 to 79 in 0197fe7

typedef enum
{
TRUE,
FALSE,
ERRORF
} bool_f;

Enum members are just int values so the first item is 0, the second is 1, the third is 2, and so on. On the other hand, TRUE is generally represented by 1 while FALSE by 0. However, if we have TRUE and FALSE declared in the enum bool_t is this order then TRUE = 0 and FALSE = 1.

Try this and check it out:

bool_t bolean = FALSE;
Try printf("%i",  bolean);
//  -> 1

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.