473,326 Members | 2,081 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

File operations in Linux

Hello all:

I'm writing a small assembly program that will open a file, process
it, then close it again. I'm trying to build a simple "framework" for it
at the moment. I've got the open, close, and exit system calls in place,
but I think there's something wrong.

My code is below. It seems to work OK, it just runs silently as given
below. But if I try it with a non-existent file (e.g. change /dev/zero to
/dev/zer) then no error message is produced.

Thanks for any advice!
section .text

path db "/dev/zero",0x00

global _start
_start:
mov eax,5 ; open
mov ebx,path
xor ecx,ecx ; O_RDONLY
mov edx,0x100 ; S_IRUSR
int 0x80

xchg eax,ebx ; put fd into ebx
mov eax,6 ; close
int 0x80

mov eax,1 ; exit
int 0x80

Jun 27 '08 #1
13 3109
On 26 May 2008 at 10:11, kid joe wrote:
My code is below. It seems to work OK, it just runs silently as given
below. But if I try it with a non-existent file (e.g. change /dev/zero
to /dev/zer) then no error message is produced.
That's hardly surprising - you didn't tell it to produce an error
message! If you use a non-existent file, then the open() system call
*will* thoughtfully inform your program that there was a problem, by
returning a negative nunber in eax. You just choose to ignore this...

A couple of other things: as you're not creating a file, the mode
argument to open() is ignored, so there's no point putting anything
special in edx beforehand. There's no need for the xchg instruction when
you immediately clobber eax anyway. And you don't return a sensible exit
status to the shell at the end.

Here's your code with these things fixed up:
section .data

path db "/dev/zero",0x00
errmsg db "Error opening file!",0x0A
errlen equ $-errmsg

section .text

global _start
_start:
mov eax,5 ; open
mov ebx,path
xor ecx,ecx ; O_RDONLY
int 0x80

or eax,eax
jns cont

; error opening file...
mov eax,4 ; write
mov ebx,2 ; stderr
mov ecx,errmsg
mov edx,errlen
int 0x80
mov ebx,1 ; return failure status
jmp finish

cont:
mov ebx,eax ; put fd into ebx
mov eax,6 ; close
int 0x80
xor ebx,ebx ; return success status

finish:
mov eax,1 ; exit
int 0x80

Jun 27 '08 #2

"Antoninus Twink" <no****@nospam.invalidwrote in message
On 26 May 2008 at 10:11, kid joe wrote:
global _start
_start:
mov eax,5 ; open
mov ebx,path
xor ecx,ecx ; O_RDONLY
int 0x80
This is indisputably off-topic. Please protect the newsgroup by not replying
here.

--
Free games and programming goodies.
http://www.personal.leeds.ac.uk/~bgy1mm
Jun 27 '08 #3
On Mon, 26 May 2008 12:20:21 +0100, Malcolm McLean wrote:
>
"Antoninus Twink" <no****@nospam.invalidwrote in message
>On 26 May 2008 at 10:11, kid joe wrote:
global _start
_start:
mov eax,5 ; open
mov ebx,path
xor ecx,ecx ; O_RDONLY
int 0x80
This is indisputably off-topic. Please protect the newsgroup by not replying
here.
Thanks a lot to AT for the advice.

Sorry it's a bit off-topic. I thought about posting to comp.lang.asm.x86
but that's a moderated newsgroup so it would take possibly days to get an
answer by the time your message is approved then any replies are approved.
This group seemed close enough and I've got my question answered so thanks.

Jun 27 '08 #4
kid joe wrote:
On Mon, 26 May 2008 12:20:21 +0100, Malcolm McLean wrote:
>"Antoninus Twink" <no****@nospam.invalidwrote in message
>>On 26 May 2008 at 10:11, kid joe wrote:
global _start
_start:
mov eax,5 ; open
mov ebx,path
xor ecx,ecx ; O_RDONLY
int 0x80
This is indisputably off-topic. Please protect the newsgroup by not replying
here.

Thanks a lot to AT for the advice.

Sorry it's a bit off-topic. I thought about posting to comp.lang.asm.x86
but that's a moderated newsgroup so it would take possibly days to get an
answer by the time your message is approved then any replies are approved.
This group seemed close enough and I've got my question answered so thanks.
It's not "a bit" off-topic, it's completely off-topic.
The question had absolutely nothing to do with C; there
wasn't even a fragment of C-like code anywhere connected
with it. Twink does everyone, even you, a disservice when
he or she rewards your self-centered impatience.

