Break of file routines into udf_file.{c,h}

udf1: Add link count
This commit is contained in:
rocky
2005-10-30 07:35:36 +00:00
parent 6c7ca93321
commit 9ec9c5a991
8 changed files with 124 additions and 116 deletions

View File

@@ -1,5 +1,5 @@
/*
$Id: udf1.c,v 1.10 2005/10/30 05:43:01 rocky Exp $
$Id: udf1.c,v 1.11 2005/10/30 07:35:36 rocky Exp $
Copyright (C) 2005 Rocky Bernstein <rocky@panix.com>
@@ -54,18 +54,15 @@ static void
print_file_info(const udf_file_t *p_udf_file)
{
time_t mod_time = udf_get_modification_time(p_udf_file);
udf_file_entry_t udf_fe;
if (udf_get_file_entry(p_udf_file, &udf_fe)) {
/* Print directory attributes*/
char psz_mode[11]="invalid";
/* Print directory attributes*/
printf("%s ", udf_mode_string(udf_get_posix_filemode(p_udf_file),
psz_mode));
}
printf("%4d ", udf_get_link_count(p_udf_file));
printf("%s %s", udf_get_filename(p_udf_file), ctime(&mod_time));
}
static udf_file_t *
list_files(const udf_t *p_udf, udf_file_t *p_udf_file, char *psz_token)
{

View File

@@ -1,4 +1,4 @@
# $Id: Makefile.am,v 1.26 2005/10/26 02:05:53 rocky Exp $
# $Id: Makefile.am,v 1.27 2005/10/30 07:35:36 rocky Exp $
#
# Copyright (C) 2003, 2004 Rocky Bernstein <rocky@panix.com>
#
@@ -48,6 +48,7 @@ libcdioinclude_HEADERS = \
track.h \
types.h \
udf.h \
udf_file.h \
udf_time.h \
util.h \
version.h \

View File

@@ -1,5 +1,5 @@
/*
$Id: udf.h,v 1.14 2005/10/30 05:43:01 rocky Exp $
$Id: udf.h,v 1.15 2005/10/30 07:35:37 rocky Exp $
Copyright (C) 2005 Rocky Bernstein <rocky@panix.com>
This program is free software; you can redistribute it and/or modify
@@ -84,6 +84,12 @@ extern "C" {
*/
udf_t *udf_open (const char *psz_path);
/*!
Return the partition number of the the opened udf handle. -1
Is returned if we have an error.
*/
int16_t udf_get_part_number(const udf_t *p_udf);
/*!
Get the root in p_udf. If b_any_partition is false then
the root must be in the given partition.
@@ -124,57 +130,11 @@ extern "C" {
bool b_any_partition,
partition_num_t i_partition);
/*!
Return the file id descriptor of the given file.
*/
bool udf_get_fileid_descriptor(const udf_file_t *p_udf_file,
/*out*/ udf_fileid_desc_t *p_udf_fid);
/*! udf_mode_string - fill in string PSZ_STR with an ls-style ASCII
representation of the i_mode. PSZ_STR is returned.
/*!
Return the name of the file
*/
const char *udf_get_filename(const udf_file_t *p_udf_file);
/*!
Return the name of the file
*/
bool udf_get_file_entry(const udf_file_t *p_udf_file,
/*out*/ udf_file_entry_t *p_udf_fe);
/*!
Returns a POSIX mode for a given p_udf_file.
*/
mode_t udf_get_posix_filemode(const udf_file_t *p_udf_file);
/*!
Return the next subdirectory.
*/
udf_file_t *udf_get_sub(const udf_t *p_udf, const udf_file_t *p_udf_file);
/*!
Return the next file.
*/
udf_file_t *udf_get_next(const udf_t *p_udf, udf_file_t *p_udf_file);
/*!
Return the partition number of the file
*/
int16_t udf_get_part_number(const udf_t *p_udf);
/*!
free free resources associated with p_udf_file.
*/
bool udf_file_free(udf_file_t *p_udf_file);
/*!
Return true if the file is a directory.
*/
bool udf_is_dir(const udf_file_t *p_udf_file);
/*! udf_mode_string - fill in string STR with an ls-style ASCII
representation of the st_mode field of file stats block STATP.
10 characters are stored in STR; no terminating null is added.
The characters stored in STR are:
10 characters are stored in PSZ_STR; a terminating null byte is added.
The characters stored in PSZ_STR are:
0 File type. 'd' for directory, 'c' for character
special, 'b' for block special, 'm' for multiplex,
@@ -207,12 +167,13 @@ extern "C" {
otherwise.
'T' if the file is sticky but not executable. */
char *udf_mode_string (mode_t mode, char *str);
char *udf_mode_string (mode_t i_mode, char *psz_str);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#include <cdio/udf_time.h>
#include <cdio/udf_file.h>
#endif /*UDF_H*/

View File

@@ -34,7 +34,7 @@ noinst_HEADERS = udf_private.h
lib_LTLIBRARIES = libudf.la
libudf_la_SOURCES = udf.c udf_fs.c udf_time.c filemode.c
libudf_la_SOURCES = udf.c udf_file.c udf_fs.c udf_time.c filemode.c
libudf_la_LIBADD = @LIBCDIO_LIBS@

View File

@@ -266,18 +266,19 @@ ftypelet (mode_t bits)
'T' if the file is sticky but not executable. */
char *
udf_mode_string (mode_t mode, char *str)
udf_mode_string (mode_t i_mode, char *psz_str)
{
str[0] = ftypelet (mode);
str[1] = mode & S_IRUSR ? 'r' : '-';
str[2] = mode & S_IWUSR ? 'w' : '-';
str[3] = mode & S_IXUSR ? 'x' : '-';
str[4] = mode & S_IRGRP ? 'r' : '-';
str[5] = mode & S_IWGRP ? 'w' : '-';
str[6] = mode & S_IXGRP ? 'x' : '-';
str[7] = mode & S_IROTH ? 'r' : '-';
str[8] = mode & S_IWOTH ? 'w' : '-';
str[9] = mode & S_IXOTH ? 'x' : '-';
setst (mode, str);
return str;
psz_str[ 0] = ftypelet (i_mode);
psz_str[ 1] = i_mode & S_IRUSR ? 'r' : '-';
psz_str[ 2] = i_mode & S_IWUSR ? 'w' : '-';
psz_str[ 3] = i_mode & S_IXUSR ? 'x' : '-';
psz_str[ 4] = i_mode & S_IRGRP ? 'r' : '-';
psz_str[ 5] = i_mode & S_IWGRP ? 'w' : '-';
psz_str[ 6] = i_mode & S_IXGRP ? 'x' : '-';
psz_str[ 7] = i_mode & S_IROTH ? 'r' : '-';
psz_str[ 8] = i_mode & S_IWOTH ? 'w' : '-';
psz_str[ 9] = i_mode & S_IXOTH ? 'x' : '-';
psz_str[10] = '\0';
setst (i_mode, psz_str);
return psz_str;
}

View File

@@ -4,6 +4,7 @@ debug_file_characteristics
debug_icbtag_file_type_enum
debug_tagid
debug_udf_enums1
debug_udf_time_enum
VSD_STD_ID_BEA01
VSD_STD_ID_BOOT2
VSD_STD_ID_CD001
@@ -15,6 +16,7 @@ udf_file_free
udf_get_file_entry
udf_get_fileid_descriptor
udf_get_filename
udf_get_link_count
udf_get_part_number
udf_get_posix_filemode
udf_get_next

View File

@@ -1,5 +1,5 @@
/*
$Id: udf.c,v 1.6 2005/10/30 05:43:01 rocky Exp $
$Id: udf.c,v 1.7 2005/10/30 07:35:37 rocky Exp $
Copyright (C) 2005 Rocky Bernstein <rocky@panix.com>
@@ -101,41 +101,9 @@ udf_get_posix_filemode(const udf_file_t *p_udf_file)
}
const char *
udf_get_filename(const udf_file_t *p_udf_file)
{
if (!p_udf_file) return NULL;
return p_udf_file->psz_name;
}
bool
udf_get_file_entry(const udf_file_t *p_udf_file,
/*out*/ udf_file_entry_t *p_udf_fe)
{
if (!p_udf_file) return false;
memcpy(p_udf_fe, &p_udf_file->fe, sizeof(udf_file_entry_t));
return true;
}
/*!
Return the file id descriptor of the given file.
*/
bool udf_get_fileid_descriptor(const udf_file_t *p_udf_file,
/*out*/ udf_fileid_desc_t *p_udf_fid)
{
if (!p_udf_file) return false;
if (!p_udf_file->fid) {
/* FIXME do something about trying to get the descriptor. */
return false;
}
memcpy(p_udf_fid, p_udf_file->fid, sizeof(udf_fileid_desc_t));
return true;
}
/*!
Return the partition number of the file
Return the partition number of the the opened udf handle. -1
Is returned if we have an error.
*/
int16_t udf_get_part_number(const udf_t *p_udf)
{
@@ -143,8 +111,3 @@ int16_t udf_get_part_number(const udf_t *p_udf)
return p_udf->i_partition;
}
bool
udf_is_dir(const udf_file_t *p_udf_file)
{
return p_udf_file->b_dir;
}

