Helps needs to under stand the SD Card data logging program.

First of all i am not an expert person in Arduino.Now i have tried to learn and under stand the program through this type web plat form.So i expecting favorable reply from this community.I want to make data loging in SD card module with the help of arduino Uno.So i collect the program from the gogle and its working fine. Here is my code.

#include <Wire.h>     // lib for RTC
#include "RTClib.h"   // lib for RTC
#include <SPI.h>      // lib for SD
#include <SD.h>       // lib for SD

// set up variables using the SD utility library functions:
Sd2Card card;
SdVolume volume;
SdFile root;
const int chipSelect = 4;
File data;

// set up for RTC
RTC_DS1307 RTC;

// set up for led + button
const int buttonPin = 2;     // the number of the pushbutton pin
const int ledPin =  3;      // the number of the LED pin
int buttonState = 0;         // variable for reading the pushbutton status
int pbuttonState;

byte ok;  //stop the loop if SD card was not initialized
byte first=1;

void setup() {
  Serial.begin(57600);
  // led + button
  pinMode(ledPin, OUTPUT); 
  pinMode(buttonPin, INPUT); 
  
  // SD
   Serial.print("Initializing SD card...");
   pinMode(10, OUTPUT); // it's needed for SD library to work even if the CS is not connected to pin 10
            // see if the card is present and can be initialized:
  if (!SD.begin(chipSelect)) {
    Serial.println("Card failed, or not present");
    // don't do anything more:
    ok=0;
    
  }else{
  Serial.println("card initialized.");
  ok=1;  
 }
  // RTC
  Wire.begin();
  RTC.begin();
  // RTC.adjust(DateTime(__DATE__, __TIME__));  // set to pc time   

}

void loop() {
 if(ok==1)
{ 
  if(first==1)
  {
  
  buttonState = digitalRead(buttonPin);
  pbuttonState= buttonState;
  call(buttonState);
  first = 0;
  }
  else
  { 
    buttonState = digitalRead(buttonPin);
    if(pbuttonState != buttonState)
    {call(buttonState);
    pbuttonState=buttonState;
    }
  }
  delay(100);
}
}

String time()
{
 String dataString = "";  
 DateTime now = RTC.now();
 dataString += String(now.year(), DEC);
 dataString += String('/');
 dataString += String(now.month(), DEC);
 dataString += String('/');
 dataString += String(now.day(), DEC);
 dataString += String(' ');
 dataString += String(now.hour(), DEC);
 dataString += String(':');
 dataString += String(now.minute(), DEC);
 dataString += String(':');
 dataString += String(now.second(), DEC);

return dataString;       
}

void call( int buttonState)
{
    if (buttonState == LOW) {     
    // door is open    
    digitalWrite(ledPin, HIGH); 
    SDwrite(buttonState);
 
} 
  else {
    // door is closed
    digitalWrite(ledPin, LOW); 
    SDwrite(buttonState);
}
}


void SDwrite(int state)
{
String message = "";
if (state==LOW)  
{message = "OPEN";}
else
{message = "CLOSED";}
    data = SD.open("log.txt", FILE_WRITE);
    if (data) {
    if(state == LOW)
    {Serial.print("Door is open");}
    else
    {Serial.print("Door is closed");}
    data.print(time());
    data.print("   ");
    data.println(message);
  // close the file:
    data.close();
    Serial.println("  :done.");
  } else {
    // if the file didn't open, print an error:
    Serial.println("error opening log.txt");
  }  
  
}

But i can’t under stand below mentioned line in this code.

void SDwrite(int state)
{
String message = "";
if (state==LOW)
{message = "OPEN";}
else
{message = "CLOSED";}

How the “state” co related with “buttonPin” position?