--
Eric Sosman
es*****@ieee-dot-org.invalid
Jun 27 '08 #5
kid joe wrote:
On Mon, 26 May 2008 12:20:21 +0100, Malcolm McLean wrote:
>>
"Antoninus Twink" <no****@nospam.invalidwrote in message
>>On 26 May 2008 at 10:11, kid joe wrote:
global _start
_start:
mov eax,5 ; open
mov ebx,path
xor ecx,ecx ; O_RDONLY
int 0x80
This is indisputably off-topic. Please protect the newsgroup by not
replying here.

Thanks a lot to AT for the advice.

Sorry it's a bit off-topic.
That the understatemenmt of the month, in not of the decade...
I thought about posting to
comp.lang.asm.x86 but that's a moderated newsgroup so it would take
possibly days to get an answer by the time your message is approved
then any replies are approved. This group seemed close enough and
This group seemed close enough
This goup is by no means close enough, here we don't discuss either
assembler, open or Linux, there are other newsgroups dedicated to that
(comp.lang.asm.x86, comp.unix.programmer and comp.os.linux.* respectively).

Bye, Jojo
Jun 27 '08 #6
In article <Zc******************************@bt.com>,
Malcolm McLean <re*******@btinternet.comwrote:
>
"Antoninus Twink" <no****@nospam.invalidwrote in message
>On 26 May 2008 at 10:11, kid joe wrote:
global _start
_start:
mov eax,5 ; open
mov ebx,path
xor ecx,ecx ; O_RDONLY
int 0x80
This is indisputably off-topic. Please protect the newsgroup by not replying
here.
The newsgroup must be awfully fragile if this post is capable of harming
it.

Jun 27 '08 #7
kid joe wrote:
On Mon, 26 May 2008 12:20:21 +0100, Malcolm McLean wrote:
>>
"Antoninus Twink" <no****@nospam.invalidwrote in message
>>On 26 May 2008 at 10:11, kid joe wrote:
global _start
_start:
mov eax,5 ; open
mov ebx,path
xor ecx,ecx ; O_RDONLY
int 0x80
This is indisputably off-topic. Please protect the newsgroup by not
replying here.

Thanks a lot to AT for the advice.

Sorry it's a bit off-topic. I thought about posting to
comp.lang.asm.x86 but that's a moderated newsgroup so it would take
possibly days to get an answer by the time your message is approved
then any replies are approved. This group seemed close enough and I've
got my question answered so thanks.
The experts in alt.lang.asm are just itching for challenging posts from
newbies. And it's unmoderated. Next time try there.

Jun 27 '08 #8
kid joe wrote:

Thanks a lot to AT for the advice.
Twink is a troll, who has used you as a pawn in his on-going attempt to
disrupt the newsgroup. As such, it's not doing you very much good.
Should you in the future have a legitimate question for the group,
you'll be less likely to get advice from the very knowledgable people
here.


Brian
Jun 27 '08 #9
"Kenny McCormack" <ga*****@xmission.xmission.comwrote in message
In article <Zc******************************@bt.com>,
Malcolm McLean <re*******@btinternet.comwrote:
>>
"Antoninus Twink" <no****@nospam.invalidwrote in message
>>On 26 May 2008 at 10:11, kid joe wrote:
global _start
_start:
mov eax,5 ; open
mov ebx,path
xor ecx,ecx ; O_RDONLY
int 0x80
This is indisputably off-topic. Please protect the newsgroup by not
replying
here.

The newsgroup must be awfully fragile if this post is capable of harming
it.
Unfortunately that's a characteristic of computers. The trivial is
important. One email from Mr Conue in Nigeria trying to persuade me to allow
him to deposit $15 million of illegal bribes in my bank account is merely
amusing, but they very rapidly mount to a major nuisance.

It's not a face to face conversation, and different social rules apply.

--
Free games and programming goodies.
http://www.personal.leeds.ac.uk/~bgy1mm

Jun 27 '08 #10
"Default User" <de***********@yahoo.comwrites:
kid joe wrote:

>Thanks a lot to AT for the advice.

Twink is a troll, who has used you as a pawn in his on-going attempt to
disrupt the newsgroup. As such, it's not doing you very much good.
Should you in the future have a legitimate question for the group,
you'll be less likely to get advice from the very knowledgable people
here.
Why is this? This is a help group and if he asks a legit questions I am
sure someone will help him quickly.
Jun 27 '08 #11
Eligiusz Narutowicz <el*************@hotmail.comwrote:
"Default User" <de***********@yahoo.comwrites:
kid joe wrote:
Thanks a lot to AT for the advice.
Twink is a troll, who has used you as a pawn in his on-going attempt to
disrupt the newsgroup. As such, it's not doing you very much good.
Should you in the future have a legitimate question for the group,
you'll be less likely to get advice from the very knowledgable people
here.
Why is this? This is a help group and if he asks a legit questions I am
sure someone will help him quickly.
Are you really that dense? This is no all-kind-of-questions-
that-may-come-to-mind help group, this is a group about the
programming language C in case you didn't notice yet. Or do
you want next to answer questions where to buy shoes? Every-
one here is also some kind of "expert" on buying shoes since
probably all here bought some pairs, but that doesn't make it
topical HERE. If you want a group where all and every question
gets aneswered then go through the process of creating it and
good luck. I guess we can then send all the people with off-
topic questions there.

--
\ Jens Thoms Toerring ___ jt@toerring.de
\__________________________ http://toerring.de
Jun 27 '08 #12
Jens Thoms Toerring said:
Eligiusz Narutowicz <el*************@hotmail.comwrote:
<snip>
>This is a help group and if he asks a legit questions I am
sure someone will help him quickly.

Are you really that dense?
Yes, he's really that dense. If you find that hard to believe, look at his
track record.

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Jun 27 '08 #13
jt@toerring.de (Jens Thoms Toerring) writes:
Eligiusz Narutowicz <el*************@hotmail.comwrote:
>"Default User" <de***********@yahoo.comwrites:
kid joe wrote:

Thanks a lot to AT for the advice.

Twink is a troll, who has used you as a pawn in his on-going attempt to
disrupt the newsgroup. As such, it's not doing you very much good.
Should you in the future have a legitimate question for the group,
you'll be less likely to get advice from the very knowledgable people
here.
>Why is this? This is a help group and if he asks a legit questions I am
sure someone will help him quickly.

Are you really that dense? This is no all-kind-of-questions-
that-may-come-to-mind help group, this is a group about the
programming language C in case you didn't notice yet. Or do
you want next to answer questions where to buy shoes? Every-
one here is also some kind of "expert" on buying shoes since
probably all here bought some pairs, but that doesn't make it
topical HERE. If you want a group where all and every question
gets aneswered then go through the process of creating it and
good luck. I guess we can then send all the people with off-
topic questions there.
Erm, he said "legit questions". Default Jobsworth was saying people
would not help him with on topic, legitimate questions. I think you owe
the poster an apology.

Its good to pop back and see the usual arrogant, preening wannabes
strutting around and being as rude and obnoxious as possible. What a
hoot.
Jun 27 '08 #14

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

48
by: Joseph | last post by:
Hi I'm writing a commercial program which must be reliable. It has to do some basic reading and writing to and from files on the hard disk, and also to a floppy. I have foreseen a potential...
1
by: vin pane | last post by:
your code will not work to flush the previous contents. okey I want three line code. main() { getchar(); sleep(); eat_stdin(); // flush_stdin --- some code here to remove what user is...
5
by: JG | last post by:
Hi all, Does anyone know how the implementations on Linux and Windows handle synchronization between a read and write FD open to the same file. For example, if I have 2 FD open to file X.txt. ...
6
by: the friendly display name | last post by:
Hello, When it's needed to upload a file, and get the name of it: uploadfile is a HtmlInputFile type: string NameOfFile = uploadfile.PostedFile.FileName; NameOfFile will not only get the...
68
by: vim | last post by:
hello everybody Plz tell the differance between binary file and ascii file............... Thanks in advance vim
9
by: Julien Biezemans | last post by:
Hi! Here is the problem: I'd like to restrict local filesystem stream operations to one directory just like a root jail. fopen('/file.bin') would actually open /some/path/file.bin. One goal...
9
by: Claudio Grondi | last post by:
I am aware, that it is maybe the wrong group to ask this question, but as I would like to know the history of past file operations from within a Python script I see a chance, that someone in this...
2
by: Remi.Arntzen | last post by:
I tried to compile a program to a elf shared library for a Linux platform on a windows machine with the command: gcc -o Prog.so -shared -Wl,--oformat -Wl,elf32-i386 however this results in ld:...
4
by: Tony B | last post by:
I've moved an existing site (which I didn't write) from a apache/php/mysql host under windows to a linux apache/php/mysql host. I've sorted out most problems except one. There is an upload...
8
ashitpro
by: ashitpro | last post by:
Understanding Ext-2 file system:chapter 1 The first block in each Ext2 partition is never managed by the Ext2 filesystem, because it is reserved for the partition boot sector. The rest of the...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.