From: Karel Zak Date: Wed, 1 Sep 2021 15:50:51 +0000 (+0200) Subject: lsfd: use 'new_' prefix when we allocate something X-Git-Tag: v2.38-rc1~144^2~123 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=2d95dc093b17eab5a8e80c0db48301a25dd55a2e;p=thirdparty%2Futil-linux.git lsfd: use 'new_' prefix when we allocate something It's more readable than rather than 'make_'. Signed-off-by: Karel Zak --- diff --git a/misc-utils/lsfd-bdev.c b/misc-utils/lsfd-bdev.c index 2bfca240c7..24ef05596b 100644 --- a/misc-utils/lsfd-bdev.c +++ b/misc-utils/lsfd-bdev.c @@ -71,16 +71,16 @@ static bool bdev_fill_column(struct proc *proc __attribute__((__unused__)), return true; } -struct file *make_bdev(const struct file_class *class, +struct file *new_bdev(const struct file_class *class, struct stat *sb, const char *name, struct map_file_data *map_file_data, int fd) { - return make_file(class? class: &bdev_class, + return new_file(class? class: &bdev_class, sb, name, map_file_data, fd); } -static struct partition *make_partition(dev_t dev, const char *name) +static struct partition *new_partition(dev_t dev, const char *name) { struct partition *partition = xcalloc(1, sizeof(*partition)); @@ -109,7 +109,7 @@ static void read_partitions(struct list_head *partitions_list, FILE *part_fp) if (sscanf(line, "%u %u %*u %s", &major, &minor, name) != 3) continue; - partition = make_partition(makedev(major, minor), name); + partition = new_partition(makedev(major, minor), name); list_add_tail(&partition->partitions, partitions_list); } } diff --git a/misc-utils/lsfd-cdev.c b/misc-utils/lsfd-cdev.c index e83fe6db43..f697a5bf7a 100644 --- a/misc-utils/lsfd-cdev.c +++ b/misc-utils/lsfd-cdev.c @@ -106,16 +106,16 @@ static bool cdev_fill_column(struct proc *proc __attribute__((__unused__)), return true; } -struct file *make_cdev(const struct file_class *class, +struct file *new_cdev(const struct file_class *class, struct stat *sb, const char *name, struct map_file_data *map_file_data, int fd) { - return make_file(class? class: &cdev_class, + return new_file(class? class: &cdev_class, sb, name, map_file_data, fd); } -static struct chrdrv *make_chrdrv(unsigned long major, const char *name) +static struct chrdrv *new_chrdrv(unsigned long major, const char *name) { struct chrdrv *chrdrv = xcalloc(1, sizeof(*chrdrv)); @@ -149,12 +149,12 @@ static void read_devices(struct list_head *chrdrvs_list, FILE *devices_fp) if (sscanf(line, "%lu %s", &major, name) != 2) continue; - chrdrv = make_chrdrv(major, name); + chrdrv = new_chrdrv(major, name); list_add_tail(&chrdrv->chrdrvs, chrdrvs_list); } } -static struct miscdev *make_miscdev(unsigned long minor, const char *name) +static struct miscdev *new_miscdev(unsigned long minor, const char *name) { struct miscdev *miscdev = xcalloc(1, sizeof(*miscdev)); @@ -184,7 +184,7 @@ static void read_misc(struct list_head *miscdevs_list, FILE *misc_fp) if (sscanf(line, "%lu %s", &minor, name) != 2) continue; - miscdev = make_miscdev(minor, name); + miscdev = new_miscdev(minor, name); list_add_tail(&miscdev->miscdevs, miscdevs_list); } } diff --git a/misc-utils/lsfd-fifo.c b/misc-utils/lsfd-fifo.c index e745fd5547..bae969d821 100644 --- a/misc-utils/lsfd-fifo.c +++ b/misc-utils/lsfd-fifo.c @@ -56,12 +56,12 @@ static bool fifo_fill_column(struct proc *proc __attribute__((__unused__)), return true; } -struct file *make_fifo(const struct file_class *class, +struct file *new_fifo(const struct file_class *class, struct stat *sb, const char *name, struct map_file_data *map_file_data, int fd) { - return make_file(class? class: &fifo_class, + return new_file(class? class: &fifo_class, sb, name, map_file_data, fd); } diff --git a/misc-utils/lsfd-file.c b/misc-utils/lsfd-file.c index 762d759f1e..b496e214d0 100644 --- a/misc-utils/lsfd-file.c +++ b/misc-utils/lsfd-file.c @@ -340,7 +340,7 @@ static void file_free_content(struct file *file) free(file->name); } -struct file *make_file(const struct file_class *class, +struct file *new_file(const struct file_class *class, struct stat *sb, const char *name, struct map_file_data *map_file_data, int association) diff --git a/misc-utils/lsfd-sock.c b/misc-utils/lsfd-sock.c index da1aa59dfa..d5bf88b79d 100644 --- a/misc-utils/lsfd-sock.c +++ b/misc-utils/lsfd-sock.c @@ -76,13 +76,13 @@ static bool sock_fill_column(struct proc *proc __attribute__((__unused__)), return true; } -struct file *make_sock(const struct file_class *class, +struct file *new_sock(const struct file_class *class, struct stat *sb, const char *name, struct map_file_data *map_file_data, int fd, struct proc *proc) { - struct file *file = make_file(class? class: &sock_class, + struct file *file = new_file(class? class: &sock_class, sb, name, map_file_data, fd); if (fd >= 0 || fd == -ASSOC_MEM || fd == -ASSOC_SHM) { struct sock *sock = (struct sock *)file; diff --git a/misc-utils/lsfd-unkn.c b/misc-utils/lsfd-unkn.c index 64613a2816..302f312ca1 100644 --- a/misc-utils/lsfd-unkn.c +++ b/misc-utils/lsfd-unkn.c @@ -56,12 +56,12 @@ static bool unkn_fill_column(struct proc *proc __attribute__((__unused__)), return true; } -struct file *make_unkn(const struct file_class *class, +struct file *new_unkn(const struct file_class *class, struct stat *sb, const char *name, struct map_file_data *map_file_data, int fd) { - return make_file(class? class: &unkn_class, + return new_file(class? class: &unkn_class, sb, name, map_file_data, fd); } diff --git a/misc-utils/lsfd.c b/misc-utils/lsfd.c index 1d4be15d8f..5daa920e94 100644 --- a/misc-utils/lsfd.c +++ b/misc-utils/lsfd.c @@ -219,7 +219,7 @@ static const struct colinfo *get_column_info(int num) return &infos[ get_column_id(num) ]; } -static struct proc *make_proc(pid_t pid, struct proc * leader) +static struct proc *new_prococess(pid_t pid, struct proc * leader) { struct proc *proc = xcalloc(1, sizeof(*proc)); @@ -242,7 +242,7 @@ static void free_file(struct file *file) free(file); } -static struct nodev* make_nodev(unsigned long minor, const char *filesystem) +static struct nodev* new_nodev(unsigned long minor, const char *filesystem) { struct nodev *nodev = xcalloc(1, sizeof(*nodev)); @@ -305,7 +305,7 @@ static void collect_tasks(struct proc *leader, continue; } - proc = make_proc((pid_t)num, leader); + proc = new_prococess((pid_t)num, leader); enqueue_proc(procs, proc); } } @@ -336,7 +336,7 @@ static void collect(struct list_head *procs, struct lsfd_control *ctl) if (!(num = strtol(dp->d_name, NULL, 10))) continue; - proc = make_proc((pid_t)num, NULL); + proc = new_prococess((pid_t)num, NULL); enqueue_proc(procs, proc); if (ctl->threads) { @@ -364,19 +364,19 @@ static struct file *collect_file(struct proc *proc, { switch (sb->st_mode & S_IFMT) { case S_IFCHR: - return make_cdev(NULL, sb, name, map_file_data, assoc); + return new_cdev(NULL, sb, name, map_file_data, assoc); case S_IFBLK: - return make_bdev(NULL, sb, name, map_file_data, assoc); + return new_bdev(NULL, sb, name, map_file_data, assoc); case S_IFSOCK: - return make_sock(NULL, sb, name, map_file_data, assoc, proc); + return new_sock(NULL, sb, name, map_file_data, assoc, proc); case S_IFIFO: - return make_fifo(NULL, sb, name, map_file_data, assoc); + return new_fifo(NULL, sb, name, map_file_data, assoc); case S_IFLNK: case S_IFREG: case S_IFDIR: - return make_file(NULL, sb, name, map_file_data, assoc); + return new_file(NULL, sb, name, map_file_data, assoc); default: - return make_unkn(NULL, sb, name, map_file_data, assoc); + return new_unkn(NULL, sb, name, map_file_data, assoc); } } @@ -543,7 +543,7 @@ static void collect_fd_files(struct proc *proc) closedir(dirp); } -static struct map* make_map(unsigned long mem_addr_start, unsigned long long file_offset, +static struct map* new_map(unsigned long mem_addr_start, unsigned long long file_offset, int r, int w, int x, int s) { struct map *map = xcalloc(1, sizeof(*map)); @@ -588,7 +588,7 @@ static void read_maps(struct list_head *maps_list, FILE *maps_fp) &start, &end, &r, &w, &x, &s, &file_offset, &major, &minor, &inode) != 10) continue; - map = make_map(start, file_offset, r == 'r', w == 'w', x == 'x', s == 's'); + map = new_map(start, file_offset, r == 'r', w == 'w', x == 'x', s == 's'); list_add_tail(&map->maps, maps_list); } } @@ -1143,11 +1143,15 @@ FILE *fopenf(const char *mode, const char *format, ...) static void add_nodev(unsigned long minor, const char *filesystem) { + struct nodev *nodev; + int slot; + if (get_nodev_filesystem(minor)) return; - struct nodev *nodev = make_nodev(minor, filesystem); - int slot = minor % NODEV_TABLE_SIZE; + nodev = new_nodev(minor, filesystem); + slot = minor % NODEV_TABLE_SIZE; + list_add_tail(&nodev->nodevs, &nodev_table.tables[slot]); } @@ -1155,6 +1159,7 @@ const char *get_nodev_filesystem(unsigned long minor) { struct list_head *n; int slot = minor % NODEV_TABLE_SIZE; + list_for_each (n, &nodev_table.tables[slot]) { struct nodev *nodev = list_entry(n, struct nodev, nodevs); if (nodev->minor == minor) diff --git a/misc-utils/lsfd.h b/misc-utils/lsfd.h index 149808b3c6..089cff4ca0 100644 --- a/misc-utils/lsfd.h +++ b/misc-utils/lsfd.h @@ -152,28 +152,28 @@ struct file_class { extern const struct file_class file_class, cdev_class, bdev_class, sock_class, unkn_class, fifo_class; -struct file *make_file(const struct file_class *class, +struct file *new_file(const struct file_class *class, struct stat *sb, const char *name, struct map_file_data *map_file_data, int association); -struct file *make_cdev(const struct file_class *class, +struct file *new_cdev(const struct file_class *class, struct stat *sb, const char *name, struct map_file_data *map_file_data, int fd); -struct file *make_bdev(const struct file_class *class, +struct file *new_bdev(const struct file_class *class, struct stat *sb, const char *name, struct map_file_data *map_file_data, int fd); -struct file *make_sock(const struct file_class *class, +struct file *new_sock(const struct file_class *class, struct stat *sb, const char *name, struct map_file_data *map_file_data, int fd, struct proc *proc); -struct file *make_unkn(const struct file_class *class, +struct file *new_unkn(const struct file_class *class, struct stat *sb, const char *name, struct map_file_data *map_file_data, int fd); -struct file *make_fifo(const struct file_class *class, +struct file *new_fifo(const struct file_class *class, struct stat *sb, const char *name, struct map_file_data *map_file_data, int fd);