chore: sync repo
This commit is contained in:
parent
5861542ef8
commit
8ad9864c38
68
libfs/dir.c
68
libfs/dir.c
|
@ -65,7 +65,73 @@ fs_dir_link(struct fs_inode *dp, const char *name, uint32_t inum)
|
|||
{
|
||||
return (-1);
|
||||
}
|
||||
fs_inode_update(dp);
|
||||
|
||||
ip = fs_inode_get(dp->super, inum);
|
||||
if (ip->valid == 0)
|
||||
{
|
||||
fs_inode_read(ip);
|
||||
}
|
||||
ip->inode.nlink += 1;
|
||||
|
||||
fs_inode_update(ip);
|
||||
fs_inode_release(ip);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
int
|
||||
fs_dir_unlink(struct fs_inode *dp, const char *name)
|
||||
{
|
||||
int offset;
|
||||
struct fs_inode *ip;
|
||||
struct stpdfs_dirent dirent;
|
||||
|
||||
ip = fs_dir_lookup(dp, name, 0);
|
||||
if (ip == NULL)
|
||||
{
|
||||
return (-1);
|
||||
}
|
||||
|
||||
ip->inode.nlink -= 1;
|
||||
|
||||
fs_inode_update(ip);
|
||||
fs_inode_release(ip);
|
||||
|
||||
for (offset = 0; offset < dp->inode.size; offset += STPDFS_DIRENT_SIZE)
|
||||
{
|
||||
fs_read(dp, (uint8_t *)&dirent, offset, STPDFS_DIRENT_SIZE);
|
||||
if (strncmp(dirent.filename, name, STPDFS_NAME_MAX) == 0)
|
||||
{
|
||||
memset(dirent.filename, 0, STPDFS_NAME_MAX);
|
||||
dirent.inode = 0;
|
||||
fs_write(dp, (uint8_t *)&dirent, offset, STPDFS_DIRENT_SIZE);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
fs_mkdir(struct fs_inode *dp, const char *name)
|
||||
{
|
||||
struct fs_inode *ndp;
|
||||
|
||||
if (!(dp->inode.mode & STPDFS_S_IFDIR))
|
||||
{
|
||||
return (-1);
|
||||
}
|
||||
|
||||
ndp = fs_inode_alloc(dp->super);
|
||||
if (ndp == NULL)
|
||||
{
|
||||
return (-1);
|
||||
}
|
||||
|
||||
ndp->inode.mode |= STPDFS_S_IFDIR;
|
||||
|
||||
fs_dir_link(ndp, ".", ndp->inum);
|
||||
fs_dir_link(ndp, "..", dp->inum);
|
||||
|
||||
fs_dir_link(dp, name, ndp->inum);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
|
|
@ -5,12 +5,13 @@
|
|||
# include "inode.h"
|
||||
|
||||
struct fs_dir {
|
||||
char name[STPDFS_NAME_MAX];
|
||||
uint32_t inum;
|
||||
|
||||
|
||||
struct fs_inode *dp;
|
||||
int offset;
|
||||
};
|
||||
|
||||
struct fs_inode *fs_dir_lookup(struct fs_inode *dp, const char *name, size_t *offset);
|
||||
int fs_dir_link(struct fs_inode *dp, const char *name, uint32_t inum);
|
||||
int fs_dir_unlink(struct fs_inode *dp, const char *name);
|
||||
int fs_mkdir(struct fs_inode *dp, const char *name);
|
||||
|
||||
#endif /* !FS_DIR_H */
|
|
@ -71,7 +71,7 @@ fs_inode_read(struct fs_inode *ip)
|
|||
buff = fs_bio_bread(ip->super->fd, IBLOCK(ip->inum));
|
||||
if (buff == NULL) return (NULL);
|
||||
|
||||
dinode = (struct stpdfs_inode *)buff->data + ip->inum % STPDFS_INODES_PER_BLOCK;;
|
||||
dinode = (struct stpdfs_inode *)buff->data + ip->inum % STPDFS_INODES_PER_BLOCK;
|
||||
memcpy(&ip->inode, dinode, sizeof(struct stpdfs_inode));
|
||||
|
||||
fs_bio_brelse(buff);
|
||||
|
|
|
@ -34,7 +34,6 @@ static struct option long_options[] = {
|
|||
};
|
||||
#endif /* HAVE_STRUCT_OPTION */
|
||||
|
||||
|
||||
static int
|
||||
inspect(void)
|
||||
{
|
||||
|
|
|
@ -11,11 +11,11 @@
|
|||
LF equ 0xA
|
||||
|
||||
struc inode
|
||||
.mode: resb 1
|
||||
.nlink: resb 1
|
||||
.uid: resb 1
|
||||
.gid: resb 1
|
||||
.flags: resb 1
|
||||
.mode: resw 1
|
||||
.nlink: resw 1
|
||||
.uid: resw 1
|
||||
.gid: resw 1
|
||||
.flags: resw 1
|
||||
.size: resd 1
|
||||
.zones: resd 10
|
||||
.actime: resq 1
|
||||
|
@ -75,7 +75,7 @@ start:
|
|||
jc .reset_disk
|
||||
|
||||
; read superblock
|
||||
mov ax, DISK_BUFFER/10
|
||||
mov ax, DISK_BUFFER
|
||||
mov es, ax
|
||||
|
||||
; load two sector in memory
|
||||
|
@ -92,29 +92,46 @@ start:
|
|||
; inode 0 bad
|
||||
; inode 1 root dir
|
||||
; inode 2 is loader, let's keep things easy
|
||||
mov ax, word [DISK_BUFFER + 34 * 2 + inode.flags]
|
||||
mov ax, word [DISK_BUFFER + 512 + 0x46 * 2 + inode.flags]
|
||||
and ax, INODE_ALLOCATED
|
||||
jz .err_no_loader
|
||||
|
||||
mov dword eax, [DISK_BUFFER + 34 * 2 + inode.size] ; size
|
||||
mov dword eax, [DISK_BUFFER + 512 + 0x46 * 2 + inode.size] ; size
|
||||
mov dword [uFsize], eax
|
||||
|
||||
xor ecx, ecx
|
||||
.read_loop:
|
||||
xchg bx, bx
|
||||
|
||||
xor ecx, ecx
|
||||
xor edx, edx
|
||||
mov eax, DISK_BUFFER + 0x46 * 2 + inode.zone ; first zone
|
||||
.read_loop:
|
||||
cmp dword ecx, [uFsize]
|
||||
jg .all_read
|
||||
|
||||
|
||||
.zone_loop:
|
||||
cmp edx, 7
|
||||
jb .zone_direct
|
||||
|
||||
.zone_triple:
|
||||
|
||||
.zone_double:
|
||||
|
||||
.zone_indirect:
|
||||
|
||||
.zone_direct:
|
||||
mov eax, edx
|
||||
shr eax, 2
|
||||
add eax, DISK_BUFFER + 0x46 + 2 + inode.zone
|
||||
|
||||
|
||||
inc edx
|
||||
.end_zone:
|
||||
add ecx, BLOCK_SIZE
|
||||
jmp .read_loop
|
||||
.all_read:
|
||||
|
||||
mov eax, DISK_BUFFER + 34 * 2 + 14 ; first zone
|
||||
|
||||
mov ax, LOADER_BASE/10
|
||||
mov es, ax
|
||||
|
||||
jmp 0x0:LOADER_BASE
|
||||
|
||||
.err_no_loader:
|
||||
mov si, szErrorNoLoader
|
||||
call bios_print
|
||||
|
@ -150,10 +167,11 @@ disk_read_sectors:
|
|||
mov word [disk_packet.segment], es
|
||||
mov word [disk_packet.offset], bx
|
||||
mov dword [disk_packet.lba], eax
|
||||
mov si, [disk_packet]
|
||||
mov si, disk_packet
|
||||
mov dl, [bpb.drive_num]
|
||||
mov ah, 0x42
|
||||
int 0x13
|
||||
jc start.err_lba
|
||||
ret
|
||||
|
||||
disk_packet:
|
||||
|
|
|
@ -1,8 +1,3 @@
|
|||
#include "libfs/dir.h"
|
||||
#include "libfs/fs.h"
|
||||
#include "libfs/inode.h"
|
||||
#include "libfs/super.h"
|
||||
#include "stupidfs.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/stat.h>
|
||||
|
@ -16,6 +11,8 @@
|
|||
#ifdef HAVE_GETOPT_H
|
||||
# include <getopt.h>
|
||||
#endif /* HAVE_GETOPT_H */
|
||||
# include <stupidfs.h>
|
||||
# include "libfs/fs.h"
|
||||
|
||||
#ifdef HAVE_STRUCT_OPTION
|
||||
static struct option long_options[] = {
|
||||
|
@ -75,6 +72,7 @@ do_copy(void)
|
|||
ip->inode.gid = st.st_gid;
|
||||
ip->inode.modtime = st.st_mtime;
|
||||
ip->inode.actime = st.st_atime;
|
||||
ip->inode.flags = STPDFS_INO_FLAG_ALOC;
|
||||
|
||||
fs_inode_update(ip);
|
||||
|
||||
|
@ -151,7 +149,11 @@ copy(int argc, char **argv)
|
|||
|
||||
if (dest == NULL)
|
||||
{
|
||||
dest = src;
|
||||
#ifdef HAVE_LIBGEN_H
|
||||
dest = basename(src);
|
||||
#else
|
||||
dest = src;
|
||||
#endif
|
||||
}
|
||||
|
||||
return (do_copy());
|
||||
|
|
Loading…
Reference in a new issue