1 /* -*- mode: C; c-file-style: "linux" -*- */
3 /* MemProf -- memory profiler and leak detector
4 * Copyright 1999, 2000, 2001, Red Hat, Inc.
5 * Copyright 2002, Kristian Rietveld
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
28 /************************************************************
29 * Inode finding code - not needed for kernel 2.2 or greater
30 ************************************************************/
32 GHashTable
*inode_table
= NULL
;
41 inode_hash (gconstpointer data
)
43 return (((Inode
*)data
)->device
+ (((Inode
*)data
)->inode
<< 11));
47 inode_compare (gconstpointer a
, gconstpointer b
)
49 return ((((Inode
*)a
)->device
== ((Inode
*)b
)->device
) &&
50 (((Inode
*)a
)->inode
== ((Inode
*)b
)->inode
));
54 read_inode (const gchar
*path
)
58 g_return_if_fail (path
!= NULL
);
61 inode_table
= g_hash_table_new (inode_hash
, inode_compare
);
63 if (!stat (path
, &stbuf
)) {
64 Inode
*inode
= g_new (Inode
, 1);
65 inode
->device
= stbuf
.st_dev
;
66 inode
->inode
= stbuf
.st_ino
;
67 if (!g_hash_table_lookup (inode_table
, inode
)) {
68 inode
->name
= g_strdup (path
);
69 g_hash_table_insert (inode_table
, inode
, inode
);
78 static const char *directories
[] = {
89 for (dirname
= directories
; *dirname
; dirname
++)
91 DIR *dir
= opendir (*dirname
);
95 while ((ent
= readdir (dir
))) {
97 snprintf(buf
, 1024-1, "%s/%s", *dirname
, ent
->d_name
);
107 locate_inode (dev_t device
, ino_t inode
)
112 lookup
.device
= device
;
113 lookup
.inode
= inode
;
118 result
= g_hash_table_lookup (inode_table
, &lookup
);