83
lib/udf/udf_file.c Normal file
View File

@@ -0,0 +1,83 @@
/*
$Id: udf_file.c,v 1.1 2005/10/30 07:35:37 rocky Exp $
Copyright (C) 2005 Rocky Bernstein <rocky@panix.com>
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.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/* Access routines */
#include <cdio/bytesex.h>
#include "udf_private.h"
#ifdef HAVE_STRING_H
# include <string.h>
#endif
const char *
udf_get_filename(const udf_file_t *p_udf_file)
{
if (!p_udf_file) return NULL;
return p_udf_file->psz_name;
}
bool
udf_get_file_entry(const udf_file_t *p_udf_file,
/*out*/ udf_file_entry_t *p_udf_fe)
{
if (!p_udf_file) return false;
memcpy(p_udf_fe, &p_udf_file->fe, sizeof(udf_file_entry_t));
return true;
}
/*!
Return the file id descriptor of the given file.
*/
bool udf_get_fileid_descriptor(const udf_file_t *p_udf_file,
/*out*/ udf_fileid_desc_t *p_udf_fid)
{
if (!p_udf_file) return false;
if (!p_udf_file->fid) {
/* FIXME do something about trying to get the descriptor. */
return false;
}
memcpy(p_udf_fid, p_udf_file->fid, sizeof(udf_fileid_desc_t));
return true;
}
/*!
Return the number of hard links of the file. Return 0 if error.
*/
uint16_t udf_get_link_count(const udf_file_t *p_udf_file)
{
if (p_udf_file) {
udf_file_entry_t udf_fe;
if (udf_get_file_entry(p_udf_file, &udf_fe)) {
return uint16_from_le(udf_fe.link_count);
}
}
return 0; /* Error. Non-error case handled above. */
}
/*!
Return true if the file is a directory.
*/
bool
udf_is_dir(const udf_file_t *p_udf_file)
{
return p_udf_file->b_dir;
}