Main Page   Alphabetical List   Compound List   File List   Compound Members   File Members  

tarfs_tar.c File Reference

#include "tarfs_tar.h"
#include "tarfs_util.h"
#include "tarfs_common.h"
#include <linux/slab.h>

Go to the source code of this file.

Compounds

struct  posix_header

Defines

#define TMAGIC   "ustar"
#define TMAGLEN   6
#define TVERSION   "00"
#define TVERSLEN   2
#define REGTYPE   '0'
#define AREGTYPE   '\0'
#define LNKTYPE   '1'
#define SYMTYPE   '2'
#define CHRTYPE   '3'
#define BLKTYPE   '4'
#define DIRTYPE   '5'
#define FIFOTYPE   '6'
#define CONTTYPE   '7'
#define TSUID   04000
#define TSGID   02000
#define TSVTX   01000
#define TUREAD   00400
#define TUWRITE   00200
#define TUEXEC   00100
#define TGREAD   00040
#define TGWRITE   00020
#define TGEXEC   00010
#define TOREAD   00004
#define TOWRITE   00002
#define TOEXEC   00001
#define OFFSET_BY_INO(X)   ((X) - 1)
 For given inode number, returns offset of its header block.


Typedefs

typedef posix_header posix_header

Functions

int is_tar (posix_header *blok)
 Controls if given block is a valid tar block.

int tar_quick_validation (struct super_block *s)
 Performs quick valiadtion of tar.

unsigned long get_root_ino_pom (posix_header *blok)
 Helper routine for tar_get_root_inode.

unsigned long tar_get_root_ino (struct super_block *s)
 Returns number of root inode.

unsigned long tar_length (struct super_block *s)
 Returns number of blocks in tar.

int pom_read_name (struct super_block *s, char **file_name, unsigned long size, unsigned long offset)
 Helper routine, reads filename of file starting at given position.

unsigned long offset_by_name (struct super_block *s, char *name)
 Searches for given file in tar.

unsigned long offset_by_name2 (struct super_block *s, unsigned long pos, char *name, unsigned int fsize)
 Does the same thing as offset_by_name, with some changes.

unsigned long skip_blocks (struct super_block *s, unsigned long whence)
 Returns position, where real datablock is stored.

int get_type (posix_header *blok, unsigned *type)
 Converts from types of tar inodes to types defined in fs.h.

int tar_fill_inode (struct super_block *s, struct inode *inode, int *rdev)
 Reads inode from tar.

unsigned long find_nolink (struct super_block *s, unsigned long ino)
 Returns physical position of file of given inode.

char * symlinkname (struct super_block *s, unsigned long ino)
 reads symlinks target

unsigned long tar_read_page (struct super_block *s, struct inode *inode, loff_t offset, void *buffer)
 Fills buffer with data from given inode.

unsigned long tar_readdir (struct file *filp, void *dirent, filldir_t filldir)
 Reads directory entries.

unsigned long tar_lookup (struct super_block *s, unsigned long ino, const char *fname, unsigned int fsize)
 Searches for file in given directory.


Detailed Description

Contains routines working with tar format With a little work it can be used in other programs reading tar files

Author:
Jaroslav Drazan <jaroslavdrazan@seznam.cz>

Petr Cermak <xgxg@seznam.cz>

Definition in file tarfs_tar.c.


Define Documentation

#define AREGTYPE   '\0'
 

regular file

Definition at line 56 of file tarfs_tar.c.

Referenced by find_nolink(), get_type(), offset_by_name(), offset_by_name2(), skip_blocks(), tar_fill_inode(), tar_get_root_ino(), and tar_readdir().

#define BLKTYPE   '4'
 

block special

Definition at line 60 of file tarfs_tar.c.

Referenced by find_nolink(), get_type(), offset_by_name(), offset_by_name2(), skip_blocks(), tar_fill_inode(), tar_get_root_ino(), and tar_readdir().

#define CHRTYPE   '3'
 

character special

Definition at line 59 of file tarfs_tar.c.

