Skip to content

Commit

Permalink
Merge pull request #1708 from ghaerr/devname
Browse files Browse the repository at this point in the history
[kernel][libc][cmds] Add devname libc function
  • Loading branch information
ghaerr authored Sep 10, 2023
2 parents 6aa6483 + 4327394 commit 51b8bcc
Show file tree
Hide file tree
Showing 21 changed files with 298 additions and 296 deletions.
5 changes: 3 additions & 2 deletions elks/arch/i86/boot/setup.S
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
*/

#include <linuxmt/config.h>
#include <linuxmt/devnum.h>
#include <linuxmt/boot.h>

// Relocating loader debug option
Expand Down Expand Up @@ -241,9 +242,9 @@ start_os:
// Check for correct a.out header

#ifdef CONFIG_ROMFS_FS
movw $0x0600,root_dev // ROMFS is device 6,0
movw $DEV_ROM,root_dev // ROMFS
#else
movw $0x0380,root_dev // floppy is device 3,128
movw $DEV_FD0,root_dev // floppy 0
#endif
mov $CONFIG_ROM_KERNEL_CODE,%ax // DS = ROM a.out image
mov %ax,%ds
Expand Down
89 changes: 45 additions & 44 deletions elks/fs/msdos/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,55 +12,56 @@
#include <linuxmt/errno.h>
#include <linuxmt/string.h>
#include <linuxmt/stat.h>
#include <linuxmt/devnum.h>
#include <linuxmt/debug.h>

