I just started studying about smart contracts and from what I understand, smart contracts only deal with the data present on the blockchain. While working on a private blockchain, I want to know whether a smart contract in the blockchain can access external data and make changes to it. By external, I mean the data present on the nodes in the blockchain network, not data from the internet. So, no oracles. Since smart contracts are deterministic and gets executed on every node, assume I have the same file in the "datadir" of every node on the network. Can I access this file from a smart contract and make changes to it if necessary?
You are right. Out of the box, Ethereum is completely isolated.
The Ethereum Virtual Machine
The Ethereum Virtual Machine or EVM is the runtime environment for smart contracts in Ethereum. It is not only sandboxed but actually completely isolated, which means that code running inside the EVM has no access to network, filesystem or other processes. Smart contracts even have limited access to other smart contracts.
An alternative could be having an external machine listen for
events in the blockchain. It can decide what to do based on those.
In theory if you're running a private chain your validators control the validation software, so you can program it to do whatever you like. However, since it's designed for a public chain that expects validation to be deterministic and self-contained, the Ethereum software as originally shipped doesn't, on its own, give you a way to do this.
One thing you might want to look at would be native contracts in Hydrachain, where IIUC you can write arbitrary python code and get your validators to run it, and use the results in contracts.
Another approach looks a bit like oracles, but it doesn't change your trust model in the way that oracles normally would: Get each of your validators to run a parallel system that watches the public blockchain and publish signed data (or send signed transactions, it comes to the same thing) testifying to what they saw. Then in your contract, check each that each thing you want to verify has been signed off on by 51% of validators. You can be screwed if 51% of your validators collude to lie about what they saw on the public blockchain, but your private blockchain is broken under those conditions anyway.