[prev in list] [next in list] [prev in thread] [next in thread]
List: klik-devel
Subject: [klik-devel] [klikclient commit] r1681 -
From: codesite-noreply () google ! com
Date: 2008-08-26 17:46:13
Message-ID: 0016361e86c0dbe5da0455607a04 () google ! com
[Download RAW message or body]
Author: cristian.debian
Date: Tue Aug 26 10:45:38 2008
New Revision: 1681
Modified:
branches/cristian/fusioniso/fusioniso/src/fusioniso_fs.c
branches/cristian/fusioniso/fusioniso/src/fusioniso_isofs.c
Log:
Fix return value for all functions in isofs.c: there is no need to return
-ESOMETHING because all of these functions are internal functions used by
fs.c, not by fuse.
Standardize return vales for some functions, i.e.:
return 1 if found, 0 if not, -1 on error
return >=0 on read success, -1 on error
Modified: branches/cristian/fusioniso/fusioniso/src/fusioniso_fs.c
==============================================================================
--- branches/cristian/fusioniso/fusioniso/src/fusioniso_fs.c (original)
+++ branches/cristian/fusioniso/fusioniso/src/fusioniso_fs.c Tue Aug 26
10:45:38 2008
@@ -603,11 +603,11 @@
rc = isofs_parse_sa(inode,
((char *) record) + sizeof(struct
iso_directory_record) + name_len + pad_len + extern_context.susp_skip,
sa_len);
- if (rc)
+ if (rc<0)
{
free(buf);
isofs_free_inode(inode);
- return rc;
+ return -EIO;
}
}
@@ -997,7 +997,7 @@
if (ISO_FLAGS_DIR(record->flags))
{
FSDEBUG("%s not a file",path);
- return -EINVAL;
+ return -EISDIR;
}
if (ISO_FLAGS_HIDDEN(record->flags))
{
@@ -1008,6 +1008,9 @@
if (inode->ZF) // this
file is compressed, handle it specially
{
int v_count = isofs_real_read_zf(inode, out_buf, size, offset);
+ if (v_count<0)
+ return -EINVAL;
+
if (extern_glibc && offset==0 && v_count>18 && out_buf[0]==127 &&
memcmp(&(out_buf[1]), "ELF",3)==0)
{
fs_rewrite_loader(out_buf, v_count);
Modified: branches/cristian/fusioniso/fusioniso/src/fusioniso_isofs.c
==============================================================================
--- branches/cristian/fusioniso/fusioniso/src/fusioniso_isofs.c (original)
+++ branches/cristian/fusioniso/fusioniso/src/fusioniso_isofs.c Tue Aug 26
10:45:38 2008
@@ -95,6 +95,14 @@
return str;
}
+
+/**
+ * Check for Rock Ridge header
+ *
+ * @return 1 if RR header is found,
+ * 0 if not found,
+ * -1 on error
+ */
static int isofs_check_rr(struct iso_directory_record *root_record)
{
int extent = isonum_733(root_record->extent);
@@ -102,7 +110,7 @@
if (!buf)
{
FSWARNING("can\'t malloc: %s",strerror(errno));
- return -ENOMEM;
+ return -1;
}
int rc = isofs_read_raw_block(extent, buf);
@@ -117,24 +125,25 @@
size_t name_len = isonum_711(record->name_len);
size_t pad_len = ((name_len & 1) ? 0 : 1); //
padding byte if name_len is even
size_t sa_len = record_length - name_len - sizeof(struct
iso_directory_record) - pad_len;
+
if (record_length < sizeof(struct iso_directory_record))
{
FSWARNING("directory record length too small: %d",record_length);
free(buf);
- return -EIO;
+ return -1;
}
if (name_len != 1)
{
FSWARNING("file name length too big for . record: %d",name_len);
free(buf);
- return -EIO;
+ return -1;
}
if (sa_len < 0)
{
// probably something wrong with name_len
FSWARNING("wrong name_len in directory entry: %d,
record_length %d",name_len, record_length);
free(buf);
- return -EIO;
+ return -1;
}
if (sa_len >= 7)
@@ -181,6 +190,13 @@
return 0;
}
+
+/**
+ * Extract date info from a string
+ *
+ * @return >0 (timestamp) if string contains a date,
+ * 0 otherwise
+ */
static time_t isofs_date(char *stamp, int stamp_len)
{
struct tm tm;
@@ -223,13 +239,21 @@
0x37, 0xE4, 0x53, 0x96, 0xC9, 0xDB, 0xD6, 0x07
};
+
+/**
+ * Parse inode and search for zisofs header
+ *
+ * @return 1 if zisofs header is found,
+ * 0 if not found (or invalid),
+ * -1 on error
+ */
static int isofs_parse_zisofs_header(isofs_inode *inode)
{
char *buf = (char *) malloc(extern_context.block_size);
if (!buf)
{
FSWARNING("can\'t malloc: %s",strerror(errno));
- return -ENOMEM;
+ return -1;
}
int block_num = isonum_733(inode->record->extent);
@@ -237,13 +261,13 @@
if (len < 0)
{
free(buf);
- return len;
+ return -1;
}
if (len < (int)inode->zf_header_size)
{
FSWARNING("too small block len %d",len);
free(buf);
- return -EIO;
+ return -1;
}
zf_file_header *zf_header = (zf_file_header *) buf;
@@ -252,7 +276,7 @@
{
// invalid compressed file header
free(buf);
- return 1;
+ return 0;
}
size_t block_size = 1 << inode->zf_block_shift;
@@ -266,7 +290,7 @@
if (!inode->zf_blockptr)
{
FSWARNING("can\'t malloc: %s",strerror(errno));
- return -ENOMEM;
+ return -1;
}
}
@@ -297,7 +321,7 @@
if (len < 0)
{
free(buf);
- return len;
+ return -1;
}
/* printf("isofs_parse_sa: block_num: %d, len: %d\n",
@@ -315,7 +339,7 @@
// all information for compressed file we have already in ZF entry
// so just signal what this is really compressed file
free(buf);
- return 0;
+ return 1;
}
int isofs_real_preinit(char* imagefile, int fd)
@@ -474,9 +498,11 @@
// printf("Data block size: %d\n",
extern_context.block_size);
}
- if (isofs_check_rr(extern_context.root))
- {
+ int rc = isofs_check_rr(extern_context.root);
+ if (rc) {
extern_context.pd_have_rr = 1;
+ } else if (rc<0) {
+ return -1;
}
}
break;
@@ -510,8 +536,9 @@
}
}
- int have_rr =
- isofs_check_rr((struct iso_directory_record *)
sd->root_directory_record);
+ int have_rr = isofs_check_rr((struct
iso_directory_record *) sd->root_directory_record);
+ if (have_rr<0)
+ return -1;
// switch to SVD only if it contain RRIP or if PVD
have no RRIP
// in other words, prefer VD with RRIP
@@ -646,20 +673,27 @@
return (void*) &extern_context;
}
+
+/**
+ * Read data at 'block' offset and put them into buf
+ *
+ * @return >=0 on read success (number of bytes read)
+ * -1 on error
+ */
int isofs_read_raw_block(int block, char *buf)
{
off_t off = block * extern_context.block_size +
extern_context.block_offset + extern_context.file_offset;
if (pthread_mutex_lock(& fd_mutex))
{
- int err = errno;
+ //int err = errno;
FSWARNING("can\'t lock fd_mutex: %s",strerror(errno));
- return -err;
+ return -1;
}
if (lseek(extern_context.fd, off, SEEK_SET) == -1)
{
FSWARNING("can\'t lseek: %s",strerror(errno));
pthread_mutex_unlock(& fd_mutex);
- return -EIO;
+ return -1;
}
size_t len = read(extern_context.fd, buf, extern_context.data_size);
if (len != extern_context.data_size)
@@ -676,6 +710,12 @@
return len;
}
+
+/**
+ * Parse inode and fill struct stat
+ *
+ * @return 0 anyhow
+ */
int isofs_direntry2stat(struct stat *st, isofs_inode *inode)
{
struct iso_directory_record *record = inode->record;
@@ -741,6 +781,12 @@
return 0;
}
+/**
+ * Fix string 'entry' (lowercase, charset, ...)
+ *
+ * @return fixed string on success,
+ * NULL on error
+ */
char *isofs_fix_entry(char *entry, size_t len)
{
if (!extern_context.joliet_level) //
iso9660 names
@@ -834,6 +880,13 @@
}
}
+
+/**
+ * Parse inode and extract info based on its signature
+ *
+ * @return 0 on success,
+ * -1 on error
+ */
int isofs_parse_sa(isofs_inode *inode, char *sa, size_t sa_len)
{
int cont_block = 0;
@@ -864,7 +917,7 @@
FSWARNING("incorrect SP entry: sue_len %d,
sue_version %d, magic %c%c",
sue_len, sue_version, sue->u.SP.magic[0],
sue->u.SP.magic[1]);
extern_context.susp = 0;
- return 0;
+ return -1;
}
else
{
@@ -1079,7 +1132,7 @@
if (!inode->sl)
{
FSWARNING("can\'t
malloc: %s",strerror(errno));
- return -ENOMEM;
+ return -1;
}
}
@@ -1217,7 +1270,7 @@
if (!inode->nm)
{
FSWARNING("can\'t
malloc: %s",strerror(errno));
- return -ENOMEM;
+ return -1;
}
}
@@ -1261,13 +1314,13 @@
if (!buf)
{
FSWARNING("can\'t malloc: %s",strerror(errno));
- return -ENOMEM;
+ return -1;
}
int rc = isofs_read_raw_block(inode->cl_block, buf);
if (rc < 0)
{
free(buf);
- return rc;
+ return -1;
}
struct iso_directory_record *record = (struct
iso_directory_record *) buf;
@@ -1283,13 +1336,13 @@
{
FSWARNING("CL entry: directory record length too
small: %d",record_length);
free(buf);
- return -EIO;
+ return -1;
}
if (name_len != 1)
{
FSWARNING("file name length too big for .
record: %d",name_len);
free(buf);
- return -EIO;
+ return -1;
}
if (sa_len < 0)
{
@@ -1297,7 +1350,7 @@
FSWARNING("CL record: wrong name_len in directory
entry: %d, record_length %d",
name_len, record_length);
free(buf);
- return -EIO;
+ return -1;
}
// ignoring anything from original record
@@ -1306,7 +1359,7 @@
if (!cl_record)
{
FSWARNING("can\'t malloc: %s",strerror(errno));
- return -ENOMEM;
+ return -1;
}
memcpy(cl_record, record, sizeof(struct
iso_directory_record));
@@ -1325,10 +1378,10 @@
sizeof(struct iso_directory_record) +
name_len + pad_len + extern_context.susp_skip,
sa_len);
- if (rc)
+ if (rc<0)
{
free(buf);
- return rc;
+ return -1;
}
free(buf);
@@ -1453,7 +1506,7 @@
inode->real_size = isonum_733(sue->u.ZF.real_size);
// check if file is really compressed, ignore ZF entry
otherwise
int rc = isofs_parse_zisofs_header(inode);
- if (rc == 0)
+ if (rc)
{
//FSDEBUG("ZF entry found, algorithm %02x%02x,
header size %d, block shift %d, compressed size %d, real size %d",
// inode->zf_algorithm[0],
inode->zf_algorithm[1],
@@ -1461,13 +1514,13 @@
// inode->zf_size, inode->real_size);
inode->ZF = 1;
}
- else if (rc > 0)
+ else if (rc==0)
{
FSDEBUG("ZF entry found, but file is not really
compressed");
} //
some error occur
else
{
- return rc;
+ return -1;
}
}
else
@@ -1491,7 +1544,7 @@
{
FSWARNING("inappropriate susp entry length: %d,
signature %c%c",
sue_len, sue->signature[0], sue->signature[1]);
- return -EIO;
+ return -1;
} //
probably there are no more susp entries
else
{
@@ -1506,21 +1559,21 @@
if (!buf)
{
FSWARNING("can\'t malloc: %s",strerror(errno));
- return -ENOMEM;
+ return -1;
}
int rc = isofs_read_raw_block(cont_block, buf);
if (rc < 0)
{
free(buf);
- return rc;
+ return -1;
}
//FSDEBUG("deep into CE, extent %d, offset %d, size %d",
// cont_block, cont_offset, cont_size);
rc = isofs_parse_sa(inode, buf + cont_offset, cont_size);
- if (rc)
+ if (rc<0)
{
free(buf);
- return rc;
+ return -1;
}
free(buf);
@@ -1529,6 +1582,13 @@
return 0;
}
+
+/**
+ * Read compressed data from inode
+ *
+ * @return >=0 on read success (number of bytes read)
+ * -1 on error
+ */
int isofs_real_read_zf(isofs_inode *inode, char *out_buf, size_t size,
off_t offset)
{
int zf_block_size = 1 << inode->zf_block_shift;
@@ -1545,19 +1605,19 @@
// protection against some ununderstandable errors
if (zf_start >= inode->zf_nblocks) zf_start = inode->zf_nblocks-1;
if (zf_end >= inode->zf_nblocks) zf_end = inode->zf_nblocks-1;
- if (zf_end < 0 || zf_start < 0) return 0;
+ if (zf_end < 0 || zf_start < 0) return -1;
unsigned char *cbuf = (unsigned char *) malloc(zf_block_size * 2);
if (!cbuf)
{
FSWARNING("can\'t malloc: %s",strerror(errno));
- return -ENOMEM;
+ return -1;
}
unsigned char *ubuf = (unsigned char *) malloc(zf_block_size);
if (!ubuf)
{
FSWARNING("can\'t malloc: %s",strerror(errno));
- return -ENOMEM;
+ return -1;
}
size_t total_size = 0;
@@ -1586,7 +1646,7 @@
"block size %d, uncompressed block
size %d",block_size,zf_block_size);
free(cbuf);
free(ubuf);
- return -EIO;
+ return -1;
}
else
{
@@ -1597,11 +1657,11 @@
if (pthread_mutex_lock(& fd_mutex))
{
- int err = errno;
+ //int err = errno;
FSWARNING("can\'t lock fd_mutex: %s",strerror(errno));
free(cbuf);
free(ubuf);
- return -err;
+ return -1;
}
if (lseek(extern_context.fd, image_off, SEEK_SET) == -1)
{
@@ -1609,7 +1669,7 @@
pthread_mutex_unlock(& fd_mutex);
free(cbuf);
free(ubuf);
- return -EIO;
+ return -1;
}
size_t len = read(extern_context.fd, cbuf, block_size);
if ((int)len != block_size)
@@ -1619,7 +1679,7 @@
pthread_mutex_unlock(& fd_mutex);
free(cbuf);
free(ubuf);
- return -EIO;
+ return -1;
}
pthread_mutex_unlock(& fd_mutex);
@@ -1632,7 +1692,7 @@
free(cbuf);
free(ubuf);
FSWARNING("uncompress() error %i: %s",rc,strerror(rc));
- return -rc;
+ return -1;
}
// ubuf contain uncompressed data, usize contain uncompressed
block size
_______________________________________________
klik-devel mailing list
klik-devel@kde.org
https://mail.kde.org/mailman/listinfo/klik-devel
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic