From: Frank Kotler <fbkotler@comcast.net>
To: Niel A <amerei@gmail.com>
Cc: "linux-assembly@vger.kernel.org" <linux-assembly@vger.kernel.org>
Subject: Re: help with sys_stat
Date: Sat, 28 Jan 2006 05:41:57 -0500 [thread overview]
Message-ID: <43DB4A75.2040506@comcast.net> (raw)
In-Reply-To: <20060128150139.04fee74e.amerei@gmail.com>
Niel A wrote:
> hey guys! it's me again (with another useless program! hehehehe)
They're *all* useless... until you put the pieces together to do
something useful. (This is on my to-do list...)
> actually.. i have two problems.. how to use struc in nasm.. and how to determine if a file is a directory...
>
> i'm totally clueless about this .. so i used struc straightforward in segment. bss based on struct stat in /usr/include/asm/stat.h
>
> segment .bss
> struc stat
This can go anywhere - like a "%define", it doesn't generate any code.
It's a "typedef". An instance of your struc would want to go in .data,
if it's initialized, or in .bss if you just want to reserve space for it
(this case, I think)... If you "%include 'system.inc'" from asmutils,
you've *got* the "typedef"...
my_stat_buf resb stat_size
> .st_dev resw 1
> -- snip --
... .??? resw 1
... .??? resd 1
... .st_mode resw 1 ; <- this one!
> endstruc
>
> ? but somehow, i think that i should make a struc somewhere at the beginning .. like a prototype of some sort and use it's name in segment .bss intead.
You probably want both. The "typedef" anyplace, and an instance in .bss.
> so far, i have a filename in edi and i call stat like ..
> mov eax, 106 ; stat
> mov ebx, edi ; file
> mov ecx, stat
This may be a problem. You want some memory (stat_size bytes) to point
this at. Just "struc" doesn't allocate memory - you'd want "istruc", or
"stat_size" reserved in .bss, or just subtract it from esp...
> int 80h
>
> any suggestions on this one ? i'm reading asmutil's "rm" alongside making my own program.. but i'm only interested in determining if a given filename is a directory or not. do i also have to deal with trailing slashes in directory names??
I think not. Once you've got the buffer filled, you can just test "mybuf
+ stat.st_mode" for the directory bit. Note that C gives these in
octal!!! "NNNNq" for nasm...
This is pretty crude...
mov eax, 106 ; sys_stat
lea ebx, [edi + 10] ; filename
sub esp, 64 ; stat_size
mov ecx, esp
int 80h
test dword [ecx + 8], 40000q
jz notsubdir
...
(don't forget to add stat_size back onto the stack to "free" the buffer,
if you do it this way!)
Soon, we'll tackle some "time" functions and figure out what in hell
timezone you're in :)
Best,
Frank
prev parent reply other threads:[~2006-01-28 10:41 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-01-28 15:01 help with sys_stat Niel A
2006-01-28 10:41 ` Frank Kotler [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=43DB4A75.2040506@comcast.net \
--to=fbkotler@comcast.net \
--cc=amerei@gmail.com \
--cc=linux-assembly@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.