#ifdef CONFIG_FS_DEV
/* FAT device table, increase DEVDIR_SIZE and DEVINO_BASE to add entries*/
struct msdos_devdir_entry devnods[DEVDIR_SIZE] = {
{ "hda", S_IFBLK | 0644, MKDEV(3, 0) },
{ "hda1", S_IFBLK | 0644, MKDEV(3, 1) },
{ "hda2", S_IFBLK | 0644, MKDEV(3, 2) },
{ "hda3", S_IFBLK | 0644, MKDEV(3, 3) },
{ "hda4", S_IFBLK | 0644, MKDEV(3, 4) },
{ "hdb", S_IFBLK | 0644, MKDEV(3, 32)},
{ "hdb1", S_IFBLK | 0644, MKDEV(3, 33)},
{ "hdb2", S_IFBLK | 0644, MKDEV(3, 34)},
{ "hdb3", S_IFBLK | 0644, MKDEV(3, 35)},
{ "hdb4", S_IFBLK | 0644, MKDEV(3, 36)},
{ "hdc", S_IFBLK | 0644, MKDEV(3, 64)},
{ "hdc1", S_IFBLK | 0644, MKDEV(3, 65)},
{ "hdc2", S_IFBLK | 0644, MKDEV(3, 66)},
{ "hdc3", S_IFBLK | 0644, MKDEV(3, 67)},
{ "hdb4", S_IFBLK | 0644, MKDEV(3, 68)},
{ "hdd", S_IFBLK | 0644, MKDEV(3, 96)},
{ "hdd1", S_IFBLK | 0644, MKDEV(3, 97)},
{ "hdd2", S_IFBLK | 0644, MKDEV(3, 98)},
{ "hdd3", S_IFBLK | 0644, MKDEV(3, 99)},
{ "hdd4", S_IFBLK | 0644, MKDEV(3,100)},
{ "fd0", S_IFBLK | 0644, MKDEV(3,128)},
{ "fd1", S_IFBLK | 0644, MKDEV(3,160)},
{ "fd2", S_IFBLK | 0644, MKDEV(3,192)},
{ "fd3", S_IFBLK | 0644, MKDEV(3,224)},
{ "rd0", S_IFBLK | 0644, MKDEV(1, 0) },
{ "ssd", S_IFBLK | 0644, MKDEV(2, 0) },
{ "kmem", S_IFCHR | 0644, MKDEV(1, 2) },
{ "null", S_IFCHR | 0644, MKDEV(1, 3) },
{ "zero", S_IFCHR | 0644, MKDEV(1, 5) },
{ "tty1", S_IFCHR | 0644, MKDEV(4, 0) },
{ "tty2", S_IFCHR | 0644, MKDEV(4, 1) },
{ "tty3", S_IFCHR | 0644, MKDEV(4, 2) },
{ "ttyS0", S_IFCHR | 0644, MKDEV(4, 64)},
{ "ttyS1", S_IFCHR | 0644, MKDEV(4, 65)},
{ "console",S_IFCHR | 0600, MKDEV(4, 254)},
{ "tty", S_IFCHR | 0666, MKDEV(4, 255)},
{ "ttyp0", S_IFCHR | 0644, MKDEV(4, 8) },
{ "ptyp0", S_IFCHR | 0644, MKDEV(2, 8) },
{ "ttyp1", S_IFCHR | 0644, MKDEV(4, 9) },
{ "ptyp1", S_IFCHR | 0644, MKDEV(2, 9) },
{ "tcpdev", S_IFCHR | 0644, MKDEV(8, 0) },
{ "ne0", S_IFCHR | 0644, MKDEV(9, 0) },
{ "wd0", S_IFCHR | 0644, MKDEV(9, 1) },
{ "3c0", S_IFCHR | 0644, MKDEV(9, 2) },
{ "hda", S_IFBLK | 0644, DEV_HDA },
{ "hda1", S_IFBLK | 0644, DEV_HDA+1 },
{ "hda2", S_IFBLK | 0644, DEV_HDA+2 },
{ "hda3", S_IFBLK | 0644, DEV_HDA+3 },
{ "hda4", S_IFBLK | 0644, DEV_HDA+4 },
{ "hdb", S_IFBLK | 0644, DEV_HDB },
{ "hdb1", S_IFBLK | 0644, DEV_HDB+1 },
{ "hdb2", S_IFBLK | 0644, DEV_HDB+2 },
{ "hdb3", S_IFBLK | 0644, DEV_HDB+3 },
{ "hdb4", S_IFBLK | 0644, DEV_HDB+4 },
{ "hdc", S_IFBLK | 0644, DEV_HDC },
{ "hdc1", S_IFBLK | 0644, DEV_HDC+1 },
{ "hdc2", S_IFBLK | 0644, DEV_HDC+2 },
{ "hdc3", S_IFBLK | 0644, DEV_HDC+3 },
{ "hdc4", S_IFBLK | 0644, DEV_HDC+4 },
{ "hdd", S_IFBLK | 0644, DEV_HDD },
{ "hdd1", S_IFBLK | 0644, DEV_HDD+1 },
{ "hdd2", S_IFBLK | 0644, DEV_HDD+2 },
{ "hdd3", S_IFBLK | 0644, DEV_HDD+3 },
{ "hdd4", S_IFBLK | 0644, DEV_HDD+4 },
{ "fd0", S_IFBLK | 0644, DEV_FD0 },
{ "fd1", S_IFBLK | 0644, DEV_FD1 },
{ "fd2", S_IFBLK | 0644, DEV_FD2 },
{ "fd3", S_IFBLK | 0644, DEV_FD3 },
{ "rd0", S_IFBLK | 0644, MKDEV(RAM_MAJOR, 0) },
{ "ssd", S_IFBLK | 0644, MKDEV(SSD_MAJOR, 0) },
{ "kmem", S_IFCHR | 0644, MKDEV(MEM_MAJOR, 2) },
{ "null", S_IFCHR | 0644, MKDEV(MEM_MAJOR, 3) },
{ "zero", S_IFCHR | 0644, MKDEV(MEM_MAJOR, 5) },
{ "tty1", S_IFCHR | 0644, MKDEV(TTY_MAJOR, 0) },
{ "tty2", S_IFCHR | 0644, MKDEV(TTY_MAJOR, 1) },
{ "tty3", S_IFCHR | 0644, MKDEV(TTY_MAJOR, 2) },
{ "ttyS0", S_IFCHR | 0644, MKDEV(TTY_MAJOR, 64) },
{ "ttyS1", S_IFCHR | 0644, MKDEV(TTY_MAJOR, 65) },
{ "console",S_IFCHR | 0600, MKDEV(TTY_MAJOR, 254) },
{ "tty", S_IFCHR | 0666, MKDEV(TTY_MAJOR, 255) },
{ "ttyp0", S_IFCHR | 0644, MKDEV(TTY_MAJOR, 8) },
{ "ttyp1", S_IFCHR | 0644, MKDEV(TTY_MAJOR, 9) },
{ "ptyp0", S_IFCHR | 0644, MKDEV(PTY_MASTER_MAJOR, 8) },
{ "ptyp1", S_IFCHR | 0644, MKDEV(PTY_MASTER_MAJOR, 9) },
{ "tcpdev", S_IFCHR | 0644, MKDEV(TCPDEV_MAJOR, 0) },
{ "ne0", S_IFCHR | 0644, MKDEV(ETH_MAJOR, 0) },
{ "wd0", S_IFCHR | 0644, MKDEV(ETH_MAJOR, 1) },
{ "3c0", S_IFCHR | 0644, MKDEV(ETH_MAJOR, 2) },
};
#endif

