Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

Set files Attriutes

 
Post new topic   Reply to topic    www.mcselec.com Forum Index -> AVR-DOS
View previous topic :: View next topic  
Author Message
pedro

Bascom Member



Joined: 24 Apr 2009
Posts: 128

portugal.gif
PostPosted: Mon Jun 15, 2009 1:19 pm    Post subject: Set files Attriutes Reply with quote

Hello

In AVR-DOS exists the function GetAttr to read the files Attributes. Is there a possibility to SET with AVR-DOS the Files Attributes?

Thanks

Regards
Sato
Back to top
View user's profile
AdrianJ

Bascom Expert



Joined: 16 Jan 2006
Posts: 2483
Location: Queensland

australia.gif
PostPosted: Thu Jun 18, 2009 12:08 am    Post subject: Reply with quote

There is a library call to read the file attribute, but not to write it back, at least I did not find one.

Presumably you only need to protect the file when its in a PC ? If your users are likely to overwrite the file there, then just setting the attribute will not stop them.

_________________
Adrian Jansen
Computer language is a framework for creativity
Back to top
View user's profile Visit poster's website
pedro

Bascom Member



Joined: 24 Apr 2009
Posts: 128

portugal.gif
PostPosted: Thu Jun 18, 2009 10:49 pm    Post subject: Reply with quote

Hello Adrianj

Not on the PC, i want to change the file atributes on the sd card in my board with Bascom

Regards
Sato
Back to top
View user's profile
AdrianJ

Bascom Expert



Joined: 16 Jan 2006
Posts: 2483
Location: Queensland

australia.gif
PostPosted: Thu Jun 18, 2009 11:04 pm    Post subject: Reply with quote

Why precisely do you need to change the attribute at the Bascom end ? You have full control over what is written there, and can avoid an overwrite or delete. In any case I doubt that AVR-DOS respects the attribute, ie I would think that it would happily delete a file even if the read-only bit was set ( but I havent tried it ).
_________________
Adrian Jansen
Computer language is a framework for creativity
Back to top
View user's profile Visit poster's website
pedro

Bascom Member



Joined: 24 Apr 2009
Posts: 128

portugal.gif
PostPosted: Fri Jun 19, 2009 11:03 am    Post subject: Reply with quote

Hello Adrianj

The situation is the following: I have a program in the PC that makes in loop a wireless scan of my boards, on that i have a sd card. Everytime in the scan process, the boards send files to the PC.
The reason to want change the files attributes in the sd card is to change it to only read the files that have sucessfull receibed on the PC. Than on next scan process i checked the files attributes and the files that are only read i donīt need to send it again.

Regards
Sato
Back to top
View user's profile
AdrianJ

Bascom Expert



Joined: 16 Jan 2006
Posts: 2483
Location: Queensland

australia.gif
PostPosted: Sun Jun 21, 2009 8:22 am    Post subject: Reply with quote

I see. So you are looking at something like the archive attribute. But maybe you could do the same thing by looking at the file date/time. If you keep track of the last date/time the file was transferred, then only send it again if the date/time is changed, that achieves the same result. Maybe not as simple as the archive bit, but it should work.

It might also be worth asking Josef directly whether he has a routine to write to the archive bit. It should not be that difficult to do, just identify the byte in the directory structure, and change the correct bit.

_________________
Adrian Jansen
Computer language is a framework for creativity
Back to top
View user's profile Visit poster's website
pedro

Bascom Member



Joined: 24 Apr 2009
Posts: 128

portugal.gif
PostPosted: Tue Jun 23, 2009 11:57 am    Post subject: Reply with quote

Hello Adrianj

Thank You for your great help on this Forum.
Yes, perhaps can Josef do that, than for my purpose there is the easy and best way.

Regards
Pedro
Back to top
View user's profile
oe9vfj

Moderator



Joined: 17 Jun 2004
Posts: 269
Location: Austria, Hard

austria.gif
PostPosted: Wed Aug 12, 2009 1:28 pm    Post subject: Reply with quote

Hi Pedro

You can test following function to set the Read-Only Attribut-Bit.

Code:
Function SetReadAttr(strFileName as String, byval bAttr as Byte) as Byte

_SetReadAttr:
   ldd xl, Y+2                          ' Pointer to filename to X
   ldd xh, Y+3

   !call _SearchDirEntry_CheckFileName ' with norming file name and checking wildcard
   brcc _SetReadAttr2
   ' If not Found or other Error leave with Error-code
   rjmp _SetReadAttr3

_SetReadAttr2:
   ldd xl, Y+0                           ' Pointer to new attribut to X
   ldd xh, Y+1
   ld r25, X                             ' Attribut Parameter to r25
   ldd r24, Z+11                         ' file-attribut from directory
   bst r25, 0                            ' transfer attribut-Bit to
   bld r24, 0                            ' File Attribut-byte
   std Z+11, r24                         ' store back to directory
   !call _SetDIRWritePending            ' set flag to write directory-buffer to disk
   !call _SaveSector_DIR                ' save Directory-Sector
   clr r25                               ' Return-Code is 0
_SetReadAttr3:
   ldd xl, Y+4                           ' Pointer to return-Byte
   ldd xh, Y+5
   st X, r25                             ' Store return-value

End Function



Somewhere at the top of the program you have to declare the function

Code:
Function SetReadAttr(strFileName as String, byval bAttr as Byte) as Byte


you can use the function like this

Code:
Dim FileName as String * 12
Dim bReturn as Byte


FileName = "Test.txt"

bReturn = SetReadAttr ( FileName, 1)   ' Set Read Only to 1

bReturn = SetReadAttr ( FileName, 0)   ' set Read Only to 0 (Write allowed)


The return-value is the error-code of AVR-DOS. IF 0, setting of the read-only attribut bit was OK, if > 0, there was an error, check the AVR-DOS Error-Code.

_________________
regards Josef

DOS - File System for BASCOM-AVR on http://members.aon.at/voegel
Back to top
View user's profile Visit poster's website
pedro

Bascom Member



Joined: 24 Apr 2009
Posts: 128

portugal.gif
PostPosted: Mon Aug 17, 2009 5:06 pm    Post subject: Reply with quote

Hello Josef

Thanks again for Your help.
I will test it the next days, and send Feedback

Regards
Pedro
Back to top
View user's profile
Display posts from previous:   
Post new topic   Reply to topic    www.mcselec.com Forum Index -> AVR-DOS All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum