fs: follow symlinks like Linux; Linux mknod; /proc/partitions
Symlinks are followed in namex_from() now, in the middle of a path as well as at the end, and a relative target resolves from the directory that holds the link rather than from the caller's cwd. `ln -s f d1/s; cat d1/s` said "Symbolic link loop" because it looked for ./f. A loop is ELOOP after 40 links, a dangling link ENOENT, and open(O_CREAT) through a link to a file opens the file. divesymlink() is gone. mknod from a Linux program passes (mode, dev) where the native call passes (major, minor), and was read as the native one: `mknod n c 1 2` made node 432,258, and mkfifo made a character device. Both are decoded now; a FIFO is EPERM, and an existing name is EEXIST. /proc/mounts listed devtmpfs twice: once from a fixed line and once from the mount table. The fixed line is gone, and mount_add() refuses a filesystem mounted on its own root, which is where a second devtmpfs mount lands. A read-only FAT mount says ro. /proc/partitions exists, in Linux's format, and /proc/filesystems lists vfat. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01S1giNvrHTrPMPw7V6x1kQ4
This commit is contained in:
parent
edb560de66
commit
7a1e63a553
8 changed files with 274 additions and 136 deletions
|
|
@ -372,23 +372,35 @@ putu(char *buf, int cap, int off, uint64 v)
|
|||
return off;
|
||||
}
|
||||
|
||||
// putu(), right-aligned in `w` columns, the way printf("%*llu") would.
|
||||
static int
|
||||
putw(char *buf, int cap, int off, uint64 v, int w)
|
||||
{
|
||||
int n = 1;
|
||||
for (uint64 t = v; t >= 10; t /= 10)
|
||||
n++;
|
||||
for (; w > n; w--)
|
||||
off = put(buf, cap, off, " ");
|
||||
return putu(buf, cap, off, v);
|
||||
}
|
||||
|
||||
// /proc/partitions, in Linux's format to the column, because that is what
|
||||
// reads it: lsblk's fallback, fdisk -l, every installer and rescue script.
|
||||
// Sizes are in 1 KB blocks. The major is 8 for all of them, the one devtmpfs
|
||||
// gives every disk here, and the minor is the device number, as in /dev.
|
||||
int
|
||||
blkdev_info(char *buf, int cap)
|
||||
{
|
||||
int off = put(buf, cap, 0, "dev name MB type\n");
|
||||
int off = put(buf, cap, 0, "major minor #blocks name\n\n");
|
||||
for (int s = 0; s < NBLKDEV; s++) {
|
||||
struct blkdev *d = &devs[s];
|
||||
if (!d->used)
|
||||
continue;
|
||||
off = putu(buf, cap, off, BLKDEV_FIRST + s);
|
||||
off = put(buf, cap, off, " ");
|
||||
off = putw(buf, cap, off, 8, 4);
|
||||
off = putw(buf, cap, off, BLKDEV_FIRST + s, 8);
|
||||
off = putw(buf, cap, off, (d->nsectors * d->secsize) >> 10, 11);
|
||||
off = put(buf, cap, off, " ");
|
||||
off = put(buf, cap, off, d->name);
|
||||
for (int pad = 12 - strlen(d->name); pad > 0; pad--)
|
||||
off = put(buf, cap, off, " ");
|
||||
off = putu(buf, cap, off, (d->nsectors * d->secsize) >> 20);
|
||||
off = put(buf, cap, off, d->parent < 0 ? " disk" :
|
||||
d->schfs > 0 ? " schfs" :
|
||||
d->schfs < 0 ? " fat" : " part");
|
||||
off = put(buf, cap, off, "\n");
|
||||
}
|
||||
return off;
|
||||
|
|
|
|||
Loading…
Reference in a new issue