PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.lang.c > File operations in Linux
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
File operations in Linux

Réponse
 
LinkBack Outils de la discussion
Vieux 26/05/2008, 11h11   #1
kid joe
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut 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

  Réponse avec citation
Vieux 26/05/2008, 11h44   #2
Antoninus Twink
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: File operations in Linux

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

  Réponse avec citation
Vieux 26/05/2008, 12h20   #3
Malcolm McLean
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: File operations in Linux


"Antoninus Twink" <nospam@nospam.invalid> wrote 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


  Réponse avec citation
Vieux 26/05/2008, 14h21   #4
kid joe
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: File operations in Linux

On Mon, 26 May 2008 12:20:21 +0100, Malcolm McLean wrote:

>
> "Antoninus Twink" <nospam@nospam.invalid> wrote 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.

  Réponse avec citation
Vieux 26/05/2008, 14h52   #5
Eric Sosman
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: File operations in Linux

kid joe wrote:
> On Mon, 26 May 2008 12:20:21 +0100, Malcolm McLean wrote:
>
>> "Antoninus Twink" <nospam@nospam.invalid> wrote 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
esosman@ieee-dot-org.invalid
  Réponse avec citation
Vieux 26/05/2008, 15h00   #6
Joachim Schmitz
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: File operations in Linux

kid joe wrote:
> On Mon, 26 May 2008 12:20:21 +0100, Malcolm McLean wrote:
>
>>
>> "Antoninus Twink" <nospam@nospam.invalid> wrote 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


  Réponse avec citation
Vieux 26/05/2008, 15h59   #7
Kenny McCormack
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: File operations in Linux

In article <ZcWdnXkoxrFDAafVnZ2dneKdnZydnZ2d@bt.com>,
Malcolm McLean <regniztar@btinternet.com> wrote:
>
>"Antoninus Twink" <nospam@nospam.invalid> wrote 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.

  Réponse avec citation
Vieux 26/05/2008, 19h01   #8
santosh
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: File operations in Linux

kid joe wrote:

> On Mon, 26 May 2008 12:20:21 +0100, Malcolm McLean wrote:
>
>>
>> "Antoninus Twink" <nospam@nospam.invalid> wrote 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.

  Réponse avec citation
Vieux 26/05/2008, 20h35   #9
Default User
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: File operations in Linux

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
  Réponse avec citation
Vieux 26/05/2008, 21h20   #10
Malcolm McLean
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: File operations in Linux

"Kenny McCormack" <gazelle@xmission.xmission.com> wrote in message
> In article <ZcWdnXkoxrFDAafVnZ2dneKdnZydnZ2d@bt.com>,
> Malcolm McLean <regniztar@btinternet.com> wrote:
>>
>>"Antoninus Twink" <nospam@nospam.invalid> wrote 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

  Réponse avec citation
Vieux 27/05/2008, 13h05   #11
Eligiusz Narutowicz
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: File operations in Linux

"Default User" <defaultuserbr@yahoo.com> writes:

> 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 group and if he asks a legit questions I am
sure someone will him quickly.
  Réponse avec citation
Vieux 27/05/2008, 13h24   #12
Jens Thoms Toerring
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: File operations in Linux

Eligiusz Narutowicz <eligiuszdotnaru@hotmail.com> wrote:
> "Default User" <defaultuserbr@yahoo.com> writes:


> > 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 group and if he asks a legit questions I am
> sure someone will him quickly.


Are you really that dense? This is no all-kind-of-questions-
that-may-come-to-mind 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
  Réponse avec citation
Vieux 27/05/2008, 13h36   #13
Richard Heathfield
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: File operations in Linux

Jens Thoms Toerring said:

> Eligiusz Narutowicz <eligiuszdotnaru@hotmail.com> wrote:


<snip>

>> This is a group and if he asks a legit questions I am
>> sure someone will 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
  Réponse avec citation
Vieux 27/05/2008, 15h04   #14
Richard
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: File operations in Linux

jt@toerring.de (Jens Thoms Toerring) writes:

> Eligiusz Narutowicz <eligiuszdotnaru@hotmail.com> wrote:
>> "Default User" <defaultuserbr@yahoo.com> writes:

>
>> > 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 group and if he asks a legit questions I am
>> sure someone will him quickly.

>
> Are you really that dense? This is no all-kind-of-questions-
> that-may-come-to-mind 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 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.


  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 14h06.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,20736 seconds with 22 queries