/** * @file tarfs_util.h * * Header file for tarfs_util.c * Contains declarations of helper functions for tarfs_tar.c * * @author Jaroslav Drazan * @author Petr Cermak */ /* ************************************************************************* * * * * 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. * * * * ************************************************************************* */ #include #include #include #ifndef __TARFS_UTIL_H__ #define __TARFS_UTIL_H__ /** * @brief Reads block from device * * Reads #i block from device specified in super block s * * @param s Super block * @param i No. of block * @param blok Allocated buffer in which to store data (size TAFS_BLKSIZE) * @return 1 - OK, 0 - error */ int read_block(struct super_block* s, unsigned long i, void* blok); /** * @brief Checks if given block is full of zeroes * * @param blok Block of data to check * @param size Size of block * @return 1 - OK, 0 - some non-zero character found or error */ int is_nullblock(void *blok, unsigned long size); /** * @brief Compares two strings * * b must be zero-terminated. * * @param a First string * @param b Second string * @param first_length maximum length of a * @return 1 - equal, 0 - nonequal */ int name_comparator(void* a, void* b, int first_length); /** * @brief Compares two strings, (except trailing '/') * * b must be zero-terminated. * * @param a First string * @param b Second string * @param first_length maximum length of a * @param second_length maximum length of b * @return 1 - equal, 0 - nonequal * @see name_comparator */ int name_comparator2(void* a, void* b, unsigned int first_length, unsigned int second_length); /** * @brief Compares two paths (strings) * * sais, whether the dname is right prefix of fname. * It's equal to dname contains fname* * @param dname full path of directory (char*, but couldn't be NULL-terminated) * @param dsize size of dname * @param fname full file path (char*, but couldn't be NULL-terminated) * @param fsize size of fname * @return 1 - dname contains fname, 0 - dname is not ancestor of fname in dir tree * - can be changed by makro TARFS_CAN_ADD-1 - dname is ancestor, but not father * @see TARFS_CAN_ADD */ int is_right_prefix(char* dname, unsigned int dsize, char* fname, unsigned int fsize); /** * @brief Converts octal number into decimal integer * * Supposes that the number is in big endian format * * @param what Number in octal format (string) * @param length Length of what - string * @return Number in decimal format, TARFS_EVAL - error */ unsigned long oct_to_dec(void* what, unsigned int length); /** * @brief Checks if given character is '0' - '7' * * @param ch Character * @return 0 - no, nonzero - yes */ int is_octal(char ch); /** * @brief Ceil value of nom / denom * * @param nom Nominator * @param denom Denominator * @return Ceil value of nom / denom */ unsigned long hcc(unsigned long co, unsigned long cim); /** * @brief Returns length of filename stored in one block * * @param name Any zero-terminated string * @return min(length of name, 100) */ unsigned int short_name_size(char* name); #endif // __TARFS_UTIL_H__