|| (file)->association == -ASSOC_SHM \
|| (file)->association == -ASSOC_MEM)
+static unsigned long get_map_length(struct file *file)
+{
+ unsigned long res = 0;
+
+ if (is_association(file, SHM) || is_association(file, MEM)) {
+ static size_t pagesize = 0;
+
+ if (!pagesize)
+ pagesize = getpagesize();
+
+ res = (file->map_end - file->map_start) / pagesize;
+ }
+
+ return res;
+}
+
static bool file_fill_column(struct proc *proc,
struct file *file,
struct libscols_line *ln,
if (file->association != -ASSOC_SHM
&& file->association != -ASSOC_MEM)
return true;
- xasprintf(&str, "%lu", file->assoc_data.map_length);
+ xasprintf(&str, "%lu", get_map_length(file));
break;
default:
return false;
return &unkn_class;
}
-static struct file *new_file(
- struct proc *proc,
- struct stat *sb, const char *name,
- struct map_file_data *map_file_data,
- int association)
+static struct file *new_file(struct proc *proc, const struct file_class *class)
{
struct file *file;
- const struct file_class *class = stat2class(sb);
-
- assert(class);
file = xcalloc(1, class->size);
-
- file->class = class;
- file->association = association;
- file->name = xstrdup(name);
- file->stat = *sb;
file->proc = proc;
- /* add file to the process */
INIT_LIST_HEAD(&file->files);
list_add_tail(&file->files, &proc->files);
- if (is_association(file, SHM) || is_association(file, MEM)) {
- static size_t pagesize = 0;
+ return file;
+}
- assert(map_file_data);
- if (!pagesize)
- pagesize = getpagesize();
+static void file_set_path(struct file *file, struct stat *sb, const char *name, int association)
+{
+ const struct file_class *class = stat2class(sb);
- file->assoc_data.map_length =
- (map_file_data->end - map_file_data->start) / pagesize;
- }
+ assert(class);
- if (file->class->initialize_content)
- file->class->initialize_content(file, map_file_data);
+ file->class = class;
+ file->association = association;
+ file->name = xstrdup(name);
+ file->stat = *sb;
+}
- return file;
+static void file_init_content(struct file *file)
+{
+ if (file->class && file->class->initialize_content)
+ file->class->initialize_content(file);
}
static void free_file(struct file *file)
if (ul_path_readlink(pc, sym, sizeof(sym), name) < 0)
return NULL;
- f = new_file(proc, &sb, sym, NULL, assoc);
- if (!f)
- return NULL;
+ f = new_file(proc, stat2class(&sb));
+
+ file_set_path(f, &sb, sym, assoc);
+ file_init_content(f);
if (is_association(f, EXE))
proc->uid = sb.st_uid;
fclose(fdinfo);
}
}
+
return f;
}
ssize_t len;
char sym[PATH_MAX];
struct file *f;
- struct map_file_data map_file_data;
+ unsigned long start, end;
struct map *map;
enum association assoc;
+ mode_t mode = 0;
if (fstatat(dd, dp->d_name, &sb, 0) < 0)
return NULL;
map = NULL;
- if (sscanf(dp->d_name, "%lx-%lx", &map_file_data.start, &map_file_data.end) == 2)
- map = find_map(maps, map_file_data.start);
+ if (sscanf(dp->d_name, "%lx-%lx", &start, &end) == 2)
+ map = find_map(maps, start);
assoc = (map && map->shared)? ASSOC_SHM: ASSOC_MEM;
- f = new_file(proc, &sb, sym, &map_file_data, -assoc);
- if (!f)
- return NULL;
- if (map) {
- f->mode = (map->read? S_IRUSR: 0) | (map->write? S_IWUSR: 0) | (map->exec? S_IXUSR: 0);
- f->pos = map->file_offset;
- }
+ f = new_file(proc, stat2class(&sb));
+ file_set_path(f, &sb, sym, -assoc);
+
+ if (map)
+ mode = (map->read? S_IRUSR: 0) | (map->write? S_IWUSR: 0) | (map->exec? S_IXUSR: 0);
+
+ f->map_start = start;
+ f->map_end = end;
+ f->pos = map ? map->file_offset : 0;
+ f->mode = mode;
+
+ file_init_content(f);
return f;
}