Referenced by find_nolink(), get_type(), offset_by_name(), offset_by_name2(), skip_blocks(), tar_fill_inode(), tar_get_root_ino(), and tar_readdir().

#define CONTTYPE   '7'
 

reserved

Definition at line 63 of file tarfs_tar.c.

#define DIRTYPE   '5'
 

directory

Definition at line 61 of file tarfs_tar.c.

Referenced by find_nolink(), get_root_ino_pom(), get_type(), offset_by_name(), offset_by_name2(), skip_blocks(), tar_fill_inode(), tar_get_root_ino(), tar_lookup(), and tar_readdir().

#define FIFOTYPE   '6'
 

FIFO special

Definition at line 62 of file tarfs_tar.c.

Referenced by find_nolink(), get_type(), offset_by_name(), offset_by_name2(), skip_blocks(), tar_fill_inode(), tar_get_root_ino(), and tar_readdir().

#define LNKTYPE   '1'
 

link

Definition at line 57 of file tarfs_tar.c.

Referenced by find_nolink(), get_type(), offset_by_name(), offset_by_name2(), skip_blocks(), tar_fill_inode(), tar_get_root_ino(), and tar_readdir().

#define OFFSET_BY_INO  )     ((X) - 1)
 

For given inode number, returns offset of its header block.

Parameters:
X Inode number
Returns:
Offset of header block

Definition at line 86 of file tarfs_tar.c.

Referenced by symlinkname(), tar_fill_inode(), tar_lookup(), and tar_readdir().

#define REGTYPE   '0'
 

regular file

Definition at line 55 of file tarfs_tar.c.

Referenced by find_nolink(), get_type(), offset_by_name(), offset_by_name2(), skip_blocks(), tar_fill_inode(), tar_get_root_ino(), and tar_readdir().

#define SYMTYPE   '2'
 

reserved

Definition at line 58 of file tarfs_tar.c.

Referenced by find_nolink(), get_type(), offset_by_name(), offset_by_name2(), skip_blocks(), symlinkname(), tar_fill_inode(), tar_get_root_ino(), and tar_readdir().

#define TGEXEC   00010
 

execute/search by group

Definition at line 75 of file tarfs_tar.c.

#define TGREAD   00040
 

read by group

Definition at line 73 of file tarfs_tar.c.

#define TGWRITE   00020
 

write by group

Definition at line 74 of file tarfs_tar.c.

#define TMAGIC   "ustar"
 

ustar and a null

Definition at line 49 of file tarfs_tar.c.

Referenced by is_tar().

#define TMAGLEN   6
 

Definition at line 50 of file tarfs_tar.c.

Referenced by is_tar().

#define TOEXEC   00001
 

execute by other

Definition at line 78 of file tarfs_tar.c.

#define TOREAD   00004
 

read by other

Definition at line 76 of file tarfs_tar.c.

#define TOWRITE   00002
 

write by other

Definition at line 77 of file tarfs_tar.c.

#define TSGID   02000
 

set GID on execution

Definition at line 67 of file tarfs_tar.c.

#define TSUID   04000
 

set UID on execution

Definition at line 66 of file tarfs_tar.c.

#define TSVTX   01000
 

reserved

Definition at line 68 of file tarfs_tar.c.

#define TUEXEC   00100
 

execute/search by owner

Definition at line 72 of file tarfs_tar.c.

#define TUREAD   00400
 

read by owner

Definition at line 70 of file tarfs_tar.c.

#define TUWRITE   00200
 

write by owner

Definition at line 71 of file tarfs_tar.c.

#define TVERSION   "00"
 

00 and no null

Definition at line 51 of file tarfs_tar.c.

#define TVERSLEN   2
 

Definition at line 52 of file tarfs_tar.c.


Typedef Documentation

typedef struct posix_header posix_header
 

One block of tar


Function Documentation

unsigned long find_nolink struct super_block *  s,
unsigned long  ino
 

Returns physical position of file of given inode.

If hardlink, it jumps to the linked position

Parameters:
s Super block structure needed to perform i/o operations
ino Inode number of file to be found
Returns:
Position of searched file, TARFS_EVAL in case of error

Definition at line 915 of file tarfs_tar.c.

References AREGTYPE, BLKTYPE, CHRTYPE, DIRTYPE, FIFOTYPE, is_tar(), posix_header::linkname, LNKTYPE, oct_to_dec(), offset_by_name(), pom_read_name(), read_block(), REGTYPE, short_name_size(), posix_header::size, skip_blocks(), SYMTYPE, TARFS_EVAL, TARFS_NUMLENGTH, and posix_header::typeflag.

Referenced by tar_read_page().

unsigned long get_root_ino_pom posix_header blok  ) 
 

Helper routine for tar_get_root_inode.

Returns:
Root inode number, TARFS_EVAL if any error occures

Definition at line 166 of file tarfs_tar.c.

References DIRTYPE, posix_header::name, TARFS_EVAL, TARFS_ROOT_INO, and posix_header::typeflag.

Referenced by tar_get_root_ino().

int get_type posix_header blok,
unsigned *  type
 

Converts from types of tar inodes to types defined in fs.h.

Parameters:
blok A tar block to be examined
type [out] Type of block
Returns:
0 - OK, -1 otherwise

Definition at line 690 of file tarfs_tar.c.

References AREGTYPE, BLKTYPE, CHRTYPE, DIRTYPE, FIFOTYPE, LNKTYPE, REGTYPE, SYMTYPE, and posix_header::typeflag.

Referenced by tar_readdir().

int is_tar posix_header blok  ) 
 

Controls if given block is a valid tar block.

Controls the magic and checksum fields

Parameters:
blok Block to be checked
Returns:
1 - OK, 0 - error

Definition at line 96 of file tarfs_tar.c.

References posix_header::chksum, posix_header::magic, oct_to_dec(), TMAGIC, and TMAGLEN.

Referenced by find_nolink(), offset_by_name(), offset_by_name2(), skip_blocks(), symlinkname(), tar_fill_inode(), tar_get_root_ino(), tar_length(), tar_lookup(), tar_quick_validation(), and tar_readdir().

unsigned long offset_by_name struct super_block *  s,
char *  name
 

Searches for given file in tar.

Parameters:
s Super block structure needed to perform i/o operations
name Name of file to be found (zero-terminated)
See also:
offset_by_name2
Returns:
Position, where desired file is located, TARFS_EVAL if any error occures

Definition at line 352 of file tarfs_tar.c.

References AREGTYPE, BLKTYPE, CHRTYPE, DIRTYPE, FIFOTYPE, hcc(), is_tar(), LNKTYPE, name_comparator(), oct_to_dec(), pom_read_name(), read_block(), REGTYPE, posix_header::size, SYMTYPE, TARFS_BLKSIZE, TARFS_EVAL, TARFS_NUMLENGTH, and posix_header::typeflag.

Referenced by find_nolink(), and tar_fill_inode().

unsigned long offset_by_name2 struct super_block *  s,
unsigned long  pos,
char *  name,
unsigned int  fsize
 

Does the same thing as offset_by_name, with some changes.

This function searches from the position pos and takes a bit different parameters

Parameters:
s Super block structure needed to perform i/o operations
pos Position where to start search from
name Name of file to be found (doesn't have to be zero-terminated)
fsize Length of name
See also:
offset_by_name
Returns:
Position, where desired file is located, TARFS_EVAL if any error occures

Definition at line 492 of file tarfs_tar.c.

References AREGTYPE, BLKTYPE, CHRTYPE, DIRTYPE, FIFOTYPE, hcc(), is_tar(), LNKTYPE, posix_header::name, name_comparator2(), oct_to_dec(), pom_read_name(), read_block(), REGTYPE, short_name_size(), posix_header::size, SYMTYPE, TARFS_BLKSIZE, TARFS_EVAL, TARFS_NUMLENGTH, and posix_header::typeflag.

Referenced by tar_lookup().

int pom_read_name struct super_block *  s,
char **  file_name,
unsigned long  size,
unsigned long  offset
 

Helper routine, reads filename of file starting at given position.

Parameters:
s Super block structure needed to perform i/o operations
file_name [out] Filename of file starting at offset. (Allocated)
size Size of filename buffer
offset Where to start reading from
Returns:
1 - OK, 0 - Error

Definition at line 301 of file tarfs_tar.c.

References hcc(), read_block(), and TARFS_BLKSIZE.

Referenced by find_nolink(), offset_by_name(), offset_by_name2(), symlinkname(), tar_fill_inode(), tar_lookup(), and tar_readdir().

unsigned long skip_blocks struct super_block *  s,
unsigned long  whence
 

Returns position, where real datablock is stored.

This function has meaning only for skipping blocks with type 'K' or 'L'. Otherwise use find_nolink

Parameters:
s Super block structure needed to perform i/o operations
whence Position where to start searching from
Returns:
Position of datablock, TARFS_EVAL if any error occures
See also:
find_nolink

Definition at line 631 of file tarfs_tar.c.

References AREGTYPE, BLKTYPE, CHRTYPE, DIRTYPE, FIFOTYPE, hcc(), is_tar(), LNKTYPE, oct_to_dec(), read_block(), REGTYPE, posix_header::size, SYMTYPE, TARFS_BLKSIZE, TARFS_EVAL, TARFS_NUMLENGTH, and posix_header::typeflag.

Referenced by find_nolink(), symlinkname(), tar_fill_inode(), and tar_readdir().

char* symlinkname struct super_block *  s,
unsigned long  ino
 

reads symlinks target

Parameters:
s Super block structure needed to perform i/o operations
ino - inode number of symlink
Returns:
NULL-terminated string which represents symlink's target 0 - error

Definition at line 1030 of file tarfs_tar.c.

References hcc(), is_tar(), posix_header::linkname, oct_to_dec(), OFFSET_BY_INO, pom_read_name(), read_block(), short_name_size(), posix_header::size, skip_blocks(), SYMTYPE, TARFS_BLKSIZE, TARFS_NUMLENGTH, and posix_header::typeflag.

Referenced by tar_read_page().

int tar_fill_inode struct super_block *  s,
struct inode *  inode,
int *  rdev
 

Reads inode from tar.

Fills inode data like times, acces rights, size of file

Parameters:
s Super block structure needed to perform i/o operations
inode Inode structure to be filled
rdev [out] If inode type is device, this parameter is filled with value kdev_t_to_nr(major, minor)
Returns:
Type of inode, as defined in stat.h (S_IFREG, S_IFLNK, S_IFCHR, S_IFBLK, S_IFIFO, S_IFDIR), 0 in case of error

Definition at line 739 of file tarfs_tar.c.

References AREGTYPE, BLKTYPE, CHRTYPE, posix_header::devmajor, posix_header::devminor, DIRTYPE, FIFOTYPE, posix_header::gid, is_tar(), posix_header::linkname, LNKTYPE, posix_header::mode, posix_header::mtime, oct_to_dec(), OFFSET_BY_INO, offset_by_name(), pom_read_name(), read_block(), REGTYPE, short_name_size(), posix_header::size, skip_blocks(), SYMTYPE, TARFS_EVAL, TARFS_NUMLENGTH, TARFS_ROOT_INO, posix_header::typeflag, and posix_header::uid.

Referenced by tarfs_read_inode().

unsigned long tar_get_root_ino struct super_block *  s  ) 
 

Returns number of root inode.

Parameters:
s Super block structure needed to perform i/o operations
Returns:
Number of root inode, TARFS_EVAL - error

Definition at line 184 of file tarfs_tar.c.

References AREGTYPE, BLKTYPE, CHRTYPE, DIRTYPE, FIFOTYPE, get_root_ino_pom(), hcc(), is_tar(), LNKTYPE, oct_to_dec(), read_block(), REGTYPE, posix_header::size, SYMTYPE, TARFS_BLKSIZE, TARFS_EVAL, TARFS_NUMLENGTH, and posix_header::typeflag.

Referenced by tarfs_read_super().

unsigned long tar_length struct super_block *  s  ) 
 

Returns number of blocks in tar.

Parameters:
s Super block structure needed to perform i/o operations
Returns:
Number of blocks, 0 - error (or empty)

Definition at line 241 of file tarfs_tar.c.

References hcc(), is_nullblock(), is_tar(), oct_to_dec(), read_block(), posix_header::size, tar_quick_validation(), TARFS_BLKSIZE, and TARFS_NUMLENGTH.

Referenced by tarfs_statfs().

unsigned long tar_lookup struct super_block *  s,
unsigned long  ino,
const char *  fname,
unsigned int  fsize
 

Searches for file in given directory.

Parameters:
s Super block structure needed to perform i/o operations
ino Inode of directory to be searched in
fname Name of desired file
fsize Size of fname
Returns:
Inode number of file if found, TARFS_EVAL otherwise

Definition at line 1499 of file tarfs_tar.c.

References DIRTYPE, hcc(), is_tar(), posix_header::name, oct_to_dec(), OFFSET_BY_INO, offset_by_name2(), pom_read_name(), read_block(), short_name_size(), posix_header::size, TARFS_BLKSIZE, TARFS_EVAL, TARFS_NUMLENGTH, TARFS_ROOT_INO, and posix_header::typeflag.

Referenced by tarfs_lookup().

int tar_quick_validation struct super_block *  s  ) 
 

Performs quick valiadtion of tar.

This function controls only the first block

Parameters:
s Super block structure needed to perform i/o operations
Returns:
1 - OK, 0 - is not tar, or other error

Definition at line 137 of file tarfs_tar.c.

References is_tar(), and read_block().

Referenced by tar_length(), and tarfs_read_super().

unsigned long tar_read_page struct super_block *  s,
struct inode *  inode,
loff_t  offset,
void *  buffer
 

Fills buffer with data from given inode.

Reads data from inode with given offset to the end of file or end of buffer (max PAGE_SIZE bytes)

Parameters:
s Super block structure needed to perform i/o operations
inode Inode with data to be read
offset Offset of desired data
buffer Alredy allocated buffer of size PAGE_SIZE (PAGE_SIZE should be multiple of TARFS_BLKSIZE)
Returns:
0 - EOF, 1 - OK, 2 - Symlink, TARFS_EVAL otherwise

Definition at line 1099 of file tarfs_tar.c.

References find_nolink(), hcc(), read_block(), symlinkname(), TARFS_BLKSIZE, TARFS_EVAL, and TARFS_ROOT_INO.

Referenced by tarfs_readpage().

unsigned long tar_readdir struct file *  filp,
void *  dirent,
filldir_t  filldir
 

Reads directory entries.

Reads directory entries, until stopped by returning <0 from filldir function, after that, it stores last entry id read into filp->f_pos. When called again, it continues from the last f_pos stored.

Parameters:
filp A file structure representing directory being read
dirent Falls through this function to the filldir call
filldir Pointer to a function called to add new dir entry
Returns:
Count of directory entries read, TARFS_EVAL otherwise

Definition at line 1218 of file tarfs_tar.c.

References AREGTYPE, BLKTYPE, CHRTYPE, DIRTYPE, FIFOTYPE, get_type(), hcc(), is_nullblock(), is_right_prefix(), is_tar(), LNKTYPE, posix_header::name, oct_to_dec(), OFFSET_BY_INO, pom_read_name(), read_block(), REGTYPE, short_name_size(), posix_header::size, skip_blocks(), SYMTYPE, TARFS_BLKSIZE, TARFS_EVAL, TARFS_NUMLENGTH, TARFS_PARENTDIR_FPOS, TARFS_ROOT_INO, TARFS_THISDIR_FPOS, and posix_header::typeflag.

Referenced by tarfs_readdir().


Generated on Fri May 23 02:10:44 2003 for TarFS by doxygen1.3