Commit ed9dcec5 authored by Joao Eriberto Mota Filho's avatar Joao Eriberto Mota Filho

Import Debian changes 1.8-1

jdupes (1.8-1) unstable; urgency=medium

  * New upstream release.
  * debian/clean: created to remove a file forgotten by the upstream.
  * debian/control: bumped Standards-Version to 4.0.0.
  * debian/copyright:
      - All upstream files are unde MIT license now.
      - Updated the upstream copyright years.
  * debian/patches/10_fix-segfault.patch: removed. This patch was previously
    supplied by the upstream and it is already in 1.8 source code.
parents 6774c913 4f04f47a
......@@ -17,9 +17,9 @@
#
# Normal output and testing dirs
#
/?dupes
/?dupes-jody
/?dupes*.exe
/jdupes
/jdupes*.exe
/*.pkg.tar.xz
#
# Backups / patches
......
jdupes 1.8
- All files are now licensed under The MIT License exclusively
- Fixed a serious memory alloc bug; upgrading is *strongly* recommended
- Several huge improvements to progress indicators
- Fix some error message display problems and add more error checking
- Fixes for several potential crashes and buffer overflows
- Indicate no duplicates were found if printing matches and none exist
- On Linux, jdupes now auto-tunes I/O size based on CPU L1 D-cache size
- The -v switch now also shows info about bitness in the version string
jdupes 1.7
- Incompatible change: zero-length files no longer duplicates by default
......
......@@ -6,8 +6,8 @@ make
su root
make install
This will install the program in /usr/local/bin. You may change this
to a different location by editing the Makefile. Please refer to the
This will install the program in /usr/bin. You may change this to a
different location by editing the Makefile. Please refer to the
Makefile for an explanation of compile-time options. If you're having
trouble compiling, please take a look at the Makefile.
......
The MIT License (MIT)
Copyright (c) 2015-2016 Jody Lee Bruchon and contributors
Copyright (C) 2015-2017 Jody Lee Bruchon and contributors
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
......
......@@ -20,6 +20,10 @@ PREFIX = /usr
# This can be enabled at build time: 'make LOW_MEMORY=1'
#LOW_MEMORY=1
# Uncomment this to build in hardened mode.
# This can be enabled at build time: 'make HARDEN=1'
#HARDEN=1
#####################################################################
# Developer Configuration Section #
#####################################################################
......@@ -63,6 +67,10 @@ endif
ifdef DEBUG
COMPILER_OPTIONS += -DDEBUG
endif
ifdef HARDEN
COMPILER_OPTIONS += -Wformat -Wformat-security -D_FORTIFY_SOURCE=2 -fstack-protector-strong -fPIE -fpie -Wl,-z,relro -Wl,-z,now
endif
# MinGW needs this for printf() conversions to work
ifeq ($(OS), Windows_NT)
......@@ -83,6 +91,7 @@ endif
# New BTRFS support option
ifdef ENABLE_BTRFS
COMPILER_OPTIONS += -DENABLE_BTRFS
OBJECT_FILES += act_dedupefiles.o
endif
# Low memory mode
ifdef LOW_MEMORY
......@@ -99,7 +108,8 @@ INSTALL_DATA = $(INSTALL) -c -m 0644
#ADDITIONAL_OBJECTS += getopt.o
OBJECT_FILES += jdupes.o jody_hash.o jody_paths.o jody_sort.o jody_win_unicode.o string_malloc.o
OBJECT_FILES += act_deletefiles.o act_dedupefiles.o act_linkfiles.o act_printmatches.o act_summarize.o
OBJECT_FILES += jody_cacheinfo.o
OBJECT_FILES += act_deletefiles.o act_linkfiles.o act_printmatches.o act_summarize.o
OBJECT_FILES += $(ADDITIONAL_OBJECTS)
all: jdupes
......@@ -117,3 +127,9 @@ install: jdupes installdirs
clean:
$(RM) $(OBJECT_FILES) $(PROGRAM_NAME) jdupes.exe *~ *.gcno *.gcda *.gcov
distclean: clean
$(RM) *.pkg.tar.xz
package:
+./chroot_build.sh
......@@ -299,10 +299,9 @@ Please DO NOT contact Adrian Lopez about issues with jdupes.
Legal Information and Software License
--------------------------------------------------------------------------
jdupes is Copyright (C) 2015-2016 by Jody Bruchon <jody@jodybruchon.com>
Derived from the original 'fdupes' (C) 1999-2016 by Adrian Lopez
Includes jody_hash, jody_paths, jody_sort, and string_malloc, all of
which are (C) 2015-2016 Jody Bruchon
jdupes is Copyright (C) 2015-2017 by Jody Bruchon <jody@jodybruchon.com>
Derived from the original 'fdupes' (C) 1999-2017 by Adrian Lopez
Includes other code libraries which are (C) 2015-2017 by Jody Bruchon
The MIT License
......
- A bug with -S shows wrong results.
- A bug causes the following behavior:
$ jdupes --symlinks testdir
testdir/with spaces b
testdir/with spaces a
testdir/zero_b
testdir/zero_a
testdir/symlink_two
testdir/twice_one
$ cp testdir/two testdir/two_again
$ jdupes --symlinks testdir
testdir/two_again
testdir/two
testdir/twice_one
testdir/symlink_two
testdir/with spaces b
testdir/with spaces a
testdir/zero_b
testdir/zero_a
** This is not the desired behavior. Likewise:
$ jdupes testdir
testdir/with spaces b
testdir/with spaces a
testdir/zero_b
testdir/zero_a
testdir/twice_one
testdir/two
$ jdupes --symlinks testdir
testdir/with spaces b
testdir/with spaces a
testdir/zero_b
testdir/zero_a
testdir/symlink_two
testdir/twice_one
- Option -R should not have to be separated from the rest,
such that "jdupes -dR testdir", "jdupes -d -R testdir",
"jdupes -Rd testdir", etc., all yield the same results.
......@@ -61,19 +12,6 @@
explicit loading in future runs to speed up repeated calls to
the program.
- Add an option to exclude files in the same directory from being
matched. This should be extensible so that various exclusion
criteria can be added later.
- Also add code to make directory ordering of pair matching more
stable; for instance, if dirs 'foo' and 'bar' are specified,
always put 'foo' at the start of the dupe set (which makes it
take precedence over 'bar' in this example.)
- The way that duplicates are sorted does not seem to work properly. The
sorting needs to be separated into its own function that sorts fully.
As it stands, sorting is only correct on specific match pairs and is
sometimes overridden by other match pairs to mess up the sort.
- The --xsize option can be improved. Instead of simply specifying an
exclusion size min/max, the option should offer multiple ways to
specify allowed file sizes. Examples:
......
/* BTRFS deduplication of file blocks */
/* BTRFS deduplication of file blocks
* This file is part of jdupes; see jdupes.c for license information */
#include "jdupes.h"
......@@ -9,9 +10,8 @@
#include <errno.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <linux/btrfs.h>
#include <sys/ioctl.h>
#include "act_dedupefiles.h"
/* Message to append to BTRFS warnings based on write permissions */
......
/* jdupes action for BTRFS block-level deduplication */
/* jdupes action for BTRFS block-level deduplication
* This file is part of jdupes; see jdupes.c for license information */
#ifndef ACT_DEDUPEFILES_H
#define ACT_DEDUPEFILES_H
......
/* Delete duplicate files automatically or interactively */
/* Delete duplicate files automatically or interactively
* This file is part of jdupes; see jdupes.c for license information */
#include <stdio.h>
#include <stdlib.h>
......
/* jdupes action for deleting duplicate files */
/* jdupes action for deleting duplicate files
* This file is part of jdupes; see jdupes.c for license information */
#ifndef ACT_DELETEFILES_H
#define ACT_DELETEFILES_H
......
/* Hard link or symlink files */
/* Hard link or symlink files
* This file is part of jdupes; see jdupes.c for license information */
#include "jdupes.h"
......
/* jdupes action for hard and soft file linking */
/* jdupes action for hard and soft file linking
* This file is part of jdupes; see jdupes.c for license information */
#ifndef ACT_LINKFILES_H
#define ACT_LINKFILES_H
......
/* Print matched file sets
* This file is part of jdupes; see jdupes.c for license information */
#include <stdio.h>
#include "jdupes.h"
#include "jody_win_unicode.h"
......@@ -6,9 +9,11 @@
extern void printmatches(file_t * restrict files)
{
file_t * restrict tmpfile;
int printed = 0;
while (files != NULL) {
if (ISFLAG(files->flags, F_HAS_DUPES)) {
printed = 1;
if (!ISFLAG(flags, F_OMITFIRST)) {
if (ISFLAG(flags, F_SHOWSIZE)) printf("%jd byte%c each:\n", (intmax_t)files->size,
(files->size != 1) ? 's' : ' ');
......@@ -25,5 +30,8 @@ extern void printmatches(file_t * restrict files)
files = files->next;
}
if (printed == 0) fprintf(stderr, "No duplicates found.\n");
return;
}
/* jdupes action for printing matched file sets to stdout */
/* jdupes action for printing matched file sets to stdout
* This file is part of jdupes; see jdupes.c for license information */
#ifndef ACT_PRINTMATCHES_H
#define ACT_PRINTMATCHES_H
......
/* Print summary of match statistics to stdout */
/* Print summary of match statistics to stdout
* This file is part of jdupes; see jdupes.c for license information */
#include <stdio.h>
#include "jdupes.h"
......
/* jdupes action for printing a summary of match stats to stdout */
/* jdupes action for printing a summary of match stats to stdout
* This file is part of jdupes; see jdupes.c for license information */
#ifndef ACT_SUMMARIZE_H
#define ACT_SUMMARIZE_H
......
#!/bin/sh
# Jody's generic chroot build script
# Version 1.0
ARCHES="i386 x86-64 uclibc-i386 uclibc-x86-64"
test -z "$NAME" && NAME="$(basename "$(pwd)")"
test -e "version.h" && VER="$(grep '#define VER ' version.h | tr -d \\\" | cut -d' ' -f3)"
test -z "$VER" && VER=0
export NAME
export VER
export CHROOT_BASE=/chroots
export WD="$(pwd)"
export PKG="pkg"
echo "chroot builder: building '$NAME' version '$VER'"
trap clean_exit INT QUIT ABRT HUP
clean_exit () {
umount $CHROOT/proc $CHROOT/sys $CHROOT/tmp $CHROOT/dev $CHROOT/usr/src $CHROOT/home
}
do_build () {
test -z "$WD" && echo "WD not set, aborting" && exit 1
test -z "$PKG" && echo "PKG not set, aborting" && exit 1
make clean
if ! make -j$JOBS all
then echo "Build failed"; exit 1
else
echo "WD/PKG: $WD/$PKG"
test -d $WD/$PKG && rm -rf $WD/$PKG
mkdir $WD/$PKG
make DESTDIR=$WD/$PKG install && \
tar -C pkg -c usr | xz -e > ${NAME}_$VER-$ARCH.pkg.tar.xz
echo "Built ${NAME}_$VER-$ARCH.pkg.tar.xz"
fi
}
if [ "$(id -u)" != "0" ]
then echo "You must be root to auto-build chroot packages."
exit 1
fi
if [ "$DO_CHROOT_BUILD" = "1" ]
then
test -z "$1" && echo "No arch specified" && exit 1
test ! -d "$1" && echo "Not a directory: $1" && exit 1
cd $1
export WD="$1"
do_build
echo "finished: $1"
exit
else
echo baz
export DO_CHROOT_BUILD=1
for ARCH in $ARCHES
do
export ARCH
export CHROOT="$CHROOT_BASE/$ARCH"
test ! -d $CHROOT && echo "$CHROOT not present, not building $ARCH package." && continue
echo "Performing package build for $CHROOT"
test ! -x $CHROOT/bin/sh && echo "$CHROOT does not seem to be a chroot; aborting." && exit 1
mount --bind /dev $CHROOT/dev || clean_exit
mount --bind /usr/src $CHROOT/usr/src || clean_exit
mount --bind /home $CHROOT/home || clean_exit
mount -t proc proc $CHROOT/proc || clean_exit
mount -t sysfs sysfs $CHROOT/sys || clean_exit
mount -t tmpfs tmpfs $CHROOT/tmp || clean_exit
if echo "$ARCH" | grep -q "i386"
then linux32 chroot $CHROOT $WD/$0 $WD
else chroot $CHROOT $WD/$0 $WD
fi
umount $CHROOT/proc $CHROOT/sys $CHROOT/tmp $CHROOT/dev $CHROOT/usr/src $CHROOT/home
test -d $WD/$PKG && rm -rf $WD/$PKG
done
fi
jdupes (1.8-1) unstable; urgency=medium
* New upstream release.
* debian/clean: created to remove a file forgotten by the upstream.
* debian/control: bumped Standards-Version to 4.0.0.
* debian/copyright:
- All upstream files are unde MIT license now.
- Updated the upstream copyright years.
* debian/patches/10_fix-segfault.patch: removed. This patch was previously
supplied by the upstream and it is already in 1.8 source code.
-- Joao Eriberto Mota Filho <eriberto@debian.org> Thu, 20 Jul 2017 10:44:07 -0300
jdupes (1.7-2) unstable; urgency=medium
* debian/patches/10_fix-segfault.patch: added to fix a segmentation fault in
......
act_dedupefiles.o
......@@ -3,7 +3,7 @@ Section: utils
Priority: optional
Maintainer: Joao Eriberto Mota Filho <eriberto@debian.org>
Build-Depends: debhelper (>= 10)
Standards-Version: 3.9.8
Standards-Version: 4.0.0
Homepage: https://github.com/jbruchon/jdupes
Vcs-Git: https://anonscm.debian.org/git/collab-maint/jdupes.git
Vcs-Browser: https://anonscm.debian.org/git/collab-maint/jdupes.git
......
......@@ -4,27 +4,11 @@ Upstream-Contact: Jody Bruchon <jody@jodybruchon.com>
Source: https://github.com/jbruchon/jdupes
Files: *
Copyright: 1999-2016 Adrian Lopez <adrian2@caribe.net>
2015-2016 Jody Bruchon <jody@jodybruchon.com>
Copyright: 1999-2017 Adrian Lopez <adrian2@caribe.net>
2015-2017 Jody Bruchon <jody@jodybruchon.com>
License: MIT
Comment: jdupes is based in fdupes. Adrian is the fdupes upstream.
Files: jody_hash.c
jody_hash.h
jody_paths.c
jody_paths.h
jody_sort.c
jody_sort.h
string_malloc.c
string_malloc.h
Copyright: 2014-2016 Jody Bruchon <jody@jodybruchon.com>
License: MIT or GPL-2
Files: win_stat.c
win_stat.h
Copyright: 2016 Jody Bruchon <jody@jodybruchon.com>
License: MIT or GPL-2 or GPL-3
Files: debian/*
Copyright: 2016-2017 Joao Eriberto Mota Filho <eriberto@debian.org>
License: MIT
......@@ -47,35 +31,3 @@ License: MIT
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
License: GPL-2
This package 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; version 2 of the License.
.
This package 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, see <https://www.gnu.org/licenses/>
.
On Debian systems, the complete text of the GNU General
Public License version 2 can be found in "/usr/share/common-licenses/GPL-2".
License: GPL-3
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, version 3 of the License.
.
This package 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, see <https://www.gnu.org/licenses/>.
.
On Debian systems, the complete text of the GNU General
Public License version 3 can be found in "/usr/share/common-licenses/GPL-3".
Description: fix a major bug in string_malloc()'s free list functionality
(Closes: #854427)
Author: Jody Bruchon <jody@jodybruchon.com>
Last-Update: 2017-01-19
Index: jdupes-1.7/string_malloc.c
===================================================================
--- jdupes-1.7.orig/string_malloc.c
+++ jdupes-1.7/string_malloc.c
@@ -30,7 +30,7 @@
#endif
static void *sma_head = NULL;
-static uintptr_t *sma_lastpage = NULL;
+static uintptr_t *sma_curpage = NULL;
static unsigned int sma_pages = 0;
static void *sma_freelist[SMA_MAX_FREE];
static int sma_freelist_cnt = 0;
@@ -52,9 +52,9 @@ uintmax_t sma_free_tails = 0;
/* Scan the freed chunk list for a suitably sized object */
static inline void *scan_freelist(const size_t size)
{
- size_t *min_p, *object;
+ size_t *object, *min_p;
size_t sz, min = 0;
- int i, used = 0;
+ int i, used = 0, min_i = -1;
/* Don't bother scanning if the list is empty */
if (sma_freelist_cnt == 0) return NULL;
@@ -74,9 +74,9 @@ static inline void *scan_freelist(const
/* Skip smaller objects */
if (sz < size) continue;
/* Object is big enough; record if it's the new minimum */
- if (min == 0 || sz < min) {
+ if (min == 0 || sz <= min) {
min = sz;
- min_p = object;
+ min_i = i;
/* Always stop scanning if exact sized object found */
if (sz == size) break;
}
@@ -85,8 +85,9 @@ static inline void *scan_freelist(const
/* Enhancement TODO: split the free item if it's big enough */
/* Return smallest object found and delete from free list */
- if (min != 0) {
- sma_freelist[i] = NULL;
+ if (min_i != -1) {
+ min_p = sma_freelist[min_i];
+ sma_freelist[min_i] = NULL;
sma_freelist_cnt--;
min_p++;
return (void *)min_p;
@@ -107,10 +108,10 @@ static inline void *string_malloc_page(v
*pageptr = (uintptr_t)NULL;
/* Link previous page to this page, if applicable */
- if (sma_lastpage != NULL) *sma_lastpage = (uintptr_t)pageptr;
+ if (sma_curpage != NULL) *sma_curpage = (uintptr_t)pageptr;
/* Update last page pointers and total page counter */
- sma_lastpage = pageptr;
+ sma_curpage = pageptr;
sma_pages++;
return (void *)pageptr;
@@ -119,7 +120,7 @@ static inline void *string_malloc_page(v
void *string_malloc(size_t len)
{
- const void * restrict page = (char *)sma_lastpage;
+ const void * restrict page = (char *)sma_curpage;
static size_t *address;
/* Calling with no actual length is invalid */
@@ -130,8 +131,6 @@ void *string_malloc(size_t len)
len &= ~(sizeof(uintptr_t) - 1);
len += sizeof(uintptr_t);
}
- /* Make room for size prefix */
- len += sizeof(size_t);
/* Pass-through allocations larger than maximum object size to malloc() */
if (len > (SMA_PAGE_SIZE - sizeof(uintptr_t) - sizeof(size_t))) {
@@ -151,7 +150,7 @@ void *string_malloc(size_t len)
for (int i = 0; i < SMA_MAX_FREE; i++) sma_freelist[i] = NULL;
/* Allocate first page and set up for first allocation */
sma_head = string_malloc_page();
- if (!sma_head) return NULL;
+ if (sma_head == NULL) return NULL;
sma_nextfree = sizeof(uintptr_t);
page = sma_head;
}
@@ -164,17 +163,20 @@ void *string_malloc(size_t len)
}
/* Allocate new page if this object won't fit */
- if ((sma_nextfree + len) > SMA_PAGE_SIZE) {
+ if ((sma_nextfree + len + sizeof(size_t)) > SMA_PAGE_SIZE) {
size_t sz;
size_t *tailaddr;
/* See if remaining space is usable */
- if (sma_freelist_cnt < SMA_MAX_FREE && sma_nextfree < SMA_PAGE_SIZE) {
- /* Get total remaining space size */
- sz = SMA_PAGE_SIZE - sma_nextfree;
- if (sz >= (SMA_MIN_SLACK + sizeof(size_t))) {
+ if (sma_freelist_cnt < SMA_MAX_FREE && (sma_nextfree + sizeof(size_t)) < SMA_PAGE_SIZE) {
+ /* Get remaining space size minus page linkage and obj size prefix */
+ sz = sma_nextfree + sizeof(size_t) + SMA_MIN_SLACK;
+
+ if (sz <= SMA_PAGE_SIZE) {
+ sz = SMA_PAGE_SIZE - sma_nextfree - sizeof(size_t);
tailaddr = (size_t *)((uintptr_t)page + sma_nextfree);
- *tailaddr = sz;
- string_free(tailaddr + 1);
+ *tailaddr = (size_t)sz;
+ tailaddr++;
+ string_free(tailaddr);
DBG(sma_free_tails++;)
}
}
@@ -188,7 +190,7 @@ void *string_malloc(size_t len)
/* Prefix object with its size */
*address = len;
address++;
- sma_nextfree += len;
+ sma_nextfree += len + sizeof(size_t);
DBG(sma_allocs++;)
return (void *)address;
@@ -206,7 +208,7 @@ void string_free(void * const restrict a
goto sf_failed;
/* Tiny objects keep big ones from being freed; ignore them */
- if (*(size_t *)((uintptr_t)addr - sizeof(size_t)) < (SMA_MIN_SLACK + sizeof(size_t)))
+ if (*(size_t *)((uintptr_t)addr - sizeof(size_t)) < SMA_MIN_SLACK)
goto sf_failed;
/* Add object to free list */
@@ -233,6 +235,7 @@ void string_malloc_destroy(void)
uintptr_t *next;
cur = (void *)sma_head;
+ if (sma_head == NULL) return;
while (sma_pages > 0) {
next = (uintptr_t *)*(uintptr_t *)cur;
free(cur);
10_fix-segfault.patch
......@@ -52,7 +52,7 @@ reverse (invert) the sort order of matches
isolate each command-line parameter from one another; only match if the
files are under different parameter specifications
.TP
.B -L --hardlink
.B -L --linkhard
replace all duplicate files with hardlinks to the first file in each set
of duplicates
.TP
......@@ -96,7 +96,7 @@ Examples section below for further explanation)
.B -r --recurse
for every directory given follow subdirectories encountered within
.TP
.B -s --linksoft
.B -l --linksoft
replace all duplicate files with symlinks to the first file in each set
of duplicates
.TP
......
This diff is collapsed.
/* jdupes module header */
/* jdupes main program header
* See jdupes.c for license information */
#ifndef JDUPES_H
#define JDUPES_H
......@@ -77,8 +78,6 @@ extern int out_mode;
/* Low memory option overrides */
#ifdef LOW_MEMORY
#undef DEBUG
#undef LOUD_DEBUG
#undef USE_TREE_REBALANCE
#ifndef NO_PERMS
#define NO_PERMS 1
......@@ -150,10 +149,6 @@ typedef enum {
ORDER_TIME
} ordertype_t;
/* Larger chunk size makes large files process faster but uses more RAM */
#ifndef CHUNK_SIZE
#define CHUNK_SIZE 65536
#endif
#ifndef PARTIAL_HASH_SIZE
#define PARTIAL_HASH_SIZE 4096
#endif
......@@ -215,6 +210,7 @@ extern struct stat s;
#endif
extern void oom(const char * const restrict msg);
extern void nullptr(const char * restrict func);
extern int file_has_changed(file_t * const restrict file);
extern int getfilestats(file_t * const restrict file);
extern int getdirstats(const char * const restrict name,
......
/* Detect and report size of CPU caches
*
* Copyright (C) 2017 by Jody Bruchon <jody@jodybruchon.com>
* Distributed under The MIT License
*
* If an error occurs or a cache is missing, zeroes are returned
* Unified caches populate l1/l2/l3; split caches populate lXi/lXd instead
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "jody_cacheinfo.h"
static char *pathidx;
static char buf[16];
static char path[64] = "/sys/devices/system/cpu/cpu0/cache/index";
/*** End declarations, begin code ***/
/* Linux sysfs */
#ifndef ON_WINDOWS
static size_t read_procfile(const char * const restrict name)
{
FILE *fp;
size_t i;
if (name == NULL) return 0;
memset(buf, 0, 16);
/* Create path */
*pathidx = '\0';
strcpy(pathidx, name);
fp = fopen(path, "rb");
if (fp == NULL) return 0;
i = fread(buf, 1, 16, fp);
if (ferror(fp)) return 0;
fclose(fp);
return i;
}
void get_proc_cacheinfo(struct proc_cacheinfo *pci)
{
char *idx;
size_t i;
size_t size;
int level;
char type;
char index;
if (pci == NULL) return;
memset(pci, 0, sizeof(struct proc_cacheinfo));
i = strlen(path);
if (i > 48) return;
idx = path + i;
pathidx = idx + 1;
*pathidx = '/'; pathidx++;
for (index = '0'; index < '9'; index++) {
*idx = index;
/* Get the level for this index */
if (read_procfile("level") == 0) break;
if (*buf < '1' || *buf > '3') break;
else level = (*buf) + 1 - '1';
/* Get the size */
if (read_procfile("size") == 0) break;
size = (size_t)atoi(buf) * 1024;
if (size == 0) break;
/* Get the type */
if (read_procfile("type") == 0) break;
if (*buf != 'U' && *buf != 'I' && *buf != 'D') break;
type = *buf;
/* Act on it */
switch (type) {
case 'D':
switch (level) {
case 1: pci->l1d = size; break;
case 2: pci->l2d = size; break;
case 3: pci->l3d = size; break;
default: return;
};
break;
case 'I':