Expand Down
3 changes: 2 additions & 1 deletion elks/fs/super.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <linuxmt/mm.h>
#include <linuxmt/fs.h>
#include <linuxmt/kdev_t.h>
#include <linuxmt/devnum.h>
#include <linuxmt/debug.h>

#include <arch/system.h>
Expand Down Expand Up @@ -491,7 +492,7 @@ void mount_root(void)
} while (*(++fs_type) && !retval);

#ifdef CONFIG_BLK_DEV_BIOS
if (ROOT_DEV == 0x0380) {
if (ROOT_DEV == DEV_FD0) {
if (!filp->f_op->release)
printk("Release not defined\n");
close_filp(d_inode, filp);
Expand Down
32 changes: 32 additions & 0 deletions elks/include/linuxmt/devnum.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#ifndef __LINUXMT_DEVNUM_H
#define __LINUXMT_DEVNUM_H

#include <linuxmt/major.h>
#include <linuxmt/kdev_t.h>

/*
* Device numbers for block and character devices
*
* NOTE: If a block device MINOR_SHIFT changes, must be updated here also.
*/

/* block devices */
#define DEV_HDA MKDEV(BIOSHD_MAJOR, 0)
#define DEV_HDB MKDEV(BIOSHD_MAJOR, 32)
#define DEV_HDC MKDEV(BIOSHD_MAJOR, 64)
#define DEV_HDD MKDEV(BIOSHD_MAJOR, 96)
#define DEV_FD0 MKDEV(BIOSHD_MAJOR, 128)
#define DEV_FD1 MKDEV(BIOSHD_MAJOR, 160)
#define DEV_FD2 MKDEV(BIOSHD_MAJOR, 192)
#define DEV_FD3 MKDEV(BIOSHD_MAJOR, 224)
#define DEV_ROM MKDEV(ROMFLASH_MAJOR, 0)

/* char devices */
#define DEV_TTY1 MKDEV(TTY_MAJOR, 0)
#define DEV_TTY2 MKDEV(TTY_MAJOR, 1)
#define DEV_TTY3 MKDEV(TTY_MAJOR, 2)
#define DEV_TTYS0 MKDEV(TTY_MAJOR, 64)
#define DEV_TTYS1 MKDEV(TTY_MAJOR, 65)


#endif /* !__LINUXMT_DEVNUM_H */
3 changes: 1 addition & 2 deletions elks/include/linuxmt/dirent.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
#define __LINUXMT_DIRENT_H

#include <linuxmt/types.h>

#define MAXNAMLEN 26 /* 14 for MINIX, 26 for FAT */
#include <linuxmt/limits.h>

struct dirent {
u_ino_t d_ino;
Expand Down
7 changes: 0 additions & 7 deletions elks/include/linuxmt/fs.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,6 @@

#endif /* __KERNEL__ */

/*
* Now the file code is no longer dependent on bitmaps in unsigned
* longs, but uses the new fd_set structure..
*/

#define NR_OPEN 20

#define BLOCK_SIZE 1024
#define BLOCK_SIZE_BITS 10

Expand Down
14 changes: 10 additions & 4 deletions elks/include/linuxmt/kdev_t.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,20 @@
/* Some programs want their definitions of MAJOR and MINOR and MKDEV
* from the kernel sources. Here we use unsigned short instead of __u16.
*/
#ifdef __ASSEMBLER__
#define _CAST_U16
#else
#define _CAST_U16 (unsigned short)
#endif

#define MINORBITS 8
#define MINORMASK ((1 << MINORBITS) - 1)
#define MAJOR(dev) ((unsigned short) ((dev) >> MINORBITS))
#define MINOR(dev) ((unsigned short) ((dev) & MINORMASK))
#define MKDEV(major,minor) ((unsigned short) (((major) << MINORBITS) | (minor)))
#define MAJOR(dev) (_CAST_U16 ((dev) >> MINORBITS))
#define MINOR(dev) (_CAST_U16 ((dev) & MINORMASK))
#define MKDEV(major,minor) (_CAST_U16 (((major) << MINORBITS) | (minor)))
#define NODEV MKDEV(0,0)

#ifdef __KERNEL__
#if defined(__KERNEL__) && !defined(__ASSEMBLER__)
#include <arch/types.h>

typedef __u16 kdev_t;
Expand Down
7 changes: 5 additions & 2 deletions elks/include/linuxmt/limits.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#ifdef CONFIG_ASYNCIO
#define KSTACK_BYTES 700 /* Size of kernel stacks w/async I/O */
#else
#define KSTACK_BYTES 640 /* Size of kernel stacks w/sync I/O */
#define KSTACK_BYTES 640 /* Size of kernel stacks w/o async I/O */
#endif
#endif

Expand All @@ -34,10 +34,13 @@
/* filesystem */
#define NR_INODE 96 /* this should be bigger than NR_FILE */
#define NR_FILE 64 /* this can well be larger on a larger system */
#define NR_SUPER 6 /* max mounts */
#define NR_OPEN 20 /* Max open files per process */
#define NR_SUPER 6 /* Max mounts */

#define PIPE_BUFSIZ 80 /* doesn't have to be power of two */

#define MAXNAMLEN 26 /* Max filename, 14 for MINIX, 26 for FAT (not tunable) */

#define NR_ALARMS 5 /* Max number of simultaneous alarms system-wide */

#define MAX_PACKET_ETH 1536 /* Max packet size, 6 blocks of 256 bytes */
Expand Down
26 changes: 14 additions & 12 deletions elks/init/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <linuxmt/utsname.h>
#include <linuxmt/netstat.h>
#include <linuxmt/trace.h>
#include <linuxmt/devnum.h>
#include <arch/system.h>
#include <arch/segment.h>
#include <arch/ports.h>
Expand Down Expand Up @@ -252,17 +253,18 @@ static struct dev_name_struct {
const char *name;
int num;
} devices[] = {
/* root_dev_name needs first 5 in order*/
{ "hda", 0x0300 },
{ "hdb", 0x0320 },
{ "hdc", 0x0340 },
{ "hdd", 0x0360 },
{ "fd0", 0x0380 },
{ "fd1", 0x03a0 },
{ "ttyS", 0x0440 },
{ "tty1", 0x0400 },
{ "tty2", 0x0401 },
{ "tty3", 0x0402 },
/* the 4 partitionable drives must be first */
{ "hda", DEV_HDA },
{ "hdb", DEV_HDB },
{ "hdc", DEV_HDC },
{ "hdd", DEV_HDD },
{ "fd0", DEV_FD0 },
{ "fd1", DEV_FD1 },
{ "ttyS0", DEV_TTYS0 },
{ "ttyS1", DEV_TTYS1 },
{ "tty1", DEV_TTY1 },
{ "tty2", DEV_TTY2 },
{ "tty3", DEV_TTY3 },
{ NULL, 0 }
};

Expand All @@ -282,7 +284,7 @@ static char * INITPROC root_dev_name(int dev)
if (i < 4) {
if (dev & 0x07) {
name[NAMEOFF+3] = '0' + (dev & 7);
name[NAMEOFF+4] = 0;
name[NAMEOFF+4] = '\0';
}
}
return name;
Expand Down
50 changes: 4 additions & 46 deletions elkscmd/disk_utils/df.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ struct dnames {
char *name;
char *mpoint;
};
struct dnames *devname(char *);
static char *dev_name(dev_t);
struct dnames *device_path(char *);
int df_fat(char *, int);

int iflag= 0; /* Focus on inodes instead of blocks. */
Expand Down Expand Up @@ -85,7 +84,7 @@ int main(int argc, char *argv[])
if (argc > 1)
device = argv[1];

dname = devname(device);
dname = device_path(device);
if (!(blockdev = dname->name)) {
fprintf(stderr, "Can't find /dev/ device for %s\n", device);
exit(1);
Expand All @@ -105,7 +104,7 @@ int main(int argc, char *argv[])
int i;
for (i = 0; i < NR_SUPER; i++) {
if (ustatfs(i, &statfs, UF_NOFREESPACE) >= 0) {
char *nm = dev_name(statfs.f_dev);
char *nm = devname(statfs.f_dev, S_IFBLK);
char *filler = " "; /* Text alignment */
if (Pflag) filler = "";
if (statfs.f_type > FST_MSDOS || (statfs.f_type == FST_MSDOS && (Pflag||iflag)))
Expand Down Expand Up @@ -277,7 +276,7 @@ bit_t bit_count(unsigned blocks, bit_t bits, int fd)
*/

/* return /dev/ device from dirname */
struct dnames *devname(char *dirname)
struct dnames *device_path(char *dirname)
{
static char dev[] = "/dev";
struct stat st, dst;
Expand Down Expand Up @@ -322,44 +321,3 @@ struct dnames *devname(char *dirname)
closedir(fp);
return NULL;
}

/*
* Convert a block device number to name.
* From mount.c
*/
static struct dev_name_struct {
char *name;
dev_t num;
} devices[] = {
/* root_dev_name needs first 5 in order*/
{ "hda", 0x0300 },
{ "hdb", 0x0320 },
{ "hdc", 0x0340 },
{ "hdd", 0x0360 },
{ "fd0", 0x0380 },
{ "fd1", 0x03a0 },
{ "ssd", 0x0200 },
{ "rd", 0x0100 },
{ NULL, 0 }
};

static char *dev_name(dev_t dev)
{
int i;
#define NAMEOFF 5
static char name[10] = "/dev/";

for (i=0; i<sizeof(devices)/sizeof(devices[0])-1; i++) {
if (devices[i].num == (dev & 0xfff0)) {
strcpy(&name[NAMEOFF], devices[i].name);
if (i < 4) {
if (dev & 0x07) {
name[NAMEOFF+3] = '0' + (dev & 7);
name[NAMEOFF+4] = 0;
}
}
return name;
}
}
return NULL;
}
4 changes: 2 additions & 2 deletions elkscmd/screen/screen.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ extern char AnsiVersion[];
extern flowctl;
extern errno;
extern sys_nerr;
extern char *getenv(), *MakeTermcap();
extern char *getlogin(), *ttyname();
extern char *MakeTermcap();
extern char *getlogin();
static AttacherFinit(), Finit(), SigHup(), SigChld();
static char *MakeBellMsg(), *Filename(), **SaveArgs(), *GetTtyName();

Expand Down
Loading

0 comments on commit 51b8bcc

Please sign in to comment.